phecda-server 7.0.0-alpha.0 → 7.0.0-alpha.10

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 (86) hide show
  1. package/assets/ps.json +24 -24
  2. package/assets/schema.json +55 -55
  3. package/bin/cli.mjs +31 -18
  4. package/dist/chunk-4LLLQOMF.js +152 -0
  5. package/dist/{chunk-BGXSMOLX.js → chunk-6OQ2SB5W.js} +138 -70
  6. package/dist/{chunk-SW5IKE5H.js → chunk-G7JFKM2M.js} +136 -89
  7. package/dist/{chunk-MBCHNDAY.js → chunk-KCPBITYZ.js} +24 -24
  8. package/dist/{chunk-HMVLXNV3.mjs → chunk-MUI6MTUO.mjs} +1 -1
  9. package/dist/chunk-NQ55PA2X.mjs +152 -0
  10. package/dist/{chunk-5622RBNB.mjs → chunk-YCES6ABN.mjs} +125 -57
  11. package/dist/{chunk-P75VKZJY.mjs → chunk-Z7NAAE4M.mjs} +94 -47
  12. package/dist/{core-BIcUwV18.d.mts → core-CUTbX_IS.d.ts} +5 -3
  13. package/dist/{core-CYwEPfN4.d.ts → core-DIfgUKIU.d.mts} +5 -3
  14. package/dist/helper.d.mts +8 -6
  15. package/dist/helper.d.ts +8 -6
  16. package/dist/helper.js +8 -3
  17. package/dist/helper.mjs +10 -5
  18. package/dist/http/elysia/index.d.mts +4 -4
  19. package/dist/http/elysia/index.d.ts +4 -4
  20. package/dist/http/elysia/index.js +43 -44
  21. package/dist/http/elysia/index.mjs +9 -10
  22. package/dist/http/express/index.d.mts +4 -4
  23. package/dist/http/express/index.d.ts +4 -4
  24. package/dist/http/express/index.js +40 -41
  25. package/dist/http/express/index.mjs +9 -10
  26. package/dist/http/fastify/index.d.mts +4 -4
  27. package/dist/http/fastify/index.d.ts +4 -4
  28. package/dist/http/fastify/index.js +41 -42
  29. package/dist/http/fastify/index.mjs +9 -10
  30. package/dist/http/h3/index.d.mts +4 -4
  31. package/dist/http/h3/index.d.ts +4 -4
  32. package/dist/http/h3/index.js +41 -42
  33. package/dist/http/h3/index.mjs +9 -10
  34. package/dist/http/hono/index.d.mts +4 -4
  35. package/dist/http/hono/index.d.ts +4 -4
  36. package/dist/http/hono/index.js +37 -39
  37. package/dist/http/hono/index.mjs +5 -7
  38. package/dist/http/hyper-express/index.d.mts +4 -4
  39. package/dist/http/hyper-express/index.d.ts +4 -4
  40. package/dist/http/hyper-express/index.js +38 -39
  41. package/dist/http/hyper-express/index.mjs +8 -9
  42. package/dist/http/koa/index.d.mts +4 -4
  43. package/dist/http/koa/index.d.ts +4 -4
  44. package/dist/http/koa/index.js +40 -41
  45. package/dist/http/koa/index.mjs +9 -10
  46. package/dist/index.d.mts +46 -40
  47. package/dist/index.d.ts +46 -40
  48. package/dist/index.js +48 -42
  49. package/dist/index.mjs +21 -15
  50. package/dist/{meta-BXKLFTgG.d.mts → meta-CR-D39hQ.d.mts} +7 -5
  51. package/dist/{meta-BXKLFTgG.d.ts → meta-CR-D39hQ.d.ts} +7 -5
  52. package/dist/rpc/bullmq/index.d.mts +5 -5
  53. package/dist/rpc/bullmq/index.d.ts +5 -5
  54. package/dist/rpc/bullmq/index.js +15 -14
  55. package/dist/rpc/bullmq/index.mjs +4 -3
  56. package/dist/rpc/kafka/index.d.mts +4 -4
  57. package/dist/rpc/kafka/index.d.ts +4 -4
  58. package/dist/rpc/kafka/index.js +15 -14
  59. package/dist/rpc/kafka/index.mjs +3 -2
  60. package/dist/rpc/nats/index.d.mts +4 -4
  61. package/dist/rpc/nats/index.d.ts +4 -4
  62. package/dist/rpc/nats/index.js +14 -13
  63. package/dist/rpc/nats/index.mjs +4 -3
  64. package/dist/rpc/rabbitmq/index.d.mts +4 -4
  65. package/dist/rpc/rabbitmq/index.d.ts +4 -4
  66. package/dist/rpc/rabbitmq/index.js +16 -15
  67. package/dist/rpc/rabbitmq/index.mjs +4 -3
  68. package/dist/rpc/redis/index.d.mts +4 -4
  69. package/dist/rpc/redis/index.d.ts +4 -4
  70. package/dist/rpc/redis/index.js +14 -13
  71. package/dist/rpc/redis/index.mjs +4 -3
  72. package/dist/test.d.mts +3 -3
  73. package/dist/test.d.ts +3 -3
  74. package/dist/test.js +6 -6
  75. package/dist/test.mjs +2 -2
  76. package/dist/{types-h40T3cRG.d.mts → types-BF1TDbFV.d.ts} +4 -3
  77. package/dist/{types-BtbL49Zs.d.mts → types-DYRu0vic.d.ts} +4 -3
  78. package/dist/{types-VFzEM7LL.d.ts → types-DYviSl5B.d.mts} +4 -3
  79. package/dist/{types-m3IEDKjP.d.ts → types-DqH1qA-q.d.mts} +4 -3
  80. package/package.json +8 -5
  81. package/register/export.mjs +30 -0
  82. package/register/index.mjs +50 -40
  83. package/register/loader.mjs +384 -367
  84. package/register/utils.mjs +60 -56
  85. package/dist/chunk-J5CFUN4V.js +0 -73
  86. package/dist/chunk-WHJ5FALK.mjs +0 -73
