phecda-server 5.0.0-alpha.12 → 5.0.0-alpha.14

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 (38) hide show
  1. package/dist/chunk-6FRXLKGA.mjs +32 -0
  2. package/dist/{chunk-SSZS3GSQ.js → chunk-CRAV4WSB.js} +21 -4
  3. package/dist/{chunk-L5SFPHG6.mjs → chunk-MGHJFKVZ.mjs} +20 -17
  4. package/dist/{chunk-UXPHQ7OT.mjs → chunk-O3NJOWWO.mjs} +15 -19
  5. package/dist/{chunk-DJO45NRZ.mjs → chunk-ONUMVNO7.mjs} +2 -2
  6. package/dist/{chunk-GWLM5DEJ.js → chunk-T4C6CCWM.js} +2 -2
  7. package/dist/{chunk-KOWUK5OV.js → chunk-VUOACQPJ.js} +62 -59
  8. package/dist/{chunk-27WMBKFH.js → chunk-WOJAARJJ.js} +33 -37
  9. package/dist/{core-295348b7.d.ts → core-b8dcc009.d.ts} +14 -4
  10. package/dist/index.d.ts +27 -23
  11. package/dist/index.js +75 -59
  12. package/dist/index.mjs +32 -16
  13. package/dist/rpc/kafka/index.d.ts +2 -1
  14. package/dist/rpc/kafka/index.js +9 -9
  15. package/dist/rpc/kafka/index.mjs +2 -2
  16. package/dist/rpc/rabbitmq/index.d.ts +2 -1
  17. package/dist/rpc/rabbitmq/index.js +9 -9
  18. package/dist/rpc/rabbitmq/index.mjs +2 -2
  19. package/dist/rpc/redis/index.d.ts +2 -1
  20. package/dist/rpc/redis/index.js +9 -9
  21. package/dist/rpc/redis/index.mjs +2 -2
  22. package/dist/server/express/index.d.ts +3 -3
  23. package/dist/server/express/index.js +37 -31
  24. package/dist/server/express/index.mjs +17 -11
  25. package/dist/server/fastify/index.d.ts +3 -3
  26. package/dist/server/fastify/index.js +35 -30
  27. package/dist/server/fastify/index.mjs +17 -12
  28. package/dist/server/h3/index.d.ts +3 -3
  29. package/dist/server/h3/index.js +37 -46
  30. package/dist/server/h3/index.mjs +20 -29
  31. package/dist/server/koa/index.d.ts +3 -3
  32. package/dist/server/koa/index.js +36 -29
  33. package/dist/server/koa/index.mjs +16 -9
  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
  38. package/dist/chunk-HQ5RLYMA.mjs +0 -15
@@ -0,0 +1,32 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-ONUMVNO7.mjs";
4
+
5
+ // src/server/helper.ts
6
+ function resolveDep(ret, key) {
7
+ if (key)
8
+ return ret?.[key];
9
+ return ret;
10
+ }
11
+ __name(resolveDep, "resolveDep");
12
+ function argToReq(params, args, headers) {
13
+ const req = {
14
+ body: {},
15
+ query: {},
16
+ params: {},
17
+ headers
18
+ };
19
+ params.forEach((param) => {
20
+ if (param.key)
21
+ req[param.type][param.key] = args[param.index];
22
+ else
23
+ req[param.type] = args[param.index];
24
+ });
25
+ return req;
26
+ }
27
+ __name(argToReq, "argToReq");
28
+
29
+ export {
30
+ resolveDep,
31
+ argToReq
32
+ };
@@ -1,15 +1,32 @@
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 _chunkGWLM5DEJjs = require('./chunk-GWLM5DEJ.js');
3
+ var _chunkT4C6CCWMjs = require('./chunk-T4C6CCWM.js');
4
4
 
5
- // src/helper.ts
5
+ // src/server/helper.ts
6
6
  function resolveDep(ret, key) {
7
7
  if (key)
8
8
  return _optionalChain([ret, 'optionalAccess', _ => _[key]]);
9
9
  return ret;
10
10
  }
