-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
621 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { ObjectInitType, ObjectInitTypeLike } from '../enum/ObjectInitType'; | ||
import { AccessLevel } from '../enum/AccessLevel'; | ||
import { DEFAULT_PROTO_IMPL_TYPE } from './Prototype'; | ||
import { | ||
EggMultiInstanceCallbackPrototypeInfo, | ||
EggMultiInstancePrototypeInfo, | ||
MultiInstancePrototypeGetObjectsContext, | ||
ObjectInfo, | ||
} from '../model/EggMultiInstancePrototypeInfo'; | ||
import { EggProtoImplClass } from '../model/EggPrototypeInfo'; | ||
import { PrototypeUtil } from '../util/PrototypeUtil'; | ||
import { StackUtil } from '@eggjs/tegg-common-util'; | ||
|
||
const DEFAULT_PARAMS = { | ||
initType: ObjectInitType.SINGLETON, | ||
accessLevel: AccessLevel.PRIVATE, | ||
protoImplType: DEFAULT_PROTO_IMPL_TYPE, | ||
}; | ||
|
||
export interface BaseMultiInstancePrototypeCallbackParams { | ||
/** | ||
* obj init type | ||
*/ | ||
initType?: ObjectInitTypeLike; | ||
/** | ||
* access level | ||
*/ | ||
accessLevel?: AccessLevel; | ||
/** | ||
* EggPrototype implement type | ||
*/ | ||
protoImplType?: string; | ||
} | ||
|
||
export interface MultiInstancePrototypeCallbackParams extends BaseMultiInstancePrototypeCallbackParams { | ||
getObjects(ctx: MultiInstancePrototypeGetObjectsContext): ObjectInfo[]; | ||
} | ||
|
||
export interface MultiInstancePrototypeStaticParams extends BaseMultiInstancePrototypeCallbackParams { | ||
/** | ||
* object info list | ||
*/ | ||
objects: ObjectInfo[]; | ||
} | ||
|
||
export type MultiInstancePrototypeParams = MultiInstancePrototypeCallbackParams | MultiInstancePrototypeStaticParams; | ||
|
||
export function MultiInstanceProto(param: MultiInstancePrototypeParams) { | ||
return function(clazz: EggProtoImplClass) { | ||
PrototypeUtil.setIsEggMultiInstancePrototype(clazz); | ||
if ((param as MultiInstancePrototypeStaticParams).objects) { | ||
const property: EggMultiInstancePrototypeInfo = { | ||
...DEFAULT_PARAMS, | ||
...param as MultiInstancePrototypeStaticParams, | ||
}; | ||
PrototypeUtil.setMultiInstanceStaticProperty(clazz, property); | ||
} else if ((param as MultiInstancePrototypeCallbackParams).getObjects) { | ||
const property: EggMultiInstanceCallbackPrototypeInfo = { | ||
...DEFAULT_PARAMS, | ||
...param as MultiInstancePrototypeCallbackParams, | ||
}; | ||
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/[email protected]@reflect-metadata/Reflect.js', | ||
// './tegg/core/core-decorator/node_modules/[email protected]@reflect-metadata/Reflect.js', | ||
// './tegg/core/core-decorator/test/fixtures/decators/CacheService.ts', | ||
PrototypeUtil.setFilePath(clazz, StackUtil.getCalleeFromStack(false, 4)); | ||
}; | ||
} |
54 changes: 54 additions & 0 deletions
54
core/core-decorator/src/model/EggMultiInstancePrototypeInfo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { ObjectInitTypeLike } from '../enum/ObjectInitType'; | ||
import { AccessLevel } from '../enum/AccessLevel'; | ||
import { EggPrototypeName } from './EggPrototypeInfo'; | ||
import { QualifierInfo } from './QualifierInfo'; | ||
|
||
export interface ObjectInfo { | ||
name: EggPrototypeName; | ||
qualifiers: QualifierInfo[]; | ||
} | ||
|
||
export interface MultiInstancePrototypeGetObjectsContext { | ||
unitPath: string; | ||
} | ||
|
||
export interface EggMultiInstancePrototypeInfo { | ||
/** | ||
* obj init type | ||
*/ | ||
initType: ObjectInitTypeLike; | ||
/** | ||
* access level | ||
*/ | ||
accessLevel: AccessLevel; | ||
/** | ||
* EggPrototype implement type | ||
*/ | ||
protoImplType: string; | ||
|
||
/** | ||
* object info list | ||
*/ | ||
objects: ObjectInfo[]; | ||
} | ||
|
||
export interface EggMultiInstanceCallbackPrototypeInfo { | ||
/** | ||
* obj init type | ||
*/ | ||
initType: ObjectInitTypeLike; | ||
/** | ||
* access level | ||
*/ | ||
accessLevel: AccessLevel; | ||
/** | ||
* EggPrototype implement type | ||
*/ | ||
protoImplType: string; | ||
|
||
/** | ||
* get object callback | ||
* @param ctx | ||
*/ | ||
getObjects(ctx: MultiInstancePrototypeGetObjectsContext): ObjectInfo[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { MultiInstanceProto } from '../../../src/decorator/MultiInstanceProto'; | ||
import { AccessLevel } from '../../../src/enum/AccessLevel'; | ||
import { ObjectInitType } from '../../../src/enum/ObjectInitType'; | ||
|
||
export const FOO_ATTRIBUTE = Symbol.for('FOO_ATTRIBUTE'); | ||
|
||
@MultiInstanceProto({ | ||
accessLevel: AccessLevel.PUBLIC, | ||
initType: ObjectInitType.SINGLETON, | ||
protoImplType: 'foo', | ||
objects: [{ | ||
name: 'foo', | ||
qualifiers: [{ | ||
attribute: FOO_ATTRIBUTE, | ||
value: 'foo1', | ||
}], | ||
}, { | ||
name: 'foo', | ||
qualifiers: [{ | ||
attribute: FOO_ATTRIBUTE, | ||
value: 'foo2', | ||
}], | ||
}], | ||
}) | ||
export class FooLogger { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.