@eggjs/tegg-plugin 4.0.0-beta.9 → 4.0.2-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 -49
- package/dist/app/extend/application.js +69 -79
- package/dist/app/extend/application.unittest.d.ts +9 -21
- package/dist/app/extend/application.unittest.js +39 -53
- package/dist/app/extend/context.d.ts +12 -19
- package/dist/app/extend/context.js +27 -34
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +6 -3
- package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +7 -3
- package/dist/app.d.ts +20 -16
- package/dist/app.js +50 -56
- package/dist/index.d.ts +3 -3
- package/dist/index.js +4 -3
- package/dist/lib/AppLoadUnit.d.ts +23 -18
- package/dist/lib/AppLoadUnit.js +77 -89
- package/dist/lib/AppLoadUnitInstance.d.ts +23 -19
- package/dist/lib/AppLoadUnitInstance.js +69 -81
- package/dist/lib/CompatibleUtil.d.ts +22 -13
- package/dist/lib/CompatibleUtil.js +99 -95
- package/dist/lib/ConfigSourceLoadUnitHook.d.ts +13 -8
- package/dist/lib/ConfigSourceLoadUnitHook.js +20 -20
- package/dist/lib/EggAppLoader.d.ts +19 -15
- package/dist/lib/EggAppLoader.js +104 -127
- package/dist/lib/EggCompatibleObject.d.ts +19 -17
- package/dist/lib/EggCompatibleObject.js +34 -40
- package/dist/lib/EggCompatibleProtoImpl.d.ts +25 -20
- package/dist/lib/EggCompatibleProtoImpl.js +49 -52
- package/dist/lib/EggContextCompatibleHook.d.ts +13 -9
- package/dist/lib/EggContextCompatibleHook.js +32 -44
- package/dist/lib/EggContextHandler.d.ts +12 -8
- package/dist/lib/EggContextHandler.js +28 -26
- package/dist/lib/EggContextImpl.d.ts +9 -5
- package/dist/lib/EggContextImpl.js +18 -15
- package/dist/lib/EggModuleLoader.d.ts +16 -10
- package/dist/lib/EggModuleLoader.js +53 -53
- package/dist/lib/EggQualifierProtoHook.d.ts +13 -9
- package/dist/lib/EggQualifierProtoHook.js +46 -62
- package/dist/lib/ModuleConfigLoader.d.ts +11 -7
- package/dist/lib/ModuleConfigLoader.js +81 -80
- package/dist/lib/ModuleHandler.d.ts +17 -12
- package/dist/lib/ModuleHandler.js +47 -52
- package/dist/lib/Utils.d.ts +4 -1
- package/dist/lib/Utils.js +30 -33
- package/dist/lib/ctx_lifecycle_middleware.d.ts +6 -2
- package/dist/lib/ctx_lifecycle_middleware.js +36 -31
- package/dist/lib/run_in_background.d.ts +7 -3
- package/dist/lib/run_in_background.js +46 -54
- package/dist/types.d.ts +54 -8
- package/dist/types.js +3 -5
- package/package.json +49 -54
|
@@ -1,33 +1,38 @@
|
|
|
1
|
-
import { ROOT_PROTO, TEGG_CONTEXT } from '@eggjs/egg-module-common';
|
|
2
|
-
import {} from '@eggjs/tegg-runtime';
|
|
3
1
|
import { EggContextImpl } from "./EggContextImpl.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
2
|
+
import { StreamUtil } from "@eggjs/tegg-common-util";
|
|
3
|
+
import { ROOT_PROTO, TEGG_CONTEXT } from "@eggjs/module-common";
|
|
4
|
+
import awaitFirst from "await-first";
|
|
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
|
+
}
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { ctxLifecycleMiddleware };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import { Application } from
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Application } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/run_in_background.d.ts
|
|
4
|
+
declare const LONG_STACK_DELIMITER = "\n --------------------\n";
|
|
5
|
+
declare function hijackRunInBackground(app: Application): void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { LONG_STACK_DELIMITER, hijackRunInBackground };
|
|
@@ -1,58 +1,50 @@
|
|
|
1
|
-
import { Application } from 'egg';
|
|
2
|
-
import { BackgroundTaskHelper, PrototypeUtil } from '@eggjs/tegg';
|
|
3
|
-
import {} from '@eggjs/tegg-metadata';
|
|
4
|
-
import { TEGG_CONTEXT } from '@eggjs/egg-module-common';
|
|
5
|
-
import TEggPluginContext from "../app/extend/context.js";
|
|
6
1
|
import { getCalleeFromStack } from "./Utils.js";
|
|
7
|
-
|
|
2
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
3
|
+
import { BackgroundTaskHelper } from "@eggjs/background-task";
|
|
4
|
+
import { TEGG_CONTEXT } from "@eggjs/module-common";
|
|
5
|
+
|
|
6
|
+
//#region src/lib/run_in_background.ts
|
|
7
|
+
const LONG_STACK_DELIMITER = "\n --------------------\n";
|
|
8
8
|
function addLongStackTrace(err, causeError) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const index = callSiteStack.indexOf('\n');
|
|
14
|
-
if (index !== -1) {
|
|
15
|
-
err.stack += LONG_STACK_DELIMITER + callSiteStack.substring(index + 1);
|
|
16
|
-
}
|
|
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);
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const eggObject = app.eggContainerFactory.getEggObject(proto);
|
|
52
|
-
const backgroundTaskHelper = eggObject.obj;
|
|
53
|
-
backgroundTaskHelper.run(async () => {
|
|
54
|
-
await backgroundTaskPromise;
|
|
55
|
-
});
|
|
56
|
-
};
|
|
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
|
+
};
|
|
57
47
|
}
|
|
58
|
-
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { LONG_STACK_DELIMITER, hijackRunInBackground };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,54 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,5 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import "./app/extend/context.js";
|
|
5
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvdHlwZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTywwQkFBMEIsQ0FBQztBQUVsQyxPQUFPLDZCQUE2QixDQUFDO0FBQ3JDLE9BQU8sc0NBQXNDLENBQUM7QUFDOUMsT0FBTyx5QkFBeUIsQ0FBQyJ9
|
|
1
|
+
import "@eggjs/tegg-config/types";
|
|
2
|
+
|
|
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.9",
|
|
3
|
+
"version": "4.0.2-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-runtime": "4.0.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
"egg": "beta",
|
|
75
|
-
"@eggjs/tegg-config": "4.0.0-beta.9"
|
|
62
|
+
"@eggjs/background-task": "4.0.2-beta.0",
|
|
63
|
+
"@eggjs/dynamic-inject-runtime": "4.0.2-beta.0",
|
|
64
|
+
"@eggjs/lifecycle": "4.0.2-beta.0",
|
|
65
|
+
"@eggjs/core-decorator": "4.0.2-beta.0",
|
|
66
|
+
"@eggjs/module-common": "4.0.2-beta.0",
|
|
67
|
+
"@eggjs/metadata": "4.0.2-beta.0",
|
|
68
|
+
"@eggjs/tegg-loader": "4.0.2-beta.0",
|
|
69
|
+
"@eggjs/tegg-runtime": "4.0.2-beta.0",
|
|
70
|
+
"@eggjs/tegg-common-util": "4.0.2-beta.0",
|
|
71
|
+
"@eggjs/tegg-types": "4.0.2-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.2-beta.0",
|
|
78
|
+
"@eggjs/mock": "7.0.2-beta.0",
|
|
79
|
+
"@eggjs/tegg-config": "4.0.2-beta.0",
|
|
80
|
+
"@eggjs/tracer": "4.0.2-beta.0",
|
|
81
|
+
"egg": "4.1.2-beta.0"
|
|
90
82
|
},
|
|
91
|
-
"
|
|
92
|
-
"
|
|
83
|
+
"peerDependencies": {
|
|
84
|
+
"@eggjs/tegg-config": "4.0.2-beta.0",
|
|
85
|
+
"egg": "4.1.2-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 && rimraf dist && tsc -b --clean && tsc -p tsconfig.build.json"
|
|
97
|
+
"typecheck": "tsgo --noEmit"
|
|
103
98
|
}
|
|
104
99
|
}
|