@eggjs/tegg-runtime 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.
- package/dist/factory/EggContainerFactory.d.ts +26 -0
- package/dist/factory/EggContainerFactory.js +90 -0
- package/dist/factory/EggObjectFactory.d.ts +14 -0
- package/dist/factory/EggObjectFactory.js +46 -0
- package/dist/factory/LoadUnitInstanceFactory.d.ts +12 -0
- package/dist/factory/LoadUnitInstanceFactory.js +57 -0
- package/dist/factory/index.d.ts +3 -0
- package/dist/factory/index.js +4 -0
- package/dist/impl/ContextInitiator.d.ts +8 -0
- package/dist/impl/ContextInitiator.js +37 -0
- package/dist/impl/ContextObjectGraph.d.ts +6 -0
- package/dist/impl/ContextObjectGraph.js +38 -0
- package/dist/impl/EggAlwaysNewObjectContainer.d.ts +13 -0
- package/dist/impl/EggAlwaysNewObjectContainer.js +33 -0
- package/dist/impl/EggObjectImpl.d.ts +17 -0
- package/dist/impl/EggObjectImpl.js +179 -0
- package/dist/impl/EggObjectUtil.d.ts +7 -0
- package/dist/impl/EggObjectUtil.js +172 -0
- package/dist/impl/ModuleLoadUnitInstance.d.ts +18 -0
- package/dist/impl/ModuleLoadUnitInstance.js +90 -0
- package/dist/impl/index.d.ts +6 -0
- package/dist/impl/index.js +7 -0
- package/dist/index.d.ts +5 -171
- package/dist/index.js +5 -528
- package/dist/model/AbstractEggContext.d.ts +18 -0
- package/dist/model/AbstractEggContext.js +93 -0
- package/dist/model/ContextHandler.d.ts +9 -0
- package/dist/model/ContextHandler.js +14 -0
- package/dist/model/EggContext.d.ts +3 -0
- package/dist/model/EggContext.js +3 -0
- package/dist/model/EggObject.d.ts +3 -0
- package/dist/model/EggObject.js +3 -0
- package/dist/model/LoadUnitInstance.d.ts +3 -0
- package/dist/model/LoadUnitInstance.js +3 -0
- package/dist/model/index.d.ts +5 -0
- package/dist/model/index.js +6 -0
- package/package.json +8 -8
- package/dist/ContextInitiator-DazHfq05.js +0 -160
- package/dist/ContextInitiator-GmZYvMSm.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LifecycleUtil } from '@eggjs/tegg-lifecycle';
|
|
2
|
+
export const EggContextLifecycleUtil = new LifecycleUtil();
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRWdnQ29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tb2RlbC9FZ2dDb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUV0RCxNQUFNLENBQUMsTUFBTSx1QkFBdUIsR0FBRyxJQUFJLGFBQWEsRUFBaUQsQ0FBQyJ9
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LifecycleUtil } from '@eggjs/tegg-lifecycle';
|
|
2
|
+
export const EggObjectLifecycleUtil = new LifecycleUtil();
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiRWdnT2JqZWN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL21vZGVsL0VnZ09iamVjdC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sdUJBQXVCLENBQUM7QUFHdEQsTUFBTSxDQUFDLE1BQU0sc0JBQXNCLEdBQUcsSUFBSSxhQUFhLEVBQXdDLENBQUMifQ==
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { LifecycleUtil } from '@eggjs/tegg-lifecycle';
|
|
2
|
+
export const LoadUnitInstanceLifecycleUtil = new LifecycleUtil();
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9hZFVuaXRJbnN0YW5jZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9tb2RlbC9Mb2FkVW5pdEluc3RhbmNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sRUFBRSxhQUFhLEVBQUUsTUFBTSx1QkFBdUIsQ0FBQztBQUV0RCxNQUFNLENBQUMsTUFBTSw2QkFBNkIsR0FBRyxJQUFJLGFBQWEsRUFBc0QsQ0FBQyJ9
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./AbstractEggContext.js";
|
|
2
|
+
export * from "./ContextHandler.js";
|
|
3
|
+
export * from "./EggContext.js";
|
|
4
|
+
export * from "./EggObject.js";
|
|
5
|
+
export * from "./LoadUnitInstance.js";
|
|
6
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvbW9kZWwvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsY0FBYyx5QkFBeUIsQ0FBQztBQUN4QyxjQUFjLHFCQUFxQixDQUFDO0FBQ3BDLGNBQWMsaUJBQWlCLENBQUM7QUFDaEMsY0FBYyxnQkFBZ0IsQ0FBQztBQUMvQixjQUFjLHVCQUF1QixDQUFDIn0=
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-runtime",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.9",
|
|
4
4
|
"description": "tegg runtime",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -31,11 +31,11 @@
|
|
|
31
31
|
"node": ">=22.18.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@eggjs/core-decorator": "4.0.0-beta.
|
|
35
|
-
"@eggjs/tegg-common-util": "4.0.0-beta.
|
|
36
|
-
"@eggjs/tegg-
|
|
37
|
-
"@eggjs/tegg-
|
|
38
|
-
"@eggjs/tegg-types": "4.0.0-beta.
|
|
34
|
+
"@eggjs/core-decorator": "4.0.0-beta.9",
|
|
35
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.9",
|
|
36
|
+
"@eggjs/tegg-metadata": "4.0.0-beta.9",
|
|
37
|
+
"@eggjs/tegg-lifecycle": "4.0.0-beta.9",
|
|
38
|
+
"@eggjs/tegg-types": "4.0.0-beta.9"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/node": "^22.10.5",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"tsdown": "^0.15.6",
|
|
44
44
|
"unplugin-unused": "^0.5.3",
|
|
45
45
|
"@eggjs/module-test-util": "4.0.0-beta.4",
|
|
46
|
-
"@eggjs/tegg-loader": "4.0.0-beta.
|
|
46
|
+
"@eggjs/tegg-loader": "4.0.0-beta.9"
|
|
47
47
|
},
|
|
48
48
|
"publishConfig": {
|
|
49
49
|
"access": "public"
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"types": "./dist/index.d.ts",
|
|
54
54
|
"scripts": {
|
|
55
55
|
"clean": "rimraf dist",
|
|
56
|
-
"build": "tsdown",
|
|
56
|
+
"build": "tsdown && rimraf dist && tsc -b --clean && tsc",
|
|
57
57
|
"typecheck": "tsc --noEmit"
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { debuglog } from "node:util";
|
|
2
|
-
import { ObjectInitType } from "@eggjs/tegg-types";
|
|
3
|
-
import { EggPrototypeFactory, LoadUnitFactory } from "@eggjs/tegg-metadata";
|
|
4
|
-
import { NameUtil } from "@eggjs/tegg-common-util";
|
|
5
|
-
import { PrototypeUtil } from "@eggjs/core-decorator";
|
|
6
|
-
import assert from "node:assert";
|
|
7
|
-
|
|
8
|
-
//#region src/model/ContextHandler.ts
|
|
9
|
-
var ContextHandler = class {
|
|
10
|
-
static getContextCallback;
|
|
11
|
-
static runInContextCallback;
|
|
12
|
-
static getContext() {
|
|
13
|
-
assert(this.getContextCallback, "getContextCallback not set");
|
|
14
|
-
return this.getContextCallback ? this.getContextCallback() : void 0;
|
|
15
|
-
}
|
|
16
|
-
static run(context, fn) {
|
|
17
|
-
assert(this.runInContextCallback, "runInContextCallback not set");
|
|
18
|
-
return this.runInContextCallback(context, fn);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/factory/EggContainerFactory.ts
|
|
24
|
-
const debug = debuglog("tegg/core/runtime/EggContainerFactory");
|
|
25
|
-
var EggContainerFactory = class EggContainerFactory {
|
|
26
|
-
static containerGetMethodMap = /* @__PURE__ */ new Map();
|
|
27
|
-
static ContextInitiatorClass;
|
|
28
|
-
static registerContainerGetMethod(initType, method) {
|
|
29
|
-
if (debug.enabled) debug("registerContainerGetMethod %o %o, exists: %s", initType, method.toString(), this.containerGetMethodMap.has(initType));
|
|
30
|
-
this.containerGetMethodMap.set(initType, method);
|
|
31
|
-
}
|
|
32
|
-
static getContainer(proto) {
|
|
33
|
-
const method = this.containerGetMethodMap.get(proto.initType);
|
|
34
|
-
if (!method) throw new Error(`InitType ${proto.initType} has not register ContainerGetMethod`);
|
|
35
|
-
return method(proto);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* get or create egg object
|
|
39
|
-
* If get singleton egg object in context,
|
|
40
|
-
* will create context egg object for it.
|
|
41
|
-
*/
|
|
42
|
-
static async getOrCreateEggObject(proto, name) {
|
|
43
|
-
const container = this.getContainer(proto);
|
|
44
|
-
name = name || proto.name;
|
|
45
|
-
const obj = await container.getOrCreateEggObject(name, proto);
|
|
46
|
-
const ctx = ContextHandler.getContext();
|
|
47
|
-
if (ctx) {
|
|
48
|
-
if (!EggContainerFactory.ContextInitiatorClass) {
|
|
49
|
-
const { ContextInitiator: ContextInitiator$1 } = await import("./ContextInitiator-GmZYvMSm.js");
|
|
50
|
-
debug("import ContextInitiator to fix dependency cycle");
|
|
51
|
-
EggContainerFactory.ContextInitiatorClass = ContextInitiator$1;
|
|
52
|
-
}
|
|
53
|
-
await EggContainerFactory.ContextInitiatorClass.createContextInitiator(ctx).init(obj);
|
|
54
|
-
debug("getOrCreateEggObject with context eggObject:%o, from proto:%o, name:%s", obj.name, proto.name, name);
|
|
55
|
-
} else debug("getOrCreateEggObject without context, get eggObject:%o, from proto:%o, name:%s", obj.name, proto.name, name);
|
|
56
|
-
return obj;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* get or create egg object from the Class
|
|
60
|
-
* If get singleton egg object in context,
|
|
61
|
-
* will create context egg object for it.
|
|
62
|
-
*/
|
|
63
|
-
static async getOrCreateEggObjectFromClazz(clazz, name, qualifiers) {
|
|
64
|
-
let proto = PrototypeUtil.getClazzProto(clazz);
|
|
65
|
-
const isMultiInstance = PrototypeUtil.isEggMultiInstancePrototype(clazz);
|
|
66
|
-
debug("getOrCreateEggObjectFromClazz:%o, isMultiInstance:%s, proto:%o", clazz.name, isMultiInstance, !!proto);
|
|
67
|
-
if (isMultiInstance) {
|
|
68
|
-
const defaultName = NameUtil.getClassName(clazz);
|
|
69
|
-
name = name ?? defaultName;
|
|
70
|
-
proto = EggPrototypeFactory.instance.getPrototype(name, void 0, qualifiers);
|
|
71
|
-
} else if (proto) name = name ?? proto.name;
|
|
72
|
-
if (!proto) {
|
|
73
|
-
debug("getOrCreateEggObjectFromClazz:%o not found, eggObjectName:%s, qualifiers:%o, proto:%o, isMultiInstance:%s", clazz.name, name, qualifiers, proto, isMultiInstance);
|
|
74
|
-
throw new Error(`can not get proto for clazz ${clazz.name}`);
|
|
75
|
-
}
|
|
76
|
-
return await this.getOrCreateEggObject(proto, name);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* get or create egg object from the Name
|
|
80
|
-
* If get singleton egg object in context,
|
|
81
|
-
* will create context egg object for it.
|
|
82
|
-
*/
|
|
83
|
-
static async getOrCreateEggObjectFromName(name, qualifiers) {
|
|
84
|
-
const proto = EggPrototypeFactory.instance.getPrototype(name, void 0, qualifiers);
|
|
85
|
-
if (!proto) throw new Error(`can not get proto for clazz ${String(name)}`);
|
|
86
|
-
return await this.getOrCreateEggObject(proto, name);
|
|
87
|
-
}
|
|
88
|
-
static getEggObject(proto, name) {
|
|
89
|
-
const container = this.getContainer(proto);
|
|
90
|
-
name = name || proto.name;
|
|
91
|
-
return container.getEggObject(name, proto);
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/impl/ContextObjectGraph.ts
|
|
97
|
-
var InjectProtoHolder = class {
|
|
98
|
-
idSet = /* @__PURE__ */ new Set();
|
|
99
|
-
injectProtos = [];
|
|
100
|
-
addInjectProto(injectObjectProto) {
|
|
101
|
-
const id = `${String(injectObjectProto.objName)}:${injectObjectProto.proto.id}`;
|
|
102
|
-
if (this.idSet.has(id)) return;
|
|
103
|
-
this.idSet.add(id);
|
|
104
|
-
this.injectProtos.push(injectObjectProto);
|
|
105
|
-
}
|
|
106
|
-
dumpProtos() {
|
|
107
|
-
return this.injectProtos;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var ContextObjectGraph = class ContextObjectGraph {
|
|
111
|
-
static eggObjectInitRecorder = /* @__PURE__ */ new WeakMap();
|
|
112
|
-
static getContextProto(proto) {
|
|
113
|
-
if (ContextObjectGraph.eggObjectInitRecorder.has(proto)) return ContextObjectGraph.eggObjectInitRecorder.get(proto);
|
|
114
|
-
const holder = new InjectProtoHolder();
|
|
115
|
-
this.doGetContextProto(proto, holder);
|
|
116
|
-
const injectObjectProtos = holder.dumpProtos();
|
|
117
|
-
ContextObjectGraph.eggObjectInitRecorder.set(proto, injectObjectProtos);
|
|
118
|
-
return injectObjectProtos;
|
|
119
|
-
}
|
|
120
|
-
static doGetContextProto(proto, holder) {
|
|
121
|
-
for (const injectObject of proto.injectObjects) {
|
|
122
|
-
if (injectObject.proto.initType === ObjectInitType.CONTEXT && proto.initType !== ObjectInitType.CONTEXT) holder.addInjectProto(injectObject);
|
|
123
|
-
ContextObjectGraph.doGetContextProto(injectObject.proto, holder);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
//#endregion
|
|
129
|
-
//#region src/impl/ContextInitiator.ts
|
|
130
|
-
const CONTEXT_INITIATOR = Symbol("EggContext#ContextInitiator");
|
|
131
|
-
var ContextInitiator = class ContextInitiator {
|
|
132
|
-
eggContext;
|
|
133
|
-
eggObjectInitRecorder;
|
|
134
|
-
constructor(eggContext) {
|
|
135
|
-
this.eggContext = eggContext;
|
|
136
|
-
this.eggObjectInitRecorder = /* @__PURE__ */ new WeakMap();
|
|
137
|
-
this.eggContext.set(CONTEXT_INITIATOR, this);
|
|
138
|
-
}
|
|
139
|
-
async init(obj) {
|
|
140
|
-
if (this.eggObjectInitRecorder.get(obj) === true) return;
|
|
141
|
-
this.eggObjectInitRecorder.set(obj, true);
|
|
142
|
-
const injectObjectProtos = ContextObjectGraph.getContextProto(obj.proto);
|
|
143
|
-
await Promise.all(injectObjectProtos.map(async (injectObject) => {
|
|
144
|
-
const proto = injectObject.proto;
|
|
145
|
-
if (!LoadUnitFactory.getLoadUnitById(proto.loadUnitId)) throw new Error(`can not find load unit: ${proto.loadUnitId}`);
|
|
146
|
-
await EggContainerFactory.getOrCreateEggObject(proto, injectObject.objName);
|
|
147
|
-
}));
|
|
148
|
-
}
|
|
149
|
-
static createContextInitiator(context) {
|
|
150
|
-
let initiator = context.get(CONTEXT_INITIATOR);
|
|
151
|
-
if (!initiator) {
|
|
152
|
-
initiator = new ContextInitiator(context);
|
|
153
|
-
context.set(CONTEXT_INITIATOR, initiator);
|
|
154
|
-
}
|
|
155
|
-
return initiator;
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
//#endregion
|
|
160
|
-
export { ContextHandler, ContextInitiator, ContextObjectGraph, EggContainerFactory };
|