phecda-server 5.0.2 → 5.1.1

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 (57) hide show
  1. package/README.md +4 -102
  2. package/bin/cli.mjs +17 -14
  3. package/dist/{chunk-RCTOVYZY.mjs → chunk-2HKQPZDT.mjs} +1 -1
  4. package/dist/{chunk-BXLBWRHS.js → chunk-3BV2GRS7.js} +38 -38
  5. package/dist/{chunk-AB4OX3WV.mjs → chunk-665MB62T.mjs} +127 -99
  6. package/dist/{chunk-YERBWZCS.js → chunk-FSBD5R22.js} +180 -152
  7. package/dist/{chunk-F5YWXY5W.js → chunk-HMPTPTFL.js} +17 -17
  8. package/dist/{chunk-W5EOVGQD.mjs → chunk-UU6RHGRF.mjs} +2 -2
  9. package/dist/{chunk-ITTD2GBR.mjs → chunk-VLV3AO3H.mjs} +7 -19
  10. package/dist/{chunk-YR5Q5F2K.js → chunk-ZP7HNASU.js} +7 -19
  11. package/dist/{core-fd134ffa.d.ts → core-39f27fe8.d.ts} +4 -3
  12. package/dist/{helper-73e8d2f0.d.ts → helper-6133f78f.d.ts} +1 -1
  13. package/dist/{helper-f29f082f.d.ts → helper-fcbf6aa8.d.ts} +4 -3
  14. package/dist/index.d.ts +27 -32
  15. package/dist/index.js +44 -40
  16. package/dist/index.mjs +14 -10
  17. package/dist/rpc/bullmq/index.d.ts +10 -6
  18. package/dist/rpc/bullmq/index.js +32 -53
  19. package/dist/rpc/bullmq/index.mjs +26 -47
  20. package/dist/rpc/kafka/index.d.ts +10 -4
  21. package/dist/rpc/kafka/index.js +20 -37
  22. package/dist/rpc/kafka/index.mjs +15 -32
  23. package/dist/rpc/nats/index.d.ts +2 -2
  24. package/dist/rpc/nats/index.js +20 -34
  25. package/dist/rpc/nats/index.mjs +13 -27
  26. package/dist/rpc/rabbitmq/index.d.ts +2 -2
  27. package/dist/rpc/rabbitmq/index.js +23 -37
  28. package/dist/rpc/rabbitmq/index.mjs +14 -28
  29. package/dist/rpc/redis/index.d.ts +10 -4
  30. package/dist/rpc/redis/index.js +23 -37
  31. package/dist/rpc/redis/index.mjs +16 -30
  32. package/dist/server/elysia/index.d.ts +4 -3
  33. package/dist/server/elysia/index.js +77 -94
  34. package/dist/server/elysia/index.mjs +74 -91
  35. package/dist/server/express/index.d.ts +5 -4
  36. package/dist/server/express/index.js +79 -93
  37. package/dist/server/express/index.mjs +77 -91
  38. package/dist/server/fastify/index.d.ts +8 -5
  39. package/dist/server/fastify/index.js +83 -102
  40. package/dist/server/fastify/index.mjs +79 -98
  41. package/dist/server/h3/index.d.ts +5 -4
  42. package/dist/server/h3/index.js +81 -97
  43. package/dist/server/h3/index.mjs +80 -96
  44. package/dist/server/hono/index.d.ts +5 -4
  45. package/dist/server/hono/index.js +73 -90
  46. package/dist/server/hono/index.mjs +72 -89
  47. package/dist/server/hyper-express/index.d.ts +6 -5
  48. package/dist/server/hyper-express/index.js +78 -96
  49. package/dist/server/hyper-express/index.mjs +77 -95
  50. package/dist/server/koa/index.d.ts +5 -4
  51. package/dist/server/koa/index.js +79 -92
  52. package/dist/server/koa/index.mjs +76 -89
  53. package/dist/test.d.ts +1 -1
  54. package/dist/test.js +6 -6
  55. package/dist/test.mjs +2 -2
  56. package/package.json +9 -8
  57. package/register/loader.mjs +19 -5
@@ -1,4 +1,4 @@
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; } var _class;
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
3
 
4
4
 
@@ -6,7 +6,7 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkYR5Q5F2Kjs = require('./chunk-YR5Q5F2K.js');
9
+ var _chunkZP7HNASUjs = require('./chunk-ZP7HNASU.js');
10
10
 
