@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,4 +1,29 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
1
|
+
import { EggProtoImplClass, QualifierInfo } from "@eggjs/core-decorator";
|
|
2
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
3
|
+
import { EggPrototypeCreatorFactory, EggPrototypeFactory, EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from "@eggjs/metadata";
|
|
4
|
+
import { AbstractEggContext, EggContainerFactory, EggContextLifecycleUtil, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
5
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
6
|
+
import { RuntimeConfig } from "@eggjs/tegg-types";
|
|
7
|
+
|
|
8
|
+
//#region src/app/extend/application.d.ts
|
|
9
|
+
declare class TEggPluginApplication {
|
|
10
|
+
get eggPrototypeCreatorFactory(): typeof EggPrototypeCreatorFactory;
|
|
11
|
+
get eggPrototypeFactory(): EggPrototypeFactory;
|
|
12
|
+
get loadUnitLifecycleUtil(): typeof LoadUnitLifecycleUtil;
|
|
13
|
+
get loadUnitFactory(): typeof LoadUnitFactory;
|
|
14
|
+
get eggObjectFactory(): typeof EggObjectFactory;
|
|
15
|
+
get loadUnitInstanceFactory(): typeof LoadUnitInstanceFactory;
|
|
16
|
+
get loadUnitInstanceLifecycleUtil(): typeof LoadUnitInstanceLifecycleUtil;
|
|
17
|
+
get eggContainerFactory(): typeof EggContainerFactory;
|
|
18
|
+
get loaderFactory(): typeof LoaderFactory;
|
|
19
|
+
get eggPrototypeLifecycleUtil(): typeof EggPrototypeLifecycleUtil;
|
|
20
|
+
get eggContextLifecycleUtil(): typeof EggContextLifecycleUtil;
|
|
21
|
+
get eggObjectLifecycleUtil(): typeof EggObjectLifecycleUtil;
|
|
22
|
+
get abstractEggContext(): typeof AbstractEggContext;
|
|
23
|
+
get identicalUtil(): typeof IdenticalUtil;
|
|
24
|
+
get runtimeConfig(): RuntimeConfig;
|
|
25
|
+
getEggObject<T>(clazz: EggProtoImplClass<T>, name?: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
26
|
+
getEggObjectFromName<T extends object>(name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
4
29
|
export { TEggPluginApplication as default };
|
|
@@ -1,10 +1,69 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "
|
|
3
|
-
import "
|
|
4
|
-
import "
|
|
5
|
-
import "../../CompatibleUtil-CNhydb0E.js";
|
|
6
|
-
import "../../ModuleHandler-fKcUqWca.js";
|
|
7
|
-
import "../../EggContextHandler-D8gfTbZs.js";
|
|
8
|
-
import { TEggPluginApplication } from "../../application-DFI1junS.js";
|
|
1
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
2
|
+
import { EggPrototypeCreatorFactory, EggPrototypeFactory, EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from "@eggjs/metadata";
|
|
3
|
+
import { AbstractEggContext, EggContainerFactory, EggContextLifecycleUtil, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
4
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
9
5
|
|
|
6
|
+
//#region src/app/extend/application.ts
|
|
7
|
+
var TEggPluginApplication = class {
|
|
8
|
+
get eggPrototypeCreatorFactory() {
|
|
9
|
+
return EggPrototypeCreatorFactory;
|
|
10
|
+
}
|
|
11
|
+
get eggPrototypeFactory() {
|
|
12
|
+
return EggPrototypeFactory.instance;
|
|
13
|
+
}
|
|
14
|
+
get loadUnitLifecycleUtil() {
|
|
15
|
+
return LoadUnitLifecycleUtil;
|
|
16
|
+
}
|
|
17
|
+
get loadUnitFactory() {
|
|
18
|
+
return LoadUnitFactory;
|
|
19
|
+
}
|
|
20
|
+
get eggObjectFactory() {
|
|
21
|
+
return EggObjectFactory;
|
|
22
|
+
}
|
|
23
|
+
get loadUnitInstanceFactory() {
|
|
24
|
+
return LoadUnitInstanceFactory;
|
|
25
|
+
}
|
|
26
|
+
get loadUnitInstanceLifecycleUtil() {
|
|
27
|
+
return LoadUnitInstanceLifecycleUtil;
|
|
28
|
+
}
|
|
29
|
+
get eggContainerFactory() {
|
|
30
|
+
return EggContainerFactory;
|
|
31
|
+
}
|
|
32
|
+
get loaderFactory() {
|
|
33
|
+
return LoaderFactory;
|
|
34
|
+
}
|
|
35
|
+
get eggPrototypeLifecycleUtil() {
|
|
36
|
+
return EggPrototypeLifecycleUtil;
|
|
37
|
+
}
|
|
38
|
+
get eggContextLifecycleUtil() {
|
|
39
|
+
return EggContextLifecycleUtil;
|
|
40
|
+
}
|
|
41
|
+
get eggObjectLifecycleUtil() {
|
|
42
|
+
return EggObjectLifecycleUtil;
|
|
43
|
+
}
|
|
44
|
+
get abstractEggContext() {
|
|
45
|
+
return AbstractEggContext;
|
|
46
|
+
}
|
|
47
|
+
get identicalUtil() {
|
|
48
|
+
return IdenticalUtil;
|
|
49
|
+
}
|
|
50
|
+
get runtimeConfig() {
|
|
51
|
+
const config = this.config;
|
|
52
|
+
return {
|
|
53
|
+
baseDir: config.baseDir,
|
|
54
|
+
env: config.env,
|
|
55
|
+
name: config.name
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async getEggObject(clazz, name, qualifiers) {
|
|
59
|
+
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
60
|
+
return (await EggContainerFactory.getOrCreateEggObjectFromClazz(clazz, name, qualifiers)).obj;
|
|
61
|
+
}
|
|
62
|
+
async getEggObjectFromName(name, qualifiers) {
|
|
63
|
+
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
64
|
+
return (await EggContainerFactory.getOrCreateEggObjectFromName(name, qualifiers)).obj;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
10
69
|
export { TEggPluginApplication as default };
|
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Application, Context } from "egg";
|
|
2
|
+
|
|
3
|
+
//#region src/app/extend/application.unittest.d.ts
|
|
4
|
+
declare class TEggPluginApplicationUnittest {
|
|
5
|
+
mockModuleContext(this: Application, data?: any): Promise<Context>;
|
|
6
|
+
destroyModuleContext(this: Application, ctx: Context): Promise<void>;
|
|
7
|
+
mockModuleContextScope<R = any>(fn: (ctx: Context) => Promise<R>, data?: any): Promise<R>;
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
2
10
|
export { TEggPluginApplicationUnittest as default };
|
|
@@ -1,4 +1,41 @@
|
|
|
1
|
-
import "../../EggContextImpl
|
|
2
|
-
import { TEggPluginApplicationUnittest } from "../../application.unittest-Cmia71Fx.js";
|
|
1
|
+
import { EggContextImpl } from "../../lib/EggContextImpl.js";
|
|
3
2
|
|
|
3
|
+
//#region src/app/extend/application.unittest.ts
|
|
4
|
+
const TEGG_LIFECYCLE_CACHE = /* @__PURE__ */ new Map();
|
|
5
|
+
let hasMockModuleContext = false;
|
|
6
|
+
var TEggPluginApplicationUnittest = class {
|
|
7
|
+
async mockModuleContext(data) {
|
|
8
|
+
this.deprecate("app.mockModuleContext is deprecated, use mockModuleContextScope.");
|
|
9
|
+
if (hasMockModuleContext) throw new Error("should not call mockModuleContext twice.");
|
|
10
|
+
const ctx = this.mockContext(data);
|
|
11
|
+
const teggCtx = new EggContextImpl(ctx);
|
|
12
|
+
const lifecycle = {};
|
|
13
|
+
TEGG_LIFECYCLE_CACHE.set(teggCtx, lifecycle);
|
|
14
|
+
if (teggCtx.init) await teggCtx.init(lifecycle);
|
|
15
|
+
hasMockModuleContext = true;
|
|
16
|
+
return ctx;
|
|
17
|
+
}
|
|
18
|
+
async destroyModuleContext(ctx) {
|
|
19
|
+
hasMockModuleContext = false;
|
|
20
|
+
const teggCtx = ctx.teggContext;
|
|
21
|
+
if (!teggCtx) return;
|
|
22
|
+
const lifecycle = TEGG_LIFECYCLE_CACHE.get(teggCtx);
|
|
23
|
+
if (teggCtx.destroy && lifecycle) await teggCtx.destroy(lifecycle);
|
|
24
|
+
}
|
|
25
|
+
async mockModuleContextScope(fn, data) {
|
|
26
|
+
if (hasMockModuleContext) throw new Error("mockModuleContextScope can not use with mockModuleContext, should use mockModuleContextScope only.");
|
|
27
|
+
return this.mockContextScope(async (ctx) => {
|
|
28
|
+
const teggCtx = new EggContextImpl(ctx);
|
|
29
|
+
const lifecycle = {};
|
|
30
|
+
if (teggCtx.init) await teggCtx.init(lifecycle);
|
|
31
|
+
try {
|
|
32
|
+
return await fn(ctx);
|
|
33
|
+
} finally {
|
|
34
|
+
await teggCtx.destroy(lifecycle);
|
|
35
|
+
}
|
|
36
|
+
}, data);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
4
41
|
export { TEggPluginApplicationUnittest as default };
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EggProtoImplClass, QualifierInfo } from "@eggjs/core-decorator";
|
|
2
|
+
import { EggContext } from "@eggjs/tegg-runtime";
|
|
3
|
+
import { Context } from "egg";
|
|
4
|
+
|
|
5
|
+
//#region src/app/extend/context.d.ts
|
|
6
|
+
declare class TEggPluginContext {
|
|
7
|
+
beginModuleScope(this: Context, func: () => Promise<void>): Promise<void>;
|
|
8
|
+
get teggContext(): EggContext;
|
|
9
|
+
getEggObject<T>(this: Context, clazz: EggProtoImplClass<T>, name?: string): Promise<T>;
|
|
10
|
+
getEggObjectFromName<T>(this: Context, name: string, qualifiers?: QualifierInfo | QualifierInfo[]): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
//#endregion
|
|
2
13
|
export { TEggPluginContext as default };
|
|
@@ -1,5 +1,28 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import "
|
|
3
|
-
import {
|
|
1
|
+
import { ctxLifecycleMiddleware } from "../../lib/ctx_lifecycle_middleware.js";
|
|
2
|
+
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
3
|
+
import { TEGG_CONTEXT } from "@eggjs/module-common";
|
|
4
4
|
|
|
5
|
+
//#region src/app/extend/context.ts
|
|
6
|
+
var TEggPluginContext = class {
|
|
7
|
+
async beginModuleScope(func) {
|
|
8
|
+
await ctxLifecycleMiddleware(this, func);
|
|
9
|
+
}
|
|
10
|
+
get teggContext() {
|
|
11
|
+
const ctx = this;
|
|
12
|
+
if (!ctx[TEGG_CONTEXT]) throw new Error("tegg context have not ready, should call after teggCtxLifecycleMiddleware");
|
|
13
|
+
return ctx[TEGG_CONTEXT];
|
|
14
|
+
}
|
|
15
|
+
async getEggObject(clazz, name) {
|
|
16
|
+
const protoObj = PrototypeUtil.getClazzProto(clazz);
|
|
17
|
+
if (!protoObj) throw new Error(`can not get proto for clazz ${clazz.name}`);
|
|
18
|
+
const proto = protoObj;
|
|
19
|
+
return (await this.app.eggContainerFactory.getOrCreateEggObject(proto, name ?? proto.name)).obj;
|
|
20
|
+
}
|
|
21
|
+
async getEggObjectFromName(name, qualifiers) {
|
|
22
|
+
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
23
|
+
return (await this.app.eggContainerFactory.getOrCreateEggObjectFromName(name, qualifiers)).obj;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
5
28
|
export { TEggPluginContext as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MiddlewareFunc } from "egg";
|
|
2
2
|
|
|
3
3
|
//#region src/app/middleware/tegg_ctx_lifecycle_middleware.d.ts
|
|
4
|
-
declare const _default: () =>
|
|
4
|
+
declare const _default: () => MiddlewareFunc;
|
|
5
5
|
//#endregion
|
|
6
6
|
export { _default as default };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import "../../
|
|
2
|
-
import { ctxLifecycleMiddleware } from "../../ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
1
|
+
import { ctxLifecycleMiddleware } from "../../lib/ctx_lifecycle_middleware.js";
|
|
3
2
|
|
|
4
3
|
//#region src/app/middleware/tegg_ctx_lifecycle_middleware.ts
|
|
5
4
|
var tegg_ctx_lifecycle_middleware_default = () => {
|
package/dist/app.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import "./AppLoadUnit
|
|
2
|
-
import "./AppLoadUnitInstance
|
|
3
|
-
import "./
|
|
4
|
-
import "./EggCompatibleObject-lzUCfsIY.js";
|
|
1
|
+
import "./lib/AppLoadUnit.js";
|
|
2
|
+
import "./lib/AppLoadUnitInstance.js";
|
|
3
|
+
import "./lib/EggCompatibleObject.js";
|
|
5
4
|
import { Application, ILifecycleBoot } from "egg";
|
|
6
5
|
|
|
7
6
|
//#region src/app.d.ts
|
|
8
|
-
declare class
|
|
7
|
+
declare class TeggAppBoot implements ILifecycleBoot {
|
|
9
8
|
private readonly app;
|
|
10
9
|
private compatibleHook?;
|
|
11
10
|
private eggContextHandler;
|
|
@@ -19,4 +18,4 @@ declare class App implements ILifecycleBoot {
|
|
|
19
18
|
beforeClose(): Promise<void>;
|
|
20
19
|
}
|
|
21
20
|
//#endregion
|
|
22
|
-
export {
|
|
21
|
+
export { TeggAppBoot as default };
|
package/dist/app.js
CHANGED
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import "./AppLoadUnit
|
|
2
|
-
import "./AppLoadUnitInstance
|
|
3
|
-
import "./
|
|
4
|
-
import "./
|
|
5
|
-
import "./
|
|
6
|
-
import "./
|
|
7
|
-
import "./
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
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";
|
|
19
|
-
import { LoadUnitMultiInstanceProtoHook } from "@eggjs/tegg-metadata";
|
|
1
|
+
import "./lib/AppLoadUnit.js";
|
|
2
|
+
import "./lib/AppLoadUnitInstance.js";
|
|
3
|
+
import "./lib/EggCompatibleObject.js";
|
|
4
|
+
import { CompatibleUtil } from "./lib/CompatibleUtil.js";
|
|
5
|
+
import { ConfigSourceLoadUnitHook } from "./lib/ConfigSourceLoadUnitHook.js";
|
|
6
|
+
import { ModuleHandler } from "./lib/ModuleHandler.js";
|
|
7
|
+
import { EggContextCompatibleHook } from "./lib/EggContextCompatibleHook.js";
|
|
8
|
+
import { EggContextHandler } from "./lib/EggContextHandler.js";
|
|
9
|
+
import { EggQualifierProtoHook } from "./lib/EggQualifierProtoHook.js";
|
|
10
|
+
import { hijackRunInBackground } from "./lib/run_in_background.js";
|
|
11
|
+
import { LoadUnitMultiInstanceProtoHook } from "@eggjs/metadata";
|
|
20
12
|
|
|
21
13
|
//#region src/app.ts
|
|
22
|
-
var
|
|
14
|
+
var TeggAppBoot = class {
|
|
23
15
|
app;
|
|
24
16
|
compatibleHook;
|
|
25
17
|
eggContextHandler;
|
|
@@ -62,4 +54,4 @@ var App = class {
|
|
|
62
54
|
};
|
|
63
55
|
|
|
64
56
|
//#endregion
|
|
65
|
-
export {
|
|
57
|
+
export { TeggAppBoot as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
4
|
-
import "./application.unittest-CpoCu6-E.js";
|
|
5
|
-
import "./context-BoIt2G5h.js";
|
|
6
|
-
import "./types-CuoKQV4X.js";
|
|
1
|
+
import "./app/extend/application.js";
|
|
2
|
+
import "./app/extend/context.js";
|
|
3
|
+
import "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
import "./
|
|
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 "./types.js";
|
|
2
|
+
import "./app/extend/application.js";
|
|
3
|
+
import "./app/extend/context.js";
|
|
14
4
|
|
|
15
5
|
export { };
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { QualifierInfo } from "@eggjs/core-decorator";
|
|
2
|
+
import { EggLoadUnitTypeLike, EggPrototype, LoadUnit, LoadUnitLifecycleContext, Loader } from "@eggjs/metadata";
|
|
3
|
+
import { Id } from "@eggjs/tegg-types";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/AppLoadUnit.d.ts
|
|
6
|
+
declare class AppLoadUnit implements LoadUnit {
|
|
7
|
+
private readonly loader;
|
|
8
|
+
id: Id;
|
|
9
|
+
readonly name: string;
|
|
10
|
+
readonly type: EggLoadUnitTypeLike;
|
|
11
|
+
readonly unitPath: string;
|
|
12
|
+
private protoMap;
|
|
13
|
+
constructor(name: string, unitPath: string, loader: Loader);
|
|
14
|
+
init(): Promise<void>;
|
|
15
|
+
containPrototype(proto: EggPrototype): boolean;
|
|
16
|
+
getEggPrototype(name: string, qualifiers: QualifierInfo[]): EggPrototype[];
|
|
17
|
+
registerEggPrototype(proto: EggPrototype): void;
|
|
18
|
+
deletePrototype(proto: EggPrototype): void;
|
|
19
|
+
destroy(): Promise<void>;
|
|
20
|
+
iterateEggPrototype(): IterableIterator<EggPrototype>;
|
|
21
|
+
static createModule(ctx: LoadUnitLifecycleContext): AppLoadUnit;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
2
24
|
export { AppLoadUnit };
|
package/dist/lib/AppLoadUnit.js
CHANGED
|
@@ -1,3 +1,78 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { debuglog } from "node:util";
|
|
2
|
+
import { InitTypeQualifierAttribute, LoadUnitNameQualifierAttribute, PrototypeUtil, QualifierUtil } from "@eggjs/core-decorator";
|
|
3
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
4
|
+
import { EggLoadUnitType, EggPrototypeCreatorFactory, EggPrototypeFactory, LoadUnitFactory } from "@eggjs/metadata";
|
|
5
|
+
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
2
6
|
|
|
7
|
+
//#region src/lib/AppLoadUnit.ts
|
|
8
|
+
const debug = debuglog("egg/tegg/plugin/tegg/lib/AppLoadUnit");
|
|
9
|
+
var AppLoadUnit = class AppLoadUnit {
|
|
10
|
+
loader;
|
|
11
|
+
id;
|
|
12
|
+
name;
|
|
13
|
+
type = EggLoadUnitType.APP;
|
|
14
|
+
unitPath;
|
|
15
|
+
protoMap = /* @__PURE__ */ new Map();
|
|
16
|
+
constructor(name, unitPath, loader) {
|
|
17
|
+
this.id = IdenticalUtil.createLoadUnitId(name);
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.unitPath = unitPath;
|
|
20
|
+
this.loader = loader;
|
|
21
|
+
}
|
|
22
|
+
async init() {
|
|
23
|
+
const clazzList = await this.loader.load();
|
|
24
|
+
if (debug.enabled) debug("init, get clazzList:%j, from unitPath:%o:%o:%o", clazzList.map((t) => t.name), this.type, this.name, this.unitPath);
|
|
25
|
+
for (const clazz of clazzList) {
|
|
26
|
+
[{
|
|
27
|
+
attribute: InitTypeQualifierAttribute,
|
|
28
|
+
value: await PrototypeUtil.getInitType(clazz, {
|
|
29
|
+
unitPath: this.unitPath,
|
|
30
|
+
moduleName: this.name
|
|
31
|
+
})
|
|
32
|
+
}, {
|
|
33
|
+
attribute: LoadUnitNameQualifierAttribute,
|
|
34
|
+
value: this.name
|
|
35
|
+
}].forEach((qualifier) => {
|
|
36
|
+
QualifierUtil.addProtoQualifier(clazz, qualifier.attribute, qualifier.value, true);
|
|
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
|
|
3
78
|
export { AppLoadUnit };
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EggObjectName, EggPrototypeName } from "@eggjs/core-decorator";
|
|
2
|
+
import { EggPrototype, LoadUnit } from "@eggjs/metadata";
|
|
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
|
|
2
24
|
export { AppLoadUnitInstance };
|
|
@@ -1,3 +1,70 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ObjectInitType } from "@eggjs/core-decorator";
|
|
2
|
+
import { IdenticalUtil } from "@eggjs/lifecycle";
|
|
3
|
+
import { EggLoadUnitType } from "@eggjs/metadata";
|
|
4
|
+
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
5
|
+
import { EggObjectFactory, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
2
6
|
|
|
7
|
+
//#region src/lib/AppLoadUnitInstance.ts
|
|
8
|
+
var AppLoadUnitInstance = class AppLoadUnitInstance {
|
|
9
|
+
loadUnit;
|
|
10
|
+
id;
|
|
11
|
+
name;
|
|
12
|
+
protoToCreateMap = /* @__PURE__ */ new Map();
|
|
13
|
+
eggObjectMap = /* @__PURE__ */ new Map();
|
|
14
|
+
eggObjectPromiseMap = /* @__PURE__ */ new Map();
|
|
15
|
+
constructor(loadUnit) {
|
|
16
|
+
this.loadUnit = loadUnit;
|
|
17
|
+
this.name = loadUnit.name;
|
|
18
|
+
const iterator = this.loadUnit.iterateEggPrototype();
|
|
19
|
+
for (const proto of iterator) if (proto.initType === ObjectInitType.SINGLETON) this.protoToCreateMap.set(proto.name, proto);
|
|
20
|
+
this.id = IdenticalUtil.createLoadUnitInstanceId(loadUnit.id);
|
|
21
|
+
}
|
|
22
|
+
iterateProtoToCreate() {
|
|
23
|
+
return this.protoToCreateMap.entries();
|
|
24
|
+
}
|
|
25
|
+
addProtoToCreate(name, proto) {
|
|
26
|
+
this.protoToCreateMap.set(name, proto);
|
|
27
|
+
}
|
|
28
|
+
deleteProtoToCreate(name) {
|
|
29
|
+
this.protoToCreateMap.delete(name);
|
|
30
|
+
}
|
|
31
|
+
async init(ctx) {
|
|
32
|
+
await LoadUnitInstanceLifecycleUtil.objectPreCreate(ctx, this);
|
|
33
|
+
for (const [name, proto] of this.protoToCreateMap) await this.getOrCreateEggObject(name, proto);
|
|
34
|
+
}
|
|
35
|
+
async destroy() {
|
|
36
|
+
const objs = [];
|
|
37
|
+
for (const protoObjMap of this.eggObjectMap.values()) for (const protoObj of protoObjMap.values()) objs.push(protoObj);
|
|
38
|
+
this.eggObjectMap.clear();
|
|
39
|
+
await Promise.all(objs.map(async (obj) => {
|
|
40
|
+
await EggObjectFactory.destroyObject(obj);
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
43
|
+
async getOrCreateEggObject(name, proto) {
|
|
44
|
+
if (!this.loadUnit.containPrototype(proto)) throw new Error("load unit not contain proto");
|
|
45
|
+
const protoObjMap = MapUtil.getOrStore(this.eggObjectMap, proto.id, /* @__PURE__ */ new Map());
|
|
46
|
+
if (!protoObjMap.has(name)) {
|
|
47
|
+
const protoObjPromiseMap = MapUtil.getOrStore(this.eggObjectPromiseMap, proto.id, /* @__PURE__ */ new Map());
|
|
48
|
+
if (!protoObjPromiseMap.has(name)) {
|
|
49
|
+
const objPromise = EggObjectFactory.createObject(name, proto);
|
|
50
|
+
protoObjPromiseMap.set(name, objPromise);
|
|
51
|
+
const obj = await objPromise;
|
|
52
|
+
protoObjPromiseMap.delete(name);
|
|
53
|
+
protoObjMap.set(name, obj);
|
|
54
|
+
} else await protoObjPromiseMap.get(name);
|
|
55
|
+
}
|
|
56
|
+
return protoObjMap.get(name);
|
|
57
|
+
}
|
|
58
|
+
getEggObject(name, proto) {
|
|
59
|
+
const protoObjMap = this.eggObjectMap.get(proto.id);
|
|
60
|
+
if (!protoObjMap || !protoObjMap.has(name)) throw new Error(`EggObject ${String(proto.name)} not found`);
|
|
61
|
+
return protoObjMap.get(name);
|
|
62
|
+
}
|
|
63
|
+
static createModuleLoadUnitInstance(ctx) {
|
|
64
|
+
return new AppLoadUnitInstance(ctx.loadUnit);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
LoadUnitInstanceFactory.registerLoadUnitInstanceClass(EggLoadUnitType.APP, AppLoadUnitInstance.createModuleLoadUnitInstance);
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
3
70
|
export { AppLoadUnitInstance };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EggPrototype } from "@eggjs/
|
|
1
|
+
import { EggPrototype } from "@eggjs/metadata";
|
|
2
2
|
import { LoadUnitInstance } from "@eggjs/tegg-runtime";
|
|
3
3
|
import { Application, Context } from "egg";
|
|
4
4
|
|
|
@@ -11,7 +11,12 @@ declare class CompatibleUtil {
|
|
|
11
11
|
private static singletonModuleProxyFactory;
|
|
12
12
|
static appCompatible(app: Application, loadUnitInstance: LoadUnitInstance): void;
|
|
13
13
|
static contextModuleProxyFactory(holder: Record<string, any>, ctx: Context, loadUnitInstance: LoadUnitInstance): any;
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Compatible the context module, only for koa application
|
|
16
|
+
* @param contextPrototype - The prototype of the context
|
|
17
|
+
* @param loadUnitInstances - The load unit instances
|
|
18
|
+
*/
|
|
19
|
+
static contextModuleCompatible(contextPrototype: any, loadUnitInstances: LoadUnitInstance[]): void;
|
|
15
20
|
static clean(): void;
|
|
16
21
|
}
|
|
17
22
|
//#endregion
|
|
@@ -1,3 +1,99 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { InitTypeQualifierAttribute, ObjectInitType } from "@eggjs/core-decorator";
|
|
2
|
+
import { EggPrototypeFactory } from "@eggjs/metadata";
|
|
3
|
+
import { ProxyUtil } from "@eggjs/tegg-common-util";
|
|
4
|
+
import { EggContainerFactory } from "@eggjs/tegg-runtime";
|
|
2
5
|
|
|
6
|
+
//#region src/lib/CompatibleUtil.ts
|
|
7
|
+
var CompatibleUtil = class CompatibleUtil {
|
|
8
|
+
static singletonProtoCache = /* @__PURE__ */ new Map();
|
|
9
|
+
static requestProtoCache = /* @__PURE__ */ new Map();
|
|
10
|
+
static getSingletonProto(name) {
|
|
11
|
+
if (!this.singletonProtoCache.has(name)) {
|
|
12
|
+
const proto = EggPrototypeFactory.instance.getPrototype(name, void 0, [{
|
|
13
|
+
attribute: InitTypeQualifierAttribute,
|
|
14
|
+
value: ObjectInitType.SINGLETON
|
|
15
|
+
}]);
|
|
16
|
+
this.singletonProtoCache.set(name, proto);
|
|
17
|
+
}
|
|
18
|
+
return this.singletonProtoCache.get(name);
|
|
19
|
+
}
|
|
20
|
+
static getRequestProto(name) {
|
|
21
|
+
if (!this.requestProtoCache.has(name)) {
|
|
22
|
+
const proto = EggPrototypeFactory.instance.getPrototype(name, void 0, [{
|
|
23
|
+
attribute: InitTypeQualifierAttribute,
|
|
24
|
+
value: ObjectInitType.CONTEXT
|
|
25
|
+
}]);
|
|
26
|
+
this.requestProtoCache.set(name, proto);
|
|
27
|
+
}
|
|
28
|
+
return this.requestProtoCache.get(name);
|
|
29
|
+
}
|
|
30
|
+
static singletonModuleProxyFactory(app, loadUnitInstance) {
|
|
31
|
+
let deprecated = false;
|
|
32
|
+
return function(_, p) {
|
|
33
|
+
const proto = CompatibleUtil.getSingletonProto(p);
|
|
34
|
+
const eggObj = EggContainerFactory.getEggObject(proto);
|
|
35
|
+
if (!deprecated) {
|
|
36
|
+
deprecated = true;
|
|
37
|
+
app.deprecate(`[egg/module] Please use await app.getEggObject(clazzName) instead of app.${loadUnitInstance.name}.${String(p)}`);
|
|
38
|
+
}
|
|
39
|
+
return eggObj.obj;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
static appCompatible(app, loadUnitInstance) {
|
|
43
|
+
const moduleLoadUnitProxy = ProxyUtil.safeProxy(loadUnitInstance, CompatibleUtil.singletonModuleProxyFactory(app, loadUnitInstance));
|
|
44
|
+
Reflect.defineProperty(app.module, loadUnitInstance.name, {
|
|
45
|
+
configurable: true,
|
|
46
|
+
value: moduleLoadUnitProxy
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
static contextModuleProxyFactory(holder, ctx, loadUnitInstance) {
|
|
50
|
+
const cacheKey = `_${loadUnitInstance.name}Proxy`;
|
|
51
|
+
if (!holder[cacheKey]) {
|
|
52
|
+
let deprecated = false;
|
|
53
|
+
const getter = function(_, p) {
|
|
54
|
+
const proto = CompatibleUtil.getRequestProto(p);
|
|
55
|
+
const eggObj = EggContainerFactory.getEggObject(proto, p);
|
|
56
|
+
if (!deprecated) {
|
|
57
|
+
deprecated = true;
|
|
58
|
+
ctx.app.deprecate(`[egg/module] Please use await ctx.getEggObject(clazzName) instead of ctx.${loadUnitInstance.name}.${String(p)}`);
|
|
59
|
+
}
|
|
60
|
+
return eggObj.obj;
|
|
61
|
+
};
|
|
62
|
+
holder[cacheKey] = ProxyUtil.safeProxy(loadUnitInstance, getter);
|
|
63
|
+
}
|
|
64
|
+
return holder[cacheKey];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Compatible the context module, only for koa application
|
|
68
|
+
* @param contextPrototype - The prototype of the context
|
|
69
|
+
* @param loadUnitInstances - The load unit instances
|
|
70
|
+
*/
|
|
71
|
+
static contextModuleCompatible(contextPrototype, loadUnitInstances) {
|
|
72
|
+
const loadUnitInstanceMap = loadUnitInstances.reduce((p, c) => {
|
|
73
|
+
p[c.name] = c;
|
|
74
|
+
return p;
|
|
75
|
+
}, {});
|
|
76
|
+
Reflect.defineProperty(contextPrototype, "module", {
|
|
77
|
+
configurable: true,
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get() {
|
|
80
|
+
if (!this._moduleProxy) {
|
|
81
|
+
const ctxModule = Object.create(loadUnitInstanceMap);
|
|
82
|
+
this._moduleProxy = ProxyUtil.safeProxy(ctxModule, (_, p) => {
|
|
83
|
+
const loadUnitInstance = Reflect.get(ctxModule, p);
|
|
84
|
+
if (!loadUnitInstance) return;
|
|
85
|
+
return CompatibleUtil.contextModuleProxyFactory(ctxModule, this, loadUnitInstance);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return this._moduleProxy;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
static clean() {
|
|
93
|
+
this.singletonProtoCache.clear();
|
|
94
|
+
this.requestProtoCache.clear();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
3
99
|
export { CompatibleUtil };
|