phecda-server 6.1.0 → 7.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/assets/ps.json +24 -24
  2. package/bin/cli.mjs +165 -157
  3. package/dist/{chunk-NL6QBQAR.js → chunk-7YQ57BQS.js} +21 -22
  4. package/dist/chunk-GSPBHZBH.js +534 -0
  5. package/dist/{chunk-J7B24YSE.mjs → chunk-HMVLXNV3.mjs} +5 -14
  6. package/dist/{chunk-TVT62GIX.js → chunk-J5CFUN4V.js} +8 -1
  7. package/dist/{chunk-JDV2XJYE.js → chunk-MBCHNDAY.js} +27 -36
  8. package/dist/{chunk-2CFYUXPM.mjs → chunk-V7EI76QQ.mjs} +136 -141
  9. package/dist/{chunk-G7TD2VB7.mjs → chunk-WHJ5FALK.mjs} +7 -0
  10. package/dist/{chunk-3H3T54IC.mjs → chunk-XYVMNY2X.mjs} +4 -5
  11. package/dist/{core-P1CsH6jz.d.mts → core-BIcUwV18.d.mts} +1 -1
  12. package/dist/{core-BlN0Spy9.d.ts → core-CYwEPfN4.d.ts} +1 -1
  13. package/dist/helper.d.mts +4 -6
  14. package/dist/helper.d.ts +4 -6
  15. package/dist/helper.js +3 -3
  16. package/dist/helper.mjs +2 -2
  17. package/dist/{server → http}/elysia/index.d.mts +5 -5
  18. package/dist/{server → http}/elysia/index.d.ts +5 -5
  19. package/dist/{server → http}/elysia/index.js +80 -62
  20. package/dist/{server → http}/elysia/index.mjs +50 -32
  21. package/dist/{server → http}/express/index.d.mts +5 -5
  22. package/dist/{server → http}/express/index.d.ts +5 -5
  23. package/dist/{server → http}/express/index.js +71 -55
  24. package/dist/{server → http}/express/index.mjs +42 -26
  25. package/dist/{server → http}/fastify/index.d.mts +5 -5
  26. package/dist/{server → http}/fastify/index.d.ts +5 -5
  27. package/dist/{server → http}/fastify/index.js +72 -72
  28. package/dist/{server → http}/fastify/index.mjs +47 -47
  29. package/dist/{server → http}/h3/index.d.mts +5 -5
  30. package/dist/{server → http}/h3/index.d.ts +5 -5
  31. package/dist/http/h3/index.js +160 -0
  32. package/dist/{server → http}/h3/index.mjs +68 -62
  33. package/dist/{server → http}/hono/index.d.mts +5 -5
  34. package/dist/{server → http}/hono/index.d.ts +5 -5
  35. package/dist/{server → http}/hono/index.js +69 -54
  36. package/dist/{server → http}/hono/index.mjs +41 -26
  37. package/dist/{server → http}/hyper-express/index.d.mts +5 -5
  38. package/dist/{server → http}/hyper-express/index.d.ts +5 -5
  39. package/dist/{server → http}/hyper-express/index.js +69 -56
  40. package/dist/{server → http}/hyper-express/index.mjs +41 -28
  41. package/dist/{server → http}/koa/index.d.mts +5 -5
  42. package/dist/{server → http}/koa/index.d.ts +5 -5
  43. package/dist/{server → http}/koa/index.js +71 -55
  44. package/dist/{server → http}/koa/index.mjs +42 -26
  45. package/dist/index.d.mts +52 -41
  46. package/dist/index.d.ts +52 -41
  47. package/dist/index.js +59 -81
  48. package/dist/index.mjs +39 -61
  49. package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
  50. package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
  51. package/dist/rpc/bullmq/index.d.mts +6 -6
  52. package/dist/rpc/bullmq/index.d.ts +6 -6
  53. package/dist/rpc/bullmq/index.js +24 -24
  54. package/dist/rpc/bullmq/index.mjs +14 -14
  55. package/dist/rpc/kafka/index.d.mts +3 -3
  56. package/dist/rpc/kafka/index.d.ts +3 -3
  57. package/dist/rpc/kafka/index.js +25 -21
  58. package/dist/rpc/kafka/index.mjs +15 -11
  59. package/dist/rpc/nats/index.d.mts +3 -3
  60. package/dist/rpc/nats/index.d.ts +3 -3
  61. package/dist/rpc/nats/index.js +22 -21
  62. package/dist/rpc/nats/index.mjs +13 -12
  63. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  64. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  65. package/dist/rpc/rabbitmq/index.js +23 -22
  66. package/dist/rpc/rabbitmq/index.mjs +12 -11
  67. package/dist/rpc/redis/index.d.mts +3 -3
  68. package/dist/rpc/redis/index.d.ts +3 -3
  69. package/dist/rpc/redis/index.js +24 -20
  70. package/dist/rpc/redis/index.mjs +15 -11
  71. package/dist/test.d.mts +3 -3
  72. package/dist/test.d.ts +3 -3
  73. package/dist/test.js +6 -6
  74. package/dist/test.mjs +2 -2
  75. package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
  76. package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
  77. package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
  78. package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
  79. package/package.json +23 -23
  80. package/register/loader.mjs +366 -367
  81. package/dist/chunk-DVTBLV6I.js +0 -539
  82. package/dist/server/h3/index.js +0 -154
