phecda-server 7.1.4 → 8.0.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 (84) hide show
  1. package/dist/{chunk-MKRHYZCL.mjs → chunk-FI5756JX.mjs} +2 -2
  2. package/dist/{chunk-YRS4ECPT.js → chunk-OLNN4U3O.js} +12 -8
  3. package/dist/{chunk-5MAGRSEM.mjs → chunk-PFPOEZHH.mjs} +12 -8
  4. package/dist/{chunk-DPPDWBYO.js → chunk-UYZSUBX4.js} +2 -2
  5. package/dist/{chunk-P3CS65OP.mjs → chunk-VAHCYYCB.mjs} +32 -17
  6. package/dist/{chunk-OV3UJLGP.js → chunk-YJ3QHGTC.js} +32 -17
  7. package/dist/{core-B5yKYkMJ.d.mts → core-BTSHIAyB.d.ts} +2 -1
  8. package/dist/{core-BRuvL6hY.d.ts → core-D1YYphEn.d.mts} +2 -1
  9. package/dist/helper.d.mts +1 -1
  10. package/dist/helper.d.ts +1 -1
  11. package/dist/helper.js +2 -2
  12. package/dist/helper.mjs +1 -1
  13. package/dist/http/elysia/index.d.mts +3 -3
  14. package/dist/http/elysia/index.d.ts +3 -3
  15. package/dist/http/elysia/index.js +30 -30
  16. package/dist/http/elysia/index.mjs +15 -15
  17. package/dist/http/express/index.d.mts +3 -3
  18. package/dist/http/express/index.d.ts +3 -3
  19. package/dist/http/express/index.js +27 -27
  20. package/dist/http/express/index.mjs +14 -14
  21. package/dist/http/fastify/index.d.mts +3 -3
  22. package/dist/http/fastify/index.d.ts +3 -3
  23. package/dist/http/fastify/index.js +29 -29
  24. package/dist/http/fastify/index.mjs +15 -15
  25. package/dist/http/h3/index.d.mts +3 -3
  26. package/dist/http/h3/index.d.ts +3 -3
  27. package/dist/http/h3/index.js +28 -28
  28. package/dist/http/h3/index.mjs +14 -14
  29. package/dist/http/hono/index.d.mts +3 -3
  30. package/dist/http/hono/index.d.ts +3 -3
  31. package/dist/http/hono/index.js +26 -26
  32. package/dist/http/hono/index.mjs +14 -14
  33. package/dist/http/hyper-express/index.d.mts +3 -3
  34. package/dist/http/hyper-express/index.d.ts +3 -3
  35. package/dist/http/hyper-express/index.js +26 -26
  36. package/dist/http/hyper-express/index.mjs +14 -14
  37. package/dist/http/koa/index.d.mts +3 -3
  38. package/dist/http/koa/index.d.ts +3 -3
  39. package/dist/http/koa/index.js +27 -27
  40. package/dist/http/koa/index.mjs +14 -14
  41. package/dist/index.d.mts +20 -13
  42. package/dist/index.d.ts +20 -13
  43. package/dist/index.js +112 -71
  44. package/dist/index.mjs +69 -28
  45. package/dist/{meta-C_eDyXnK.d.ts → meta-DNF6Fl27.d.mts} +11 -9
  46. package/dist/{meta-C_eDyXnK.d.mts → meta-DNF6Fl27.d.ts} +11 -9
  47. package/dist/rpc/bullmq/index.d.mts +3 -3
  48. package/dist/rpc/bullmq/index.d.ts +3 -3
  49. package/dist/rpc/bullmq/index.js +16 -16
  50. package/dist/rpc/bullmq/index.mjs +11 -11
  51. package/dist/rpc/electron/index.d.mts +3 -3
  52. package/dist/rpc/electron/index.d.ts +3 -3
  53. package/dist/rpc/electron/index.js +11 -11
  54. package/dist/rpc/electron/index.mjs +7 -7
  55. package/dist/rpc/kafka/index.d.mts +3 -3
  56. package/dist/rpc/kafka/index.d.ts +3 -3
  57. package/dist/rpc/kafka/index.js +14 -14
  58. package/dist/rpc/kafka/index.mjs +9 -9
  59. package/dist/rpc/nats/index.d.mts +3 -3
  60. package/dist/rpc/nats/index.d.ts +3 -3
  61. package/dist/rpc/nats/index.js +14 -14
  62. package/dist/rpc/nats/index.mjs +9 -9
  63. package/dist/rpc/rabbitmq/index.d.mts +3 -3
  64. package/dist/rpc/rabbitmq/index.d.ts +3 -3
  65. package/dist/rpc/rabbitmq/index.js +14 -14
  66. package/dist/rpc/rabbitmq/index.mjs +9 -9
  67. package/dist/rpc/redis/index.d.mts +3 -3
  68. package/dist/rpc/redis/index.d.ts +3 -3
  69. package/dist/rpc/redis/index.js +14 -14
  70. package/dist/rpc/redis/index.mjs +9 -9
  71. package/dist/rpc/ws/index.d.mts +3 -3
  72. package/dist/rpc/ws/index.d.ts +3 -3
  73. package/dist/rpc/ws/index.js +10 -10
  74. package/dist/rpc/ws/index.mjs +6 -6
  75. package/dist/test.d.mts +2 -2
  76. package/dist/test.d.ts +2 -2
  77. package/dist/test.js +5 -5
  78. package/dist/test.mjs +4 -4
  79. package/dist/{types-7-m2wEkP.d.mts → types-BOZ8yE2L.d.mts} +1 -1
  80. package/dist/{types-BuvMT1ta.d.ts → types-Cosv4nol.d.ts} +1 -1
  81. package/dist/{types-BKHBmSQN.d.mts → types-DtiHAXQB.d.mts} +1 -1
  82. package/dist/{types-B6aU8oT-.d.ts → types-YJ55P7A_.d.ts} +1 -1
  83. package/package.json +3 -4
  84. package/register/export.mjs +5 -1
