Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add className property to EggPrototypeInfo #157

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/core-decorator/src/decorator/MultiInstanceProto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions core/core-decorator/src/decorator/Prototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export function Prototype(param?: PrototypeParams) {
const property: Partial<EggPrototypeInfo> = {
...DEFAULT_PARAMS,
...param,
className: clazz.name,
};
if (!property.name) {
property.name = NameUtil.getClassName(clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface MultiInstancePrototypeGetObjectsContext {
}

export interface EggMultiInstancePrototypeInfo {
/**
* The class name of the object
*/
className?: string;
/**
* obj init type
*/
Expand All @@ -33,6 +37,10 @@ export interface EggMultiInstancePrototypeInfo {
}

export interface EggMultiInstanceCallbackPrototypeInfo {
/**
* The class name of the object
*/
className?: string;
/**
* obj init type
*/
Expand Down
4 changes: 4 additions & 0 deletions core/core-decorator/src/model/EggPrototypeInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface EggPrototypeInfo {
* egg object name
*/
name: EggPrototypeName;
/**
* The class name of the object
*/
className?: string;
/**
* obj init type
*/
Expand Down
2 changes: 2 additions & 0 deletions core/core-decorator/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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);
});
Expand Down
1 change: 1 addition & 0 deletions core/metadata/src/factory/EggPrototypeCreatorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class EggPrototypeCreatorFactory {
initType: multiInstanceProtoInfo.initType,
accessLevel: multiInstanceProtoInfo.accessLevel,
qualifiers: obj.qualifiers,
className: multiInstanceProtoInfo.className,
});
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions core/metadata/src/impl/EggPrototypeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class EggPrototypeBuilder {
private injectObjects: Array<InjectObject> = [];
private loadUnit: LoadUnit;
private qualifiers: QualifierInfo[] = [];
private className?: string;

static create(ctx: EggPrototypeLifecycleContext): EggPrototype {
const { clazz, loadUnit } = ctx;
Expand All @@ -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!;
Expand Down Expand Up @@ -131,6 +133,7 @@ export class EggPrototypeBuilder {
injectObjectProtos,
this.loadUnit.id,
this.qualifiers,
this.className,
);
}
}
Expand Down
3 changes: 3 additions & 0 deletions core/metadata/src/impl/EggPrototypeImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class EggPrototypeImpl implements EggPrototype {
readonly accessLevel: AccessLevel;
readonly injectObjects: InjectObjectProto[];
readonly loadUnitId: Id;
readonly className?: string;

constructor(
id: string,
Expand All @@ -31,6 +32,7 @@ export class EggPrototypeImpl implements EggPrototype {
injectObjectMap: InjectObjectProto[],
loadUnitId: Id,
qualifiers: QualifierInfo[],
className?: string,
) {
this.id = id;
this.clazz = clazz;
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions core/metadata/src/model/EggPrototype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface EggPrototype extends LifecycleObject<EggPrototypeLifecycleConte
readonly accessLevel: AccessLevel;
readonly loadUnitId: string;
readonly injectObjects: InjectObjectProto[];
readonly className?: string;

/**
* get metedata for key
Expand Down
8 changes: 5 additions & 3 deletions core/metadata/test/LoadUnit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ describe('test/LoadUnit/LoadUnit.test.ts', () => {
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);
});

Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion standalone/standalone/src/StandaloneInnerObjectProto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class StandaloneInnerObjectProto implements EggPrototype {
readonly accessLevel: AccessLevel;
readonly injectObjects: InjectObjectProto[];
readonly loadUnitId: Id;
readonly className?: string;

constructor(
id: string,
Expand All @@ -33,6 +34,7 @@ export class StandaloneInnerObjectProto implements EggPrototype {
initType: ObjectInitTypeLike,
loadUnitId: Id,
qualifiers: QualifierInfo[],
className?: string,
) {
this.id = id;
this.clazz = clazz;
Expand All @@ -42,6 +44,7 @@ export class StandaloneInnerObjectProto implements EggPrototype {
this.injectObjects = [];
this.loadUnitId = loadUnitId;
this.qualifiers = qualifiers;
this.className = className;
}

verifyQualifiers(qualifiers: QualifierInfo[]): boolean {
Expand Down Expand Up @@ -73,9 +76,10 @@ export class StandaloneInnerObjectProto implements EggPrototype {
static create(ctx: EggPrototypeLifecycleContext): EggPrototype {
const { clazz, loadUnit } = ctx;
const name = ctx.prototypeInfo.name;
const className = ctx.prototypeInfo.className;
const id = IdenticalUtil.createProtoId(loadUnit.id, name);
const proto = new StandaloneInnerObjectProto(
id, name, clazz, ctx.prototypeInfo.initType, loadUnit.id, QualifierUtil.getProtoQualifiers(clazz),
id, name, clazz, ctx.prototypeInfo.initType, loadUnit.id, QualifierUtil.getProtoQualifiers(clazz), className,
);
return proto;
}
Expand Down
Loading