@midwayjs/core 3.19.0 → 4.0.0-alpha.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 (134) hide show
  1. package/dist/baseFramework.d.ts +7 -35
  2. package/dist/baseFramework.js +10 -52
  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.js +1 -1
  8. package/dist/common/dataSourceManager.js +3 -4
  9. package/dist/common/fileDetector.d.ts +9 -9
  10. package/dist/common/fileDetector.js +30 -28
  11. package/dist/common/filterManager.js +5 -4
  12. package/dist/common/guardManager.js +3 -2
  13. package/dist/common/middlewareManager.js +4 -3
  14. package/dist/common/performanceManager.js +1 -1
  15. package/dist/common/priorityManager.js +2 -2
  16. package/dist/common/serviceFactory.js +1 -1
  17. package/dist/common/webGenerator.js +4 -6
  18. package/dist/config/config.default.js +1 -1
  19. package/dist/constants.d.ts +2 -32
  20. package/dist/constants.js +3 -33
  21. package/dist/context/componentLoader.d.ts +20 -0
  22. package/dist/context/componentLoader.js +193 -0
  23. package/dist/context/container.d.ts +14 -29
  24. package/dist/context/container.js +68 -306
  25. package/dist/context/definitionRegistry.d.ts +3 -0
  26. package/dist/context/definitionRegistry.js +8 -15
  27. package/dist/context/managedResolverFactory.d.ts +15 -40
  28. package/dist/context/managedResolverFactory.js +263 -348
  29. package/dist/context/requestContainer.d.ts +22 -12
  30. package/dist/context/requestContainer.js +43 -51
  31. package/dist/decorator/common/aspect.js +4 -4
  32. package/dist/decorator/common/autoload.js +1 -1
  33. package/dist/decorator/common/configuration.d.ts +1 -24
  34. package/dist/decorator/common/configuration.js +6 -1
  35. package/dist/decorator/common/filter.js +6 -6
  36. package/dist/decorator/common/framework.d.ts +46 -3
  37. package/dist/decorator/common/framework.js +43 -9
  38. package/dist/decorator/common/guard.js +4 -9
  39. package/dist/decorator/common/inject.d.ts +4 -2
  40. package/dist/decorator/common/inject.js +87 -4
  41. package/dist/decorator/common/mock.js +1 -1
  42. package/dist/decorator/common/objectDef.d.ts +0 -5
  43. package/dist/decorator/common/objectDef.js +8 -20
  44. package/dist/decorator/common/provide.d.ts +1 -1
  45. package/dist/decorator/common/provide.js +1 -1
  46. package/dist/decorator/common/scope.d.ts +6 -0
  47. package/dist/decorator/common/scope.js +21 -0
  48. package/dist/decorator/constant.d.ts +14 -17
  49. package/dist/decorator/constant.js +23 -35
  50. package/dist/decorator/decoratorManager.d.ts +21 -294
  51. package/dist/decorator/decoratorManager.js +127 -694
  52. package/dist/decorator/faas/serverlessTrigger.js +5 -5
  53. package/dist/decorator/index.d.ts +2 -3
  54. package/dist/decorator/index.js +6 -4
  55. package/dist/decorator/metadataManager.d.ts +127 -0
  56. package/dist/decorator/metadataManager.js +465 -0
  57. package/dist/decorator/microservice/consumer.js +3 -2
  58. package/dist/decorator/microservice/kafkaListener.js +2 -1
  59. package/dist/decorator/microservice/provider.js +6 -5
  60. package/dist/decorator/microservice/rabbitmqListener.js +2 -1
  61. package/dist/decorator/task/queue.js +3 -2
  62. package/dist/decorator/task/schedule.js +3 -2
  63. package/dist/decorator/task/task.js +4 -3
  64. package/dist/decorator/task/taskLocal.js +4 -3
  65. package/dist/decorator/web/controller.js +3 -2
  66. package/dist/decorator/web/paramMapping.js +2 -2
  67. package/dist/decorator/web/requestMapping.js +5 -5
  68. package/dist/decorator/web/response.js +6 -5
  69. package/dist/decorator/ws/webSocketController.js +3 -2
  70. package/dist/decorator/ws/webSocketEvent.js +7 -6
  71. package/dist/definitions/functionDefinition.d.ts +3 -3
  72. package/dist/definitions/functionDefinition.js +12 -11
  73. package/dist/definitions/objectCreator.d.ts +5 -11
  74. package/dist/definitions/objectCreator.js +3 -27
  75. package/dist/definitions/objectDefinition.d.ts +2 -3
  76. package/dist/definitions/objectDefinition.js +1 -3
  77. package/dist/error/base.js +2 -2
  78. package/dist/error/framework.d.ts +1 -8
  79. package/dist/error/framework.js +9 -25
  80. package/dist/error/http.js +1 -1
  81. package/dist/functional/configuration.d.ts +14 -15
  82. package/dist/functional/configuration.js +37 -47
  83. package/dist/functional/hooks.d.ts +10 -0
  84. package/dist/functional/hooks.js +68 -0
  85. package/dist/functional/index.d.ts +3 -0
  86. package/dist/functional/index.js +22 -0
  87. package/dist/index.d.ts +3 -3
  88. package/dist/index.js +3 -6
  89. package/dist/interface.d.ts +80 -114
  90. package/dist/interface.js +9 -33
  91. package/dist/legacy/constants.d.ts +29 -0
  92. package/dist/legacy/constants.js +33 -0
  93. package/dist/legacy/decorator.d.ts +255 -0
  94. package/dist/legacy/decorator.js +468 -0
  95. package/dist/legacy/index.d.ts +3 -0
  96. package/dist/legacy/index.js +19 -0
  97. package/dist/legacy/types.d.ts +2 -0
  98. package/dist/legacy/types.js +3 -0
  99. package/dist/response/base.d.ts +1 -0
  100. package/dist/response/http.d.ts +1 -0
  101. package/dist/service/aspectService.js +11 -12
  102. package/dist/service/configService.js +2 -2
  103. package/dist/service/decoratorService.d.ts +3 -3
  104. package/dist/service/decoratorService.js +14 -10
  105. package/dist/service/environmentService.js +2 -2
  106. package/dist/service/frameworkService.d.ts +5 -4
  107. package/dist/service/frameworkService.js +30 -28
  108. package/dist/service/healthService.js +4 -4
  109. package/dist/service/informationService.js +3 -4
  110. package/dist/service/lifeCycleService.js +6 -17
  111. package/dist/service/loggerService.js +3 -4
  112. package/dist/service/middlewareService.js +7 -8
  113. package/dist/service/mockService.js +9 -15
  114. package/dist/service/slsFunctionService.d.ts +1 -14
  115. package/dist/service/slsFunctionService.js +33 -81
  116. package/dist/service/webRouterService.js +11 -11
  117. package/dist/setup.d.ts +5 -5
  118. package/dist/setup.js +75 -93
  119. package/dist/util/contextUtil.d.ts +2 -2
  120. package/dist/util/httpclient.d.ts +3 -2
  121. package/dist/util/index.d.ts +14 -0
  122. package/dist/util/index.js +159 -25
  123. package/dist/util/pathFileUtil.d.ts +14 -1
  124. package/dist/util/pathFileUtil.js +27 -6
  125. package/dist/util/webRouterParam.js +2 -2
  126. package/package.json +24 -6
  127. package/dist/decorator/common/pipeline.d.ts +0 -3
  128. package/dist/decorator/common/pipeline.js +0 -12
  129. package/dist/decorator/rpc/hsf.d.ts +0 -13
  130. package/dist/decorator/rpc/hsf.js +0 -20
  131. package/dist/definitions/properties.d.ts +0 -7
  132. package/dist/definitions/properties.js +0 -19
  133. package/dist/service/pipelineService.d.ts +0 -168
  134. package/dist/service/pipelineService.js +0 -254
