@midwayjs/koa 3.15.11 → 3.16.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/dist/framework.js +37 -0
- package/dist/interface.d.ts +7 -1
- package/package.json +8 -6
package/dist/framework.js
CHANGED
|
@@ -12,6 +12,8 @@ const cookies_1 = require("@midwayjs/cookies");
|
|
|
12
12
|
const Router = require("@koa/router");
|
|
13
13
|
const koa = require("koa");
|
|
14
14
|
const onerror_1 = require("./onerror");
|
|
15
|
+
const qs = require("qs");
|
|
16
|
+
const querystring = require("querystring");
|
|
15
17
|
const COOKIES = Symbol('context#cookies');
|
|
16
18
|
class KoaControllerGenerator extends core_1.WebControllerGenerator {
|
|
17
19
|
constructor(app, webRouterService) {
|
|
@@ -85,6 +87,41 @@ let MidwayKoaFramework = class MidwayKoaFramework extends core_1.BaseFramework {
|
|
|
85
87
|
};
|
|
86
88
|
},
|
|
87
89
|
});
|
|
90
|
+
const converter = this.configurationOptions.queryParseMode === 'strict'
|
|
91
|
+
? function (value) {
|
|
92
|
+
return !Array.isArray(value) ? [value] : value;
|
|
93
|
+
}
|
|
94
|
+
: this.configurationOptions.queryParseMode === 'first'
|
|
95
|
+
? function (value) {
|
|
96
|
+
return Array.isArray(value) ? value[0] : value;
|
|
97
|
+
}
|
|
98
|
+
: undefined;
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
100
|
+
const self = this;
|
|
101
|
+
// fix query with array params
|
|
102
|
+
Object.defineProperty(this.app.request, 'query', {
|
|
103
|
+
get() {
|
|
104
|
+
const str = this.querystring;
|
|
105
|
+
const c = (this._querycache = this._querycache || {});
|
|
106
|
+
// find cache
|
|
107
|
+
if (c[str])
|
|
108
|
+
return c[str];
|
|
109
|
+
if (self.configurationOptions.queryParseMode) {
|
|
110
|
+
// use qs module to parse query
|
|
111
|
+
c[str] = qs.parse(str, self.configurationOptions.queryParseOptions || {});
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
// use querystring to parse query by default
|
|
115
|
+
c[str] = querystring.parse(str);
|
|
116
|
+
}
|
|
117
|
+
if (converter) {
|
|
118
|
+
for (const key in c[str]) {
|
|
119
|
+
c[str][key] = converter(c[str][key]);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return c[str];
|
|
123
|
+
},
|
|
124
|
+
});
|
|
88
125
|
const onerrorConfig = this.configService.getConfiguration('onerror');
|
|
89
126
|
(0, onerror_1.setupOnError)(this.app, onerrorConfig, this.logger);
|
|
90
127
|
// not found middleware
|
package/dist/interface.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { IConfigurationOptions, IMidwayApplication, IMidwayContext } from '@midw
|
|
|
3
3
|
import * as koa from 'koa';
|
|
4
4
|
import { Context as KoaContext, DefaultState, Middleware, Next } from 'koa';
|
|
5
5
|
import { RouterParamValue } from '@midwayjs/core';
|
|
6
|
+
import * as qs from 'qs';
|
|
6
7
|
export interface State extends DefaultState {
|
|
7
8
|
}
|
|
8
9
|
export type IMidwayKoaContext = IMidwayContext<KoaContext>;
|
|
@@ -77,8 +78,13 @@ export interface IMidwayKoaConfigurationOptions extends IConfigurationOptions {
|
|
|
77
78
|
*/
|
|
78
79
|
serverTimeout?: number;
|
|
79
80
|
/**
|
|
80
|
-
*
|
|
81
|
+
* qs mode
|
|
81
82
|
*/
|
|
83
|
+
queryParseMode?: 'extended' | 'strict' | 'first';
|
|
84
|
+
/**
|
|
85
|
+
* qs options
|
|
86
|
+
*/
|
|
87
|
+
queryParseOptions?: qs.IParseOptions;
|
|
82
88
|
serverOptions?: Record<string, any>;
|
|
83
89
|
}
|
|
84
90
|
export type MiddlewareParamArray = Array<Middleware<DefaultState, IMidwayKoaContext>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/koa",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.0",
|
|
4
4
|
"description": "Midway Web Framework for KOA",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -24,18 +24,20 @@
|
|
|
24
24
|
],
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@midwayjs/mock": "^3.
|
|
27
|
+
"@midwayjs/mock": "^3.16.0",
|
|
28
28
|
"@types/koa-router": "7.4.8",
|
|
29
29
|
"fs-extra": "11.2.0"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@koa/router": "^12.0.0",
|
|
33
33
|
"@midwayjs/cookies": "^1.0.2",
|
|
34
|
-
"@midwayjs/core": "^3.
|
|
35
|
-
"@midwayjs/session": "^3.
|
|
34
|
+
"@midwayjs/core": "^3.16.0",
|
|
35
|
+
"@midwayjs/session": "^3.16.0",
|
|
36
36
|
"@types/koa": "2.15.0",
|
|
37
|
+
"@types/qs": "6.9.15",
|
|
37
38
|
"koa": "2.15.3",
|
|
38
|
-
"koa-bodyparser": "4.4.1"
|
|
39
|
+
"koa-bodyparser": "4.4.1",
|
|
40
|
+
"qs": "6.12.1"
|
|
39
41
|
},
|
|
40
42
|
"author": "Harry Chen <czy88840616@gmail.com>",
|
|
41
43
|
"repository": {
|
|
@@ -45,5 +47,5 @@
|
|
|
45
47
|
"engines": {
|
|
46
48
|
"node": ">=12"
|
|
47
49
|
},
|
|
48
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7e75fe1bdc9a6df2956f9c22e704063aaa022d76"
|
|
49
51
|
}
|