@midwayjs/core 3.9.0 → 3.10.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 (90) hide show
  1. package/dist/baseFramework.d.ts +3 -0
  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/webGenerator.js +2 -1
  6. package/dist/config/config.default.js +2 -1
  7. package/dist/context/container.d.ts +1 -2
  8. package/dist/context/container.js +3 -3
  9. package/dist/context/definitionRegistry.d.ts +1 -5
  10. package/dist/context/managedResolverFactory.d.ts +1 -2
  11. package/dist/context/managedResolverFactory.js +2 -3
  12. package/dist/context/providerWrapper.d.ts +1 -2
  13. package/dist/decorator/common/aspect.d.ts +0 -18
  14. package/dist/decorator/common/aspect.js +2 -1
  15. package/dist/decorator/common/filter.d.ts +1 -1
  16. package/dist/decorator/common/filter.js +1 -1
  17. package/dist/decorator/common/framework.d.ts +1 -1
  18. package/dist/decorator/common/framework.js +2 -1
  19. package/dist/decorator/common/guard.js +1 -1
  20. package/dist/decorator/common/inject.d.ts +1 -2
  21. package/dist/decorator/common/middleware.js +2 -1
  22. package/dist/decorator/common/mock.d.ts +2 -0
  23. package/dist/decorator/common/mock.js +14 -0
  24. package/dist/decorator/common/objectDef.d.ts +2 -1
  25. package/dist/decorator/common/objectDef.js +10 -1
  26. package/dist/decorator/common/pipe.d.ts +2 -0
  27. package/dist/decorator/common/pipe.js +13 -0
  28. package/dist/decorator/common/pipeline.d.ts +1 -1
  29. package/dist/decorator/common/provide.d.ts +1 -1
  30. package/dist/decorator/constant.d.ts +1 -0
  31. package/dist/decorator/constant.js +3 -2
  32. package/dist/decorator/decoratorManager.d.ts +6 -10
  33. package/dist/decorator/decoratorManager.js +20 -8
  34. package/dist/decorator/faas/serverlessTrigger.d.ts +3 -1
  35. package/dist/decorator/faas/serverlessTrigger.js +3 -2
  36. package/dist/decorator/index.d.ts +2 -1
  37. package/dist/decorator/index.js +2 -1
  38. package/dist/decorator/microservice/consumer.d.ts +1 -1
  39. package/dist/decorator/microservice/consumer.js +2 -1
  40. package/dist/decorator/microservice/kafkaListener.d.ts +3 -3
  41. package/dist/decorator/microservice/provider.d.ts +1 -1
  42. package/dist/decorator/microservice/provider.js +2 -1
  43. package/dist/decorator/rpc/hsf.d.ts +1 -0
  44. package/dist/decorator/rpc/hsf.js +3 -1
  45. package/dist/decorator/task/schedule.js +2 -1
  46. package/dist/decorator/web/controller.d.ts +1 -1
  47. package/dist/decorator/web/controller.js +2 -1
  48. package/dist/decorator/web/requestMapping.d.ts +1 -4
  49. package/dist/decorator/ws/webSocketController.d.ts +1 -1
  50. package/dist/decorator/ws/webSocketController.js +2 -1
  51. package/dist/decorator/ws/webSocketEvent.d.ts +1 -1
  52. package/dist/definitions/functionDefinition.d.ts +1 -2
  53. package/dist/definitions/functionDefinition.js +4 -4
  54. package/dist/definitions/objectDefinition.d.ts +1 -2
  55. package/dist/definitions/objectDefinition.js +4 -4
  56. package/dist/definitions/properties.d.ts +1 -2
  57. package/dist/error/base.d.ts +2 -2
  58. package/dist/error/framework.d.ts +1 -1
  59. package/dist/error/framework.js +5 -5
  60. package/dist/interface.d.ts +327 -24
  61. package/dist/interface.js +64 -1
  62. package/dist/service/aspectService.d.ts +1 -2
  63. package/dist/service/aspectService.js +2 -1
  64. package/dist/service/configService.js +2 -1
  65. package/dist/service/decoratorService.d.ts +3 -1
  66. package/dist/service/decoratorService.js +63 -11
  67. package/dist/service/environmentService.js +2 -1
  68. package/dist/service/frameworkService.d.ts +1 -2
  69. package/dist/service/frameworkService.js +6 -1
  70. package/dist/service/informationService.js +2 -1
  71. package/dist/service/lifeCycleService.d.ts +2 -0
  72. package/dist/service/lifeCycleService.js +14 -4
  73. package/dist/service/loggerService.d.ts +1 -0
  74. package/dist/service/loggerService.js +19 -2
  75. package/dist/service/middlewareService.js +2 -1
  76. package/dist/service/mockService.d.ts +9 -1
  77. package/dist/service/mockService.js +43 -1
  78. package/dist/service/pipelineService.d.ts +2 -3
  79. package/dist/service/slsFunctionService.d.ts +1 -1
  80. package/dist/service/slsFunctionService.js +3 -2
  81. package/dist/service/webRouterService.d.ts +1 -1
  82. package/dist/service/webRouterService.js +3 -2
  83. package/dist/setup.js +2 -0
  84. package/dist/util/httpclient.d.ts +2 -2
  85. package/dist/util/pathToRegexp.d.ts +5 -5
  86. package/dist/util/webRouterParam.d.ts +2 -4
  87. package/dist/util/webRouterParam.js +5 -27
  88. package/package.json +4 -5
  89. package/dist/decorator/interface.d.ts +0 -242
  90. 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