package/dist/helper.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-KtfiBIde.js';
1
+ import { C as ControllerMetaData, M as Meta, a as ControllerMeta } from './meta-BXKLFTgG.js';
2
2
  import 'phecda-core';
3
3
 
4
4
  declare function HMR(cb: (...args: any) => any): void;
@@ -12,14 +12,12 @@ declare function shallowClone(obj: any): any;
12
12
  declare function mergeObject(...args: any[]): any;
13
13
 
14
14
  declare function createControllerMetaMap(meta: Meta[], filter: (meta: Meta) => boolean | void): Map<string, Record<string, ControllerMeta>>;
15
- declare function detectAopDep(meta: Meta[], { guards, interceptors, plugins }?: {
15
+ declare function detectAopDep(meta: Meta[], { guards, addons }?: {
16
16
  guards?: string[];
17
- interceptors?: string[];
18
- plugins?: string[];
17
+ addons?: string[];
19
18
  }, controller?: string): {
20
- pluginSet: Set<string>;
19
+ addonSet: Set<string>;
21
20
  guardSet: Set<string>;
22
- interceptorSet: Set<string>;
23
21
  pipeSet: Set<string>;
24
22
  filterSet: Set<string>;
25
23
  };
package/dist/helper.js CHANGED
@@ -7,8 +7,8 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkDVTBLV6Ijs = require('./chunk-DVTBLV6I.js');
11
- require('./chunk-TVT62GIX.js');
10
+ var _chunkGSPBHZBHjs = require('./chunk-GSPBHZBH.js');
11
+ require('./chunk-J5CFUN4V.js');
12
12
 
13
13
 
14
14
 
@@ -18,4 +18,4 @@ require('./chunk-TVT62GIX.js');
18
18
 
19
19
 
20
20
 
21
- exports.HMR = _chunkDVTBLV6Ijs.HMR; exports.argToReq = _chunkDVTBLV6Ijs.argToReq; exports.createControllerMetaMap = _chunkDVTBLV6Ijs.createControllerMetaMap; exports.detectAopDep = _chunkDVTBLV6Ijs.detectAopDep; exports.genClientQueue = _chunkDVTBLV6Ijs.genClientQueue; exports.mergeObject = _chunkDVTBLV6Ijs.mergeObject; exports.resolveDep = _chunkDVTBLV6Ijs.resolveDep; exports.shallowClone = _chunkDVTBLV6Ijs.shallowClone;
21
+ exports.HMR = _chunkGSPBHZBHjs.HMR; exports.argToReq = _chunkGSPBHZBHjs.argToReq; exports.createControllerMetaMap = _chunkGSPBHZBHjs.createControllerMetaMap; exports.detectAopDep = _chunkGSPBHZBHjs.detectAopDep; exports.genClientQueue = _chunkGSPBHZBHjs.genClientQueue; exports.mergeObject = _chunkGSPBHZBHjs.mergeObject; exports.resolveDep = _chunkGSPBHZBHjs.resolveDep; exports.shallowClone = _chunkGSPBHZBHjs.shallowClone;
package/dist/helper.mjs CHANGED
@@ -7,8 +7,8 @@ import {
7
7
  mergeObject,
8
8
  resolveDep,
9
9
  shallowClone
10
- } from "./chunk-2CFYUXPM.mjs";
11
- import "./chunk-G7TD2VB7.mjs";
10
+ } from "./chunk-V7EI76QQ.mjs";
11
+ import "./chunk-WHJ5FALK.mjs";
12
12
  export {
13
13
  HMR,
14
14
  argToReq,
@@ -1,9 +1,9 @@
1
1
  import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
2
2
  import { BaseMacro } from 'elysia/dist/types';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-BvD3B5Ny.mjs';
4
- import { F as Factory } from '../../core-P1CsH6jz.mjs';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-h40T3cRG.mjs';
4
+ import { F as Factory } from '../../core-BIcUwV18.mjs';
5
5
  import 'node:http';
6
- import '../../meta-KtfiBIde.mjs';
6
+ import '../../meta-BXKLFTgG.mjs';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface ElysiaCtx extends HttpContext {
@@ -11,8 +11,8 @@ interface ElysiaCtx extends HttpContext {
11
11
  app: Elysia$1;
12
12
  context: Context;
13
13
  }
14
- type Plugin = (app: Elysia$1<any>) => void;
14
+ type Addon = (app: Elysia$1<any>) => void;
15
15
  declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
16
16
  declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
17
17
 
18
- export { Elysia, type ElysiaCtx, type Plugin, bind };
18
+ export { type Addon, Elysia, type ElysiaCtx, bind };
@@ -1,9 +1,9 @@
1
1
  import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
2
2
  import { BaseMacro } from 'elysia/dist/types';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-DIw7B6Up.js';
4
- import { F as Factory } from '../../core-BlN0Spy9.js';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-VFzEM7LL.js';
4
+ import { F as Factory } from '../../core-CYwEPfN4.js';
5
5
  import 'node:http';
6
- import '../../meta-KtfiBIde.js';
6
+ import '../../meta-BXKLFTgG.js';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface ElysiaCtx extends HttpContext {
@@ -11,8 +11,8 @@ interface ElysiaCtx extends HttpContext {
11
11
  app: Elysia$1;
12
12
  context: Context;
13
13
  }
14
- type Plugin = (app: Elysia$1<any>) => void;
14
+ type Addon = (app: Elysia$1<any>) => void;
15
15
  declare function bind(app: Elysia$1<any>, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
16
16
  declare function Elysia(opts: LocalHook<InputSchema, RouteSchema, SingletonBase, Record<string, Error>, BaseMacro>): any;
17
17
 
18
- export { Elysia, type ElysiaCtx, type Plugin, bind };
18
+ export { type Addon, Elysia, type ElysiaCtx, bind };
@@ -1,63 +1,67 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkJDV2XJYEjs = require('../../chunk-JDV2XJYE.js');
3
+ var _chunkMBCHNDAYjs = require('../../chunk-MBCHNDAY.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunkDVTBLV6Ijs = require('../../chunk-DVTBLV6I.js');
10
+ var _chunkGSPBHZBHjs = require('../../chunk-GSPBHZBH.js');
11
11
 
12
12
 
13
- var _chunkTVT62GIXjs = require('../../chunk-TVT62GIX.js');
13
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
14
14
 
15
- // src/server/elysia/bind.ts
15
+ // src/http/elysia/bind.ts
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
  var _elysia = require('elysia');
18
18
  var debug = _debug2.default.call(void 0, "phecda-server/elysia");
19
19
  function bind(app, data, opts = {}) {
20
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
20
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
21
21
  const { moduleMap, meta } = data;
22
- const metaMap = _chunkDVTBLV6Ijs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
+ const metaMap = _chunkGSPBHZBHjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
23
23
  const { controller, http, func, tag } = meta2.data;
24
24
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
25
25
  debug(`register method "${func}" in module "${tag}"`);
26
26
  return true;
27
27
  }
28
28
  });
29
- _chunkDVTBLV6Ijs.detectAopDep.call(void 0, meta, {
30
- plugins: [
31
- ...globalPlugins,
32
- ...parallelPlugins
29
+ _chunkGSPBHZBHjs.detectAopDep.call(void 0, meta, {
30
+ addons: [
31
+ ...globalAddons,
32
+ ...parallelAddons
33
33
  ],
34
- guards: globalGuards,
35
- interceptors: globalInterceptors
34
+ guards: globalGuards
36
35
  });
37
36
  registerRoute();
38
- async function registerRoute() {
39
- _chunkDVTBLV6Ijs.Context.usePlugin(globalPlugins, "elysia").forEach((p) => p(app));
40
- const parallelRouter = new (0, _elysia.Elysia)();
41
- _chunkDVTBLV6Ijs.Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
37
+ function registerRoute() {
38
+ _chunkGSPBHZBHjs.Context.applyAddons(globalAddons, app, "elysia");
42
39
  if (parallelRoute) {
40
+ const parallelRouter = new (0, _elysia.Elysia)();
41
+ _chunkGSPBHZBHjs.Context.applyAddons(parallelAddons, app, "elysia");
43
42
  parallelRouter.post(parallelRoute, async (c) => {
44
43
  const { body } = c;
45
44
  async function errorHandler(e) {
46
- const error = await _chunkDVTBLV6Ijs.Context.filterRecord.default(e);
45
+ const error = await _chunkGSPBHZBHjs.Context.filterRecord.default(e);
47
46
  c.set.status = error.status;
48
47
  return error;
49
48
  }
50
- _chunkTVT62GIXjs.__name.call(void 0, errorHandler, "errorHandler");
51
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkDVTBLV6Ijs.BadRequestException)("data format should be an array"));
49
+ _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
50
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkGSPBHZBHjs.BadRequestException)("data format should be an array"));
52
51
  try {
53
52
  return Promise.all(body.map((item, i) => {
54
53
  return new Promise(async (resolve) => {
55
54
  const { tag, func } = item;
56
55
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
57
- if (!metaMap.has(tag)) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`module "${tag}" doesn't exist`)));
56
+ if (!metaMap.has(tag)) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
57
  const meta2 = metaMap.get(tag)[func];
59
- if (!meta2) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
58
+ if (!meta2) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
59
  const { data: { params } } = meta2;
60
+ const aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
61
+ globalGuards,
62
+ globalFilter,
63
+ globalPipe
64
+ });
61
65
  const contextData = {
62
66
  type: "elysia",
63
67
  parallel: true,
@@ -68,30 +72,25 @@ function bind(app, data, opts = {}) {
68
72
  tag,
69
73
  func,
70
74
  app,
71
- ..._chunkDVTBLV6Ijs.argToReq.call(void 0, params, item.args, c.headers),
72
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
73
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
75
+ ..._chunkGSPBHZBHjs.argToReq.call(void 0, params, item.args, c.headers),
76
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
77
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
74
78
  ...opts2,
75
79
  value
76
80
  }), "setCookie"),
77
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
78
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
79
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
80
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
81
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => {
81
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
82
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
83
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
84
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
85
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
82
86
  throw new Error("elysia can't support getRequest");
83
87
  }, "getRequest"),
84
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => {
88
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
85
89
  throw new Error("elysia can't support getResponse");
86
90
  }, "getResponse")
87
91
  };
88
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
89
- context.run({
90
- globalGuards,
91
- globalInterceptors,
92
- globalFilter,
93
- globalPipe
94
- }, resolve, resolve);
92
+ const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
93
+ context.run(aop, resolve, resolve);
95
94
  });
96
95
  })).then((ret) => {
97
96
  return ret;
@@ -100,16 +99,26 @@ function bind(app, data, opts = {}) {
100
99
  return errorHandler(e);
101
100
  }
102
101
  });
