phecda-server 5.0.0-alpha.11 → 5.0.0-alpha.13

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 (37) hide show
  1. package/dist/{chunk-JJG37LHY.mjs → chunk-BADPI5WG.mjs} +25 -21
  2. package/dist/{chunk-KGMDCF26.mjs → chunk-DJO45NRZ.mjs} +6 -2
  3. package/dist/{chunk-C36XJ7D3.js → chunk-GWLM5DEJ.js} +7 -3
  4. package/dist/{chunk-MZBE4NIO.mjs → chunk-HQ5RLYMA.mjs} +1 -1
  5. package/dist/{chunk-ANH53I6B.js → chunk-INPMEA67.js} +33 -37
  6. package/dist/{chunk-P5LJBZPN.js → chunk-MFCPWVO5.js} +65 -61
  7. package/dist/{chunk-2AI7ID6X.js → chunk-SSZS3GSQ.js} +2 -2
  8. package/dist/{chunk-KKTRNKCF.mjs → chunk-Y7AOZMC2.mjs} +15 -19
  9. package/dist/{core-39d78b79.d.ts → core-11dd822c.d.ts} +8 -5
  10. package/dist/index.d.ts +26 -25
  11. package/dist/index.js +77 -62
  12. package/dist/index.mjs +32 -17
  13. package/dist/rpc/kafka/index.d.ts +1 -1
  14. package/dist/rpc/kafka/index.js +9 -9
  15. package/dist/rpc/kafka/index.mjs +3 -3
  16. package/dist/rpc/rabbitmq/index.d.ts +1 -1
  17. package/dist/rpc/rabbitmq/index.js +9 -9
  18. package/dist/rpc/rabbitmq/index.mjs +3 -3
  19. package/dist/rpc/redis/index.d.ts +1 -1
  20. package/dist/rpc/redis/index.js +9 -9
  21. package/dist/rpc/redis/index.mjs +3 -3
  22. package/dist/server/express/index.d.ts +1 -1
  23. package/dist/server/express/index.js +24 -24
  24. package/dist/server/express/index.mjs +4 -4
  25. package/dist/server/fastify/index.d.ts +1 -1
  26. package/dist/server/fastify/index.js +22 -22
  27. package/dist/server/fastify/index.mjs +4 -4
  28. package/dist/server/h3/index.d.ts +1 -1
  29. package/dist/server/h3/index.js +21 -21
  30. package/dist/server/h3/index.mjs +4 -4
  31. package/dist/server/koa/index.d.ts +1 -1
  32. package/dist/server/koa/index.js +24 -24
  33. package/dist/server/koa/index.mjs +4 -4
  34. package/dist/test.d.ts +5 -4
  35. package/dist/test.js +45 -43
  36. package/dist/test.mjs +42 -40
  37. package/package.json +2 -2
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkC36XJ7D3js = require('./chunk-C36XJ7D3.js');
8
+ var _chunkGWLM5DEJjs = require('./chunk-GWLM5DEJ.js');
9
9
 
10
10
  // src/exception/base.ts
11
11
  var Exception = class extends Error {
@@ -23,11 +23,11 @@ var Exception = class extends Error {
23
23
  message: this.message,
24
24
  description: this.description,
25
25
  status: this.status,
26
- [_chunkC36XJ7D3js.ERROR_SYMBOL]: true
26
+ [_chunkGWLM5DEJjs.ERROR_SYMBOL]: true
27
27
  };
28
28
  }
29
29
  };
30
- _chunkC36XJ7D3js.__name.call(void 0, Exception, "Exception");
30
+ _chunkGWLM5DEJjs.__name.call(void 0, Exception, "Exception");
31
31
 
32
32
  // src/exception/validate.ts
33
33
  var ValidateException = class extends Exception {
@@ -35,11 +35,11 @@ var ValidateException = class extends Exception {
35
35
  super(message, 400, "Validate exception");
36
36
  }
37
37
  };
38
- _chunkC36XJ7D3js.__name.call(void 0, ValidateException, "ValidateException");
38
+ _chunkGWLM5DEJjs.__name.call(void 0, ValidateException, "ValidateException");
39
39
 
40
40
  // src/pipe.ts
41
41
  var _phecdacore = require('phecda-core');
