From 1fd18add08705c7d0a6196dc372d52b465176332 Mon Sep 17 00:00:00 2001 From: troy_paypac Date: Wed, 26 Mar 2014 14:58:30 +0800 Subject: [PATCH] internal module defns for node and express --- express/express.d.ts | 99 +++++++++++++++--------------- node/node.d.ts | 140 +++++++++++++++++++++---------------------- 2 files changed, 118 insertions(+), 121 deletions(-) diff --git a/express/express.d.ts b/express/express.d.ts index 243aa41d4..e18b7bc7d 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -12,14 +12,11 @@ /// -declare module "express" { - import http = require('http'); +declare module "express" { export = ExpressStatic; } +declare function ExpressStatic(): ExpressStatic.Express +declare module ExpressStatic { - // Merged declaration, e is both a callable function and a namespace - function e(): e.Express; - - module e { - interface IRoute { + export interface IRoute { path: string; method: string; @@ -35,7 +32,7 @@ declare module "express" { match(path: string): boolean; } - class Route implements IRoute { + export class Route implements IRoute { path: string; method: string; @@ -62,7 +59,7 @@ declare module "express" { new (method: string, path: string, callbacks: Function[], options: any): Route; } - interface IRouter { + export interface IRouter { /** * Map the given param placeholder `name`(s) to the given callback(s). * @@ -107,6 +104,8 @@ declare module "express" { all(path: string, ...callbacks: Function[]): void; + get(name: string): string; + get(name: string, ...handlers: RequestFunction[]): T; get(name: RegExp, ...handlers: RequestFunction[]): T; @@ -141,6 +140,8 @@ declare module "express" { all(path: string, ...callbacks: Function[]): void; + get(name: string): string; + get(name: string, ...handlers: RequestFunction[]): Router; get(name: RegExp, ...handlers: RequestFunction[]): Router; @@ -162,11 +163,11 @@ declare module "express" { patch(name: RegExp, ...handlers: RequestFunction[]): Router; } - interface Handler { + export interface Handler { (req: Request, res: Response, next?: Function): void; } - interface CookieOptions { + export interface CookieOptions { maxAge?: number; signed?: boolean; expires?: Date; @@ -176,9 +177,9 @@ declare module "express" { secure?: boolean; } - interface Errback { (err: Error): void; } + export interface Errback { (err: Error): void; } - interface Session { + export interface Session { /** * Update reset `.cookie.maxAge` to prevent * the cookie from expiring when the @@ -229,7 +230,7 @@ declare module "express" { count: number; } - interface Request { + export interface Request { session: Session; @@ -533,19 +534,19 @@ declare module "express" { url: string; } - interface MediaType { + export interface MediaType { value: string; quality: number; type: string; subtype: string; } - interface Send { + export interface Send { (status: number, body?: any): Response; (body: any): Response; } - interface Response extends http.ServerResponse { + export interface Response extends NodeHttp.ServerResponse { /** * Set status `code`. * @@ -889,11 +890,11 @@ declare module "express" { charset: string; } - interface RequestFunction { + export interface RequestFunction { (req: Request, res: Response, next: Function): any; } - interface Application extends IRouter { + export interface Application extends IRouter { /** * Initialize the server. * @@ -1145,7 +1146,7 @@ declare module "express" { routes: any; } - interface Express extends Application { + export interface Express extends Application { /** * Framework version. */ @@ -1199,7 +1200,7 @@ declare module "express" { * * @param options */ - function bodyParser(options?: any): Handler; + export function bodyParser(options?: any): Handler; /** * Error handler: @@ -1222,7 +1223,7 @@ declare module "express" { * * When accepted connect will output a nice html stack trace. */ - function errorHandler(opts?: any): Handler; + export function errorHandler(opts?: any): Handler; /** * Method Override: @@ -1235,7 +1236,7 @@ declare module "express" { * * @param key */ - function methodOverride(key?: string): Handler; + export function methodOverride(key?: string): Handler; /** * Cookie parser: @@ -1256,7 +1257,7 @@ declare module "express" { * * @param secret */ - function cookieParser(secret?: string): Handler; + export function cookieParser(secret?: string): Handler; /** * Session: @@ -1393,7 +1394,7 @@ declare module "express" { * * @param options */ - function session(options?: any): Handler; + export function session(options?: any): Handler; /** * Hash the given `sess` object omitting changes @@ -1401,7 +1402,7 @@ declare module "express" { * * @param sess */ - function hash(sess: string): string; + export function hash(sess: string): string; /** * Static: @@ -1427,7 +1428,7 @@ declare module "express" { * @param root * @param options */ - function static(root: string, options?: any): Handler; + export function static(root: string, options?: any): Handler; /** * Basic Auth: @@ -1492,7 +1493,7 @@ declare module "express" { * * @param options */ - function compress(options?: any): Handler; + export function compress(options?: any): Handler; /** * Cookie Session: @@ -1519,7 +1520,7 @@ declare module "express" { * * @param options */ - function cookieSession(options?: any): Handler; + export function cookieSession(options?: any): Handler; /** * Anti CSRF: @@ -1560,7 +1561,7 @@ declare module "express" { * @param root * @param options */ - function directory(root: string, options?: any): Handler; + export function directory(root: string, options?: any): Handler; /** * Favicon: @@ -1609,7 +1610,7 @@ declare module "express" { * * @param options */ - function json(options?: any): Handler; + export function json(options?: any): Handler; /** * Limit: @@ -1623,9 +1624,9 @@ declare module "express" { * .use(connect.limit('5.5mb')) * .use(handleImageUpload) */ - function limit(bytes: number): Handler; + export function limit(bytes: number): Handler; - function limit(bytes: string): Handler; + export function limit(bytes: string): Handler; /** * Logger: @@ -1686,18 +1687,18 @@ declare module "express" { * * connect.logger.format('name', 'string or function') */ - function logger(options: string): Handler; + export function logger(options: string): Handler; - function logger(options: Function): Handler; + export function logger(options: Function): Handler; - function logger(options?: any): Handler; + export function logger(options?: any): Handler; /** * Compile `fmt` into a function. * * @param fmt */ - function compile(fmt: string): Handler; + export function compile(fmt: string): Handler; /** * Define a token function with the given `name`, @@ -1706,14 +1707,14 @@ declare module "express" { * @param name * @param fn */ - function token(name: string, fn: Function): any; + export function token(name: string, fn: Function): any; /** * Define a `fmt` with the given `name`. */ - function format(name: string, str: string): any; + export function format(name: string, str: string): any; - function format(name: string, str: Function): any; + export function format(name: string, str: Function): any; /** * Query: @@ -1731,7 +1732,7 @@ declare module "express" { * * The `options` passed are provided to qs.parse function. */ - function query(options: any): Handler; + export function query(options: any): Handler; /** * Reponse time: @@ -1739,7 +1740,7 @@ declare module "express" { * Adds the `X-Response-Time` header displaying the response * duration in milliseconds. */ - function responseTime(): Handler; + export function responseTime(): Handler; /** * Static cache: @@ -1771,7 +1772,7 @@ declare module "express" { * - `maxObjects` max cache objects [128] * - `maxLength` max cache object length 256kb */ - function staticCache(options: any): Handler; + export function staticCache(options: any): Handler; /** * Timeout: @@ -1784,7 +1785,7 @@ declare module "express" { * the response behaviour. This error has the `.timeout` property as * well as `.status == 408`. */ - function timeout(ms: number): Handler; + export function timeout(ms: number): Handler; /** * Vhost: @@ -1802,14 +1803,10 @@ declare module "express" { * @param hostname * @param server */ - function vhost(hostname: string, server: any): Handler; + export function vhost(hostname: string, server: any): Handler; - function urlencoded(): any; + export function urlencoded(): any; - function multipart(): any; - - } - - export = e; + export function multipart(): any; } diff --git a/node/node.d.ts b/node/node.d.ts index 4fafb883e..ddfb5b94a 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -224,14 +224,16 @@ interface NodeTimer { * MODULES * * * ************************************************/ -declare module "querystring" { +declare module "querystring" { export = NodeQueryString; } +declare module NodeQueryString { export function stringify(obj: any, sep?: string, eq?: string): string; export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; export function escape(): any; export function unescape(): any; } -declare module "events" { +declare module "events" { export = NodeEvents; } +declare module NodeEvents { export class EventEmitter implements NodeEventEmitter { static listenerCount(emitter: EventEmitter, event: string): number; @@ -246,10 +248,8 @@ declare module "events" { } } -declare module "http" { - import events = require("events"); - import net = require("net"); - import stream = require("stream"); +declare module "http" { export = NodeHttp; } +declare module NodeHttp { export interface Server extends NodeEventEmitter { listen(port: number, hostname?: string, backlog?: number, callback?: Function): void; @@ -267,7 +267,7 @@ declare module "http" { setEncoding(encoding?: string): void; pause(): void; resume(): void; - connection: net.Socket; + connection: NodeNet.Socket; } export interface ServerResponse extends NodeEventEmitter, WritableStream { // Extended base methods @@ -335,9 +335,8 @@ declare module "http" { export var globalAgent: Agent; } -declare module "cluster" { - import child = require("child_process"); - import events = require("events"); +declare module "cluster" { export = NodeCluster; } +declare module NodeCluster { export interface ClusterSettings { exec?: string; @@ -345,9 +344,9 @@ declare module "cluster" { silent?: boolean; } - export class Worker extends events.EventEmitter { + export class Worker extends NodeEvents.EventEmitter { id: string; - process: child.ChildProcess; + process: NodeChildProcess.ChildProcess; suicide: boolean; send(message: any, sendHandle?: any): void; kill(signal?: string): void; @@ -375,8 +374,9 @@ declare module "cluster" { export function emit(event: string, ...args: any[]): boolean; } -declare module "zlib" { - import stream = require("stream"); +declare module "zlib" { export = NodeZlib; } +declare module NodeZlib { + export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } export interface Gzip extends ReadWriteStream { } @@ -437,7 +437,8 @@ declare module "zlib" { export var Z_NULL: number; } -declare module "os" { +declare module "os" { export = NodeOs; } +declare module NodeOs { export function tmpDir(): string; export function hostname(): string; export function type(): string; @@ -453,10 +454,8 @@ declare module "os" { export var EOL: string; } -declare module "https" { - import tls = require("tls"); - import events = require("events"); - import http = require("http"); +declare module "https" { export = NodeHttps; } +declare module NodeHttps { export interface ServerOptions { pfx?: any; @@ -499,14 +498,15 @@ declare module "https" { export var Agent: { new (options?: RequestOptions): Agent; }; - export interface Server extends tls.Server { } + export interface Server extends NodeTls.Server { } export function createServer(options: ServerOptions, requestListener?: Function): Server; - export function request(options: RequestOptions, callback?: (res: NodeEventEmitter) =>void ): http.ClientRequest; - export function get(options: RequestOptions, callback?: (res: NodeEventEmitter) =>void ): http.ClientRequest; + export function request(options: RequestOptions, callback?: (res: NodeEventEmitter) => void): NodeHttp.ClientRequest; + export function get(options: RequestOptions, callback?: (res: NodeEventEmitter) => void): NodeHttp.ClientRequest; export var globalAgent: Agent; } -declare module "punycode" { +declare module "punycode" { export = NodePunyCode; } +declare module NodePunyCode { export function decode(string: string): string; export function encode(string: string): string; export function toUnicode(domain: string): string; @@ -519,9 +519,8 @@ declare module "punycode" { export var version: any; } -declare module "repl" { - import stream = require("stream"); - import events = require("events"); +declare module "repl" { export = NodeRepl; } +declare module NodeRepl { export interface ReplOptions { prompt?: string; @@ -537,9 +536,8 @@ declare module "repl" { export function start(options: ReplOptions): NodeEventEmitter; } -declare module "readline" { - import events = require("events"); - import stream = require("stream"); +declare module "readline" { export = NodeReadLine; } +declare module NodeReadLine { export interface ReadLine extends NodeEventEmitter { setPrompt(prompt: string, length: number): void; @@ -559,7 +557,8 @@ declare module "readline" { export function createInterface(options: ReadLineOptions): ReadLine; } -declare module "vm" { +declare module "vm" { export = NodeVm; } +declare module NodeVm { export interface Context { } export interface Script { runInThisContext(): void; @@ -572,9 +571,8 @@ declare module "vm" { export function createScript(code: string, filename?: string): Script; } -declare module "child_process" { - import events = require("events"); - import stream = require("stream"); +declare module "child_process" { export = NodeChildProcess; } +declare module NodeChildProcess { export interface ChildProcess extends NodeEventEmitter { stdin: WritableStream; @@ -621,7 +619,8 @@ declare module "child_process" { }): ChildProcess; } -declare module "url" { +declare module "url" { export = NodeUrl; } +declare module NodeUrl { export interface Url { href: string; protocol: string; @@ -651,7 +650,8 @@ declare module "url" { export function resolve(from: string, to: string): string; } -declare module "dns" { +declare module "dns" { export = NodeDns; } +declare module NodeDns { export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; @@ -666,8 +666,8 @@ declare module "dns" { export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; } -declare module "net" { - import stream = require("stream"); +declare module "net" { export = NodeNet; } +declare module NodeNet { export interface Socket extends ReadWriteStream { // Extended base methods @@ -728,8 +728,8 @@ declare module "net" { export function isIPv6(input: string): boolean; } -declare module "dgram" { - import events = require("events"); +declare module "dgram" { export = NodeDgram; } +declare module NodeDgram { export function createSocket(type: string, callback?: Function): Socket; @@ -746,8 +746,8 @@ declare module "dgram" { } } -declare module "fs" { - import stream = require("stream"); +declare module "fs" { export = NodeFs; } +declare module NodeFs { interface Stats { isFile(): boolean; @@ -893,7 +893,8 @@ declare module "fs" { }): WriteStream; } -declare module "path" { +declare module "path" { export = NodePath; } +declare module NodePath { export function normalize(p: string): string; export function join(...paths: any[]): string; export function resolve(...pathSegments: any[]): string; @@ -904,7 +905,8 @@ declare module "path" { export var sep: string; } -declare module "string_decoder" { +declare module "string_decoder" { export = NodeStringDecoder; } +declare module NodeStringDecoder { export interface NodeStringDecoder { write(buffer: NodeBuffer): string; detectIncompleteChar(buffer: NodeBuffer): number; @@ -914,10 +916,8 @@ declare module "string_decoder" { }; } -declare module "tls" { - import crypto = require("crypto"); - import net = require("net"); - import stream = require("stream"); +declare module "tls" { export = NodeTls; } +declare module NodeTls { var CLIENT_RENEG_LIMIT: number; var CLIENT_RENEG_WINDOW: number; @@ -940,7 +940,7 @@ declare module "tls" { export interface ConnectionOptions { host?: string; port?: number; - socket?: net.Socket; + socket?: NodeNet.Socket; pfx?: any; //string | Buffer key?: any; //string | Buffer passphrase?: string; @@ -951,7 +951,7 @@ declare module "tls" { servername?: string; } - export interface Server extends net.Server { + export interface Server extends NodeNet.Server { // Extended base methods listen(port: number, host?: string, backlog?: number, listeningListener?: Function): void; listen(path: string, listeningListener?: Function): void; @@ -995,10 +995,11 @@ declare module "tls" { export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; + export function createSecurePair(credentials?: NodeCrypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; } -declare module "crypto" { +declare module "crypto" { export = NodeCrypto; } +declare module NodeCrypto { export interface CredentialDetails { pfx: string; key: string; @@ -1064,8 +1065,8 @@ declare module "crypto" { export function pseudoRandomBytes(size: number, callback: (err: Error, buf: NodeBuffer) =>void ): void; } -declare module "stream" { - import events = require("events"); +declare module "stream" { export = NodeStream; } +declare module NodeStream { export interface ReadableOptions { highWaterMark?: number; @@ -1073,7 +1074,7 @@ declare module "stream" { objectMode?: boolean; } - export class Readable extends events.EventEmitter implements ReadableStream { + export class Readable extends NodeEvents.EventEmitter implements ReadableStream { readable: boolean; constructor(opts?: ReadableOptions); _read(size: number): void; @@ -1094,7 +1095,7 @@ declare module "stream" { decodeStrings?: boolean; } - export class Writable extends events.EventEmitter implements WritableStream { + export class Writable extends NodeEvents.EventEmitter implements WritableStream { writable: boolean; constructor(opts?: WritableOptions); _write(data: NodeBuffer, encoding: string, callback: Function): void; @@ -1130,7 +1131,7 @@ declare module "stream" { export interface TransformOptions extends ReadableOptions, WritableOptions {} // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements ReadWriteStream { + export class Transform extends NodeEvents.EventEmitter implements ReadWriteStream { readable: boolean; writable: boolean; constructor(opts?: TransformOptions); @@ -1159,7 +1160,8 @@ declare module "stream" { export class PassThrough extends Transform {} } -declare module "util" { +declare module "util" { export = NodeUtil; } +declare module NodeUtil { export interface InspectOptions { showHidden?: boolean; depth?: number; @@ -1182,9 +1184,10 @@ declare module "util" { export function inherits(constructor: any, superConstructor: any): void; } -declare module "assert" { - function internal (value: any, message?: string): void; - module internal { +declare module "assert" { export = NodeAssert; } +declare function NodeAssert(value: any, message?: string): void; +declare module NodeAssert { + export class AssertionError implements Error { name: string; message: string; @@ -1220,29 +1223,26 @@ declare module "assert" { } export function ifError(value: any): void; - } - - export = internal; } -declare module "tty" { - import net = require("net"); +declare module "tty" { export = NodeTty; } +declare module NodeTty { export function isatty(fd: number): boolean; - export interface ReadStream extends net.Socket { + export interface ReadStream extends NodeNet.Socket { isRaw: boolean; setRawMode(mode: boolean): void; } - export interface WriteStream extends net.Socket { + export interface WriteStream extends NodeNet.Socket { columns: number; rows: number; } } -declare module "domain" { - import events = require("events"); +declare module "domain" { export = NodeDomain; } +declare module NodeDomain { - export class Domain extends events.EventEmitter { + export class Domain extends NodeEvents.EventEmitter { run(fn: Function): void; add(emitter: NodeEventEmitter): void; remove(emitter: NodeEventEmitter): void;