elysia 1.4.29 → 1.4.30
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/AGENTS.md +75 -0
- package/AI_POLICY.md +19 -0
- package/CLAUDE.md +75 -0
- package/SECURITY.md +27 -0
- package/dist/adapter/bun/handler-native.js +22 -7
- package/dist/adapter/bun/handler-native.mjs +22 -7
- package/dist/adapter/bun/index.js +3 -0
- package/dist/adapter/bun/index.mjs +3 -0
- package/dist/compose.js +14 -14
- package/dist/compose.mjs +14 -14
- package/dist/dynamic-handle.js +90 -22
- package/dist/dynamic-handle.mjs +90 -22
- package/dist/error.d.ts +4 -0
- package/dist/error.js +19 -13
- package/dist/error.mjs +18 -13
- package/dist/index.js +3 -28
- package/dist/index.mjs +3 -30
- package/dist/schema.d.ts +6 -3
- package/dist/schema.js +14 -7
- package/dist/schema.mjs +14 -7
- package/dist/ws/index.js +16 -25
- package/dist/ws/index.mjs +16 -25
- package/package.json +1 -1
package/dist/dynamic-handle.js
CHANGED
|
@@ -87,7 +87,20 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
87
87
|
if (properties)
|
|
88
88
|
for (const [key, keySchema] of Object.entries(properties))
|
|
89
89
|
obj[key] ??= keySchema.default;
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
|
+
async function validateStandardSchema(type, validator, value) {
|
|
92
|
+
const result = await validator.Validate(value);
|
|
93
|
+
if (result.issues)
|
|
94
|
+
throw new import_error.ValidationError(
|
|
95
|
+
type,
|
|
96
|
+
validator,
|
|
97
|
+
value,
|
|
98
|
+
!1,
|
|
99
|
+
result.issues
|
|
100
|
+
);
|
|
101
|
+
return result.value;
|
|
102
|
+
}
|
|
103
|
+
const createDynamicHandler = (app) => {
|
|
91
104
|
const { mapResponse, mapEarlyResponse } = app["~adapter"].handler, defaultHeader = app.setHeaders;
|
|
92
105
|
return async (request) => {
|
|
93
106
|
const url = request.url, s = url.indexOf("/", 11), qi = url.indexOf("?", s + 1), path = qi === -1 ? url.substring(s) : url.substring(s, qi), set = {
|
|
@@ -304,20 +317,35 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
304
317
|
const _header = structuredClone(context.headers);
|
|
305
318
|
for (const [key, value] of request.headers)
|
|
306
319
|
_header[key] = value;
|
|
307
|
-
if (
|
|
320
|
+
if (headerValidator.provider === "standard")
|
|
321
|
+
context.headers = await validateStandardSchema(
|
|
322
|
+
"header",
|
|
323
|
+
headerValidator,
|
|
324
|
+
_header
|
|
325
|
+
);
|
|
326
|
+
else if (validator.headers.Check(_header) === !1)
|
|
308
327
|
throw new import_error.ValidationError(
|
|
309
328
|
"header",
|
|
310
329
|
validator.headers,
|
|
311
330
|
_header
|
|
312
331
|
);
|
|
313
332
|
} else validator.headers?.Decode && (context.headers = validator.headers.Decode(context.headers));
|
|
314
|
-
if (paramsValidator?.
|
|
315
|
-
|
|
333
|
+
if (paramsValidator?.provider === "standard")
|
|
334
|
+
context.params = await validateStandardSchema(
|
|
316
335
|
"params",
|
|
317
|
-
|
|
336
|
+
paramsValidator,
|
|
318
337
|
context.params
|
|
319
338
|
);
|
|
320
|
-
|
|
339
|
+
else {
|
|
340
|
+
if (paramsValidator?.Check(context.params) === !1)
|
|
341
|
+
throw new import_error.ValidationError(
|
|
342
|
+
"params",
|
|
343
|
+
validator.params,
|
|
344
|
+
context.params
|
|
345
|
+
);
|
|
346
|
+
validator.params?.Decode && (context.params = validator.params.Decode(context.params));
|
|
347
|
+
}
|
|
348
|
+
if (validator.query?.schema) {
|
|
321
349
|
let schema = validator.query.schema;
|
|
322
350
|
schema.$defs?.[schema.$ref] && (schema = schema.$defs[schema.$ref]);
|
|
323
351
|
const properties = (0, import_schema.getSchemaProperties)(schema);
|
|
@@ -327,31 +355,59 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
327
355
|
(value.type === "array" || value.items?.type === "string") && typeof context.query[property] == "string" && context.query[property] && (context.query[property] = context.query[property].split(","));
|
|
328
356
|
}
|
|
329
357
|
}
|
|
330
|
-
if (queryValidator?.
|
|
331
|
-
|
|
358
|
+
if (queryValidator?.provider === "standard")
|
|
359
|
+
context.query = await validateStandardSchema(
|
|
332
360
|
"query",
|
|
333
|
-
|
|
361
|
+
queryValidator,
|
|
334
362
|
context.query
|
|
335
363
|
);
|
|
336
|
-
|
|
364
|
+
else {
|
|
365
|
+
if (queryValidator?.Check(context.query) === !1)
|
|
366
|
+
throw new import_error.ValidationError(
|
|
367
|
+
"query",
|
|
368
|
+
validator.query,
|
|
369
|
+
context.query
|
|
370
|
+
);
|
|
371
|
+
validator.query?.Decode && (context.query = validator.query.Decode(context.query));
|
|
372
|
+
}
|
|
373
|
+
if (validator.createCookie?.()) {
|
|
337
374
|
let cookieValue = {};
|
|
338
375
|
for (const [key, value] of Object.entries(context.cookie))
|
|
339
376
|
cookieValue[key] = value.value;
|
|
340
|
-
if (validator.cookie.
|
|
341
|
-
|
|
377
|
+
if (validator.cookie.provider === "standard") {
|
|
378
|
+
cookieValue = await validateStandardSchema(
|
|
342
379
|
"cookie",
|
|
343
380
|
validator.cookie,
|
|
344
381
|
cookieValue
|
|
345
382
|
);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
383
|
+
for (const key of Object.keys(cookieValue))
|
|
384
|
+
context.cookie[key].value = cookieValue[key];
|
|
385
|
+
} else {
|
|
386
|
+
if (validator.cookie.Check(cookieValue) === !1)
|
|
387
|
+
throw new import_error.ValidationError(
|
|
388
|
+
"cookie",
|
|
389
|
+
validator.cookie,
|
|
390
|
+
cookieValue
|
|
391
|
+
);
|
|
392
|
+
validator.cookie?.Decode && (cookieValue = validator.cookie.Decode(
|
|
393
|
+
cookieValue
|
|
394
|
+
));
|
|
395
|
+
}
|
|
349
396
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
397
|
+
const bodyValidator = validator.createBody?.();
|
|
398
|
+
if (bodyValidator?.provider === "standard")
|
|
399
|
+
context.body = await validateStandardSchema(
|
|
400
|
+
"body",
|
|
401
|
+
bodyValidator,
|
|
402
|
+
body
|
|
403
|
+
);
|
|
404
|
+
else {
|
|
405
|
+
if (bodyValidator?.Check(body) === !1)
|
|
406
|
+
throw new import_error.ValidationError("body", validator.body, body);
|
|
407
|
+
if (validator.body?.Decode) {
|
|
408
|
+
let decoded = validator.body.Decode(body);
|
|
409
|
+
decoded instanceof Promise && (decoded = await decoded), context.body = decoded?.value ?? decoded;
|
|
410
|
+
}
|
|
355
411
|
}
|
|
356
412
|
}
|
|
357
413
|
if (hooks.beforeHandle)
|
|
@@ -390,7 +446,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
390
446
|
const isCustomStatuResponse = response2 instanceof import_error.ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response2.code : set.status ? typeof set.status == "string" ? import_utils.StatusMap[set.status] : set.status : 200;
|
|
391
447
|
isCustomStatuResponse && (set.status = status2, response2 = response2.response);
|
|
392
448
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
393
|
-
if (responseValidator?.
|
|
449
|
+
if (responseValidator?.provider === "standard")
|
|
450
|
+
response2 = await validateStandardSchema(
|
|
451
|
+
"response",
|
|
452
|
+
responseValidator,
|
|
453
|
+
response2
|
|
454
|
+
);
|
|
455
|
+
else if (responseValidator?.Check(response2) === !1)
|
|
394
456
|
if (responseValidator?.Clean)
|
|
395
457
|
try {
|
|
396
458
|
const temp = responseValidator.Clean(response2);
|
|
@@ -426,7 +488,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
426
488
|
const isCustomStatuResponse = response instanceof import_error.ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response.code : set.status ? typeof set.status == "string" ? import_utils.StatusMap[set.status] : set.status : 200;
|
|
427
489
|
isCustomStatuResponse && (set.status = status2, response = response.response);
|
|
428
490
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
429
|
-
if (responseValidator?.
|
|
491
|
+
if (responseValidator?.provider === "standard")
|
|
492
|
+
response = await validateStandardSchema(
|
|
493
|
+
"response",
|
|
494
|
+
responseValidator,
|
|
495
|
+
response
|
|
496
|
+
);
|
|
497
|
+
else if (responseValidator?.Check(response) === !1)
|
|
430
498
|
if (responseValidator?.Clean)
|
|
431
499
|
try {
|
|
432
500
|
const temp = responseValidator.Clean(response);
|
package/dist/dynamic-handle.mjs
CHANGED
|
@@ -76,7 +76,20 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
76
76
|
if (properties)
|
|
77
77
|
for (const [key, keySchema] of Object.entries(properties))
|
|
78
78
|
obj[key] ??= keySchema.default;
|
|
79
|
-
}
|
|
79
|
+
};
|
|
80
|
+
async function validateStandardSchema(type, validator, value) {
|
|
81
|
+
const result = await validator.Validate(value);
|
|
82
|
+
if (result.issues)
|
|
83
|
+
throw new ValidationError(
|
|
84
|
+
type,
|
|
85
|
+
validator,
|
|
86
|
+
value,
|
|
87
|
+
!1,
|
|
88
|
+
result.issues
|
|
89
|
+
);
|
|
90
|
+
return result.value;
|
|
91
|
+
}
|
|
92
|
+
const createDynamicHandler = (app) => {
|
|
80
93
|
const { mapResponse, mapEarlyResponse } = app["~adapter"].handler, defaultHeader = app.setHeaders;
|
|
81
94
|
return async (request) => {
|
|
82
95
|
const url = request.url, s = url.indexOf("/", 11), qi = url.indexOf("?", s + 1), path = qi === -1 ? url.substring(s) : url.substring(s, qi), set = {
|
|
@@ -293,20 +306,35 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
293
306
|
const _header = structuredClone(context.headers);
|
|
294
307
|
for (const [key, value] of request.headers)
|
|
295
308
|
_header[key] = value;
|
|
296
|
-
if (
|
|
309
|
+
if (headerValidator.provider === "standard")
|
|
310
|
+
context.headers = await validateStandardSchema(
|
|
311
|
+
"header",
|
|
312
|
+
headerValidator,
|
|
313
|
+
_header
|
|
314
|
+
);
|
|
315
|
+
else if (validator.headers.Check(_header) === !1)
|
|
297
316
|
throw new ValidationError(
|
|
298
317
|
"header",
|
|
299
318
|
validator.headers,
|
|
300
319
|
_header
|
|
301
320
|
);
|
|
302
321
|
} else validator.headers?.Decode && (context.headers = validator.headers.Decode(context.headers));
|
|
303
|
-
if (paramsValidator?.
|
|
304
|
-
|
|
322
|
+
if (paramsValidator?.provider === "standard")
|
|
323
|
+
context.params = await validateStandardSchema(
|
|
305
324
|
"params",
|
|
306
|
-
|
|
325
|
+
paramsValidator,
|
|
307
326
|
context.params
|
|
308
327
|
);
|
|
309
|
-
|
|
328
|
+
else {
|
|
329
|
+
if (paramsValidator?.Check(context.params) === !1)
|
|
330
|
+
throw new ValidationError(
|
|
331
|
+
"params",
|
|
332
|
+
validator.params,
|
|
333
|
+
context.params
|
|
334
|
+
);
|
|
335
|
+
validator.params?.Decode && (context.params = validator.params.Decode(context.params));
|
|
336
|
+
}
|
|
337
|
+
if (validator.query?.schema) {
|
|
310
338
|
let schema = validator.query.schema;
|
|
311
339
|
schema.$defs?.[schema.$ref] && (schema = schema.$defs[schema.$ref]);
|
|
312
340
|
const properties = getSchemaProperties(schema);
|
|
@@ -316,31 +344,59 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
316
344
|
(value.type === "array" || value.items?.type === "string") && typeof context.query[property] == "string" && context.query[property] && (context.query[property] = context.query[property].split(","));
|
|
317
345
|
}
|
|
318
346
|
}
|
|
319
|
-
if (queryValidator?.
|
|
320
|
-
|
|
347
|
+
if (queryValidator?.provider === "standard")
|
|
348
|
+
context.query = await validateStandardSchema(
|
|
321
349
|
"query",
|
|
322
|
-
|
|
350
|
+
queryValidator,
|
|
323
351
|
context.query
|
|
324
352
|
);
|
|
325
|
-
|
|
353
|
+
else {
|
|
354
|
+
if (queryValidator?.Check(context.query) === !1)
|
|
355
|
+
throw new ValidationError(
|
|
356
|
+
"query",
|
|
357
|
+
validator.query,
|
|
358
|
+
context.query
|
|
359
|
+
);
|
|
360
|
+
validator.query?.Decode && (context.query = validator.query.Decode(context.query));
|
|
361
|
+
}
|
|
362
|
+
if (validator.createCookie?.()) {
|
|
326
363
|
let cookieValue = {};
|
|
327
364
|
for (const [key, value] of Object.entries(context.cookie))
|
|
328
365
|
cookieValue[key] = value.value;
|
|
329
|
-
if (validator.cookie.
|
|
330
|
-
|
|
366
|
+
if (validator.cookie.provider === "standard") {
|
|
367
|
+
cookieValue = await validateStandardSchema(
|
|
331
368
|
"cookie",
|
|
332
369
|
validator.cookie,
|
|
333
370
|
cookieValue
|
|
334
371
|
);
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
372
|
+
for (const key of Object.keys(cookieValue))
|
|
373
|
+
context.cookie[key].value = cookieValue[key];
|
|
374
|
+
} else {
|
|
375
|
+
if (validator.cookie.Check(cookieValue) === !1)
|
|
376
|
+
throw new ValidationError(
|
|
377
|
+
"cookie",
|
|
378
|
+
validator.cookie,
|
|
379
|
+
cookieValue
|
|
380
|
+
);
|
|
381
|
+
validator.cookie?.Decode && (cookieValue = validator.cookie.Decode(
|
|
382
|
+
cookieValue
|
|
383
|
+
));
|
|
384
|
+
}
|
|
338
385
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
386
|
+
const bodyValidator = validator.createBody?.();
|
|
387
|
+
if (bodyValidator?.provider === "standard")
|
|
388
|
+
context.body = await validateStandardSchema(
|
|
389
|
+
"body",
|
|
390
|
+
bodyValidator,
|
|
391
|
+
body
|
|
392
|
+
);
|
|
393
|
+
else {
|
|
394
|
+
if (bodyValidator?.Check(body) === !1)
|
|
395
|
+
throw new ValidationError("body", validator.body, body);
|
|
396
|
+
if (validator.body?.Decode) {
|
|
397
|
+
let decoded = validator.body.Decode(body);
|
|
398
|
+
decoded instanceof Promise && (decoded = await decoded), context.body = decoded?.value ?? decoded;
|
|
399
|
+
}
|
|
344
400
|
}
|
|
345
401
|
}
|
|
346
402
|
if (hooks.beforeHandle)
|
|
@@ -379,7 +435,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
379
435
|
const isCustomStatuResponse = response2 instanceof ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response2.code : set.status ? typeof set.status == "string" ? StatusMap[set.status] : set.status : 200;
|
|
380
436
|
isCustomStatuResponse && (set.status = status2, response2 = response2.response);
|
|
381
437
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
382
|
-
if (responseValidator?.
|
|
438
|
+
if (responseValidator?.provider === "standard")
|
|
439
|
+
response2 = await validateStandardSchema(
|
|
440
|
+
"response",
|
|
441
|
+
responseValidator,
|
|
442
|
+
response2
|
|
443
|
+
);
|
|
444
|
+
else if (responseValidator?.Check(response2) === !1)
|
|
383
445
|
if (responseValidator?.Clean)
|
|
384
446
|
try {
|
|
385
447
|
const temp = responseValidator.Clean(response2);
|
|
@@ -415,7 +477,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
415
477
|
const isCustomStatuResponse = response instanceof ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response.code : set.status ? typeof set.status == "string" ? StatusMap[set.status] : set.status : 200;
|
|
416
478
|
isCustomStatuResponse && (set.status = status2, response = response.response);
|
|
417
479
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
418
|
-
if (responseValidator?.
|
|
480
|
+
if (responseValidator?.provider === "standard")
|
|
481
|
+
response = await validateStandardSchema(
|
|
482
|
+
"response",
|
|
483
|
+
responseValidator,
|
|
484
|
+
response
|
|
485
|
+
);
|
|
486
|
+
else if (responseValidator?.Check(response) === !1)
|
|
419
487
|
if (responseValidator?.Clean)
|
|
420
488
|
try {
|
|
421
489
|
const temp = responseValidator.Clean(response);
|
package/dist/error.d.ts
CHANGED
|
@@ -107,6 +107,10 @@ interface ValueErrorWithSummary extends ValueError {
|
|
|
107
107
|
summary?: string;
|
|
108
108
|
}
|
|
109
109
|
export declare const mapValueError: (error: ValueError | undefined) => ValueErrorWithSummary | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* Maximum amount of validation error
|
|
112
|
+
*/
|
|
113
|
+
export declare const MAX_ERRORS = 64;
|
|
110
114
|
export declare class InvalidFileType extends Error {
|
|
111
115
|
property: string;
|
|
112
116
|
expected: string | string[];
|
package/dist/error.js
CHANGED
|
@@ -21,6 +21,7 @@ __export(error_exports, {
|
|
|
21
21
|
InternalServerError: () => InternalServerError,
|
|
22
22
|
InvalidCookieSignature: () => InvalidCookieSignature,
|
|
23
23
|
InvalidFileType: () => InvalidFileType,
|
|
24
|
+
MAX_ERRORS: () => MAX_ERRORS,
|
|
24
25
|
NotFoundError: () => NotFoundError,
|
|
25
26
|
ParseError: () => ParseError,
|
|
26
27
|
ValidationError: () => ValidationError,
|
|
@@ -118,6 +119,14 @@ const mapValueError = (error) => {
|
|
|
118
119
|
default:
|
|
119
120
|
return { summary: message, ...error };
|
|
120
121
|
}
|
|
122
|
+
}, MAX_ERRORS = 64, takeErrors = (iterator, limit = MAX_ERRORS) => {
|
|
123
|
+
const errors = [];
|
|
124
|
+
for (const error of iterator) {
|
|
125
|
+
if (!error) continue;
|
|
126
|
+
const mapped = mapValueError(error);
|
|
127
|
+
if (mapped && errors.push(mapped), errors.length >= limit) break;
|
|
128
|
+
}
|
|
129
|
+
return errors;
|
|
121
130
|
};
|
|
122
131
|
class InvalidFileType extends Error {
|
|
123
132
|
constructor(property, expected, message = `"${property}" has invalid file type`) {
|
|
@@ -219,16 +228,16 @@ class ValidationError extends Error {
|
|
|
219
228
|
summary: mapValueError(error)?.summary,
|
|
220
229
|
found: value,
|
|
221
230
|
expected,
|
|
222
|
-
errors: "Errors" in validator ?
|
|
223
|
-
|
|
231
|
+
errors: "Errors" in validator ? takeErrors(
|
|
232
|
+
validator.Errors(
|
|
224
233
|
value
|
|
225
234
|
)
|
|
226
|
-
|
|
227
|
-
|
|
235
|
+
) : takeErrors(
|
|
236
|
+
import_value.Value.Errors(
|
|
228
237
|
validator,
|
|
229
238
|
value
|
|
230
239
|
)
|
|
231
|
-
|
|
240
|
+
)
|
|
232
241
|
},
|
|
233
242
|
validator
|
|
234
243
|
) : error.schema.error : void 0, customError !== void 0 ? message = typeof customError == "object" ? JSON.stringify(customError) : customError + "" : isProduction && !allowUnsafeValidationDetails ? message = JSON.stringify({
|
|
@@ -244,11 +253,7 @@ class ValidationError extends Error {
|
|
|
244
253
|
summary: mapValueError(error)?.summary,
|
|
245
254
|
expected,
|
|
246
255
|
found: value,
|
|
247
|
-
errors: "Errors" in validator ?
|
|
248
|
-
mapValueError
|
|
249
|
-
) : [...import_value.Value.Errors(validator, value)].map(
|
|
250
|
-
mapValueError
|
|
251
|
-
)
|
|
256
|
+
errors: "Errors" in validator ? takeErrors(validator.Errors(value)) : takeErrors(import_value.Value.Errors(validator, value))
|
|
252
257
|
},
|
|
253
258
|
null,
|
|
254
259
|
2
|
|
@@ -278,14 +283,14 @@ class ValidationError extends Error {
|
|
|
278
283
|
"~standard" in this.validator.schema ? /* @ts-ignore */ ("~standard" in this.validator ? this.validator : (
|
|
279
284
|
// @ts-ignore
|
|
280
285
|
this.validator.schema
|
|
281
|
-
))["~standard"].validate(this.value).issues?.map((issue) => ({
|
|
286
|
+
))["~standard"].validate(this.value).issues?.slice(0, MAX_ERRORS).map((issue) => ({
|
|
282
287
|
summary: issue.message,
|
|
283
288
|
path: issue.path?.join(".") || "root",
|
|
284
289
|
message: issue.message,
|
|
285
290
|
value: this.value
|
|
286
|
-
})) || [] : "Errors" in this.validator ?
|
|
291
|
+
})) || [] : "Errors" in this.validator ? takeErrors(this.validator.Errors(this.value)) : (
|
|
287
292
|
// @ts-ignore
|
|
288
|
-
|
|
293
|
+
takeErrors(import_value.Value.Errors(this.validator, this.value))
|
|
289
294
|
)
|
|
290
295
|
);
|
|
291
296
|
}
|
|
@@ -357,6 +362,7 @@ class ValidationError extends Error {
|
|
|
357
362
|
InternalServerError,
|
|
358
363
|
InvalidCookieSignature,
|
|
359
364
|
InvalidFileType,
|
|
365
|
+
MAX_ERRORS,
|
|
360
366
|
NotFoundError,
|
|
361
367
|
ParseError,
|
|
362
368
|
ValidationError,
|
package/dist/error.mjs
CHANGED
|
@@ -88,6 +88,14 @@ const mapValueError = (error) => {
|
|
|
88
88
|
default:
|
|
89
89
|
return { summary: message, ...error };
|
|
90
90
|
}
|
|
91
|
+
}, MAX_ERRORS = 64, takeErrors = (iterator, limit = MAX_ERRORS) => {
|
|
92
|
+
const errors = [];
|
|
93
|
+
for (const error of iterator) {
|
|
94
|
+
if (!error) continue;
|
|
95
|
+
const mapped = mapValueError(error);
|
|
96
|
+
if (mapped && errors.push(mapped), errors.length >= limit) break;
|
|
97
|
+
}
|
|
98
|
+
return errors;
|
|
91
99
|
};
|
|
92
100
|
class InvalidFileType extends Error {
|
|
93
101
|
constructor(property, expected, message = `"${property}" has invalid file type`) {
|
|
@@ -189,16 +197,16 @@ class ValidationError extends Error {
|
|
|
189
197
|
summary: mapValueError(error)?.summary,
|
|
190
198
|
found: value,
|
|
191
199
|
expected,
|
|
192
|
-
errors: "Errors" in validator ?
|
|
193
|
-
|
|
200
|
+
errors: "Errors" in validator ? takeErrors(
|
|
201
|
+
validator.Errors(
|
|
194
202
|
value
|
|
195
203
|
)
|
|
196
|
-
|
|
197
|
-
|
|
204
|
+
) : takeErrors(
|
|
205
|
+
Value.Errors(
|
|
198
206
|
validator,
|
|
199
207
|
value
|
|
200
208
|
)
|
|
201
|
-
|
|
209
|
+
)
|
|
202
210
|
},
|
|
203
211
|
validator
|
|
204
212
|
) : error.schema.error : void 0, customError !== void 0 ? message = typeof customError == "object" ? JSON.stringify(customError) : customError + "" : isProduction && !allowUnsafeValidationDetails ? message = JSON.stringify({
|
|
@@ -214,11 +222,7 @@ class ValidationError extends Error {
|
|
|
214
222
|
summary: mapValueError(error)?.summary,
|
|
215
223
|
expected,
|
|
216
224
|
found: value,
|
|
217
|
-
errors: "Errors" in validator ?
|
|
218
|
-
mapValueError
|
|
219
|
-
) : [...Value.Errors(validator, value)].map(
|
|
220
|
-
mapValueError
|
|
221
|
-
)
|
|
225
|
+
errors: "Errors" in validator ? takeErrors(validator.Errors(value)) : takeErrors(Value.Errors(validator, value))
|
|
222
226
|
},
|
|
223
227
|
null,
|
|
224
228
|
2
|
|
@@ -248,14 +252,14 @@ class ValidationError extends Error {
|
|
|
248
252
|
"~standard" in this.validator.schema ? /* @ts-ignore */ ("~standard" in this.validator ? this.validator : (
|
|
249
253
|
// @ts-ignore
|
|
250
254
|
this.validator.schema
|
|
251
|
-
))["~standard"].validate(this.value).issues?.map((issue) => ({
|
|
255
|
+
))["~standard"].validate(this.value).issues?.slice(0, MAX_ERRORS).map((issue) => ({
|
|
252
256
|
summary: issue.message,
|
|
253
257
|
path: issue.path?.join(".") || "root",
|
|
254
258
|
message: issue.message,
|
|
255
259
|
value: this.value
|
|
256
|
-
})) || [] : "Errors" in this.validator ?
|
|
260
|
+
})) || [] : "Errors" in this.validator ? takeErrors(this.validator.Errors(this.value)) : (
|
|
257
261
|
// @ts-ignore
|
|
258
|
-
|
|
262
|
+
takeErrors(Value.Errors(this.validator, this.value))
|
|
259
263
|
)
|
|
260
264
|
);
|
|
261
265
|
}
|
|
@@ -326,6 +330,7 @@ export {
|
|
|
326
330
|
InternalServerError,
|
|
327
331
|
InvalidCookieSignature,
|
|
328
332
|
InvalidFileType,
|
|
333
|
+
MAX_ERRORS,
|
|
329
334
|
NotFoundError,
|
|
330
335
|
ParseError,
|
|
331
336
|
ValidationError,
|
package/dist/index.js
CHANGED
|
@@ -548,37 +548,12 @@ const _Elysia = class _Elysia {
|
|
|
548
548
|
return;
|
|
549
549
|
}
|
|
550
550
|
const adapter = this["~adapter"].handler, nativeStaticHandler = typeof handle != "function" ? () => {
|
|
551
|
-
const context = {
|
|
552
|
-
redirect: import_utils.redirect,
|
|
553
|
-
request: this["~adapter"].isWebStandard ? new Request(`http://ely.sia${path}`, {
|
|
554
|
-
method
|
|
555
|
-
}) : void 0,
|
|
556
|
-
server: null,
|
|
557
|
-
set: {
|
|
558
|
-
headers: Object.assign({}, this.setHeaders)
|
|
559
|
-
},
|
|
560
|
-
status: import_error.status,
|
|
561
|
-
store: this.store
|
|
562
|
-
};
|
|
563
|
-
try {
|
|
564
|
-
this.event.request?.map((x) => {
|
|
565
|
-
if (typeof x.fn == "function")
|
|
566
|
-
return x.fn(context);
|
|
567
|
-
if (typeof x == "function") return x(context);
|
|
568
|
-
});
|
|
569
|
-
} catch (error) {
|
|
570
|
-
let res;
|
|
571
|
-
context.error = error, this.event.error?.some((x) => {
|
|
572
|
-
if (typeof x.fn == "function")
|
|
573
|
-
return res = x.fn(context);
|
|
574
|
-
if (typeof x == "function")
|
|
575
|
-
return res = x(context);
|
|
576
|
-
}), res !== void 0 && (handle = res);
|
|
577
|
-
}
|
|
578
551
|
const fn = adapter.createNativeStaticHandler?.(
|
|
579
552
|
handle,
|
|
580
553
|
hooks,
|
|
581
|
-
|
|
554
|
+
{
|
|
555
|
+
headers: Object.assign({}, this.setHeaders)
|
|
556
|
+
}
|
|
582
557
|
);
|
|
583
558
|
return fn instanceof Promise ? fn.then((fn2) => {
|
|
584
559
|
if (fn2) return fn2;
|
package/dist/index.mjs
CHANGED
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
encodePath,
|
|
24
24
|
lifeCycleToArray,
|
|
25
25
|
supportPerMethodInlineHandler,
|
|
26
|
-
redirect,
|
|
27
26
|
emptySchema,
|
|
28
27
|
insertStandaloneValidator
|
|
29
28
|
} from "./utils.mjs";
|
|
@@ -53,7 +52,6 @@ import {
|
|
|
53
52
|
createDynamicHandler
|
|
54
53
|
} from "./dynamic-handle.mjs";
|
|
55
54
|
import {
|
|
56
|
-
status,
|
|
57
55
|
ERROR_CODE,
|
|
58
56
|
ValidationError
|
|
59
57
|
} from "./error.mjs";
|
|
@@ -546,37 +544,12 @@ const _Elysia = class _Elysia {
|
|
|
546
544
|
return;
|
|
547
545
|
}
|
|
548
546
|
const adapter = this["~adapter"].handler, nativeStaticHandler = typeof handle != "function" ? () => {
|
|
549
|
-
const context = {
|
|
550
|
-
redirect,
|
|
551
|
-
request: this["~adapter"].isWebStandard ? new Request(`http://ely.sia${path}`, {
|
|
552
|
-
method
|
|
553
|
-
}) : void 0,
|
|
554
|
-
server: null,
|
|
555
|
-
set: {
|
|
556
|
-
headers: Object.assign({}, this.setHeaders)
|
|
557
|
-
},
|
|
558
|
-
status,
|
|
559
|
-
store: this.store
|
|
560
|
-
};
|
|
561
|
-
try {
|
|
562
|
-
this.event.request?.map((x) => {
|
|
563
|
-
if (typeof x.fn == "function")
|
|
564
|
-
return x.fn(context);
|
|
565
|
-
if (typeof x == "function") return x(context);
|
|
566
|
-
});
|
|
567
|
-
} catch (error) {
|
|
568
|
-
let res;
|
|
569
|
-
context.error = error, this.event.error?.some((x) => {
|
|
570
|
-
if (typeof x.fn == "function")
|
|
571
|
-
return res = x.fn(context);
|
|
572
|
-
if (typeof x == "function")
|
|
573
|
-
return res = x(context);
|
|
574
|
-
}), res !== void 0 && (handle = res);
|
|
575
|
-
}
|
|
576
547
|
const fn = adapter.createNativeStaticHandler?.(
|
|
577
548
|
handle,
|
|
578
549
|
hooks,
|
|
579
|
-
|
|
550
|
+
{
|
|
551
|
+
headers: Object.assign({}, this.setHeaders)
|
|
552
|
+
}
|
|
580
553
|
);
|
|
581
554
|
return fn instanceof Promise ? fn.then((fn2) => {
|
|
582
555
|
if (fn2) return fn2;
|
package/dist/schema.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type Instruction as ExactMirrorInstruction } from 'exact-mirror';
|
|
|
3
3
|
import { type TypeCheck } from './type-system';
|
|
4
4
|
import { mapValueError } from './error';
|
|
5
5
|
import type { CookieOptions } from './cookies';
|
|
6
|
-
import type { AnySchema, ElysiaConfig, InputSchema, IsAny, MaybeArray, StandaloneInputSchema, UnwrapSchema } from './types';
|
|
6
|
+
import type { AnySchema, ElysiaConfig, InputSchema, IsAny, MaybeArray, MaybePromise, StandaloneInputSchema, UnwrapSchema } from './types';
|
|
7
7
|
import type { StandardSchemaV1Like } from './types';
|
|
8
8
|
import { type ReplaceSchemaTypeOptions } from './replace-schema';
|
|
9
9
|
type MapValueError = ReturnType<typeof mapValueError>;
|
|
@@ -11,11 +11,14 @@ export interface ElysiaTypeCheck<T extends AnySchema> extends Omit<TypeCheck<TSc
|
|
|
11
11
|
provider: 'typebox' | 'standard';
|
|
12
12
|
schema: T;
|
|
13
13
|
config: Object;
|
|
14
|
-
Check(value: unknown):
|
|
14
|
+
Check(value: unknown): boolean;
|
|
15
|
+
Validate?(value: unknown): MaybePromise<{
|
|
15
16
|
value: UnwrapSchema<T>;
|
|
17
|
+
issues?: never;
|
|
16
18
|
} | {
|
|
19
|
+
value?: never;
|
|
17
20
|
issues: unknown[];
|
|
18
|
-
}
|
|
21
|
+
}>;
|
|
19
22
|
Clean?(v: unknown): UnwrapSchema<T>;
|
|
20
23
|
parse(v: unknown): UnwrapSchema<T>;
|
|
21
24
|
safeParse(v: unknown): {
|