@eggjs/tegg-plugin 4.0.0-beta.8 → 4.0.0-beta.9

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.
Files changed (81) hide show
  1. package/dist/app/extend/application.d.ts +50 -4
  2. package/dist/app/extend/application.js +79 -10
  3. package/dist/app/extend/application.unittest.d.ts +22 -2
  4. package/dist/app/extend/application.unittest.js +55 -4
  5. package/dist/app/extend/context.d.ts +20 -2
  6. package/dist/app/extend/context.js +35 -5
  7. package/dist/app/middleware/tegg_ctx_lifecycle_middleware.d.ts +2 -5
  8. package/dist/app/middleware/tegg_ctx_lifecycle_middleware.js +4 -9
  9. package/dist/app.d.ts +16 -21
  10. package/dist/app.js +63 -65
  11. package/dist/index.d.ts +3 -6
  12. package/dist/index.js +4 -15
  13. package/dist/lib/AppLoadUnit.d.ts +19 -2
  14. package/dist/lib/AppLoadUnit.js +90 -3
  15. package/dist/lib/AppLoadUnitInstance.d.ts +20 -2
  16. package/dist/lib/AppLoadUnitInstance.js +82 -3
  17. package/dist/lib/CompatibleUtil.d.ts +13 -17
  18. package/dist/lib/CompatibleUtil.js +95 -3
  19. package/dist/lib/ConfigSourceLoadUnitHook.d.ts +4 -9
  20. package/dist/lib/ConfigSourceLoadUnitHook.js +21 -3
  21. package/dist/lib/EggAppLoader.d.ts +15 -19
  22. package/dist/lib/EggAppLoader.js +128 -5
  23. package/dist/lib/EggCompatibleObject.d.ts +18 -3
  24. package/dist/lib/EggCompatibleObject.js +42 -4
  25. package/dist/lib/EggCompatibleProtoImpl.d.ts +21 -2
  26. package/dist/lib/EggCompatibleProtoImpl.js +52 -3
  27. package/dist/lib/EggContextCompatibleHook.d.ts +9 -13
  28. package/dist/lib/EggContextCompatibleHook.js +44 -9
  29. package/dist/lib/EggContextHandler.d.ts +9 -2
  30. package/dist/lib/EggContextHandler.js +26 -3
  31. package/dist/lib/EggContextImpl.d.ts +5 -9
  32. package/dist/lib/EggContextImpl.js +15 -3
  33. package/dist/lib/EggModuleLoader.d.ts +10 -14
  34. package/dist/lib/EggModuleLoader.js +54 -6
  35. package/dist/lib/EggQualifierProtoHook.d.ts +9 -13
  36. package/dist/lib/EggQualifierProtoHook.js +62 -6
  37. package/dist/lib/ModuleConfigLoader.d.ts +7 -11
  38. package/dist/lib/ModuleConfigLoader.js +81 -4
  39. package/dist/lib/ModuleHandler.d.ts +13 -2
  40. package/dist/lib/ModuleHandler.js +53 -8
  41. package/dist/lib/Utils.d.ts +1 -4
  42. package/dist/lib/Utils.js +36 -3
  43. package/dist/lib/ctx_lifecycle_middleware.d.ts +2 -2
  44. package/dist/lib/ctx_lifecycle_middleware.js +33 -4
  45. package/dist/lib/run_in_background.d.ts +3 -7
  46. package/dist/lib/run_in_background.js +58 -7
  47. package/dist/types.d.ts +8 -6
  48. package/dist/types.js +5 -15
  49. package/package.json +12 -12
  50. package/dist/AppLoadUnit-BOWdS4O9.d.ts +0 -23
  51. package/dist/AppLoadUnit-uyHgElRL.js +0 -78
  52. package/dist/AppLoadUnitInstance-4Z_vSQV3.js +0 -69
  53. package/dist/AppLoadUnitInstance-DQ-DxlmR.d.ts +0 -24
  54. package/dist/CompatibleUtil-CNhydb0E.js +0 -96
  55. package/dist/ConfigSourceLoadUnitHook-BV-R31vA.js +0 -22
  56. package/dist/EggAppLoader-DFYg65ry.js +0 -106
  57. package/dist/EggCompatibleObject-XfIZyirS.js +0 -37
  58. package/dist/EggCompatibleObject-lzUCfsIY.d.ts +0 -21
  59. package/dist/EggCompatibleProtoImpl-CPxLvSu4.js +0 -50
  60. package/dist/EggCompatibleProtoImpl-DpacWKFB.d.ts +0 -25
  61. package/dist/EggContextCompatibleHook-eFfN2xm6.js +0 -31
  62. package/dist/EggContextHandler-D8gfTbZs.js +0 -29
  63. package/dist/EggContextHandler-vGi67He5.d.ts +0 -13
  64. package/dist/EggContextImpl-DkCLPTzT.js +0 -18
  65. package/dist/EggModuleLoader-CCfQMmp5.js +0 -50
  66. package/dist/EggQualifierProtoHook-D5jNm-1y.js +0 -48
  67. package/dist/ModuleConfigLoader-CvZLf99E.js +0 -84
  68. package/dist/ModuleHandler-Dyx7JGj-.d.ts +0 -17
  69. package/dist/ModuleHandler-fKcUqWca.js +0 -46
  70. package/dist/Utils-11aRpnkd.js +0 -33
  71. package/dist/application-Ccljinuy.d.ts +0 -57
  72. package/dist/application-DFI1junS.js +0 -70
  73. package/dist/application.unittest-Cmia71Fx.js +0 -43
  74. package/dist/application.unittest-CpoCu6-E.d.ts +0 -26
  75. package/dist/context-BWYE1dif.js +0 -30
  76. package/dist/context-BoIt2G5h.d.ts +0 -24
  77. package/dist/ctx_lifecycle_middleware-CIeSrbVY.js +0 -27
  78. package/dist/ctx_lifecycle_middleware-DV7uN5PG.d.ts +0 -6
  79. package/dist/run_in_background-CEUPBmDB.js +0 -51
  80. package/dist/types-BHg5p4Xk.js +0 -3
  81. package/dist/types-CuoKQV4X.d.ts +0 -7
