@eggjs/tegg-plugin 4.0.0-beta.8 → 4.0.0-beta.9
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.
- package/dist/app/extend/application.d.ts +50 -4
- package/dist/app/extend/application.js +79 -10
- package/dist/app/extend/application.unittest.d.ts +22 -2
- package/dist/app/extend/application.unittest.js +55 -4
- package/dist/app/extend/context.d.ts +20 -2
- package/dist/app/extend/context.js +35 -5
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +2 -5
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +4 -9
- package/dist/app.d.ts +16 -21
- package/dist/app.js +63 -65
- package/dist/index.d.ts +3 -6
- package/dist/index.js +4 -15
- package/dist/lib/AppLoadUnit.d.ts +19 -2
- package/dist/lib/AppLoadUnit.js +90 -3
- package/dist/lib/AppLoadUnitInstance.d.ts +20 -2
- package/dist/lib/AppLoadUnitInstance.js +82 -3
- package/dist/lib/CompatibleUtil.d.ts +13 -17
- package/dist/lib/CompatibleUtil.js +95 -3
- package/dist/lib/ConfigSourceLoadUnitHook.d.ts +4 -9
- package/dist/lib/ConfigSourceLoadUnitHook.js +21 -3
- package/dist/lib/EggAppLoader.d.ts +15 -19
- package/dist/lib/EggAppLoader.js +128 -5
- package/dist/lib/EggCompatibleObject.d.ts +18 -3
- package/dist/lib/EggCompatibleObject.js +42 -4
- package/dist/lib/EggCompatibleProtoImpl.d.ts +21 -2
- package/dist/lib/EggCompatibleProtoImpl.js +52 -3
- package/dist/lib/EggContextCompatibleHook.d.ts +9 -13
- package/dist/lib/EggContextCompatibleHook.js +44 -9
- package/dist/lib/EggContextHandler.d.ts +9 -2
- package/dist/lib/EggContextHandler.js +26 -3
- package/dist/lib/EggContextImpl.d.ts +5 -9
- package/dist/lib/EggContextImpl.js +15 -3
- package/dist/lib/EggModuleLoader.d.ts +10 -14
- package/dist/lib/EggModuleLoader.js +54 -6
- package/dist/lib/EggQualifierProtoHook.d.ts +9 -13
- package/dist/lib/EggQualifierProtoHook.js +62 -6
- package/dist/lib/ModuleConfigLoader.d.ts +7 -11
- package/dist/lib/ModuleConfigLoader.js +81 -4
- package/dist/lib/ModuleHandler.d.ts +13 -2
- package/dist/lib/ModuleHandler.js +53 -8
- package/dist/lib/Utils.d.ts +1 -4
- package/dist/lib/Utils.js +36 -3
- package/dist/lib/ctx_lifecycle_middleware.d.ts +2 -2
- package/dist/lib/ctx_lifecycle_middleware.js +33 -4
- package/dist/lib/run_in_background.d.ts +3 -7
- package/dist/lib/run_in_background.js +58 -7
- package/dist/types.d.ts +8 -6
- package/dist/types.js +5 -15
- package/package.json +12 -12
- package/dist/AppLoadUnit-BOWdS4O9.d.ts +0 -23
- package/dist/AppLoadUnit-uyHgElRL.js +0 -78
- package/dist/AppLoadUnitInstance-4Z_vSQV3.js +0 -69
- package/dist/AppLoadUnitInstance-DQ-DxlmR.d.ts +0 -24
- package/dist/CompatibleUtil-CNhydb0E.js +0 -96
- package/dist/ConfigSourceLoadUnitHook-BV-R31vA.js +0 -22
- package/dist/EggAppLoader-DFYg65ry.js +0 -106
- package/dist/EggCompatibleObject-XfIZyirS.js +0 -37
- package/dist/EggCompatibleObject-lzUCfsIY.d.ts +0 -21
- package/dist/EggCompatibleProtoImpl-CPxLvSu4.js +0 -50
- package/dist/EggCompatibleProtoImpl-DpacWKFB.d.ts +0 -25
- package/dist/EggContextCompatibleHook-eFfN2xm6.js +0 -31
- package/dist/EggContextHandler-D8gfTbZs.js +0 -29
- package/dist/EggContextHandler-vGi67He5.d.ts +0 -13
- package/dist/EggContextImpl-DkCLPTzT.js +0 -18
- package/dist/EggModuleLoader-CCfQMmp5.js +0 -50
- package/dist/EggQualifierProtoHook-D5jNm-1y.js +0 -48
- package/dist/ModuleConfigLoader-CvZLf99E.js +0 -84
- package/dist/ModuleHandler-Dyx7JGj-.d.ts +0 -17
- package/dist/ModuleHandler-fKcUqWca.js +0 -46
- package/dist/Utils-11aRpnkd.js +0 -33
- package/dist/application-Ccljinuy.d.ts +0 -57
- package/dist/application-DFI1junS.js +0 -70
- package/dist/application.unittest-Cmia71Fx.js +0 -43
- package/dist/application.unittest-CpoCu6-E.d.ts +0 -26
- package/dist/context-BWYE1dif.js +0 -30
- package/dist/context-BoIt2G5h.d.ts +0 -24
- package/dist/ctx_lifecycle_middleware-CIeSrbVY.js +0 -27
- package/dist/ctx_lifecycle_middleware-DV7uN5PG.d.ts +0 -6
- package/dist/run_in_background-CEUPBmDB.js +0 -51
- package/dist/types-BHg5p4Xk.js +0 -3
- package/dist/types-CuoKQV4X.d.ts +0 -7
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { COMPATIBLE_PROTO_IMPLE_TYPE } from "./EggCompatibleProtoImpl-CPxLvSu4.js";
|
|
2
|
-
import { ModuleConfigLoader } from "./ModuleConfigLoader-CvZLf99E.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";
|
|
9
|
-
|
|
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
|
-
export { APP_CLAZZ_BLACK_LIST, CONTEXT_CLAZZ_BLACK_LIST, DEFAULT_APP_CLAZZ, DEFAULT_CONTEXT_CLAZZ, EggAppLoader };
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl-CPxLvSu4.js";
|
|
2
|
-
import "@eggjs/tegg-metadata";
|
|
3
|
-
import { EggQualifierAttribute, EggType, IdenticalUtil } from "@eggjs/tegg";
|
|
4
|
-
import { EggObjectFactory } from "@eggjs/tegg-runtime";
|
|
5
|
-
|
|
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
|
-
export { EggCompatibleObject };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl-DpacWKFB.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
|
|
21
|
-
export { EggCompatibleObject };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import "@eggjs/tegg-metadata";
|
|
2
|
-
import { AccessLevel, IdenticalUtil, MetadataUtil, QualifierUtil } from "@eggjs/tegg";
|
|
3
|
-
|
|
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
|
-
export { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl };
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
|
25
|
-
export { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import "@eggjs/tegg-metadata";
|
|
2
|
-
import { BackgroundTaskHelper, ObjectInitType, PrototypeUtil } from "@eggjs/tegg";
|
|
3
|
-
import { EggContainerFactory } from "@eggjs/tegg-runtime";
|
|
4
|
-
import { ROOT_PROTO } from "@eggjs/egg-module-common";
|
|
5
|
-
|
|
6
|
-
//#region src/lib/EggContextCompatibleHook.ts
|
|
7
|
-
var EggContextCompatibleHook = class {
|
|
8
|
-
moduleHandler;
|
|
9
|
-
requestProtoList = [];
|
|
10
|
-
constructor(moduleHandler) {
|
|
11
|
-
this.moduleHandler = moduleHandler;
|
|
12
|
-
for (const loadUnitInstance of this.moduleHandler.loadUnitInstances) {
|
|
13
|
-
const iterator = loadUnitInstance.loadUnit.iterateEggPrototype();
|
|
14
|
-
for (const proto of iterator) if (proto.initType === ObjectInitType.CONTEXT) this.requestProtoList.push(proto);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
async preCreate(_, ctx) {
|
|
18
|
-
if (!ctx.get(ROOT_PROTO)) for (const proto of this.requestProtoList) ctx.addProtoToCreate(proto.name, proto);
|
|
19
|
-
else {
|
|
20
|
-
const protoObj = PrototypeUtil.getClazzProto(BackgroundTaskHelper);
|
|
21
|
-
await EggContainerFactory.getOrCreateEggObject(protoObj);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
async postCreate(_, ctx) {
|
|
25
|
-
const rootProto = ctx.get(ROOT_PROTO);
|
|
26
|
-
if (rootProto) await EggContainerFactory.getOrCreateEggObject(rootProto);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
export { EggContextCompatibleHook };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ContextHandler } from "@eggjs/tegg-runtime";
|
|
2
|
-
import { EGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
3
|
-
import "egg";
|
|
4
|
-
|
|
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
|
-
export { EggContextHandler };
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
|
13
|
-
export { EggContextHandler };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { IdenticalUtil } from "@eggjs/tegg";
|
|
2
|
-
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
3
|
-
import { EGG_CONTEXT, TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
4
|
-
|
|
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
|
-
export { EggContextImpl };
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { EggAppLoader } from "./EggAppLoader-DFYg65ry.js";
|
|
2
|
-
import { EggLoadUnitType, GlobalGraph, LoadUnitFactory, ModuleDescriptorDumper } from "@eggjs/tegg-metadata";
|
|
3
|
-
import { Application } from "egg";
|
|
4
|
-
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
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
|
-
export { EggModuleLoader };
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { APP_CLAZZ_BLACK_LIST, CONTEXT_CLAZZ_BLACK_LIST, DEFAULT_APP_CLAZZ, DEFAULT_CONTEXT_CLAZZ } from "./EggAppLoader-DFYg65ry.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";
|
|
7
|
-
|
|
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
|
-
export { EggQualifierProtoHook };
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { COMPATIBLE_PROTO_IMPLE_TYPE } from "./EggCompatibleProtoImpl-CPxLvSu4.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";
|
|
6
|
-
|
|
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
|
-
export { ModuleConfigLoader };
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
|
17
|
-
export { ModuleHandler };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl-CPxLvSu4.js";
|
|
2
|
-
import { EggModuleLoader } from "./EggModuleLoader-CCfQMmp5.js";
|
|
3
|
-
import { CompatibleUtil } from "./CompatibleUtil-CNhydb0E.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";
|
|
8
|
-
|
|
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
|
-
export { ModuleHandler };
|
package/dist/Utils-11aRpnkd.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { getCalleeFromStack };
|