@@ -4,11 +4,11 @@
4
4
 
5
5
 
6
6
 
7
+ var _chunkG7JFKM2Mjs = require('../../chunk-G7JFKM2M.js');
7
8
 
8
- var _chunkSW5IKE5Hjs = require('../../chunk-SW5IKE5H.js');
9
9
 
10
10
 
11
- var _chunkJ5CFUN4Vjs = require('../../chunk-J5CFUN4V.js');
11
+ var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
12
12
 
13
13
  // src/http/koa/bind.ts
14
14
  var _router = require('@koa/router'); var _router2 = _interopRequireDefault(_router);
@@ -18,14 +18,14 @@ function bind(router, data, opts = {}) {
18
18
  const { globalGuards, parallelRoute = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
19
19
  const { moduleMap, meta } = data;
20
20
  const originStack = router.stack.slice(0, router.stack.length);
21
- const metaMap = _chunkSW5IKE5Hjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkG7JFKM2Mjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
22
  const { controller, http, func, tag } = meta2.data;
23
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
24
24
  debug(`register method "${func}" in module "${tag}"`);
25
25
  return true;
26
26
  }
27
27
  });
28
- _chunkSW5IKE5Hjs.detectAopDep.call(void 0, meta, {
28
+ _chunkG7JFKM2Mjs.detectAopDep.call(void 0, meta, {
29
29
  addons: [
30
30
  ...globalAddons,
31
31
  ...parallelAddons
@@ -34,35 +34,35 @@ function bind(router, data, opts = {}) {
34
34
  });
35
35
  registerRoute();
36
36
  function registerRoute() {
37
- _chunkSW5IKE5Hjs.Context.applyAddons(globalAddons, router, "koa");
37
+ _chunkG7JFKM2Mjs.Context.applyAddons(globalAddons, router, "koa");
38
38
  if (parallelRoute) {
39
39
  const subRouter = new (0, _router2.default)();
40
- _chunkSW5IKE5Hjs.Context.applyAddons(parallelAddons, subRouter, "koa");
40
+ _chunkG7JFKM2Mjs.Context.applyAddons(parallelAddons, subRouter, "koa");
41
41
  subRouter.post(parallelRoute, async (ctx, next) => {
42
42
  const { body } = ctx.request;
43
43
  async function errorHandler(e) {
44
- const error = await _chunkSW5IKE5Hjs.Context.filterRecord.default(e);
44
+ const error = await _chunkG7JFKM2Mjs.Context.filterRecord.default(e);
45
45
  ctx.status = error.status;
46
46
  ctx.body = error;
47
47
  }
48
- _chunkJ5CFUN4Vjs.__name.call(void 0, errorHandler, "errorHandler");
49
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkSW5IKE5Hjs.BadRequestException)("data format should be an array"));
48
+ _chunk4LLLQOMFjs.__name.call(void 0, errorHandler, "errorHandler");
49
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkG7JFKM2Mjs.BadRequestException)("data format should be an array"));
50
50
  try {
51
51
  return Promise.all(body.map((item, i) => {
52
52
  return new Promise(async (resolve) => {
53
53
  const { tag, func } = item;
54
54
  debug(`(parallel)invoke method "${func}" in module "${tag}"`);
55
- if (!metaMap.has(tag)) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`module "${tag}" doesn't exist`)));
55
+ if (!metaMap.has(tag)) return resolve(await _chunkG7JFKM2Mjs.Context.filterRecord.default(new (0, _chunkG7JFKM2Mjs.BadRequestException)(`module "${tag}" doesn't exist`)));
56
56
  const meta2 = metaMap.get(tag)[func];
57
- if (!meta2) return resolve(await _chunkSW5IKE5Hjs.Context.filterRecord.default(new (0, _chunkSW5IKE5Hjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
58
- const { data: { params } } = meta2;
59
- const aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
57
+ if (!meta2) return resolve(await _chunkG7JFKM2Mjs.Context.filterRecord.default(new (0, _chunkG7JFKM2Mjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
58
+ const aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
60
59
  globalGuards,
61
60
  globalFilter,
62
61
  globalPipe
63
62
  });
64
63
  const contextData = {
65
64
  type: "koa",
65
+ category: "http",
66
66
  index: i,
67
67
  ctx,
68
68
  meta: meta2,
@@ -70,21 +70,19 @@ function bind(router, data, opts = {}) {
70
70
  parallel: true,
71
71
  next,
72
72
  app: router,
73
- ..._chunkSW5IKE5Hjs.argToReq.call(void 0, params, item.args, ctx.headers),
74
- tag,
75
- func,
76
- getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
77
- setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
78
- delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
73
+ ...item,
74
+ getCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
75
+ setCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
76
+ delCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
79
77
  expires: /* @__PURE__ */ new Date(0)
80
78
  }), "delCookie"),
81
- redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
82
- setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
83
- setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
84
- getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.req, "getRequest"),
85
- getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.res, "getResponse")
79
+ redirect: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
80
+ setResHeaders: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
81
+ setResStatus: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
82
+ getRequest: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, () => ctx.req, "getRequest"),
83
+ getResponse: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, () => ctx.res, "getResponse")
86
84
  };
87
- const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
85
+ const context = new (0, _chunkG7JFKM2Mjs.Context)(contextData);
88
86
  context.run(aop, resolve, resolve);
89
87
  });
90
88
  })).then((ret) => {
@@ -103,15 +101,15 @@ function bind(router, data, opts = {}) {
103
101
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
104
102
  let aop;
105
103
  if (!dynamic) {
106
- aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
104
+ aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
107
105
  globalFilter,
108
106
  globalGuards,
109
107
  globalPipe
110
108
  });
111
109
  }
112
110
  const subRouter = new (0, _router2.default)();
113
- _chunkSW5IKE5Hjs.Context.applyAddons(addons, subRouter, "koa");
114
- router[http.type](http.prefix + http.route, async (ctx, next) => {
111
+ _chunkG7JFKM2Mjs.Context.applyAddons(addons, subRouter, "koa");
112
+ router[http.type](_chunkG7JFKM2Mjs.joinUrl.call(void 0, http.prefix, http.route), async (ctx, next) => {
115
113
  debug(`invoke method "${func}" in module "${tag}"`);
116
114
  const contextData = {
117
115
  type: "koa",
@@ -123,24 +121,25 @@ function bind(router, data, opts = {}) {
123
121
  func,
124
122
  query: ctx.query,
125
123
  params: ctx.params,
124
+ category: "http",
126
125
  body: ctx.request.body,
127
126
  headers: ctx.headers,
128
127
  next,
129
- getCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
130
- setCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
131
- delCookie: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
128
+ getCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key) => ctx.cookies.get(key), "getCookie"),
129
+ setCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
130
+ delCookie: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (key) => ctx.cookies.set(key, "", {
132
131
  expires: /* @__PURE__ */ new Date(0)
133
132
  }), "delCookie"),
134
- redirect: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
135
- setResHeaders: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
136
- setResStatus: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
137
- getRequest: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.req, "getRequest"),
138
- getResponse: /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, () => ctx.res, "getResponse")
133
+ redirect: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (url) => ctx.redirect(url), "redirect"),
134
+ setResHeaders: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (headers) => ctx.set(headers), "setResHeaders"),
135
+ setResStatus: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (status) => ctx.status = status, "setResStatus"),
136
+ getRequest: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, () => ctx.req, "getRequest"),
137
+ getResponse: /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, () => ctx.res, "getResponse")
139
138
  };
