@midwayjs/core 3.0.0-alpha.9 → 3.0.0-beta.12

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 (111) hide show
  1. package/CHANGELOG.md +149 -0
  2. package/README.md +1 -1
  3. package/dist/baseFramework.d.ts +56 -22
  4. package/dist/baseFramework.js +157 -232
  5. package/dist/common/applicationManager.d.ts +12 -0
  6. package/dist/common/applicationManager.js +66 -0
  7. package/dist/{util → common}/fileDetector.d.ts +0 -0
  8. package/dist/{util → common}/fileDetector.js +16 -10
  9. package/dist/common/filterManager.d.ts +19 -0
  10. package/dist/common/filterManager.js +85 -0
  11. package/dist/common/middlewareManager.d.ts +68 -0
  12. package/dist/common/middlewareManager.js +183 -0
  13. package/dist/common/serviceFactory.d.ts +15 -0
  14. package/dist/{util → common}/serviceFactory.js +16 -6
  15. package/dist/{util → common}/triggerCollector.d.ts +0 -0
  16. package/dist/{util → common}/triggerCollector.js +0 -0
  17. package/dist/common/webGenerator.d.ts +16 -0
  18. package/dist/common/webGenerator.js +117 -0
  19. package/dist/{util → common}/webRouterCollector.d.ts +21 -2
  20. package/dist/common/webRouterCollector.js +331 -0
  21. package/dist/config/config.default.d.ts +7 -0
  22. package/dist/config/config.default.js +28 -0
  23. package/dist/context/container.d.ts +73 -43
  24. package/dist/context/container.js +289 -271
  25. package/dist/context/definitionRegistry.d.ts +26 -0
  26. package/dist/context/definitionRegistry.js +124 -0
  27. package/dist/context/managedResolverFactory.d.ts +15 -32
  28. package/dist/context/managedResolverFactory.js +91 -320
  29. package/dist/context/providerWrapper.d.ts +2 -3
  30. package/dist/context/requestContainer.d.ts +0 -2
  31. package/dist/context/requestContainer.js +9 -26
  32. package/dist/definitions/functionDefinition.d.ts +3 -4
  33. package/dist/definitions/functionDefinition.js +0 -6
  34. package/dist/definitions/objectCreator.js +9 -8
  35. package/dist/definitions/objectDefinition.d.ts +4 -6
  36. package/dist/definitions/objectDefinition.js +0 -8
  37. package/dist/definitions/properties.d.ts +2 -15
  38. package/dist/definitions/properties.js +3 -72
  39. package/dist/error/base.d.ts +32 -0
  40. package/dist/error/base.js +48 -0
  41. package/dist/error/framework.d.ts +45 -0
  42. package/dist/error/framework.js +87 -0
  43. package/dist/error/http.d.ts +119 -0
  44. package/dist/error/http.js +169 -0
  45. package/dist/error/index.d.ts +4 -0
  46. package/dist/error/index.js +16 -0
  47. package/dist/functional/configuration.d.ts +4 -2
  48. package/dist/functional/configuration.js +12 -2
  49. package/dist/index.d.ts +24 -11
  50. package/dist/index.js +36 -36
  51. package/dist/interface.d.ts +270 -184
  52. package/dist/interface.js +9 -1
  53. package/dist/service/aspectService.d.ts +11 -14
  54. package/dist/service/aspectService.js +116 -172
  55. package/dist/service/configService.d.ts +10 -8
  56. package/dist/service/configService.js +61 -38
  57. package/dist/service/decoratorService.d.ts +23 -0
  58. package/dist/service/decoratorService.js +149 -0
  59. package/dist/service/environmentService.js +15 -4
  60. package/dist/service/frameworkService.d.ts +26 -0
  61. package/dist/service/frameworkService.js +176 -0
  62. package/dist/service/informationService.d.ts +4 -7
  63. package/dist/service/informationService.js +41 -10
  64. package/dist/service/lifeCycleService.d.ts +14 -0
  65. package/dist/service/lifeCycleService.js +130 -0
  66. package/dist/service/loggerService.d.ts +27 -0
  67. package/dist/service/loggerService.js +132 -0
  68. package/dist/service/middlewareService.d.ts +10 -0
  69. package/dist/service/middlewareService.js +123 -0
  70. package/dist/{features/pipeline.d.ts → service/pipelineService.d.ts} +56 -46
  71. package/dist/{features/pipeline.js → service/pipelineService.js} +54 -19
  72. package/dist/setup.d.ts +4 -0
  73. package/dist/setup.js +119 -0
  74. package/dist/util/contextUtil.d.ts +1 -1
  75. package/dist/util/contextUtil.js +2 -2
  76. package/dist/util/index.d.ts +64 -0
  77. package/dist/util/index.js +195 -7
  78. package/dist/util/pathFileUtil.js +2 -2
  79. package/dist/util/pathToRegexp.d.ts +17 -0
  80. package/dist/util/pathToRegexp.js +280 -0
  81. package/dist/util/webRouterParam.d.ts +2 -2
  82. package/dist/util/webRouterParam.js +43 -24
  83. package/package.json +10 -15
  84. package/dist/common/lodashWrap.d.ts +0 -9
  85. package/dist/common/lodashWrap.js +0 -18
  86. package/dist/common/notFoundError.d.ts +0 -8
  87. package/dist/common/notFoundError.js +0 -20
  88. package/dist/common/reflectTool.d.ts +0 -15
  89. package/dist/common/reflectTool.js +0 -83
  90. package/dist/context/applicationContext.d.ts +0 -81
  91. package/dist/context/applicationContext.js +0 -263
  92. package/dist/context/managed.d.ts +0 -45
  93. package/dist/context/managed.js +0 -69
  94. package/dist/context/resolverHandler.d.ts +0 -34
  95. package/dist/context/resolverHandler.js +0 -88
  96. package/dist/definitions/messageSource.d.ts +0 -13
  97. package/dist/definitions/messageSource.js +0 -74
  98. package/dist/definitions/resource.d.ts +0 -27
  99. package/dist/definitions/resource.js +0 -116
  100. package/dist/features/index.d.ts +0 -2
  101. package/dist/features/index.js +0 -3
  102. package/dist/logger.d.ts +0 -4
  103. package/dist/logger.js +0 -20
  104. package/dist/util/containerUtil.d.ts +0 -11
  105. package/dist/util/containerUtil.js +0 -26
  106. package/dist/util/emptyFramework.d.ts +0 -62
  107. package/dist/util/emptyFramework.js +0 -72
  108. package/dist/util/serviceFactory.d.ts +0 -13
  109. package/dist/util/staticConfig.d.ts +0 -10
  110. package/dist/util/staticConfig.js +0 -67
  111. package/dist/util/webRouterCollector.js +0 -348
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MidwayLoggerService = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const configService_1 = require("./configService");
15
+ const serviceFactory_1 = require("../common/serviceFactory");
16
+ const logger_1 = require("@midwayjs/logger");
17
+ const levelTransform = level => {
18
+ if (!level) {
19
+ return undefined;
20
+ }
21
+ switch (level) {
22
+ case 'NONE':
23
+ case Infinity: // egg logger 的 none 是这个等级
24
+ return null;
25
+ case 0:
26
+ case 'DEBUG':
27
+ case 'debug':
28
+ return 'debug';
29
+ case 1:
30
+ case 'INFO':
31
+ case 'info':
32
+ return 'info';
33
+ case 2:
34
+ case 'WARN':
35
+ case 'warn':
36
+ return 'warn';
37
+ case 3:
38
+ case 'ERROR':
39
+ case 'error':
40
+ return 'error';
41
+ default:
42
+ return 'silly';
43
+ }
44
+ };
45
+ let MidwayLoggerService = class MidwayLoggerService extends serviceFactory_1.ServiceFactory {
46
+ constructor(applicationContext) {
47
+ super();
48
+ this.applicationContext = applicationContext;
49
+ }
50
+ async init() {
51
+ var _a;
52
+ const eggLoggerConfig = this.transformEggConfig();
53
+ if (eggLoggerConfig) {
54
+ this.configService.addObject(eggLoggerConfig);
55
+ }
56
+ await this.initClients(this.configService.getConfiguration('midwayLogger'));
57
+ // alias inject logger
58
+ (_a = this.applicationContext) === null || _a === void 0 ? void 0 : _a.registerObject('logger', this.getLogger('appLogger'));
59
+ }
60
+ transformEggConfig() {
61
+ if (this.configService.getConfiguration('customLogger')) {
62
+ // use egg module
63
+ return this.transformEggLogger(this.configService.getConfiguration());
64
+ }
65
+ else {
66
+ // it will be use other logger
67
+ return;
68
+ }
69
+ }
70
+ async createClient(config, name) {
71
+ logger_1.loggers.createLogger(name, config);
72
+ }
73
+ getName() {
74
+ return 'logger';
75
+ }
76
+ createLogger(name, config) {
77
+ return logger_1.loggers.createLogger(name, config);
78
+ }
79
+ getLogger(name) {
80
+ return logger_1.loggers.getLogger(name);
81
+ }
82
+ transformEggLogger(options) {
83
+ var _a, _b, _c;
84
+ const transformLoggerConfig = {
85
+ midwayLogger: {
86
+ default: {},
87
+ clients: {},
88
+ },
89
+ };
90
+ if (options.midwayLogger && !options.midwayLogger.default) {
91
+ transformLoggerConfig.midwayLogger.default = {
92
+ dir: options.logger.dir,
93
+ level: levelTransform(options.logger.level),
94
+ consoleLevel: levelTransform(options.logger.consoleLevel),
95
+ };
96
+ }
97
+ const eggCustomLogger = options['customLogger'];
98
+ for (const name in eggCustomLogger) {
99
+ transformLoggerConfig.midwayLogger.clients[name] = {
100
+ fileLogName: (_a = eggCustomLogger[name]) === null || _a === void 0 ? void 0 : _a.file,
101
+ level: levelTransform((_b = eggCustomLogger[name]) === null || _b === void 0 ? void 0 : _b.level),
102
+ consoleLevel: levelTransform((_c = eggCustomLogger[name]) === null || _c === void 0 ? void 0 : _c.consoleLevel),
103
+ };
104
+ cleanUndefinedProperty(transformLoggerConfig.midwayLogger.clients[name]);
105
+ }
106
+ return transformLoggerConfig;
107
+ }
108
+ };
109
+ __decorate([
110
+ (0, decorator_1.Inject)(),
111
+ __metadata("design:type", configService_1.MidwayConfigService)
112
+ ], MidwayLoggerService.prototype, "configService", void 0);
113
+ __decorate([
114
+ (0, decorator_1.Init)(),
115
+ __metadata("design:type", Function),
116
+ __metadata("design:paramtypes", []),
117
+ __metadata("design:returntype", Promise)
118
+ ], MidwayLoggerService.prototype, "init", null);
119
+ MidwayLoggerService = __decorate([
120
+ (0, decorator_1.Provide)(),
121
+ (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
122
+ __metadata("design:paramtypes", [Object])
123
+ ], MidwayLoggerService);
124
+ exports.MidwayLoggerService = MidwayLoggerService;
125
+ function cleanUndefinedProperty(obj) {
126
+ Object.keys(obj).forEach(key => {
127
+ if (obj[key] === undefined) {
128
+ delete obj[key];
129
+ }
130
+ });
131
+ }
132
+ //# sourceMappingURL=loggerService.js.map
@@ -0,0 +1,10 @@
1
+ import { CommonMiddleware, IMidwayContainer, IMidwayApplication } from '../interface';
2
+ export declare class MidwayMiddlewareService<T, R, N = unknown> {
3
+ readonly applicationContext: IMidwayContainer;
4
+ constructor(applicationContext: IMidwayContainer);
5
+ compose(middleware: Array<CommonMiddleware<T, R, N> | string>, app: IMidwayApplication, name?: string): Promise<{
6
+ (context: any, next?: any): Promise<any>;
7
+ _name: string;
8
+ }>;
9
+ }
10
+ //# sourceMappingURL=middlewareService.d.ts.map
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MidwayMiddlewareService = void 0;
13
+ const decorator_1 = require("@midwayjs/decorator");
14
+ const error_1 = require("../error");
15
+ const util_1 = require("../util");
16
+ let MidwayMiddlewareService = class MidwayMiddlewareService {
17
+ constructor(applicationContext) {
18
+ this.applicationContext = applicationContext;
19
+ }
20
+ async compose(middleware, app, name) {
21
+ if (!Array.isArray(middleware)) {
22
+ throw new error_1.MidwayParameterError('Middleware stack must be an array');
23
+ }
24
+ const newMiddlewareArr = [];
25
+ for (let fn of middleware) {
26
+ if ((0, decorator_1.isClass)(fn) || typeof fn === 'string') {
27
+ if (typeof fn === 'string' &&
28
+ !this.applicationContext.hasDefinition(fn)) {
29
+ throw new error_1.MidwayCommonError('Middleware definition not found in midway container');
30
+ }
31
+ const classMiddleware = await this.applicationContext.getAsync(fn);
32
+ if (classMiddleware) {
33
+ fn = classMiddleware.resolve(app);
34
+ if (!classMiddleware.match && !classMiddleware.ignore) {
35
+ if (!fn.name) {
36
+ fn._name = classMiddleware.constructor.name;
37
+ }
38
+ // just got fn
39
+ newMiddlewareArr.push(fn);
40
+ }
41
+ else {
42
+ // wrap ignore and match
43
+ const mw = fn;
44
+ const match = (0, util_1.pathMatching)({
45
+ match: classMiddleware.match,
46
+ ignore: classMiddleware.ignore,
47
+ });
48
+ fn = (ctx, next, options) => {
49
+ if (!match(ctx))
50
+ return next();
51
+ return mw(ctx, next, options);
52
+ };
53
+ fn._name = classMiddleware.constructor.name;
54
+ newMiddlewareArr.push(fn);
55
+ }
56
+ }
57
+ else {
58
+ throw new error_1.MidwayCommonError('Middleware must have resolve method!');
59
+ }
60
+ }
61
+ else {
62
+ newMiddlewareArr.push(fn);
63
+ }
64
+ }
65
+ /**
66
+ * @param {Object} context
67
+ * @param next
68
+ * @return {Promise}
69
+ * @api public
70
+ */
71
+ const composeFn = (context, next) => {
72
+ const supportBody = (0, util_1.isIncludeProperty)(context, 'body');
73
+ // last called middleware #
74
+ let index = -1;
75
+ return dispatch(0);
76
+ function dispatch(i) {
77
+ if (i <= index)
78
+ return Promise.reject(new error_1.MidwayCommonError('next() called multiple times'));
79
+ index = i;
80
+ let fn = newMiddlewareArr[i];
81
+ if (i === newMiddlewareArr.length)
82
+ fn = next;
83
+ if (!fn)
84
+ return Promise.resolve();
85
+ try {
86
+ if (supportBody) {
87
+ return Promise.resolve(fn(context, dispatch.bind(null, i + 1), {
88
+ index,
89
+ })).then(result => {
90
+ // need to set body
91
+ if (context.body && !result) {
92
+ result = context.body;
93
+ }
94
+ else if (result && context.body !== result) {
95
+ context.body = result;
96
+ }
97
+ return result;
98
+ });
99
+ }
100
+ else {
101
+ return Promise.resolve(fn(context, dispatch.bind(null, i + 1), {
102
+ index,
103
+ }));
104
+ }
105
+ }
106
+ catch (err) {
107
+ return Promise.reject(err);
108
+ }
109
+ }
110
+ };
111
+ if (name) {
112
+ composeFn._name = name;
113
+ }
114
+ return composeFn;
115
+ }
116
+ };
117
+ MidwayMiddlewareService = __decorate([
118
+ (0, decorator_1.Provide)(),
119
+ (0, decorator_1.Scope)(decorator_1.ScopeEnum.Singleton),
120
+ __metadata("design:paramtypes", [Object])
121
+ ], MidwayMiddlewareService);
122
+ exports.MidwayMiddlewareService = MidwayMiddlewareService;
123
+ //# sourceMappingURL=middlewareService.js.map
@@ -1,3 +1,35 @@
1
+ import { IMidwayContainer } from '../interface';
2
+ import { ObjectIdentifier } from '@midwayjs/decorator';
3
+ interface IPipelineInfo {
4
+ /**
5
+ * 上次执行结果(只有在执行 waterfall 时才有值)
6
+ */
7
+ prevValue?: any;
8
+ /**
9
+ * 当前执行的 valve 类
10
+ */
11
+ current: IValveHandler;
12
+ /**
13
+ * 当前执行的 valve 名称(类名)
14
+ */
15
+ currentName: string;
16
+ /**
17
+ * 之前执行的 valve 类
18
+ */
19
+ prev?: IValveHandler;
20
+ /**
21
+ * 之前执行的 valve 名称(类名)
22
+ */
23
+ prevName?: string;
24
+ /**
25
+ * 后一个将执行的 valve 类
26
+ */
27
+ next?: IValveHandler;
28
+ /**
29
+ * 后一个将执行的 valve 名称(类名)
30
+ */
31
+ nextName?: string;
32
+ }
1
33
  /**
2
34
  * 执行pipeline 时当前上下文存储内容
3
35
  */
@@ -9,24 +41,7 @@ export interface IPipelineContext {
9
41
  /**
10
42
  * valve 执行信息
11
43
  */
12
- info?: {
13
- /**
14
- * 上次执行结果(只有在执行 waterfall 时才有值)
15
- */
16
- prevValue?: any;
17
- /**
18
- * 当前执行的 valve 名称(类名)
19
- */
20
- current: string;
21
- /**
22
- * 之前执行的 valve 名称(类名)
23
- */
24
- prev?: string;
25
- /**
26
- * 后一个将执行的 valve 名称(类名)
27
- */
28
- next?: string;
29
- };
44
+ info?: IPipelineInfo;
30
45
  /**
31
46
  * 用于缓存当前 pipeline 执行中的中间过程参数
32
47
  * @param key 关键词
@@ -68,7 +83,7 @@ export interface IPipelineOptions {
68
83
  /**
69
84
  * 这次 pipeline 执行那几个 valve 白名单
70
85
  */
71
- valves?: string[];
86
+ valves?: valvesType;
72
87
  }
73
88
  /**
74
89
  * pipeline 执行返回结果
@@ -101,6 +116,26 @@ export interface IPipelineResult<T> {
101
116
  result: T;
102
117
  }
103
118
  export interface IPipelineHandler {
119
+ parallel<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
120
+ concat<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
121
+ series<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
122
+ concatSeries<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
123
+ waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
124
+ }
125
+ declare type valvesType = Array<ObjectIdentifier | (new (...args: any[]) => any)>;
126
+ export declare class PipelineContext implements IPipelineContext {
127
+ args: any;
128
+ info: IPipelineInfo;
129
+ constructor(args?: any);
130
+ private data;
131
+ get(key: string): any;
132
+ set(key: string, val: any): void;
133
+ keys(): string[];
134
+ }
135
+ export declare class MidwayPipelineService implements IPipelineHandler {
136
+ readonly applicationContext: IMidwayContainer;
137
+ readonly valves?: valvesType;
138
+ constructor(applicationContext: IMidwayContainer, valves?: valvesType);
104
139
  /**
105
140
  * 并行执行,使用 Promise.all
106
141
  * @param opts 执行参数
@@ -126,34 +161,9 @@ export interface IPipelineHandler {
126
161
  * @param opts 执行参数
127
162
  */
128
163
  waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
129
- }
130
- import { IApplicationContext } from '../interface';
131
- export declare class PipelineContext implements IPipelineContext {
132
- args: any;
133
- info: {
134
- prevValue?: any;
135
- current: string;
136
- prev?: string;
137
- next?: string;
138
- };
139
- constructor(args?: any);
140
- private data;
141
- get(key: string): any;
142
- set(key: string, val: any): void;
143
- keys(): string[];
144
- }
145
- export declare class PipelineHandler implements IPipelineHandler {
146
- private applicationContext;
147
- private valves;
148
- constructor(applicationContext: IApplicationContext, valves?: string[]);
149
- parallel<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
150
- concat<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
151
- series<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
152
- concatSeries<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
153
- waterfall<T>(opts: IPipelineOptions): Promise<IPipelineResult<T>>;
154
164
  private mergeValves;
155
165
  private prepareParallelValves;
156
166
  private packResult;
157
167
  }
