@midwayjs/core 3.0.0-beta.1 → 3.0.0-beta.13
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 +138 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +13 -10
- package/dist/baseFramework.js +32 -23
- package/dist/common/applicationManager.d.ts +12 -0
- package/dist/common/applicationManager.js +66 -0
- 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 +68 -0
- package/dist/common/middlewareManager.js +183 -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/common/webGenerator.d.ts +16 -0
- package/dist/{util → common}/webGenerator.js +36 -51
- package/dist/{util → common}/webRouterCollector.d.ts +9 -4
- package/dist/{util → common}/webRouterCollector.js +53 -29
- package/dist/config/config.default.d.ts +3 -17
- package/dist/context/container.js +13 -2
- package/dist/context/managedResolverFactory.js +5 -5
- package/dist/definitions/objectCreator.js +3 -2
- package/dist/error/base.d.ts +24 -3
- package/dist/error/base.js +34 -4
- package/dist/error/framework.d.ts +26 -2
- package/dist/error/framework.js +48 -10
- package/dist/error/http.d.ts +145 -38
- package/dist/error/http.js +162 -30
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +1 -0
- package/dist/index.d.ts +9 -9
- package/dist/index.js +13 -11
- package/dist/interface.d.ts +59 -30
- package/dist/service/configService.js +4 -5
- package/dist/service/decoratorService.js +33 -25
- package/dist/service/frameworkService.d.ts +6 -4
- package/dist/service/frameworkService.js +26 -11
- package/dist/service/lifeCycleService.js +7 -5
- package/dist/service/loggerService.d.ts +1 -2
- package/dist/service/loggerService.js +1 -10
- package/dist/service/middlewareService.d.ts +3 -4
- package/dist/service/middlewareService.js +28 -46
- package/dist/setup.js +10 -2
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/index.d.ts +46 -0
- package/dist/util/index.js +150 -1
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +41 -22
- package/package.json +7 -7
- package/dist/error/code.d.ts +0 -59
- package/dist/error/code.js +0 -64
- 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/middlewareManager.js +0 -48
- package/dist/util/webGenerator.d.ts +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,144 @@
|
|
|
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
|
+
# [3.0.0-beta.13](https://github.com/midwayjs/midway/compare/v3.0.0-beta.12...v3.0.0-beta.13) (2021-12-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* 404 error ([#1465](https://github.com/midwayjs/midway/issues/1465)) ([e7e8a9d](https://github.com/midwayjs/midway/commit/e7e8a9dedfa7198ac05b161b41024c2871f93965))
|
|
12
|
+
* add custom decorator filter ([#1477](https://github.com/midwayjs/midway/issues/1477)) ([97501a9](https://github.com/midwayjs/midway/commit/97501a989abc211b0c7400b1df45e050bb237c6a))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [3.0.0-beta.12](https://github.com/midwayjs/midway/compare/v3.0.0-beta.11...v3.0.0-beta.12) (2021-12-28)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Features
|
|
22
|
+
|
|
23
|
+
* custom error code & add @Files/@Fields ([#1438](https://github.com/midwayjs/midway/issues/1438)) ([b0032af](https://github.com/midwayjs/midway/commit/b0032afd2fa9ea0416fe69f4bd0c1a58bea5314e))
|
|
24
|
+
* support throw err status ([#1440](https://github.com/midwayjs/midway/issues/1440)) ([7b98110](https://github.com/midwayjs/midway/commit/7b98110d65c5287a8fcb3eb5356dea2d7a32cee9))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [3.0.0-beta.11](https://github.com/midwayjs/midway/compare/v3.0.0-beta.10...v3.0.0-beta.11) (2021-12-21)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @midwayjs/core
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [3.0.0-beta.10](https://github.com/midwayjs/midway/compare/v3.0.0-beta.9...v3.0.0-beta.10) (2021-12-20)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* default add session & bodyparser support for koa/express/faas ([#1420](https://github.com/midwayjs/midway/issues/1420)) ([cdaff31](https://github.com/midwayjs/midway/commit/cdaff317c3e862a95494a167995a28280af639bf))
|
|
44
|
+
* implement i18n for validate ([#1426](https://github.com/midwayjs/midway/issues/1426)) ([4c7ed2f](https://github.com/midwayjs/midway/commit/4c7ed2ff2e7ccf10f88f62abad230f92f5e76b97))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# [3.0.0-beta.9](https://github.com/midwayjs/midway/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2021-12-09)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Bug Fixes
|
|
54
|
+
|
|
55
|
+
* faas missing config in framework ([#1413](https://github.com/midwayjs/midway/issues/1413)) ([7ab16a2](https://github.com/midwayjs/midway/commit/7ab16a24b29d5254a762bfffcdf18385effdf639))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
# [3.0.0-beta.8](https://github.com/midwayjs/midway/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2021-12-08)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
### Bug Fixes
|
|
65
|
+
|
|
66
|
+
* express routing middleware takes effect at the controller level ([#1364](https://github.com/midwayjs/midway/issues/1364)) ([b9272e0](https://github.com/midwayjs/midway/commit/b9272e0971003443304b0c53815be31a0061b4bd))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# [3.0.0-beta.7](https://github.com/midwayjs/midway/compare/v3.0.0-beta.6...v3.0.0-beta.7) (2021-12-03)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
### Bug Fixes
|
|
76
|
+
|
|
77
|
+
* add app.keys ([#1395](https://github.com/midwayjs/midway/issues/1395)) ([c44afc6](https://github.com/midwayjs/midway/commit/c44afc6cc6764a959d1fa7ae04d60099282d156a))
|
|
78
|
+
* middleware with ctx.body ([#1389](https://github.com/midwayjs/midway/issues/1389)) ([77af5c0](https://github.com/midwayjs/midway/commit/77af5c0b456f1843f4dcfd3dbfd2c0aa244c51bd))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# [3.0.0-beta.6](https://github.com/midwayjs/midway/compare/v3.0.0-beta.5...v3.0.0-beta.6) (2021-11-26)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
### Bug Fixes
|
|
88
|
+
|
|
89
|
+
* class transformer method missing ([#1387](https://github.com/midwayjs/midway/issues/1387)) ([074e839](https://github.com/midwayjs/midway/commit/074e8393598dc95e2742f735df75a2191c5fe25d))
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
# [3.0.0-beta.5](https://github.com/midwayjs/midway/compare/v3.0.0-beta.4...v3.0.0-beta.5) (2021-11-25)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### Bug Fixes
|
|
99
|
+
|
|
100
|
+
* [@match](https://github.com/match) empty args ([#1384](https://github.com/midwayjs/midway/issues/1384)) ([6f90fc9](https://github.com/midwayjs/midway/commit/6f90fc993ff01e078288ff664833c61c02dede51))
|
|
101
|
+
* router sort ([#1383](https://github.com/midwayjs/midway/issues/1383)) ([f253887](https://github.com/midwayjs/midway/commit/f2538876d3eaf7dec55173d86b5b9caeeeb7be64))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
# [3.0.0-beta.4](https://github.com/midwayjs/midway/compare/v3.0.0-beta.3...v3.0.0-beta.4) (2021-11-24)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
### Bug Fixes
|
|
111
|
+
|
|
112
|
+
* logger close before bootstrap close ([#1370](https://github.com/midwayjs/midway/issues/1370)) ([6cc2720](https://github.com/midwayjs/midway/commit/6cc2720ed3445e8ffccc96d124b80ed7e2517f08))
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
### Features
|
|
116
|
+
|
|
117
|
+
* add i18n ([#1375](https://github.com/midwayjs/midway/issues/1375)) ([bffefe0](https://github.com/midwayjs/midway/commit/bffefe07afe45777d49b5a76b9ab17fc2b9d9a55))
|
|
118
|
+
* auto transform args to type ([#1372](https://github.com/midwayjs/midway/issues/1372)) ([bb3f7d2](https://github.com/midwayjs/midway/commit/bb3f7d2028a034e1926d9df554849332354c3762))
|
|
119
|
+
* support global prefix url ([#1371](https://github.com/midwayjs/midway/issues/1371)) ([cc5fe44](https://github.com/midwayjs/midway/commit/cc5fe44e1d221590562dc71e1f33ae96093e0da7))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
# [3.0.0-beta.3](https://github.com/midwayjs/midway/compare/v3.0.0-beta.2...v3.0.0-beta.3) (2021-11-18)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
### Features
|
|
129
|
+
|
|
130
|
+
* add component and framework config definition ([#1367](https://github.com/midwayjs/midway/issues/1367)) ([b2fe615](https://github.com/midwayjs/midway/commit/b2fe6157f99659471ff1333eca0b86bb889f61a3))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# [3.0.0-beta.2](https://github.com/midwayjs/midway/compare/v3.0.0-beta.1...v3.0.0-beta.2) (2021-11-16)
|
|
137
|
+
|
|
138
|
+
**Note:** Version bump only for package @midwayjs/core
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
6
144
|
# [3.0.0-beta.1](https://github.com/midwayjs/midway/compare/v2.12.4...v3.0.0-beta.1) (2021-11-14)
|
|
7
145
|
|
|
8
146
|
|
package/README.md
CHANGED
package/dist/baseFramework.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework,
|
|
1
|
+
import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, CommonMiddleware, MiddlewareRespond } from './interface';
|
|
2
2
|
import { FrameworkType } from '@midwayjs/decorator';
|
|
3
3
|
import { ILogger, LoggerOptions } from '@midwayjs/logger';
|
|
4
4
|
import { MidwayEnvironmentService } from './service/environmentService';
|
|
5
5
|
import { MidwayConfigService } from './service/configService';
|
|
6
6
|
import { MidwayInformationService } from './service/informationService';
|
|
7
7
|
import { MidwayLoggerService } from './service/loggerService';
|
|
8
|
-
import { ContextMiddlewareManager } from './
|
|
8
|
+
import { ContextMiddlewareManager } from './common/middlewareManager';
|
|
9
9
|
import { MidwayMiddlewareService } from './service/middlewareService';
|
|
10
|
-
import {
|
|
11
|
-
export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, OPT extends IConfigurationOptions> implements IMidwayFramework<APP, OPT> {
|
|
10
|
+
import { FilterManager } from './common/filterManager';
|
|
11
|
+
export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>, CTX extends IMidwayContext, OPT extends IConfigurationOptions, ResOrNext = unknown, Next = unknown> implements IMidwayFramework<APP, CTX, OPT, ResOrNext, Next> {
|
|
12
12
|
readonly applicationContext: IMidwayContainer;
|
|
13
13
|
app: APP;
|
|
14
14
|
configurationOptions: OPT;
|
|
@@ -17,14 +17,14 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
17
17
|
protected defaultContext: {};
|
|
18
18
|
protected BaseContextLoggerClass: any;
|
|
19
19
|
protected ContextLoggerApplyLogger: string;
|
|
20
|
-
protected middlewareManager: ContextMiddlewareManager<CTX,
|
|
21
|
-
protected
|
|
20
|
+
protected middlewareManager: ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
21
|
+
protected filterManager: FilterManager<CTX, ResOrNext, Next>;
|
|
22
22
|
protected composeMiddleware: any;
|
|
23
23
|
loggerService: MidwayLoggerService;
|
|
24
24
|
environmentService: MidwayEnvironmentService;
|
|
25
25
|
configService: MidwayConfigService;
|
|
26
26
|
informationService: MidwayInformationService;
|
|
27
|
-
middlewareService: MidwayMiddlewareService<CTX>;
|
|
27
|
+
middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
|
|
28
28
|
constructor(applicationContext: IMidwayContainer);
|
|
29
29
|
init(): Promise<this>;
|
|
30
30
|
abstract configure(options?: OPT): any;
|
|
@@ -72,14 +72,17 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
|
|
|
72
72
|
* @deprecated
|
|
73
73
|
*/
|
|
74
74
|
protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
|
|
75
|
-
|
|
75
|
+
applyMiddleware<R, N>(lastMiddleware?: CommonMiddleware<CTX, R, N>): Promise<MiddlewareRespond<CTX, R, N>>;
|
|
76
76
|
getLogger(name?: string): ILogger;
|
|
77
77
|
getCoreLogger(): ILogger;
|
|
78
78
|
createLogger(name: string, option?: LoggerOptions): ILogger;
|
|
79
79
|
getProjectName(): string;
|
|
80
80
|
getFrameworkName(): string;
|
|
81
81
|
getDefaultContextLoggerClass(): any;
|
|
82
|
-
useMiddleware(Middleware: CommonMiddlewareUnion<CTX>): void;
|
|
83
|
-
|
|
82
|
+
useMiddleware(Middleware: CommonMiddlewareUnion<CTX, ResOrNext, Next>): void;
|
|
83
|
+
getMiddleware(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
84
|
+
useFilter(Filter: CommonFilterUnion<CTX, ResOrNext, Next>): void;
|
|
85
|
+
protected createMiddlewareManager(): ContextMiddlewareManager<CTX, ResOrNext, Next>;
|
|
86
|
+
protected createFilterManager(): FilterManager<CTX, ResOrNext, Next>;
|
|
84
87
|
}
|
|
85
88
|
//# sourceMappingURL=baseFramework.d.ts.map
|
package/dist/baseFramework.js
CHANGED
|
@@ -18,15 +18,17 @@ const environmentService_1 = require("./service/environmentService");
|
|
|
18
18
|
const configService_1 = require("./service/configService");
|
|
19
19
|
const informationService_1 = require("./service/informationService");
|
|
20
20
|
const loggerService_1 = require("./service/loggerService");
|
|
21
|
-
const middlewareManager_1 = require("./
|
|
21
|
+
const middlewareManager_1 = require("./common/middlewareManager");
|
|
22
22
|
const middlewareService_1 = require("./service/middlewareService");
|
|
23
|
-
const
|
|
23
|
+
const filterManager_1 = require("./common/filterManager");
|
|
24
|
+
const util = require("util");
|
|
25
|
+
const debug = util.debuglog('midway:debug');
|
|
24
26
|
class BaseFramework {
|
|
25
27
|
constructor(applicationContext) {
|
|
26
28
|
this.applicationContext = applicationContext;
|
|
27
29
|
this.defaultContext = {};
|
|
28
|
-
this.middlewareManager =
|
|
29
|
-
this.
|
|
30
|
+
this.middlewareManager = this.createMiddlewareManager();
|
|
31
|
+
this.filterManager = this.createFilterManager();
|
|
30
32
|
this.composeMiddleware = null;
|
|
31
33
|
}
|
|
32
34
|
async init() {
|
|
@@ -173,13 +175,13 @@ class BaseFramework {
|
|
|
173
175
|
return this.getApplicationContext().getAttr(key);
|
|
174
176
|
},
|
|
175
177
|
useMiddleware: (middleware) => {
|
|
176
|
-
this.
|
|
178
|
+
return this.useMiddleware(middleware);
|
|
177
179
|
},
|
|
178
180
|
getMiddleware: () => {
|
|
179
|
-
return this.
|
|
181
|
+
return this.getMiddleware();
|
|
180
182
|
},
|
|
181
183
|
useFilter: (Filter) => {
|
|
182
|
-
this.
|
|
184
|
+
return this.useFilter(Filter);
|
|
183
185
|
},
|
|
184
186
|
};
|
|
185
187
|
for (const method of whiteList) {
|
|
@@ -204,30 +206,28 @@ class BaseFramework {
|
|
|
204
206
|
* @deprecated
|
|
205
207
|
*/
|
|
206
208
|
async afterContainerReady(options) { }
|
|
207
|
-
async
|
|
209
|
+
async applyMiddleware(lastMiddleware) {
|
|
208
210
|
if (!this.composeMiddleware) {
|
|
209
|
-
this.middlewareManager.insertFirst(async (ctx, next) => {
|
|
211
|
+
this.middlewareManager.insertFirst((async (ctx, next) => {
|
|
210
212
|
let returnResult = undefined;
|
|
211
213
|
try {
|
|
212
214
|
const result = await next();
|
|
213
|
-
returnResult =
|
|
214
|
-
result,
|
|
215
|
-
error: undefined,
|
|
216
|
-
};
|
|
215
|
+
returnResult = await this.filterManager.runResultFilter(result, ctx);
|
|
217
216
|
}
|
|
218
217
|
catch (err) {
|
|
219
|
-
returnResult = await this.
|
|
218
|
+
returnResult = await this.filterManager.runErrorFilter(err, ctx);
|
|
219
|
+
}
|
|
220
|
+
if (returnResult.error) {
|
|
221
|
+
throw returnResult.error;
|
|
220
222
|
}
|
|
221
|
-
return returnResult;
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
await this.
|
|
223
|
+
return returnResult.result;
|
|
224
|
+
}));
|
|
225
|
+
debug(`[core]: Compose middleware = [${this.middlewareManager.getNames()}]`);
|
|
226
|
+
this.composeMiddleware = await this.middlewareService.compose(this.middlewareManager, this.app);
|
|
227
|
+
await this.filterManager.init(this.applicationContext);
|
|
225
228
|
}
|
|
226
229
|
if (lastMiddleware) {
|
|
227
|
-
return await this.middlewareService.compose([
|
|
228
|
-
this.composeMiddleware,
|
|
229
|
-
lastMiddleware,
|
|
230
|
-
]);
|
|
230
|
+
return await this.middlewareService.compose([this.composeMiddleware, lastMiddleware], this.app);
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
233
|
return this.composeMiddleware;
|
|
@@ -255,8 +255,17 @@ class BaseFramework {
|
|
|
255
255
|
useMiddleware(Middleware) {
|
|
256
256
|
this.middlewareManager.insertLast(Middleware);
|
|
257
257
|
}
|
|
258
|
+
getMiddleware() {
|
|
259
|
+
return this.middlewareManager;
|
|
260
|
+
}
|
|
258
261
|
useFilter(Filter) {
|
|
259
|
-
this.
|
|
262
|
+
return this.filterManager.useFilter(Filter);
|
|
263
|
+
}
|
|
264
|
+
createMiddlewareManager() {
|
|
265
|
+
return new middlewareManager_1.ContextMiddlewareManager();
|
|
266
|
+
}
|
|
267
|
+
createFilterManager() {
|
|
268
|
+
return new filterManager_1.FilterManager();
|
|
260
269
|
}
|
|
261
270
|
}
|
|
262
271
|
__decorate([
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IMidwayApplication, IMidwayFramework } from '../interface';
|
|
2
|
+
import { FrameworkType } from '@midwayjs/decorator';
|
|
3
|
+
export declare class MidwayApplicationManager {
|
|
4
|
+
private globalFrameworkMap;
|
|
5
|
+
private globalFrameworkTypeMap;
|
|
6
|
+
addFramework(namespace: any, framework: IMidwayFramework<any, any, any>): void;
|
|
7
|
+
getFramework(namespaceOrFrameworkType: string | FrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
|
|
8
|
+
getApplication(namespaceOrFrameworkType: string | FrameworkType): IMidwayApplication;
|
|
9
|
+
getApplications(namespaces: Array<string | FrameworkType>): IMidwayApplication[];
|
|
10
|
+
getWebLikeApplication(): IMidwayApplication[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=applicationManager.d.ts.map
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.MidwayApplicationManager = void 0;
|
|
10
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
11
|
+
let MidwayApplicationManager = class MidwayApplicationManager {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.globalFrameworkMap = new Map();
|
|
14
|
+
this.globalFrameworkTypeMap = new WeakMap();
|
|
15
|
+
}
|
|
16
|
+
addFramework(namespace, framework) {
|
|
17
|
+
this.globalFrameworkMap.set(namespace, framework);
|
|
18
|
+
this.globalFrameworkTypeMap.set(framework.getFrameworkType(), framework);
|
|
19
|
+
}
|
|
20
|
+
getFramework(namespaceOrFrameworkType) {
|
|
21
|
+
if (typeof namespaceOrFrameworkType === 'string') {
|
|
22
|
+
if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {
|
|
23
|
+
return this.globalFrameworkMap.get(namespaceOrFrameworkType);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {
|
|
28
|
+
return this.globalFrameworkTypeMap.get(namespaceOrFrameworkType);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
getApplication(namespaceOrFrameworkType) {
|
|
33
|
+
if (typeof namespaceOrFrameworkType === 'string') {
|
|
34
|
+
if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {
|
|
35
|
+
return this.globalFrameworkMap
|
|
36
|
+
.get(namespaceOrFrameworkType)
|
|
37
|
+
.getApplication();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {
|
|
42
|
+
return this.globalFrameworkTypeMap
|
|
43
|
+
.get(namespaceOrFrameworkType)
|
|
44
|
+
.getApplication();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
getApplications(namespaces) {
|
|
49
|
+
return namespaces
|
|
50
|
+
.map(namespace => {
|
|
51
|
+
return this.getApplication(namespace);
|
|
52
|
+
})
|
|
53
|
+
.filter(app => {
|
|
54
|
+
return !!app;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
getWebLikeApplication() {
|
|
58
|
+
return this.getApplications(['express', 'koa', 'egg', 'faas']);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
MidwayApplicationManager = __decorate([
|
|
62
|
+
(0, decorator_1.Provide)(),
|
|
63
|
+
(0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
|
|
64
|
+
], MidwayApplicationManager);
|
|
65
|
+
exports.MidwayApplicationManager = MidwayApplicationManager;
|
|
66
|
+
//# sourceMappingURL=applicationManager.js.map
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { CommonFilterUnion, IMidwayContainer, IMidwayContext } from '../interface';
|
|
2
|
+
export declare class FilterManager<CTX extends IMidwayContext = IMidwayContext, R = any, N = any> {
|
|
3
|
+
private errFilterList;
|
|
4
|
+
private successFilterList;
|
|
5
|
+
private exceptionMap;
|
|
6
|
+
private defaultErrFilter;
|
|
7
|
+
private matchFnList;
|
|
8
|
+
useFilter(Filters: CommonFilterUnion<CTX, R, N>): void;
|
|
9
|
+
init(applicationContext: IMidwayContainer): Promise<void>;
|
|
10
|
+
runErrorFilter(err: Error, ctx: CTX, res?: R, next?: N): Promise<{
|
|
11
|
+
result: any;
|
|
12
|
+
error: any;
|
|
13
|
+
}>;
|
|
14
|
+
runResultFilter(result: any, ctx: CTX, res?: R, next?: N): Promise<{
|
|
15
|
+
result: any;
|
|
16
|
+
error: any;
|
|
17
|
+
}>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=filterManager.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterManager = void 0;
|
|
4
|
+
const decorator_1 = require("@midwayjs/decorator");
|
|
5
|
+
const util_1 = require("../util");
|
|
6
|
+
class FilterManager {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.errFilterList = [];
|
|
9
|
+
this.successFilterList = [];
|
|
10
|
+
this.exceptionMap = new WeakMap();
|
|
11
|
+
this.defaultErrFilter = undefined;
|
|
12
|
+
this.matchFnList = [];
|
|
13
|
+
}
|
|
14
|
+
useFilter(Filters) {
|
|
15
|
+
if (!Array.isArray(Filters)) {
|
|
16
|
+
Filters = [Filters];
|
|
17
|
+
}
|
|
18
|
+
for (const Filter of Filters) {
|
|
19
|
+
if ((0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, Filter)) {
|
|
20
|
+
this.errFilterList.push(Filter);
|
|
21
|
+
}
|
|
22
|
+
if ((0, decorator_1.getClassMetadata)(decorator_1.MATCH_KEY, Filter)) {
|
|
23
|
+
this.successFilterList.push(Filter);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async init(applicationContext) {
|
|
28
|
+
// for catch exception
|
|
29
|
+
for (const FilterClass of this.errFilterList) {
|
|
30
|
+
const filter = await applicationContext.getAsync(FilterClass);
|
|
31
|
+
const exceptionMetadata = (0, decorator_1.getClassMetadata)(decorator_1.CATCH_KEY, FilterClass);
|
|
32
|
+
if (exceptionMetadata && exceptionMetadata.catchTargets) {
|
|
33
|
+
for (const Exception of exceptionMetadata.catchTargets) {
|
|
34
|
+
this.exceptionMap.set(Exception, filter);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
// default filter
|
|
39
|
+
this.defaultErrFilter = filter;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// for success return
|
|
43
|
+
for (const FilterClass of this.successFilterList) {
|
|
44
|
+
const filter = await applicationContext.getAsync(FilterClass);
|
|
45
|
+
const matchMetadata = (0, decorator_1.getClassMetadata)(decorator_1.MATCH_KEY, FilterClass);
|
|
46
|
+
if (matchMetadata && matchMetadata.matchPattern) {
|
|
47
|
+
this.matchFnList.push({
|
|
48
|
+
matchFn: (0, util_1.toPathMatch)(matchMetadata.matchPattern),
|
|
49
|
+
target: filter,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async runErrorFilter(err, ctx, res, next) {
|
|
55
|
+
let result, error;
|
|
56
|
+
if (this.exceptionMap.has(err.constructor)) {
|
|
57
|
+
const filter = this.exceptionMap.get(err.constructor);
|
|
58
|
+
result = await filter.catch(err, ctx, res, next);
|
|
59
|
+
}
|
|
60
|
+
else if (this.defaultErrFilter) {
|
|
61
|
+
result = await this.defaultErrFilter.catch(err, ctx, res, next);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
error = err;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
result,
|
|
68
|
+
error,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async runResultFilter(result, ctx, res, next) {
|
|
72
|
+
let returnValue = result;
|
|
73
|
+
for (const matchData of this.matchFnList) {
|
|
74
|
+
if (matchData.matchFn(ctx, res)) {
|
|
75
|
+
returnValue = await matchData.target.match(returnValue, ctx, res, next);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
result: returnValue,
|
|
80
|
+
error: undefined,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.FilterManager = FilterManager;
|
|
85
|
+
//# sourceMappingURL=filterManager.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { CommonMiddleware, CommonMiddlewareUnion, IMidwayContext } from '../interface';
|
|
2
|
+
export declare class ContextMiddlewareManager<CTX extends IMidwayContext, R, N> extends Array<CommonMiddleware<CTX, R, N>> {
|
|
3
|
+
/**
|
|
4
|
+
* insert a middleware or middleware array to first
|
|
5
|
+
* @param middleware
|
|
6
|
+
*/
|
|
7
|
+
insertFirst(middleware: CommonMiddlewareUnion<CTX, R, N>): void;
|
|
8
|
+
/**
|
|
9
|
+
* insert a middleware or middleware array to last
|
|
10
|
+
* @param middleware
|
|
11
|
+
*/
|
|
12
|
+
insertLast(middleware: CommonMiddlewareUnion<CTX, R, N>): void;
|
|
13
|
+
/**
|
|
14
|
+
* insert a middleware or middleware array to after another middleware
|
|
15
|
+
* @param middleware
|
|
16
|
+
* @param idxOrBeforeMiddleware
|
|
17
|
+
*/
|
|
18
|
+
insertBefore(middleware: CommonMiddlewareUnion<CTX, R, N>, idxOrBeforeMiddleware: CommonMiddleware<CTX, R, N> | string | number): void;
|
|
19
|
+
/**
|
|
20
|
+
* insert a middleware or middleware array to after another middleware
|
|
21
|
+
* @param middleware
|
|
22
|
+
* @param idxOrAfterMiddleware
|
|
23
|
+
*/
|
|
24
|
+
insertAfter(middleware: CommonMiddlewareUnion<CTX, R, N>, idxOrAfterMiddleware: CommonMiddleware<CTX, R, N> | string | number): void;
|
|
25
|
+
/**
|
|
26
|
+
* move a middleware after another middleware
|
|
27
|
+
* @param middlewareOrName
|
|
28
|
+
* @param afterMiddleware
|
|
29
|
+
*/
|
|
30
|
+
findAndInsertAfter(middlewareOrName: CommonMiddleware<CTX, R, N> | string, afterMiddleware: CommonMiddleware<CTX, R, N> | string | number): void;
|
|
31
|
+
/**
|
|
32
|
+
* move a middleware before another middleware
|
|
33
|
+
* @param middlewareOrName
|
|
34
|
+
* @param beforeMiddleware
|
|
35
|
+
*/
|
|
36
|
+
findAndInsertBefore(middlewareOrName: CommonMiddleware<CTX, R, N> | string, beforeMiddleware: CommonMiddleware<CTX, R, N> | string | number): void;
|
|
37
|
+
/**
|
|
38
|
+
* find middleware and move to first
|
|
39
|
+
* @param middlewareOrName
|
|
40
|
+
*/
|
|
41
|
+
findAndInsertFirst(middlewareOrName: CommonMiddleware<CTX, R, N> | string): void;
|
|
42
|
+
/**
|
|
43
|
+
* find middleware and move to last
|
|
44
|
+
* @param middlewareOrName
|
|
45
|
+
*/
|
|
46
|
+
findAndInsertLast(middlewareOrName: CommonMiddleware<CTX, R, N> | string): void;
|
|
47
|
+
/**
|
|
48
|
+
* find a middleware and return index
|
|
49
|
+
* @param middlewareOrName
|
|
50
|
+
*/
|
|
51
|
+
findItemIndex(middlewareOrName: CommonMiddleware<CTX, R, N> | string | number): number;
|
|
52
|
+
findItem(middlewareOrName: CommonMiddleware<CTX, R, N> | string | number): CommonMiddleware<CTX, R, N>;
|
|
53
|
+
/**
|
|
54
|
+
* get name from middleware
|
|
55
|
+
* @param middleware
|
|
56
|
+
*/
|
|
57
|
+
getMiddlewareName(middleware: CommonMiddleware<CTX, R, N>): string;
|
|
58
|
+
/**
|
|
59
|
+
* remove a middleware
|
|
60
|
+
* @param middlewareOrNameOrIdx
|
|
61
|
+
*/
|
|
62
|
+
remove(middlewareOrNameOrIdx: CommonMiddleware<CTX, R, N> | string | number): CommonMiddleware<CTX, R, N>;
|
|
63
|
+
/**
|
|
64
|
+
* get middleware name list
|
|
65
|
+
*/
|
|
66
|
+
getNames(): string[];
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=middlewareManager.d.ts.map
|