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
@@ -5,58 +5,65 @@
5
5
 
6
6
 
7
7
 
8
- var _chunk7SYPUIBYjs = require('../../chunk-7SYPUIBY.js');
8
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
9
9
 
10
10
 
11
- var _chunkGHFSIZUOjs = require('../../chunk-GHFSIZUO.js');
11
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
12
12
 
13
- // src/server/express/bind.ts
13
+ // src/http/express/bind.ts
14
+ var _express = require('express');
14
15
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
15
16
  var debug = _debug2.default.call(void 0, "phecda-server/express");
16
17
  function bind(router, data, opts = {}) {
17
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
18
19
  const { moduleMap, meta } = data;
19
20
  const originStack = router.stack.slice(0, router.stack.length);
20
- const metaMap = _chunk7SYPUIBYjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
22
  const { controller, http, func, tag } = meta2.data;
22
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
23
24
  debug(`register method "${func}" in module "${tag}"`);
24
25
  return true;
25
26
  }
26
27
  });
27
- _chunk7SYPUIBYjs.detectAopDep.call(void 0, meta, {
28
- plugins: [
29
- ...globalPlugins,
30
- ...parallelPlugins
28
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
29
+ addons: [
30
+ ...globalAddons,
31
+ ...parallelAddons
31
32
  ],
32
- guards: globalGuards,
33
- interceptors: globalInterceptors
33
+ guards: globalGuards
34
34
  });
35
35
  registerRoute();
36
- _chunk7SYPUIBYjs.HMR.call(void 0, async () => {
36
+ _chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
37
37
  router.stack = originStack;
38
38
  registerRoute();
39
39
  });
40
- async function registerRoute() {
41
- _chunk7SYPUIBYjs.Context.usePlugin(globalPlugins, "express").forEach((p) => router.use(p));
40
+ function registerRoute() {
41
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "express");
42
42
  if (parallelRoute) {
43
- router.post(parallelRoute, ..._chunk7SYPUIBYjs.Context.usePlugin(parallelPlugins, "express"), async (req, res, next) => {
43
+ const subRouter = _express.Router.call(void 0, );
44
+ _chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, subRouter, "express");
45
+ subRouter.use(async (req, res, next) => {
44
46
  const { body } = req;
45
47
  async function errorHandler(e) {
46
- const error = await _chunk7SYPUIBYjs.Context.filterRecord.default(e);
48
+ const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
47
49
  return res.status(error.status).json(error);
48
50
  }
49
- _chunkGHFSIZUOjs.__name.call(void 0, errorHandler, "errorHandler");
50
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk7SYPUIBYjs.BadRequestException)("data format should be an array"));
51
+ _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
52
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
51
53
  try {
52
54
  return Promise.all(body.map((item, i) => {
53
55
  return new Promise(async (resolve) => {
54
56
  const { tag, func } = item;
55
57
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
56
- if (!metaMap.has(tag)) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
+ if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
57
59
  const meta2 = metaMap.get(tag)[func];
58
- if (!meta2) return resolve(await _chunk7SYPUIBYjs.Context.filterRecord.default(new (0, _chunk7SYPUIBYjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
+ if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
59
61
  const { data: { params } } = meta2;
62
+ const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
63
+ globalFilter,
64
+ globalGuards,
65
+ globalPipe
66
+ });
60
67
  const contextData = {
61
68
  type: "express",
62
69
  parallel: true,
@@ -69,25 +76,20 @@ function bind(router, data, opts = {}) {
69
76
  func,
70
77
  next,
71
78
  app: router,
72
- ..._chunk7SYPUIBYjs.argToReq.call(void 0, params, item.args, req.headers),
73
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
74
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
75
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.cookie(key, "", {
79
+ ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, req.headers),
80
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
81
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
82
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.cookie(key, "", {
76
83
  expires: /* @__PURE__ */ new Date(0)
77
84
  }), "delCookie"),
78
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
79
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
80
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
81
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
82
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
85
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
86
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
87
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
88
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
89
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
83
90
  };
84
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
85
- context.run({
86
- globalGuards,
87
- globalInterceptors,
88
- globalFilter,
89
- globalPipe
90
- }, resolve, resolve);
91
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
92
+ context.run(aop, resolve, resolve);
91
93
  });
92
94
  })).then((ret) => {
93
95
  res.json(ret);
@@ -96,13 +98,24 @@ function bind(router, data, opts = {}) {
96
98
  return errorHandler(e);
97
99
  }
98
100
  });
101
+ router.post(parallelRoute, subRouter);
99
102
  }
100
103
  for (const [tag, record] of metaMap) {
101
104
  for (const func in record) {
102
105
  const meta2 = metaMap.get(tag)[func];
103
- const { data: { plugins, http } } = meta2;
106
+ const { data: { addons, http } } = meta2;
104
107
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
105
- router[http.type](http.prefix + http.route, ..._chunk7SYPUIBYjs.Context.usePlugin(plugins, "express"), async (req, res, next) => {
108
+ let aop;
109
+ if (!dynamic) {
110
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
111
+ globalFilter,
112
+ globalGuards,
113
+ globalPipe
114
+ });
115
+ }
116
+ const subRouter = _express.Router.call(void 0, );
117
+ _chunkSW5IKE5Hjs.Context.applyAddons(addons, subRouter, "express");
118
+ subRouter[http.type](http.prefix + http.route, async (req, res, next) => {
106
119
  debug(`invoke method "${func}" in module "${tag}"`);
107
120
  const contextData = {
108
121
  type: "express",
@@ -118,25 +131,27 @@ function bind(router, data, opts = {}) {
118
131
  headers: req.headers,
119
132
  app: router,
120
133
  next,
121
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
122
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
123
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.cookie(key, "", {
134
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
135
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.cookie(key, value, opts2 || {}), "setCookie"),
136
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.cookie(key, "", {
124
137
  expires: /* @__PURE__ */ new Date(0)
125
138
  }), "delCookie"),
126
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
127
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
128
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
129
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
130
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
139
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => status ? res.redirect(status, url) : res.redirect(url), "redirect"),
140
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.set(headers), "setResHeaders"),
141
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
142
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req, "getRequest"),
143
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res, "getResponse")
131
144
  };
132
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
145
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
133
146
  if (http.headers) res.set(http.headers);
134
- await context.run({
135
- globalGuards,
136
- globalInterceptors,
137
- globalFilter,
138
- globalPipe
139
- }, (returnData) => {
147
+ if (dynamic) {
148
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
149
+ globalFilter,
150
+ globalGuards,
151
+ globalPipe
152
+ });
153
+ }
154
+ await context.run(aop, (returnData) => {
140
155
  if (res.writableEnded) return;
141
156
  if (typeof returnData === "string") res.send(returnData);
142
157
  else res.json(returnData);
@@ -145,12 +160,13 @@ function bind(router, data, opts = {}) {
145
160
  res.status(err.status).json(err);
146
161
  });
147
162
  });
163
+ router.use(subRouter);
148
164
  }
149
165
  }
150
166
  }
151
- _chunkGHFSIZUOjs.__name.call(void 0, registerRoute, "registerRoute");
167
+ _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
152
168
  }
153
- _chunkGHFSIZUOjs.__name.call(void 0, bind, "bind");
169
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
154
170
 
155
171
 
156
172
  exports.bind = bind;
@@ -5,16 +5,17 @@ import {
5
5
  argToReq,
6
6
  createControllerMetaMap,
7
7
  detectAopDep
8
- } from "../../chunk-WXFZZZRY.mjs";
8
+ } from "../../chunk-P75VKZJY.mjs";
9
9
  import {
10
10
  __name
11
- } from "../../chunk-UXD62LGG.mjs";
11
+ } from "../../chunk-WHJ5FALK.mjs";
12
12
 
