@eggjs/tegg-plugin 4.0.0-beta.8 → 4.0.1-beta.0
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 +28 -3
- package/dist/app/extend/application.js +67 -8
- package/dist/app/extend/application.unittest.d.ts +9 -1
- package/dist/app/extend/application.unittest.js +39 -2
- package/dist/app/extend/context.d.ts +12 -1
- package/dist/app/extend/context.js +26 -3
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +2 -2
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +1 -2
- package/dist/app.d.ts +5 -6
- package/dist/app.js +13 -21
- package/dist/index.d.ts +3 -6
- package/dist/index.js +3 -13
- package/dist/lib/AppLoadUnit.d.ts +23 -1
- package/dist/lib/AppLoadUnit.js +76 -1
- package/dist/lib/AppLoadUnitInstance.d.ts +23 -1
- package/dist/lib/AppLoadUnitInstance.js +68 -1
- package/dist/lib/CompatibleUtil.d.ts +7 -2
- package/dist/lib/CompatibleUtil.js +97 -1
- package/dist/lib/ConfigSourceLoadUnitHook.d.ts +6 -6
- package/dist/lib/ConfigSourceLoadUnitHook.js +19 -1
- package/dist/lib/EggAppLoader.d.ts +6 -6
- package/dist/lib/EggAppLoader.js +103 -3
- package/dist/lib/EggCompatibleObject.d.ts +19 -2
- package/dist/lib/EggCompatibleObject.js +34 -2
- package/dist/lib/EggCompatibleProtoImpl.d.ts +25 -1
- package/dist/lib/EggCompatibleProtoImpl.js +47 -1
- package/dist/lib/EggContextCompatibleHook.d.ts +2 -2
- package/dist/lib/EggContextCompatibleHook.js +30 -7
- package/dist/lib/EggContextHandler.d.ts +12 -1
- package/dist/lib/EggContextHandler.js +26 -1
- package/dist/lib/EggContextImpl.js +16 -1
- package/dist/lib/EggModuleLoader.d.ts +3 -1
- package/dist/lib/EggModuleLoader.js +52 -4
- package/dist/lib/EggQualifierProtoHook.d.ts +2 -2
- package/dist/lib/EggQualifierProtoHook.js +44 -4
- package/dist/lib/ModuleConfigLoader.d.ts +1 -1
- package/dist/lib/ModuleConfigLoader.js +80 -2
- package/dist/lib/ModuleHandler.d.ts +17 -1
- package/dist/lib/ModuleHandler.js +46 -6
- package/dist/lib/Utils.d.ts +1 -1
- package/dist/lib/Utils.js +31 -1
- package/dist/lib/ctx_lifecycle_middleware.d.ts +5 -1
- package/dist/lib/ctx_lifecycle_middleware.js +36 -2
- package/dist/lib/run_in_background.js +48 -5
- package/dist/types.d.ts +54 -6
- package/dist/types.js +1 -13
- package/package.json +49 -54
- 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,2 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GlobalGraphBuildHook, LoadUnit } from "@eggjs/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
|
+
registerGlobalGraphBuildHook(hook: GlobalGraphBuildHook): void;
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
destroy(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
2
18
|
export { ModuleHandler };
|
|
@@ -1,8 +1,48 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import {
|
|
1
|
+
import { COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl } from "./EggCompatibleProtoImpl.js";
|
|
2
|
+
import { CompatibleUtil } from "./CompatibleUtil.js";
|
|
3
|
+
import { EggModuleLoader } from "./EggModuleLoader.js";
|
|
4
|
+
import { EggLoadUnitType, LoadUnitFactory } from "@eggjs/metadata";
|
|
5
|
+
import { LoadUnitInstanceFactory } from "@eggjs/tegg-runtime";
|
|
6
|
+
import { Base } from "sdk-base";
|
|
7
7
|
|
|
8
|
+
//#region src/lib/ModuleHandler.ts
|
|
9
|
+
var ModuleHandler = class extends Base {
|
|
10
|
+
loadUnits = [];
|
|
11
|
+
loadUnitInstances = [];
|
|
12
|
+
loadUnitLoader;
|
|
13
|
+
app;
|
|
14
|
+
constructor(app) {
|
|
15
|
+
super();
|
|
16
|
+
this.app = app;
|
|
17
|
+
this.loadUnitLoader = new EggModuleLoader(this.app);
|
|
18
|
+
}
|
|
19
|
+
registerGlobalGraphBuildHook(hook) {
|
|
20
|
+
this.loadUnitLoader.registerBuildHook(hook);
|
|
21
|
+
}
|
|
22
|
+
async init() {
|
|
23
|
+
try {
|
|
24
|
+
this.app.eggPrototypeCreatorFactory.registerPrototypeCreator(COMPATIBLE_PROTO_IMPLE_TYPE, EggCompatibleProtoImpl.create);
|
|
25
|
+
await this.loadUnitLoader.load();
|
|
26
|
+
const instances = [];
|
|
27
|
+
this.app.module = {};
|
|
28
|
+
for (const loadUnit of this.loadUnits) {
|
|
29
|
+
const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
|
|
30
|
+
if (instance.loadUnit.type !== EggLoadUnitType.APP) CompatibleUtil.appCompatible(this.app, instance);
|
|
31
|
+
instances.push(instance);
|
|
32
|
+
}
|
|
33
|
+
CompatibleUtil.contextModuleCompatible(this.app.context, instances);
|
|
34
|
+
this.loadUnitInstances = instances;
|
|
35
|
+
this.ready(true);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
this.ready(e);
|
|
38
|
+
throw e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async destroy() {
|
|
42
|
+
if (this.loadUnitInstances) for (const instance of this.loadUnitInstances) await LoadUnitInstanceFactory.destroyLoadUnitInstance(instance);
|
|
43
|
+
if (this.loadUnits) for (const loadUnit of this.loadUnits) await LoadUnitFactory.destroyLoadUnit(loadUnit);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
8
48
|
export { ModuleHandler };
|
package/dist/lib/Utils.d.ts
CHANGED
package/dist/lib/Utils.js
CHANGED
|
@@ -1,3 +1,33 @@
|
|
|
1
|
-
|
|
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
|
+
}
|
|
2
31
|
|
|
32
|
+
//#endregion
|
|
3
33
|
export { getCalleeFromStack };
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context, Next } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/ctx_lifecycle_middleware.d.ts
|
|
4
|
+
declare function ctxLifecycleMiddleware(ctx: Context, next: Next): Promise<void>;
|
|
5
|
+
//#endregion
|
|
2
6
|
export { ctxLifecycleMiddleware };
|
|
@@ -1,4 +1,38 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import {
|
|
1
|
+
import { EggContextImpl } from "./EggContextImpl.js";
|
|
2
|
+
import { StreamUtil } from "@eggjs/tegg-common-util";
|
|
3
|
+
import { ROOT_PROTO, TEGG_CONTEXT } from "@eggjs/module-common";
|
|
4
|
+
import awaitFirst from "await-first";
|
|
3
5
|
|
|
6
|
+
//#region src/lib/ctx_lifecycle_middleware.ts
|
|
7
|
+
async function ctxLifecycleMiddleware(ctx, next) {
|
|
8
|
+
if (ctx[TEGG_CONTEXT]) {
|
|
9
|
+
await next();
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const lifecycleCtx = {};
|
|
13
|
+
const teggCtx = new EggContextImpl(ctx);
|
|
14
|
+
const rootProto = ctx[ROOT_PROTO];
|
|
15
|
+
if (rootProto) teggCtx.set(ROOT_PROTO, rootProto);
|
|
16
|
+
if (teggCtx.init) await teggCtx.init(lifecycleCtx);
|
|
17
|
+
async function doDestroy() {
|
|
18
|
+
if (StreamUtil.isStream(ctx.response.body)) try {
|
|
19
|
+
await awaitFirst(ctx.response.body, ["close", "error"]);
|
|
20
|
+
} catch (error) {
|
|
21
|
+
ctx.res.destroy(error);
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
if (teggCtx.destroy) await teggCtx.destroy(lifecycleCtx);
|
|
25
|
+
} catch (e) {
|
|
26
|
+
e.message = `[tegg/ctxLifecycleMiddleware] destroy tegg ctx failed: ${e.message}`;
|
|
27
|
+
ctx.logger.error(e);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
await next();
|
|
32
|
+
} finally {
|
|
33
|
+
doDestroy();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
4
38
|
export { ctxLifecycleMiddleware };
|
|
@@ -1,7 +1,50 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import { LONG_STACK_DELIMITER, hijackRunInBackground } from "../run_in_background-CEUPBmDB.js";
|
|
1
|
+
import { getCalleeFromStack } from "./Utils.js";
|
|
2
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
3
|
+
import { BackgroundTaskHelper } from "@eggjs/background-task";
|
|
4
|
+
import { TEGG_CONTEXT } from "@eggjs/module-common";
|
|
6
5
|
|
|
6
|
+
//#region src/lib/run_in_background.ts
|
|
7
|
+
const LONG_STACK_DELIMITER = "\n --------------------\n";
|
|
8
|
+
function addLongStackTrace(err, causeError) {
|
|
9
|
+
const callSiteStack = causeError.stack;
|
|
10
|
+
if (!callSiteStack || typeof callSiteStack !== "string") return;
|
|
11
|
+
const index = callSiteStack.indexOf("\n");
|
|
12
|
+
if (index !== -1) err.stack += LONG_STACK_DELIMITER + callSiteStack.substring(index + 1);
|
|
13
|
+
}
|
|
14
|
+
function hijackRunInBackground(app) {
|
|
15
|
+
const eggRunInBackground = app.context.runInBackground;
|
|
16
|
+
app.context.runInBackground = function runInBackground(scope) {
|
|
17
|
+
if (!this[TEGG_CONTEXT]) return Reflect.apply(eggRunInBackground, this, [scope]);
|
|
18
|
+
const caseError = /* @__PURE__ */ new Error("cause");
|
|
19
|
+
let resolveBackgroundTask;
|
|
20
|
+
const backgroundTaskPromise = new Promise((resolve) => {
|
|
21
|
+
resolveBackgroundTask = resolve;
|
|
22
|
+
});
|
|
23
|
+
const newScope = async () => {
|
|
24
|
+
try {
|
|
25
|
+
await scope(this);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
addLongStackTrace(e, caseError);
|
|
28
|
+
throw e;
|
|
29
|
+
} finally {
|
|
30
|
+
resolveBackgroundTask();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const taskName = scope._name || scope.name || getCalleeFromStack(true, 2);
|
|
34
|
+
scope._name = taskName;
|
|
35
|
+
Object.defineProperty(newScope, "name", {
|
|
36
|
+
value: taskName,
|
|
37
|
+
enumerable: false,
|
|
38
|
+
configurable: true,
|
|
39
|
+
writable: false
|
|
40
|
+
});
|
|
41
|
+
Reflect.apply(eggRunInBackground, this, [newScope]);
|
|
42
|
+
const proto = PrototypeUtil.getClazzProto(BackgroundTaskHelper);
|
|
43
|
+
app.eggContainerFactory.getEggObject(proto).obj.run(async () => {
|
|
44
|
+
await backgroundTaskPromise;
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
7
50
|
export { LONG_STACK_DELIMITER, hijackRunInBackground };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
import "
|
|
1
|
+
import { EggContextHandler } from "./lib/EggContextHandler.js";
|
|
2
|
+
import { ModuleHandler } from "./lib/ModuleHandler.js";
|
|
3
|
+
import { QualifierInfo } from "@eggjs/core-decorator";
|
|
4
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
5
|
+
import { EggPrototypeCreatorFactory, EggPrototypeFactory, EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from "@eggjs/metadata";
|
|
6
|
+
import { AbstractEggContext, EggContainerFactory, EggContext, EggContextLifecycleUtil, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
7
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
8
|
+
import "@eggjs/tegg-config/types";
|
|
9
|
+
|
|
10
|
+
//#region src/types.d.ts
|
|
11
|
+
declare module "egg" {
|
|
12
|
+
interface EggModule {}
|
|
13
|
+
interface Application {
|
|
14
|
+
eggPrototypeCreatorFactory: typeof EggPrototypeCreatorFactory;
|
|
15
|
+
eggPrototypeFactory: EggPrototypeFactory;
|
|
16
|
+
eggContainerFactory: typeof EggContainerFactory;
|
|
17
|
+
loadUnitFactory: typeof LoadUnitFactory;
|
|
18
|
+
eggObjectFactory: typeof EggObjectFactory;
|
|
19
|
+
loadUnitInstanceFactory: typeof LoadUnitInstanceFactory;
|
|
20
|
+
abstractEggContext: typeof AbstractEggContext;
|
|
21
|
+
identicalUtil: typeof IdenticalUtil;
|
|
22
|
+
loaderFactory: typeof LoaderFactory;
|
|
23
|
+
loadUnitLifecycleUtil: typeof LoadUnitLifecycleUtil;
|
|
24
|
+
loadUnitInstanceLifecycleUtil: typeof LoadUnitInstanceLifecycleUtil;
|
|
25
|
+
eggPrototypeLifecycleUtil: typeof EggPrototypeLifecycleUtil;
|
|
26
|
+
eggContextLifecycleUtil: typeof EggContextLifecycleUtil;
|
|
27
|
+
eggObjectLifecycleUtil: typeof EggObjectLifecycleUtil;
|
|
28
|
+
teggContext: EggContext;
|
|
29
|
+
moduleHandler: ModuleHandler;
|
|
30
|
+
eggContextHandler: EggContextHandler;
|
|
31
|
+
getEggObject<T>(clazz: new (...args: any[]) => T, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
32
|
+
getEggObjectFromName<T extends object>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
33
|
+
module: EggModule;
|
|
34
|
+
/**
|
|
35
|
+
* Mock the module context, only for unittest
|
|
36
|
+
*/
|
|
37
|
+
mockModuleContext(data?: any): Promise<Context>;
|
|
38
|
+
/**
|
|
39
|
+
* Mock the module context scope, only for unittest
|
|
40
|
+
*/
|
|
41
|
+
mockModuleContextScope<R = any>(fn: (ctx: Context) => Promise<R>, data?: any): Promise<R>;
|
|
42
|
+
/**
|
|
43
|
+
* Destroy the module context, only for unittest
|
|
44
|
+
*/
|
|
45
|
+
destroyModuleContext(context: Context): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
interface Context {
|
|
48
|
+
beginModuleScope(func: () => Promise<void>): Promise<void>;
|
|
49
|
+
getEggObject<T>(clazz: new (...args: any[]) => T, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
50
|
+
getEggObjectFromName<T>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
51
|
+
teggContext: EggContext;
|
|
52
|
+
module: EggModule;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/dist/types.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import "
|
|
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 "./EggContextImpl-DkCLPTzT.js";
|
|
9
|
-
import "./ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
10
|
-
import "./context-BWYE1dif.js";
|
|
11
|
-
import "./application-DFI1junS.js";
|
|
12
|
-
import "./application.unittest-Cmia71Fx.js";
|
|
13
|
-
import "./types-BHg5p4Xk.js";
|
|
1
|
+
import "@eggjs/tegg-config/types";
|
|
14
2
|
|
|
15
3
|
export { };
|
package/package.json
CHANGED
|
@@ -1,24 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-plugin",
|
|
3
|
-
"
|
|
4
|
-
"name": "tegg",
|
|
5
|
-
"dependencies": [
|
|
6
|
-
"teggConfig"
|
|
7
|
-
]
|
|
8
|
-
},
|
|
9
|
-
"version": "4.0.0-beta.8",
|
|
3
|
+
"version": "4.0.1-beta.0",
|
|
10
4
|
"description": "module plugin for egg",
|
|
11
5
|
"keywords": [
|
|
12
6
|
"egg",
|
|
13
|
-
"plugin",
|
|
14
|
-
"typescript",
|
|
15
7
|
"module",
|
|
16
|
-
"
|
|
8
|
+
"plugin",
|
|
9
|
+
"tegg",
|
|
10
|
+
"typescript"
|
|
17
11
|
],
|
|
12
|
+
"homepage": "https://github.com/eggjs/egg/tree/next/tegg/plugin/tegg",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/eggjs/egg/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/eggjs/egg.git",
|
|
19
|
+
"directory": "tegg/plugin/tegg"
|
|
20
|
+
},
|
|
18
21
|
"files": [
|
|
19
22
|
"dist"
|
|
20
23
|
],
|
|
21
24
|
"type": "module",
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
22
28
|
"exports": {
|
|
23
29
|
".": "./dist/index.js",
|
|
24
30
|
"./app": "./dist/app.js",
|
|
@@ -46,59 +52,48 @@
|
|
|
46
52
|
"./types": "./dist/types.js",
|
|
47
53
|
"./package.json": "./package.json"
|
|
48
54
|
},
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
"url": "https://github.com/eggjs/tegg/issues"
|
|
52
|
-
},
|
|
53
|
-
"repository": {
|
|
54
|
-
"type": "git",
|
|
55
|
-
"url": "git@github.com:eggjs/tegg.git",
|
|
56
|
-
"directory": "plugin/tegg"
|
|
57
|
-
},
|
|
58
|
-
"engines": {
|
|
59
|
-
"node": ">=22.18.0"
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
60
57
|
},
|
|
61
58
|
"dependencies": {
|
|
59
|
+
"await-first": "^1.0.0",
|
|
62
60
|
"extend2": "^4.0.0",
|
|
63
61
|
"sdk-base": "^5.0.1",
|
|
64
|
-
"@eggjs/
|
|
65
|
-
"@eggjs/
|
|
66
|
-
"@eggjs/
|
|
67
|
-
"@eggjs/
|
|
68
|
-
"@eggjs/
|
|
69
|
-
"@eggjs/
|
|
70
|
-
"@eggjs/tegg-
|
|
71
|
-
"@eggjs/tegg-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"egg": "beta",
|
|
75
|
-
"@eggjs/tegg-config": "4.0.0-beta.8"
|
|
62
|
+
"@eggjs/background-task": "4.0.1-beta.0",
|
|
63
|
+
"@eggjs/core-decorator": "4.0.1-beta.0",
|
|
64
|
+
"@eggjs/lifecycle": "4.0.1-beta.0",
|
|
65
|
+
"@eggjs/dynamic-inject-runtime": "4.0.1-beta.0",
|
|
66
|
+
"@eggjs/metadata": "4.0.1-beta.0",
|
|
67
|
+
"@eggjs/module-common": "4.0.1-beta.0",
|
|
68
|
+
"@eggjs/tegg-loader": "4.0.1-beta.0",
|
|
69
|
+
"@eggjs/tegg-common-util": "4.0.1-beta.0",
|
|
70
|
+
"@eggjs/tegg-runtime": "4.0.1-beta.0",
|
|
71
|
+
"@eggjs/tegg-types": "4.0.1-beta.0"
|
|
76
72
|
},
|
|
77
73
|
"devDependencies": {
|
|
78
|
-
"@
|
|
79
|
-
"
|
|
80
|
-
"@eggjs/tracer": "beta",
|
|
81
|
-
"@types/mocha": "^10.0.10",
|
|
82
|
-
"@types/node": "^22.10.5",
|
|
83
|
-
"egg": "beta",
|
|
84
|
-
"egg-logger": "^3.0.1",
|
|
85
|
-
"mocha": "^11.0.1",
|
|
74
|
+
"@types/node": "^24.10.2",
|
|
75
|
+
"egg-logger": "^3.5.0",
|
|
86
76
|
"typescript": "^5.9.3",
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"@eggjs/tegg-config": "4.0.
|
|
77
|
+
"@eggjs/tegg": "4.0.1-beta.0",
|
|
78
|
+
"@eggjs/tracer": "4.0.1-beta.0",
|
|
79
|
+
"@eggjs/tegg-config": "4.0.1-beta.0",
|
|
80
|
+
"egg": "4.1.1-beta.0",
|
|
81
|
+
"@eggjs/mock": "7.0.1-beta.0"
|
|
90
82
|
},
|
|
91
|
-
"
|
|
92
|
-
"
|
|
83
|
+
"peerDependencies": {
|
|
84
|
+
"@eggjs/tegg-config": "4.0.1-beta.0",
|
|
85
|
+
"egg": "4.1.1-beta.0"
|
|
86
|
+
},
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=22.18.0"
|
|
89
|
+
},
|
|
90
|
+
"eggPlugin": {
|
|
91
|
+
"name": "tegg",
|
|
92
|
+
"dependencies": [
|
|
93
|
+
"teggConfig"
|
|
94
|
+
]
|
|
93
95
|
},
|
|
94
|
-
"main": "./dist/index.js",
|
|
95
|
-
"module": "./dist/index.js",
|
|
96
|
-
"types": "./dist/index.d.ts",
|
|
97
96
|
"scripts": {
|
|
98
|
-
"typecheck": "
|
|
99
|
-
"test:mocha": "egg-bin test",
|
|
100
|
-
"cov:mocha": "egg-bin cov",
|
|
101
|
-
"clean": "rimraf dist",
|
|
102
|
-
"build": "tsdown"
|
|
97
|
+
"typecheck": "tsgo --noEmit"
|
|
103
98
|
}
|
|
104
99
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { EggLoadUnitTypeLike, EggPrototype, LoadUnit, LoadUnitLifecycleContext, Loader } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { Id, QualifierInfo } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/lib/AppLoadUnit.d.ts
|
|
5
|
-
declare class AppLoadUnit implements LoadUnit {
|
|
6
|
-
private readonly loader;
|
|
7
|
-
id: Id;
|
|
8
|
-
readonly name: string;
|
|
9
|
-
readonly type: EggLoadUnitTypeLike;
|
|
10
|
-
readonly unitPath: string;
|
|
11
|
-
private protoMap;
|
|
12
|
-
constructor(name: string, unitPath: string, loader: Loader);
|
|
13
|
-
init(): Promise<void>;
|
|
14
|
-
containPrototype(proto: EggPrototype): boolean;
|
|
15
|
-
getEggPrototype(name: string, qualifiers: QualifierInfo[]): EggPrototype[];
|
|
16
|
-
registerEggPrototype(proto: EggPrototype): void;
|
|
17
|
-
deletePrototype(proto: EggPrototype): void;
|
|
18
|
-
destroy(): Promise<void>;
|
|
19
|
-
iterateEggPrototype(): IterableIterator<EggPrototype>;
|
|
20
|
-
static createModule(ctx: LoadUnitLifecycleContext): AppLoadUnit;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
23
|
-
export { AppLoadUnit };
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { debuglog } from "node:util";
|
|
2
|
-
import { EggLoadUnitType, EggPrototypeCreatorFactory, EggPrototypeFactory, LoadUnitFactory } from "@eggjs/tegg-metadata";
|
|
3
|
-
import { IdenticalUtil, InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
|
|
4
|
-
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
5
|
-
|
|
6
|
-
//#region src/lib/AppLoadUnit.ts
|
|
7
|
-
const debug = debuglog("tegg/plugin/tegg/lib/AppLoadUnit");
|
|
8
|
-
var AppLoadUnit = class AppLoadUnit {
|
|
9
|
-
loader;
|
|
10
|
-
id;
|
|
11
|
-
name;
|
|
12
|
-
type = EggLoadUnitType.APP;
|
|
13
|
-
unitPath;
|
|
14
|
-
protoMap = /* @__PURE__ */ new Map();
|
|
15
|
-
constructor(name, unitPath, loader) {
|
|
16
|
-
this.id = IdenticalUtil.createLoadUnitId(name);
|
|
17
|
-
this.name = name;
|
|
18
|
-
this.unitPath = unitPath;
|
|
19
|
-
this.loader = loader;
|
|
20
|
-
}
|
|
21
|
-
async init() {
|
|
22
|
-
const clazzList = await this.loader.load();
|
|
23
|
-
if (debug.enabled) debug("init, get clazzList:%j, from unitPath:%o:%o:%o", clazzList.map((t) => t.name), this.type, this.name, this.unitPath);
|
|
24
|
-
for (const clazz of clazzList) {
|
|
25
|
-
const initTypeQualifierAttributeValue = await PrototypeUtil.getInitType(clazz, {
|
|
26
|
-
unitPath: this.unitPath,
|
|
27
|
-
moduleName: this.name
|
|
28
|
-
});
|
|
29
|
-
[{
|
|
30
|
-
attribute: InitTypeQualifierAttribute,
|
|
31
|
-
value: initTypeQualifierAttributeValue
|
|
32
|
-
}, {
|
|
33
|
-
attribute: LoadUnitNameQualifierAttribute,
|
|
34
|
-
value: this.name
|
|
35
|
-
}].forEach((qualifier) => {
|
|
36
|
-
QualifierUtil.addProtoQualifier(clazz, qualifier.attribute, qualifier.value);
|
|
37
|
-
});
|
|
38
|
-
const protos = await EggPrototypeCreatorFactory.createProto(clazz, this);
|
|
39
|
-
for (const proto of protos) EggPrototypeFactory.instance.registerPrototype(proto, this);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
containPrototype(proto) {
|
|
43
|
-
return !!this.protoMap.get(proto.name)?.find((t) => t === proto);
|
|
44
|
-
}
|
|
45
|
-
getEggPrototype(name, qualifiers) {
|
|
46
|
-
return this.protoMap.get(name)?.filter((proto) => proto.verifyQualifiers(qualifiers)) || [];
|
|
47
|
-
}
|
|
48
|
-
registerEggPrototype(proto) {
|
|
49
|
-
MapUtil.getOrStore(this.protoMap, proto.name, []).push(proto);
|
|
50
|
-
}
|
|
51
|
-
deletePrototype(proto) {
|
|
52
|
-
const protos = this.protoMap.get(proto.name);
|
|
53
|
-
if (protos) {
|
|
54
|
-
const index = protos.indexOf(proto);
|
|
55
|
-
if (index !== -1) protos.splice(index, 1);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async destroy() {
|
|
59
|
-
for (const namedProtos of this.protoMap.values()) {
|
|
60
|
-
const protos = namedProtos.slice();
|
|
61
|
-
for (const proto of protos) EggPrototypeFactory.instance.deletePrototype(proto, this);
|
|
62
|
-
}
|
|
63
|
-
this.protoMap.clear();
|
|
64
|
-
}
|
|
65
|
-
iterateEggPrototype() {
|
|
66
|
-
return Array.from(this.protoMap.values()).reduce((p, c) => {
|
|
67
|
-
p = p.concat(c);
|
|
68
|
-
return p;
|
|
69
|
-
}, []).values();
|
|
70
|
-
}
|
|
71
|
-
static createModule(ctx) {
|
|
72
|
-
return new AppLoadUnit("tegg-app", ctx.unitPath, ctx.loader);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
LoadUnitFactory.registerLoadUnitCreator(EggLoadUnitType.APP, AppLoadUnit.createModule);
|
|
76
|
-
|
|
77
|
-
//#endregion
|
|
78
|
-
export { AppLoadUnit };
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { EggLoadUnitType } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { IdenticalUtil, ObjectInitType } from "@eggjs/tegg";
|
|
3
|
-
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
4
|
-
import { EggObjectFactory, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
5
|
-
|
|
6
|
-
//#region src/lib/AppLoadUnitInstance.ts
|
|
7
|
-
var AppLoadUnitInstance = class AppLoadUnitInstance {
|
|
8
|
-
loadUnit;
|
|
9
|
-
id;
|
|
10
|
-
name;
|
|
11
|
-
protoToCreateMap = /* @__PURE__ */ new Map();
|
|
12
|
-
eggObjectMap = /* @__PURE__ */ new Map();
|
|
13
|
-
eggObjectPromiseMap = /* @__PURE__ */ new Map();
|
|
14
|
-
constructor(loadUnit) {
|
|
15
|
-
this.loadUnit = loadUnit;
|
|
16
|
-
this.name = loadUnit.name;
|
|
17
|
-
const iterator = this.loadUnit.iterateEggPrototype();
|
|
18
|
-
for (const proto of iterator) if (proto.initType === ObjectInitType.SINGLETON) this.protoToCreateMap.set(proto.name, proto);
|
|
19
|
-
this.id = IdenticalUtil.createLoadUnitInstanceId(loadUnit.id);
|
|
20
|
-
}
|
|
21
|
-
iterateProtoToCreate() {
|
|
22
|
-
return this.protoToCreateMap.entries();
|
|
23
|
-
}
|
|
24
|
-
addProtoToCreate(name, proto) {
|
|
25
|
-
this.protoToCreateMap.set(name, proto);
|
|
26
|
-
}
|
|
27
|
-
deleteProtoToCreate(name) {
|
|
28
|
-
this.protoToCreateMap.delete(name);
|
|
29
|
-
}
|
|
30
|
-
async init(ctx) {
|
|
31
|
-
await LoadUnitInstanceLifecycleUtil.objectPreCreate(ctx, this);
|
|
32
|
-
for (const [name, proto] of this.protoToCreateMap) await this.getOrCreateEggObject(name, proto);
|
|
33
|
-
}
|
|
34
|
-
async destroy() {
|
|
35
|
-
const objs = [];
|
|
36
|
-
for (const protoObjMap of this.eggObjectMap.values()) for (const protoObj of protoObjMap.values()) objs.push(protoObj);
|
|
37
|
-
this.eggObjectMap.clear();
|
|
38
|
-
await Promise.all(objs.map(async (obj) => {
|
|
39
|
-
await EggObjectFactory.destroyObject(obj);
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
async getOrCreateEggObject(name, proto) {
|
|
43
|
-
if (!this.loadUnit.containPrototype(proto)) throw new Error("load unit not contain proto");
|
|
44
|
-
const protoObjMap = MapUtil.getOrStore(this.eggObjectMap, proto.id, /* @__PURE__ */ new Map());
|
|
45
|
-
if (!protoObjMap.has(name)) {
|
|
46
|
-
const protoObjPromiseMap = MapUtil.getOrStore(this.eggObjectPromiseMap, proto.id, /* @__PURE__ */ new Map());
|
|
47
|
-
if (!protoObjPromiseMap.has(name)) {
|
|
48
|
-
const objPromise = EggObjectFactory.createObject(name, proto);
|
|
49
|
-
protoObjPromiseMap.set(name, objPromise);
|
|
50
|
-
const obj = await objPromise;
|
|
51
|
-
protoObjPromiseMap.delete(name);
|
|
52
|
-
protoObjMap.set(name, obj);
|
|
53
|
-
} else await protoObjPromiseMap.get(name);
|
|
54
|
-
}
|
|
55
|
-
return protoObjMap.get(name);
|
|
56
|
-
}
|
|
57
|
-
getEggObject(name, proto) {
|
|
58
|
-
const protoObjMap = this.eggObjectMap.get(proto.id);
|
|
59
|
-
if (!protoObjMap || !protoObjMap.has(name)) throw new Error(`EggObject ${String(proto.name)} not found`);
|
|
60
|
-
return protoObjMap.get(name);
|
|
61
|
-
}
|
|
62
|
-
static createModuleLoadUnitInstance(ctx) {
|
|
63
|
-
return new AppLoadUnitInstance(ctx.loadUnit);
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
LoadUnitInstanceFactory.registerLoadUnitInstanceClass(EggLoadUnitType.APP, AppLoadUnitInstance.createModuleLoadUnitInstance);
|
|
67
|
-
|
|
68
|
-
//#endregion
|
|
69
|
-
export { AppLoadUnitInstance };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EggPrototype, LoadUnit } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { EggObjectName, EggPrototypeName } from "@eggjs/tegg";
|
|
3
|
-
import { EggObject, LoadUnitInstance, LoadUnitInstanceLifecycleContext } from "@eggjs/tegg-runtime";
|
|
4
|
-
|
|
5
|
-
//#region src/lib/AppLoadUnitInstance.d.ts
|
|
6
|
-
declare class AppLoadUnitInstance implements LoadUnitInstance {
|
|
7
|
-
readonly loadUnit: LoadUnit;
|
|
8
|
-
readonly id: string;
|
|
9
|
-
readonly name: string;
|
|
10
|
-
private protoToCreateMap;
|
|
11
|
-
private eggObjectMap;
|
|
12
|
-
private eggObjectPromiseMap;
|
|
13
|
-
constructor(loadUnit: LoadUnit);
|
|
14
|
-
iterateProtoToCreate(): IterableIterator<[EggObjectName, EggPrototype]>;
|
|
15
|
-
addProtoToCreate(name: string, proto: EggPrototype): void;
|
|
16
|
-
deleteProtoToCreate(name: string): void;
|
|
17
|
-
init(ctx: LoadUnitInstanceLifecycleContext): Promise<void>;
|
|
18
|
-
destroy(): Promise<void>;
|
|
19
|
-
getOrCreateEggObject(name: EggPrototypeName, proto: EggPrototype): Promise<EggObject>;
|
|
20
|
-
getEggObject(name: EggPrototypeName, proto: EggPrototype): EggObject;
|
|
21
|
-
static createModuleLoadUnitInstance(ctx: LoadUnitInstanceLifecycleContext): LoadUnitInstance;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { AppLoadUnitInstance };
|