From 819bfb88c4908640d72553137e5bb25d527bfea9 Mon Sep 17 00:00:00 2001 From: jeffmo Date: Fri, 21 Nov 2014 14:37:20 -0800 Subject: [PATCH 1/4] Add type signature for node `dgram` module --- lib/node.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/node.js b/lib/node.js index 64ac874edf8..dd78a2040cd 100644 --- a/lib/node.js +++ b/lib/node.js @@ -217,7 +217,30 @@ declare module "crypto" { ): void; } +type dgram$Socket = { + addMembership(multicastAddress: string, multicastInterface?: string): void; + address(): {address: string; family: string; port: number}; + bind(port: number, address?: string, callback?: () => void): void; + close(): void; + dropMembership(multicastAddress: string, multicastInterface?: string): void; + ref(): void; + send( + buf: Buffer, + offset: number, + length: number, + port: number, + address: string, + callback?: (err: ?Error, bytes: any) => void + ): void; + setBroadcast(flag: boolean): void; + setMulticastLoopback(flag: boolean): void; + setMulticastTTL(ttl: number): void; + setTTL(ttl: number): void; + unref(): void; +}; + declare module "dgram" { + declare function createSocket(type: string, callback?: () => void): dgram$Socket; } declare module "dns" { From 23d69299772e6fb3d327a0d7f48bbb4be1825299 Mon Sep 17 00:00:00 2001 From: jeffmo Date: Mon, 24 Nov 2014 13:13:33 -0500 Subject: [PATCH 2/4] Add type signature for node `dns` and `dgram` modules --- lib/node.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index dd78a2040cd..01d49cb8cdd 100644 --- a/lib/node.js +++ b/lib/node.js @@ -244,7 +244,82 @@ declare module "dgram" { } declare module "dns" { - // TODO + declare var ADDRGETNETWORKPARAMS: string; + declare var BADFAMILY: string; + declare var BADFLAGS: string; + declare var BADHINTS: string; + declare var BADQUERY: string; + declare var BADNAME: string; + declare var BADRESP: string; + declare var BADSTR: string; + declare var CANCELLED: string; + declare var CONNREFUSED: string; + declare var DESTRUCTION: string; + declare var EOF: string; + declare var FILE: string; + declare var FORMER: string; + declare var LOADIPHLPAPI: string; + declare var NODATA: string; + declare var NOMEM: string; + declare var NONAME: string; + declare var NOTFOUND: string; + declare var NOTIMP: string; + declare var NOTINITIALIZED: string; + declare var REFUSED: string; + declare var SERVFAIL: string; + declare var TIMEOUT: string; + + declare function lookup( + domain: string, + family?: ?number, + callback?: (err: ?Error, address: string, family: number) => void + ): void; + + declare function resolve( + domain: string, + rrtype?: string, + callback?: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolve4( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolve6( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolveCname( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolveMx( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolveNs( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolveSrv( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function resolveTxt( + domain: string, + callback: (err: ?Error, addresses: Array) => void + ): void; + + declare function reverse( + ip: string, + callback: (err: ?Error, domains: Array) => void + ): void; } declare module "domain" { From 498a4c6aa5d5dff30cf15aec2d8d1a3908d4ab2c Mon Sep 17 00:00:00 2001 From: jeffmo Date: Mon, 24 Nov 2014 13:29:01 -0500 Subject: [PATCH 3/4] Add type signature for node `domain` module --- lib/node.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/node.js b/lib/node.js index 01d49cb8cdd..2fb2c0de061 100644 --- a/lib/node.js +++ b/lib/node.js @@ -322,10 +322,27 @@ declare module "dns" { ): void; } +type domain$Domain = { + members: Array; + + add(emitter: events$EventEmitter): void; + bind(callback: Function): Function; + dispose(): void; + enter(): void; + exit(): void; + intercept(callback: Function): Function; + remove(emitter: events$EventEmitter): void; + run(fn: Function): void; +}; + declare module "domain" { - // TODO + declare function create(): domain$Domain; } +type events$EventEmitter = { + +}; + declare module "events" { // TODO } From e23a5a2d1c79af63d1ace54bfa5338dfdcd530bc Mon Sep 17 00:00:00 2001 From: jeffmo Date: Mon, 24 Nov 2014 14:16:26 -0500 Subject: [PATCH 4/4] Add type signature for node `events` module --- lib/node.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/node.js b/lib/node.js index 2fb2c0de061..595467593d7 100644 --- a/lib/node.js +++ b/lib/node.js @@ -339,12 +339,27 @@ declare module "domain" { declare function create(): domain$Domain; } -type events$EventEmitter = { - -}; +// TODO: This is copypasta of the EventEmitter class signature exported from the +// `events` module. The only reason this exists is because other module +// interface definitions need to reference this type structure -- but +// referencing type structures defined in other modules isn't possible at +// the time of this writing. +declare class events$EventEmitter { + static listenerCount(emitter: events$EventEmitter, event: string): number; + + addListener(event: string, listener: Function): events$EventEmitter; + emit(event: string, ...args:Array): boolean; + listeners(event: string): Array; + on(event: string, listener: Function): events$EventEmitter; + once(event: string, listener: Function): events$EventEmitter; + removeAllListeners(events?: Array): events$EventEmitter; + removeListener(event: string, listener: Function): events$EventEmitter; + setMaxListeners(n: number): void; +} declare module "events" { - // TODO + // TODO: See the comment above the events$EventEmitter declaration + declare class EventEmitter extends events$EventEmitter {} } declare module "fs" {