balena-io-modules / resin-device-logs

Resin.io device logs utilities.
Apache License 2.0
3 stars 2 forks source link

Add typings for Typescript #25

Open flesler opened 6 years ago

flesler commented 6 years ago

I wrote my version of the typings. I will be deleting them so I'll paste them here in case we ever want to polish and add them.

declare module 'resin-device-logs' {

    import { EventEmitter } from 'events'

    type PubNubKeys = {
        publishKey?: string
        subscribeKey?: string
    }

    type Device = {
        logs_channel?: string
        uuid?: string
    }

    interface Emitter extends EventEmitter {
        unsubscribe() : void
    }

    type Message = {
        message: string
        timestamp?: number
        isSystem: boolean,
        serviceId?: string
    }

    type Options = {
        channel: string
        reverse?: boolean // default false
        count?: number // default 100
    }

    export function subscribe(pubnubKeys: PubNubKeys, device: Device): EventEmitter
    export function history(pubnubKeys: PubNubKeys, device: Device, options?: Options): Promise<Message[]>
    export function historySinceLastClear(pubnubKeys: PubNubKeys, device: Device, options?: Options): Promise<Message[]>
    export function clear(pubnubKeys: PubNubKeys, device: Device): Promise<any>
    export function getLastClearTime(pubnubKeys: PubNubKeys, device: Device): Promise<number>
}
pimterry commented 6 years ago

We are going to want to convert this all to typescript soonish, so this will definitely be useful, thanks!