phecda-server 8.5.4 → 8.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/{chunk-WST6E6MQ.mjs → chunk-LQFHZGVJ.mjs} +72 -22
  2. package/dist/{chunk-76UDKZOJ.js → chunk-XOWAQGBO.js} +71 -21
  3. package/dist/helper.js +2 -2
  4. package/dist/helper.mjs +1 -1
  5. package/dist/http/elysia/index.js +17 -17
  6. package/dist/http/elysia/index.mjs +1 -1
  7. package/dist/http/express/index.js +16 -16
  8. package/dist/http/express/index.mjs +1 -1
  9. package/dist/http/fastify/index.js +16 -16
  10. package/dist/http/fastify/index.mjs +1 -1
  11. package/dist/http/h3/index.js +17 -17
  12. package/dist/http/h3/index.mjs +1 -1
  13. package/dist/http/hono/index.js +14 -14
  14. package/dist/http/hono/index.mjs +1 -1
  15. package/dist/http/hyper-express/index.js +15 -15
  16. package/dist/http/hyper-express/index.mjs +1 -1
  17. package/dist/http/koa/index.js +16 -16
  18. package/dist/http/koa/index.mjs +1 -1
  19. package/dist/index.js +20 -20
  20. package/dist/index.mjs +6 -6
  21. package/dist/rpc/bullmq/index.js +6 -6
  22. package/dist/rpc/bullmq/index.mjs +1 -1
  23. package/dist/rpc/electron/index.js +5 -5
  24. package/dist/rpc/electron/index.mjs +1 -1
  25. package/dist/rpc/kafka/index.js +6 -6
  26. package/dist/rpc/kafka/index.mjs +1 -1
  27. package/dist/rpc/nats/index.js +6 -6
  28. package/dist/rpc/nats/index.mjs +1 -1
  29. package/dist/rpc/rabbitmq/index.js +6 -6
  30. package/dist/rpc/rabbitmq/index.mjs +1 -1
  31. package/dist/rpc/redis/index.js +6 -6
  32. package/dist/rpc/redis/index.mjs +1 -1
  33. package/dist/rpc/web-ext/index.js +5 -5
  34. package/dist/rpc/web-ext/index.mjs +1 -1
  35. package/dist/rpc/ws/index.js +5 -5
  36. package/dist/rpc/ws/index.mjs +1 -1
  37. package/package.json +2 -2
@@ -17,7 +17,7 @@ import Debug from "debug";
17
17
  import pc from "picocolors";
18
18
 
19
19
  // src/pipe.ts
20
- import { isPhecda, validate } from "phecda-core";
20
+ import { extractDataByRules, extractRules, isPhecda, validateWithRules } from "phecda-core";
21
21
 
22
22
  // src/exception/base.ts
