phecda-server 6.1.0 → 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.
Files changed (80) hide show
  1. package/bin/cli.mjs +160 -157
  2. package/dist/{chunk-3H3T54IC.mjs → chunk-5622RBNB.mjs} +3 -4
  3. package/dist/{chunk-NL6QBQAR.js → chunk-BGXSMOLX.js} +20 -21
  4. package/dist/{chunk-J7B24YSE.mjs → chunk-HMVLXNV3.mjs} +5 -14
  5. package/dist/{chunk-TVT62GIX.js → chunk-J5CFUN4V.js} +8 -1
  6. package/dist/{chunk-JDV2XJYE.js → chunk-MBCHNDAY.js} +27 -36
  7. package/dist/{chunk-2CFYUXPM.mjs → chunk-P75VKZJY.mjs} +101 -137
  8. package/dist/chunk-SW5IKE5H.js +503 -0
  9. package/dist/{chunk-G7TD2VB7.mjs → chunk-WHJ5FALK.mjs} +7 -0
  10. package/dist/{core-P1CsH6jz.d.mts → core-BIcUwV18.d.mts} +1 -1
  11. package/dist/{core-BlN0Spy9.d.ts → core-CYwEPfN4.d.ts} +1 -1
  12. package/dist/helper.d.mts +4 -6
  13. package/dist/helper.d.ts +4 -6
  14. package/dist/helper.js +3 -3
  15. package/dist/helper.mjs +2 -2
  16. package/dist/{server → http}/elysia/index.d.mts +5 -5
  17. package/dist/{server → http}/elysia/index.d.ts +5 -5
  18. package/dist/{server → http}/elysia/index.js +80 -62
  19. package/dist/{server → http}/elysia/index.mjs +50 -32
  20. package/dist/{server → http}/express/index.d.mts +5 -5
  21. package/dist/{server → http}/express/index.d.ts +5 -5
  22. package/dist/{server → http}/express/index.js +71 -55
  23. package/dist/{server → http}/express/index.mjs +42 -26
  24. package/dist/{server → http}/fastify/index.d.mts +5 -5
  25. package/dist/{server → http}/fastify/index.d.ts +5 -5
  26. package/dist/{server → http}/fastify/index.js +72 -72
  27. package/dist/{server → http}/fastify/index.mjs +47 -47
  28. package/dist/{server → http}/h3/index.d.mts +5 -5
  29. package/dist/{server → http}/h3/index.d.ts +5 -5
  30. package/dist/http/h3/index.js +160 -0
  31. package/dist/{server → http}/h3/index.mjs +68 -62
  32. package/dist/{server → http}/hono/index.d.mts +5 -5
  33. package/dist/{server → http}/hono/index.d.ts +5 -5
  34. package/dist/{server → http}/hono/index.js +69 -54
  35. package/dist/{server → http}/hono/index.mjs +41 -26
  36. package/dist/{server → http}/hyper-express/index.d.mts +5 -5
  37. package/dist/{server → http}/hyper-express/index.d.ts +5 -5
  38. package/dist/{server → http}/hyper-express/index.js +69 -56
  39. package/dist/{server → http}/hyper-express/index.mjs +41 -28
  40. package/dist/{server → http}/koa/index.d.mts +5 -5
  41. package/dist/{server → http}/koa/index.d.ts +5 -5
  42. package/dist/{server → http}/koa/index.js +71 -55
  43. package/dist/{server → http}/koa/index.mjs +42 -26
  44. package/dist/index.d.mts +51 -40
  45. package/dist/index.d.ts +51 -40
  46. package/dist/index.js +59 -81
  47. package/dist/index.mjs +39 -61
  48. package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
  49. package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
  50. package/dist/rpc/bullmq/index.d.mts +6 -6
  51. package/dist/rpc/bullmq/index.d.ts +6 -6
  52. package/dist/rpc/bullmq/index.js +24 -24
  53. package/dist/rpc/bullmq/index.mjs +14 -14
  54. package/dist/rpc/kafka/index.d.mts +3 -3
  55. package/dist/rpc/kafka/index.d.ts +3 -3
  56. package/dist/rpc/kafka/index.js +25 -21
  57. package/dist/rpc/kafka/index.mjs +15 -11
  58. package/dist/rpc/nats/index.d.mts +3 -3
  59. package/dist/rpc/nats/index.d.ts +3 -3
  60. package/dist/rpc/nats/index.js +22 -21
  61. package/dist/rpc/nats/index.mjs +13 -12
  62. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  63. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  64. package/dist/rpc/rabbitmq/index.js +23 -22
  65. package/dist/rpc/rabbitmq/index.mjs +12 -11
  66. package/dist/rpc/redis/index.d.mts +3 -3
  67. package/dist/rpc/redis/index.d.ts +3 -3
  68. package/dist/rpc/redis/index.js +24 -20
  69. package/dist/rpc/redis/index.mjs +15 -11
  70. package/dist/test.d.mts +3 -3
  71. package/dist/test.d.ts +3 -3
  72. package/dist/test.js +6 -6
  73. package/dist/test.mjs +2 -2
  74. package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
  75. package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
  76. package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
  77. package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
  78. package/package.json +23 -23
  79. package/dist/chunk-DVTBLV6I.js +0 -539
  80. package/dist/server/h3/index.js +0 -154