102
+ app.use(parallelRouter);
103
103
  }
104
- app.use(parallelRouter);
105
104
  for (const [tag, record] of metaMap) {
106
105
  for (const func in record) {
107
106
  const meta2 = metaMap.get(tag)[func];
108
- const { data: { define, plugins, http } } = meta2;
109
- const funcRouter = new (0, _elysia.Elysia)();
107
+ const { data: { define, addons, http } } = meta2;
108
+ const subApp = new (0, _elysia.Elysia)({
109
+ prefix: ""
110
+ });
110
111
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
111
- _chunkDVTBLV6Ijs.Context.usePlugin(plugins, "elysia").forEach((p) => p(funcRouter));
112
- funcRouter[http.type](http.prefix + http.route, async (c) => {
112
+ let aop;
113
+ if (!dynamic) {
114
+ aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
115
+ globalFilter,
116
+ globalGuards,
117
+ globalPipe
118
+ });
119
+ }
120
+ _chunkGSPBHZBHjs.Context.applyAddons(addons, subApp, "elysia");
121
+ subApp[http.type](http.prefix + http.route, async (c) => {
113
122
  debug(`invoke method "${func}" in module "${tag}"`);
114
123
  const contextData = {
115
124
  type: "elysia",
@@ -123,45 +132,54 @@ function bind(app, data, opts = {}) {
123
132
  params: c.params,
124
133
  headers: c.headers,
125
134
  app,
126
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
127
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
135
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].value, "getCookie"),
136
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2 = {}) => c.cookie[key].set({
128
137
  ...opts2,
129
138
  value
130
139
  }), "setCookie"),
131
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
132
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
133
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
134
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
135
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => {
140
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => c.cookie[key].remove(), "delCookie"),
141
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
142
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => Object.assign(c.set.headers, headers), "setResHeaders"),
143
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.set.status = status, "setResStatus"),
144
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
136
145
  throw new Error("elysia can't support getRequest");
