@eggjs/tegg-standalone 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.
- package/dist/index.d.ts +119 -6
- package/dist/index.js +413 -6
- package/package.json +12 -12
- package/dist/ConfigSourceLoadUnitHook.js +0 -21
- package/dist/EggModuleLoader.d.ts +0 -22
- package/dist/EggModuleLoader.js +0 -54
- package/dist/Runner.d.ts +0 -54
- package/dist/Runner.js +0 -181
- package/dist/StandaloneContext.d.ts +0 -9
- package/dist/StandaloneContext.js +0 -14
- package/dist/StandaloneContextHandler.js +0 -18
- package/dist/StandaloneInnerObject.d.ts +0 -20
- package/dist/StandaloneInnerObject.js +0 -31
- package/dist/StandaloneInnerObjectProto.d.ts +0 -24
- package/dist/StandaloneInnerObjectProto.js +0 -49
- package/dist/StandaloneLoadUnit.d.ts +0 -10
- package/dist/StandaloneLoadUnit.js +0 -54
- package/dist/main.d.ts +0 -7
- package/dist/main.js +0 -31
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { EggPrototype, EggPrototypeLifecycleContext, InjectObjectProto, LoadUnit } from "@eggjs/tegg-metadata";
|
|
2
|
+
import { ModuleReference, ReadModuleReferenceOptions } from "@eggjs/tegg-common-util";
|
|
3
|
+
import { AbstractEggContext, EggContext, EggObject, LoadUnitInstance } from "@eggjs/tegg-runtime";
|
|
4
|
+
import { AccessLevel, EggObjectName, EggProtoImplClass, EggPrototypeName, Id, Logger, MetaDataKey, ModuleConfigHolder, ObjectInitTypeLike, QualifierInfo, QualifierValue } from "@eggjs/tegg";
|
|
5
|
+
|
|
6
|
+
//#region src/EggModuleLoader.d.ts
|
|
7
|
+
interface EggModuleLoaderOptions {
|
|
8
|
+
logger: Logger;
|
|
9
|
+
baseDir: string;
|
|
10
|
+
dump?: boolean;
|
|
11
|
+
}
|
|
12
|
+
declare class EggModuleLoader {
|
|
13
|
+
private moduleReferences;
|
|
14
|
+
private globalGraph;
|
|
15
|
+
private options;
|
|
16
|
+
constructor(moduleReferences: readonly ModuleReference[], options: EggModuleLoaderOptions);
|
|
17
|
+
init(): Promise<void>;
|
|
18
|
+
private static generateAppGraph;
|
|
19
|
+
load(): Promise<LoadUnit[]>;
|
|
20
|
+
static preLoad(moduleReferences: readonly ModuleReference[], options: EggModuleLoaderOptions): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/StandaloneLoadUnit.d.ts
|
|
24
|
+
interface InnerObject {
|
|
25
|
+
obj: object;
|
|
26
|
+
qualifiers?: QualifierInfo[];
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/Runner.d.ts
|
|
30
|
+
interface ModuleDependency extends ReadModuleReferenceOptions {
|
|
31
|
+
baseDir: string;
|
|
32
|
+
}
|
|
33
|
+
interface RunnerOptions {
|
|
34
|
+
/**
|
|
35
|
+
* @deprecated
|
|
36
|
+
* use inner object handlers instead
|
|
37
|
+
*/
|
|
38
|
+
innerObjects?: Record<string, object>;
|
|
39
|
+
env?: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
innerObjectHandlers?: Record<string, InnerObject[]>;
|
|
42
|
+
dependencies?: (string | ModuleDependency)[];
|
|
43
|
+
dump?: boolean;
|
|
44
|
+
}
|
|
45
|
+
declare class Runner {
|
|
46
|
+
readonly cwd: string;
|
|
47
|
+
readonly moduleReferences: readonly ModuleReference[];
|
|
48
|
+
readonly moduleConfigs: Record<string, ModuleConfigHolder>;
|
|
49
|
+
readonly env?: string;
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
readonly options?: RunnerOptions;
|
|
52
|
+
private loadUnitLoader;
|
|
53
|
+
private runnerProto;
|
|
54
|
+
private configSourceEggPrototypeHook;
|
|
55
|
+
private loadUnitMultiInstanceProtoHook;
|
|
56
|
+
private dalTableEggPrototypeHook;
|
|
57
|
+
private dalModuleLoadUnitHook;
|
|
58
|
+
private transactionPrototypeHook;
|
|
59
|
+
private crosscutAdviceFactory;
|
|
60
|
+
private loadUnitAopHook;
|
|
61
|
+
private eggPrototypeCrossCutHook;
|
|
62
|
+
private eggObjectAopHook;
|
|
63
|
+
loadUnits: LoadUnit[];
|
|
64
|
+
loadUnitInstances: LoadUnitInstance[];
|
|
65
|
+
innerObjects: Record<string, InnerObject[]>;
|
|
66
|
+
constructor(cwd: string, options?: RunnerOptions);
|
|
67
|
+
load(): Promise<LoadUnit[]>;
|
|
68
|
+
static getModuleReferences(cwd: string, dependencies?: RunnerOptions['dependencies']): readonly ModuleReference[];
|
|
69
|
+
static preLoad(cwd: string, dependencies?: RunnerOptions['dependencies']): Promise<void>;
|
|
70
|
+
private initLoaderInstance;
|
|
71
|
+
init(): Promise<void>;
|
|
72
|
+
run<T>(aCtx?: EggContext): Promise<T>;
|
|
73
|
+
destroy(): Promise<void>;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/main.d.ts
|
|
77
|
+
declare function preLoad(cwd: string, dependencies?: RunnerOptions['dependencies']): Promise<void>;
|
|
78
|
+
declare function main<T = void>(cwd: string, options?: RunnerOptions): Promise<T>;
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/StandaloneInnerObjectProto.d.ts
|
|
81
|
+
declare class StandaloneInnerObjectProto implements EggPrototype {
|
|
82
|
+
[key: symbol]: PropertyDescriptor;
|
|
83
|
+
private readonly clazz;
|
|
84
|
+
private readonly qualifiers;
|
|
85
|
+
readonly id: string;
|
|
86
|
+
readonly name: EggPrototypeName;
|
|
87
|
+
readonly initType: ObjectInitTypeLike;
|
|
88
|
+
readonly accessLevel: AccessLevel;
|
|
89
|
+
readonly injectObjects: InjectObjectProto[];
|
|
90
|
+
readonly loadUnitId: Id;
|
|
91
|
+
constructor(id: string, name: EggPrototypeName, clazz: EggProtoImplClass, initType: ObjectInitTypeLike, loadUnitId: Id, qualifiers: QualifierInfo[]);
|
|
92
|
+
verifyQualifiers(qualifiers: QualifierInfo[]): boolean;
|
|
93
|
+
verifyQualifier(qualifier: QualifierInfo): boolean;
|
|
94
|
+
constructEggObject(): object;
|
|
95
|
+
getMetaData<T>(metadataKey: MetaDataKey): T | undefined;
|
|
96
|
+
getQualifier(attribute: string): QualifierValue | undefined;
|
|
97
|
+
static create(ctx: EggPrototypeLifecycleContext): EggPrototype;
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/StandaloneContext.d.ts
|
|
101
|
+
declare class StandaloneContext extends AbstractEggContext {
|
|
102
|
+
id: string;
|
|
103
|
+
constructor();
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/StandaloneInnerObject.d.ts
|
|
107
|
+
declare const OBJ: unique symbol;
|
|
108
|
+
declare class StandaloneInnerObject implements EggObject {
|
|
109
|
+
readonly isReady: boolean;
|
|
110
|
+
private [OBJ];
|
|
111
|
+
readonly proto: StandaloneInnerObjectProto;
|
|
112
|
+
readonly name: EggObjectName;
|
|
113
|
+
readonly id: string;
|
|
114
|
+
constructor(name: EggObjectName, proto: StandaloneInnerObjectProto);
|
|
115
|
+
get obj(): object;
|
|
116
|
+
injectProperty(): void;
|
|
117
|
+
static createObject(name: EggObjectName, proto: EggPrototype): Promise<StandaloneInnerObject>;
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
7
120
|
export { EggModuleLoader, EggModuleLoaderOptions, ModuleDependency, Runner, RunnerOptions, StandaloneContext, StandaloneInnerObject, StandaloneInnerObjectProto, main, preLoad };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,415 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
import { EggLoadUnitType, EggPrototypeFactory, EggPrototypeLifecycleUtil, GlobalGraph, LoadUnitFactory, LoadUnitLifecycleUtil, LoadUnitMultiInstanceProtoHook, ModuleDescriptorDumper } from "@eggjs/tegg-metadata";
|
|
2
|
+
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
3
|
+
import { MapUtil, ModuleConfigUtil } from "@eggjs/tegg-common-util";
|
|
4
|
+
import { AbstractEggContext, ContextHandler, EggContainerFactory, EggObjectFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, ModuleLoadUnitInstance } from "@eggjs/tegg-runtime";
|
|
5
|
+
import { AccessLevel, ConfigSourceQualifier, ConfigSourceQualifierAttribute, IdenticalUtil, MetadataUtil, ModuleConfigs, ObjectInitType, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
|
|
6
|
+
import { StandaloneUtil } from "@eggjs/tegg/standalone";
|
|
7
|
+
import { CrosscutAdviceFactory } from "@eggjs/tegg/aop";
|
|
8
|
+
import { EggObjectAopHook, EggPrototypeCrossCutHook, LoadUnitAopHook, crossCutGraphHook, pointCutGraphHook } from "@eggjs/tegg-aop-runtime";
|
|
9
|
+
import { DalModuleLoadUnitHook, DalTableEggPrototypeHook, MysqlDataSourceManager, SqlMapManager, TableModelManager, TransactionPrototypeHook } from "@eggjs/tegg-dal-plugin";
|
|
10
|
+
import { IdenticalUtil as IdenticalUtil$1 } from "@eggjs/tegg-lifecycle";
|
|
11
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
7
12
|
|
|
13
|
+
//#region src/EggModuleLoader.ts
|
|
14
|
+
var EggModuleLoader = class EggModuleLoader {
|
|
15
|
+
moduleReferences;
|
|
16
|
+
globalGraph;
|
|
17
|
+
options;
|
|
18
|
+
constructor(moduleReferences, options) {
|
|
19
|
+
this.moduleReferences = moduleReferences;
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
22
|
+
async init() {
|
|
23
|
+
GlobalGraph.instance = this.globalGraph = await EggModuleLoader.generateAppGraph(this.moduleReferences, this.options);
|
|
24
|
+
}
|
|
25
|
+
static async generateAppGraph(moduleReferences, options) {
|
|
26
|
+
const moduleDescriptors = await LoaderFactory.loadApp(moduleReferences);
|
|
27
|
+
if (options.dump !== false) for (const moduleDescriptor of moduleDescriptors) ModuleDescriptorDumper.dump(moduleDescriptor, { dumpDir: options.baseDir }).catch((e) => {
|
|
28
|
+
e.message = "dump module descriptor failed: " + e.message;
|
|
29
|
+
options.logger.warn(e);
|
|
30
|
+
});
|
|
31
|
+
return await GlobalGraph.create(moduleDescriptors);
|
|
32
|
+
}
|
|
33
|
+
async load() {
|
|
34
|
+
const loadUnits = [];
|
|
35
|
+
this.globalGraph.build();
|
|
36
|
+
this.globalGraph.sort();
|
|
37
|
+
const moduleConfigList = GlobalGraph.instance.moduleConfigList;
|
|
38
|
+
for (const moduleConfig of moduleConfigList) {
|
|
39
|
+
const modulePath = moduleConfig.path;
|
|
40
|
+
const loader = LoaderFactory.createLoader(modulePath, EggLoadUnitType.MODULE);
|
|
41
|
+
const loadUnit = await LoadUnitFactory.createLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
|
|
42
|
+
loadUnits.push(loadUnit);
|
|
43
|
+
}
|
|
44
|
+
return loadUnits;
|
|
45
|
+
}
|
|
46
|
+
static async preLoad(moduleReferences, options) {
|
|
47
|
+
const loadUnits = [];
|
|
48
|
+
const loaderCache = /* @__PURE__ */ new Map();
|
|
49
|
+
const globalGraph = GlobalGraph.instance = await EggModuleLoader.generateAppGraph(moduleReferences, options);
|
|
50
|
+
globalGraph.sort();
|
|
51
|
+
const moduleConfigList = globalGraph.moduleConfigList;
|
|
52
|
+
for (const moduleConfig of moduleConfigList) {
|
|
53
|
+
const modulePath = moduleConfig.path;
|
|
54
|
+
const loader = loaderCache.get(modulePath);
|
|
55
|
+
const loadUnit = await LoadUnitFactory.createPreloadLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
|
|
56
|
+
loadUnits.push(loadUnit);
|
|
57
|
+
}
|
|
58
|
+
for (const load of loadUnits) await load.preLoad?.();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/StandaloneInnerObjectProto.ts
|
|
64
|
+
var StandaloneInnerObjectProto = class StandaloneInnerObjectProto {
|
|
65
|
+
clazz;
|
|
66
|
+
qualifiers;
|
|
67
|
+
id;
|
|
68
|
+
name;
|
|
69
|
+
initType;
|
|
70
|
+
accessLevel;
|
|
71
|
+
injectObjects;
|
|
72
|
+
loadUnitId;
|
|
73
|
+
constructor(id, name, clazz, initType, loadUnitId, qualifiers) {
|
|
74
|
+
this.id = id;
|
|
75
|
+
this.clazz = clazz;
|
|
76
|
+
this.name = name;
|
|
77
|
+
this.initType = initType;
|
|
78
|
+
this.accessLevel = AccessLevel.PUBLIC;
|
|
79
|
+
this.injectObjects = [];
|
|
80
|
+
this.loadUnitId = loadUnitId;
|
|
81
|
+
this.qualifiers = qualifiers;
|
|
82
|
+
}
|
|
83
|
+
verifyQualifiers(qualifiers) {
|
|
84
|
+
for (const qualifier of qualifiers) if (!this.verifyQualifier(qualifier)) return false;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
verifyQualifier(qualifier) {
|
|
88
|
+
return this.qualifiers.find((t) => t.attribute === qualifier.attribute)?.value === qualifier.value;
|
|
89
|
+
}
|
|
90
|
+
constructEggObject() {
|
|
91
|
+
return Reflect.apply(this.clazz, null, []);
|
|
92
|
+
}
|
|
93
|
+
getMetaData(metadataKey) {
|
|
94
|
+
return MetadataUtil.getMetaData(metadataKey, this.clazz);
|
|
95
|
+
}
|
|
96
|
+
getQualifier(attribute) {
|
|
97
|
+
return this.qualifiers.find((t) => t.attribute === attribute)?.value;
|
|
98
|
+
}
|
|
99
|
+
static create(ctx) {
|
|
100
|
+
const { clazz, loadUnit } = ctx;
|
|
101
|
+
const name = ctx.prototypeInfo.name;
|
|
102
|
+
const id = IdenticalUtil.createProtoId(loadUnit.id, name);
|
|
103
|
+
return new StandaloneInnerObjectProto(id, name, clazz, ctx.prototypeInfo.initType, loadUnit.id, QualifierUtil.getProtoQualifiers(clazz));
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/StandaloneLoadUnit.ts
|
|
109
|
+
const StandaloneLoadUnitType = "StandaloneLoadUnitType";
|
|
110
|
+
var StandaloneLoadUnit = class {
|
|
111
|
+
id = "StandaloneLoadUnit";
|
|
112
|
+
name = "StandaloneLoadUnit";
|
|
113
|
+
unitPath = "MockStandaloneLoadUnitPath";
|
|
114
|
+
type = StandaloneLoadUnitType;
|
|
115
|
+
innerObject;
|
|
116
|
+
protoMap = /* @__PURE__ */ new Map();
|
|
117
|
+
constructor(innerObject) {
|
|
118
|
+
this.innerObject = innerObject;
|
|
119
|
+
}
|
|
120
|
+
async init() {
|
|
121
|
+
for (const [name, objs] of Object.entries(this.innerObject)) for (const { obj, qualifiers } of objs) {
|
|
122
|
+
const proto = new StandaloneInnerObjectProto(IdenticalUtil$1.createProtoId(this.id, name), name, (() => obj), ObjectInitType.SINGLETON, this.id, qualifiers || []);
|
|
123
|
+
EggPrototypeFactory.instance.registerPrototype(proto, this);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
containPrototype(proto) {
|
|
127
|
+
return !!this.protoMap.get(proto.name)?.find((t) => t === proto);
|
|
128
|
+
}
|
|
129
|
+
getEggPrototype(name, qualifiers) {
|
|
130
|
+
return this.protoMap.get(name)?.filter((proto) => proto.verifyQualifiers(qualifiers)) || [];
|
|
131
|
+
}
|
|
132
|
+
registerEggPrototype(proto) {
|
|
133
|
+
MapUtil.getOrStore(this.protoMap, proto.name, []).push(proto);
|
|
134
|
+
}
|
|
135
|
+
deletePrototype(proto) {
|
|
136
|
+
const protos = this.protoMap.get(proto.name);
|
|
137
|
+
if (protos) {
|
|
138
|
+
const index = protos.indexOf(proto);
|
|
139
|
+
if (index !== -1) protos.splice(index, 1);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async destroy() {
|
|
143
|
+
for (const namedProtoMap of this.protoMap.values()) for (const proto of namedProtoMap.values()) EggPrototypeFactory.instance.deletePrototype(proto, this);
|
|
144
|
+
this.protoMap.clear();
|
|
145
|
+
}
|
|
146
|
+
iterateEggPrototype() {
|
|
147
|
+
return Array.from(this.protoMap.values()).reduce((p, c) => {
|
|
148
|
+
p = p.concat(c);
|
|
149
|
+
return p;
|
|
150
|
+
}, []).values();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/StandaloneContext.ts
|
|
156
|
+
var StandaloneContext = class extends AbstractEggContext {
|
|
157
|
+
id;
|
|
158
|
+
constructor() {
|
|
159
|
+
super();
|
|
160
|
+
this.id = IdenticalUtil$1.createContextId();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/StandaloneContextHandler.ts
|
|
166
|
+
var StandaloneContextHandler = class StandaloneContextHandler {
|
|
167
|
+
static storage = new AsyncLocalStorage();
|
|
168
|
+
static register() {
|
|
169
|
+
ContextHandler.getContextCallback = () => {
|
|
170
|
+
return StandaloneContextHandler.storage.getStore();
|
|
171
|
+
};
|
|
172
|
+
ContextHandler.runInContextCallback = (context, fn) => {
|
|
173
|
+
return StandaloneContextHandler.storage.run(context, fn);
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/ConfigSourceLoadUnitHook.ts
|
|
180
|
+
/**
|
|
181
|
+
* Hook for inject moduleConfig.
|
|
182
|
+
* Add default qualifier value is current module name.
|
|
183
|
+
*/
|
|
184
|
+
var ConfigSourceLoadUnitHook = class {
|
|
185
|
+
async preCreate(ctx, loadUnit) {
|
|
186
|
+
const classList = await ctx.loader.load();
|
|
187
|
+
for (const clazz of classList) {
|
|
188
|
+
const moduleConfigObject = PrototypeUtil.getInjectObjects(clazz).find((t) => t.objName === "moduleConfig");
|
|
189
|
+
const configSourceQualifier = QualifierUtil.getProperQualifier(clazz, "moduleConfig", ConfigSourceQualifierAttribute);
|
|
190
|
+
if (moduleConfigObject && !configSourceQualifier) ConfigSourceQualifier(loadUnit.name)(clazz.prototype, moduleConfigObject.refName);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
//#endregion
|
|
196
|
+
//#region src/Runner.ts
|
|
197
|
+
var Runner = class Runner {
|
|
198
|
+
cwd;
|
|
199
|
+
moduleReferences;
|
|
200
|
+
moduleConfigs;
|
|
201
|
+
env;
|
|
202
|
+
name;
|
|
203
|
+
options;
|
|
204
|
+
loadUnitLoader;
|
|
205
|
+
runnerProto;
|
|
206
|
+
configSourceEggPrototypeHook;
|
|
207
|
+
loadUnitMultiInstanceProtoHook;
|
|
208
|
+
dalTableEggPrototypeHook;
|
|
209
|
+
dalModuleLoadUnitHook;
|
|
210
|
+
transactionPrototypeHook;
|
|
211
|
+
crosscutAdviceFactory;
|
|
212
|
+
loadUnitAopHook;
|
|
213
|
+
eggPrototypeCrossCutHook;
|
|
214
|
+
eggObjectAopHook;
|
|
215
|
+
loadUnits = [];
|
|
216
|
+
loadUnitInstances = [];
|
|
217
|
+
innerObjects;
|
|
218
|
+
constructor(cwd, options) {
|
|
219
|
+
this.cwd = cwd;
|
|
220
|
+
this.env = options?.env;
|
|
221
|
+
this.name = options?.name;
|
|
222
|
+
this.options = options;
|
|
223
|
+
this.moduleReferences = Runner.getModuleReferences(this.cwd, options?.dependencies);
|
|
224
|
+
this.moduleConfigs = {};
|
|
225
|
+
this.innerObjects = {
|
|
226
|
+
moduleConfigs: [{ obj: new ModuleConfigs(this.moduleConfigs) }],
|
|
227
|
+
moduleConfig: []
|
|
228
|
+
};
|
|
229
|
+
const runtimeConfig = {
|
|
230
|
+
baseDir: this.cwd,
|
|
231
|
+
name: this.name,
|
|
232
|
+
env: this.env
|
|
233
|
+
};
|
|
234
|
+
this.innerObjects.runtimeConfig = [{ obj: runtimeConfig }];
|
|
235
|
+
if (!ModuleConfigUtil.configNames) ModuleConfigUtil.configNames = ["module.default", `module.${this.env}`];
|
|
236
|
+
for (const reference of this.moduleReferences) {
|
|
237
|
+
const absoluteRef = {
|
|
238
|
+
path: ModuleConfigUtil.resolveModuleDir(reference.path, this.cwd),
|
|
239
|
+
name: reference.name
|
|
240
|
+
};
|
|
241
|
+
const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path);
|
|
242
|
+
this.moduleConfigs[moduleName] = {
|
|
243
|
+
name: moduleName,
|
|
244
|
+
reference: absoluteRef,
|
|
245
|
+
config: ModuleConfigUtil.loadModuleConfigSync(absoluteRef.path)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
for (const moduleConfig of Object.values(this.moduleConfigs)) this.innerObjects.moduleConfig.push({
|
|
249
|
+
obj: moduleConfig.config,
|
|
250
|
+
qualifiers: [{
|
|
251
|
+
attribute: ConfigSourceQualifierAttribute,
|
|
252
|
+
value: moduleConfig.name
|
|
253
|
+
}]
|
|
254
|
+
});
|
|
255
|
+
if (options?.innerObjects) for (const [name, obj] of Object.entries(options.innerObjects)) this.innerObjects[name] = [{ obj }];
|
|
256
|
+
else if (options?.innerObjectHandlers) Object.assign(this.innerObjects, options.innerObjectHandlers);
|
|
257
|
+
}
|
|
258
|
+
async load() {
|
|
259
|
+
StandaloneContextHandler.register();
|
|
260
|
+
LoadUnitFactory.registerLoadUnitCreator(StandaloneLoadUnitType, () => {
|
|
261
|
+
return new StandaloneLoadUnit(this.innerObjects);
|
|
262
|
+
});
|
|
263
|
+
LoadUnitInstanceFactory.registerLoadUnitInstanceClass(StandaloneLoadUnitType, ModuleLoadUnitInstance.createModuleLoadUnitInstance);
|
|
264
|
+
const standaloneLoadUnit = await LoadUnitFactory.createLoadUnit("MockStandaloneLoadUnitPath", StandaloneLoadUnitType, { async load() {
|
|
265
|
+
return [];
|
|
266
|
+
} });
|
|
267
|
+
const loadUnits = await this.loadUnitLoader.load();
|
|
268
|
+
return [standaloneLoadUnit, ...loadUnits];
|
|
269
|
+
}
|
|
270
|
+
static getModuleReferences(cwd, dependencies) {
|
|
271
|
+
return (dependencies || []).concat(cwd).reduce((list, baseDir) => {
|
|
272
|
+
const module = typeof baseDir === "string" ? { baseDir } : baseDir;
|
|
273
|
+
return list.concat(...ModuleConfigUtil.readModuleReference(module.baseDir, module));
|
|
274
|
+
}, []);
|
|
275
|
+
}
|
|
276
|
+
static async preLoad(cwd, dependencies) {
|
|
277
|
+
const moduleReferences = Runner.getModuleReferences(cwd, dependencies);
|
|
278
|
+
await EggModuleLoader.preLoad(moduleReferences, {
|
|
279
|
+
baseDir: cwd,
|
|
280
|
+
logger: console,
|
|
281
|
+
dump: false
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
async initLoaderInstance() {
|
|
285
|
+
this.loadUnitLoader = new EggModuleLoader(this.moduleReferences, {
|
|
286
|
+
logger: (this.innerObjects.logger && this.innerObjects.logger[0])?.obj || console,
|
|
287
|
+
baseDir: this.cwd,
|
|
288
|
+
dump: this.options?.dump
|
|
289
|
+
});
|
|
290
|
+
await this.loadUnitLoader.init();
|
|
291
|
+
GlobalGraph.instance.registerBuildHook(crossCutGraphHook);
|
|
292
|
+
GlobalGraph.instance.registerBuildHook(pointCutGraphHook);
|
|
293
|
+
const configSourceEggPrototypeHook = new ConfigSourceLoadUnitHook();
|
|
294
|
+
LoadUnitLifecycleUtil.registerLifecycle(configSourceEggPrototypeHook);
|
|
295
|
+
this.crosscutAdviceFactory = new CrosscutAdviceFactory();
|
|
296
|
+
this.loadUnitAopHook = new LoadUnitAopHook(this.crosscutAdviceFactory);
|
|
297
|
+
this.eggPrototypeCrossCutHook = new EggPrototypeCrossCutHook(this.crosscutAdviceFactory);
|
|
298
|
+
this.eggObjectAopHook = new EggObjectAopHook();
|
|
299
|
+
EggPrototypeLifecycleUtil.registerLifecycle(this.eggPrototypeCrossCutHook);
|
|
300
|
+
LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitAopHook);
|
|
301
|
+
EggObjectLifecycleUtil.registerLifecycle(this.eggObjectAopHook);
|
|
302
|
+
this.loadUnitMultiInstanceProtoHook = new LoadUnitMultiInstanceProtoHook();
|
|
303
|
+
LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitMultiInstanceProtoHook);
|
|
304
|
+
const logger = (this.innerObjects.logger && this.innerObjects.logger[0])?.obj || console;
|
|
305
|
+
this.dalModuleLoadUnitHook = new DalModuleLoadUnitHook(this.env ?? "", this.moduleConfigs, logger);
|
|
306
|
+
this.dalTableEggPrototypeHook = new DalTableEggPrototypeHook(logger);
|
|
307
|
+
this.transactionPrototypeHook = new TransactionPrototypeHook(this.moduleConfigs, logger);
|
|
308
|
+
EggPrototypeLifecycleUtil.registerLifecycle(this.dalTableEggPrototypeHook);
|
|
309
|
+
EggPrototypeLifecycleUtil.registerLifecycle(this.transactionPrototypeHook);
|
|
310
|
+
LoadUnitLifecycleUtil.registerLifecycle(this.dalModuleLoadUnitHook);
|
|
311
|
+
}
|
|
312
|
+
async init() {
|
|
313
|
+
await this.initLoaderInstance();
|
|
314
|
+
this.loadUnits = await this.load();
|
|
315
|
+
const instances = [];
|
|
316
|
+
for (const loadUnit of this.loadUnits) {
|
|
317
|
+
const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
|
|
318
|
+
instances.push(instance);
|
|
319
|
+
}
|
|
320
|
+
this.loadUnitInstances = instances;
|
|
321
|
+
const runnerClass = StandaloneUtil.getMainRunner();
|
|
322
|
+
if (!runnerClass) throw new Error("not found runner class. Do you add @Runner decorator?");
|
|
323
|
+
const proto = PrototypeUtil.getClazzProto(runnerClass);
|
|
324
|
+
if (!proto) throw new Error(`can not get proto for clazz ${runnerClass.name}`);
|
|
325
|
+
this.runnerProto = proto;
|
|
326
|
+
}
|
|
327
|
+
async run(aCtx) {
|
|
328
|
+
const lifecycle = {};
|
|
329
|
+
const ctx = aCtx || new StandaloneContext();
|
|
330
|
+
return await ContextHandler.run(ctx, async () => {
|
|
331
|
+
if (ctx.init) await ctx.init(lifecycle);
|
|
332
|
+
const runner = (await EggContainerFactory.getOrCreateEggObject(this.runnerProto)).obj;
|
|
333
|
+
try {
|
|
334
|
+
return await runner.main();
|
|
335
|
+
} finally {
|
|
336
|
+
if (ctx.destroy) ctx.destroy(lifecycle).catch((e) => {
|
|
337
|
+
e.message = `[tegg/standalone] destroy tegg context failed: ${e.message}`;
|
|
338
|
+
console.warn(e);
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
async destroy() {
|
|
344
|
+
if (this.loadUnitInstances) for (const instance of this.loadUnitInstances) await LoadUnitInstanceFactory.destroyLoadUnitInstance(instance);
|
|
345
|
+
if (this.loadUnits) for (const loadUnit of this.loadUnits) await LoadUnitFactory.destroyLoadUnit(loadUnit);
|
|
346
|
+
if (this.configSourceEggPrototypeHook) LoadUnitLifecycleUtil.deleteLifecycle(this.configSourceEggPrototypeHook);
|
|
347
|
+
if (this.eggPrototypeCrossCutHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.eggPrototypeCrossCutHook);
|
|
348
|
+
if (this.loadUnitAopHook) LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitAopHook);
|
|
349
|
+
if (this.eggObjectAopHook) EggObjectLifecycleUtil.deleteLifecycle(this.eggObjectAopHook);
|
|
350
|
+
if (this.loadUnitMultiInstanceProtoHook) LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitMultiInstanceProtoHook);
|
|
351
|
+
if (this.dalTableEggPrototypeHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.dalTableEggPrototypeHook);
|
|
352
|
+
if (this.dalModuleLoadUnitHook) LoadUnitLifecycleUtil.deleteLifecycle(this.dalModuleLoadUnitHook);
|
|
353
|
+
if (this.transactionPrototypeHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.transactionPrototypeHook);
|
|
354
|
+
MysqlDataSourceManager.instance.clear();
|
|
355
|
+
SqlMapManager.instance.clear();
|
|
356
|
+
TableModelManager.instance.clear();
|
|
357
|
+
ModuleConfigUtil.setConfigNames(void 0);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
//#endregion
|
|
362
|
+
//#region src/main.ts
|
|
363
|
+
async function preLoad(cwd, dependencies) {
|
|
364
|
+
try {
|
|
365
|
+
await Runner.preLoad(cwd, dependencies);
|
|
366
|
+
} catch (e) {
|
|
367
|
+
if (e instanceof Error) e.message = `[tegg/standalone] bootstrap standalone preLoad failed: ${e.message}`;
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
async function main(cwd, options) {
|
|
372
|
+
const runner = new Runner(cwd, options);
|
|
373
|
+
try {
|
|
374
|
+
await runner.init();
|
|
375
|
+
} catch (e) {
|
|
376
|
+
if (e instanceof Error) e.message = `[tegg/standalone] bootstrap tegg failed: ${e.message}`;
|
|
377
|
+
throw e;
|
|
378
|
+
}
|
|
379
|
+
try {
|
|
380
|
+
return await runner.run();
|
|
381
|
+
} finally {
|
|
382
|
+
runner.destroy().catch((e) => {
|
|
383
|
+
e.message = `[tegg/standalone] destroy tegg failed: ${e.message}`;
|
|
384
|
+
console.warn(e);
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
//#endregion
|
|
390
|
+
//#region src/StandaloneInnerObject.ts
|
|
391
|
+
const OBJ = Symbol("EggCompatibleObject#obj");
|
|
392
|
+
var StandaloneInnerObject = class StandaloneInnerObject {
|
|
393
|
+
isReady = true;
|
|
394
|
+
[OBJ];
|
|
395
|
+
proto;
|
|
396
|
+
name;
|
|
397
|
+
id;
|
|
398
|
+
constructor(name, proto) {
|
|
399
|
+
this.proto = proto;
|
|
400
|
+
this.name = name;
|
|
401
|
+
this.id = IdenticalUtil.createObjectId(this.proto.id);
|
|
402
|
+
}
|
|
403
|
+
get obj() {
|
|
404
|
+
if (!this[OBJ]) this[OBJ] = this.proto.constructEggObject();
|
|
405
|
+
return this[OBJ];
|
|
406
|
+
}
|
|
407
|
+
injectProperty() {}
|
|
408
|
+
static async createObject(name, proto) {
|
|
409
|
+
return new StandaloneInnerObject(name, proto);
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
EggObjectFactory.registerEggObjectCreateMethod(StandaloneInnerObjectProto, StandaloneInnerObject.createObject);
|
|
413
|
+
|
|
414
|
+
//#endregion
|
|
8
415
|
export { EggModuleLoader, Runner, StandaloneContext, StandaloneInnerObject, StandaloneInnerObjectProto, main, preLoad };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eggjs/tegg-standalone",
|
|
3
3
|
"description": "tegg standalone",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.8",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"egg",
|
|
7
7
|
"typescript",
|
|
@@ -33,14 +33,14 @@
|
|
|
33
33
|
"author": "killagu <killa123@126.com>",
|
|
34
34
|
"license": "MIT",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@eggjs/tegg": "4.0.0-beta.
|
|
37
|
-
"@eggjs/tegg-
|
|
38
|
-
"@eggjs/tegg-
|
|
39
|
-
"@eggjs/tegg-
|
|
40
|
-
"@eggjs/tegg-
|
|
41
|
-
"@eggjs/tegg-
|
|
42
|
-
"@eggjs/tegg-
|
|
43
|
-
"@eggjs/tegg-
|
|
36
|
+
"@eggjs/tegg": "4.0.0-beta.8",
|
|
37
|
+
"@eggjs/tegg-aop-runtime": "4.0.0-beta.8",
|
|
38
|
+
"@eggjs/tegg-common-util": "4.0.0-beta.8",
|
|
39
|
+
"@eggjs/tegg-dal-plugin": "4.0.0-beta.8",
|
|
40
|
+
"@eggjs/tegg-loader": "4.0.0-beta.8",
|
|
41
|
+
"@eggjs/tegg-metadata": "4.0.0-beta.8",
|
|
42
|
+
"@eggjs/tegg-lifecycle": "4.0.0-beta.8",
|
|
43
|
+
"@eggjs/tegg-runtime": "4.0.0-beta.8"
|
|
44
44
|
},
|
|
45
45
|
"publishConfig": {
|
|
46
46
|
"access": "public"
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"typescript": "^5.9.3",
|
|
55
55
|
"tsdown": "^0.15.6",
|
|
56
56
|
"unplugin-unused": "^0.5.3",
|
|
57
|
-
"@eggjs/
|
|
58
|
-
"@eggjs/
|
|
59
|
-
"@eggjs/
|
|
57
|
+
"@eggjs/tegg-ajv-plugin": "4.0.0-beta.8",
|
|
58
|
+
"@eggjs/core-decorator": "4.0.0-beta.8",
|
|
59
|
+
"@eggjs/dal-decorator": "4.0.0-beta.8"
|
|
60
60
|
},
|
|
61
61
|
"main": "./dist/index.js",
|
|
62
62
|
"module": "./dist/index.js",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "@eggjs/tegg-metadata";
|
|
2
|
-
import { ConfigSourceQualifier, ConfigSourceQualifierAttribute, PrototypeUtil, QualifierUtil } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/ConfigSourceLoadUnitHook.ts
|
|
5
|
-
/**
|
|
6
|
-
* Hook for inject moduleConfig.
|
|
7
|
-
* Add default qualifier value is current module name.
|
|
8
|
-
*/
|
|
9
|
-
var ConfigSourceLoadUnitHook = class {
|
|
10
|
-
async preCreate(ctx, loadUnit) {
|
|
11
|
-
const classList = await ctx.loader.load();
|
|
12
|
-
for (const clazz of classList) {
|
|
13
|
-
const moduleConfigObject = PrototypeUtil.getInjectObjects(clazz).find((t) => t.objName === "moduleConfig");
|
|
14
|
-
const configSourceQualifier = QualifierUtil.getProperQualifier(clazz, "moduleConfig", ConfigSourceQualifierAttribute);
|
|
15
|
-
if (moduleConfigObject && !configSourceQualifier) ConfigSourceQualifier(loadUnit.name)(clazz.prototype, moduleConfigObject.refName);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
//#endregion
|
|
21
|
-
export { ConfigSourceLoadUnitHook };
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { LoadUnit } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { ModuleReference } from "@eggjs/tegg-common-util";
|
|
3
|
-
import { Logger } from "@eggjs/tegg";
|
|
4
|
-
|
|
5
|
-
//#region src/EggModuleLoader.d.ts
|
|
6
|
-
interface EggModuleLoaderOptions {
|
|
7
|
-
logger: Logger;
|
|
8
|
-
baseDir: string;
|
|
9
|
-
dump?: boolean;
|
|
10
|
-
}
|
|
11
|
-
declare class EggModuleLoader {
|
|
12
|
-
private moduleReferences;
|
|
13
|
-
private globalGraph;
|
|
14
|
-
private options;
|
|
15
|
-
constructor(moduleReferences: readonly ModuleReference[], options: EggModuleLoaderOptions);
|
|
16
|
-
init(): Promise<void>;
|
|
17
|
-
private static generateAppGraph;
|
|
18
|
-
load(): Promise<LoadUnit[]>;
|
|
19
|
-
static preLoad(moduleReferences: readonly ModuleReference[], options: EggModuleLoaderOptions): Promise<void>;
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { EggModuleLoader, EggModuleLoaderOptions };
|
package/dist/EggModuleLoader.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { EggLoadUnitType, GlobalGraph, LoadUnitFactory, ModuleDescriptorDumper } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { LoaderFactory } from "@eggjs/tegg-loader";
|
|
3
|
-
|
|
4
|
-
//#region src/EggModuleLoader.ts
|
|
5
|
-
var EggModuleLoader = class EggModuleLoader {
|
|
6
|
-
moduleReferences;
|
|
7
|
-
globalGraph;
|
|
8
|
-
options;
|
|
9
|
-
constructor(moduleReferences, options) {
|
|
10
|
-
this.moduleReferences = moduleReferences;
|
|
11
|
-
this.options = options;
|
|
12
|
-
}
|
|
13
|
-
async init() {
|
|
14
|
-
GlobalGraph.instance = this.globalGraph = await EggModuleLoader.generateAppGraph(this.moduleReferences, this.options);
|
|
15
|
-
}
|
|
16
|
-
static async generateAppGraph(moduleReferences, options) {
|
|
17
|
-
const moduleDescriptors = await LoaderFactory.loadApp(moduleReferences);
|
|
18
|
-
if (options.dump !== false) for (const moduleDescriptor of moduleDescriptors) ModuleDescriptorDumper.dump(moduleDescriptor, { dumpDir: options.baseDir }).catch((e) => {
|
|
19
|
-
e.message = "dump module descriptor failed: " + e.message;
|
|
20
|
-
options.logger.warn(e);
|
|
21
|
-
});
|
|
22
|
-
return await GlobalGraph.create(moduleDescriptors);
|
|
23
|
-
}
|
|
24
|
-
async load() {
|
|
25
|
-
const loadUnits = [];
|
|
26
|
-
this.globalGraph.build();
|
|
27
|
-
this.globalGraph.sort();
|
|
28
|
-
const moduleConfigList = GlobalGraph.instance.moduleConfigList;
|
|
29
|
-
for (const moduleConfig of moduleConfigList) {
|
|
30
|
-
const modulePath = moduleConfig.path;
|
|
31
|
-
const loader = LoaderFactory.createLoader(modulePath, EggLoadUnitType.MODULE);
|
|
32
|
-
const loadUnit = await LoadUnitFactory.createLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
|
|
33
|
-
loadUnits.push(loadUnit);
|
|
34
|
-
}
|
|
35
|
-
return loadUnits;
|
|
36
|
-
}
|
|
37
|
-
static async preLoad(moduleReferences, options) {
|
|
38
|
-
const loadUnits = [];
|
|
39
|
-
const loaderCache = /* @__PURE__ */ new Map();
|
|
40
|
-
const globalGraph = GlobalGraph.instance = await EggModuleLoader.generateAppGraph(moduleReferences, options);
|
|
41
|
-
globalGraph.sort();
|
|
42
|
-
const moduleConfigList = globalGraph.moduleConfigList;
|
|
43
|
-
for (const moduleConfig of moduleConfigList) {
|
|
44
|
-
const modulePath = moduleConfig.path;
|
|
45
|
-
const loader = loaderCache.get(modulePath);
|
|
46
|
-
const loadUnit = await LoadUnitFactory.createPreloadLoadUnit(modulePath, EggLoadUnitType.MODULE, loader);
|
|
47
|
-
loadUnits.push(loadUnit);
|
|
48
|
-
}
|
|
49
|
-
for (const load of loadUnits) await load.preLoad?.();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
export { EggModuleLoader };
|
package/dist/Runner.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { InnerObject } from "./StandaloneLoadUnit.js";
|
|
2
|
-
import { LoadUnit } from "@eggjs/tegg-metadata";
|
|
3
|
-
import { ModuleReference, ReadModuleReferenceOptions } from "@eggjs/tegg-common-util";
|
|
4
|
-
import { EggContext, LoadUnitInstance } from "@eggjs/tegg-runtime";
|
|
5
|
-
import { ModuleConfigHolder } from "@eggjs/tegg";
|
|
6
|
-
|
|
7
|
-
//#region src/Runner.d.ts
|
|
8
|
-
interface ModuleDependency extends ReadModuleReferenceOptions {
|
|
9
|
-
baseDir: string;
|
|
10
|
-
}
|
|
11
|
-
interface RunnerOptions {
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated
|
|
14
|
-
* use inner object handlers instead
|
|
15
|
-
*/
|
|
16
|
-
innerObjects?: Record<string, object>;
|
|
17
|
-
env?: string;
|
|
18
|
-
name?: string;
|
|
19
|
-
innerObjectHandlers?: Record<string, InnerObject[]>;
|
|
20
|
-
dependencies?: (string | ModuleDependency)[];
|
|
21
|
-
dump?: boolean;
|
|
22
|
-
}
|
|
23
|
-
declare class Runner {
|
|
24
|
-
readonly cwd: string;
|
|
25
|
-
readonly moduleReferences: readonly ModuleReference[];
|
|
26
|
-
readonly moduleConfigs: Record<string, ModuleConfigHolder>;
|
|
27
|
-
readonly env?: string;
|
|
28
|
-
readonly name?: string;
|
|
29
|
-
readonly options?: RunnerOptions;
|
|
30
|
-
private loadUnitLoader;
|
|
31
|
-
private runnerProto;
|
|
32
|
-
private configSourceEggPrototypeHook;
|
|
33
|
-
private loadUnitMultiInstanceProtoHook;
|
|
34
|
-
private dalTableEggPrototypeHook;
|
|
35
|
-
private dalModuleLoadUnitHook;
|
|
36
|
-
private transactionPrototypeHook;
|
|
37
|
-
private crosscutAdviceFactory;
|
|
38
|
-
private loadUnitAopHook;
|
|
39
|
-
private eggPrototypeCrossCutHook;
|
|
40
|
-
private eggObjectAopHook;
|
|
41
|
-
loadUnits: LoadUnit[];
|
|
42
|
-
loadUnitInstances: LoadUnitInstance[];
|
|
43
|
-
innerObjects: Record<string, InnerObject[]>;
|
|
44
|
-
constructor(cwd: string, options?: RunnerOptions);
|
|
45
|
-
load(): Promise<LoadUnit[]>;
|
|
46
|
-
static getModuleReferences(cwd: string, dependencies?: RunnerOptions['dependencies']): readonly ModuleReference[];
|
|
47
|
-
static preLoad(cwd: string, dependencies?: RunnerOptions['dependencies']): Promise<void>;
|
|
48
|
-
private initLoaderInstance;
|
|
49
|
-
init(): Promise<void>;
|
|
50
|
-
run<T>(aCtx?: EggContext): Promise<T>;
|
|
51
|
-
destroy(): Promise<void>;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
export { ModuleDependency, Runner, RunnerOptions };
|
package/dist/Runner.js
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { EggModuleLoader } from "./EggModuleLoader.js";
|
|
2
|
-
import { StandaloneLoadUnit, StandaloneLoadUnitType } from "./StandaloneLoadUnit.js";
|
|
3
|
-
import { StandaloneContext } from "./StandaloneContext.js";
|
|
4
|
-
import { StandaloneContextHandler } from "./StandaloneContextHandler.js";
|
|
5
|
-
import { ConfigSourceLoadUnitHook } from "./ConfigSourceLoadUnitHook.js";
|
|
6
|
-
import { EggPrototypeLifecycleUtil, GlobalGraph, LoadUnitFactory, LoadUnitLifecycleUtil, LoadUnitMultiInstanceProtoHook } from "@eggjs/tegg-metadata";
|
|
7
|
-
import { ModuleConfigUtil } from "@eggjs/tegg-common-util";
|
|
8
|
-
import { ContextHandler, EggContainerFactory, EggObjectLifecycleUtil, LoadUnitInstanceFactory, ModuleLoadUnitInstance } from "@eggjs/tegg-runtime";
|
|
9
|
-
import { ConfigSourceQualifierAttribute, ModuleConfigs, PrototypeUtil } from "@eggjs/tegg";
|
|
10
|
-
import { StandaloneUtil } from "@eggjs/tegg/standalone";
|
|
11
|
-
import { CrosscutAdviceFactory } from "@eggjs/tegg/aop";
|
|
12
|
-
import { EggObjectAopHook, EggPrototypeCrossCutHook, LoadUnitAopHook, crossCutGraphHook, pointCutGraphHook } from "@eggjs/tegg-aop-runtime";
|
|
13
|
-
import { DalModuleLoadUnitHook, DalTableEggPrototypeHook, MysqlDataSourceManager, SqlMapManager, TableModelManager, TransactionPrototypeHook } from "@eggjs/tegg-dal-plugin";
|
|
14
|
-
|
|
15
|
-
//#region src/Runner.ts
|
|
16
|
-
var Runner = class Runner {
|
|
17
|
-
cwd;
|
|
18
|
-
moduleReferences;
|
|
19
|
-
moduleConfigs;
|
|
20
|
-
env;
|
|
21
|
-
name;
|
|
22
|
-
options;
|
|
23
|
-
loadUnitLoader;
|
|
24
|
-
runnerProto;
|
|
25
|
-
configSourceEggPrototypeHook;
|
|
26
|
-
loadUnitMultiInstanceProtoHook;
|
|
27
|
-
dalTableEggPrototypeHook;
|
|
28
|
-
dalModuleLoadUnitHook;
|
|
29
|
-
transactionPrototypeHook;
|
|
30
|
-
crosscutAdviceFactory;
|
|
31
|
-
loadUnitAopHook;
|
|
32
|
-
eggPrototypeCrossCutHook;
|
|
33
|
-
eggObjectAopHook;
|
|
34
|
-
loadUnits = [];
|
|
35
|
-
loadUnitInstances = [];
|
|
36
|
-
innerObjects;
|
|
37
|
-
constructor(cwd, options) {
|
|
38
|
-
this.cwd = cwd;
|
|
39
|
-
this.env = options?.env;
|
|
40
|
-
this.name = options?.name;
|
|
41
|
-
this.options = options;
|
|
42
|
-
this.moduleReferences = Runner.getModuleReferences(this.cwd, options?.dependencies);
|
|
43
|
-
this.moduleConfigs = {};
|
|
44
|
-
this.innerObjects = {
|
|
45
|
-
moduleConfigs: [{ obj: new ModuleConfigs(this.moduleConfigs) }],
|
|
46
|
-
moduleConfig: []
|
|
47
|
-
};
|
|
48
|
-
const runtimeConfig = {
|
|
49
|
-
baseDir: this.cwd,
|
|
50
|
-
name: this.name,
|
|
51
|
-
env: this.env
|
|
52
|
-
};
|
|
53
|
-
this.innerObjects.runtimeConfig = [{ obj: runtimeConfig }];
|
|
54
|
-
if (!ModuleConfigUtil.configNames) ModuleConfigUtil.configNames = ["module.default", `module.${this.env}`];
|
|
55
|
-
for (const reference of this.moduleReferences) {
|
|
56
|
-
const absoluteRef = {
|
|
57
|
-
path: ModuleConfigUtil.resolveModuleDir(reference.path, this.cwd),
|
|
58
|
-
name: reference.name
|
|
59
|
-
};
|
|
60
|
-
const moduleName = ModuleConfigUtil.readModuleNameSync(absoluteRef.path);
|
|
61
|
-
this.moduleConfigs[moduleName] = {
|
|
62
|
-
name: moduleName,
|
|
63
|
-
reference: absoluteRef,
|
|
64
|
-
config: ModuleConfigUtil.loadModuleConfigSync(absoluteRef.path)
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
for (const moduleConfig of Object.values(this.moduleConfigs)) this.innerObjects.moduleConfig.push({
|
|
68
|
-
obj: moduleConfig.config,
|
|
69
|
-
qualifiers: [{
|
|
70
|
-
attribute: ConfigSourceQualifierAttribute,
|
|
71
|
-
value: moduleConfig.name
|
|
72
|
-
}]
|
|
73
|
-
});
|
|
74
|
-
if (options?.innerObjects) for (const [name, obj] of Object.entries(options.innerObjects)) this.innerObjects[name] = [{ obj }];
|
|
75
|
-
else if (options?.innerObjectHandlers) Object.assign(this.innerObjects, options.innerObjectHandlers);
|
|
76
|
-
}
|
|
77
|
-
async load() {
|
|
78
|
-
StandaloneContextHandler.register();
|
|
79
|
-
LoadUnitFactory.registerLoadUnitCreator(StandaloneLoadUnitType, () => {
|
|
80
|
-
return new StandaloneLoadUnit(this.innerObjects);
|
|
81
|
-
});
|
|
82
|
-
LoadUnitInstanceFactory.registerLoadUnitInstanceClass(StandaloneLoadUnitType, ModuleLoadUnitInstance.createModuleLoadUnitInstance);
|
|
83
|
-
const standaloneLoadUnit = await LoadUnitFactory.createLoadUnit("MockStandaloneLoadUnitPath", StandaloneLoadUnitType, { async load() {
|
|
84
|
-
return [];
|
|
85
|
-
} });
|
|
86
|
-
const loadUnits = await this.loadUnitLoader.load();
|
|
87
|
-
return [standaloneLoadUnit, ...loadUnits];
|
|
88
|
-
}
|
|
89
|
-
static getModuleReferences(cwd, dependencies) {
|
|
90
|
-
return (dependencies || []).concat(cwd).reduce((list, baseDir) => {
|
|
91
|
-
const module = typeof baseDir === "string" ? { baseDir } : baseDir;
|
|
92
|
-
return list.concat(...ModuleConfigUtil.readModuleReference(module.baseDir, module));
|
|
93
|
-
}, []);
|
|
94
|
-
}
|
|
95
|
-
static async preLoad(cwd, dependencies) {
|
|
96
|
-
const moduleReferences = Runner.getModuleReferences(cwd, dependencies);
|
|
97
|
-
await EggModuleLoader.preLoad(moduleReferences, {
|
|
98
|
-
baseDir: cwd,
|
|
99
|
-
logger: console,
|
|
100
|
-
dump: false
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
async initLoaderInstance() {
|
|
104
|
-
this.loadUnitLoader = new EggModuleLoader(this.moduleReferences, {
|
|
105
|
-
logger: (this.innerObjects.logger && this.innerObjects.logger[0])?.obj || console,
|
|
106
|
-
baseDir: this.cwd,
|
|
107
|
-
dump: this.options?.dump
|
|
108
|
-
});
|
|
109
|
-
await this.loadUnitLoader.init();
|
|
110
|
-
GlobalGraph.instance.registerBuildHook(crossCutGraphHook);
|
|
111
|
-
GlobalGraph.instance.registerBuildHook(pointCutGraphHook);
|
|
112
|
-
const configSourceEggPrototypeHook = new ConfigSourceLoadUnitHook();
|
|
113
|
-
LoadUnitLifecycleUtil.registerLifecycle(configSourceEggPrototypeHook);
|
|
114
|
-
this.crosscutAdviceFactory = new CrosscutAdviceFactory();
|
|
115
|
-
this.loadUnitAopHook = new LoadUnitAopHook(this.crosscutAdviceFactory);
|
|
116
|
-
this.eggPrototypeCrossCutHook = new EggPrototypeCrossCutHook(this.crosscutAdviceFactory);
|
|
117
|
-
this.eggObjectAopHook = new EggObjectAopHook();
|
|
118
|
-
EggPrototypeLifecycleUtil.registerLifecycle(this.eggPrototypeCrossCutHook);
|
|
119
|
-
LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitAopHook);
|
|
120
|
-
EggObjectLifecycleUtil.registerLifecycle(this.eggObjectAopHook);
|
|
121
|
-
this.loadUnitMultiInstanceProtoHook = new LoadUnitMultiInstanceProtoHook();
|
|
122
|
-
LoadUnitLifecycleUtil.registerLifecycle(this.loadUnitMultiInstanceProtoHook);
|
|
123
|
-
const logger = (this.innerObjects.logger && this.innerObjects.logger[0])?.obj || console;
|
|
124
|
-
this.dalModuleLoadUnitHook = new DalModuleLoadUnitHook(this.env ?? "", this.moduleConfigs, logger);
|
|
125
|
-
this.dalTableEggPrototypeHook = new DalTableEggPrototypeHook(logger);
|
|
126
|
-
this.transactionPrototypeHook = new TransactionPrototypeHook(this.moduleConfigs, logger);
|
|
127
|
-
EggPrototypeLifecycleUtil.registerLifecycle(this.dalTableEggPrototypeHook);
|
|
128
|
-
EggPrototypeLifecycleUtil.registerLifecycle(this.transactionPrototypeHook);
|
|
129
|
-
LoadUnitLifecycleUtil.registerLifecycle(this.dalModuleLoadUnitHook);
|
|
130
|
-
}
|
|
131
|
-
async init() {
|
|
132
|
-
await this.initLoaderInstance();
|
|
133
|
-
this.loadUnits = await this.load();
|
|
134
|
-
const instances = [];
|
|
135
|
-
for (const loadUnit of this.loadUnits) {
|
|
136
|
-
const instance = await LoadUnitInstanceFactory.createLoadUnitInstance(loadUnit);
|
|
137
|
-
instances.push(instance);
|
|
138
|
-
}
|
|
139
|
-
this.loadUnitInstances = instances;
|
|
140
|
-
const runnerClass = StandaloneUtil.getMainRunner();
|
|
141
|
-
if (!runnerClass) throw new Error("not found runner class. Do you add @Runner decorator?");
|
|
142
|
-
const proto = PrototypeUtil.getClazzProto(runnerClass);
|
|
143
|
-
if (!proto) throw new Error(`can not get proto for clazz ${runnerClass.name}`);
|
|
144
|
-
this.runnerProto = proto;
|
|
145
|
-
}
|
|
146
|
-
async run(aCtx) {
|
|
147
|
-
const lifecycle = {};
|
|
148
|
-
const ctx = aCtx || new StandaloneContext();
|
|
149
|
-
return await ContextHandler.run(ctx, async () => {
|
|
150
|
-
if (ctx.init) await ctx.init(lifecycle);
|
|
151
|
-
const runner = (await EggContainerFactory.getOrCreateEggObject(this.runnerProto)).obj;
|
|
152
|
-
try {
|
|
153
|
-
return await runner.main();
|
|
154
|
-
} finally {
|
|
155
|
-
if (ctx.destroy) ctx.destroy(lifecycle).catch((e) => {
|
|
156
|
-
e.message = `[tegg/standalone] destroy tegg context failed: ${e.message}`;
|
|
157
|
-
console.warn(e);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
async destroy() {
|
|
163
|
-
if (this.loadUnitInstances) for (const instance of this.loadUnitInstances) await LoadUnitInstanceFactory.destroyLoadUnitInstance(instance);
|
|
164
|
-
if (this.loadUnits) for (const loadUnit of this.loadUnits) await LoadUnitFactory.destroyLoadUnit(loadUnit);
|
|
165
|
-
if (this.configSourceEggPrototypeHook) LoadUnitLifecycleUtil.deleteLifecycle(this.configSourceEggPrototypeHook);
|
|
166
|
-
if (this.eggPrototypeCrossCutHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.eggPrototypeCrossCutHook);
|
|
167
|
-
if (this.loadUnitAopHook) LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitAopHook);
|
|
168
|
-
if (this.eggObjectAopHook) EggObjectLifecycleUtil.deleteLifecycle(this.eggObjectAopHook);
|
|
169
|
-
if (this.loadUnitMultiInstanceProtoHook) LoadUnitLifecycleUtil.deleteLifecycle(this.loadUnitMultiInstanceProtoHook);
|
|
170
|
-
if (this.dalTableEggPrototypeHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.dalTableEggPrototypeHook);
|
|
171
|
-
if (this.dalModuleLoadUnitHook) LoadUnitLifecycleUtil.deleteLifecycle(this.dalModuleLoadUnitHook);
|
|
172
|
-
if (this.transactionPrototypeHook) EggPrototypeLifecycleUtil.deleteLifecycle(this.transactionPrototypeHook);
|
|
173
|
-
MysqlDataSourceManager.instance.clear();
|
|
174
|
-
SqlMapManager.instance.clear();
|
|
175
|
-
TableModelManager.instance.clear();
|
|
176
|
-
ModuleConfigUtil.setConfigNames(void 0);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
//#endregion
|
|
181
|
-
export { Runner };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AbstractEggContext } from "@eggjs/tegg-runtime";
|
|
2
|
-
import { IdenticalUtil } from "@eggjs/tegg-lifecycle";
|
|
3
|
-
|
|
4
|
-
//#region src/StandaloneContext.ts
|
|
5
|
-
var StandaloneContext = class extends AbstractEggContext {
|
|
6
|
-
id;
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
this.id = IdenticalUtil.createContextId();
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { StandaloneContext };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ContextHandler } from "@eggjs/tegg-runtime";
|
|
2
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
|
-
|
|
4
|
-
//#region src/StandaloneContextHandler.ts
|
|
5
|
-
var StandaloneContextHandler = class StandaloneContextHandler {
|
|
6
|
-
static storage = new AsyncLocalStorage();
|
|
7
|
-
static register() {
|
|
8
|
-
ContextHandler.getContextCallback = () => {
|
|
9
|
-
return StandaloneContextHandler.storage.getStore();
|
|
10
|
-
};
|
|
11
|
-
ContextHandler.runInContextCallback = (context, fn) => {
|
|
12
|
-
return StandaloneContextHandler.storage.run(context, fn);
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { StandaloneContextHandler };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { StandaloneInnerObjectProto } from "./StandaloneInnerObjectProto.js";
|
|
2
|
-
import { EggPrototype } from "@eggjs/tegg-metadata";
|
|
3
|
-
import { EggObject } from "@eggjs/tegg-runtime";
|
|
4
|
-
import { EggObjectName } from "@eggjs/tegg";
|
|
5
|
-
|
|
6
|
-
//#region src/StandaloneInnerObject.d.ts
|
|
7
|
-
declare const OBJ: unique symbol;
|
|
8
|
-
declare class StandaloneInnerObject implements EggObject {
|
|
9
|
-
readonly isReady: boolean;
|
|
10
|
-
private [OBJ];
|
|
11
|
-
readonly proto: StandaloneInnerObjectProto;
|
|
12
|
-
readonly name: EggObjectName;
|
|
13
|
-
readonly id: string;
|
|
14
|
-
constructor(name: EggObjectName, proto: StandaloneInnerObjectProto);
|
|
15
|
-
get obj(): object;
|
|
16
|
-
injectProperty(): void;
|
|
17
|
-
static createObject(name: EggObjectName, proto: EggPrototype): Promise<StandaloneInnerObject>;
|
|
18
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { StandaloneInnerObject };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { StandaloneInnerObjectProto } from "./StandaloneInnerObjectProto.js";
|
|
2
|
-
import "@eggjs/tegg-metadata";
|
|
3
|
-
import { EggObjectFactory } from "@eggjs/tegg-runtime";
|
|
4
|
-
import { IdenticalUtil } from "@eggjs/tegg";
|
|
5
|
-
|
|
6
|
-
//#region src/StandaloneInnerObject.ts
|
|
7
|
-
const OBJ = Symbol("EggCompatibleObject#obj");
|
|
8
|
-
var StandaloneInnerObject = class StandaloneInnerObject {
|
|
9
|
-
isReady = true;
|
|
10
|
-
[OBJ];
|
|
11
|
-
proto;
|
|
12
|
-
name;
|
|
13
|
-
id;
|
|
14
|
-
constructor(name, proto) {
|
|
15
|
-
this.proto = proto;
|
|
16
|
-
this.name = name;
|
|
17
|
-
this.id = IdenticalUtil.createObjectId(this.proto.id);
|
|
18
|
-
}
|
|
19
|
-
get obj() {
|
|
20
|
-
if (!this[OBJ]) this[OBJ] = this.proto.constructEggObject();
|
|
21
|
-
return this[OBJ];
|
|
22
|
-
}
|
|
23
|
-
injectProperty() {}
|
|
24
|
-
static async createObject(name, proto) {
|
|
25
|
-
return new StandaloneInnerObject(name, proto);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
EggObjectFactory.registerEggObjectCreateMethod(StandaloneInnerObjectProto, StandaloneInnerObject.createObject);
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
export { StandaloneInnerObject };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { EggPrototype, EggPrototypeLifecycleContext, InjectObjectProto } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { AccessLevel, EggProtoImplClass, EggPrototypeName, Id, MetaDataKey, ObjectInitTypeLike, QualifierInfo, QualifierValue } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/StandaloneInnerObjectProto.d.ts
|
|
5
|
-
declare class StandaloneInnerObjectProto implements EggPrototype {
|
|
6
|
-
[key: symbol]: PropertyDescriptor;
|
|
7
|
-
private readonly clazz;
|
|
8
|
-
private readonly qualifiers;
|
|
9
|
-
readonly id: string;
|
|
10
|
-
readonly name: EggPrototypeName;
|
|
11
|
-
readonly initType: ObjectInitTypeLike;
|
|
12
|
-
readonly accessLevel: AccessLevel;
|
|
13
|
-
readonly injectObjects: InjectObjectProto[];
|
|
14
|
-
readonly loadUnitId: Id;
|
|
15
|
-
constructor(id: string, name: EggPrototypeName, clazz: EggProtoImplClass, initType: ObjectInitTypeLike, loadUnitId: Id, qualifiers: QualifierInfo[]);
|
|
16
|
-
verifyQualifiers(qualifiers: QualifierInfo[]): boolean;
|
|
17
|
-
verifyQualifier(qualifier: QualifierInfo): boolean;
|
|
18
|
-
constructEggObject(): object;
|
|
19
|
-
getMetaData<T>(metadataKey: MetaDataKey): T | undefined;
|
|
20
|
-
getQualifier(attribute: string): QualifierValue | undefined;
|
|
21
|
-
static create(ctx: EggPrototypeLifecycleContext): EggPrototype;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { StandaloneInnerObjectProto };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import "@eggjs/tegg-metadata";
|
|
2
|
-
import { AccessLevel, IdenticalUtil, MetadataUtil, QualifierUtil } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/StandaloneInnerObjectProto.ts
|
|
5
|
-
var StandaloneInnerObjectProto = class StandaloneInnerObjectProto {
|
|
6
|
-
clazz;
|
|
7
|
-
qualifiers;
|
|
8
|
-
id;
|
|
9
|
-
name;
|
|
10
|
-
initType;
|
|
11
|
-
accessLevel;
|
|
12
|
-
injectObjects;
|
|
13
|
-
loadUnitId;
|
|
14
|
-
constructor(id, name, clazz, initType, loadUnitId, qualifiers) {
|
|
15
|
-
this.id = id;
|
|
16
|
-
this.clazz = clazz;
|
|
17
|
-
this.name = name;
|
|
18
|
-
this.initType = initType;
|
|
19
|
-
this.accessLevel = AccessLevel.PUBLIC;
|
|
20
|
-
this.injectObjects = [];
|
|
21
|
-
this.loadUnitId = loadUnitId;
|
|
22
|
-
this.qualifiers = qualifiers;
|
|
23
|
-
}
|
|
24
|
-
verifyQualifiers(qualifiers) {
|
|
25
|
-
for (const qualifier of qualifiers) if (!this.verifyQualifier(qualifier)) return false;
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
verifyQualifier(qualifier) {
|
|
29
|
-
return this.qualifiers.find((t) => t.attribute === qualifier.attribute)?.value === qualifier.value;
|
|
30
|
-
}
|
|
31
|
-
constructEggObject() {
|
|
32
|
-
return Reflect.apply(this.clazz, null, []);
|
|
33
|
-
}
|
|
34
|
-
getMetaData(metadataKey) {
|
|
35
|
-
return MetadataUtil.getMetaData(metadataKey, this.clazz);
|
|
36
|
-
}
|
|
37
|
-
getQualifier(attribute) {
|
|
38
|
-
return this.qualifiers.find((t) => t.attribute === attribute)?.value;
|
|
39
|
-
}
|
|
40
|
-
static create(ctx) {
|
|
41
|
-
const { clazz, loadUnit } = ctx;
|
|
42
|
-
const name = ctx.prototypeInfo.name;
|
|
43
|
-
const id = IdenticalUtil.createProtoId(loadUnit.id, name);
|
|
44
|
-
return new StandaloneInnerObjectProto(id, name, clazz, ctx.prototypeInfo.initType, loadUnit.id, QualifierUtil.getProtoQualifiers(clazz));
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { StandaloneInnerObjectProto };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EggPrototype, LoadUnit } from "@eggjs/tegg-metadata";
|
|
2
|
-
import { QualifierInfo } from "@eggjs/tegg";
|
|
3
|
-
|
|
4
|
-
//#region src/StandaloneLoadUnit.d.ts
|
|
5
|
-
interface InnerObject {
|
|
6
|
-
obj: object;
|
|
7
|
-
qualifiers?: QualifierInfo[];
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { InnerObject };
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { StandaloneInnerObjectProto } from "./StandaloneInnerObjectProto.js";
|
|
2
|
-
import { EggPrototypeFactory } from "@eggjs/tegg-metadata";
|
|
3
|
-
import { MapUtil } from "@eggjs/tegg-common-util";
|
|
4
|
-
import { ObjectInitType } from "@eggjs/tegg";
|
|
5
|
-
import { IdenticalUtil as IdenticalUtil$1 } from "@eggjs/tegg-lifecycle";
|
|
6
|
-
|
|
7
|
-
//#region src/StandaloneLoadUnit.ts
|
|
8
|
-
const StandaloneLoadUnitType = "StandaloneLoadUnitType";
|
|
9
|
-
var StandaloneLoadUnit = class {
|
|
10
|
-
id = "StandaloneLoadUnit";
|
|
11
|
-
name = "StandaloneLoadUnit";
|
|
12
|
-
unitPath = "MockStandaloneLoadUnitPath";
|
|
13
|
-
type = StandaloneLoadUnitType;
|
|
14
|
-
innerObject;
|
|
15
|
-
protoMap = /* @__PURE__ */ new Map();
|
|
16
|
-
constructor(innerObject) {
|
|
17
|
-
this.innerObject = innerObject;
|
|
18
|
-
}
|
|
19
|
-
async init() {
|
|
20
|
-
for (const [name, objs] of Object.entries(this.innerObject)) for (const { obj, qualifiers } of objs) {
|
|
21
|
-
const proto = new StandaloneInnerObjectProto(IdenticalUtil$1.createProtoId(this.id, name), name, (() => obj), ObjectInitType.SINGLETON, this.id, qualifiers || []);
|
|
22
|
-
EggPrototypeFactory.instance.registerPrototype(proto, this);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
containPrototype(proto) {
|
|
26
|
-
return !!this.protoMap.get(proto.name)?.find((t) => t === proto);
|
|
27
|
-
}
|
|
28
|
-
getEggPrototype(name, qualifiers) {
|
|
29
|
-
return this.protoMap.get(name)?.filter((proto) => proto.verifyQualifiers(qualifiers)) || [];
|
|
30
|
-
}
|
|
31
|
-
registerEggPrototype(proto) {
|
|
32
|
-
MapUtil.getOrStore(this.protoMap, proto.name, []).push(proto);
|
|
33
|
-
}
|
|
34
|
-
deletePrototype(proto) {
|
|
35
|
-
const protos = this.protoMap.get(proto.name);
|
|
36
|
-
if (protos) {
|
|
37
|
-
const index = protos.indexOf(proto);
|
|
38
|
-
if (index !== -1) protos.splice(index, 1);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
async destroy() {
|
|
42
|
-
for (const namedProtoMap of this.protoMap.values()) for (const proto of namedProtoMap.values()) EggPrototypeFactory.instance.deletePrototype(proto, this);
|
|
43
|
-
this.protoMap.clear();
|
|
44
|
-
}
|
|
45
|
-
iterateEggPrototype() {
|
|
46
|
-
return Array.from(this.protoMap.values()).reduce((p, c) => {
|
|
47
|
-
p = p.concat(c);
|
|
48
|
-
return p;
|
|
49
|
-
}, []).values();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
export { StandaloneLoadUnit, StandaloneLoadUnitType };
|
package/dist/main.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { RunnerOptions } from "./Runner.js";
|
|
2
|
-
|
|
3
|
-
//#region src/main.d.ts
|
|
4
|
-
declare function preLoad(cwd: string, dependencies?: RunnerOptions['dependencies']): Promise<void>;
|
|
5
|
-
declare function main<T = void>(cwd: string, options?: RunnerOptions): Promise<T>;
|
|
6
|
-
//#endregion
|
|
7
|
-
export { main, preLoad };
|
package/dist/main.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Runner } from "./Runner.js";
|
|
2
|
-
|
|
3
|
-
//#region src/main.ts
|
|
4
|
-
async function preLoad(cwd, dependencies) {
|
|
5
|
-
try {
|
|
6
|
-
await Runner.preLoad(cwd, dependencies);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
if (e instanceof Error) e.message = `[tegg/standalone] bootstrap standalone preLoad failed: ${e.message}`;
|
|
9
|
-
throw e;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
async function main(cwd, options) {
|
|
13
|
-
const runner = new Runner(cwd, options);
|
|
14
|
-
try {
|
|
15
|
-
await runner.init();
|
|
16
|
-
} catch (e) {
|
|
17
|
-
if (e instanceof Error) e.message = `[tegg/standalone] bootstrap tegg failed: ${e.message}`;
|
|
18
|
-
throw e;
|
|
19
|
-
}
|
|
20
|
-
try {
|
|
21
|
-
return await runner.run();
|
|
22
|
-
} finally {
|
|
23
|
-
runner.destroy().catch((e) => {
|
|
24
|
-
e.message = `[tegg/standalone] destroy tegg failed: ${e.message}`;
|
|
25
|
-
console.warn(e);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
export { main, preLoad };
|