From ac21e1c86dbdee7582aa38bf8d6aa53879cf276c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 16:25:12 +0100 Subject: [PATCH 01/10] body-parser v1.16 --- body-parser/body-parser-tests.ts | 9 ++ body-parser/index.d.ts | 152 ++++++------------------------- body-parser/tslint.json | 3 + 3 files changed, 42 insertions(+), 122 deletions(-) create mode 100644 body-parser/body-parser-tests.ts create mode 100644 body-parser/tslint.json diff --git a/body-parser/body-parser-tests.ts b/body-parser/body-parser-tests.ts new file mode 100644 index 0000000000..2022d3af09 --- /dev/null +++ b/body-parser/body-parser-tests.ts @@ -0,0 +1,9 @@ +import * as bodyParser from 'body-parser'; +import * as express from 'express'; + +const app = express(); + +express.use(bodyParser.json()); +express.use(bodyParser.raw()); +express.use(bodyParser.text()); +express.use(bodyParser.urlencoded()); diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index b8a1b0dc86..f71d58fffe 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -1,137 +1,45 @@ -// Type definitions for body-parser +// Type definitions for body-parser 1.16 // Project: http://expressjs.com -// Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle +// Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle , Tomasz Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +import { Request, RequestHandler, Response } from 'express'; +// for docs go to https://github.com/expressjs/body-parser/tree/1.16.0#body-parser - -import * as express from "express"; - -/** - * bodyParser: use individual json/urlencoded middlewares - * @deprecated - */ - -declare function bodyParser(options?: { - /** - * if deflated bodies will be inflated. (default: true) - */ - inflate?: boolean; - /** - * maximum request body size. (default: '100kb') - */ - limit?: any; - /** - * function to verify body content, the parsing can be aborted by throwing an error. - */ - verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - /** - * only parse objects and arrays. (default: true) - */ - strict?: boolean; - /** - * passed to JSON.parse(). - */ - reviver?: (key: string, value: any) => any; - /** - * parse extended syntax with the qs module. (default: true) - */ - extended?: boolean; -}): express.RequestHandler; +// @deprecated +declare function bodyParser(options?: bodyParser.OptionsJson | bodyParser.OptionsText | bodyParser.OptionsUrlencoded): RequestHandler; declare namespace bodyParser { - export function json(options?: { - /** - * if deflated bodies will be inflated. (default: true) - */ + + export interface Options { inflate?: boolean; - /** - * maximum request body size. (default: '100kb') - */ - limit?: any; - /** - * request content-type to parse, passed directly to the type-is library. (default: 'json') - */ - type?: any; - /** - * function to verify body content, the parsing can be aborted by throwing an error. - */ - verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - /** - * only parse objects and arrays. (default: true) - */ + limit?: number | string; + type?: string | ((req: Request) => any); + verify?: (req: Request, res: Response, buf: Buffer, encoding: string) => void; + } + + export interface OptionsJson extends Options { + reviever?: (key: string, value: any) => any; strict?: boolean; - /** - * passed to JSON.parse(). - */ - reviver?: (key: string, value: any) => any; - }): express.RequestHandler; + } - export function raw(options?: { - /** - * if deflated bodies will be inflated. (default: true) - */ - inflate?: boolean; - /** - * maximum request body size. (default: '100kb') - */ - limit?: any; - /** - * request content-type to parse, passed directly to the type-is library. (default: 'application/octet-stream') - */ - type?: any; - /** - * function to verify body content, the parsing can be aborted by throwing an error. - */ - verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - }): express.RequestHandler; - - export function text(options?: { - /** - * if deflated bodies will be inflated. (default: true) - */ - inflate?: boolean; - /** - * maximum request body size. (default: '100kb') - */ - limit?: any; - /** - * request content-type to parse, passed directly to the type-is library. (default: 'text/plain') - */ - type?: any; - /** - * function to verify body content, the parsing can be aborted by throwing an error. - */ - verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - /** - * the default charset to parse as, if not specified in content-type. (default: 'utf-8') - */ + export interface OptionsText extends Options { defaultCharset?: string; - }): express.RequestHandler; + } - export function urlencoded(options: { - /** - * if deflated bodies will be inflated. (default: true) - */ - inflate?: boolean; - /** - * maximum request body size. (default: '100kb') - */ - limit?: any; - /** - * request content-type to parse, passed directly to the type-is library. (default: 'urlencoded') - */ - type?: any; - /** - * function to verify body content, the parsing can be aborted by throwing an error. - */ - verify?: (req: express.Request, res: express.Response, buf: Buffer, encoding: string) => void; - /** - * parse extended syntax with the qs module. - */ - extended: boolean; - }): express.RequestHandler; + export interface OptionsUrlencoded extends Options { + extended?: boolean; + parameterLimit?: number; + } + + export function json(options?: OptionsJson): RequestHandler; + + export function raw(options?: Options): RequestHandler; + + export function text(options?: OptionsText): RequestHandler; + + export function urlencoded(options: OptionsUrlencoded): RequestHandler; } export = bodyParser; diff --git a/body-parser/tslint.json b/body-parser/tslint.json new file mode 100644 index 0000000000..ec365f164b --- /dev/null +++ b/body-parser/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../tslint.json" +} From b958299670bf6b764f92dccd90de7ac8bba2b8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 16:39:44 +0100 Subject: [PATCH 02/10] fix files --- body-parser/tsconfig.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/body-parser/tsconfig.json b/body-parser/tsconfig.json index 27e01ecd7b..800ea22e81 100644 --- a/body-parser/tsconfig.json +++ b/body-parser/tsconfig.json @@ -16,6 +16,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "body-parser-tests.ts" ] -} \ No newline at end of file +} From a055ddf1eec3ffc28c400fa9d0c67b3f5c33fdbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 16:42:22 +0100 Subject: [PATCH 03/10] reference node for Buffer --- body-parser/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index f71d58fffe..d7862557b5 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -3,6 +3,8 @@ // Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle , Tomasz Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + import { Request, RequestHandler, Response } from 'express'; // for docs go to https://github.com/expressjs/body-parser/tree/1.16.0#body-parser From fb165d383ba74c12247ca2de7d9a0f05bb76f559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Feb 2017 16:48:18 +0100 Subject: [PATCH 04/10] do not test that --- body-parser/body-parser-tests.ts | 9 --------- body-parser/tsconfig.json | 3 +-- 2 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 body-parser/body-parser-tests.ts diff --git a/body-parser/body-parser-tests.ts b/body-parser/body-parser-tests.ts deleted file mode 100644 index 2022d3af09..0000000000 --- a/body-parser/body-parser-tests.ts +++ /dev/null @@ -1,9 +0,0 @@ -import * as bodyParser from 'body-parser'; -import * as express from 'express'; - -const app = express(); - -express.use(bodyParser.json()); -express.use(bodyParser.raw()); -express.use(bodyParser.text()); -express.use(bodyParser.urlencoded()); diff --git a/body-parser/tsconfig.json b/body-parser/tsconfig.json index 800ea22e81..fe0b5d1b8a 100644 --- a/body-parser/tsconfig.json +++ b/body-parser/tsconfig.json @@ -16,7 +16,6 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "body-parser-tests.ts" + "index.d.ts" ] } From d7e823fd074a330c5da15f9f505c9ee8b385cdff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Thu, 9 Feb 2017 20:44:41 +0100 Subject: [PATCH 05/10] comments --- body-parser/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index d7862557b5..3a1ebaaba8 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for body-parser 1.16 -// Project: http://expressjs.com -// Definitions by: Santi Albo , VILIC VANE , Jonathan Häberle , Tomasz Łaziuk +// Project: https://github.com/expressjs/body-parser +// Definitions by: Santi Albo , Vilic Vane , Jonathan Häberle , Tomasz Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 9de4486dbeb4bd5c71ebd751c052b0f443259a2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Sat, 11 Feb 2017 00:58:28 +0100 Subject: [PATCH 06/10] tests --- body-parser/body-parser-tests.ts | 22 ++++++++++++++++++++++ body-parser/tsconfig.json | 6 ++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 body-parser/body-parser-tests.ts diff --git a/body-parser/body-parser-tests.ts b/body-parser/body-parser-tests.ts new file mode 100644 index 0000000000..ffac86e592 --- /dev/null +++ b/body-parser/body-parser-tests.ts @@ -0,0 +1,22 @@ +import * as express from 'express'; +import { + json, + raw, + text, + urlencoded, +} from 'body-parser'; + +const app = express(); + +express.use(json()); +express.use(raw()); +express.use(text()); +express.use(urlencoded()); + +// send any data, it should be parsed and printed +express.all('/', (req, res, next) => { + console.log(req.body); + res.json(req.body); +}); + +express.listen(8080); diff --git a/body-parser/tsconfig.json b/body-parser/tsconfig.json index fe0b5d1b8a..e798cd97d3 100644 --- a/body-parser/tsconfig.json +++ b/body-parser/tsconfig.json @@ -2,7 +2,8 @@ "compilerOptions": { "module": "commonjs", "lib": [ - "es6" + "es6", + "dom" ], "noImplicitAny": true, "noImplicitThis": true, @@ -16,6 +17,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "body-parser-tests.ts" ] } From f3b78d096de05c25a6084a44d54321ffd48b8bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Mar 2017 08:17:48 +0100 Subject: [PATCH 07/10] update typings --- body-parser/body-parser-tests.ts | 12 ++++++------ body-parser/index.d.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/body-parser/body-parser-tests.ts b/body-parser/body-parser-tests.ts index ffac86e592..fa18cad13b 100644 --- a/body-parser/body-parser-tests.ts +++ b/body-parser/body-parser-tests.ts @@ -8,15 +8,15 @@ import { const app = express(); -express.use(json()); -express.use(raw()); -express.use(text()); -express.use(urlencoded()); +app.use(json()); +app.use(raw()); +app.use(text()); +app.use(urlencoded()); // send any data, it should be parsed and printed -express.all('/', (req, res, next) => { +app.all('/', (req, res, next) => { console.log(req.body); res.json(req.body); }); -express.listen(8080); +app.listen(8080); diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index 3a1ebaaba8..a11205f6f3 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -41,7 +41,7 @@ declare namespace bodyParser { export function text(options?: OptionsText): RequestHandler; - export function urlencoded(options: OptionsUrlencoded): RequestHandler; + export function urlencoded(options?: OptionsUrlencoded): RequestHandler; } export = bodyParser; From 02e581761193557c093fa7de9b76c4afb45bbb95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Mar 2017 08:27:13 +0100 Subject: [PATCH 08/10] newline --- body-parser/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index 5fd2096c27..c1d2949293 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -45,4 +45,4 @@ declare namespace bodyParser { } -export = bodyParser; \ No newline at end of file +export = bodyParser; From a8c42d9ef87d1432ff230cc4c58077fb0512627f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 7 Mar 2017 08:29:47 +0100 Subject: [PATCH 09/10] added Grevik Babakhani --- body-parser/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/body-parser/index.d.ts b/body-parser/index.d.ts index c1d2949293..c0ce775bb0 100644 --- a/body-parser/index.d.ts +++ b/body-parser/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for body-parser 1.16 // Project: https://github.com/expressjs/body-parser -// Definitions by: Santi Albo , Vilic Vane , Jonathan Häberle , Tomasz Łaziuk +// Definitions by: Santi Albo , Vilic Vane , Jonathan Häberle , Gevik Babakhani , Tomasz Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// From 5ed36ce5a8367dde3c2240ed8613ca332208e507 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Wed, 8 Mar 2017 21:33:44 +0100 Subject: [PATCH 10/10] max-lint-length --- body-parser/tslint.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/body-parser/tslint.json b/body-parser/tslint.json index ec365f164b..9311f348d9 100644 --- a/body-parser/tslint.json +++ b/body-parser/tslint.json @@ -1,3 +1,6 @@ { - "extends": "../tslint.json" + "extends": "../tslint.json", + "rules": { + "max-line-length": false + } }