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
@@ -4,17 +4,18 @@ 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/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-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 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-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 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 _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/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 = _chunkDVTBLV6Ijs.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
- _chunkDVTBLV6Ijs.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
- _chunkDVTBLV6Ijs.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: _chunkDVTBLV6Ijs.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 _chunkDVTBLV6Ijs.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
- _chunkTVT62GIXjs.__name.call(void 0, errorHandler, "errorHandler");
46
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkDVTBLV6Ijs.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 _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.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 _chunkDVTBLV6Ijs.Context.filterRecord.default(new (0, _chunkDVTBLV6Ijs.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
- ..._chunkDVTBLV6Ijs.argToReq.call(void 0, params, item.args, req.headers),
69
- getCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
70
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__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__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
72
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
73
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
74
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
75
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => req, "getRequest"),
76
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__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, _chunkDVTBLV6Ijs.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, ..._chunkDVTBLV6Ijs.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__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
117
- setCookie: /* @__PURE__ */ _chunkTVT62GIXjs.__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__ */ _chunkTVT62GIXjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
119
- redirect: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (url) => res.redirect(url), "redirect"),
120
- setResHeaders: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
121
- setResStatus: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
122
- getRequest: /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, () => req, "getRequest"),
123
- getResponse: /* @__PURE__ */ _chunkTVT62GIXjs.__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, _chunkDVTBLV6Ijs.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
- _chunkTVT62GIXjs.__name.call(void 0, registerRoute, "registerRoute");
159
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
147
160
  }
148
- _chunkTVT62GIXjs.__name.call(void 0, bind, "bind");
161
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
149
162
 
150
163
 
151
164
  exports.bind = bind;
@@ -4,16 +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/hyper-express/bind.ts
12
+ // src/http/hyper-express/bind.ts
13
+ import { Router } from "hyper-express";
13
14
  import Debug from "debug";
14
15
  var debug = Debug("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
19
  const metaMap = createControllerMetaMap(meta, (meta2) => {
19
20
  const { controller, http, func, tag } = meta2.data;
@@ -23,20 +24,18 @@ function bind(router, data, opts = {}) {
23
24
  }
24
25
  });
25
26
  detectAopDep(meta, {
26
- plugins: [
27
- ...globalPlugins,
28
- ...parallelPlugins
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
- Context.usePlugin(globalPlugins, "hyper-express").forEach((p) => router.use(p));
35
+ Context.applyAddons(globalAddons, router, "hyper-express");
36
36
  if (parallelRoute) {
37
- router.post(parallelRoute, {
38
- middlewares: Context.usePlugin(parallelPlugins, "hyper-express")
39
- }, async (req, res, next) => {
37
+ const subRouter = new Router();
38
+ subRouter.post(parallelRoute, async (req, res, next) => {
40
39
  const body = await req.json();
41
40
  async function errorHandler(e) {
42
41
  const error = await Context.filterRecord.default(e);
@@ -53,6 +52,11 @@ function bind(router, data, opts = {}) {
53
52
  const meta2 = metaMap.get(tag)[func];
54
53
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
55
54
  const { data: { params } } = meta2;
55
+ const aop = Context.getAop(meta2, {
56
+ globalFilter,
57
+ globalGuards,
58
+ globalPipe
59
+ });
56
60
  const contextData = {
57
61
  type: "hyper-express",
58
62
  parallel: true,
@@ -63,9 +67,9 @@ function bind(router, data, opts = {}) {
63
67
  moduleMap,
64
68
  tag,
65
69
  func,
66
- next,
67
70
  app: router,
68
71
  ...argToReq(params, item.args, req.headers),
72
+ next,
69
73
  getCookie: /* @__PURE__ */ __name((key) => req.cookies[key], "getCookie"),
70
74
  setCookie: /* @__PURE__ */ __name((key, value, opts2) => res.cookie(key, value, opts2?.expires && opts2.expires.getTime() - Date.now(), opts2 || {}), "setCookie"),
71
75
  delCookie: /* @__PURE__ */ __name((key) => res.clearCookie(key), "delCookie"),
@@ -76,12 +80,7 @@ function bind(router, data, opts = {}) {
76
80
  getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
77
81
  };
78
82
  const context = new Context(contextData);
79
- context.run({
80
- globalGuards,
81
- globalInterceptors,
82
- globalFilter,
83
- globalPipe
84
- }, resolve, resolve);
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 (!http?.type) continue;
99
99
  const needBody = params.some((item) => item.type === "body");
100
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "hyper-express"), async (req, res, next) => {
100
+ let aop;
101
+ if (!dynamic) {
102
+ aop = Context.getAop(meta2, {
103
+ globalFilter,
104
+ globalGuards,
105
+ globalPipe
106
+ });
107
+ }
108
+ const subRouter = new Router();
109
+ 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",
@@ -126,12 +136,14 @@ function bind(router, data, opts = {}) {
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 = 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,6 +152,7 @@ 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
  }
@@ -1,9 +1,9 @@
1
1
  import Router, { RouterParamContext } from '@koa/router';
2
2
  import { DefaultContext, DefaultState } from 'koa';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-BvD3B5Ny.mjs';
4
- import { F as Factory } from '../../core-P1CsH6jz.mjs';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-h40T3cRG.mjs';
4
+ import { F as Factory } from '../../core-BIcUwV18.mjs';
5
5
  import 'node:http';
6
- import '../../meta-KtfiBIde.mjs';
6
+ import '../../meta-BXKLFTgG.mjs';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface KoaCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface KoaCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = Router.Middleware;
15
+ type Addon = Router.Middleware;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type KoaCtx, type Plugin, bind };
18
+ export { type Addon, type KoaCtx, bind };
@@ -1,9 +1,9 @@
1
1
  import Router, { RouterParamContext } from '@koa/router';
2
2
  import { DefaultContext, DefaultState } from 'koa';
3
- import { H as HttpContext, a as HttpOptions } from '../../types-DIw7B6Up.js';
4
- import { F as Factory } from '../../core-BlN0Spy9.js';
3
+ import { H as HttpContext, a as HttpOptions } from '../../types-VFzEM7LL.js';
4
+ import { F as Factory } from '../../core-CYwEPfN4.js';
5
5
  import 'node:http';
6
- import '../../meta-KtfiBIde.js';
6
+ import '../../meta-BXKLFTgG.js';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface KoaCtx extends HttpContext {
@@ -12,7 +12,7 @@ interface KoaCtx extends HttpContext {
12
12
  next: Function;
13
13
  app: Router;
14
14
  }
15
- type Plugin = Router.Middleware;
15
+ type Addon = Router.Middleware;
16
16
  declare function bind(router: Router, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions): void;
17
17
 
18
- export { type KoaCtx, type Plugin, bind };
18
+ export { type Addon, type KoaCtx, bind };