phecda-server 6.0.2 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/bin/cli.mjs +160 -157
  2. package/dist/{chunk-HDQAT2IM.mjs → chunk-5622RBNB.mjs} +118 -90
  3. package/dist/chunk-BGXSMOLX.js +265 -0
  4. package/dist/{chunk-F3W3NN7F.mjs → chunk-HMVLXNV3.mjs} +5 -14
  5. package/dist/{chunk-GHFSIZUO.js → chunk-J5CFUN4V.js} +18 -3
  6. package/dist/{chunk-XCND2QW3.js → chunk-MBCHNDAY.js} +27 -36
  7. package/dist/{chunk-WXFZZZRY.mjs → chunk-P75VKZJY.mjs} +101 -137
  8. package/dist/chunk-SW5IKE5H.js +503 -0
  9. package/dist/{chunk-UXD62LGG.mjs → chunk-WHJ5FALK.mjs} +17 -2
  10. package/dist/core-BIcUwV18.d.mts +47 -0
  11. package/dist/core-CYwEPfN4.d.ts +47 -0
  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 +53 -41
  45. package/dist/index.d.ts +53 -41
  46. package/dist/index.js +62 -78
  47. package/dist/index.mjs +46 -62
  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 +24 -24
  79. package/dist/chunk-7SYPUIBY.js +0 -539
  80. package/dist/chunk-LYEZ6RGX.js +0 -237
  81. package/dist/core-2SNw8m2B.d.mts +0 -30
  82. package/dist/core-BmJJLUqj.d.ts +0 -30
  83. package/dist/server/h3/index.js +0 -154
@@ -4,55 +4,61 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk7SYPUIBYjs = require('../../chunk-7SYPUIBY.js');
7
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
8
8
 
9
9
 
10
- var _chunkGHFSIZUOjs = require('../../chunk-GHFSIZUO.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 = _chunk7SYPUIBYjs.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
- _chunk7SYPUIBYjs.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
- _chunk7SYPUIBYjs.Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
35
+ function registerRoute() {
37
36
  if (parallelRoute) {
38
- router.post(parallelRoute, ..._chunk7SYPUIBYjs.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 _chunk7SYPUIBYjs.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
- _chunkGHFSIZUOjs.__name.call(void 0, errorHandler, "errorHandler");
46
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk7SYPUIBYjs.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 _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.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 _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.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
- ..._chunk7SYPUIBYjs.argToReq.call(void 0, params, item.args, c.req.header()),
67
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
68
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
69
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
70
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
71
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__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__ */ _chunkGHFSIZUOjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
75
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => c.req.raw, "getRequest"),
76
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__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, _chunk7SYPUIBYjs.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, ..._chunk7SYPUIBYjs.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__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _cookie.getCookie.call(void 0, c, key), "getCookie"),
115
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => _cookie.deleteCookie.call(void 0, c, key), "delCookie"),
116
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => _cookie.setCookie.call(void 0, c, key, value, opts2), "setCookie"),
117
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url) => c.redirect(url), "redirect"),
118
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__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__ */ _chunkGHFSIZUOjs.__name.call(void 0, (status) => c.status(status), "setResStatus"),
122
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => c.req.raw, "getRequest"),
123
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__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, _chunk7SYPUIBYjs.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
- _chunkGHFSIZUOjs.__name.call(void 0, registerRoute, "registerRoute");
161
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
147
162
  }
148
- _chunkGHFSIZUOjs.__name.call(void 0, bind, "bind");
163
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
149
164
 
150
165
 
151
166
  exports.bind = bind;
@@ -4,17 +4,18 @@ import {
4
4
  argToReq,
5
5
  createControllerMetaMap,
6
6
  detectAopDep
7
- } from "../../chunk-WXFZZZRY.mjs";
7
+ } from "../../chunk-P75VKZJY.mjs";
8
8
  import {
9
9
  __name
10
- } from "../../chunk-UXD62LGG.mjs";
10
+ } from "../../chunk-WHJ5FALK.mjs";
11
11
 
12
- // src/server/hono/bind.ts
12
+ // src/http/hono/bind.ts
13
13
  import Debug from "debug";
14
+ import { Hono } from "hono";
14
15
  import { deleteCookie, getCookie, setCookie } from "hono/cookie";
