@midwayjs/core 3.5.4-beta.2 → 3.6.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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/dist/baseFramework.d.ts +7 -2
  3. package/dist/baseFramework.js +27 -9
  4. package/dist/common/applicationManager.d.ts +1 -1
  5. package/dist/common/applicationManager.js +1 -1
  6. package/dist/common/dataListener.js +1 -1
  7. package/dist/common/dataSourceManager.js +7 -7
  8. package/dist/common/fileDetector.js +6 -5
  9. package/dist/common/filterManager.js +1 -1
  10. package/dist/common/guardManager.d.ts +6 -0
  11. package/dist/common/guardManager.js +49 -0
  12. package/dist/common/middlewareManager.d.ts +2 -2
  13. package/dist/common/webGenerator.d.ts +2 -1
  14. package/dist/common/webGenerator.js +12 -3
  15. package/dist/config/config.default.d.ts +2 -11
  16. package/dist/config/config.default.js +2 -2
  17. package/dist/{common/constants.d.ts → constants.d.ts} +10 -1
  18. package/dist/{common/constants.js → constants.js} +18 -2
  19. package/dist/context/container.d.ts +1 -1
  20. package/dist/context/container.js +16 -14
  21. package/dist/context/definitionRegistry.d.ts +1 -1
  22. package/dist/context/definitionRegistry.js +1 -1
  23. package/dist/context/managedResolverFactory.d.ts +1 -4
  24. package/dist/context/managedResolverFactory.js +6 -6
  25. package/dist/context/providerWrapper.d.ts +1 -1
  26. package/dist/context/providerWrapper.js +1 -1
  27. package/dist/context/requestContainer.js +3 -3
  28. package/dist/decorator/common/aspect.d.ts +20 -0
  29. package/dist/decorator/common/aspect.js +22 -0
  30. package/dist/decorator/common/autoload.d.ts +2 -0
  31. package/dist/decorator/common/autoload.js +13 -0
  32. package/dist/decorator/common/configuration.d.ts +24 -0
  33. package/dist/decorator/common/configuration.js +11 -0
  34. package/dist/decorator/common/filter.d.ts +6 -0
  35. package/dist/decorator/common/filter.js +31 -0
  36. package/dist/decorator/common/framework.d.ts +8 -0
  37. package/dist/decorator/common/framework.js +41 -0
  38. package/dist/decorator/common/guard.d.ts +4 -0
  39. package/dist/decorator/common/guard.js +30 -0
  40. package/dist/decorator/common/inject.d.ts +3 -0
  41. package/dist/decorator/common/inject.js +11 -0
  42. package/dist/decorator/common/middleware.d.ts +2 -0
  43. package/dist/decorator/common/middleware.js +12 -0
  44. package/dist/decorator/common/objectDef.d.ts +7 -0
  45. package/dist/decorator/common/objectDef.js +25 -0
  46. package/dist/decorator/common/pipeline.d.ts +3 -0
  47. package/dist/decorator/common/pipeline.js +12 -0
  48. package/dist/decorator/common/provide.d.ts +3 -0
  49. package/dist/decorator/common/provide.js +11 -0
  50. package/dist/decorator/constant.d.ts +55 -0
  51. package/dist/decorator/constant.js +86 -0
  52. package/dist/decorator/decoratorManager.d.ts +301 -0
  53. package/dist/decorator/decoratorManager.js +709 -0
  54. package/dist/decorator/faas/serverlessTrigger.d.ts +13 -0
  55. package/dist/decorator/faas/serverlessTrigger.js +29 -0
  56. package/dist/decorator/index.d.ts +31 -0
  57. package/dist/decorator/index.js +55 -0
  58. package/dist/decorator/interface.d.ts +238 -0
  59. package/dist/decorator/interface.js +67 -0
  60. package/dist/decorator/microservice/consumer.d.ts +5 -0
  61. package/dist/decorator/microservice/consumer.js +17 -0
  62. package/dist/decorator/microservice/kafkaListener.d.ts +24 -0
  63. package/dist/decorator/microservice/kafkaListener.js +13 -0
  64. package/dist/decorator/microservice/provider.d.ts +16 -0
  65. package/dist/decorator/microservice/provider.js +47 -0
  66. package/dist/decorator/microservice/rabbitmqListener.d.ts +50 -0
  67. package/dist/decorator/microservice/rabbitmqListener.js +13 -0
  68. package/dist/decorator/rpc/hsf.d.ts +12 -0
  69. package/dist/decorator/rpc/hsf.js +18 -0
  70. package/dist/decorator/task/queue.d.ts +2 -0
  71. package/dist/decorator/task/queue.js +17 -0
  72. package/dist/decorator/task/schedule.d.ts +21 -0
  73. package/dist/decorator/task/schedule.js +14 -0
  74. package/dist/decorator/task/task.d.ts +2 -0
  75. package/dist/decorator/task/task.js +18 -0
  76. package/dist/decorator/task/taskLocal.d.ts +2 -0
  77. package/dist/decorator/task/taskLocal.js +17 -0
  78. package/dist/decorator/web/controller.d.ts +20 -0
  79. package/dist/decorator/web/controller.js +18 -0
  80. package/dist/decorator/web/paramMapping.d.ts +31 -0
  81. package/dist/decorator/web/paramMapping.js +50 -0
  82. package/dist/decorator/web/requestMapping.d.ts +132 -0
  83. package/dist/decorator/web/requestMapping.js +83 -0
  84. package/dist/decorator/web/response.d.ts +9 -0
  85. package/dist/decorator/web/response.js +65 -0
  86. package/dist/decorator/ws/webSocketController.d.ts +10 -0
  87. package/dist/decorator/ws/webSocketController.js +20 -0
  88. package/dist/decorator/ws/webSocketEvent.d.ts +60 -0
  89. package/dist/decorator/ws/webSocketEvent.js +87 -0
  90. package/dist/definitions/functionDefinition.d.ts +1 -1
  91. package/dist/definitions/functionDefinition.js +1 -1
  92. package/dist/definitions/objectCreator.d.ts +1 -1
  93. package/dist/definitions/objectCreator.js +7 -7
  94. package/dist/definitions/objectDefinition.d.ts +1 -1
  95. package/dist/definitions/objectDefinition.js +1 -1
  96. package/dist/definitions/properties.d.ts +1 -1
  97. package/dist/error/framework.d.ts +5 -1
  98. package/dist/error/framework.js +9 -2
  99. package/dist/functional/configuration.d.ts +1 -1
  100. package/dist/index.d.ts +18 -15
  101. package/dist/index.js +40 -27
  102. package/dist/interface.d.ts +52 -18
  103. package/dist/interface.js +1 -17
  104. package/dist/service/aspectService.d.ts +1 -1
  105. package/dist/service/aspectService.js +3 -2
  106. package/dist/service/configService.js +3 -2
  107. package/dist/service/decoratorService.js +1 -1
  108. package/dist/service/environmentService.js +1 -1
  109. package/dist/service/frameworkService.d.ts +1 -1
  110. package/dist/service/frameworkService.js +3 -3
  111. package/dist/service/informationService.js +1 -1
  112. package/dist/service/lifeCycleService.js +1 -1
  113. package/dist/service/loggerService.js +1 -1
  114. package/dist/service/middlewareService.js +3 -2
  115. package/dist/service/mockService.js +1 -1
  116. package/dist/service/pipelineService.d.ts +1 -1
  117. package/dist/service/pipelineService.js +1 -1
  118. package/dist/service/slsFunctionService.d.ts +1 -1
  119. package/dist/service/slsFunctionService.js +1 -1
  120. package/dist/service/webRouterService.d.ts +9 -1
  121. package/dist/service/webRouterService.js +6 -3
  122. package/dist/setup.d.ts +3 -3
  123. package/dist/setup.js +1 -1
  124. package/dist/util/camelCase.d.ts +3 -0
  125. package/dist/util/camelCase.js +88 -0
  126. package/dist/util/contextUtil.js +2 -2
  127. package/dist/util/extend.js +3 -3
  128. package/dist/util/flatted.d.ts +7 -0
  129. package/dist/util/flatted.js +91 -0
  130. package/dist/util/format.d.ts +25 -0
  131. package/dist/util/format.js +38 -0
  132. package/dist/util/fs.d.ts +5 -0
  133. package/dist/util/fs.js +15 -0
  134. package/dist/util/httpclient.d.ts +1 -0
  135. package/dist/util/index.d.ts +26 -0
  136. package/dist/util/index.js +80 -1
  137. package/dist/util/pathFileUtil.d.ts +6 -3
  138. package/dist/util/pathFileUtil.js +28 -22
  139. package/dist/util/retry.js +2 -2
  140. package/dist/util/types.d.ts +35 -0
  141. package/dist/util/types.js +121 -0
  142. package/dist/util/uuid.d.ts +5 -0
  143. package/dist/util/uuid.js +64 -0
  144. package/dist/util/webRouterParam.js +1 -1
  145. package/package.json +8 -11
