phecda-server 6.1.0 → 7.0.0-alpha.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 (82) hide show
  1. package/assets/ps.json +24 -24
  2. package/bin/cli.mjs +165 -157
  3. package/dist/{chunk-NL6QBQAR.js → chunk-7YQ57BQS.js} +21 -22
  4. package/dist/chunk-GSPBHZBH.js +534 -0
  5. package/dist/{chunk-J7B24YSE.mjs → chunk-HMVLXNV3.mjs} +5 -14
  6. package/dist/{chunk-TVT62GIX.js → chunk-J5CFUN4V.js} +8 -1
  7. package/dist/{chunk-JDV2XJYE.js → chunk-MBCHNDAY.js} +27 -36
  8. package/dist/{chunk-2CFYUXPM.mjs → chunk-V7EI76QQ.mjs} +136 -141
  9. package/dist/{chunk-G7TD2VB7.mjs → chunk-WHJ5FALK.mjs} +7 -0
  10. package/dist/{chunk-3H3T54IC.mjs → chunk-XYVMNY2X.mjs} +4 -5
  11. package/dist/{core-P1CsH6jz.d.mts → core-BIcUwV18.d.mts} +1 -1
  12. package/dist/{core-BlN0Spy9.d.ts → core-CYwEPfN4.d.ts} +1 -1
  13. package/dist/helper.d.mts +4 -6
  14. package/dist/helper.d.ts +4 -6
  15. package/dist/helper.js +3 -3
  16. package/dist/helper.mjs +2 -2
  17. package/dist/{server → http}/elysia/index.d.mts +5 -5
  18. package/dist/{server → http}/elysia/index.d.ts +5 -5
  19. package/dist/{server → http}/elysia/index.js +80 -62
  20. package/dist/{server → http}/elysia/index.mjs +50 -32
  21. package/dist/{server → http}/express/index.d.mts +5 -5
  22. package/dist/{server → http}/express/index.d.ts +5 -5
  23. package/dist/{server → http}/express/index.js +71 -55
  24. package/dist/{server → http}/express/index.mjs +42 -26
  25. package/dist/{server → http}/fastify/index.d.mts +5 -5
  26. package/dist/{server → http}/fastify/index.d.ts +5 -5
  27. package/dist/{server → http}/fastify/index.js +72 -72
  28. package/dist/{server → http}/fastify/index.mjs +47 -47
  29. package/dist/{server → http}/h3/index.d.mts +5 -5
  30. package/dist/{server → http}/h3/index.d.ts +5 -5
  31. package/dist/http/h3/index.js +160 -0
  32. package/dist/{server → http}/h3/index.mjs +68 -62
  33. package/dist/{server → http}/hono/index.d.mts +5 -5
  34. package/dist/{server → http}/hono/index.d.ts +5 -5
  35. package/dist/{server → http}/hono/index.js +69 -54
  36. package/dist/{server → http}/hono/index.mjs +41 -26
  37. package/dist/{server → http}/hyper-express/index.d.mts +5 -5
  38. package/dist/{server → http}/hyper-express/index.d.ts +5 -5
  39. package/dist/{server → http}/hyper-express/index.js +69 -56
  40. package/dist/{server → http}/hyper-express/index.mjs +41 -28
  41. package/dist/{server → http}/koa/index.d.mts +5 -5
  42. package/dist/{server → http}/koa/index.d.ts +5 -5
  43. package/dist/{server → http}/koa/index.js +71 -55
  44. package/dist/{server → http}/koa/index.mjs +42 -26
  45. package/dist/index.d.mts +52 -41
  46. package/dist/index.d.ts +52 -41
  47. package/dist/index.js +59 -81
  48. package/dist/index.mjs +39 -61
  49. package/dist/{meta-KtfiBIde.d.ts → meta-BXKLFTgG.d.mts} +2 -3
  50. package/dist/{meta-KtfiBIde.d.mts → meta-BXKLFTgG.d.ts} +2 -3
  51. package/dist/rpc/bullmq/index.d.mts +6 -6
  52. package/dist/rpc/bullmq/index.d.ts +6 -6
  53. package/dist/rpc/bullmq/index.js +24 -24
  54. package/dist/rpc/bullmq/index.mjs +14 -14
  55. package/dist/rpc/kafka/index.d.mts +3 -3
  56. package/dist/rpc/kafka/index.d.ts +3 -3
  57. package/dist/rpc/kafka/index.js +25 -21
  58. package/dist/rpc/kafka/index.mjs +15 -11
  59. package/dist/rpc/nats/index.d.mts +3 -3
  60. package/dist/rpc/nats/index.d.ts +3 -3
  61. package/dist/rpc/nats/index.js +22 -21
  62. package/dist/rpc/nats/index.mjs +13 -12
  63. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  64. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  65. package/dist/rpc/rabbitmq/index.js +23 -22
  66. package/dist/rpc/rabbitmq/index.mjs +12 -11
  67. package/dist/rpc/redis/index.d.mts +3 -3
  68. package/dist/rpc/redis/index.d.ts +3 -3
  69. package/dist/rpc/redis/index.js +24 -20
  70. package/dist/rpc/redis/index.mjs +15 -11
  71. package/dist/test.d.mts +3 -3
  72. package/dist/test.d.ts +3 -3
  73. package/dist/test.js +6 -6
  74. package/dist/test.mjs +2 -2
  75. package/dist/{types-JVT0mgLD.d.ts → types-BtbL49Zs.d.mts} +2 -1
  76. package/dist/{types-DIw7B6Up.d.ts → types-VFzEM7LL.d.ts} +5 -5
  77. package/dist/{types-BvD3B5Ny.d.mts → types-h40T3cRG.d.mts} +5 -5
  78. package/dist/{types-t9D1fU6G.d.mts → types-m3IEDKjP.d.ts} +2 -1
  79. package/package.json +23 -23
  80. package/register/loader.mjs +366 -367
  81. package/dist/chunk-DVTBLV6I.js +0 -539
  82. package/dist/server/h3/index.js +0 -154
