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
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkTVT62GIXjs = require('./chunk-TVT62GIX.js');
3
+ var _chunkJ5CFUN4Vjs = require('./chunk-J5CFUN4V.js');
4
4
 
5
5
  // src/decorators/param.ts
6
6
  var _phecdacore = require('phecda-core');
@@ -10,42 +10,42 @@ function BaseParam(data) {
10
10
  _phecdacore.setMeta.call(void 0, target, property, index, data);
11
11
  };
12
12
  }
13
- _chunkTVT62GIXjs.__name.call(void 0, BaseParam, "BaseParam");
13
+ _chunkJ5CFUN4Vjs.__name.call(void 0, BaseParam, "BaseParam");
14
14
  function Body(key = "") {
15
15
  return BaseParam({
16
16
  type: "body",
17
17
  key
18
18
  });
19
19
  }
20
- _chunkTVT62GIXjs.__name.call(void 0, Body, "Body");
20
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Body, "Body");
21
21
  function Head(key) {
22
22
  return BaseParam({
23
23
  type: "headers",
24
24
  key: key.toLowerCase()
25
25
  });
26
26
  }
27
- _chunkTVT62GIXjs.__name.call(void 0, Head, "Head");
27
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Head, "Head");
28
28
  function Query(key = "") {
29
29
  return BaseParam({
30
30
  type: "query",
31
31
  key
32
32
  });
33
33
  }
34
- _chunkTVT62GIXjs.__name.call(void 0, Query, "Query");
34
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Query, "Query");
35
35
  function Param(key) {
36
36
  return BaseParam({
37
37
  type: "params",
38
38
  key
39
39
  });
40
40
  }
41
- _chunkTVT62GIXjs.__name.call(void 0, Param, "Param");
41
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Param, "Param");
42
42
  function Arg(target, k, index) {
43
43
  BaseParam({
44
44
  type: "args",
45
45
  key: `${index}`
46
46
  })(target, k, index);
47
47
  }
48
- _chunkTVT62GIXjs.__name.call(void 0, Arg, "Arg");
48
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Arg, "Arg");
49
49
 
50
50
  // src/decorators/aop.ts
51
51
 
@@ -56,23 +56,15 @@ function Guard(...guards) {
56
56
  });
57
57
  };
58
58
  }
59
- _chunkTVT62GIXjs.__name.call(void 0, Guard, "Guard");
60
- function Plugin(...plugins) {
59
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Guard, "Guard");
60
+ function Addon(...addons) {
61
61
  return (target, property) => {
62
62
  _phecdacore.setMeta.call(void 0, target, property, void 0, {
63
- plugins
63
+ addons
64
64
  });
65
65
  };
66
66
  }
67
- _chunkTVT62GIXjs.__name.call(void 0, Plugin, "Plugin");
68
- function Interceptor(...interceptors) {
69
- return (target, property) => {
70
- _phecdacore.setMeta.call(void 0, target, property, void 0, {
71
- interceptors
72
- });
73
- };
74
- }
75
- _chunkTVT62GIXjs.__name.call(void 0, Interceptor, "Interceptor");
67
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Addon, "Addon");
76
68
  function Filter(filter) {
77
69
  return (target, property) => {
78
70
  _phecdacore.setMeta.call(void 0, target, property, void 0, {
@@ -80,7 +72,7 @@ function Filter(filter) {
80
72
  });
81
73
  };
82
74
  }
83
- _chunkTVT62GIXjs.__name.call(void 0, Filter, "Filter");
75
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Filter, "Filter");
84
76
  function Pipe(pipe) {
85
77
  return (target, property, index) => {
86
78
  if (typeof index === "number") {
@@ -94,7 +86,7 @@ function Pipe(pipe) {
94
86
  });
95
87
  };
96
88
  }
97
- _chunkTVT62GIXjs.__name.call(void 0, Pipe, "Pipe");
89
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Pipe, "Pipe");
98
90
 
99
91
  // src/decorators/http.ts
100
92
 
