phecda-server 8.5.3 → 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.
- package/dist/{chunk-WST6E6MQ.mjs → chunk-LQFHZGVJ.mjs} +72 -22
- package/dist/{chunk-76UDKZOJ.js → chunk-XOWAQGBO.js} +71 -21
- package/dist/{core-DCERPmy5.d.mts → core-BYxcQ8kf.d.mts} +1 -1
- package/dist/{core-D7uMDEXI.d.ts → core-BiS3xJKx.d.ts} +1 -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 +17 -17
- package/dist/http/elysia/index.mjs +1 -1
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +16 -16
- package/dist/http/express/index.mjs +1 -1
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +16 -16
- package/dist/http/fastify/index.mjs +1 -1
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +17 -17
- package/dist/http/h3/index.mjs +1 -1
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +14 -14
- package/dist/http/hono/index.mjs +1 -1
- 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 +15 -15
- package/dist/http/hyper-express/index.mjs +1 -1
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +16 -16
- package/dist/http/koa/index.mjs +1 -1
- package/dist/index.d.mts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +20 -20
- package/dist/index.mjs +6 -6
- package/dist/{meta-CZDDYaRV.d.mts → meta-Csp1xcSR.d.mts} +1 -1
- package/dist/{meta-CZDDYaRV.d.ts → meta-Csp1xcSR.d.ts} +1 -1
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +6 -6
- package/dist/rpc/bullmq/index.mjs +1 -1
- package/dist/rpc/electron/index.d.mts +3 -3
- package/dist/rpc/electron/index.d.ts +3 -3
- package/dist/rpc/electron/index.js +5 -5
- package/dist/rpc/electron/index.mjs +1 -1
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +6 -6
- package/dist/rpc/kafka/index.mjs +1 -1
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +6 -6
- package/dist/rpc/nats/index.mjs +1 -1
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +6 -6
- package/dist/rpc/rabbitmq/index.mjs +1 -1
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +6 -6
- package/dist/rpc/redis/index.mjs +1 -1
- package/dist/rpc/web-ext/index.d.mts +11 -1
- package/dist/rpc/web-ext/index.d.ts +11 -1
- package/dist/rpc/web-ext/index.js +71 -1
- package/dist/rpc/web-ext/index.mjs +71 -0
- package/dist/rpc/ws/index.d.mts +3 -3
- package/dist/rpc/ws/index.d.ts +3 -3
- package/dist/rpc/ws/index.js +5 -5
- package/dist/rpc/ws/index.mjs +1 -1
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/{types-S1PZEcrK.d.ts → types-Bs64nYvd.d.ts} +1 -1
- package/dist/{types-LPSac5sm.d.mts → types-CjVwVyJT.d.mts} +1 -1
- package/dist/{types-DG5DI_EC.d.ts → types-DExQe0qk.d.ts} +1 -1
- package/dist/{types-BbnTNTe3.d.mts → types-DSlyrmns.d.mts} +1 -1
- 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,
|
|
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
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
249
|
-
|
|
300
|
+
try {
|
|
301
|
+
await validatePhecdaByRules(item, arg, canUseShallowModelConvert, index);
|
|
250
302
|
isCorrect = true;
|
|
251
|
-
|
|
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 (
|
|
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
|
|
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
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
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
|
-
|
|
249
|
-
|
|
300
|
+
try {
|
|
301
|
+
await validatePhecdaByRules(item, arg, canUseShallowModelConvert, index);
|
|
250
302
|
isCorrect = true;
|
|
251
|
-
|
|
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 (
|
|
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.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { M as Meta,
|
|
1
|
+
import { M as Meta, C as ControllerMeta } from './meta-Csp1xcSR.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,
|
|
1
|
+
import { M as Meta, C as ControllerMeta } from './meta-Csp1xcSR.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 _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 =
|
|
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
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Elysia as Elysia$1, Context } from 'elysia';
|
|
2
2
|
import { AnyLocalHook } 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-CjVwVyJT.mjs';
|
|
4
|
+
import { F as Factory } from '../../core-BYxcQ8kf.mjs';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-Csp1xcSR.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 } from 'elysia';
|
|
2
2
|
import { AnyLocalHook } 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-Bs64nYvd.js';
|
|
4
|
+
import { F as Factory } from '../../core-BiS3xJKx.js';
|
|
5
5
|
import 'node:http';
|
|
6
|
-
import '../../meta-
|
|
6
|
+
import '../../meta-Csp1xcSR.js';
|
|
7
7
|
import 'phecda-core';
|
|
8
8
|
|
|
9
9
|
interface ElysiaCtx extends HttpCtx {
|
|
@@ -7,7 +7,7 @@ var _chunk5ZZAOOKEjs = require('../../chunk-5ZZAOOKE.js');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
var
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
38
|
+
_chunkXOWAQGBOjs.Context.applyAddons(globalAddons, app, "elysia");
|
|
39
39
|
if (parallelRoute) {
|
|
40
40
|
const parallelRouter = new (0, _elysia.Elysia)();
|
|
41
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
62
|
+
return resolve(await _chunkXOWAQGBOjs.Context.filterRecord.default(new (0, _chunkXOWAQGBOjs.BadRequestException)(`"${method}" in "${tag}" doesn't exist`)));
|
|
63
63
|
}
|
|
64
|
-
const aop =
|
|
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,
|
|
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 =
|
|
117
|
+
aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
|
|
118
118
|
globalFilter,
|
|
119
119
|
globalGuards,
|
|
120
120
|
globalPipe
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
subApp[http.method](
|
|
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 =
|
|
156
|
+
aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
|
|
157
157
|
globalFilter,
|
|
158
158
|
globalGuards,
|
|
159
159
|
globalPipe
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
-
const context = new (0,
|
|
162
|
+
const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
|
|
163
163
|
if (http.headers) c.set.headers = http.headers;
|
|
164
164
|
if (dynamic) {
|
|
165
|
-
aop =
|
|
165
|
+
aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
|
|
166
166
|
globalFilter,
|
|
167
167
|
globalGuards,
|
|
168
168
|
globalPipe
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RequestHandler, Request, Response, Router } from 'express';
|
|
2
|
-
import { H as HttpCtx, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-CjVwVyJT.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BYxcQ8kf.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-Csp1xcSR.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface ExpressCtx extends HttpCtx {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { RequestHandler, Request, Response, Router } from 'express';
|
|
2
|
-
import { H as HttpCtx, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-Bs64nYvd.js';
|
|
3
|
+
import { F as Factory } from '../../core-BiS3xJKx.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-Csp1xcSR.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface ExpressCtx extends HttpCtx {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
var
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
41
|
+
_chunkXOWAQGBOjs.Context.applyAddons(globalAddons, router, "express");
|
|
42
42
|
if (parallelRoute) {
|
|
43
43
|
const subRouter = _express.Router.call(void 0, );
|
|
44
|
-
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
62
|
-
const aop =
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
117
|
-
subRouter[http.method](
|
|
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,
|
|
145
|
+
const context = new (0, _chunkXOWAQGBOjs.Context)(contextData);
|
|
146
146
|
if (http.headers) res.set(http.headers);
|
|
147
147
|
if (dynamic) {
|
|
148
|
-
aop =
|
|
148
|
+
aop = _chunkXOWAQGBOjs.Context.getAop(meta2, {
|
|
149
149
|
globalFilter,
|
|
150
150
|
globalGuards,
|
|
151
151
|
globalPipe
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FastifyPluginCallback, RouteShorthandOptions, FastifyRequest, FastifyReply, FastifyInstance, FastifyRegisterOptions, FastifyPluginOptions } from 'fastify';
|
|
2
|
-
import { H as HttpCtx, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-CjVwVyJT.mjs';
|
|
3
|
+
import { F as Factory } from '../../core-BYxcQ8kf.mjs';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-Csp1xcSR.mjs';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface FastifyCtx extends HttpCtx {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { FastifyPluginCallback, RouteShorthandOptions, FastifyRequest, FastifyReply, FastifyInstance, FastifyRegisterOptions, FastifyPluginOptions } from 'fastify';
|
|
2
|
-
import { H as HttpCtx, a as HttpOptions } from '../../types-
|
|
3
|
-
import { F as Factory } from '../../core-
|
|
2
|
+
import { H as HttpCtx, a as HttpOptions } from '../../types-Bs64nYvd.js';
|
|
3
|
+
import { F as Factory } from '../../core-BiS3xJKx.js';
|
|
4
4
|
import 'node:http';
|
|
5
|
-
import '../../meta-
|
|
5
|
+
import '../../meta-Csp1xcSR.js';
|
|
6
6
|
import 'phecda-core';
|
|
7
7
|
|
|
8
8
|
interface FastifyCtx extends HttpCtx {
|