@midwayjs/core 3.8.0 → 3.10.0

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 (101) hide show
  1. package/dist/baseFramework.d.ts +5 -2
  2. package/dist/baseFramework.js +17 -0
  3. package/dist/common/applicationManager.d.ts +1 -2
  4. package/dist/common/applicationManager.js +2 -1
  5. package/dist/common/dataSourceManager.d.ts +1 -0
  6. package/dist/common/dataSourceManager.js +14 -12
  7. package/dist/common/loggerFactory.d.ts +8 -0
  8. package/dist/common/loggerFactory.js +7 -0
  9. package/dist/common/serviceFactory.d.ts +3 -2
  10. package/dist/common/webGenerator.js +2 -1
  11. package/dist/config/config.default.js +2 -1
  12. package/dist/constants.d.ts +1 -11
  13. package/dist/constants.js +2 -12
  14. package/dist/context/container.d.ts +1 -2
  15. package/dist/context/container.js +3 -3
  16. package/dist/context/definitionRegistry.d.ts +1 -5
  17. package/dist/context/managedResolverFactory.d.ts +1 -2
  18. package/dist/context/managedResolverFactory.js +2 -3
  19. package/dist/context/providerWrapper.d.ts +1 -2
  20. package/dist/decorator/common/aspect.d.ts +0 -18
  21. package/dist/decorator/common/aspect.js +2 -1
  22. package/dist/decorator/common/filter.d.ts +1 -1
  23. package/dist/decorator/common/filter.js +1 -1
  24. package/dist/decorator/common/framework.d.ts +1 -1
  25. package/dist/decorator/common/framework.js +2 -1
  26. package/dist/decorator/common/guard.js +1 -1
  27. package/dist/decorator/common/inject.d.ts +2 -1
  28. package/dist/decorator/common/inject.js +9 -1
  29. package/dist/decorator/common/middleware.js +2 -1
  30. package/dist/decorator/common/mock.d.ts +2 -0
  31. package/dist/decorator/common/mock.js +14 -0
  32. package/dist/decorator/common/objectDef.d.ts +2 -1
  33. package/dist/decorator/common/objectDef.js +10 -1
  34. package/dist/decorator/common/pipe.d.ts +2 -0
  35. package/dist/decorator/common/pipe.js +13 -0
  36. package/dist/decorator/common/pipeline.d.ts +1 -1
  37. package/dist/decorator/common/provide.d.ts +1 -1
  38. package/dist/decorator/constant.d.ts +2 -0
  39. package/dist/decorator/constant.js +4 -2
  40. package/dist/decorator/decoratorManager.d.ts +6 -10
  41. package/dist/decorator/decoratorManager.js +20 -8
  42. package/dist/decorator/faas/serverlessTrigger.d.ts +3 -1
  43. package/dist/decorator/faas/serverlessTrigger.js +3 -2
  44. package/dist/decorator/index.d.ts +2 -1
  45. package/dist/decorator/index.js +2 -1
  46. package/dist/decorator/microservice/consumer.d.ts +1 -1
  47. package/dist/decorator/microservice/consumer.js +2 -1
  48. package/dist/decorator/microservice/kafkaListener.d.ts +3 -3
  49. package/dist/decorator/microservice/provider.d.ts +1 -1
  50. package/dist/decorator/microservice/provider.js +2 -1
  51. package/dist/decorator/rpc/hsf.d.ts +1 -0
  52. package/dist/decorator/rpc/hsf.js +3 -1
  53. package/dist/decorator/task/schedule.js +2 -1
  54. package/dist/decorator/web/controller.d.ts +1 -1
  55. package/dist/decorator/web/controller.js +2 -1
  56. package/dist/decorator/web/requestMapping.d.ts +1 -4
  57. package/dist/decorator/ws/webSocketController.d.ts +1 -1
  58. package/dist/decorator/ws/webSocketController.js +2 -1
  59. package/dist/decorator/ws/webSocketEvent.d.ts +1 -1
  60. package/dist/definitions/functionDefinition.d.ts +1 -2
  61. package/dist/definitions/functionDefinition.js +4 -4
  62. package/dist/definitions/objectDefinition.d.ts +1 -2
  63. package/dist/definitions/objectDefinition.js +4 -4
  64. package/dist/definitions/properties.d.ts +1 -2
  65. package/dist/error/base.d.ts +2 -2
  66. package/dist/error/framework.d.ts +1 -1
  67. package/dist/error/framework.js +5 -5
  68. package/dist/index.d.ts +1 -0
  69. package/dist/index.js +1 -0
  70. package/dist/interface.d.ts +344 -25
  71. package/dist/interface.js +64 -1
  72. package/dist/service/aspectService.d.ts +1 -2
  73. package/dist/service/aspectService.js +2 -1
  74. package/dist/service/configService.js +2 -1
  75. package/dist/service/decoratorService.d.ts +3 -1
  76. package/dist/service/decoratorService.js +64 -12
  77. package/dist/service/environmentService.js +2 -1
  78. package/dist/service/frameworkService.d.ts +1 -2
  79. package/dist/service/frameworkService.js +21 -1
  80. package/dist/service/informationService.js +2 -1
  81. package/dist/service/lifeCycleService.d.ts +2 -0
  82. package/dist/service/lifeCycleService.js +14 -4
  83. package/dist/service/loggerService.d.ts +11 -7
  84. package/dist/service/loggerService.js +31 -9
  85. package/dist/service/middlewareService.js +2 -1
  86. package/dist/service/mockService.d.ts +9 -1
  87. package/dist/service/mockService.js +43 -1
  88. package/dist/service/pipelineService.d.ts +2 -3
  89. package/dist/service/slsFunctionService.d.ts +1 -1
  90. package/dist/service/slsFunctionService.js +3 -2
  91. package/dist/service/webRouterService.d.ts +1 -1
  92. package/dist/service/webRouterService.js +3 -2
  93. package/dist/setup.js +6 -2
  94. package/dist/util/camelCase.js +8 -5
  95. package/dist/util/httpclient.d.ts +2 -2
  96. package/dist/util/pathToRegexp.d.ts +5 -5
  97. package/dist/util/webRouterParam.d.ts +2 -4
  98. package/dist/util/webRouterParam.js +5 -27
  99. package/package.json +5 -6
  100. package/dist/decorator/interface.d.ts +0 -242
  101. package/dist/decorator/interface.js +0 -66
