Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Upgrade flow to 0.93.0 (#358)
Browse files Browse the repository at this point in the history
* Upgrade flow

* don't lint flow-typed folder
  • Loading branch information
lhorie authored Feb 14, 2019
1 parent a907591 commit 7094e23
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 136 deletions.
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
flow-typed/
node_modules/
dist/
dist-tests/
coverage/
.nyc_output/

.DS_Store
npm-debug.log
yarn-error.log
240 changes: 110 additions & 130 deletions flow-typed/npm/koa_v2.x.x.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @flow
// flow-typed signature: 1a33220ead1c6b6e3205a55b2a2ec3a0
// flow-typed version: 18b7d8b101/koa_v2.x.x/flow_>=v0.47.x
// flow-typed signature: 225656ba2479b8c1dd8b10776913e73f
// flow-typed version: b7d0245d00/koa_v2.x.x/flow_>=v0.47.x

/*
* Type def from from source code of koa.
Expand All @@ -10,28 +9,23 @@
* Changelog
* breaking: remove unused app.name
* breaking: ctx.throw([status], [msg], [properties]) (caused by http-errors (#957) )
**/
**/
declare module 'koa' {
// Currently, import type doesnt work well ?
// Currently, import type doesn't work well ?
// so copy `Server` from flow/lib/node.js#L820
declare class Server extends net$Server {
listen(
port?: number,
hostname?: string,
backlog?: number,
callback?: Function
): Server;
listen(path: string, callback?: Function): Server;
listen(handle: Object, callback?: Function): Server;
close(callback?: Function): Server;
maxHeadersCount: number;
setTimeout(msecs: number, callback: Function): Server;
timeout: number;
listen(port?: number, hostname?: string, backlog?: number, callback?: Function): Server,
listen(path: string, callback?: Function): Server,
listen(handle: Object, callback?: Function): Server,
close(callback?: Function): Server,
maxHeadersCount: number,
setTimeout(msecs: number, callback: Function): Server,
timeout: number,
}
declare type ServerType = Server;

declare type JSON = string | number | boolean | null | JSONObject | JSONArray;
declare type JSONObject = {[key: string]: JSON};
declare type JSON = | string | number | boolean | null | JSONObject | JSONArray;
declare type JSONObject = { [key: string]: JSON };
declare type JSONArray = Array<JSON>;

declare type SimpleHeader = {
Expand All @@ -40,14 +34,14 @@ declare module 'koa' {
};

declare type RequestJSON = {
method: string,
url: string,
header: SimpleHeader,
'method': string,
'url': string,
'header': SimpleHeader,
};
declare type RequestInspect = void | RequestJSON;
declare type RequestInspect = void|RequestJSON;
declare type Request = {
app: Application,
req: http$IncomingMessage,
req: http$IncomingMessage<net$Socket>,
res: http$ServerResponse,
ctx: Context,
response: Response,
Expand Down Expand Up @@ -76,55 +70,55 @@ declare module 'koa' {
type: string,
url: string,

charset: string | void,
length: number | void,
charset: string|void,
length: number|void,

// Those functions comes from https://github.com/jshttp/accepts/blob/master/index.js
// request.js$L445
// https://github.com/jshttp/accepts/blob/master/test/type.js
accepts: ((args: string[]) => string | false) &
// ToDo: There is an issue https://github.com/facebook/flow/issues/3009
// if you meet some error here, temporarily add an additional annotation
// like: `request.accepts((['json', 'text']:Array<string>))` to fix it.
((arg: string, ...args: string[]) => string | false) &
(() => string[]), // return the old value.
// Those functions comes from https://github.com/jshttp/accepts/blob/master/index.js
// request.js$L445
// https://github.com/jshttp/accepts/blob/master/test/type.js
accepts: ((args: string[]) => string|false)&
// ToDo: There is an issue https://github.com/facebook/flow/issues/3009
// if you meet some error here, temporarily add an additional annotation
// like: `request.accepts((['json', 'text']:Array<string>))` to fix it.
((arg: string, ...args: string[]) => string|false) &
( () => string[] ) , // return the old value.

// https://github.com/jshttp/accepts/blob/master/index.js#L153
// https://github.com/jshttp/accepts/blob/master/test/charset.js
acceptsCharsets: ((args: string[]) => buffer$Encoding | false) &
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
((arg: string, ...args: string[]) => buffer$Encoding | false) &
(() => string[]),
// https://github.com/jshttp/accepts/blob/master/index.js#L153
// https://github.com/jshttp/accepts/blob/master/test/charset.js
acceptsCharsets: ( (args: string[]) => buffer$Encoding|false)&
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
( (arg: string, ...args: string[]) => buffer$Encoding|false ) &
( () => string[] ),

// https://github.com/jshttp/accepts/blob/master/index.js#L119
// https://github.com/jshttp/accepts/blob/master/test/encoding.js
acceptsEncodings: ((args: string[]) => string | false) &
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
((arg: string, ...args: string[]) => string | false) &
(() => string[]),
// https://github.com/jshttp/accepts/blob/master/index.js#L119
// https://github.com/jshttp/accepts/blob/master/test/encoding.js
acceptsEncodings: ( (args: string[]) => string|false)&
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
( (arg: string, ...args: string[]) => string|false ) &
( () => string[] ),

// https://github.com/jshttp/accepts/blob/master/index.js#L185
// https://github.com/jshttp/accepts/blob/master/test/language.js
acceptsLanguages: ((args: string[]) => string | false) &
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
((arg: string, ...args: string[]) => string | false) &
(() => string[]),
// https://github.com/jshttp/accepts/blob/master/index.js#L185
// https://github.com/jshttp/accepts/blob/master/test/language.js
acceptsLanguages: ( (args: string[]) => string|false) &
// ToDo: https://github.com/facebook/flow/issues/3009
// if you meet some error here, see L70.
( (arg: string, ...args: string[]) => string|false ) &
( () => string[] ),

get: (field: string) => string,

/* https://github.com/jshttp/type-is/blob/master/test/test.js
* Check if the incoming request contains the "Content-Type"
* header field, and it contains any of the give mime `type`s.
* If there is no request body, `null` is returned.
* If there is no content type, `false` is returned.
* Otherwise, it returns the first `type` that matches.
*/
is: ((args: string[]) => null | false | string) &
((arg: string, ...args: string[]) => null | false | string) &
(() => string), // should return the mime type
/* https://github.com/jshttp/type-is/blob/master/test/test.js
* Check if the incoming request contains the "Content-Type"
* header field, and it contains any of the give mime `type`s.
* If there is no request body, `null` is returned.
* If there is no content type, `false` is returned.
* Otherwise, it returns the first `type` that matches.
*/
is: ( (args: string[]) => null|false|string)&
( (arg: string, ...args: string[]) => null|false|string ) &
( () => string ), // should return the mime type

toJSON: () => RequestJSON,
inspect: () => RequestInspect,
Expand All @@ -133,25 +127,25 @@ declare module 'koa' {
};

declare type ResponseJSON = {
status: mixed,
message: mixed,
header: mixed,
'status': mixed,
'message': mixed,
'header': mixed,
};
declare type ResponseInspect = {
status: mixed,
message: mixed,
header: mixed,
body: mixed,
'status': mixed,
'message': mixed,
'header': mixed,
'body': mixed,
};
declare type Response = {
app: Application,
req: http$IncomingMessage,
req: http$IncomingMessage<net$Socket>,
res: http$ServerResponse,
ctx: Context,
request: Request,

// docs/api/response.md#L113.
body: string | Buffer | stream$Stream | Object | Array<mixed> | null, // JSON contains null
body: string|Buffer|stream$Stream|Object|Array<mixed>|null, // JSON contains null
etag: string,
header: SimpleHeader,
headers: SimpleHeader, // alias as header
Expand All @@ -166,20 +160,20 @@ declare module 'koa' {
writable: boolean,

// charset: string, // doesn't find in response.js
length: number | void,
length: number|void,

append: (field: string, val: string | string[]) => void,
attachment: (filename?: string) => void,
get: (field: string) => string,
// https://github.com/jshttp/type-is/blob/master/test/test.js
// https://github.com/koajs/koa/blob/v2.x/lib/response.js#L382
is: ((arg: string[]) => false | string) &
((arg: string, ...args: string[]) => false | string) &
(() => string), // should return the mime type
is: ( (arg: string[]) => false|string) &
( (arg: string, ...args: string[]) => false|string ) &
( () => string ), // should return the mime type
redirect: (url: string, alt?: string) => void,
remove: (field: string) => void,
// https://github.com/koajs/koa/blob/v2.x/lib/response.js#L418
set: ((field: string, val: string | string[]) => void) &
set: ((field: string, val: string | string[]) => void)&
((field: {[key: string]: string | string[]}) => void),

vary: (field: string) => void,
Expand All @@ -189,7 +183,7 @@ declare module 'koa' {
inspect(): ResponseInspect,

[key: string]: mixed, // props added by middlewares.
};
}

declare type ContextJSON = {
request: RequestJSON,
Expand All @@ -202,25 +196,21 @@ declare module 'koa' {
};
// https://github.com/pillarjs/cookies
declare type CookiesSetOptions = {
maxAge: number, // milliseconds from Date.now() for expiry
expires: Date, //cookie's expiration date (expires at the end of session by default).
path: string, // the path of the cookie (/ by default).
domain: string, // domain of the cookie (no default).
secure: boolean, // false by default for HTTP, true by default for HTTPS
httpOnly: boolean, // a boolean indicating whether the cookie is only to be sent over HTTP(S),
maxAge: number, // milliseconds from Date.now() for expiry
expires?: Date, //cookie's expiration date (expires at the end of session by default).
path?: string, // the path of the cookie (/ by default).
secure?: boolean, // false by default for HTTP, true by default for HTTPS
httpOnly?: boolean, // a boolean indicating whether the cookie is only to be sent over HTTP(S),
// and not made available to client JavaScript (true by default).
signed: boolean, // whether the cookie is to be signed (false by default)
overwrite: boolean, // whether to overwrite previously set cookies of the same name (false by default).
signed?: boolean, // whether the cookie is to be signed (false by default)
overwrite?: boolean, // whether to overwrite previously set cookies of the same name (false by default).
};
declare type Cookies = {
get: (name: string, options?: {signed: boolean}) => string | void,
set: ((
name: string,
value: string,
options?: CookiesSetOptions
) => Context) &
// delete cookie (an outbound header with an expired date is used.)
((name: string) => Context),
get: (name: string, options?: {signed: boolean}) => string|void,
set: ((name: string, value: string, options?: CookiesSetOptions) => Context)&
// delete cookie (an outbound header with an expired date is used.)
( (name: string) => Context),
};
// The default props of context come from two files
// `application.createContext` & `context.js`
Expand All @@ -230,25 +220,20 @@ declare module 'koa' {
cookies: Cookies,
name?: string, // ?
originalUrl: string,
req: http$IncomingMessage,
req: http$IncomingMessage<net$Socket>,
request: Request,
res: http$ServerResponse,
respond?: boolean, // should not be used, allow bypassing koa application.js#L193
response: Response,
state: Object,

// context.js#L55
assert: (
test: mixed,
status: number,
message?: string,
opts?: mixed
) => void,
assert: (test: mixed, status: number, message?: string, opts?: mixed) => void,
// context.js#L107
// if (!(err instanceof Error)) err = new Error(`non-error thrown: ${err}`);
onerror: (err?: mixed) => void,
// context.md#L88
throw: (status: number, msg?: string, opts?: Object) => void,
throw: ( status: number, msg?: string, opts?: Object) => void,
toJSON(): ContextJSON,
inspect(): ContextJSON,

Expand Down Expand Up @@ -302,38 +287,33 @@ declare module 'koa' {
ip: $PropertyType<Request, 'ip'>,

[key: string]: any, // props added by middlewares.
};
}

declare type Middleware = (
ctx: Context,
next: () => Promise<void>
) => Promise<void> | void;
declare type Middleware =
(ctx: Context, next: () => Promise<void>) => Promise<void>|void;
declare type ApplicationJSON = {
subdomainOffset: mixed,
proxy: mixed,
env: string,
'subdomainOffset': mixed,
'proxy': mixed,
'env': string,
};
declare class Application extends events$EventEmitter {
context: Context;
context: Context,
// request handler for node's native http server.
callback: () => (
req: http$IncomingMessage,
res: http$ServerResponse
) => void;
env: string;
keys?: Array<string> | Object; // https://github.com/crypto-utils/keygrip
middleware: Array<Middleware>;
proxy: boolean; // when true proxy header fields will be trusted
request: Request;
response: Response;
server: Server;
subdomainOffset: number;
callback: () => (req: http$IncomingMessage<net$Socket>, res: http$ServerResponse) => void,
env: string,
keys?: Array<string>|Object, // https://github.com/crypto-utils/keygrip
middleware: Array<Middleware>,
proxy: boolean, // when true proxy header fields will be trusted
request: Request,
response: Response,
server: Server,
subdomainOffset: number,

listen: $PropertyType<Server, 'listen'>;
toJSON(): ApplicationJSON;
inspect(): ApplicationJSON;
use(fn: Middleware): this;
listen: $PropertyType<Server, 'listen'>,
toJSON(): ApplicationJSON,
inspect(): ApplicationJSON,
use(fn: Middleware): this,
}
// eslint-disable-next-line

declare module.exports: Class<Application>;
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"clean": "rm -rf dist",
"lint": "eslint . --ignore-path .gitignore",
"lint": "eslint src",
"transpile": "npm run clean && cup build",
"build-test": "rm -rf dist-tests && cup build-tests",
"just-test": "unitest --browser=dist-tests/browser.js --node=dist-tests/node.js",
Expand Down Expand Up @@ -54,7 +54,7 @@
"eslint-plugin-jest": "^22.1.2",
"eslint-plugin-prettier": "^3.0.0",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "^0.92.0",
"flow-bin": "^0.93.0",
"node-fetch": "^2.3.0",
"nyc": "^13.1.0",
"prettier": "^1.15.3",
Expand Down
Loading

0 comments on commit 7094e23

Please sign in to comment.