11
- _chunkGWLM5DEJjs.__name.call(void 0, resolveDep, "resolveDep");
11
+ _chunkT4C6CCWMjs.__name.call(void 0, resolveDep, "resolveDep");
12
+ function argToReq(params, args, headers) {
13
+ const req = {
14
+ body: {},
15
+ query: {},
16
+ params: {},
17
+ headers
18
+ };
19
+ params.forEach((param) => {
20
+ if (param.key)
21
+ req[param.type][param.key] = args[param.index];
22
+ else
23
+ req[param.type] = args[param.index];
24
+ });
25
+ return req;
26
+ }
27
+ _chunkT4C6CCWMjs.__name.call(void 0, argToReq, "argToReq");
28
+
12
29
 
13
30
 
14
31
 
15
- exports.resolveDep = resolveDep;
32
+ exports.resolveDep = resolveDep; exports.argToReq = argToReq;
@@ -1,11 +1,12 @@
1
1
  import {
2
2
  ERROR_SYMBOL,
3
3
  IS_DEV,
4
+ IS_LOG_BAN,
4
5
  IS_STRICT,
5
6
  __name,
6
7
  __publicField,
7
8
  log
8
- } from "./chunk-DJO45NRZ.mjs";
9
+ } from "./chunk-ONUMVNO7.mjs";
9
10
 
10
11
  // src/exception/base.ts
11
12
  var Exception = class extends Error {
@@ -170,11 +171,13 @@ import pc from "picocolors";
170
171
  var defaultFilter = /* @__PURE__ */ __name((e) => {
171
172
  if (!(e instanceof Exception)) {
172
173
  log(e.message, "error");
173
- console.error(e.stack);
174
+ if (!IS_LOG_BAN)
175
+ console.error(e.stack);
174
176
  e = new UndefinedException(e.message || e);
175
177
  } else {
176
178
  log(`[${e.constructor.name}] ${e.message}`, "error");
177
- console.error(e.stack);
179
+ if (!IS_LOG_BAN)
180
+ console.error(e.stack);
178
181
  }
179
182
  return e.data;
180
183
  }, "defaultFilter");
@@ -268,12 +271,12 @@ var _Context = class {
268
271
  static usePlugin(plugins) {
269
272
  const ret = [];
270
273
  for (const m of plugins) {
271
- if (!(m in _Context.addonRecord)) {
274
+ if (!(m in _Context.pluginRecord)) {
272
275
  if (IS_STRICT)
273
276
  throw new FrameworkException(`can't find middleware named '${m}'`);
274
277
  continue;
275
278
  }
276
- ret.push(_Context.addonRecord[m]);
279
+ ret.push(_Context.pluginRecord[m]);
277
280
  }
278
281
  return ret;
279
282
  }
@@ -288,34 +291,34 @@ __publicField(Context, "pipeRecord", {
288
291
  });
289
292
  __publicField(Context, "guardRecord", {});
290
293
  __publicField(Context, "interceptorRecord", {});
291
- __publicField(Context, "addonRecord", {});
292
- function addAddon(key, handler) {
293
- if (Context.addonRecord[key] && Context.addonRecord[key] !== handler)
294
- log(`overwrite Addon "${key}"`, "warn");
295
- Context.addonRecord[key] = handler;
294
+ __publicField(Context, "pluginRecord", {});
295
+ function addPlugin(key, handler) {
296
+ if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)
297
+ log(`overwrite Plugin "${String(key)}"`, "warn");
298
+ Context.pluginRecord[key] = handler;
296
299
  }
297
- __name(addAddon, "addAddon");
300
+ __name(addPlugin, "addPlugin");
298
301
  function addPipe(key, handler) {
299
302
  if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
300
- log(`overwrite Pipe "${key}"`, "warn");
303
+ log(`overwrite Pipe "${String(key)}"`, "warn");
301
304
  Context.pipeRecord[key] = handler;
302
305
  }
303
306
  __name(addPipe, "addPipe");
304
307
  function addFilter(key, handler) {
305
308
  if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
306
- log(`overwrite Filter "${key}"`, "warn");
309
+ log(`overwrite Filter "${String(key)}"`, "warn");
307
310
  Context.filterRecord[key] = handler;
308
311
  }
309
312
  __name(addFilter, "addFilter");
310
313
  function addGuard(key, handler) {
311
314
  if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
312
- log(`overwrite Guard "${key}"`, "warn");
315
+ log(`overwrite Guard "${String(key)}"`, "warn");
313
316
  Context.guardRecord[key] = handler;
314
317
  }
315
318
  __name(addGuard, "addGuard");
316
319
  function addInterceptor(key, handler) {
317
320
  if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
318
- log(`overwrite Interceptor "${key}"`, "warn");
321
+ log(`overwrite Interceptor "${String(key)}"`, "warn");
319
322
  Context.interceptorRecord[key] = handler;
320
323
  }
321
324
  __name(addInterceptor, "addInterceptor");
@@ -338,7 +341,7 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
338
341
  });
339
342
  const missPlugins = [
340
343
  ...pluginSet
341
- ].filter((i) => !Context.addonRecord[i]);
344
+ ].filter((i) => !Context.pluginRecord[i]);
342
345
  const missGuards = [
343
346
  ...guardSet
344
347
  ].filter((i) => !Context.guardRecord[i]);
