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