@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
@@ -1,4 +1,4 @@
1
- import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContainer, IMidwayContext, IMidwayFramework, CommonFilterUnion, MiddlewareRespond, CommonGuardUnion, ILogger, MidwayLoggerOptions } from './interface';
1
+ import { CommonMiddlewareUnion, IConfigurationOptions, IMidwayApplication, IMidwayBootstrapOptions, IMidwayContext, IMidwayFramework, CommonFilterUnion, MiddlewareRespond, CommonGuardUnion, ILogger, MidwayLoggerOptions, IMidwayGlobalContainer } from './interface';
2
2
  import { MidwayEnvironmentService } from './service/environmentService';
3
3
  import { MidwayConfigService } from './service/configService';
4
4
  import { MidwayInformationService } from './service/informationService';
@@ -10,14 +10,12 @@ import { MidwayMockService } from './service/mockService';
10
10
  import { AsyncContextManager } from './common/asyncContextManager';
11
11
  import { GuardManager } from './common/guardManager';
12
12
  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> {
13
- readonly applicationContext: IMidwayContainer;
13
+ readonly applicationContext: IMidwayGlobalContainer;
14
14
  app: APP;
15
15
  configurationOptions: OPT;
16
16
  protected logger: ILogger;
17
- protected appLogger: ILogger;
17
+ protected frameworkLoggerName: string;
18
18
  protected defaultContext: {};
19
- protected contextLoggerApplyLogger: string;
20
- protected contextLoggerFormat: any;
21
19
  protected middlewareManager: ContextMiddlewareManager<CTX, ResOrNext, Next>;
22
20
  protected filterManager: FilterManager<CTX, ResOrNext, Next>;
23
21
  protected guardManager: GuardManager<CTX>;
@@ -31,51 +29,23 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
31
29
  informationService: MidwayInformationService;
32
30
  middlewareService: MidwayMiddlewareService<CTX, ResOrNext, Next>;
33
31
  mockService: MidwayMockService;
34
- constructor(applicationContext: IMidwayContainer);
35
- init(): Promise<this>;
36
- abstract configure(options?: OPT): any;
32
+ constructor(applicationContext: IMidwayGlobalContainer);
33
+ protected init(): Promise<this>;
34
+ abstract configure(options?: OPT): OPT;
35
+ abstract applicationInitialize(options: IMidwayBootstrapOptions): void | Promise<void>;
36
+ abstract run(): Promise<void>;
37
37
  isEnable(): boolean;
38
38
  initialize(options?: IMidwayBootstrapOptions): Promise<void>;
39
- /**
40
- * @deprecated
41
- */
42
- protected containerInitialize(options: IMidwayBootstrapOptions): Promise<void>;
43
- /**
44
- * @deprecated
45
- */
46
- protected containerDirectoryLoad(options: IMidwayBootstrapOptions): Promise<void>;
47
- /**
48
- * @deprecated
49
- */
50
- protected containerReady(options: IMidwayBootstrapOptions): Promise<void>;
51
- getApplicationContext(): IMidwayContainer;
39
+ getApplicationContext(): IMidwayGlobalContainer;
52
40
  getConfiguration(key?: string): any;
53
41
  getCurrentEnvironment(): string;
54
42
  getApplication(): APP;
55
- abstract applicationInitialize(options: IMidwayBootstrapOptions): any;
56
- abstract run(): Promise<void>;
57
43
  protected createContextLogger(ctx: CTX, name?: string): ILogger;
58
44
  stop(): Promise<void>;
59
45
  getAppDir(): string;
60
46
  getBaseDir(): string;
61
47
  protected defineApplicationProperties(applicationProperties?: {}, whiteList?: string[]): void;
62
48
  protected beforeStop(): Promise<void>;
63
- /**
64
- * @deprecated
65
- */
66
- protected beforeContainerInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
67
- /**
68
- * @deprecated
69
- */
70
- protected afterContainerInitialize(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
71
- /**
72
- * @deprecated
73
- */
74
- protected afterContainerDirectoryLoad(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
75
- /**
76
- * @deprecated
77
- */
78
- protected afterContainerReady(options: Partial<IMidwayBootstrapOptions>): Promise<void>;
79
49
  applyMiddleware<R, N>(lastMiddleware?: CommonMiddlewareUnion<CTX, R, N>): Promise<MiddlewareRespond<CTX, R, N>>;
80
50
  getLogger(name?: string): any;
81
51
  getCoreLogger(): ILogger;
@@ -92,5 +62,10 @@ export declare abstract class BaseFramework<APP extends IMidwayApplication<CTX>,
92
62
  protected createGuardManager(): GuardManager<CTX>;
93
63
  setNamespace(namespace: string): void;
94
64
  getNamespace(): string;
65
+ /**
66
+ * Set the default framework logger name
67
+ * @since 4.0.0
68
+ */
69
+ setFrameworkLoggerName(loggerName: string): void;
95
70
  }
96
71
  //# sourceMappingURL=baseFramework.d.ts.map
@@ -29,6 +29,7 @@ const debug = util.debuglog('midway:debug');
29
29
  class BaseFramework {
30
30
  constructor(applicationContext) {
31
31
  this.applicationContext = applicationContext;
32
+ this.frameworkLoggerName = 'appLogger';
32
33
  this.defaultContext = {};
33
34
  this.middlewareManager = this.createMiddlewareManager();
34
35
  this.filterManager = this.createFilterManager();
@@ -36,13 +37,8 @@ class BaseFramework {
36
37
  this.composeMiddleware = null;
37
38
  }
38
39
  async init() {
39
- var _a, _b;
40
- this.configurationOptions = (_a = this.configure()) !== null && _a !== void 0 ? _a : {};
41
- this.contextLoggerApplyLogger =
42
- (_b = this.configurationOptions.contextLoggerApplyLogger) !== null && _b !== void 0 ? _b : 'appLogger';
43
- this.contextLoggerFormat = this.configurationOptions.contextLoggerFormat;
40
+ this.configurationOptions = this.configure() ?? {};
44
41
  this.logger = this.loggerService.getLogger('coreLogger');
45
- this.appLogger = this.loggerService.getLogger('appLogger');
46
42
  return this;
47
43
  }
48
44
  isEnable() {
@@ -50,34 +46,17 @@ class BaseFramework {
50
46
  }
51
47
  async initialize(options) {
52
48
  this.bootstrapOptions = options;
53
- await this.beforeContainerInitialize(options);
54
- await this.containerInitialize(options);
55
- await this.afterContainerInitialize(options);
56
- await this.containerDirectoryLoad(options);
57
- await this.afterContainerDirectoryLoad(options);
58
49
  /**
59
50
  * Third party application initialization
60
51
  */
61
52
  await this.applicationInitialize(options);
62
- await this.containerReady(options);
63
- await this.afterContainerReady(options);
64
- await this.mockService.runSimulatorAppSetup(this.app);
65
- }
66
- /**
67
- * @deprecated
68
- */
69
- async containerInitialize(options) { }
70
- /**
71
- * @deprecated
72
- */
73
- async containerDirectoryLoad(options) { }
74
- /**
75
- * @deprecated
76
- */
77
- async containerReady(options) {
53
+ /**
54
+ * define application properties if not exists
55
+ */
78
56
  if (!this.app.getApplicationContext) {
79
57
  this.defineApplicationProperties();
80
58
  }
59
+ await this.mockService.runSimulatorAppSetup(this.app);
81
60
  }
82
61
  getApplicationContext() {
83
62
  return this.applicationContext;
@@ -92,7 +71,7 @@ class BaseFramework {
92
71
  return this.app;
93
72
  }
94
73
  createContextLogger(ctx, name) {
95
- if (name && name !== 'appLogger') {
74
+ if (name && name !== this.frameworkLoggerName) {
96
75
  const appLogger = this.getLogger(name);
97
76
  let ctxLoggerCache = ctx.getAttr(constants_1.REQUEST_CTX_LOGGER_CACHE_KEY);
98
77
  if (!ctxLoggerCache) {
@@ -109,14 +88,12 @@ class BaseFramework {
109
88
  return ctxLogger;
110
89
  }
111
90
  else {
112
- const appLogger = this.getLogger(name !== null && name !== void 0 ? name : this.contextLoggerApplyLogger);
113
91
  // avoid maximum call stack size exceeded
114
92
  if (ctx['_logger']) {
115
93
  return ctx['_logger'];
116
94
  }
117
- ctx['_logger'] = this.loggerService.createContextLogger(ctx, appLogger, {
118
- contextFormat: this.contextLoggerFormat,
119
- });
95
+ const appLogger = this.getLogger(name);
96
+ ctx['_logger'] = this.loggerService.createContextLogger(ctx, appLogger);
120
97
  return ctx['_logger'];
121
98
  }
122
99
  }
@@ -147,11 +124,6 @@ class BaseFramework {
147
124
  getConfig: (key) => {
148
125
  return this.getConfiguration(key);
149
126
  },
150
- getFrameworkType: () => {
151
- if (this['getFrameworkType']) {
152
- return this['getFrameworkType']();
153
- }
154
- },
155
127
  getProcessType: () => {
156
128
  return interface_1.MidwayProcessTypeEnum.APPLICATION;
157
129
  },
@@ -180,7 +152,6 @@ class BaseFramework {
180
152
  }
181
153
  if (!ctx.requestContext) {
182
154
  ctx.requestContext = new requestContainer_1.MidwayRequestContainer(ctx, this.getApplicationContext());
183
- ctx.requestContext.ready();
184
155
  }
185
156
  if (!ctx.getLogger) {
186
157
  ctx.getLogger = name => {
@@ -229,30 +200,13 @@ class BaseFramework {
229
200
  Object.assign(this.app, defaultApplicationProperties, applicationProperties);
230
201
  }
231
202
  async beforeStop() { }
232
- /**
233
- * @deprecated
234
- */
235
- async beforeContainerInitialize(options) { }
236
- /**
237
- * @deprecated
238
- */
239
- async afterContainerInitialize(options) { }
240
- /**
241
- * @deprecated
242
- */
243
- async afterContainerDirectoryLoad(options) { }
244
- /**
245
- * @deprecated
246
- */
247
- async afterContainerReady(options) { }
248
203
  async applyMiddleware(lastMiddleware) {
249
- var _a;
250
204
  if (!this.composeMiddleware) {
251
205
  if (!this.applicationContext.hasObject(constants_1.ASYNC_CONTEXT_MANAGER_KEY)) {
252
206
  const asyncContextManagerEnabled = this.configService.getConfiguration('asyncContextManager.enable') ||
253
207
  false;
254
208
  const contextManager = asyncContextManagerEnabled
255
- ? ((_a = this.bootstrapOptions) === null || _a === void 0 ? void 0 : _a.asyncContextManager) ||
209
+ ? this.bootstrapOptions?.asyncContextManager ||
256
210
  new asyncContextManager_1.NoopContextManager()
257
211
  : new asyncContextManager_1.NoopContextManager();
258
212
  if (asyncContextManagerEnabled) {
@@ -299,8 +253,7 @@ class BaseFramework {
299
253
  return this.composeMiddleware;
300
254
  }
301
255
  getLogger(name) {
302
- var _a;
303
- return (_a = this.loggerService.getLogger(name)) !== null && _a !== void 0 ? _a : this.appLogger;
256
+ return this.loggerService.getLogger(name ?? this.frameworkLoggerName);
304
257
  }
305
258
  getCoreLogger() {
306
259
  return this.logger;
@@ -344,7 +297,15 @@ class BaseFramework {
344
297
  getNamespace() {
345
298
  return this.namespace;
346
299
  }
300
+ /**
301
+ * Set the default framework logger name
302
+ * @since 4.0.0
303
+ */
304
+ setFrameworkLoggerName(loggerName) {
305
+ this.frameworkLoggerName = loggerName;
306
+ }
347
307
  }
308
+ exports.BaseFramework = BaseFramework;
348
309
  __decorate([
349
310
  (0, decorator_1.Inject)(),
350
311
  __metadata("design:type", loggerService_1.MidwayLoggerService)
@@ -375,5 +336,4 @@ __decorate([
375
336
  __metadata("design:paramtypes", []),
376
337
  __metadata("design:returntype", Promise)
377
338
  ], BaseFramework.prototype, "init", null);
378
- exports.BaseFramework = BaseFramework;
379
339
  //# sourceMappingURL=baseFramework.js.map
@@ -1,10 +1,10 @@
1
- import { IMidwayApplication, IMidwayFramework, FrameworkType } from '../interface';
1
+ import { IMidwayApplication, IMidwayFramework } from '../interface';
2
2
  export declare class MidwayApplicationManager {
3
3
  private globalFrameworkMap;
4
- private globalFrameworkTypeMap;
5
- addFramework(namespace: any, framework: IMidwayFramework<any, any, any>): void;
6
- getFramework(namespaceOrFrameworkType: string | FrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
7
- getApplication(namespaceOrFrameworkType: string | FrameworkType): IMidwayApplication;
8
- getApplications(namespaces?: Array<string | FrameworkType>): IMidwayApplication[];
4
+ addFramework(frameworkNameOrNamespace: string, framework: IMidwayFramework<any, any, any>): void;
5
+ hasFramework(frameworkNameOrNamespace: string): boolean;
6
+ getFramework(frameworkNameOrNamespace: string): IMidwayFramework<any, any, any, unknown, unknown>;
7
+ getApplication(frameworkNameOrNamespace: string): IMidwayApplication;
8
+ getApplications(frameworkNameOrNamespace?: Array<string>): IMidwayApplication[];
9
9
  }
10
10
  //# sourceMappingURL=applicationManager.d.ts.map
@@ -12,44 +12,27 @@ const decorator_1 = require("../decorator");
12
12
  let MidwayApplicationManager = class MidwayApplicationManager {
13
13
  constructor() {
14
14
  this.globalFrameworkMap = new Map();
15
- this.globalFrameworkTypeMap = new WeakMap();
16
15
  }
17
- addFramework(namespace, framework) {
18
- this.globalFrameworkMap.set(namespace, framework);
19
- if (framework['getFrameworkType']) {
20
- this.globalFrameworkTypeMap.set(framework['getFrameworkType'](), framework);
21
- }
16
+ addFramework(frameworkNameOrNamespace, framework) {
17
+ this.globalFrameworkMap.set(frameworkNameOrNamespace, framework);
22
18
  }
23
- getFramework(namespaceOrFrameworkType) {
24
- if (typeof namespaceOrFrameworkType === 'string') {
25
- if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {
26
- return this.globalFrameworkMap.get(namespaceOrFrameworkType);
27
- }
28
- }
29
- else {
30
- if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {
31
- return this.globalFrameworkTypeMap.get(namespaceOrFrameworkType);
32
- }
33
- }
19
+ hasFramework(frameworkNameOrNamespace) {
20
+ return this.globalFrameworkMap.has(frameworkNameOrNamespace);
34
21
  }
35
- getApplication(namespaceOrFrameworkType) {
36
- if (typeof namespaceOrFrameworkType === 'string') {
37
- if (this.globalFrameworkMap.has(namespaceOrFrameworkType)) {
38
- return this.globalFrameworkMap
39
- .get(namespaceOrFrameworkType)
40
- .getApplication();
41
- }
22
+ getFramework(frameworkNameOrNamespace) {
23
+ if (this.globalFrameworkMap.has(frameworkNameOrNamespace)) {
24
+ return this.globalFrameworkMap.get(frameworkNameOrNamespace);
42
25
  }
43
- else {
44
- if (this.globalFrameworkTypeMap.has(namespaceOrFrameworkType)) {
45
- return this.globalFrameworkTypeMap
46
- .get(namespaceOrFrameworkType)
47
- .getApplication();
48
- }
26
+ }
27
+ getApplication(frameworkNameOrNamespace) {
28
+ if (this.globalFrameworkMap.has(frameworkNameOrNamespace)) {
29
+ return this.globalFrameworkMap
30
+ .get(frameworkNameOrNamespace)
31
+ .getApplication();
49
32
  }
50
33
  }
51
- getApplications(namespaces) {
52
- if (!namespaces) {
34
+ getApplications(frameworkNameOrNamespace) {
35
+ if (!frameworkNameOrNamespace) {
53
36
  return Array.from(this.globalFrameworkMap.values())
54
37
  .map(framework => {
55
38
  return framework.getApplication();
@@ -59,7 +42,7 @@ let MidwayApplicationManager = class MidwayApplicationManager {
59
42
  });
60
43
  }
61
44
  else {
62
- return namespaces
45
+ return frameworkNameOrNamespace
63
46
  .map(namespace => {
64
47
  return this.getApplication(namespace);
65
48
  })
@@ -69,9 +52,9 @@ let MidwayApplicationManager = class MidwayApplicationManager {
69
52
  }
70
53
  }
71
54
  };
72
- MidwayApplicationManager = __decorate([
55
+ exports.MidwayApplicationManager = MidwayApplicationManager;
56
+ exports.MidwayApplicationManager = MidwayApplicationManager = __decorate([
73
57
  (0, decorator_1.Provide)(),
74
58
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
75
59
  ], MidwayApplicationManager);
76
- exports.MidwayApplicationManager = MidwayApplicationManager;
77
60
  //# sourceMappingURL=applicationManager.js.map
@@ -58,4 +58,19 @@ export declare class NoopContextManager implements AsyncContextManager {
58
58
  enable(): this;
59
59
  disable(): this;
60
60
  }
61
+ export declare class AsyncLocalStorageContextManager implements AsyncContextManager {
62
+ private _asyncLocalStorage;
63
+ constructor();
64
+ active(): AsyncContext;
65
+ with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(context: AsyncContext, fn: F, thisArg?: ThisParameterType<F>, ...args: A): ReturnType<F>;
66
+ enable(): this;
67
+ disable(): this;
68
+ /**
69
+ * Binds a the certain context or the active one to the target function and then returns the target
70
+ * @param context A context (span) to be bind to target
71
+ * @param target a function. When target or one of its callbacks is called,
72
+ * the provided context will be used as the active context for the duration of the call.
73
+ */
74
+ bind<T>(context: AsyncContext, target: T): T;
75
+ }
61
76
  //# sourceMappingURL=asyncContextManager.d.ts.map
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncLocalStorageContextManager = exports.NoopContextManager = exports.ASYNC_ROOT_CONTEXT = void 0;
2
4
  /*
3
5
  * Copyright The OpenTelemetry Authors
4
6
  *
@@ -14,8 +16,7 @@
14
16
  * See the License for the specific language governing permissions and
15
17
  * limitations under the License.
16
18
  */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.NoopContextManager = exports.ASYNC_ROOT_CONTEXT = void 0;
19
+ const async_hooks_1 = require("async_hooks");
19
20
  class AsyncBaseContext {
20
21
  /**
21
22
  * Construct a new context which inherits values from an optional parent context.
@@ -60,4 +61,52 @@ class NoopContextManager {
60
61
  }
61
62
  }
62
63
  exports.NoopContextManager = NoopContextManager;
64
+ class AsyncLocalStorageContextManager {
65
+ constructor() {
66
+ this._asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
67
+ }
68
+ active() {
69
+ return this._asyncLocalStorage.getStore() ?? exports.ASYNC_ROOT_CONTEXT;
70
+ }
71
+ with(context, fn, thisArg, ...args) {
72
+ const cb = thisArg == null ? fn : fn.bind(thisArg);
73
+ return this._asyncLocalStorage.run(context, cb, ...args);
74
+ }
75
+ enable() {
76
+ return this;
77
+ }
78
+ disable() {
79
+ this._asyncLocalStorage.disable();
80
+ return this;
81
+ }
82
+ /**
83
+ * Binds a the certain context or the active one to the target function and then returns the target
84
+ * @param context A context (span) to be bind to target
85
+ * @param target a function. When target or one of its callbacks is called,
86
+ * the provided context will be used as the active context for the duration of the call.
87
+ */
88
+ bind(context, target) {
89
+ if (typeof target === 'function') {
90
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
91
+ const manager = this;
92
+ const contextWrapper = function (...args) {
93
+ return manager.with(context, () => target.apply(this, args));
94
+ };
95
+ Object.defineProperty(contextWrapper, 'length', {
96
+ enumerable: false,
97
+ configurable: true,
98
+ writable: false,
99
+ value: target.length,
100
+ });
101
+ /**
102
+ * It isn't possible to tell Typescript that contextWrapper is the same as T
103
+ * so we forced to cast as any here.
104
+ */
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ return contextWrapper;
107
+ }
108
+ return target;
109
+ }
110
+ }
111
+ exports.AsyncLocalStorageContextManager = AsyncLocalStorageContextManager;
63
112
  //# sourceMappingURL=asyncContextManager.js.map
@@ -1,10 +1,12 @@
1
- export declare abstract class DataListener<T> {
2
- private innerData;
1
+ export declare abstract class DataListener<T, U = T> {
2
+ protected innerData: T;
3
+ private isReady;
3
4
  protected init(): Promise<void>;
4
5
  abstract initData(): T | Promise<T>;
5
6
  abstract onData(callback: (data: T) => void): any;
6
7
  protected setData(data: T): void;
7
- getData(): T;
8
+ getData(): U;
9
+ protected transformData(data: T): U;
8
10
  stop(): Promise<void>;
9
11
  protected destroyListener(): Promise<void>;
10
12
  }
@@ -12,21 +12,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.DataListener = void 0;
13
13
  const decorator_1 = require("../decorator");
14
14
  class DataListener {
15
+ constructor() {
16
+ this.isReady = false;
17
+ }
15
18
  async init() {
16
- this.innerData = await this.initData();
17
- await this.onData(this.setData.bind(this));
19
+ if (!this.isReady) {
20
+ this.innerData = await this.initData();
21
+ await this.onData(this.setData.bind(this));
22
+ this.isReady = true;
23
+ }
18
24
  }
19
25
  setData(data) {
20
26
  this.innerData = data;
21
27
  }
22
28
  getData() {
23
- return this.innerData;
29
+ return this.transformData(this.innerData);
30
+ }
31
+ transformData(data) {
32
+ return data;
24
33
  }
25
34
  async stop() {
26
35
  await this.destroyListener();
27
36
  }
28
37
  async destroyListener() { }
29
38
  }
39
+ exports.DataListener = DataListener;
30
40
  __decorate([
31
41
  (0, decorator_1.Init)(),
32
42
  __metadata("design:type", Function),
@@ -39,5 +49,4 @@ __decorate([
39
49
  __metadata("design:paramtypes", []),
40
50
  __metadata("design:returntype", Promise)
41
51
  ], DataListener.prototype, "stop", null);
42
- exports.DataListener = DataListener;
43
52
  //# sourceMappingURL=dataListener.js.map
@@ -1,18 +1,20 @@
1
- import { ModuleLoadType, DataSourceManagerConfigOption } from '../interface';
1
+ import { ModuleLoadType, DataSourceManagerConfigOption, IDataSourceManager, BaseDataSourceManagerConfigOption } from '../interface';
2
2
  import { MidwayEnvironmentService } from '../service/environmentService';
3
3
  import { MidwayPriorityManager } from './priorityManager';
4
- export declare abstract class DataSourceManager<T, ConnectionOpts extends Record<string, any> = Record<string, any>> {
4
+ export declare abstract class DataSourceManager<T, ConnectionOpts extends BaseDataSourceManagerConfigOption<Record<string, any>, ENTITY_CONFIG_KEY> = BaseDataSourceManagerConfigOption<Record<string, any>, 'entities'>, ENTITY_CONFIG_KEY extends string = 'entities'> implements IDataSourceManager<T, ConnectionOpts> {
5
5
  protected dataSource: Map<string, T>;
6
- protected options: DataSourceManagerConfigOption<ConnectionOpts>;
6
+ protected options: DataSourceManagerConfigOption<ConnectionOpts, ENTITY_CONFIG_KEY>;
7
7
  protected modelMapping: WeakMap<object, any>;
8
8
  private innerDefaultDataSourceName;
9
9
  protected dataSourcePriority: Record<string, string>;
10
- protected appDir: string;
10
+ private creatingDataSources;
11
+ protected baseDir: string;
11
12
  protected environmentService: MidwayEnvironmentService;
12
13
  protected priorityManager: MidwayPriorityManager;
13
- protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts>, baseDirOrOptions: {
14
- baseDir: string;
14
+ protected initDataSource(dataSourceConfig: DataSourceManagerConfigOption<ConnectionOpts, ENTITY_CONFIG_KEY>, baseDirOrOptions: {
15
+ baseDir?: string;
15
16
  entitiesConfigKey?: string;
17
+ concurrent?: boolean;
16
18
  } | string): Promise<void>;
17
19
  /**
18
20
  * get a data source instance
@@ -31,8 +33,15 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
31
33
  * @param dataSourceName
32
34
  */
33
35
  isConnected(dataSourceName: string): Promise<boolean>;
34
- createInstance(config: any, clientName: any, options?: {
36
+ createInstance(config: ConnectionOpts): Promise<T | void>;
37
+ createInstance(config: ConnectionOpts, clientName: string, options?: {
38
+ /**
39
+ * @deprecated
40
+ */
35
41
  validateConnection?: boolean;
42
+ /**
43
+ * @deprecated
44
+ */
36
45
  cacheInstance?: boolean | undefined;
37
46
  }): Promise<T | void>;
38
47
  /**
@@ -53,7 +62,7 @@ export declare abstract class DataSourceManager<T, ConnectionOpts extends Record
53
62
  isHighPriority(name: string): boolean;
54
63
  isMediumPriority(name: string): boolean;
55
64
  isLowPriority(name: string): boolean;
65
+ static formatGlobString(globString: string): string[];
66
+ static globModels(globString: string, baseDir: string, loadMode?: ModuleLoadType): Promise<any[]>;
56
67
  }
57
- export declare function formatGlobString(globString: string): string[];
58
- export declare function globModels(globString: string, appDir: string, loadMode?: ModuleLoadType): Promise<any[]>;
59
68
  //# sourceMappingURL=dataSourceManager.d.ts.map