@@ -108,7 +100,7 @@ function Route(route, type) {
108
100
  });
109
101
  };
110
102
  }
111
- _chunkTVT62GIXjs.__name.call(void 0, Route, "Route");
103
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Route, "Route");
112
104
  function Header(headers) {
113
105
  return (target, property) => {
114
106
  _phecdacore.setMeta.call(void 0, target, property, void 0, {
@@ -118,31 +110,31 @@ function Header(headers) {
118
110
  });
119
111
  };
120
112
  }
121
- _chunkTVT62GIXjs.__name.call(void 0, Header, "Header");
113
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Header, "Header");
122
114
  function Get(route = "") {
123
115
  return Route(route, "get");
124
116
  }
125
- _chunkTVT62GIXjs.__name.call(void 0, Get, "Get");
117
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Get, "Get");
126
118
  function Post(route = "") {
127
119
  return Route(route, "post");
128
120
  }
129
- _chunkTVT62GIXjs.__name.call(void 0, Post, "Post");
121
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Post, "Post");
130
122
  function Put(route = "") {
131
123
  return Route(route, "put");
132
124
  }
133
- _chunkTVT62GIXjs.__name.call(void 0, Put, "Put");
125
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Put, "Put");
134
126
  function Search(route = "") {
135
127
  return Route(route, "search");
136
128
  }
137
- _chunkTVT62GIXjs.__name.call(void 0, Search, "Search");
129
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Search, "Search");
138
130
  function Patch(route = "") {
139
131
  return Route(route, "patch");
140
132
  }
141
- _chunkTVT62GIXjs.__name.call(void 0, Patch, "Patch");
133
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Patch, "Patch");
142
134
  function Delete(route = "") {
143
135
  return Route(route, "delete");
144
136
  }
145
- _chunkTVT62GIXjs.__name.call(void 0, Delete, "Delete");
137
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Delete, "Delete");
146
138
  function Controller(prefix = "") {
147
139
  return (target) => {
148
140
  _phecdacore.setMeta.call(void 0, target, void 0, void 0, {
@@ -153,7 +145,7 @@ function Controller(prefix = "") {
153
145
  });
154
146
  };
155
147
  }
156
- _chunkTVT62GIXjs.__name.call(void 0, Controller, "Controller");
148
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Controller, "Controller");
157
149
 
158
150
  // src/decorators/rpc.ts
159
151
 
@@ -167,7 +159,7 @@ function Queue(queue = "", isEvent) {
167
159
  });
168
160
  };
169
161
  }
170
- _chunkTVT62GIXjs.__name.call(void 0, Queue, "Queue");
162
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Queue, "Queue");
171
163
  function Rpc() {
172
164
  return (target) => {
173
165
  _phecdacore.setMeta.call(void 0, target, void 0, void 0, {
@@ -175,11 +167,11 @@ function Rpc() {
175
167
  });
176
168
  };
177
169
  }
178
- _chunkTVT62GIXjs.__name.call(void 0, Rpc, "Rpc");
170
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Rpc, "Rpc");
179
171
 
180
172
  // src/decorators/ctx.ts
181
173
 