158
- export declare function pipelineFactory(applicationContext: IApplicationContext, valves?: string[]): PipelineHandler;
159
- //# sourceMappingURL=pipeline.d.ts.map
168
+ export {};
169
+ //# sourceMappingURL=pipelineService.d.ts.map
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pipelineFactory = exports.PipelineHandler = exports.PipelineContext = void 0;
3
+ exports.MidwayPipelineService = exports.PipelineContext = void 0;
4
4
  const decorator_1 = require("@midwayjs/decorator");
5
- const providerWrapper_1 = require("../context/providerWrapper");
5
+ ////////////// implements ///////////////////////
6
6
  class PipelineContext {
7
7
  constructor(args) {
8
- this.info = { current: null };
8
+ this.info = { current: null, currentName: null };
9
9
  this.data = new Map();
10
10
  this.args = args;
11
11
  }
@@ -25,21 +25,34 @@ class PipelineContext {
25
25
  }
26
26
  }
27
27
  exports.PipelineContext = PipelineContext;
28
- class PipelineHandler {
28
+ class MidwayPipelineService {
29
+ // 默认的 valves (@Pipeline(['test1', 'test2']))
29
30
  constructor(applicationContext, valves) {
30
31
  this.applicationContext = applicationContext;
31
32
  this.valves = valves;
32
33
  }
34
+ /**
35
+ * 并行执行,使用 Promise.all
36
+ * @param opts 执行参数
37
+ */
33
38
  async parallel(opts) {
34
39
  const valves = this.prepareParallelValves(opts);
35
40
  const res = await Promise.all(valves);
36
41
  return this.packResult(res, false);
37
42
  }
43
+ /**
44
+ * 并行执行,最终 result 为数组
45
+ * @param opts 执行参数
46
+ */
38
47
  async concat(opts) {
39
48
  const valves = this.prepareParallelValves(opts);
40
49
  const res = await Promise.all(valves);
41
50
  return this.packResult(res, true);
42
51
  }
52
+ /**
53
+ * 串行执行,使用 foreach await
54
+ * @param opts 执行参数
55
+ */
43
56
  async series(opts) {
44
57
  const valves = this.mergeValves(opts.valves);
45
58
  const ctx = new PipelineContext(opts.args);
@@ -48,18 +61,25 @@ class PipelineHandler {
48
61
  const info = {
49
62
  prevValue: null,
50
63
  current: null,
64
+ currentName: null,
51
65
  prev: null,
66
+ prevName: null,
52
67
  next: null,
68
+ nextName: null,
53
69
  };
54
70
  let nextIdx = 1;
55
71
  for (const v of valves) {
56
72
  info.prev = info.current;
73
+ info.prevName = getName(info.prev);
57
74
  info.current = v;
75
+ info.currentName = getName(info.current);
58
76
  if (nextIdx < valves.length) {
59
77
  info.next = valves[nextIdx];
78
+ info.nextName = getName(info.next);
60
79
  }
61
80
  else {
62
81
  info.next = undefined;
82
+ info.nextName = undefined;
63
83
  }
64
84
  nextIdx += 1;
65
85
  ctx.info = info;
@@ -76,7 +96,7 @@ class PipelineHandler {
76
96
  catch (e) {
77
97
  result.success = false;
78
98
  result.error = {
79
- valveName: v,
99
+ valveName: typeof v === 'string' ? v : v.name,
80
100
  message: e.message,
81
101
  error: e,
82
102
  };
@@ -86,6 +106,10 @@ class PipelineHandler {
86
106
  result.result = data;
87
107
  return result;
88
108
  }
109
+ /**
110
+ * 串行执行,使用 foreach await,最终 result 为数组
111
+ * @param opts 执行参数
112
+ */
89
113
  async concatSeries(opts) {
90
114
  const valves = this.mergeValves(opts.valves);
91
115
  const ctx = new PipelineContext(opts.args);
@@ -94,18 +118,25 @@ class PipelineHandler {
94
118
  const info = {
95
119
  prevValue: null,
96
120
  current: null,
121
+ currentName: null,
97
122
  prev: null,
123
+ prevName: null,
98
124
  next: null,
125
+ nextName: null,
99
126
  };
100
127
  let nextIdx = 1;
101
128
  for (const v of valves) {
102
129
  info.prev = info.current;
130
+ info.prevName = getName(info.prev);
103
131
  info.current = v;
132
+ info.currentName = getName(info.current);
104
133
  if (nextIdx < valves.length) {
105
134
  info.next = valves[nextIdx];
135
+ info.nextName = getName(info.next);
106
136
  }
107
137
  else {
108
138
  info.next = undefined;
139
+ info.nextName = undefined;
109
140
  }
110
141
  nextIdx += 1;
111
142
  ctx.info = info;
@@ -118,7 +149,7 @@ class PipelineHandler {
118
149
  catch (e) {
119
150
  result.success = false;
120
151
  result.error = {
121
- valveName: v,
152
+ valveName: typeof v === 'string' ? v : v.name,
122
153
  message: e.message,
123
154
  error: e,
124
155
  };
@@ -128,6 +159,10 @@ class PipelineHandler {
128
159
  result.result = data;
129
160
  return result;
130
161
  }
162
+ /**
163
+ * 串行执行,但是会把前者执行结果当成入参,传入到下一个执行中去,最后一个执行的 valve 结果会被返回
164
+ * @param opts 执行参数
165
+ */
131
166
  async waterfall(opts) {
132
167
  const result = await this.concatSeries(opts);
133
168
  if (result.success) {
@@ -185,7 +220,7 @@ class PipelineHandler {
185
220
  if (r.error) {
186
221
  result.success = false;
187
222
  result.error = {
188
- valveName: r.valveName,
223
+ valveName: typeof r.valveName === 'string' ? r.valveName : r.valveName.name,
189
224
  message: r.error.message,
190
225
  error: r.error,
191
226
  };
@@ -204,16 +239,16 @@ class PipelineHandler {
204
239
  return result;
205
240
  }
206
241
  }
207
- exports.PipelineHandler = PipelineHandler;
208
- function pipelineFactory(applicationContext, valves) {
209
- return new PipelineHandler(applicationContext, valves);
242
+ exports.MidwayPipelineService = MidwayPipelineService;
243
+ function getName(target) {
244
+ if (target) {
245
+ if (typeof target === 'string') {
246
+ return target;
247
+ }
248
+ else {
249
+ return (0, decorator_1.getProviderName)(target);
250
+ }
251
+ }
252
+ return null;
210
253
  }
211
- exports.pipelineFactory = pipelineFactory;
212
- providerWrapper_1.providerWrapper([
213
- {
214
- id: decorator_1.PIPELINE_IDENTIFIER,
215
- provider: pipelineFactory,
216
- scope: decorator_1.ScopeEnum.Prototype,
217
- },
218
- ]);
219
- //# sourceMappingURL=pipeline.js.map
254
+ //# sourceMappingURL=pipelineService.js.map
@@ -0,0 +1,4 @@
1
+ import { IMidwayBootstrapOptions, IMidwayContainer } from './';
2
+ export declare function initializeGlobalApplicationContext(globalOptions: IMidwayBootstrapOptions): Promise<IMidwayContainer>;
3
+ export declare function destroyGlobalApplicationContext(applicationContext: IMidwayContainer): Promise<void>;
4
+ //# sourceMappingURL=setup.d.ts.map