Express definitions complete rework and update to 3.0

This commit is contained in:
Boris Yankov
2012-10-26 10:23:00 +03:00
parent 4040630bd6
commit c02fecfcef
3 changed files with 410 additions and 167 deletions
-124
View File
@@ -1,124 +0,0 @@
///<reference path='node.d.ts' />
declare module "express" {
export function createServer(): ExpressServer;
export function static(path: string): any;
import http = module("http");
export var listen;
// Connect middleware
export function bodyParser(options?:any): (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function errorHandler(opts?:any): (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export function methodOverride(): (req: ExpressServerRequest, res: ExpressServerResponse, next) =>void;
export interface ExpressSettings {
env?: string;
views?: string;
}
export interface ExpressServer {
set(name: string): any;
set(name: string, val: any): any;
enable(name: string): ExpressServer;
disable(name: string): ExpressServer;
enabled(name: string): bool;
disabled(name: string): bool;
configure(env: string, callback: () => void): ExpressServer;
configure(env: string, env2: string, callback: () => void ): ExpressServer;
configure(callback: () => void): ExpressServer;
settings: ExpressSettings;
engine(ext: string, callback: any): void;
param(param: Function): ExpressServer;
param(name: string, callback: Function): ExpressServer;
param(name: string, expressParam: any): ExpressServer;
param(name: any[], callback: Function): ExpressServer;
get(name: string): any;
get(path: string, handler: (req: ExpressServerRequest, res: ExpressServerResponse) => void ): void;
get(path: RegExp, handler: (req: ExpressServerRequest, res: ExpressServerResponse) => void ): void;
get(path: string, callbacks: any, callback: () => void ): void;
post(path: string, handler: (req: ExpressServerRequest, res: ExpressServerResponse) => void ): void;
post(path: RegExp, handler: (req: ExpressServerRequest, res: ExpressServerResponse) => void ): void;
post(path: string, callbacks: any, callback: () => void ): void;
all(path: string, callback: Function): void;
all(path: string, callback: Function, callback2: Function): void;
locals: any;
render(view: string, callback: (err: Error, html) => void ): void;
render(view: string, opts: any, callback: (err: Error, html) => void ): void;
routes: any;
listen(port: number, hostname: string, backlog: number, callback: Function): void;
listen(port: number, callback: Function): void;
listen(path: string, callback?: Function): void;
listen(handle: any, listeningListener?: Function): void;
use(route: string, callback: Function): ExpressServer;
use(route: string, server: ExpressServer): ExpressServer;
use(callback: Function): ExpressServer;
use(server: ExpressServer): ExpressServer;
}
export interface ExpressServerRequest extends http.ServerRequest {
params: any;
query: any;
body: any;
files: any;
param(name: string): any;
route: any;
cookies: any;
signedCookies: any;
get(field: string): string;
accepts(types: string): any;
accepts(types: string[]): any;
accepted: any;
is(type: string): bool;
ip: string;
ips: string[];
path: string;
host: string;
fresh: bool;
stale: bool;
xhr: bool;
protocol: string;
secure: bool;
subdomains: string[];
acceptedLanguages: string[];
acceptedCharsets: string[];
acceptsCharset(charset: string): bool;
acceptsLanguage(lang: string): bool;
}
export interface ExpressServerResponse extends http.ServerResponse {
status(code: number): any;
set(field: any): void;
set(field: string, value: string): void;
header(field: any): void;
header(field: string, value: string): void;
get(field: string): any;
cookie(name: string, value: any, options?: any): void;
clearcookie(name: string, options?: any): void;
redirect(status: number, url: string): void;
redirect(url: string): void;
charset: string;
send(bodyOrStatus: any);
send(body: any, status: any);
send(body: any, headers: any, status: number);
json(bodyOrStatus: any);
json(body: any, status: any);
json(body: any, headers: any, status: number);
jsonp(bodyOrStatus: any);
jsonp(body: any, status: any);
jsonp(body: any, headers: any, status: number);
type(type: string): void;
format(object: any): void;
attachment(filename?: string);
sendfile(path: string): void;
sendfile(path: string, options: any): void;
sendfile(path: string, options: any, fn: (err: Error) =>void ): void;
download(path: string): void;
download(path: string, filename: string): void;
download(path: string, filename: string, fn: (err: Error) =>void ): void;
links(links: any): void;
locals: any;
render(view: string, locals: any): void;
render(view: string, callback: (err: Error, html: any) =>void ): void;
render(view: string, locals: any, callback: (err: Error, html: any) =>void ): void;
}
}
+187
View File
@@ -0,0 +1,187 @@
// Type definitions for Express 3.0
// Project: http://expressjs.com
// Definitions: https://github.com/borisyankov/DefinitelyTyped
///<reference path='node-0.8.d.ts' />
declare module "express" {
export function createServer(): ServerApplication;
export function static(path: string): any;
import http = module("http");
export var listen;
interface ReqResNext {
(req: ServerRequest, res: ServerResponse, next: Function): void;
}
interface Errback { (err: Error): void; }
interface CookieOptions {
maxAge?: number;
signed?: bool;
expires?: Date;
httpOnly?: bool;
path?: string;
domain?: string;
secure?: bool;
}
// Connect middleware
export function bodyParser(options?: any): ReqResNext;
export function errorHandler(opts?: any): ReqResNext;
export function methodOverride(): ReqResNext;
export interface ExpressSettings {
env?: string;
views?: string;
}
export interface ServerApplication {
settings: ExpressSettings;
locals: any;
routes: any;
(): ServerApplication;
router: ReqResNext;
use(route: string, callback: Function): ServerApplication;
use(route: string, server: ServerApplication): ServerApplication;
use(callback: Function): ServerApplication;
use(server: ServerApplication): ServerApplication;
engine(ext: string, callback: Function): ServerApplication;
param(param: Function): ServerApplication;
param(name: string, callback: Function): ServerApplication;
param(name: string, expressParam: any): ServerApplication;
param(name: any[], callback: Function): ServerApplication;
set(name: string): ServerApplication;
set(name: string, val: any): ServerApplication;
enabled(name: string): bool;
disabled(name: string): bool;
enable(name: string): ServerApplication;
disable(name: string): ServerApplication;
configure(env: string, callback: () => void ): ServerApplication;
configure(...params: any[]): ServerApplication; // covering this case: (...env: string[], callback: () => void)
configure(callback: () => void ): ServerApplication;
all(path: string, ...callbacks: Function[]): void;
render(view: string, callback: (err: Error, html) => void ): void;
render(view: string, optionss: any, callback: (err: Error, html) => void ): void;
listen(port: number, hostname: string, backlog: number, callback: Function): void;
listen(port: number, callback: Function): void;
listen(path: string, callback?: Function): void;
listen(handle: any, listeningListener?: Function): void;
get(name: string): any;
get(path: string, handler: (req: ServerRequest, res: ServerResponse) => void ): void;
get(path: RegExp, handler: (req: ServerRequest, res: ServerResponse) => void ): void;
get(path: string, callbacks: any, callback: () => void ): void;
post(path: string, handler: (req: ServerRequest, res: ServerResponse) => void ): void;
post(path: RegExp, handler: (req: ServerRequest, res: ServerResponse) => void ): void;
post(path: string, callbacks: any, callback: () => void ): void;
}
export interface ServerRequest extends http.ServerRequest {
accepted: any[];
acceptedLanguages: string[];
acceptedCharsets: string[];
params: any;
query: any;
body: any;
files: any;
route: any;
cookies: any;
signedCookies: any;
get(field: string): string;
header(field: string): string;
accepts(types: string): any;
accepts(types: string[]): any;
acceptsCharset(charset: string): bool;
acceptsLanguage(lang: string): bool;
range(size: number): number[];
param(name: string, defaultValue?: any): string;
is(type: string): bool;
protocol: string;
secure: bool;
ip: string;
ips: string[];
auth: any;
subdomains: string[];
path: string;
host: string;
fresh: bool;
stale: bool;
xhr: bool;
}
export interface ServerResponse extends http.ServerResponse {
charset: string;
locals: any;
status(code: number): ServerResponse;
links(links: any): ServerResponse;
send(status: number): ServerResponse;
send(bodyOrStatus: any): ServerResponse;
send(status: number, body: any): ServerResponse;
json(status: number): ServerResponse;
json(bodyOrStatus: any): ServerResponse;
json(status: number, body: any): ServerResponse;
jsonp(status: number): ServerResponse;
jsonp(bodyOrStatus: any): ServerResponse;
jsonp(status: number, body: any): ServerResponse;
sendfile(path: string): void;
sendfile(path: string, options: any): void;
sendfile(path: string, fn: Errback): void;
sendfile(path: string, options: any, fn: Errback): void;
download(path: string): void;
download(path: string, filename: string): void;
download(path: string, fn: Errback): void;
download(path: string, filename: string, fn: Errback): void;
type(type: string): ServerResponse;
contentType(type: string): ServerResponse;
format(object: any): ServerResponse;
attachment(filename?: string): ServerResponse;
set(field: any): void;
set(field: string, value: string): void;
header(field: any): void;
header(field: string, value: string): void;
get(field: string): string;
clearCookie(name: string, options?: any): ServerResponse;
cookie(name: string, value: any, options?: CookieOptions): ServerResponse;
redirect(url: string): void;
redirect(status: number, url: string): void;
redirect(url: string, status: number): void;
render(view: string, options: any): void;
render(view: string, callback: (err: Error, html: any) => void ): void;
render(view: string, options: any, callback: (err: Error, html: any) => void ): void;
}
}