@@ -16,6 +16,7 @@ const aspectService_1 = require("./aspectService");
16
16
  const error_1 = require("../error");
17
17
  const util = require("util");
18
18
  const types_1 = require("../util/types");
19
+ const metadataManager_1 = require("../decorator/metadataManager");
19
20
  const debug = util.debuglog('midway:debug');
20
21
  let MidwayDecoratorService = class MidwayDecoratorService {
21
22
  constructor(applicationContext) {
@@ -28,9 +29,11 @@ let MidwayDecoratorService = class MidwayDecoratorService {
28
29
  init() {
29
30
  // add custom method decorator listener
30
31
  this.applicationContext.onBeforeBind(Clzz => {
32
+ debug(`[core]: Bind class ${Clzz.name} in decorator service`);
31
33
  // find custom method decorator metadata, include method decorator information array
32
- const methodDecoratorMetadataList = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_METHOD, Clzz);
34
+ const methodDecoratorMetadataList = metadataManager_1.MetadataManager.getMetadata(decorator_1.CUSTOM_METHOD_INJECT_KEY, Clzz);
33
35
  if (methodDecoratorMetadataList) {
36
+ debug(`[core]: Find method decorator metadata in ${Clzz.name}`);
34
37
  // loop it, save this order for decorator run
35
38
  for (const meta of methodDecoratorMetadataList) {
36
39
  const { propertyName, key, metadata, options } = meta;
@@ -52,8 +55,9 @@ let MidwayDecoratorService = class MidwayDecoratorService {
52
55
  }
53
56
  }
54
57
  // find custom param decorator metadata
55
- const parameterDecoratorMetadata = (0, decorator_1.getClassMetadata)(decorator_1.INJECT_CUSTOM_PARAM, Clzz);
58
+ const parameterDecoratorMetadata = metadataManager_1.MetadataManager.getOwnPropertiesWithMetadata(decorator_1.CUSTOM_PARAM_INJECT_KEY, Clzz);
56
59
  if (parameterDecoratorMetadata) {
60
+ debug(`[core]: Find parameter decorator metadata in ${Clzz.name}`);
57
61
  // loop it, save this order for decorator run
58
62
  for (const methodName of Object.keys(parameterDecoratorMetadata)) {
59
63
  // add aspect implementation first
@@ -78,7 +82,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
78
82
  return originArgs[parameterIndex];
79
83
  };
80
84
  }
81
- const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
85
+ const paramTypes = metadataManager_1.MetadataManager.getMethodParamTypes(Clzz, propertyName);
82
86
  let skipPipes = false;
83
87
  try {
84
88
  newArgs[parameterIndex] = await parameterDecoratorHandler({
@@ -93,7 +97,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
93
97
  }
94
98
  catch (err) {
95
99
  skipPipes = true;
96
- if ((options === null || options === void 0 ? void 0 : options.throwError) === true) {
100
+ if (options?.throwError === true) {
97
101
  throw err;
98
102
  }
99
103
  else {
@@ -106,7 +110,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
106
110
  }
107
111
  const pipes = [
108
112
  ...(this.parameterDecoratorPipes.get(key) || []),
109
- ...((options === null || options === void 0 ? void 0 : options.pipes) || []),
113
+ ...(options?.pipes || []),
110
114
  ];
111
115
  for (const pipe of pipes) {
112
116
  let transform;
@@ -124,7 +128,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
124
128
  throw new error_1.MidwayParameterError('Pipe must be a function or implement PipeTransform interface');
125
129
  }
126
130
  newArgs[parameterIndex] = await transform(newArgs[parameterIndex], {
127
- metaType: (0, decorator_1.transformTypeFromTSDesign)(paramTypes[parameterIndex]),
131
+ metaType: metadataManager_1.MetadataManager.transformTypeFromTSDesign(paramTypes[parameterIndex]),
128
132
  metadata,
129
133
  target: joinPoint.target,
130
134
  methodName: joinPoint.methodName,
@@ -182,8 +186,8 @@ let MidwayDecoratorService = class MidwayDecoratorService {
182
186
  if (prop && getterHandler) {
183
187
  if (prop.propertyName) {
184
188
  Object.defineProperty(instance, prop.propertyName, {
185
- get: () => { var _a; return getterHandler(prop.propertyName, (_a = prop.metadata) !== null && _a !== void 0 ? _a : {}, instance); },
186
- configurable: true,
189
+ get: () => getterHandler(prop.propertyName, prop.metadata ?? {}, instance),
190
+ configurable: true, // 继承对象有可能会有相同属性,这里需要配置成 true
187
191
  enumerable: true,
188
192
  });
189
193
  }
@@ -195,6 +199,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
195
199
  }
196
200
  }
197
201
  };
202
+ exports.MidwayDecoratorService = MidwayDecoratorService;
198
203
  __decorate([
199
204
  (0, decorator_1.Inject)(),
200
205
  __metadata("design:type", aspectService_1.MidwayAspectService)
@@ -205,10 +210,9 @@ __decorate([
205
210
  __metadata("design:paramtypes", []),
206
211
  __metadata("design:returntype", void 0)
207
212
  ], MidwayDecoratorService.prototype, "init", null);
208
- MidwayDecoratorService = __decorate([
213
+ exports.MidwayDecoratorService = MidwayDecoratorService = __decorate([
209
214
  (0, decorator_1.Provide)(),
210
215
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
211
216
  __metadata("design:paramtypes", [Object])
212
217
  ], MidwayDecoratorService);
213
- exports.MidwayDecoratorService = MidwayDecoratorService;
214
218
  //# sourceMappingURL=decoratorService.js.map
@@ -36,9 +36,9 @@ let MidwayEnvironmentService = class MidwayEnvironmentService {
36
36
  return typeof process['pkg'] !== 'undefined';
37
37
  }
38
38
  };
39
- MidwayEnvironmentService = __decorate([
39
+ exports.MidwayEnvironmentService = MidwayEnvironmentService;
40
+ exports.MidwayEnvironmentService = MidwayEnvironmentService = __decorate([
40
41
  (0, decorator_1.Provide)(),
41
42
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
42
43
  ], MidwayEnvironmentService);
43
- exports.MidwayEnvironmentService = MidwayEnvironmentService;
44
44
  //# sourceMappingURL=environmentService.js.map
@@ -1,24 +1,25 @@
1
- import { IMidwayContainer, IMidwayFramework, MidwayFrameworkType } from '../interface';
1
+ import { IMidwayFramework, IMidwayGlobalContainer } from '../interface';
2
2
  import { MidwayConfigService } from './configService';
3
3
  import { MidwayLoggerService } from './loggerService';
4
4
  import { MidwayDecoratorService } from './decoratorService';
5
5
  import { MidwayAspectService } from './aspectService';
6
6
  import { MidwayApplicationManager } from '../common/applicationManager';
7
7
  export declare class MidwayFrameworkService {
8
- readonly applicationContext: IMidwayContainer;
8
+ readonly applicationContext: IMidwayGlobalContainer;
9
9
  readonly globalOptions: any;
10
10
  configService: MidwayConfigService;
11
11
  loggerService: MidwayLoggerService;
12
12
  aspectService: MidwayAspectService;
13
13
  decoratorService: MidwayDecoratorService;
14
14
  applicationManager: MidwayApplicationManager;
15
- constructor(applicationContext: IMidwayContainer, globalOptions: any);
15
+ constructor(applicationContext: IMidwayGlobalContainer, globalOptions: any);
16
16
  private mainFramework;
17
17
  private globalFrameworkList;
18
18
  protected init(): Promise<void>;
19
19
  getMainApp(): any;
20
+ setMainApp(namespace: string): void;
20
21
  getMainFramework(): IMidwayFramework<any, any, any, unknown, unknown>;
21
- getFramework(namespaceOrFrameworkType: string | MidwayFrameworkType): IMidwayFramework<any, any, any, unknown, unknown>;
22
+ getFramework(namespace: string): IMidwayFramework<any, any, any, unknown, unknown>;
22
23
  runFramework(): Promise<void>;
23
24
  stopFramework(): Promise<void>;
24
25
  }
@@ -15,13 +15,11 @@ const interface_1 = require("../interface");
15
15
  const configService_1 = require("./configService");
16
16
  const loggerService_1 = require("./loggerService");
17
17
  const baseFramework_1 = require("../baseFramework");
18
- const pipelineService_1 = require("./pipelineService");
19
18
  const decoratorService_1 = require("./decoratorService");
20
19
  const aspectService_1 = require("./aspectService");
21
20
  const applicationManager_1 = require("../common/applicationManager");
22
21
  const util = require("util");
23
22
  const error_1 = require("../error");
24
- const constants_1 = require("../constants");
25
23
  const performanceManager_1 = require("../common/performanceManager");
26
24
  const debug = util.debuglog('midway:debug');
27
25
  let MidwayFrameworkService = class MidwayFrameworkService {
@@ -31,25 +29,18 @@ let MidwayFrameworkService = class MidwayFrameworkService {
31
29
  this.globalFrameworkList = [];
32
30
  }
33
31
  async init() {
34
- var _a, _b;
35
32
  // register base config hook
36
33
  this.decoratorService.registerPropertyHandler(decorator_1.CONFIG_KEY, (propertyName, meta) => {
37
- var _a;
38
- if (meta.identifier === decorator_1.ALL) {
34
+ if (meta.identifier === decorator_1.ALL_VALUE_KEY) {
39
35
  return this.configService.getConfiguration();
40
36
  }
41
37
  else {
42
- return this.configService.getConfiguration((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
38
+ return this.configService.getConfiguration(meta.identifier ?? propertyName);
43
39
  }
44
40
  });
45
41
  // register @Logger decorator handler
46
42
  this.decoratorService.registerPropertyHandler(decorator_1.LOGGER_KEY, (propertyName, meta) => {
47
- var _a;
48
- return this.loggerService.getLogger((_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName);
49
- });
50
- this.decoratorService.registerPropertyHandler(decorator_1.PIPELINE_IDENTIFIER, (key, meta, instance) => {
51
- var _a, _b;
52
- return new pipelineService_1.MidwayPipelineService((_b = (_a = instance[constants_1.REQUEST_OBJ_CTX_KEY]) === null || _a === void 0 ? void 0 : _a.requestContext) !== null && _b !== void 0 ? _b : this.applicationContext, meta.valves);
43
+ return this.loggerService.getLogger(meta.identifier ?? propertyName);
53
44
  });
54
45
  // register @App decorator handler
55
46
  this.decoratorService.registerPropertyHandler(decorator_1.APPLICATION_KEY, (propertyName, meta) => {
@@ -64,9 +55,12 @@ let MidwayFrameworkService = class MidwayFrameworkService {
64
55
  return this.getMainApp();
65
56
  }
66
57
  });
58
+ // register @MainApp decorator handler
59
+ this.decoratorService.registerPropertyHandler(decorator_1.MAIN_APPLICATION_KEY, (propertyName, meta) => {
60
+ return this.getMainApp();
61
+ });
67
62
  this.decoratorService.registerPropertyHandler(decorator_1.PLUGIN_KEY, (propertyName, meta) => {
68
- var _a;
69
- return this.getMainApp()[(_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName];
63
+ return this.getMainApp()[meta.identifier ?? propertyName];
70
64
  });
71
65
  this.decoratorService.registerPropertyHandler(decorator_1.FACTORY_SERVICE_CLIENT_KEY, (propertyName, meta) => {
72
66
  const factory = this.applicationContext.get(meta.serviceFactoryClz);
@@ -83,13 +77,13 @@ let MidwayFrameworkService = class MidwayFrameworkService {
83
77
  }
84
78
  }
85
79
  });
86
- let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
80
+ let frameworks = decorator_1.DecoratorManager.listModule(decorator_1.FRAMEWORK_KEY);
87
81
  // filter proto
88
82
  frameworks = filterProtoFramework(frameworks);
89
83
  debug(`[core]: Found Framework length = ${frameworks.length}`);
90
84
  if (frameworks.length) {
91
85
  for (const frameworkClz of frameworks) {
92
- if (!this.applicationContext.hasDefinition((0, decorator_1.getProviderUUId)(frameworkClz))) {
86
+ if (!this.applicationContext.hasDefinition(decorator_1.DecoratorManager.getProviderUUId(frameworkClz))) {
93
87
  debug(`[core]: Found Framework "${frameworkClz.name}" but missing definition, skip initialize.`);
94
88
  continue;
95
89
  }
@@ -110,11 +104,16 @@ let MidwayFrameworkService = class MidwayFrameworkService {
110
104
  debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and delay initialize.`);
111
105
  }
112
106
  // app init
113
- const definition = this.applicationContext.registry.getDefinition((0, decorator_1.getProviderUUId)(frameworkClz));
107
+ const definition = this.applicationContext.registry.getDefinition(decorator_1.DecoratorManager.getProviderUUId(frameworkClz));
114
108
  // set framework namespace here
115
- frameworkInstance.setNamespace(definition === null || definition === void 0 ? void 0 : definition.namespace);
109
+ frameworkInstance.setNamespace(definition?.namespace);
116
110
  // link framework to application manager
117
- this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
111
+ this.applicationManager.addFramework(frameworkInstance.getFrameworkName() ?? definition?.namespace, frameworkInstance);
112
+ // Namespace associates unique framework
113
+ if (definition?.namespace &&
114
+ !this.applicationManager.hasFramework(definition.namespace)) {
115
+ this.applicationManager.addFramework(definition.namespace, frameworkInstance);
116
+ }
118
117
  this.globalFrameworkList.push(frameworkInstance);
119
118
  }
120
119
  let mainNs;
@@ -126,28 +125,31 @@ let MidwayFrameworkService = class MidwayFrameworkService {
126
125
  */
127
126
  const namespaceList = this.applicationContext.getNamespaceList();
128
127
  for (const namespace of namespaceList) {
129
- const framework = this.applicationManager.getApplication(namespace);
130
- if (framework) {
128
+ const frameworkApp = this.applicationManager.getApplication(namespace);
129
+ if (frameworkApp) {
131
130
  mainNs = namespace;
132
131
  break;
133
132
  }
134
133
  }
135
134
  global['MIDWAY_MAIN_FRAMEWORK'] = this.mainFramework =
136
- (_b = this.applicationManager.getFramework(mainNs)) !== null && _b !== void 0 ? _b : this.globalFrameworkList[0];
135
+ this.applicationManager.getFramework(mainNs) ??
136
+ this.globalFrameworkList[0];
137
137
  debug(`[core]: Current main Framework is "${mainNs}".`);
138
138
  }
139
139
  // init aspect module
140
140
  await this.aspectService.loadAspect();
141
141
  }
142
142
  getMainApp() {
143
- var _a;
144
- return (_a = this.mainFramework) === null || _a === void 0 ? void 0 : _a.getApplication();
143
+ return this.mainFramework?.getApplication();
144
+ }
145
+ setMainApp(namespace) {
146
+ this.mainFramework = this.applicationManager.getFramework(namespace);
145
147
  }
146
148
  getMainFramework() {
147
149
  return this.mainFramework;
148
150
  }
149
- getFramework(namespaceOrFrameworkType) {
150
- return this.applicationManager.getFramework(namespaceOrFrameworkType);
151
+ getFramework(namespace) {
152
+ return this.applicationManager.getFramework(namespace);
151
153
  }
152
154
  async runFramework() {
153
155
  const namespaceList = this.applicationContext.getNamespaceList();
@@ -173,6 +175,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
173
175
  }));
174
176
  }
175
177
  };
178
+ exports.MidwayFrameworkService = MidwayFrameworkService;
176
179
  __decorate([
177
180
  (0, decorator_1.Inject)(),
178
181
  __metadata("design:type", configService_1.MidwayConfigService)
@@ -199,12 +202,11 @@ __decorate([
199
202
  __metadata("design:paramtypes", []),
200
203
  __metadata("design:returntype", Promise)
201
204
  ], MidwayFrameworkService.prototype, "init", null);
202
- MidwayFrameworkService = __decorate([
205
+ exports.MidwayFrameworkService = MidwayFrameworkService = __decorate([
203
206
  (0, decorator_1.Provide)(),
204
207
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
205
208
  __metadata("design:paramtypes", [Object, Object])
206
209
  ], MidwayFrameworkService);
207
- exports.MidwayFrameworkService = MidwayFrameworkService;
208
210
  function filterProtoFramework(frameworks) {
209
211
  const frameworkProtoArr = [];
210
212
  // 这里把继承的框架父类都找出来,然后排除掉,只取第一层
@@ -70,8 +70,8 @@ let MidwayHealthService = class MidwayHealthService {
70
70
  const failedResult = checkResult.find(item => !item.status);
71
71
  return {
72
72
  status: !failedResult,
73
- namespace: failedResult === null || failedResult === void 0 ? void 0 : failedResult.namespace,
74
- reason: failedResult === null || failedResult === void 0 ? void 0 : failedResult.reason,
73
+ namespace: failedResult?.namespace,
74
+ reason: failedResult?.reason,
75
75
  results: checkResult,
76
76
  };
77
77
  }
@@ -79,6 +79,7 @@ let MidwayHealthService = class MidwayHealthService {
79
79
  this.healthCheckTimeout = timeout;
80
80
  }
81
81
  };
82
+ exports.MidwayHealthService = MidwayHealthService;
82
83
  __decorate([
83
84
  (0, decorator_1.Inject)(),
84
85
  __metadata("design:type", configService_1.MidwayConfigService)
@@ -87,9 +88,8 @@ __decorate([
87
88
  (0, decorator_1.ApplicationContext)(),
88
89
  __metadata("design:type", Object)
89
90
  ], MidwayHealthService.prototype, "applicationContext", void 0);
90
- MidwayHealthService = __decorate([
91
+ exports.MidwayHealthService = MidwayHealthService = __decorate([
91
92
  (0, decorator_1.Provide)(),
92
93
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
93
94
  ], MidwayHealthService);
94
- exports.MidwayHealthService = MidwayHealthService;
95
95
  //# sourceMappingURL=healthService.js.map
@@ -49,14 +49,14 @@ let MidwayInformationService = class MidwayInformationService {
49
49
  return this.pkg;
50
50
  }
51
51
  getProjectName() {
52
- var _a;
53
- return ((_a = this.pkg) === null || _a === void 0 ? void 0 : _a['name']) || '';
52
+ return this.pkg?.['name'] || '';
54
53
  }
55
54
  getRoot() {
56
55
  const isDevelopmentEnv = (0, util_1.isDevelopmentEnvironment)((0, util_1.getCurrentEnvironment)());
57
56
  return isDevelopmentEnv ? this.getAppDir() : this.getHome();
58
57
  }
59
58
  };
59
+ exports.MidwayInformationService = MidwayInformationService;
60
60
  __decorate([
61
61
  (0, decorator_1.Inject)(),
62
62
  __metadata("design:type", String)
@@ -71,9 +71,8 @@ __decorate([
71
71
  __metadata("design:paramtypes", []),
72
72
  __metadata("design:returntype", void 0)
73
73
  ], MidwayInformationService.prototype, "init", null);
74
- MidwayInformationService = __decorate([
74
+ exports.MidwayInformationService = MidwayInformationService = __decorate([
75
75
  (0, decorator_1.Provide)(),
76
76
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
77
77
  ], MidwayInformationService);
78
- exports.MidwayInformationService = MidwayInformationService;
79
78
  //# sourceMappingURL=informationService.js.map
@@ -12,12 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayLifeCycleService = void 0;
13
13
  const interface_1 = require("../interface");
14
14
  const decorator_1 = require("../decorator");
15
- const configuration_1 = require("../functional/configuration");
16
15
  const frameworkService_1 = require("./frameworkService");
17
16
  const configService_1 = require("./configService");
18
17
  const util_1 = require("util");
19
18
  const mockService_1 = require("./mockService");
20
19
  const healthService_1 = require("./healthService");
20
+ const metadataManager_1 = require("../decorator/metadataManager");
21
21
  const performanceManager_1 = require("../common/performanceManager");
22
22
  const debug = (0, util_1.debuglog)('midway:debug');
23
23
  let MidwayLifeCycleService = class MidwayLifeCycleService {
@@ -29,10 +29,10 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
29
29
  // exec simulator init
30
30
  await this.mockService.initSimulation();
31
31
  // run lifecycle
32
- const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
32
+ const cycles = decorator_1.DecoratorManager.listModule(decorator_1.CONFIGURATION_KEY);
33
33
  debug(`[core]: Found Configuration length = ${cycles.length}`);
34
34
  for (const cycle of cycles) {
35
- if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
35
+ if (metadataManager_1.MetadataManager.hasOwnMetadata(decorator_1.CONFIGURATION_OBJECT_KEY, cycle.target)) {
36
36
  // 函数式写法
37
37
  cycle.instance = cycle.target;
38
38
  }
@@ -75,18 +75,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
75
75
  async stop() {
76
76
  await this.mockService.runSimulatorTearDown();
77
77
  // stop lifecycle
78
- const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY) || [];
79
- for (const cycle of cycles.reverse()) {
80
- let inst;
81
- if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
82
- // 函数式写法
83
- inst = cycle.target;
84
- }
85
- else {
86
- inst = await this.applicationContext.getAsync(cycle.target);
87
- }
88
- await this.runContainerLifeCycle(inst, 'onStop');
89
- }
78
+ await this.runContainerLifeCycle(this.lifecycleInstanceList.reverse(), 'onStop');
90
79
  // stop framework
91
80
  await this.frameworkService.stopFramework();
92
81
  }
@@ -140,6 +129,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
140
129
  return this.lifecycleInstanceList;
141
130
  }
142
131
  };
132
+ exports.MidwayLifeCycleService = MidwayLifeCycleService;
143
133
  __decorate([
144
134
  (0, decorator_1.Inject)(),
145
135
  __metadata("design:type", frameworkService_1.MidwayFrameworkService)
@@ -162,10 +152,9 @@ __decorate([
162
152
  __metadata("design:paramtypes", []),
163
153
  __metadata("design:returntype", Promise)
164
154
  ], MidwayLifeCycleService.prototype, "init", null);
165
- MidwayLifeCycleService = __decorate([
155
+ exports.MidwayLifeCycleService = MidwayLifeCycleService = __decorate([
166
156
  (0, decorator_1.Provide)(),
167
157
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
168
158
  __metadata("design:paramtypes", [Object])
169
159
  ], MidwayLifeCycleService);
170
- exports.MidwayLifeCycleService = MidwayLifeCycleService;
171
160
  //# sourceMappingURL=lifeCycleService.js.map
@@ -25,7 +25,6 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
25
25
  this.aliasLoggerMap = new Map();
26
26
  }
27
27
  init() {
28
- var _a;
29
28
  const loggerFactory = this.configService.getConfiguration('loggerFactory');
30
29
  // load logger factory from user config first
31
30
  this.loggerFactory =
@@ -42,7 +41,7 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
42
41
  // init logger
43
42
  this.initClients(this.configService.getConfiguration('midwayLogger'));
44
43
  // alias inject logger
45
- (_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
44
+ this.applicationContext?.registerObject('logger', this.getLogger('appLogger'));
46
45
  }
47
46
  createClient(config, name) {
48
47
  if (config.aliasName) {
@@ -93,6 +92,7 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
93
92
  return Array.from(this.clients.keys());
94
93
  }
95
94
  };
95
+ exports.MidwayLoggerService = MidwayLoggerService;
96
96
  __decorate([
97
97
  (0, decorator_1.Inject)(),
98
98
  __metadata("design:type", configService_1.MidwayConfigService)
@@ -103,10 +103,9 @@ __decorate([
103
103
  __metadata("design:paramtypes", []),
104
104
  __metadata("design:returntype", void 0)
105
105
  ], MidwayLoggerService.prototype, "init", null);
106
- MidwayLoggerService = __decorate([
106
+ exports.MidwayLoggerService = MidwayLoggerService = __decorate([
107
107
  (0, decorator_1.Provide)(),
108
108
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
109
109
  __metadata("design:paramtypes", [Object, Object])
110
110
  ], MidwayLoggerService);
111
- exports.MidwayLoggerService = MidwayLoggerService;
112
111
  //# sourceMappingURL=loggerService.js.map
@@ -22,23 +22,22 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
22
22
  this.applicationContext = applicationContext;
23
23
  }
24
24
  async compose(middleware, app, name) {
25
- var _a;
26
25
  if (!Array.isArray(middleware)) {
27
26
  throw new error_1.MidwayParameterError('Middleware stack must be an array');
28
27
  }
29
28
  const newMiddlewareArr = [];
30
29
  for (let fn of middleware) {
31
- if (types_1.Types.isClass(fn) || typeof fn === 'string' || (fn === null || fn === void 0 ? void 0 : fn['middleware'])) {
32
- let mw = (_a = fn === null || fn === void 0 ? void 0 : fn['middleware']) !== null && _a !== void 0 ? _a : fn;
33
- const mwConfig = fn === null || fn === void 0 ? void 0 : fn['options'];
34
- let mwName = fn === null || fn === void 0 ? void 0 : fn['name'];
30
+ if (types_1.Types.isClass(fn) || typeof fn === 'string' || fn?.['middleware']) {
31
+ let mw = fn?.['middleware'] ?? fn;
32
+ const mwConfig = fn?.['options'];
33
+ let mwName = fn?.['name'];
35
34
  if (typeof mw === 'string' &&
36
35
  !this.applicationContext.hasDefinition(mw)) {
37
36
  throw new error_1.MidwayCommonError(`Middleware definition of "${mw}" not found in midway container`);
38
37
  }
39
38
  const classMiddleware = await this.applicationContext.getAsync(mw);
40
39
  if (classMiddleware) {
41
- mwName = mwName !== null && mwName !== void 0 ? mwName : classMiddleware.constructor.name;
40
+ mwName = mwName ?? classMiddleware.constructor.name;
42
41
  mw = await classMiddleware.resolve(app, mwConfig);
43
42
  if (!mw) {
44
43
  // for middleware enabled
@@ -139,10 +138,10 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
139
138
  return composeFn;
140
139
  }
141
140
  };
142
- MidwayMiddlewareService = __decorate([
141
+ exports.MidwayMiddlewareService = MidwayMiddlewareService;
142
+ exports.MidwayMiddlewareService = MidwayMiddlewareService = __decorate([
143
143
  (0, decorator_1.Provide)(),
144
144
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
145
145
  __metadata("design:paramtypes", [Object])
146
146
  ], MidwayMiddlewareService);
147
- exports.MidwayMiddlewareService = MidwayMiddlewareService;
148
147
  //# sourceMappingURL=middlewareService.js.map
@@ -166,7 +166,7 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
166
166
  return descriptor;
167
167
  }
168
168
  async initSimulation(group = 'default') {
169
- const simulationModule = (0, decorator_1.listModule)(decorator_1.MOCK_KEY);
169
+ const simulationModule = decorator_1.DecoratorManager.listModule(decorator_1.MOCK_KEY);
170
170
  for (const module of simulationModule) {
171
171
  const instance = await this.applicationContext.getAsync(module);
172
172
  if (await instance.enableCondition()) {
@@ -176,48 +176,43 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
176
176
  }
177
177
  }
178
178
  async runSimulatorSetup() {
179
- var _a;
180
179
  for (const simulator of this.simulatorList) {
181
- await ((_a = simulator.setup) === null || _a === void 0 ? void 0 : _a.call(simulator));
180
+ await simulator.setup?.();
182
181
  }
183
182
  }
184
183
  async runSimulatorTearDown() {
185
- var _a;
186
184
  // reverse loop and not change origin simulatorList
187
185
  for (let i = this.simulatorList.length - 1; i >= 0; i--) {
188
186
  const simulator = this.simulatorList[i];
189
- await ((_a = simulator.tearDown) === null || _a === void 0 ? void 0 : _a.call(simulator));
187
+ await simulator.tearDown?.();
190
188
  }
191
189
  }
192
190
  async runSimulatorAppSetup(app) {
193
- var _a;
194
191
  for (const simulator of this.simulatorList) {
195
- await ((_a = simulator.appSetup) === null || _a === void 0 ? void 0 : _a.call(simulator, app));
192
+ await simulator.appSetup?.(app);
196
193
  }
197
194
  }
198
195
  async runSimulatorAppTearDown(app) {
199
- var _a;
200
196
  // reverse loop and not change origin simulatorList
201
197
  for (let i = this.simulatorList.length - 1; i >= 0; i--) {
202
198
  const simulator = this.simulatorList[i];
203
- await ((_a = simulator.appTearDown) === null || _a === void 0 ? void 0 : _a.call(simulator, app));
199
+ await simulator.appTearDown?.(app);
204
200
  }
205
201
  }
206
202
  async runSimulatorContextSetup(ctx, app) {
207
- var _a;
208
203
  for (const simulator of this.simulatorList) {
209
- await ((_a = simulator.contextSetup) === null || _a === void 0 ? void 0 : _a.call(simulator, ctx, app));
204
+ await simulator.contextSetup?.(ctx, app);
210
205
  }
211
206
  }
212
207
  async runSimulatorContextTearDown(ctx, app) {
213
- var _a;
214
208
  // reverse loop and not change origin simulatorList
215
209
  for (let i = this.simulatorList.length - 1; i >= 0; i--) {
216
210
  const simulator = this.simulatorList[i];
217
- await ((_a = simulator === null || simulator === void 0 ? void 0 : simulator.contextTearDown) === null || _a === void 0 ? void 0 : _a.call(simulator, ctx, app));
211
+ await simulator?.contextTearDown?.(ctx, app);
218
212
  }
219
213
  }
220
214
  };
215
+ exports.MidwayMockService = MidwayMockService;
221
216
  /**
222
217
  * Prepare mocks before the service is initialized
223
218
  */
@@ -234,10 +229,9 @@ __decorate([
234
229
  __metadata("design:paramtypes", []),
235
230
  __metadata("design:returntype", void 0)
236
231
  ], MidwayMockService.prototype, "restoreAll", null);
237
- MidwayMockService = MidwayMockService_1 = __decorate([
232
+ exports.MidwayMockService = MidwayMockService = MidwayMockService_1 = __decorate([
238
233
  (0, decorator_1.Provide)(),
239
234
  (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
240
235
  __metadata("design:paramtypes", [Object])
241
236
  ], MidwayMockService);
242
- exports.MidwayMockService = MidwayMockService;
243
237
  //# sourceMappingURL=mockService.js.map
@@ -1,4 +1,4 @@
1
- import { MidwayWebRouterService, RouterCollectorOptions, RouterInfo, RouterPriority } from './webRouterService';
1
+ import { MidwayWebRouterService, RouterCollectorOptions, RouterInfo } from './webRouterService';
2
2
  import { FaaSMetadata } from '../interface';
3
3
  export declare class MidwayServerlessFunctionService extends MidwayWebRouterService {
4
4
  readonly options: RouterCollectorOptions;
@@ -9,17 +9,4 @@ export declare class MidwayServerlessFunctionService extends MidwayWebRouterServ
9
9
  getFunctionList(): Promise<RouterInfo[]>;
10
10
  addServerlessFunction(func: (...args: any[]) => Promise<any>, triggerOptions: FaaSMetadata.TriggerMetadata, functionOptions?: FaaSMetadata.ServerlessFunctionOptions): void;
11
11
  }
12
- /**
13
- * @deprecated use built-in MidwayWebRouterService first
14
- */
15
- export declare class WebRouterCollector {
16
- private baseDir;
17
- private options;
18
- private proxy;
19
- constructor(baseDir?: string, options?: RouterCollectorOptions);
20
- protected init(): Promise<void>;
21
- getRoutePriorityList(): Promise<RouterPriority[]>;
22
- getRouterTable(): Promise<Map<string, RouterInfo[]>>;
23
- getFlattenRouterTable(): Promise<RouterInfo[]>;
24
- }
25
12
  //# sourceMappingURL=slsFunctionService.d.ts.map