11
11
  // src/exception/base.ts
12
12
  var Exception = class extends Error {
@@ -24,11 +24,11 @@ var Exception = class extends Error {
24
24
  message: this.message,
25
25
  description: this.description,
26
26
  status: this.status,
27
- [_chunkYR5Q5F2Kjs.ERROR_SYMBOL]: true
27
+ [_chunkZP7HNASUjs.ERROR_SYMBOL]: true
28
28
  };
29
29
  }
30
30
  };
31
- _chunkYR5Q5F2Kjs.__name.call(void 0, Exception, "Exception");
31
+ _chunkZP7HNASUjs.__name.call(void 0, Exception, "Exception");
32
32
 
33
33
  // src/exception/validate.ts
34
34
  var ValidateException = class extends Exception {
@@ -36,11 +36,11 @@ var ValidateException = class extends Exception {
36
36
  super(message, 400, "Validate exception");
37
37
  }
38
38
  };
39
- _chunkYR5Q5F2Kjs.__name.call(void 0, ValidateException, "ValidateException");
39
+ _chunkZP7HNASUjs.__name.call(void 0, ValidateException, "ValidateException");
40
40
 
41
41
  // src/pipe.ts
42
42
  var _phecdacore = require('phecda-core');
43
- var defaultPipe = /* @__PURE__ */ _chunkYR5Q5F2Kjs.__name.call(void 0, ({ arg, reflect, index }) => {
43
+ var defaultPipe = /* @__PURE__ */ _chunkZP7HNASUjs.__name.call(void 0, ({ arg, reflect, index }) => {
44
44
  if (_phecdacore.isPhecda.call(void 0, reflect)) {
45
45
  const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
46
46
  const err = _phecdacore.transformInstance.call(void 0, instance);
@@ -68,7 +68,7 @@ var UndefinedException = class extends Exception {
68
68
  super(message, 500, "Undefined error");
69
69
  }
70
70
  };
71
- _chunkYR5Q5F2Kjs.__name.call(void 0, UndefinedException, "UndefinedException");
71
+ _chunkZP7HNASUjs.__name.call(void 0, UndefinedException, "UndefinedException");
72
72
 
73
73
  // src/exception/forbidden.ts
74
74
  var ForbiddenException = class extends Exception {
@@ -76,7 +76,7 @@ var ForbiddenException = class extends Exception {
76
76
  super(message, 403, "Forbidden resource");
77
77
  }
78
78
  };
79
- _chunkYR5Q5F2Kjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
79
+ _chunkZP7HNASUjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
80
80
 
81
81
  // src/exception/bad-request.ts
82
82
  var BadRequestException = class extends Exception {
@@ -84,7 +84,7 @@ var BadRequestException = class extends Exception {
84
84
  super(message, 400, "Bad Request");
85
85
  }
86
86
  };
87
- _chunkYR5Q5F2Kjs.__name.call(void 0, BadRequestException, "BadRequestException");
87
+ _chunkZP7HNASUjs.__name.call(void 0, BadRequestException, "BadRequestException");
88
88
 
89
89
  // src/exception/not-found.ts
90
90
  var NotFoundException = class extends Exception {
@@ -92,7 +92,7 @@ var NotFoundException = class extends Exception {
92
92
  super(message, 404, "Not Found");
93
93
  }
94
94
  };
95
- _chunkYR5Q5F2Kjs.__name.call(void 0, NotFoundException, "NotFoundException");
95
+ _chunkZP7HNASUjs.__name.call(void 0, NotFoundException, "NotFoundException");
96
96
 
97
97
  // src/exception/conflict.ts
98
98
  var ConflictException = class extends Exception {
@@ -100,7 +100,7 @@ var ConflictException = class extends Exception {
100
100
  super(message, 409, "Conflict");
101
101
  }
102
102
  };
103
- _chunkYR5Q5F2Kjs.__name.call(void 0, ConflictException, "ConflictException");
103
+ _chunkZP7HNASUjs.__name.call(void 0, ConflictException, "ConflictException");
104
104
 
105
105
  // src/exception/bad-gateway.ts
106
106
  var BadGatewayException = class extends Exception {
@@ -108,7 +108,7 @@ var BadGatewayException = class extends Exception {
108
108
  super(message, 502, "Bad Gatrway");
109
109
  }
110
110
  };
111
- _chunkYR5Q5F2Kjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
111
+ _chunkZP7HNASUjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
112
112
 
113
113
  // src/exception/invalid-input.ts
114
114
  var InvalidInputException = class extends Exception {
@@ -116,7 +116,7 @@ var InvalidInputException = class extends Exception {
116
116
  super(message, 502, "Invalid Input");
117
117
  }
118
118
  };
119
- _chunkYR5Q5F2Kjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
119
+ _chunkZP7HNASUjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
120
120
 
121
121
  // src/exception/media-type.ts
122
122
  var UnsupportedMediaTypeException = class extends Exception {
@@ -124,7 +124,7 @@ var UnsupportedMediaTypeException = class extends Exception {
124
124
  super(message, 415, "Unsupported Media Type");
125
125
  }
126
126
  };
127
- _chunkYR5Q5F2Kjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
127
+ _chunkZP7HNASUjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
128
128
 
129
129
  // src/exception/payload-large.ts
130
130
  var PayloadLargeException = class extends Exception {
@@ -132,7 +132,7 @@ var PayloadLargeException = class extends Exception {
132
132
  super(message, 413, "Payload Too Large");
133
133
  }
134
134
  };
135
- _chunkYR5Q5F2Kjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
135
+ _chunkZP7HNASUjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
136
136
 
137
137
  // src/exception/timeout.ts
138
138
  var TimeoutException = class extends Exception {
@@ -140,7 +140,7 @@ var TimeoutException = class extends Exception {
140
140
  super(message, 408, "Request Timeout");
141
141
  }
142
142
  };
143
- _chunkYR5Q5F2Kjs.__name.call(void 0, TimeoutException, "TimeoutException");
143
+ _chunkZP7HNASUjs.__name.call(void 0, TimeoutException, "TimeoutException");
144
144
 
145
145
  // src/exception/unauthorized.ts
146
146
  var UnauthorizedException = class extends Exception {
@@ -148,7 +148,7 @@ var UnauthorizedException = class extends Exception {
148
148
  super(message, 401, "Unauthorized");
149
149
  }
150
150
  };
151
- _chunkYR5Q5F2Kjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
151
+ _chunkZP7HNASUjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
152
152
 
153
153
  // src/exception/unavailable-service.ts
154
154
  var ServiceUnavailableException = class extends Exception {
@@ -156,7 +156,7 @@ var ServiceUnavailableException = class extends Exception {
156
156
  super(message, 503, "Service Unavailable");
157
157
  }
158
158
  };
159
- _chunkYR5Q5F2Kjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
159
+ _chunkZP7HNASUjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
160
160
 
161
161
  // src/exception/framework.ts
162
162
  var FrameworkException = class extends Exception {
@@ -164,7 +164,7 @@ var FrameworkException = class extends Exception {
164
164
  super(`[phecda-server] ${message}`, 500, "Framework Error");
165
165
  }
166
166
  };
167
- _chunkYR5Q5F2Kjs.__name.call(void 0, FrameworkException, "FrameworkException");
167
+ _chunkZP7HNASUjs.__name.call(void 0, FrameworkException, "FrameworkException");
168
168
 
169
169
  // src/exception/timer.ts
170
170
  var TimerException = class extends Exception {
@@ -172,7 +172,7 @@ var TimerException = class extends Exception {
172
172
  super(message, 0, "Timer Error");
173
173
  }
174
174
  };
175
- _chunkYR5Q5F2Kjs.__name.call(void 0, TimerException, "TimerException");
175
+ _chunkZP7HNASUjs.__name.call(void 0, TimerException, "TimerException");
176
176
 
177
177
  // src/exception/worker.ts
178
178
  var WorkerException = class extends Exception {
@@ -180,14 +180,14 @@ var WorkerException = class extends Exception {
180
180
  super(message, 0, "Worker Error");
181
181
  }
182
182
  };
183
- _chunkYR5Q5F2Kjs.__name.call(void 0, WorkerException, "WorkerException");
183
+ _chunkZP7HNASUjs.__name.call(void 0, WorkerException, "WorkerException");
184
184
 
185
185
  // src/hmr.ts
186
186
  function HMR(cb) {
187
- if (_chunkYR5Q5F2Kjs.IS_HMR)
187
+ if (_chunkZP7HNASUjs.IS_HMR)
188
188
  _optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
189
189
  }
190
- _chunkYR5Q5F2Kjs.__name.call(void 0, HMR, "HMR");
190
+ _chunkZP7HNASUjs.__name.call(void 0, HMR, "HMR");
191
191
 
192
192
  // src/server/helper.ts
193
193
  function resolveDep(ret, key) {
@@ -195,7 +195,7 @@ function resolveDep(ret, key) {
195
195
  return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
196
196
  return ret;
197
197
  }
198
- _chunkYR5Q5F2Kjs.__name.call(void 0, resolveDep, "resolveDep");
198
+ _chunkZP7HNASUjs.__name.call(void 0, resolveDep, "resolveDep");
199
199
  function argToReq(params, args, headers) {
200
200
  const req = {
201
201
  body: {},
@@ -211,14 +211,14 @@ function argToReq(params, args, headers) {
211
211
  });
212
212
  return req;
213
213
  }
214
- _chunkYR5Q5F2Kjs.__name.call(void 0, argToReq, "argToReq");
214
+ _chunkZP7HNASUjs.__name.call(void 0, argToReq, "argToReq");
215
215
 
216
216
  // src/rpc/helper.ts
217
217
  var _os = require('os');
218
218
  function genClientQueue(key) {
219
219
  return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
220
220
  }
221
- _chunkYR5Q5F2Kjs.__name.call(void 0, genClientQueue, "genClientQueue");
221
+ _chunkZP7HNASUjs.__name.call(void 0, genClientQueue, "genClientQueue");
222
222
 
223
223
  // src/decorators/helper.ts
224
224
  function shallowClone(obj) {
@@ -226,49 +226,37 @@ function shallowClone(obj) {
226
226
  ...obj
227
227
  };
228
228
  }
229
- _chunkYR5Q5F2Kjs.__name.call(void 0, shallowClone, "shallowClone");
229
+ _chunkZP7HNASUjs.__name.call(void 0, shallowClone, "shallowClone");
230
230
  function mergeObject(...args) {
231
231
  return Object.assign({}, ...args);
232
232
  }
233
- _chunkYR5Q5F2Kjs.__name.call(void 0, mergeObject, "mergeObject");
233
+ _chunkZP7HNASUjs.__name.call(void 0, mergeObject, "mergeObject");
234
234
  function mergeArray(...args) {
235
235
  return args.filter((item) => !!item).flat();
236
236
  }
237
- _chunkYR5Q5F2Kjs.__name.call(void 0, mergeArray, "mergeArray");
237
+ _chunkZP7HNASUjs.__name.call(void 0, mergeArray, "mergeArray");
238
238
 
239
- // src/context.ts
239
+ // src/helper.ts
240
240
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
241
+
242
+ // src/context.ts
241
243
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
242
244
 
243
245
  // src/filter.ts
244
- var defaultFilter = /* @__PURE__ */ _chunkYR5Q5F2Kjs.__name.call(void 0, (e) => {
246
+ var defaultFilter = /* @__PURE__ */ _chunkZP7HNASUjs.__name.call(void 0, (e) => {
245
247
  if (!(e instanceof Exception)) {
246
- _chunkYR5Q5F2Kjs.log.call(void 0, e.message, "error");
247
- if (_chunkYR5Q5F2Kjs.LOG_LEVEL <= 0)
248
+ _chunkZP7HNASUjs.log.call(void 0, e.message, "error");
249
+ if (_chunkZP7HNASUjs.LOG_LEVEL <= 0)
248
250
  console.error(e.stack);
249
251
  e = new UndefinedException(e.message || e);
250
252
  } else {
251
- _chunkYR5Q5F2Kjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
252
- if (_chunkYR5Q5F2Kjs.LOG_LEVEL <= 0)
253
+ _chunkZP7HNASUjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
254
+ if (_chunkZP7HNASUjs.LOG_LEVEL <= 0)
253
255
  console.error(e.stack);
254
256
  }
255
257
  return e.data;
256
258
  }, "defaultFilter");
257
259
 
258
- // src/history.ts
259
- var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this);_class.prototype.__init2.call(this); }
260
- __init() {this.guard = []}
261
- __init2() {this.interceptor = []}
262
- record(name, type) {
263
- if (!this[type].includes(name)) {
264
- this[type].push(name);
265
- return true;
266
- }
267
- return false;
268
- }
269
- }, _class);
270
- _chunkYR5Q5F2Kjs.__name.call(void 0, Histroy, "Histroy");
271
-
272
260
  // src/context.ts
273
261
  var debug = _debug2.default.call(void 0, "phecda-server(Context)");
274
262
  var _Context = class {
@@ -276,11 +264,9 @@ var _Context = class {
276
264
 
277
265
 
278
266
 
279
-
280
267
  constructor(data) {
281
268
  this.data = data;
282
- this.history = new Histroy();
283
- if (_chunkYR5Q5F2Kjs.IS_HMR)
269
+ if (_chunkZP7HNASUjs.IS_HMR)
284
270
  data._context = this;
285
271
  }
286
272
  async run(opts, successCb, failCb) {
@@ -322,7 +308,7 @@ var _Context = class {
322
308
  usePipe(args) {
323
309
  return Promise.all(args.map((item) => {
324
310
  if (item.pipe && !_Context.pipeRecord[item.pipe]) {
325
- if (_chunkYR5Q5F2Kjs.IS_STRICT) {
311
+ if (_chunkZP7HNASUjs.IS_STRICT) {
326
312
  throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
327
313
  } else {
328
314
  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`);
@@ -334,7 +320,7 @@ var _Context = class {
334
320
  }
335
321
  useFilter(arg, filter = "default") {
336
322
  if (!_Context.filterRecord[filter]) {
337
- if (_chunkYR5Q5F2Kjs.IS_STRICT) {
323
+ if (_chunkZP7HNASUjs.IS_STRICT) {
338
324
  throw new FrameworkException(`can't find filter named "${filter}"`);
339
325
  } else {
340
326
  debug(`Can't find filter named "${filter}" when handling func "${this.data.func}" on module "${this.data.tag}",use default filter instead`);
@@ -344,18 +330,16 @@ var _Context = class {
344
330
  return _Context.filterRecord[filter](arg, this.data);
345
331
  }
346
332
  async useGuard(guards) {
347
- for (const guard of guards) {
348
- if (this.history.record(guard, "guard")) {
349
- if (!(guard in _Context.guardRecord)) {
350
- if (_chunkYR5Q5F2Kjs.IS_STRICT)
351
- throw new FrameworkException(`Can't find guard named "${guard}"`);
352
- else
353
- debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
354
- continue;
355
- }
356
- if (!await _Context.guardRecord[guard](this.data))
357
- throw new ForbiddenException(`Guard exception--[${guard}]`);
333
+ for (const guard of new Set(guards)) {
334
+ if (!(guard in _Context.guardRecord)) {
335
+ if (_chunkZP7HNASUjs.IS_STRICT)
336
+ throw new FrameworkException(`Can't find guard named "${guard}"`);
337
+ else
338
+ debug(`Can't find guard named "${guard}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
339
+ continue;
358
340
  }
341
+ if (!await _Context.guardRecord[guard](this.data))
342
+ throw new ForbiddenException(`Guard exception--[${guard}]`);
359
343
  }
360
344
  }
361
345
  async usePostInterceptor(data) {
@@ -367,138 +351,182 @@ var _Context = class {
367
351
  }
368
352
  async useInterceptor(interceptors) {
369
353
  const cb = [];
370
- for (const interceptor of interceptors) {
371
- if (this.history.record(interceptor, "interceptor")) {
372
- if (!(interceptor in _Context.interceptorRecord)) {
373
- if (_chunkYR5Q5F2Kjs.IS_STRICT)
374
- throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
375
- else
376
- debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
377
- continue;
378
- }
379
- const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
380
- if (interceptRet !== void 0) {
381
- if (typeof interceptRet === "function")
382
- cb.push(interceptRet);
383
- else
384
- return interceptRet;
385
- }
354
+ for (const interceptor of new Set(interceptors)) {
355
+ if (!(interceptor in _Context.interceptorRecord)) {
356
+ if (_chunkZP7HNASUjs.IS_STRICT)
357
+ throw new FrameworkException(`can't find interceptor named "${interceptor}"`);
358
+ else
359
+ debug(`Can't find interceptor named "${interceptor}" when handling func "${this.data.func}" on module "${this.data.tag}",skip it`);
360
+ continue;
361
+ }
362
+ const interceptRet = await _Context.interceptorRecord[interceptor](this.data);
363
+ if (interceptRet !== void 0) {
364
+ if (typeof interceptRet === "function")
365
+ cb.push(interceptRet);
366
+ else
367
+ return interceptRet;
386
368
  }
387
369
  }
388
370
  this.postInterceptors = cb;
389
371
  }
390
- static usePlugin(plugins) {
372
+ static usePlugin(plugins, framework) {
391
373
  const ret = [];
392
- for (const m of plugins) {
374
+ for (const m of new Set(plugins)) {
393
375
  if (!(m in _Context.pluginRecord)) {
394
- if (_chunkYR5Q5F2Kjs.IS_STRICT)
376
+ if (_chunkZP7HNASUjs.IS_STRICT)
395
377
  throw new FrameworkException(`can't find middleware named '${m}'`);
396
378
  continue;
397
379
  }
398
- ret.push(_Context.pluginRecord[m]);
380
+ const plugin = _Context.pluginRecord[m](framework);
381
+ plugin && ret.push(plugin);
399
382
  }
400
383
  return ret;
401
384
  }
402
385
  };
403
386
  var Context = _Context;
404
- _chunkYR5Q5F2Kjs.__name.call(void 0, Context, "Context");
405
- _chunkYR5Q5F2Kjs.__publicField.call(void 0, Context, "filterRecord", {
387
+ _chunkZP7HNASUjs.__name.call(void 0, Context, "Context");
388
+ _chunkZP7HNASUjs.__publicField.call(void 0, Context, "filterRecord", {
406
389
  default: defaultFilter
407
390
  });
408
- _chunkYR5Q5F2Kjs.__publicField.call(void 0, Context, "pipeRecord", {
391
+ _chunkZP7HNASUjs.__publicField.call(void 0, Context, "pipeRecord", {
409
392
  default: defaultPipe
410
393
  });
411
- _chunkYR5Q5F2Kjs.__publicField.call(void 0, Context, "guardRecord", {});
412
- _chunkYR5Q5F2Kjs.__publicField.call(void 0, Context, "interceptorRecord", {});
413
- _chunkYR5Q5F2Kjs.__publicField.call(void 0, Context, "pluginRecord", {});
394
+ _chunkZP7HNASUjs.__publicField.call(void 0, Context, "guardRecord", {});
395
+ _chunkZP7HNASUjs.__publicField.call(void 0, Context, "interceptorRecord", {});
396
+ _chunkZP7HNASUjs.__publicField.call(void 0, Context, "pluginRecord", {});
414
397
  function addPlugin(key, handler) {
415
398
  if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)
416
- _chunkYR5Q5F2Kjs.log.call(void 0, `overwrite Plugin "${String(key)}"`, "warn");
399
+ _chunkZP7HNASUjs.log.call(void 0, `overwrite Plugin "${String(key)}"`, "warn");
417
400
  Context.pluginRecord[key] = handler;
418
401
  }
419
- _chunkYR5Q5F2Kjs.__name.call(void 0, addPlugin, "addPlugin");
402
+ _chunkZP7HNASUjs.__name.call(void 0, addPlugin, "addPlugin");
420
403
  function addPipe(key, handler) {
421
404
  if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
422
- _chunkYR5Q5F2Kjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
405
+ _chunkZP7HNASUjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
423
406
  Context.pipeRecord[key] = handler;
424
407
  }
425
- _chunkYR5Q5F2Kjs.__name.call(void 0, addPipe, "addPipe");
408
+ _chunkZP7HNASUjs.__name.call(void 0, addPipe, "addPipe");
426
409
  function addFilter(key, handler) {
427
410
  if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
428
- _chunkYR5Q5F2Kjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
411
+ _chunkZP7HNASUjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
429
412
  Context.filterRecord[key] = handler;
430
413
  }
431
- _chunkYR5Q5F2Kjs.__name.call(void 0, addFilter, "addFilter");
414
+ _chunkZP7HNASUjs.__name.call(void 0, addFilter, "addFilter");
432
415
  function addGuard(key, handler) {
433
416
  if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
434
- _chunkYR5Q5F2Kjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
417
+ _chunkZP7HNASUjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
435
418
  Context.guardRecord[key] = handler;
436
419
  }
437
- _chunkYR5Q5F2Kjs.__name.call(void 0, addGuard, "addGuard");
420
+ _chunkZP7HNASUjs.__name.call(void 0, addGuard, "addGuard");
438
421
  function addInterceptor(key, handler) {
439
422
  if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
440
- _chunkYR5Q5F2Kjs.log.call(void 0, `overwrite Interceptor "${String(key)}"`, "warn");
423
+ _chunkZP7HNASUjs.log.call(void 0, `overwrite Interceptor "${String(key)}"`, "warn");
441
424
  Context.interceptorRecord[key] = handler;
442
425
  }
443
- _chunkYR5Q5F2Kjs.__name.call(void 0, addInterceptor, "addInterceptor");
426
+ _chunkZP7HNASUjs.__name.call(void 0, addInterceptor, "addInterceptor");
427
+
428
+ // src/helper.ts
429
+ function createControllerMetaMap(meta, filter) {
430
+ const metaMap = /* @__PURE__ */ new Map();
431
+ function handleMeta() {
432
+ metaMap.clear();
433
+ for (const item of meta) {
434
+ const { tag, func } = item.data;
435
+ if (!filter(item))
436
+ continue;
437
+ if (metaMap.has(tag))
438
+ metaMap.get(tag)[func] = item;
439
+ else
440
+ metaMap.set(tag, {
441
+ [func]: item
442
+ });
443
+ }
444
+ }
445
+ _chunkZP7HNASUjs.__name.call(void 0, handleMeta, "handleMeta");
446
+ handleMeta();
447
+ HMR(handleMeta);
448
+ return metaMap;
449
+ }
450
+ _chunkZP7HNASUjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
444
451
  function detectAopDep(meta, { guards, interceptors, plugins } = {}, controller = "http") {
445
- const pluginSet = new Set(plugins);
446
- const guardSet = new Set(guards);
447
- const interceptorSet = new Set(interceptors);
452
+ const pluginSet = /* @__PURE__ */ new Set();
453
+ const guardSet = /* @__PURE__ */ new Set();
454
+ const interceptorSet = /* @__PURE__ */ new Set();
448
455
  const pipeSet = /* @__PURE__ */ new Set();
449
456
  const filterSet = /* @__PURE__ */ new Set();
450
457
  const warningSet = /* @__PURE__ */ new Set();
451
- meta.forEach(({ data }) => {
452
- if (data.controller !== controller) {
453
- if (data[controller])
454
- 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}"`);
455
- return;
456
- }
457
- if (data.filter)
458
- filterSet.add(data.filter);
459
- data.interceptors.forEach((i) => interceptorSet.add(i));
460
- data.guards.forEach((i) => guardSet.add(i));
461
- data.plugins.forEach((i) => pluginSet.add(i));
462
- data.params.forEach((i) => {
463
- if (i.pipe)
464
- pipeSet.add(i.pipe);
458
+ function handleMeta() {
459
+ pluginSet.clear();
460
+ guardSet.clear();
461
+ interceptorSet.clear();
462
+ pipeSet.clear();
463
+ filterSet.clear();
464
+ warningSet.clear();
465
+ _optionalChain([plugins, 'optionalAccess', _5 => _5.forEach, 'call', _6 => _6((item) => {
466
+ pluginSet.add(item);
467
+ })]);
468
+ _optionalChain([guards, 'optionalAccess', _7 => _7.forEach, 'call', _8 => _8((item) => {
469
+ guardSet.add(item);
470
+ })]);
471
+ _optionalChain([interceptors, 'optionalAccess', _9 => _9.forEach, 'call', _10 => _10((item) => {
472
+ interceptorSet.add(item);
473
+ })]);
474
+ meta.forEach(({ data }) => {
475
+ if (data.controller !== controller) {
476
+ if (data[controller])
477
+ 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}"`);
478
+ return;
479
+ }
480
+ if (data.filter)
481
+ filterSet.add(data.filter);
482
+ data.interceptors.forEach((i) => interceptorSet.add(i));
483
+ data.guards.forEach((i) => guardSet.add(i));
484
+ data.plugins.forEach((i) => pluginSet.add(i));
485
+ data.params.forEach((i) => {
486
+ if (i.pipe)
487
+ pipeSet.add(i.pipe);
488
+ });
465
489
  });
466
- });
467
- const missPlugins = [
468
- ...pluginSet
469
- ].filter((i) => !Context.pluginRecord[i]);
470
- const missGuards = [
471
- ...guardSet
472
- ].filter((i) => !Context.guardRecord[i]);
473
- const missInterceptors = [
474
- ...interceptorSet
475
- ].filter((i) => !Context.interceptorRecord[i]);
476
- const missPipes = [
477
- ...pipeSet
478
- ].filter((i) => !Context.pipeRecord[i]);
479
- const missFilters = [
480
- ...filterSet
481
- ].filter((i) => !Context.filterRecord[i]);
482
- if (missPlugins.length)
483
- _chunkYR5Q5F2Kjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
484
- if (missGuards.length)
485
- _chunkYR5Q5F2Kjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
486
- if (missInterceptors.length)
487
- _chunkYR5Q5F2Kjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
488
- if (missPipes.length)
489
- _chunkYR5Q5F2Kjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
490
- if (missFilters.length)
491
- _chunkYR5Q5F2Kjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
492
- warningSet.forEach((warn) => _chunkYR5Q5F2Kjs.log.call(void 0, warn, "warn"));
490
+ const missPlugins = [
491
+ ...pluginSet
492
+ ].filter((i) => !Context.pluginRecord[i]);
493
+ const missGuards = [
494
+ ...guardSet
495
+ ].filter((i) => !Context.guardRecord[i]);
496
+ const missInterceptors = [
497
+ ...interceptorSet
498
+ ].filter((i) => !Context.interceptorRecord[i]);
499
+ const missPipes = [
500
+ ...pipeSet
501
+ ].filter((i) => !Context.pipeRecord[i]);
502
+ const missFilters = [
503
+ ...filterSet
504
+ ].filter((i) => !Context.filterRecord[i]);
505
+ if (missPlugins.length)
506
+ _chunkZP7HNASUjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
507
+ if (missGuards.length)
508
+ _chunkZP7HNASUjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
509
+ if (missInterceptors.length)
510
+ _chunkZP7HNASUjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
511
+ if (missPipes.length)
512
+ _chunkZP7HNASUjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
513
+ if (missFilters.length)
514
+ _chunkZP7HNASUjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
515
+ warningSet.forEach((warn) => _chunkZP7HNASUjs.log.call(void 0, warn, "warn"));
516
+ }
517
+ _chunkZP7HNASUjs.__name.call(void 0, handleMeta, "handleMeta");
518
+ handleMeta();
519
+ HMR(handleMeta);
493
520
  return {
494
- missPlugins,
495
- missGuards,
496
- missInterceptors,
497
- missPipes,
498
- missFilters
521
+ pluginSet,
522
+ guardSet,
523
+ interceptorSet,
524
+ pipeSet,
525
+ filterSet
499
526
  };
500
527
  }
501
- _chunkYR5Q5F2Kjs.__name.call(void 0, detectAopDep, "detectAopDep");
528
+ _chunkZP7HNASUjs.__name.call(void 0, detectAopDep, "detectAopDep");
529
+
502
530
 
503
531
 
504
532
 
@@ -533,4 +561,4 @@ _chunkYR5Q5F2Kjs.__name.call(void 0, detectAopDep, "detectAopDep");
533
561
 
534
562
 
535
563
 
536
- exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.TimerException = TimerException; exports.WorkerException = WorkerException; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.mergeArray = mergeArray; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.detectAopDep = detectAopDep;
564
+ exports.Exception = Exception; exports.ValidateException = ValidateException; exports.defaultPipe = defaultPipe; exports.UndefinedException = UndefinedException; exports.ForbiddenException = ForbiddenException; exports.BadRequestException = BadRequestException; exports.NotFoundException = NotFoundException; exports.ConflictException = ConflictException; exports.BadGatewayException = BadGatewayException; exports.InvalidInputException = InvalidInputException; exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException; exports.PayloadLargeException = PayloadLargeException; exports.TimeoutException = TimeoutException; exports.UnauthorizedException = UnauthorizedException; exports.ServiceUnavailableException = ServiceUnavailableException; exports.FrameworkException = FrameworkException; exports.TimerException = TimerException; exports.WorkerException = WorkerException; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.mergeArray = mergeArray; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor;