@eggjs/tegg-plugin 4.0.0-beta.6 → 4.0.0-beta.8

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 (72) hide show
  1. package/dist/AppLoadUnit-BOWdS4O9.d.ts +23 -0
  2. package/dist/AppLoadUnit-uyHgElRL.js +78 -0
  3. package/dist/AppLoadUnitInstance-4Z_vSQV3.js +69 -0
  4. package/dist/AppLoadUnitInstance-DQ-DxlmR.d.ts +24 -0
  5. package/dist/CompatibleUtil-CNhydb0E.js +96 -0
  6. package/dist/ConfigSourceLoadUnitHook-BV-R31vA.js +22 -0
  7. package/dist/EggAppLoader-DFYg65ry.js +106 -0
  8. package/dist/EggCompatibleObject-XfIZyirS.js +37 -0
  9. package/dist/EggCompatibleObject-lzUCfsIY.d.ts +21 -0
  10. package/dist/EggCompatibleProtoImpl-CPxLvSu4.js +50 -0
  11. package/dist/EggCompatibleProtoImpl-DpacWKFB.d.ts +25 -0
  12. package/dist/EggContextCompatibleHook-eFfN2xm6.js +31 -0
  13. package/dist/EggContextHandler-D8gfTbZs.js +29 -0
  14. package/dist/EggContextHandler-vGi67He5.d.ts +13 -0
  15. package/dist/EggContextImpl-DkCLPTzT.js +18 -0
  16. package/dist/EggModuleLoader-CCfQMmp5.js +50 -0
  17. package/dist/EggQualifierProtoHook-D5jNm-1y.js +48 -0
  18. package/dist/ModuleConfigLoader-CvZLf99E.js +84 -0
  19. package/dist/ModuleHandler-Dyx7JGj-.d.ts +17 -0
  20. package/dist/ModuleHandler-fKcUqWca.js +46 -0
  21. package/dist/Utils-11aRpnkd.js +33 -0
  22. package/dist/app/extend/application.d.ts +3 -56
  23. package/dist/app/extend/application.js +8 -70
  24. package/dist/app/extend/application.unittest.d.ts +1 -25
  25. package/dist/app/extend/application.unittest.js +2 -41
  26. package/dist/app/extend/context.d.ts +1 -23
  27. package/dist/app/extend/context.js +3 -28
  28. package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +1 -1
  29. package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +2 -1
  30. package/dist/app.d.ts +4 -1
  31. package/dist/app.js +18 -10
  32. package/dist/application-Ccljinuy.d.ts +57 -0
  33. package/dist/application-DFI1junS.js +70 -0
  34. package/dist/application.unittest-Cmia71Fx.js +43 -0
  35. package/dist/application.unittest-CpoCu6-E.d.ts +26 -0
  36. package/dist/context-BWYE1dif.js +30 -0
  37. package/dist/context-BoIt2G5h.d.ts +24 -0
  38. package/dist/ctx_lifecycle_middleware-CIeSrbVY.js +27 -0
  39. package/dist/ctx_lifecycle_middleware-DV7uN5PG.d.ts +6 -0
  40. package/dist/index.d.ts +6 -1
  41. package/dist/index.js +13 -3
  42. package/dist/lib/AppLoadUnit.d.ts +1 -22
  43. package/dist/lib/AppLoadUnit.js +1 -76
  44. package/dist/lib/AppLoadUnitInstance.d.ts +1 -23
  45. package/dist/lib/AppLoadUnitInstance.js +1 -67
  46. package/dist/lib/CompatibleUtil.js +1 -94
  47. package/dist/lib/ConfigSourceLoadUnitHook.js +1 -20
  48. package/dist/lib/EggAppLoader.js +3 -104
  49. package/dist/lib/EggCompatibleObject.d.ts +2 -20
  50. package/dist/lib/EggCompatibleObject.js +2 -35
  51. package/dist/lib/EggCompatibleProtoImpl.d.ts +1 -24
  52. package/dist/lib/EggCompatibleProtoImpl.js +1 -48
  53. package/dist/lib/EggContextCompatibleHook.d.ts +1 -1
  54. package/dist/lib/EggContextCompatibleHook.js +7 -30
  55. package/dist/lib/EggContextHandler.d.ts +1 -12
  56. package/dist/lib/EggContextHandler.js +1 -27
  57. package/dist/lib/EggContextImpl.js +1 -16
  58. package/dist/lib/EggModuleLoader.js +4 -48
  59. package/dist/lib/EggQualifierProtoHook.js +4 -46
  60. package/dist/lib/ModuleConfigLoader.js +2 -82
  61. package/dist/lib/ModuleHandler.d.ts +1 -16
  62. package/dist/lib/ModuleHandler.js +6 -44
  63. package/dist/lib/Utils.js +1 -31
  64. package/dist/lib/ctx_lifecycle_middleware.d.ts +1 -5
  65. package/dist/lib/ctx_lifecycle_middleware.js +2 -25
  66. package/dist/lib/run_in_background.js +5 -50
  67. package/dist/run_in_background-CEUPBmDB.js +51 -0
  68. package/dist/types-BHg5p4Xk.js +3 -0
  69. package/dist/types-CuoKQV4X.d.ts +7 -0
  70. package/dist/types.d.ts +6 -7
  71. package/dist/types.js +13 -4
  72. package/package.json +11 -11