13
- // src/server/express/bind.ts
13
+ // src/http/express/bind.ts
14
+ import { Router } from "express";
14
15
  import Debug from "debug";
15
16
  var debug = Debug("phecda-server/express");
16
17
  function bind(router, data, opts = {}) {
17
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe } = opts;
18
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
18
19
  const { moduleMap, meta } = data;
19
20
  const originStack = router.stack.slice(0, router.stack.length);
20
21
  const metaMap = createControllerMetaMap(meta, (meta2) => {
@@ -25,22 +26,23 @@ function bind(router, data, opts = {}) {
25
26
  }
26
27
  });
27
28
  detectAopDep(meta, {
28
- plugins: [
29
- ...globalPlugins,
30
- ...parallelPlugins
29
+ addons: [
30
+ ...globalAddons,
31
+ ...parallelAddons
31
32
  ],
32
- guards: globalGuards,
33
- interceptors: globalInterceptors
33
+ guards: globalGuards
34
34
  });
35
35
  registerRoute();
36
36
  HMR(async () => {
37
37
  router.stack = originStack;
38
38
  registerRoute();
39
39
  });
40
- async function registerRoute() {
41
- Context.usePlugin(globalPlugins, "express").forEach((p) => router.use(p));
40
+ function registerRoute() {
41
+ Context.applyAddons(globalAddons, router, "express");
42
42
  if (parallelRoute) {
43
- router.post(parallelRoute, ...Context.usePlugin(parallelPlugins, "express"), async (req, res, next) => {
43
+ const subRouter = Router();
44
+ Context.applyAddons(parallelAddons, subRouter, "express");
45
+ subRouter.use(async (req, res, next) => {
44
46
  const { body } = req;
45
47
  async function errorHandler(e) {
46
48
  const error = await Context.filterRecord.default(e);
@@ -57,6 +59,11 @@ function bind(router, data, opts = {}) {
57
59
  const meta2 = metaMap.get(tag)[func];
58
60
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
59
61
  const { data: { params } } = meta2;
62
+ const aop = Context.getAop(meta2, {
63
+ globalFilter,
64
+ globalGuards,
65
+ globalPipe
66
+ });
60
67
  const contextData = {
61
68
  type: "express",
62
69
  parallel: true,
@@ -82,12 +89,7 @@ function bind(router, data, opts = {}) {
82
89
  getResponse: /* @__PURE__ */ __name(() => res, "getResponse")
83
90
  };
84
91
  const context = new Context(contextData);
85
- context.run({
86
- globalGuards,
87
- globalInterceptors,
88
- globalFilter,
89
- globalPipe
90
- }, resolve, resolve);
92
+ context.run(aop, resolve, resolve);
91
93
  });
92
94
  })).then((ret) => {
93
95
  res.json(ret);
@@ -96,13 +98,24 @@ function bind(router, data, opts = {}) {
96
98
  return errorHandler(e);
97
99
  }
98
100
  });
101
+ router.post(parallelRoute, subRouter);
99
102
  }
100
103
  for (const [tag, record] of metaMap) {
101
104
  for (const func in record) {
102
105
  const meta2 = metaMap.get(tag)[func];
103
- const { data: { plugins, http } } = meta2;
106
+ const { data: { addons, http } } = meta2;
104
107
  if (!http?.type) continue;
105
- router[http.type](http.prefix + http.route, ...Context.usePlugin(plugins, "express"), async (req, res, next) => {
108
+ let aop;
109
+ if (!dynamic) {
110
+ aop = Context.getAop(meta2, {
111
+ globalFilter,
112
+ globalGuards,
113
+ globalPipe
114
+ });
115
+ }
116
+ const subRouter = Router();
117
+ Context.applyAddons(addons, subRouter, "express");
118
+ subRouter[http.type](http.prefix + http.route, async (req, res, next) => {
106
119
  debug(`invoke method "${func}" in module "${tag}"`);
107
120
  const contextData = {
108
121
  type: "express",
@@ -131,12 +144,14 @@ function bind(router, data, opts = {}) {
131
144
  };
132
145
  const context = new Context(contextData);
133
146
  if (http.headers) res.set(http.headers);
134
- await context.run({
135
- globalGuards,
136
- globalInterceptors,
137
- globalFilter,
138
- globalPipe
139
- }, (returnData) => {
147
+ if (dynamic) {
148
+ aop = Context.getAop(meta2, {
149
+ globalFilter,
150
+ globalGuards,
151
+ globalPipe
152
+ });
153
+ }
154
+ await context.run(aop, (returnData) => {
140
155
  if (res.writableEnded) return;
141
156
  if (typeof returnData === "string") res.send(returnData);
142
157
  else res.json(returnData);
@@ -145,6 +160,7 @@ function bind(router, data, opts = {}) {
145
160
  res.status(err.status).json(err);
146
161
  });
147
162
  });
163
+ router.use(subRouter);
148
164
  }
149
165
  }
150
166
  }
@@ -1,8 +1,8 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, FastifyRegisterOptions, FastifyPluginOptions, RouteShorthandOptions } from 'fastify';
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 FastifyCtx extends HttpContext {
@@ -11,10 +11,10 @@ interface FastifyCtx extends HttpContext {
11
11
  response: FastifyReply;
12
12
  app: FastifyInstance;
13
13
  }
14
- type Plugin = FastifyPluginCallback;
14
+ type Addon = FastifyPluginCallback;
15
15
  declare function bind(fastify: FastifyInstance, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions & {
16
16
  fastifyOpts?: FastifyRegisterOptions<FastifyPluginOptions>;
17
17
  }): void;
18
18
  declare function Fastify(opts: RouteShorthandOptions): any;
19
19
 
20
- export { Fastify, type FastifyCtx, type Plugin, bind };
20
+ export { type Addon, Fastify, type FastifyCtx, bind };
@@ -1,8 +1,8 @@
1
1
  import { FastifyRequest, FastifyReply, FastifyInstance, FastifyPluginCallback, FastifyRegisterOptions, FastifyPluginOptions, RouteShorthandOptions } from 'fastify';
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 FastifyCtx extends HttpContext {
@@ -11,10 +11,10 @@ interface FastifyCtx extends HttpContext {
11
11
  response: FastifyReply;
12
12
  app: FastifyInstance;
13
13
  }
14
- type Plugin = FastifyPluginCallback;
14
+ type Addon = FastifyPluginCallback;
15
15
  declare function bind(fastify: FastifyInstance, data: Awaited<ReturnType<typeof Factory>>, opts?: HttpOptions & {
16
16
  fastifyOpts?: FastifyRegisterOptions<FastifyPluginOptions>;
17
17
  }): void;
18
18
  declare function Fastify(opts: RouteShorthandOptions): any;
19
19
 
20
- export { Fastify, type FastifyCtx, type Plugin, bind };
20
+ export { type Addon, Fastify, type FastifyCtx, bind };
@@ -1,66 +1,64 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkXCND2QW3js = require('../../chunk-XCND2QW3.js');
3
+ var _chunkMBCHNDAYjs = require('../../chunk-MBCHNDAY.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunk7SYPUIBYjs = require('../../chunk-7SYPUIBY.js');
10
+ var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
11
11
 
12
12
 
13
- var _chunkGHFSIZUOjs = require('../../chunk-GHFSIZUO.js');
13
+ var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
14
14
 
15
- // src/server/fastify/bind.ts
15
+ // src/http/fastify/bind.ts
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
  var debug = _debug2.default.call(void 0, "phecda-server/fastify");
18
18
  function bind(fastify, data, opts = {}) {
19
- const { globalGuards, globalInterceptors, parallelRoute = "/__PHECDA_SERVER__", globalPlugins = [], parallelPlugins = [], globalFilter, globalPipe, fastifyOpts } = opts;
19
+ const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, fastifyOpts, dynamic = false } = opts;
20
20
  const { moduleMap, meta } = data;
21
- const metaMap = _chunk7SYPUIBYjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
22
  const { controller, http, func, tag } = meta2.data;
23
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _2 => _2.type])) {
24
24
  debug(`register method "${func}" in module "${tag}"`);
25
25
  return true;
26
26
  }
27
27
  });
28
- _chunk7SYPUIBYjs.detectAopDep.call(void 0, meta, {
29
- plugins: [
30
- ...globalPlugins,
31
- ...parallelPlugins
28
+ _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
29
+ addons: [
30
+ ...globalAddons,
31
+ ...parallelAddons
32
32
  ],
33
- guards: globalGuards,
34
- interceptors: globalInterceptors
33
+ guards: globalGuards
35
34
  });
36
- fastify.register((fastify2, _, done) => {
37
- _chunk7SYPUIBYjs.Context.usePlugin(globalPlugins, "fastify").forEach((p) => {
38
- p[Symbol.for("skip-override")] = true;
39
- fastify2.register(p);
40
- });
41
- fastify2.register((fastify3, _opts, done2) => {
42
- _chunk7SYPUIBYjs.Context.usePlugin(parallelPlugins, "fastify").forEach((p) => {
43
- p[Symbol.for("skip-override")] = true;
44
- fastify3.register(p);
45
- });
46
- if (parallelRoute) {
35
+ fastify.register(async (fastify2, _, done) => {
36
+ _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, fastify2, "fastify");
37
+ if (parallelRoute) {
38
+ fastify2.register(async (fastify3, _opts, done2) => {
39
+ _chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, fastify3, "fastify");
47
40
  fastify3.post(parallelRoute, async (req, res) => {
48
41
  const { body } = req;
49
42
  async function errorHandler(e) {
50
- const error = await _chunk7SYPUIBYjs.Context.filterRecord.default(e);
43
+ const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
51
44
  return res.status(error.status).send(error);
52
45
  }
53
- _chunkGHFSIZUOjs.__name.call(void 0, errorHandler, "errorHandler");
54
- 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"));
55
48
  try {
56
49
  return Promise.all(body.map((item, i) => {
57
50
  return new Promise(async (resolve) => {
58
51
  const { tag, func } = item;
59
52
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
60
- 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`)));
61
54
  const meta2 = metaMap.get(tag)[func];
62
- 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`)));
63
56
  const { data: { params } } = meta2;
57
+ const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
58
+ globalFilter,
59
+ globalGuards,
60
+ globalPipe
61
+ });
64
62
  const contextData = {
65
63
  type: "fastify",
66
64
  parallel: true,
@@ -72,26 +70,21 @@ function bind(fastify, data, opts = {}) {
72
70
  tag,
73
71
  func,
74
72
  app: fastify3,
75
- ..._chunk7SYPUIBYjs.argToReq.call(void 0, params, item.args, req.headers),
73
+ ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, req.headers),
76
74
  // @ts-expect-error need @fastify/cookie
77
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
75
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
78
76
  // @ts-expect-error need @fastify/cookie
79
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.setCookie(key, value, opts2), "setCookie"),
77
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.setCookie(key, value, opts2), "setCookie"),
80
78
  // @ts-expect-error need @fastify/cookie
81
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
82
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url, status) => res.redirect(url, status), "redirect"),
83
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.headers(headers), "setResHeaders"),
84
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
85
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
86
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
79
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key), "delCookie"),
80
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => res.redirect(url, status), "redirect"),
81
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.headers(headers), "setResHeaders"),
82
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
83
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req.raw, "getRequest"),
84
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res.raw, "getResponse")
87
85
  };
88
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
89
- context.run({
90
- globalGuards,
91
- globalInterceptors,
92
- globalFilter,
93
- globalPipe
94
- }, resolve, resolve);
86
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
87
+ context.run(aop, resolve, resolve);
95
88
  });
96
89
  })).then((ret) => {
97
90
  res.send(ret);
@@ -100,19 +93,24 @@ function bind(fastify, data, opts = {}) {
100
93
  return errorHandler(e);
101
94
  }
102
95
  });
103
- }
104
- done2();
105
- });
96
+ done2();
97
+ });
98
+ }
106
99
  for (const [tag, record] of metaMap) {
107
100
  for (const func in record) {
108
101
  const meta2 = metaMap.get(tag)[func];
109
- const { data: { plugins, define, http } } = meta2;
102
+ const { data: { addons, define, http } } = meta2;
110
103
  if (!_optionalChain([http, 'optionalAccess', _3 => _3.type])) continue;
111
- fastify2.register((fastify3, _opts, done2) => {
112
- _chunk7SYPUIBYjs.Context.usePlugin(plugins, "fastify").forEach((p) => {
113
- p[Symbol.for("skip-override")] = true;
114
- fastify3.register(p);
115
- });
104
+ fastify2.register(async (fastify3, _opts, done2) => {
105
+ _chunkSW5IKE5Hjs.Context.applyAddons(addons, fastify3, "fastify");
106
+ let aop;
107
+ if (!dynamic) {
108
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
109
+ globalFilter,
110
+ globalGuards,
111
+ globalPipe
112
+ });
113
+ }
116
114
  fastify3[http.type](http.prefix + http.route, _optionalChain([define, 'optionalAccess', _4 => _4.fastify]) || {}, async (req, res) => {
117
115
  debug(`invoke method "${func}" in module "${tag}"`);
118
116
  const contextData = {
@@ -129,27 +127,29 @@ function bind(fastify, data, opts = {}) {
129
127
  headers: req.headers,
130
128
  app: fastify3,
131
129
  // @ts-expect-error need @fastify/cookie
132
- getCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
130
+ getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => req.cookies[key], "getCookie"),
133
131
  // @ts-expect-error need @fastify/cookie
134
- setCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key, value, opts2) => res.setCookie(key, value, opts2), "setCookie"),
132
+ setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => res.setCookie(key, value, opts2), "setCookie"),
135
133
  // @ts-expect-error need @fastify/cookie
136
- delCookie: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (key) => res.clearCookie(key, {
137
- path: ""
134
+ delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => res.clearCookie(key, {
135
+ url: ""
138
136
  }), "delCookie"),
139
- redirect: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (url, status) => res.redirect(url, status), "redirect"),
140
- setResHeaders: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (headers) => res.headers(headers), "setResHeaders"),
141
- setResStatus: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
142
- getRequest: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => req, "getRequest"),
143
- getResponse: /* @__PURE__ */ _chunkGHFSIZUOjs.__name.call(void 0, () => res, "getResponse")
137
+ redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url, status) => res.redirect(url, status), "redirect"),
138
+ setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => res.headers(headers), "setResHeaders"),
139
+ setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (code) => res.status(code), "setResStatus"),
140
+ getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => req.raw, "getRequest"),
141
+ getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => res.raw, "getResponse")
144
142
  };
