mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-23 17:58:06 +00:00
flow: update libdefs for express
, removing hacks (#1879)
Summary: This removes a SourceCred-specific hack because the upstream issue has been fixed. Removing the hack is important because it uses a suppression comment and thus hampers upgrading to latest Flow. The libdef portion of this change was generated by removing the old file and then running `flow-typed install express@4.17.1`. Test Plan: That `yarn flow` passes suffices. wchargin-branch: libdefs-express
This commit is contained in:
parent
e744b2bd4a
commit
deb257ff6a
@ -3,6 +3,7 @@ const express = require("express");
|
||||
/*::
|
||||
import type {
|
||||
$Application as ExpressApp,
|
||||
$Request as ExpressRequest,
|
||||
$Response as ExpressResponse,
|
||||
} from "express";
|
||||
*/
|
||||
@ -39,7 +40,7 @@ async function makeConfig(
|
||||
},
|
||||
devServer: {
|
||||
inline: false,
|
||||
before: (app /*: ExpressApp */) => {
|
||||
before: (app /*: ExpressApp<ExpressRequest, ExpressResponse> */) => {
|
||||
let developmentInstancePath /*: ?string */ =
|
||||
process.env["SOURCECRED_DEV_INSTANCE"];
|
||||
const argv = process.argv;
|
||||
|
@ -1,5 +1,5 @@
|
||||
// flow-typed signature: 4d07de2fe5c108c382d1873ff51b03b7
|
||||
// flow-typed version: c6154227d1/express_v4.16.x/flow_>=v0.104.x
|
||||
// flow-typed signature: 7e46c8fddb9d601f9b5b405919c74216
|
||||
// flow-typed version: 72a1136f77/express_v4.17.x/flow_>=v0.104.x
|
||||
|
||||
declare type express$RouterOptions = {
|
||||
caseSensitive?: boolean,
|
||||
@ -9,12 +9,39 @@ declare type express$RouterOptions = {
|
||||
};
|
||||
|
||||
declare class express$RequestResponseBase {
|
||||
app: express$Application;
|
||||
app: express$Application<any, any>;
|
||||
get(field: string): string | void;
|
||||
}
|
||||
|
||||
declare type express$RequestParams = { [param: string]: string, ... };
|
||||
|
||||
/*
|
||||
NOTE: Use caution when extending `express$Request` or `express$Response`. When
|
||||
a request first hits the server, its `req` and `res` will not have any
|
||||
additional properties, even if you explicitly type them with your custom
|
||||
subclass. Subsequent middleware may assign these properties, but you must be
|
||||
cognizant of this ordering. One way to handle this is marking all properties
|
||||
as optional to force refinement every time a property is accessed. Therefore,
|
||||
we advise that you always mark properties as _optional_ in `express$Request`
|
||||
and `express$Response` subclasses.
|
||||
|
||||
You may decide not to do this, in which case the typings will be unsound and
|
||||
the behavior will be similar to how arrays work in Flow. See here for more
|
||||
information: https://flow.org/en/docs/types/arrays/#toc-array-access-is-unsafe
|
||||
|
||||
See #3578 and #3337 for additional discussion. If you have ideas on how to
|
||||
improve these typings, please share them in #3578 or open a new issue.
|
||||
|
||||
**BAD**
|
||||
declare class test_express$CustomRequest extends express$Request {
|
||||
foo: string;
|
||||
}
|
||||
|
||||
**GOOD**
|
||||
declare class test_express$CustomRequest extends express$Request {
|
||||
foo: string | void;
|
||||
}
|
||||
*/
|
||||
declare class express$Request extends http$IncomingMessage mixins express$RequestResponseBase {
|
||||
baseUrl: string;
|
||||
body: mixed;
|
||||
@ -116,75 +143,77 @@ declare class express$Response extends http$ServerResponse mixins express$Reques
|
||||
}
|
||||
|
||||
declare type express$NextFunction = (err?: ?Error | "route") => mixed;
|
||||
declare type express$Middleware =
|
||||
| ((
|
||||
// SourceCred-specific hack, pending real fix here:
|
||||
// <https://github.com/flow-typed/flow-typed/pull/3337>
|
||||
// $ExpectFlowError
|
||||
req: $Subtype<express$Request>,
|
||||
res: express$Response,
|
||||
next: express$NextFunction
|
||||
) => mixed)
|
||||
| ((
|
||||
error: Error,
|
||||
// SourceCred-specific hack, pending real fix here:
|
||||
// <https://github.com/flow-typed/flow-typed/pull/3337>
|
||||
// $ExpectFlowError
|
||||
req: $Subtype<express$Request>,
|
||||
res: express$Response,
|
||||
next: express$NextFunction
|
||||
) => mixed);
|
||||
declare interface express$RouteMethodType<T> {
|
||||
(middleware: express$Middleware): T;
|
||||
(...middleware: Array<express$Middleware>): T;
|
||||
declare type express$Middleware<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> =
|
||||
((req: Req, res: Res, next: express$NextFunction) => mixed) |
|
||||
((error: Error, req: Req, res: Res, next: express$NextFunction) => mixed);
|
||||
|
||||
declare interface express$RouteMethodType<
|
||||
T,
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> {
|
||||
(middleware: express$Middleware<Req, Res>): T;
|
||||
(...middleware: Array<express$Middleware<Req, Res>>): T;
|
||||
(
|
||||
path: express$Path | express$Path[],
|
||||
...middleware: Array<express$Middleware>
|
||||
path: express$Path | $ReadOnlyArray<express$Path>,
|
||||
...middleware: Array<express$Middleware<Req, Res>>
|
||||
): T;
|
||||
}
|
||||
declare class express$Route {
|
||||
all: express$RouteMethodType<this>;
|
||||
get: express$RouteMethodType<this>;
|
||||
post: express$RouteMethodType<this>;
|
||||
put: express$RouteMethodType<this>;
|
||||
head: express$RouteMethodType<this>;
|
||||
delete: express$RouteMethodType<this>;
|
||||
options: express$RouteMethodType<this>;
|
||||
trace: express$RouteMethodType<this>;
|
||||
copy: express$RouteMethodType<this>;
|
||||
lock: express$RouteMethodType<this>;
|
||||
mkcol: express$RouteMethodType<this>;
|
||||
move: express$RouteMethodType<this>;
|
||||
purge: express$RouteMethodType<this>;
|
||||
propfind: express$RouteMethodType<this>;
|
||||
proppatch: express$RouteMethodType<this>;
|
||||
unlock: express$RouteMethodType<this>;
|
||||
report: express$RouteMethodType<this>;
|
||||
mkactivity: express$RouteMethodType<this>;
|
||||
checkout: express$RouteMethodType<this>;
|
||||
merge: express$RouteMethodType<this>;
|
||||
|
||||
declare class express$Route<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> {
|
||||
all: express$RouteMethodType<this, Req, Res>;
|
||||
get: express$RouteMethodType<this, Req, Res>;
|
||||
post: express$RouteMethodType<this, Req, Res>;
|
||||
put: express$RouteMethodType<this, Req, Res>;
|
||||
head: express$RouteMethodType<this, Req, Res>;
|
||||
delete: express$RouteMethodType<this, Req, Res>;
|
||||
options: express$RouteMethodType<this, Req, Res>;
|
||||
trace: express$RouteMethodType<this, Req, Res>;
|
||||
copy: express$RouteMethodType<this, Req, Res>;
|
||||
lock: express$RouteMethodType<this, Req, Res>;
|
||||
mkcol: express$RouteMethodType<this, Req, Res>;
|
||||
move: express$RouteMethodType<this, Req, Res>;
|
||||
purge: express$RouteMethodType<this, Req, Res>;
|
||||
propfind: express$RouteMethodType<this, Req, Res>;
|
||||
proppatch: express$RouteMethodType<this, Req, Res>;
|
||||
unlock: express$RouteMethodType<this, Req, Res>;
|
||||
report: express$RouteMethodType<this, Req, Res>;
|
||||
mkactivity: express$RouteMethodType<this, Req, Res>;
|
||||
checkout: express$RouteMethodType<this, Req, Res>;
|
||||
merge: express$RouteMethodType<this, Req, Res>;
|
||||
|
||||
// @TODO Missing 'm-search' but get flow illegal name error.
|
||||
|
||||
notify: express$RouteMethodType<this>;
|
||||
subscribe: express$RouteMethodType<this>;
|
||||
unsubscribe: express$RouteMethodType<this>;
|
||||
patch: express$RouteMethodType<this>;
|
||||
search: express$RouteMethodType<this>;
|
||||
connect: express$RouteMethodType<this>;
|
||||
notify: express$RouteMethodType<this, Req, Res>;
|
||||
subscribe: express$RouteMethodType<this, Req, Res>;
|
||||
unsubscribe: express$RouteMethodType<this, Req, Res>;
|
||||
patch: express$RouteMethodType<this, Req, Res>;
|
||||
search: express$RouteMethodType<this, Req, Res>;
|
||||
connect: express$RouteMethodType<this, Req, Res>;
|
||||
}
|
||||
|
||||
declare class express$Router extends express$Route {
|
||||
declare type express$RouterUseable<Req: express$Request, Res: express$Response> =
|
||||
| express$Middleware<Req, Res>
|
||||
| express$Router<Req, Res>
|
||||
| $ReadOnlyArray<express$Middleware<Req, Res> | express$Router<Req, Res>>;
|
||||
|
||||
declare class express$Router<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> extends express$Route<Req, Res> {
|
||||
constructor(options?: express$RouterOptions): void;
|
||||
route(path: string): express$Route;
|
||||
static (options?: express$RouterOptions): express$Router;
|
||||
use(middleware: express$Middleware): this;
|
||||
use(...middleware: Array<express$Middleware>): this;
|
||||
use(
|
||||
path: express$Path | express$Path[],
|
||||
...middleware: Array<express$Middleware>
|
||||
): this;
|
||||
use(path: string, router: express$Router): this;
|
||||
route(path: string): express$Route<Req, Res>;
|
||||
static <Req2: express$Request, Res2: express$Response>(
|
||||
options?: express$RouterOptions,
|
||||
): express$Router<Req2, Res2>;
|
||||
use(express$RouterUseable<Req, Res>, ...express$RouterUseable<Req, Res>[]): this;
|
||||
use(express$Path, express$RouterUseable<Req, Res>, ...express$RouterUseable<Req, Res>[]): this;
|
||||
handle(
|
||||
req: http$IncomingMessage<>,
|
||||
res: http$ServerResponse,
|
||||
@ -193,13 +222,11 @@ declare class express$Router extends express$Route {
|
||||
param(
|
||||
param: string,
|
||||
callback: (
|
||||
// SourceCred-specific hack, pending real fix here:
|
||||
// <https://github.com/flow-typed/flow-typed/pull/3337>
|
||||
// $ExpectFlowError
|
||||
req: $Subtype<express$Request>,
|
||||
res: express$Response,
|
||||
req: Req,
|
||||
res: Res,
|
||||
next: express$NextFunction,
|
||||
id: string
|
||||
value: string,
|
||||
paramName: string,
|
||||
) => mixed
|
||||
): void;
|
||||
(
|
||||
@ -217,7 +244,10 @@ To work around this issue, we changed Server to ?Server here, so that our invoca
|
||||
not be deemed to lack type coverage.
|
||||
*/
|
||||
|
||||
declare class express$Application extends express$Router mixins events$EventEmitter {
|
||||
declare class express$Application<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> extends express$Router<Req, Res> mixins events$EventEmitter {
|
||||
constructor(): void;
|
||||
locals: { [name: string]: mixed, ... };
|
||||
mountpath: string;
|
||||
@ -237,7 +267,7 @@ declare class express$Application extends express$Router mixins events$EventEmit
|
||||
listen(handle: Object, callback?: (err?: ?Error) => mixed): ?http$Server;
|
||||
disable(name: string): void;
|
||||
disabled(name: string): boolean;
|
||||
enable(name: string): express$Application;
|
||||
enable(name: string): this;
|
||||
enabled(name: string): boolean;
|
||||
engine(name: string, callback: Function): void;
|
||||
/**
|
||||
@ -296,22 +326,28 @@ declare type express$UrlEncodedOptions = {
|
||||
declare module "express" {
|
||||
declare export type RouterOptions = express$RouterOptions;
|
||||
declare export type CookieOptions = express$CookieOptions;
|
||||
declare export type Middleware = express$Middleware;
|
||||
declare export type Middleware<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> = express$Middleware<Req, Res>;
|
||||
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 export type $Application<
|
||||
Req: express$Request = express$Request,
|
||||
Res: express$Response = express$Response,
|
||||
> = express$Application<Req, Res>;
|
||||
|
||||
declare module.exports: {
|
||||
// If you try to call like a function, it will use this signature
|
||||
(): express$Application,
|
||||
json: (opts: ?JsonOptions) => express$Middleware,
|
||||
<Req: express$Request, Res: express$Response>(): express$Application<Req, Res>,
|
||||
json: (opts: ?JsonOptions) => express$Middleware<>,
|
||||
// `static` property on the function
|
||||
static: (root: string, options?: Object) => express$Middleware,
|
||||
static: <Req: express$Request, Res: express$Response>(root: string, options?: Object) => express$Middleware<Req, Res>,
|
||||
// `Router` property on the function
|
||||
Router: typeof express$Router,
|
||||
urlencoded: (opts: ?express$UrlEncodedOptions) => express$Middleware,
|
||||
urlencoded: (opts: ?express$UrlEncodedOptions) => express$Middleware<>,
|
||||
...
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user