@@ -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");
@@ -97,6 +98,7 @@ let MidwayFrameworkService = class MidwayFrameworkService {
97
98
  // app init
98
99
  await frameworkInstance.initialize({
99
100
  applicationContext: this.applicationContext,
101
+ namespace: frameworkInstance.getNamespace(),
100
102
  ...this.globalOptions,
101
103
  });
102
104
  debug(`[core]: Found Framework "${frameworkInstance.getFrameworkName()}" and initialize.`);
@@ -106,6 +108,9 @@ let MidwayFrameworkService = class MidwayFrameworkService {
106
108
  }
107
109
  // app init
108
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
109
114
  this.applicationManager.addFramework((_a = definition === null || definition === void 0 ? void 0 : definition.namespace) !== null && _a !== void 0 ? _a : frameworkInstance.getFrameworkName(), frameworkInstance);
110
115
  this.globalFrameworkList.push(frameworkInstance);
111
116
  }
@@ -184,7 +189,7 @@ __decorate([
184
189
  ], MidwayFrameworkService.prototype, "init", null);
185
190
  MidwayFrameworkService = __decorate([
186
191
  (0, decorator_1.Provide)(),
187
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
192
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
188
193
  __metadata("design:paramtypes", [Object, Object])
189
194
  ], MidwayFrameworkService);
190
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;
@@ -7,6 +7,7 @@ export declare class MidwayLoggerService extends ServiceFactory<ILogger> {
7
7
  readonly globalOptions: {};
8
8
  configService: MidwayConfigService;
9
9
  private loggerFactory;
10
+ private lazyLoggerConfigMap;
10
11
  constructor(applicationContext: IMidwayContainer, globalOptions?: {});
11
12
  protected init(): void;
12
13
  protected createClient(config: any, name?: string): void;
@@ -13,12 +13,14 @@ 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
19
  constructor(applicationContext, globalOptions = {}) {
19
20
  super();
20
21
  this.applicationContext = applicationContext;
21
22
  this.globalOptions = globalOptions;
23
+ this.lazyLoggerConfigMap = new Map();
22
24
  }
23
25
  init() {
24
26
  var _a;
@@ -28,7 +30,13 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
28
30
  (_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
29
31
  }
30
32
  createClient(config, name) {
31
- this.loggerFactory.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
+ }
32
40
  }
33
41
  getName() {
34
42
  return 'logger';
@@ -37,6 +45,15 @@ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.Ser
37
45
  return this.loggerFactory.createLogger(name, config);
38
46
  }
39
47
  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
+ }
40
57
  return this.loggerFactory.getLogger(name);
41
58
  }