137
146
  }, "getRequest"),
138
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => {
147
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => {
139
148
  throw new Error("elysia can't support getResponse");
140
149
  }, "getResponse")
141
150
  };
142
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
151
+ if (dynamic) {
152
+ aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
153
+ globalFilter,
154
+ globalGuards,
155
+ globalPipe
156
+ });
157
+ }
158
+ const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
143
159
  if (http.headers) c.set.headers = http.headers;
144
- return context.run({
145
- globalGuards,
146
- globalInterceptors,
147
- globalFilter,
148
- globalPipe
149
- }, (returnData) => returnData, (err) => {
160
+ if (dynamic) {
161
+ aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
162
+ globalFilter,
163
+ globalGuards,
164
+ globalPipe
165
+ });
166
+ }
167
+ return context.run(aop, (returnData) => returnData, (err) => {
150
168
  c.set.status = err.status;
151
169
  return err;
152
170
  });
153
171
  }, define.elysia);
154
- app.use(funcRouter);
172
+ app.use(subApp);
155
173
  }
156
174
  }
157
175
  }
158
- _chunkTVT62GIXjs.__name.call(void 0, registerRoute, "registerRoute");
176
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
159
177
  }
160
- _chunkTVT62GIXjs.__name.call(void 0, bind, "bind");
178
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
161
179
  function Elysia(opts) {
162
- return _chunkJDV2XJYEjs.Define.call(void 0, "elysia", opts);
180
+ return _chunkMBCHNDAYjs.Define.call(void 0, "elysia", opts);
163
181
  }
