MCPcopy
hub / github.com/midwayjs/midway / saveInjectMetadata

Function saveInjectMetadata

packages/core/src/decorator/common/inject.ts:30–110  ·  view source on GitHub ↗
(
  identifier,
  target,
  targetKey,
  isLazyInject = false,
  parameterIndex?: number
)

Source from the content-addressed store, hash-verified

28}
29
30export function saveInjectMetadata(
31 identifier,
32 target,
33 targetKey,
34 isLazyInject = false,
35 parameterIndex?: number
36) {
37 // 1、use identifier by user
38 // let identifier = opts.identifier;
39 let injectMode = InjectModeEnum.Identifier;
40 let id = identifier;
41 const isConstructor = parameterIndex !== undefined;
42 // 2、use identifier by class uuid
43 if (isConstructor) {
44 const paramNames = getConstructParamNames(target);
45
46 if (!id) {
47 const argsTypes = MetadataManager.getMethodParamTypes(target, targetKey);
48 const type = MetadataManager.transformTypeFromTSDesign(
49 argsTypes[parameterIndex]
50 );
51 if (
52 !type.isBaseType &&
53 isClass(type.originDesign) &&
54 DecoratorManager.isProvide(type.originDesign)
55 ) {
56 id = DecoratorManager.getProviderUUId(type.originDesign as ClassType);
57 injectMode = InjectModeEnum.Class;
58 }
59 if (!id) {
60 // 3、use identifier by property name
61 id = paramNames[parameterIndex];
62 injectMode = InjectModeEnum.SelfName;
63 }
64 }
65 MetadataManager.attachMetadata(
66 CONSTRUCTOR_INJECT_KEY,
67 {
68 targetKey,
69 id,
70 name: paramNames[parameterIndex],
71 injectMode,
72 isLazyInject,
73 parameterIndex,
74 },
75 target,
76 'default'
77 );
78 } else {
79 if (!id) {
80 const type = MetadataManager.transformTypeFromTSDesign(
81 MetadataManager.getPropertyType(target, targetKey)
82 );
83 if (
84 !type.isBaseType &&
85 isClass(type.originDesign) &&
86 DecoratorManager.isProvide(type.originDesign)
87 ) {

Callers 3

savePropertyInjectFunction · 0.90
InjectFunction · 0.85
LazyInjectFunction · 0.85

Calls 9

isClassFunction · 0.90
getConstructParamNamesFunction · 0.85
getMethodParamTypesMethod · 0.80
isProvideMethod · 0.80
getProviderUUIdMethod · 0.80
attachMetadataMethod · 0.80
getPropertyTypeMethod · 0.80
defineMetadataMethod · 0.80

Tested by

no test coverage detected