@eggjs/core-decorator 4.0.0-beta.4 → 4.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +13 -1
  2. package/dist/decorator/ConfigSource.d.ts +4 -0
  3. package/dist/decorator/ConfigSource.js +13 -0
  4. package/dist/decorator/ContextProto.d.ts +7 -0
  5. package/dist/decorator/ContextProto.js +14 -0
  6. package/dist/decorator/EggQualifier.d.ts +6 -0
  7. package/dist/decorator/EggQualifier.js +13 -0
  8. package/dist/decorator/InitTypeQualifier.d.ts +6 -0
  9. package/dist/decorator/InitTypeQualifier.js +13 -0
  10. package/dist/decorator/Inject.d.ts +7 -0
  11. package/dist/decorator/Inject.js +77 -0
  12. package/dist/decorator/ModuleQualifier.d.ts +4 -0
  13. package/dist/decorator/ModuleQualifier.js +13 -0
  14. package/dist/decorator/MultiInstanceInfo.d.ts +6 -0
  15. package/dist/decorator/MultiInstanceInfo.js +13 -0
  16. package/dist/decorator/MultiInstanceProto.d.ts +6 -0
  17. package/dist/decorator/MultiInstanceProto.js +35 -0
  18. package/dist/decorator/Prototype.d.ts +6 -0
  19. package/dist/decorator/Prototype.js +27 -0
  20. package/dist/decorator/SingletonProto.d.ts +7 -0
  21. package/dist/decorator/SingletonProto.js +14 -0
  22. package/dist/decorator/index.js +12 -0
  23. package/dist/index.d.ts +15 -0
  24. package/dist/index.js +19 -0
  25. package/dist/util/MetadataUtil.d.ts +39 -0
  26. package/dist/util/MetadataUtil.js +75 -0
  27. package/dist/util/PrototypeUtil.d.ts +112 -0
  28. package/dist/util/PrototypeUtil.js +216 -0
  29. package/dist/util/QualifierUtil.d.ts +17 -0
  30. package/dist/util/QualifierUtil.js +67 -0
  31. package/dist/util/index.js +5 -0
  32. package/package.json +24 -26
  33. package/src/decorator/ConfigSource.d.ts +0 -1
  34. package/src/decorator/ConfigSource.js +0 -8
  35. package/src/decorator/ContextProto.d.ts +0 -2
  36. package/src/decorator/ContextProto.js +0 -10
  37. package/src/decorator/EggQualifier.d.ts +0 -2
  38. package/src/decorator/EggQualifier.js +0 -8
  39. package/src/decorator/InitTypeQualifier.d.ts +0 -2
  40. package/src/decorator/InitTypeQualifier.js +0 -8
  41. package/src/decorator/Inject.d.ts +0 -3
  42. package/src/decorator/Inject.js +0 -95
  43. package/src/decorator/ModuleQualifier.d.ts +0 -1
  44. package/src/decorator/ModuleQualifier.js +0 -8
  45. package/src/decorator/MultiInstanceInfo.d.ts +0 -2
  46. package/src/decorator/MultiInstanceInfo.js +0 -8
  47. package/src/decorator/MultiInstanceProto.d.ts +0 -2
  48. package/src/decorator/MultiInstanceProto.js +0 -36
  49. package/src/decorator/Prototype.d.ts +0 -2
  50. package/src/decorator/Prototype.js +0 -29
  51. package/src/decorator/SingletonProto.d.ts +0 -2
  52. package/src/decorator/SingletonProto.js +0 -10
  53. package/src/decorator/index.d.ts +0 -10
  54. package/src/decorator/index.js +0 -11
  55. package/src/index.d.ts +0 -3
  56. package/src/index.js +0 -4
  57. package/src/util/MetadataUtil.d.ts +0 -35
  58. package/src/util/MetadataUtil.js +0 -83
  59. package/src/util/PrototypeUtil.d.ts +0 -108
  60. package/src/util/PrototypeUtil.js +0 -249
  61. package/src/util/QualifierUtil.d.ts +0 -13
  62. package/src/util/QualifierUtil.js +0 -92
  63. package/src/util/index.d.ts +0 -3
  64. package/src/util/index.js +0 -4
package/README.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # `@eggjs/core-decorator`
2
2
 