@@ -383,7 +386,7 @@ export {
383
386
  FrameworkException,
384
387
  guardRecord,
385
388
  Context,
386
- addAddon,
389
+ addPlugin,
387
390
  addPipe,
388
391
  addFilter,
389
392
  addGuard,
@@ -1,9 +1,8 @@
1
1
  import {
2
2
  IS_DEV,
3
- UNMOUNT_SYMBOL,
4
3
  __name,
5
4
  log
6
- } from "./chunk-DJO45NRZ.mjs";
5
+ } from "./chunk-ONUMVNO7.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;
@@ -16,8 +16,8 @@ var IS_DEV = process.env.NODE_ENV === "development";
16
16
  var IS_STRICT = !!process.env.PS_STRICT;
17
17
  var IS_LOG_BAN = !!process.env.PS_LOG_BAN;
18
18
  var ERROR_SYMBOL = "__PS_ERROR__";
19
- var PS_FILE_RE = /\.(controller|service|module|extension|ext|guard|interceptor|addon|filter|pipe|edge)\.ts$/i;
20
- var PS_IMPORT_RE = /\.(controller|extension|ext|guard|interceptor|addon|filter|pipe|edge)\.ts$/i;
19
+ var PS_FILE_RE = /\.(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
20
+ var PS_IMPORT_RE = /\.(controller|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
21
21
 
22
22
  // src/utils.ts
23
23
  import pc from "picocolors";
@@ -16,8 +16,8 @@ var IS_DEV = process.env.NODE_ENV === "development";
16
16
  var IS_STRICT = !!process.env.PS_STRICT;
17
17
  var IS_LOG_BAN = !!process.env.PS_LOG_BAN;
18
18
  var ERROR_SYMBOL = "__PS_ERROR__";
19
- var PS_FILE_RE = /\.(controller|service|module|extension|ext|guard|interceptor|addon|filter|pipe|edge)\.ts$/i;
20
- var PS_IMPORT_RE = /\.(controller|extension|ext|guard|interceptor|addon|filter|pipe|edge)\.ts$/i;
19
+ var PS_FILE_RE = /\.(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
20
+ var PS_IMPORT_RE = /\.(controller|extension|ext|guard|interceptor|plugin|filter|pipe|edge)\.ts$/i;
21
21
 
22
22
  // src/utils.ts
23
23
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
@@ -5,7 +5,8 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkGWLM5DEJjs = require('./chunk-GWLM5DEJ.js');
8
+
9
+ var _chunkT4C6CCWMjs = require('./chunk-T4C6CCWM.js');
9
10
 
10
11
  // src/exception/base.ts
11
12
  var Exception = class extends Error {
@@ -23,11 +24,11 @@ var Exception = class extends Error {
23
24
  message: this.message,
24
25
  description: this.description,
25
26
  status: this.status,
26
- [_chunkGWLM5DEJjs.ERROR_SYMBOL]: true
27
+ [_chunkT4C6CCWMjs.ERROR_SYMBOL]: true
27
28
  };
28
29
  }
29
30
  };
30
- _chunkGWLM5DEJjs.__name.call(void 0, Exception, "Exception");
31
+ _chunkT4C6CCWMjs.__name.call(void 0, Exception, "Exception");
31
32
 
32
33
  // src/exception/validate.ts
33
34
  var ValidateException = class extends Exception {
@@ -35,11 +36,11 @@ var ValidateException = class extends Exception {
35
36
  super(message, 400, "Validate exception");
36
37
  }
37
38
  };
38
- _chunkGWLM5DEJjs.__name.call(void 0, ValidateException, "ValidateException");
39
+ _chunkT4C6CCWMjs.__name.call(void 0, ValidateException, "ValidateException");
39
40
 
40
41
  // src/pipe.ts
41
42
  var _phecdacore = require('phecda-core');
42
- var defaultPipe = /* @__PURE__ */ _chunkGWLM5DEJjs.__name.call(void 0, async ({ arg, reflect, index }) => {
43
+ var defaultPipe = /* @__PURE__ */ _chunkT4C6CCWMjs.__name.call(void 0, async ({ arg, reflect, index }) => {
43
44
  if (_phecdacore.isPhecda.call(void 0, reflect)) {
44
45
  const instance = _phecdacore.plainToClass.call(void 0, reflect, arg);
45
46
  const err = await _phecdacore.transformClass.call(void 0, instance);
@@ -65,7 +66,7 @@ var UndefinedException = class extends Exception {
65
66
  super(message, 500, "Undefined error");
66
67
  }
67
68
  };
68
- _chunkGWLM5DEJjs.__name.call(void 0, UndefinedException, "UndefinedException");
69
+ _chunkT4C6CCWMjs.__name.call(void 0, UndefinedException, "UndefinedException");
69
70
 
70
71
  // src/exception/forbidden.ts
71
72
  var ForbiddenException = class extends Exception {
@@ -73,7 +74,7 @@ var ForbiddenException = class extends Exception {
73
74
  super(message, 403, "Forbidden resource");
74
75
  }
75
76
  };
76
- _chunkGWLM5DEJjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
77
+ _chunkT4C6CCWMjs.__name.call(void 0, ForbiddenException, "ForbiddenException");
77
78
 
78
79
  // src/exception/bad-request.ts
79
80
  var BadRequestException = class extends Exception {
@@ -81,7 +82,7 @@ var BadRequestException = class extends Exception {
81
82
  super(message, 400, "Bad Request");
82
83
  }
83
84
  };
84
- _chunkGWLM5DEJjs.__name.call(void 0, BadRequestException, "BadRequestException");
85
+ _chunkT4C6CCWMjs.__name.call(void 0, BadRequestException, "BadRequestException");
85
86
 
86
87
  // src/exception/not-found.ts
87
88
  var NotFoundException = class extends Exception {
@@ -89,7 +90,7 @@ var NotFoundException = class extends Exception {
89
90
  super(message, 404, "Not Found");
90
91
  }
91
92
  };
92
- _chunkGWLM5DEJjs.__name.call(void 0, NotFoundException, "NotFoundException");
93
+ _chunkT4C6CCWMjs.__name.call(void 0, NotFoundException, "NotFoundException");
93
94
 
94
95
  // src/exception/conflict.ts
95
96
  var ConflictException = class extends Exception {
@@ -97,7 +98,7 @@ var ConflictException = class extends Exception {
97
98
  super(message, 409, "Conflict");
98
99
  }
99
100
  };
100
- _chunkGWLM5DEJjs.__name.call(void 0, ConflictException, "ConflictException");
101
+ _chunkT4C6CCWMjs.__name.call(void 0, ConflictException, "ConflictException");
101
102
 
102
103
  // src/exception/bad-gateway.ts
103
104
  var BadGatewayException = class extends Exception {
@@ -105,7 +106,7 @@ var BadGatewayException = class extends Exception {
105
106
  super(message, 502, "Bad Gatrway");
106
107
  }
107
108
  };
108
- _chunkGWLM5DEJjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
109
+ _chunkT4C6CCWMjs.__name.call(void 0, BadGatewayException, "BadGatewayException");
109
110
 
110
111
  // src/exception/invalid-input.ts
111
112
  var InvalidInputException = class extends Exception {
@@ -113,7 +114,7 @@ var InvalidInputException = class extends Exception {
113
114
  super(message, 502, "Invalid Input");
114
115
  }
115
116
  };
116
- _chunkGWLM5DEJjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
117
+ _chunkT4C6CCWMjs.__name.call(void 0, InvalidInputException, "InvalidInputException");
117
118
 
118
119
  // src/exception/media-type.ts
119
120
  var UnsupportedMediaTypeException = class extends Exception {
@@ -121,7 +122,7 @@ var UnsupportedMediaTypeException = class extends Exception {
121
122
  super(message, 415, "Unsupported Media Type");
122
123
  }
123
124
  };
124
- _chunkGWLM5DEJjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
125
+ _chunkT4C6CCWMjs.__name.call(void 0, UnsupportedMediaTypeException, "UnsupportedMediaTypeException");
125
126
 
126
127
  // src/exception/payload-large.ts
127
128
  var PayloadLargeException = class extends Exception {
@@ -129,7 +130,7 @@ var PayloadLargeException = class extends Exception {
129
130
  super(message, 413, "Payload Too Large");
130
131
  }
131
132
  };
132
- _chunkGWLM5DEJjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
133
+ _chunkT4C6CCWMjs.__name.call(void 0, PayloadLargeException, "PayloadLargeException");
133
134
 
134
135
  // src/exception/timeout.ts
135
136
  var TimeoutException = class extends Exception {
@@ -137,7 +138,7 @@ var TimeoutException = class extends Exception {
137
138
  super(message, 408, "Request Timeout");
138
139
  }
139
140
  };
140
- _chunkGWLM5DEJjs.__name.call(void 0, TimeoutException, "TimeoutException");
141
+ _chunkT4C6CCWMjs.__name.call(void 0, TimeoutException, "TimeoutException");
141
142
 
142
143
  // src/exception/unauthorized.ts
143
144
  var UnauthorizedException = class extends Exception {
@@ -145,7 +146,7 @@ var UnauthorizedException = class extends Exception {
145
146
  super(message, 401, "Unauthorized");
146
147
  }
147
148
  };
148
- _chunkGWLM5DEJjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
149
+ _chunkT4C6CCWMjs.__name.call(void 0, UnauthorizedException, "UnauthorizedException");
149
150
 
150
151
  // src/exception/unavailable-service.ts
151
152
  var ServiceUnavailableException = class extends Exception {
@@ -153,7 +154,7 @@ var ServiceUnavailableException = class extends Exception {
153
154
  super(message, 503, "Service Unavailable");
154
155
  }
155
156
  };
156
- _chunkGWLM5DEJjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
157
+ _chunkT4C6CCWMjs.__name.call(void 0, ServiceUnavailableException, "ServiceUnavailableException");
157
158
 
158
159
  // src/exception/framework.ts
159
160
  var FrameworkException = class extends Exception {
@@ -161,20 +162,22 @@ var FrameworkException = class extends Exception {
161
162
  super(`[phecda-server] ${message}`, 500, "Framework Error");
162
163
  }
163
164
  };
164
- _chunkGWLM5DEJjs.__name.call(void 0, FrameworkException, "FrameworkException");
165
+ _chunkT4C6CCWMjs.__name.call(void 0, FrameworkException, "FrameworkException");
165
166
 
166
167
  // src/context.ts
167
168
  var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefault(_picocolors);
168
169
 
169
170
  // src/filter.ts
170
- var defaultFilter = /* @__PURE__ */ _chunkGWLM5DEJjs.__name.call(void 0, (e) => {
171
+ var defaultFilter = /* @__PURE__ */ _chunkT4C6CCWMjs.__name.call(void 0, (e) => {
171
172
  if (!(e instanceof Exception)) {
172
- _chunkGWLM5DEJjs.log.call(void 0, e.message, "error");
173
- console.error(e.stack);
173
+ _chunkT4C6CCWMjs.log.call(void 0, e.message, "error");
174
+ if (!_chunkT4C6CCWMjs.IS_LOG_BAN)
175
+ console.error(e.stack);
174
176
  e = new UndefinedException(e.message || e);
175
177
  } else {
176
- _chunkGWLM5DEJjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
177
- console.error(e.stack);
178
+ _chunkT4C6CCWMjs.log.call(void 0, `[${e.constructor.name}] ${e.message}`, "error");
179
+ if (!_chunkT4C6CCWMjs.IS_LOG_BAN)
180
+ console.error(e.stack);
178
181
  }
179
182
  return e.data;
180
183
  }, "defaultFilter");
@@ -191,7 +194,7 @@ var Histroy = (_class = class {constructor() { _class.prototype.__init.call(this
191
194
  return false;
192
195
  }
193
196
  }, _class);
194
- _chunkGWLM5DEJjs.__name.call(void 0, Histroy, "Histroy");
197
+ _chunkT4C6CCWMjs.__name.call(void 0, Histroy, "Histroy");
195
198
 
196
199
  // src/context.ts
197
200
  var guardRecord = {};
@@ -204,13 +207,13 @@ var _Context = class {
204
207
  constructor(data) {
205
208
  this.data = data;
206
209
  this.history = new Histroy();
207
- if (_chunkGWLM5DEJjs.IS_DEV)
210
+ if (_chunkT4C6CCWMjs.IS_DEV)
208
211
  data._context = this;
209
212
  }
210
213
  usePipe(args) {
211
214
  return Promise.all(args.map((item) => {
212
215
  if (item.pipe && !_Context.pipeRecord[item.pipe]) {
213
- if (_chunkGWLM5DEJjs.IS_STRICT)
216
+ if (_chunkT4C6CCWMjs.IS_STRICT)
214
217
  throw new FrameworkException(`can't find pipe named '${item.pipe}'`);
215
218
  else
216
219
  return _Context.pipeRecord.default(item, this.data);
@@ -220,7 +223,7 @@ var _Context = class {
220
223
  }
221
224
  useFilter(arg, filter = "default") {
222
225
  if (!_Context.filterRecord[filter]) {
223
- if (_chunkGWLM5DEJjs.IS_STRICT)
226
+ if (_chunkT4C6CCWMjs.IS_STRICT)
224
227
  throw new FrameworkException(`can't find filter named '${filter}'`);
225
228
  else
226
229
  return _Context.filterRecord.default(arg, this.data);
@@ -231,7 +234,7 @@ var _Context = class {
231
234
  for (const guard of guards) {
232
235
  if (this.history.record(guard, "guard")) {
233
236
  if (!(guard in _Context.guardRecord)) {
234
- if (_chunkGWLM5DEJjs.IS_STRICT)
237
+ if (_chunkT4C6CCWMjs.IS_STRICT)
235
238
  throw new FrameworkException(`can't find guard named '${guard}'`);
236
239
  continue;
237
240
  }
@@ -250,7 +253,7 @@ var _Context = class {
250
253
  for (const interceptor of interceptors) {
251
254
  if (this.history.record(interceptor, "interceptor")) {
252
255
  if (!(interceptor in _Context.interceptorRecord)) {
253
- if (_chunkGWLM5DEJjs.IS_STRICT)
256
+ if (_chunkT4C6CCWMjs.IS_STRICT)
254
257
  throw new FrameworkException(`can't find interceptor named '${interceptor}'`);
255
258
  continue;
256
259
  }
@@ -268,57 +271,57 @@ var _Context = class {
268
271
  static usePlugin(plugins) {
269
272
  const ret = [];
270
273
  for (const m of plugins) {
271
- if (!(m in _Context.addonRecord)) {
272
- if (_chunkGWLM5DEJjs.IS_STRICT)
274
+ if (!(m in _Context.pluginRecord)) {
275
+ if (_chunkT4C6CCWMjs.IS_STRICT)
273
276
  throw new FrameworkException(`can't find middleware named '${m}'`);
274
277
  continue;
275
278
  }
276
- ret.push(_Context.addonRecord[m]);
279
+ ret.push(_Context.pluginRecord[m]);
277
280
  }
278
281
  return ret;
279
282
  }
280
283
  };
281
284
  var Context = _Context;
282
- _chunkGWLM5DEJjs.__name.call(void 0, Context, "Context");
283
- _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "filterRecord", {
285
+ _chunkT4C6CCWMjs.__name.call(void 0, Context, "Context");
286
+ _chunkT4C6CCWMjs.__publicField.call(void 0, Context, "filterRecord", {
284
287
  default: defaultFilter
285
288
  });
286
- _chunkGWLM5DEJjs.__publicField.call(void 0, Context, "pipeRecord", {
289
+ _chunkT4C6CCWMjs.__publicField.call(void 0, Context, "pipeRecord", {
287
290
  default: defaultPipe
288
291
  });
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 "${key}"`, "warn");
295
- Context.addonRecord[key] = handler;
292
+ _chunkT4C6CCWMjs.__publicField.call(void 0, Context, "guardRecord", {});
293
+ _chunkT4C6CCWMjs.__publicField.call(void 0, Context, "interceptorRecord", {});
294
+ _chunkT4C6CCWMjs.__publicField.call(void 0, Context, "pluginRecord", {});
295
+ function addPlugin(key, handler) {
296
+ if (Context.pluginRecord[key] && Context.pluginRecord[key] !== handler)
297
+ _chunkT4C6CCWMjs.log.call(void 0, `overwrite Plugin "${String(key)}"`, "warn");
298
+ Context.pluginRecord[key] = handler;
296
299
  }
297
- _chunkGWLM5DEJjs.__name.call(void 0, addAddon, "addAddon");
300
+ _chunkT4C6CCWMjs.__name.call(void 0, addPlugin, "addPlugin");
298
301
  function addPipe(key, handler) {
299
302
  if (Context.pipeRecord[key] && Context.pipeRecord[key] !== handler)
300
- _chunkGWLM5DEJjs.log.call(void 0, `overwrite Pipe "${key}"`, "warn");
303
+ _chunkT4C6CCWMjs.log.call(void 0, `overwrite Pipe "${String(key)}"`, "warn");
301
304
  Context.pipeRecord[key] = handler;
302
305
  }
303
- _chunkGWLM5DEJjs.__name.call(void 0, addPipe, "addPipe");
306
+ _chunkT4C6CCWMjs.__name.call(void 0, addPipe, "addPipe");
304
307
  function addFilter(key, handler) {
305
308
  if (Context.filterRecord[key] && Context.filterRecord[key] !== handler)
306
- _chunkGWLM5DEJjs.log.call(void 0, `overwrite Filter "${key}"`, "warn");
309
+ _chunkT4C6CCWMjs.log.call(void 0, `overwrite Filter "${String(key)}"`, "warn");
307
310
  Context.filterRecord[key] = handler;
308
311
  }
309
- _chunkGWLM5DEJjs.__name.call(void 0, addFilter, "addFilter");
312
+ _chunkT4C6CCWMjs.__name.call(void 0, addFilter, "addFilter");
310
313
  function addGuard(key, handler) {
311
314
  if (Context.guardRecord[key] && Context.guardRecord[key] !== handler)
312
- _chunkGWLM5DEJjs.log.call(void 0, `overwrite Guard "${key}"`, "warn");
315
+ _chunkT4C6CCWMjs.log.call(void 0, `overwrite Guard "${String(key)}"`, "warn");
313
316
  Context.guardRecord[key] = handler;
314
317
  }
315
- _chunkGWLM5DEJjs.__name.call(void 0, addGuard, "addGuard");
318
+ _chunkT4C6CCWMjs.__name.call(void 0, addGuard, "addGuard");
316
319
  function addInterceptor(key, handler) {
317
320
  if (Context.interceptorRecord[key] && Context.interceptorRecord[key] !== handler)
318
- _chunkGWLM5DEJjs.log.call(void 0, `overwrite Interceptor "${key}"`, "warn");
321
+ _chunkT4C6CCWMjs.log.call(void 0, `overwrite Interceptor "${String(key)}"`, "warn");
319
322
  Context.interceptorRecord[key] = handler;
320
323
  }
321
- _chunkGWLM5DEJjs.__name.call(void 0, addInterceptor, "addInterceptor");
324
+ _chunkT4C6CCWMjs.__name.call(void 0, addInterceptor, "addInterceptor");
322
325
  function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
323
326
  const pluginSet = new Set(plugins);
324
327
  const guardSet = new Set(guards);
@@ -338,7 +341,7 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
338
341
  });
339
342
  const missPlugins = [
340
343
  ...pluginSet
341
- ].filter((i) => !Context.addonRecord[i]);
344
+ ].filter((i) => !Context.pluginRecord[i]);
342
345
  const missGuards = [
343
346
  ...guardSet
344
347
  ].filter((i) => !Context.guardRecord[i]);
@@ -352,17 +355,17 @@ function isAopDepInject(meta, { guards, interceptors, plugins } = {}) {
352
355
  ...filterSet
353
356
  ].filter((i) => !Context.filterRecord[i]);
354
357
  if (missPlugins.length)
355
- _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
358
+ _chunkT4C6CCWMjs.log.call(void 0, `${_picocolors2.default.white(`Plugin [${missPlugins.join(",")}]`)} doesn't exist`, "warn");
356
359
  if (missGuards.length)
357
- _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
360
+ _chunkT4C6CCWMjs.log.call(void 0, `${_picocolors2.default.magenta(`Guard [${missGuards.join(",")}]`)} doesn't exist`, "warn");
358
361
  if (missInterceptors.length)
359
- _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
362
+ _chunkT4C6CCWMjs.log.call(void 0, `${_picocolors2.default.cyan(`Interceptor [${missInterceptors.join(",")}]`)} doesn't exist`, "warn");
360
363
  if (missPipes.length)
361
- _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
364
+ _chunkT4C6CCWMjs.log.call(void 0, `${_picocolors2.default.blue(`Pipe [${missPipes.join(",")}]`)} doesn't exist`, "warn");
362
365
  if (missFilters.length)
363
- _chunkGWLM5DEJjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
366
+ _chunkT4C6CCWMjs.log.call(void 0, `${_picocolors2.default.red(`Filter [${missFilters.join(",")}]`)} doesn't exist`, "warn");
364
367
  }
365
- _chunkGWLM5DEJjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
368
+ _chunkT4C6CCWMjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
366
369
 
367
370
 
368
371
 
@@ -389,4 +392,4 @@ _chunkGWLM5DEJjs.__name.call(void 0, isAopDepInject, "isAopDepInject");
389
392
 
390
393
 
391
394
 
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;
395
+ 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;