Skip to content

Commit bddac97

Browse files
authored
feat: add className property to EggPrototypeInfo (#158)
1 parent a775d34 commit bddac97

11 files changed

Lines changed: 66 additions & 4 deletions

File tree

core/core-decorator/src/decorator/MultiInstanceProto.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,18 @@ export function MultiInstanceProto(param: MultiInstancePrototypeParams) {
5252
const property: EggMultiInstancePrototypeInfo = {
5353
...DEFAULT_PARAMS,
5454
...param as MultiInstancePrototypeStaticParams,
55+
className: clazz.name,
5556
};
5657
PrototypeUtil.setMultiInstanceStaticProperty(clazz, property);
5758
} else if ((param as MultiInstancePrototypeCallbackParams).getObjects) {
5859
const property: EggMultiInstanceCallbackPrototypeInfo = {
5960
...DEFAULT_PARAMS,
6061
...param as MultiInstancePrototypeCallbackParams,
62+
className: clazz.name,
6163
};
6264
PrototypeUtil.setMultiInstanceCallbackProperty(clazz, property);
6365
}
6466

65-
6667
// './tegg/core/common-util/src/StackUtil.ts',
6768
// './tegg/core/core-decorator/src/decorator/Prototype.ts',
6869
// './tegg/core/core-decorator/node_modules/[email protected]@reflect-metadata/Reflect.js',

core/core-decorator/src/decorator/Prototype.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export function Prototype(param?: PrototypeParams) {
2626
const property: Partial<EggPrototypeInfo> = {
2727
...DEFAULT_PARAMS,
2828
...param,
29+
className: clazz.name,
2930
};
3031
if (!property.name) {
3132
property.name = NameUtil.getClassName(clazz);

core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export interface MultiInstancePrototypeGetObjectsContext {
1313
}
1414

1515
export interface EggMultiInstancePrototypeInfo {
16+
/**
17+
* The class name of the object
18+
*/
19+
className?: string;
1620
/**
1721
* obj init type
1822
*/
@@ -33,6 +37,10 @@ export interface EggMultiInstancePrototypeInfo {
3337
}
3438

3539
export interface EggMultiInstanceCallbackPrototypeInfo {
40+
/**
41+
* The class name of the object
42+
*/
43+
className?: string;
3644
/**
3745
* obj init type
3846
*/

core/core-decorator/src/model/EggPrototypeInfo.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ export interface EggPrototypeInfo {
1010
* egg object name
1111
*/
1212
name: EggPrototypeName;
13+
/**
14+
* The class name of the object
15+
*/
16+
className?: string;
1317
/**
1418
* obj init type
1519
*/

core/core-decorator/test/decorators.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('test/decorator.test.ts', () => {
2828
initType: ObjectInitType.CONTEXT,
2929
accessLevel: AccessLevel.PUBLIC,
3030
protoImplType: DEFAULT_PROTO_IMPL_TYPE,
31+
className: 'ContextCache',
3132
};
3233
assert.deepStrictEqual(PrototypeUtil.getProperty(ContextCache), expectObjectProperty);
3334
});
@@ -41,6 +42,7 @@ describe('test/decorator.test.ts', () => {
4142
initType: ObjectInitType.SINGLETON,
4243
accessLevel: AccessLevel.PUBLIC,
4344
protoImplType: DEFAULT_PROTO_IMPL_TYPE,
45+
className: 'SingletonCache',
4446
};
4547
assert.deepStrictEqual(PrototypeUtil.getProperty(SingletonCache), expectObjectProperty);
4648
});
@@ -112,6 +114,7 @@ describe('test/decorator.test.ts', () => {
112114
value: 'foo2',
113115
}],
114116
}],
117+
className: 'FooLogger',
115118
};
116119
assert.deepStrictEqual(PrototypeUtil.getMultiInstanceProperty(FooLogger, {
117120
unitPath: 'foo',

core/metadata/src/factory/EggPrototypeCreatorFactory.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class EggPrototypeCreatorFactory {
2828
initType: multiInstanceProtoInfo.initType,
2929
accessLevel: multiInstanceProtoInfo.accessLevel,
3030
qualifiers: obj.qualifiers,
31+
className: multiInstanceProtoInfo.className,
3132
});
3233
}
3334
} else {

core/metadata/src/impl/EggPrototypeBuilder.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export class EggPrototypeBuilder {
4040
private injectObjects: Array<InjectObject> = [];
4141
private loadUnit: LoadUnit;
4242
private qualifiers: QualifierInfo[] = [];
43+
private className?: string;
4344

4445
static create(ctx: EggPrototypeLifecycleContext): EggPrototype {
4546
const { clazz, loadUnit } = ctx;
@@ -48,6 +49,7 @@ export class EggPrototypeBuilder {
4849
const builder = new EggPrototypeBuilder();
4950
builder.clazz = clazz;
5051
builder.name = ctx.prototypeInfo.name;
52+
builder.className = ctx.prototypeInfo.className;
5153
builder.initType = ctx.prototypeInfo.initType;
5254
builder.accessLevel = ctx.prototypeInfo.accessLevel;
5355
builder.filepath = filepath!;
@@ -131,6 +133,7 @@ export class EggPrototypeBuilder {
131133
injectObjectProtos,
132134
this.loadUnit.id,
133135
this.qualifiers,
136+
this.className,
134137
);
135138
}
136139
}

core/metadata/src/impl/EggPrototypeImpl.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class EggPrototypeImpl implements EggPrototype {
2020
readonly accessLevel: AccessLevel;
2121
readonly injectObjects: InjectObjectProto[];
2222
readonly loadUnitId: Id;
23+
readonly className?: string;
2324

2425
constructor(
2526
id: string,
@@ -31,6 +32,7 @@ export class EggPrototypeImpl implements EggPrototype {
3132
injectObjectMap: InjectObjectProto[],
3233
loadUnitId: Id,
3334
qualifiers: QualifierInfo[],
35+
className?: string,
3436
) {
3537
this.id = id;
3638
this.clazz = clazz;
@@ -41,6 +43,7 @@ export class EggPrototypeImpl implements EggPrototype {
4143
this.injectObjects = injectObjectMap;
4244
this.loadUnitId = loadUnitId;
4345
this.qualifiers = qualifiers;
46+
this.className = className;
4447
}
4548

4649
verifyQualifiers(qualifiers: QualifierInfo[]): boolean {

core/metadata/src/model/EggPrototype.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface EggPrototype extends LifecycleObject<EggPrototypeLifecycleConte
4545
readonly accessLevel: AccessLevel;
4646
readonly loadUnitId: string;
4747
readonly injectObjects: InjectObjectProto[];
48+
readonly className?: string;
4849

4950
/**
5051
* get metedata for key

core/metadata/test/LoadUnit.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ describe('test/LoadUnit/LoadUnit.test.ts', () => {
1717
const appRepoProto = loadUnit.getEggPrototype('appRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]);
1818
const sprintRepoProto = loadUnit.getEggPrototype('sprintRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]);
1919
const userRepoProto = loadUnit.getEggPrototype('userRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]);
20-
assert(appRepoProto);
21-
assert(sprintRepoProto);
22-
assert(userRepoProto);
20+
assert.strictEqual(appRepoProto.length, 1);
21+
assert.strictEqual(appRepoProto[0].className, 'AppRepo');
22+
assert.strictEqual(sprintRepoProto.length, 1);
23+
assert.strictEqual(userRepoProto.length, 1);
2324
await LoadUnitFactory.destroyLoadUnit(loadUnit);
2425
});
2526

@@ -92,6 +93,7 @@ describe('test/LoadUnit/LoadUnit.test.ts', () => {
9293
const foo2Prototype = loadUnit.getEggPrototype('foo', [{ attribute: FOO_ATTRIBUTE, value: 'foo2' }]);
9394
assert(foo1Prototype);
9495
assert(foo1Prototype.length === 1);
96+
assert.strictEqual(foo1Prototype[0].className, 'FooLogger');
9597
assert(foo2Prototype);
9698
assert(foo2Prototype.length === 1);
9799
await LoadUnitFactory.destroyLoadUnit(loadUnit);

0 commit comments

Comments
 (0)