@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.
Files changed (151) hide show
  1. package/dist/baseFramework.d.ts +14 -39
  2. package/dist/baseFramework.js +19 -59
  3. package/dist/common/applicationManager.d.ts +6 -6
  4. package/dist/common/applicationManager.js +18 -35
  5. package/dist/common/asyncContextManager.d.ts +15 -0
  6. package/dist/common/asyncContextManager.js +51 -2
  7. package/dist/common/dataListener.d.ts +5 -3
  8. package/dist/common/dataListener.js +13 -4
  9. package/dist/common/dataSourceManager.d.ts +18 -9
  10. package/dist/common/dataSourceManager.js +121 -72
  11. package/dist/common/fileDetector.d.ts +9 -9
  12. package/dist/common/fileDetector.js +30 -28
  13. package/dist/common/filterManager.js +5 -4
  14. package/dist/common/guardManager.js +3 -2
  15. package/dist/common/middlewareManager.js +4 -3
  16. package/dist/common/performanceManager.js +1 -1
  17. package/dist/common/priorityManager.js +2 -2
  18. package/dist/common/serviceDiscovery/healthCheck.d.ts +66 -0
  19. package/dist/common/serviceDiscovery/healthCheck.js +207 -0
  20. package/dist/common/serviceDiscovery/loadBalancer.d.ts +21 -0
  21. package/dist/common/serviceDiscovery/loadBalancer.js +51 -0
  22. package/dist/common/serviceDiscovery/serviceDiscovery.d.ts +59 -0
  23. package/dist/common/serviceDiscovery/serviceDiscovery.js +104 -0
  24. package/dist/common/serviceFactory.d.ts +5 -2
  25. package/dist/common/serviceFactory.js +44 -9
  26. package/dist/common/webGenerator.js +4 -6
  27. package/dist/config/config.default.js +4 -1
  28. package/dist/constants.d.ts +2 -32
  29. package/dist/constants.js +3 -33
  30. package/dist/context/componentLoader.d.ts +20 -0
  31. package/dist/context/componentLoader.js +193 -0
  32. package/dist/context/container.d.ts +18 -32
  33. package/dist/context/container.js +74 -308
  34. package/dist/context/definitionRegistry.d.ts +5 -0
  35. package/dist/context/definitionRegistry.js +17 -26
  36. package/dist/context/dynamicContainer.d.ts +17 -0
  37. package/dist/context/dynamicContainer.js +202 -0
  38. package/dist/context/managedResolverFactory.d.ts +15 -41
  39. package/dist/context/managedResolverFactory.js +271 -349
  40. package/dist/context/requestContainer.d.ts +23 -12
  41. package/dist/context/requestContainer.js +46 -51
  42. package/dist/decorator/common/aspect.js +4 -4
  43. package/dist/decorator/common/autoload.js +1 -1
  44. package/dist/decorator/common/configuration.d.ts +1 -24
  45. package/dist/decorator/common/configuration.js +6 -1
  46. package/dist/decorator/common/filter.js +6 -6
  47. package/dist/decorator/common/framework.d.ts +46 -3
  48. package/dist/decorator/common/framework.js +43 -9
  49. package/dist/decorator/common/guard.js +4 -9
  50. package/dist/decorator/common/inject.d.ts +4 -2
  51. package/dist/decorator/common/inject.js +87 -4
  52. package/dist/decorator/common/mock.js +1 -1
  53. package/dist/decorator/common/objectDef.d.ts +0 -5
  54. package/dist/decorator/common/objectDef.js +8 -20
  55. package/dist/decorator/common/provide.d.ts +1 -1
  56. package/dist/decorator/common/provide.js +1 -1
  57. package/dist/decorator/common/scope.d.ts +6 -0
  58. package/dist/decorator/common/scope.js +21 -0
  59. package/dist/decorator/constant.d.ts +14 -17
  60. package/dist/decorator/constant.js +23 -35
  61. package/dist/decorator/decoratorManager.d.ts +21 -294
  62. package/dist/decorator/decoratorManager.js +127 -694
  63. package/dist/decorator/faas/serverlessTrigger.js +5 -5
  64. package/dist/decorator/index.d.ts +2 -3
  65. package/dist/decorator/index.js +6 -4
  66. package/dist/decorator/metadataManager.d.ts +131 -0
  67. package/dist/decorator/metadataManager.js +465 -0
  68. package/dist/decorator/microservice/consumer.js +3 -2
  69. package/dist/decorator/microservice/kafkaListener.js +2 -1
  70. package/dist/decorator/microservice/provider.js +6 -5
  71. package/dist/decorator/microservice/rabbitmqListener.js +2 -1
  72. package/dist/decorator/task/queue.js +3 -2
  73. package/dist/decorator/task/schedule.js +3 -2
  74. package/dist/decorator/task/task.js +4 -3
  75. package/dist/decorator/task/taskLocal.js +4 -3
  76. package/dist/decorator/web/controller.js +3 -2
  77. package/dist/decorator/web/paramMapping.js +2 -2
  78. package/dist/decorator/web/requestMapping.js +5 -5
  79. package/dist/decorator/web/response.js +6 -5
  80. package/dist/decorator/ws/webSocketController.js +3 -2
  81. package/dist/decorator/ws/webSocketEvent.js +7 -6
  82. package/dist/definitions/functionDefinition.d.ts +3 -3
  83. package/dist/definitions/functionDefinition.js +12 -11
  84. package/dist/definitions/objectCreator.d.ts +5 -11
  85. package/dist/definitions/objectCreator.js +6 -28
  86. package/dist/definitions/objectDefinition.d.ts +2 -3
  87. package/dist/definitions/objectDefinition.js +1 -3
  88. package/dist/error/base.js +2 -2
  89. package/dist/error/framework.d.ts +2 -9
  90. package/dist/error/framework.js +13 -27
  91. package/dist/error/http.js +1 -1
  92. package/dist/functional/configuration.d.ts +14 -15
  93. package/dist/functional/configuration.js +37 -47
  94. package/dist/functional/hooks.d.ts +12 -0
  95. package/dist/functional/hooks.js +78 -0
  96. package/dist/functional/index.d.ts +3 -0
  97. package/dist/functional/index.js +22 -0
  98. package/dist/index.d.ts +8 -4
  99. package/dist/index.js +10 -7
  100. package/dist/interface.d.ts +261 -137
  101. package/dist/interface.js +23 -33
  102. package/dist/legacy/constants.d.ts +29 -0
  103. package/dist/legacy/constants.js +33 -0
  104. package/dist/legacy/decorator.d.ts +255 -0
  105. package/dist/legacy/decorator.js +468 -0
  106. package/dist/legacy/index.d.ts +3 -0
  107. package/dist/legacy/index.js +19 -0
  108. package/dist/legacy/types.d.ts +2 -0
  109. package/dist/legacy/types.js +3 -0
  110. package/dist/service/aspectService.js +11 -12
  111. package/dist/service/configService.d.ts +1 -1
  112. package/dist/service/configService.js +5 -4
  113. package/dist/service/decoratorService.d.ts +3 -3
  114. package/dist/service/decoratorService.js +14 -10
  115. package/dist/service/environmentService.js +2 -2
  116. package/dist/service/frameworkService.d.ts +5 -4
  117. package/dist/service/frameworkService.js +30 -28
  118. package/dist/service/healthService.d.ts +2 -0
  119. package/dist/service/healthService.js +19 -8
  120. package/dist/service/informationService.d.ts +3 -0
  121. package/dist/service/informationService.js +13 -4
  122. package/dist/service/lifeCycleService.d.ts +13 -7
  123. package/dist/service/lifeCycleService.js +54 -48
  124. package/dist/service/loggerService.js +3 -4
  125. package/dist/service/middlewareService.js +7 -8
  126. package/dist/service/mockService.js +9 -15
  127. package/dist/service/slsFunctionService.d.ts +1 -14
  128. package/dist/service/slsFunctionService.js +33 -81
  129. package/dist/service/webRouterService.js +11 -11
  130. package/dist/setup.d.ts +5 -5
  131. package/dist/setup.js +83 -94
  132. package/dist/util/contextUtil.d.ts +2 -2
  133. package/dist/util/httpclient.d.ts +2 -2
  134. package/dist/util/index.d.ts +16 -17
  135. package/dist/util/index.js +153 -78
  136. package/dist/util/network.d.ts +10 -0
  137. package/dist/util/network.js +40 -0
  138. package/dist/util/pathFileUtil.d.ts +15 -2
  139. package/dist/util/pathFileUtil.js +27 -6
  140. package/dist/util/timeout.d.ts +57 -0
  141. package/dist/util/timeout.js +144 -0
  142. package/dist/util/webRouterParam.js +2 -2
  143. package/package.json +24 -6
  144. package/dist/decorator/common/pipeline.d.ts +0 -3
  145. package/dist/decorator/common/pipeline.js +0 -12
  146. package/dist/decorator/rpc/hsf.d.ts +0 -13
  147. package/dist/decorator/rpc/hsf.js +0 -20
  148. package/dist/definitions/properties.d.ts +0 -7
  149. package/dist/definitions/properties.js +0 -19
  150. package/dist/service/pipelineService.d.ts +0 -168
  151. 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\nStep ${stepIdx++}: ${stepInfo}\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 preload modules');
