@midwayjs/core 3.20.4 → 4.0.0-beta.1
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/baseFramework.d.ts +14 -39
- package/dist/baseFramework.js +19 -59
- package/dist/common/applicationManager.d.ts +6 -6
- package/dist/common/applicationManager.js +18 -35
- package/dist/common/asyncContextManager.d.ts +15 -0
- package/dist/common/asyncContextManager.js +51 -2
- package/dist/common/dataListener.d.ts +5 -3
- package/dist/common/dataListener.js +13 -4
- package/dist/common/dataSourceManager.d.ts +18 -9
- package/dist/common/dataSourceManager.js +121 -72
- package/dist/common/fileDetector.d.ts +9 -9
- package/dist/common/fileDetector.js +30 -28
- package/dist/common/filterManager.js +5 -4
- package/dist/common/guardManager.js +3 -2
- package/dist/common/middlewareManager.js +4 -3
- package/dist/common/performanceManager.js +1 -1
- package/dist/common/priorityManager.js +2 -2
- package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
- package/dist/common/serviceDiscovery/healthCheck.js +207 -0
- package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
- package/dist/common/serviceDiscovery/loadBalancer.js +51 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
- package/dist/common/serviceDiscovery/serviceDiscovery.js +104 -0
- package/dist/common/serviceFactory.d.ts +5 -2
- package/dist/common/serviceFactory.js +44 -9
- package/dist/common/webGenerator.js +4 -6
- package/dist/config/config.default.js +4 -1
- package/dist/constants.d.ts +2 -32
- package/dist/constants.js +3 -33
- package/dist/context/componentLoader.d.ts +20 -0
- package/dist/context/componentLoader.js +193 -0
- package/dist/context/container.d.ts +18 -32
- package/dist/context/container.js +74 -308
- package/dist/context/definitionRegistry.d.ts +5 -0
- package/dist/context/definitionRegistry.js +17 -26
- package/dist/context/dynamicContainer.d.ts +17 -0
- package/dist/context/dynamicContainer.js +202 -0
- package/dist/context/managedResolverFactory.d.ts +15 -41
- package/dist/context/managedResolverFactory.js +271 -349
- package/dist/context/requestContainer.d.ts +23 -12
- package/dist/context/requestContainer.js +46 -51
- package/dist/decorator/common/aspect.js +4 -4
- package/dist/decorator/common/autoload.js +1 -1
- package/dist/decorator/common/configuration.d.ts +1 -24
- package/dist/decorator/common/configuration.js +6 -1
- package/dist/decorator/common/filter.js +6 -6
- package/dist/decorator/common/framework.d.ts +46 -3
- package/dist/decorator/common/framework.js +43 -9
- package/dist/decorator/common/guard.js +4 -9
- package/dist/decorator/common/inject.d.ts +4 -2
- package/dist/decorator/common/inject.js +87 -4
- package/dist/decorator/common/mock.js +1 -1
- package/dist/decorator/common/objectDef.d.ts +0 -5
- package/dist/decorator/common/objectDef.js +8 -20
- package/dist/decorator/common/provide.d.ts +1 -1
- package/dist/decorator/common/provide.js +1 -1
- package/dist/decorator/common/scope.d.ts +6 -0
- package/dist/decorator/common/scope.js +21 -0
- package/dist/decorator/constant.d.ts +14 -17
- package/dist/decorator/constant.js +23 -35
- package/dist/decorator/decoratorManager.d.ts +21 -294
- package/dist/decorator/decoratorManager.js +127 -694
- package/dist/decorator/faas/serverlessTrigger.js +5 -5
- package/dist/decorator/index.d.ts +2 -3
- package/dist/decorator/index.js +6 -4
- package/dist/decorator/metadataManager.d.ts +131 -0
- package/dist/decorator/metadataManager.js +465 -0
- package/dist/decorator/microservice/consumer.js +3 -2
- package/dist/decorator/microservice/kafkaListener.js +2 -1
- package/dist/decorator/microservice/provider.js +6 -5
- package/dist/decorator/microservice/rabbitmqListener.js +2 -1
- package/dist/decorator/task/queue.js +3 -2
- package/dist/decorator/task/schedule.js +3 -2
- package/dist/decorator/task/task.js +4 -3
- package/dist/decorator/task/taskLocal.js +4 -3
- package/dist/decorator/web/controller.js +3 -2
- package/dist/decorator/web/paramMapping.js +2 -2
- package/dist/decorator/web/requestMapping.js +5 -5
- package/dist/decorator/web/response.js +6 -5
- package/dist/decorator/ws/webSocketController.js +3 -2
- package/dist/decorator/ws/webSocketEvent.js +7 -6
- package/dist/definitions/functionDefinition.d.ts +3 -3
- package/dist/definitions/functionDefinition.js +12 -11
- package/dist/definitions/objectCreator.d.ts +5 -11
- package/dist/definitions/objectCreator.js +6 -28
- package/dist/definitions/objectDefinition.d.ts +2 -3
- package/dist/definitions/objectDefinition.js +1 -3
- package/dist/error/base.js +2 -2
- package/dist/error/framework.d.ts +2 -9
- package/dist/error/framework.js +13 -27
- package/dist/error/http.js +1 -1
- package/dist/functional/configuration.d.ts +14 -15
- package/dist/functional/configuration.js +37 -47
- package/dist/functional/hooks.d.ts +12 -0
- package/dist/functional/hooks.js +78 -0
- package/dist/functional/index.d.ts +3 -0
- package/dist/functional/index.js +22 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +10 -7
- package/dist/interface.d.ts +261 -137
- package/dist/interface.js +23 -33
- package/dist/legacy/constants.d.ts +29 -0
- package/dist/legacy/constants.js +33 -0
- package/dist/legacy/decorator.d.ts +255 -0
- package/dist/legacy/decorator.js +468 -0
- package/dist/legacy/index.d.ts +3 -0
- package/dist/legacy/index.js +19 -0
- package/dist/legacy/types.d.ts +2 -0
- package/dist/legacy/types.js +3 -0
- package/dist/service/aspectService.js +11 -12
- package/dist/service/configService.d.ts +1 -1
- package/dist/service/configService.js +5 -4
- package/dist/service/decoratorService.d.ts +3 -3
- package/dist/service/decoratorService.js +14 -10
- package/dist/service/environmentService.js +2 -2
- package/dist/service/frameworkService.d.ts +5 -4
- package/dist/service/frameworkService.js +30 -28
- package/dist/service/healthService.d.ts +2 -0
- package/dist/service/healthService.js +19 -8
- package/dist/service/informationService.d.ts +3 -0
- package/dist/service/informationService.js +13 -4
- package/dist/service/lifeCycleService.d.ts +13 -7
- package/dist/service/lifeCycleService.js +54 -48
- package/dist/service/loggerService.js +3 -4
- package/dist/service/middlewareService.js +7 -8
- package/dist/service/mockService.js +9 -15
- package/dist/service/slsFunctionService.d.ts +1 -14
- package/dist/service/slsFunctionService.js +33 -81
- package/dist/service/webRouterService.js +11 -11
- package/dist/setup.d.ts +5 -5
- package/dist/setup.js +83 -94
- package/dist/util/contextUtil.d.ts +2 -2
- package/dist/util/httpclient.d.ts +2 -2
- package/dist/util/index.d.ts +16 -17
- package/dist/util/index.js +153 -78
- package/dist/util/network.d.ts +10 -0
- package/dist/util/network.js +40 -0
- package/dist/util/pathFileUtil.d.ts +15 -2
- package/dist/util/pathFileUtil.js +27 -6
- package/dist/util/timeout.d.ts +57 -0
- package/dist/util/timeout.js +144 -0
- package/dist/util/webRouterParam.js +2 -2
- package/package.json +24 -6
- package/dist/decorator/common/pipeline.d.ts +0 -3
- package/dist/decorator/common/pipeline.js +0 -12
- package/dist/decorator/rpc/hsf.d.ts +0 -13
- package/dist/decorator/rpc/hsf.js +0 -20
- package/dist/definitions/properties.d.ts +0 -7
- package/dist/definitions/properties.js +0 -19
- package/dist/service/pipelineService.d.ts +0 -168
- package/dist/service/pipelineService.js +0 -254
package/dist/setup.js
CHANGED
|
@@ -3,16 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.prepareGlobalApplicationContext = exports.prepareGlobalApplicationContextAsync = exports.destroyGlobalApplicationContext = exports.initializeGlobalApplicationContext = void 0;
|
|
4
4
|
const _1 = require("./");
|
|
5
5
|
const config_default_1 = require("./config/config.default");
|
|
6
|
-
const decorator_1 = require("./decorator");
|
|
7
6
|
const util = require("util");
|
|
8
7
|
const slsFunctionService_1 = require("./service/slsFunctionService");
|
|
9
|
-
const path_1 = require("path");
|
|
10
8
|
const healthService_1 = require("./service/healthService");
|
|
9
|
+
const componentLoader_1 = require("./context/componentLoader");
|
|
10
|
+
const util_1 = require("./util");
|
|
11
|
+
const asyncContextManager_1 = require("./common/asyncContextManager");
|
|
11
12
|
const performanceManager_1 = require("./common/performanceManager");
|
|
12
13
|
const debug = util.debuglog('midway:debug');
|
|
13
14
|
let stepIdx = 1;
|
|
15
|
+
let projectIdx = 1;
|
|
14
16
|
function printStepDebugInfo(stepInfo) {
|
|
15
|
-
debug(`\n\
|
|
17
|
+
debug(`\n\nProject ${projectIdx} - Step ${stepIdx++}: ${stepInfo}\n`);
|
|
16
18
|
}
|
|
17
19
|
/**
|
|
18
20
|
* midway framework main entry, this method bootstrap all service and framework.
|
|
@@ -51,12 +53,12 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
51
53
|
applicationContext,
|
|
52
54
|
]);
|
|
53
55
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.LIFECYCLE_PREPARE);
|
|
54
|
-
printStepDebugInfo('Init
|
|
56
|
+
printStepDebugInfo('Init pre-start modules');
|
|
55
57
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.PRELOAD_MODULE_PREPARE);
|
|
56
|
-
// some
|
|
57
|
-
const modules =
|
|
58
|
+
// some pre-start module init
|
|
59
|
+
const modules = _1.DecoratorManager.listPreStartModule();
|
|
58
60
|
for (const module of modules) {
|
|
59
|
-
//
|
|
61
|
+
// pre-start init context
|
|
60
62
|
await applicationContext.getAsync(module);
|
|
61
63
|
}
|
|
62
64
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.PRELOAD_MODULE_PREPARE);
|
|
@@ -66,18 +68,25 @@ async function initializeGlobalApplicationContext(globalOptions) {
|
|
|
66
68
|
}
|
|
67
69
|
exports.initializeGlobalApplicationContext = initializeGlobalApplicationContext;
|
|
68
70
|
async function destroyGlobalApplicationContext(applicationContext) {
|
|
71
|
+
printStepDebugInfo('Ready to destroy applicationContext');
|
|
69
72
|
const loggerService = await applicationContext.getAsync(_1.MidwayLoggerService);
|
|
70
73
|
const loggerFactory = loggerService.getCurrentLoggerFactory();
|
|
74
|
+
printStepDebugInfo('Stopping lifecycle');
|
|
71
75
|
// stop lifecycle
|
|
72
76
|
const lifecycleService = await applicationContext.getAsync(_1.MidwayLifeCycleService);
|
|
73
77
|
await lifecycleService.stop();
|
|
78
|
+
printStepDebugInfo('Stopping applicationContext');
|
|
74
79
|
// stop container
|
|
75
80
|
await applicationContext.stop();
|
|
76
|
-
(
|
|
81
|
+
printStepDebugInfo('Closing loggerFactory');
|
|
77
82
|
loggerFactory.close();
|
|
83
|
+
printStepDebugInfo('Cleaning performance manager');
|
|
78
84
|
performanceManager_1.MidwayPerformanceManager.cleanAll();
|
|
79
85
|
global['MIDWAY_APPLICATION_CONTEXT'] = undefined;
|
|
80
86
|
global['MIDWAY_MAIN_FRAMEWORK'] = undefined;
|
|
87
|
+
// reset counter
|
|
88
|
+
stepIdx = 1;
|
|
89
|
+
projectIdx++;
|
|
81
90
|
}
|
|
82
91
|
exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
83
92
|
/**
|
|
@@ -85,22 +94,22 @@ exports.destroyGlobalApplicationContext = destroyGlobalApplicationContext;
|
|
|
85
94
|
* @param globalOptions
|
|
86
95
|
*/
|
|
87
96
|
async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
88
|
-
var _a, _b, _c, _d, _e;
|
|
89
97
|
printStepDebugInfo('Ready to create applicationContext');
|
|
90
98
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
91
99
|
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
92
|
-
const appDir =
|
|
93
|
-
const baseDir =
|
|
100
|
+
const appDir = globalOptions.appDir ?? '';
|
|
101
|
+
const baseDir = globalOptions.baseDir ?? '';
|
|
94
102
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
95
103
|
// new container
|
|
96
|
-
const applicationContext =
|
|
97
|
-
// bind container to decoratorManager
|
|
98
|
-
debug('[core]: delegate module map from decoratorManager');
|
|
99
|
-
(0, decorator_1.bindContainer)(applicationContext);
|
|
104
|
+
const applicationContext = globalOptions.applicationContext ?? new _1.MidwayContainer();
|
|
100
105
|
global['MIDWAY_APPLICATION_CONTEXT'] = applicationContext;
|
|
101
106
|
// register baseDir and appDir
|
|
102
107
|
applicationContext.registerObject('baseDir', baseDir);
|
|
103
108
|
applicationContext.registerObject('appDir', appDir);
|
|
109
|
+
if (!globalOptions.asyncContextManager) {
|
|
110
|
+
globalOptions.asyncContextManager = new asyncContextManager_1.AsyncLocalStorageContextManager();
|
|
111
|
+
}
|
|
112
|
+
debug('[core]: set default module load type and entry file');
|
|
104
113
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
105
114
|
debug('[core]: set default file detector');
|
|
106
115
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
@@ -108,37 +117,14 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
108
117
|
if (!globalOptions.moduleLoadType) {
|
|
109
118
|
globalOptions.moduleLoadType = 'commonjs';
|
|
110
119
|
}
|
|
111
|
-
// set
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
globalOptions.imports = [
|
|
117
|
-
await (0, _1.loadModule)((0, path_1.join)(baseDir, `configuration${(0, _1.isTypeScriptEnvironment)() ? '.ts' : '.js'}`), {
|
|
118
|
-
loadMode: globalOptions.moduleLoadType,
|
|
119
|
-
safeLoad: true,
|
|
120
|
-
}),
|
|
121
|
-
];
|
|
122
|
-
}
|
|
123
|
-
if (globalOptions.moduleDetector === undefined) {
|
|
124
|
-
if (globalOptions.moduleLoadType === 'esm') {
|
|
125
|
-
applicationContext.setFileDetector(new _1.ESModuleFileDetector({
|
|
126
|
-
loadDir: baseDir,
|
|
127
|
-
ignore: (_d = globalOptions.ignore) !== null && _d !== void 0 ? _d : [],
|
|
128
|
-
}));
|
|
129
|
-
globalOptions.moduleLoadType = 'esm';
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
applicationContext.setFileDetector(new _1.CommonJSFileDetector({
|
|
133
|
-
loadDir: baseDir,
|
|
134
|
-
ignore: (_e = globalOptions.ignore) !== null && _e !== void 0 ? _e : [],
|
|
135
|
-
}));
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
120
|
+
// set entry file
|
|
121
|
+
globalOptions.imports = [
|
|
122
|
+
...(globalOptions.imports ?? []),
|
|
123
|
+
await (0, util_1.findProjectEntryFile)(appDir, baseDir, globalOptions.moduleLoadType),
|
|
124
|
+
];
|
|
139
125
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
140
|
-
printStepDebugInfo('Binding
|
|
141
|
-
// bind
|
|
126
|
+
printStepDebugInfo('Binding built-in service');
|
|
127
|
+
// bind built-in service
|
|
142
128
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
143
129
|
applicationContext.bindClass(_1.MidwayInformationService);
|
|
144
130
|
applicationContext.bindClass(_1.MidwayAspectService);
|
|
@@ -154,13 +140,6 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
154
140
|
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
155
141
|
applicationContext.bindClass(healthService_1.MidwayHealthService);
|
|
156
142
|
applicationContext.bindClass(_1.MidwayPriorityManager);
|
|
157
|
-
printStepDebugInfo('Binding preload module');
|
|
158
|
-
// bind preload module
|
|
159
|
-
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
160
|
-
for (const preloadModule of globalOptions.preloadModules) {
|
|
161
|
-
applicationContext.bindClass(preloadModule);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
143
|
printStepDebugInfo('Init MidwayConfigService, MidwayAspectService and MidwayDecoratorService');
|
|
165
144
|
// init default environment
|
|
166
145
|
const environmentService = applicationContext.get(_1.MidwayEnvironmentService);
|
|
@@ -176,12 +155,27 @@ async function prepareGlobalApplicationContextAsync(globalOptions) {
|
|
|
176
155
|
applicationContext.get(_1.MidwayAspectService, [applicationContext]);
|
|
177
156
|
// init decorator service
|
|
178
157
|
applicationContext.get(_1.MidwayDecoratorService, [applicationContext]);
|
|
158
|
+
printStepDebugInfo('Binding preload module');
|
|
159
|
+
// bind preload module
|
|
160
|
+
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
161
|
+
for (const preloadModule of globalOptions.preloadModules) {
|
|
162
|
+
applicationContext.bindClass(preloadModule);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
179
165
|
printStepDebugInfo('Load imports(component) and user code configuration module');
|
|
180
|
-
applicationContext.load([].concat(globalOptions.imports).concat(globalOptions.configurationModule));
|
|
181
|
-
printStepDebugInfo('Run applicationContext ready method');
|
|
182
166
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
183
|
-
//
|
|
184
|
-
|
|
167
|
+
// load configuration
|
|
168
|
+
const componentConfigurationLoader = new componentLoader_1.ComponentConfigurationLoader(applicationContext);
|
|
169
|
+
const importModules = [...(globalOptions.imports ?? [])];
|
|
170
|
+
for (const mod of importModules) {
|
|
171
|
+
if (mod) {
|
|
172
|
+
await componentConfigurationLoader.load(mod);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
for (const ns of componentConfigurationLoader.getNamespaceList()) {
|
|
176
|
+
applicationContext.addNamespace(ns);
|
|
177
|
+
debug(`[core]: load configuration in namespace="${ns}" complete`);
|
|
178
|
+
}
|
|
185
179
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
186
180
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
187
181
|
if (globalOptions.globalConfig) {
|
|
@@ -207,41 +201,33 @@ exports.prepareGlobalApplicationContextAsync = prepareGlobalApplicationContextAs
|
|
|
207
201
|
* @param globalOptions
|
|
208
202
|
*/
|
|
209
203
|
function prepareGlobalApplicationContext(globalOptions) {
|
|
210
|
-
var _a, _b, _c, _d;
|
|
211
204
|
printStepDebugInfo('Ready to create applicationContext');
|
|
212
205
|
debug('[core]: start "initializeGlobalApplicationContext"');
|
|
213
206
|
debug(`[core]: bootstrap options = ${util.inspect(globalOptions)}`);
|
|
214
|
-
const appDir =
|
|
215
|
-
const baseDir =
|
|
207
|
+
const appDir = globalOptions.appDir ?? '';
|
|
208
|
+
const baseDir = globalOptions.baseDir ?? '';
|
|
216
209
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
217
210
|
// new container
|
|
218
|
-
const applicationContext =
|
|
219
|
-
// bind container to decoratorManager
|
|
220
|
-
debug('[core]: delegate module map from decoratorManager');
|
|
221
|
-
(0, decorator_1.bindContainer)(applicationContext);
|
|
211
|
+
const applicationContext = globalOptions.applicationContext ?? new _1.MidwayContainer();
|
|
222
212
|
global['MIDWAY_APPLICATION_CONTEXT'] = applicationContext;
|
|
223
213
|
// register baseDir and appDir
|
|
224
214
|
applicationContext.registerObject('baseDir', baseDir);
|
|
225
215
|
applicationContext.registerObject('appDir', appDir);
|
|
216
|
+
if (!globalOptions.asyncContextManager) {
|
|
217
|
+
globalOptions.asyncContextManager = new asyncContextManager_1.AsyncLocalStorageContextManager();
|
|
218
|
+
}
|
|
226
219
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.METADATA_PREPARE);
|
|
227
|
-
|
|
228
|
-
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
220
|
+
debug('[core]: set default module load type and entry file');
|
|
229
221
|
if (!globalOptions.moduleLoadType) {
|
|
230
222
|
globalOptions.moduleLoadType = 'commonjs';
|
|
231
223
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
applicationContext.setFileDetector(globalOptions.moduleDetector);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DETECTOR_PREPARE);
|
|
243
|
-
printStepDebugInfo('Binding inner service');
|
|
244
|
-
// bind inner service
|
|
224
|
+
// set entry file
|
|
225
|
+
globalOptions.imports = [
|
|
226
|
+
...(globalOptions.imports ?? []),
|
|
227
|
+
(0, util_1.findProjectEntryFileSync)(appDir, baseDir),
|
|
228
|
+
];
|
|
229
|
+
printStepDebugInfo('Binding built-in service');
|
|
230
|
+
// bind built-in service
|
|
245
231
|
applicationContext.bindClass(_1.MidwayEnvironmentService);
|
|
246
232
|
applicationContext.bindClass(_1.MidwayInformationService);
|
|
247
233
|
applicationContext.bindClass(_1.MidwayAspectService);
|
|
@@ -257,13 +243,6 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
257
243
|
applicationContext.bindClass(slsFunctionService_1.MidwayServerlessFunctionService);
|
|
258
244
|
applicationContext.bindClass(healthService_1.MidwayHealthService);
|
|
259
245
|
applicationContext.bindClass(_1.MidwayPriorityManager);
|
|
260
|
-
printStepDebugInfo('Binding preload module');
|
|
261
|
-
// bind preload module
|
|
262
|
-
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
263
|
-
for (const preloadModule of globalOptions.preloadModules) {
|
|
264
|
-
applicationContext.bindClass(preloadModule);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
246
|
printStepDebugInfo('Init MidwayConfigService, MidwayAspectService and MidwayDecoratorService');
|
|
268
247
|
// init default environment
|
|
269
248
|
const environmentService = applicationContext.get(_1.MidwayEnvironmentService);
|
|
@@ -279,17 +258,27 @@ function prepareGlobalApplicationContext(globalOptions) {
|
|
|
279
258
|
applicationContext.get(_1.MidwayAspectService, [applicationContext]);
|
|
280
259
|
// init decorator service
|
|
281
260
|
applicationContext.get(_1.MidwayDecoratorService, [applicationContext]);
|
|
282
|
-
printStepDebugInfo('
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
261
|
+
printStepDebugInfo('Binding preload module');
|
|
262
|
+
// bind preload module
|
|
263
|
+
if (globalOptions.preloadModules && globalOptions.preloadModules.length) {
|
|
264
|
+
for (const preloadModule of globalOptions.preloadModules) {
|
|
265
|
+
applicationContext.bindClass(preloadModule);
|
|
266
|
+
}
|
|
287
267
|
}
|
|
288
|
-
|
|
289
|
-
|
|
268
|
+
printStepDebugInfo('Load imports(component) and user code configuration module');
|
|
269
|
+
// load configuration
|
|
270
|
+
const componentConfigurationLoader = new componentLoader_1.ComponentConfigurationLoader(applicationContext);
|
|
271
|
+
const importModules = [...(globalOptions.imports ?? [])];
|
|
290
272
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
291
|
-
|
|
292
|
-
|
|
273
|
+
for (const mod of importModules) {
|
|
274
|
+
if (mod) {
|
|
275
|
+
componentConfigurationLoader.loadSync(mod);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
for (const ns of componentConfigurationLoader.getNamespaceList()) {
|
|
279
|
+
applicationContext.addNamespace(ns);
|
|
280
|
+
debug(`[core]: load configuration in namespace="${ns}" complete`);
|
|
281
|
+
}
|
|
293
282
|
performanceManager_1.MidwayInitializerPerformanceManager.markEnd(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.DEFINITION_PREPARE);
|
|
294
283
|
performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.CONFIG_LOAD);
|
|
295
284
|
if (globalOptions.globalConfig) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IConfigurationOptions,
|
|
1
|
+
import { IConfigurationOptions, IMidwayFramework, IMidwayGlobalContainer } from '../interface';
|
|
2
2
|
import { AsyncContextManager } from '../common/asyncContextManager';
|
|
3
|
-
export declare const getCurrentApplicationContext: () =>
|
|
3
|
+
export declare const getCurrentApplicationContext: () => IMidwayGlobalContainer;
|
|
4
4
|
export declare const getCurrentMainFramework: <APP extends import("../interface").IMidwayBaseApplication<CTX>, CTX extends import("../interface").Context, CONFIG extends IConfigurationOptions>() => IMidwayFramework<APP, CTX, CONFIG, unknown, unknown>;
|
|
5
5
|
export declare const getCurrentMainApp: <APP extends import("../interface").IMidwayBaseApplication<import("../interface").Context>>() => APP;
|
|
6
6
|
export declare const getCurrentAsyncContextManager: () => AsyncContextManager;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="node" />
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import http
|
|
6
|
-
import https
|
|
5
|
+
import * as http from 'http';
|
|
6
|
+
import * as https from 'https';
|
|
7
7
|
export type HttpClientMimeType = 'text' | 'json' | undefined;
|
|
8
8
|
export interface HttpClientOptions<Data = any> extends https.RequestOptions {
|
|
9
9
|
headers?: any;
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { FunctionMiddleware, IgnoreMatcher } from '../interface';
|
|
2
3
|
import { camelCase, pascalCase } from './camelCase';
|
|
3
4
|
import { randomUUID } from './uuid';
|
|
@@ -27,7 +28,18 @@ export declare const loadModule: (p: string, options?: {
|
|
|
27
28
|
enableCache?: boolean;
|
|
28
29
|
loadMode?: 'commonjs' | 'esm';
|
|
29
30
|
safeLoad?: boolean;
|
|
31
|
+
warnOnLoadError?: boolean;
|
|
30
32
|
}) => Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* load module sync, and it must be commonjs mode
|
|
35
|
+
* @param p
|
|
36
|
+
* @param options
|
|
37
|
+
*/
|
|
38
|
+
export declare const loadModuleSync: (p: string, options?: {
|
|
39
|
+
enableCache?: boolean;
|
|
40
|
+
safeLoad?: boolean;
|
|
41
|
+
warnOnLoadError?: boolean;
|
|
42
|
+
}) => any;
|
|
31
43
|
/**
|
|
32
44
|
* @example
|
|
33
45
|
* safelyGet(['a','b'],{a: {b: 2}}) // => 2
|
|
@@ -110,7 +122,7 @@ export declare function pathMatching(options: {
|
|
|
110
122
|
export declare function wrapMiddleware(mw: FunctionMiddleware<any, any>, options: any): (context: any, next: any, options?: any) => any;
|
|
111
123
|
export declare function isIncludeProperty(obj: any, prop: string): boolean;
|
|
112
124
|
export declare function wrapAsync(handler: any): (...args: any[]) => any;
|
|
113
|
-
export declare function sleep(sleepTime?: number): Promise<void>;
|
|
125
|
+
export declare function sleep(sleepTime?: number, abortController?: AbortController): Promise<void>;
|
|
114
126
|
/**
|
|
115
127
|
* get parameter name from function
|
|
116
128
|
* @param func
|
|
@@ -123,22 +135,9 @@ export declare function generateRandomId(): string;
|
|
|
123
135
|
export declare function merge(target: any, src: any): any;
|
|
124
136
|
export declare function toAsyncFunction<T extends (...args: any[]) => any>(method: T): (...args: Parameters<T>) => Promise<ReturnType<T>>;
|
|
125
137
|
export declare function isTypeScriptEnvironment(): boolean;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
*/
|
|
130
|
-
export declare function createPromiseTimeoutInvokeChain<Result>(options: {
|
|
131
|
-
promiseItems: Array<Promise<any> | {
|
|
132
|
-
item: Promise<any>;
|
|
133
|
-
meta?: any;
|
|
134
|
-
timeout?: number;
|
|
135
|
-
}>;
|
|
136
|
-
timeout: number;
|
|
137
|
-
methodName: string;
|
|
138
|
-
onSuccess?: (result: any, meta: any) => Result | Promise<Result>;
|
|
139
|
-
onFail: (err: Error, meta: any) => Result | Promise<Result>;
|
|
140
|
-
isConcurrent?: boolean;
|
|
141
|
-
}): Promise<Result[]>;
|
|
138
|
+
export declare function isConfigurationExport(exports: any): boolean;
|
|
139
|
+
export declare function findProjectEntryFile(appDir: string, baseDir: string, loadMode: 'commonjs' | 'esm'): Promise<any>;
|
|
140
|
+
export declare function findProjectEntryFileSync(appDir: string, baseDir: string): any;
|
|
142
141
|
export declare const Utils: {
|
|
143
142
|
sleep: typeof sleep;
|
|
144
143
|
getParamNames: typeof getParamNames;
|