phecda-server 6.0.2 → 7.0.0-alpha.0
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/bin/cli.mjs +160 -157
- package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
- package/dist/chunk-BGXSMOLX.js +265 -0
- package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
- package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
- package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
- package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
- package/dist/chunk-SW5IKE5H.js +503 -0
- package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
- package/dist/core-BIcUwV18.d.mts +47 -0
- package/dist/core-CYwEPfN4.d.ts +47 -0
- package/dist/helper.d.mts +4 -6
- package/dist/helper.d.ts +4 -6
- package/dist/helper.js +3 -3
- package/dist/helper.mjs +2 -2
- package/dist/{server → http}/elysia/index.d.mts +5 -5
- package/dist/{server → http}/elysia/index.d.ts +5 -5
- package/dist/{server → http}/elysia/index.js +80 -62
- package/dist/{server → http}/elysia/index.mjs +50 -32
- package/dist/{server → http}/express/index.d.mts +5 -5
- package/dist/{server → http}/express/index.d.ts +5 -5
- package/dist/{server → http}/express/index.js +71 -55
- package/dist/{server → http}/express/index.mjs +42 -26
- package/dist/{server → http}/fastify/index.d.mts +5 -5
- package/dist/{server → http}/fastify/index.d.ts +5 -5
- package/dist/{server → http}/fastify/index.js +72 -72
- package/dist/{server → http}/fastify/index.mjs +47 -47
- package/dist/{server → http}/h3/index.d.mts +5 -5
- package/dist/{server → http}/h3/index.d.ts +5 -5
- package/dist/http/h3/index.js +160 -0
- package/dist/{server → http}/h3/index.mjs +68 -62
- package/dist/{server → http}/hono/index.d.mts +5 -5
- package/dist/{server → http}/hono/index.d.ts +5 -5
- package/dist/{server → http}/hono/index.js +69 -54
- package/dist/{server → http}/hono/index.mjs +41 -26
- package/dist/{server → http}/hyper-express/index.d.mts +5 -5
- package/dist/{server → http}/hyper-express/index.d.ts +5 -5
- package/dist/{server → http}/hyper-express/index.js +69 -56
- package/dist/{server → http}/hyper-express/index.mjs +41 -28
- package/dist/{server → http}/koa/index.d.mts +5 -5
- package/dist/{server → http}/koa/index.d.ts +5 -5
- package/dist/{server → http}/koa/index.js +71 -55
- package/dist/{server → http}/koa/index.mjs +42 -26
- package/dist/index.d.mts +53 -41
- package/dist/index.d.ts +53 -41
- package/dist/index.js +62 -78
- package/dist/index.mjs +46 -62
- package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
- package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
- package/dist/rpc/bullmq/index.d.mts +6 -6
- package/dist/rpc/bullmq/index.d.ts +6 -6
- package/dist/rpc/bullmq/index.js +24 -24
- package/dist/rpc/bullmq/index.mjs +14 -14
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +25 -21
- package/dist/rpc/kafka/index.mjs +15 -11
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +22 -21
- package/dist/rpc/nats/index.mjs +13 -12
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +23 -22
- package/dist/rpc/rabbitmq/index.mjs +12 -11
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +24 -20
- package/dist/rpc/redis/index.mjs +15 -11
- 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-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
- package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
- package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
- package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
- package/package.json +24 -24
- package/dist/chunk-7SYPUIBY.js +0 -539
- package/dist/chunk-LYEZ6RGX.js +0 -237
- package/dist/core-2SNw8m2B.d.mts +0 -30
- package/dist/core-BmJJLUqj.d.ts +0 -30
- package/dist/server/h3/index.js +0 -154
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ERROR_SYMBOL,
|
|
3
3
|
IS_HMR,
|
|
4
|
-
IS_STRICT,
|
|
5
4
|
LOG_LEVEL,
|
|
6
5
|
__name,
|
|
7
6
|
log
|
|
8
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-WHJ5FALK.mjs";
|
|
9
8
|
|
|
10
9
|
// src/helper.ts
|
|
11
10
|
import pc from "picocolors";
|
|
@@ -228,143 +227,120 @@ var Context = class _Context {
|
|
|
228
227
|
default: defaultPipe
|
|
229
228
|
};
|
|
230
229
|
static guardRecord = {};
|
|
231
|
-
static
|
|
232
|
-
static pluginRecord = {};
|
|
233
|
-
postInterceptors;
|
|
230
|
+
static addonRecord = {};
|
|
234
231
|
constructor(data) {
|
|
235
232
|
this.data = data;
|
|
236
233
|
if (IS_HMR)
|
|
237
234
|
data._context = this;
|
|
238
235
|
}
|
|
239
|
-
|
|
240
|
-
const {
|
|
241
|
-
const {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
await this.useGuard([
|
|
236
|
+
static getAop(meta, opts) {
|
|
237
|
+
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
238
|
+
const { data: { guards, filter, params } } = meta;
|
|
239
|
+
return {
|
|
240
|
+
guards: this.getGuards([
|
|
245
241
|
...globalGuards,
|
|
246
242
|
...guards
|
|
247
|
-
])
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
243
|
+
]),
|
|
244
|
+
pipe: this.getPipe(params.map((item) => item.pipe || globalPipe)),
|
|
245
|
+
filter: this.getFilter(filter || globalFilter)
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
249
|
+
const { meta, moduleMap } = this.data;
|
|
250
|
+
const { paramsType, data: { ctxs, tag, params, func } } = meta;
|
|
251
|
+
try {
|
|
252
|
+
let res;
|
|
253
|
+
const nextHandler = /* @__PURE__ */ __name((index) => {
|
|
254
|
+
return async () => {
|
|
255
|
+
if (index === guards.length) {
|
|
256
|
+
const instance = moduleMap.get(tag);
|
|
257
|
+
if (ctxs) {
|
|
258
|
+
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
259
|
+
}
|
|
260
|
+
const args = await Promise.all(params.map((item, i) => pipe[i]({
|
|
261
|
+
arg: resolveDep(this.data[item.type], item.key),
|
|
262
|
+
reflect: paramsType[item.index],
|
|
263
|
+
...item
|
|
264
|
+
}, this.data)));
|
|
265
|
+
res = await instance[func](...args);
|
|
266
|
+
} else {
|
|
267
|
+
let nextPromise;
|
|
268
|
+
async function next() {
|
|
269
|
+
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
270
|
+
if (ret2 !== void 0) {
|
|
271
|
+
debug(`The ${index + 1}th guard rewrite the response value.`);
|
|
272
|
+
res = ret2;
|
|
273
|
+
}
|
|
274
|
+
return res;
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
__name(next, "next");
|
|
278
|
+
const ret = await guards[index](this.data, next);
|
|
279
|
+
if (ret !== void 0) {
|
|
280
|
+
res = ret;
|
|
281
|
+
} else {
|
|
282
|
+
if (!nextPromise) await next();
|
|
283
|
+
else await nextPromise;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
259
286
|
};
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
ctxs.forEach((ctx) => instance[ctx] = this.data);
|
|
264
|
-
}
|
|
265
|
-
const returnData = await instance[func](...args);
|
|
266
|
-
const i2 = await this.usePostInterceptor(returnData);
|
|
267
|
-
if (i2 !== void 0) return successCb(i2);
|
|
268
|
-
return successCb(returnData);
|
|
287
|
+
}, "nextHandler");
|
|
288
|
+
await nextHandler(0)();
|
|
289
|
+
return successCb(res);
|
|
269
290
|
} catch (e) {
|
|
270
|
-
const err = await
|
|
291
|
+
const err = await filter(e, this.data);
|
|
271
292
|
return failCb(err);
|
|
272
293
|
}
|
|
273
294
|
}
|
|
274
|
-
|
|
275
|
-
return
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
|
|
279
|
-
} else {
|
|
280
|
-
debug(`Can't find pipe named "${item.pipe}" when handling the ${item.index + 1}th argument of the func "${this.data.func}" on module "${this.data.tag}",use default pipe instead`);
|
|
281
|
-
return _Context.pipeRecord.default(item, this.data);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return _Context.pipeRecord[item.pipe || "default"](item, this.data);
|
|
285
|
-
}));
|
|
286
|
-
}
|
|
287
|
-
useFilter(arg, filter = "default") {
|
|
288
|
-
if (!_Context.filterRecord[filter]) {
|
|
289
|
-
if (IS_STRICT) {
|
|
290
|
-
throw new FrameworkException(`can't find filter named "${filter}"`);
|
|
291
|
-
} else {
|
|
292
|
-
debug(`Can't find filter named "${filter}" when handling func "${this.data.func}" on module "${this.data.tag}",use default filter instead`);
|
|
293
|
-
return _Context.filterRecord.default(arg, this.data);
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
return _Context.filterRecord[filter](arg, this.data);
|
|
297
|
-
}
|
|
298
|
-
async useGuard(guards) {
|
|
299
|
-
for (const guard of new Set(guards)) {
|
|
300
|
-
if (!(guard in _Context.guardRecord)) {
|
|
301
|
-
if (IS_STRICT) throw new FrameworkException(`Can't find guard named "${guard}"`);
|
|
302
|
-
else debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
303
|
-
continue;
|
|
304
|
-
}
|
|
305
|
-
if (!await _Context.guardRecord[guard](this.data)) throw new ForbiddenException(`Guard exception--[${guard}]`);
|
|
306
|
-
}
|
|
295
|
+
static getPipe(pipe) {
|
|
296
|
+
return pipe.map((pipe2) => {
|
|
297
|
+
return _Context.pipeRecord[pipe2] || _Context.pipeRecord.default;
|
|
298
|
+
});
|
|
307
299
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const ret = await cb(data);
|
|
311
|
-
if (ret !== void 0) return ret;
|
|
312
|
-
}
|
|
300
|
+
static getFilter(filter = "default") {
|
|
301
|
+
return _Context.filterRecord[filter] || _Context.filterRecord.default;
|
|
313
302
|
}
|
|
314
|
-
|
|
315
|
-
const
|
|
316
|
-
for (const
|
|
317
|
-
if (
|
|
318
|
-
if (IS_STRICT) throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
|
|
319
|
-
else debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
|
-
const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
|
|
323
|
-
if (interceptRet !== void 0) {
|
|
324
|
-
if (typeof interceptRet === "function") cb.push(interceptRet);
|
|
325
|
-
else return interceptRet;
|
|
326
|
-
}
|
|
303
|
+
static getGuards(guards) {
|
|
304
|
+
const ret = [];
|
|
305
|
+
for (const guard of new Set(guards)) {
|
|
306
|
+
if (guard in _Context.guardRecord) ret.push(_Context.guardRecord[guard]);
|
|
327
307
|
}
|
|
328
|
-
|
|
308
|
+
return ret.sort((a, b) => b.priority - a.priority).map((item) => item.value);
|
|
329
309
|
}
|
|
330
|
-
static
|
|
310
|
+
static applyAddons(addons, router, framework) {
|
|
331
311
|
const ret = [];
|
|
332
|
-
for (const
|
|
333
|
-
if (
|
|
334
|
-
if (IS_STRICT) throw new FrameworkException(`can't find middleware named '${m}'`);
|
|
335
|
-
continue;
|
|
336
|
-
}
|
|
337
|
-
const plugin = _Context.pluginRecord[m](framework);
|
|
338
|
-
plugin && ret.push(plugin);
|
|
312
|
+
for (const a of new Set(addons)) {
|
|
313
|
+
if (a in _Context.addonRecord) ret.push(_Context.addonRecord[a]);
|
|
339
314
|
}
|
|
340
|
-
|
|
315
|
+
ret.sort((a, b) => b.priority - a.priority).forEach((item) => item.value(router, framework));
|
|
341
316
|
}
|
|
342
317
|
};
|
|
343
|
-
function
|
|
344
|
-
if (Context.
|
|
345
|
-
Context.
|
|
346
|
-
}
|
|
347
|
-
__name(addPlugin, "addPlugin");
|
|
348
|
-
function addPipe(key, handler) {
|
|
349
|
-
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler) log(`overwrite Pipe "${String(key)}"`, "warn");
|
|
350
|
-
Context.pipeRecord[key] = handler;
|
|
318
|
+
function addPipe(key, pipe) {
|
|
319
|
+
if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) log(`overwrite Pipe "${String(key)}"`, "warn");
|
|
320
|
+
Context.pipeRecord[key] = pipe;
|
|
351
321
|
}
|
|
352
322
|
__name(addPipe, "addPipe");
|
|
353
|
-
function addFilter(key,
|
|
354
|
-
if (Context.filterRecord[key] && Context.filterRecord[key] !==
|
|
355
|
-
Context.filterRecord[key] =
|
|
323
|
+
function addFilter(key, filter) {
|
|
324
|
+
if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) log(`overwrite Filter "${String(key)}"`, "warn");
|
|
325
|
+
Context.filterRecord[key] = filter;
|
|
356
326
|
}
|
|
357
327
|
__name(addFilter, "addFilter");
|
|
358
|
-
function addGuard(key,
|
|
359
|
-
if (Context.guardRecord[key] && Context.guardRecord[key] !==
|
|
360
|
-
Context.guardRecord[key] =
|
|
328
|
+
function addGuard(key, guard, priority = 0) {
|
|
329
|
+
if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) log(`overwrite Guard "${String(key)}"`, "warn");
|
|
330
|
+
Context.guardRecord[key] = {
|
|
331
|
+
value: guard,
|
|
332
|
+
priority
|
|
333
|
+
};
|
|
361
334
|
}
|
|
362
335
|
__name(addGuard, "addGuard");
|
|
363
|
-
function
|
|
364
|
-
if (Context.
|
|
365
|
-
Context.
|
|
336
|
+
function addAddon(key, addon, priority = 0) {
|
|
337
|
+
if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) log(`overwrite Addon "${String(key)}"`, "warn");
|
|
338
|
+
Context.addonRecord[key] = {
|
|
339
|
+
value: addon,
|
|
340
|
+
priority
|
|
341
|
+
};
|
|
366
342
|
}
|
|
367
|
-
__name(
|
|
343
|
+
__name(addAddon, "addAddon");
|
|
368
344
|
|
|
369
345
|
// src/hmr.ts
|
|
370
346
|
function HMR(cb) {
|
|
@@ -372,7 +348,7 @@ function HMR(cb) {
|
|
|
372
348
|
}
|
|
373
349
|
__name(HMR, "HMR");
|
|
374
350
|
|
|
375
|
-
// src/
|
|
351
|
+
// src/http/helper.ts
|
|
376
352
|
function resolveDep(ret, key) {
|
|
377
353
|
if (key) return ret?.[key];
|
|
378
354
|
return ret;
|
|
@@ -432,60 +408,50 @@ function createControllerMetaMap(meta, filter) {
|
|
|
432
408
|
return metaMap;
|
|
433
409
|
}
|
|
434
410
|
__name(createControllerMetaMap, "createControllerMetaMap");
|
|
435
|
-
function detectAopDep(meta, { guards,
|
|
436
|
-
const
|
|
411
|
+
function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
|
|
412
|
+
const addonSet = /* @__PURE__ */ new Set();
|
|
437
413
|
const guardSet = /* @__PURE__ */ new Set();
|
|
438
|
-
const interceptorSet = /* @__PURE__ */ new Set();
|
|
439
414
|
const pipeSet = /* @__PURE__ */ new Set();
|
|
440
415
|
const filterSet = /* @__PURE__ */ new Set();
|
|
441
416
|
const warningSet = /* @__PURE__ */ new Set();
|
|
442
417
|
function handleMeta() {
|
|
443
|
-
|
|
418
|
+
addonSet.clear();
|
|
444
419
|
guardSet.clear();
|
|
445
|
-
interceptorSet.clear();
|
|
446
420
|
pipeSet.clear();
|
|
447
421
|
filterSet.clear();
|
|
448
422
|
warningSet.clear();
|
|
449
|
-
|
|
450
|
-
|
|
423
|
+
addons?.forEach((item) => {
|
|
424
|
+
addonSet.add(item);
|
|
451
425
|
});
|
|
452
426
|
guards?.forEach((item) => {
|
|
453
427
|
guardSet.add(item);
|
|
454
428
|
});
|
|
455
|
-
interceptors?.forEach((item) => {
|
|
456
|
-
interceptorSet.add(item);
|
|
457
|
-
});
|
|
458
429
|
meta.forEach(({ data }) => {
|
|
459
430
|
if (data.controller !== controller) {
|
|
460
431
|
if (data[controller]) warningSet.add(`Module "${data.tag === data.name ? data.name : `${data.name}(${data.tag})`}" should use ${controller} controller to decorate class or remove ${controller} decorator on method "${data.func}"`);
|
|
461
432
|
return;
|
|
462
433
|
}
|
|
463
434
|
if (data.filter) filterSet.add(data.filter);
|
|
464
|
-
data.interceptors.forEach((i) => interceptorSet.add(i));
|
|
465
435
|
data.guards.forEach((i) => guardSet.add(i));
|
|
466
|
-
data.
|
|
436
|
+
data.addons.forEach((i) => addonSet.add(i));
|
|
467
437
|
data.params.forEach((i) => {
|
|
468
438
|
if (i.pipe) pipeSet.add(i.pipe);
|
|
469
439
|
});
|
|
470
440
|
});
|
|
471
|
-
const
|
|
472
|
-
...
|
|
473
|
-
].filter((i) => !Context.
|
|
441
|
+
const missAddons = [
|
|
442
|
+
...addonSet
|
|
443
|
+
].filter((i) => !Context.addonRecord[i]);
|
|
474
444
|
const missGuards = [
|
|
475
445
|
...guardSet
|
|
476
446
|
].filter((i) => !Context.guardRecord[i]);
|
|
477
|
-
const missInterceptors = [
|
|
478
|
-
...interceptorSet
|
|
479
|
-
].filter((i) => !Context.interceptorRecord[i]);
|
|
480
447
|
const missPipes = [
|
|
481
448
|
...pipeSet
|
|
482
449
|
].filter((i) => !Context.pipeRecord[i]);
|
|
483
450
|
const missFilters = [
|
|
484
451
|
...filterSet
|
|
485
452
|
].filter((i) => !Context.filterRecord[i]);
|
|
486
|
-
if (
|
|
453
|
+
if (missAddons.length) log(`${pc.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
|
|
487
454
|
if (missGuards.length) log(`${pc.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
|
|
488
|
-
if (missInterceptors.length) log(`${pc.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
|
|
489
455
|
if (missPipes.length) log(`${pc.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
|
|
490
456
|
if (missFilters.length) log(`${pc.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
|
|
491
457
|
warningSet.forEach((warn) => log(warn, "warn"));
|
|
@@ -494,9 +460,8 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
|
|
|
494
460
|
handleMeta();
|
|
495
461
|
HMR(handleMeta);
|
|
496
462
|
return {
|
|
497
|
-
|
|
463
|
+
addonSet,
|
|
498
464
|
guardSet,
|
|
499
|
-
interceptorSet,
|
|
500
465
|
pipeSet,
|
|
501
466
|
filterSet
|
|
502
467
|
};
|
|
@@ -523,11 +488,10 @@ export {
|
|
|
523
488
|
TimerException,
|
|
524
489
|
WorkerException,
|
|
525
490
|
Context,
|
|
526
|
-
addPlugin,
|
|
527
491
|
addPipe,
|
|
528
492
|
addFilter,
|
|
529
493
|
addGuard,
|
|
530
|
-
|
|
494
|
+
addAddon,
|
|
531
495
|
HMR,
|
|
532
496
|
resolveDep,
|
|
533
497
|
argToReq,
|