23
23
  var Exception = class extends Error {
@@ -202,7 +202,63 @@ var WorkerException = class extends Exception {
202
202
  };
203
203
 
204
204
  // src/pipe.ts
205
- var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, type }, { method }) => {
205
+ var modelRulesCache = /* @__PURE__ */ new WeakMap();
206
+ function isPlainObject(value) {
207
+ return Object.prototype.toString.call(value) === "[object Object]";
208
+ }
209
+ __name(isPlainObject, "isPlainObject");
210
+ function convertForRequestInput(value, type, index) {
211
+ if (value === void 0) return value;
212
+ if (type === Number && typeof value === "string") {
213
+ const num = Number(value);
214
+ if (Number.isNaN(num)) throw new ValidateException(`param ${index + 1} is not a number`);
215
+ return num;
216
+ }
217
+ if (type === Boolean && typeof value === "string") {
218
+ if (value === "true") return true;
219
+ if (value === "false") return false;
220
+ throw new ValidateException(`param ${index + 1} is not a boolean`);
221
+ }
222
+ return value;
223
+ }
224
+ __name(convertForRequestInput, "convertForRequestInput");
225
+ function isStrTypeParam(type) {
226
+ return [
227
+ "params",
228
+ "query",
229
+ "headers"
230
+ ].includes(type);
231
+ }
232
+ __name(isStrTypeParam, "isStrTypeParam");
233
+ function convertExtractedDataByRules(data, rules, index) {
234
+ if (!data || typeof data !== "object") return data;
235
+ for (const rule of rules) {
236
+ if (!rule.property) continue;
237
+ if (rule.property.includes(".") || rule.property.includes("[]")) throw new ValidateException("default pipe only supports simple shallow phecda class for query/params/headers; please use custom pipe for nested data");
238
+ data[rule.property] = convertForRequestInput(data[rule.property], rule.designType, index);
239
+ }
240
+ return data;
241
+ }
242
+ __name(convertExtractedDataByRules, "convertExtractedDataByRules");
243
+ function getModelRules(model) {
244
+ const cached = modelRulesCache.get(model);
245
+ if (cached) return cached;
246
+ const rules = extractRules(model);
247
+ modelRulesCache.set(model, rules);
248
+ return rules;
249
+ }
250
+ __name(getModelRules, "getModelRules");
251
+ async function validatePhecdaByRules(model, input, shouldConvert, index) {
252
+ if (!isPlainObject(input)) throw new ValidateException("data must be an object");
253
+ const rules = getModelRules(model);
254
+ let data = extractDataByRules(input, rules);
255
+ if (shouldConvert) data = convertExtractedDataByRules(data, rules, index);
256
+ const errs = await validateWithRules(data, rules);
257
+ if (errs.length) throw new ValidateException(errs[0]);
258
+ return data;
259
+ }
260
+ __name(validatePhecdaByRules, "validatePhecdaByRules");
261
+ var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, type, key }, { method }) => {
206
262
  if (meta.const) {
207
263
  if (arg !== meta.const) throw new ValidateException(`param ${index + 1} must be ${meta.const}`);
208
264
  }
@@ -210,19 +266,15 @@ var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, typ
210
266
  if (meta.required === false) return arg;
211
267
  else throw new ValidateException(`param ${index + 1} is required`);
212
268
  }
