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
@@ -1,22 +1,22 @@
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/fastify/bind.ts
15
+ // src/http/fastify/bind.ts
16
16
  import Debug from "debug";
17
17
  var debug = Debug("phecda-server/fastify");
18
18
  function bind(fastify, data, opts = {}) {
19
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe, fastifyOpts } = opts;
19
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, fastifyOpts, dynamic = false } = opts;
20
20
  const { moduleMap, meta } = data;
21
21
  const metaMap = createControllerMetaMap(meta, (meta2) => {
22
22
  const { controller, http, func, tag } = meta2.data;
@@ -26,24 +26,17 @@ function bind(fastify, data, opts = {}) {
26
26
  }
27
27
  });
28
28
  detectAopDep(meta, {
29
- plugins: [
30
- ...globalPlugins,
31
- ...parallelPlugins
29
+ addons: [
30
+ ...globalAddons,
31
+ ...parallelAddons
32
32
  ],
33
- guards: globalGuards,
34
- interceptors: globalInterceptors
33
+ guards: globalGuards
35
34
  });
36
- fastify.register((fastify2, _, done) => {
37
- Context.usePlugin(globalPlugins, "fastify").forEach((p) => {
38
- p[Symbol.for("skip-override")] = true;
39
- fastify2.register(p);
40
- });
41
- fastify2.register((fastify3, _opts, done2) => {
42
- Context.usePlugin(parallelPlugins, "fastify").forEach((p) => {
43
- p[Symbol.for("skip-override")] = true;
44
- fastify3.register(p);
45
- });
46
- if (parallelRoute) {
35
+ fastify.register(async (fastify2, _, done) => {
36
+ Context.applyAddons(globalAddons, fastify2, "fastify");
37
+ if (parallelRoute) {
38
+ fastify2.register(async (fastify3, _opts, done2) => {
39
+ Context.applyAddons(parallelAddons, fastify3, "fastify");
47
40
  fastify3.post(parallelRoute, async (req, res) => {
48
41
  const { body } = req;
49
42
  async function errorHandler(e) {
@@ -61,6 +54,11 @@ function bind(fastify, data, opts = {}) {
61
54
  const meta2 = metaMap.get(tag)[func];
62
55
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
63
56
  const { data: { params } } = meta2;
57
+ const aop = Context.getAop(meta2, {
58
+ globalFilter,
59
+ globalGuards,
60
+ globalPipe
61
+ });
64
62
  const contextData = {
65
63
  type: "fastify",
66
64
  parallel: true,
@@ -82,16 +80,11 @@ function bind(fastify, data, opts = {}) {
82
80
  redirect: /* @__PURE__ */ __name((url, status) => res.redirect(url, status), "redirect"),
83
81
  setResHeaders: /* @__PURE__ */ __name((headers) => res.headers(headers), "setResHeaders"),
84
82
  setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus"),
85
- getRequest: /* @__PURE__ */ __name(() => req, "getRequest"),
86
- getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
83
+ getRequest: /* @__PURE__ */ __name(() => req.raw, "getRequest"),
84
+ getResponse: /* @__PURE__ */ __name(() => res.raw, "getResponse")
87
85
  };
88
86
  const context = new Context(contextData);
89
- context.run({
90
- globalGuards,
91
- globalInterceptors,
92
- globalFilter,
93
- globalPipe
94
- }, resolve, resolve);
87
+ context.run(aop, resolve, resolve);
95
88
  });
96
89
  })).then((ret) => {
97
90
  res.send(ret);
@@ -100,19 +93,24 @@ function bind(fastify, data, opts = {}) {
100
93
  return errorHandler(e);
101
94
  }
102
95
  });
103
- }
104
- done2();
105
- });
96
+ done2();
97
+ });
98
+ }
106
99
  for (const [tag, record] of metaMap) {
107
100
  for (const func in record) {
108
101
  const meta2 = metaMap.get(tag)[func];
109
- const { data: { plugins, define, http } } = meta2;
102
+ const { data: { addons, define, http } } = meta2;
110
103
  if (!http?.type) continue;
111
- fastify2.register((fastify3, _opts, done2) => {
112
- Context.usePlugin(plugins, "fastify").forEach((p) => {
113
- p[Symbol.for("skip-override")] = true;
114
- fastify3.register(p);
115
- });
104
+ fastify2.register(async (fastify3, _opts, done2) => {
105
+ Context.applyAddons(addons, fastify3, "fastify");
106
+ let aop;
107
+ if (!dynamic) {
108
+ aop = Context.getAop(meta2, {
109
+ globalFilter,
110
+ globalGuards,
111
+ globalPipe
112
+ });
113
+ }
116
114
  fastify3[http.type](http.prefix + http.route, define?.fastify || {}, async (req, res) => {
117
115
  debug(`invoke method "${func}" in module "${tag}"`);
118
116
  const contextData = {
@@ -134,22 +132,24 @@ function bind(fastify, data, opts = {}) {
134
132
  setCookie: /* @__PURE__ */ __name((key, value, opts2) => res.setCookie(key, value, opts2), "setCookie"),
135
133
  // @ts-expect-error need @fastify/cookie
136
134
  delCookie: /* @__PURE__ */ __name((key) => res.clearCookie(key, {
137
- path: ""
135
+ url: ""
138
136
  }), "delCookie"),
139
137
  redirect: /* @__PURE__ */ __name((url, status) => res.redirect(url, status), "redirect"),
140
138
  setResHeaders: /* @__PURE__ */ __name((headers) => res.headers(headers), "setResHeaders"),
141
139
  setResStatus: /* @__PURE__ */ __name((code) => res.status(code), "setResStatus"),
142
- getRequest: /* @__PURE__ */ __name(() => req, "getRequest"),
143
- getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
140
+ getRequest: /* @__PURE__ */ __name(() => req.raw, "getRequest"),
141
+ getResponse: /* @__PURE__ */ __name(() => res.raw, "getResponse")
144
142
  };
145
143
  const context = new Context(contextData);
146
144
  if (http.headers) res.headers(http.headers);
147
- return context.run({
148
- globalGuards,
149
- globalInterceptors,
150
- globalFilter,
151
- globalPipe
152
- }, (returnData) => {
145
+ if (dynamic) {
146
+ aop = Context.getAop(meta2, {
147
+ globalFilter,
148
+ globalGuards,
149
+ globalPipe
150
+ });
151
+ }
152
+ return context.run(aop, (returnData) => {
153
153
  if (res.sent) return;
154
154
  return returnData;
155
155
  }, (err) => {
@@ -1,8 +1,8 @@
1
1
  import { H3Event, Router, _RequestMiddleware } from 'h3';
2
- import { F as Factory } from '../../core-P1CsH6jz.mjs';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-BvD3B5Ny.mjs';
2
+ import { F as Factory } from '../../core-BIcUwV18.mjs';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-h40T3cRG.mjs';
4
4
  import 'phecda-core';
5
- import '../../meta-KtfiBIde.mjs';
5
+ import '../../meta-BXKLFTgG.mjs';
6
6
  import 'node:http';
7
7
 
8
8
  interface H3Ctx extends HttpContext {
@@ -10,7 +10,7 @@ interface H3Ctx extends HttpContext {
10
10
  event: H3Event;
11
11
  app: Router;
12
12
  }
13
- type Plugin = _RequestMiddleware;
13
+ type Addon = _RequestMiddleware;
14
14
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
15
 
16
- export { type H3Ctx, type Plugin, bind };
16
+ export { type Addon, type H3Ctx, bind };
@@ -1,8 +1,8 @@
1
1
  import { H3Event, Router, _RequestMiddleware } from 'h3';
2
- import { F as Factory } from '../../core-BlN0Spy9.js';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-DIw7B6Up.js';
2
+ import { F as Factory } from '../../core-CYwEPfN4.js';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-VFzEM7LL.js';
4
4
  import 'phecda-core';
5
- import '../../meta-KtfiBIde.js';
5
+ import '../../meta-BXKLFTgG.js';
6
6
  import 'node:http';
7
7
 
8
8
  interface H3Ctx extends HttpContext {
@@ -10,7 +10,7 @@ interface H3Ctx extends HttpContext {
10
10
  event: H3Event;
11
11
  app: Router;
12
12
  }
13
- type Plugin = _RequestMiddleware;
13
+ type Addon = _RequestMiddleware;
14
14
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
15
 
16
- export { type H3Ctx, type Plugin, bind };
16
+ export { type Addon, type H3Ctx, bind };
@@ -0,0 +1,160 @@
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
+
3
+
4
+
5
+
6
+
7
+ var _chunkGSPBHZBHjs = require('../../chunk-GSPBHZBH.js');
8
+
9
+
10
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
11
+
12
+ // src/http/h3/bind.ts
13
+ var _h3 = require('h3');
14
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
15
+ var debug = _debug2.default.call(void 0, "phecda-server/h3");
16
+ function bind(router, data, opts = {}) {
17
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
18
+ const { moduleMap, meta } = data;
19
+ const metaMap = _chunkGSPBHZBHjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const { controller, http, func, tag } = meta2.data;
21
+ if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
22
+ debug(`register method "${func}" in module "${tag}"`);
23
+ return true;
24
+ }
25
+ });
26
+ _chunkGSPBHZBHjs.detectAopDep.call(void 0, meta, {
27
+ addons: [
28
+ ...globalAddons,
29
+ ...parallelAddons
30
+ ],
31
+ guards: globalGuards
32
+ });
33
+ registerRoute();
34
+ function registerRoute() {
35
+ _chunkGSPBHZBHjs.Context.applyAddons(globalAddons, router, "h3");
36
+ if (parallelRoute) {
37
+ const subRouter = _h3.createRouter.call(void 0, );
38
+ _chunkGSPBHZBHjs.Context.applyAddons(parallelAddons, subRouter, "h3");
39
+ subRouter.post(parallelRoute, _h3.eventHandler.call(void 0, {
40
+ handler: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, async (event) => {
41
+ const body = await _h3.readBody.call(void 0, event, {
42
+ strict: true
43
+ });
44
+ async function errorHandler(e) {
45
+ const error = await _chunkGSPBHZBHjs.Context.filterRecord.default(e);
46
+ _h3.setResponseStatus.call(void 0, event, error.status);
47
+ return error;
48
+ }
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"));
51
+ try {
52
+ return Promise.all(body.map((item, i) => {
53
+ return new Promise(async (resolve) => {
54
+ const { tag, func } = item;
55
+ debug(`(parallel)invoke method "${func}" in module "${tag}"`);
56
+ if (!metaMap.has(tag)) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`module "${tag}" doesn't exist`)));
57
+ const meta2 = metaMap.get(tag)[func];
58
+ if (!meta2) return resolve(await _chunkGSPBHZBHjs.Context.filterRecord.default(new (0, _chunkGSPBHZBHjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
+ const { data: { params } } = meta2;
60
+ const aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
61
+ globalFilter,
62
+ globalGuards,
63
+ globalPipe
64
+ });
65
+ const contextData = {
66
+ type: "h3",
67
+ index: i,
68
+ event,
69
+ meta: meta2,
70
+ moduleMap,
71
+ tag,
72
+ func,
73
+ parallel: true,
74
+ app: router,
75
+ ..._chunkGSPBHZBHjs.argToReq.call(void 0, params, item.args, _h3.getRequestHeaders.call(void 0, event)),
76
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _h3.getCookie.call(void 0, event, key), "getCookie"),
77
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _h3.setCookie.call(void 0, event, key, value, opts2), "setCookie"),
78
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _h3.deleteCookie.call(void 0, event, key), "delCookie"),
79
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => _h3.sendRedirect.call(void 0, event, url, status), "redirect"),
80
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => _h3.setResponseHeaders.call(void 0, event, headers), "setResHeaders"),
81
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => _h3.setResponseStatus.call(void 0, event, code), "setResStatus"),
82
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => event.node.req, "getRequest"),
83
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => event.node.res, "getResponse")
84
+ };
85
+ const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
86
+ context.run(aop, resolve, resolve);
87
+ });
88
+ }));
89
+ } catch (e) {
90
+ return errorHandler(e);
91
+ }
92
+ }, "handler")
93
+ }));
94
+ router.use(parallelRoute, _h3.useBase.call(void 0, "", subRouter.handler));
95
+ }
96
+ for (const [tag, record] of metaMap) {
97
+ for (const func in record) {
98
+ const meta2 = metaMap.get(tag)[func];
99
+ const { data: { http, params, addons } } = meta2;
100
+ if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
101
+ const needBody = params.some((item) => item.type === "body");
102
+ let aop;
103
+ if (!dynamic) {
104
+ aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
105
+ globalFilter,
106
+ globalGuards,
107
+ globalPipe
108
+ });
109
+ }
110
+ const subRouter = _h3.createRouter.call(void 0, );
111
+ _chunkGSPBHZBHjs.Context.applyAddons(addons, subRouter, "h3");
112
+ subRouter[http.type](http.prefix + http.route, _h3.defineEventHandler.call(void 0, async (event) => {
113
+ debug(`invoke method "${func}" in module "${tag}"`);
114
+ const contextData = {
115
+ type: "h3",
116
+ meta: meta2,
117
+ event,
118
+ moduleMap,
119
+ tag,
120
+ func,
121
+ headers: _h3.getRequestHeaders.call(void 0, event),
122
+ params: _h3.getRouterParams.call(void 0, event),
123
+ query: _h3.getQuery.call(void 0, event),
124
+ app: router,
125
+ body: needBody ? await _h3.readBody.call(void 0, event, {
126
+ strict: true
127
+ }) : void 0,
128
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _h3.getCookie.call(void 0, event, key), "getCookie"),
129
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _h3.setCookie.call(void 0, event, key, value, opts2), "setCookie"),
130
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => _h3.sendRedirect.call(void 0, event, url), "redirect"),
131
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => _h3.setResponseHeaders.call(void 0, event, headers), "setResHeaders"),
132
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => _h3.setResponseStatus.call(void 0, event, code), "setResStatus"),
133
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _h3.deleteCookie.call(void 0, event, key), "delCookie"),
134
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => event.node.req, "getRequest"),
135
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => event.node.res, "getResponse")
136
+ };
137
+ const context = new (0, _chunkGSPBHZBHjs.Context)(contextData);
138
+ _h3.setHeaders.call(void 0, event, http.headers || {});
139
+ if (dynamic) {
140
+ aop = _chunkGSPBHZBHjs.Context.getAop(meta2, {
141
+ globalFilter,
142
+ globalGuards,
143
+ globalPipe
144
+ });
145
+ }
146
+ return context.run(aop, (returnData) => returnData, (err) => {
147
+ _h3.setResponseStatus.call(void 0, event, err.status);
148
+ return err;
149
+ });
150
+ }));
151
+ router.use(http.prefix + http.route, _h3.useBase.call(void 0, "", subRouter.handler));
152
+ }
153
+ }
154
+ }
155
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
156
+ }
157
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
158
+
159
+
160
+ exports.bind = bind;
@@ -4,17 +4,17 @@ import {
4
4
  argToReq,
5
5
  createControllerMetaMap,
6
6
  detectAopDep
7
- } from "../../chunk-2CFYUXPM.mjs";
7
+ } from "../../chunk-V7EI76QQ.mjs";
8
8
  import {
9
9
  __name
10
- } from "../../chunk-G7TD2VB7.mjs";
10
+ } from "../../chunk-WHJ5FALK.mjs";
11
11
 