3
+ [![NPM version][npm-image]][npm-url]
4
+ [![Known Vulnerabilities][snyk-image]][snyk-url]
5
+ [![npm download][download-image]][download-url]
6
+ [![Node.js Version](https://img.shields.io/node/v/@eggjs/core-decorator.svg?style=flat)](https://nodejs.org/en/download/)
7
+
8
+ [npm-image]: https://img.shields.io/npm/v/@eggjs/core-decorator.svg?style=flat-square
9
+ [npm-url]: https://npmjs.org/package/@eggjs/core-decorator
10
+ [snyk-image]: https://snyk.io/test/npm/@eggjs/core-decorator/badge.svg?style=flat-square
11
+ [snyk-url]: https://snyk.io/test/npm/@eggjs/core-decorator
12
+ [download-image]: https://img.shields.io/npm/dm/@eggjs/core-decorator.svg?style=flat-square
13
+ [download-url]: https://npmjs.org/package/@eggjs/core-decorator
14
+
3
15
  ## Usage
4
16
 
5
- Please read [@eggjs/tegg-plugin](../../plugin/tegg)
17
+ Please read [@eggjs/tegg-plugin](../../plugin/tegg/README.md)
@@ -0,0 +1,4 @@
1
+ //#region src/decorator/ConfigSource.d.ts
2
+ declare function ConfigSourceQualifier(moduleName: string): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
3
+ //#endregion
4
+ export { ConfigSourceQualifier };
@@ -0,0 +1,13 @@
1
+ import { QualifierUtil } from "../util/QualifierUtil.js";
2
+ import "../util/index.js";
3
+ import { ConfigSourceQualifierAttribute } from "@eggjs/tegg-types";
4
+
5
+ //#region src/decorator/ConfigSource.ts
6
+ function ConfigSourceQualifier(moduleName) {
7
+ return function(target, propertyKey, parameterIndex) {
8
+ QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, ConfigSourceQualifierAttribute, moduleName);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ export { ConfigSourceQualifier };
@@ -0,0 +1,7 @@
1
+ import * as _eggjs_tegg_types0 from "@eggjs/tegg-types";
2
+ import { ContextProtoParams } from "@eggjs/tegg-types";
3
+
4
+ //#region src/decorator/ContextProto.d.ts
5
+ declare function ContextProto(params?: ContextProtoParams): (clazz: _eggjs_tegg_types0.EggProtoImplClass) => void;
6
+ //#endregion
7
+ export { ContextProto };
@@ -0,0 +1,14 @@
1
+ import { Prototype } from "./Prototype.js";
2
+ import { AccessLevel, ObjectInitType } from "@eggjs/tegg-types";
3
+
4
+ //#region src/decorator/ContextProto.ts
5
+ function ContextProto(params) {
6
+ return Prototype({
7
+ initType: ObjectInitType.CONTEXT,
8
+ accessLevel: params?.accessLevel || AccessLevel.PRIVATE,
9
+ ...params
10
+ });
11
+ }
12
+
13
+ //#endregion
14
+ export { ContextProto };
@@ -0,0 +1,6 @@
1
+ import { EggType } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/EggQualifier.d.ts
4
+ declare function EggQualifier(eggType: EggType): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
5
+ //#endregion
6
+ export { EggQualifier };
@@ -0,0 +1,13 @@
1
+ import { QualifierUtil } from "../util/QualifierUtil.js";
2
+ import "../util/index.js";
3
+ import { EggQualifierAttribute } from "@eggjs/tegg-types";
4
+
5
+ //#region src/decorator/EggQualifier.ts
6
+ function EggQualifier(eggType) {
7
+ return function(target, propertyKey, parameterIndex) {
8
+ QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, EggQualifierAttribute, eggType);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ export { EggQualifier };
@@ -0,0 +1,6 @@
1
+ import { ObjectInitTypeLike } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/InitTypeQualifier.d.ts
4
+ declare function InitTypeQualifier(initType: ObjectInitTypeLike): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
5
+ //#endregion
6
+ export { InitTypeQualifier };
@@ -0,0 +1,13 @@
1
+ import { QualifierUtil } from "../util/QualifierUtil.js";
2
+ import "../util/index.js";
3
+ import { InitTypeQualifierAttribute } from "@eggjs/tegg-types";
4
+
5
+ //#region src/decorator/InitTypeQualifier.ts
6
+ function InitTypeQualifier(initType) {
7
+ return function(target, propertyKey, parameterIndex) {
8
+ QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, InitTypeQualifierAttribute, initType);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ export { InitTypeQualifier };
@@ -0,0 +1,7 @@
1
+ import { InjectParams } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/Inject.d.ts
4
+ declare function Inject(param?: InjectParams | string): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
5
+ declare function InjectOptional(param?: Omit<InjectParams, 'optional'> | string): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
6
+ //#endregion
7
+ export { Inject, InjectOptional };
@@ -0,0 +1,77 @@
1
+ import { PrototypeUtil } from "../util/PrototypeUtil.js";
2
+ import { QualifierUtil } from "../util/QualifierUtil.js";
3
+ import "../util/index.js";
4
+ import { InitTypeQualifierAttribute, InjectType } from "@eggjs/tegg-types";
5
+ import { ObjectUtils } from "@eggjs/tegg-common-util";
6
+ import { debuglog } from "node:util";
7
+
8
+ //#region src/decorator/Inject.ts
9
+ const debug = debuglog("tegg/core/core-decorator/decorator/Inject");
10
+ function guessInjectInfo(clazz, name, proto) {
11
+ let objName;
12
+ let initType;
13
+ if (typeof proto === "function" && proto !== Object) {
14
+ const info = PrototypeUtil.getProperty(proto);
15
+ objName = info?.name;
16
+ if (info?.initType) {
17
+ if (!QualifierUtil.getProperQualifier(clazz, name, InitTypeQualifierAttribute)) initType = info.initType;
18
+ }
19
+ }
20
+ return {
21
+ objName,
22
+ initType
23
+ };
24
+ }
25
+ function Inject(param) {
26
+ const injectParam = typeof param === "string" ? { name: param } : param;
27
+ function propertyInject(target, propertyKey) {
28
+ let objName;
29
+ let initType;
30
+ if (!injectParam) {
31
+ const proto = PrototypeUtil.getDesignType(target, propertyKey);
32
+ const result = guessInjectInfo(target.constructor, propertyKey, proto);
33
+ objName = result.objName;
34
+ initType = result.initType;
35
+ } else objName = injectParam?.name;
36
+ const injectObject = {
37
+ refName: propertyKey,
38
+ objName: objName || propertyKey
39
+ };
40
+ if (injectParam?.optional) injectObject.optional = true;
41
+ PrototypeUtil.setInjectType(target.constructor, InjectType.PROPERTY);
42
+ PrototypeUtil.addInjectObject(target.constructor, injectObject);
43
+ debug("propertyInject, clazz: %s, propertyKey: %s, injectObject: %o", target.constructor.name, propertyKey, injectObject);
44
+ if (initType) QualifierUtil.addProperQualifier(target.constructor, propertyKey, InitTypeQualifierAttribute, initType);
45
+ }
46
+ function constructorInject(target, parameterIndex) {
47
+ const argName = ObjectUtils.getConstructorArgNameList(target)[parameterIndex];
48
+ let objName;
49
+ let initType;
50
+ if (!injectParam) {
51
+ const protos = PrototypeUtil.getDesignParamtypes(target);
52
+ ({objName, initType} = guessInjectInfo(target, argName, protos?.[parameterIndex]));
53
+ } else objName = injectParam?.name;
54
+ const injectObject = {
55
+ refIndex: parameterIndex,
56
+ refName: argName,
57
+ objName: objName || argName
58
+ };
59
+ if (injectParam?.optional) injectObject.optional = true;
60
+ PrototypeUtil.setInjectType(target, InjectType.CONSTRUCTOR);
61
+ PrototypeUtil.addInjectConstructor(target, injectObject);
62
+ if (initType) QualifierUtil.addProperQualifier(target, argName, InitTypeQualifierAttribute, initType);
63
+ }
64
+ return function(target, propertyKey, parameterIndex) {
65
+ if (typeof parameterIndex === "undefined") propertyInject(target, propertyKey);
66
+ else constructorInject(target, parameterIndex);
67
+ };
68
+ }
69
+ function InjectOptional(param) {
70
+ return Inject({
71
+ ...typeof param === "string" ? { name: param } : param,
72
+ optional: true
73
+ });
74
+ }
75
+
76
+ //#endregion
77
+ export { Inject, InjectOptional };
@@ -0,0 +1,4 @@
1
+ //#region src/decorator/ModuleQualifier.d.ts
2
+ declare function ModuleQualifier(moduleName: string): (target: any, propertyKey?: PropertyKey, parameterIndex?: number) => void;
3
+ //#endregion
4
+ export { ModuleQualifier };
@@ -0,0 +1,13 @@
1
+ import { QualifierUtil } from "../util/QualifierUtil.js";
2
+ import "../util/index.js";
3
+ import { LoadUnitNameQualifierAttribute } from "@eggjs/tegg-types";
4
+
5
+ //#region src/decorator/ModuleQualifier.ts
6
+ function ModuleQualifier(moduleName) {
7
+ return function(target, propertyKey, parameterIndex) {
8
+ QualifierUtil.addInjectQualifier(target, propertyKey, parameterIndex, LoadUnitNameQualifierAttribute, moduleName);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ export { ModuleQualifier };
@@ -0,0 +1,6 @@
1
+ import { QualifierAttribute } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/MultiInstanceInfo.d.ts
4
+ declare function MultiInstanceInfo(attributes: QualifierAttribute[]): (target: any, _propertyKey: PropertyKey | undefined, parameterIndex: number) => void;
5
+ //#endregion
6
+ export { MultiInstanceInfo };
@@ -0,0 +1,13 @@
1
+ import { PrototypeUtil } from "../util/PrototypeUtil.js";
2
+ import "../util/index.js";
3
+
4
+ //#region src/decorator/MultiInstanceInfo.ts
5
+ function MultiInstanceInfo(attributes) {
6
+ return function(target, _propertyKey, parameterIndex) {
7
+ PrototypeUtil.setMultiInstanceConstructorIndex(target, parameterIndex);
8
+ PrototypeUtil.setMultiInstanceConstructorAttributes(target, attributes);
9
+ };
10
+ }
11
+
12
+ //#endregion
13
+ export { MultiInstanceInfo };
@@ -0,0 +1,6 @@
1
+ import { EggProtoImplClass, MultiInstancePrototypeParams } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/MultiInstanceProto.d.ts
4
+ declare function MultiInstanceProto(param: MultiInstancePrototypeParams): (clazz: EggProtoImplClass) => void;
5
+ //#endregion
6
+ export { MultiInstanceProto };
@@ -0,0 +1,35 @@
1
+ import { PrototypeUtil } from "../util/PrototypeUtil.js";
2
+ import "../util/index.js";
3
+ import { AccessLevel, DEFAULT_PROTO_IMPL_TYPE, ObjectInitType } from "@eggjs/tegg-types";
4
+ import { StackUtil } from "@eggjs/tegg-common-util";
5
+
6
+ //#region src/decorator/MultiInstanceProto.ts
7
+ const DEFAULT_PARAMS = {
8
+ initType: ObjectInitType.SINGLETON,
9
+ accessLevel: AccessLevel.PRIVATE,
10
+ protoImplType: DEFAULT_PROTO_IMPL_TYPE
11
+ };
12
+ function MultiInstanceProto(param) {
13
+ return function(clazz) {
14
+ PrototypeUtil.setIsEggMultiInstancePrototype(clazz);
15
+ if (param.objects) {
16
+ const property = {
17
+ ...DEFAULT_PARAMS,
18
+ ...param,
19
+ className: clazz.name
20
+ };
21
+ PrototypeUtil.setMultiInstanceStaticProperty(clazz, property);
22
+ } else if (param.getObjects) {
23
+ const property = {
24
+ ...DEFAULT_PARAMS,
25
+ ...param,
26
+ className: clazz.name
27
+ };
28
+ PrototypeUtil.setMultiInstanceCallbackProperty(clazz, property);
29
+ }
30
+ PrototypeUtil.setFilePath(clazz, StackUtil.getCalleeFromStack(false, 4));
31
+ };
32
+ }
33
+
34
+ //#endregion
35
+ export { MultiInstanceProto };
@@ -0,0 +1,6 @@
1
+ import { EggProtoImplClass, PrototypeParams } from "@eggjs/tegg-types";
2
+
3
+ //#region src/decorator/Prototype.d.ts
4
+ declare function Prototype(param?: PrototypeParams): (clazz: EggProtoImplClass) => void;
5
+ //#endregion
6
+ export { Prototype };
@@ -0,0 +1,27 @@
1
+ import { PrototypeUtil } from "../util/PrototypeUtil.js";
2
+ import "../util/index.js";
3
+ import { AccessLevel, DEFAULT_PROTO_IMPL_TYPE, ObjectInitType } from "@eggjs/tegg-types";
4
+ import { NameUtil, StackUtil } from "@eggjs/tegg-common-util";
5
+
6
+ //#region src/decorator/Prototype.ts
7
+ const DEFAULT_PARAMS = {
8
+ initType: ObjectInitType.SINGLETON,
9
+ accessLevel: AccessLevel.PRIVATE,
10
+ protoImplType: DEFAULT_PROTO_IMPL_TYPE
11
+ };
12
+ function Prototype(param) {
13
+ return function(clazz) {
14
+ PrototypeUtil.setIsEggPrototype(clazz);
15
+ const property = {
16
+ ...DEFAULT_PARAMS,
17
+ ...param,
18
+ className: clazz.name
19
+ };
20
+ if (!property.name) property.name = NameUtil.getClassName(clazz);
21
+ PrototypeUtil.setProperty(clazz, property);
22
+ PrototypeUtil.setFilePath(clazz, StackUtil.getCalleeFromStack(false, 4));
23
+ };
24
+ }
25
+
26
+ //#endregion
27
+ export { Prototype };
@@ -0,0 +1,7 @@
1
+ import * as _eggjs_tegg_types0 from "@eggjs/tegg-types";
2
+ import { SingletonProtoParams } from "@eggjs/tegg-types";
3
+
4
+ //#region src/decorator/SingletonProto.d.ts
5
+ declare function SingletonProto(params?: SingletonProtoParams): (clazz: _eggjs_tegg_types0.EggProtoImplClass) => void;
6
+ //#endregion
7
+ export { SingletonProto };
@@ -0,0 +1,14 @@
1
+ import { Prototype } from "./Prototype.js";
2
+ import { AccessLevel, ObjectInitType } from "@eggjs/tegg-types";
3
+
4
+ //#region src/decorator/SingletonProto.ts
5
+ function SingletonProto(params) {
6
+ return Prototype({
7
+ initType: ObjectInitType.SINGLETON,
8
+ accessLevel: params?.accessLevel || AccessLevel.PRIVATE,
9
+ ...params
10
+ });
11
+ }
12
+
13
+ //#endregion
14
+ export { SingletonProto };
@@ -0,0 +1,12 @@
1
+ import { ConfigSourceQualifier } from "./ConfigSource.js";
2
+ import { Prototype } from "./Prototype.js";
3
+ import { ContextProto } from "./ContextProto.js";
4
+ import { EggQualifier } from "./EggQualifier.js";
5
+ import { InitTypeQualifier } from "./InitTypeQualifier.js";
6
+ import { Inject, InjectOptional } from "./Inject.js";
7
+ import { ModuleQualifier } from "./ModuleQualifier.js";
8
+ import { MultiInstanceInfo } from "./MultiInstanceInfo.js";
9
+ import { MultiInstanceProto } from "./MultiInstanceProto.js";
10
+ import { SingletonProto } from "./SingletonProto.js";
11
+
12
+ export { };
@@ -0,0 +1,15 @@
1
+ import { ConfigSourceQualifier } from "./decorator/ConfigSource.js";
2
+ import { ContextProto } from "./decorator/ContextProto.js";
3
+ import { EggQualifier } from "./decorator/EggQualifier.js";
4
+ import { InitTypeQualifier } from "./decorator/InitTypeQualifier.js";
5
+ import { Inject, InjectOptional } from "./decorator/Inject.js";
6
+ import { ModuleQualifier } from "./decorator/ModuleQualifier.js";
7
+ import { MultiInstanceInfo } from "./decorator/MultiInstanceInfo.js";
8
+ import { MultiInstanceProto } from "./decorator/MultiInstanceProto.js";
9
+ import { Prototype } from "./decorator/Prototype.js";
10
+ import { SingletonProto } from "./decorator/SingletonProto.js";
11
+ import { MetadataUtil } from "./util/MetadataUtil.js";
12
+ import { PrototypeUtil } from "./util/PrototypeUtil.js";
13
+ import { QualifierUtil } from "./util/QualifierUtil.js";
14
+ export * from "@eggjs/tegg-types/core-decorator";
15
+ export { ConfigSourceQualifier, ContextProto, EggQualifier, InitTypeQualifier, Inject, InjectOptional, MetadataUtil, ModuleQualifier, MultiInstanceInfo, MultiInstanceProto, Prototype, PrototypeUtil, QualifierUtil, SingletonProto };
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ import { MetadataUtil } from "./util/MetadataUtil.js";
2
+ import { PrototypeUtil } from "./util/PrototypeUtil.js";
3
+ import { QualifierUtil } from "./util/QualifierUtil.js";
4
+ import "./util/index.js";
5
+ import { ConfigSourceQualifier } from "./decorator/ConfigSource.js";
6
+ import { Prototype } from "./decorator/Prototype.js";
7
+ import { ContextProto } from "./decorator/ContextProto.js";
8
+ import { EggQualifier } from "./decorator/EggQualifier.js";
9
+ import { InitTypeQualifier } from "./decorator/InitTypeQualifier.js";
10
+ import { Inject, InjectOptional } from "./decorator/Inject.js";
11
+ import { ModuleQualifier } from "./decorator/ModuleQualifier.js";
12
+ import { MultiInstanceInfo } from "./decorator/MultiInstanceInfo.js";
13
+ import { MultiInstanceProto } from "./decorator/MultiInstanceProto.js";
14
+ import { SingletonProto } from "./decorator/SingletonProto.js";
15
+ import "./decorator/index.js";
16
+
17
+ export * from "@eggjs/tegg-types/core-decorator"
18
+
19
+ export { ConfigSourceQualifier, ContextProto, EggQualifier, InitTypeQualifier, Inject, InjectOptional, MetadataUtil, ModuleQualifier, MultiInstanceInfo, MultiInstanceProto, Prototype, PrototypeUtil, QualifierUtil, SingletonProto };
@@ -0,0 +1,39 @@
1
+ import { EggProtoImplClass, MetaDataKey } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/MetadataUtil.d.ts
4
+ declare class MetadataUtil {
5
+ static deleteMetaData(metadataKey: MetaDataKey, clazz: EggProtoImplClass): void;
6
+ static defineMetaData<T>(metadataKey: MetaDataKey, metadataValue: T, clazz: EggProtoImplClass): void;
7
+ static getOwnMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass): T | undefined;
8
+ static hasMetaData(metadataKey: MetaDataKey, clazz: EggProtoImplClass, propKey?: PropertyKey): boolean;
9
+ static getMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass, propKey?: PropertyKey): T | undefined;
10
+ static getBooleanMetaData(metadataKey: MetaDataKey, clazz: EggProtoImplClass): boolean;
11
+ static getOwnBooleanMetaData(metadataKey: MetaDataKey, clazz: EggProtoImplClass): boolean;
12
+ static getArrayMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass): Array<T>;
13
+ /**
14
+ * init array metadata
15
+ * not inherit parent metadata
16
+ * return value true means use default value
17
+ * return value false means use map value
18
+ */
19
+ static initArrayMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass, defaultValue: Array<T>): Array<T>;
20
+ /**
21
+ * init own array metadata
22
+ * if parent metadata exists, inherit
23
+ * if parent metadata not exits, use default value
24
+ * return value true means use default value
25
+ * return value false means use map value
26
+ */
27
+ static initOwnArrayMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass, defaultValue: Array<T>): Array<T>;
28
+ /**
29
+ * init own map metadata
30
+ * if parent metadata exists, inherit
31
+ * if parent metadata not exits, use default value
32
+ * return value true means use default value
33
+ * return value false means use map value
34
+ */
35
+ static initOwnMapMetaData<K, V>(metadataKey: MetaDataKey, clazz: EggProtoImplClass, defaultValue: Map<K, V>): Map<K, V>;
36
+ static getOrStoreMetaData<T>(metadataKey: MetaDataKey, clazz: EggProtoImplClass, metadataValue: T): T;
37
+ }
38
+ //#endregion
39
+ export { MetadataUtil };
@@ -0,0 +1,75 @@
1
+ //#region src/util/MetadataUtil.ts
2
+ var MetadataUtil = class {
3
+ static deleteMetaData(metadataKey, clazz) {
4
+ Reflect.deleteMetadata(metadataKey, clazz);
5
+ }
6
+ static defineMetaData(metadataKey, metadataValue, clazz) {
7
+ Reflect.defineMetadata(metadataKey, metadataValue, clazz);
8
+ }
9
+ static getOwnMetaData(metadataKey, clazz) {
10
+ return Reflect.getOwnMetadata(metadataKey, clazz);
11
+ }
12
+ static hasMetaData(metadataKey, clazz, propKey) {
13
+ return Reflect.hasMetadata(metadataKey, clazz, propKey);
14
+ }
15
+ static getMetaData(metadataKey, clazz, propKey) {
16
+ return Reflect.getMetadata(metadataKey, clazz, propKey);
17
+ }
18
+ static getBooleanMetaData(metadataKey, clazz) {
19
+ return !!this.getMetaData(metadataKey, clazz);
20
+ }
21
+ static getOwnBooleanMetaData(metadataKey, clazz) {
22
+ return !!this.getOwnMetaData(metadataKey, clazz);
23
+ }
24
+ static getArrayMetaData(metadataKey, clazz) {
25
+ return this.getMetaData(metadataKey, clazz) || [];
26
+ }
27
+ /**
28
+ * init array metadata
29
+ * not inherit parent metadata
30
+ * return value true means use default value
31
+ * return value false means use map value
32
+ */
33
+ static initArrayMetaData(metadataKey, clazz, defaultValue) {
34
+ if (!this.getOwnMetaData(metadataKey, clazz)) this.defineMetaData(metadataKey, defaultValue, clazz);
35
+ return this.getOwnMetaData(metadataKey, clazz);
36
+ }
37
+ /**
38
+ * init own array metadata
39
+ * if parent metadata exists, inherit
40
+ * if parent metadata not exits, use default value
41
+ * return value true means use default value
42
+ * return value false means use map value
43
+ */
44
+ static initOwnArrayMetaData(metadataKey, clazz, defaultValue) {
45
+ if (!this.getOwnMetaData(metadataKey, clazz)) {
46
+ const selfValue = (this.getMetaData(metadataKey, clazz) || defaultValue).slice();
47
+ this.defineMetaData(metadataKey, selfValue, clazz);
48
+ }
49
+ return this.getOwnMetaData(metadataKey, clazz);
50
+ }
51
+ /**
52
+ * init own map metadata
53
+ * if parent metadata exists, inherit
54
+ * if parent metadata not exits, use default value
55
+ * return value true means use default value
56
+ * return value false means use map value
57
+ */
58
+ static initOwnMapMetaData(metadataKey, clazz, defaultValue) {
59
+ if (!this.getOwnMetaData(metadataKey, clazz)) {
60
+ const parentValue = this.getMetaData(metadataKey, clazz);
61
+ const selfValue = /* @__PURE__ */ new Map();
62
+ const ownDefaultValue = parentValue || defaultValue;
63
+ for (const [k, v] of ownDefaultValue) selfValue.set(k, v);
64
+ this.defineMetaData(metadataKey, selfValue, clazz);
65
+ }
66
+ return this.getOwnMetaData(metadataKey, clazz);
67
+ }
68
+ static getOrStoreMetaData(metadataKey, clazz, metadataValue) {
69
+ if (!Reflect.hasMetadata(metadataKey, clazz)) Reflect.defineMetadata(metadataKey, metadataValue, clazz);
70
+ return Reflect.getMetadata(metadataKey, clazz);
71
+ }
72
+ };
73
+
74
+ //#endregion
75
+ export { MetadataUtil };
@@ -0,0 +1,112 @@
1
+ import { EggMultiInstanceCallbackPrototypeInfo, EggMultiInstancePrototypeInfo, EggProtoImplClass, EggPrototypeInfo, EggPrototypeName, InjectConstructorInfo, InjectObjectInfo, InjectType, MultiInstancePrototypeGetObjectsContext, MultiInstanceType, QualifierAttribute } from "@eggjs/tegg-types";
2
+
3
+ //#region src/util/PrototypeUtil.d.ts
4
+ declare class PrototypeUtil {
5
+ static readonly IS_EGG_OBJECT_PROTOTYPE: unique symbol;
6
+ static readonly IS_EGG_OBJECT_MULTI_INSTANCE_PROTOTYPE: unique symbol;
7
+ static readonly FILE_PATH: unique symbol;
8
+ static readonly PROTOTYPE_PROPERTY: unique symbol;
9
+ static readonly MULTI_INSTANCE_PROTOTYPE_STATIC_PROPERTY: unique symbol;
10
+ static readonly MULTI_INSTANCE_PROTOTYPE_CALLBACK_PROPERTY: unique symbol;
11
+ static readonly INJECT_OBJECT_NAME_SET: unique symbol;
12
+ static readonly INJECT_TYPE: unique symbol;
13
+ static readonly INJECT_CONSTRUCTOR_NAME_SET: unique symbol;
14
+ static readonly CLAZZ_PROTO: unique symbol;
15
+ static readonly MULTI_INSTANCE_CONSTRUCTOR_INDEX: unique symbol;
16
+ static readonly MULTI_INSTANCE_CONSTRUCTOR_ATTRIBUTES: unique symbol;
17
+ /**
18
+ * Mark class is egg object prototype
19
+ * @param {Function} clazz -
20
+ */
21
+ static setIsEggPrototype(clazz: EggProtoImplClass): void;
22
+ /**
23
+ * If class is egg object prototype, return true
24
+ * @param {Function} clazz -
25
+ */
26
+ static isEggPrototype(clazz: EggProtoImplClass): boolean;
27
+ /**
28
+ * Mark class is egg object multi instance prototype
29
+ * @param {Function} clazz -
30
+ */
31
+ static setIsEggMultiInstancePrototype(clazz: EggProtoImplClass): void;
32
+ /**
33
+ * If class is egg object multi instance prototype, return true
34
+ * @param {Function} clazz -
35
+ */
36
+ static isEggMultiInstancePrototype(clazz: EggProtoImplClass): boolean;
37
+ /**
38
+ * Get the type of the egg multi-instance prototype.
39
+ * @param {Function} clazz -
40
+ */
41
+ static getEggMultiInstancePrototypeType(clazz: EggProtoImplClass): MultiInstanceType | undefined;
42
+ /**
43
+ * set class file path
44
+ * @param {Function} clazz -
45
+ * @param {string} filePath -
46
+ */
47
+ static setFilePath(clazz: EggProtoImplClass, filePath: string): void;
48
+ /**
49
+ * get class file path
50
+ * @param {Function} clazz -
51
+ */
52
+ static getFilePath(clazz: EggProtoImplClass): string | undefined;
53
+ /**
54
+ * set class property
55
+ * @param {EggProtoImplClass} clazz -
56
+ * @param {EggPrototypeInfo} property -
57
+ */
58
+ static setProperty(clazz: EggProtoImplClass, property: EggPrototypeInfo): void;
59
+ /**
60
+ * get class property
61
+ * @param {EggProtoImplClass} clazz -
62
+ * @return {EggPrototypeInfo} -
63
+ */
64
+ static getProperty(clazz: EggProtoImplClass): EggPrototypeInfo | undefined;
65
+ static getInitType(clazz: EggProtoImplClass, ctx: MultiInstancePrototypeGetObjectsContext): Promise<string | undefined>;
66
+ static getAccessLevel(clazz: EggProtoImplClass, ctx: MultiInstancePrototypeGetObjectsContext): Promise<string | undefined>;
67
+ static getObjNames(clazz: EggProtoImplClass, ctx: MultiInstancePrototypeGetObjectsContext): Promise<EggPrototypeName[]>;
68
+ /**
69
+ * set class property
70
+ * @param {EggProtoImplClass} clazz -
71
+ * @param {EggPrototypeInfo} property -
72
+ */
73
+ static setMultiInstanceStaticProperty(clazz: EggProtoImplClass, property: EggMultiInstancePrototypeInfo): void;
74
+ /**
75
+ * set class property
76
+ * @param {EggProtoImplClass} clazz -
77
+ * @param {EggPrototypeInfo} property -
78
+ */
79
+ static setMultiInstanceCallbackProperty(clazz: EggProtoImplClass, property: EggMultiInstanceCallbackPrototypeInfo): void;
80
+ /**
81
+ * Get instance property of Static multi-instance prototype.
82
+ * @param {EggProtoImplClass} clazz -
83
+ */
84
+ static getStaticMultiInstanceProperty(clazz: EggProtoImplClass): EggMultiInstancePrototypeInfo | undefined;
85
+ /**
86
+ * Get instance property of Dynamic multi-instance prototype.
87
+ * @param {EggProtoImplClass} clazz -
88
+ * @param {MultiInstancePrototypeGetObjectsContext} ctx -
89
+ */
90
+ static getDynamicMultiInstanceProperty(clazz: EggProtoImplClass, ctx: MultiInstancePrototypeGetObjectsContext): Promise<EggMultiInstancePrototypeInfo | undefined>;
91
+ /**
92
+ * get class property
93
+ * @param {EggProtoImplClass} clazz -
94
+ * @param {MultiInstancePrototypeGetObjectsContext} ctx -
95
+ */
96
+ static getMultiInstanceProperty(clazz: EggProtoImplClass, ctx: MultiInstancePrototypeGetObjectsContext): Promise<EggMultiInstancePrototypeInfo | undefined>;
97
+ static setMultiInstanceConstructorAttributes(clazz: EggProtoImplClass, attributes: QualifierAttribute[]): void;
98
+ static getMultiInstanceConstructorAttributes(clazz: EggProtoImplClass): QualifierAttribute[];
99
+ static setMultiInstanceConstructorIndex(clazz: EggProtoImplClass, index: number): void;
100
+ static getMultiInstanceConstructorIndex(clazz: EggProtoImplClass): number | undefined;
101
+ static setInjectType(clazz: EggProtoImplClass, type: InjectType): void;
102
+ static addInjectObject(clazz: EggProtoImplClass, injectObject: InjectObjectInfo): void;
103
+ static addInjectConstructor(clazz: EggProtoImplClass, injectConstructorInfo: InjectConstructorInfo): void;
104
+ static getInjectType(clazz: EggProtoImplClass): InjectType | undefined;
105
+ static getInjectObjects(clazz: EggProtoImplClass): Array<InjectObjectInfo | InjectConstructorInfo>;
106
+ static getClazzProto(clazz: EggProtoImplClass): object | undefined;
107
+ static setClazzProto(clazz: EggProtoImplClass, proto: object): void;
108
+ static getDesignType(clazz: EggProtoImplClass, propKey?: PropertyKey): unknown;
109
+ static getDesignParamtypes(clazz: EggProtoImplClass, propKey?: PropertyKey): unknown[];
110
+ }
111
+ //#endregion
112
+ export { PrototypeUtil };