@midwayjs/core 3.19.0 → 4.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/dist/baseFramework.d.ts +7 -35
  2. package/dist/baseFramework.js +10 -52
  3. package/dist/common/applicationManager.d.ts +6 -6
  4. package/dist/common/applicationManager.js +18 -35
  5. package/dist/common/asyncContextManager.d.ts +15 -0
  6. package/dist/common/asyncContextManager.js +51 -2
  7. package/dist/common/dataListener.js +1 -1
  8. package/dist/common/dataSourceManager.js +3 -4
  9. package/dist/common/fileDetector.d.ts +9 -9
  10. package/dist/common/fileDetector.js +30 -28
  11. package/dist/common/filterManager.js +5 -4
  12. package/dist/common/guardManager.js +3 -2
  13. package/dist/common/middlewareManager.js +4 -3
  14. package/dist/common/performanceManager.js +1 -1
  15. package/dist/common/priorityManager.js +2 -2
  16. package/dist/common/serviceFactory.js +1 -1
  17. package/dist/common/webGenerator.js +4 -6
  18. package/dist/config/config.default.js +1 -1
  19. package/dist/constants.d.ts +2 -32
  20. package/dist/constants.js +3 -33
  21. package/dist/context/componentLoader.d.ts +20 -0
  22. package/dist/context/componentLoader.js +193 -0
  23. package/dist/context/container.d.ts +14 -29
  24. package/dist/context/container.js +68 -306
  25. package/dist/context/definitionRegistry.d.ts +3 -0
  26. package/dist/context/definitionRegistry.js +8 -15
  27. package/dist/context/managedResolverFactory.d.ts +15 -40
  28. package/dist/context/managedResolverFactory.js +263 -348
  29. package/dist/context/requestContainer.d.ts +22 -12
  30. package/dist/context/requestContainer.js +43 -51
  31. package/dist/decorator/common/aspect.js +4 -4
  32. package/dist/decorator/common/autoload.js +1 -1
  33. package/dist/decorator/common/configuration.d.ts +1 -24
  34. package/dist/decorator/common/configuration.js +6 -1
  35. package/dist/decorator/common/filter.js +6 -6
  36. package/dist/decorator/common/framework.d.ts +46 -3
  37. package/dist/decorator/common/framework.js +43 -9
  38. package/dist/decorator/common/guard.js +4 -9
  39. package/dist/decorator/common/inject.d.ts +4 -2
  40. package/dist/decorator/common/inject.js +87 -4
  41. package/dist/decorator/common/mock.js +1 -1
  42. package/dist/decorator/common/objectDef.d.ts +0 -5
  43. package/dist/decorator/common/objectDef.js +8 -20
  44. package/dist/decorator/common/provide.d.ts +1 -1
  45. package/dist/decorator/common/provide.js +1 -1
  46. package/dist/decorator/common/scope.d.ts +6 -0
  47. package/dist/decorator/common/scope.js +21 -0
  48. package/dist/decorator/constant.d.ts +14 -17
  49. package/dist/decorator/constant.js +23 -35
  50. package/dist/decorator/decoratorManager.d.ts +21 -294
  51. package/dist/decorator/decoratorManager.js +127 -694
  52. package/dist/decorator/faas/serverlessTrigger.js +5 -5
  53. package/dist/decorator/index.d.ts +2 -3
  54. package/dist/decorator/index.js +6 -4
  55. package/dist/decorator/metadataManager.d.ts +127 -0
  56. package/dist/decorator/metadataManager.js +465 -0
  57. package/dist/decorator/microservice/consumer.js +3 -2
  58. package/dist/decorator/microservice/kafkaListener.js +2 -1
  59. package/dist/decorator/microservice/provider.js +6 -5
  60. package/dist/decorator/microservice/rabbitmqListener.js +2 -1
  61. package/dist/decorator/task/queue.js +3 -2
  62. package/dist/decorator/task/schedule.js +3 -2
  63. package/dist/decorator/task/task.js +4 -3
  64. package/dist/decorator/task/taskLocal.js +4 -3
  65. package/dist/decorator/web/controller.js +3 -2
  66. package/dist/decorator/web/paramMapping.js +2 -2
  67. package/dist/decorator/web/requestMapping.js +5 -5
  68. package/dist/decorator/web/response.js +6 -5
  69. package/dist/decorator/ws/webSocketController.js +3 -2
  70. package/dist/decorator/ws/webSocketEvent.js +7 -6
  71. package/dist/definitions/functionDefinition.d.ts +3 -3
  72. package/dist/definitions/functionDefinition.js +12 -11
  73. package/dist/definitions/objectCreator.d.ts +5 -11
  74. package/dist/definitions/objectCreator.js +3 -27
  75. package/dist/definitions/objectDefinition.d.ts +2 -3
  76. package/dist/definitions/objectDefinition.js +1 -3
  77. package/dist/error/base.js +2 -2
  78. package/dist/error/framework.d.ts +1 -8
  79. package/dist/error/framework.js +9 -25
  80. package/dist/error/http.js +1 -1
  81. package/dist/functional/configuration.d.ts +14 -15
  82. package/dist/functional/configuration.js +37 -47
  83. package/dist/functional/hooks.d.ts +10 -0
  84. package/dist/functional/hooks.js +68 -0
  85. package/dist/functional/index.d.ts +3 -0
  86. package/dist/functional/index.js +22 -0
  87. package/dist/index.d.ts +3 -3
  88. package/dist/index.js +3 -6
  89. package/dist/interface.d.ts +80 -114
  90. package/dist/interface.js +9 -33
  91. package/dist/legacy/constants.d.ts +29 -0
  92. package/dist/legacy/constants.js +33 -0
  93. package/dist/legacy/decorator.d.ts +255 -0
  94. package/dist/legacy/decorator.js +468 -0
  95. package/dist/legacy/index.d.ts +3 -0
  96. package/dist/legacy/index.js +19 -0
  97. package/dist/legacy/types.d.ts +2 -0
  98. package/dist/legacy/types.js +3 -0
  99. package/dist/response/base.d.ts +1 -0
  100. package/dist/response/http.d.ts +1 -0
  101. package/dist/service/aspectService.js +11 -12
  102. package/dist/service/configService.js +2 -2
  103. package/dist/service/decoratorService.d.ts +3 -3
  104. package/dist/service/decoratorService.js +14 -10
  105. package/dist/service/environmentService.js +2 -2
  106. package/dist/service/frameworkService.d.ts +5 -4
  107. package/dist/service/frameworkService.js +30 -28
  108. package/dist/service/healthService.js +4 -4
  109. package/dist/service/informationService.js +3 -4
  110. package/dist/service/lifeCycleService.js +6 -17
  111. package/dist/service/loggerService.js +3 -4
  112. package/dist/service/middlewareService.js +7 -8
  113. package/dist/service/mockService.js +9 -15
  114. package/dist/service/slsFunctionService.d.ts +1 -14
  115. package/dist/service/slsFunctionService.js +33 -81
  116. package/dist/service/webRouterService.js +11 -11
  117. package/dist/setup.d.ts +5 -5
  118. package/dist/setup.js +75 -93
  119. package/dist/util/contextUtil.d.ts +2 -2
  120. package/dist/util/httpclient.d.ts +3 -2
  121. package/dist/util/index.d.ts +14 -0
  122. package/dist/util/index.js +159 -25
  123. package/dist/util/pathFileUtil.d.ts +14 -1
  124. package/dist/util/pathFileUtil.js +27 -6
  125. package/dist/util/webRouterParam.js +2 -2
  126. package/package.json +24 -6
  127. package/dist/decorator/common/pipeline.d.ts +0 -3
  128. package/dist/decorator/common/pipeline.js +0 -12
  129. package/dist/decorator/rpc/hsf.d.ts +0 -13
  130. package/dist/decorator/rpc/hsf.js +0 -20
  131. package/dist/definitions/properties.d.ts +0 -7
  132. package/dist/definitions/properties.js +0 -19
  133. package/dist/service/pipelineService.d.ts +0 -168
  134. package/dist/service/pipelineService.js +0 -254
