alp-body-parser 5.2.0 → 6.0.2
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 +1 -1
- package/CHANGELOG.md +49 -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 +19 -24
- package/rollup.config.mjs +5 -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,55 @@
|
|
|
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.2](https://github.com/christophehurpeau/alp/compare/alp-body-parser@6.0.1...alp-body-parser@6.0.2) (2022-02-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package alp-body-parser
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [6.0.1](https://github.com/christophehurpeau/alp/compare/alp-body-parser@6.0.0...alp-body-parser@6.0.1) (2022-01-15)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Bug Fixes
|
|
18
|
+
|
|
19
|
+
* update peer dependencies ([74892bc](https://github.com/christophehurpeau/alp/commit/74892bc8dd99ca862ba427914eb893b083e9b9da))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# [6.0.0](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.2.1...alp-body-parser@6.0.0) (2022-01-02)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* update nightingale and fix tests ([3691716](https://github.com/christophehurpeau/alp/commit/36917162d0ee3dccc07384caf018b7760d98b744))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Features
|
|
34
|
+
|
|
35
|
+
* **deps:** update dependency @types/co-body to v6 ([#263](https://github.com/christophehurpeau/alp/issues/263)) ([7f832bd](https://github.com/christophehurpeau/alp/commit/7f832bda15a2a69f9d144e96d91d17a7709bcb0b))
|
|
36
|
+
* use ESM and drop node 12 ([f45054e](https://github.com/christophehurpeau/alp/commit/f45054e931eea88451d183722797eba057511236))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### BREAKING CHANGES
|
|
40
|
+
|
|
41
|
+
* requires node 14 and ESM
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## [5.2.1](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.2.0...alp-body-parser@5.2.1) (2021-04-10)
|
|
48
|
+
|
|
49
|
+
**Note:** Version bump only for package alp-body-parser
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
6
55
|
# [5.2.0](https://github.com/christophehurpeau/alp/compare/alp-body-parser@5.1.0...alp-body-parser@5.2.0) (2021-03-28)
|
|
7
56
|
|
|
8
57
|
|
|
@@ -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.2",
|
|
4
4
|
"description": "body parser in alp framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"alp",
|
|
@@ -17,33 +17,30 @@
|
|
|
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
|
-
"build": "
|
|
37
|
+
"build": "yarn clean:build && rollup --config rollup.config.mjs && yarn run build:definitions",
|
|
42
38
|
"build:definitions": "tsc -p tsconfig.build.json",
|
|
43
|
-
"clean": "
|
|
39
|
+
"clean": "yarn clean:build",
|
|
40
|
+
"clean:build": "rm -Rf dist",
|
|
44
41
|
"lint": "yarn run lint:eslint",
|
|
45
|
-
"lint:eslint": "
|
|
46
|
-
"watch": "
|
|
42
|
+
"lint:eslint": "cd ../.. && yarn run eslint --report-unused-disable-directives --resolve-plugins-relative-to . --quiet packages/alp-body-parser",
|
|
43
|
+
"watch": "yarn clean:build && rollup --config rollup.config.mjs --watch"
|
|
47
44
|
},
|
|
48
45
|
"prettier": {
|
|
49
46
|
"trailingComma": "all",
|
|
@@ -54,9 +51,8 @@
|
|
|
54
51
|
"babelEnvs": [
|
|
55
52
|
{
|
|
56
53
|
"target": "node",
|
|
57
|
-
"version": "
|
|
54
|
+
"version": "14",
|
|
58
55
|
"formats": [
|
|
59
|
-
"cjs",
|
|
60
56
|
"es"
|
|
61
57
|
]
|
|
62
58
|
}
|
|
@@ -66,19 +62,18 @@
|
|
|
66
62
|
]
|
|
67
63
|
},
|
|
68
64
|
"peerDependencies": {
|
|
69
|
-
"alp-node": "^
|
|
65
|
+
"alp-node": "^4.0.2"
|
|
70
66
|
},
|
|
71
67
|
"dependencies": {
|
|
72
|
-
"@types/co-body": "^
|
|
68
|
+
"@types/co-body": "^6.0.0",
|
|
73
69
|
"@types/koa": "^2.13.1",
|
|
74
70
|
"co-body": "^6.0.0",
|
|
75
71
|
"koa": "^2.13.1"
|
|
76
72
|
},
|
|
77
73
|
"devDependencies": {
|
|
78
|
-
"@babel/core": "7.
|
|
79
|
-
"babel
|
|
80
|
-
"
|
|
81
|
-
"rollup": "2.43.1"
|
|
74
|
+
"@babel/core": "7.17.0",
|
|
75
|
+
"pob-babel": "31.0.0",
|
|
76
|
+
"typescript": "4.5.5"
|
|
82
77
|
},
|
|
83
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "1af3cf2eb4bba25ab23f174cda860416ff68a63d"
|
|
84
79
|
}
|
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
|