|
| 1 | +// flow-typed signature: 41a220e96fcef89a09244ac3797039e8 |
| 2 | +// flow-typed version: 9f7cf2ab0c/express_v4.16.x/flow_>=v0.32.x |
| 3 | + |
| 4 | +import type { Server } from 'http'; |
| 5 | +import type { Socket } from 'net'; |
| 6 | + |
| 7 | +declare type express$RouterOptions = { |
| 8 | + caseSensitive?: boolean, |
| 9 | + mergeParams?: boolean, |
| 10 | + strict?: boolean |
| 11 | +}; |
| 12 | + |
| 13 | +declare class express$RequestResponseBase { |
| 14 | + app: express$Application; |
| 15 | + get(field: string): string | void; |
| 16 | +} |
| 17 | + |
| 18 | +declare type express$RequestParams = { |
| 19 | + [param: string]: string |
| 20 | +}; |
| 21 | + |
| 22 | +declare class express$Request extends http$IncomingMessage mixins express$RequestResponseBase { |
| 23 | + baseUrl: string; |
| 24 | + body: mixed; |
| 25 | + cookies: { [cookie: string]: string }; |
| 26 | + connection: Socket; |
| 27 | + fresh: boolean; |
| 28 | + hostname: string; |
| 29 | + ip: string; |
| 30 | + ips: Array<string>; |
| 31 | + method: string; |
| 32 | + originalUrl: string; |
| 33 | + params: express$RequestParams; |
| 34 | + path: string; |
| 35 | + protocol: 'https' | 'http'; |
| 36 | + query: { [name: string]: string | Array<string> }; |
| 37 | + route: string; |
| 38 | + secure: boolean; |
| 39 | + signedCookies: { [signedCookie: string]: string }; |
| 40 | + stale: boolean; |
| 41 | + subdomains: Array<string>; |
| 42 | + xhr: boolean; |
| 43 | + accepts(types: string): string | false; |
| 44 | + accepts(types: Array<string>): string | false; |
| 45 | + acceptsCharsets(...charsets: Array<string>): string | false; |
| 46 | + acceptsEncodings(...encoding: Array<string>): string | false; |
| 47 | + acceptsLanguages(...lang: Array<string>): string | false; |
| 48 | + header(field: string): string | void; |
| 49 | + is(type: string): boolean; |
| 50 | + param(name: string, defaultValue?: string): string | void; |
| 51 | +} |
| 52 | + |
| 53 | +declare type express$CookieOptions = { |
| 54 | + domain?: string, |
| 55 | + encode?: (value: string) => string, |
| 56 | + expires?: Date, |
| 57 | + httpOnly?: boolean, |
| 58 | + maxAge?: number, |
| 59 | + path?: string, |
| 60 | + secure?: boolean, |
| 61 | + signed?: boolean |
| 62 | +}; |
| 63 | + |
| 64 | +declare type express$Path = string | RegExp; |
| 65 | + |
| 66 | +declare type express$RenderCallback = (err: Error | null, html?: string) => mixed; |
| 67 | + |
| 68 | +declare type express$SendFileOptions = { |
| 69 | + maxAge?: number, |
| 70 | + root?: string, |
| 71 | + lastModified?: boolean, |
| 72 | + headers?: { [name: string]: string }, |
| 73 | + dotfiles?: 'allow' | 'deny' | 'ignore' |
| 74 | +}; |
| 75 | + |
| 76 | +declare class express$Response extends http$ServerResponse mixins express$RequestResponseBase { |
| 77 | + headersSent: boolean; |
| 78 | + locals: { [name: string]: mixed }; |
| 79 | + append(field: string, value?: string): this; |
| 80 | + attachment(filename?: string): this; |
| 81 | + cookie(name: string, value: string, options?: express$CookieOptions): this; |
| 82 | + clearCookie(name: string, options?: express$CookieOptions): this; |
| 83 | + download(path: string, filename?: string, callback?: (err?: ?Error) => void): this; |
| 84 | + format(typesObject: { [type: string]: Function }): this; |
| 85 | + json(body?: mixed): this; |
| 86 | + jsonp(body?: mixed): this; |
| 87 | + links(links: { [name: string]: string }): this; |
| 88 | + location(path: string): this; |
| 89 | + redirect(url: string, ...args: Array<void>): this; |
| 90 | + redirect(status: number, url: string, ...args: Array<void>): this; |
| 91 | + render(view: string, locals?: { [name: string]: mixed }, callback?: express$RenderCallback): this; |
| 92 | + send(body?: mixed): this; |
| 93 | + sendFile(path: string, options?: express$SendFileOptions, callback?: (err?: ?Error) => mixed): this; |
| 94 | + sendStatus(statusCode: number): this; |
| 95 | + header(field: string, value?: string): this; |
| 96 | + header(headers: { [name: string]: string }): this; |
| 97 | + set(field: string, value?: string | string[]): this; |
| 98 | + set(headers: { [name: string]: string }): this; |
| 99 | + status(statusCode: number): this; |
| 100 | + type(type: string): this; |
| 101 | + vary(field: string): this; |
| 102 | + req: express$Request; |
| 103 | +} |
| 104 | + |
| 105 | +declare type express$NextFunction = (err?: ?Error | 'route') => mixed; |
| 106 | +declare type express$Middleware = ((req: $Subtype<express$Request>, res: express$Response, next: express$NextFunction) => mixed) | ((error: Error, req: $Subtype<express$Request>, res: express$Response, next: express$NextFunction) => mixed); |
| 107 | +declare interface express$RouteMethodType<T> { |
| 108 | + (middleware: express$Middleware): T; |
| 109 | + (...middleware: Array<express$Middleware>): T; |
| 110 | + (path: express$Path | express$Path[], ...middleware: Array<express$Middleware>): T; |
| 111 | +} |
| 112 | +declare class express$Route { |
| 113 | + all: express$RouteMethodType<this>; |
| 114 | + get: express$RouteMethodType<this>; |
| 115 | + post: express$RouteMethodType<this>; |
| 116 | + put: express$RouteMethodType<this>; |
| 117 | + head: express$RouteMethodType<this>; |
| 118 | + delete: express$RouteMethodType<this>; |
| 119 | + options: express$RouteMethodType<this>; |
| 120 | + trace: express$RouteMethodType<this>; |
| 121 | + copy: express$RouteMethodType<this>; |
| 122 | + lock: express$RouteMethodType<this>; |
| 123 | + mkcol: express$RouteMethodType<this>; |
| 124 | + move: express$RouteMethodType<this>; |
| 125 | + purge: express$RouteMethodType<this>; |
| 126 | + propfind: express$RouteMethodType<this>; |
| 127 | + proppatch: express$RouteMethodType<this>; |
| 128 | + unlock: express$RouteMethodType<this>; |
| 129 | + report: express$RouteMethodType<this>; |
| 130 | + mkactivity: express$RouteMethodType<this>; |
| 131 | + checkout: express$RouteMethodType<this>; |
| 132 | + merge: express$RouteMethodType<this>; |
| 133 | + |
| 134 | + // @TODO Missing 'm-search' but get flow illegal name error. |
| 135 | + |
| 136 | + notify: express$RouteMethodType<this>; |
| 137 | + subscribe: express$RouteMethodType<this>; |
| 138 | + unsubscribe: express$RouteMethodType<this>; |
| 139 | + patch: express$RouteMethodType<this>; |
| 140 | + search: express$RouteMethodType<this>; |
| 141 | + connect: express$RouteMethodType<this>; |
| 142 | +} |
| 143 | + |
| 144 | +declare class express$Router extends express$Route { |
| 145 | + constructor(options?: express$RouterOptions): void; |
| 146 | + route(path: string): express$Route; |
| 147 | + static (options?: express$RouterOptions): express$Router; |
| 148 | + use(middleware: express$Middleware): this; |
| 149 | + use(...middleware: Array<express$Middleware>): this; |
| 150 | + use(path: express$Path | express$Path[], ...middleware: Array<express$Middleware>): this; |
| 151 | + use(path: string, router: express$Router): this; |
| 152 | + handle(req: http$IncomingMessage, res: http$ServerResponse, next: express$NextFunction): void; |
| 153 | + param(param: string, callback: (req: $Subtype<express$Request>, res: express$Response, next: express$NextFunction, id: string) => mixed): void; |
| 154 | + |
| 155 | + // Can't use regular callable signature syntax due to https://github.com/facebook/flow/issues/3084 |
| 156 | + $call: (req: http$IncomingMessage, res: http$ServerResponse, next?: ?express$NextFunction) => void; |
| 157 | +} |
| 158 | + |
| 159 | +/* |
| 160 | +With flow-bin ^0.59, express app.listen() is deemed to return any and fails flow type coverage. |
| 161 | +Which is ironic because https://github.com/facebook/flow/blob/master/Changelog.md#misc-2 (release notes for 0.59) |
| 162 | +says "Improves typings for Node.js HTTP server listen() function." See that? IMPROVES! |
| 163 | +To work around this issue, we changed Server to ?Server here, so that our invocations of express.listen() will |
| 164 | +not be deemed to lack type coverage. |
| 165 | +*/ |
| 166 | + |
| 167 | +declare class express$Application extends express$Router mixins events$EventEmitter { |
| 168 | + constructor(): void; |
| 169 | + locals: { [name: string]: mixed }; |
| 170 | + mountpath: string; |
| 171 | + listen(port: number, hostname?: string, backlog?: number, callback?: (err?: ?Error) => mixed): ?Server; |
| 172 | + listen(port: number, hostname?: string, callback?: (err?: ?Error) => mixed): ?Server; |
| 173 | + listen(port: number, callback?: (err?: ?Error) => mixed): ?Server; |
| 174 | + listen(path: string, callback?: (err?: ?Error) => mixed): ?Server; |
| 175 | + listen(handle: Object, callback?: (err?: ?Error) => mixed): ?Server; |
| 176 | + disable(name: string): void; |
| 177 | + disabled(name: string): boolean; |
| 178 | + enable(name: string): express$Application; |
| 179 | + enabled(name: string): boolean; |
| 180 | + engine(name: string, callback: Function): void; |
| 181 | + /** |
| 182 | + * Mixed will not be taken as a value option. Issue around using the GET http method name and the get for settings. |
| 183 | + */ |
| 184 | + // get(name: string): mixed; |
| 185 | + set(name: string, value: mixed): mixed; |
| 186 | + render(name: string, optionsOrFunction: { [name: string]: mixed }, callback: express$RenderCallback): void; |
| 187 | + handle(req: http$IncomingMessage, res: http$ServerResponse, next?: ?express$NextFunction): void; |
| 188 | +} |
| 189 | + |
| 190 | +declare type JsonOptions = { |
| 191 | + inflate?: boolean, |
| 192 | + limit?: string | number, |
| 193 | + reviver?: (key: string, value: mixed) => mixed, |
| 194 | + strict?: boolean, |
| 195 | + type?: string | Array<string> | ((req: express$Request) => boolean), |
| 196 | + verify?: (req: express$Request, res: express$Response, buf: Buffer, encoding: string) => mixed |
| 197 | +}; |
| 198 | + |
| 199 | +declare module 'express' { |
| 200 | + declare export type RouterOptions = express$RouterOptions; |
| 201 | + declare export type CookieOptions = express$CookieOptions; |
| 202 | + declare export type Middleware = express$Middleware; |
| 203 | + declare export type NextFunction = express$NextFunction; |
| 204 | + declare export type RequestParams = express$RequestParams; |
| 205 | + declare export type $Response = express$Response; |
| 206 | + declare export type $Request = express$Request; |
| 207 | + declare export type $Application = express$Application; |
| 208 | + |
| 209 | + declare module.exports: { |
| 210 | + (): express$Application, // If you try to call like a function, it will use this signature |
| 211 | + json: (opts: ?JsonOptions) => express$Middleware, |
| 212 | + static: (root: string, options?: Object) => express$Middleware, // `static` property on the function |
| 213 | + Router: typeof express$Router // `Router` property on the function |
| 214 | + }; |
| 215 | +} |
0 commit comments