nordlaender

express-3.0.d.ts

Dec 29th, 2012
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.06 KB | None | 0 0
  1. // Type definitions for Express 3.0
  2. // Project: http://expressjs.com
  3. // Definitions by: Boris Yankov <https://github.com/borisyankov/>
  4. // Definitions: https://github.com/borisyankov/DefinitelyTyped
  5.  
  6. /*
  7. USAGE
  8.  
  9. ///<reference path="./DefinitelyTyped/Definitions/express-3.0.d.ts"/>
  10. import express = module('express')
  11. var app = <express.ServerApplication> express()
  12. ...
  13.  
  14. MIDDLEWARE
  15.  
  16. express exports lots of middleware, like .static, .session, etc, but use connect so you don't have to escape
  17. var connect = require('connect')
  18. connect.session({})
  19.  
  20. */
  21.  
  22. ///<reference path='node-0.8.d.ts' />
  23.  
  24. // do not reference this. use module('express') instead
  25. declare module _express {
  26.  
  27. import http = module("http");
  28.  
  29. export interface Handler {
  30. (req: ServerRequest, res: ServerResponse, next?: Function): void;
  31. }
  32.  
  33. export interface Errback { (err: Error): void; }
  34.  
  35. export interface CookieOptions {
  36. maxAge?: number;
  37. signed?: bool;
  38. expires?: Date;
  39. httpOnly?: bool;
  40. path?: string;
  41. domain?: string;
  42. secure?: bool;
  43. }
  44.  
  45. export interface ExpressSettings {
  46. env?: string;
  47. views?: string;
  48. }
  49.  
  50. export interface ServerApplication {
  51.  
  52. settings: ExpressSettings;
  53. locals: any;
  54. routes: any;
  55.  
  56. (): ServerApplication;
  57.  
  58. router: Handler;
  59.  
  60. use(route: string, callback: Function): ServerApplication;
  61. use(route: string, server: ServerApplication): ServerApplication;
  62. use(callback: Function): ServerApplication;
  63. use(server: ServerApplication): ServerApplication;
  64.  
  65. engine(ext: string, callback: Function): ServerApplication;
  66.  
  67. param(param: Function): ServerApplication;
  68. param(name: string, callback: Function): ServerApplication;
  69. param(name: string, expressParam: any): ServerApplication;
  70. param(name: any[], callback: Function): ServerApplication;
  71.  
  72. set(name: string): ServerApplication;
  73. set(name: string, val: any): ServerApplication;
  74.  
  75. enabled(name: string): bool;
  76. disabled(name: string): bool;
  77.  
  78. enable(name: string): ServerApplication;
  79. disable(name: string): ServerApplication;
  80.  
  81. configure(env: string, callback: () => void ): ServerApplication;
  82. configure(...params: any[]): ServerApplication; // covering this case: (...env: string[], callback: () => void)
  83. configure(callback: () => void ): ServerApplication;
  84.  
  85. all(path: string, ...callbacks: Function[]): void;
  86.  
  87. render(view: string, callback: (err: Error, html) => void ): void;
  88. render(view: string, optionss: any, callback: (err: Error, html) => void ): void;
  89.  
  90. listen(port: number, hostname: string, backlog: number, callback: Function): void;
  91. listen(port: number, callback: Function): void;
  92. listen(path: string, callback?: Function): void;
  93. listen(handle: any, listeningListener?: Function): void;
  94.  
  95. get(name: string): any;
  96. get(path: string, handler: Handler ): void;
  97. get(path: RegExp, handler: Handler ): void;
  98. get(path: string, ...callbacks: Handler[]): void;
  99.  
  100. post(path: string, handler: Handler ): void;
  101. post(path: RegExp, handler: Handler ): void;
  102. post(path: string, ...callbacks: Handler[]): void;
  103.  
  104. put(path: string, handler: Handler ): void;
  105. put(path: RegExp, handler: Handler ): void;
  106. put(path: string, ...callbacks: Handler[]): void;
  107.  
  108. del(path: string, handler: Handler ): void;
  109. del(path: RegExp, handler: Handler ): void;
  110. del(path: string, ...callbacks: Handler[]): void;
  111. }
  112.  
  113. export interface ServerRequest extends http.ServerRequest {
  114.  
  115. accepted: any[];
  116. acceptedLanguages: string[];
  117. acceptedCharsets: string[];
  118.  
  119. params: any;
  120. query: any;
  121. body: any;
  122. files: any;
  123.  
  124. route: any;
  125. cookies: any;
  126. signedCookies: any;
  127.  
  128. get(field: string): string;
  129. header(field: string): string;
  130.  
  131. accepts(types: string): any;
  132. accepts(types: string[]): any;
  133. acceptsCharset(charset: string): bool;
  134. acceptsLanguage(lang: string): bool;
  135.  
  136. range(size: number): number[];
  137.  
  138. param(name: string, defaultValue?: any): string;
  139. is(type: string): bool;
  140.  
  141. protocol: string;
  142. secure: bool;
  143. ip: string;
  144. ips: string[];
  145. auth: any;
  146. subdomains: string[];
  147. path: string;
  148. host: string;
  149. fresh: bool;
  150. stale: bool;
  151. xhr: bool;
  152. }
  153.  
  154. export interface ServerResponse extends http.ServerResponse {
  155.  
  156. charset: string;
  157. locals: any;
  158.  
  159. status(code: number): ServerResponse;
  160. links(links: any): ServerResponse;
  161.  
  162. send(status: number): ServerResponse;
  163. send(bodyOrStatus: any): ServerResponse;
  164. send(status: number, body: any): ServerResponse;
  165. json(status: number): ServerResponse;
  166. json(bodyOrStatus: any): ServerResponse;
  167. json(status: number, body: any): ServerResponse;
  168. jsonp(status: number): ServerResponse;
  169. jsonp(bodyOrStatus: any): ServerResponse;
  170. jsonp(status: number, body: any): ServerResponse;
  171.  
  172. sendfile(path: string): void;
  173. sendfile(path: string, options: any): void;
  174. sendfile(path: string, fn: Errback): void;
  175. sendfile(path: string, options: any, fn: Errback): void;
  176. download(path: string): void;
  177. download(path: string, filename: string): void;
  178. download(path: string, fn: Errback): void;
  179. download(path: string, filename: string, fn: Errback): void;
  180.  
  181. type(type: string): ServerResponse;
  182. contentType(type: string): ServerResponse;
  183.  
  184. format(object: any): ServerResponse;
  185. attachment(filename?: string): ServerResponse;
  186.  
  187. set(field: any): void;
  188. set(field: string, value: string): void;
  189. header(field: any): void;
  190. header(field: string, value: string): void;
  191.  
  192. get(field: string): string;
  193.  
  194. clearCookie(name: string, options?: any): ServerResponse;
  195. cookie(name: string, value: any, options?: CookieOptions): ServerResponse;
  196.  
  197. redirect(url: string): void;
  198. redirect(status: number, url: string): void;
  199. redirect(url: string, status: number): void;
  200.  
  201. render(view: string, options: any): void;
  202. render(view: string, callback: (err: Error, html: any) => void ): void;
  203. render(view: string, options: any, callback: (err: Error, html: any) => void ): void;
  204. }
  205. }
  206.  
  207. declare module "express" {
  208. export function (): _express.ServerApplication;
  209. export function createServer(): ServerApplication;
  210. export function static(path: string): any;
  211. export var listen;
  212.  
  213. // Connect middleware
  214. export function bodyParser(options?: any): Handler;
  215. export function errorHandler(opts?: any): Handler;
  216. export function methodOverride(): Handler;
  217.  
  218. export interface ServerApplication extends _express.ServerApplication {}
  219. export interface ServerRequest extends _express.ServerRequest {}
  220. export interface ServerResponse extends _express.ServerResponse {}
  221. export interface Handler extends _express.Handler {}
  222. }
Advertisement
Add Comment
Please, Sign In to add comment