164
- _chunkTVT62GIXjs.__name.call(void 0, Elysia, "Elysia");
182
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Elysia, "Elysia");
165
183
 
166
184
 
167
185
 
@@ -1,23 +1,23 @@
1
1
  import {
2
2
  Define
3
- } from "../../chunk-J7B24YSE.mjs";
3
+ } from "../../chunk-HMVLXNV3.mjs";
4
4
  import {
5
5
  BadRequestException,
6
6
  Context,
7
7
  argToReq,
8
8
  createControllerMetaMap,
9
9
  detectAopDep
10
- } from "../../chunk-2CFYUXPM.mjs";
10
+ } from "../../chunk-V7EI76QQ.mjs";
11
11
  import {
12
12
  __name
13
- } from "../../chunk-G7TD2VB7.mjs";
13
+ } from "../../chunk-WHJ5FALK.mjs";
14
14
 
15
- // src/server/elysia/bind.ts
15
+ // src/http/elysia/bind.ts
16
16
  import Debug from "debug";
17
17
  import { Elysia as App } from "elysia";
18
18
  var debug = Debug("phecda-server/elysia");
19
19
  function bind(app, data, opts = {}) {
20
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
20
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
21
21
  const { moduleMap, meta } = data;
22
22
  const metaMap = createControllerMetaMap(meta, (meta2) => {
23
23
  const { controller, http, func, tag } = meta2.data;
@@ -27,19 +27,18 @@ function bind(app, data, opts = {}) {
27
27
  }
28
28
  });
29
29
  detectAopDep(meta, {
30
- plugins: [
31
- ...globalPlugins,
32
- ...parallelPlugins
30
+ addons: [
31
+ ...globalAddons,
32
+ ...parallelAddons
33
33
  ],
34
- guards: globalGuards,
35
- interceptors: globalInterceptors
34
+ guards: globalGuards
36
35
  });
37
36
  registerRoute();
38
- async function registerRoute() {
39
- Context.usePlugin(globalPlugins, "elysia").forEach((p) => p(app));
40
- const parallelRouter = new App();
41
- Context.usePlugin(parallelPlugins, "elysia").forEach((p) => p(parallelRouter));
37
+ function registerRoute() {
38
+ Context.applyAddons(globalAddons, app, "elysia");
42
39
  if (parallelRoute) {
40
+ const parallelRouter = new App();
41
+ Context.applyAddons(parallelAddons, app, "elysia");
43
42
  parallelRouter.post(parallelRoute, async (c) => {
44
43
  const { body } = c;
45
44
  async function errorHandler(e) {
@@ -58,6 +57,11 @@ function bind(app, data, opts = {}) {
58
57
  const meta2 = metaMap.get(tag)[func];
59
58
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
60
59
  const { data: { params } } = meta2;
60
+ const aop = Context.getAop(meta2, {
61
+ globalGuards,
62
+ globalFilter,
63
+ globalPipe
64
+ });
61
65
  const contextData = {
62
66
  type: "elysia",
63
67
  parallel: true,
@@ -86,12 +90,7 @@ function bind(app, data, opts = {}) {
86
90
  }, "getResponse")
87
91
  };
88
92
  const context = new Context(contextData);
89
- context.run({
90
- globalGuards,
91
- globalInterceptors,
92
- globalFilter,
93
- globalPipe
94
- }, resolve, resolve);
93
+ context.run(aop, resolve, resolve);
95
94
  });
96
95
  })).then((ret) => {
97
96
  return ret;
@@ -100,16 +99,26 @@ function bind(app, data, opts = {}) {
100
99
  return errorHandler(e);
101
100
  }
102
101
  });
102
+ app.use(parallelRouter);
103
103
  }
104
- app.use(parallelRouter);
105
104
  for (const [tag, record] of metaMap) {
106
105
  for (const func in record) {
107
106
  const meta2 = metaMap.get(tag)[func];
108
- const { data: { define, plugins, http } } = meta2;
109
- const funcRouter = new App();
107
+ const { data: { define, addons, http } } = meta2;
108
+ const subApp = new App({
109
+ prefix: ""
110
+ });
110
111
  if (!http?.type) continue;
111
- Context.usePlugin(plugins, "elysia").forEach((p) => p(funcRouter));
112
- funcRouter[http.type](http.prefix + http.route, async (c) => {
112
+ let aop;
113
+ if (!dynamic) {
114
+ aop = Context.getAop(meta2, {
115
+ globalFilter,
116
+ globalGuards,
117
+ globalPipe
118
+ });
119
+ }
120
+ Context.applyAddons(addons, subApp, "elysia");
121
+ subApp[http.type](http.prefix + http.route, async (c) => {
113
122
  debug(`invoke method "${func}" in module "${tag}"`);
114
123
  const contextData = {
115
124
  type: "elysia",
@@ -139,19 +148,28 @@ function bind(app, data, opts = {}) {
139
148
  throw new Error("elysia can't support getResponse");
140
149
  }, "getResponse")
141
150
  };
151
+ if (dynamic) {
152
+ aop = Context.getAop(meta2, {
153
+ globalFilter,
154
+ globalGuards,
155
+ globalPipe
156
+ });
157
+ }
142
158
  const context = new Context(contextData);
143
159
  if (http.headers) c.set.headers = http.headers;
144
- return context.run({
145
- globalGuards,
146
- globalInterceptors,
147
- globalFilter,
148
- globalPipe
149
- }, (returnData) => returnData, (err) => {
160
+ if (dynamic) {
161
+ aop = Context.getAop(meta2, {
162
+ globalFilter,
163
+ globalGuards,
164
+ globalPipe
165
+ });
166
+ }
167
+ return context.run(aop, (returnData) => returnData, (err) => {
150
168
  c.set.status = err.status;
151
169
  return err;
152
170
  });
153
171
  }, define.elysia);
154
- app.use(funcRouter);
172
+ app.use(subApp);
155
173
  }
156
174
  }
157
175
  }
@@ -1,8 +1,8 @@
1
1
  import { Request, Response, Router, RequestHandler } from 'express';
2
- import { H as HttpContext, a as HttpOptions } from '../../types-BvD3B5Ny.mjs';
3
- import { F as Factory } from '../../core-P1CsH6jz.mjs';
2
+ import { H as HttpContext, a as HttpOptions } from '../../types-h40T3cRG.mjs';
3
+ import { F as Factory } from '../../core-BIcUwV18.mjs';
4
4
  import 'node:http';
5
- import '../../meta-KtfiBIde.mjs';
5
+ import '../../meta-BXKLFTgG.mjs';
6
6
  import 'phecda-core';
7
7
 
8
8
  interface ExpressCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface ExpressCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = RequestHandler;
15
+ type Addon = RequestHandler;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type ExpressCtx, type Plugin, bind };
18
+ export { type Addon, type ExpressCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { Request, Response, Router, RequestHandler } from 'express';
2
- import { H as HttpContext, a as HttpOptions } from '../../types-DIw7B6Up.js';
3
- import { F as Factory } from '../../core-BlN0Spy9.js';
2
+ import { H as HttpContext, a as HttpOptions } from '../../types-VFzEM7LL.js';
3
+ import { F as Factory } from '../../core-CYwEPfN4.js';
4
4
  import 'node:http';
5
- import '../../meta-KtfiBIde.js';
5
+ import '../../meta-BXKLFTgG.js';
6
6
  import 'phecda-core';
7
7
 
8
8
  interface ExpressCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface ExpressCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = RequestHandler;
15
+ type Addon = RequestHandler;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type ExpressCtx, type Plugin, bind };
18
+ export { type Addon, type ExpressCtx, bind };