@@ -1,106 +1,5 @@
1
- import { COMPATIBLE_PROTO_IMPLE_TYPE } from "./EggCompatibleProtoImpl.js";
2
- import { ModuleConfigLoader } from "./ModuleConfigLoader.js";
3
- import { TeggError } from "@eggjs/tegg-metadata";
4
- import { AccessLevel, EggQualifierAttribute, EggType, InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute, ObjectInitType, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
5
- import { ObjectUtils } from "@eggjs/tegg-common-util";
6
- import { Application } from "egg";
7
- import { BackgroundTaskHelper as BackgroundTaskHelper$1 } from "@eggjs/tegg-background-task";
8
- import { EggObjectFactory } from "@eggjs/tegg-dynamic-inject-runtime";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import "../ModuleConfigLoader-CvZLf99E.js";
3
+ import { APP_CLAZZ_BLACK_LIST, CONTEXT_CLAZZ_BLACK_LIST, DEFAULT_APP_CLAZZ, DEFAULT_CONTEXT_CLAZZ, EggAppLoader } from "../EggAppLoader-DFYg65ry.js";
9
4
 
10
- //#region src/lib/EggAppLoader.ts
11
- const APP_CLAZZ_BLACK_LIST = ["eggObjectFactory", "moduleConfigs"];
12
- const CONTEXT_CLAZZ_BLACK_LIST = ["logger"];
13
- const DEFAULT_APP_CLAZZ = [];
14
- const DEFAULT_CONTEXT_CLAZZ = ["user"];
15
- var EggAppLoader = class {
16
- app;
17
- moduleConfigLoader;
18
- constructor(app) {
19
- this.app = app;
20
- this.moduleConfigLoader = new ModuleConfigLoader(this.app);
21
- }
22
- buildClazz(name, eggType) {
23
- const app = this.app;
24
- let func;
25
- if (eggType === EggType.APP) func = function() {
26
- return app[name];
27
- };
28
- else func = function() {
29
- const ctx = app.currentContext;
30
- if (!ctx) throw TeggError.create(`Can not read property \`${name}\` because egg ctx has been destroyed`, "read_after_ctx_destroyed");
31
- return ctx[name];
32
- };
33
- Object.defineProperty(func, "name", {
34
- value: name,
35
- writable: false,
36
- enumerable: false,
37
- configurable: true
38
- });
39
- PrototypeUtil.setIsEggPrototype(func);
40
- PrototypeUtil.setFilePath(func, "mock_file_path");
41
- PrototypeUtil.setProperty(func, {
42
- name,
43
- initType: ObjectInitType.SINGLETON,
44
- accessLevel: AccessLevel.PUBLIC,
45
- protoImplType: COMPATIBLE_PROTO_IMPLE_TYPE
46
- });
47
- QualifierUtil.addProtoQualifier(func, LoadUnitNameQualifierAttribute, "app");
48
- QualifierUtil.addProtoQualifier(func, InitTypeQualifierAttribute, ObjectInitType.SINGLETON);
49
- QualifierUtil.addProtoQualifier(func, EggQualifierAttribute, eggType);
50
- return func;
51
- }
52
- buildAppLoggerClazz(name) {
53
- const app = this.app;
54
- const func = function() {
55
- return app.getLogger(name);
56
- };
57
- Object.defineProperty(func, "name", {
58
- value: name,
59
- writable: false,
60
- enumerable: false,
61
- configurable: true
62
- });
63
- PrototypeUtil.setIsEggPrototype(func);
64
- PrototypeUtil.setFilePath(func, "mock_file_path");
65
- PrototypeUtil.setProperty(func, {
66
- name,
67
- initType: ObjectInitType.SINGLETON,
68
- accessLevel: AccessLevel.PUBLIC,
69
- protoImplType: COMPATIBLE_PROTO_IMPLE_TYPE
70
- });
71
- QualifierUtil.addProtoQualifier(func, LoadUnitNameQualifierAttribute, "app");
72
- QualifierUtil.addProtoQualifier(func, InitTypeQualifierAttribute, ObjectInitType.SINGLETON);
73
- QualifierUtil.addProtoQualifier(func, EggQualifierAttribute, EggType.APP);
74
- return func;
75
- }
76
- getLoggerNames(ctxClazzNames, singletonClazzNames) {
77
- return Array.from(this.app.loggers.keys()).filter((t) => !ctxClazzNames.includes(t) && !singletonClazzNames.includes(t));
78
- }
79
- async load() {
80
- const app = this.app;
81
- const appProperties = ObjectUtils.getProperties(app);
82
- const contextProperties = ObjectUtils.getProperties(app.context);
83
- const allSingletonClazzNameSet = new Set([...appProperties, ...DEFAULT_APP_CLAZZ]);
84
- APP_CLAZZ_BLACK_LIST.forEach((t) => allSingletonClazzNameSet.delete(t));
85
- const allSingletonClazzNames = Array.from(allSingletonClazzNameSet);
86
- const allContextClazzNamesSet = new Set([...contextProperties, ...DEFAULT_CONTEXT_CLAZZ]);
87
- CONTEXT_CLAZZ_BLACK_LIST.forEach((t) => allContextClazzNamesSet.delete(t));
88
- const allContextClazzNames = Array.from(allContextClazzNamesSet);
89
- const loggerNames = this.getLoggerNames(allContextClazzNames, allSingletonClazzNames);
90
- const allSingletonClazzs = allSingletonClazzNames.map((name) => this.buildClazz(name, EggType.APP));
91
- const allContextClazzs = allContextClazzNames.map((name) => this.buildClazz(name, EggType.CONTEXT));
92
- const appLoggerClazzs = loggerNames.map((name) => this.buildAppLoggerClazz(name));
93
- const moduleConfigList = this.moduleConfigLoader.loadModuleConfigList();
94
- return [
95
- ...allSingletonClazzs,
96
- ...allContextClazzs,
97
- ...appLoggerClazzs,
98
- ...moduleConfigList,
99
- BackgroundTaskHelper$1,
100
- EggObjectFactory
101
- ];
102
- }
103
- };
104
-
105
- //#endregion
106
5
  export { APP_CLAZZ_BLACK_LIST, CONTEXT_CLAZZ_BLACK_LIST, DEFAULT_APP_CLAZZ, DEFAULT_CONTEXT_CLAZZ, EggAppLoader };
@@ -1,21 +1,3 @@
1
- import { EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl.js";
2
- import { EggPrototype } from "@eggjs/tegg-metadata";
3
- import { EggObjectName } from "@eggjs/tegg";
4
- import { EggObject } from "@eggjs/tegg-runtime";
5
-
6
- //#region src/lib/EggCompatibleObject.d.ts
7
- declare const OBJ: unique symbol;
8
- declare class EggCompatibleObject implements EggObject {
9
- readonly isReady: boolean;
10
- private [OBJ];
11
- readonly proto: EggCompatibleProtoImpl;
12
- readonly name: EggObjectName;
13
- readonly id: string;
14
- readonly isContext: boolean;
15
- constructor(name: EggObjectName, proto: EggCompatibleProtoImpl);
16
- get obj(): object;
17
- injectProperty(): void;
18
- static createObject(name: EggObjectName, proto: EggPrototype): Promise<EggCompatibleObject>;
19
- }
20
- //#endregion
1
+ import "../EggCompatibleProtoImpl-DpacWKFB.js";
2
+ import { EggCompatibleObject } from "../EggCompatibleObject-lzUCfsIY.js";
21
3
  export { EggCompatibleObject };
@@ -1,37 +1,4 @@
1
- import { EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl.js";
2
- import "@eggjs/tegg-metadata";
3
- import { EggQualifierAttribute, EggType, IdenticalUtil } from "@eggjs/tegg";
4
- import { EggObjectFactory } from "@eggjs/tegg-runtime";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import { EggCompatibleObject } from "../EggCompatibleObject-XfIZyirS.js";
5
3
 
6
- //#region src/lib/EggCompatibleObject.ts
7
- const OBJ = Symbol("EggCompatibleObject#obj");
8
- var EggCompatibleObject = class EggCompatibleObject {
9
- isReady = true;
10
- [OBJ];
11
- proto;
12
- name;
13
- id;
14
- isContext;
15
- constructor(name, proto) {
16
- this.proto = proto;
17
- this.name = name;
18
- this.id = IdenticalUtil.createObjectId(this.proto.id);
19
- this.isContext = this.proto.verifyQualifier({
20
- value: EggType.CONTEXT,
21
- attribute: EggQualifierAttribute
22
- });
23
- }
24
- get obj() {
25
- if (this.isContext) return this.proto.constructEggObject();
26
- if (!this[OBJ]) this[OBJ] = this.proto.constructEggObject();
27
- return this[OBJ];
28
- }
29
- injectProperty() {}
30
- static async createObject(name, proto) {
31
- return new EggCompatibleObject(name, proto);
32
- }
33
- };
34
- EggObjectFactory.registerEggObjectCreateMethod(EggCompatibleProtoImpl, EggCompatibleObject.createObject);
35
-
36
- //#endregion
37
4
  export { EggCompatibleObject };
@@ -1,25 +1,2 @@
1
- import { EggPrototype, EggPrototypeLifecycleContext, InjectObjectProto } from "@eggjs/tegg-metadata";
2
- import { AccessLevel, EggProtoImplClass, EggPrototypeName, Id, MetaDataKey, ObjectInitTypeLike, QualifierInfo, QualifierValue } from "@eggjs/tegg";
3
-
4
- //#region src/lib/EggCompatibleProtoImpl.d.ts
5
- declare const COMPATIBLE_PROTO_IMPLE_TYPE = "EGG_COMPATIBLE";
6
- declare class EggCompatibleProtoImpl implements EggPrototype {
7
- [key: symbol]: PropertyDescriptor;
8
- private readonly clazz;
9
- private readonly qualifiers;
10
- readonly id: string;
11
- readonly name: EggPrototypeName;
12
- readonly initType: ObjectInitTypeLike;
13
- readonly accessLevel: AccessLevel;
14
- readonly injectObjects: InjectObjectProto[];
15
- readonly loadUnitId: Id;
16
- constructor(id: string, name: EggPrototypeName, clazz: EggProtoImplClass, initType: ObjectInitTypeLike, loadUnitId: Id, qualifiers: QualifierInfo[]);
17
- verifyQualifiers(qualifiers: QualifierInfo[]): boolean;
18
- verifyQualifier(qualifier: QualifierInfo): boolean;
19
- getQualifier(attribute: string): QualifierValue | undefined;
20
- constructEggObject(): object;
21
- getMetaData<T>(metadataKey: MetaDataKey): T | undefined;
22
- static create(ctx: EggPrototypeLifecycleContext): EggPrototype;
23
- }
24
- //#endregion
1
+ import { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl } from "../EggCompatibleProtoImpl-DpacWKFB.js";
25
2
  export { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl };
@@ -1,50 +1,3 @@
1
- import "@eggjs/tegg-metadata";
2
- import { AccessLevel, IdenticalUtil, MetadataUtil, QualifierUtil } from "@eggjs/tegg";
1
+ import { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl } from "../EggCompatibleProtoImpl-CPxLvSu4.js";
3
2
 
4
- //#region src/lib/EggCompatibleProtoImpl.ts
5
- const COMPATIBLE_PROTO_IMPLE_TYPE = "EGG_COMPATIBLE";
6
- var EggCompatibleProtoImpl = class EggCompatibleProtoImpl {
7
- clazz;
8
- qualifiers;
9
- id;
10
- name;
11
- initType;
12
- accessLevel;
13
- injectObjects;
14
- loadUnitId;
15
- constructor(id, name, clazz, initType, loadUnitId, qualifiers) {
16
- this.id = id;
17
- this.clazz = clazz;
18
- this.name = name;
19
- this.initType = initType;
20
- this.accessLevel = AccessLevel.PUBLIC;
21
- this.injectObjects = [];
22
- this.loadUnitId = loadUnitId;
23
- this.qualifiers = qualifiers;
24
- }
25
- verifyQualifiers(qualifiers) {
26
- for (const qualifier of qualifiers) if (!this.verifyQualifier(qualifier)) return false;
27
- return true;
28
- }
29
- verifyQualifier(qualifier) {
30
- return this.qualifiers.find((t) => t.attribute === qualifier.attribute)?.value === qualifier.value;
31
- }
32
- getQualifier(attribute) {
33
- return this.qualifiers.find((t) => t.attribute === attribute)?.value;
34
- }
35
- constructEggObject() {
36
- return Reflect.apply(this.clazz, null, []);
37
- }
38
- getMetaData(metadataKey) {
39
- return MetadataUtil.getMetaData(metadataKey, this.clazz);
40
- }
41
- static create(ctx) {
42
- const { clazz, loadUnit } = ctx;
43
- const name = ctx.prototypeInfo.name;
44
- const id = IdenticalUtil.createProtoId(loadUnit.id, name);
45
- return new EggCompatibleProtoImpl(id, name, clazz, ctx.prototypeInfo.initType, loadUnit.id, QualifierUtil.mergeQualifiers(QualifierUtil.getProtoQualifiers(clazz), ctx.prototypeInfo.qualifiers ?? []));
46
- }
47
- };
48
-
49
- //#endregion
50
3
  export { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl };
@@ -1,4 +1,4 @@
1
- import { ModuleHandler } from "./ModuleHandler.js";
1
+ import { ModuleHandler } from "../ModuleHandler-Dyx7JGj-.js";
2
2
  import { LifecycleHook } from "@eggjs/tegg";
3
3
  import { EggContext, EggContextLifecycleContext } from "@eggjs/tegg-runtime";
4
4
 
@@ -1,32 +1,9 @@
1
- import "./ModuleHandler.js";
2
- import "@eggjs/tegg-metadata";
3
- import { BackgroundTaskHelper, ObjectInitType, PrototypeUtil } from "@eggjs/tegg";
4
- import { EggContainerFactory } from "@eggjs/tegg-runtime";
5
- import { ROOT_PROTO } from "@eggjs/egg-module-common";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import "../ModuleConfigLoader-CvZLf99E.js";
3
+ import "../EggAppLoader-DFYg65ry.js";
4
+ import "../EggModuleLoader-CCfQMmp5.js";
5
+ import "../CompatibleUtil-CNhydb0E.js";
6
+ import "../ModuleHandler-fKcUqWca.js";
7
+ import { EggContextCompatibleHook } from "../EggContextCompatibleHook-eFfN2xm6.js";
6
8
 
7
- //#region src/lib/EggContextCompatibleHook.ts
8
- var EggContextCompatibleHook = class {
9
- moduleHandler;
10
- requestProtoList = [];
11
- constructor(moduleHandler) {
12
- this.moduleHandler = moduleHandler;
13
- for (const loadUnitInstance of this.moduleHandler.loadUnitInstances) {
14
- const iterator = loadUnitInstance.loadUnit.iterateEggPrototype();
15
- for (const proto of iterator) if (proto.initType === ObjectInitType.CONTEXT) this.requestProtoList.push(proto);
16
- }
17
- }
18
- async preCreate(_, ctx) {
19
- if (!ctx.get(ROOT_PROTO)) for (const proto of this.requestProtoList) ctx.addProtoToCreate(proto.name, proto);
20
- else {
21
- const protoObj = PrototypeUtil.getClazzProto(BackgroundTaskHelper);
22
- await EggContainerFactory.getOrCreateEggObject(protoObj);
23
- }
24
- }
25
- async postCreate(_, ctx) {
26
- const rootProto = ctx.get(ROOT_PROTO);
27
- if (rootProto) await EggContainerFactory.getOrCreateEggObject(rootProto);
28
- }
29
- };
30
-
31
- //#endregion
32
9
  export { EggContextCompatibleHook };
@@ -1,13 +1,2 @@
1
- import { EggContext } from "@eggjs/tegg-runtime";
2
- import { Application } from "egg";
3
-
4
- //#region src/lib/EggContextHandler.d.ts
5
- declare class EggContextHandler {
6
- private readonly app;
7
- constructor(app: Application);
8
- getContextCallback(): EggContext | undefined;
9
- run<R>(eggContext: EggContext, fn: () => Promise<R>): Promise<R>;
10
- register(): void;
11
- }
12
- //#endregion
1
+ import { EggContextHandler } from "../EggContextHandler-vGi67He5.js";
13
2
  export { EggContextHandler };
@@ -1,29 +1,3 @@
1
- import { ContextHandler } from "@eggjs/tegg-runtime";
2
- import { EGG_CONTEXT } from "@eggjs/egg-module-common";
3
- import "egg";
1
+ import { EggContextHandler } from "../EggContextHandler-D8gfTbZs.js";
4
2
 
5
- //#region src/lib/EggContextHandler.ts
6
- var EggContextHandler = class {
7
- app;
8
- constructor(app) {
9
- this.app = app;
10
- }
11
- getContextCallback() {
12
- return this.app.currentContext?.teggContext;
13
- }
14
- async run(eggContext, fn) {
15
- const ctx = eggContext.get(EGG_CONTEXT);
16
- return await this.app.ctxStorage.run(ctx, fn);
17
- }
18
- register() {
19
- ContextHandler.getContextCallback = () => {
20
- return this.getContextCallback();
21
- };
22
- ContextHandler.runInContextCallback = async (context, fn) => {
23
- return await this.run(context, fn);
24
- };
25
- }
26
- };
27
-
28
- //#endregion
29
3
  export { EggContextHandler };
@@ -1,18 +1,3 @@
1
- import { IdenticalUtil } from "@eggjs/tegg";
2
- import { AbstractEggContext } from "@eggjs/tegg-runtime";
3
- import { EGG_CONTEXT, TEGG_CONTEXT } from "@eggjs/egg-module-common";
1
+ import { EggContextImpl } from "../EggContextImpl-DkCLPTzT.js";
4
2
 
5
- //#region src/lib/EggContextImpl.ts
6
- var EggContextImpl = class extends AbstractEggContext {
7
- id;
8
- constructor(ctx) {
9
- super();
10
- this.set(EGG_CONTEXT, ctx);
11
- ctx[TEGG_CONTEXT] = this;
12
- const tracer = ctx.tracer;
13
- this.id = IdenticalUtil.createContextId(tracer?.traceId);
14
- }
15
- };
16
-
17
- //#endregion
18
3
  export { EggContextImpl };
@@ -1,50 +1,6 @@
1
- import { EggAppLoader } from "./EggAppLoader.js";
2
- import { EggLoadUnitType, GlobalGraph, LoadUnitFactory, ModuleDescriptorDumper } from "@eggjs/tegg-metadata";
3
- import { Application } from "egg";
4
- import { LoaderFactory } from "@eggjs/tegg-loader";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import "../ModuleConfigLoader-CvZLf99E.js";
3
+ import "../EggAppLoader-DFYg65ry.js";
4
+ import { EggModuleLoader } from "../EggModuleLoader-CCfQMmp5.js";
5
5
 
6
- //#region src/lib/EggModuleLoader.ts
7
- var EggModuleLoader = class {
8
- app;
9
- globalGraph;
10
- constructor(app) {
11
- this.app = app;
12
- }
13
- async loadApp() {
14
- const loader = new EggAppLoader(this.app);
15
- const loadUnit = await LoadUnitFactory.createLoadUnit(this.app.baseDir, EggLoadUnitType.APP, loader);
16
- this.app.moduleHandler.loadUnits.push(loadUnit);
17
- }
18
- async buildAppGraph() {
19
- for (const plugin of Object.values(this.app.plugins)) {
20
- if (!plugin.enable) continue;
21
- const modulePlugin = this.app.moduleReferences.find((t) => t.path === plugin.path);
22
- if (modulePlugin) modulePlugin.optional = false;
23
- }
24
- const moduleDescriptors = await LoaderFactory.loadApp(this.app.moduleReferences);
25
- for (const moduleDescriptor of moduleDescriptors) ModuleDescriptorDumper.dump(moduleDescriptor, { dumpDir: this.app.baseDir }).catch((e) => {
26
- e.message = "dump module descriptor failed: " + e.message;
27
- this.app.logger.warn(e);
28
- });
29
- return await GlobalGraph.create(moduleDescriptors);
30
- }
31
- async loadModule() {
32
- this.globalGraph.build();
33
- this.globalGraph.sort();
34
- const moduleConfigList = this.globalGraph.moduleConfigList;
35
- for (const moduleConfig of moduleConfigList) {
36
- const modulePath = moduleConfig.path;
37
- const loader = LoaderFactory.createLoader(modulePath, EggLoadUnitType.MODULE);
38
- const loadUnit = await LoadUnitFactory.createLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
39
- this.app.moduleHandler.loadUnits.push(loadUnit);
40
- }
41
- }
42
- async load() {
43
- GlobalGraph.instance = this.globalGraph = await this.buildAppGraph();
44
- await this.loadApp();
45
- await this.loadModule();
46
- }
47
- };
48
-
49
- //#endregion
50
6
  export { EggModuleLoader };
@@ -1,48 +1,6 @@
1
- import { APP_CLAZZ_BLACK_LIST, CONTEXT_CLAZZ_BLACK_LIST, DEFAULT_APP_CLAZZ, DEFAULT_CONTEXT_CLAZZ } from "./EggAppLoader.js";
2
- import { debuglog } from "node:util";
3
- import "@eggjs/tegg-metadata";
4
- import { EggQualifierAttribute, EggType, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
5
- import { ObjectUtils } from "@eggjs/tegg-common-util";
6
- import { Application } from "egg";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import "../ModuleConfigLoader-CvZLf99E.js";
3
+ import "../EggAppLoader-DFYg65ry.js";
4
+ import { EggQualifierProtoHook } from "../EggQualifierProtoHook-D5jNm-1y.js";
7
5
 
8
- //#region src/lib/EggQualifierProtoHook.ts
9
- const debug = debuglog("tegg/plugin/tegg/lib/EggQualifierProtoHook");
10
- var EggQualifierProtoHook = class {
11
- app;
12
- constructor(app) {
13
- this.app = app;
14
- }
15
- async preCreate(ctx) {
16
- const clazzList = await ctx.loader.load();
17
- const appProperties = ObjectUtils.getProperties(this.app);
18
- const ctxProperties = ObjectUtils.getProperties(this.app.context);
19
- if (debug.enabled) debug("preCreate, get clazzList:%o, appProperties:%o, ctxProperties:%o, from unitPath:%o", clazzList.map((t) => t.name), appProperties.length, ctxProperties.length, ctx.unitPath);
20
- for (const clazz of clazzList) {
21
- const inbjectObjects = PrototypeUtil.getInjectObjects(clazz) || [];
22
- if (debug.enabled && inbjectObjects.length > 0) debug("preCreate, get injectObjects:%o, from clazz:%o, from unitPath:%o", inbjectObjects.map((t) => t.refName), clazz.name, ctx.unitPath);
23
- for (const injectObject of inbjectObjects) {
24
- if (QualifierUtil.getProperQualifiers(clazz, injectObject.refName).find((t) => t.attribute === EggQualifierAttribute)) continue;
25
- if (this.isCtxObject(injectObject.objName, ctxProperties)) QualifierUtil.addProperQualifier(clazz, injectObject.refName, EggQualifierAttribute, EggType.CONTEXT);
26
- else if (this.isAppObject(injectObject.objName, appProperties)) {
27
- QualifierUtil.addProperQualifier(clazz, injectObject.refName, EggQualifierAttribute, EggType.APP);
28
- debug("preCreate, add proper qualifier:%o to clazz:%o, from unitPath:%o", injectObject.refName, clazz.name, ctx.unitPath);
29
- }
30
- }
31
- }
32
- }
33
- isAppObject(name, appProperties) {
34
- name = String(name);
35
- if (APP_CLAZZ_BLACK_LIST.includes(name)) return false;
36
- if (DEFAULT_APP_CLAZZ.includes(name)) return true;
37
- return appProperties.includes(name);
38
- }
39
- isCtxObject(name, ctxProperties) {
40
- name = String(name);
41
- if (CONTEXT_CLAZZ_BLACK_LIST.includes(name)) return false;
42
- if (DEFAULT_CONTEXT_CLAZZ.includes(name)) return true;
43
- return ctxProperties.includes(name);
44
- }
45
- };
46
-
47
- //#endregion
48
6
  export { EggQualifierProtoHook };
@@ -1,84 +1,4 @@
1
- import { COMPATIBLE_PROTO_IMPLE_TYPE } from "./EggCompatibleProtoImpl.js";
2
- import { AccessLevel, ConfigSourceQualifierAttribute, EggQualifierAttribute, EggType, InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute, ModuleConfigs, ObjectInitType, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
3
- import { Application } from "egg";
4
- import { ModuleConfigUtil } from "@eggjs/tegg/helper";
5
- import { extend } from "extend2";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import { ModuleConfigLoader } from "../ModuleConfigLoader-CvZLf99E.js";
6
3
 
7
- //#region src/lib/ModuleConfigLoader.ts
8
- var ModuleConfigLoader = class {
9
- app;
10
- constructor(app) {
11
- this.app = app;
12
- }
13
- loadModuleConfigs(moduleConfigMap) {
14
- const moduleConfigs = new ModuleConfigs(moduleConfigMap);
15
- const func = function() {
16
- return moduleConfigs;
17
- };
18
- const name = "moduleConfigs";
19
- Object.defineProperty(func, "name", {
20
- value: name,
21
- writable: false,
22
- enumerable: false,
23
- configurable: true
24
- });
25
- PrototypeUtil.setIsEggPrototype(func);
26
- PrototypeUtil.setFilePath(func, "mock_file_path");
27
- PrototypeUtil.setProperty(func, {
28
- name,
29
- initType: ObjectInitType.SINGLETON,
30
- accessLevel: AccessLevel.PUBLIC,
31
- protoImplType: COMPATIBLE_PROTO_IMPLE_TYPE
32
- });
33
- QualifierUtil.addProtoQualifier(func, LoadUnitNameQualifierAttribute, "app");
34
- QualifierUtil.addProtoQualifier(func, InitTypeQualifierAttribute, ObjectInitType.SINGLETON);
35
- QualifierUtil.addProtoQualifier(func, EggQualifierAttribute, EggType.APP);
36
- return func;
37
- }
38
- loadModuleConfigList() {
39
- const result = [];
40
- const moduleConfigMap = {};
41
- for (const reference of this.app.moduleReferences) {
42
- const moduleName = ModuleConfigUtil.readModuleNameSync(reference.path);
43
- const defaultConfig = ModuleConfigUtil.loadModuleConfigSync(reference.path, void 0, this.app.config.env);
44
- const config = extend(true, {}, defaultConfig, this.app.moduleConfigs[moduleName]?.config);
45
- moduleConfigMap[moduleName] = {
46
- name: moduleName,
47
- reference: {
48
- name: moduleName,
49
- path: reference.path
50
- },
51
- config
52
- };
53
- const func = function() {
54
- return config;
55
- };
56
- const name = "moduleConfig";
57
- Object.defineProperty(func, "name", {
58
- value: name,
59
- writable: false,
60
- enumerable: false,
61
- configurable: true
62
- });
63
- PrototypeUtil.setIsEggPrototype(func);
64
- PrototypeUtil.setFilePath(func, "mock_file_path");
65
- PrototypeUtil.setProperty(func, {
66
- name,
67
- initType: ObjectInitType.SINGLETON,
68
- accessLevel: AccessLevel.PUBLIC,
69
- protoImplType: COMPATIBLE_PROTO_IMPLE_TYPE
70
- });
71
- QualifierUtil.addProtoQualifier(func, LoadUnitNameQualifierAttribute, "app");
72
- QualifierUtil.addProtoQualifier(func, InitTypeQualifierAttribute, ObjectInitType.SINGLETON);
73
- QualifierUtil.addProtoQualifier(func, EggQualifierAttribute, EggType.APP);
74
- QualifierUtil.addProtoQualifier(func, ConfigSourceQualifierAttribute, moduleName);
75
- result.push(func);
76
- }
77
- const moduleConfigs = this.loadModuleConfigs(moduleConfigMap);
78
- result.push(moduleConfigs);
79
- return result;
80
- }
81
- };
82
-
83
- //#endregion
84
4
  export { ModuleConfigLoader };
@@ -1,17 +1,2 @@
1
- import { LoadUnit } from "@eggjs/tegg-metadata";
2
- import { LoadUnitInstance } from "@eggjs/tegg-runtime";
3
- import { Base } from "sdk-base";
4
- import { Application } from "egg";
5
-
6
- //#region src/lib/ModuleHandler.d.ts
7
- declare class ModuleHandler extends Base {
8
- loadUnits: LoadUnit[];
9
- loadUnitInstances: LoadUnitInstance[];
10
- private readonly loadUnitLoader;
11
- private readonly app;
12
- constructor(app: Application);
13
- init(): Promise<void>;
14
- destroy(): Promise<void>;
15
- }
16
- //#endregion
1
+ import { ModuleHandler } from "../ModuleHandler-Dyx7JGj-.js";
17
2
  export { ModuleHandler };
@@ -1,46 +1,8 @@
1
- import { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl.js";
2
- import { EggModuleLoader } from "./EggModuleLoader.js";
3
- import { CompatibleUtil } from "./CompatibleUtil.js";
4
- import { EggLoadUnitType, LoadUnitFactory } from "@eggjs/tegg-metadata";
5
- import { LoadUnitInstanceFactory } from "@eggjs/tegg-runtime";
6
- import { Base } from "sdk-base";
7
- import { Application, Context } from "egg";
1
+ import "../EggCompatibleProtoImpl-CPxLvSu4.js";
2
+ import "../ModuleConfigLoader-CvZLf99E.js";
3
+ import "../EggAppLoader-DFYg65ry.js";
4
+ import "../EggModuleLoader-CCfQMmp5.js";
5
+ import "../CompatibleUtil-CNhydb0E.js";
6
+ import { ModuleHandler } from "../ModuleHandler-fKcUqWca.js";
8
7
 
9
- //#region src/lib/ModuleHandler.ts
10
- var ModuleHandler = class extends Base {
11
- loadUnits = [];
12
- loadUnitInstances = [];
13
- loadUnitLoader;
14
- app;
15
- constructor(app) {
16
- super();
17
- this.app = app;
18
- this.loadUnitLoader = new EggModuleLoader(this.app);
19
- }
20
- async init() {
21
- try {
22
- this.app.eggPrototypeCreatorFactory.registerPrototypeCreator(COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl.create);
23
- await this.loadUnitLoader.load();
24
- const instances = [];
25
- this.app.module = {};
26
- for (const loadUnit of this.loadUnits) {
27
- const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
28
- if (instance.loadUnit.type !== EggLoadUnitType.APP) CompatibleUtil.appCompatible(this.app, instance);
29
- instances.push(instance);
30
- }
31
- CompatibleUtil.contextModuleCompatible(this.app.context, instances);
32
- this.loadUnitInstances = instances;
33
- this.ready(true);
34
- } catch (e) {
35
- this.ready(e);
36
- throw e;
37
- }
38
- }
39
- async destroy() {
40
- if (this.loadUnitInstances) for (const instance of this.loadUnitInstances) await LoadUnitInstanceFactory.destroyLoadUnitInstance(instance);
41
- if (this.loadUnits) for (const loadUnit of this.loadUnits) await LoadUnitFactory.destroyLoadUnit(loadUnit);
42
- }
43
- };
44
-
45
- //#endregion
46
8
  export { ModuleHandler };
package/dist/lib/Utils.js CHANGED
@@ -1,33 +1,3 @@
1
- //#region src/lib/Utils.ts
2
- function prepareObjectStackTrace(_, stack) {
3
- return stack;
4
- }
5
- function getCalleeFromStack(withLine, stackIndex) {
6
- stackIndex = stackIndex === void 0 ? 2 : stackIndex;
7
- const limit = Error.stackTraceLimit;
8
- const prep = Error.prepareStackTrace;
9
- Error.prepareStackTrace = prepareObjectStackTrace;
10
- Error.stackTraceLimit = 5;
11
- const obj = {};
12
- Error.captureStackTrace(obj);
13
- let callSite = obj.stack[stackIndex];
14
- let fileName;
15
- /* istanbul ignore else */
16
- if (callSite) {
17
- fileName = callSite.getFileName();
18
- /* istanbul ignore if */
19
- if (fileName && fileName.endsWith("egg-mock/lib/app.js")) {
20
- callSite = obj.stack[stackIndex + 1];
21
- fileName = callSite.getFileName();
22
- }
23
- }
24
- Error.prepareStackTrace = prep;
25
- Error.stackTraceLimit = limit;
26
- /* istanbul ignore if */
27
- if (!callSite || !fileName) return "<anonymous>";
28
- if (!withLine) return fileName;
29
- return `${fileName}:${callSite.getLineNumber()}:${callSite.getColumnNumber()}`;
30
- }
1
+ import { getCalleeFromStack } from "../Utils-11aRpnkd.js";
31
2
 
32
- //#endregion
33
3
  export { getCalleeFromStack };