@@ -1,57 +0,0 @@
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 };
@@ -1,70 +0,0 @@
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 };
@@ -1,43 +0,0 @@
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 };
@@ -1,26 +0,0 @@
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 };
@@ -1,30 +0,0 @@
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 };
@@ -1,24 +0,0 @@
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 };
@@ -1,27 +0,0 @@
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 };
@@ -1,6 +0,0 @@
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
6
- export { ctxLifecycleMiddleware };
@@ -1,51 +0,0 @@
1
- import { getCalleeFromStack } from "./Utils-11aRpnkd.js";
2
- import "@eggjs/tegg-metadata";
3
- import { BackgroundTaskHelper, PrototypeUtil } from "@eggjs/tegg";
4
- import { TEGG_CONTEXT } from "@eggjs/egg-module-common";
5
- import { Application } from "egg";
6
-
7
- //#region src/lib/run_in_background.ts
8
- const LONG_STACK_DELIMITER = "\n --------------------\n";
9
- function addLongStackTrace(err, causeError) {
10
- const callSiteStack = causeError.stack;
11
- if (!callSiteStack || typeof callSiteStack !== "string") return;
12
- const index = callSiteStack.indexOf("\n");
13
- if (index !== -1) err.stack += LONG_STACK_DELIMITER + callSiteStack.substring(index + 1);
14
- }
15
- function hijackRunInBackground(app) {
16
- const eggRunInBackground = app.context.runInBackground;
17
- app.context.runInBackground = function runInBackground(scope) {
18
- if (!this[TEGG_CONTEXT]) return Reflect.apply(eggRunInBackground, this, [scope]);
19
- const caseError = /* @__PURE__ */ new Error("cause");
20
- let resolveBackgroundTask;
21
- const backgroundTaskPromise = new Promise((resolve) => {
22
- resolveBackgroundTask = resolve;
23
- });
24
- const newScope = async () => {
25
- try {
26
- await scope(this);
27
- } catch (e) {
28
- addLongStackTrace(e, caseError);
29
- throw e;
30
- } finally {
31
- resolveBackgroundTask();
32
- }
33
- };
34
- const taskName = scope._name || scope.name || getCalleeFromStack(true, 2);
35
- scope._name = taskName;
36
- Object.defineProperty(newScope, "name", {
37
- value: taskName,
38
- enumerable: false,
39
- configurable: true,
40
- writable: false
41
- });
42
- Reflect.apply(eggRunInBackground, this, [newScope]);
43
- const proto = PrototypeUtil.getClazzProto(BackgroundTaskHelper);
44
- app.eggContainerFactory.getEggObject(proto).obj.run(async () => {
45
- await backgroundTaskPromise;
46
- });
47
- };
48
- }
49
-
50
- //#endregion
51
- export { LONG_STACK_DELIMITER, hijackRunInBackground };
@@ -1,3 +0,0 @@
1
- import "@eggjs/tegg-config/types";
2
-
3
- export { };
@@ -1,7 +0,0 @@
1
- import "@eggjs/tegg-config/types";
2
-
3
- //#region src/types.d.ts
4
-
5
- declare module 'egg' {
6
- interface EggModule {}
7
- }