42
- var defaultPipe = /* @__PURE__ */ _chunkC36XJ7D3js.__name.call(void 0, async ({ arg, reflect, index }) => {
42
+ var defaultPipe = /* @__PURE__ */ _chunkGWLM5DEJjs.__name.call(void 0, async ({ arg, reflect, index }) => {
43
43
  if (_phecdacore.isPhecda.call(void 0, reflect)) {
44
44
  const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
45
45
  const err = await _phecdacore.transformClass.call(void 0, instance);
@@ -65,7 +65,7 @@ var UndefinedException = class extends Exception {
65
65
  super(message, 500, "Undefined error");
66
66
  }
67
67
  };
68
- _chunkC36XJ7D3js.__name.call(void 0, UndefinedException, "UndefinedException");
68
+ _chunkGWLM5DEJjs.__name.call(void 0, UndefinedException, "UndefinedException");
69
69
 
70
70
  // src/exception/forbidden.ts
71
71
  var ForbiddenException = class extends Exception {
@@ -73,7 +73,7 @@ var ForbiddenException = class extends Exception {
73
73
  super(message, 403, "Forbidden resource");
74
74
  }
75
75
  };
76
- _chunkC36XJ7D3js.__name.call(void 0, ForbiddenException, "ForbiddenException");
76
+ _chunkGWLM5DEJjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
77
77
 
78
78
  // src/exception/bad-request.ts
79
79
  var BadRequestException = class extends Exception {
@@ -81,7 +81,7 @@ var BadRequestException = class extends Exception {
81
81
  super(message, 400, "Bad Request");
82
82
  }
83
83
  };
84
- _chunkC36XJ7D3js.__name.call(void 0, BadRequestException, "BadRequestException");
84
+ _chunkGWLM5DEJjs.__name.call(void 0, BadRequestException, "BadRequestException");
85
85
 
86
86
  // src/exception/not-found.ts
87
87
  var NotFoundException = class extends Exception {
@@ -89,7 +89,7 @@ var NotFoundException = class extends Exception {
89
89
  super(message, 404, "Not Found");
90
90
  }
91
91
  };
92
- _chunkC36XJ7D3js.__name.call(void 0, NotFoundException, "NotFoundException");
92
+ _chunkGWLM5DEJjs.__name.call(void 0, NotFoundException, "NotFoundException");
93
93
 
94
94
  // src/exception/conflict.ts
95
95
  var ConflictException = class extends Exception {
@@ -97,7 +97,7 @@ var ConflictException = class extends Exception {
97
97
  super(message, 409, "Conflict");
98
98
  }
99
99
  };
100
- _chunkC36XJ7D3js.__name.call(void 0, ConflictException, "ConflictException");
100
+ _chunkGWLM5DEJjs.__name.call(void 0, ConflictException, "ConflictException");
101
101
 
102
102
  // src/exception/bad-gateway.ts
103
103
  var BadGatewayException = class extends Exception {
@@ -105,7 +105,7 @@ var BadGatewayException = class extends Exception {
105
105
  super(message, 502, "Bad Gatrway");
106
106
  }
107
107
  };
108
- _chunkC36XJ7D3js.__name.call(void 0, BadGatewayException, "BadGatewayException");
108
+ _chunkGWLM5DEJjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
109
109
 
110
110
  // src/exception/invalid-input.ts
111
111
  var InvalidInputException = class extends Exception {
@@ -113,7 +113,7 @@ var InvalidInputException = class extends Exception {
113
113
  super(message, 502, "Invalid Input");
114
114
  }
115
115
  };
116
- _chunkC36XJ7D3js.__name.call(void 0, InvalidInputException, "InvalidInputException");
116
+ _chunkGWLM5DEJjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
117
117
 
118
118
  // src/exception/media-type.ts
119
119
  var UnsupportedMediaTypeException = class extends Exception {
@@ -121,7 +121,7 @@ var UnsupportedMediaTypeException = class extends Exception {
121
121
  super(message, 415, "Unsupported Media Type");
122
122
  }
123
123
  };
124
- _chunkC36XJ7D3js.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
124
+ _chunkGWLM5DEJjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
125
125
 
126
126
  // src/exception/payload-large.ts
127
127
  var PayloadLargeException = class extends Exception {
@@ -129,7 +129,7 @@ var PayloadLargeException = class extends Exception {
129
129
  super(message, 413, "Payload Too Large");
130
130
  }
131
131
  };
132
- _chunkC36XJ7D3js.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
132
+ _chunkGWLM5DEJjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
133
133
 
134
134
  // src/exception/timeout.ts
135
135
  var TimeoutException = class extends Exception {
@@ -137,7 +137,7 @@ var TimeoutException = class extends Exception {
137
137
  super(message, 408, "Request Timeout");
138
138
  }
139
139
  };
140
- _chunkC36XJ7D3js.__name.call(void 0, TimeoutException, "TimeoutException");
140
+ _chunkGWLM5DEJjs.__name.call(void 0, TimeoutException, "TimeoutException");
141
141
 
142
142
  // src/exception/unauthorized.ts
143
143
  var UnauthorizedException = class extends Exception {
@@ -145,7 +145,7 @@ var UnauthorizedException = class extends Exception {
145
145
  super(message, 401, "Unauthorized");
146
146
  }
147
147
  };
148
- _chunkC36XJ7D3js.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
148
+ _chunkGWLM5DEJjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
149
149
 
150
150
  // src/exception/unavailable-service.ts
151
151
  var ServiceUnavailableException = class extends Exception {
@@ -153,7 +153,7 @@ var ServiceUnavailableException = class extends Exception {
153
153
  super(message, 503, "Service Unavailable");
154
154
  }
155
155
  };
156
- _chunkC36XJ7D3js.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
156
+ _chunkGWLM5DEJjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
157
157
 
158
158
  // src/exception/framework.ts
159
159
  var FrameworkException = class extends Exception {
@@ -161,24 +161,20 @@ var FrameworkException = class extends Exception {
161
161
  super(`[phecda-server] ${message}`, 500, "Framework Error");
162
162
  }
163
163
  };
164
- _chunkC36XJ7D3js.__name.call(void 0, FrameworkException, "FrameworkException");
164
+ _chunkGWLM5DEJjs.__name.call(void 0, FrameworkException, "FrameworkException");
165
165
 
166
166
  // src/context.ts
167
167
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
168
168
 
169
169
  // src/filter.ts
170
- var defaultFilter = /* @__PURE__ */ _chunkC36XJ7D3js.__name.call(void 0, (e) => {
170
+ var defaultFilter = /* @__PURE__ */ _chunkGWLM5DEJjs.__name.call(void 0, (e) => {
171
171
  if (!(e instanceof Exception)) {
172
- if (_chunkC36XJ7D3js.IS_DEV) {
173
- _chunkC36XJ7D3js.log.call(void 0, e.message, "error");
174
- console.error(e.stack);
175
- }
172
+ _chunkGWLM5DEJjs.log.call(void 0, e.message, "error");
173
+ console.error(e.stack);
176
174
  e = new UndefinedException(e.message || e);
177
175
  } else {
178
- if (_chunkC36XJ7D3js.IS_DEV) {
179
- _chunkC36XJ7D3js.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
180
- console.error(e.stack);
181
- }
176
+ _chunkGWLM5DEJjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
177
+ console.error(e.stack);
182
178
  }
183
179
  return e.data;
184
180
  }, "defaultFilter");
@@ -195,7 +191,7 @@ var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this
195
191
  return false;
196
192
  }
197
193
  }, _class);
198
- _chunkC36XJ7D3js.__name.call(void 0, Histroy, "Histroy");
194
+ _chunkGWLM5DEJjs.__name.call(void 0, Histroy, "Histroy");
199
195
 
200
196
  // src/context.ts
201
197
  var guardRecord = {};
@@ -208,13 +204,13 @@ var _Context = class {
208
204
  constructor(data) {
209
205
  this.data = data;
210
206
  this.history = new Histroy();
211
- if (_chunkC36XJ7D3js.IS_DEV)
207
+ if (_chunkGWLM5DEJjs.IS_DEV)
212
208
  data._context = this;
213
209
  }
214
210
  usePipe(args) {
215
211
  return Promise.all(args.map((item) => {
216
212
  if (item.pipe && !_Context.pipeRecord[item.pipe]) {
217
- if (_chunkC36XJ7D3js.IS_STRICT)
213
+ if (_chunkGWLM5DEJjs.IS_STRICT)
218
214
  throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
219
215
  else
220
216
  return _Context.pipeRecord.default(item, this.data);
@@ -224,7 +220,7 @@ var _Context = class {
224
220
  }
225
221
  useFilter(arg, filter = "default") {
226
222
  if (!_Context.filterRecord[filter]) {
227
- if (_chunkC36XJ7D3js.IS_STRICT)
223
+ if (_chunkGWLM5DEJjs.IS_STRICT)
228
224
  throw new FrameworkException(`can't find filter named '${filter}'`);
229
225
  else
230
226
  return _Context.filterRecord.default(arg, this.data);
@@ -235,7 +231,7 @@ var _Context = class {
235
231
  for (const guard of guards) {
236
232
  if (this.history.record(guard, "guard")) {
237
233
  if (!(guard in _Context.guardRecord)) {
238
- if (_chunkC36XJ7D3js.IS_STRICT)
234
+ if (_chunkGWLM5DEJjs.IS_STRICT)
239
235
  throw new FrameworkException(`can't find guard named '${guard}'`);
240
236
  continue;
241
237
  }
@@ -254,7 +250,7 @@ var _Context = class {
254
250
  for (const interceptor of interceptors) {
255
251
  if (this.history.record(interceptor, "interceptor")) {
256
252
  if (!(interceptor in _Context.interceptorRecord)) {
257
- if (_chunkC36XJ7D3js.IS_STRICT)
253
+ if (_chunkGWLM5DEJjs.IS_STRICT)
258
254
  throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
259
255
  continue;
260
256
  }
@@ -272,50 +268,58 @@ var _Context = class {
272
268
  static usePlugin(plugins) {
273
269
  const ret = [];
274
270
  for (const m of plugins) {
275
- if (!(m in _Context.pluginRecord)) {
276
- if (_chunkC36XJ7D3js.IS_STRICT)
271
+ if (!(m in _Context.addonRecord)) {
272
+ if (_chunkGWLM5DEJjs.IS_STRICT)
277
273
  throw new FrameworkException(`can't find middleware named '${m}'`);
278
274
  continue;
279
275
  }
280
- ret.push(_Context.pluginRecord[m]);
276
+ ret.push(_Context.addonRecord[m]);
281
277
  }
282
278
  return ret;
283
279
  }
284
280
  };
285
281
  var Context = _Context;
286
- _chunkC36XJ7D3js.__name.call(void 0, Context, "Context");
287
- _chunkC36XJ7D3js.__publicField.call(void 0, Context, "filterRecord", {
282
+ _chunkGWLM5DEJjs.__name.call(void 0, Context, "Context");
283
+ _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "filterRecord", {
288
284
  default: defaultFilter
289
285
  });
290
- _chunkC36XJ7D3js.__publicField.call(void 0, Context, "pipeRecord", {
286
+ _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "pipeRecord", {
291
287
  default: defaultPipe
292
288
  });
293
- _chunkC36XJ7D3js.__publicField.call(void 0, Context, "guardRecord", {});
294
- _chunkC36XJ7D3js.__publicField.call(void 0, Context, "interceptorRecord", {});
295
- _chunkC36XJ7D3js.__publicField.call(void 0, Context, "pluginRecord", {});
296
- function addPlugin(key, handler) {
297
- Context.pluginRecord[key] = handler;
289
+ _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "guardRecord", {});
290
+ _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "interceptorRecord", {});
291
+ _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "addonRecord", {});
292
+ function addAddon(key, handler) {
293
+ if (Context.addonRecord[key] && Context.addonRecord[key] !== handler)
294
+ _chunkGWLM5DEJjs.log.call(void 0, `overwrite Addon "${String(key)}"`, "warn");
295
+ Context.addonRecord[key] = handler;
298
296
  }
299
- _chunkC36XJ7D3js.__name.call(void 0, addPlugin, "addPlugin");
300
- function addPipe(key, pipe) {
301
- Context.pipeRecord[key] = pipe;
297
+ _chunkGWLM5DEJjs.__name.call(void 0, addAddon, "addAddon");
298
+ function addPipe(key, handler) {
299
+ if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
300
+ _chunkGWLM5DEJjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
301
+ Context.pipeRecord[key] = handler;
302
302
  }
303
- _chunkC36XJ7D3js.__name.call(void 0, addPipe, "addPipe");
303
+ _chunkGWLM5DEJjs.__name.call(void 0, addPipe, "addPipe");
304
304
  function addFilter(key, handler) {
305
+ if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
306
+ _chunkGWLM5DEJjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
305
307
  Context.filterRecord[key] = handler;
306
308
  }
307
- _chunkC36XJ7D3js.__name.call(void 0, addFilter, "addFilter");
309
+ _chunkGWLM5DEJjs.__name.call(void 0, addFilter, "addFilter");
308
310
  function addGuard(key, handler) {
311
+ if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
312
+ _chunkGWLM5DEJjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
309
313
  Context.guardRecord[key] = handler;
310
314
  }
311
- _chunkC36XJ7D3js.__name.call(void 0, addGuard, "addGuard");
315
+ _chunkGWLM5DEJjs.__name.call(void 0, addGuard, "addGuard");
312
316
  function addInterceptor(key, handler) {
317
+ if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
318
+ _chunkGWLM5DEJjs.log.call(void 0, `overwrite Interceptor "${String(key)}"`, "warn");
313
319
  Context.interceptorRecord[key] = handler;
314
320
  }
315
- _chunkC36XJ7D3js.__name.call(void 0, addInterceptor, "addInterceptor");
321
+ _chunkGWLM5DEJjs.__name.call(void 0, addInterceptor, "addInterceptor");
316
322
  function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
317
- if (!_chunkC36XJ7D3js.IS_DEV)
318
- return;
319
323
  const pluginSet = new Set(plugins);
320
324
  const guardSet = new Set(guards);
321
325
  const interceptorSet = new Set(interceptors);
@@ -334,7 +338,7 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
334
338
  });
335
339
  const missPlugins = [
336
340
  ...pluginSet
337
- ].filter((i) => !Context.pluginRecord[i]);
341
+ ].filter((i) => !Context.addonRecord[i]);
338
342
  const missGuards = [
339
343
  ...guardSet
340
344
  ].filter((i) => !Context.guardRecord[i]);
@@ -348,17 +352,17 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
348
352
  ...filterSet
349
353
  ].filter((i) => !Context.filterRecord[i]);
350
354
  if (missPlugins.length)
351
- _chunkC36XJ7D3js.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
355
+ _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
352
356
  if (missGuards.length)
353
- _chunkC36XJ7D3js.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
357
+ _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
354
358
  if (missInterceptors.length)
355
- _chunkC36XJ7D3js.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
359
+ _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
356
360
  if (missPipes.length)
357
- _chunkC36XJ7D3js.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
361
+ _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
358
362
  if (missFilters.length)
359
- _chunkC36XJ7D3js.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
363
+ _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
360
364
  }
361
- _chunkC36XJ7D3js.__name.call(void 0, isAopDepInject, "isAopDepInject");
365
+ _chunkGWLM5DEJjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
362
366
 
363
367
 
364
368
 
@@ -385,4 +389,4 @@ _chunkC36XJ7D3js.__name.call(void 0, isAopDepInject, "isAopDepInject");
385
389
 
386
390
 
387
391
 
388
- 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.guardRecord = guardRecord; exports.Context = Context; exports.addPlugin = addPlugin; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.isAopDepInject = isAopDepInject;
392
+ 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.guardRecord = guardRecord; exports.Context = Context; exports.addAddon = addAddon; exports.addPipe = addPipe; exports.addFilter = addFilter; exports.addGuard = addGuard; exports.addInterceptor = addInterceptor; exports.isAopDepInject = isAopDepInject;
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkC36XJ7D3js = require('./chunk-C36XJ7D3.js');
3
+ var _chunkGWLM5DEJjs = require('./chunk-GWLM5DEJ.js');
4
4
 
5
5
  // src/helper.ts
6
6
  function resolveDep(ret, key) {
@@ -8,7 +8,7 @@ function resolveDep(ret, key) {
8
8
  return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
9
9
  return ret;
10
10
  }
11
- _chunkC36XJ7D3js.__name.call(void 0, resolveDep, "resolveDep");
11
+ _chunkGWLM5DEJjs.__name.call(void 0, resolveDep, "resolveDep");
12
12
 
13
13
 
14
14
 
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  IS_DEV,
3
- UNMOUNT_SYMBOL,
4
3
  __name,
5
4
  log
6
- } from "./chunk-KGMDCF26.mjs";
5
+ } from "./chunk-DJO45NRZ.mjs";
7
6
 
8
7
  // src/meta.ts
9
8
  var Meta = class {
@@ -103,7 +102,7 @@ __name(generateHTTPCode, "generateHTTPCode");
103
102
  import "reflect-metadata";
104
103
  import fs from "fs";
105
104
  import EventEmitter from "node:events";
106
- import { Empty, SHARE_KEY, getExposeKey, getHandler, getProperty, getState, getTag, injectProperty, isPhecda, registerSerial } from "phecda-core";
105
+ import { Empty, SHARE_KEY, getExposeKey, getHandler, getProperty, getState, getTag, injectProperty, isPhecda, registerSerial, unmountParallel } from "phecda-core";
107
106
  import Debug from "debug";
108
107
  function Injectable() {
109
108
  return (target) => Empty(target);
@@ -121,27 +120,22 @@ async function Factory(Modules, opts = {}) {
121
120
  if (!getProperty("watcher")) {
122
121
  injectProperty("watcher", ({ eventName, instance, key, options }) => {
123
122
  const fn = typeof instance[key] === "function" ? instance[key].bind(instance) : (v) => instance[key] = v;
124
- if (!instance[UNMOUNT_SYMBOL])
125
- instance[UNMOUNT_SYMBOL] = [];
126
- instance[UNMOUNT_SYMBOL].push(() => {
127
- emitter.off(eventName, fn);
128
- });
129
123
  if (options?.once)
130
124
  emitter.once(eventName, fn);
131
125
  else
132
126
  emitter.on(eventName, fn);
127
+ return () => {
128
+ emitter.off(eventName, fn);
129
+ };
133
130
  });
134
131
  }
135
132
  async function del(tag) {
136
133
  if (!moduleMap.has(tag))
137
134
  return;
138
135
  const instance = moduleMap.get(tag);
139
- debug(`unmount module "${tag}"`);
140
- if (instance?.[UNMOUNT_SYMBOL]) {
141
- for (const cb of instance[UNMOUNT_SYMBOL])
142
- await cb();
143
- }
144
- debug(`del module "${tag}"`);
136
+ debug(`unmount module "${String(tag)}"`);
137
+ unmountParallel(instance);
138
+ debug(`del module "${String(tag)}"`);
145
139
  moduleMap.delete(tag);
146
140
  constructorMap.delete(tag);
147
141
  for (let i = meta.length - 1; i >= 0; i--) {
@@ -182,10 +176,10 @@ async function Factory(Modules, opts = {}) {
182
176
  if (moduleMap.has(tag)) {
183
177
  instance = moduleMap.get(tag);
184
178
  if (!instance)
185
- throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${tag}--[module] ${Module}`);
179
+ throw new Error(`exist Circular-Dependency or Multiple modules with the same name/tag [tag] ${String(tag)}--[module] ${Module}`);
186
180
  if (constructorMap.get(tag) !== Module && !constructorSet.has(Module)) {
187
181
  constructorSet.add(Module);
188
- log(`Synonym module: Module taged "${tag}" has been loaded before, so phecda-server won't load Module "${Module.name}"`, "warn");
182
+ log(`Synonym module: Module taged "${String(tag)}" has been loaded before, so phecda-server won't load Module "${Module.name}"`, "warn");
189
183
  }
190
184
  return {
191
185
  instance,
@@ -193,7 +187,7 @@ async function Factory(Modules, opts = {}) {
193
187
  };
194
188
  }
195
189
  moduleMap.set(tag, void 0);
196
- debug(`instantiate module "${tag}"`);
190
+ debug(`instantiate module "${String(tag)}"`);
197
191
  if (paramtypes) {
198
192
  const paramtypesInstances = [];
199
193
  for (const i in paramtypes) {
@@ -208,9 +202,9 @@ async function Factory(Modules, opts = {}) {
208
202
  instance = new Module();
209
203
  }
210
204
  meta.push(...getMetaFromInstance(instance, tag, Module.name));
211
- debug(`init module "${tag}"`);
205
+ debug(`init module "${String(tag)}"`);
212
206
  await registerSerial(instance);
213
- debug(`add module "${tag}"`);
207
+ debug(`add module "${String(tag)}"`);
214
208
  moduleMap.set(tag, instance);
215
209
  constructorMap.set(tag, Module);
216
210
  return {
@@ -280,6 +274,8 @@ function getMetaFromInstance(instance, tag, name) {
280
274
  ...state.rpc
281
275
  };
282
276
  }
277
+ if (typeof tag !== "string" && (meta.rpc || meta.http))
278
+ log(`can't use Tag with ${typeof tag} on http/rpc controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
283
279
  meta.name = name;
284
280
  meta.tag = tag;
285
281
  meta.method = i;
@@ -20,6 +20,7 @@ declare const META_SYMBOL = "__PS_META__";
20
20
  declare const APP_SYMBOL = "__PS__";
21
21
  declare const IS_DEV: boolean;
22
22
  declare const IS_STRICT: boolean;
23
+ declare const IS_LOG_BAN: boolean;
23
24
  declare const ERROR_SYMBOL = "__PS_ERROR__";
24
25
  declare const PS_FILE_RE: RegExp;
25
26
  declare const PS_IMPORT_RE: RegExp;
@@ -64,7 +65,9 @@ declare namespace P {
64
65
  type ResOrErr<R> = {
65
66
  [K in keyof R]: Awaited<R[K]> | Error;
66
67
  };
67
- type Res<T> = T;
68
+ type Res<T> = T extends {
69
+ toJSON(): infer R;
70
+ } ? R : T;
68
71
  type Guard<C extends BaseContext = any> = ((ctx: C) => Promise<boolean> | boolean);
69
72
  type Interceptor<C extends BaseContext = any> = (ctx: C) => (any | ((ret: any) => any));
70
73
  type Pipe<C extends BaseContext = any> = (arg: {
@@ -103,7 +106,7 @@ declare namespace P {
103
106
  plugins: string[];
104
107
  method: string;
105
108
  name: string;
106
- tag: string;
109
+ tag: PropertyKey;
107
110
  }
108
111
  }
109
112
 
@@ -113,12 +116,12 @@ declare function Factory(Modules: (new (...args: any) => any)[], opts?: {
113
116
  http?: string;
114
117
  rpc?: string;
115
118
  }): Promise<{
116
- moduleMap: Map<string, any>;
119
+ moduleMap: Map<PropertyKey, any>;
117
120
  meta: Meta[];
118
121
  constructorMap: Map<any, any>;
119
122
  add: (Module: Construct) => Promise<void>;
120
- del: (tag: string) => Promise<any>;
123
+ del: (tag: PropertyKey) => Promise<any>;
121
124
  destroy: () => Promise<void>;
122
125
  }>;
123
126
 
124
- export { APP_SYMBOL as A, Exception as E, Factory as F, Injectable as I, Meta as M, P, RequestType as R, ToControllerMap as T, UNMOUNT_SYMBOL as U, Emitter as a, PickKeysByValue as b, PickFunc as c, MERGE_SYMBOL as d, emitter as e, MODULE_SYMBOL as f, META_SYMBOL as g, IS_DEV as h, IS_STRICT as i, ERROR_SYMBOL as j, PS_FILE_RE as k, PS_IMPORT_RE as l };
127
+ export { APP_SYMBOL as A, Exception as E, Factory as F, Injectable as I, Meta as M, P, RequestType as R, ToControllerMap as T, UNMOUNT_SYMBOL as U, Emitter as a, PickKeysByValue as b, PickFunc as c, MERGE_SYMBOL as d, emitter as e, MODULE_SYMBOL as f, META_SYMBOL as g, IS_DEV as h, IS_STRICT as i, IS_LOG_BAN as j, ERROR_SYMBOL as k, PS_FILE_RE as l, PS_IMPORT_RE as m };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { E as Exception, P, M as Meta, U as UNMOUNT_SYMBOL } from './core-39d78b79.js';
2
- export { A as APP_SYMBOL, j as ERROR_SYMBOL, a as Emitter, F as Factory, h as IS_DEV, i as IS_STRICT, I as Injectable, d as MERGE_SYMBOL, g as META_SYMBOL, f as MODULE_SYMBOL, k as PS_FILE_RE, l as PS_IMPORT_RE, c as PickFunc, b as PickKeysByValue, R as RequestType, T as ToControllerMap, e as emitter } from './core-39d78b79.js';
1
+ import { E as Exception, P, M as Meta, U as UNMOUNT_SYMBOL } from './core-11dd822c.js';
2
+ export { A as APP_SYMBOL, k as ERROR_SYMBOL, a as Emitter, F as Factory, h as IS_DEV, j as IS_LOG_BAN, i as IS_STRICT, I as Injectable, d as MERGE_SYMBOL, g as META_SYMBOL, f as MODULE_SYMBOL, l as PS_FILE_RE, m as PS_IMPORT_RE, c as PickFunc, b as PickKeysByValue, R as RequestType, T as ToControllerMap, e as emitter } from './core-11dd822c.js';
3
3
  import { Construct } from 'phecda-core';
4
4
  export * from 'phecda-core';
5
5
 
@@ -71,11 +71,11 @@ declare class Context<Data extends P.BaseContext> {
71
71
  method: string;
72
72
  params: string[];
73
73
  history: Histroy;
74
- static filterRecord: Record<string, P.Filter>;
75
- static pipeRecord: Record<string, P.Pipe>;
76
- static guardRecord: Record<string, P.Guard>;
77
- static interceptorRecord: Record<string, P.Interceptor>;
78
- static pluginRecord: Record<string, any>;
74
+ static filterRecord: Record<PropertyKey, P.Filter>;
75
+ static pipeRecord: Record<PropertyKey, P.Pipe>;
76
+ static guardRecord: Record<PropertyKey, P.Guard>;
77
+ static interceptorRecord: Record<PropertyKey, P.Interceptor>;
78
+ static addonRecord: Record<PropertyKey, any>;
79
79
  postInterceptors: Function[];
80
80
  constructor(data: Data);
81
81
  usePipe(args: {
@@ -93,11 +93,11 @@ declare class Context<Data extends P.BaseContext> {
93
93
  useInterceptor(interceptors: string[]): Promise<any>;
94
94
  static usePlugin(plugins: string[]): any[];
95
95
  }
96
- declare function addPlugin<T>(key: string, handler: T): void;
97
- declare function addPipe<C extends P.BaseContext>(key: string, pipe: P.Pipe<C>): void;
98
- declare function addFilter<C extends P.BaseContext>(key: string, handler: P.Filter<C>): void;
99
- declare function addGuard<C extends P.BaseContext>(key: string, handler: P.Guard<C>): void;
100
- declare function addInterceptor<C extends P.BaseContext>(key: string, handler: P.Interceptor<C>): void;
96
+ declare function addAddon<T>(key: PropertyKey, handler: T): void;
97
+ declare function addPipe<C extends P.BaseContext>(key: PropertyKey, handler: P.Pipe<C>): void;
98
+ declare function addFilter<C extends P.BaseContext>(key: PropertyKey, handler: P.Filter<C>): void;
99
+ declare function addGuard<C extends P.BaseContext>(key: PropertyKey, handler: P.Guard<C>): void;
100
+ declare function addInterceptor<C extends P.BaseContext>(key: PropertyKey, handler: P.Interceptor<C>): void;
101
101
  declare function isAopDepInject(meta: Meta[], { guards, interceptors, plugins }?: {
102
102
  guards?: string[];
103
103
  interceptors?: string[];
@@ -113,11 +113,11 @@ declare function Param(key: string): any;
113
113
  declare function Arg(): any;
114
114
 
115
115
  declare function Route(route: string, type?: string): any;
116
- declare function Get(route: string): any;
117
- declare function Post(route: string): any;
118
- declare function Put(route: string): any;
119
- declare function Patch(route: string): any;
120
- declare function Delete(route: string): any;
116
+ declare function Get(route?: string): any;
117
+ declare function Post(route?: string): any;
118
+ declare function Put(route?: string): any;
119
+ declare function Patch(route?: string): any;
120
+ declare function Delete(route?: string): any;
121
121
  declare function Controller(route?: string): any;
122
122
  declare function Rpc(...types: ('rabbitmq' | 'redis' | 'kafka' | string)[]): (target: any, key?: PropertyKey) => void;
123
123
  declare function Event(isEvent?: boolean): (target: any, key?: PropertyKey) => void;
@@ -137,28 +137,29 @@ declare function resolveDep(ret: any, key: string): any;
137
137
  declare class Dev {
138
138
  private readonly [UNMOUNT_SYMBOL];
139
139
  onUnmount(cb: () => void): void;
140
+ private unmount;
140
141
  }
141
142
 
142
143
  declare abstract class PFilter<C extends P.BaseContext = any, E extends Exception = Exception> extends Dev {
143
- readonly key: string;
144
+ readonly key: PropertyKey;
144
145
  constructor(tag?: string);
145
146
  abstract use(error: Error | E, ctx?: C): P.Error;
146
147
  }
147
148
 
148
149
  declare abstract class PGuard<C extends P.BaseContext = any> extends Dev {
149
150
  abstract use(ctx: C): Promise<boolean> | boolean;
150
- readonly key: string;
151
+ readonly key: PropertyKey;
151
152
  constructor(tag?: string);
152
153
  }
153
154
 
154
155
  declare abstract class PInterceptor<C extends P.BaseContext = any> extends Dev {
155
156
  abstract use(ctx: C): Function | Promise<Function> | any;
156
- readonly key: string;
157
+ readonly key: PropertyKey;
157
158
  constructor(tag?: string);
158
159
  }
159
160
 
160
161
  declare abstract class PPipe<C extends P.BaseContext = any> extends Dev {
161
- readonly key: string;
162
+ readonly key: PropertyKey;
162
163
  constructor(tag?: string);
163
164
  abstract use(param: {
164
165
  arg: any;
@@ -171,7 +172,7 @@ declare abstract class PPipe<C extends P.BaseContext = any> extends Dev {
171
172
  }
172
173
 
173
174
  declare abstract class PAddon<Params extends any[] = any[]> extends Dev {
174
- readonly key: string;
175
+ readonly key: PropertyKey;
175
176
  constructor(tag?: string);
176
177
  abstract use(...args: Params): void;
177
178
  }
@@ -188,10 +189,10 @@ interface PExtension<C extends P.BaseContext = any, E extends Exception = Except
188
189
  reflect: any;
189
190
  }, ctx: C): any;
190
191
  filter(error: Error | E, ctx?: C): P.Error;
191
- plugin(...args: any): void;
192
+ addon(...args: any): void;
192
193
  }
193
194
  declare class PExtension extends Dev {
194
- readonly key: string;
195
+ readonly key: PropertyKey;
195
196
  constructor(tag?: string);
196
197
  }
197
198
 
@@ -204,4 +205,4 @@ declare function getConfig<C = any>(key: string, defaultConf?: C): C;
204
205
  declare function setConfig<C = any>(key: string, conf: C, force?: boolean): void;
205
206
  declare function Mix<C1 extends Construct, C2 extends Construct>(InternalClass: C1, ExtendClass: C2): new (...args: ConstructorParameters<C2>) => InstanceType<C1> & InstanceType<C2>;
206
207
 
207
- export { Arg, BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Context, Controller, Define, Delete, Dev, Event, Exception, Filter, ForbiddenException, FrameworkException, Get, Guard, Head, Header, Interceptor, InvalidInputException, Meta, Mix, NotFoundException, P, PAddon, PExtension, PFilter, PGuard, PInterceptor, PPipe, Param, Patch, PayloadLargeException, Pipe, Plugin, Post, Put, Query, Route, Rpc, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addFilter, addGuard, addInterceptor, addPipe, addPlugin, defaultPipe, generateHTTPCode, generateRPCCode, getConfig, guardRecord, isAopDepInject, log, resolveDep, setConfig };
208
+ export { Arg, BadGatewayException, BadRequestException, BaseParam, Body, ConflictException, Context, Controller, Define, Delete, Dev, Event, Exception, Filter, ForbiddenException, FrameworkException, Get, Guard, Head, Header, Interceptor, InvalidInputException, Meta, Mix, NotFoundException, P, PAddon, PExtension, PFilter, PGuard, PInterceptor, PPipe, Param, Patch, PayloadLargeException, Pipe, Plugin, Post, Put, Query, Route, Rpc, ServiceUnavailableException, TimeoutException, UNMOUNT_SYMBOL, UnauthorizedException, UndefinedException, UnsupportedMediaTypeException, ValidateException, addAddon, addFilter, addGuard, addInterceptor, addPipe, defaultPipe, generateHTTPCode, generateRPCCode, getConfig, guardRecord, isAopDepInject, log, resolveDep, setConfig };