Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more node std libs #115

Merged
merged 4 commits into from
Nov 26, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 133 additions & 3 deletions lib/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,19 +217,149 @@ declare module "crypto" {
): void;
}

type dgram$Socket = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dgram.Socket inherits from EventEmitter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch, I'll circle back on this in a follow-up

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" {
// 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;
}

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;
}

// 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<Function>;
on(event: string, listener: Function): events$EventEmitter;
once(event: string, listener: Function): events$EventEmitter;
removeAllListeners(events?: Array<string>): 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" {
Expand Down