From 2c717154fc453ec46c0a249946cd21033c5ddb4a Mon Sep 17 00:00:00 2001 From: popomore Date: Tue, 19 Sep 2023 17:02:59 +0800 Subject: [PATCH 1/3] feat: add className property to EggPrototypeInfo --- core/core-decorator/src/decorator/Prototype.ts | 1 + core/core-decorator/src/model/EggPrototypeInfo.ts | 4 ++++ core/core-decorator/test/decorators.test.ts | 2 ++ 3 files changed, 7 insertions(+) diff --git a/core/core-decorator/src/decorator/Prototype.ts b/core/core-decorator/src/decorator/Prototype.ts index 7da72323..54c52d0d 100644 --- a/core/core-decorator/src/decorator/Prototype.ts +++ b/core/core-decorator/src/decorator/Prototype.ts @@ -26,6 +26,7 @@ export function Prototype(param?: PrototypeParams) { const property: Partial = { ...DEFAULT_PARAMS, ...param, + className: clazz.name, }; if (!property.name) { property.name = NameUtil.getClassName(clazz); diff --git a/core/core-decorator/src/model/EggPrototypeInfo.ts b/core/core-decorator/src/model/EggPrototypeInfo.ts index b5b5f806..53779c3e 100644 --- a/core/core-decorator/src/model/EggPrototypeInfo.ts +++ b/core/core-decorator/src/model/EggPrototypeInfo.ts @@ -26,4 +26,8 @@ export interface EggPrototypeInfo { * EggPrototype qualifiers */ qualifiers?: QualifierInfo[]; + /** + * The class name of the object + */ + className?: string; } diff --git a/core/core-decorator/test/decorators.test.ts b/core/core-decorator/test/decorators.test.ts index 1e905564..51f08625 100644 --- a/core/core-decorator/test/decorators.test.ts +++ b/core/core-decorator/test/decorators.test.ts @@ -28,6 +28,7 @@ describe('test/decorator.test.ts', () => { initType: ObjectInitType.CONTEXT, accessLevel: AccessLevel.PUBLIC, protoImplType: DEFAULT_PROTO_IMPL_TYPE, + className: 'ContextCache', }; assert.deepStrictEqual(PrototypeUtil.getProperty(ContextCache), expectObjectProperty); }); @@ -41,6 +42,7 @@ describe('test/decorator.test.ts', () => { initType: ObjectInitType.SINGLETON, accessLevel: AccessLevel.PUBLIC, protoImplType: DEFAULT_PROTO_IMPL_TYPE, + className: 'SingletonCache', }; assert.deepStrictEqual(PrototypeUtil.getProperty(SingletonCache), expectObjectProperty); }); From 9bd8979c165c1d3f3f4ee6d2d1356beeeda6bf4c Mon Sep 17 00:00:00 2001 From: popomore Date: Tue, 19 Sep 2023 17:45:37 +0800 Subject: [PATCH 2/3] f --- core/core-decorator/src/decorator/MultiInstanceProto.ts | 3 ++- .../src/model/EggMultiInstancePrototypeInfo.ts | 8 ++++++++ core/core-decorator/src/model/EggPrototypeInfo.ts | 8 ++++---- core/metadata/src/factory/EggPrototypeCreatorFactory.ts | 1 + core/metadata/src/impl/EggPrototypeBuilder.ts | 3 +++ core/metadata/src/impl/EggPrototypeImpl.ts | 3 +++ core/metadata/src/model/EggPrototype.ts | 1 + core/metadata/test/LoadUnit.test.ts | 8 +++++--- 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/core/core-decorator/src/decorator/MultiInstanceProto.ts b/core/core-decorator/src/decorator/MultiInstanceProto.ts index ec76110a..fc638af0 100644 --- a/core/core-decorator/src/decorator/MultiInstanceProto.ts +++ b/core/core-decorator/src/decorator/MultiInstanceProto.ts @@ -52,17 +52,18 @@ export function MultiInstanceProto(param: MultiInstancePrototypeParams) { const property: EggMultiInstancePrototypeInfo = { ...DEFAULT_PARAMS, ...param as MultiInstancePrototypeStaticParams, + className: clazz.name, }; PrototypeUtil.setMultiInstanceStaticProperty(clazz, property); } else if ((param as MultiInstancePrototypeCallbackParams).getObjects) { const property: EggMultiInstanceCallbackPrototypeInfo = { ...DEFAULT_PARAMS, ...param as MultiInstancePrototypeCallbackParams, + className: clazz.name, }; PrototypeUtil.setMultiInstanceCallbackProperty(clazz, property); } - // './tegg/core/common-util/src/StackUtil.ts', // './tegg/core/core-decorator/src/decorator/Prototype.ts', // './tegg/core/core-decorator/node_modules/_reflect-metadata@0.1.13@reflect-metadata/Reflect.js', diff --git a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts index b3a1ea96..89e90a12 100644 --- a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts +++ b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts @@ -13,6 +13,10 @@ export interface MultiInstancePrototypeGetObjectsContext { } export interface EggMultiInstancePrototypeInfo { + /** + * The class name of the object + */ + className: string; /** * obj init type */ @@ -33,6 +37,10 @@ export interface EggMultiInstancePrototypeInfo { } export interface EggMultiInstanceCallbackPrototypeInfo { + /** + * The class name of the object + */ + className: string; /** * obj init type */ diff --git a/core/core-decorator/src/model/EggPrototypeInfo.ts b/core/core-decorator/src/model/EggPrototypeInfo.ts index 53779c3e..52762e18 100644 --- a/core/core-decorator/src/model/EggPrototypeInfo.ts +++ b/core/core-decorator/src/model/EggPrototypeInfo.ts @@ -10,6 +10,10 @@ export interface EggPrototypeInfo { * egg object name */ name: EggPrototypeName; + /** + * The class name of the object + */ + className: string; /** * obj init type */ @@ -26,8 +30,4 @@ export interface EggPrototypeInfo { * EggPrototype qualifiers */ qualifiers?: QualifierInfo[]; - /** - * The class name of the object - */ - className?: string; } diff --git a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts index aa8760d1..a3efb42f 100644 --- a/core/metadata/src/factory/EggPrototypeCreatorFactory.ts +++ b/core/metadata/src/factory/EggPrototypeCreatorFactory.ts @@ -28,6 +28,7 @@ export class EggPrototypeCreatorFactory { initType: multiInstanceProtoInfo.initType, accessLevel: multiInstanceProtoInfo.accessLevel, qualifiers: obj.qualifiers, + className: multiInstanceProtoInfo.className, }); } } else { diff --git a/core/metadata/src/impl/EggPrototypeBuilder.ts b/core/metadata/src/impl/EggPrototypeBuilder.ts index 48e6a153..a4c64605 100644 --- a/core/metadata/src/impl/EggPrototypeBuilder.ts +++ b/core/metadata/src/impl/EggPrototypeBuilder.ts @@ -40,6 +40,7 @@ export class EggPrototypeBuilder { private injectObjects: Array = []; private loadUnit: LoadUnit; private qualifiers: QualifierInfo[] = []; + private className: string; static create(ctx: EggPrototypeLifecycleContext): EggPrototype { const { clazz, loadUnit } = ctx; @@ -48,6 +49,7 @@ export class EggPrototypeBuilder { const builder = new EggPrototypeBuilder(); builder.clazz = clazz; builder.name = ctx.prototypeInfo.name; + builder.className = ctx.prototypeInfo.className; builder.initType = ctx.prototypeInfo.initType; builder.accessLevel = ctx.prototypeInfo.accessLevel; builder.filepath = filepath!; @@ -131,6 +133,7 @@ export class EggPrototypeBuilder { injectObjectProtos, this.loadUnit.id, this.qualifiers, + this.className, ); } } diff --git a/core/metadata/src/impl/EggPrototypeImpl.ts b/core/metadata/src/impl/EggPrototypeImpl.ts index 6d0d8fe5..e14ef9d0 100644 --- a/core/metadata/src/impl/EggPrototypeImpl.ts +++ b/core/metadata/src/impl/EggPrototypeImpl.ts @@ -20,6 +20,7 @@ export class EggPrototypeImpl implements EggPrototype { readonly accessLevel: AccessLevel; readonly injectObjects: InjectObjectProto[]; readonly loadUnitId: Id; + readonly className: string; constructor( id: string, @@ -31,6 +32,7 @@ export class EggPrototypeImpl implements EggPrototype { injectObjectMap: InjectObjectProto[], loadUnitId: Id, qualifiers: QualifierInfo[], + className: string, ) { this.id = id; this.clazz = clazz; @@ -41,6 +43,7 @@ export class EggPrototypeImpl implements EggPrototype { this.injectObjects = injectObjectMap; this.loadUnitId = loadUnitId; this.qualifiers = qualifiers; + this.className = className; } verifyQualifiers(qualifiers: QualifierInfo[]): boolean { diff --git a/core/metadata/src/model/EggPrototype.ts b/core/metadata/src/model/EggPrototype.ts index 790f2aed..73d8c817 100644 --- a/core/metadata/src/model/EggPrototype.ts +++ b/core/metadata/src/model/EggPrototype.ts @@ -45,6 +45,7 @@ export interface EggPrototype extends LifecycleObject { const appRepoProto = loadUnit.getEggPrototype('appRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); const sprintRepoProto = loadUnit.getEggPrototype('sprintRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); const userRepoProto = loadUnit.getEggPrototype('userRepo', [{ attribute: InitTypeQualifierAttribute, value: ObjectInitType.SINGLETON }]); - assert(appRepoProto); - assert(sprintRepoProto); - assert(userRepoProto); + assert.strictEqual(appRepoProto.length, 1); + assert.strictEqual(appRepoProto[0].className, 'AppRepo'); + assert.strictEqual(sprintRepoProto.length, 1); + assert.strictEqual(userRepoProto.length, 1); await LoadUnitFactory.destroyLoadUnit(loadUnit); }); @@ -92,6 +93,7 @@ describe('test/LoadUnit/LoadUnit.test.ts', () => { const foo2Prototype = loadUnit.getEggPrototype('foo', [{ attribute: FOO_ATTRIBUTE, value: 'foo2' }]); assert(foo1Prototype); assert(foo1Prototype.length === 1); + assert.strictEqual(foo1Prototype[0].className, 'FooLogger'); assert(foo2Prototype); assert(foo2Prototype.length === 1); await LoadUnitFactory.destroyLoadUnit(loadUnit); From 21c7fd2f2c61ef0cfbe72a0470f5dbfa13b87288 Mon Sep 17 00:00:00 2001 From: popomore Date: Tue, 19 Sep 2023 19:43:03 +0800 Subject: [PATCH 3/3] f --- .../src/model/EggMultiInstancePrototypeInfo.ts | 4 ++-- core/core-decorator/src/model/EggPrototypeInfo.ts | 2 +- core/metadata/src/impl/EggPrototypeBuilder.ts | 2 +- core/metadata/src/impl/EggPrototypeImpl.ts | 4 ++-- core/metadata/src/model/EggPrototype.ts | 2 +- standalone/standalone/src/StandaloneInnerObjectProto.ts | 6 +++++- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts index 89e90a12..f329e3d0 100644 --- a/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts +++ b/core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts @@ -16,7 +16,7 @@ export interface EggMultiInstancePrototypeInfo { /** * The class name of the object */ - className: string; + className?: string; /** * obj init type */ @@ -40,7 +40,7 @@ export interface EggMultiInstanceCallbackPrototypeInfo { /** * The class name of the object */ - className: string; + className?: string; /** * obj init type */ diff --git a/core/core-decorator/src/model/EggPrototypeInfo.ts b/core/core-decorator/src/model/EggPrototypeInfo.ts index 52762e18..f612897f 100644 --- a/core/core-decorator/src/model/EggPrototypeInfo.ts +++ b/core/core-decorator/src/model/EggPrototypeInfo.ts @@ -13,7 +13,7 @@ export interface EggPrototypeInfo { /** * The class name of the object */ - className: string; + className?: string; /** * obj init type */ diff --git a/core/metadata/src/impl/EggPrototypeBuilder.ts b/core/metadata/src/impl/EggPrototypeBuilder.ts index a4c64605..d10798bd 100644 --- a/core/metadata/src/impl/EggPrototypeBuilder.ts +++ b/core/metadata/src/impl/EggPrototypeBuilder.ts @@ -40,7 +40,7 @@ export class EggPrototypeBuilder { private injectObjects: Array = []; private loadUnit: LoadUnit; private qualifiers: QualifierInfo[] = []; - private className: string; + private className?: string; static create(ctx: EggPrototypeLifecycleContext): EggPrototype { const { clazz, loadUnit } = ctx; diff --git a/core/metadata/src/impl/EggPrototypeImpl.ts b/core/metadata/src/impl/EggPrototypeImpl.ts index e14ef9d0..5548c045 100644 --- a/core/metadata/src/impl/EggPrototypeImpl.ts +++ b/core/metadata/src/impl/EggPrototypeImpl.ts @@ -20,7 +20,7 @@ export class EggPrototypeImpl implements EggPrototype { readonly accessLevel: AccessLevel; readonly injectObjects: InjectObjectProto[]; readonly loadUnitId: Id; - readonly className: string; + readonly className?: string; constructor( id: string, @@ -32,7 +32,7 @@ export class EggPrototypeImpl implements EggPrototype { injectObjectMap: InjectObjectProto[], loadUnitId: Id, qualifiers: QualifierInfo[], - className: string, + className?: string, ) { this.id = id; this.clazz = clazz; diff --git a/core/metadata/src/model/EggPrototype.ts b/core/metadata/src/model/EggPrototype.ts index 73d8c817..83a38ec0 100644 --- a/core/metadata/src/model/EggPrototype.ts +++ b/core/metadata/src/model/EggPrototype.ts @@ -45,7 +45,7 @@ export interface EggPrototype extends LifecycleObject