From 0ab96c53c1b558db884d6994ff0bccfffe78caac Mon Sep 17 00:00:00 2001 From: Tanay PrabhuDesai Date: Sun, 11 Apr 2021 00:23:11 +0530 Subject: [PATCH] Closes #37 Add TypeScript type declarations --- index.d.ts | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 2 files changed, 53 insertions(+) create mode 100644 index.d.ts diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..e407c5e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,52 @@ +declare module 'bugout' { + type BugoutOpts = { + announce?: string[] + } + + type SeenCallBack = (address: string) => void + type ServerCallback = (address: string) => void + type ConnectionsCallback = (count: number) => void + type MessageCallback = (address: string, message: Record, packet: Record) => void + type PingCallback = (address: string) => void + type LeftCallback = (address: string) => void + type TimeoutCallback = (address: string) => void + type RPCCallback = (address: string, callback: (...any) => void) => void + type RPCResponseCallBack = (address: string, none: string, response: Record) => void + + type EventCallbacks = + | SeenCallBack + | ServerCallback + | ConnectionsCallback + | MessageCallback + | PingCallback + | LeftCallback + | TimeoutCallback + | RPCCallback + | RPCResponseCallBack + + class Bugout { + constructor(identifier: string, opts: BugoutOpts) + address(): string + register(callName: string, func: Function, docString: string): void + rpc(address: string, callName: string, args: Array>, callback: () => void) + send(address: string, message: string): void + send(message: string): void + heartbeat(milliseconds: number): void + destroy(callback?: () => void): void + on(eventName: string, callback: CallbackType) + } + export default Bugout + export { + Bugout, + BugoutOpts, + SeenCallBack, + ServerCallback, + ConnectionsCallback, + MessageCallback, + PingCallback, + LeftCallback, + TimeoutCallback, + RPCCallback, + RPCResponseCallBack, + } +} diff --git a/package.json b/package.json index bd55144..71541bf 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.11", "description": "Backend web services over WebRTC.", "main": "index.js", + "types": "index.d.ts", "author": "Chris McCormick ", "homepage": "https://github.com/chr15m/bugout", "repository": {