213
- if ([
214
- "params",
215
- "query"
216
- ].includes(type)) {
217
- if (reflect === Number) {
218
- arg = reflect(arg);
219
- if (isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
220
- } else if (reflect === Boolean) {
221
- if (arg === "false") arg = false;
222
- else if (arg === "true") arg = true;
223
- else throw new ValidateException(`param ${index + 1} is not a boolean`);
224
- }
225
- } else {
269
+ const isModel = isPhecda(reflect);
270
+ const isStrType = isStrTypeParam(type);
271
+ const canUseShallowModelConvert = isStrType && !key;
272
+ if (isModel && isStrType && key) {
273
+ throw new ValidateException("phecda class cannot be used with specified field in query/params/headers in default pipe");
274
+ }
275
+ if (!isModel && isStrType) {
276
+ arg = convertForRequestInput(arg, reflect, index);
277
+ } else if (!isModel) {
226
278
  if (reflect === Number && typeof arg !== "number") throw new ValidateException(`param ${index + 1} is not a number`);
227
279
  if (reflect === Boolean && typeof arg !== "boolean") throw new ValidateException(`param ${index + 1} is not a boolean`);
228
280
  if (reflect === String && typeof arg !== "string") throw new ValidateException(`param ${index + 1} is not a string`);
@@ -245,11 +297,12 @@ var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, typ
245
297
  break;
246
298
  default:
247
299
  if (isPhecda(item)) {
248
- const errs = await validate(item, arg);
249
- if (!errs.length) {
300
+ try {
301
+ await validatePhecdaByRules(item, arg, canUseShallowModelConvert, index);
250
302
  isCorrect = true;
251
- break;
303
+ } catch {
252
304
  }
305
+ if (isCorrect) break;
253
306
  } else if (typeof item === "function") {
254
307
  const ret = await item(arg);
255
308
  if (ret) {
@@ -278,10 +331,7 @@ var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, typ
278
331
  if (err.length > 0) throw new ValidateException(err[0]);
279
332
  }
280
333
  }
281
- if (isPhecda(reflect)) {
282
- const errs = await validate(reflect, arg);
283
- if (errs.length) throw new ValidateException(errs[0]);
284
- }
334
+ if (isModel) arg = await validatePhecdaByRules(reflect, arg, canUseShallowModelConvert, index);
285
335
  return arg;
286
336
  }, "defaultPipe");
287
337
 
@@ -202,7 +202,63 @@ var WorkerException = class extends Exception {
202
202
  };
203
203
 
204
204
  // src/pipe.ts
205
- var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({ arg, reflect, meta, index, type }, { method }) => {
205
+ var modelRulesCache = /* @__PURE__ */ new WeakMap();
206
+ function isPlainObject(value) {
207
+ return Object.prototype.toString.call(value) === "[object Object]";
208
+ }
209
+ _chunkLLF55NZPjs.__name.call(void 0, isPlainObject, "isPlainObject");
210
+ function convertForRequestInput(value, type, index) {
211
+ if (value === void 0) return value;
212
+ if (type === Number && typeof value === "string") {
213
+ const num = Number(value);
214
+ if (Number.isNaN(num)) throw new ValidateException(`param ${index + 1} is not a number`);
215
+ return num;
216
+ }
217
+ if (type === Boolean && typeof value === "string") {
218
+ if (value === "true") return true;
219
+ if (value === "false") return false;
220
+ throw new ValidateException(`param ${index + 1} is not a boolean`);
221
+ }
222
+ return value;
223
+ }
224
+ _chunkLLF55NZPjs.__name.call(void 0, convertForRequestInput, "convertForRequestInput");
225
+ function isStrTypeParam(type) {
226
+ return [
227
+ "params",
228
+ "query",
229
+ "headers"
230
+ ].includes(type);
231
+ }
232
+ _chunkLLF55NZPjs.__name.call(void 0, isStrTypeParam, "isStrTypeParam");
233
+ function convertExtractedDataByRules(data, rules, index) {
234
+ if (!data || typeof data !== "object") return data;
235
+ for (const rule of rules) {
236
+ if (!rule.property) continue;
237
+ if (rule.property.includes(".") || rule.property.includes("[]")) throw new ValidateException("default pipe only supports simple shallow phecda class for query/params/headers; please use custom pipe for nested data");
238
+ data[rule.property] = convertForRequestInput(data[rule.property], rule.designType, index);
239
+ }
240
+ return data;
241
+ }
242
+ _chunkLLF55NZPjs.__name.call(void 0, convertExtractedDataByRules, "convertExtractedDataByRules");
243
+ function getModelRules(model) {
244
+ const cached = modelRulesCache.get(model);
245
+ if (cached) return cached;
246
+ const rules = _phecdacore.extractRules.call(void 0, model);
247
+ modelRulesCache.set(model, rules);
248
+ return rules;
249
+ }
250
+ _chunkLLF55NZPjs.__name.call(void 0, getModelRules, "getModelRules");
251
+ async function validatePhecdaByRules(model, input, shouldConvert, index) {
252
+ if (!isPlainObject(input)) throw new ValidateException("data must be an object");
253
+ const rules = getModelRules(model);
254
+ let data = _phecdacore.extractDataByRules.call(void 0, input, rules);
255
+ if (shouldConvert) data = convertExtractedDataByRules(data, rules, index);
256
+ const errs = await _phecdacore.validateWithRules.call(void 0, data, rules);
257
+ if (errs.length) throw new ValidateException(errs[0]);
258
+ return data;
259
+ }
260
+ _chunkLLF55NZPjs.__name.call(void 0, validatePhecdaByRules, "validatePhecdaByRules");
261
+ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({ arg, reflect, meta, index, type, key }, { method }) => {
206
262
  if (meta.const) {
207
263
  if (arg !== meta.const) throw new ValidateException(`param ${index + 1} must be ${meta.const}`);
208
264
  }
@@ -210,19 +266,15 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
210
266
  if (meta.required === false) return arg;
211
267
  else throw new ValidateException(`param ${index + 1} is required`);
212
268
  }
213
- if ([
214
- "params",
215
- "query"
216
- ].includes(type)) {
217
- if (reflect === Number) {
218
- arg = reflect(arg);
219
- if (isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
220
- } else if (reflect === Boolean) {
221
- if (arg === "false") arg = false;
222
- else if (arg === "true") arg = true;
223
- else throw new ValidateException(`param ${index + 1} is not a boolean`);
224
- }
225
- } else {
269
+ const isModel = _phecdacore.isPhecda.call(void 0, reflect);
270
+ const isStrType = isStrTypeParam(type);
271
+ const canUseShallowModelConvert = isStrType && !key;
272
+ if (isModel && isStrType && key) {
273
+ throw new ValidateException("phecda class cannot be used with specified field in query/params/headers in default pipe");
274
+ }
275
+ if (!isModel && isStrType) {
276
+ arg = convertForRequestInput(arg, reflect, index);
277
+ } else if (!isModel) {
226
278
  if (reflect === Number && typeof arg !== "number") throw new ValidateException(`param ${index + 1} is not a number`);
227
279
  if (reflect === Boolean && typeof arg !== "boolean") throw new ValidateException(`param ${index + 1} is not a boolean`);
228
280
  if (reflect === String && typeof arg !== "string") throw new ValidateException(`param ${index + 1} is not a string`);
@@ -245,11 +297,12 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
245
297
  break;
246
298
  default:
247
299
  if (_phecdacore.isPhecda.call(void 0, item)) {
248
- const errs = await _phecdacore.validate.call(void 0, item, arg);
249
- if (!errs.length) {
300
+ try {
301
+ await validatePhecdaByRules(item, arg, canUseShallowModelConvert, index);
250
302
  isCorrect = true;
251
- break;
303
+ } catch (e2) {
252
304
  }
305
+ if (isCorrect) break;
253
306
  } else if (typeof item === "function") {
254
307
  const ret = await item(arg);
255
308
  if (ret) {
@@ -278,10 +331,7 @@ var defaultPipe = /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, async ({
278
331
  if (err.length > 0) throw new ValidateException(err[0]);
279
332
  }
280
333
  }
281
- if (_phecdacore.isPhecda.call(void 0, reflect)) {
282
- const errs = await _phecdacore.validate.call(void 0, reflect, arg);
283
- if (errs.length) throw new ValidateException(errs[0]);
284
- }
334
+ if (isModel) arg = await validatePhecdaByRules(reflect, arg, canUseShallowModelConvert, index);
285
335
  return arg;
286
336
  }, "defaultPipe");
287
337
 
package/dist/helper.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunk76UDKZOJjs = require('./chunk-76UDKZOJ.js');
8
+ var _chunkXOWAQGBOjs = require('./chunk-XOWAQGBO.js');
9
9
 
10
10
 
11
11
 
@@ -23,4 +23,4 @@ var _chunkLLF55NZPjs = require('./chunk-LLF55NZP.js');
23
23
 
24
24
 
25
25
 
26
- exports.EXIT = _chunkLLF55NZPjs.EXIT; exports.HMR = _chunkLLF55NZPjs.HMR; exports.RELAUNCH = _chunkLLF55NZPjs.RELAUNCH; exports.RELOAD = _chunkLLF55NZPjs.RELOAD; exports.createControllerMetaMap = _chunk76UDKZOJjs.createControllerMetaMap; exports.detectAopDep = _chunk76UDKZOJjs.detectAopDep; exports.joinUrl = _chunk76UDKZOJjs.joinUrl; exports.mergeObject = _chunk76UDKZOJjs.mergeObject; exports.resolveDep = _chunk76UDKZOJjs.resolveDep; exports.shallowClone = _chunk76UDKZOJjs.shallowClone;
26
+ exports.EXIT = _chunkLLF55NZPjs.EXIT; exports.HMR = _chunkLLF55NZPjs.HMR; exports.RELAUNCH = _chunkLLF55NZPjs.RELAUNCH; exports.RELOAD = _chunkLLF55NZPjs.RELOAD; exports.createControllerMetaMap = _chunkXOWAQGBOjs.createControllerMetaMap; exports.detectAopDep = _chunkXOWAQGBOjs.detectAopDep; exports.joinUrl = _chunkXOWAQGBOjs.joinUrl; exports.mergeObject = _chunkXOWAQGBOjs.mergeObject; exports.resolveDep = _chunkXOWAQGBOjs.resolveDep; exports.shallowClone = _chunkXOWAQGBOjs.shallowClone;
package/dist/helper.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  mergeObject,
6
6
  resolveDep,
7
7
  shallowClone
8
- } from "./chunk-WST6E6MQ.mjs";
8
+ } from "./chunk-LQFHZGVJ.mjs";
9
9
  import {
10
10
  EXIT,
11
11
  HMR,
@@ -7,7 +7,7 @@ var _chunk5ZZAOOKEjs = require('../../chunk-5ZZAOOKE.js');
7
7
 
8
8
 
9
9
 
10
- var _chunk76UDKZOJjs = require('../../chunk-76UDKZOJ.js');
10
+ var _chunkXOWAQGBOjs = require('../../chunk-XOWAQGBO.js');
11
11
 
12
12
 
13
13
  var _chunkLLF55NZPjs = require('../../chunk-LLF55NZP.js');
@@ -19,14 +19,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/elysia");
19
19
  function bind(app, data, opts = {}) {
20
20
  const { globalGuards, parallelRoute, globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
21
21
  const { moduleMap, meta } = data;
22
- const metaMap = _chunk76UDKZOJjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
+ const metaMap = _chunkXOWAQGBOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
23
23
  const { controller, http, method, tag } = meta2.data;
24
24
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.method])) {
25
25
  debug(`register method "${method}" in module "${tag}"`);
26
26
  return true;
27
27
  }
28
28
  });
29
- _chunk76UDKZOJjs.detectAopDep.call(void 0, meta, {
29
+ _chunkXOWAQGBOjs.detectAopDep.call(void 0, meta, {
30
30
  addons: [
31
31
  ...globalAddons,
32
32
  ...parallelAddons
@@ -35,19 +35,19 @@ function bind(app, data, opts = {}) {
35
35
  });
36
36
  registerRoute();
37
37
  function registerRoute() {
38
- _chunk76UDKZOJjs.Context.applyAddons(globalAddons, app, "elysia");
38
+ _chunkXOWAQGBOjs.Context.applyAddons(globalAddons, app, "elysia");
39
39
  if (parallelRoute) {
40
40
  const parallelRouter = new (0, _elysia.Elysia)();
41
- _chunk76UDKZOJjs.Context.applyAddons(parallelAddons, app, "elysia");
41
+ _chunkXOWAQGBOjs.Context.applyAddons(parallelAddons, app, "elysia");
42
42
  parallelRouter.post(parallelRoute, async (c) => {
43
43
  const { body } = c;
44
44
  async function errorHandler(e) {
45
- const error = await _chunk76UDKZOJjs.Context.filterRecord.default(e);
45
+ const error = await _chunkXOWAQGBOjs.Context.filterRecord.default(e);
46
46
  c.set.status = error.status;
47
47
  return error;
48
48
  }
49
49
  _chunkLLF55NZPjs.__name.call(void 0, errorHandler, "errorHandler");
50
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk76UDKZOJjs.BadRequestException)("data format should be an array"));
50
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkXOWAQGBOjs.BadRequestException)("data format should be an array"));
51
51
  try {
52
52
  return Promise.all(body.map((item, i) => {
53
53
  return new Promise(async (resolve) => {
@@ -55,13 +55,13 @@ function bind(app, data, opts = {}) {
55
55
  const { tag, method } = item;
56
56
  debug(`(parallel)invoke method "${method}" in module "${tag}"`);
57
57
  if (!metaMap.has(tag)) {
58
- return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
+ return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`module "${tag}" doesn't exist`)));
59
59
  }
60
60
  const meta2 = metaMap.get(tag)[method];
61
61
  if (!meta2) {
62
- return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
62
+ return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
63
63
  }
64
- const aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
64
+ const aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
65
65
  globalGuards,
66
66
  globalFilter,
67
67
  globalPipe
@@ -92,7 +92,7 @@ function bind(app, data, opts = {}) {
92
92
  throw new Error("elysia can't support getResponse");
93
93
  }, "getResponse")
94
94
  };
95
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
95
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
96
96
  context.run(aop, resolve, resolve);
97
97
  });
98
98
  })).then((ret) => {
@@ -114,14 +114,14 @@ function bind(app, data, opts = {}) {
114
114
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.method])) continue;
115
115
  let aop;
116
116
  if (!dynamic) {
117
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
117
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
118
118
  globalFilter,
119
119
  globalGuards,
120
120
  globalPipe
121
121
  });
122
122
  }
123
- _chunk76UDKZOJjs.Context.applyAddons(addons, subApp, "elysia");
124
- subApp[http.method](_chunk76UDKZOJjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
123
+ _chunkXOWAQGBOjs.Context.applyAddons(addons, subApp, "elysia");
124
+ subApp[http.method](_chunkXOWAQGBOjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
125
125
  debug(`invoke method "${method}" in module "${tag}"`);
126
126
  const contextData = {
127
127
  type: "elysia",
@@ -153,16 +153,16 @@ function bind(app, data, opts = {}) {
153
153
  }, "getResponse")
154
154
  };
155
155
  if (dynamic) {
156
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
156
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
157
157
  globalFilter,
158
158
  globalGuards,
159
159
  globalPipe
160
160
  });
161
161
  }
162
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
162
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
163
163
  if (http.headers) c.set.headers = http.headers;
164
164
  if (dynamic) {
165
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
165
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
166
166
  globalFilter,
167
167
  globalGuards,
168
168
  globalPipe
@@ -7,7 +7,7 @@ import {
7
7
  createControllerMetaMap,
8
8
  detectAopDep,
9
9
  joinUrl
10
- } from "../../chunk-WST6E6MQ.mjs";
10
+ } from "../../chunk-LQFHZGVJ.mjs";
11
11
  import {
12
12
  __name
13
13
  } from "../../chunk-URKOYTBU.mjs";
@@ -4,7 +4,7 @@
4
4
 
5
5
 
6
6
 
7
- var _chunk76UDKZOJjs = require('../../chunk-76UDKZOJ.js');
7
+ var _chunkXOWAQGBOjs = require('../../chunk-XOWAQGBO.js');
8
8
 
9
9
 
10
10
 
@@ -18,14 +18,14 @@ function bind(router, data, opts = {}) {
18
18
  const { globalGuards, parallelRoute, globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
19
19
  const { moduleMap, meta } = data;
20
20
  const originStack = router.stack.slice(0, router.stack.length);
21
- const metaMap = _chunk76UDKZOJjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkXOWAQGBOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
22
  const { controller, http, method, tag } = meta2.data;
23
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.method])) {
24
24
  debug(`register method "${method}" in module "${tag}"`);
25
25
  return true;
26
26
  }
