@midwayjs/core 3.0.0-alpha.43 → 3.0.0-beta.10
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 +129 -0
- package/README.md +1 -1
- package/dist/baseFramework.d.ts +56 -22
- package/dist/baseFramework.js +156 -204
- 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 +14 -8
- 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/common/serviceFactory.d.ts +15 -0
- package/dist/{util → common}/serviceFactory.js +7 -5
- 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/common/webGenerator.js +114 -0
- package/dist/{util → common}/webRouterCollector.d.ts +9 -4
- package/dist/{util → common}/webRouterCollector.js +56 -29
- package/dist/config/config.default.d.ts +7 -0
- package/dist/config/config.default.js +28 -0
- package/dist/context/container.d.ts +46 -40
- package/dist/context/container.js +125 -104
- package/dist/context/managedResolverFactory.d.ts +3 -16
- package/dist/context/managedResolverFactory.js +77 -77
- package/dist/context/requestContainer.d.ts +0 -2
- package/dist/context/requestContainer.js +4 -18
- package/dist/definitions/functionDefinition.d.ts +3 -2
- package/dist/definitions/objectDefinition.d.ts +3 -2
- package/dist/definitions/properties.d.ts +2 -13
- package/dist/definitions/properties.js +3 -56
- package/dist/error/base.d.ts +13 -0
- package/dist/error/base.js +19 -0
- package/dist/error/code.d.ts +60 -0
- package/dist/error/code.js +65 -0
- package/dist/error/framework.d.ts +24 -0
- package/dist/error/framework.js +58 -0
- package/dist/error/http.d.ts +58 -0
- package/dist/error/http.js +82 -0
- package/dist/error/index.d.ts +4 -0
- package/dist/error/index.js +16 -0
- package/dist/functional/configuration.d.ts +3 -3
- package/dist/functional/configuration.js +3 -3
- package/dist/index.d.ts +24 -11
- package/dist/index.js +36 -14
- package/dist/interface.d.ts +252 -157
- package/dist/interface.js +9 -1
- package/dist/service/aspectService.d.ts +11 -14
- package/dist/service/aspectService.js +114 -170
- package/dist/service/configService.d.ts +10 -8
- package/dist/service/configService.js +56 -33
- package/dist/service/decoratorService.d.ts +23 -0
- package/dist/service/decoratorService.js +149 -0
- package/dist/service/environmentService.js +13 -2
- package/dist/service/frameworkService.d.ts +26 -0
- package/dist/service/frameworkService.js +176 -0
- package/dist/service/informationService.d.ts +4 -7
- package/dist/service/informationService.js +39 -8
- package/dist/service/lifeCycleService.d.ts +14 -0
- package/dist/service/lifeCycleService.js +130 -0
- package/dist/service/loggerService.d.ts +27 -0
- package/dist/service/loggerService.js +132 -0
- package/dist/service/middlewareService.d.ts +11 -0
- package/dist/service/middlewareService.js +127 -0
- package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
- package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
- package/dist/setup.d.ts +4 -0
- package/dist/setup.js +119 -0
- package/dist/util/contextUtil.d.ts +1 -1
- package/dist/util/contextUtil.js +1 -1
- package/dist/util/index.d.ts +64 -0
- package/dist/util/index.js +192 -4
- package/dist/util/pathToRegexp.d.ts +17 -0
- package/dist/util/pathToRegexp.js +280 -0
- package/dist/util/webRouterParam.d.ts +2 -2
- package/dist/util/webRouterParam.js +19 -20
- package/package.json +9 -15
- package/dist/common/lodashWrap.d.ts +0 -9
- package/dist/common/lodashWrap.js +0 -18
- package/dist/common/notFoundError.d.ts +0 -8
- package/dist/common/notFoundError.js +0 -20
- package/dist/common/reflectTool.d.ts +0 -17
- package/dist/common/reflectTool.js +0 -83
- package/dist/context/resolverHandler.d.ts +0 -34
- package/dist/context/resolverHandler.js +0 -88
- package/dist/definitions/messageSource.d.ts +0 -13
- package/dist/definitions/messageSource.js +0 -74
- package/dist/definitions/resource.d.ts +0 -27
- package/dist/definitions/resource.js +0 -116
- package/dist/features/index.d.ts +0 -2
- package/dist/features/index.js +0 -3
- package/dist/logger.d.ts +0 -4
- package/dist/logger.js +0 -20
- package/dist/util/containerUtil.d.ts +0 -11
- package/dist/util/containerUtil.js +0 -26
- package/dist/util/emptyFramework.d.ts +0 -62
- package/dist/util/emptyFramework.js +0 -72
- package/dist/util/serviceFactory.d.ts +0 -15
package/dist/baseFramework.js
CHANGED
|
@@ -1,161 +1,87 @@
|
|
|
1
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
exports.BaseFramework = void 0;
|
|
4
13
|
const interface_1 = require("./interface");
|
|
5
14
|
const decorator_1 = require("@midwayjs/decorator");
|
|
6
15
|
const logger_1 = require("@midwayjs/logger");
|
|
7
|
-
const logger_2 = require("./logger");
|
|
8
16
|
const requestContainer_1 = require("./context/requestContainer");
|
|
9
|
-
const
|
|
17
|
+
const environmentService_1 = require("./service/environmentService");
|
|
18
|
+
const configService_1 = require("./service/configService");
|
|
10
19
|
const informationService_1 = require("./service/informationService");
|
|
11
|
-
const
|
|
20
|
+
const loggerService_1 = require("./service/loggerService");
|
|
21
|
+
const middlewareManager_1 = require("./common/middlewareManager");
|
|
22
|
+
const middlewareService_1 = require("./service/middlewareService");
|
|
23
|
+
const filterManager_1 = require("./common/filterManager");
|
|
24
|
+
const util = require("util");
|
|
25
|
+
const debug = util.debuglog('midway:debug');
|
|
12
26
|
class BaseFramework {
|
|
13
|
-
constructor() {
|
|
27
|
+
constructor(applicationContext) {
|
|
28
|
+
this.applicationContext = applicationContext;
|
|
14
29
|
this.defaultContext = {};
|
|
30
|
+
this.middlewareManager = this.createMiddlewareManager();
|
|
31
|
+
this.filterManager = this.createFilterManager();
|
|
32
|
+
this.composeMiddleware = null;
|
|
15
33
|
}
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
async init() {
|
|
35
|
+
var _a, _b, _c;
|
|
36
|
+
this.configurationOptions = (_a = this.configure()) !== null && _a !== void 0 ? _a : {};
|
|
18
37
|
this.BaseContextLoggerClass =
|
|
19
|
-
this.configurationOptions.ContextLoggerClass
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.
|
|
38
|
+
(_b = this.configurationOptions.ContextLoggerClass) !== null && _b !== void 0 ? _b : this.getDefaultContextLoggerClass();
|
|
39
|
+
this.ContextLoggerApplyLogger =
|
|
40
|
+
(_c = this.configurationOptions.ContextLoggerApplyLogger) !== null && _c !== void 0 ? _c : 'appLogger';
|
|
41
|
+
this.logger = this.loggerService.getLogger('coreLogger');
|
|
42
|
+
this.appLogger = this.loggerService.getLogger('appLogger');
|
|
23
43
|
return this;
|
|
24
44
|
}
|
|
45
|
+
isEnable() {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
25
48
|
async initialize(options) {
|
|
26
|
-
this.isMainFramework = options.isMainFramework;
|
|
27
|
-
this.configurationOptions = this.configurationOptions || {};
|
|
28
|
-
/**
|
|
29
|
-
* before create MidwayContainer instance,can change init parameters
|
|
30
|
-
*/
|
|
31
49
|
await this.beforeContainerInitialize(options);
|
|
32
|
-
/**
|
|
33
|
-
* initialize MidwayContainer instance
|
|
34
|
-
*/
|
|
35
50
|
await this.containerInitialize(options);
|
|
36
|
-
/**
|
|
37
|
-
* before container load directory and bind
|
|
38
|
-
*/
|
|
39
51
|
await this.afterContainerInitialize(options);
|
|
40
|
-
/**
|
|
41
|
-
* run container loadDirectoryLoad method to create object definition
|
|
42
|
-
*/
|
|
43
52
|
await this.containerDirectoryLoad(options);
|
|
44
|
-
/**
|
|
45
|
-
* after container load directory and bind
|
|
46
|
-
*/
|
|
47
53
|
await this.afterContainerDirectoryLoad(options);
|
|
48
54
|
/**
|
|
49
55
|
* Third party application initialization
|
|
50
56
|
*/
|
|
51
57
|
await this.applicationInitialize(options);
|
|
52
|
-
/**
|
|
53
|
-
* start container ready
|
|
54
|
-
*/
|
|
55
58
|
await this.containerReady(options);
|
|
56
|
-
if (this.isMainFramework !== undefined) {
|
|
57
|
-
// 多框架场景,由 bootstrap 执行后续流程
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* load extensions and lifeCycle
|
|
62
|
-
*/
|
|
63
|
-
await this.loadExtension();
|
|
64
|
-
/**
|
|
65
|
-
* after container refresh
|
|
66
|
-
*/
|
|
67
59
|
await this.afterContainerReady(options);
|
|
68
60
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
if (!this.appLogger) {
|
|
81
|
-
this.appLogger = (0, logger_2.createMidwayLogger)(this, 'logger', {
|
|
82
|
-
fileLogName: 'midway-app.log',
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async containerInitialize(options) {
|
|
87
|
-
/**
|
|
88
|
-
* initialize container
|
|
89
|
-
*/
|
|
90
|
-
if (options.applicationContext) {
|
|
91
|
-
this.applicationContext = options.applicationContext;
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this.applicationContext = (0, containerUtil_1.createDirectoryGlobContainer)({
|
|
95
|
-
baseDir: options.baseDir,
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
this.applicationContext.registerObject('baseDir', options.baseDir);
|
|
99
|
-
this.applicationContext.registerObject('appDir', options.appDir);
|
|
100
|
-
/**
|
|
101
|
-
* initialize base information
|
|
102
|
-
*/
|
|
103
|
-
await this.initializeInfo(options);
|
|
104
|
-
/**
|
|
105
|
-
* initialize framework logger
|
|
106
|
-
*/
|
|
107
|
-
await this.initializeLogger(options);
|
|
108
|
-
}
|
|
109
|
-
async containerDirectoryLoad(options) {
|
|
110
|
-
if (options.preloadModules && options.preloadModules.length) {
|
|
111
|
-
for (const preloadModule of options.preloadModules) {
|
|
112
|
-
this.applicationContext.bindClass(preloadModule);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// register app
|
|
116
|
-
this.applicationContext.registerDataHandler(decorator_1.APPLICATION_KEY, (key, meta) => {
|
|
117
|
-
var _a;
|
|
118
|
-
if (options.globalApplicationHandler) {
|
|
119
|
-
return ((_a = options.globalApplicationHandler(meta === null || meta === void 0 ? void 0 : meta.type)) !== null && _a !== void 0 ? _a : this.getApplication());
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
return this.getApplication();
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
// register logger
|
|
126
|
-
this.getApplicationContext().registerDataHandler(decorator_1.LOGGER_KEY, key => {
|
|
127
|
-
return this.getLogger(key);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated
|
|
63
|
+
*/
|
|
64
|
+
async containerInitialize(options) { }
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated
|
|
67
|
+
*/
|
|
68
|
+
async containerDirectoryLoad(options) { }
|
|
69
|
+
/**
|
|
70
|
+
* @deprecated
|
|
71
|
+
*/
|
|
130
72
|
async containerReady(options) {
|
|
131
73
|
if (!this.app.getApplicationContext) {
|
|
132
74
|
this.defineApplicationProperties();
|
|
133
75
|
}
|
|
134
|
-
await this.applicationContext.ready();
|
|
135
|
-
}
|
|
136
|
-
async loadExtension() {
|
|
137
|
-
// 切面支持
|
|
138
|
-
await this.applicationContext.getAspectService().loadAspect();
|
|
139
|
-
// 预加载模块支持
|
|
140
|
-
await this.loadPreloadModule();
|
|
141
|
-
// lifecycle 支持
|
|
142
|
-
await this.loadLifeCycles();
|
|
143
|
-
}
|
|
144
|
-
async containerStop() {
|
|
145
|
-
await this.applicationContext.stop();
|
|
146
76
|
}
|
|
147
77
|
getApplicationContext() {
|
|
148
78
|
return this.applicationContext;
|
|
149
79
|
}
|
|
150
80
|
getConfiguration(key) {
|
|
151
|
-
return this.
|
|
152
|
-
.getConfigService()
|
|
153
|
-
.getConfiguration(key);
|
|
81
|
+
return this.configService.getConfiguration(key);
|
|
154
82
|
}
|
|
155
83
|
getCurrentEnvironment() {
|
|
156
|
-
return this.
|
|
157
|
-
.getEnvironmentService()
|
|
158
|
-
.getCurrentEnvironment();
|
|
84
|
+
return this.environmentService.getCurrentEnvironment();
|
|
159
85
|
}
|
|
160
86
|
getApplication() {
|
|
161
87
|
return this.app;
|
|
@@ -164,44 +90,34 @@ class BaseFramework {
|
|
|
164
90
|
this.BaseContextLoggerClass = BaseContextLogger;
|
|
165
91
|
}
|
|
166
92
|
createContextLogger(ctx, name) {
|
|
167
|
-
const appLogger = this.getLogger(name);
|
|
93
|
+
const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.ContextLoggerApplyLogger);
|
|
168
94
|
return new this.BaseContextLoggerClass(ctx, appLogger);
|
|
169
95
|
}
|
|
170
96
|
async stop() {
|
|
171
97
|
await this.beforeStop();
|
|
172
|
-
if (this.isMainFramework === true || this.isMainFramework === undefined) {
|
|
173
|
-
await this.stopLifeCycles();
|
|
174
|
-
await this.containerStop();
|
|
175
|
-
}
|
|
176
98
|
}
|
|
177
99
|
getAppDir() {
|
|
178
|
-
return this.
|
|
100
|
+
return this.informationService.getAppDir();
|
|
179
101
|
}
|
|
180
102
|
getBaseDir() {
|
|
181
|
-
return this.
|
|
103
|
+
return this.informationService.getBaseDir();
|
|
182
104
|
}
|
|
183
105
|
defineApplicationProperties(applicationProperties = {}, whiteList = []) {
|
|
184
106
|
const defaultApplicationProperties = {
|
|
185
107
|
getBaseDir: () => {
|
|
186
|
-
return this.
|
|
187
|
-
.getInformationService()
|
|
188
|
-
.getBaseDir();
|
|
108
|
+
return this.getBaseDir();
|
|
189
109
|
},
|
|
190
110
|
getAppDir: () => {
|
|
191
|
-
return this.
|
|
111
|
+
return this.getAppDir();
|
|
192
112
|
},
|
|
193
113
|
getEnv: () => {
|
|
194
|
-
return this.
|
|
195
|
-
.getEnvironmentService()
|
|
196
|
-
.getCurrentEnvironment();
|
|
114
|
+
return this.getCurrentEnvironment();
|
|
197
115
|
},
|
|
198
116
|
getApplicationContext: () => {
|
|
199
117
|
return this.getApplicationContext();
|
|
200
118
|
},
|
|
201
119
|
getConfig: (key) => {
|
|
202
|
-
return this.
|
|
203
|
-
.getConfigService()
|
|
204
|
-
.getConfiguration(key);
|
|
120
|
+
return this.getConfiguration(key);
|
|
205
121
|
},
|
|
206
122
|
getFrameworkType: () => {
|
|
207
123
|
return this.getFrameworkType();
|
|
@@ -238,20 +154,35 @@ class BaseFramework {
|
|
|
238
154
|
return this.createContextLogger(ctx, name);
|
|
239
155
|
};
|
|
240
156
|
}
|
|
157
|
+
ctx.setAttr = (key, value) => {
|
|
158
|
+
ctx.requestContext.setAttr(key, value);
|
|
159
|
+
};
|
|
160
|
+
ctx.getAttr = (key) => {
|
|
161
|
+
return ctx.requestContext.getAttr(key);
|
|
162
|
+
};
|
|
241
163
|
return ctx;
|
|
242
164
|
},
|
|
243
165
|
setContextLoggerClass: (BaseContextLogger) => {
|
|
244
166
|
return this.setContextLoggerClass(BaseContextLogger);
|
|
245
167
|
},
|
|
246
|
-
addConfigObject(obj) {
|
|
247
|
-
this.
|
|
168
|
+
addConfigObject: (obj) => {
|
|
169
|
+
this.configService.addObject(obj);
|
|
248
170
|
},
|
|
249
|
-
setAttr(key, value) {
|
|
171
|
+
setAttr: (key, value) => {
|
|
250
172
|
this.getApplicationContext().setAttr(key, value);
|
|
251
173
|
},
|
|
252
|
-
getAttr(key) {
|
|
174
|
+
getAttr: (key) => {
|
|
253
175
|
return this.getApplicationContext().getAttr(key);
|
|
254
176
|
},
|
|
177
|
+
useMiddleware: (middleware) => {
|
|
178
|
+
return this.useMiddleware(middleware);
|
|
179
|
+
},
|
|
180
|
+
getMiddleware: () => {
|
|
181
|
+
return this.getMiddleware();
|
|
182
|
+
},
|
|
183
|
+
useFilter: (Filter) => {
|
|
184
|
+
return this.useFilter(Filter);
|
|
185
|
+
},
|
|
255
186
|
};
|
|
256
187
|
for (const method of whiteList) {
|
|
257
188
|
delete defaultApplicationProperties[method];
|
|
@@ -259,94 +190,115 @@ class BaseFramework {
|
|
|
259
190
|
Object.assign(this.app, defaultApplicationProperties, applicationProperties);
|
|
260
191
|
}
|
|
261
192
|
async beforeStop() { }
|
|
193
|
+
/**
|
|
194
|
+
* @deprecated
|
|
195
|
+
*/
|
|
262
196
|
async beforeContainerInitialize(options) { }
|
|
197
|
+
/**
|
|
198
|
+
* @deprecated
|
|
199
|
+
*/
|
|
263
200
|
async afterContainerInitialize(options) { }
|
|
201
|
+
/**
|
|
202
|
+
* @deprecated
|
|
203
|
+
*/
|
|
264
204
|
async afterContainerDirectoryLoad(options) { }
|
|
205
|
+
/**
|
|
206
|
+
* @deprecated
|
|
207
|
+
*/
|
|
265
208
|
async afterContainerReady(options) { }
|
|
266
|
-
async
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
274
|
-
// 函数式写法
|
|
275
|
-
cycle.instance = cycle.target;
|
|
276
|
-
}
|
|
277
|
-
else {
|
|
278
|
-
// 普通类写法
|
|
279
|
-
const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
|
|
280
|
-
if (this.getApplicationContext().registry.hasDefinition(providerId)) {
|
|
281
|
-
cycle.instance =
|
|
282
|
-
await this.getApplicationContext().getAsync(providerId);
|
|
209
|
+
async applyMiddleware(lastMiddleware) {
|
|
210
|
+
if (!this.composeMiddleware) {
|
|
211
|
+
this.middlewareManager.insertFirst((async (ctx, next) => {
|
|
212
|
+
let returnResult = undefined;
|
|
213
|
+
try {
|
|
214
|
+
const result = await next();
|
|
215
|
+
returnResult = await this.filterManager.runResultFilter(result, ctx);
|
|
283
216
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
// exec onConfigLoad()
|
|
288
|
-
for (const cycle of lifecycleInstanceList) {
|
|
289
|
-
if (typeof cycle.instance.onConfigLoad === 'function') {
|
|
290
|
-
const configData = await cycle.instance.onConfigLoad(this.getApplicationContext());
|
|
291
|
-
if (configData) {
|
|
292
|
-
this.getApplicationContext().getConfigService().addObject(configData);
|
|
217
|
+
catch (err) {
|
|
218
|
+
returnResult = await this.filterManager.runErrorFilter(err, ctx);
|
|
293
219
|
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
220
|
+
if (returnResult.error) {
|
|
221
|
+
throw returnResult.error;
|
|
222
|
+
}
|
|
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);
|
|
300
228
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
|
|
304
|
-
for (const cycle of cycles) {
|
|
305
|
-
let inst;
|
|
306
|
-
if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
|
|
307
|
-
// 函数式写法
|
|
308
|
-
inst = cycle.target;
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
const providerId = (0, decorator_1.getProviderUUId)(cycle.target);
|
|
312
|
-
inst = await this.applicationContext.getAsync(providerId);
|
|
313
|
-
}
|
|
314
|
-
if (inst.onStop && typeof inst.onStop === 'function') {
|
|
315
|
-
await inst.onStop(this.getApplicationContext(), this.app);
|
|
316
|
-
}
|
|
229
|
+
if (lastMiddleware) {
|
|
230
|
+
return await this.middlewareService.compose([this.composeMiddleware, lastMiddleware], this.app);
|
|
317
231
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
* load preload module for container
|
|
321
|
-
* @private
|
|
322
|
-
*/
|
|
323
|
-
async loadPreloadModule() {
|
|
324
|
-
// some common decorator implementation
|
|
325
|
-
const modules = (0, decorator_1.listPreloadModule)();
|
|
326
|
-
for (const module of modules) {
|
|
327
|
-
// preload init context
|
|
328
|
-
await this.applicationContext.getAsync(module);
|
|
232
|
+
else {
|
|
233
|
+
return this.composeMiddleware;
|
|
329
234
|
}
|
|
330
235
|
}
|
|
331
236
|
getLogger(name) {
|
|
332
237
|
var _a;
|
|
333
|
-
return (_a =
|
|
238
|
+
return (_a = this.loggerService.getLogger(name)) !== null && _a !== void 0 ? _a : this.appLogger;
|
|
334
239
|
}
|
|
335
240
|
getCoreLogger() {
|
|
336
241
|
return this.logger;
|
|
337
242
|
}
|
|
338
243
|
createLogger(name, option = {}) {
|
|
339
|
-
return
|
|
244
|
+
return this.loggerService.createLogger(name, option);
|
|
340
245
|
}
|
|
341
246
|
getProjectName() {
|
|
342
|
-
return this.
|
|
247
|
+
return this.informationService.getProjectName();
|
|
343
248
|
}
|
|
344
249
|
getFrameworkName() {
|
|
345
|
-
return this.getFrameworkType().
|
|
250
|
+
return this.getFrameworkType().name;
|
|
346
251
|
}
|
|
347
252
|
getDefaultContextLoggerClass() {
|
|
348
253
|
return logger_1.MidwayContextLogger;
|
|
349
254
|
}
|
|
255
|
+
useMiddleware(Middleware) {
|
|
256
|
+
this.middlewareManager.insertLast(Middleware);
|
|
257
|
+
}
|
|
258
|
+
getMiddleware() {
|
|
259
|
+
return this.middlewareManager;
|
|
260
|
+
}
|
|
261
|
+
useFilter(Filter) {
|
|
262
|
+
return this.filterManager.useFilter(Filter);
|
|
263
|
+
}
|
|
264
|
+
createMiddlewareManager() {
|
|
265
|
+
return new middlewareManager_1.ContextMiddlewareManager();
|
|
266
|
+
}
|
|
267
|
+
createFilterManager() {
|
|
268
|
+
return new filterManager_1.FilterManager();
|
|
269
|
+
}
|
|
350
270
|
}
|
|
271
|
+
__decorate([
|
|
272
|
+
(0, decorator_1.Inject)(),
|
|
273
|
+
__metadata("design:type", loggerService_1.MidwayLoggerService)
|
|
274
|
+
], BaseFramework.prototype, "loggerService", void 0);
|
|
275
|
+
__decorate([
|
|
276
|
+
(0, decorator_1.Inject)(),
|
|
277
|
+
__metadata("design:type", environmentService_1.MidwayEnvironmentService)
|
|
278
|
+
], BaseFramework.prototype, "environmentService", void 0);
|
|
279
|
+
__decorate([
|
|
280
|
+
(0, decorator_1.Inject)(),
|
|
281
|
+
__metadata("design:type", configService_1.MidwayConfigService)
|
|
282
|
+
], BaseFramework.prototype, "configService", void 0);
|
|
283
|
+
__decorate([
|
|
284
|
+
(0, decorator_1.Inject)(),
|
|
285
|
+
__metadata("design:type", informationService_1.MidwayInformationService)
|
|
286
|
+
], BaseFramework.prototype, "informationService", void 0);
|
|
287
|
+
__decorate([
|
|
288
|
+
(0, decorator_1.Inject)(),
|
|
289
|
+
__metadata("design:type", middlewareService_1.MidwayMiddlewareService)
|
|
290
|
+
], BaseFramework.prototype, "middlewareService", void 0);
|
|
291
|
+
__decorate([
|
|
292
|
+
(0, decorator_1.Init)(),
|
|
293
|
+
__metadata("design:type", Function),
|
|
294
|
+
__metadata("design:paramtypes", []),
|
|
295
|
+
__metadata("design:returntype", Promise)
|
|
296
|
+
], BaseFramework.prototype, "init", null);
|
|
297
|
+
__decorate([
|
|
298
|
+
(0, decorator_1.Destroy)(),
|
|
299
|
+
__metadata("design:type", Function),
|
|
300
|
+
__metadata("design:paramtypes", []),
|
|
301
|
+
__metadata("design:returntype", Promise)
|
|
302
|
+
], BaseFramework.prototype, "stop", null);
|
|
351
303
|
exports.BaseFramework = BaseFramework;
|
|
352
304
|
//# sourceMappingURL=baseFramework.js.map
|
|
@@ -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
|
|
@@ -29,7 +29,6 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
29
29
|
this.directoryFilterArray = [];
|
|
30
30
|
}
|
|
31
31
|
run(container) {
|
|
32
|
-
const debugLogger = container.getDebugLogger();
|
|
33
32
|
const loadDirs = [].concat(this.options.loadDir || []);
|
|
34
33
|
for (const dir of loadDirs) {
|
|
35
34
|
const fileResults = (0, glob_1.run)(DEFAULT_PATTERN.concat(this.options.pattern || []), {
|
|
@@ -37,8 +36,6 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
37
36
|
ignore: DEFAULT_IGNORE_PATTERN.concat(this.options.ignore || []),
|
|
38
37
|
});
|
|
39
38
|
for (const file of fileResults) {
|
|
40
|
-
debugLogger(`\nmain:*********** binding "${file}" ***********`);
|
|
41
|
-
debugLogger(` namespace => "${this.options.namespace}"`);
|
|
42
39
|
if (this.directoryFilterArray.length) {
|
|
43
40
|
for (const resolveFilter of this.directoryFilterArray) {
|
|
44
41
|
if (typeof resolveFilter.pattern === 'string') {
|
|
@@ -61,15 +58,21 @@ class DirectoryFileDetector extends AbstractFileDetector {
|
|
|
61
58
|
}
|
|
62
59
|
const exports = require(file);
|
|
63
60
|
// add module to set
|
|
64
|
-
container.bindClass(exports,
|
|
65
|
-
|
|
61
|
+
container.bindClass(exports, {
|
|
62
|
+
namespace: this.options.namespace,
|
|
63
|
+
srcPath: file,
|
|
64
|
+
createFrom: 'file',
|
|
65
|
+
});
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
69
|
const exports = require(file);
|
|
70
70
|
// add module to set
|
|
71
|
-
container.bindClass(exports,
|
|
72
|
-
|
|
71
|
+
container.bindClass(exports, {
|
|
72
|
+
namespace: this.options.namespace,
|
|
73
|
+
srcPath: file,
|
|
74
|
+
createFrom: 'file',
|
|
75
|
+
});
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
}
|
|
@@ -79,7 +82,10 @@ exports.DirectoryFileDetector = DirectoryFileDetector;
|
|
|
79
82
|
class CustomModuleDetector extends AbstractFileDetector {
|
|
80
83
|
run(container) {
|
|
81
84
|
for (const module of this.options.modules) {
|
|
82
|
-
container.bindClass(module,
|
|
85
|
+
container.bindClass(module, {
|
|
86
|
+
namespace: this.options.namespace,
|
|
87
|
+
createFrom: 'module',
|
|
88
|
+
});
|
|
83
89
|
}
|
|
84
90
|
}
|
|
85
91
|
}
|
|
@@ -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
|