@@ -1,254 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MidwayPipelineService = exports.PipelineContext = void 0;
4
- const decorator_1 = require("../decorator");
5
- ////////////// implements ///////////////////////
6
- class PipelineContext {
7
- constructor(args) {
8
- this.info = { current: null, currentName: null };
9
- this.data = new Map();
10
- this.args = args;
11
- }
12
- get(key) {
13
- return this.data.get(key);
14
- }
15
- set(key, val) {
16
- this.data.set(key, val);
17
- }
18
- keys() {
19
- const keys = [];
20
- const iter = this.data.keys();
21
- for (const k of iter) {
22
- keys.push(k);
23
- }
24
- return keys;
25
- }
26
- }
27
- exports.PipelineContext = PipelineContext;
28
- class MidwayPipelineService {
29
- // 默认的 valves (@Pipeline(['test1', 'test2']))
30
- constructor(applicationContext, valves) {
31
- this.applicationContext = applicationContext;
32
- this.valves = valves;
33
- }
34
- /**
35
- * 并行执行,使用 Promise.all
36
- * @param opts 执行参数
37
- */
38
- async parallel(opts) {
39
- const valves = this.prepareParallelValves(opts);
40
- const res = await Promise.all(valves);
41
- return this.packResult(res, false);
42
- }
43
- /**
44
- * 并行执行,最终 result 为数组
45
- * @param opts 执行参数
46
- */
47
- async concat(opts) {
48
- const valves = this.prepareParallelValves(opts);
49
- const res = await Promise.all(valves);
50
- return this.packResult(res, true);
51
- }
52
- /**
53
- * 串行执行,使用 foreach await
54
- * @param opts 执行参数
55
- */
56
- async series(opts) {
57
- const valves = this.mergeValves(opts.valves);
58
- const ctx = new PipelineContext(opts.args);
59
- const result = { success: true, result: null };
60
- const data = {};
61
- const info = {
62
- prevValue: null,
63
- current: null,
64
- currentName: null,
65
- prev: null,
66
- prevName: null,
67
- next: null,
68
- nextName: null,
69
- };
70
- let nextIdx = 1;
71
- for (const v of valves) {
72
- info.prev = info.current;
73
- info.prevName = getName(info.prev);
74
- info.current = v;
75
- info.currentName = getName(info.current);
76
- if (nextIdx < valves.length) {
77
- info.next = valves[nextIdx];
78
- info.nextName = getName(info.next);
79
- }
80
- else {
81
- info.next = undefined;
82
- info.nextName = undefined;
83
- }
84
- nextIdx += 1;
85
- ctx.info = info;
86
- try {
87
- const inst = await this.applicationContext.getAsync(v);
88
- const tmpValue = await inst.invoke(ctx);
89
- let key = v;
90
- if (inst.alias) {
91
- key = inst.alias;
92
- }
93
- data[key] = tmpValue;
94
- info.prevValue = tmpValue;
95
- }
96
- catch (e) {
97
- result.success = false;
98
- result.error = {
99
- valveName: typeof v === 'string' ? v : v.name,
100
- message: e.message,
101
- error: e,
102
- };
103
- return result;
104
- }
105
- }
106
- result.result = data;
107
- return result;
108
- }
109
- /**
110
- * 串行执行,使用 foreach await,最终 result 为数组
111
- * @param opts 执行参数
112
- */
113
- async concatSeries(opts) {
114
- const valves = this.mergeValves(opts.valves);
115
- const ctx = new PipelineContext(opts.args);
116
- const result = { success: true, result: null };
117
- const data = [];
118
- const info = {
119
- prevValue: null,
120
- current: null,
121
- currentName: null,
122
- prev: null,
123
- prevName: null,
124
- next: null,
125
- nextName: null,
126
- };
127
- let nextIdx = 1;
128
- for (const v of valves) {
129
- info.prev = info.current;
130
- info.prevName = getName(info.prev);
131
- info.current = v;
132
- info.currentName = getName(info.current);
133
- if (nextIdx < valves.length) {
134
- info.next = valves[nextIdx];
135
- info.nextName = getName(info.next);
136
- }
137
- else {
138
- info.next = undefined;
139
- info.nextName = undefined;
140
- }
141
- nextIdx += 1;
142
- ctx.info = info;
143
- try {
144
- const inst = await this.applicationContext.getAsync(v);
145
- const tmpValue = await inst.invoke(ctx);
146
- data.push(tmpValue);
147
- info.prevValue = tmpValue;
148
- }
149
- catch (e) {
150
- result.success = false;
151
- result.error = {
152
- valveName: typeof v === 'string' ? v : v.name,
153
- message: e.message,
154
- error: e,
155
- };
156
- return result;
157
- }
158
- }
159
- result.result = data;
160
- return result;
161
- }
162
- /**
163
- * 串行执行,但是会把前者执行结果当成入参,传入到下一个执行中去,最后一个执行的 valve 结果会被返回
164
- * @param opts 执行参数
165
- */
166
- async waterfall(opts) {
167
- const result = await this.concatSeries(opts);
168
- if (result.success) {
169
- const data = result.result;
170
- result.result = data[data.length - 1];
171
- }
172
- return result;
173
- }
174
- mergeValves(valves) {
175
- let items = [];
176
- if (this.valves && this.valves.length > 0) {
177
- items = this.valves;
178
- }
179
- let newItems = [];
180
- if (valves) {
181
- for (const v of valves) {
182
- if (items.includes(v)) {
183
- newItems.push(v);
184
- }
185
- }
186
- }
187
- else {
188
- newItems = items;
189
- }
190
- return newItems;
191
- }
192
- prepareParallelValves(opts) {
193
- const valves = this.mergeValves(opts.valves);
194
- const ctx = new PipelineContext(opts.args);
195
- return valves.map(async (v) => {
196
- const rt = { valveName: v, dataKey: v, data: null };
197
- try {
198
- const inst = await this.applicationContext.getAsync(v);
199
- if (inst.alias) {
200
- rt.dataKey = inst.alias;
201
- }
202
- rt.data = await inst.invoke(ctx);
203
- }
204
- catch (e) {
205
- rt.error = e;
206
- }
207
- return rt;
208
- });
209
- }
210
- packResult(res, resultIsArray = false) {
211
- const result = { success: true, result: null };
212
- let data;
213
- if (resultIsArray) {
214
- data = [];
215
- }
216
- else {
217
- data = {};
218
- }
219
- for (const r of res) {
220
- if (r.error) {
221
- result.success = false;
222
- result.error = {
223
- valveName: typeof r.valveName === 'string' ? r.valveName : r.valveName.name,
224
- message: r.error.message,
225
- error: r.error,
226
- };
227
- return result;
228
- }
229
- else {
230
- if (resultIsArray) {
231
- data.push(r.data);
232
- }
233
- else {
234
- data[r.dataKey] = r.data;
235
- }
236
- }
237
- }
238
- result.result = data;
239
- return result;
240
- }
241
- }
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;
253
- }
254
- //# sourceMappingURL=pipelineService.js.map