|
| 1 | +// flow-typed signature: 106bbf49ff0c0b351c95d483d617ffba |
| 2 | +// flow-typed version: 7fe23c8e85/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 = ( |
| 67 | + err: Error | null, |
| 68 | + html?: string |
| 69 | +) => mixed; |
| 70 | + |
| 71 | +declare type express$SendFileOptions = { |
| 72 | + maxAge?: number, |
| 73 | + root?: string, |
| 74 | + lastModified?: boolean, |
| 75 | + headers?: { [name: string]: string }, |
| 76 | + dotfiles?: "allow" | "deny" | "ignore" |
| 77 | +}; |
| 78 | + |
| 79 | +declare class express$Response extends http$ServerResponse mixins express$RequestResponseBase { |
| 80 | + headersSent: boolean; |
| 81 | + locals: { [name: string]: mixed }; |
| 82 | + append(field: string, value?: string): this; |
| 83 | + attachment(filename?: string): this; |
| 84 | + cookie(name: string, value: string, options?: express$CookieOptions): this; |
| 85 | + clearCookie(name: string, options?: express$CookieOptions): this; |
| 86 | + download( |
| 87 | + path: string, |
| 88 | + filename?: string, |
| 89 | + callback?: (err?: ?Error) => void |
| 90 | + ): this; |
| 91 | + format(typesObject: { [type: string]: Function }): this; |
| 92 | + json(body?: mixed): this; |
| 93 | + jsonp(body?: mixed): this; |
| 94 | + links(links: { [name: string]: string }): this; |
| 95 | + location(path: string): this; |
| 96 | + redirect(url: string, ...args: Array<void>): this; |
| 97 | + redirect(status: number, url: string, ...args: Array<void>): this; |
| 98 | + render( |
| 99 | + view: string, |
| 100 | + locals?: { [name: string]: mixed }, |
| 101 | + callback?: express$RenderCallback |
| 102 | + ): this; |
| 103 | + send(body?: mixed): this; |
| 104 | + sendFile( |
| 105 | + path: string, |
| 106 | + options?: express$SendFileOptions, |
| 107 | + callback?: (err?: ?Error) => mixed |
| 108 | + ): this; |
| 109 | + sendStatus(statusCode: number): this; |
| 110 | + header(field: string, value?: string): this; |
| 111 | + header(headers: { [name: string]: string }): this; |
| 112 | + set(field: string, value?: string | string[]): this; |
| 113 | + set(headers: { [name: string]: string }): this; |
| 114 | + status(statusCode: number): this; |
| 115 | + type(type: string): this; |
| 116 | + vary(field: string): this; |
| 117 | + req: express$Request; |
| 118 | +} |
| 119 | + |
| 120 | +// Lagoon addition: extend Error to have status property (for auth-server) |
| 121 | +declare interface express$LagoonErrorWithStatus extends Error { |
| 122 | + status: number; |
| 123 | +} |
| 124 | + |
| 125 | +declare type express$NextFunction = (err?: ?Error | "route") => mixed; |
| 126 | +declare type express$Middleware = |
| 127 | + | (( |
| 128 | + req: $Subtype<express$Request>, |
| 129 | + res: express$Response, |
| 130 | + next: express$NextFunction |
| 131 | + ) => mixed) |
| 132 | + | (( |
| 133 | + // Lagoon change: extend Error to have status property (for auth-server). Original: |
| 134 | + // error: Error, |
| 135 | + error: express$LagoonErrorWithStatus, |
| 136 | + req: $Subtype<express$Request>, |
| 137 | + res: express$Response, |
| 138 | + next: express$NextFunction |
| 139 | + ) => mixed); |
| 140 | +declare interface express$RouteMethodType<T> { |
| 141 | + (middleware: express$Middleware): T; |
| 142 | + (...middleware: Array<express$Middleware>): T; |
| 143 | + ( |
| 144 | + path: express$Path | express$Path[], |
| 145 | + ...middleware: Array<express$Middleware> |
| 146 | + ): T; |
| 147 | +} |
| 148 | +declare class express$Route { |
| 149 | + all: express$RouteMethodType<this>; |
| 150 | + // Lagoon change: Type relaxed to allow for modifying the context. (for api) |
| 151 | + // Original: |
| 152 | + // get: express$RouteMethodType<this>; |
| 153 | + get: Function; |
| 154 | + post: express$RouteMethodType<this>; |
| 155 | + put: express$RouteMethodType<this>; |
| 156 | + head: express$RouteMethodType<this>; |
| 157 | + delete: express$RouteMethodType<this>; |
| 158 | + options: express$RouteMethodType<this>; |
| 159 | + trace: express$RouteMethodType<this>; |
| 160 | + copy: express$RouteMethodType<this>; |
| 161 | + lock: express$RouteMethodType<this>; |
| 162 | + mkcol: express$RouteMethodType<this>; |
| 163 | + move: express$RouteMethodType<this>; |
| 164 | + purge: express$RouteMethodType<this>; |
| 165 | + propfind: express$RouteMethodType<this>; |
| 166 | + proppatch: express$RouteMethodType<this>; |
| 167 | + unlock: express$RouteMethodType<this>; |
| 168 | + report: express$RouteMethodType<this>; |
| 169 | + mkactivity: express$RouteMethodType<this>; |
| 170 | + checkout: express$RouteMethodType<this>; |
| 171 | + merge: express$RouteMethodType<this>; |
| 172 | + |
| 173 | + // @TODO Missing 'm-search' but get flow illegal name error. |
| 174 | + |
| 175 | + notify: express$RouteMethodType<this>; |
| 176 | + subscribe: express$RouteMethodType<this>; |
| 177 | + unsubscribe: express$RouteMethodType<this>; |
| 178 | + patch: express$RouteMethodType<this>; |
| 179 | + search: express$RouteMethodType<this>; |
| 180 | + connect: express$RouteMethodType<this>; |
| 181 | +} |
| 182 | + |
| 183 | +declare class express$Router extends express$Route { |
| 184 | + constructor(options?: express$RouterOptions): void; |
| 185 | + route(path: string): express$Route; |
| 186 | + static (options?: express$RouterOptions): express$Router; |
| 187 | + use(middleware: express$Middleware): this; |
| 188 | + use(...middleware: Array<express$Middleware>): this; |
| 189 | + use( |
| 190 | + path: express$Path | express$Path[], |
| 191 | + ...middleware: Array<express$Middleware> |
| 192 | + ): this; |
| 193 | + use(path: string, router: express$Router): this; |
| 194 | + handle( |
| 195 | + req: http$IncomingMessage, |
| 196 | + res: http$ServerResponse, |
| 197 | + next: express$NextFunction |
| 198 | + ): void; |
| 199 | + param( |
| 200 | + param: string, |
| 201 | + callback: ( |
| 202 | + req: $Subtype<express$Request>, |
| 203 | + res: express$Response, |
| 204 | + next: express$NextFunction, |
| 205 | + id: string |
| 206 | + ) => mixed |
| 207 | + ): void; |
| 208 | + |
| 209 | + // Can't use regular callable signature syntax due to https://github.com/facebook/flow/issues/3084 |
| 210 | + $call: ( |
| 211 | + req: http$IncomingMessage, |
| 212 | + res: http$ServerResponse, |
| 213 | + next?: ?express$NextFunction |
| 214 | + ) => void; |
| 215 | +} |
| 216 | + |
| 217 | +/* |
| 218 | +With flow-bin ^0.59, express app.listen() is deemed to return any and fails flow type coverage. |
| 219 | +Which is ironic because https://github.com/facebook/flow/blob/master/Changelog.md#misc-2 (release notes for 0.59) |
| 220 | +says "Improves typings for Node.js HTTP server listen() function." See that? IMPROVES! |
| 221 | +To work around this issue, we changed Server to ?Server here, so that our invocations of express.listen() will |
| 222 | +not be deemed to lack type coverage. |
| 223 | +*/ |
| 224 | + |
| 225 | +declare class express$Application extends express$Router mixins events$EventEmitter { |
| 226 | + constructor(): void; |
| 227 | + locals: { [name: string]: mixed }; |
| 228 | + mountpath: string; |
| 229 | + listen( |
| 230 | + port: number, |
| 231 | + hostname?: string, |
| 232 | + backlog?: number, |
| 233 | + callback?: (err?: ?Error) => mixed |
| 234 | + ): ?Server; |
| 235 | + listen( |
| 236 | + port: number, |
| 237 | + hostname?: string, |
| 238 | + callback?: (err?: ?Error) => mixed |
| 239 | + ): ?Server; |
| 240 | + listen(port: number, callback?: (err?: ?Error) => mixed): ?Server; |
| 241 | + listen(path: string, callback?: (err?: ?Error) => mixed): ?Server; |
| 242 | + listen(handle: Object, callback?: (err?: ?Error) => mixed): ?Server; |
| 243 | + disable(name: string): void; |
| 244 | + disabled(name: string): boolean; |
| 245 | + enable(name: string): express$Application; |
| 246 | + enabled(name: string): boolean; |
| 247 | + engine(name: string, callback: Function): void; |
| 248 | + /** |
| 249 | + * Mixed will not be taken as a value option. Issue around using the GET http method name and the get for settings. |
| 250 | + */ |
| 251 | + // get(name: string): mixed; |
| 252 | + set(name: string, value: mixed): mixed; |
| 253 | + render( |
| 254 | + name: string, |
| 255 | + optionsOrFunction: { [name: string]: mixed }, |
| 256 | + callback: express$RenderCallback |
| 257 | + ): void; |
| 258 | + handle( |
| 259 | + req: http$IncomingMessage, |
| 260 | + res: http$ServerResponse, |
| 261 | + next?: ?express$NextFunction |
| 262 | + ): void; |
| 263 | +} |
| 264 | + |
| 265 | +declare type JsonOptions = { |
| 266 | + inflate?: boolean, |
| 267 | + limit?: string | number, |
| 268 | + reviver?: (key: string, value: mixed) => mixed, |
| 269 | + strict?: boolean, |
| 270 | + type?: string | Array<string> | ((req: express$Request) => boolean), |
| 271 | + verify?: ( |
| 272 | + req: express$Request, |
| 273 | + res: express$Response, |
| 274 | + buf: Buffer, |
| 275 | + encoding: string |
| 276 | + ) => mixed |
| 277 | +}; |
| 278 | + |
| 279 | +declare type express$UrlEncodedOptions = { |
| 280 | + extended?: boolean, |
| 281 | + inflate?: boolean, |
| 282 | + limit?: string | number, |
| 283 | + parameterLimit?: number, |
| 284 | + type?: string | Array<string> | ((req: express$Request) => boolean), |
| 285 | + verify?: ( |
| 286 | + req: express$Request, |
| 287 | + res: express$Response, |
| 288 | + buf: Buffer, |
| 289 | + encoding: string |
| 290 | + ) => mixed, |
| 291 | +} |
| 292 | + |
| 293 | +declare module "express" { |
| 294 | + declare export type RouterOptions = express$RouterOptions; |
| 295 | + declare export type CookieOptions = express$CookieOptions; |
| 296 | + declare export type Middleware = express$Middleware; |
| 297 | + declare export type NextFunction = express$NextFunction; |
| 298 | + declare export type RequestParams = express$RequestParams; |
| 299 | + declare export type $Response = express$Response; |
| 300 | + declare export type $Request = express$Request; |
| 301 | + declare export type $Application = express$Application; |
| 302 | + declare export type LagoonErrorWithStatus = express$LagoonErrorWithStatus; |
| 303 | + |
| 304 | + declare module.exports: { |
| 305 | + (): express$Application, // If you try to call like a function, it will use this signature |
| 306 | + json: (opts: ?JsonOptions) => express$Middleware, |
| 307 | + static: (root: string, options?: Object) => express$Middleware, // `static` property on the function |
| 308 | + Router: typeof express$Router, // `Router` property on the function |
| 309 | + urlencoded: (opts: ?express$UrlEncodedOptions) => express$Middleware, |
| 310 | + }; |
| 311 | +} |
0 commit comments