@@ -104,12 +104,12 @@ __name(Pipe, "Pipe");
104
104
 
105
105
  // src/decorators/http.ts
106
106
  import { setMeta as setMeta3 } from "phecda-core";
107
- function Route(route, type) {
107
+ function Route(route, method) {
108
108
  return (target, property) => {
109
109
  setMeta3(target, property, void 0, {
110
110
  http: {
111
111
  route,
112
- type
112
+ method
113
113
  }
114
114
  });
115
115
  };
@@ -13,14 +13,17 @@ var Meta = class {
13
13
  }
14
14
 
15
15
 
16
- constructor(data, paramsType) {
16
+
17
+
18
+ constructor(data, paramsType, module, model) {
17
19
  this.data = data;
18
20
  this.paramsType = paramsType;
21
+ this.module = module;
22
+ this.model = model;
19
23
  }
20
24
  };
21
25
 
22
26
  // src/core.ts
23
- require('reflect-metadata');
24
27
  var _events = require('events'); var _events2 = _interopRequireDefault(_events);
25
28
  var _phecdacore = require('phecda-core');
26
29
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
@@ -149,7 +152,7 @@ var ServerPhecda = (_class = class {
149
152
  } else {
150
153
  module = this.parseModule(new Model());
151
154
  }
152
- this.meta.push(...getMetaFromInstance(module, tag, Model.name).map(this.parseMeta).filter((item) => !!item));
155
+ this.meta.push(...getMetaFromInstance(module, tag, Model).map(this.parseMeta).filter((item) => !!item));
153
156
  debug(`init module "${String(tag)}"`);
154
157
  if (!_chunk4LLLQOMFjs.IS_ONLY_GENERATE) await _phecdacore.invokeInit.call(void 0, module);
155
158
  debug(`add module "${String(tag)}"`);
@@ -227,7 +230,8 @@ function useS(nsOrModel, namespace) {
227
230
  else return serverPhecda;
228
231
  }
229
232
  _chunk4LLLQOMFjs.__name.call(void 0, useS, "useS");
230
- function getMetaFromInstance(instance, tag, name) {
233
+ function getMetaFromInstance(instance, tag, model) {
234
+ const name = model.name;
231
235
  const propertyKeys = _phecdacore.getMetaKey.call(void 0, instance).filter((item) => typeof item === "string");
232
236
  const baseMeta = _phecdacore.getMergedMeta.call(void 0, instance, void 0);
233
237
  const ctxs = baseMeta.ctxs;
@@ -237,7 +241,7 @@ function getMetaFromInstance(instance, tag, name) {
237
241
  ...meta,
238
242
  name,
239
243
  tag,
240
- func: i
244
+ method: i
241
245
  };
242
246
  if (baseMeta.controller) {
243
247
  if (typeof tag !== "string") _chunk4LLLQOMFjs.log.call(void 0, `can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
@@ -247,7 +251,7 @@ function getMetaFromInstance(instance, tag, name) {
247
251
  ...meta[baseMeta.controller]
248
252
  };
249
253
  const params = _phecdacore.getMetaParams.call(void 0, instance, i).map((item) => _phecdacore.getMergedMeta.call(void 0, instance, i, item));
250
- metaData.rawMeta = meta;
254
+ metaData.meta = meta;
251
255
  metaData.ctxs = ctxs;
252
256
  metaData.params = params.map((item, index) => {
253
257
  return {
@@ -255,7 +259,7 @@ function getMetaFromInstance(instance, tag, name) {
255
259
  pipe: item.pipe || meta.pipe || baseMeta.pipe,
256
260
  define: item.define || {},
257
261
  index,
258
- rawMeta: item
262
+ meta: item
259
263
  };
260
264
  });
261
265
  metaData.filter = meta.filter || baseMeta.filter;
@@ -279,7 +283,7 @@ function getMetaFromInstance(instance, tag, name) {
279
283
  ];
280
284
  }
281
285
  }
282
- return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
286
+ return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || [], instance, model);
283
287
  });
284
288
  }
285
289
  _chunk4LLLQOMFjs.__name.call(void 0, getMetaFromInstance, "getMetaFromInstance");
@@ -13,14 +13,17 @@ var Meta = class {
13
13
  }
14
14
  data;
15
15
  paramsType;
16
- constructor(data, paramsType) {
16
+ module;
17
+ model;
18
+ constructor(data, paramsType, module, model) {
17
19
  this.data = data;
18
20
  this.paramsType = paramsType;
21
+ this.module = module;
22
+ this.model = model;
19
23
  }
20
24
  };
21
25
 
22
26
  // src/core.ts
23
- import "reflect-metadata";
24
27
  import EventEmitter from "events";
25
28
  import { getInject, getMergedMeta, getMetaKey, getMetaParams, getTag, invokeInit, invokeUnmount, setInject } from "phecda-core";
26
29
  import Debug from "debug";
@@ -149,7 +152,7 @@ var ServerPhecda = class {
149
152
  } else {
150
153
  module = this.parseModule(new Model());
151
154
  }
152
- this.meta.push(...getMetaFromInstance(module, tag, Model.name).map(this.parseMeta).filter((item) => !!item));
155
+ this.meta.push(...getMetaFromInstance(module, tag, Model).map(this.parseMeta).filter((item) => !!item));
153
156
  debug(`init module "${String(tag)}"`);
154
157
  if (!IS_ONLY_GENERATE) await invokeInit(module);
155
158
  debug(`add module "${String(tag)}"`);
@@ -227,7 +230,8 @@ function useS(nsOrModel, namespace) {
227
230
  else return serverPhecda;
228
231
  }
229
232
  __name(useS, "useS");
230
- function getMetaFromInstance(instance, tag, name) {
233
+ function getMetaFromInstance(instance, tag, model) {
234
+ const name = model.name;
231
235
  const propertyKeys = getMetaKey(instance).filter((item) => typeof item === "string");
232
236
  const baseMeta = getMergedMeta(instance, void 0);
233
237
  const ctxs = baseMeta.ctxs;
@@ -237,7 +241,7 @@ function getMetaFromInstance(instance, tag, name) {
237
241
  ...meta,
238
242
  name,
239
243
  tag,
240
- func: i
244
+ method: i
241
245
  };
242
246
  if (baseMeta.controller) {
243
247
  if (typeof tag !== "string") log(`can't use Tag with ${typeof tag} on controller "${instance.constructor.name}",instead with "${tag = String(tag)}"`, "error");
@@ -247,7 +251,7 @@ function getMetaFromInstance(instance, tag, name) {
247
251
  ...meta[baseMeta.controller]
248
252
  };
249
253
  const params = getMetaParams(instance, i).map((item) => getMergedMeta(instance, i, item));
250
- metaData.rawMeta = meta;
254
+ metaData.meta = meta;
251
255
  metaData.ctxs = ctxs;
252
256
  metaData.params = params.map((item, index) => {
253
257
  return {
@@ -255,7 +259,7 @@ function getMetaFromInstance(instance, tag, name) {
255
259
  pipe: item.pipe || meta.pipe || baseMeta.pipe,
256
260
  define: item.define || {},
257
261
  index,
258
- rawMeta: item
262
+ meta: item
259
263
  };
260
264
  });
261
265
  metaData.filter = meta.filter || baseMeta.filter;
@@ -279,7 +283,7 @@ function getMetaFromInstance(instance, tag, name) {
279
283
  ];
280
284
  }
281
285
  }
282
- return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || []);
286
+ return new Meta(deepFreeze(metaData), getParamTypes(instance, i) || [], instance, model);
283
287
  });
284
288
  }
285
289
  __name(getMetaFromInstance, "getMetaFromInstance");
@@ -104,12 +104,12 @@ _chunk4LLLQOMFjs.__name.call(void 0, Pipe, "Pipe");
104
104
 
105
105
  // src/decorators/http.ts
106
106
 
107
- function Route(route, type) {
107
+ function Route(route, method) {
108
108
  return (target, property) => {
109
109
  _phecdacore.setMeta.call(void 0, target, property, void 0, {
110
110
  http: {
111
111
  route,
112
- type
112
+ method
113
113
  }
114
114
  });
115
115
  };
@@ -16,6 +16,9 @@ import pc2 from "picocolors";
16
16
  import Debug from "debug";
17
17
  import pc from "picocolors";
18
18
 
19
+ // src/pipe.ts
20
+ import { isPhecda, validate } from "phecda-core";
21
+
19
22
  // src/exception/base.ts
20
23
  var Exception = class extends Error {
21
24
  static {
@@ -198,21 +201,33 @@ var WorkerException = class extends Exception {
198
201
  };
199
202
 
200
203
  // src/pipe.ts
201
- var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, rawMeta, index }) => {
202
- if (arg !== void 0 && [
204
+ var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index }, { method }) => {
205
+ if (arg === void 0) {
206
+ if (meta.required === false) return arg;
207
+ else throw new ValidateException(`param ${index + 1} is required`);
208
+ }
209
+ if ([
203
210
  Number,
204
211
  Boolean,
205
212
  String
206
213
  ].includes(reflect)) arg = reflect(arg);
207
- if (rawMeta.required && arg === void 0) throw new ValidateException(`param ${index} is required`);
208
- if (rawMeta.rules) {
209
- for (const rule of rawMeta.rules) {
210
- let res = rule(arg);
211
- if (res instanceof Promise) res = await res;
212
- if (typeof res === "string") throw new ValidateException(res);
213
- if (res === false) throw new ValidateException(`validation failed for param ${index}`);
214
+ if (reflect === Number && isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
215
+ if (meta.rules) {
216
+ for (const rule of meta.rules) {
217
+ const err = await rule({
218
+ value: arg,
219
+ property: method,
220
+ meta,
221
+ model: reflect,
222
+ index
223
+ });
224
+ if (err.length > 0) throw new ValidateException(err[0]);
214
225
  }
215
226
  }
227
+ if (isPhecda(reflect)) {
228
+ const errs = await validate(reflect, arg);
229
+ if (errs.length) throw new ValidateException(errs[0]);
230
+ }
216
231
  return arg;
217
232
  }, "defaultPipe");
218
233
 
@@ -265,7 +280,7 @@ var Context = class _Context {
265
280
  }
266
281
  static getAop(meta, opts) {
267
282
  const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
268
- const { data: { guards, filter, params, tag, func } } = meta;
283
+ const { data: { guards, filter, params, tag, method } } = meta;
269
284
  const resolved = {
270
285
  guards: [
271
286
  ...globalGuards,
@@ -276,7 +291,7 @@ var Context = class _Context {
276
291
  };
277
292
  if (process.env.DEBUG) {
278
293
  const { guards: guards2, pipe, filter: filter2 } = resolved;
279
- debug(`func "${tag}-${func}" aop:
294
+ debug(`method "${tag}-${method}" aop:
280
295
  ${pc.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
281
296
  ${pc.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
282
297
  ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
@@ -289,7 +304,7 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
289
304
  }
290
305
  async run({ guards, filter, pipe }, successCb, failCb) {
291
306
  const { meta, moduleMap } = this.data;
292
- const { paramsType, data: { ctxs, tag, params, func } } = meta;
307
+ const { paramsType, data: { ctxs, tag, params, method } } = meta;
293
308
  try {
294
309
  let res;
295
310
  const nextHandler = /* @__PURE__ */ __name((index) => {
@@ -304,13 +319,13 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
304
319
  reflect: paramsType[item.index],
305
320
  ...item
306
321
  }, this.ctx)));
307
- res = await instance[func](...args);
322
+ res = await instance[method](...args);
308
323
  } else {
309
324
  let nextPromise;
310
325
  async function next() {
311
326
  return nextPromise = nextHandler(index + 1)().then((ret2) => {
312
327
  if (ret2 !== void 0) {
313
- debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
328
+ debug(`The ${index + 1}th guard on "${tag}-${method}" rewrite the response value.`);
314
329
  res = ret2;
315
330
  }
316
331
  return res;
@@ -409,11 +424,11 @@ function createControllerMetaMap(meta, filter) {
409
424
  function handleMeta() {
410
425
  metaMap.clear();
411
426
  for (const item of meta) {
412
- const { tag, func } = item.data;
427
+ const { tag, method } = item.data;
413
428
  if (!filter(item)) continue;
414
- if (metaMap.has(tag)) metaMap.get(tag)[func] = item;
429
+ if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
415
430
  else metaMap.set(tag, {
416
- [func]: item
431
+ [method]: item
417
432
  });
418
433
  }
419
434
  }
@@ -16,6 +16,9 @@ var _picocolors = require('picocolors'); var _picocolors2 = _interopRequireDefau
16
16
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
17
17
 
18
18
 
19
+ // src/pipe.ts
20
+ var _phecdacore = require('phecda-core');
21
+
19
22
  // src/exception/base.ts
20
23
  var Exception = class extends Error {
21
24
  static {
@@ -198,21 +201,33 @@ var WorkerException = class extends Exception {
198
201
  };
199
202
 
200
203
  // src/pipe.ts
201
- var defaultPipe = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, async ({ arg, reflect, rawMeta, index }) => {
202
- if (arg !== void 0 && [
204
+ var defaultPipe = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, async ({ arg, reflect, meta, index }, { method }) => {
205
+ if (arg === void 0) {
206
+ if (meta.required === false) return arg;
207
+ else throw new ValidateException(`param ${index + 1} is required`);
208
+ }
209
+ if ([
203
210
  Number,
204
211
  Boolean,
205
212
  String
206
213
  ].includes(reflect)) arg = reflect(arg);
207
- if (rawMeta.required && arg === void 0) throw new ValidateException(`param ${index} is required`);
208
- if (rawMeta.rules) {
209
- for (const rule of rawMeta.rules) {
210
- let res = rule(arg);
211
- if (res instanceof Promise) res = await res;
212
- if (typeof res === "string") throw new ValidateException(res);
213
- if (res === false) throw new ValidateException(`validation failed for param ${index}`);
214
+ if (reflect === Number && isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
215
+ if (meta.rules) {
216
+ for (const rule of meta.rules) {
217
+ const err = await rule({
218
+ value: arg,
219
+ property: method,
220
+ meta,
221
+ model: reflect,
222
+ index
223
+ });
224
+ if (err.length > 0) throw new ValidateException(err[0]);
214
225
  }
215
226
  }
227
+ if (_phecdacore.isPhecda.call(void 0, reflect)) {
228
+ const errs = await _phecdacore.validate.call(void 0, reflect, arg);
229
+ if (errs.length) throw new ValidateException(errs[0]);
230
+ }
216
231
  return arg;
217
232
  }, "defaultPipe");
218
233
 
@@ -265,7 +280,7 @@ var Context = (_class = class _Context {
265
280
  }
266
281
  static getAop(meta, opts) {
267
282
  const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
268
- const { data: { guards, filter, params, tag, func } } = meta;
283
+ const { data: { guards, filter, params, tag, method } } = meta;
269
284
  const resolved = {
270
285
  guards: [
271
286
  ...globalGuards,
@@ -276,7 +291,7 @@ var Context = (_class = class _Context {
276
291
  };
277
292
  if (process.env.DEBUG) {
278
293
  const { guards: guards2, pipe, filter: filter2 } = resolved;
279
- debug(`func "${tag}-${func}" aop:
294
+ debug(`method "${tag}-${method}" aop:
280
295
  ${_picocolors2.default.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
281
296
  ${_picocolors2.default.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
282
297
  ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
@@ -289,7 +304,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
289
304
  }
290
305
  async run({ guards, filter, pipe }, successCb, failCb) {
291
306
  const { meta, moduleMap } = this.data;
292
- const { paramsType, data: { ctxs, tag, params, func } } = meta;
307
+ const { paramsType, data: { ctxs, tag, params, method } } = meta;
293
308
  try {
294
309
  let res;
295
310
  const nextHandler = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (index) => {
@@ -304,13 +319,13 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
304
319
  reflect: paramsType[item.index],
305
320
  ...item
306
321
  }, this.ctx)));
307
- res = await instance[func](...args);
322
+ res = await instance[method](...args);
308
323
  } else {
309
324
  let nextPromise;
310
325
  async function next() {
311
326
  return nextPromise = nextHandler(index + 1)().then((ret2) => {
312
327
  if (ret2 !== void 0) {
313
- debug(`The ${index + 1}th guard on "${tag}-${func}" rewrite the response value.`);
328
+ debug(`The ${index + 1}th guard on "${tag}-${method}" rewrite the response value.`);
314
329
  res = ret2;
315
330
  }
316
331
  return res;
@@ -409,11 +424,11 @@ function createControllerMetaMap(meta, filter) {
409
424
  function handleMeta() {
410
425
  metaMap.clear();
411
426
  for (const item of meta) {
412
- const { tag, func } = item.data;
427
+ const { tag, method } = item.data;
413
428
  if (!filter(item)) continue;
414
- if (metaMap.has(tag)) metaMap.get(tag)[func] = item;
429
+ if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
415
430
  else metaMap.set(tag, {
416
- [func]: item
431
+ [method]: item
417
432
  });
418
433
  }
419
434
  }
@@ -1,9 +1,10 @@
1
1
  import { Construct } from 'phecda-core';
2
- import { M as Meta, E as Emitter } from './meta-C_eDyXnK.mjs';
2
+ import { M as Meta, E as Emitter } from './meta-DNF6Fl27.js';
3
3
 
4
4
  declare abstract class Generator {
5
5
  private _path;
6
6
  constructor(path?: string);
7
+ ext: string;
7
8
  abstract name: string;
8
9
  get path(): string;
9
10
  abstract generateCode(meta: Meta[]): string;
@@ -1,9 +1,10 @@
1
1
  import { Construct } from 'phecda-core';
2
- import { M as Meta, E as Emitter } from './meta-C_eDyXnK.js';
2
+ import { M as Meta, E as Emitter } from './meta-DNF6Fl27.mjs';
3
3
 
4
4
  declare abstract class Generator {
5
5
  private _path;
6
6
  constructor(path?: string);
7
+ ext: string;
7
8
  abstract name: string;
8
9
  get path(): string;
9
10
  abstract generateCode(meta: Meta[]): string;
package/dist/helper.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as Meta, a as ControllerMeta } from './meta-C_eDyXnK.mjs';
1
+ import { M as Meta, a as ControllerMeta } from './meta-DNF6Fl27.mjs';
2
2
  import { Construct } from 'phecda-core';
3
3
 
4
4
  declare function HMR(cb: (oldModels: Construct[], newModels: Construct[]) => any): void;
package/dist/helper.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as Meta, a as ControllerMeta } from './meta-C_eDyXnK.js';
1
+ import { M as Meta, a as ControllerMeta } from './meta-DNF6Fl27.js';
2
2
  import { Construct } from 'phecda-core';
3
3
 
4
4
  declare function HMR(cb: (oldModels: Construct[], newModels: Construct[]) => any): void;
package/dist/helper.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkOV3UJLGPjs = require('./chunk-OV3UJLGP.js');
8
+ var _chunkYJ3QHGTCjs = require('./chunk-YJ3QHGTC.js');
9
9
 
10
10
 
11
11
 
@@ -21,4 +21,4 @@ var _chunk4LLLQOMFjs = require('./chunk-4LLLQOMF.js');
21
21
 
22
22
 
23
23
 
24
- exports.HMR = _chunk4LLLQOMFjs.HMR; exports.RELAUNCH = _chunk4LLLQOMFjs.RELAUNCH; exports.RELOAD = _chunk4LLLQOMFjs.RELOAD; exports.createControllerMetaMap = _chunkOV3UJLGPjs.createControllerMetaMap; exports.detectAopDep = _chunkOV3UJLGPjs.detectAopDep; exports.joinUrl = _chunkOV3UJLGPjs.joinUrl; exports.mergeObject = _chunkOV3UJLGPjs.mergeObject; exports.resolveDep = _chunkOV3UJLGPjs.resolveDep; exports.shallowClone = _chunkOV3UJLGPjs.shallowClone;
24
+ exports.HMR = _chunk4LLLQOMFjs.HMR; exports.RELAUNCH = _chunk4LLLQOMFjs.RELAUNCH; exports.RELOAD = _chunk4LLLQOMFjs.RELOAD; exports.createControllerMetaMap = _chunkYJ3QHGTCjs.createControllerMetaMap; exports.detectAopDep = _chunkYJ3QHGTCjs.detectAopDep; exports.joinUrl = _chunkYJ3QHGTCjs.joinUrl; exports.mergeObject = _chunkYJ3QHGTCjs.mergeObject; exports.resolveDep = _chunkYJ3QHGTCjs.resolveDep; exports.shallowClone = _chunkYJ3QHGTCjs.shallowClone;
package/dist/helper.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  mergeObject,
6
6
  resolveDep,
7
7
  shallowClone
8
- } from "./chunk-P3CS65OP.mjs";
8
+ } from "./chunk-VAHCYYCB.mjs";
9
9
  import {
10
10
  HMR,
11
11
  RELAUNCH,
@@ -1,9 +1,9 @@
1
1
  import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
2
2
  import { BaseMacro } from 'elysia/dist/types';
3
- import { H as HttpCtx, a as HttpOptions } from '../../types-BKHBmSQN.mjs';
4
- import { F as Factory } from '../../core-B5yKYkMJ.mjs';
3
+ import { H as HttpCtx, a as HttpOptions } from '../../types-DtiHAXQB.mjs';
4
+ import { F as Factory } from '../../core-D1YYphEn.mjs';
5
5
  import 'node:http';
6
- import '../../meta-C_eDyXnK.mjs';
6
+ import '../../meta-DNF6Fl27.mjs';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface ElysiaCtx extends HttpCtx {
@@ -1,9 +1,9 @@
1
1
  import { Elysia as Elysia$1, Context, LocalHook, InputSchema, RouteSchema, SingletonBase } from 'elysia';
2
2
  import { BaseMacro } from 'elysia/dist/types';
3
- import { H as HttpCtx, a as HttpOptions } from '../../types-BuvMT1ta.js';
4
- import { F as Factory } from '../../core-BRuvL6hY.js';
3
+ import { H as HttpCtx, a as HttpOptions } from '../../types-Cosv4nol.js';
4
+ import { F as Factory } from '../../core-BTSHIAyB.js';
5
5
  import 'node:http';
6
- import '../../meta-C_eDyXnK.js';
6
+ import '../../meta-DNF6Fl27.js';
7
7
  import 'phecda-core';
8
8
 
9
9
  interface ElysiaCtx extends HttpCtx {
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
- var _chunkDPPDWBYOjs = require('../../chunk-DPPDWBYO.js');
3
+ var _chunkUYZSUBX4js = require('../../chunk-UYZSUBX4.js');
4
4
 
5
5
 
6
6
 
7
7
 
8
8
 
9
9
 
10
- var _chunkOV3UJLGPjs = require('../../chunk-OV3UJLGP.js');
10
+ var _chunkYJ3QHGTCjs = require('../../chunk-YJ3QHGTC.js');
11
11
 
12
12
 
13
13
  var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.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 = "/__PHECDA_SERVER__", globalAddons = [], parallelAddons = [], globalFilter, globalPipe, dynamic = false } = opts;
21
21
  const { moduleMap, meta } = data;
22
- const metaMap = _chunkOV3UJLGPjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
23
- const { controller, http, func, tag } = meta2.data;
24
- if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.type])) {
25
- debug(`register method "${func}" in module "${tag}"`);
22
+ const metaMap = _chunkYJ3QHGTCjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
23
+ const { controller, http, method, tag } = meta2.data;
24
+ if (controller === "http" && _optionalChain([http, 'optionalAccess', _ => _.method])) {
25
+ debug(`register method "${method}" in module "${tag}"`);
26
26
  return true;
27
27
  }
28
28
  });
29
- _chunkOV3UJLGPjs.detectAopDep.call(void 0, meta, {
29
+ _chunkYJ3QHGTCjs.detectAopDep.call(void 0, meta, {
30
30
  addons: [
31
31
  ...globalAddons,
32
32
  ...parallelAddons
@@ -35,29 +35,29 @@ function bind(app, data, opts = {}) {
35
35
  });
36
36
  registerRoute();
37
37
  function registerRoute() {
38
- _chunkOV3UJLGPjs.Context.applyAddons(globalAddons, app, "elysia");
38
+ _chunkYJ3QHGTCjs.Context.applyAddons(globalAddons, app, "elysia");
39
39
  if (parallelRoute) {
40
40
  const parallelRouter = new (0, _elysia.Elysia)();
41
- _chunkOV3UJLGPjs.Context.applyAddons(parallelAddons, app, "elysia");
41
+ _chunkYJ3QHGTCjs.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 _chunkOV3UJLGPjs.Context.filterRecord.default(e);
45
+ const error = await _chunkYJ3QHGTCjs.Context.filterRecord.default(e);
46
46
  c.set.status = error.status;
47
47
  return error;
48
48
  }
49
49
  _chunk4LLLQOMFjs.__name.call(void 0, errorHandler, "errorHandler");
50
- if (!Array.isArray(body)) return errorHandler(new (0, _chunkOV3UJLGPjs.BadRequestException)("data format should be an array"));
50
+ if (!Array.isArray(body)) return errorHandler(new (0, _chunkYJ3QHGTCjs.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) => {
54
54
  if (!item) return resolve(null);
55
- const { tag, func } = item;
56
- debug(`(parallel)invoke method "${func}" in module "${tag}"`);
57
- if (!metaMap.has(tag)) return resolve(await _chunkOV3UJLGPjs.Context.filterRecord.default(new (0, _chunkOV3UJLGPjs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
- const meta2 = metaMap.get(tag)[func];
59
- if (!meta2) return resolve(await _chunkOV3UJLGPjs.Context.filterRecord.default(new (0, _chunkOV3UJLGPjs.BadRequestException)(`"${func}" in "${tag}" doesn't exist`)));
60
- const aop = _chunkOV3UJLGPjs.Context.getAop(meta2, {
55
+ const { tag, method } = item;
56
+ debug(`(parallel)invoke method "${method}" in module "${tag}"`);
57
+ if (!metaMap.has(tag)) return resolve(await _chunkYJ3QHGTCjs.Context.filterRecord.default(new (0, _chunkYJ3QHGTCjs.BadRequestException)(`module "${tag}" doesn't exist`)));
58
+ const meta2 = metaMap.get(tag)[method];
59
+ if (!meta2) return resolve(await _chunkYJ3QHGTCjs.Context.filterRecord.default(new (0, _chunkYJ3QHGTCjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
60
+ const aop = _chunkYJ3QHGTCjs.Context.getAop(meta2, {
61
61
  globalGuards,
62
62
  globalFilter,
63
63
  globalPipe
@@ -88,7 +88,7 @@ function bind(app, data, opts = {}) {
88
88
  throw new Error("elysia can't support getResponse");
89
89
  }, "getResponse")
90
90
  };
91
- const context = new (0, _chunkOV3UJLGPjs.Context)(contextData);
91
+ const context = new (0, _chunkYJ3QHGTCjs.Context)(contextData);
92
92
  context.run(aop, resolve, resolve);
93
93
  });
94
94
  })).then((ret) => {
@@ -101,24 +101,24 @@ function bind(app, data, opts = {}) {
101
101
  app.use(parallelRouter);
102
102
  }
103
103
  for (const [tag, record] of metaMap) {
104
- for (const func in record) {
105
- const meta2 = metaMap.get(tag)[func];
104
+ for (const method in record) {
105
+ const meta2 = metaMap.get(tag)[method];
106
106
  const { data: { define, addons, http } } = meta2;
107
107
  const subApp = new (0, _elysia.Elysia)({
108
108
  prefix: ""
109
109
  });
110
- if (!_optionalChain([http, 'optionalAccess', _2 => _2.type])) continue;
110
+ if (!_optionalChain([http, 'optionalAccess', _2 => _2.method])) continue;
111
111
  let aop;
112
112
  if (!dynamic) {
113
- aop = _chunkOV3UJLGPjs.Context.getAop(meta2, {
113
+ aop = _chunkYJ3QHGTCjs.Context.getAop(meta2, {
114
114
  globalFilter,
115
115
  globalGuards,
116
116
  globalPipe
117
117
  });
118
118
  }
119
- _chunkOV3UJLGPjs.Context.applyAddons(addons, subApp, "elysia");
120
- subApp[http.type](_chunkOV3UJLGPjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
121
- debug(`invoke method "${func}" in module "${tag}"`);
119
+ _chunkYJ3QHGTCjs.Context.applyAddons(addons, subApp, "elysia");
120
+ subApp[http.method](_chunkYJ3QHGTCjs.joinUrl.call(void 0, http.prefix, http.route), async (c) => {
121
+ debug(`invoke method "${method}" in module "${tag}"`);
122
122
  const contextData = {
123
123
  type: "elysia",
124
124
  category: "http",
@@ -126,7 +126,7 @@ function bind(app, data, opts = {}) {
126
126
  meta: meta2,
127
127
  moduleMap,
128
128
  tag,
129
- func,
129
+ method,
130
130
  query: c.query,
131
131
  body: c.body,
132
132
  params: c.params,
@@ -149,16 +149,16 @@ function bind(app, data, opts = {}) {
149
149
  }, "getResponse")
150
150
  };
151
151
  if (dynamic) {
152
- aop = _chunkOV3UJLGPjs.Context.getAop(meta2, {
152
+ aop = _chunkYJ3QHGTCjs.Context.getAop(meta2, {
153
153
  globalFilter,
154
154
  globalGuards,
155
155
  globalPipe
156
156
  });
157
157
  }
158
- const context = new (0, _chunkOV3UJLGPjs.Context)(contextData);
158
+ const context = new (0, _chunkYJ3QHGTCjs.Context)(contextData);
159
159
  if (http.headers) c.set.headers = http.headers;
160
160
  if (dynamic) {
161
- aop = _chunkOV3UJLGPjs.Context.getAop(meta2, {
161
+ aop = _chunkYJ3QHGTCjs.Context.getAop(meta2, {
162
162
  globalFilter,
163
163
  globalGuards,
164
164
  globalPipe
@@ -177,7 +177,7 @@ function bind(app, data, opts = {}) {
177
177
  }
178
178
  _chunk4LLLQOMFjs.__name.call(void 0, bind, "bind");
179
179
  function Elysia(opts) {
180
- return _chunkDPPDWBYOjs.Define.call(void 0, "elysia", opts);
180
+ return _chunkUYZSUBX4js.Define.call(void 0, "elysia", opts);
181
181
  }
182
182
  _chunk4LLLQOMFjs.__name.call(void 0, Elysia, "Elysia");
183
183