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
@@ -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 _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.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 = _chunkSW5IKE5Hjs.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
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
27
+ addons: [
28
+ ...globalAddons,
29
+ ...parallelAddons
30
+ ],
31
+ guards: globalGuards
32
+ });
33
+ registerRoute();
34
+ function registerRoute() {
35
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "h3");
36
+ if (parallelRoute) {
37
+ const subRouter = _h3.createRouter.call(void 0, );
38
+ _chunkSW5IKE5Hjs.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 _chunkSW5IKE5Hjs.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, _chunkSW5IKE5Hjs.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 _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
57
+ const meta2 = metaMap.get(tag)[func];
58
+ if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
+ const { data: { params } } = meta2;
60
+ const aop = _chunkSW5IKE5Hjs.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
+ ..._chunkSW5IKE5Hjs.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, _chunkSW5IKE5Hjs.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 = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
105
+ globalFilter,
106
+ globalGuards,
107
+ globalPipe
108
+ });
109
+ }
110
+ const subRouter = _h3.createRouter.call(void 0, );
111
+ _chunkSW5IKE5Hjs.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, _chunkSW5IKE5Hjs.Context)(contextData);
138
+ _h3.setHeaders.call(void 0, event, http.headers || {});
139
+ if (dynamic) {
140
+ aop = _chunkSW5IKE5Hjs.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-P75VKZJY.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 };
@@ -4,55 +4,61 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkDVTBLV6Ijs = require('../../chunk-DVTBLV6I.js');
7
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
8
8
 
9
9
 
10
- var _chunkTVT62GIXjs = require('../../chunk-TVT62GIX.js');
10
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
11
11
 
12
- // src/server/hono/bind.ts
12
+ // src/http/hono/bind.ts
13
13
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
+ var _hono = require('hono');
14
15
  var _cookie = require('hono/cookie');
15
16
  var debug = _debug2.default.call(void 0, "phecda-server/hono");
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
- const metaMap = _chunkDVTBLV6Ijs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
21
  const { controller, http, func, tag } = meta2.data;
21
22
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
22
23
  debug(`register method "${func}" in module "${tag}"`);
23
24
  return true;
24
25
  }
25
26
  });
26
- _chunkDVTBLV6Ijs.detectAopDep.call(void 0, meta, {
27
- plugins: [
28
- ...globalPlugins,
29
- ...parallelPlugins
27
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
28
+ addons: [
29
+ ...globalAddons,
30
+ ...parallelAddons
30
31
  ],
31
- guards: globalGuards,
32
- interceptors: globalInterceptors
32
+ guards: globalGuards
33
33
  });
34
34
  registerRoute();
35
- async function registerRoute() {
36
- _chunkDVTBLV6Ijs.Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
35
+ function registerRoute() {
37
36
  if (parallelRoute) {
38
- router.post(parallelRoute, ..._chunkDVTBLV6Ijs.Context.usePlugin(parallelPlugins, "hono"), async (c) => {
37
+ const subApp = new (0, _hono.Hono)();
38
+ _chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, subApp, "hono");
39
+ subApp.post("", async (c) => {
39
40
  const body = await c.req.json();
40
41
  async function errorHandler(e) {
41
- const error = await _chunkDVTBLV6Ijs.Context.filterRecord.default(e);
42
+ const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
42
43
  c.status(error.status);
43
44
  return c.json(error);
44
45
  }
45
- _chunkTVT62GIXjs.__name.call(void 0, errorHandler, "errorHandler");
46
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkDVTBLV6Ijs.BadRequestException)("data format should be an array"));
46
+ _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
47
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
47
48
  try {
48
49
  return Promise.all(body.map((item, i) => {
49
50
  return new Promise(async (resolve) => {
50
51
  const { tag, func } = item;
51
52
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
52
- if (!metaMap.has(tag)) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`module "${tag}" doesn't exist`)));
53
+ if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
53
54
  const meta2 = metaMap.get(tag)[func];
54
- if (!meta2) return resolve(await _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
55
+ if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
55
56
  const { data: { params } } = meta2;
57
+ const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
58
+ globalFilter,
59
+ globalGuards,
60
+ globalPipe
61
+ });
56
62
  const contextData = {
57
63
  type: "hono",
58
64
  parallel: true,
@@ -63,25 +69,20 @@ function bind(router, data, opts = {}) {
63
69
  tag,
64
70
  func,
65
71
  app: router,
66
- ..._chunkDVTBLV6Ijs.argToReq.call(void 0, params, item.args, c.req.header()),
67
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
68
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
69
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
70
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
71
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => {
72
+ ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, c.req.header()),
73
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
74
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
75
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
76
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
77
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => {
72
78
  for (const name in headers) c.header(name, headers[name]);
73
79
  }, "setResHeaders"),
74
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
75
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => c.req.raw, "getRequest"),
76
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => c.res, "getResponse")
80
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
81
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.req.raw, "getRequest"),
82
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.res, "getResponse")
77
83
  };
78
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
79
- context.run({
80
- globalGuards,
81
- globalInterceptors,
82
- globalFilter,
83
- globalPipe
84
- }, resolve, resolve);
84
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
85
+ context.run(aop, resolve, resolve);
85
86
  });
86
87
  })).then((ret) => {
87
88
  return c.json(ret);
@@ -90,14 +91,25 @@ function bind(router, data, opts = {}) {
90
91
  return errorHandler(e);
91
92
  }
92
93
  });
