diff --git a/flow-typed/npm/express_v4.16.x.js b/flow-typed/npm/express_v4.16.x.js new file mode 100644 index 0000000..8a9aab0 --- /dev/null +++ b/flow-typed/npm/express_v4.16.x.js @@ -0,0 +1,300 @@ +// flow-typed signature: 106bbf49ff0c0b351c95d483d617ffba +// flow-typed version: 7fe23c8e85/express_v4.16.x/flow_>=v0.32.x + +import type { Server } from "http"; +import type { Socket } from "net"; + +declare type express$RouterOptions = { + caseSensitive?: boolean, + mergeParams?: boolean, + strict?: boolean +}; + +declare class express$RequestResponseBase { + app: express$Application; + get(field: string): string | void; +} + +declare type express$RequestParams = { + [param: string]: string +}; + +declare class express$Request extends http$IncomingMessage mixins express$RequestResponseBase { + baseUrl: string; + body: mixed; + cookies: { [cookie: string]: string }; + connection: Socket; + fresh: boolean; + hostname: string; + ip: string; + ips: Array; + method: string; + originalUrl: string; + params: express$RequestParams; + path: string; + protocol: "https" | "http"; + query: { [name: string]: string | Array }; + route: string; + secure: boolean; + signedCookies: { [signedCookie: string]: string }; + stale: boolean; + subdomains: Array; + xhr: boolean; + accepts(types: string): string | false; + accepts(types: Array): string | false; + acceptsCharsets(...charsets: Array): string | false; + acceptsEncodings(...encoding: Array): string | false; + acceptsLanguages(...lang: Array): string | false; + header(field: string): string | void; + is(type: string): boolean; + param(name: string, defaultValue?: string): string | void; +} + +declare type express$CookieOptions = { + domain?: string, + encode?: (value: string) => string, + expires?: Date, + httpOnly?: boolean, + maxAge?: number, + path?: string, + secure?: boolean, + signed?: boolean +}; + +declare type express$Path = string | RegExp; + +declare type express$RenderCallback = ( + err: Error | null, + html?: string +) => mixed; + +declare type express$SendFileOptions = { + maxAge?: number, + root?: string, + lastModified?: boolean, + headers?: { [name: string]: string }, + dotfiles?: "allow" | "deny" | "ignore" +}; + +declare class express$Response extends http$ServerResponse mixins express$RequestResponseBase { + headersSent: boolean; + locals: { [name: string]: mixed }; + append(field: string, value?: string): this; + attachment(filename?: string): this; + cookie(name: string, value: string, options?: express$CookieOptions): this; + clearCookie(name: string, options?: express$CookieOptions): this; + download( + path: string, + filename?: string, + callback?: (err?: ?Error) => void + ): this; + format(typesObject: { [type: string]: Function }): this; + json(body?: mixed): this; + jsonp(body?: mixed): this; + links(links: { [name: string]: string }): this; + location(path: string): this; + redirect(url: string, ...args: Array): this; + redirect(status: number, url: string, ...args: Array): this; + render( + view: string, + locals?: { [name: string]: mixed }, + callback?: express$RenderCallback + ): this; + send(body?: mixed): this; + sendFile( + path: string, + options?: express$SendFileOptions, + callback?: (err?: ?Error) => mixed + ): this; + sendStatus(statusCode: number): this; + header(field: string, value?: string): this; + header(headers: { [name: string]: string }): this; + set(field: string, value?: string | string[]): this; + set(headers: { [name: string]: string }): this; + status(statusCode: number): this; + type(type: string): this; + vary(field: string): this; + req: express$Request; +} + +declare type express$NextFunction = (err?: ?Error | "route") => mixed; +declare type express$Middleware = + | (( + req: $Subtype, + res: express$Response, + next: express$NextFunction + ) => mixed) + | (( + error: Error, + req: $Subtype, + res: express$Response, + next: express$NextFunction + ) => mixed); +declare interface express$RouteMethodType { + (middleware: express$Middleware): T; + (...middleware: Array): T; + ( + path: express$Path | express$Path[], + ...middleware: Array + ): T; +} +declare class express$Route { + all: express$RouteMethodType; + get: express$RouteMethodType; + post: express$RouteMethodType; + put: express$RouteMethodType; + head: express$RouteMethodType; + delete: express$RouteMethodType; + options: express$RouteMethodType; + trace: express$RouteMethodType; + copy: express$RouteMethodType; + lock: express$RouteMethodType; + mkcol: express$RouteMethodType; + move: express$RouteMethodType; + purge: express$RouteMethodType; + propfind: express$RouteMethodType; + proppatch: express$RouteMethodType; + unlock: express$RouteMethodType; + report: express$RouteMethodType; + mkactivity: express$RouteMethodType; + checkout: express$RouteMethodType; + merge: express$RouteMethodType; + + // @TODO Missing 'm-search' but get flow illegal name error. + + notify: express$RouteMethodType; + subscribe: express$RouteMethodType; + unsubscribe: express$RouteMethodType; + patch: express$RouteMethodType; + search: express$RouteMethodType; + connect: express$RouteMethodType; +} + +declare class express$Router extends express$Route { + constructor(options?: express$RouterOptions): void; + route(path: string): express$Route; + static (options?: express$RouterOptions): express$Router; + use(middleware: express$Middleware): this; + use(...middleware: Array): this; + use( + path: express$Path | express$Path[], + ...middleware: Array + ): this; + use(path: string, router: express$Router): this; + handle( + req: http$IncomingMessage, + res: http$ServerResponse, + next: express$NextFunction + ): void; + param( + param: string, + callback: ( + req: $Subtype, + res: express$Response, + next: express$NextFunction, + id: string + ) => mixed + ): void; + + // Can't use regular callable signature syntax due to https://github.com/facebook/flow/issues/3084 + $call: ( + req: http$IncomingMessage, + res: http$ServerResponse, + next?: ?express$NextFunction + ) => void; +} + +/* +With flow-bin ^0.59, express app.listen() is deemed to return any and fails flow type coverage. +Which is ironic because https://github.com/facebook/flow/blob/master/Changelog.md#misc-2 (release notes for 0.59) +says "Improves typings for Node.js HTTP server listen() function." See that? IMPROVES! +To work around this issue, we changed Server to ?Server here, so that our invocations of express.listen() will +not be deemed to lack type coverage. +*/ + +declare class express$Application extends express$Router mixins events$EventEmitter { + constructor(): void; + locals: { [name: string]: mixed }; + mountpath: string; + listen( + port: number, + hostname?: string, + backlog?: number, + callback?: (err?: ?Error) => mixed + ): ?Server; + listen( + port: number, + hostname?: string, + callback?: (err?: ?Error) => mixed + ): ?Server; + listen(port: number, callback?: (err?: ?Error) => mixed): ?Server; + listen(path: string, callback?: (err?: ?Error) => mixed): ?Server; + listen(handle: Object, callback?: (err?: ?Error) => mixed): ?Server; + disable(name: string): void; + disabled(name: string): boolean; + enable(name: string): express$Application; + enabled(name: string): boolean; + engine(name: string, callback: Function): void; + /** + * Mixed will not be taken as a value option. Issue around using the GET http method name and the get for settings. + */ + // get(name: string): mixed; + set(name: string, value: mixed): mixed; + render( + name: string, + optionsOrFunction: { [name: string]: mixed }, + callback: express$RenderCallback + ): void; + handle( + req: http$IncomingMessage, + res: http$ServerResponse, + next?: ?express$NextFunction + ): void; +} + +declare type JsonOptions = { + inflate?: boolean, + limit?: string | number, + reviver?: (key: string, value: mixed) => mixed, + strict?: boolean, + type?: string | Array | ((req: express$Request) => boolean), + verify?: ( + req: express$Request, + res: express$Response, + buf: Buffer, + encoding: string + ) => mixed +}; + +declare type express$UrlEncodedOptions = { + extended?: boolean, + inflate?: boolean, + limit?: string | number, + parameterLimit?: number, + type?: string | Array | ((req: express$Request) => boolean), + verify?: ( + req: express$Request, + res: express$Response, + buf: Buffer, + encoding: string + ) => mixed, +} + +declare module "express" { + declare export type RouterOptions = express$RouterOptions; + declare export type CookieOptions = express$CookieOptions; + declare export type Middleware = express$Middleware; + declare export type NextFunction = express$NextFunction; + declare export type RequestParams = express$RequestParams; + declare export type $Response = express$Response; + declare export type $Request = express$Request; + declare export type $Application = express$Application; + + declare module.exports: { + (): express$Application, // If you try to call like a function, it will use this signature + json: (opts: ?JsonOptions) => express$Middleware, + static: (root: string, options?: Object) => express$Middleware, // `static` property on the function + Router: typeof express$Router, // `Router` property on the function + urlencoded: (opts: ?express$UrlEncodedOptions) => express$Middleware, + }; +} diff --git a/package.json b/package.json index ab1ab6d..cbef899 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "eslint-plugin-import": "2.8.0", "eslint-plugin-jsx-a11y": "5.1.1", "eslint-plugin-react": "7.4.0", + "express": "^4.16.3", "extract-text-webpack-plugin": "3.0.2", "file-loader": "1.1.5", "flow-bin": "^0.65.0", diff --git a/yarn.lock b/yarn.lock index 01b6fcb..516f881 100644 --- a/yarn.lock +++ b/yarn.lock @@ -69,6 +69,13 @@ accepts@~1.3.4: mime-types "~2.1.16" negotiator "0.6.1" +accepts@~1.3.5: + version "1.3.5" + resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.5.tgz#eb777df6011723a3b14e8a72c0805c8e86746bd2" + dependencies: + mime-types "~2.1.18" + negotiator "0.6.1" + acorn-dynamic-import@^2.0.0: version "2.0.2" resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-2.0.2.tgz#c752bd210bef679501b6c6cb7fc84f8f47158cc4" @@ -1977,7 +1984,7 @@ depd@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.1.tgz#5783b4e1c459f06fa5ca27f991f3d06e7a310359" -depd@~1.1.1: +depd@~1.1.1, depd@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/depd/-/depd-1.1.2.tgz#9bcd52e14c097763e749b274c4346ed2e560b5a9" @@ -2182,7 +2189,7 @@ emojis-list@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" -encodeurl@~1.0.1: +encodeurl@~1.0.1, encodeurl@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/encodeurl/-/encodeurl-1.0.2.tgz#ad3ff4c86ec2d029322f5a02c3a9a606c95b3f59" @@ -2644,6 +2651,41 @@ express@^4.13.3: utils-merge "1.0.1" vary "~1.1.2" +express@^4.16.3: + version "4.16.3" + resolved "https://registry.yarnpkg.com/express/-/express-4.16.3.tgz#6af8a502350db3246ecc4becf6b5a34d22f7ed53" + dependencies: + accepts "~1.3.5" + array-flatten "1.1.1" + body-parser "1.18.2" + content-disposition "0.5.2" + content-type "~1.0.4" + cookie "0.3.1" + cookie-signature "1.0.6" + debug "2.6.9" + depd "~1.1.2" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + finalhandler "1.1.1" + fresh "0.5.2" + merge-descriptors "1.0.1" + methods "~1.1.2" + on-finished "~2.3.0" + parseurl "~1.3.2" + path-to-regexp "0.1.7" + proxy-addr "~2.0.3" + qs "6.5.1" + range-parser "~1.2.0" + safe-buffer "5.1.1" + send "0.16.2" + serve-static "1.13.2" + setprototypeof "1.1.0" + statuses "~1.4.0" + type-is "~1.6.16" + utils-merge "1.0.1" + vary "~1.1.2" + extend@~3.0.0, extend@~3.0.1: version "3.0.1" resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444" @@ -2795,6 +2837,18 @@ finalhandler@1.1.0: statuses "~1.3.1" unpipe "~1.0.0" +finalhandler@1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.1.1.tgz#eebf4ed840079c83f4249038c9d703008301b105" + dependencies: + debug "2.6.9" + encodeurl "~1.0.2" + escape-html "~1.0.3" + on-finished "~2.3.0" + parseurl "~1.3.2" + statuses "~1.4.0" + unpipe "~1.0.0" + find-cache-dir@^0.1.1: version "0.1.1" resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-0.1.1.tgz#c8defae57c8a52a8a784f9e31c57c742e993a0b9" @@ -3498,6 +3552,10 @@ ipaddr.js@1.5.2: version "1.5.2" resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.5.2.tgz#d4b505bde9946987ccf0fc58d9010ff9607e3fa0" +ipaddr.js@1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.6.0.tgz#e3fa357b773da619f26e95f049d055c72796f86b" + is-absolute-url@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/is-absolute-url/-/is-absolute-url-2.1.0.tgz#50530dfb84fcc9aa7dbe7852e83a37b93b9f2aa6" @@ -4578,12 +4636,22 @@ mime-db@~1.30.0: version "1.30.0" resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01" +mime-db@~1.33.0: + version "1.33.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.33.0.tgz#a3492050a5cb9b63450541e39d9788d2272783db" + mime-types@^2.1.12, mime-types@~2.1.15, mime-types@~2.1.16, mime-types@~2.1.17, mime-types@~2.1.7: version "2.1.17" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.17.tgz#09d7a393f03e995a79f8af857b70a9e0ab16557a" dependencies: mime-db "~1.30.0" +mime-types@~2.1.18: + version "2.1.18" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.18.tgz#6f323f60a83d11146f831ff11fd66e2fe5503bb8" + dependencies: + mime-db "~1.33.0" + mime@1.4.1: version "1.4.1" resolved "https://registry.yarnpkg.com/mime/-/mime-1.4.1.tgz#121f9ebc49e3766f311a76e1fa1c8003c4b03aa6" @@ -5582,6 +5650,13 @@ proxy-addr@~2.0.2: forwarded "~0.1.2" ipaddr.js "1.5.2" +proxy-addr@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-2.0.3.tgz#355f262505a621646b3130a728eb647e22055341" + dependencies: + forwarded "~0.1.2" + ipaddr.js "1.6.0" + prr@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/prr/-/prr-1.0.1.tgz#d3fc114ba06995a45ec6893f484ceb1d78f5f476" @@ -6186,6 +6261,24 @@ send@0.16.1: range-parser "~1.2.0" statuses "~1.3.1" +send@0.16.2: + version "0.16.2" + resolved "https://registry.yarnpkg.com/send/-/send-0.16.2.tgz#6ecca1e0f8c156d141597559848df64730a6bbc1" + dependencies: + debug "2.6.9" + depd "~1.1.2" + destroy "~1.0.4" + encodeurl "~1.0.2" + escape-html "~1.0.3" + etag "~1.8.1" + fresh "0.5.2" + http-errors "~1.6.2" + mime "1.4.1" + ms "2.0.0" + on-finished "~2.3.0" + range-parser "~1.2.0" + statuses "~1.4.0" + serve-index@^1.7.2: version "1.9.1" resolved "https://registry.yarnpkg.com/serve-index/-/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239" @@ -6207,6 +6300,15 @@ serve-static@1.13.1: parseurl "~1.3.2" send "0.16.1" +serve-static@1.13.2: + version "1.13.2" + resolved "https://registry.yarnpkg.com/serve-static/-/serve-static-1.13.2.tgz#095e8472fd5b46237db50ce486a43f4b86c6cec1" + dependencies: + encodeurl "~1.0.2" + escape-html "~1.0.3" + parseurl "~1.3.2" + send "0.16.2" + serviceworker-cache-polyfill@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/serviceworker-cache-polyfill/-/serviceworker-cache-polyfill-4.0.0.tgz#de19ee73bef21ab3c0740a37b33db62464babdeb" @@ -6398,7 +6500,7 @@ staged-git-files@1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/staged-git-files/-/staged-git-files-1.0.0.tgz#cdb847837c1fcc52c08a872d4883cc0877668a80" -"statuses@>= 1.3.1 < 2": +"statuses@>= 1.3.1 < 2", statuses@~1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/statuses/-/statuses-1.4.0.tgz#bb73d446da2796106efcc1b601a253d6c46bd087" @@ -6758,6 +6860,13 @@ type-is@~1.6.15: media-typer "0.3.0" mime-types "~2.1.15" +type-is@~1.6.16: + version "1.6.16" + resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.16.tgz#f89ce341541c672b25ee7ae3c73dee3b2be50194" + dependencies: + media-typer "0.3.0" + mime-types "~2.1.18" + typedarray@^0.0.6: version "0.0.6" resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"