56
+ printStepDebugInfo('Init pre-start modules');
55
57
  performanceManager_1.MidwayInitializerPerformanceManager.markStart(performanceManager_1.MidwayInitializerPerformanceManager.MEASURE_KEYS.PRELOAD_MODULE_PREPARE);
56
- // some preload module init
57
- const modules = (0, decorator_1.listPreloadModule)();
58
+ // some pre-start module init
59
+ const modules = _1.DecoratorManager.listPreStartModule();
58
60
  for (const module of modules) {
59
- // preload init context
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
- (0, decorator_1.clearBindContainer)();
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 = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
93
- const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
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 = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
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 module detector
112
- if (globalOptions.moduleDetector !== false) {
113
- debug('[core]: set module load type = %s', globalOptions.moduleLoadType);
114
- // set default entry file
115
- if (!globalOptions.imports) {
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 inner service');
141
- // bind inner service
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
- // bind user code module
184
- await applicationContext.ready();
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 = (_a = globalOptions.appDir) !== null && _a !== void 0 ? _a : '';
215
- const baseDir = (_b = globalOptions.baseDir) !== null && _b !== void 0 ? _b : '';
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 = (_c = globalOptions.applicationContext) !== null && _c !== void 0 ? _c : new _1.MidwayContainer();
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
- printStepDebugInfo('Ready module detector');
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
- if (globalOptions.moduleDetector !== false) {
233
- if (globalOptions.moduleDetector === undefined) {
234
- applicationContext.setFileDetector(new _1.CommonJSFileDetector({
235
- ignore: (_d = globalOptions.ignore) !== null && _d !== void 0 ? _d : [],
236
- }));
237
- }
238
- else if (globalOptions.moduleDetector) {
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('Load imports(component) and user code configuration module');
283
- if (!globalOptions.imports) {
284
- globalOptions.imports = [
285
- (0, _1.safeRequire)((0, path_1.join)(globalOptions.baseDir, 'configuration')),
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
- applicationContext.load([].concat(globalOptions.imports).concat(globalOptions.configurationModule));
289
- printStepDebugInfo('Run applicationContext ready method');
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
- // bind user code module
292
- applicationContext.ready();
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, IMidwayContainer, IMidwayFramework } from '../interface';
1
+ import { IConfigurationOptions, IMidwayFramework, IMidwayGlobalContainer } from '../interface';
2
2
  import { AsyncContextManager } from '../common/asyncContextManager';
3
- export declare const getCurrentApplicationContext: () => IMidwayContainer;
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 = require('http');
6
- import https = require('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;
@@ -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
- * Create a Promise that resolves after the specified time
128
- * @param options
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;