@eggjs/tegg-plugin 4.0.0-beta.7 → 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.
- package/dist/AppLoadUnit-BOWdS4O9.d.ts +23 -0
- package/dist/AppLoadUnit-uyHgElRL.js +78 -0
- package/dist/AppLoadUnitInstance-4Z_vSQV3.js +69 -0
- package/dist/AppLoadUnitInstance-DQ-DxlmR.d.ts +24 -0
- package/dist/CompatibleUtil-CNhydb0E.js +96 -0
- package/dist/ConfigSourceLoadUnitHook-BV-R31vA.js +22 -0
- package/dist/EggAppLoader-DFYg65ry.js +106 -0
- package/dist/EggCompatibleObject-XfIZyirS.js +37 -0
- package/dist/EggCompatibleObject-lzUCfsIY.d.ts +21 -0
- package/dist/EggCompatibleProtoImpl-CPxLvSu4.js +50 -0
- package/dist/EggCompatibleProtoImpl-DpacWKFB.d.ts +25 -0
- package/dist/EggContextCompatibleHook-eFfN2xm6.js +31 -0
- package/dist/EggContextHandler-D8gfTbZs.js +29 -0
- package/dist/EggContextHandler-vGi67He5.d.ts +13 -0
- package/dist/EggContextImpl-DkCLPTzT.js +18 -0
- package/dist/EggModuleLoader-CCfQMmp5.js +50 -0
- package/dist/EggQualifierProtoHook-D5jNm-1y.js +48 -0
- package/dist/ModuleConfigLoader-CvZLf99E.js +84 -0
- package/dist/ModuleHandler-Dyx7JGj-.d.ts +17 -0
- package/dist/ModuleHandler-fKcUqWca.js +46 -0
- package/dist/Utils-11aRpnkd.js +33 -0
- package/dist/app/extend/application.d.ts +3 -56
- package/dist/app/extend/application.js +8 -70
- package/dist/app/extend/application.unittest.d.ts +1 -25
- package/dist/app/extend/application.unittest.js +2 -41
- package/dist/app/extend/context.d.ts +1 -23
- package/dist/app/extend/context.js +3 -28
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +1 -1
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +2 -1
- package/dist/app.d.ts +4 -1
- package/dist/app.js +18 -10
- package/dist/application-Ccljinuy.d.ts +57 -0
- package/dist/application-DFI1junS.js +70 -0
- package/dist/application.unittest-Cmia71Fx.js +43 -0
- package/dist/application.unittest-CpoCu6-E.d.ts +26 -0
- package/dist/context-BWYE1dif.js +30 -0
- package/dist/context-BoIt2G5h.d.ts +24 -0
- package/dist/ctx_lifecycle_middleware-CIeSrbVY.js +27 -0
- package/dist/ctx_lifecycle_middleware-DV7uN5PG.d.ts +6 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +13 -3
- package/dist/lib/AppLoadUnit.d.ts +1 -22
- package/dist/lib/AppLoadUnit.js +1 -76
- package/dist/lib/AppLoadUnitInstance.d.ts +1 -23
- package/dist/lib/AppLoadUnitInstance.js +1 -67
- package/dist/lib/CompatibleUtil.js +1 -94
- package/dist/lib/ConfigSourceLoadUnitHook.js +1 -20
- package/dist/lib/EggAppLoader.js +3 -104
- package/dist/lib/EggCompatibleObject.d.ts +2 -20
- package/dist/lib/EggCompatibleObject.js +2 -35
- package/dist/lib/EggCompatibleProtoImpl.d.ts +1 -24
- package/dist/lib/EggCompatibleProtoImpl.js +1 -48
- package/dist/lib/EggContextCompatibleHook.d.ts +1 -1
- package/dist/lib/EggContextCompatibleHook.js +7 -30
- package/dist/lib/EggContextHandler.d.ts +1 -12
- package/dist/lib/EggContextHandler.js +1 -27
- package/dist/lib/EggContextImpl.js +1 -16
- package/dist/lib/EggModuleLoader.js +4 -48
- package/dist/lib/EggQualifierProtoHook.js +4 -46
- package/dist/lib/ModuleConfigLoader.js +2 -82
- package/dist/lib/ModuleHandler.d.ts +1 -16
- package/dist/lib/ModuleHandler.js +6 -44
- package/dist/lib/Utils.js +1 -31
- package/dist/lib/ctx_lifecycle_middleware.d.ts +1 -5
- package/dist/lib/ctx_lifecycle_middleware.js +2 -25
- package/dist/lib/run_in_background.js +5 -50
- package/dist/run_in_background-CEUPBmDB.js +51 -0
- package/dist/types-BHg5p4Xk.js +3 -0
- package/dist/types-CuoKQV4X.d.ts +7 -0
- package/dist/types.d.ts +6 -7
- package/dist/types.js +13 -4
- package/package.json +11 -11
|
@@ -0,0 +1,50 @@
|
|
|
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 };
|
|
@@ -0,0 +1,48 @@
|
|
|
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 };
|
|
@@ -0,0 +1,84 @@
|
|
|
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 };
|
|
@@ -0,0 +1,17 @@
|
|
|
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 };
|
|
@@ -0,0 +1,46 @@
|
|
|
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 };
|
|
@@ -0,0 +1,33 @@
|
|
|
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 };
|
|
@@ -1,57 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { EggPrototypeCreatorFactory, EggPrototypeFactory, EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from "@eggjs/tegg-metadata";
|
|
5
|
-
import * as _eggjs_tegg0 from "@eggjs/tegg";
|
|
6
|
-
import { EggProtoImplClass, IdenticalUtil, QualifierInfo, RuntimeConfig } from "@eggjs/tegg";
|
|
7
|
-
import * as _eggjs_tegg_runtime0 from "@eggjs/tegg-runtime";
|
|
8
|
-
import { AbstractEggContext, EggContainerFactory, EggContext, EggContextLifecycleUtil, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
9
|
-
import { Application } from "egg";
|
|
10
|
-
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
11
|
-
|
|
12
|
-
//#region src/app/extend/application.d.ts
|
|
13
|
-
declare class TEggPluginApplication extends Application {
|
|
14
|
-
get eggPrototypeCreatorFactory(): typeof EggPrototypeCreatorFactory;
|
|
15
|
-
get eggPrototypeFactory(): EggPrototypeFactory;
|
|
16
|
-
get loadUnitLifecycleUtil(): _eggjs_tegg0.LifecycleUtil<_eggjs_tegg_metadata0.LoadUnitLifecycleContext, _eggjs_tegg_metadata0.LoadUnit>;
|
|
17
|
-
get loadUnitFactory(): typeof LoadUnitFactory;
|
|
18
|
-
get eggObjectFactory(): typeof EggObjectFactory;
|
|
19
|
-
get loadUnitInstanceFactory(): typeof LoadUnitInstanceFactory;
|
|
20
|
-
get loadUnitInstanceLifecycleUtil(): _eggjs_tegg0.LifecycleUtil<_eggjs_tegg_runtime0.LoadUnitInstanceLifecycleContext, _eggjs_tegg_runtime0.LoadUnitInstance>;
|
|
21
|
-
get eggContainerFactory(): typeof EggContainerFactory;
|
|
22
|
-
get loaderFactory(): typeof LoaderFactory;
|
|
23
|
-
get eggPrototypeLifecycleUtil(): _eggjs_tegg0.LifecycleUtil<_eggjs_tegg_metadata0.EggPrototypeLifecycleContext, _eggjs_tegg_metadata0.EggPrototype>;
|
|
24
|
-
get eggContextLifecycleUtil(): _eggjs_tegg0.LifecycleUtil<_eggjs_tegg_runtime0.EggContextLifecycleContext, EggContext>;
|
|
25
|
-
get eggObjectLifecycleUtil(): _eggjs_tegg0.LifecycleUtil<_eggjs_tegg_runtime0.EggObjectLifeCycleContext, _eggjs_tegg_runtime0.EggObject>;
|
|
26
|
-
get abstractEggContext(): typeof AbstractEggContext;
|
|
27
|
-
get identicalUtil(): typeof IdenticalUtil;
|
|
28
|
-
get runtimeConfig(): RuntimeConfig;
|
|
29
|
-
getEggObject<T>(clazz: EggProtoImplClass<T>, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
30
|
-
getEggObjectFromName<T extends object>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
31
|
-
}
|
|
32
|
-
declare module 'egg' {
|
|
33
|
-
interface Application {
|
|
34
|
-
eggPrototypeCreatorFactory: typeof EggPrototypeCreatorFactory;
|
|
35
|
-
eggPrototypeFactory: EggPrototypeFactory;
|
|
36
|
-
eggContainerFactory: typeof EggContainerFactory;
|
|
37
|
-
loadUnitFactory: typeof LoadUnitFactory;
|
|
38
|
-
eggObjectFactory: typeof EggObjectFactory;
|
|
39
|
-
loadUnitInstanceFactory: typeof LoadUnitInstanceFactory;
|
|
40
|
-
abstractEggContext: typeof AbstractEggContext;
|
|
41
|
-
identicalUtil: typeof IdenticalUtil;
|
|
42
|
-
loaderFactory: typeof LoaderFactory;
|
|
43
|
-
loadUnitLifecycleUtil: typeof LoadUnitLifecycleUtil;
|
|
44
|
-
loadUnitInstanceLifecycleUtil: typeof LoadUnitInstanceLifecycleUtil;
|
|
45
|
-
eggPrototypeLifecycleUtil: typeof EggPrototypeLifecycleUtil;
|
|
46
|
-
eggContextLifecycleUtil: typeof EggContextLifecycleUtil;
|
|
47
|
-
eggObjectLifecycleUtil: typeof EggObjectLifecycleUtil;
|
|
48
|
-
teggContext: EggContext;
|
|
49
|
-
moduleHandler: ModuleHandler;
|
|
50
|
-
eggContextHandler: EggContextHandler;
|
|
51
|
-
getEggObject<T>(clazz: new (...args: any[]) => T, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
52
|
-
getEggObjectFromName<T extends object>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
53
|
-
module: EggModule;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
//#endregion
|
|
1
|
+
import "../../ModuleHandler-Dyx7JGj-.js";
|
|
2
|
+
import "../../EggContextHandler-vGi67He5.js";
|
|
3
|
+
import { TEggPluginApplication } from "../../application-Ccljinuy.js";
|
|
57
4
|
export { TEggPluginApplication as default };
|
|
@@ -1,72 +1,10 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import "../../
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
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 "../../EggContextHandler-D8gfTbZs.js";
|
|
8
|
+
import { TEggPluginApplication } from "../../application-DFI1junS.js";
|
|
8
9
|
|
|
9
|
-
//#region src/app/extend/application.ts
|
|
10
|
-
var TEggPluginApplication = class extends Application {
|
|
11
|
-
get eggPrototypeCreatorFactory() {
|
|
12
|
-
return EggPrototypeCreatorFactory;
|
|
13
|
-
}
|
|
14
|
-
get eggPrototypeFactory() {
|
|
15
|
-
return EggPrototypeFactory.instance;
|
|
16
|
-
}
|
|
17
|
-
get loadUnitLifecycleUtil() {
|
|
18
|
-
return LoadUnitLifecycleUtil;
|
|
19
|
-
}
|
|
20
|
-
get loadUnitFactory() {
|
|
21
|
-
return LoadUnitFactory;
|
|
22
|
-
}
|
|
23
|
-
get eggObjectFactory() {
|
|
24
|
-
return EggObjectFactory;
|
|
25
|
-
}
|
|
26
|
-
get loadUnitInstanceFactory() {
|
|
27
|
-
return LoadUnitInstanceFactory;
|
|
28
|
-
}
|
|
29
|
-
get loadUnitInstanceLifecycleUtil() {
|
|
30
|
-
return LoadUnitInstanceLifecycleUtil;
|
|
31
|
-
}
|
|
32
|
-
get eggContainerFactory() {
|
|
33
|
-
return EggContainerFactory;
|
|
34
|
-
}
|
|
35
|
-
get loaderFactory() {
|
|
36
|
-
return LoaderFactory;
|
|
37
|
-
}
|
|
38
|
-
get eggPrototypeLifecycleUtil() {
|
|
39
|
-
return EggPrototypeLifecycleUtil;
|
|
40
|
-
}
|
|
41
|
-
get eggContextLifecycleUtil() {
|
|
42
|
-
return EggContextLifecycleUtil;
|
|
43
|
-
}
|
|
44
|
-
get eggObjectLifecycleUtil() {
|
|
45
|
-
return EggObjectLifecycleUtil;
|
|
46
|
-
}
|
|
47
|
-
get abstractEggContext() {
|
|
48
|
-
return AbstractEggContext;
|
|
49
|
-
}
|
|
50
|
-
get identicalUtil() {
|
|
51
|
-
return IdenticalUtil;
|
|
52
|
-
}
|
|
53
|
-
get runtimeConfig() {
|
|
54
|
-
const config = this.config;
|
|
55
|
-
return {
|
|
56
|
-
baseDir: config.baseDir,
|
|
57
|
-
env: config.env,
|
|
58
|
-
name: config.name
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async getEggObject(clazz, name, qualifiers) {
|
|
62
|
-
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
63
|
-
return (await EggContainerFactory.getOrCreateEggObjectFromClazz(clazz, name, qualifiers)).obj;
|
|
64
|
-
}
|
|
65
|
-
async getEggObjectFromName(name, qualifiers) {
|
|
66
|
-
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
67
|
-
return (await EggContainerFactory.getOrCreateEggObjectFromName(name, qualifiers)).obj;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
10
|
export { TEggPluginApplication as default };
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/app/extend/application.unittest.d.ts
|
|
4
|
-
declare class TEggPluginApplicationUnittest extends Application {
|
|
5
|
-
mockModuleContext(data?: any): Promise<Context>;
|
|
6
|
-
destroyModuleContext(ctx: Context): Promise<void>;
|
|
7
|
-
mockModuleContextScope<R = any>(fn: (ctx: Context) => Promise<R>, data?: any): Promise<R>;
|
|
8
|
-
}
|
|
9
|
-
declare module 'egg' {
|
|
10
|
-
interface Application {
|
|
11
|
-
/**
|
|
12
|
-
* Mock the module context, only for unittest
|
|
13
|
-
*/
|
|
14
|
-
mockModuleContext(data?: any): Promise<Context>;
|
|
15
|
-
/**
|
|
16
|
-
* Mock the module context scope, only for unittest
|
|
17
|
-
*/
|
|
18
|
-
mockModuleContextScope<R = any>(fn: (ctx: Context) => Promise<R>, data?: any): Promise<R>;
|
|
19
|
-
/**
|
|
20
|
-
* Destroy the module context, only for unittest
|
|
21
|
-
*/
|
|
22
|
-
destroyModuleContext(context: Context): Promise<void>;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
1
|
+
import { TEggPluginApplicationUnittest } from "../../application.unittest-CpoCu6-E.js";
|
|
26
2
|
export { TEggPluginApplicationUnittest as default };
|
|
@@ -1,43 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "
|
|
3
|
-
import { Application } from "egg";
|
|
1
|
+
import "../../EggContextImpl-DkCLPTzT.js";
|
|
2
|
+
import { TEggPluginApplicationUnittest } from "../../application.unittest-Cmia71Fx.js";
|
|
4
3
|
|
|
5
|
-
//#region src/app/extend/application.unittest.ts
|
|
6
|
-
const TEGG_LIFECYCLE_CACHE = /* @__PURE__ */ new Map();
|
|
7
|
-
let hasMockModuleContext = false;
|
|
8
|
-
var TEggPluginApplicationUnittest = class extends Application {
|
|
9
|
-
async mockModuleContext(data) {
|
|
10
|
-
this.deprecate("app.mockModuleContext is deprecated, use mockModuleContextScope.");
|
|
11
|
-
if (hasMockModuleContext) throw new Error("should not call mockModuleContext twice.");
|
|
12
|
-
const ctx = this.mockContext(data);
|
|
13
|
-
const teggCtx = new EggContextImpl(ctx);
|
|
14
|
-
const lifecycle = {};
|
|
15
|
-
TEGG_LIFECYCLE_CACHE.set(teggCtx, lifecycle);
|
|
16
|
-
if (teggCtx.init) await teggCtx.init(lifecycle);
|
|
17
|
-
hasMockModuleContext = true;
|
|
18
|
-
return ctx;
|
|
19
|
-
}
|
|
20
|
-
async destroyModuleContext(ctx) {
|
|
21
|
-
hasMockModuleContext = false;
|
|
22
|
-
const teggCtx = ctx.teggContext;
|
|
23
|
-
if (!teggCtx) return;
|
|
24
|
-
const lifecycle = TEGG_LIFECYCLE_CACHE.get(teggCtx);
|
|
25
|
-
if (teggCtx.destroy && lifecycle) await teggCtx.destroy(lifecycle);
|
|
26
|
-
}
|
|
27
|
-
async mockModuleContextScope(fn, data) {
|
|
28
|
-
if (hasMockModuleContext) throw new Error("mockModuleContextScope can not use with mockModuleContext, should use mockModuleContextScope only.");
|
|
29
|
-
return this.mockContextScope(async (ctx) => {
|
|
30
|
-
const teggCtx = new EggContextImpl(ctx);
|
|
31
|
-
const lifecycle = {};
|
|
32
|
-
if (teggCtx.init) await teggCtx.init(lifecycle);
|
|
33
|
-
try {
|
|
34
|
-
return await fn(ctx);
|
|
35
|
-
} finally {
|
|
36
|
-
await teggCtx.destroy(lifecycle);
|
|
37
|
-
}
|
|
38
|
-
}, data);
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
4
|
export { TEggPluginApplicationUnittest as default };
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EggContext } from "@eggjs/tegg-runtime";
|
|
3
|
-
import { TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
4
|
-
import { Context } from "egg";
|
|
5
|
-
|
|
6
|
-
//#region src/app/extend/context.d.ts
|
|
7
|
-
declare class TEggPluginContext extends Context {
|
|
8
|
-
[TEGG_CONTEXT]: EggContext | undefined;
|
|
9
|
-
beginModuleScope(func: () => Promise<void>): Promise<void>;
|
|
10
|
-
get teggContext(): EggContext;
|
|
11
|
-
getEggObject<T>(clazz: EggProtoImplClass<T>, name?: string): Promise<T>;
|
|
12
|
-
getEggObjectFromName<T>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
13
|
-
}
|
|
14
|
-
declare module 'egg' {
|
|
15
|
-
interface Context {
|
|
16
|
-
beginModuleScope(func: () => Promise<void>): Promise<void>;
|
|
17
|
-
getEggObject<T>(clazz: new (...args: any[]) => T, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
18
|
-
getEggObjectFromName<T>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
19
|
-
teggContext: EggContext;
|
|
20
|
-
module: EggModule;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
1
|
+
import { TEggPluginContext } from "../../context-BoIt2G5h.js";
|
|
24
2
|
export { TEggPluginContext as default };
|
|
@@ -1,30 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
4
|
-
import { TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
5
|
-
import { Context } from "egg";
|
|
1
|
+
import "../../EggContextImpl-DkCLPTzT.js";
|
|
2
|
+
import "../../ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
3
|
+
import { TEggPluginContext } from "../../context-BWYE1dif.js";
|
|
6
4
|
|
|
7
|
-
//#region src/app/extend/context.ts
|
|
8
|
-
var TEggPluginContext = class extends Context {
|
|
9
|
-
[TEGG_CONTEXT];
|
|
10
|
-
async beginModuleScope(func) {
|
|
11
|
-
await ctxLifecycleMiddleware(this, func);
|
|
12
|
-
}
|
|
13
|
-
get teggContext() {
|
|
14
|
-
if (!this[TEGG_CONTEXT]) throw new Error("tegg context have not ready, should call after teggCtxLifecycleMiddleware");
|
|
15
|
-
return this[TEGG_CONTEXT];
|
|
16
|
-
}
|
|
17
|
-
async getEggObject(clazz, name) {
|
|
18
|
-
const protoObj = PrototypeUtil.getClazzProto(clazz);
|
|
19
|
-
if (!protoObj) throw new Error(`can not get proto for clazz ${clazz.name}`);
|
|
20
|
-
const proto = protoObj;
|
|
21
|
-
return (await this.app.eggContainerFactory.getOrCreateEggObject(proto, name ?? proto.name)).obj;
|
|
22
|
-
}
|
|
23
|
-
async getEggObjectFromName(name, qualifiers) {
|
|
24
|
-
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
25
|
-
return (await this.app.eggContainerFactory.getOrCreateEggObjectFromName(name, qualifiers)).obj;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
5
|
export { TEggPluginContext as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ctxLifecycleMiddleware } from "../../
|
|
1
|
+
import { ctxLifecycleMiddleware } from "../../ctx_lifecycle_middleware-DV7uN5PG.js";
|
|
2
2
|
|
|
3
3
|
//#region src/app/middleware/tegg_ctx_lifecycle_middleware.d.ts
|
|
4
4
|
declare const _default: () => typeof ctxLifecycleMiddleware;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../EggContextImpl-DkCLPTzT.js";
|
|
2
|
+
import { ctxLifecycleMiddleware } from "../../ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
2
3
|
|
|
3
4
|
//#region src/app/middleware/tegg_ctx_lifecycle_middleware.ts
|
|
4
5
|
var tegg_ctx_lifecycle_middleware_default = () => {
|
package/dist/app.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import "./AppLoadUnit-BOWdS4O9.js";
|
|
2
|
+
import "./AppLoadUnitInstance-DQ-DxlmR.js";
|
|
3
|
+
import "./EggCompatibleProtoImpl-DpacWKFB.js";
|
|
4
|
+
import "./EggCompatibleObject-lzUCfsIY.js";
|
|
1
5
|
import { Application, ILifecycleBoot } from "egg";
|
|
2
6
|
|
|
3
7
|
//#region src/app.d.ts
|
|
4
|
-
|
|
5
8
|
declare class App implements ILifecycleBoot {
|
|
6
9
|
private readonly app;
|
|
7
10
|
private compatibleHook?;
|
package/dist/app.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
1
|
+
import "./AppLoadUnit-uyHgElRL.js";
|
|
2
|
+
import "./AppLoadUnitInstance-4Z_vSQV3.js";
|
|
3
|
+
import "./EggCompatibleProtoImpl-CPxLvSu4.js";
|
|
4
|
+
import "./EggCompatibleObject-XfIZyirS.js";
|
|
5
|
+
import "./ModuleConfigLoader-CvZLf99E.js";
|
|
6
|
+
import "./EggAppLoader-DFYg65ry.js";
|
|
7
|
+
import "./EggModuleLoader-CCfQMmp5.js";
|
|
8
|
+
import { CompatibleUtil } from "./CompatibleUtil-CNhydb0E.js";
|
|
9
|
+
import { ModuleHandler } from "./ModuleHandler-fKcUqWca.js";
|
|
10
|
+
import { EggContextCompatibleHook } from "./EggContextCompatibleHook-eFfN2xm6.js";
|
|
11
|
+
import { EggContextHandler } from "./EggContextHandler-D8gfTbZs.js";
|
|
12
|
+
import "./EggContextImpl-DkCLPTzT.js";
|
|
13
|
+
import "./ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
14
|
+
import "./context-BWYE1dif.js";
|
|
15
|
+
import "./Utils-11aRpnkd.js";
|
|
16
|
+
import { hijackRunInBackground } from "./run_in_background-CEUPBmDB.js";
|
|
17
|
+
import { EggQualifierProtoHook } from "./EggQualifierProtoHook-D5jNm-1y.js";
|
|
18
|
+
import { ConfigSourceLoadUnitHook } from "./ConfigSourceLoadUnitHook-BV-R31vA.js";
|
|
11
19
|
import { LoadUnitMultiInstanceProtoHook } from "@eggjs/tegg-metadata";
|
|
12
20
|
|
|
13
21
|
//#region src/app.ts
|