@@ -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 _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.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 = _chunkSW5IKE5Hjs.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
+ _chunkSW5IKE5Hjs.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
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, app, "elysia");
42
39
  if (parallelRoute) {
40
+ const parallelRouter = new (0, _elysia.Elysia)();
41
+ _chunkSW5IKE5Hjs.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 _chunkSW5IKE5Hjs.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, _chunkSW5IKE5Hjs.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 _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.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 _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
59
  const { data: { params } } = meta2;
60
+ const aop = _chunkSW5IKE5Hjs.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
+ ..._chunkSW5IKE5Hjs.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, _chunkSW5IKE5Hjs.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 = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
115
+ globalFilter,
116
+ globalGuards,
117
+ globalPipe
118
+ });
119
+ }
120
+ _chunkSW5IKE5Hjs.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 = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
153
+ globalFilter,
154
+ globalGuards,
155
+ globalPipe
156
+ });
157
+ }
158
+ const context = new (0, _chunkSW5IKE5Hjs.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 = _chunkSW5IKE5Hjs.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-P75VKZJY.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 };
@@ -5,58 +5,65 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkDVTBLV6Ijs = require('../../chunk-DVTBLV6I.js');
8
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
9
9
 
10
10
 
11
- var _chunkTVT62GIXjs = require('../../chunk-TVT62GIX.js');
11
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
12
12
 
13
- // src/server/express/bind.ts
13
+ // src/http/express/bind.ts
14
+ var _express = require('express');
14
15
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
15
16
  var debug = _debug2.default.call(void 0, "phecda-server/express");
16
17
  function bind(router, data, opts = {}) {
17
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
18
19
  const { moduleMap, meta } = data;
19
20
  const originStack = router.stack.slice(0, router.stack.length);
20
- const metaMap = _chunkDVTBLV6Ijs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
22
  const { controller, http, func, tag } = meta2.data;
22
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
23
24
  debug(`register method "${func}" in module "${tag}"`);
24
25
  return true;
25
26
  }
26
27
  });