27
27
  });
28
- _chunk76UDKZOJjs.detectAopDep.call(void 0, meta, {
28
+ _chunkXOWAQGBOjs.detectAopDep.call(void 0, meta, {
29
29
  addons: [
30
30
  ...globalAddons,
31
31
  ...parallelAddons
@@ -38,28 +38,28 @@ function bind(router, data, opts = {}) {
38
38
  registerRoute();
39
39
  });
40
40
  function registerRoute() {
41
- _chunk76UDKZOJjs.Context.applyAddons(globalAddons, router, "express");
41
+ _chunkXOWAQGBOjs.Context.applyAddons(globalAddons, router, "express");
42
42
  if (parallelRoute) {
43
43
  const subRouter = _express.Router.call(void 0, );
44
- _chunk76UDKZOJjs.Context.applyAddons(parallelAddons, subRouter, "express");
44
+ _chunkXOWAQGBOjs.Context.applyAddons(parallelAddons, subRouter, "express");
45
45
  subRouter.use(async (req, res, next) => {
46
46
  const { body } = req;
47
47
  async function errorHandler(e) {
48
- const error = await _chunk76UDKZOJjs.Context.filterRecord.default(e);
48
+ const error = await _chunkXOWAQGBOjs.Context.filterRecord.default(e);
49
49
  return res.status(error.status).json(error);
50
50
  }
51
51
  _chunkLLF55NZPjs.__name.call(void 0, errorHandler, "errorHandler");
52
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk76UDKZOJjs.BadRequestException)("data format should be an array"));
52
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkXOWAQGBOjs.BadRequestException)("data format should be an array"));
53
53
  try {
54
54
  return Promise.all(body.map((item, i) => {
55
55
  return new Promise(async (resolve) => {
56
56
  if (!item) return resolve(null);
57
57
  const { tag, method } = item;
58
58
  debug(`(parallel)invoke method "${method}" in module "${tag}"`);
59
- if (!metaMap.has(tag)) return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`module "${tag}" doesn't exist`)));
59
+ if (!metaMap.has(tag)) return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`module "${tag}" doesn't exist`)));
60
60
  const meta2 = metaMap.get(tag)[method];
61
- if (!meta2) return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
62
- const aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
61
+ if (!meta2) return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
62
+ const aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
63
63
  globalFilter,
64
64
  globalGuards,
65
65
  globalPipe
@@ -87,7 +87,7 @@ function bind(router, data, opts = {}) {
87
87
  getRequest: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => req, "getRequest"),
88
88
  getResponse: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => res, "getResponse")
89
89
  };
90
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
90
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
91
91
  context.run(aop, resolve, resolve);
92
92
  });