@@ -0,0 +1,534 @@
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;
2
+
3
+
4
+
5
+
6
+
7
+
8
+ var _chunkJ5CFUN4Vjs = require('./chunk-J5CFUN4V.js');
9
+
10
+ // src/helper.ts
11
+ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
12
+
13
+ // src/context.ts
14
+ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
15
+
16
+
17
+ // src/pipe.ts
18
+ var defaultPipe = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, ({ arg }) => {
19
+ return arg;
20
+ }, "defaultPipe");
21
+
22
+ // src/exception/base.ts
23
+ var Exception = class extends Error {
24
+ static {
25
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "Exception");
26
+ }
27
+
28
+
29
+
30
+ constructor(message, status = 0, description = "Exception") {
31
+ super(message), this.message = message, this.status = status, this.description = description;
32
+ }
33
+ get data() {
34
+ return {
35
+ message: this.message,
36
+ description: this.description,
37
+ status: this.status,
38
+ [_chunkJ5CFUN4Vjs.ERROR_SYMBOL]: true
39
+ };
40
+ }
41
+ };
42
+
43
+ // src/exception/undefine.ts
44
+ var UndefinedException = class extends Exception {
45
+ static {
46
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "UndefinedException");
47
+ }
48
+ constructor(message) {
49
+ super(message, 500, "Undefined error");
50
+ }
51
+ };
52
+
53
+ // src/exception/validate.ts
54
+ var ValidateException = class extends Exception {
55
+ static {
56
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "ValidateException");
57
+ }
58
+ constructor(message) {
59
+ super(message, 400, "Validate exception");
60
+ }
61
+ };
62
+
63
+ // src/exception/forbidden.ts
64
+ var ForbiddenException = class extends Exception {
65
+ static {
66
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "ForbiddenException");
67
+ }
68
+ constructor(message) {
69
+ super(message, 403, "Forbidden resource");
70
+ }
71
+ };
72
+
73
+ // src/exception/bad-request.ts
74
+ var BadRequestException = class extends Exception {
75
+ static {
76
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "BadRequestException");
77
+ }
78
+ constructor(message) {
79
+ super(message, 400, "Bad Request");
80
+ }
81
+ };
82
+
83
+ // src/exception/not-found.ts
84
+ var NotFoundException = class extends Exception {
85
+ static {
86
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "NotFoundException");
87
+ }
88
+ constructor(message) {
89
+ super(message, 404, "Not Found");
90
+ }
91
+ };
92
+
93
+ // src/exception/conflict.ts
94
+ var ConflictException = class extends Exception {
95
+ static {
96
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "ConflictException");
97
+ }
98
+ constructor(message) {
99
+ super(message, 409, "Conflict");
100
+ }
101
+ };
102
+
103
+ // src/exception/bad-gateway.ts
104
+ var BadGatewayException = class extends Exception {
105
+ static {
106
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "BadGatewayException");
107
+ }
108
+ constructor(message) {
109
+ super(message, 502, "Bad Gatrway");
110
+ }
111
+ };
112
+
113
+ // src/exception/invalid-input.ts
114
+ var InvalidInputException = class extends Exception {
115
+ static {
116
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "InvalidInputException");
117
+ }
118
+ constructor(message) {
119
+ super(message, 502, "Invalid Input");
120
+ }
121
+ };
122
+
123
+ // src/exception/media-type.ts
124
+ var UnsupportedMediaTypeException = class extends Exception {
125
+ static {
126
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "UnsupportedMediaTypeException");
127
+ }
128
+ constructor(message) {
129
+ super(message, 415, "Unsupported Media Type");
130
+ }
131
+ };
132
+
133
+ // src/exception/payload-large.ts
134
+ var PayloadLargeException = class extends Exception {
135
+ static {
136
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "PayloadLargeException");
137
+ }
138
+ constructor(message) {
139
+ super(message, 413, "Payload Too Large");
140
+ }
141
+ };
142
+
143
+ // src/exception/timeout.ts
144
+ var TimeoutException = class extends Exception {
145
+ static {
146
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "TimeoutException");
147
+ }
148
+ constructor(message) {
149
+ super(message, 408, "Request Timeout");
150
+ }
151
+ };
152
+
153
+ // src/exception/unauthorized.ts
154
+ var UnauthorizedException = class extends Exception {
155
+ static {
156
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "UnauthorizedException");
157
+ }
158
+ constructor(message) {
159
+ super(message, 401, "Unauthorized");
160
+ }
161
+ };
162
+
163
+ // src/exception/unavailable-service.ts
164
+ var ServiceUnavailableException = class extends Exception {
165
+ static {
166
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "ServiceUnavailableException");
167
+ }
168
+ constructor(message) {
169
+ super(message, 503, "Service Unavailable");
170
+ }
171
+ };
172
+
173
+ // src/exception/framework.ts
174
+ var FrameworkException = class extends Exception {
175
+ static {
176
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "FrameworkException");
177
+ }
178
+ constructor(message) {
179
+ super(`[phecda-server] ${message}`, 500, "Framework Error");
180
+ }
181
+ };
182
+
183
+ // src/exception/timer.ts
184
+ var TimerException = class extends Exception {
185
+ static {
186
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "TimerException");
187
+ }
188
+ constructor(message) {
189
+ super(message, 0, "Timer Error");
190
+ }
191
+ };
192
+
193
+ // src/exception/worker.ts
194
+ var WorkerException = class extends Exception {
195
+ static {
196
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "WorkerException");
197
+ }
198
+ constructor(message) {
199
+ super(message, 0, "Worker Error");
200
+ }
201
+ };
202
+
203
+ // src/filter.ts
204
+ var defaultFilter = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (e) => {
205
+ if (!(e instanceof Exception)) {
206
+ _chunkJ5CFUN4Vjs.log.call(void 0, e.message, "error");
207
+ if (_chunkJ5CFUN4Vjs.LOG_LEVEL <= 0) console.error(e.stack);
208
+ e = new UndefinedException(e.message || e);
209
+ } else {
210
+ _chunkJ5CFUN4Vjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
211
+ if (_chunkJ5CFUN4Vjs.LOG_LEVEL <= 0) console.error(e.stack);
212
+ }
213
+ return e.data;
214
+ }, "defaultFilter");
215
+
216
+ // src/context.ts
217
+ var debug = _debug2.default.call(void 0, "phecda-server(Context)");
218
+ var Context = (_class = class _Context {
219
+ static {
220
+ _chunkJ5CFUN4Vjs.__name.call(void 0, this, "Context");
221
+ }
222
+
223
+
224
+
225
+ static __initStatic() {this.filterRecord = {
226
+ default: defaultFilter
227
+ }}
228
+ static __initStatic2() {this.pipeRecord = {
229
+ default: defaultPipe
230
+ }}
231
+ static __initStatic3() {this.guardRecord = {}}
232
+ static __initStatic4() {this.addonRecord = {}}
233
+ constructor(data) {
234
+ this.data = data;
235
+ if (_chunkJ5CFUN4Vjs.IS_HMR)
236
+ data._context = this;
237
+ }
238
+ static getAop(meta, opts) {
239
+ const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
240
+ const { data: { guards, filter, params, tag, func } } = meta;
241
+ const resolved = {
242
+ guards: [
243
+ ...globalGuards,
244
+ ...guards
245
+ ],
246
+ pipe: params.map((item) => item.pipe || globalPipe),
247
+ filter: filter || globalFilter
248
+ };
249
+ if (process.env.DEBUG) {
250
+ const { guards: guards2, pipe, filter: filter2 } = resolved;
251
+ debug(`func "${tag}-${func}" aop:
252
+ ${_picocolors2.default.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
253
+ ${_picocolors2.default.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
254
+ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
255
+ }
256
+ return {
257
+ guards: this.getGuards(resolved.guards),
258
+ pipe: this.getPipe(resolved.pipe),
259
+ filter: this.getFilter(resolved.filter)
260
+ };
261
+ }
262
+ async run({ guards, filter, pipe }, successCb, failCb) {
263
+ const { meta, moduleMap } = this.data;
264
+ const { paramsType, data: { ctxs, tag, params, func } } = meta;
265
+ try {
266
+ let res;
267
+ const nextHandler = /* @__PURE__ */ _chunkJ5CFUN4Vjs.__name.call(void 0, (index) => {
268
+ return async () => {
269
+ if (index === guards.length) {
270
+ const instance = moduleMap.get(tag);
271
+ if (ctxs) {
272
+ ctxs.forEach((ctx) => instance[ctx] = this.data);
273
+ }
274
+ const args = await Promise.all(params.map((item, i) => pipe[i]({
275
+ arg: resolveDep(this.data[item.type], item.key),
276
+ reflect: paramsType[item.index],
277
+ ...item
278
+ }, this.data)));
279
+ res = await instance[func](...args);
280
+ } else {
281
+ let nextPromise;
282
+ async function next() {
283
+ return nextPromise = nextHandler(index + 1)().then((ret2) => {
284
+ if (ret2 !== void 0) {
285
+ debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
286
+ res = ret2;
287
+ }
288
+ return res;
289
+ });
290
+ }
291
+ _chunkJ5CFUN4Vjs.__name.call(void 0, next, "next");
292
+ const ret = await guards[index](this.data, next);
293
+ if (ret !== void 0) {
294
+ res = ret;
295
+ } else {
296
+ if (!nextPromise) await next();
297
+ else await nextPromise;
298
+ }
299
+ }
300
+ };
301
+ }, "nextHandler");
302
+ await nextHandler(0)();
303
+ return successCb(res);
304
+ } catch (e) {
305
+ const err = await filter(e, this.data);
306
+ return failCb(err);
307
+ }
308
+ }
309
+ static getPipe(pipe) {
310
+ return pipe.map((pipe2) => {
311
+ return _Context.pipeRecord[pipe2] || _Context.pipeRecord.default;
312
+ });
313
+ }
314
+ static getFilter(filter = "default") {
315
+ return _Context.filterRecord[filter] || _Context.filterRecord.default;
316
+ }
317
+ static getGuards(guards) {
318
+ const ret = [];
319
+ for (const guard of new Set(guards)) {
320
+ if (guard in _Context.guardRecord) ret.push(_Context.guardRecord[guard]);
321
+ }
322
+ return ret.sort((a, b) => b.priority - a.priority).map((item) => item.value);
323
+ }
324
+ static applyAddons(addons, router, framework) {
325
+ const ret = [];
326
+ for (const a of new Set(addons)) {
327
+ if (a in _Context.addonRecord) ret.push(_Context.addonRecord[a]);
328
+ }
329
+ ret.sort((a, b) => b.priority - a.priority).forEach((item) => item.value(router, framework));
330
+ }
331
+ }, _class.__initStatic(), _class.__initStatic2(), _class.__initStatic3(), _class.__initStatic4(), _class);
332
+ function addPipe(key, pipe) {
333
+ if (Context.pipeRecord[key] && Context.pipeRecord[key] !== pipe) debug(`overwrite Pipe "${String(key)}"`, "warn");
334
+ Context.pipeRecord[key] = pipe;
335
+ }
336
+ _chunkJ5CFUN4Vjs.__name.call(void 0, addPipe, "addPipe");
337
+ function addFilter(key, filter) {
338
+ if (Context.filterRecord[key] && Context.filterRecord[key] !== filter) debug(`overwrite Filter "${String(key)}"`, "warn");
339
+ Context.filterRecord[key] = filter;
340
+ }
341
+ _chunkJ5CFUN4Vjs.__name.call(void 0, addFilter, "addFilter");
342
+ function addGuard(key, guard, priority = 0) {
343
+ if (Context.guardRecord[key] && Context.guardRecord[key].value !== guard) debug(`overwrite Guard "${String(key)}"`, "warn");
344
+ Context.guardRecord[key] = {
345
+ value: guard,
346
+ priority
347
+ };
348
+ }
349
+ _chunkJ5CFUN4Vjs.__name.call(void 0, addGuard, "addGuard");
350
+ function addAddon(key, addon, priority = 0) {
351
+ if (Context.addonRecord[key] && Context.addonRecord[key].value !== addon) debug(`overwrite Addon "${String(key)}"`, "warn");
352
+ Context.addonRecord[key] = {
353
+ value: addon,
354
+ priority
355
+ };
356
+ }
357
+ _chunkJ5CFUN4Vjs.__name.call(void 0, addAddon, "addAddon");
358
+
359
+ // src/hmr.ts
360
+ function HMR(cb) {
361
+ if (_chunkJ5CFUN4Vjs.IS_HMR) _optionalChain([globalThis, 'access', _ => _.__PS_HMR__, 'optionalAccess', _2 => _2.push, 'call', _3 => _3(cb)]);
362
+ }
363
+ _chunkJ5CFUN4Vjs.__name.call(void 0, HMR, "HMR");
364
+
365
+ // src/http/helper.ts
366
+ function resolveDep(ret, key) {
367
+ if (key) return _optionalChain([ret, 'optionalAccess', _4 => _4[key]]);
368
+ return ret;
369
+ }
370
+ _chunkJ5CFUN4Vjs.__name.call(void 0, resolveDep, "resolveDep");
371
+ function argToReq(params, args, headers) {
372
+ const req = {
373
+ body: {},
374
+ query: {},
375
+ params: {},
376
+ headers
377
+ };
378
+ params.forEach((param) => {
379
+ if (param.key) req[param.type][param.key] = args[param.index];
380
+ else req[param.type] = args[param.index];
381
+ });
382
+ return req;
383
+ }
384
+ _chunkJ5CFUN4Vjs.__name.call(void 0, argToReq, "argToReq");
385
+
386
+ // src/rpc/helper.ts
387
+ var _os = require('os');
388
+ function genClientQueue(key) {
389
+ return `PS-${key ? `${key}-` : ""}${_os.hostname.call(void 0, )}-${process.pid}`;
390
+ }
391
+ _chunkJ5CFUN4Vjs.__name.call(void 0, genClientQueue, "genClientQueue");
392
+
393
+ // src/decorators/helper.ts
394
+ function shallowClone(obj) {
395
+ return {
396
+ ...obj
397
+ };
398
+ }
399
+ _chunkJ5CFUN4Vjs.__name.call(void 0, shallowClone, "shallowClone");
400
+ function mergeObject(...args) {
401
+ return Object.assign({}, ...args);
402
+ }
403
+ _chunkJ5CFUN4Vjs.__name.call(void 0, mergeObject, "mergeObject");
404
+
405
+ // src/helper.ts
406
+ function createControllerMetaMap(meta, filter) {
407
+ const metaMap = /* @__PURE__ */ new Map();
408
+ function handleMeta() {
409
+ metaMap.clear();
410
+ for (const item of meta) {
411
+ const { tag, func } = item.data;
412
+ if (!filter(item)) continue;
413
+ if (metaMap.has(tag)) metaMap.get(tag)[func] = item;
414
+ else metaMap.set(tag, {
415
+ [func]: item
416
+ });
417
+ }
418
+ }
419
+ _chunkJ5CFUN4Vjs.__name.call(void 0, handleMeta, "handleMeta");
420
+ handleMeta();
421
+ HMR(handleMeta);
422
+ return metaMap;
423
+ }
424
+ _chunkJ5CFUN4Vjs.__name.call(void 0, createControllerMetaMap, "createControllerMetaMap");
425
+ function detectAopDep(meta, { guards, addons } = {}, controller = "http") {
426
+ const addonSet = /* @__PURE__ */ new Set();
427
+ const guardSet = /* @__PURE__ */ new Set();
428
+ const pipeSet = /* @__PURE__ */ new Set();
429
+ const filterSet = /* @__PURE__ */ new Set();
430
+ const warningSet = /* @__PURE__ */ new Set();
431
+ function handleMeta() {
432
+ addonSet.clear();
433
+ guardSet.clear();
434
+ pipeSet.clear();
435
+ filterSet.clear();
436
+ warningSet.clear();
437
+ _optionalChain([addons, 'optionalAccess', _5 => _5.forEach, 'call', _6 => _6((item) => {
438
+ addonSet.add(item);
439
+ })]);
440
+ _optionalChain([guards, 'optionalAccess', _7 => _7.forEach, 'call', _8 => _8((item) => {
441
+ guardSet.add(item);
442
+ })]);
443
+ meta.forEach(({ data }) => {
444
+ if (data.controller !== controller) {
445
+ if (data[controller]) warningSet.add(`Should use ${controller} controller to decorate class "${data.name}" or method "${data.func}"`);
446
+ return;
447
+ }
448
+ if (data.filter) filterSet.add(data.filter);
449
+ data.guards.forEach((i) => guardSet.add(i));
450
+ data.addons.forEach((i) => addonSet.add(i));
451
+ data.params.forEach((i) => {
452
+ if (i.pipe) pipeSet.add(i.pipe);
453
+ });
454
+ });
455
+ const missAddons = [
456
+ ...addonSet
457
+ ].filter((i) => !Context.addonRecord[i]);
458
+ const missGuards = [
459
+ ...guardSet
460
+ ].filter((i) => !Context.guardRecord[i]);
461
+ const missPipes = [
462
+ ...pipeSet
463
+ ].filter((i) => !Context.pipeRecord[i]);
464
+ const missFilters = [
465
+ ...filterSet
466
+ ].filter((i) => !Context.filterRecord[i]);
467
+ function exit() {
468
+ if (_chunkJ5CFUN4Vjs.IS_STRICT) process.exit(5);
469
+ }
470
+ _chunkJ5CFUN4Vjs.__name.call(void 0, exit, "exit");
471
+ if (missAddons.length) {
472
+ _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.white(`Addon [${missAddons.join(",")}]`)} doesn't exist`, "warn");
473
+ exit();
474
+ }
475
+ if (missGuards.length) {
476
+ _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
477
+ exit();
478
+ }
479
+ if (missPipes.length) {
480
+ _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
481
+ exit();
482
+ }
483
+ if (missFilters.length) {
484
+ _chunkJ5CFUN4Vjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
485
+ exit();
486
+ }
487
+ warningSet.forEach((warn) => _chunkJ5CFUN4Vjs.log.call(void 0, warn, "warn"));
488
+ if (warningSet.size) exit();
489
+ }
490
+ _chunkJ5CFUN4Vjs.__name.call(void 0, handleMeta, "handleMeta");
491
+ handleMeta();
492
+ HMR(handleMeta);
493
+ return {
494
+ addonSet,
495
+ guardSet,
496
+ pipeSet,
497
+ filterSet
498
+ };
499
+ }
500
+ _chunkJ5CFUN4Vjs.__name.call(void 0, detectAopDep, "detectAopDep");
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+ exports.defaultPipe = defaultPipe; exports.Exception = Exception; exports.UndefinedException = UndefinedException; exports.ValidateException = ValidateException; 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.Context = Context; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addAddon = addAddon; exports.HMR = HMR; exports.resolveDep = resolveDep; exports.argToReq = argToReq; exports.genClientQueue = genClientQueue; exports.shallowClone = shallowClone; exports.mergeObject = mergeObject; exports.createControllerMetaMap = createControllerMetaMap; exports.detectAopDep = detectAopDep;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __name
3
- } from "./chunk-G7TD2VB7.mjs";
3
+ } from "./chunk-WHJ5FALK.mjs";
4
4
 