27
- _chunkDVTBLV6Ijs.detectAopDep.call(void 0, meta, {
28
- plugins: [
29
- ...globalPlugins,
30
- ...parallelPlugins
28
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
29
+ addons: [
30
+ ...globalAddons,
31
+ ...parallelAddons
31
32
  ],
32
- guards: globalGuards,
33
- interceptors: globalInterceptors
33
+ guards: globalGuards
34
34
  });
35
35
  registerRoute();
36
- _chunkDVTBLV6Ijs.HMR.call(void 0, async () => {
36
+ _chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
37
37
  router.stack = originStack;
38
38
  registerRoute();
39
39
  });
40
- async function registerRoute() {
41
- _chunkDVTBLV6Ijs.Context.usePlugin(globalPlugins, "express").forEach((p) => router.use(p));
40
+ function registerRoute() {
41
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "express");
42
42
  if (parallelRoute) {
43
- router.post(parallelRoute, ..._chunkDVTBLV6Ijs.Context.usePlugin(parallelPlugins, "express"), async (req, res, next) => {
43
+ const subRouter = _express.Router.call(void 0, );
44
+ _chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, subRouter, "express");
45
+ subRouter.use(async (req, res, next) => {
44
46
  const { body } = req;
45
47
  async function errorHandler(e) {
46
- const error = await _chunkDVTBLV6Ijs.Context.filterRecord.default(e);
48
+ const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
47
49
  return res.status(error.status).json(error);
48
50
  }
49
- _chunkTVT62GIXjs.__name.call(void 0, errorHandler, "errorHandler");
50
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkDVTBLV6Ijs.BadRequestException)("data format should be an array"));
51
+ _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
52
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
51
53
  try {
52
54
  return Promise.all(body.map((item, i) => {
53
55
  return new Promise(async (resolve) => {
54
56
  const { tag, func } = item;
55
57
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
56
- if (!metaMap.has(tag)) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
+ if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
57
59
  const meta2 = metaMap.get(tag)[func];
58
- if (!meta2) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
+ if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
61
  const { data: { params } } = meta2;
62
+ const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
63
+ globalFilter,
64
+ globalGuards,
65
+ globalPipe
66
+ });
60
67
  const contextData = {
61
68
  type: "express",
62
69
  parallel: true,
@@ -69,25 +76,20 @@ function bind(router, data, opts = {}) {
69
76
  func,
70
77
  next,
71
78
  app: router,
72
- ..._chunkDVTBLV6Ijs.argToReq.call(void 0, params, item.args, req.headers),
73
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
74
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
75
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => res.cookie(key, "", {
79
+ ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, req.headers),
80
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
81
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
82
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.cookie(key, "", {
76
83
  expires: /* @__PURE__ */ new Date(0)
77
84
  }), "delCookie"),
78
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
79
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
80
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
81
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => req, "getRequest"),
82
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => res, "getResponse")
85
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
86
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
87
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
88
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
89
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
83
90
  };
84
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
85
- context.run({
86
- globalGuards,
87
- globalInterceptors,
88
- globalFilter,
89
- globalPipe
90
- }, resolve, resolve);
91
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
92
+ context.run(aop, resolve, resolve);
91
93
  });
92
94
  })).then((ret) => {
93
95
  res.json(ret);
@@ -96,13 +98,24 @@ function bind(router, data, opts = {}) {
96
98
  return errorHandler(e);
97
99
  }
98
100
  });
101
+ router.post(parallelRoute, subRouter);
99
102
  }
100
103
  for (const [tag, record] of metaMap) {
101
104
  for (const func in record) {
102
105
  const meta2 = metaMap.get(tag)[func];
103
- const { data: { plugins, http } } = meta2;
106
+ const { data: { addons, http } } = meta2;
104
107
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
105
- router[http.type](http.prefix + http.route, ..._chunkDVTBLV6Ijs.Context.usePlugin(plugins, "express"), async (req, res, next) => {
108
+ let aop;
109
+ if (!dynamic) {
110
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
111
+ globalFilter,
112
+ globalGuards,
113
+ globalPipe
114
+ });
115
+ }
116
+ const subRouter = _express.Router.call(void 0, );
117
+ _chunkSW5IKE5Hjs.Context.applyAddons(addons, subRouter, "express");
118
+ subRouter[http.type](http.prefix + http.route, async (req, res, next) => {
106
119
  debug(`invoke method "${func}" in module "${tag}"`);
107
120
  const contextData = {
108
121
  type: "express",
@@ -118,25 +131,27 @@ function bind(router, data, opts = {}) {
118
131
  headers: req.headers,
119
132
  app: router,
120
133
  next,
121
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
122
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
123
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => res.cookie(key, "", {
134
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
135
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
136
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.cookie(key, "", {
124
137
  expires: /* @__PURE__ */ new Date(0)
125
138
  }), "delCookie"),
126
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
127
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
128
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
129
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => req, "getRequest"),
130
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => res, "getResponse")
139
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
140
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
141
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
142
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
143
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
131
144
  };
132
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
145
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
133
146
  if (http.headers) res.set(http.headers);
134
- await context.run({
135
- globalGuards,
136
- globalInterceptors,
137
- globalFilter,
138
- globalPipe
139
- }, (returnData) => {
147
+ if (dynamic) {
148
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
149
+ globalFilter,
150
+ globalGuards,
151
+ globalPipe
152
+ });
153
+ }
154
+ await context.run(aop, (returnData) => {
140
155
  if (res.writableEnded) return;
141
156
  if (typeof returnData === "string") res.send(returnData);
142
157
  else res.json(returnData);
@@ -145,12 +160,13 @@ function bind(router, data, opts = {}) {
145
160
  res.status(err.status).json(err);
146
161
  });
147
162
  });
163
+ router.use(subRouter);
148
164
  }
149
165
  }
150
166
  }
151
- _chunkTVT62GIXjs.__name.call(void 0, registerRoute, "registerRoute");
167
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
152
168
  }
153
- _chunkTVT62GIXjs.__name.call(void 0, bind, "bind");
169
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
154
170
 
155
171
 
156
172
  exports.bind = bind;