12
- // src/server/h3/bind.ts
13
- import { defineRequestMiddleware, deleteCookie, eventHandler, getCookie, getQuery, getRequestHeaders, getRouterParams, readBody, sendRedirect, setCookie, setHeaders, setResponseHeaders, setResponseStatus } from "h3";
12
+ // src/http/h3/bind.ts
13
+ import { createRouter, defineEventHandler, deleteCookie, eventHandler, getCookie, getQuery, getRequestHeaders, getRouterParams, readBody, sendRedirect, setCookie, setHeaders, setResponseHeaders, setResponseStatus, useBase } from "h3";
14
14
  import Debug from "debug";
15
15
  var debug = Debug("phecda-server/h3");
16
16
  function bind(router, data, opts = {}) {
17
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
17
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
18
18
  const { moduleMap, meta } = data;
19
19
  const metaMap = createControllerMetaMap(meta, (meta2) => {
20
20
  const { controller, http, func, tag } = meta2.data;
@@ -24,21 +24,19 @@ function bind(router, data, opts = {}) {
24
24
  }
25
25
  });
26
26
  detectAopDep(meta, {
27
- plugins: [
28
- ...globalPlugins,
29
- ...parallelPlugins
27
+ addons: [
28
+ ...globalAddons,
29
+ ...parallelAddons
30
30
  ],
31
- guards: globalGuards,
32
- interceptors: globalInterceptors
31
+ guards: globalGuards
33
32
  });
34
33
  registerRoute();
35
- async function registerRoute() {
34
+ function registerRoute() {
35
+ Context.applyAddons(globalAddons, router, "h3");
36
36
  if (parallelRoute) {
37
- router.post(parallelRoute, eventHandler({
38
- onRequest: Context.usePlugin([
39
- ...globalPlugins,
40
- ...parallelPlugins
41
- ], "h3").map(defineRequestMiddleware),
37
+ const subRouter = createRouter();
38
+ Context.applyAddons(parallelAddons, subRouter, "h3");
39
+ subRouter.post(parallelRoute, eventHandler({
42
40
  handler: /* @__PURE__ */ __name(async (event) => {
43
41
  const body = await readBody(event, {
44
42
  strict: true
@@ -59,6 +57,11 @@ function bind(router, data, opts = {}) {
59
57
  const meta2 = metaMap.get(tag)[func];
60
58
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
61
59
  const { data: { params } } = meta2;
60
+ const aop = Context.getAop(meta2, {
61
+ globalFilter,
62
+ globalGuards,
63
+ globalPipe
64
+ });
62
65
  const contextData = {
63
66
  type: "h3",
64
67
  index: i,
@@ -80,12 +83,7 @@ function bind(router, data, opts = {}) {
80
83
  getResponse: /* @__PURE__ */ __name(() => event.node.res, "getResponse")
81
84
  };
82
85
  const context = new Context(contextData);
83
- context.run({
84
- globalGuards,
85
- globalInterceptors,
86
- globalFilter,
87
- globalPipe
88
- }, resolve, resolve);
86
+ context.run(aop, resolve, resolve);
89
87
  });
90
88
  }));
91
89
  } catch (e) {
@@ -93,56 +91,64 @@ function bind(router, data, opts = {}) {
93
91
  }
94
92
  }, "handler")
95
93
  }));
94
+ router.use(parallelRoute, useBase("", subRouter.handler));
96
95
  }
97
96
  for (const [tag, record] of metaMap) {
98
97
  for (const func in record) {
99
98
  const meta2 = metaMap.get(tag)[func];
100
- const { data: { http, params, plugins } } = meta2;
99
+ const { data: { http, params, addons } } = meta2;
101
100
  if (!http?.type) continue;
102
101
  const needBody = params.some((item) => item.type === "body");
103
- router[http.type](http.prefix + http.route, eventHandler({
104
- onRequest: Context.usePlugin([
105
- ...globalPlugins,
106
- ...plugins
107
- ], "h3").map(defineRequestMiddleware),
108
- handler: /* @__PURE__ */ __name(async (event) => {
109
- debug(`invoke method "${func}" in module "${tag}"`);
110
- const contextData = {
111
- type: "h3",
112
- meta: meta2,
113
- event,
114
- moduleMap,
115
- tag,
116
- func,
117
- headers: getRequestHeaders(event),
118
- params: getRouterParams(event),
119
- query: getQuery(event),
120
- app: router,
121
- body: needBody ? await readBody(event, {
122
- strict: true
123
- }) : void 0,
124
- getCookie: /* @__PURE__ */ __name((key) => getCookie(event, key), "getCookie"),
125
- setCookie: /* @__PURE__ */ __name((key, value, opts2) => setCookie(event, key, value, opts2), "setCookie"),
126
- redirect: /* @__PURE__ */ __name((url) => sendRedirect(event, url), "redirect"),
127
- setResHeaders: /* @__PURE__ */ __name((headers) => setResponseHeaders(event, headers), "setResHeaders"),
128
- setResStatus: /* @__PURE__ */ __name((code) => setResponseStatus(event, code), "setResStatus"),
129
- delCookie: /* @__PURE__ */ __name((key) => deleteCookie(event, key), "delCookie"),
130
- getRequest: /* @__PURE__ */ __name(() => event.node.req, "getRequest"),
131
- getResponse: /* @__PURE__ */ __name(() => event.node.res, "getResponse")
132
- };
133
- const context = new Context(contextData);
134
- setHeaders(event, http.headers || {});
135
- return context.run({
136
- globalGuards,
137
- globalInterceptors,
102
+ let aop;
103
+ if (!dynamic) {
104
+ aop = Context.getAop(meta2, {
105
+ globalFilter,
106
+ globalGuards,
107
+ globalPipe
108
+ });
109
+ }
110
+ const subRouter = createRouter();
111
+ Context.applyAddons(addons, subRouter, "h3");
112
+ subRouter[http.type](http.prefix + http.route, defineEventHandler(async (event) => {
113
+ debug(`invoke method "${func}" in module "${tag}"`);
114
+ const contextData = {
115
+ type: "h3",
116
+ meta: meta2,
117
+ event,
118
+ moduleMap,
119
+ tag,
120
+ func,
121
+ headers: getRequestHeaders(event),
122
+ params: getRouterParams(event),
123
+ query: getQuery(event),
124
+ app: router,
125
+ body: needBody ? await readBody(event, {
126
+ strict: true
127
+ }) : void 0,
128
+ getCookie: /* @__PURE__ */ __name((key) => getCookie(event, key), "getCookie"),
129
+ setCookie: /* @__PURE__ */ __name((key, value, opts2) => setCookie(event, key, value, opts2), "setCookie"),
130
+ redirect: /* @__PURE__ */ __name((url) => sendRedirect(event, url), "redirect"),
131
+ setResHeaders: /* @__PURE__ */ __name((headers) => setResponseHeaders(event, headers), "setResHeaders"),
132
+ setResStatus: /* @__PURE__ */ __name((code) => setResponseStatus(event, code), "setResStatus"),
133
+ delCookie: /* @__PURE__ */ __name((key) => deleteCookie(event, key), "delCookie"),
134
+ getRequest: /* @__PURE__ */ __name(() => event.node.req, "getRequest"),
135
+ getResponse: /* @__PURE__ */ __name(() => event.node.res, "getResponse")
136
+ };
137
+ const context = new Context(contextData);
138
+ setHeaders(event, http.headers || {});
139
+ if (dynamic) {
140
+ aop = Context.getAop(meta2, {
138
141
  globalFilter,
142
+ globalGuards,
139
143
  globalPipe
140
- }, (returnData) => returnData, (err) => {
141
- setResponseStatus(event, err.status);
142
- return err;
143
144
  });
144
- }, "handler")
145
+ }
146
+ return context.run(aop, (returnData) => returnData, (err) => {
147
+ setResponseStatus(event, err.status);
148
+ return err;
149
+ });
145
150
  }));
151
+ router.use(http.prefix + http.route, useBase("", subRouter.handler));
146
152
  }
147
153
  }
148
154
  }
@@ -1,8 +1,8 @@
1
1
  import { Context, Hono, MiddlewareHandler } from 'hono';
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 HonoCtx extends HttpContext {
@@ -10,7 +10,7 @@ interface HonoCtx extends HttpContext {
10
10
  context: Context;
11
11
  app: Hono;
12
12
  }
13
- type Plugin = MiddlewareHandler;
13
+ type Addon = MiddlewareHandler;
14
14
  declare function bind(router: Hono, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
15
 
16
- export { type HonoCtx, type Plugin, bind };
16
+ export { type Addon, type HonoCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { Context, Hono, MiddlewareHandler } from 'hono';
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 HonoCtx extends HttpContext {
@@ -10,7 +10,7 @@ interface HonoCtx extends HttpContext {
10
10
  context: Context;
11
11
  app: Hono;
12
12
  }
13
- type Plugin = MiddlewareHandler;
13
+ type Addon = MiddlewareHandler;
14
14
  declare function bind(router: Hono, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
15
15
 
16
- export { type HonoCtx, type Plugin, bind };
16
+ export { type Addon, type HonoCtx, bind };