@eggjs/tegg-runtime 4.0.0-beta.6 → 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.
Files changed (35) hide show
  1. package/dist/{factory/EggContainerFactory.js → ContextInitiator-DazHfq05.js} +86 -6
  2. package/dist/ContextInitiator-GmZYvMSm.js +3 -0
  3. package/dist/index.d.ts +168 -14
  4. package/dist/index.js +524 -17
  5. package/package.json +7 -7
  6. package/dist/factory/EggContainerFactory.d.ts +0 -30
  7. package/dist/factory/EggObjectFactory.d.ts +0 -17
  8. package/dist/factory/EggObjectFactory.js +0 -52
  9. package/dist/factory/LoadUnitInstanceFactory.d.ts +0 -15
  10. package/dist/factory/LoadUnitInstanceFactory.js +0 -49
  11. package/dist/factory/index.js +0 -5
  12. package/dist/impl/ContextInitiator.d.ts +0 -12
  13. package/dist/impl/ContextInitiator.js +0 -37
  14. package/dist/impl/ContextObjectGraph.d.ts +0 -10
  15. package/dist/impl/ContextObjectGraph.js +0 -36
  16. package/dist/impl/EggAlwaysNewObjectContainer.d.ts +0 -17
  17. package/dist/impl/EggAlwaysNewObjectContainer.js +0 -30
  18. package/dist/impl/EggObjectImpl.d.ts +0 -21
  19. package/dist/impl/EggObjectImpl.js +0 -126
  20. package/dist/impl/EggObjectUtil.d.ts +0 -11
  21. package/dist/impl/EggObjectUtil.js +0 -147
  22. package/dist/impl/ModuleLoadUnitInstance.d.ts +0 -22
  23. package/dist/impl/ModuleLoadUnitInstance.js +0 -73
  24. package/dist/impl/index.js +0 -8
  25. package/dist/model/AbstractEggContext.d.ts +0 -22
  26. package/dist/model/AbstractEggContext.js +0 -83
  27. package/dist/model/ContextHandler.d.ts +0 -12
  28. package/dist/model/ContextHandler.js +0 -18
  29. package/dist/model/EggContext.d.ts +0 -7
  30. package/dist/model/EggContext.js +0 -7
  31. package/dist/model/EggObject.d.ts +0 -7
  32. package/dist/model/EggObject.js +0 -7
  33. package/dist/model/LoadUnitInstance.d.ts +0 -7
  34. package/dist/model/LoadUnitInstance.js +0 -7
  35. package/dist/model/index.js +0 -7