5
5
  // src/decorators/param.ts
6
6
  import { setMeta } from "phecda-core";
@@ -57,22 +57,14 @@ function Guard(...guards) {
57
57
  };
58
58
  }
59
59
  __name(Guard, "Guard");
60
- function Plugin(...plugins) {
60
+ function Addon(...addons) {
61
61
  return (target, property) => {
62
62
  setMeta2(target, property, void 0, {
63
- plugins
63
+ addons
64
64
  });
65
65
  };
66
66
  }
67
- __name(Plugin, "Plugin");
68
- function Interceptor(...interceptors) {
69
- return (target, property) => {
70
- setMeta2(target, property, void 0, {
71
- interceptors
72
- });
73
- };
74
- }
75
- __name(Interceptor, "Interceptor");
67
+ __name(Addon, "Addon");
76
68
  function Filter(filter) {
77
69
  return (target, property) => {
78
70
  setMeta2(target, property, void 0, {
@@ -218,8 +210,7 @@ export {
218
210
  Param,
219
211
  Arg,
220
212
  Guard,
221
- Plugin,
222
- Interceptor,
213
+ Addon,
223
214
  Filter,
224
215
  Pipe,
225
216
  Route,
@@ -50,6 +50,13 @@ function log(msg, level = "log") {
50
50
  console[level](`${_picocolors2.default.magenta("[phecda-server]")} ${_picocolors2.default.gray(`${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`)} ${_picocolors2.default[color](msg)} ${_picocolors2.default.gray(interval)}`);
51
51
  }
52
52
  __name(log, "log");
53
+ function runMiddleware(ctx, middleware) {
54
+ return new Promise((resolve) => {
55
+ middleware(ctx.getRequest(), ctx.getResponse(), resolve);
56
+ });
57
+ }
58
+ __name(runMiddleware, "runMiddleware");
59
+
53
60
 
54
61
 
55
62
 
@@ -63,4 +70,4 @@ __name(log, "log");
63
70
 
64
71
 
65
72
 
66
- exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_HMR = IS_HMR; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.Mixin = _tsmixer.Mixin;
73
+ exports.__name = __name; exports.ERROR_SYMBOL = ERROR_SYMBOL; exports.IS_HMR = IS_HMR; exports.IS_ONLY_GENERATE = IS_ONLY_GENERATE; exports.IS_STRICT = IS_STRICT; exports.LOG_LEVEL = LOG_LEVEL; exports.PS_EXIT_CODE = PS_EXIT_CODE; exports.setLogger = setLogger; exports.getLogger = getLogger; exports.log = log; exports.runMiddleware = runMiddleware; exports.Mixin = _tsmixer.Mixin;