145
- const context = new (0, _chunk7SYPUIBYjs.Context)(contextData);
143
+ const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
146
144
  if (http.headers) res.headers(http.headers);
147
- return context.run({
148
- globalGuards,
149
- globalInterceptors,
150
- globalFilter,
151
- globalPipe
152
- }, (returnData) => {
145
+ if (dynamic) {
146
+ aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
147
+ globalFilter,
148
+ globalGuards,
149
+ globalPipe
150
+ });
151
+ }
152
+ return context.run(aop, (returnData) => {
153
153
  if (res.sent) return;
154
154
  return returnData;
155
155
  }, (err) => {
@@ -164,11 +164,11 @@ function bind(fastify, data, opts = {}) {
164
164
  done();
165
165
  }, fastifyOpts);
166
166
  }
167
- _chunkGHFSIZUOjs.__name.call(void 0, bind, "bind");
167
+ _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
168
168
  function Fastify(opts) {
169
- return _chunkXCND2QW3js.Define.call(void 0, "fastify", opts);
169
+ return _chunkMBCHNDAYjs.Define.call(void 0, "fastify", opts);
170
170
  }
171
- _chunkGHFSIZUOjs.__name.call(void 0, Fastify, "Fastify");
171
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Fastify, "Fastify");
172
172
 
173
173
 
174
174