@midwayjs/core 3.0.0-beta.1 → 3.0.0-beta.5
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/CHANGELOG.md +49 -0
- package/dist/baseFramework.d.ts +11 -9
- package/dist/baseFramework.js +17 -14
- package/dist/{util → common}/fileDetector.d.ts +0 -0
- package/dist/{util → common}/fileDetector.js +0 -0
- package/dist/common/filterManager.d.ts +19 -0
- package/dist/common/filterManager.js +85 -0
- package/dist/common/middlewareManager.d.ts +11 -0
- package/dist/{util → common}/middlewareManager.js +0 -0
- package/dist/{util → common}/serviceFactory.d.ts +0 -0
- package/dist/{util → common}/serviceFactory.js +0 -0
- package/dist/{util → common}/triggerCollector.d.ts +0 -0
- package/dist/{util → common}/triggerCollector.js +0 -0
- package/dist/{util → common}/webGenerator.d.ts +6 -9
- package/dist/{util → common}/webGenerator.js +14 -21
- package/dist/{util → common}/webRouterCollector.d.ts +9 -4
- package/dist/{util → common}/webRouterCollector.js +47 -27
- package/dist/config/config.default.d.ts +3 -17
- package/dist/error/base.d.ts +3 -1
- package/dist/error/base.js +1 -0
- package/dist/error/code.d.ts +1 -1
- package/dist/error/code.js +1 -1
- package/dist/error/framework.d.ts +2 -2
- package/dist/error/framework.js +8 -5
- package/dist/error/http.d.ts +2 -1
- package/dist/error/http.js +3 -3
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +1 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.js +10 -8
- package/dist/interface.d.ts +50 -28
- package/dist/service/configService.js +4 -5
- package/dist/service/decoratorService.js +2 -0
- package/dist/service/frameworkService.d.ts +4 -3
- package/dist/service/frameworkService.js +10 -0
- package/dist/service/lifeCycleService.js +2 -0
- package/dist/service/loggerService.d.ts +1 -2
- package/dist/service/loggerService.js +1 -10
- package/dist/service/middlewareService.d.ts +2 -2
- package/dist/service/middlewareService.js +3 -25
- package/dist/setup.js +2 -0
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/index.d.ts +37 -0
- package/dist/util/index.js +95 -1
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +17 -18
- package/package.json +5 -5
- package/dist/util/exceptionFilterManager.d.ts +0 -13
- package/dist/util/exceptionFilterManager.js +0 -53
- package/dist/util/middlewareManager.d.ts +0 -11
package/dist/util/index.d.ts
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 2.0.0
|
|
3
|
+
* @param env
|
|
4
|
+
*/
|
|
1
5
|
export declare const isDevelopmentEnvironment: (env: any) => boolean;
|
|
6
|
+
/**
|
|
7
|
+
* @since 2.0.0
|
|
8
|
+
*/
|
|
2
9
|
export declare const getCurrentEnvironment: () => string;
|
|
10
|
+
/**
|
|
11
|
+
* @param p
|
|
12
|
+
* @param enabledCache
|
|
13
|
+
* @since 2.0.0
|
|
14
|
+
*/
|
|
3
15
|
export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
|
|
4
16
|
/**
|
|
5
17
|
* safelyGet(['a','b'],{a: {b: 2}}) // => 2
|
|
@@ -8,11 +20,13 @@ export declare const safeRequire: (p: any, enabledCache?: boolean) => any;
|
|
|
8
20
|
* safelyGet(['a','1'],{a: {b: 2}}) // => undefined
|
|
9
21
|
* safelyGet('a.b',{a: {b: 2}}) // => 2
|
|
10
22
|
* safelyGet('a.b',{c: {b: 2}}) // => undefined
|
|
23
|
+
* @since 2.0.0
|
|
11
24
|
*/
|
|
12
25
|
export declare function safelyGet(list: string | string[], obj?: Record<string, unknown>): any;
|
|
13
26
|
/**
|
|
14
27
|
* 剔除 @ 符号
|
|
15
28
|
* @param provideId provideId
|
|
29
|
+
* @since 2.0.0
|
|
16
30
|
*/
|
|
17
31
|
export declare function parsePrefix(provideId: string): string;
|
|
18
32
|
export declare function getUserHome(): string;
|
|
@@ -21,19 +35,42 @@ export declare function joinURLPath(...strArray: any[]): string;
|
|
|
21
35
|
* 代理目标所有的原型方法,不包括构造器和内部隐藏方法
|
|
22
36
|
* @param derivedCtor
|
|
23
37
|
* @param constructors
|
|
38
|
+
* @since 2.0.0
|
|
24
39
|
*/
|
|
25
40
|
export declare function delegateTargetPrototypeMethod(derivedCtor: any, constructors: any[]): void;
|
|
26
41
|
/**
|
|
27
42
|
* 代理目标原型上的特定方法
|
|
28
43
|
* @param derivedCtor
|
|
29
44
|
* @param methods
|
|
45
|
+
* @since 2.0.0
|
|
30
46
|
*/
|
|
31
47
|
export declare function delegateTargetMethod(derivedCtor: any, methods: string[]): void;
|
|
32
48
|
/**
|
|
33
49
|
* 代理目标原型属性
|
|
34
50
|
* @param derivedCtor
|
|
35
51
|
* @param properties
|
|
52
|
+
* @since 2.0.0
|
|
36
53
|
*/
|
|
37
54
|
export declare function delegateTargetProperties(derivedCtor: any, properties: string[]): void;
|
|
55
|
+
/**
|
|
56
|
+
* 代理目标原型属性
|
|
57
|
+
* @since 2.0.0
|
|
58
|
+
* @param timestamp
|
|
59
|
+
*/
|
|
38
60
|
export declare const getCurrentDateString: (timestamp?: number) => string;
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param message
|
|
64
|
+
* @since 3.0.0
|
|
65
|
+
*/
|
|
66
|
+
export declare const deprecatedOutput: (message: string) => void;
|
|
67
|
+
/**
|
|
68
|
+
* transform request object to definition type
|
|
69
|
+
*
|
|
70
|
+
* @param originValue
|
|
71
|
+
* @param targetType
|
|
72
|
+
* @since 3.0.0
|
|
73
|
+
*/
|
|
74
|
+
export declare const transformRequestObjectByType: (originValue: any, targetType?: any) => any;
|
|
75
|
+
export declare function toPathMatch(pattern: any): any;
|
|
39
76
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.js
CHANGED
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
3
|
+
exports.toPathMatch = exports.transformRequestObjectByType = exports.deprecatedOutput = exports.getCurrentDateString = exports.delegateTargetProperties = exports.delegateTargetMethod = exports.delegateTargetPrototypeMethod = exports.joinURLPath = exports.getUserHome = exports.parsePrefix = exports.safelyGet = exports.safeRequire = exports.getCurrentEnvironment = exports.isDevelopmentEnvironment = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const util_1 = require("util");
|
|
7
|
+
const class_transformer_1 = require("class-transformer");
|
|
8
|
+
const pathToRegexp_1 = require("./pathToRegexp");
|
|
9
|
+
const error_1 = require("../error");
|
|
7
10
|
const debug = (0, util_1.debuglog)('midway:container:util');
|
|
11
|
+
/**
|
|
12
|
+
* @since 2.0.0
|
|
13
|
+
* @param env
|
|
14
|
+
*/
|
|
8
15
|
const isDevelopmentEnvironment = env => {
|
|
9
16
|
return ['local', 'test', 'unittest'].includes(env);
|
|
10
17
|
};
|
|
11
18
|
exports.isDevelopmentEnvironment = isDevelopmentEnvironment;
|
|
19
|
+
/**
|
|
20
|
+
* @since 2.0.0
|
|
21
|
+
*/
|
|
12
22
|
const getCurrentEnvironment = () => {
|
|
13
23
|
return process.env['MIDWAY_SERVER_ENV'] || process.env['NODE_ENV'] || 'prod';
|
|
14
24
|
};
|
|
15
25
|
exports.getCurrentEnvironment = getCurrentEnvironment;
|
|
26
|
+
/**
|
|
27
|
+
* @param p
|
|
28
|
+
* @param enabledCache
|
|
29
|
+
* @since 2.0.0
|
|
30
|
+
*/
|
|
16
31
|
const safeRequire = (p, enabledCache = true) => {
|
|
17
32
|
if (p.startsWith(`.${path_1.sep}`) || p.startsWith(`..${path_1.sep}`)) {
|
|
18
33
|
p = (0, path_1.resolve)((0, path_1.dirname)(module.parent.filename), p);
|
|
@@ -41,6 +56,7 @@ exports.safeRequire = safeRequire;
|
|
|
41
56
|
* safelyGet(['a','1'],{a: {b: 2}}) // => undefined
|
|
42
57
|
* safelyGet('a.b',{a: {b: 2}}) // => 2
|
|
43
58
|
* safelyGet('a.b',{c: {b: 2}}) // => undefined
|
|
59
|
+
* @since 2.0.0
|
|
44
60
|
*/
|
|
45
61
|
function safelyGet(list, obj) {
|
|
46
62
|
if (arguments.length === 1) {
|
|
@@ -66,6 +82,7 @@ exports.safelyGet = safelyGet;
|
|
|
66
82
|
/**
|
|
67
83
|
* 剔除 @ 符号
|
|
68
84
|
* @param provideId provideId
|
|
85
|
+
* @since 2.0.0
|
|
69
86
|
*/
|
|
70
87
|
function parsePrefix(provideId) {
|
|
71
88
|
if (provideId.includes('@')) {
|
|
@@ -79,6 +96,7 @@ function getUserHome() {
|
|
|
79
96
|
}
|
|
80
97
|
exports.getUserHome = getUserHome;
|
|
81
98
|
function joinURLPath(...strArray) {
|
|
99
|
+
strArray = strArray.filter(item => !!item);
|
|
82
100
|
if (strArray.length === 0) {
|
|
83
101
|
return '';
|
|
84
102
|
}
|
|
@@ -94,6 +112,7 @@ exports.joinURLPath = joinURLPath;
|
|
|
94
112
|
* 代理目标所有的原型方法,不包括构造器和内部隐藏方法
|
|
95
113
|
* @param derivedCtor
|
|
96
114
|
* @param constructors
|
|
115
|
+
* @since 2.0.0
|
|
97
116
|
*/
|
|
98
117
|
function delegateTargetPrototypeMethod(derivedCtor, constructors) {
|
|
99
118
|
constructors.forEach(baseCtor => {
|
|
@@ -111,6 +130,7 @@ exports.delegateTargetPrototypeMethod = delegateTargetPrototypeMethod;
|
|
|
111
130
|
* 代理目标原型上的特定方法
|
|
112
131
|
* @param derivedCtor
|
|
113
132
|
* @param methods
|
|
133
|
+
* @since 2.0.0
|
|
114
134
|
*/
|
|
115
135
|
function delegateTargetMethod(derivedCtor, methods) {
|
|
116
136
|
methods.forEach(name => {
|
|
@@ -124,6 +144,7 @@ exports.delegateTargetMethod = delegateTargetMethod;
|
|
|
124
144
|
* 代理目标原型属性
|
|
125
145
|
* @param derivedCtor
|
|
126
146
|
* @param properties
|
|
147
|
+
* @since 2.0.0
|
|
127
148
|
*/
|
|
128
149
|
function delegateTargetProperties(derivedCtor, properties) {
|
|
129
150
|
properties.forEach(name => {
|
|
@@ -135,6 +156,11 @@ function delegateTargetProperties(derivedCtor, properties) {
|
|
|
135
156
|
});
|
|
136
157
|
}
|
|
137
158
|
exports.delegateTargetProperties = delegateTargetProperties;
|
|
159
|
+
/**
|
|
160
|
+
* 代理目标原型属性
|
|
161
|
+
* @since 2.0.0
|
|
162
|
+
* @param timestamp
|
|
163
|
+
*/
|
|
138
164
|
const getCurrentDateString = (timestamp = Date.now()) => {
|
|
139
165
|
const d = new Date(timestamp);
|
|
140
166
|
return `${d.getFullYear()}-${(d.getMonth() + 1)
|
|
@@ -142,4 +168,72 @@ const getCurrentDateString = (timestamp = Date.now()) => {
|
|
|
142
168
|
.padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`;
|
|
143
169
|
};
|
|
144
170
|
exports.getCurrentDateString = getCurrentDateString;
|
|
171
|
+
/**
|
|
172
|
+
*
|
|
173
|
+
* @param message
|
|
174
|
+
* @since 3.0.0
|
|
175
|
+
*/
|
|
176
|
+
const deprecatedOutput = (message) => {
|
|
177
|
+
console.warn('DeprecationWarning: ' + message);
|
|
178
|
+
};
|
|
179
|
+
exports.deprecatedOutput = deprecatedOutput;
|
|
180
|
+
/**
|
|
181
|
+
* transform request object to definition type
|
|
182
|
+
*
|
|
183
|
+
* @param originValue
|
|
184
|
+
* @param targetType
|
|
185
|
+
* @since 3.0.0
|
|
186
|
+
*/
|
|
187
|
+
const transformRequestObjectByType = (originValue, targetType) => {
|
|
188
|
+
if (targetType === undefined ||
|
|
189
|
+
targetType === null ||
|
|
190
|
+
targetType === Object) {
|
|
191
|
+
return originValue;
|
|
192
|
+
}
|
|
193
|
+
switch (targetType) {
|
|
194
|
+
case Number:
|
|
195
|
+
return Number(originValue);
|
|
196
|
+
case String:
|
|
197
|
+
return String(originValue);
|
|
198
|
+
case Boolean:
|
|
199
|
+
if (originValue === '0' || originValue === 'false') {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
return Boolean(originValue);
|
|
203
|
+
default:
|
|
204
|
+
if (originValue instanceof targetType) {
|
|
205
|
+
return originValue;
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return (0, class_transformer_1.plainToClass)(targetType, originValue);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.transformRequestObjectByType = transformRequestObjectByType;
|
|
213
|
+
function toPathMatch(pattern) {
|
|
214
|
+
if (typeof pattern === 'boolean') {
|
|
215
|
+
return ctx => pattern;
|
|
216
|
+
}
|
|
217
|
+
if (typeof pattern === 'string') {
|
|
218
|
+
const reg = (0, pathToRegexp_1.pathToRegexp)(pattern, [], { end: false });
|
|
219
|
+
if (reg.global)
|
|
220
|
+
reg.lastIndex = 0;
|
|
221
|
+
return ctx => reg.test(ctx.path);
|
|
222
|
+
}
|
|
223
|
+
if (pattern instanceof RegExp) {
|
|
224
|
+
return ctx => {
|
|
225
|
+
if (pattern.global)
|
|
226
|
+
pattern.lastIndex = 0;
|
|
227
|
+
return pattern.test(ctx.path);
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (typeof pattern === 'function')
|
|
231
|
+
return pattern;
|
|
232
|
+
if (Array.isArray(pattern)) {
|
|
233
|
+
const matchs = pattern.map(item => toPathMatch(item));
|
|
234
|
+
return ctx => matchs.some(match => match(ctx));
|
|
235
|
+
}
|
|
236
|
+
throw new error_1.MidwayCommonError('match/ignore pattern must be RegExp, Array or String, but got ' + pattern);
|
|
237
|
+
}
|
|
238
|
+
exports.toPathMatch = toPathMatch;
|
|
145
239
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const extractKoaLikeValue: (key: any, data: any) => (ctx: any, next: any) => any;
|
|
2
|
-
export declare const extractExpressLikeValue: (key: any, data: any) => (req: any, res: any, next: any) => any;
|
|
1
|
+
export declare const extractKoaLikeValue: (key: any, data: any, paramType?: any) => (ctx: any, next: any) => any;
|
|
2
|
+
export declare const extractExpressLikeValue: (key: any, data: any, paramType?: any) => (req: any, res: any, next: any) => any;
|
|
3
3
|
//# sourceMappingURL=webRouterParam.d.ts.map
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractExpressLikeValue = exports.extractKoaLikeValue = void 0;
|
|
4
4
|
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
-
const
|
|
5
|
+
const index_1 = require("./index");
|
|
6
|
+
const extractKoaLikeValue = (key, data, paramType) => {
|
|
6
7
|
if (decorator_1.ALL === data) {
|
|
7
8
|
data = undefined;
|
|
8
9
|
}
|
|
@@ -11,17 +12,15 @@ const extractKoaLikeValue = (key, data) => {
|
|
|
11
12
|
case decorator_1.RouteParamTypes.NEXT:
|
|
12
13
|
return next;
|
|
13
14
|
case decorator_1.RouteParamTypes.BODY:
|
|
14
|
-
return data && ctx.request.body
|
|
15
|
-
? ctx.request.body[data]
|
|
16
|
-
: ctx.request.body;
|
|
15
|
+
return (0, index_1.transformRequestObjectByType)(data && ctx.request.body ? ctx.request.body[data] : ctx.request.body, paramType);
|
|
17
16
|
case decorator_1.RouteParamTypes.PARAM:
|
|
18
|
-
return data ? ctx.params[data] : ctx.params;
|
|
17
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.params[data] : ctx.params, paramType);
|
|
19
18
|
case decorator_1.RouteParamTypes.QUERY:
|
|
20
|
-
return data ? ctx.query[data] : ctx.query;
|
|
19
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
|
|
21
20
|
case decorator_1.RouteParamTypes.HEADERS:
|
|
22
|
-
return data ? ctx.get(data) : ctx.headers;
|
|
21
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.get(data) : ctx.headers, paramType);
|
|
23
22
|
case decorator_1.RouteParamTypes.SESSION:
|
|
24
|
-
return data ? ctx.session[data] : ctx.session;
|
|
23
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.session[data] : ctx.session, paramType);
|
|
25
24
|
case decorator_1.RouteParamTypes.FILESTREAM:
|
|
26
25
|
return ctx.getFileStream && ctx.getFileStream(data);
|
|
27
26
|
case decorator_1.RouteParamTypes.FILESSTREAM:
|
|
@@ -32,10 +31,10 @@ const extractKoaLikeValue = (key, data) => {
|
|
|
32
31
|
return ctx['ip'];
|
|
33
32
|
case decorator_1.RouteParamTypes.QUERIES:
|
|
34
33
|
if (ctx.queries) {
|
|
35
|
-
return data ? ctx.queries[data] : ctx.queries;
|
|
34
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.queries[data] : ctx.queries, paramType);
|
|
36
35
|
}
|
|
37
36
|
else {
|
|
38
|
-
return data ? ctx.query[data] : ctx.query;
|
|
37
|
+
return (0, index_1.transformRequestObjectByType)(data ? ctx.query[data] : ctx.query, paramType);
|
|
39
38
|
}
|
|
40
39
|
default:
|
|
41
40
|
return null;
|
|
@@ -43,7 +42,7 @@ const extractKoaLikeValue = (key, data) => {
|
|
|
43
42
|
};
|
|
44
43
|
};
|
|
45
44
|
exports.extractKoaLikeValue = extractKoaLikeValue;
|
|
46
|
-
const extractExpressLikeValue = (key, data) => {
|
|
45
|
+
const extractExpressLikeValue = (key, data, paramType) => {
|
|
47
46
|
if (decorator_1.ALL === data) {
|
|
48
47
|
data = undefined;
|
|
49
48
|
}
|
|
@@ -52,15 +51,15 @@ const extractExpressLikeValue = (key, data) => {
|
|
|
52
51
|
case decorator_1.RouteParamTypes.NEXT:
|
|
53
52
|
return next;
|
|
54
53
|
case decorator_1.RouteParamTypes.BODY:
|
|
55
|
-
return data && req.body ? req.body[data] : req.body;
|
|
54
|
+
return (0, index_1.transformRequestObjectByType)(data && req.body ? req.body[data] : req.body, paramType);
|
|
56
55
|
case decorator_1.RouteParamTypes.PARAM:
|
|
57
|
-
return data ? req.params[data] : req.params;
|
|
56
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.params[data] : req.params, paramType);
|
|
58
57
|
case decorator_1.RouteParamTypes.QUERY:
|
|
59
|
-
return data ? req.query[data] : req.query;
|
|
58
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
|
|
60
59
|
case decorator_1.RouteParamTypes.HEADERS:
|
|
61
|
-
return data ? req.get(data) : req.headers;
|
|
60
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.get(data) : req.headers, paramType);
|
|
62
61
|
case decorator_1.RouteParamTypes.SESSION:
|
|
63
|
-
return data ? req.session[data] : req.session;
|
|
62
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.session[data] : req.session, paramType);
|
|
64
63
|
case decorator_1.RouteParamTypes.FILESTREAM:
|
|
65
64
|
return req.getFileStream && req.getFileStream(data);
|
|
66
65
|
case decorator_1.RouteParamTypes.FILESSTREAM:
|
|
@@ -71,10 +70,10 @@ const extractExpressLikeValue = (key, data) => {
|
|
|
71
70
|
return req['ip'];
|
|
72
71
|
case decorator_1.RouteParamTypes.QUERIES:
|
|
73
72
|
if (req.queries) {
|
|
74
|
-
return data ? req.queries[data] : req.queries;
|
|
73
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.queries[data] : req.queries, paramType);
|
|
75
74
|
}
|
|
76
75
|
else {
|
|
77
|
-
return data ? req.query[data] : req.query;
|
|
76
|
+
return (0, index_1.transformRequestObjectByType)(data ? req.query[data] : req.query, paramType);
|
|
78
77
|
}
|
|
79
78
|
default:
|
|
80
79
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midwayjs/core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
4
|
"description": "midway core",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"typings": "dist/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@midwayjs/decorator": "^3.0.0-beta.
|
|
24
|
+
"@midwayjs/decorator": "^3.0.0-beta.5",
|
|
25
25
|
"midway-test-component": "*",
|
|
26
26
|
"mm": "3",
|
|
27
27
|
"sinon": "^7.2.2"
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@midwayjs/glob": "^1.0.2",
|
|
34
|
-
"@midwayjs/logger": "^3.0.0-beta.
|
|
35
|
-
"class-transformer": "^0.
|
|
34
|
+
"@midwayjs/logger": "^3.0.0-beta.5",
|
|
35
|
+
"class-transformer": "^0.4.0",
|
|
36
36
|
"extend2": "^1.0.0",
|
|
37
37
|
"picomatch": "^2.2.2",
|
|
38
38
|
"reflect-metadata": "^0.1.13"
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"engines": {
|
|
46
46
|
"node": ">=12"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "ab0bf05ae6d13f6435db2f7223202be61d585a1b"
|
|
49
49
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { CommonExceptionFilterUnion, IMidwayContainer, IMidwayContext } from '../interface';
|
|
2
|
-
export declare class ExceptionFilterManager<T extends IMidwayContext = IMidwayContext, R = any, N = any> {
|
|
3
|
-
private filterList;
|
|
4
|
-
private exceptionMap;
|
|
5
|
-
private defaultFilter;
|
|
6
|
-
useFilter(Filter: CommonExceptionFilterUnion<T, R, N>): void;
|
|
7
|
-
init(applicationContext: IMidwayContainer): Promise<void>;
|
|
8
|
-
run(err: Error, ctx: T, res?: R, next?: N): Promise<{
|
|
9
|
-
result: any;
|
|
10
|
-
error: any;
|
|
11
|
-
}>;
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=exceptionFilterManager.d.ts.map
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ExceptionFilterManager = void 0;
|
|
4
|
-
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
-
class ExceptionFilterManager {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.filterList = [];
|
|
8
|
-
this.exceptionMap = new WeakMap();
|
|
9
|
-
this.defaultFilter = undefined;
|
|
10
|
-
}
|
|
11
|
-
useFilter(Filter) {
|
|
12
|
-
if (Array.isArray(Filter)) {
|
|
13
|
-
this.filterList.push(...Filter);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
this.filterList.push(Filter);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
async init(applicationContext) {
|
|
20
|
-
for (const FilterClass of this.filterList) {
|
|
21
|
-
const filter = await applicationContext.getAsync(FilterClass);
|
|
22
|
-
const exceptionMetadata = (0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, FilterClass);
|
|
23
|
-
if (exceptionMetadata && exceptionMetadata.catchTargets) {
|
|
24
|
-
for (const Exception of exceptionMetadata.catchTargets) {
|
|
25
|
-
this.exceptionMap.set(Exception, filter);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
// default filter
|
|
30
|
-
this.defaultFilter = filter;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
async run(err, ctx, res, next) {
|
|
35
|
-
let result, error;
|
|
36
|
-
if (this.exceptionMap.has(err.constructor)) {
|
|
37
|
-
const filter = this.exceptionMap.get(err.constructor);
|
|
38
|
-
result = await filter.catch(err, ctx, res, next);
|
|
39
|
-
}
|
|
40
|
-
else if (this.defaultFilter) {
|
|
41
|
-
result = await this.defaultFilter.catch(err, ctx, res, next);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
error = err;
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
result,
|
|
48
|
-
error,
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
exports.ExceptionFilterManager = ExceptionFilterManager;
|
|
53
|
-
//# sourceMappingURL=exceptionFilterManager.js.map
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { CommonMiddleware, CommonMiddlewareUnion, IMidwayContext } from '../interface';
|
|
2
|
-
export declare class ContextMiddlewareManager<T extends IMidwayContext = IMidwayContext, R = any, N = any> extends Array<CommonMiddleware<T, R, N>> {
|
|
3
|
-
insertFirst(middleware: CommonMiddlewareUnion<T, R, N>): void;
|
|
4
|
-
insertBefore(middleware: CommonMiddlewareUnion<T, R, N>, idxOrBeforeMiddleware: number): any;
|
|
5
|
-
insertBefore(middleware: CommonMiddlewareUnion<T, R, N>, idxOrBeforeMiddleware: CommonMiddlewareUnion<T, R, N>): any;
|
|
6
|
-
insertAfter(middleware: CommonMiddlewareUnion<T, R, N>, idxOrAfterMiddleware: number): any;
|
|
7
|
-
insertAfter(middleware: CommonMiddlewareUnion<T, R, N>, idxOrAfterMiddleware: CommonMiddlewareUnion<T, R, N>): any;
|
|
8
|
-
insertLast(middleware: CommonMiddlewareUnion<T, R, N>): void;
|
|
9
|
-
private findItemIndex;
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=middlewareManager.d.ts.map
|