@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,57 @@
|
|
|
1
|
+
import { ModuleHandler } from "./ModuleHandler-Dyx7JGj-.js";
|
|
2
|
+
import { EggContextHandler } from "./EggContextHandler-vGi67He5.js";
|
|
3
|
+
import * as _eggjs_tegg_metadata0 from "@eggjs/tegg-metadata";
|
|
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
|
|
57
|
+
export { TEggPluginApplication };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { EggPrototypeCreatorFactory, EggPrototypeFactory, EggPrototypeLifecycleUtil, LoadUnitFactory, LoadUnitLifecycleUtil } from "@eggjs/tegg-metadata";
|
|
2
|
+
import { IdenticalUtil } from "@eggjs/tegg";
|
|
3
|
+
import { AbstractEggContext, EggContainerFactory, EggContextLifecycleUtil, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
4
|
+
import { Application } from "egg";
|
|
5
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
6
|
+
|
|
7
|
+
//#region src/app/extend/application.ts
|
|
8
|
+
var TEggPluginApplication = class extends Application {
|
|
9
|
+
get eggPrototypeCreatorFactory() {
|
|
10
|
+
return EggPrototypeCreatorFactory;
|
|
11
|
+
}
|
|
12
|
+
get eggPrototypeFactory() {
|
|
13
|
+
return EggPrototypeFactory.instance;
|
|
14
|
+
}
|
|
15
|
+
get loadUnitLifecycleUtil() {
|
|
16
|
+
return LoadUnitLifecycleUtil;
|
|
17
|
+
}
|
|
18
|
+
get loadUnitFactory() {
|
|
19
|
+
return LoadUnitFactory;
|
|
20
|
+
}
|
|
21
|
+
get eggObjectFactory() {
|
|
22
|
+
return EggObjectFactory;
|
|
23
|
+
}
|
|
24
|
+
get loadUnitInstanceFactory() {
|
|
25
|
+
return LoadUnitInstanceFactory;
|
|
26
|
+
}
|
|
27
|
+
get loadUnitInstanceLifecycleUtil() {
|
|
28
|
+
return LoadUnitInstanceLifecycleUtil;
|
|
29
|
+
}
|
|
30
|
+
get eggContainerFactory() {
|
|
31
|
+
return EggContainerFactory;
|
|
32
|
+
}
|
|
33
|
+
get loaderFactory() {
|
|
34
|
+
return LoaderFactory;
|
|
35
|
+
}
|
|
36
|
+
get eggPrototypeLifecycleUtil() {
|
|
37
|
+
return EggPrototypeLifecycleUtil;
|
|
38
|
+
}
|
|
39
|
+
get eggContextLifecycleUtil() {
|
|
40
|
+
return EggContextLifecycleUtil;
|
|
41
|
+
}
|
|
42
|
+
get eggObjectLifecycleUtil() {
|
|
43
|
+
return EggObjectLifecycleUtil;
|
|
44
|
+
}
|
|
45
|
+
get abstractEggContext() {
|
|
46
|
+
return AbstractEggContext;
|
|
47
|
+
}
|
|
48
|
+
get identicalUtil() {
|
|
49
|
+
return IdenticalUtil;
|
|
50
|
+
}
|
|
51
|
+
get runtimeConfig() {
|
|
52
|
+
const config = this.config;
|
|
53
|
+
return {
|
|
54
|
+
baseDir: config.baseDir,
|
|
55
|
+
env: config.env,
|
|
56
|
+
name: config.name
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
async getEggObject(clazz, name, qualifiers) {
|
|
60
|
+
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
61
|
+
return (await EggContainerFactory.getOrCreateEggObjectFromClazz(clazz, name, qualifiers)).obj;
|
|
62
|
+
}
|
|
63
|
+
async getEggObjectFromName(name, qualifiers) {
|
|
64
|
+
if (qualifiers) qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];
|
|
65
|
+
return (await EggContainerFactory.getOrCreateEggObjectFromName(name, qualifiers)).obj;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
//#endregion
|
|
70
|
+
export { TEggPluginApplication };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EggContextImpl } from "./EggContextImpl-DkCLPTzT.js";
|
|
2
|
+
import "@eggjs/tegg-runtime";
|
|
3
|
+
import { Application } from "egg";
|
|
4
|
+
|
|
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
|
+
export { TEggPluginApplicationUnittest };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Application, Context } from "egg";
|
|
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
|
|
26
|
+
export { TEggPluginApplicationUnittest };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ctxLifecycleMiddleware } from "./ctx_lifecycle_middleware-CIeSrbVY.js";
|
|
2
|
+
import "@eggjs/tegg-metadata";
|
|
3
|
+
import { PrototypeUtil } from "@eggjs/tegg";
|
|
4
|
+
import { TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
5
|
+
import { Context } from "egg";
|
|
6
|
+
|
|
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
|
+
export { TEggPluginContext };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { EggProtoImplClass, QualifierInfo } from "@eggjs/tegg";
|
|
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
|
|
24
|
+
export { TEggPluginContext };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EggContextImpl } from "./EggContextImpl-DkCLPTzT.js";
|
|
2
|
+
import "@eggjs/tegg-runtime";
|
|
3
|
+
import { ROOT_PROTO, TEGG_CONTEXT } from "@eggjs/egg-module-common";
|
|
4
|
+
|
|
5
|
+
//#region src/lib/ctx_lifecycle_middleware.ts
|
|
6
|
+
async function ctxLifecycleMiddleware(ctx, next) {
|
|
7
|
+
if (ctx[TEGG_CONTEXT]) {
|
|
8
|
+
await next();
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const lifecycleCtx = {};
|
|
12
|
+
const teggCtx = new EggContextImpl(ctx);
|
|
13
|
+
const rootProto = ctx[ROOT_PROTO];
|
|
14
|
+
if (rootProto) teggCtx.set(ROOT_PROTO, rootProto);
|
|
15
|
+
if (teggCtx.init) await teggCtx.init(lifecycleCtx);
|
|
16
|
+
try {
|
|
17
|
+
await next();
|
|
18
|
+
} finally {
|
|
19
|
+
if (teggCtx.destroy) teggCtx.destroy(lifecycleCtx).catch((e) => {
|
|
20
|
+
e.message = `[tegg/ctxLifecycleMiddleware] destroy tegg ctx failed: ${e.message}`;
|
|
21
|
+
ctx.logger.error(e);
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { ctxLifecycleMiddleware };
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import "./
|
|
3
|
-
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 "./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";
|
|
4
14
|
|
|
5
15
|
export { };
|
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
1
|
+
import { AppLoadUnit } from "../AppLoadUnit-BOWdS4O9.js";
|
|
23
2
|
export { AppLoadUnit };
|
package/dist/lib/AppLoadUnit.js
CHANGED
|
@@ -1,78 +1,3 @@
|
|
|
1
|
-
import {
|
|
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";
|
|
1
|
+
import { AppLoadUnit } from "../AppLoadUnit-uyHgElRL.js";
|
|
5
2
|
|
|
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
3
|
export { AppLoadUnit };
|
|
@@ -1,24 +1,2 @@
|
|
|
1
|
-
import {
|
|
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
|
|
1
|
+
import { AppLoadUnitInstance } from "../AppLoadUnitInstance-DQ-DxlmR.js";
|
|
24
2
|
export { AppLoadUnitInstance };
|
|
@@ -1,69 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IdenticalUtil, ObjectInitType } from "@eggjs/tegg";
|
|
3
|
-
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
4
|
-
import { EggObjectFactory, LoadUnitInstanceFactory, LoadUnitInstanceLifecycleUtil } from "@eggjs/tegg-runtime";
|
|
1
|
+
import { AppLoadUnitInstance } from "../AppLoadUnitInstance-4Z_vSQV3.js";
|
|
5
2
|
|
|
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
3
|
export { AppLoadUnitInstance };
|
|
@@ -1,96 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { InitTypeQualifierAttribute, ObjectInitType } from "@eggjs/tegg";
|
|
3
|
-
import { ProxyUtil } from "@eggjs/tegg-common-util";
|
|
4
|
-
import { EggContainerFactory } from "@eggjs/tegg-runtime";
|
|
5
|
-
import { Application, Context } from "egg";
|
|
1
|
+
import { CompatibleUtil } from "../CompatibleUtil-CNhydb0E.js";
|
|
6
2
|
|
|
7
|
-
//#region src/lib/CompatibleUtil.ts
|
|
8
|
-
var CompatibleUtil = class CompatibleUtil {
|
|
9
|
-
static singletonProtoCache = /* @__PURE__ */ new Map();
|
|
10
|
-
static requestProtoCache = /* @__PURE__ */ new Map();
|
|
11
|
-
static getSingletonProto(name) {
|
|
12
|
-
if (!this.singletonProtoCache.has(name)) {
|
|
13
|
-
const proto = EggPrototypeFactory.instance.getPrototype(name, void 0, [{
|
|
14
|
-
attribute: InitTypeQualifierAttribute,
|
|
15
|
-
value: ObjectInitType.SINGLETON
|
|
16
|
-
}]);
|
|
17
|
-
this.singletonProtoCache.set(name, proto);
|
|
18
|
-
}
|
|
19
|
-
return this.singletonProtoCache.get(name);
|
|
20
|
-
}
|
|
21
|
-
static getRequestProto(name) {
|
|
22
|
-
if (!this.requestProtoCache.has(name)) {
|
|
23
|
-
const proto = EggPrototypeFactory.instance.getPrototype(name, void 0, [{
|
|
24
|
-
attribute: InitTypeQualifierAttribute,
|
|
25
|
-
value: ObjectInitType.CONTEXT
|
|
26
|
-
}]);
|
|
27
|
-
this.requestProtoCache.set(name, proto);
|
|
28
|
-
}
|
|
29
|
-
return this.requestProtoCache.get(name);
|
|
30
|
-
}
|
|
31
|
-
static singletonModuleProxyFactory(app, loadUnitInstance) {
|
|
32
|
-
let deprecated = false;
|
|
33
|
-
return function(_, p) {
|
|
34
|
-
const proto = CompatibleUtil.getSingletonProto(p);
|
|
35
|
-
const eggObj = EggContainerFactory.getEggObject(proto);
|
|
36
|
-
if (!deprecated) {
|
|
37
|
-
deprecated = true;
|
|
38
|
-
app.deprecate(`[egg/module] Please use await app.getEggObject(clazzName) instead of app.${loadUnitInstance.name}.${String(p)}`);
|
|
39
|
-
}
|
|
40
|
-
return eggObj.obj;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
static appCompatible(app, loadUnitInstance) {
|
|
44
|
-
const moduleLoadUnitProxy = ProxyUtil.safeProxy(loadUnitInstance, CompatibleUtil.singletonModuleProxyFactory(app, loadUnitInstance));
|
|
45
|
-
Reflect.defineProperty(app.module, loadUnitInstance.name, {
|
|
46
|
-
configurable: true,
|
|
47
|
-
value: moduleLoadUnitProxy
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
static contextModuleProxyFactory(holder, ctx, loadUnitInstance) {
|
|
51
|
-
const cacheKey = `_${loadUnitInstance.name}Proxy`;
|
|
52
|
-
if (!holder[cacheKey]) {
|
|
53
|
-
let deprecated = false;
|
|
54
|
-
const getter = function(_, p) {
|
|
55
|
-
const proto = CompatibleUtil.getRequestProto(p);
|
|
56
|
-
const eggObj = EggContainerFactory.getEggObject(proto, p);
|
|
57
|
-
if (!deprecated) {
|
|
58
|
-
deprecated = true;
|
|
59
|
-
ctx.app.deprecate(`[egg/module] Please use await ctx.getEggObject(clazzName) instead of ctx.${loadUnitInstance.name}.${String(p)}`);
|
|
60
|
-
}
|
|
61
|
-
return eggObj.obj;
|
|
62
|
-
};
|
|
63
|
-
holder[cacheKey] = ProxyUtil.safeProxy(loadUnitInstance, getter);
|
|
64
|
-
}
|
|
65
|
-
return holder[cacheKey];
|
|
66
|
-
}
|
|
67
|
-
static contextModuleCompatible(ctx, loadUnitInstances) {
|
|
68
|
-
const loadUnitInstanceMap = loadUnitInstances.reduce((p, c) => {
|
|
69
|
-
p[c.name] = c;
|
|
70
|
-
return p;
|
|
71
|
-
}, {});
|
|
72
|
-
Reflect.defineProperty(ctx, "module", {
|
|
73
|
-
configurable: true,
|
|
74
|
-
enumerable: true,
|
|
75
|
-
get() {
|
|
76
|
-
const ctx$1 = this;
|
|
77
|
-
if (!this._moduleProxy) {
|
|
78
|
-
const ctxModule = Object.create(loadUnitInstanceMap);
|
|
79
|
-
this._moduleProxy = ProxyUtil.safeProxy(ctxModule, (_, p) => {
|
|
80
|
-
const loadUnitInstance = Reflect.get(ctxModule, p);
|
|
81
|
-
if (!loadUnitInstance) return;
|
|
82
|
-
return CompatibleUtil.contextModuleProxyFactory(ctxModule, ctx$1, loadUnitInstance);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
return this._moduleProxy;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
static clean() {
|
|
90
|
-
this.singletonProtoCache.clear();
|
|
91
|
-
this.requestProtoCache.clear();
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
3
|
export { CompatibleUtil };
|
|
@@ -1,22 +1,3 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { ConfigSourceQualifier, ConfigSourceQualifierAttribute, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
|
|
1
|
+
import { ConfigSourceLoadUnitHook } from "../ConfigSourceLoadUnitHook-BV-R31vA.js";
|
|
3
2
|
|
|
4
|
-
//#region src/lib/ConfigSourceLoadUnitHook.ts
|
|
5
|
-
/**
|
|
6
|
-
* Copy from standalone/src/ConfigSourceLoadUnitHook
|
|
7
|
-
* Hook for inject moduleConfig.
|
|
8
|
-
* Add default qualifier value is current module name.
|
|
9
|
-
*/
|
|
10
|
-
var ConfigSourceLoadUnitHook = class {
|
|
11
|
-
async preCreate(ctx, loadUnit) {
|
|
12
|
-
const classList = await ctx.loader.load();
|
|
13
|
-
for (const clazz of classList) {
|
|
14
|
-
const moduleConfigObject = PrototypeUtil.getInjectObjects(clazz).find((t) => t.objName === "moduleConfig");
|
|
15
|
-
const configSourceQualifier = QualifierUtil.getProperQualifier(clazz, "moduleConfig", ConfigSourceQualifierAttribute);
|
|
16
|
-
if (moduleConfigObject && !configSourceQualifier) ConfigSourceQualifier(loadUnit.name)(clazz.prototype, moduleConfigObject.refName);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
3
|
export { ConfigSourceLoadUnitHook };
|