@@ -11,9 +11,11 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayDecoratorService = void 0;
13
13
  const decorator_1 = require("../decorator");
14
+ const interface_1 = require("../interface");
14
15
  const aspectService_1 = require("./aspectService");
15
16
  const error_1 = require("../error");
16
17
  const util = require("util");
18
+ const types_1 = require("../util/types");
17
19
  const debug = util.debuglog('midway:debug');
18
20
  let MidwayDecoratorService = class MidwayDecoratorService {
19
21
  constructor(applicationContext) {
@@ -21,6 +23,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
21
23
  this.propertyHandlerMap = new Map();
22
24
  this.methodDecoratorMap = new Map();
23
25
  this.parameterDecoratorMap = new Map();
26
+ this.parameterDecoratorPipes = new Map();
24
27
  }
25
28
  init() {
26
29
  // add custom method decorator listener
@@ -30,8 +33,8 @@ let MidwayDecoratorService = class MidwayDecoratorService {
30
33
  if (methodDecoratorMetadataList) {
31
34
  // loop it, save this order for decorator run
32
35
  for (const meta of methodDecoratorMetadataList) {
33
- const { propertyName, key, metadata, impl } = meta;
34
- if (!impl) {
36
+ const { propertyName, key, metadata, options } = meta;
37
+ if (!options.impl) {
35
38
  continue;
36
39
  }
37
40
  // add aspect implementation first
@@ -40,7 +43,7 @@ let MidwayDecoratorService = class MidwayDecoratorService {
40
43
  if (!methodDecoratorHandler) {
41
44
  throw new error_1.MidwayCommonError(`Method Decorator "${key}" handler not found, please register first.`);
42
45
  }
43
- return this.methodDecoratorMap.get(key)({
46
+ return methodDecoratorHandler({
44
47
  target: Clzz,
45
48
  propertyName,
46
49
  metadata,
@@ -60,15 +63,23 @@ let MidwayDecoratorService = class MidwayDecoratorService {
60
63
  // joinPoint.args
61
64
  const newArgs = [...joinPoint.args];
62
65
  for (const meta of parameterDecoratorMetadata[methodName]) {
63
- const { propertyName, key, metadata, parameterIndex, impl } = meta;
64
- if (!impl) {
65
- continue;
66
+ const { propertyName, key, metadata, parameterIndex, options, } = meta;
67
+ let parameterDecoratorHandler;
68
+ if (options.impl) {
69
+ parameterDecoratorHandler =
70
+ this.parameterDecoratorMap.get(key);
71
+ if (!parameterDecoratorHandler) {
72
+ throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
73
+ }
66
74
  }
67
- const parameterDecoratorHandler = this.parameterDecoratorMap.get(key);
68
- if (!parameterDecoratorHandler) {
69
- throw new error_1.MidwayCommonError(`Parameter Decorator "${key}" handler not found, please register first.`);
75
+ else {
76
+ // set default handler
77
+ parameterDecoratorHandler = async ({ parameterIndex, originArgs, }) => {
78
+ return originArgs[parameterIndex];
79
+ };
70
80
  }
71
81
  const paramTypes = (0, decorator_1.getMethodParamTypes)(Clzz, propertyName);
82
+ let skipPipes = false;
72
83
  try {
73
84
  newArgs[parameterIndex] = await parameterDecoratorHandler({
74
85
  metadata,
@@ -80,8 +91,43 @@ let MidwayDecoratorService = class MidwayDecoratorService {
80
91
  });
81
92
  }
82
93
  catch (err) {
83
- // ignore
84
- debug(`[core]: Parameter decorator throw error and use origin args, ${err.stack}`);
94
+ skipPipes = true;
95
+ if ((options === null || options === void 0 ? void 0 : options.throwError) === true) {
96
+ throw err;
97
+ }
98
+ else {
99
+ // ignore
100
+ debug(`[core]: Parameter decorator throw error and use origin args, ${err.stack}`);
101
+ }
102
+ }
103
+ if (skipPipes) {
104
+ continue;
105
+ }
106
+ const pipes = [
107
+ ...(this.parameterDecoratorPipes.get(key) || []),
108
+ ...((options === null || options === void 0 ? void 0 : options.pipes) || []),
109
+ ];
110
+ for (const pipe of pipes) {
111
+ let transform;
112
+ if ('transform' in pipe) {
113
+ transform = pipe['transform'].bind(pipe);
114
+ }
115
+ else if ((0, types_1.isClass)(pipe)) {
116
+ const ins = await this.applicationContext.getAsync(pipe);
117
+ transform = ins.transform.bind(ins);
118
+ }
119
+ else if (typeof pipe === 'function') {
120
+ transform = pipe;
121
+ }
122
+ else {
123
+ throw new error_1.MidwayParameterError('Pipe must be a function or implement PipeTransform interface');
124
+ }
125
+ newArgs[parameterIndex] = await transform(newArgs[parameterIndex], {
126
+ metaType: (0, decorator_1.transformTypeFromTSDesign)(paramTypes[parameterIndex]),
127
+ metadata,
128
+ target: joinPoint.target,
129
+ methodName: joinPoint.methodName,
130
+ });
85
131
  }
86
132
  }
87
133
  joinPoint.args = newArgs;
@@ -118,6 +164,12 @@ let MidwayDecoratorService = class MidwayDecoratorService {
118
164
  debug(`[core]: Register parameter decorator key="${decoratorKey}"`);
119
165
  this.parameterDecoratorMap.set(decoratorKey, fn);
120
166
  }
167
+ registerParameterPipes(decoratorKey, pipes) {
168
+ if (!this.parameterDecoratorPipes.has(decoratorKey)) {
169
+ this.parameterDecoratorPipes.set(decoratorKey, []);
170
+ }
171
+ this.parameterDecoratorPipes.set(decoratorKey, this.parameterDecoratorPipes.get(decoratorKey).concat(pipes));
172
+ }
121
173
  /**
122
174
  * binding getter method for decorator
123
175
  *
@@ -154,7 +206,7 @@ __decorate([
154
206
  ], MidwayDecoratorService.prototype, "init", null);
155
207
  MidwayDecoratorService = __decorate([
156
208
  (0, decorator_1.Provide)(),
157
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
209
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
158
210
  __metadata("design:paramtypes", [Object])
159
211
  ], MidwayDecoratorService);
160
212
  exports.MidwayDecoratorService = MidwayDecoratorService;
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
7
7
  };
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.MidwayEnvironmentService = void 0;
10
+ const interface_1 = require("../interface");
10
11
  const util_1 = require("../util");
11
12
  const decorator_1 = require("../decorator");
12
13
  let MidwayEnvironmentService = class MidwayEnvironmentService {
@@ -25,7 +26,7 @@ let MidwayEnvironmentService = class MidwayEnvironmentService {
25
26
  };
26
27
  MidwayEnvironmentService = __decorate([
27
28
  (0, decorator_1.Provide)(),
28
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
29
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
29
30
  ], MidwayEnvironmentService);
30
31
  exports.MidwayEnvironmentService = MidwayEnvironmentService;
31
32
  //# sourceMappingURL=environmentService.js.map
@@ -1,5 +1,4 @@
1
- import { MidwayFrameworkType } from '../decorator';
2
- import { IMidwayContainer, IMidwayFramework } from '../interface';
1
+ import { IMidwayContainer, IMidwayFramework, MidwayFrameworkType } from '../interface';
3
2
  import { MidwayConfigService } from './configService';
4
3
  import { MidwayLoggerService } from './loggerService';
5
4
  import { MidwayDecoratorService } from './decoratorService';
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayFrameworkService = void 0;
13
13
  const decorator_1 = require("../decorator");
14
+ const interface_1 = require("../interface");
14
15
  const configService_1 = require("./configService");
15
16
  const loggerService_1 = require("./loggerService");
16
17
  const baseFramework_1 = require("../baseFramework");
@@ -66,6 +67,21 @@ let MidwayFrameworkService = class MidwayFrameworkService {
66
67
  var _a;
67
68
  return this.getMainApp()[(_a = meta.identifier) !== null && _a !== void 0 ? _a : propertyName];
68
69
  });
70
+ this.decoratorService.registerPropertyHandler(decorator_1.FACTORY_SERVICE_CLIENT_KEY, (propertyName, meta) => {
71
+ const factory = this.applicationContext.get(meta.serviceFactoryClz);
72
+ const clientName = meta.clientName || factory.getDefaultClientName();
73
+ if (clientName && factory.has(clientName)) {
74
+ return factory.get(clientName);
75
+ }
76
+ else {
77
+ if (!clientName) {
78
+ throw new error_1.MidwayParameterError(`Please set clientName or options.defaultClientName for ${meta.serviceFactoryClz.name}).`);
79
+ }
80
+ else {
81
+ throw new error_1.MidwayParameterError(`ClientName(${clientName} not found in ${meta.serviceFactoryClz.name}).`);
82
+ }
83
+ }
84
+ });
69
85
  let frameworks = (0, decorator_1.listModule)(decorator_1.FRAMEWORK_KEY);
70
86
  // filter proto
71
87
  frameworks = filterProtoFramework(frameworks);
@@ -82,6 +98,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
82
98
  // app init
83
99
  await frameworkInstance.initialize({
84
100
  applicationContext: this.applicationContext,
101
+ namespace: frameworkInstance.getNamespace(),
85
102
  ...this.globalOptions,
86
103
  });
87
104
  debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
@@ -91,6 +108,9 @@ let MidwayFrameworkService = class MidwayFrameworkService {
91
108
  }
92
109
  // app init
93
110
  const definition = this.applicationContext.registry.getDefinition((0, decorator_1.getProviderUUId)(frameworkClz));
111
+ // set framework namespace here
112
+ frameworkInstance.setNamespace(definition === null || definition === void 0 ? void 0 : definition.namespace);
113
+ // link framework to application manager
94
114
  this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
95
115
  this.globalFrameworkList.push(frameworkInstance);
96
116
  }
@@ -169,7 +189,7 @@ __decorate([
169
189
  ], MidwayFrameworkService.prototype, "init", null);
170
190
  MidwayFrameworkService = __decorate([
171
191
  (0, decorator_1.Provide)(),
172
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
192
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
173
193
  __metadata("design:paramtypes", [Object, Object])
174
194
  ], MidwayFrameworkService);
175
195
  exports.MidwayFrameworkService = MidwayFrameworkService;
@@ -10,6 +10,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayInformationService = void 0;
13
+ const interface_1 = require("../interface");
13
14
  const util_1 = require("../util");
14
15
  const path_1 = require("path");
15
16
  const decorator_1 = require("../decorator");
@@ -62,7 +63,7 @@ __decorate([
62
63
  ], MidwayInformationService.prototype, "init", null);
63
64
  MidwayInformationService = __decorate([
64
65
  (0, decorator_1.Provide)(),
65
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton)
66
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton)
66
67
  ], MidwayInformationService);
67
68
  exports.MidwayInformationService = MidwayInformationService;
68
69
  //# sourceMappingURL=informationService.js.map
@@ -1,10 +1,12 @@
1
1
  import { IMidwayContainer } from '../interface';
2
2
  import { MidwayFrameworkService } from './frameworkService';
3
3
  import { MidwayConfigService } from './configService';
4
+ import { MidwayMockService } from './mockService';
4
5
  export declare class MidwayLifeCycleService {
5
6
  readonly applicationContext: IMidwayContainer;
6
7
  protected frameworkService: MidwayFrameworkService;
7
8
  protected configService: MidwayConfigService;
9
+ protected mockService: MidwayMockService;
8
10
  constructor(applicationContext: IMidwayContainer);
9
11
  protected init(): Promise<void>;
10
12
  stop(): Promise<void>;
@@ -10,17 +10,21 @@ var __metadata = (this && this.__metadata) || function (k, v) {
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayLifeCycleService = void 0;
13
+ const interface_1 = require("../interface");
13
14
  const decorator_1 = require("../decorator");
14
15
  const configuration_1 = require("../functional/configuration");
15
16
  const frameworkService_1 = require("./frameworkService");
16
17
  const configService_1 = require("./configService");
17
18
  const util_1 = require("util");
19
+ const mockService_1 = require("./mockService");
18
20
  const debug = (0, util_1.debuglog)('midway:debug');
19
21
  let MidwayLifeCycleService = class MidwayLifeCycleService {
20
22
  constructor(applicationContext) {
21
23
  this.applicationContext = applicationContext;
22
24
  }
23
25
  async init() {
26
+ // exec simulator init
27
+ await this.mockService.initSimulation();
24
28
  // run lifecycle
25
29
  const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
26
30
  debug(`[core]: Found Configuration length = ${cycles.length}`);
@@ -32,7 +36,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
32
36
  }
33
37
  else {
34
38
  // 普通类写法
35
- debug(`[core]: Lifecycle run ${cycle.target.name} init`);
39
+ debug(`[core]: Lifecycle run ${cycle.namespace} init`);
36
40
  cycle.instance = await this.applicationContext.getAsync(cycle.target);
37
41
  }
38
42
  cycle.instance && lifecycleInstanceList.push(cycle);
@@ -52,6 +56,7 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
52
56
  this.configService.addObject(configData);
53
57
  }
54
58
  });
59
+ await this.mockService.runSimulatorSetup();
55
60
  // exec onReady()
56
61
  await this.runContainerLifeCycle(lifecycleInstanceList, 'onReady');
57
62
  // exec framework.run()
@@ -64,9 +69,10 @@ let MidwayLifeCycleService = class MidwayLifeCycleService {
64
69
  }
65
70
  }
66
71
  async stop() {
72
+ await this.mockService.runSimulatorTearDown();
67
73
  // stop lifecycle
68
- const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY);
69
- for (const cycle of cycles) {
74
+ const cycles = (0, decorator_1.listModule)(decorator_1.CONFIGURATION_KEY) || [];
75
+ for (const cycle of cycles.reverse()) {
70
76
  let inst;
71
77
  if (cycle.target instanceof configuration_1.FunctionalConfiguration) {
72
78
  // 函数式写法
@@ -119,6 +125,10 @@ __decorate([
119
125
  (0, decorator_1.Inject)(),
120
126
  __metadata("design:type", configService_1.MidwayConfigService)
121
127
  ], MidwayLifeCycleService.prototype, "configService", void 0);
128
+ __decorate([
129
+ (0, decorator_1.Inject)(),
130
+ __metadata("design:type", mockService_1.MidwayMockService)
131
+ ], MidwayLifeCycleService.prototype, "mockService", void 0);
122
132
  __decorate([
123
133
  (0, decorator_1.Init)(),
124
134
  __metadata("design:type", Function),
@@ -127,7 +137,7 @@ __decorate([
127
137
  ], MidwayLifeCycleService.prototype, "init", null);
128
138
  MidwayLifeCycleService = __decorate([
129
139
  (0, decorator_1.Provide)(),
130
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
140
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
131
141
  __metadata("design:paramtypes", [Object])
132
142
  ], MidwayLifeCycleService);
133
143
  exports.MidwayLifeCycleService = MidwayLifeCycleService;
@@ -1,15 +1,19 @@
1
1
  import { MidwayConfigService } from './configService';
2
2
  import { ServiceFactory } from '../common/serviceFactory';
3
- import { ILogger, LoggerOptions } from '@midwayjs/logger';
4
- import { IMidwayContainer } from '../interface';
3
+ import { ILogger, IMidwayContainer } from '../interface';
4
+ import { LoggerFactory } from '../common/loggerFactory';
5
5
  export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
6
6
  readonly applicationContext: IMidwayContainer;
7
+ readonly globalOptions: {};
7
8
  configService: MidwayConfigService;
8
- constructor(applicationContext: IMidwayContainer);
9
- protected init(): void;
10
- protected createClient(config: LoggerOptions, name?: string): void;
9
+ private loggerFactory;
10
+ private lazyLoggerConfigMap;
11
+ constructor(applicationContext: IMidwayContainer, globalOptions?: {});
12
+ protected init(): Promise<void>;
13
+ protected createClient(config: any, name?: string): void;
11
14
  getName(): string;
12
- createLogger(name: any, config: any): ILogger;
13
- getLogger(name: string): ILogger;
15
+ createLogger(name: any, config: any): any;
16
+ getLogger(name: string): any;
17
+ getCurrentLoggerFactory(): LoggerFactory<any, any>;
14
18
  }
15
19
  //# sourceMappingURL=loggerService.d.ts.map
@@ -13,29 +13,51 @@ exports.MidwayLoggerService = void 0;
13
13
  const decorator_1 = require("../decorator");
14
14
  const configService_1 = require("./configService");
15
15
  const serviceFactory_1 = require("../common/serviceFactory");
16
+ const interface_1 = require("../interface");
16
17
  const logger_1 = require("@midwayjs/logger");
17
18
  let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
18
- constructor(applicationContext) {
19
+ constructor(applicationContext, globalOptions = {}) {
19
20
  super();
20
21
  this.applicationContext = applicationContext;
22
+ this.globalOptions = globalOptions;
23
+ this.lazyLoggerConfigMap = new Map();
21
24
  }
22
- init() {
25
+ async init() {
23
26
  var _a;
24
- this.initClients(this.configService.getConfiguration('midwayLogger'));
27
+ this.loggerFactory = this.globalOptions['loggerFactory'] || logger_1.loggers;
28
+ await this.initClients(this.configService.getConfiguration('midwayLogger'));
25
29
  // alias inject logger
26
30
  (_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
27
31
  }
28
32
  createClient(config, name) {
29
- logger_1.loggers.createLogger(name, config);
33
+ if (!config.lazyLoad) {
34
+ this.loggerFactory.createLogger(name, config);
35
+ }
36
+ else {
37
+ delete config['lazyLoad'];
38
+ this.lazyLoggerConfigMap.set(name, config);
39
+ }
30
40
  }
31
41
  getName() {
32
42
  return 'logger';
33
43
  }
34
44
  createLogger(name, config) {
35
- return logger_1.loggers.createLogger(name, config);
45
+ return this.loggerFactory.createLogger(name, config);
36
46
  }
37
47
  getLogger(name) {
38
- return logger_1.loggers.getLogger(name);
48
+ const logger = this.loggerFactory.getLogger(name);
49
+ if (logger) {
50
+ return logger;
51
+ }
52
+ if (this.lazyLoggerConfigMap.has(name)) {
53
+ // try to lazy init
54
+ this.createClient(this.lazyLoggerConfigMap.get(name), name);
55
+ this.lazyLoggerConfigMap.delete(name);
56
+ }
57
+ return this.loggerFactory.getLogger(name);
58
+ }
59
+ getCurrentLoggerFactory() {
60
+ return this.loggerFactory;
39
61
  }
40
62
  };
41
63
  __decorate([
@@ -46,12 +68,12 @@ __decorate([
46
68
  (0, decorator_1.Init)(),
47
69
  __metadata("design:type", Function),
48
70
  __metadata("design:paramtypes", []),
49
- __metadata("design:returntype", void 0)
71
+ __metadata("design:returntype", Promise)
50
72
  ], MidwayLoggerService.prototype, "init", null);
51
73
  MidwayLoggerService = __decorate([
52
74
  (0, decorator_1.Provide)(),
53
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
54
- __metadata("design:paramtypes", [Object])
75
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
76
+ __metadata("design:paramtypes", [Object, Object])
55
77
  ], MidwayLoggerService);
56
78
  exports.MidwayLoggerService = MidwayLoggerService;
57
79
  //# sourceMappingURL=loggerService.js.map
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.MidwayMiddlewareService = void 0;
13
13
  const decorator_1 = require("../decorator");
14
+ const interface_1 = require("../interface");
14
15
  const error_1 = require("../error");
15
16
  const util_1 = require("../util");
16
17
  const types_1 = require("../util/types");
@@ -126,7 +127,7 @@ let MidwayMiddlewareService = class MidwayMiddlewareService {
126
127
  };
127
128
  MidwayMiddlewareService = __decorate([
128
129
  (0, decorator_1.Provide)(),
129
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
130
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
130
131
  __metadata("design:paramtypes", [Object])
131
132
  ], MidwayMiddlewareService);
132
133
  exports.MidwayMiddlewareService = MidwayMiddlewareService;
@@ -1,4 +1,4 @@
1
- import { IMidwayApplication, IMidwayContainer, IMidwayContext } from '../interface';
1
+ import { IMidwayApplication, IMidwayContainer, IMidwayContext, ISimulation } from '../interface';
2
2
  export declare class MidwayMockService {
3
3
  readonly applicationContext: IMidwayContainer;
4
4
  protected mocks: any[];
@@ -8,6 +8,7 @@ export declare class MidwayMockService {
8
8
  value: any;
9
9
  }>;
10
10
  protected cache: Map<any, any>;
11
+ protected simulatorList: Array<ISimulation>;
11
12
  constructor(applicationContext: IMidwayContainer);
12
13
  init(): Promise<void>;
13
14
  static prepareMocks: any[];
@@ -21,5 +22,12 @@ export declare class MidwayMockService {
21
22
  applyContextMocks(app: IMidwayApplication, ctx: IMidwayContext): void;
22
23
  getContextMocksSize(): number;
23
24
  private overridePropertyDescriptor;
25
+ initSimulation(): Promise<void>;
26
+ runSimulatorSetup(): Promise<void>;
27
+ runSimulatorTearDown(): Promise<void>;
28
+ runSimulatorAppSetup(app: IMidwayApplication): Promise<void>;
29
+ runSimulatorAppTearDown(app: IMidwayApplication): Promise<void>;
30
+ runSimulatorContextSetup(ctx: IMidwayContext, app: IMidwayApplication): Promise<void>;
31
+ runSimulatorContextTearDown(ctx: IMidwayContext, app: IMidwayApplication): Promise<void>;
24
32
  }
25
33
  //# sourceMappingURL=mockService.d.ts.map
@@ -11,6 +11,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
11
11
  var MidwayMockService_1;
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.MidwayMockService = void 0;
14
+ const interface_1 = require("../interface");
14
15
  const decorator_1 = require("../decorator");
15
16
  let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
16
17
  constructor(applicationContext) {
@@ -18,6 +19,7 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
18
19
  this.mocks = [];
19
20
  this.contextMocks = [];
20
21
  this.cache = new Map();
22
+ this.simulatorList = [];
21
23
  }
22
24
  async init() {
23
25
  if (MidwayMockService_1.prepareMocks.length > 0) {
@@ -86,6 +88,7 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
86
88
  this.mocks = [];
87
89
  this.contextMocks = [];
88
90
  this.cache.clear();
91
+ this.simulatorList = [];
89
92
  MidwayMockService_1.prepareMocks = [];
90
93
  }
91
94
  isMocked(obj, key) {
@@ -127,6 +130,45 @@ let MidwayMockService = MidwayMockService_1 = class MidwayMockService {
127
130
  }
128
131
  return descriptor;
129
132
  }
133
+ async initSimulation() {
134
+ const simulationModule = (0, decorator_1.listModule)(decorator_1.MOCK_KEY);
135
+ for (const module of simulationModule) {
136
+ const instance = await this.applicationContext.getAsync(module);
137
+ if (await instance.enableCondition()) {
138
+ this.simulatorList.push(instance);
139
+ }
140
+ }
141
+ }
142
+ async runSimulatorSetup() {
143
+ for (const simulator of this.simulatorList) {
144
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.setup());
145
+ }
146
+ }
147
+ async runSimulatorTearDown() {
148
+ for (const simulator of this.simulatorList) {
149
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.tearDown());
150
+ }
151
+ }
152
+ async runSimulatorAppSetup(app) {
153
+ for (const simulator of this.simulatorList) {
154
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.appSetup(app));
155
+ }
156
+ }
157
+ async runSimulatorAppTearDown(app) {
158
+ for (const simulator of this.simulatorList) {
159
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.appTearDown(app));
160
+ }
161
+ }
162
+ async runSimulatorContextSetup(ctx, app) {
163
+ for (const simulator of this.simulatorList) {
164
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.contextSetup(ctx, app));
165
+ }
166
+ }
167
+ async runSimulatorContextTearDown(ctx, app) {
168
+ for (const simulator of this.simulatorList) {
169
+ await (simulator === null || simulator === void 0 ? void 0 : simulator.contextTearDown(ctx, app));
170
+ }
171
+ }
130
172
  };
131
173
  MidwayMockService.prepareMocks = [];
132
174
  __decorate([
@@ -143,7 +185,7 @@ __decorate([
143
185
  ], MidwayMockService.prototype, "restore", null);
144
186
  MidwayMockService = MidwayMockService_1 = __decorate([
145
187
  (0, decorator_1.Provide)(),
146
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
188
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
147
189
  __metadata("design:paramtypes", [Object])
148
190
  ], MidwayMockService);
149
191
  exports.MidwayMockService = MidwayMockService;
@@ -1,5 +1,4 @@
1
- import { IMidwayContainer } from '../interface';
2
- import { ObjectIdentifier } from '../decorator';
1
+ import { IMidwayContainer, ObjectIdentifier } from '../interface';
3
2
  interface IPipelineInfo {
4
3
  /**
5
4
  * 上次执行结果(只有在执行 waterfall 时才有值)
@@ -122,7 +121,7 @@ export interface IPipelineHandler {
122
121
  concatSeries<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
123
122
  waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
124
123
  }
125
- declare type valvesType = Array<ObjectIdentifier | (new (...args: any[]) => any)>;
124
+ type valvesType = Array<ObjectIdentifier | (new (...args: any[]) => any)>;
126
125
  export declare class PipelineContext implements IPipelineContext {
127
126
  args: any;
128
127
  info: IPipelineInfo;
@@ -1,5 +1,5 @@
1
- import { FaaSMetadata } from '../decorator';
2
1
  import { MidwayWebRouterService, RouterCollectorOptions, RouterInfo, RouterPriority } from './webRouterService';
2
+ import { FaaSMetadata } from '../interface';
3
3
  export declare class MidwayServerlessFunctionService extends MidwayWebRouterService {
4
4
  readonly options: RouterCollectorOptions;
5
5
  constructor(options?: RouterCollectorOptions);
@@ -15,6 +15,7 @@ const webRouterService_1 = require("./webRouterService");
15
15
  const container_1 = require("../context/container");
16
16
  const fileDetector_1 = require("../common/fileDetector");
17
17
  const contextUtil_1 = require("../util/contextUtil");
18
+ const interface_1 = require("../interface");
18
19
  let MidwayServerlessFunctionService = class MidwayServerlessFunctionService extends webRouterService_1.MidwayWebRouterService {
19
20
  constructor(options = {}) {
20
21
  super(Object.assign({}, options, {
@@ -97,8 +98,8 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
97
98
  data.functionTriggerName = webRouter['type'];
98
99
  data.functionTriggerMetadata = webRouter['metadata'];
99
100
  data.functionMetadata = {
100
- functionName,
101
101
  ...functionMeta,
102
+ functionName,
102
103
  };
103
104
  this.checkDuplicateAndPush(prefix, data);
104
105
  }
@@ -179,7 +180,7 @@ let MidwayServerlessFunctionService = class MidwayServerlessFunctionService exte
179
180
  };
180
181
  MidwayServerlessFunctionService = __decorate([
181
182
  (0, decorator_1.Provide)(),
182
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
183
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
183
184
  __metadata("design:paramtypes", [Object])
184
185
  ], MidwayServerlessFunctionService);
185
186
  exports.MidwayServerlessFunctionService = MidwayServerlessFunctionService;
@@ -93,7 +93,7 @@ export interface RouterInfo {
93
93
  */
94
94
  fullUrlFlattenString?: string;
95
95
  }
96
- export declare type DynamicRouterInfo = Omit<RouterInfo, 'id' | 'method' | 'controllerId' | 'controllerMiddleware' | 'responseMetadata'>;
96
+ export type DynamicRouterInfo = Omit<RouterInfo, 'id' | 'method' | 'controllerId' | 'controllerMiddleware' | 'responseMetadata'>;
97
97
  export interface RouterPriority {
98
98
  prefix: string;
99
99
  priority: number;
@@ -16,6 +16,7 @@ const error_1 = require("../error");
16
16
  const util = require("util");
17
17
  const pathToRegexp_1 = require("../util/pathToRegexp");
18
18
  const types_1 = require("../util/types");
19
+ const interface_1 = require("../interface");
19
20
  const debug = util.debuglog('midway:debug');
20
21
  let MidwayWebRouterService = class MidwayWebRouterService {
21
22
  constructor(options = {}) {
@@ -142,7 +143,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
142
143
  if (functionMeta) {
143
144
  // get function information
144
145
  data.functionName = controllerId + '-' + webRouter.method;
145
- data.functionTriggerName = decorator_1.ServerlessTriggerType.HTTP;
146
+ data.functionTriggerName = interface_1.ServerlessTriggerType.HTTP;
146
147
  data.functionTriggerMetadata = {
147
148
  path: (0, util_1.joinURLPath)(prefix, webRouter.path.toString()),
148
149
  method: webRouter.requestMethod,
@@ -323,7 +324,7 @@ let MidwayWebRouterService = class MidwayWebRouterService {
323
324
  };
324
325
  MidwayWebRouterService = __decorate([
325
326
  (0, decorator_1.Provide)(),
326
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
327
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
327
328
  __metadata("design:paramtypes", [Object])
328
329
  ], MidwayWebRouterService);
329
330
  exports.MidwayWebRouterService = MidwayWebRouterService;