phecda-server 7.1.4 → 8.0.1
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/dist/{chunk-MKRHYZCL.mjs → chunk-FI5756JX.mjs} +2 -2
- package/dist/{chunk-P3CS65OP.mjs → chunk-G5IH3TP7.mjs} +81 -21
- package/dist/{chunk-OV3UJLGP.js → chunk-LD7YMHIE.js} +81 -21
- package/dist/{chunk-YRS4ECPT.js → chunk-OLNN4U3O.js} +12 -8
- package/dist/{chunk-5MAGRSEM.mjs → chunk-PFPOEZHH.mjs} +12 -8
- package/dist/{chunk-DPPDWBYO.js → chunk-UYZSUBX4.js} +2 -2
- 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/utils.mjs +0 -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,
|
|
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
|
};
|
|
@@ -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,20 +201,77 @@ 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
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
|
|
204
|
+
var defaultPipe = /* @__PURE__ */ __name(async ({ arg, reflect, meta, index, type }, { 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 ([
|
|
210
|
+
"params",
|
|
211
|
+
"query"
|
|
212
|
+
].includes(type)) {
|
|
213
|
+
if (reflect === Number) {
|
|
214
|
+
arg = reflect(arg);
|
|
215
|
+
if (isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
|
|
216
|
+
} else if (reflect === Boolean) {
|
|
217
|
+
if (arg === "false") arg = false;
|
|
218
|
+
else if (arg === "true") arg = true;
|
|
219
|
+
else throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
214
220
|
}
|
|
221
|
+
} else {
|
|
222
|
+
if (reflect === Number && typeof arg !== "number") throw new ValidateException(`param ${index + 1} is not a number`);
|
|
223
|
+
if (reflect === Boolean && typeof arg !== "boolean") throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
224
|
+
if (reflect === String && typeof arg !== "string") throw new ValidateException(`param ${index + 1} is not a string`);
|
|
225
|
+
}
|
|
226
|
+
if (meta.enum) {
|
|
227
|
+
if (!Object.values(meta.enum).includes(arg)) throw new ValidateException(`param ${index + 1} is not a valid enum value`);
|
|
228
|
+
}
|
|
229
|
+
if (meta.oneOf) {
|
|
230
|
+
let isCorrect = false;
|
|
231
|
+
for (const modelOrRule of meta.oneOf) {
|
|
232
|
+
switch (modelOrRule) {
|
|
233
|
+
case String:
|
|
234
|
+
if (typeof arg === "string") isCorrect = true;
|
|
235
|
+
break;
|
|
236
|
+
case Number:
|
|
237
|
+
if (typeof arg === "number") isCorrect = true;
|
|
238
|
+
break;
|
|
239
|
+
case Boolean:
|
|
240
|
+
if (typeof arg === "boolean") isCorrect = true;
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
if (isPhecda(modelOrRule)) {
|
|
244
|
+
const errs = await validate(modelOrRule, arg);
|
|
245
|
+
if (!errs.length) {
|
|
246
|
+
isCorrect = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
} else if (typeof modelOrRule === "function") {
|
|
250
|
+
const ret = await modelOrRule(arg);
|
|
251
|
+
if (ret) {
|
|
252
|
+
isCorrect = true;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!isCorrect) throw new ValidateException(`param ${index + 1} can't pass one of these validations`);
|
|
259
|
+
}
|
|
260
|
+
if (meta.rules) {
|
|
261
|
+
for (const rule of meta.rules) {
|
|
262
|
+
const err = await rule({
|
|
263
|
+
value: arg,
|
|
264
|
+
property: method,
|
|
265
|
+
meta,
|
|
266
|
+
model: reflect,
|
|
267
|
+
index
|
|
268
|
+
});
|
|
269
|
+
if (err.length > 0) throw new ValidateException(err[0]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (isPhecda(reflect)) {
|
|
273
|
+
const errs = await validate(reflect, arg);
|
|
274
|
+
if (errs.length) throw new ValidateException(errs[0]);
|
|
215
275
|
}
|
|
216
276
|
return arg;
|
|
217
277
|
}, "defaultPipe");
|
|
@@ -265,7 +325,7 @@ var Context = class _Context {
|
|
|
265
325
|
}
|
|
266
326
|
static getAop(meta, opts) {
|
|
267
327
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
268
|
-
const { data: { guards, filter, params, tag,
|
|
328
|
+
const { data: { guards, filter, params, tag, method } } = meta;
|
|
269
329
|
const resolved = {
|
|
270
330
|
guards: [
|
|
271
331
|
...globalGuards,
|
|
@@ -276,7 +336,7 @@ var Context = class _Context {
|
|
|
276
336
|
};
|
|
277
337
|
if (process.env.DEBUG) {
|
|
278
338
|
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
279
|
-
debug(`
|
|
339
|
+
debug(`method "${tag}-${method}" aop:
|
|
280
340
|
${pc.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
281
341
|
${pc.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
282
342
|
${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
@@ -289,7 +349,7 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
289
349
|
}
|
|
290
350
|
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
291
351
|
const { meta, moduleMap } = this.data;
|
|
292
|
-
const { paramsType, data: { ctxs, tag, params,
|
|
352
|
+
const { paramsType, data: { ctxs, tag, params, method } } = meta;
|
|
293
353
|
try {
|
|
294
354
|
let res;
|
|
295
355
|
const nextHandler = /* @__PURE__ */ __name((index) => {
|
|
@@ -304,13 +364,13 @@ ${pc.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
304
364
|
reflect: paramsType[item.index],
|
|
305
365
|
...item
|
|
306
366
|
}, this.ctx)));
|
|
307
|
-
res = await instance[
|
|
367
|
+
res = await instance[method](...args);
|
|
308
368
|
} else {
|
|
309
369
|
let nextPromise;
|
|
310
370
|
async function next() {
|
|
311
371
|
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
312
372
|
if (ret2 !== void 0) {
|
|
313
|
-
debug(`The ${index + 1}th guard on "${tag}-${
|
|
373
|
+
debug(`The ${index + 1}th guard on "${tag}-${method}" rewrite the response value.`);
|
|
314
374
|
res = ret2;
|
|
315
375
|
}
|
|
316
376
|
return res;
|
|
@@ -409,11 +469,11 @@ function createControllerMetaMap(meta, filter) {
|
|
|
409
469
|
function handleMeta() {
|
|
410
470
|
metaMap.clear();
|
|
411
471
|
for (const item of meta) {
|
|
412
|
-
const { tag,
|
|
472
|
+
const { tag, method } = item.data;
|
|
413
473
|
if (!filter(item)) continue;
|
|
414
|
-
if (metaMap.has(tag)) metaMap.get(tag)[
|
|
474
|
+
if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
|
|
415
475
|
else metaMap.set(tag, {
|
|
416
|
-
[
|
|
476
|
+
[method]: item
|
|
417
477
|
});
|
|
418
478
|
}
|
|
419
479
|
}
|
|
@@ -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,20 +201,77 @@ 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
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
|
|
204
|
+
var defaultPipe = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, async ({ arg, reflect, meta, index, type }, { 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 ([
|
|
210
|
+
"params",
|
|
211
|
+
"query"
|
|
212
|
+
].includes(type)) {
|
|
213
|
+
if (reflect === Number) {
|
|
214
|
+
arg = reflect(arg);
|
|
215
|
+
if (isNaN(arg)) throw new ValidateException(`param ${index + 1} is not a number`);
|
|
216
|
+
} else if (reflect === Boolean) {
|
|
217
|
+
if (arg === "false") arg = false;
|
|
218
|
+
else if (arg === "true") arg = true;
|
|
219
|
+
else throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
214
220
|
}
|
|
221
|
+
} else {
|
|
222
|
+
if (reflect === Number && typeof arg !== "number") throw new ValidateException(`param ${index + 1} is not a number`);
|
|
223
|
+
if (reflect === Boolean && typeof arg !== "boolean") throw new ValidateException(`param ${index + 1} is not a boolean`);
|
|
224
|
+
if (reflect === String && typeof arg !== "string") throw new ValidateException(`param ${index + 1} is not a string`);
|
|
225
|
+
}
|
|
226
|
+
if (meta.enum) {
|
|
227
|
+
if (!Object.values(meta.enum).includes(arg)) throw new ValidateException(`param ${index + 1} is not a valid enum value`);
|
|
228
|
+
}
|
|
229
|
+
if (meta.oneOf) {
|
|
230
|
+
let isCorrect = false;
|
|
231
|
+
for (const modelOrRule of meta.oneOf) {
|
|
232
|
+
switch (modelOrRule) {
|
|
233
|
+
case String:
|
|
234
|
+
if (typeof arg === "string") isCorrect = true;
|
|
235
|
+
break;
|
|
236
|
+
case Number:
|
|
237
|
+
if (typeof arg === "number") isCorrect = true;
|
|
238
|
+
break;
|
|
239
|
+
case Boolean:
|
|
240
|
+
if (typeof arg === "boolean") isCorrect = true;
|
|
241
|
+
break;
|
|
242
|
+
default:
|
|
243
|
+
if (_phecdacore.isPhecda.call(void 0, modelOrRule)) {
|
|
244
|
+
const errs = await _phecdacore.validate.call(void 0, modelOrRule, arg);
|
|
245
|
+
if (!errs.length) {
|
|
246
|
+
isCorrect = true;
|
|
247
|
+
break;
|
|
248
|
+
}
|
|
249
|
+
} else if (typeof modelOrRule === "function") {
|
|
250
|
+
const ret = await modelOrRule(arg);
|
|
251
|
+
if (ret) {
|
|
252
|
+
isCorrect = true;
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (!isCorrect) throw new ValidateException(`param ${index + 1} can't pass one of these validations`);
|
|
259
|
+
}
|
|
260
|
+
if (meta.rules) {
|
|
261
|
+
for (const rule of meta.rules) {
|
|
262
|
+
const err = await rule({
|
|
263
|
+
value: arg,
|
|
264
|
+
property: method,
|
|
265
|
+
meta,
|
|
266
|
+
model: reflect,
|
|
267
|
+
index
|
|
268
|
+
});
|
|
269
|
+
if (err.length > 0) throw new ValidateException(err[0]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
if (_phecdacore.isPhecda.call(void 0, reflect)) {
|
|
273
|
+
const errs = await _phecdacore.validate.call(void 0, reflect, arg);
|
|
274
|
+
if (errs.length) throw new ValidateException(errs[0]);
|
|
215
275
|
}
|
|
216
276
|
return arg;
|
|
217
277
|
}, "defaultPipe");
|
|
@@ -265,7 +325,7 @@ var Context = (_class = class _Context {
|
|
|
265
325
|
}
|
|
266
326
|
static getAop(meta, opts) {
|
|
267
327
|
const { globalGuards = [], globalFilter = "default", globalPipe = "default" } = opts;
|
|
268
|
-
const { data: { guards, filter, params, tag,
|
|
328
|
+
const { data: { guards, filter, params, tag, method } } = meta;
|
|
269
329
|
const resolved = {
|
|
270
330
|
guards: [
|
|
271
331
|
...globalGuards,
|
|
@@ -276,7 +336,7 @@ var Context = (_class = class _Context {
|
|
|
276
336
|
};
|
|
277
337
|
if (process.env.DEBUG) {
|
|
278
338
|
const { guards: guards2, pipe, filter: filter2 } = resolved;
|
|
279
|
-
debug(`
|
|
339
|
+
debug(`method "${tag}-${method}" aop:
|
|
280
340
|
${_picocolors2.default.magenta(`Guard ${guards2.join("->")}[${guards2.filter((g) => g in this.guardRecord).join("->")}]`)}
|
|
281
341
|
${_picocolors2.default.blue(`Pipe ${pipe.join("-")}[${pipe.map((p) => p in this.pipeRecord ? p : "default").join("-")}]`)}
|
|
282
342
|
${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
@@ -289,7 +349,7 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
289
349
|
}
|
|
290
350
|
async run({ guards, filter, pipe }, successCb, failCb) {
|
|
291
351
|
const { meta, moduleMap } = this.data;
|
|
292
|
-
const { paramsType, data: { ctxs, tag, params,
|
|
352
|
+
const { paramsType, data: { ctxs, tag, params, method } } = meta;
|
|
293
353
|
try {
|
|
294
354
|
let res;
|
|
295
355
|
const nextHandler = /* @__PURE__ */ _chunk4LLLQOMFjs.__name.call(void 0, (index) => {
|
|
@@ -304,13 +364,13 @@ ${_picocolors2.default.red(`Filter ${filter2}[${filter2 || "default"}]`)}`);
|
|
|
304
364
|
reflect: paramsType[item.index],
|
|
305
365
|
...item
|
|
306
366
|
}, this.ctx)));
|
|
307
|
-
res = await instance[
|
|
367
|
+
res = await instance[method](...args);
|
|
308
368
|
} else {
|
|
309
369
|
let nextPromise;
|
|
310
370
|
async function next() {
|
|
311
371
|
return nextPromise = nextHandler(index + 1)().then((ret2) => {
|
|
312
372
|
if (ret2 !== void 0) {
|
|
313
|
-
debug(`The ${index + 1}th guard on "${tag}-${
|
|
373
|
+
debug(`The ${index + 1}th guard on "${tag}-${method}" rewrite the response value.`);
|
|
314
374
|
res = ret2;
|
|
315
375
|
}
|
|
316
376
|
return res;
|
|
@@ -409,11 +469,11 @@ function createControllerMetaMap(meta, filter) {
|
|
|
409
469
|
function handleMeta() {
|
|
410
470
|
metaMap.clear();
|
|
411
471
|
for (const item of meta) {
|
|
412
|
-
const { tag,
|
|
472
|
+
const { tag, method } = item.data;
|
|
413
473
|
if (!filter(item)) continue;
|
|
414
|
-
if (metaMap.has(tag)) metaMap.get(tag)[
|
|
474
|
+
if (metaMap.has(tag)) metaMap.get(tag)[method] = item;
|
|
415
475
|
else metaMap.set(tag, {
|
|
416
|
-
[
|
|
476
|
+
[method]: item
|
|
417
477
|
});
|
|
418
478
|
}
|
|
419
479
|
}
|
|
@@ -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");
|
|
@@ -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");
|
|
@@ -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
|
};
|
|
@@ -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 _chunkLD7YMHIEjs = require('./chunk-LD7YMHIE.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 = _chunkLD7YMHIEjs.createControllerMetaMap; exports.detectAopDep = _chunkLD7YMHIEjs.detectAopDep; exports.joinUrl = _chunkLD7YMHIEjs.joinUrl; exports.mergeObject = _chunkLD7YMHIEjs.mergeObject; exports.resolveDep = _chunkLD7YMHIEjs.resolveDep; exports.shallowClone = _chunkLD7YMHIEjs.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 {
|