phecda-server 7.1.3 → 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.
- package/assets/schema.json +5 -0
- package/dist/{chunk-MKRHYZCL.mjs → chunk-FI5756JX.mjs} +2 -2
- package/dist/{chunk-JTSD2LIG.js → chunk-OLNN4U3O.js} +13 -11
- package/dist/{chunk-TQSHE4PZ.mjs → chunk-PFPOEZHH.mjs} +13 -11
- package/dist/{chunk-DPPDWBYO.js → chunk-UYZSUBX4.js} +2 -2
- package/dist/{chunk-P3CS65OP.mjs → chunk-VAHCYYCB.mjs} +32 -17
- package/dist/{chunk-OV3UJLGP.js → chunk-YJ3QHGTC.js} +32 -17
- package/dist/{core-B5yKYkMJ.d.mts → core-BTSHIAyB.d.ts} +2 -1
- package/dist/{core-BRuvL6hY.d.ts → core-D1YYphEn.d.mts} +2 -1
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +2 -2
- package/dist/helper.mjs +1 -1
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +30 -30
- package/dist/http/elysia/index.mjs +15 -15
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +27 -27
- package/dist/http/express/index.mjs +14 -14
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +29 -29
- package/dist/http/fastify/index.mjs +15 -15
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +28 -28
- package/dist/http/h3/index.mjs +14 -14
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +26 -26
- package/dist/http/hono/index.mjs +14 -14
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +26 -26
- package/dist/http/hyper-express/index.mjs +14 -14
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +27 -27
- package/dist/http/koa/index.mjs +14 -14
- package/dist/index.d.mts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +112 -71
- package/dist/index.mjs +69 -28
- package/dist/{meta-C_eDyXnK.d.ts → meta-DNF6Fl27.d.mts} +11 -9
- package/dist/{meta-C_eDyXnK.d.mts → meta-DNF6Fl27.d.ts} +11 -9
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +16 -16
- package/dist/rpc/bullmq/index.mjs +11 -11
- package/dist/rpc/electron/index.d.mts +3 -3
- package/dist/rpc/electron/index.d.ts +3 -3
- package/dist/rpc/electron/index.js +11 -11
- package/dist/rpc/electron/index.mjs +7 -7
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +9 -9
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +14 -14
- package/dist/rpc/nats/index.mjs +9 -9
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +14 -14
- package/dist/rpc/rabbitmq/index.mjs +9 -9
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +14 -14
- package/dist/rpc/redis/index.mjs +9 -9
- package/dist/rpc/ws/index.d.mts +3 -3
- package/dist/rpc/ws/index.d.ts +3 -3
- package/dist/rpc/ws/index.js +10 -10
- package/dist/rpc/ws/index.mjs +6 -6
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/test.js +5 -5
- package/dist/test.mjs +4 -4
- package/dist/{types-7-m2wEkP.d.mts → types-BOZ8yE2L.d.mts} +1 -1
- package/dist/{types-BuvMT1ta.d.ts → types-Cosv4nol.d.ts} +1 -1
- package/dist/{types-BKHBmSQN.d.mts → types-DtiHAXQB.d.mts} +1 -1
- package/dist/{types-B6aU8oT-.d.ts → types-YJ55P7A_.d.ts} +1 -1
- package/package.json +3 -4
- package/register/export.mjs +5 -1
- package/register/loader.mjs +293 -292
- package/register/utils.mjs +43 -70
package/assets/schema.json
CHANGED
|
@@ -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,
|
|
107
|
+
function Route(route, method) {
|
|
108
108
|
return (target, property) => {
|
|
109
109
|
setMeta3(target, property, void 0, {
|
|
110
110
|
http: {
|
|
111
111
|
route,
|
|
112
|
-
|
|
112
|
+
method
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
};
|
|
@@ -13,14 +13,17 @@ var Meta = class {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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");
|
|
@@ -292,9 +296,7 @@ function deepFreeze(object) {
|
|
|
292
296
|
}
|
|
293
297
|
_chunk4LLLQOMFjs.__name.call(void 0, deepFreeze, "deepFreeze");
|
|
294
298
|
function getParamTypes(Model, key) {
|
|
295
|
-
|
|
296
|
-
if (typeof paramTypes === "function") return paramTypes();
|
|
297
|
-
else return paramTypes;
|
|
299
|
+
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
298
300
|
}
|
|
299
301
|
_chunk4LLLQOMFjs.__name.call(void 0, getParamTypes, "getParamTypes");
|
|
300
302
|
|
|
@@ -13,14 +13,17 @@ var Meta = class {
|
|
|
13
13
|
}
|
|
14
14
|
data;
|
|
15
15
|
paramsType;
|
|
16
|
-
|
|
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
|
|
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,
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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");
|
|
@@ -292,9 +296,7 @@ function deepFreeze(object) {
|
|
|
292
296
|
}
|
|
293
297
|
__name(deepFreeze, "deepFreeze");
|
|
294
298
|
function getParamTypes(Model, key) {
|
|
295
|
-
|
|
296
|
-
if (typeof paramTypes === "function") return paramTypes();
|
|
297
|
-
else return paramTypes;
|
|
299
|
+
return Reflect.getMetadata("design:paramtypes", Model, key);
|
|
298
300
|
}
|
|
299
301
|
__name(getParamTypes, "getParamTypes");
|
|
300
302
|
|
|
@@ -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,
|
|
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
|
-
|
|
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,
|
|
202
|
-
if (arg
|
|
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 (
|
|
208
|
-
if (
|
|
209
|
-
for (const rule of
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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,
|
|
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(`
|
|
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,
|
|
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[
|
|
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}-${
|
|
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,
|
|
427
|
+
const { tag, method } = item.data;
|
|
413
428
|
if (!filter(item)) continue;
|
|
414
|
-
if (metaMap.has(tag)) metaMap.get(tag)[
|
|
429
|
+
if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
|
|
415
430
|
else metaMap.set(tag, {
|
|
416
|
-
[
|
|
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,
|
|
202
|
-
if (arg
|
|
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 (
|
|
208
|
-
if (
|
|
209
|
-
for (const rule of
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
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,
|
|
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(`
|
|
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,
|
|
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[
|
|
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}-${
|
|
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,
|
|
427
|
+
const { tag, method } = item.data;
|
|
413
428
|
if (!filter(item)) continue;
|
|
414
|
-
if (metaMap.has(tag)) metaMap.get(tag)[
|
|
429
|
+
if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
|
|
415
430
|
else metaMap.set(tag, {
|
|
416
|
-
[
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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
|
|
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 =
|
|
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
|
@@ -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-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
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-
|
|
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-
|
|
4
|
-
import { F as Factory } from '../../core-
|
|
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-
|
|
6
|
+
import '../../meta-DNF6Fl27.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface ElysiaCtx extends HttpCtx {
|