alp-body-parser 5.0.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +2 -2
- package/CHANGELOG.md +53 -0
- package/dist/{index-node12-dev.mjs → index-node14.mjs} +2 -2
- package/dist/{index-node12.mjs.map → index-node14.mjs.map} +1 -1
- package/package.json +17 -23
- package/rollup.config.mjs +3 -0
- package/src/.eslintrc.json +19 -2
- package/dist/index-node12-dev.cjs.js +0 -41
- package/dist/index-node12-dev.cjs.js.map +0 -1
- package/dist/index-node12-dev.mjs.map +0 -1
- package/dist/index-node12.cjs.js +0 -41
- package/dist/index-node12.cjs.js.map +0 -1
- package/dist/index-node12.mjs +0 -33
- package/index.js +0 -6
package/.eslintrc.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,59 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.0.0](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.2.1...alp-body-parser@6.0.0) (2022-01-02)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* **deps:** update dependency @types/co-body to v6 ([#263](https://github.com/christophehurpeau/alp/issues/263)) ([7f832bd](https://github.com/christophehurpeau/alp/commit/7f832bda15a2a69f9d144e96d91d17a7709bcb0b))
|
|
17
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### BREAKING CHANGES
|
|
21
|
+
|
|
22
|
+
* requires node 14 and ESM
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## [5.2.1](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.2.0...alp-body-parser@5.2.1) (2021-04-10)
|
|
29
|
+
|
|
30
|
+
**Note:** Version bump only for package alp-body-parser
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
# [5.2.0](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.1.0...alp-body-parser@5.2.0) (2021-03-28)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* update koa ([8be5ecf](https://github.com/christophehurpeau/alp/commit/8be5ecf11e53a2deced805683195cc5c67ba9ea2))
|
|
42
|
+
* **deps:** update dependency @types/co-body to v5 ([#193](https://github.com/christophehurpeau/alp/issues/193)) ([52d1c87](https://github.com/christophehurpeau/alp/commit/52d1c8768765b907b83f50c00856a9dfb9d2f328))
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# [5.1.0](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.0.3...alp-body-parser@5.1.0) (2021-03-21)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
### Features
|
|
52
|
+
|
|
53
|
+
* update dependencies and browserlist config ([ec17710](https://github.com/christophehurpeau/alp/commit/ec177106dbfb094fface3d2791800916929305fc))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
6
59
|
## [5.0.3](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.0.2...alp-body-parser@5.0.3) (2021-01-23)
|
|
7
60
|
|
|
8
61
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-
|
|
1
|
+
{"version":3,"file":"index-node14.mjs","sources":["../src/index.ts"],"sourcesContent":["import parse from 'co-body';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport Application, { Context } from 'koa';\n\ndeclare module 'koa' {\n interface Request {\n body: any;\n }\n\n interface BaseContext {\n parseBody: <T>() => Promise<T>;\n parseBodyJson: <T>() => Promise<T>;\n parseBodyText: <T>() => Promise<T>;\n }\n}\n\nconst assertBodyNotParsed = (ctx: Context): void => {\n if (ctx.request.body) {\n throw new Error('Request is already parsed');\n }\n};\n\nexport default function alpBodyParser(app: Application): void {\n app.context.parseBody = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.form(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyJson = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.json(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyText = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.text(this)) as T;\n this.request.body = body;\n return body;\n };\n}\n"],"names":["assertBodyNotParsed","ctx","request","body","Error","alpBodyParser","app","context","parseBody","parse","form","parseBodyJson","json","parseBodyText","text"],"mappings":";;AAgBA,MAAMA,mBAAmB,GAAIC,GAAD,IAAwB;AAClD,MAAIA,GAAG,CAACC,OAAJ,CAAYC,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAU,2BAAV,CAAN;AACD;AACF,CAJD;;AAMe,SAASC,aAAT,CAAuBC,GAAvB,EAA+C;AAC5DA,EAAAA,GAAG,CAACC,OAAJ,CAAYC,SAAZ,GAAwB,kBAA8C;AACpER,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACC,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKR,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYI,aAAZ,GAA4B,kBAA8C;AACxEX,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACG,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKV,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYM,aAAZ,GAA4B,kBAA8C;AACxEb,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACK,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKZ,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;AAMD;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alp-body-parser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"description": "body parser in alp framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alp",
|
|
@@ -17,32 +17,28 @@
|
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/alpjs/alp-body-parser/issues"
|
|
19
19
|
},
|
|
20
|
+
"type": "module",
|
|
20
21
|
"engines": {
|
|
21
|
-
"node": ">=
|
|
22
|
+
"node": "^14.13.1 || >=16.0.0"
|
|
22
23
|
},
|
|
23
|
-
"main": "./index.
|
|
24
|
+
"main": "./dist/index-node14.mjs",
|
|
24
25
|
"types": "./dist/index.d.ts",
|
|
25
26
|
"exports": {
|
|
27
|
+
"./package.json": "./package.json",
|
|
26
28
|
".": {
|
|
27
29
|
"node": {
|
|
28
|
-
"
|
|
29
|
-
"import": "./dist/index-node12-dev.mjs",
|
|
30
|
-
"require": "./dist/index-node12-dev.cjs.js"
|
|
31
|
-
},
|
|
32
|
-
"import": "./dist/index-node12.mjs",
|
|
33
|
-
"require": "./dist/index-node12.cjs.js"
|
|
30
|
+
"import": "./dist/index-node14.mjs"
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
},
|
|
37
|
-
"module:node": "./dist/index-
|
|
38
|
-
"module:node-dev": "./dist/index-node12-dev.mjs",
|
|
34
|
+
"module:node": "./dist/index-node14.mjs",
|
|
39
35
|
"sideEffects": false,
|
|
40
36
|
"scripts": {
|
|
41
37
|
"build": "pob-build && yarn run build:definitions",
|
|
42
38
|
"build:definitions": "tsc -p tsconfig.build.json",
|
|
43
|
-
"clean": "rm -Rf
|
|
39
|
+
"clean": "rm -Rf dist",
|
|
44
40
|
"lint": "yarn run lint:eslint",
|
|
45
|
-
"lint:eslint": "
|
|
41
|
+
"lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/alp-body-parser",
|
|
46
42
|
"watch": "pob-watch"
|
|
47
43
|
},
|
|
48
44
|
"prettier": {
|
|
@@ -54,9 +50,8 @@
|
|
|
54
50
|
"babelEnvs": [
|
|
55
51
|
{
|
|
56
52
|
"target": "node",
|
|
57
|
-
"version": "
|
|
53
|
+
"version": "14",
|
|
58
54
|
"formats": [
|
|
59
|
-
"cjs",
|
|
60
55
|
"es"
|
|
61
56
|
]
|
|
62
57
|
}
|
|
@@ -69,16 +64,15 @@
|
|
|
69
64
|
"alp-node": "^3.0.1"
|
|
70
65
|
},
|
|
71
66
|
"dependencies": {
|
|
72
|
-
"@types/co-body": "^0.0
|
|
73
|
-
"@types/koa": "^2.
|
|
67
|
+
"@types/co-body": "^6.0.0",
|
|
68
|
+
"@types/koa": "^2.13.1",
|
|
74
69
|
"co-body": "^6.0.0",
|
|
75
|
-
"koa": "^2.
|
|
70
|
+
"koa": "^2.13.1"
|
|
76
71
|
},
|
|
77
72
|
"devDependencies": {
|
|
78
|
-
"@babel/core": "7.
|
|
79
|
-
"babel
|
|
80
|
-
"
|
|
81
|
-
"rollup": "2.36.2"
|
|
73
|
+
"@babel/core": "7.16.7",
|
|
74
|
+
"pob-babel": "29.6.1",
|
|
75
|
+
"typescript": "4.5.4"
|
|
82
76
|
},
|
|
83
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "854189ce2307f42363e81bcf7862c5f1deced54a"
|
|
84
78
|
}
|
package/src/.eslintrc.json
CHANGED
|
@@ -7,7 +7,24 @@
|
|
|
7
7
|
"plugins": ["@typescript-eslint"],
|
|
8
8
|
"extends": [
|
|
9
9
|
"@pob/eslint-config-typescript",
|
|
10
|
-
"@pob/eslint-config-typescript
|
|
10
|
+
"@pob/eslint-config-typescript/node"
|
|
11
11
|
],
|
|
12
|
-
"ignorePatterns": ["*.d.ts"]
|
|
12
|
+
"ignorePatterns": ["*.d.ts"],
|
|
13
|
+
"overrides": [
|
|
14
|
+
{
|
|
15
|
+
"files": ["**/*.test.ts", "__tests__/**/*.ts"],
|
|
16
|
+
"extends": ["@pob/eslint-config-typescript/test"],
|
|
17
|
+
"env": {
|
|
18
|
+
"jest": true
|
|
19
|
+
},
|
|
20
|
+
"rules": {
|
|
21
|
+
"import/no-extraneous-dependencies": [
|
|
22
|
+
"error",
|
|
23
|
+
{
|
|
24
|
+
"devDependencies": true
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
]
|
|
13
30
|
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const parse = require('co-body');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
8
|
-
|
|
9
|
-
const parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
|
|
10
|
-
|
|
11
|
-
const assertBodyNotParsed = ctx => {
|
|
12
|
-
if (ctx.request.body) {
|
|
13
|
-
throw new Error('Request is already parsed');
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function alpBodyParser(app) {
|
|
18
|
-
app.context.parseBody = async function () {
|
|
19
|
-
assertBodyNotParsed(this);
|
|
20
|
-
const body = await parse__default.form(this);
|
|
21
|
-
this.request.body = body;
|
|
22
|
-
return body;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
app.context.parseBodyJson = async function () {
|
|
26
|
-
assertBodyNotParsed(this);
|
|
27
|
-
const body = await parse__default.json(this);
|
|
28
|
-
this.request.body = body;
|
|
29
|
-
return body;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
app.context.parseBodyText = async function () {
|
|
33
|
-
assertBodyNotParsed(this);
|
|
34
|
-
const body = await parse__default.text(this);
|
|
35
|
-
this.request.body = body;
|
|
36
|
-
return body;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.default = alpBodyParser;
|
|
41
|
-
//# sourceMappingURL=index-node12-dev.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12-dev.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import parse from 'co-body';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport Application, { Context } from 'koa';\n\ndeclare module 'koa' {\n interface Request {\n body: any;\n }\n\n interface BaseContext {\n parseBody: <T>() => Promise<T>;\n parseBodyJson: <T>() => Promise<T>;\n parseBodyText: <T>() => Promise<T>;\n }\n}\n\nconst assertBodyNotParsed = (ctx: Context): void => {\n if (ctx.request.body) {\n throw new Error('Request is already parsed');\n }\n};\n\nexport default function alpBodyParser(app: Application): void {\n app.context.parseBody = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.form(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyJson = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.json(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyText = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.text(this)) as T;\n this.request.body = body;\n return body;\n };\n}\n"],"names":["assertBodyNotParsed","ctx","request","body","Error","alpBodyParser","app","context","parseBody","parse","form","parseBodyJson","json","parseBodyText","text"],"mappings":";;;;;;;;;;AAgBA,MAAMA,mBAAmB,GAAIC,GAAD,IAAwB;AAClD,MAAIA,GAAG,CAACC,OAAJ,CAAYC,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAU,2BAAV,CAAN;AACD;AACF,CAJD;;AAMe,SAASC,aAAT,CAAuBC,GAAvB,EAA+C;AAC5DA,EAAAA,GAAG,CAACC,OAAJ,CAAYC,SAAZ,GAAwB,kBAA8C;AACpER,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACC,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKR,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYI,aAAZ,GAA4B,kBAA8C;AACxEX,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACG,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKV,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYM,aAAZ,GAA4B,kBAA8C;AACxEb,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACK,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKZ,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;AAMD;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12-dev.mjs","sources":["../src/index.ts"],"sourcesContent":["import parse from 'co-body';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport Application, { Context } from 'koa';\n\ndeclare module 'koa' {\n interface Request {\n body: any;\n }\n\n interface BaseContext {\n parseBody: <T>() => Promise<T>;\n parseBodyJson: <T>() => Promise<T>;\n parseBodyText: <T>() => Promise<T>;\n }\n}\n\nconst assertBodyNotParsed = (ctx: Context): void => {\n if (ctx.request.body) {\n throw new Error('Request is already parsed');\n }\n};\n\nexport default function alpBodyParser(app: Application): void {\n app.context.parseBody = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.form(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyJson = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.json(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyText = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.text(this)) as T;\n this.request.body = body;\n return body;\n };\n}\n"],"names":["assertBodyNotParsed","ctx","request","body","Error","alpBodyParser","app","context","parseBody","parse","form","parseBodyJson","json","parseBodyText","text"],"mappings":";;AAgBA,MAAMA,mBAAmB,GAAIC,GAAD,IAAwB;AAClD,MAAIA,GAAG,CAACC,OAAJ,CAAYC,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAU,2BAAV,CAAN;AACD;AACF,CAJD;;AAMe,SAASC,aAAT,CAAuBC,GAAvB,EAA+C;AAC5DA,EAAAA,GAAG,CAACC,OAAJ,CAAYC,SAAZ,GAAwB,kBAA8C;AACpER,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACC,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKR,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYI,aAAZ,GAA4B,kBAA8C;AACxEX,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACG,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKV,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYM,aAAZ,GAA4B,kBAA8C;AACxEb,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,KAAK,CAACK,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKZ,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;AAMD;;;;"}
|
package/dist/index-node12.cjs.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
const parse = require('co-body');
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e['default'] : e; }
|
|
8
|
-
|
|
9
|
-
const parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
|
|
10
|
-
|
|
11
|
-
const assertBodyNotParsed = ctx => {
|
|
12
|
-
if (ctx.request.body) {
|
|
13
|
-
throw new Error('Request is already parsed');
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
function alpBodyParser(app) {
|
|
18
|
-
app.context.parseBody = async function () {
|
|
19
|
-
assertBodyNotParsed(this);
|
|
20
|
-
const body = await parse__default.form(this);
|
|
21
|
-
this.request.body = body;
|
|
22
|
-
return body;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
app.context.parseBodyJson = async function () {
|
|
26
|
-
assertBodyNotParsed(this);
|
|
27
|
-
const body = await parse__default.json(this);
|
|
28
|
-
this.request.body = body;
|
|
29
|
-
return body;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
app.context.parseBodyText = async function () {
|
|
33
|
-
assertBodyNotParsed(this);
|
|
34
|
-
const body = await parse__default.text(this);
|
|
35
|
-
this.request.body = body;
|
|
36
|
-
return body;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.default = alpBodyParser;
|
|
41
|
-
//# sourceMappingURL=index-node12.cjs.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-node12.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import parse from 'co-body';\n// eslint-disable-next-line @typescript-eslint/consistent-type-imports\nimport Application, { Context } from 'koa';\n\ndeclare module 'koa' {\n interface Request {\n body: any;\n }\n\n interface BaseContext {\n parseBody: <T>() => Promise<T>;\n parseBodyJson: <T>() => Promise<T>;\n parseBodyText: <T>() => Promise<T>;\n }\n}\n\nconst assertBodyNotParsed = (ctx: Context): void => {\n if (ctx.request.body) {\n throw new Error('Request is already parsed');\n }\n};\n\nexport default function alpBodyParser(app: Application): void {\n app.context.parseBody = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.form(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyJson = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.json(this)) as T;\n this.request.body = body;\n return body;\n };\n\n app.context.parseBodyText = async function <T>(this: Context): Promise<T> {\n assertBodyNotParsed(this);\n const body: T = (await parse.text(this)) as T;\n this.request.body = body;\n return body;\n };\n}\n"],"names":["assertBodyNotParsed","ctx","request","body","Error","alpBodyParser","app","context","parseBody","parse","form","parseBodyJson","json","parseBodyText","text"],"mappings":";;;;;;;;;;AAgBA,MAAMA,mBAAmB,GAAIC,GAAD,IAAwB;AAClD,MAAIA,GAAG,CAACC,OAAJ,CAAYC,IAAhB,EAAsB;AACpB,UAAM,IAAIC,KAAJ,CAAU,2BAAV,CAAN;AACD;AACF,CAJD;;AAMe,SAASC,aAAT,CAAuBC,GAAvB,EAA+C;AAC5DA,EAAAA,GAAG,CAACC,OAAJ,CAAYC,SAAZ,GAAwB,kBAA8C;AACpER,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACC,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKR,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYI,aAAZ,GAA4B,kBAA8C;AACxEX,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACG,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKV,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;;AAOAG,EAAAA,GAAG,CAACC,OAAJ,CAAYM,aAAZ,GAA4B,kBAA8C;AACxEb,IAAAA,mBAAmB,CAAC,IAAD,CAAnB;AACA,UAAMG,IAAO,GAAI,MAAMM,cAAK,CAACK,IAAN,CAAW,IAAX,CAAvB;AACA,SAAKZ,OAAL,CAAaC,IAAb,GAAoBA,IAApB;AACA,WAAOA,IAAP;AACD,GALD;AAMD;;;;"}
|
package/dist/index-node12.mjs
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import parse from 'co-body';
|
|
2
|
-
|
|
3
|
-
const assertBodyNotParsed = ctx => {
|
|
4
|
-
if (ctx.request.body) {
|
|
5
|
-
throw new Error('Request is already parsed');
|
|
6
|
-
}
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
function alpBodyParser(app) {
|
|
10
|
-
app.context.parseBody = async function () {
|
|
11
|
-
assertBodyNotParsed(this);
|
|
12
|
-
const body = await parse.form(this);
|
|
13
|
-
this.request.body = body;
|
|
14
|
-
return body;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
app.context.parseBodyJson = async function () {
|
|
18
|
-
assertBodyNotParsed(this);
|
|
19
|
-
const body = await parse.json(this);
|
|
20
|
-
this.request.body = body;
|
|
21
|
-
return body;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
app.context.parseBodyText = async function () {
|
|
25
|
-
assertBodyNotParsed(this);
|
|
26
|
-
const body = await parse.text(this);
|
|
27
|
-
this.request.body = body;
|
|
28
|
-
return body;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default alpBodyParser;
|
|
33
|
-
//# sourceMappingURL=index-node12.mjs.map
|