94
+ router.route(parallelRoute, subApp);
93
95
  }
94
96
  for (const [tag, record] of metaMap) {
95
97
  for (const func in record) {
96
98
  const meta2 = metaMap.get(tag)[func];
97
- const { data: { params, plugins, http } } = meta2;
99
+ const { data: { params, addons, http } } = meta2;
98
100
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
99
101
  const needBody = params.some((item) => item.type === "body");
100
- router[http.type](http.prefix + http.route, ..._chunkDVTBLV6Ijs.Context.usePlugin(plugins, "hono"), async (c) => {
102
+ let aop;
103
+ if (!dynamic) {
104
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
105
+ globalFilter,
106
+ globalGuards,
107
+ globalPipe
108
+ });
109
+ }
110
+ const subApp = new (0, _hono.Hono)();
111
+ _chunkSW5IKE5Hjs.Context.applyAddons(addons, subApp, "hono");
112
+ subApp[http.type](http.route, async (c) => {
101
113
  debug(`invoke method "${func}" in module "${tag}"`);
102
114
  const contextData = {
103
115
  type: "hono",
@@ -111,27 +123,29 @@ function bind(router, data, opts = {}) {
111
123
  params: c.req.param(),
112
124
  headers: c.req.header(),
113
125
  app: router,
114
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
115
- delCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
116
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
117
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
118
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => {
126
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
127
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
128
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
129
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
130
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => {
119
131
  for (const name in headers) c.header(name, headers[name]);
120
132
  }, "setResHeaders"),
121
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
122
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => c.req.raw, "getRequest"),
123
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => c.res, "getResponse")
133
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
134
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.req.raw, "getRequest"),
135
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => c.res, "getResponse")
124
136
  };
125
- const context = new (0, _chunkDVTBLV6Ijs.Context)(contextData);
137
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
126
138
  if (http.headers) {
127
139
  for (const name in http.headers) c.header(name, http.headers[name]);
128
140
  }
129
- return context.run({
130
- globalGuards,
131
- globalInterceptors,
132
- globalFilter,
133
- globalPipe
134
- }, (returnData) => {
141
+ if (dynamic) {
142
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
143
+ globalFilter,
144
+ globalGuards,
145
+ globalPipe
146
+ });
147
+ }
148
+ return context.run(aop, (returnData) => {
135
149
  if (returnData instanceof Response) return returnData;
136
150
  if (typeof returnData === "string") return c.text(returnData);
137
151
  else return c.json(returnData);
@@ -140,12 +154,13 @@ function bind(router, data, opts = {}) {
140
154
  return c.json(err);
141
155
  });
142
156
  });
157
+ router.route(http.prefix, subApp);
143
158
  }
144
159
  }
145
160
  }
146
- _chunkTVT62GIXjs.__name.call(void 0, registerRoute, "registerRoute");
161
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
147
162
  }
148
- _chunkTVT62GIXjs.__name.call(void 0, bind, "bind");
163
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
149
164
 
150
165
 
151
166
  exports.bind = bind;