@@ -0,0 +1,709 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCustomParamDecorator = exports.createCustomMethodDecorator = exports.createCustomPropertyDecorator = exports.getMethodReturnTypes = exports.getPropertyType = exports.getMethodParamTypes = exports.BaseType = exports.isProvide = exports.getProviderUUId = exports.getProviderName = exports.getProviderId = exports.saveProviderId = exports.getObjectDefinition = exports.saveObjectDefinition = exports.getPropertyInject = exports.savePropertyInject = exports.clearAllModule = exports.resetModule = exports.listModule = exports.clearBindContainer = exports.bindContainer = exports.saveModule = exports.listPreloadModule = exports.savePreloadModule = exports.getPropertyMetadata = exports.attachPropertyMetadata = exports.savePropertyMetadata = exports.listPropertyDataFromClass = exports.getPropertyDataFromClass = exports.attachPropertyDataToClass = exports.savePropertyDataToClass = exports.getClassMetadata = exports.getClassExtendedMetadata = exports.attachClassMetadata = exports.saveClassMetadata = exports.DecoratorManager = exports.INJECT_CLASS_KEY_PREFIX = exports.PRELOAD_MODULE_KEY = void 0;
4
+ require("reflect-metadata");
5
+ const interface_1 = require("./interface");
6
+ const constant_1 = require("./constant");
7
+ const types_1 = require("../util/types");
8
+ const camelCase_1 = require("../util/camelCase");
9
+ const util_1 = require("../util");
10
+ const debug = require('util').debuglog('midway:core');
11
+ exports.PRELOAD_MODULE_KEY = 'INJECTION_PRELOAD_MODULE_KEY';
12
+ exports.INJECT_CLASS_KEY_PREFIX = 'INJECTION_CLASS_META_DATA';
13
+ class DecoratorManager extends Map {
14
+ constructor() {
15
+ super(...arguments);
16
+ /**
17
+ * the key for meta data store in class
18
+ */
19
+ this.injectClassKeyPrefix = exports.INJECT_CLASS_KEY_PREFIX;
20
+ /**
21
+ * the key for method meta data store in class
22
+ */
23
+ this.injectClassMethodKeyPrefix = 'INJECTION_CLASS_METHOD_META_DATA';
24
+ /**
25
+ * the key for method meta data store in method
26
+ */
27
+ this.injectMethodKeyPrefix = 'INJECTION_METHOD_META_DATA';
28
+ }
29
+ saveModule(key, module) {
30
+ if (this.container) {
31
+ return this.container.saveModule(key, module);
32
+ }
33
+ if (!this.has(key)) {
34
+ this.set(key, new Set());
35
+ }
36
+ this.get(key).add(module);
37
+ }
38
+ listModule(key) {
39
+ if (this.container) {
40
+ return this.container.listModule(key);
41
+ }
42
+ return Array.from(this.get(key) || {});
43
+ }
44
+ resetModule(key) {
45
+ this.set(key, new Set());
46
+ }
47
+ bindContainer(container) {
48
+ this.container = container;
49
+ this.container.transformModule(this);
50
+ }
51
+ static getDecoratorClassKey(decoratorNameKey) {
52
+ return decoratorNameKey.toString() + '_CLS';
53
+ }
54
+ static removeDecoratorClassKeySuffix(decoratorNameKey) {
55
+ return decoratorNameKey.toString().replace('_CLS', '');
56
+ }
57
+ static getDecoratorMethodKey(decoratorNameKey) {
58
+ return decoratorNameKey.toString() + '_METHOD';
59
+ }
60
+ static getDecoratorClsExtendedKey(decoratorNameKey) {
61
+ return decoratorNameKey.toString() + '_EXT';
62
+ }
63
+ static getDecoratorClsMethodPrefix(decoratorNameKey) {
64
+ return decoratorNameKey.toString() + '_CLS_METHOD';
65
+ }
66
+ static getDecoratorClsMethodKey(decoratorNameKey, methodKey) {
67
+ return (DecoratorManager.getDecoratorClsMethodPrefix(decoratorNameKey) +
68
+ ':' +
69
+ methodKey.toString());
70
+ }
71
+ static getDecoratorMethod(decoratorNameKey, methodKey) {
72
+ return (DecoratorManager.getDecoratorMethodKey(decoratorNameKey) +
73
+ '_' +
74
+ methodKey.toString());
75
+ }
76
+ static saveMetadata(metaKey, target, dataKey, data) {
77
+ // filter Object.create(null)
78
+ if (typeof target === 'object' && target.constructor) {
79
+ target = target.constructor;
80
+ }
81
+ let m;
82
+ if (Reflect.hasOwnMetadata(metaKey, target)) {
83
+ m = Reflect.getMetadata(metaKey, target);
84
+ }
85
+ else {
86
+ m = new Map();
87
+ }
88
+ m.set(dataKey, data);
89
+ Reflect.defineMetadata(metaKey, m, target);
90
+ }
91
+ static attachMetadata(metaKey, target, dataKey, data, groupBy, groupMode = 'one') {
92
+ // filter Object.create(null)
93
+ if (typeof target === 'object' && target.constructor) {
94
+ target = target.constructor;
95
+ }
96
+ let m;
97
+ if (Reflect.hasOwnMetadata(metaKey, target)) {
98
+ m = Reflect.getMetadata(metaKey, target);
99
+ }
100
+ else {
101
+ m = new Map();
102
+ }
103
+ if (!m.has(dataKey)) {
104
+ if (groupBy) {
105
+ m.set(dataKey, {});
106
+ }
107
+ else {
108
+ m.set(dataKey, []);
109
+ }
110
+ }
111
+ if (groupBy) {
112
+ if (groupMode === 'one') {
113
+ m.get(dataKey)[groupBy] = data;
114
+ }
115
+ else {
116
+ if (m.get(dataKey)[groupBy]) {
117
+ m.get(dataKey)[groupBy].push(data);
118
+ }
119
+ else {
120
+ m.get(dataKey)[groupBy] = [data];
121
+ }
122
+ }
123
+ }
124
+ else {
125
+ m.get(dataKey).push(data);
126
+ }
127
+ Reflect.defineMetadata(metaKey, m, target);
128
+ }
129
+ static getMetadata(metaKey, target, dataKey) {
130
+ // filter Object.create(null)
131
+ if (typeof target === 'object' && target.constructor) {
132
+ target = target.constructor;
133
+ }
134
+ let m;
135
+ if (!Reflect.hasOwnMetadata(metaKey, target)) {
136
+ m = new Map();
137
+ Reflect.defineMetadata(metaKey, m, target);
138
+ }
139
+ else {
140
+ m = Reflect.getMetadata(metaKey, target);
141
+ }
142
+ if (!dataKey) {
143
+ return m;
144
+ }
145
+ return m.get(dataKey);
146
+ }
147
+ /**
148
+ * save meta data to class or property
149
+ * @param decoratorNameKey the alias name for decorator
150
+ * @param data the data you want to store
151
+ * @param target target class
152
+ * @param propertyName
153
+ */
154
+ saveMetadata(decoratorNameKey, data, target, propertyName) {
155
+ if (propertyName) {
156
+ const dataKey = DecoratorManager.getDecoratorMethod(decoratorNameKey, propertyName);
157
+ DecoratorManager.saveMetadata(this.injectMethodKeyPrefix, target, dataKey, data);
158
+ }
159
+ else {
160
+ const dataKey = DecoratorManager.getDecoratorClassKey(decoratorNameKey);
161
+ DecoratorManager.saveMetadata(this.injectClassKeyPrefix, target, dataKey, data);
162
+ }
163
+ }
164
+ /**
165
+ * attach data to class or property
166
+ * @param decoratorNameKey
167
+ * @param data
168
+ * @param target
169
+ * @param propertyName
170
+ * @param groupBy
171
+ */
172
+ attachMetadata(decoratorNameKey, data, target, propertyName, groupBy, groupMode) {
173
+ if (propertyName) {
174
+ const dataKey = DecoratorManager.getDecoratorMethod(decoratorNameKey, propertyName);
175
+ DecoratorManager.attachMetadata(this.injectMethodKeyPrefix, target, dataKey, data, groupBy, groupMode);
176
+ }
177
+ else {
178
+ const dataKey = DecoratorManager.getDecoratorClassKey(decoratorNameKey);
179
+ DecoratorManager.attachMetadata(this.injectClassKeyPrefix, target, dataKey, data, groupBy, groupMode);
180
+ }
181
+ }
182
+ /**
183
+ * get single data from class or property
184
+ * @param decoratorNameKey
185
+ * @param target
186
+ * @param propertyName
187
+ */
188
+ getMetadata(decoratorNameKey, target, propertyName) {
189
+ if (propertyName) {
190
+ const dataKey = DecoratorManager.getDecoratorMethod(decoratorNameKey, propertyName);
191
+ return DecoratorManager.getMetadata(this.injectMethodKeyPrefix, target, dataKey);
192
+ }
193
+ else {
194
+ const dataKey = `${DecoratorManager.getDecoratorClassKey(decoratorNameKey)}`;
195
+ return DecoratorManager.getMetadata(this.injectClassKeyPrefix, target, dataKey);
196
+ }
197
+ }
198
+ /**
199
+ * save property data to class
200
+ * @param decoratorNameKey
201
+ * @param data
202
+ * @param target
203
+ * @param propertyName
204
+ */
205
+ savePropertyDataToClass(decoratorNameKey, data, target, propertyName) {
206
+ const dataKey = DecoratorManager.getDecoratorClsMethodKey(decoratorNameKey, propertyName);
207
+ DecoratorManager.saveMetadata(this.injectClassMethodKeyPrefix, target, dataKey, data);
208
+ }
209
+ /**
210
+ * attach property data to class
211
+ * @param decoratorNameKey
212
+ * @param data
213
+ * @param target
214
+ * @param propertyName
215
+ * @param groupBy
216
+ */
217
+ attachPropertyDataToClass(decoratorNameKey, data, target, propertyName, groupBy) {
218
+ const dataKey = DecoratorManager.getDecoratorClsMethodKey(decoratorNameKey, propertyName);
219
+ DecoratorManager.attachMetadata(this.injectClassMethodKeyPrefix, target, dataKey, data, groupBy);
220
+ }
221
+ /**
222
+ * get property data from class
223
+ * @param decoratorNameKey
224
+ * @param target
225
+ * @param propertyName
226
+ */
227
+ getPropertyDataFromClass(decoratorNameKey, target, propertyName) {
228
+ const dataKey = DecoratorManager.getDecoratorClsMethodKey(decoratorNameKey, propertyName);
229
+ return DecoratorManager.getMetadata(this.injectClassMethodKeyPrefix, target, dataKey);
230
+ }
231
+ /**
232
+ * list property data from class
233
+ * @param decoratorNameKey
234
+ * @param target
235
+ */
236
+ listPropertyDataFromClass(decoratorNameKey, target) {
237
+ const originMap = DecoratorManager.getMetadata(this.injectClassMethodKeyPrefix, target);
238
+ const res = [];
239
+ for (const [key, value] of originMap) {
240
+ if (key.indexOf(DecoratorManager.getDecoratorClsMethodPrefix(decoratorNameKey)) !== -1) {
241
+ res.push(value);
242
+ }
243
+ }
244
+ return res;
245
+ }
246
+ }
247
+ exports.DecoratorManager = DecoratorManager;
248
+ let manager = new DecoratorManager();
249
+ if (typeof global === 'object') {
250
+ if (global['MIDWAY_GLOBAL_DECORATOR_MANAGER']) {
251
+ console.warn('DecoratorManager not singleton and please check @midwayjs/core version by "npm ls @midwayjs/core"');
252
+ manager = global['MIDWAY_GLOBAL_DECORATOR_MANAGER'];
253
+ }
254
+ else {
255
+ global['MIDWAY_GLOBAL_DECORATOR_MANAGER'] = manager;
256
+ }
257
+ }
258
+ /**
259
+ * save data to class
260
+ * @param decoratorNameKey
261
+ * @param data
262
+ * @param target
263
+ * @param mergeIfExist
264
+ */
265
+ function saveClassMetadata(decoratorNameKey, data, target, mergeIfExist) {
266
+ if (mergeIfExist && typeof data === 'object') {
267
+ const originData = manager.getMetadata(decoratorNameKey, target);
268
+ if (!originData) {
269
+ return manager.saveMetadata(decoratorNameKey, data, target);
270
+ }
271
+ if (Array.isArray(originData)) {
272
+ return manager.saveMetadata(decoratorNameKey, originData.concat(data), target);
273
+ }
274
+ else {
275
+ return manager.saveMetadata(decoratorNameKey, Object.assign(originData, data), target);
276
+ }
277
+ }
278
+ else {
279
+ return manager.saveMetadata(decoratorNameKey, data, target);
280
+ }
281
+ }
282
+ exports.saveClassMetadata = saveClassMetadata;
283
+ /**
284
+ * attach data to class
285
+ * @param decoratorNameKey
286
+ * @param data
287
+ * @param target
288
+ * @param groupBy
289
+ */
290
+ function attachClassMetadata(decoratorNameKey, data, target, groupBy, groupMode) {
291
+ return manager.attachMetadata(decoratorNameKey, data, target, undefined, groupBy, groupMode);
292
+ }
293
+ exports.attachClassMetadata = attachClassMetadata;
294
+ /**
295
+ * get data from class and proto
296
+ * @param decoratorNameKey
297
+ * @param target
298
+ * @param propertyName
299
+ * @param useCache
300
+ */
301
+ function getClassExtendedMetadata(decoratorNameKey, target, propertyName, useCache) {
302
+ if (useCache === undefined) {
303
+ useCache = true;
304
+ }
305
+ const extKey = DecoratorManager.getDecoratorClsExtendedKey(decoratorNameKey);
306
+ let metadata = manager.getMetadata(extKey, target, propertyName);
307
+ if (useCache && metadata !== undefined) {
308
+ return metadata;
309
+ }
310
+ const father = Reflect.getPrototypeOf(target);
311
+ if (father && father.constructor !== Object) {
312
+ metadata = (0, util_1.merge)(getClassExtendedMetadata(decoratorNameKey, father, propertyName, useCache), manager.getMetadata(decoratorNameKey, target, propertyName));
313
+ }
314
+ manager.saveMetadata(extKey, metadata || null, target, propertyName);
315
+ return metadata;
316
+ }
317
+ exports.getClassExtendedMetadata = getClassExtendedMetadata;
318
+ /**
319
+ * get data from class
320
+ * @param decoratorNameKey
321
+ * @param target
322
+ */
323
+ function getClassMetadata(decoratorNameKey, target) {
324
+ return manager.getMetadata(decoratorNameKey, target);
325
+ }
326
+ exports.getClassMetadata = getClassMetadata;
327
+ /**
328
+ * save property data to class
329
+ * @param decoratorNameKey
330
+ * @param data
331
+ * @param target
332
+ * @param propertyName
333
+ */
334
+ function savePropertyDataToClass(decoratorNameKey, data, target, propertyName) {
335
+ return manager.savePropertyDataToClass(decoratorNameKey, data, target, propertyName);
336
+ }
337
+ exports.savePropertyDataToClass = savePropertyDataToClass;
338
+ /**
339
+ * attach property data to class
340
+ * @param decoratorNameKey
341
+ * @param data
342
+ * @param target
343
+ * @param propertyName
344
+ * @param groupBy
345
+ */
346
+ function attachPropertyDataToClass(decoratorNameKey, data, target, propertyName, groupBy) {
347
+ return manager.attachPropertyDataToClass(decoratorNameKey, data, target, propertyName, groupBy);
348
+ }
349
+ exports.attachPropertyDataToClass = attachPropertyDataToClass;
350
+ /**
351
+ * get property data from class
352
+ * @param decoratorNameKey
353
+ * @param target
354
+ * @param propertyName
355
+ */
356
+ function getPropertyDataFromClass(decoratorNameKey, target, propertyName) {
357
+ return manager.getPropertyDataFromClass(decoratorNameKey, target, propertyName);
358
+ }
359
+ exports.getPropertyDataFromClass = getPropertyDataFromClass;
360
+ /**
361
+ * list property data from class
362
+ * @param decoratorNameKey
363
+ * @param target
364
+ */
365
+ function listPropertyDataFromClass(decoratorNameKey, target) {
366
+ return manager.listPropertyDataFromClass(decoratorNameKey, target);
367
+ }
368
+ exports.listPropertyDataFromClass = listPropertyDataFromClass;
369
+ /**
370
+ * save property data
371
+ * @param decoratorNameKey
372
+ * @param data
373
+ * @param target
374
+ * @param propertyName
375
+ */
376
+ function savePropertyMetadata(decoratorNameKey, data, target, propertyName) {
377
+ return manager.saveMetadata(decoratorNameKey, data, target, propertyName);
378
+ }
379
+ exports.savePropertyMetadata = savePropertyMetadata;
380
+ /**
381
+ * attach property data
382
+ * @param decoratorNameKey
383
+ * @param data
384
+ * @param target
385
+ * @param propertyName
386
+ */
387
+ function attachPropertyMetadata(decoratorNameKey, data, target, propertyName) {
388
+ return manager.attachMetadata(decoratorNameKey, data, target, propertyName);
389
+ }
390
+ exports.attachPropertyMetadata = attachPropertyMetadata;
391
+ /**
392
+ * get property data
393
+ * @param decoratorNameKey
394
+ * @param target
395
+ * @param propertyName
396
+ */
397
+ function getPropertyMetadata(decoratorNameKey, target, propertyName) {
398
+ return manager.getMetadata(decoratorNameKey, target, propertyName);
399
+ }
400
+ exports.getPropertyMetadata = getPropertyMetadata;
401
+ /**
402
+ * save preload module by target
403
+ * @param target
404
+ */
405
+ function savePreloadModule(target) {
406
+ return saveModule(exports.PRELOAD_MODULE_KEY, target);
407
+ }
408
+ exports.savePreloadModule = savePreloadModule;
409
+ /**
410
+ * list preload module
411
+ */
412
+ function listPreloadModule() {
413
+ return listModule(exports.PRELOAD_MODULE_KEY);
414
+ }
415
+ exports.listPreloadModule = listPreloadModule;
416
+ /**
417
+ * save module to inner map
418
+ * @param decoratorNameKey
419
+ * @param target
420
+ */
421
+ function saveModule(decoratorNameKey, target) {
422
+ if ((0, types_1.isClass)(target)) {
423
+ saveProviderId(undefined, target);
424
+ }
425
+ return manager.saveModule(decoratorNameKey, target);
426
+ }
427
+ exports.saveModule = saveModule;
428
+ function bindContainer(container) {
429
+ return manager.bindContainer(container);
430
+ }
431
+ exports.bindContainer = bindContainer;
432
+ function clearBindContainer() {
433
+ return (manager.container = null);
434
+ }
435
+ exports.clearBindContainer = clearBindContainer;
436
+ /**
437
+ * list module from decorator key
438
+ * @param decoratorNameKey
439
+ * @param filter
440
+ */
441
+ function listModule(decoratorNameKey, filter) {
442
+ const modules = manager.listModule(decoratorNameKey);
443
+ if (filter) {
444
+ return modules.filter(filter);
445
+ }
446
+ else {
447
+ return modules;
448
+ }
449
+ }
450
+ exports.listModule = listModule;
451
+ /**
452
+ * reset module
453
+ * @param decoratorNameKey
454
+ */
455
+ function resetModule(decoratorNameKey) {
456
+ return manager.resetModule(decoratorNameKey);
457
+ }
458
+ exports.resetModule = resetModule;
459
+ /**
460
+ * clear all module
461
+ */
462
+ function clearAllModule() {
463
+ debug('--- clear all module here ---');
464
+ return manager.clear();
465
+ }
466
+ exports.clearAllModule = clearAllModule;
467
+ function transformTypeFromTSDesign(designFn) {
468
+ if ((0, types_1.isNullOrUndefined)(designFn)) {
469
+ return { name: 'undefined', isBaseType: true, originDesign: designFn };
470
+ }
471
+ switch (designFn.name) {
472
+ case 'String':
473
+ return { name: 'string', isBaseType: true, originDesign: designFn };
474
+ case 'Number':
475
+ return { name: 'number', isBaseType: true, originDesign: designFn };
476
+ case 'Boolean':
477
+ return { name: 'boolean', isBaseType: true, originDesign: designFn };
478
+ case 'Symbol':
479
+ return { name: 'symbol', isBaseType: true, originDesign: designFn };
480
+ case 'Object':
481
+ return { name: 'object', isBaseType: true, originDesign: designFn };
482
+ case 'Function':
483
+ return { name: 'function', isBaseType: true, originDesign: designFn };
484
+ default:
485
+ return {
486
+ name: designFn.name,
487
+ isBaseType: false,
488
+ originDesign: designFn,
489
+ };
490
+ }
491
+ }
492
+ /**
493
+ * save property inject args
494
+ * @param opts 参数
495
+ */
496
+ function savePropertyInject(opts) {
497
+ // 1、use identifier by user
498
+ let identifier = opts.identifier;
499
+ let injectMode = interface_1.InjectModeEnum.Identifier;
500
+ // 2、use identifier by class uuid
501
+ if (!identifier) {
502
+ const type = getPropertyType(opts.target, opts.targetKey);
503
+ if (!type.isBaseType &&
504
+ (0, types_1.isClass)(type.originDesign) &&
505
+ isProvide(type.originDesign)) {
506
+ identifier = getProviderUUId(type.originDesign);
507
+ injectMode = interface_1.InjectModeEnum.Class;
508
+ }
509
+ if (!identifier) {
510
+ // 3、use identifier by property name
511
+ identifier = opts.targetKey;
512
+ injectMode = interface_1.InjectModeEnum.PropertyName;
513
+ }
514
+ }
515
+ attachClassMetadata(constant_1.INJECT_TAG, {
516
+ targetKey: opts.targetKey,
517
+ value: identifier,
518
+ args: opts.args,
519
+ injectMode,
520
+ }, opts.target, opts.targetKey);
521
+ }
522
+ exports.savePropertyInject = savePropertyInject;
523
+ /**
524
+ * get property inject args
525
+ * @param target
526
+ * @param useCache
527
+ */
528
+ function getPropertyInject(target, useCache) {
529
+ return getClassExtendedMetadata(constant_1.INJECT_TAG, target, undefined, useCache);
530
+ }
531
+ exports.getPropertyInject = getPropertyInject;
532
+ /**
533
+ * save class object definition
534
+ * @param target class
535
+ * @param props property data
536
+ */
537
+ function saveObjectDefinition(target, props = {}) {
538
+ saveClassMetadata(constant_1.OBJ_DEF_CLS, props, target, true);
539
+ return target;
540
+ }
541
+ exports.saveObjectDefinition = saveObjectDefinition;
542
+ /**
543
+ * get class object definition from metadata
544
+ * @param target
545
+ */
546
+ function getObjectDefinition(target) {
547
+ return getClassExtendedMetadata(constant_1.OBJ_DEF_CLS, target);
548
+ }
549
+ exports.getObjectDefinition = getObjectDefinition;
550
+ /**
551
+ * class provider id
552
+ * @param identifier id
553
+ * @param target class
554
+ */
555
+ function saveProviderId(identifier, target) {
556
+ if (isProvide(target)) {
557
+ if (identifier) {
558
+ const meta = getClassMetadata(constant_1.TAGGED_CLS, target);
559
+ if (meta.id !== identifier) {
560
+ meta.id = identifier;
561
+ // save class id and uuid
562
+ saveClassMetadata(constant_1.TAGGED_CLS, meta, target);
563
+ debug(`update provide: ${target.name} -> ${meta.uuid}`);
564
+ }
565
+ }
566
+ }
567
+ else {
568
+ // save
569
+ const uuid = (0, util_1.generateRandomId)();
570
+ // save class id and uuid
571
+ saveClassMetadata(constant_1.TAGGED_CLS, {
572
+ id: identifier,
573
+ originName: target.name,
574
+ uuid,
575
+ name: (0, camelCase_1.camelCase)(target.name),
576
+ }, target);
577
+ debug(`save provide: ${target.name} -> ${uuid}`);
578
+ }
579
+ return target;
580
+ }
581
+ exports.saveProviderId = saveProviderId;
582
+ /**
583
+ * get provider id from module
584
+ * @param module
585
+ */
586
+ function getProviderId(module) {
587
+ const metaData = getClassMetadata(constant_1.TAGGED_CLS, module);
588
+ if (metaData && metaData.id) {
589
+ return metaData.id;
590
+ }
591
+ }
592
+ exports.getProviderId = getProviderId;
593
+ function getProviderName(module) {
594
+ const metaData = getClassMetadata(constant_1.TAGGED_CLS, module);
595
+ if (metaData && metaData.name) {
596
+ return metaData.name;
597
+ }
598
+ }
599
+ exports.getProviderName = getProviderName;
600
+ /**
601
+ * get provider uuid from module
602
+ * @param module
603
+ */
604
+ function getProviderUUId(module) {
605
+ const metaData = getClassMetadata(constant_1.TAGGED_CLS, module);
606
+ if (metaData && metaData.uuid) {
607
+ return metaData.uuid;
608
+ }
609
+ }
610
+ exports.getProviderUUId = getProviderUUId;
611
+ /**
612
+ * use @Provide decorator or not
613
+ * @param target class
614
+ */
615
+ function isProvide(target) {
616
+ return !!getClassMetadata(constant_1.TAGGED_CLS, target);
617
+ }
618
+ exports.isProvide = isProvide;
619
+ var BaseType;
620
+ (function (BaseType) {
621
+ BaseType["Boolean"] = "boolean";
622
+ BaseType["Number"] = "number";
623
+ BaseType["String"] = "string";
624
+ })(BaseType = exports.BaseType || (exports.BaseType = {}));
625
+ /**
626
+ * get parameters type by reflect-metadata
627
+ */
628
+ function getMethodParamTypes(target, methodName) {
629
+ if ((0, types_1.isClass)(target)) {
630
+ target = target.prototype;
631
+ }
632
+ return Reflect.getMetadata('design:paramtypes', target, methodName);
633
+ }
634
+ exports.getMethodParamTypes = getMethodParamTypes;
635
+ /**
636
+ * get property(method) type from metadata
637
+ * @param target
638
+ * @param methodName
639
+ */
640
+ function getPropertyType(target, methodName) {
641
+ return transformTypeFromTSDesign(Reflect.getMetadata('design:type', target, methodName));
642
+ }
643
+ exports.getPropertyType = getPropertyType;
644
+ /**
645
+ * get method return type from metadata
646
+ * @param target
647
+ * @param methodName
648
+ */
649
+ function getMethodReturnTypes(target, methodName) {
650
+ if ((0, types_1.isClass)(target)) {
651
+ target = target.prototype;
652
+ }
653
+ return Reflect.getMetadata('design:returntype', target, methodName);
654
+ }
655
+ exports.getMethodReturnTypes = getMethodReturnTypes;
656
+ /**
657
+ * create a custom property inject
658
+ * @param decoratorKey
659
+ * @param metadata
660
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
661
+ */
662
+ function createCustomPropertyDecorator(decoratorKey, metadata, impl = true) {
663
+ return function (target, propertyName) {
664
+ attachClassMetadata(constant_1.INJECT_CUSTOM_PROPERTY, {
665
+ propertyName,
666
+ key: decoratorKey,
667
+ metadata,
668
+ impl,
669
+ }, target, propertyName);
670
+ };
671
+ }
672
+ exports.createCustomPropertyDecorator = createCustomPropertyDecorator;
673
+ /**
674
+ *
675
+ * @param decoratorKey
676
+ * @param metadata
677
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
678
+ */
679
+ function createCustomMethodDecorator(decoratorKey, metadata, impl = true) {
680
+ return function (target, propertyName, descriptor) {
681
+ attachClassMetadata(constant_1.INJECT_CUSTOM_METHOD, {
682
+ propertyName,
683
+ key: decoratorKey,
684
+ metadata,
685
+ impl,
686
+ }, target);
687
+ };
688
+ }
689
+ exports.createCustomMethodDecorator = createCustomMethodDecorator;
690
+ /**
691
+ *
692
+ * @param decoratorKey
693
+ * @param metadata
694
+ * @param impl default true, configuration need decoratorService.registerMethodHandler
695
+ */
696
+ function createCustomParamDecorator(decoratorKey, metadata, impl = true) {
697
+ return function (target, propertyName, parameterIndex) {
698
+ // const parameterName = getParamNames(target[methodName])[parameterIndex];
699
+ attachClassMetadata(constant_1.INJECT_CUSTOM_PARAM, {
700
+ key: decoratorKey,
701
+ parameterIndex,
702
+ propertyName,
703
+ metadata,
704
+ impl,
705
+ }, target, propertyName, 'multi');
706
+ };
707
+ }
708
+ exports.createCustomParamDecorator = createCustomParamDecorator;
709
+ //# sourceMappingURL=decoratorManager.js.map