15
16
  var debug = Debug("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
20
  const metaMap = createControllerMetaMap(meta, (meta2) => {
20
21
  const { controller, http, func, tag } = meta2.data;
@@ -24,18 +25,18 @@ function bind(router, data, opts = {}) {
24
25
  }
25
26
  });
26
27
  detectAopDep(meta, {
27
- plugins: [
28
- ...globalPlugins,
29
- ...parallelPlugins
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
- Context.usePlugin(globalPlugins, "hono").forEach((p) => router.use(p));
35
+ function registerRoute() {
37
36
  if (parallelRoute) {
38
- router.post(parallelRoute, ...Context.usePlugin(parallelPlugins, "hono"), async (c) => {
37
+ const subApp = new Hono();
38
+ 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
42
  const error = await Context.filterRecord.default(e);
@@ -53,6 +54,11 @@ function bind(router, data, opts = {}) {
53
54
  const meta2 = metaMap.get(tag)[func];
54
55
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
55
56
  const { data: { params } } = meta2;
57
+ const aop = Context.getAop(meta2, {
58
+ globalFilter,
59
+ globalGuards,
60
+ globalPipe
61
+ });
56
62
  const contextData = {
57
63
  type: "hono",
58
64
  parallel: true,
@@ -76,12 +82,7 @@ function bind(router, data, opts = {}) {
76
82
  getResponse: /* @__PURE__ */ __name(() => c.res, "getResponse")
77
83
  };
78
84
  const context = new Context(contextData);
79
- context.run({
80
- globalGuards,
81
- globalInterceptors,
82
- globalFilter,
83
- globalPipe
84
- }, resolve, resolve);
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 (!http?.type) continue;
99
101
  const needBody = params.some((item) => item.type === "body");
100
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "hono"), async (c) => {
102
+ let aop;
103
+ if (!dynamic) {
104
+ aop = Context.getAop(meta2, {
105
+ globalFilter,
106
+ globalGuards,
107
+ globalPipe
108
+ });
109
+ }
110
+ const subApp = new Hono();
111
+ 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",
@@ -126,12 +138,14 @@ function bind(router, data, opts = {}) {
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 = 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,6 +154,7 @@ 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
  }
@@ -1,8 +1,8 @@
1
1
  import { Request, Response, Router, MiddlewareHandler } from 'hyper-express';
2
- import { H as HttpContext, a as HttpOptions } from '../../types-BvD3B5Ny.mjs';
3
- import { F as Factory } from '../../core-2SNw8m2B.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 HyperExpressCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface HyperExpressCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = MiddlewareHandler;
15
+ type Addon = MiddlewareHandler;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type HyperExpressCtx, type Plugin, bind };
18
+ export { type Addon, type HyperExpressCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { Request, Response, Router, MiddlewareHandler } from 'hyper-express';
2
- import { H as HttpContext, a as HttpOptions } from '../../types-DIw7B6Up.js';
3
- import { F as Factory } from '../../core-BmJJLUqj.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 HyperExpressCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface HyperExpressCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = MiddlewareHandler;
15
+ type Addon = MiddlewareHandler;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type HyperExpressCtx, type Plugin, bind };
18
+ export { type Addon, type HyperExpressCtx, bind };
@@ -4,55 +4,59 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk7SYPUIBYjs = require('../../chunk-7SYPUIBY.js');
7
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
8
8
 
9
9
 
10
- var _chunkGHFSIZUOjs = require('../../chunk-GHFSIZUO.js');
10
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
11
11
 
12
- // src/server/hyper-express/bind.ts
12
+ // src/http/hyper-express/bind.ts
13
+ var _hyperexpress = require('hyper-express');
13
14
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
14
15
  var debug = _debug2.default.call(void 0, "phecda-server/hyper-express");
15
16
  function bind(router, data, opts = {}) {
16
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
17
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
17
18
  const { moduleMap, meta } = data;
18
- const metaMap = _chunk7SYPUIBYjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
19
+ const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
19
20
  const { controller, http, func, tag } = meta2.data;
20
21
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
21
22
  debug(`register method "${func}" in module "${tag}"`);
22
23
  return true;
23
24
  }
24
25
  });
25
- _chunk7SYPUIBYjs.detectAopDep.call(void 0, meta, {
26
- plugins: [
27
- ...globalPlugins,
28
- ...parallelPlugins
26
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
27
+ addons: [
28
+ ...globalAddons,
29
+ ...parallelAddons
29
30
  ],
30
- guards: globalGuards,
31
- interceptors: globalInterceptors
31
+ guards: globalGuards
32
32
  });
33
33
  registerRoute();
34
34
  async function registerRoute() {
35
- _chunk7SYPUIBYjs.Context.usePlugin(globalPlugins, "hyper-express").forEach((p) => router.use(p));
35
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "hyper-express");
36
36
  if (parallelRoute) {
37
- router.post(parallelRoute, {
38
- middlewares: _chunk7SYPUIBYjs.Context.usePlugin(parallelPlugins, "hyper-express")
39
- }, async (req, res, next) => {
37
+ const subRouter = new (0, _hyperexpress.Router)();
38
+ subRouter.post(parallelRoute, async (req, res, next) => {
40
39
  const body = await req.json();
41
40
  async function errorHandler(e) {
42
- const error = await _chunk7SYPUIBYjs.Context.filterRecord.default(e);
41
+ const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
43
42
  return res.status(error.status).json(error);
44
43
  }
45
- _chunkGHFSIZUOjs.__name.call(void 0, errorHandler, "errorHandler");
46
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk7SYPUIBYjs.BadRequestException)("data format should be an array"));
44
+ _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
45
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
47
46
  try {
48
47
  return Promise.all(body.map((item, i) => {
49
48
  return new Promise(async (resolve) => {
50
49
  const { tag, func } = item;
51
50
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
52
- if (!metaMap.has(tag)) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`module "${tag}" doesn't exist`)));
51
+ if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
53
52
  const meta2 = metaMap.get(tag)[func];
54
- if (!meta2) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
53
+ if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
55
54
  const { data: { params } } = meta2;
55
+ const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
56
+ globalFilter,
57
+ globalGuards,
58
+ globalPipe
59
+ });
56
60
  const contextData = {
57
61
  type: "hyper-express",
58
62
  parallel: true,
@@ -63,25 +67,20 @@ function bind(router, data, opts = {}) {
63
67
  moduleMap,
64
68
  tag,
65
69
  func,
66
- next,
67
70
  app: router,
68
- ..._chunk7SYPUIBYjs.argToReq.call(void 0, params, item.args, req.headers),
69
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
70
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _2 => _2.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
71
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
72
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
73
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
74
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
75
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
76
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
71
+ ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, req.headers),
72
+ next,
73
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
74
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _2 => _2.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
75
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
76
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
77
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
78
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
79
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
80
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
77
81
  };
78
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
79
- context.run({
80
- globalGuards,
81
- globalInterceptors,
82
- globalFilter,
83
- globalPipe
84
- }, resolve, resolve);
82
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
83
+ context.run(aop, resolve, resolve);
85
84
  });
86
85
  })).then((ret) => {
87
86
  res.json(ret);
@@ -90,14 +89,25 @@ function bind(router, data, opts = {}) {
90
89
  return errorHandler(e);
91
90
  }
92
91
  });
92
+ router.use(subRouter);
93
93
  }
94
94
  for (const [tag, record] of metaMap) {
95
95
  for (const func in record) {
96
96
  const meta2 = metaMap.get(tag)[func];
97
- const { data: { params, plugins, http } } = meta2;
97
+ const { data: { params, addons, http } } = meta2;
98
98
  if (!_optionalChain([http, 'optionalAccess', _3 => _3.type])) continue;
99
99
  const needBody = params.some((item) => item.type === "body");
100
- router[http.type](http.prefix + http.route, ..._chunk7SYPUIBYjs.Context.usePlugin(plugins, "hyper-express"), async (req, res, next) => {
100
+ let aop;
101
+ if (!dynamic) {
102
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
103
+ globalFilter,
104
+ globalGuards,
105
+ globalPipe
106
+ });
107
+ }
108
+ const subRouter = new (0, _hyperexpress.Router)();
109
+ _chunkSW5IKE5Hjs.Context.applyAddons(addons, subRouter, "hyper-express");
110
+ subRouter[http.type](http.prefix + http.route, async (req, res, next) => {
101
111
  debug(`invoke method "${func}" in module "${tag}"`);
102
112
  const contextData = {
103
113
  type: "hyper-express",
@@ -113,25 +123,27 @@ function bind(router, data, opts = {}) {
113
123
  params: req.path_parameters,
114
124
  headers: req.headers,
115
125
  next,
116
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
117
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _4 => _4.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
118
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
119
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
120
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
121
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
122
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
123
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
126
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
127
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, _optionalChain([opts2, 'optionalAccess', _4 => _4.expires]) && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
128
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
129
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
130
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
131
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
132
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
133
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
124
134
  };
125
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
135
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
126
136
  if (http.headers) {
127
137
  for (const name in http.headers) res.set(name, http.headers[name]);
128
138
  }
129
- await context.run({
130
- globalGuards,
131
- globalInterceptors,
132
- globalFilter,
133
- globalPipe
134
- }, (returnData) => {
139
+ if (dynamic) {
140
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
141
+ globalFilter,
142
+ globalGuards,
143
+ globalPipe
144
+ });
145
+ }
146
+ await context.run(aop, (returnData) => {
135
147
  if (res.writableEnded) return;
136
148
  if (typeof returnData === "string") res.send(returnData);
137
149
  else res.json(returnData);
@@ -140,12 +152,13 @@ function bind(router, data, opts = {}) {
140
152
  res.status(err.status).json(err);
141
153
  });
142
154
  });
155
+ router.use(subRouter);
143
156
  }
144
157
  }
145
158
  }
146
- _chunkGHFSIZUOjs.__name.call(void 0, registerRoute, "registerRoute");
159
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
147
160
  }
148
- _chunkGHFSIZUOjs.__name.call(void 0, bind, "bind");
161
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
149
162
 
150
163
 
151
164
  exports.bind = bind;