93
93
  })).then((ret) => {
@@ -106,15 +106,15 @@ function bind(router, data, opts = {}) {
106
106
  if (!_optionalChain([http, 'optionalAccess', _2 => _2.method])) continue;
107
107
  let aop;
108
108
  if (!dynamic) {
109
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
109
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
110
110
  globalFilter,
111
111
  globalGuards,
112
112
  globalPipe
113
113
  });
114
114
  }
115
115
  const subRouter = _express.Router.call(void 0, );
116
- _chunk76UDKZOJjs.Context.applyAddons(addons, subRouter, "express");
117
- subRouter[http.method](_chunk76UDKZOJjs.joinUrl.call(void 0, http.prefix, http.route), async (req, res, next) => {
116
+ _chunkXOWAQGBOjs.Context.applyAddons(addons, subRouter, "express");
117
+ subRouter[http.method](_chunkXOWAQGBOjs.joinUrl.call(void 0, http.prefix, http.route), async (req, res, next) => {
118
118
  debug(`invoke method "${method}" in module "${tag}"`);
119
119
  const contextData = {
120
120
  type: "express",
@@ -142,10 +142,10 @@ function bind(router, data, opts = {}) {
142
142
  getRequest: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => req, "getRequest"),
143
143
  getResponse: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => res, "getResponse")
144
144
  };
145
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
145
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
146
146
  if (http.headers) res.set(http.headers);
147
147
  if (dynamic) {
148
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
148
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
149
149
  globalFilter,
150
150
  globalGuards,
151
151
  globalPipe
@@ -4,7 +4,7 @@ import {
4
4
  createControllerMetaMap,
5
5
  detectAopDep,
6
6
  joinUrl
7
- } from "../../chunk-WST6E6MQ.mjs";
7
+ } from "../../chunk-LQFHZGVJ.mjs";
8
8
  import {
9
9
  HMR,
10
10
  __name
@@ -7,7 +7,7 @@ var _chunk5ZZAOOKEjs = require('../../chunk-5ZZAOOKE.js');
7
7
 
8
8
 
9
9
 
10
- var _chunk76UDKZOJjs = require('../../chunk-76UDKZOJ.js');
10
+ var _chunkXOWAQGBOjs = require('../../chunk-XOWAQGBO.js');
11
11
 
12
12
 
13
13
  var _chunkLLF55NZPjs = require('../../chunk-LLF55NZP.js');
@@ -18,14 +18,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/fastify");
18
18
  function bind(fastify, data, opts = {}) {
19
19
  const { globalGuards, parallelRoute, globalAddons = [], parallelAddons = [], globalFilter, globalPipe, fastifyOpts, dynamic = false } = opts;
20
20
  const { moduleMap, meta } = data;
21
- const metaMap = _chunk76UDKZOJjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
+ const metaMap = _chunkXOWAQGBOjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
22
22
  const { controller, http, method, tag } = meta2.data;
23
23
  if (controller === "http" && _optionalChain([http, 'optionalAccess', _2 => _2.method])) {
24
24
  debug(`register method "${method}" in module "${tag}"`);
25
25
  return true;
26
26
  }
27
27
  });
28
- _chunk76UDKZOJjs.detectAopDep.call(void 0, meta, {
28
+ _chunkXOWAQGBOjs.detectAopDep.call(void 0, meta, {
29
29
  addons: [
30
30
  ...globalAddons,
31
31
  ...parallelAddons
@@ -33,28 +33,28 @@ function bind(fastify, data, opts = {}) {
33
33
  guards: globalGuards
34
34
  });
35
35
  fastify.register(async (fastify2, _, done) => {
36
- _chunk76UDKZOJjs.Context.applyAddons(globalAddons, fastify2, "fastify");
36
+ _chunkXOWAQGBOjs.Context.applyAddons(globalAddons, fastify2, "fastify");
37
37
  if (parallelRoute) {
38
38
  fastify2.register(async (fastify3, _opts, done2) => {
39
- _chunk76UDKZOJjs.Context.applyAddons(parallelAddons, fastify3, "fastify");
39
+ _chunkXOWAQGBOjs.Context.applyAddons(parallelAddons, fastify3, "fastify");
40
40
  fastify3.post(parallelRoute, async (req, res) => {
41
41
  const { body } = req;
42
42
  async function errorHandler(e) {
43
- const error = await _chunk76UDKZOJjs.Context.filterRecord.default(e);
43
+ const error = await _chunkXOWAQGBOjs.Context.filterRecord.default(e);
44
44
  return res.status(error.status).send(error);
45
45
  }
46
46
  _chunkLLF55NZPjs.__name.call(void 0, errorHandler, "errorHandler");
47
- if (!Array.isArray(body)) return errorHandler(new (0, _chunk76UDKZOJjs.BadRequestException)("data format should be an array"));
47
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkXOWAQGBOjs.BadRequestException)("data format should be an array"));
48
48
  try {
49
49
  return Promise.all(body.map((item, i) => {
50
50
  return new Promise(async (resolve) => {
51
51
  if (!item) return resolve(null);
52
52
  const { tag, method } = item;
53
53
  debug(`(parallel)invoke method "${method}" in module "${tag}"`);
54
- if (!metaMap.has(tag)) return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`module "${tag}" doesn't exist`)));
54
+ if (!metaMap.has(tag)) return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`module "${tag}" doesn't exist`)));
55
55
  const meta2 = metaMap.get(tag)[method];
56
- if (!meta2) return resolve(await _chunk76UDKZOJjs.Context.filterRecord.default(new (0, _chunk76UDKZOJjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
57
- const aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
56
+ if (!meta2) return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
57
+ const aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
58
58
  globalFilter,
59
59
  globalGuards,
60
60
  globalPipe
@@ -82,7 +82,7 @@ function bind(fastify, data, opts = {}) {
82
82
  getRequest: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => req.raw, "getRequest"),
83
83
  getResponse: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => res.raw, "getResponse")
84
84
  };
85
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
85
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
86
86
  context.run(aop, resolve, resolve);
87
87
  });
88
88
  })).then((ret) => {
@@ -101,16 +101,16 @@ function bind(fastify, data, opts = {}) {
101
101
  const { data: { addons, define, http } } = meta2;
102
102
  if (!_optionalChain([http, 'optionalAccess', _3 => _3.method])) continue;
103
103
  fastify2.register(async (fastify3, _opts, done2) => {
104
- _chunk76UDKZOJjs.Context.applyAddons(addons, fastify3, "fastify");
104
+ _chunkXOWAQGBOjs.Context.applyAddons(addons, fastify3, "fastify");
105
105
  let aop;
106
106
  if (!dynamic) {
107
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
107
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
108
108
  globalFilter,
109
109
  globalGuards,
110
110
  globalPipe
111
111
  });
112
112
  }
113
- fastify3[http.method](_chunk76UDKZOJjs.joinUrl.call(void 0, http.prefix, http.route), _optionalChain([define, 'optionalAccess', _4 => _4.fastify]) || {}, async (req, res) => {
113
+ fastify3[http.method](_chunkXOWAQGBOjs.joinUrl.call(void 0, http.prefix, http.route), _optionalChain([define, 'optionalAccess', _4 => _4.fastify]) || {}, async (req, res) => {
114
114
  debug(`invoke method "${method}" in module "${tag}"`);
115
115
  const contextData = {
116
116
  type: "fastify",
@@ -140,10 +140,10 @@ function bind(fastify, data, opts = {}) {
140
140
  getRequest: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => req.raw, "getRequest"),
141
141
  getResponse: /* @__PURE__ */ _chunkLLF55NZPjs.__name.call(void 0, () => res.raw, "getResponse")
142
142
  };
143
- const context = new (0, _chunk76UDKZOJjs.Context)(contextData);
143
+ const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
144
144
  if (http.headers) res.headers(http.headers);
145
145
  if (dynamic) {
146
- aop = _chunk76UDKZOJjs.Context.getAop(meta2, {
146
+ aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
147
147
  globalFilter,
148
148
  globalGuards,
149
149
  globalPipe
@@ -7,7 +7,7 @@ import {
7
7
  createControllerMetaMap,
8
8
  detectAopDep,
9
9
  joinUrl
10
- } from "../../chunk-WST6E6MQ.mjs";
10
+ } from "../../chunk-LQFHZGVJ.mjs";
11
11
  import {
12
12
  __name
13
13
  } from "../../chunk-URKOYTBU.mjs";