42
59
  getCurrentLoggerFactory() {
@@ -55,7 +72,7 @@ __decorate([
55
72
  ], MidwayLoggerService.prototype, "init", null);
56
73
  MidwayLoggerService = __decorate([
57
74
  (0, decorator_1.Provide)(),
58
- (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
75
+ (0, decorator_1.Scope)(interface_1.ScopeEnum.Singleton),
59
76
  __metadata("design:paramtypes", [Object, Object])
60
77
  ], MidwayLoggerService);
61
78
  exports.MidwayLoggerService = MidwayLoggerService;
@@ -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;
package/dist/setup.js CHANGED
@@ -32,6 +32,8 @@ async function initializeGlobalApplicationContext(globalOptions) {
32
32
  await applicationContext.getAsync(_1.MidwayLifeCycleService, [
33
33
  applicationContext,
34
34
  ]);
35
+ // mock support
36
+ await applicationContext.get(_1.MidwayMockService, [applicationContext]);
35
37
  // some preload module init
36
38
  const modules = (0, decorator_1.listPreloadModule)();
37
39
  for (const module of modules) {
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import http = require('http');
4
- declare type MethodType = 'GET' | 'POST';
5
- declare type MimeType = 'text' | 'json' | undefined;
4
+ type MethodType = 'GET' | 'POST';
5
+ type MimeType = 'text' | 'json' | undefined;
6
6
  interface IOptions {
7
7
  method?: MethodType;
8
8
  headers?: any;
@@ -30,7 +30,7 @@ interface TokensToFunctionOptions {
30
30
  * Compile a string to a template function for the path.
31
31
  */
32
32
  declare function compile<P extends object = object>(str: string, options?: ParseOptions & TokensToFunctionOptions): PathFunction<P>;
33
- declare type PathFunction<P extends object = object> = (data?: P) => string;
33
+ type PathFunction<P extends object = object> = (data?: P) => string;
34
34
  interface RegexpToFunctionOptions {
35
35
  /**
36
36
  * Function for decoding strings for params.
@@ -48,11 +48,11 @@ interface MatchResult<P extends object = object> {
48
48
  /**
49
49
  * A match is either `false` (no match) or a match result.
50
50
  */
51
- declare type Match<P extends object = object> = false | MatchResult<P>;
51
+ type Match<P extends object = object> = false | MatchResult<P>;
52
52
  /**
53
53
  * The match function takes a string and returns whether it matched the path.
54
54
  */
55
- declare type MatchFunction<P extends object = object> = (path: string) => Match<P>;
55
+ type MatchFunction<P extends object = object> = (path: string) => Match<P>;
56
56
  /**
57
57
  * Create path match function from `path-to-regexp` spec.
58
58
  */
@@ -70,7 +70,7 @@ interface Key {
70
70
  /**
71
71
  * A token is a string (nothing special) or key metadata (capture group).
72
72
  */
73
- declare type Token = string | Key;
73
+ type Token = string | Key;
74
74
  interface TokensToRegexpOptions {
75
75
  /**
76
76
  * When `true` the regexp will be case sensitive. (default: `false`)
@@ -104,7 +104,7 @@ interface TokensToRegexpOptions {
104
104
  /**
105
105
  * Supported `path-to-regexp` input types.
106
106
  */
107
- declare type Path = string | RegExp | Array<string | RegExp>;
107
+ type Path = string | RegExp | Array<string | RegExp>;
108
108
  /**
109
109
  * Normalize the given path string, returning a regular expression.
110
110
  *
@@ -1,5 +1,3 @@
1
- import { PipeTransform, PipeTransformFunction } from '../decorator';
2
- export declare function callPipes(pipes: Array<PipeTransform | PipeTransformFunction>, value: any): Promise<any>;
3
- export declare const extractKoaLikeValue: (key: any, data: any, paramType?: any, pipes?: PipeTransform[]) => (ctx: any, next: any) => Promise<any>;
4
- export declare const extractExpressLikeValue: (key: any, data: any, paramType?: any, pipes?: PipeTransform[]) => (req: any, res: any, next: any) => Promise<any>;
1
+ export declare const extractKoaLikeValue: (key: any, data: any, paramType?: any) => (ctx: any, next: any) => any;
2
+ export declare const extractExpressLikeValue: (key: any, data: any, paramType?: any) => (req: any, res: any, next: any) => any;
5
3
  //# sourceMappingURL=webRouterParam.d.ts.map