140
- const context = new (0, _chunkSW5IKE5Hjs.Context)(contextData);
139
+ const context = new (0, _chunkG7JFKM2Mjs.Context)(contextData);
141
140
  if (http.headers) ctx.set(http.headers);
142
141
  if (dynamic) {
143
- aop = _chunkSW5IKE5Hjs.Context.getAop(meta2, {
142
+ aop = _chunkG7JFKM2Mjs.Context.getAop(meta2, {
144
143
  globalFilter,
145
144
  globalGuards,
146
145
  globalPipe
@@ -159,13 +158,13 @@ function bind(router, data, opts = {}) {
159
158
  }
160
159
  }
161
160
  }
162
- _chunkJ5CFUN4Vjs.__name.call(void 0, registerRoute, "registerRoute");
163
- _chunkSW5IKE5Hjs.HMR.call(void 0, async () => {
161
+ _chunk4LLLQOMFjs.__name.call(void 0, registerRoute, "registerRoute");
162
+ _chunk4LLLQOMFjs.HMR.call(void 0, async () => {
164
163
  router.stack = originStack;
165
164
  registerRoute();
166
165
  });
167
166
  }
168
- _chunkJ5CFUN4Vjs.__name.call(void 0, bind, "bind");
167
+ _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
169
168
 
170
169
 
171
170
  exports.bind = bind;
@@ -1,14 +1,14 @@
1
1
  import {
2
2
  BadRequestException,
3
3
  Context,
4
- HMR,
5
- argToReq,
6
4
  createControllerMetaMap,
7
- detectAopDep
8
- } from "../../chunk-P75VKZJY.mjs";
5
+ detectAopDep,
6
+ joinUrl
7
+ } from "../../chunk-Z7NAAE4M.mjs";
9
8
  import {
9
+ HMR,
10
10
  __name
11
- } from "../../chunk-WHJ5FALK.mjs";
11
+ } from "../../chunk-NQ55PA2X.mjs";
12
12
 
13
13
  // src/http/koa/bind.ts
14
14
  import Router from "@koa/router";
@@ -55,7 +55,6 @@ function bind(router, data, opts = {}) {
55
55
  if (!metaMap.has(tag)) return resolve(await Context.filterRecord.default(new BadRequestException(`module "${tag}" doesn't exist`)));
56
56
  const meta2 = metaMap.get(tag)[func];
57
57
  if (!meta2) return resolve(await Context.filterRecord.default(new BadRequestException(`"${func}" in "${tag}" doesn't exist`)));
58
- const { data: { params } } = meta2;
59
58
  const aop = Context.getAop(meta2, {
60
59
  globalGuards,
61
60
  globalFilter,
@@ -63,6 +62,7 @@ function bind(router, data, opts = {}) {
63
62
  });
64
63
  const contextData = {
65
64
  type: "koa",
65
+ category: "http",
66
66
  index: i,
67
67
  ctx,
68
68
  meta: meta2,
@@ -70,9 +70,7 @@ function bind(router, data, opts = {}) {
70
70
  parallel: true,
71
71
  next,
72
72
  app: router,
73
- ...argToReq(params, item.args, ctx.headers),
74
- tag,
75
- func,
73
+ ...item,
76
74
  getCookie: /* @__PURE__ */ __name((key) => ctx.cookies.get(key), "getCookie"),
77
75
  setCookie: /* @__PURE__ */ __name((key, value, opts2) => ctx.cookies.set(key, value, opts2), "setCookie"),
78
76
  delCookie: /* @__PURE__ */ __name((key) => ctx.cookies.set(key, "", {
@@ -111,7 +109,7 @@ function bind(router, data, opts = {}) {
111
109
  }
112
110
  const subRouter = new Router();
113
111
  Context.applyAddons(addons, subRouter, "koa");
114
- router[http.type](http.prefix + http.route, async (ctx, next) => {
112
+ router[http.type](joinUrl(http.prefix, http.route), async (ctx, next) => {
115
113
  debug(`invoke method "${func}" in module "${tag}"`);
116
114
  const contextData = {
117
115
  type: "koa",
@@ -123,6 +121,7 @@ function bind(router, data, opts = {}) {
123
121
  func,
124
122
  query: ctx.query,
125
123
  params: ctx.params,
124
+ category: "http",
126
125
  body: ctx.request.body,
127
126
  headers: ctx.headers,
128
127
  next,
package/dist/index.d.mts CHANGED
@@ -1,13 +1,13 @@
1
- import { B as BaseContext, a as ControllerMeta, D as DefaultOptions, C as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-BXKLFTgG.mjs';
2
- export { g as BaseRequestType, f as BaseReturn, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_HMR, k as IS_ONLY_GENERATE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, m as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-BXKLFTgG.mjs';
3
- import { G as Generator } from './core-BIcUwV18.mjs';
4
- export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-BIcUwV18.mjs';
1
+ import { B as BaseCtx, C as ControllerMeta, D as DefaultOptions, a as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-CR-D39hQ.mjs';
2
+ export { g as BaseRequestType, f as BaseReturn, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_DEV, k as IS_ONLY_GENERATE, m as IS_PURE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, n as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-CR-D39hQ.mjs';
3
+ import { G as Generator } from './core-DIfgUKIU.mjs';
4
+ export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-DIfgUKIU.mjs';
5
5
  import { Base } from 'phecda-core';
6
6
  export * from 'phecda-core';
7
- import { H as HttpContext } from './types-h40T3cRG.mjs';
8
- export { C as CookieSerializeOptions, a as HttpOptions } from './types-h40T3cRG.mjs';
9
- import { R as RpcContext } from './types-BtbL49Zs.mjs';
10
- export { b as RpcClientOptions, a as RpcServerOptions } from './types-BtbL49Zs.mjs';
7
+ import { H as HttpCtx } from './types-DYviSl5B.mjs';
8
+ export { C as CookieSerializeOptions, a as HttpOptions } from './types-DYviSl5B.mjs';
9
+ import { R as RpcCtx } from './types-DqH1qA-q.mjs';
10
+ export { b as RpcClientOptions, a as RpcServerOptions } from './types-DqH1qA-q.mjs';
11
11
  export { Mixin } from 'ts-mixer';
12
12
  import 'node:http';
13
13
 
@@ -102,11 +102,11 @@ interface PipeArg {
102
102
  reflect: any;
103
103
  define: Record<string, any>;
104
104
  }
105
- type GuardType<C extends BaseContext = any> = (ctx: C, next: () => Promise<any>) => any;
106
- type PipeType<C extends BaseContext = any> = (arg: PipeArg, ctx: C) => Promise<any>;
107
- type FilterType<C extends BaseContext = any, E extends Exception = any> = (err: E | Error, ctx?: C) => Error | any;
108
- declare class Context<Data extends BaseContext> {
109
- data: Data;
105
+ type GuardType<Ctx extends BaseCtx = any> = (ctx: Ctx, next: () => Promise<any>) => any;
106
+ type PipeType<Ctx extends BaseCtx = any> = (arg: PipeArg, ctx: Ctx) => Promise<any>;
107
+ type FilterType<Ctx extends BaseCtx = any, E extends Exception = any> = (err: E | Error, ctx?: Ctx) => Error | any;
108
+ declare class Context<Ctx extends BaseCtx> {
109
+ data: Ctx;
110
110
  method: string;
111
111
  params: string[];
112
112
  static filterRecord: Record<PropertyKey, FilterType>;
@@ -119,7 +119,9 @@ declare class Context<Data extends BaseContext> {
119
119
  value: (router: any, framework: string) => any;
120
120
  priority: number;
121
121
  }>;
122
- constructor(data: Data);
122
+ ctx: Ctx;
123
+ protected canGetCtx: boolean;
124
+ constructor(data: Ctx);
123
125
  static getAop(meta: ControllerMeta, opts: DefaultOptions): {
124
126
  guards: GuardType<any>[];
125
127
  pipe: PipeType<any>[];
@@ -135,10 +137,10 @@ declare class Context<Data extends BaseContext> {
135
137
  static getGuards(guards: string[]): GuardType<any>[];
136
138
  static applyAddons(addons: string[], router: any, framework: string): void;
137
139
  }
138
- declare function addPipe<C extends BaseContext>(key: PropertyKey, pipe: PipeType<C>): void;
139
- declare function addFilter<C extends BaseContext>(key: PropertyKey, filter: FilterType<C>): void;
140
- declare function addGuard<C extends BaseContext>(key: PropertyKey, guard: GuardType<C>, priority?: number): void;
141
- declare function addAddon<T>(key: PropertyKey, addon: (router: any, framework: string) => T, priority?: number): void;
140
+ declare function addPipe<C extends BaseCtx>(key: PropertyKey, pipe: PipeType<C>): void;
141
+ declare function addFilter<C extends BaseCtx>(key: PropertyKey, filter: FilterType<C>): void;
142
+ declare function addGuard<C extends BaseCtx>(key: PropertyKey, guard: GuardType<C>, priority?: number): void;
143
+ declare function addAddon(key: PropertyKey, addon: (router: any, framework: string) => void, priority?: number): void;
142
144
 
143
145
  declare class RPCGenerator extends Generator {
144
146
  name: string;
@@ -190,30 +192,40 @@ declare function Define(key: string, value: any): any;
190
192
 
191
193
  declare const defaultPipe: PipeType;
192
194
 
195
+ type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
196
+ interface Logger {
197
+ log(msg: unknown, level: LogLevel, ctx?: string): void;
198
+ }
199
+ declare function setLogger(logger: Logger): void;
200
+ declare function getLogger(): Logger;
201
+ declare function log(msg: unknown, level?: LogLevel, ctx?: any): void;
202
+ declare function runMiddleware(ctx: HttpCtx, middleware: (req: any, res: any, next?: any) => any): Promise<unknown>;
203
+
193
204
  declare class ServerBase extends Base {
194
205
  emitter: Emitter;
206
+ log(msg: unknown, level?: LogLevel): void;
195
207
  }
196
- declare class HttpBase extends ServerBase {
197
- context: HttpContext;
208
+ declare class HttpBase<Ctx extends HttpCtx = HttpCtx> extends ServerBase {
209
+ context: Ctx;
198
210
  }
199
- declare class RpcBase extends ServerBase {
200
- context: RpcContext;
211
+ declare class RpcBase<Ctx extends RpcCtx = RpcCtx> extends ServerBase {
212
+ context: Ctx;
201
213
  }
202
214
 
203
- declare abstract class PFilter<C extends BaseContext = any, E extends Exception = Exception> extends ServerBase {
215
+ declare abstract class PFilter<Ctx extends BaseCtx = any, E extends Exception = Exception> extends ServerBase {
204
216
  readonly key: PropertyKey;
205
217
  constructor(tag?: string);
206
- abstract use(error: Error | E, ctx?: C): BaseError;
218
+ abstract use(error: Error | E, ctx?: Ctx): BaseError;
207
219
  }
208
220
 
209
- declare abstract class PGuard<C extends BaseContext = any> extends ServerBase {
210
- abstract use(ctx: C): Promise<boolean> | boolean;
221
+ declare abstract class PGuard<Ctx extends BaseCtx = any> extends ServerBase {
222
+ abstract use(ctx: Ctx, next: () => Promise<any>): any;
211
223
  readonly key: PropertyKey;
212
224
  priority: number;
213
225
  constructor(tag?: string);
214
226
  }
215
227
 
216
- declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
228
+ declare abstract class PPipe<Ctx extends BaseCtx = any> extends ServerBase {
217
229
  readonly key: PropertyKey;
218
230
  constructor(tag?: string);
219
231
  abstract use(param: {
@@ -223,18 +235,18 @@ declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
223
235
  type: string;
224
236
  index: number;
225
237
  reflect: any;
226
- }, ctx: C): any;
238
+ }, ctx: Ctx): any;
227
239
  }
228
240
 
229
241
  declare abstract class PAddon extends ServerBase {
230
242
  readonly key: PropertyKey;
231
243
  priority: number;
232
244
  constructor(tag?: string);
233
- abstract use<Addon = any>(framework: string): Addon | undefined;
245
+ abstract use(router: any, framework: string): undefined;
234
246
  }
235
247
 
236
- interface PExtension<C extends BaseContext = any, E extends Exception = Exception> {
237
- guard(ctx: C): Promise<boolean> | boolean;
248
+ interface PExtension<Ctx extends BaseCtx = any, E extends Exception = Exception> {
249
+ guard(ctx: Ctx): Promise<boolean> | boolean;
238
250
  pipe(param: {
239
251
  arg: any;
240
252
  option?: any;
@@ -242,8 +254,8 @@ interface PExtension<C extends BaseContext = any, E extends Exception = Exceptio
242
254
  type: string;
243
255
  index: number;
244
256
  reflect: any;
245
- }, ctx: C): any;
246
- filter(error: Error | E, ctx?: C): BaseError;
257
+ }, ctx: Ctx): any;
258
+ filter(error: Error | E, ctx?: Ctx): BaseError;
247
259
  addon<Addon = any>(framework: string): Addon;
248
260
  }
249
261
  declare class PExtension extends ServerBase {
@@ -253,10 +265,4 @@ declare class PExtension extends ServerBase {
253
265
  constructor(tag?: string);
254
266
  }
255
267
 
256
- type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
257
- declare function setLogger(logger: Record<LogLevel, (msg: string) => void>): void;
258
- declare function getLogger(): Record<LogLevel, (msg: string) => void>;
259
- declare function log(msg: string, level?: LogLevel): void;
260
- declare function runMiddleware(ctx: HttpContext, middleware: (req: any, res: any, next?: any) => any): Promise<unknown>;
261
-
262
- export { type AOP, Addon, Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMeta, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, InvalidInputException, MetaData, NotFoundException, PAddon, PExtension, PFilter, PGuard, PPipe, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addAddon, addFilter, addGuard, addPipe, defaultPipe, getLogger, log, runMiddleware, setLogger };
268
+ export { type AOP, Addon, Arg, BadGatewayException, BadRequestException, BaseCtx, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMeta, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpCtx, InvalidInputException, type LogLevel, type Logger, MetaData, NotFoundException, PAddon, PExtension, PFilter, PGuard, PPipe, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcCtx, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addAddon, addFilter, addGuard, addPipe, defaultPipe, getLogger, log, runMiddleware, setLogger };
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { B as BaseContext, a as ControllerMeta, D as DefaultOptions, C as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-BXKLFTgG.js';
2
- export { g as BaseRequestType, f as BaseReturn, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_HMR, k as IS_ONLY_GENERATE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, m as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-BXKLFTgG.js';
3
- import { G as Generator } from './core-CYwEPfN4.js';
4
- export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-CYwEPfN4.js';
1
+ import { B as BaseCtx, C as ControllerMeta, D as DefaultOptions, a as ControllerMetaData, b as MetaData, E as Emitter, c as BaseError } from './meta-CR-D39hQ.js';
2
+ export { g as BaseRequestType, f as BaseReturn, h as CustomResponse, j as ERROR_SYMBOL, i as ExtractResponse, I as IS_DEV, k as IS_ONLY_GENERATE, m as IS_PURE, l as IS_STRICT, L as LOG_LEVEL, M as Meta, O as OmitFunction, n as PS_EXIT_CODE, P as PickFunc, S as ServiceMetaData, e as ToClientFn, d as ToClientInstance, T as ToClientMap } from './meta-CR-D39hQ.js';
3
+ import { G as Generator } from './core-CUTbX_IS.js';
4
+ export { F as Factory, O as Options, S as ServerPhecda, d as defaultServerInject, e as emitter, p as phecdaNamespace, u as useS } from './core-CUTbX_IS.js';
5
5
  import { Base } from 'phecda-core';
6
6
  export * from 'phecda-core';
7
- import { H as HttpContext } from './types-VFzEM7LL.js';
8
- export { C as CookieSerializeOptions, a as HttpOptions } from './types-VFzEM7LL.js';
9
- import { R as RpcContext } from './types-m3IEDKjP.js';
10
- export { b as RpcClientOptions, a as RpcServerOptions } from './types-m3IEDKjP.js';
7
+ import { H as HttpCtx } from './types-BF1TDbFV.js';
8
+ export { C as CookieSerializeOptions, a as HttpOptions } from './types-BF1TDbFV.js';
9
+ import { R as RpcCtx } from './types-DYRu0vic.js';
10
+ export { b as RpcClientOptions, a as RpcServerOptions } from './types-DYRu0vic.js';
11
11
  export { Mixin } from 'ts-mixer';
12
12
  import 'node:http';
13
13
 
@@ -102,11 +102,11 @@ interface PipeArg {
102
102
  reflect: any;
103
103
  define: Record<string, any>;
104
104
  }
105
- type GuardType<C extends BaseContext = any> = (ctx: C, next: () => Promise<any>) => any;
106
- type PipeType<C extends BaseContext = any> = (arg: PipeArg, ctx: C) => Promise<any>;
107
- type FilterType<C extends BaseContext = any, E extends Exception = any> = (err: E | Error, ctx?: C) => Error | any;
108
- declare class Context<Data extends BaseContext> {
109
- data: Data;
105
+ type GuardType<Ctx extends BaseCtx = any> = (ctx: Ctx, next: () => Promise<any>) => any;
106
+ type PipeType<Ctx extends BaseCtx = any> = (arg: PipeArg, ctx: Ctx) => Promise<any>;
107
+ type FilterType<Ctx extends BaseCtx = any, E extends Exception = any> = (err: E | Error, ctx?: Ctx) => Error | any;
108
+ declare class Context<Ctx extends BaseCtx> {
109
+ data: Ctx;
110
110
  method: string;
111
111
  params: string[];
112
112
  static filterRecord: Record<PropertyKey, FilterType>;
@@ -119,7 +119,9 @@ declare class Context<Data extends BaseContext> {
119
119
  value: (router: any, framework: string) => any;
120
120
  priority: number;
121
121
  }>;
122
- constructor(data: Data);
122
+ ctx: Ctx;
123
+ protected canGetCtx: boolean;
124
+ constructor(data: Ctx);
123
125
  static getAop(meta: ControllerMeta, opts: DefaultOptions): {
124
126
  guards: GuardType<any>[];
125
127
  pipe: PipeType<any>[];
@@ -135,10 +137,10 @@ declare class Context<Data extends BaseContext> {
135
137
  static getGuards(guards: string[]): GuardType<any>[];
136
138
  static applyAddons(addons: string[], router: any, framework: string): void;
137
139
  }
138
- declare function addPipe<C extends BaseContext>(key: PropertyKey, pipe: PipeType<C>): void;
139
- declare function addFilter<C extends BaseContext>(key: PropertyKey, filter: FilterType<C>): void;
140
- declare function addGuard<C extends BaseContext>(key: PropertyKey, guard: GuardType<C>, priority?: number): void;
141
- declare function addAddon<T>(key: PropertyKey, addon: (router: any, framework: string) => T, priority?: number): void;
140
+ declare function addPipe<C extends BaseCtx>(key: PropertyKey, pipe: PipeType<C>): void;
141
+ declare function addFilter<C extends BaseCtx>(key: PropertyKey, filter: FilterType<C>): void;
142
+ declare function addGuard<C extends BaseCtx>(key: PropertyKey, guard: GuardType<C>, priority?: number): void;
143
+ declare function addAddon(key: PropertyKey, addon: (router: any, framework: string) => void, priority?: number): void;
142
144
 
143
145
  declare class RPCGenerator extends Generator {
144
146
  name: string;
@@ -190,30 +192,40 @@ declare function Define(key: string, value: any): any;
190
192
 
191
193
  declare const defaultPipe: PipeType;
192
194
 
195
+ type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
196
+ interface Logger {
197
+ log(msg: unknown, level: LogLevel, ctx?: string): void;
198
+ }
199
+ declare function setLogger(logger: Logger): void;
200
+ declare function getLogger(): Logger;
201
+ declare function log(msg: unknown, level?: LogLevel, ctx?: any): void;
202
+ declare function runMiddleware(ctx: HttpCtx, middleware: (req: any, res: any, next?: any) => any): Promise<unknown>;
203
+
193
204
  declare class ServerBase extends Base {
194
205
  emitter: Emitter;
206
+ log(msg: unknown, level?: LogLevel): void;
195
207
  }
196
- declare class HttpBase extends ServerBase {
197
- context: HttpContext;
208
+ declare class HttpBase<Ctx extends HttpCtx = HttpCtx> extends ServerBase {
209
+ context: Ctx;
198
210
  }
199
- declare class RpcBase extends ServerBase {
200
- context: RpcContext;
211
+ declare class RpcBase<Ctx extends RpcCtx = RpcCtx> extends ServerBase {
212
+ context: Ctx;
201
213
  }
202
214
 
203
- declare abstract class PFilter<C extends BaseContext = any, E extends Exception = Exception> extends ServerBase {
215
+ declare abstract class PFilter<Ctx extends BaseCtx = any, E extends Exception = Exception> extends ServerBase {
204
216
  readonly key: PropertyKey;
205
217
  constructor(tag?: string);
206
- abstract use(error: Error | E, ctx?: C): BaseError;
218
+ abstract use(error: Error | E, ctx?: Ctx): BaseError;
207
219
  }
208
220
 
209
- declare abstract class PGuard<C extends BaseContext = any> extends ServerBase {
210
- abstract use(ctx: C): Promise<boolean> | boolean;
221
+ declare abstract class PGuard<Ctx extends BaseCtx = any> extends ServerBase {
222
+ abstract use(ctx: Ctx, next: () => Promise<any>): any;
211
223
  readonly key: PropertyKey;
212
224
  priority: number;
213
225
  constructor(tag?: string);
214
226
  }
215
227
 
216
- declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
228
+ declare abstract class PPipe<Ctx extends BaseCtx = any> extends ServerBase {
217
229
  readonly key: PropertyKey;
218
230
  constructor(tag?: string);
219
231
  abstract use(param: {
@@ -223,18 +235,18 @@ declare abstract class PPipe<C extends BaseContext = any> extends ServerBase {
223
235
  type: string;
224
236
  index: number;
225
237
  reflect: any;
226
- }, ctx: C): any;
238
+ }, ctx: Ctx): any;
227
239
  }
228
240
 
229
241
  declare abstract class PAddon extends ServerBase {
230
242
  readonly key: PropertyKey;
231
243
  priority: number;
232
244
  constructor(tag?: string);
233
- abstract use<Addon = any>(framework: string): Addon | undefined;
245
+ abstract use(router: any, framework: string): undefined;
234
246
  }
235
247
 
236
- interface PExtension<C extends BaseContext = any, E extends Exception = Exception> {
237
- guard(ctx: C): Promise<boolean> | boolean;
248
+ interface PExtension<Ctx extends BaseCtx = any, E extends Exception = Exception> {
249
+ guard(ctx: Ctx): Promise<boolean> | boolean;
238
250
  pipe(param: {
239
251
  arg: any;
240
252
  option?: any;
@@ -242,8 +254,8 @@ interface PExtension<C extends BaseContext = any, E extends Exception = Exceptio
242
254
  type: string;
243
255
  index: number;
244
256
  reflect: any;
245
- }, ctx: C): any;
246
- filter(error: Error | E, ctx?: C): BaseError;
257
+ }, ctx: Ctx): any;
258
+ filter(error: Error | E, ctx?: Ctx): BaseError;
247
259
  addon<Addon = any>(framework: string): Addon;
248
260
  }
249
261
  declare class PExtension extends ServerBase {
@@ -253,10 +265,4 @@ declare class PExtension extends ServerBase {
253
265
  constructor(tag?: string);
254
266
  }
255
267
 
256
- type LogLevel = 'error' | 'info' | 'warn' | 'log' | 'debug';
257
- declare function setLogger(logger: Record<LogLevel, (msg: string) => void>): void;
258
- declare function getLogger(): Record<LogLevel, (msg: string) => void>;
259
- declare function log(msg: string, level?: LogLevel): void;
260
- declare function runMiddleware(ctx: HttpContext, middleware: (req: any, res: any, next?: any) => any): Promise<unknown>;
261
-
262
- export { type AOP, Addon, Arg, BadGatewayException, BadRequestException, BaseContext, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMeta, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpContext, InvalidInputException, MetaData, NotFoundException, PAddon, PExtension, PFilter, PGuard, PPipe, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcContext, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addAddon, addFilter, addGuard, addPipe, defaultPipe, getLogger, log, runMiddleware, setLogger };
268
+ export { type AOP, Addon, Arg, BadGatewayException, BadRequestException, BaseCtx, BaseError, BaseParam, Body, ConflictException, Context, Controller, ControllerMeta, ControllerMetaData, Ctx, DefaultOptions, Define, Delete, Emitter, Exception, Filter, type FilterType, ForbiddenException, FrameworkException, Generator, Get, Guard, type GuardType, HTTPGenerator, Head, Header, HttpBase, HttpCtx, InvalidInputException, type LogLevel, type Logger, MetaData, NotFoundException, PAddon, PExtension, PFilter, PGuard, PPipe, Param, Patch, PayloadLargeException, Pipe, type PipeArg, type PipeType, Post, Put, Query, Queue, RPCGenerator, Route, Rpc, RpcBase, RpcCtx, Search, ServerBase, ServiceUnavailableException, TimeoutException, TimerException, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, WorkerException, addAddon, addFilter, addGuard, addPipe, defaultPipe, getLogger, log, runMiddleware, setLogger };