elysia 1.4.28 → 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/adapter/web-standard/index.js +3 -2
- package/dist/adapter/web-standard/index.mjs +3 -2
- package/dist/compose.js +14 -14
- package/dist/compose.mjs +14 -14
- package/dist/dynamic-handle.js +111 -31
- package/dist/dynamic-handle.mjs +111 -31
- 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 = {
|
|
@@ -142,10 +155,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
142
155
|
break;
|
|
143
156
|
case "multipart/form-data": {
|
|
144
157
|
body = {};
|
|
145
|
-
const form = await request.formData();
|
|
146
|
-
|
|
158
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
159
|
+
form.forEach((v, k) => {
|
|
160
|
+
const list = grouped.get(k);
|
|
161
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
162
|
+
});
|
|
163
|
+
for (const [key, value] of grouped) {
|
|
147
164
|
if (body[key]) continue;
|
|
148
|
-
const
|
|
165
|
+
const finalValue = normalizeFormValue(value);
|
|
149
166
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
150
167
|
}
|
|
151
168
|
break;
|
|
@@ -181,10 +198,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
181
198
|
case "formdata":
|
|
182
199
|
case "multipart/form-data": {
|
|
183
200
|
body = {};
|
|
184
|
-
const form = await request.formData();
|
|
185
|
-
|
|
201
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
202
|
+
form.forEach((v, k) => {
|
|
203
|
+
const list = grouped.get(k);
|
|
204
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
205
|
+
});
|
|
206
|
+
for (const [key, value] of grouped) {
|
|
186
207
|
if (body[key]) continue;
|
|
187
|
-
const
|
|
208
|
+
const finalValue = normalizeFormValue(value);
|
|
188
209
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
189
210
|
}
|
|
190
211
|
break;
|
|
@@ -228,10 +249,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
228
249
|
break;
|
|
229
250
|
case "multipart/form-data": {
|
|
230
251
|
body = {};
|
|
231
|
-
const form = await request.formData();
|
|
232
|
-
|
|
252
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
253
|
+
form.forEach((v, k) => {
|
|
254
|
+
const list = grouped.get(k);
|
|
255
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
256
|
+
});
|
|
257
|
+
for (const [key, value] of grouped) {
|
|
233
258
|
if (body[key]) continue;
|
|
234
|
-
const
|
|
259
|
+
const finalValue = normalizeFormValue(value);
|
|
235
260
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
236
261
|
}
|
|
237
262
|
break;
|
|
@@ -292,20 +317,35 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
292
317
|
const _header = structuredClone(context.headers);
|
|
293
318
|
for (const [key, value] of request.headers)
|
|
294
319
|
_header[key] = value;
|
|
295
|
-
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)
|
|
296
327
|
throw new import_error.ValidationError(
|
|
297
328
|
"header",
|
|
298
329
|
validator.headers,
|
|
299
330
|
_header
|
|
300
331
|
);
|
|
301
332
|
} else validator.headers?.Decode && (context.headers = validator.headers.Decode(context.headers));
|
|
302
|
-
if (paramsValidator?.
|
|
303
|
-
|
|
333
|
+
if (paramsValidator?.provider === "standard")
|
|
334
|
+
context.params = await validateStandardSchema(
|
|
304
335
|
"params",
|
|
305
|
-
|
|
336
|
+
paramsValidator,
|
|
306
337
|
context.params
|
|
307
338
|
);
|
|
308
|
-
|
|
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) {
|
|
309
349
|
let schema = validator.query.schema;
|
|
310
350
|
schema.$defs?.[schema.$ref] && (schema = schema.$defs[schema.$ref]);
|
|
311
351
|
const properties = (0, import_schema.getSchemaProperties)(schema);
|
|
@@ -315,31 +355,59 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
315
355
|
(value.type === "array" || value.items?.type === "string") && typeof context.query[property] == "string" && context.query[property] && (context.query[property] = context.query[property].split(","));
|
|
316
356
|
}
|
|
317
357
|
}
|
|
318
|
-
if (queryValidator?.
|
|
319
|
-
|
|
358
|
+
if (queryValidator?.provider === "standard")
|
|
359
|
+
context.query = await validateStandardSchema(
|
|
320
360
|
"query",
|
|
321
|
-
|
|
361
|
+
queryValidator,
|
|
322
362
|
context.query
|
|
323
363
|
);
|
|
324
|
-
|
|
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?.()) {
|
|
325
374
|
let cookieValue = {};
|
|
326
375
|
for (const [key, value] of Object.entries(context.cookie))
|
|
327
376
|
cookieValue[key] = value.value;
|
|
328
|
-
if (validator.cookie.
|
|
329
|
-
|
|
377
|
+
if (validator.cookie.provider === "standard") {
|
|
378
|
+
cookieValue = await validateStandardSchema(
|
|
330
379
|
"cookie",
|
|
331
380
|
validator.cookie,
|
|
332
381
|
cookieValue
|
|
333
382
|
);
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
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
|
+
}
|
|
337
396
|
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
+
}
|
|
343
411
|
}
|
|
344
412
|
}
|
|
345
413
|
if (hooks.beforeHandle)
|
|
@@ -378,7 +446,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
378
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;
|
|
379
447
|
isCustomStatuResponse && (set.status = status2, response2 = response2.response);
|
|
380
448
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
381
|
-
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)
|
|
382
456
|
if (responseValidator?.Clean)
|
|
383
457
|
try {
|
|
384
458
|
const temp = responseValidator.Clean(response2);
|
|
@@ -414,7 +488,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
414
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;
|
|
415
489
|
isCustomStatuResponse && (set.status = status2, response = response.response);
|
|
416
490
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
417
|
-
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)
|
|
418
498
|
if (responseValidator?.Clean)
|
|
419
499
|
try {
|
|
420
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 = {
|
|
@@ -131,10 +144,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
131
144
|
break;
|
|
132
145
|
case "multipart/form-data": {
|
|
133
146
|
body = {};
|
|
134
|
-
const form = await request.formData();
|
|
135
|
-
|
|
147
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
148
|
+
form.forEach((v, k) => {
|
|
149
|
+
const list = grouped.get(k);
|
|
150
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
151
|
+
});
|
|
152
|
+
for (const [key, value] of grouped) {
|
|
136
153
|
if (body[key]) continue;
|
|
137
|
-
const
|
|
154
|
+
const finalValue = normalizeFormValue(value);
|
|
138
155
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
139
156
|
}
|
|
140
157
|
break;
|
|
@@ -170,10 +187,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
170
187
|
case "formdata":
|
|
171
188
|
case "multipart/form-data": {
|
|
172
189
|
body = {};
|
|
173
|
-
const form = await request.formData();
|
|
174
|
-
|
|
190
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
191
|
+
form.forEach((v, k) => {
|
|
192
|
+
const list = grouped.get(k);
|
|
193
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
194
|
+
});
|
|
195
|
+
for (const [key, value] of grouped) {
|
|
175
196
|
if (body[key]) continue;
|
|
176
|
-
const
|
|
197
|
+
const finalValue = normalizeFormValue(value);
|
|
177
198
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
178
199
|
}
|
|
179
200
|
break;
|
|
@@ -217,10 +238,14 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
217
238
|
break;
|
|
218
239
|
case "multipart/form-data": {
|
|
219
240
|
body = {};
|
|
220
|
-
const form = await request.formData();
|
|
221
|
-
|
|
241
|
+
const form = await request.formData(), grouped = /* @__PURE__ */ new Map();
|
|
242
|
+
form.forEach((v, k) => {
|
|
243
|
+
const list = grouped.get(k);
|
|
244
|
+
list ? list.push(v) : grouped.set(k, [v]);
|
|
245
|
+
});
|
|
246
|
+
for (const [key, value] of grouped) {
|
|
222
247
|
if (body[key]) continue;
|
|
223
|
-
const
|
|
248
|
+
const finalValue = normalizeFormValue(value);
|
|
224
249
|
key.includes(".") || key.includes("[") ? setNestedValue(body, key, finalValue) : body[key] = finalValue;
|
|
225
250
|
}
|
|
226
251
|
break;
|
|
@@ -281,20 +306,35 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
281
306
|
const _header = structuredClone(context.headers);
|
|
282
307
|
for (const [key, value] of request.headers)
|
|
283
308
|
_header[key] = value;
|
|
284
|
-
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)
|
|
285
316
|
throw new ValidationError(
|
|
286
317
|
"header",
|
|
287
318
|
validator.headers,
|
|
288
319
|
_header
|
|
289
320
|
);
|
|
290
321
|
} else validator.headers?.Decode && (context.headers = validator.headers.Decode(context.headers));
|
|
291
|
-
if (paramsValidator?.
|
|
292
|
-
|
|
322
|
+
if (paramsValidator?.provider === "standard")
|
|
323
|
+
context.params = await validateStandardSchema(
|
|
293
324
|
"params",
|
|
294
|
-
|
|
325
|
+
paramsValidator,
|
|
295
326
|
context.params
|
|
296
327
|
);
|
|
297
|
-
|
|
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) {
|
|
298
338
|
let schema = validator.query.schema;
|
|
299
339
|
schema.$defs?.[schema.$ref] && (schema = schema.$defs[schema.$ref]);
|
|
300
340
|
const properties = getSchemaProperties(schema);
|
|
@@ -304,31 +344,59 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
304
344
|
(value.type === "array" || value.items?.type === "string") && typeof context.query[property] == "string" && context.query[property] && (context.query[property] = context.query[property].split(","));
|
|
305
345
|
}
|
|
306
346
|
}
|
|
307
|
-
if (queryValidator?.
|
|
308
|
-
|
|
347
|
+
if (queryValidator?.provider === "standard")
|
|
348
|
+
context.query = await validateStandardSchema(
|
|
309
349
|
"query",
|
|
310
|
-
|
|
350
|
+
queryValidator,
|
|
311
351
|
context.query
|
|
312
352
|
);
|
|
313
|
-
|
|
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?.()) {
|
|
314
363
|
let cookieValue = {};
|
|
315
364
|
for (const [key, value] of Object.entries(context.cookie))
|
|
316
365
|
cookieValue[key] = value.value;
|
|
317
|
-
if (validator.cookie.
|
|
318
|
-
|
|
366
|
+
if (validator.cookie.provider === "standard") {
|
|
367
|
+
cookieValue = await validateStandardSchema(
|
|
319
368
|
"cookie",
|
|
320
369
|
validator.cookie,
|
|
321
370
|
cookieValue
|
|
322
371
|
);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
+
}
|
|
326
385
|
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
+
}
|
|
332
400
|
}
|
|
333
401
|
}
|
|
334
402
|
if (hooks.beforeHandle)
|
|
@@ -367,7 +435,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
367
435
|
const isCustomStatuResponse = response2 instanceof ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response2.code : set.status ? typeof set.status == "string" ? StatusMap[set.status] : set.status : 200;
|
|
368
436
|
isCustomStatuResponse && (set.status = status2, response2 = response2.response);
|
|
369
437
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
370
|
-
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)
|
|
371
445
|
if (responseValidator?.Clean)
|
|
372
446
|
try {
|
|
373
447
|
const temp = responseValidator.Clean(response2);
|
|
@@ -403,7 +477,13 @@ const ARRAY_INDEX_REGEX = /^(.+)\[(\d+)\]$/, DANGEROUS_KEYS = /* @__PURE__ */ ne
|
|
|
403
477
|
const isCustomStatuResponse = response instanceof ElysiaCustomStatusResponse, status2 = isCustomStatuResponse ? response.code : set.status ? typeof set.status == "string" ? StatusMap[set.status] : set.status : 200;
|
|
404
478
|
isCustomStatuResponse && (set.status = status2, response = response.response);
|
|
405
479
|
const responseValidator = validator?.createResponse?.()?.[status2];
|
|
406
|
-
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)
|
|
407
487
|
if (responseValidator?.Clean)
|
|
408
488
|
try {
|
|
409
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;
|