@@ -1,83 +0,0 @@
1
- import { EggContainerFactory } from "../factory/EggContainerFactory.js";
2
- import { EggObjectFactory } from "../factory/EggObjectFactory.js";
3
- import "../factory/index.js";
4
- import { ContextHandler } from "./ContextHandler.js";
5
- import { EggContextLifecycleUtil } from "./EggContext.js";
6
- import { debuglog } from "node:util";
7
- import { ObjectInitType } from "@eggjs/tegg-types";
8
- import { TeggError } from "@eggjs/tegg-metadata";
9
- import { MapUtil } from "@eggjs/tegg-common-util";
10
-
11
- //#region src/model/AbstractEggContext.ts
12
- const debug = debuglog("tegg/core/runtime/AbstractEggContext");
13
- var AbstractEggContext = class {
14
- contextData = /* @__PURE__ */ new Map();
15
- protoToCreate = /* @__PURE__ */ new Map();
16
- eggObjectMap = /* @__PURE__ */ new Map();
17
- eggObjectPromiseMap = /* @__PURE__ */ new Map();
18
- destroyed = false;
19
- addProtoToCreate(name, proto) {
20
- this.protoToCreate.set(name, proto);
21
- }
22
- deleteProtoToCreate(name) {
23
- this.protoToCreate.delete(name);
24
- }
25
- async destroy(ctx) {
26
- await EggContextLifecycleUtil.objectPreDestroy(ctx, this);
27
- const objs = [];
28
- for (const protoObjMap of this.eggObjectMap.values()) for (const protoObj of protoObjMap.values()) objs.push(protoObj);
29
- this.eggObjectMap.clear();
30
- await Promise.all(objs.map(async (obj) => {
31
- await EggObjectFactory.destroyObject(obj);
32
- }));
33
- this.contextData.clear();
34
- this.destroyed = true;
35
- await EggContextLifecycleUtil.clearObjectLifecycle(this);
36
- }
37
- get(key) {
38
- return this.contextData.get(key);
39
- }
40
- getEggObject(name, proto) {
41
- if (this.destroyed) throw TeggError.create(`Can not read property \`${String(name)}\` because egg ctx has been destroyed`, "read_after_ctx_destroyed");
42
- const protoObjMap = this.eggObjectMap.get(proto.id);
43
- if (!protoObjMap || !protoObjMap.has(name)) throw new Error(`EggObject ${String(proto.name)} not found`);
44
- return protoObjMap.get(name);
45
- }
46
- async getOrCreateEggObject(name, proto) {
47
- const protoObjMap = MapUtil.getOrStore(this.eggObjectMap, proto.id, /* @__PURE__ */ new Map());
48
- if (!protoObjMap.has(name)) {
49
- const protoObjPromiseMap = MapUtil.getOrStore(this.eggObjectPromiseMap, proto.id, /* @__PURE__ */ new Map());
50
- if (!protoObjPromiseMap.has(name)) {
51
- const objPromise = EggObjectFactory.createObject(name, proto);
52
- protoObjPromiseMap.set(name, objPromise);
53
- const obj = await objPromise;
54
- protoObjPromiseMap.delete(name);
55
- if (!protoObjPromiseMap.size) this.eggObjectPromiseMap.delete(proto.id);
56
- protoObjMap.set(name, obj);
57
- } else await protoObjPromiseMap.get(name);
58
- }
59
- return protoObjMap.get(name);
60
- }
61
- async init(ctx) {
62
- await EggContextLifecycleUtil.objectPreCreate(ctx, this);
63
- for (const [name, proto] of this.protoToCreate) await this.getOrCreateEggObject(name, proto);
64
- await EggContextLifecycleUtil.objectPostCreate(ctx, this);
65
- }
66
- iterateProtoToCreate() {
67
- return this.protoToCreate.entries();
68
- }
69
- set(key, val) {
70
- this.contextData.set(key, val);
71
- }
72
- };
73
- EggContainerFactory.registerContainerGetMethod(ObjectInitType.CONTEXT, () => {
74
- const ctx = ContextHandler.getContext();
75
- if (!ctx) {
76
- debug("can not get teggCtx from ContextHandler");
77
- throw new Error("ctx is required");
78
- }
79
- return ctx;
80
- });
81
-
82
- //#endregion
83
- export { AbstractEggContext };
@@ -1,12 +0,0 @@
1
- import { EggRuntimeContext } from "@eggjs/tegg-types";
2
-
3
- //#region src/model/ContextHandler.d.ts
4
- type runInContextCallback<R = any> = (context: EggRuntimeContext, fn: () => Promise<R>) => Promise<R>;
5
- declare class ContextHandler {
6
- static getContextCallback: () => EggRuntimeContext | undefined;
7
- static runInContextCallback: runInContextCallback;
8
- static getContext(): EggRuntimeContext | undefined;
9
- static run<R = any>(context: EggRuntimeContext, fn: () => Promise<R>): Promise<R>;
10
- }
11
- //#endregion
12
- export { ContextHandler };
@@ -1,18 +0,0 @@
1
- import assert from "node:assert";
2
-
3
- //#region src/model/ContextHandler.ts
4
- var ContextHandler = class {
5
- static getContextCallback;
6
- static runInContextCallback;
7
- static getContext() {
8
- assert(this.getContextCallback, "getContextCallback not set");
9
- return this.getContextCallback ? this.getContextCallback() : void 0;
10
- }
11
- static run(context, fn) {
12
- assert(this.runInContextCallback, "runInContextCallback not set");
13
- return this.runInContextCallback(context, fn);
14
- }
15
- };
16
-
17
- //#endregion
18
- export { ContextHandler };
@@ -1,7 +0,0 @@
1
- import { EggContextLifecycleContext, EggRuntimeContext } from "@eggjs/tegg-types";
2
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
3
-
4
- //#region src/model/EggContext.d.ts
5
- declare const EggContextLifecycleUtil: LifecycleUtil<EggContextLifecycleContext, EggRuntimeContext>;
6
- //#endregion
7
- export { EggContextLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
2
-
3
- //#region src/model/EggContext.ts
4
- const EggContextLifecycleUtil = new LifecycleUtil();
5
-
6
- //#endregion
7
- export { EggContextLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { EggObject, EggObjectLifeCycleContext } from "@eggjs/tegg-types";
2
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
3
-
4
- //#region src/model/EggObject.d.ts
5
- declare const EggObjectLifecycleUtil: LifecycleUtil<EggObjectLifeCycleContext, EggObject>;
6
- //#endregion
7
- export { EggObjectLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
2
-
3
- //#region src/model/EggObject.ts
4
- const EggObjectLifecycleUtil = new LifecycleUtil();
5
-
6
- //#endregion
7
- export { EggObjectLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { LoadUnitInstance, LoadUnitInstanceLifecycleContext } from "@eggjs/tegg-types";
2
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
3
-
4
- //#region src/model/LoadUnitInstance.d.ts
5
- declare const LoadUnitInstanceLifecycleUtil: LifecycleUtil<LoadUnitInstanceLifecycleContext, LoadUnitInstance>;
6
- //#endregion
7
- export { LoadUnitInstanceLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { LifecycleUtil } from "@eggjs/tegg-lifecycle";
2
-
3
- //#region src/model/LoadUnitInstance.ts
4
- const LoadUnitInstanceLifecycleUtil = new LifecycleUtil();
5
-
6
- //#endregion
7
- export { LoadUnitInstanceLifecycleUtil };
@@ -1,7 +0,0 @@
1
- import { LoadUnitInstanceLifecycleUtil } from "./LoadUnitInstance.js";
2
- import { ContextHandler } from "./ContextHandler.js";
3
- import { EggContextLifecycleUtil } from "./EggContext.js";
4
- import { AbstractEggContext } from "./AbstractEggContext.js";
5
- import { EggObjectLifecycleUtil } from "./EggObject.js";
6
-
7
- export { };