phecda-server 7.0.0-alpha.8 → 7.0.0-alpha.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/{chunk-VSGYTGHY.js → chunk-5RBTN33A.js} +22 -2
- package/dist/{chunk-B45BN7LY.mjs → chunk-7ZGYJ5OW.mjs} +88 -54
- package/dist/{chunk-SGMQZRP6.mjs → chunk-CVPZWDXU.mjs} +2 -23
- package/dist/{chunk-7EMAZGYO.js → chunk-FX3LDQII.js} +59 -80
- package/dist/{chunk-YKP4ODZA.mjs → chunk-FXTJ3BJ6.mjs} +23 -3
- package/dist/{chunk-QJIAXSLZ.js → chunk-KJUD2BKE.js} +103 -69
- package/dist/{chunk-7NWDKK7D.mjs → chunk-ODVWOXVB.mjs} +1 -1
- package/dist/{chunk-BBNJVYVX.js → chunk-V5EYXVJT.js} +24 -24
- package/dist/{core-BcKywWLd.d.mts → core-BDkhrEyf.d.mts} +4 -3
- package/dist/{core-BGEsBtTG.d.ts → core-D_cz0tKa.d.ts} +4 -3
- package/dist/helper.d.mts +6 -5
- package/dist/helper.d.ts +6 -5
- package/dist/helper.js +6 -3
- package/dist/helper.mjs +8 -5
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +41 -45
- package/dist/http/elysia/index.mjs +4 -8
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +38 -42
- package/dist/http/express/index.mjs +4 -8
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +39 -43
- package/dist/http/fastify/index.mjs +4 -8
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +39 -43
- package/dist/http/h3/index.mjs +3 -7
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +35 -39
- package/dist/http/hono/index.mjs +3 -7
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +36 -40
- package/dist/http/hyper-express/index.mjs +3 -7
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +38 -42
- package/dist/http/koa/index.mjs +4 -8
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +40 -42
- package/dist/index.mjs +4 -6
- package/dist/{meta-B_HW7cWh.d.mts → meta-BX5jhe4Z.d.mts} +1 -2
- package/dist/{meta-B_HW7cWh.d.ts → meta-BX5jhe4Z.d.ts} +1 -2
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +14 -14
- package/dist/rpc/bullmq/index.mjs +3 -3
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +2 -2
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +13 -13
- package/dist/rpc/nats/index.mjs +3 -3
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +15 -15
- package/dist/rpc/rabbitmq/index.mjs +3 -3
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +13 -13
- package/dist/rpc/redis/index.mjs +3 -3
- package/dist/test.d.mts +3 -3
- package/dist/test.d.ts +3 -3
- package/dist/test.js +6 -6
- package/dist/test.mjs +2 -2
- package/dist/{types-DEQb_e59.d.mts → types-B-rUM9Fm.d.mts} +1 -1
- package/dist/{types-PFPIQWVF.d.ts → types-CMeuFoyd.d.ts} +1 -1
- package/dist/{types-C2SQ9U9V.d.mts → types-DKVhyZk_.d.mts} +1 -1
- package/dist/{types-CYF0vha6.d.ts → types-MxxtkZXw.d.ts} +1 -1
- package/package.json +1 -1
- package/register/index.mjs +20 -11
- package/register/loader.mjs +12 -27
|
@@ -7,7 +7,6 @@ var IS_DEV = process.env.NODE_ENV === "development";
|
|
|
7
7
|
var IS_ONLY_GENERATE = !!process.env.PS_GENERATE;
|
|
8
8
|
var IS_STRICT = !!process.env.PS_STRICT;
|
|
9
9
|
var LOG_LEVEL = Number(process.env.PS_LOG_LEVEL || 0);
|
|
10
|
-
var IS_READY = Symbol("IS_READY");
|
|
11
10
|
var PS_EXIT_CODE = /* @__PURE__ */ function(PS_EXIT_CODE2) {
|
|
12
11
|
PS_EXIT_CODE2[PS_EXIT_CODE2["RELAUNCH"] = 2] = "RELAUNCH";
|
|
13
12
|
PS_EXIT_CODE2[PS_EXIT_CODE2["CODE"] = 4] = "CODE";
|
|
@@ -110,6 +109,27 @@ function runMiddleware(ctx, middleware) {
|
|
|
110
109
|
}
|
|
111
110
|
__name(runMiddleware, "runMiddleware");
|
|
112
111
|
|
|
112
|
+
// src/hmr.ts
|
|
113
|
+
function HMR(cb) {
|
|
114
|
+
if (IS_DEV) {
|
|
115
|
+
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
116
|
+
globalThis.__PS_HMR__.push(cb);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
__name(HMR, "HMR");
|
|
120
|
+
async function RELOAD(oldModels, newModels) {
|
|
121
|
+
log("reload module...");
|
|
122
|
+
for (const cb of globalThis.__PS_HMR__) await cb(oldModels, newModels);
|
|
123
|
+
log("reload done");
|
|
124
|
+
}
|
|
125
|
+
__name(RELOAD, "RELOAD");
|
|
126
|
+
function RELAUNCH() {
|
|
127
|
+
if (IS_DEV) process.exit(2);
|
|
128
|
+
}
|
|
129
|
+
__name(RELAUNCH, "RELAUNCH");
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
113
133
|
|
|
114
134
|
|
|
115
135
|
|
|
@@ -124,4 +144,4 @@ __name(runMiddleware, "runMiddleware");
|
|
|
124
144
|
|
|
125
145
|
|
|
126
146
|
|
|
127
|
-
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.
|
|
147
|
+
exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_DEV = IS_DEV; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin; exports.HMR = HMR; exports.RELOAD = RELOAD; exports.RELAUNCH = RELAUNCH;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
HMR,
|
|
3
3
|
IS_ONLY_GENERATE,
|
|
4
4
|
__name,
|
|
5
5
|
log
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FXTJ3BJ6.mjs";
|
|
7
7
|
|
|
8
8
|
// src/meta.ts
|
|
9
9
|
var Meta = class {
|
|
@@ -21,7 +21,7 @@ var Meta = class {
|
|
|
21
21
|
// src/core.ts
|
|
22
22
|
import "reflect-metadata";
|
|
23
23
|
import EventEmitter from "node:events";
|
|
24
|
-
import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount,
|
|
24
|
+
import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount, setInject } from "phecda-core";
|
|
25
25
|
import Debug from "debug";
|
|
26
26
|
var debug = Debug("phecda-server(Factory)");
|
|
27
27
|
var emitter = new EventEmitter();
|
|
@@ -61,63 +61,58 @@ var ServerPhecda = class {
|
|
|
61
61
|
}
|
|
62
62
|
async start(models) {
|
|
63
63
|
for (const model of models) await this.buildDepModule(model);
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return Promise.all(this.generators.map((generator) => {
|
|
67
|
-
debug(`generate "${generator.name}" code to ${generator.path}`);
|
|
68
|
-
return generator.output(this.meta);
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
}, "generateCode");
|
|
72
|
-
generateCode().then(() => {
|
|
64
|
+
this.hmr();
|
|
65
|
+
this.generateCode().then(() => {
|
|
73
66
|
if (IS_ONLY_GENERATE) process.exit(4);
|
|
74
67
|
});
|
|
75
|
-
if (IS_DEV) {
|
|
76
|
-
if (!globalThis.__PS_HMR__) globalThis.__PS_HMR__ = [];
|
|
77
|
-
globalThis.__PS_HMR__?.push(async (files) => {
|
|
78
|
-
debug("reload files ");
|
|
79
|
-
for (const file of files) {
|
|
80
|
-
const models2 = await import(file);
|
|
81
|
-
for (const i in models2) {
|
|
82
|
-
if (isPhecda(models2[i])) await this.add(models2[i]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
generateCode();
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async add(Model) {
|
|
90
|
-
const tag = getTag(Model);
|
|
91
|
-
const oldInstance = await this.del(tag);
|
|
92
|
-
const { module: newModule } = await this.buildDepModule(Model);
|
|
93
|
-
if (oldInstance && this.dependenceGraph.has(tag)) {
|
|
94
|
-
debug(`replace module "${String(tag)}"`);
|
|
95
|
-
[
|
|
96
|
-
...this.dependenceGraph.get(tag)
|
|
97
|
-
].forEach((tag2) => {
|
|
98
|
-
const module = this.moduleMap.get(tag2);
|
|
99
|
-
for (const key in module) {
|
|
100
|
-
if (module[key] === oldInstance) module[key] = newModule;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
68
|
}
|
|
105
|
-
async
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
69
|
+
generateCode = /* @__PURE__ */ __name(async () => {
|
|
70
|
+
return Promise.all(this.generators.map((generator) => {
|
|
71
|
+
debug(`generate "${generator.name}" code to ${generator.path}`);
|
|
72
|
+
return generator.output(this.meta);
|
|
73
|
+
}));
|
|
74
|
+
}, "generateCode");
|
|
75
|
+
hmr() {
|
|
76
|
+
HMR(async (oldModels, newModels) => {
|
|
77
|
+
debug("reload models ");
|
|
78
|
+
await this.replace(oldModels, newModels);
|
|
79
|
+
this.generateCode();
|
|
80
|
+
});
|
|
117
81
|
}
|
|
82
|
+
// async add(Model: Construct) {
|
|
83
|
+
// const tag = getTag(Model)
|
|
84
|
+
// const oldInstance = await this.del(tag)
|
|
85
|
+
// const { module: newModule } = await this.buildDepModule(Model)
|
|
86
|
+
// if (oldInstance && this.dependenceGraph.has(tag)) {
|
|
87
|
+
// debug(`replace module "${String(tag)}"`);
|
|
88
|
+
// [...this.dependenceGraph.get(tag)!].forEach((tag) => {
|
|
89
|
+
// const module = this.moduleMap.get(tag)
|
|
90
|
+
// for (const key in module) {
|
|
91
|
+
// if (module[key] === oldInstance)
|
|
92
|
+
// module[key] = newModule
|
|
93
|
+
// }
|
|
94
|
+
// })
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
// async del(modelOrTag: Construct | PropertyKey) {
|
|
98
|
+
// const tag = typeof modelOrTag === 'function' ? getTag(modelOrTag) : modelOrTag
|
|
99
|
+
// if (!this.moduleMap.has(tag))
|
|
100
|
+
// return
|
|
101
|
+
// const module = this.moduleMap.get(tag)
|
|
102
|
+
// debug(`unmount module "${String(tag)}"`)
|
|
103
|
+
// await invokeUnmount(module)
|
|
104
|
+
// debug(`del module "${String(tag)}"`)
|
|
105
|
+
// this.moduleMap.delete(tag)
|
|
106
|
+
// this.modelMap.delete(module)
|
|
107
|
+
// for (let i = this.meta.length - 1; i >= 0; i--) {
|
|
108
|
+
// if (this.meta[i].data.tag === tag)
|
|
109
|
+
// this.meta.splice(i, 1)
|
|
110
|
+
// }
|
|
111
|
+
// return module
|
|
112
|
+
// }
|
|
118
113
|
async destroy() {
|
|
119
114
|
debug("destroy all");
|
|
120
|
-
|
|
115
|
+
this.replace(Object.values(this.modelMap), []);
|
|
121
116
|
}
|
|
122
117
|
createProxyModule(tag) {
|
|
123
118
|
const that = this;
|
|
@@ -133,6 +128,9 @@ var ServerPhecda = class {
|
|
|
133
128
|
has(_target, prop) {
|
|
134
129
|
return Reflect.has(that.moduleMap.get(tag), prop);
|
|
135
130
|
},
|
|
131
|
+
ownKeys() {
|
|
132
|
+
return Reflect.ownKeys(that.moduleMap.get(tag));
|
|
133
|
+
},
|
|
136
134
|
getPrototypeOf() {
|
|
137
135
|
return Reflect.getPrototypeOf(that.moduleMap.get(tag));
|
|
138
136
|
},
|
|
@@ -189,6 +187,42 @@ var ServerPhecda = class {
|
|
|
189
187
|
tag
|
|
190
188
|
};
|
|
191
189
|
}
|
|
190
|
+
async replace(oldModels, newModels) {
|
|
191
|
+
const oldModules = (await Promise.all(oldModels.map(async (model) => {
|
|
192
|
+
const tag = getTag(model);
|
|
193
|
+
if (!this.has(tag)) return;
|
|
194
|
+
const module = this.moduleMap.get(tag);
|
|
195
|
+
debug(`unmount module "${String(tag)}"`);
|
|
196
|
+
await invokeUnmount(module);
|
|
197
|
+
debug(`del module "${String(tag)}"`);
|
|
198
|
+
this.moduleMap.delete(tag);
|
|
199
|
+
this.modelMap.delete(module);
|
|
200
|
+
for (let i = this.meta.length - 1; i >= 0; i--) {
|
|
201
|
+
if (this.meta[i].data.tag === tag) this.meta.splice(i, 1);
|
|
202
|
+
}
|
|
203
|
+
return module;
|
|
204
|
+
}))).filter((item) => item);
|
|
205
|
+
for (const model of newModels) {
|
|
206
|
+
debug(`mount module: ${model.name}`);
|
|
207
|
+
await this.buildDepModule(model);
|
|
208
|
+
}
|
|
209
|
+
debug("replace old modules");
|
|
210
|
+
for (const module of oldModules) {
|
|
211
|
+
const tag = getTag(module);
|
|
212
|
+
if (this.dependenceGraph.has(tag)) {
|
|
213
|
+
[
|
|
214
|
+
...this.dependenceGraph.get(tag)
|
|
215
|
+
].forEach((depTag) => {
|
|
216
|
+
const depModule = this.moduleMap.get(depTag);
|
|
217
|
+
if (depModule) {
|
|
218
|
+
for (const key in depModule) {
|
|
219
|
+
if (depModule[key] === module) depModule[key] = this.moduleMap.get(tag);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
192
226
|
has(modelOrTag) {
|
|
193
227
|
return this.moduleMap.has(typeof modelOrTag === "function" ? getTag(modelOrTag) : modelOrTag);
|
|
194
228
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ERROR_SYMBOL,
|
|
3
|
+
HMR,
|
|
3
4
|
IS_DEV,
|
|
4
5
|
IS_STRICT,
|
|
5
6
|
LOG_LEVEL,
|
|
6
7
|
__name,
|
|
7
8
|
log
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-FXTJ3BJ6.mjs";
|
|
9
10
|
|
|
10
11
|
// src/helper.ts
|
|
11
12
|
import pc2 from "picocolors";
|
|
@@ -377,32 +378,12 @@ function addAddon(key, addon, priority = 0) {
|
|
|
377
378
|
}
|
|
378
379
|
__name(addAddon, "addAddon");
|
|
379
380
|
|
|
380
|
-
// src/hmr.ts
|
|
381
|
-
function HMR(cb) {
|
|
382
|
-
if (IS_DEV) globalThis.__PS_HMR__?.push(cb);
|
|
383
|
-
}
|
|
384
|
-
__name(HMR, "HMR");
|
|
385
|
-
|
|
386
381
|
// src/http/helper.ts
|
|
387
382
|
function resolveDep(ret, key) {
|
|
388
383
|
if (key) return ret?.[key];
|
|
389
384
|
return ret;
|
|
390
385
|
}
|
|
391
386
|
__name(resolveDep, "resolveDep");
|
|
392
|
-
function argToReq(params, args, headers) {
|
|
393
|
-
const req = {
|
|
394
|
-
body: {},
|
|
395
|
-
query: {},
|
|
396
|
-
params: {},
|
|
397
|
-
headers
|
|
398
|
-
};
|
|
399
|
-
params.forEach((param) => {
|
|
400
|
-
if (param.key) req[param.type][param.key] = args[param.index];
|
|
401
|
-
else req[param.type] = args[param.index];
|
|
402
|
-
});
|
|
403
|
-
return req;
|
|
404
|
-
}
|
|
405
|
-
__name(argToReq, "argToReq");
|
|
406
387
|
|
|
407
388
|
// src/rpc/helper.ts
|
|
408
389
|
import { hostname } from "os";
|
|
@@ -552,9 +533,7 @@ export {
|
|
|
552
533
|
addFilter,
|
|
553
534
|
addGuard,
|
|
554
535
|
addAddon,
|
|
555
|
-
HMR,
|
|
556
536
|
resolveDep,
|
|
557
|
-
argToReq,
|
|
558
537
|
genClientQueue,
|
|
559
538
|
shallowClone,
|
|
560
539
|
mergeObject,
|