182
- var Ctx = /* @__PURE__ */ _chunkTVT62GIXjs.__name.call(void 0, (target, property) => {
174
+ var Ctx = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (target, property) => {
183
175
  _phecdacore.setMeta.call(void 0, target, _phecdacore.SHARE_KEY, void 0, {
184
176
  ctxs: [
185
177
  property
@@ -208,8 +200,7 @@ function Define(key, value) {
208
200
  }
209
201
  };
210
202
  }
211
- _chunkTVT62GIXjs.__name.call(void 0, Define, "Define");
212
-
203
+ _chunkJ5CFUN4Vjs.__name.call(void 0, Define, "Define");
213
204
 
214
205
 
215
206
 
@@ -235,4 +226,4 @@ _chunkTVT62GIXjs.__name.call(void 0, Define, "Define");
235
226
 
236
227
 
237
228
 
238
- exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.Guard = Guard; exports.Plugin = Plugin; exports.Interceptor = Interceptor; exports.Filter = Filter; exports.Pipe = Pipe; exports.Route = Route; exports.Header = Header; exports.Get = Get; exports.Post = Post; exports.Put = Put; exports.Search = Search; exports.Patch = Patch; exports.Delete = Delete; exports.Controller = Controller; exports.Queue = Queue; exports.Rpc = Rpc; exports.Ctx = Ctx; exports.Define = Define;
229
+ exports.BaseParam = BaseParam; exports.Body = Body; exports.Head = Head; exports.Query = Query; exports.Param = Param; exports.Arg = Arg; exports.Guard = Guard; exports.Addon = Addon; exports.Filter = Filter; exports.Pipe = Pipe; exports.Route = Route; exports.Header = Header; exports.Get = Get; exports.Post = Post; exports.Put = Put; exports.Search = Search; exports.Patch = Patch; exports.Delete = Delete; exports.Controller = Controller; exports.Queue = Queue; exports.Rpc = Rpc; exports.Ctx = Ctx; exports.Define = Define;
@@ -1,11 +1,10 @@
1
1
  import {
2
2
  ERROR_SYMBOL,
3
3
  IS_HMR,
4
- IS_STRICT,
5
4
  LOG_LEVEL,
6
5
  __name,
7
6
  log
8
- } from "./chunk-G7TD2VB7.mjs";
7
+ } from "./chunk-WHJ5FALK.mjs";
9
8
 
10
9
  // src/helper.ts
11
10
  import pc from "picocolors";
@@ -228,143 +227,120 @@ var Context = class _Context {
228
227
  default: defaultPipe
229
228
  };
230
229
  static guardRecord = {};
231
- static interceptorRecord = {};
232
- static pluginRecord = {};
233
- postInterceptors;
230
+ static addonRecord = {};
234
231
  constructor(data) {
235
232
  this.data = data;
236
233
  if (IS_HMR)
237
234
  data._context = this;
238
235
  }
239
- async run(opts, successCb, failCb) {
240
- const { meta, moduleMap } = this.data;
241
- const { globalGuards = [], globalFilter, globalInterceptors = [], globalPipe } = opts;
242
- const { paramsType, data: { guards, interceptors, params, tag, func, ctxs, filter } } = meta;
243
- try {
244
- await this.useGuard([
236
+ static getAop(meta, opts) {
237
+ const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
238
+ const { data: { guards, filter, params } } = meta;
239
+ return {
240
+ guards: this.getGuards([
245
241
  ...globalGuards,
246
242
  ...guards
247
- ]);
248
- const i1 = await this.useInterceptor([
249
- ...globalInterceptors,
250
- ...interceptors
251
- ]);
252
- if (i1 !== void 0) return successCb(i1);
253
- const args = await this.usePipe(params.map((param) => {
254
- return {
255
- arg: resolveDep(this.data[param.type], param.key),
256
- reflect: paramsType[param.index],
257
- ...param,
258
- pipe: param.pipe || globalPipe
243
+ ]),
244
+ pipe: this.getPipe(params.map((item) => item.pipe || globalPipe)),
245
+ filter: this.getFilter(filter || globalFilter)
246
+ };
247
+ }
248
+ async run({ guards, filter, pipe }, successCb, failCb) {
249
+ const { meta, moduleMap } = this.data;
250
+ const { paramsType, data: { ctxs, tag, params, func } } = meta;
251
+ try {
252
+ let res;
253
+ const nextHandler = /* @__PURE__ */ __name((index) => {
254
+ return async () => {
255
+ if (index === guards.length) {
256
+ const instance = moduleMap.get(tag);
257
+ if (ctxs) {
258
+ ctxs.forEach((ctx) => instance[ctx] = this.data);
259
+ }
260
+ const args = await Promise.all(params.map((item, i) => pipe[i]({
261
+ arg: resolveDep(this.data[item.type], item.key),
262
+ reflect: paramsType[item.index],
263
+ ...item
264
+ }, this.data)));
265
+ res = await instance[func](...args);
266
+ } else {
267
+ let nextPromise;
268
+ async function next() {
269
+ return nextPromise = nextHandler(index + 1)().then((ret2) => {
270
+ if (ret2 !== void 0) {
271
+ debug(`The ${index + 1}th guard rewrite the response value.`);
272
+ res = ret2;
273
+ }
274
+ return res;
275
+ });
276
+ }
277
+ __name(next, "next");
278
+ const ret = await guards[index](this.data, next);
279
+ if (ret !== void 0) {
280
+ res = ret;
281
+ } else {
282
+ if (!nextPromise) await next();
283
+ else await nextPromise;
284
+ }
285
+ }
259
286
  };
260
- }));
261
- const instance = moduleMap.get(tag);
262
- if (ctxs) {
263
- ctxs.forEach((ctx) => instance[ctx] = this.data);
264
- }
265
- const returnData = await instance[func](...args);
266
- const i2 = await this.usePostInterceptor(returnData);
267
- if (i2 !== void 0) return successCb(i2);
268
- return successCb(returnData);
287
+ }, "nextHandler");
288
+ await nextHandler(0)();
289
+ return successCb(res);
269
290
  } catch (e) {
270
- const err = await this.useFilter(e, filter || globalFilter);
291
+ const err = await filter(e, this.data);
271
292
  return failCb(err);
272
293
  }
273
294
  }
274
- usePipe(args) {
275
- return Promise.all(args.map((item) => {
276
- if (item.pipe && !_Context.pipeRecord[item.pipe]) {
277
- if (IS_STRICT) {
278
- throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
279
- } else {
280
- debug(`Can't find pipe named "${item.pipe}" when handling the ${item.index + 1}th argument of the func "${this.data.func}" on module "${this.data.tag}",use default pipe instead`);
281
- return _Context.pipeRecord.default(item, this.data);
282
- }
283
- }
284
- return _Context.pipeRecord[item.pipe || "default"](item, this.data);
285
- }));
286
- }
287
- useFilter(arg, filter = "default") {
288
- if (!_Context.filterRecord[filter]) {
289
- if (IS_STRICT) {
290
- throw new FrameworkException(`can't find filter named "${filter}"`);
291
- } else {
292
- debug(`Can't find filter named "${filter}" when handling func "${this.data.func}" on module "${this.data.tag}",use default filter instead`);
293
- return _Context.filterRecord.default(arg, this.data);
294
- }
295
- }
296
- return _Context.filterRecord[filter](arg, this.data);
297
- }
298
- async useGuard(guards) {
299
- for (const guard of new Set(guards)) {
300
- if (!(guard in _Context.guardRecord)) {
301
- if (IS_STRICT) throw new FrameworkException(`Can't find guard named "${guard}"`);
302
- else debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
303
- continue;
304
- }
305
- if (!await _Context.guardRecord[guard](this.data)) throw new ForbiddenException(`Guard exception--[${guard}]`);
306
- }
295
+ static getPipe(pipe) {
296
+ return pipe.map((pipe2) => {
297
+ return _Context.pipeRecord[pipe2] || _Context.pipeRecord.default;
298
+ });
307
299
  }
308
- async usePostInterceptor(data) {
309
- for (const cb of this.postInterceptors) {
310
- const ret = await cb(data);
311
- if (ret !== void 0) return ret;
312
- }
300
+ static getFilter(filter = "default") {
301
+ return _Context.filterRecord[filter] || _Context.filterRecord.default;
313
302
  }
314
- async useInterceptor(interceptors) {
315
- const cb = [];
316
- for (const interceptor of new Set(interceptors)) {
317
- if (!(interceptor in _Context.interceptorRecord)) {
318
- if (IS_STRICT) throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
319
- else debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
320
- continue;
321
- }
322
- const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
323
- if (interceptRet !== void 0) {
324
- if (typeof interceptRet === "function") cb.push(interceptRet);
325
- else return interceptRet;
326
- }
303
+ static getGuards(guards) {
304
+ const ret = [];
305
+ for (const guard of new Set(guards)) {
306
+ if (guard in _Context.guardRecord) ret.push(_Context.guardRecord[guard]);
327
307
  }
328
- this.postInterceptors = cb;
308
+ return ret.sort((a, b) => b.priority - a.priority).map((item) => item.value);
329
309
  }
330
- static usePlugin(plugins, framework) {
310
+ static applyAddons(addons, router, framework) {
331
311
  const ret = [];
332
- for (const m of new Set(plugins)) {
333
- if (!(m in _Context.pluginRecord)) {
334
- if (IS_STRICT) throw new FrameworkException(`can't find middleware named '${m}'`);
335
- continue;
336
- }
337
- const plugin = _Context.pluginRecord[m](framework);
338
- plugin && ret.push(plugin);
312
+ for (const a of new Set(addons)) {
313
+ if (a in _Context.addonRecord) ret.push(_Context.addonRecord[a]);
339
314
  }
340
- return ret;
315
+ ret.sort((a, b) => b.priority - a.priority).forEach((item) => item.value(router, framework));
341
316
  }
342
317
  };
343
- function addPlugin(key, handler) {
344
- if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler) log(`overwrite Plugin "${String(key)}"`, "warn");
345
- Context.pluginRecord[key] = handler;
346
- }
347
- __name(addPlugin, "addPlugin");
348
- function addPipe(key, handler) {
349
- if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler) log(`overwrite Pipe "${String(key)}"`, "warn");
350
- Context.pipeRecord[key] = handler;
318
+ function addPipe(key, pipe) {
319
+ if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) log(`overwrite Pipe "${String(key)}"`, "warn");
320
+ Context.pipeRecord[key] = pipe;
351
321
  }
352
322
  __name(addPipe, "addPipe");
353
- function addFilter(key, handler) {
354
- if (Context.filterRecord[key] && Context.filterRecord[key] !== handler) log(`overwrite Filter "${String(key)}"`, "warn");
355
- Context.filterRecord[key] = handler;
323
+ function addFilter(key, filter) {
324
+ if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) log(`overwrite Filter "${String(key)}"`, "warn");
325
+ Context.filterRecord[key] = filter;
356
326
  }
357
327
  __name(addFilter, "addFilter");
358
- function addGuard(key, handler) {
359
- if (Context.guardRecord[key] && Context.guardRecord[key] !== handler) log(`overwrite Guard "${String(key)}"`, "warn");
360
- Context.guardRecord[key] = handler;
328
+ function addGuard(key, guard, priority = 0) {
329
+ if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) log(`overwrite Guard "${String(key)}"`, "warn");
330
+ Context.guardRecord[key] = {
331
+ value: guard,
332
+ priority
333
+ };
361
334
  }
362
335
  __name(addGuard, "addGuard");
363
- function addInterceptor(key, handler) {
364
- if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler) log(`overwrite Interceptor "${String(key)}"`, "warn");
365
- Context.interceptorRecord[key] = handler;
336
+ function addAddon(key, addon, priority = 0) {
337
+ if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) log(`overwrite Addon "${String(key)}"`, "warn");
338
+ Context.addonRecord[key] = {
339
+ value: addon,
340
+ priority
341
+ };
366
342
  }
367
- __name(addInterceptor, "addInterceptor");
343
+ __name(addAddon, "addAddon");
368
344
 
369
345
  // src/hmr.ts
370
346
  function HMR(cb) {
@@ -372,7 +348,7 @@ function HMR(cb) {
372
348
  }
373
349
  __name(HMR, "HMR");
374
350
 
375
- // src/server/helper.ts
351
+ // src/http/helper.ts
376
352
  function resolveDep(ret, key) {
377
353
  if (key) return ret?.[key];
378
354
  return ret;
@@ -432,60 +408,50 @@ function createControllerMetaMap(meta, filter) {
432
408
  return metaMap;
433
409
  }
434
410
  __name(createControllerMetaMap, "createControllerMetaMap");
435
- function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller = "http") {
436
- const pluginSet = /* @__PURE__ */ new Set();
411
+ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
412
+ const addonSet = /* @__PURE__ */ new Set();
437
413
  const guardSet = /* @__PURE__ */ new Set();
438
- const interceptorSet = /* @__PURE__ */ new Set();
439
414
  const pipeSet = /* @__PURE__ */ new Set();
440
415
  const filterSet = /* @__PURE__ */ new Set();
441
416
  const warningSet = /* @__PURE__ */ new Set();
442
417
  function handleMeta() {
443
- pluginSet.clear();
418
+ addonSet.clear();
444
419
  guardSet.clear();
445
- interceptorSet.clear();
446
420
  pipeSet.clear();
447
421
  filterSet.clear();
448
422
  warningSet.clear();
449
- plugins?.forEach((item) => {
450
- pluginSet.add(item);
423
+ addons?.forEach((item) => {
424
+ addonSet.add(item);
451
425
  });
452
426
  guards?.forEach((item) => {
453
427
  guardSet.add(item);
454
428
  });
455
- interceptors?.forEach((item) => {
456
- interceptorSet.add(item);
457
- });
458
429
  meta.forEach(({ data }) => {
459
430
  if (data.controller !== controller) {
460
431
  if (data[controller]) warningSet.add(`Module "${data.tag === data.name ? data.name : `${data.name}(${data.tag})`}" should use ${controller} controller to decorate class or remove ${controller} decorator on method "${data.func}"`);
461
432
  return;
462
433
  }
463
434
  if (data.filter) filterSet.add(data.filter);
464
- data.interceptors.forEach((i) => interceptorSet.add(i));
465
435
  data.guards.forEach((i) => guardSet.add(i));
466
- data.plugins.forEach((i) => pluginSet.add(i));
436
+ data.addons.forEach((i) => addonSet.add(i));
467
437
  data.params.forEach((i) => {
468
438
  if (i.pipe) pipeSet.add(i.pipe);
469
439
  });
470
440
  });
471
- const missPlugins = [
472
- ...pluginSet
473
- ].filter((i) => !Context.pluginRecord[i]);
441
+ const missAddons = [
442
+ ...addonSet
443
+ ].filter((i) => !Context.addonRecord[i]);
474
444
  const missGuards = [
475
445
  ...guardSet
476
446
  ].filter((i) => !Context.guardRecord[i]);
477
- const missInterceptors = [
478
- ...interceptorSet
479
- ].filter((i) => !Context.interceptorRecord[i]);
480
447
  const missPipes = [
481
448
  ...pipeSet
482
449
  ].filter((i) => !Context.pipeRecord[i]);
483
450
  const missFilters = [
484
451
  ...filterSet
485
452
  ].filter((i) => !Context.filterRecord[i]);
486
- if (missPlugins.length) log(`${pc.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
453
+ if (missAddons.length) log(`${pc.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
487
454
  if (missGuards.length) log(`${pc.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
488
- if (missInterceptors.length) log(`${pc.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
489
455
  if (missPipes.length) log(`${pc.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
490
456
  if (missFilters.length) log(`${pc.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
491
457
  warningSet.forEach((warn) => log(warn, "warn"));
@@ -494,9 +460,8 @@ function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller =
494
460
  handleMeta();
495
461
  HMR(handleMeta);
496
462
  return {
497
- pluginSet,
463
+ addonSet,
498
464
  guardSet,
499
- interceptorSet,
500
465
  pipeSet,
501
466
  filterSet
502
467
  };
@@ -523,11 +488,10 @@ export {
523
488
  TimerException,
524
489
  WorkerException,
525
490
  Context,
526
- addPlugin,
527
491
  addPipe,
528
492
  addFilter,
529
493
  addGuard,
530
- addInterceptor,
494
+ addAddon,
531
495
  HMR,
532
496
  resolveDep,
533
497
  argToReq,