elysia 1.0.21 → 1.0.23
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/bun/index.d.ts +1 -1
- package/dist/bun/index.js +111 -110
- package/dist/bun/index.js.map +23 -32
- package/dist/cjs/compose.js +171 -39
- package/dist/cjs/cookies.js +9 -2
- package/dist/cjs/dynamic-handle.js +129 -31
- package/dist/cjs/error.js +3 -2
- package/dist/cjs/handler.js +117 -20
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +185 -48
- package/dist/cjs/sucrose.js +5 -1
- package/dist/cjs/type-system.js +3 -2
- package/dist/cjs/types.d.ts +11 -4
- package/dist/cjs/utils.d.ts +16 -4
- package/dist/cjs/utils.js +28 -11
- package/dist/cjs/ws/index.js +3 -2
- package/dist/compose.mjs +171 -39
- package/dist/cookies.mjs +9 -2
- package/dist/dynamic-handle.mjs +129 -31
- package/dist/error.mjs +3 -2
- package/dist/handler.mjs +117 -20
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +184 -48
- package/dist/sucrose.mjs +5 -1
- package/dist/type-system.mjs +3 -2
- package/dist/types.d.ts +11 -4
- package/dist/utils.d.ts +16 -4
- package/dist/utils.mjs +26 -11
- package/dist/ws/index.mjs +3 -2
- package/package.json +2 -1
- package/tsconfig.test.tsbuildinfo +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(src_exports, {
|
|
|
43
43
|
ValidationError: () => ValidationError,
|
|
44
44
|
default: () => Elysia,
|
|
45
45
|
error: () => error,
|
|
46
|
+
form: () => form,
|
|
46
47
|
getResponseSchemaValidator: () => getResponseSchemaValidator,
|
|
47
48
|
getSchemaValidator: () => getSchemaValidator,
|
|
48
49
|
mapCompactResponse: () => mapCompactResponse,
|
|
@@ -410,8 +411,10 @@ var separateFunction = (code) => {
|
|
|
410
411
|
}
|
|
411
412
|
const start = code.indexOf("(");
|
|
412
413
|
if (start !== -1) {
|
|
413
|
-
const
|
|
414
|
+
const sep = code.indexOf("\n", 2);
|
|
415
|
+
const parameter = code.slice(0, sep);
|
|
414
416
|
const end = parameter.lastIndexOf(")") + 1;
|
|
417
|
+
const body = code.slice(sep + 1);
|
|
415
418
|
return [
|
|
416
419
|
parameter.slice(start, end),
|
|
417
420
|
"{" + body,
|
|
@@ -691,6 +694,8 @@ var validateInferencedQueries = (queries) => {
|
|
|
691
694
|
return false;
|
|
692
695
|
if (query.indexOf(" ") !== -1)
|
|
693
696
|
return false;
|
|
697
|
+
if (query.indexOf("(") !== -1)
|
|
698
|
+
return false;
|
|
694
699
|
}
|
|
695
700
|
return true;
|
|
696
701
|
};
|
|
@@ -1052,6 +1057,12 @@ var parseCookie = async (set, cookieString, {
|
|
|
1052
1057
|
throw new InvalidCookieSignature(name);
|
|
1053
1058
|
}
|
|
1054
1059
|
}
|
|
1060
|
+
if (value == null) {
|
|
1061
|
+
jar[name] = {
|
|
1062
|
+
value: v
|
|
1063
|
+
};
|
|
1064
|
+
continue;
|
|
1065
|
+
}
|
|
1055
1066
|
const start = value.charCodeAt(0);
|
|
1056
1067
|
if (start === 123 || start === 91)
|
|
1057
1068
|
try {
|
|
@@ -1192,9 +1203,21 @@ var mapResponse = (response, set, request) => {
|
|
|
1192
1203
|
return new Response(response, set);
|
|
1193
1204
|
case "Blob":
|
|
1194
1205
|
return handleFile(response, set);
|
|
1195
|
-
case "Object":
|
|
1196
1206
|
case "Array":
|
|
1197
1207
|
return Response.json(response, set);
|
|
1208
|
+
case "Object":
|
|
1209
|
+
for (const value in Object.values(response)) {
|
|
1210
|
+
switch (value?.constructor?.name) {
|
|
1211
|
+
case "Blob":
|
|
1212
|
+
case "File":
|
|
1213
|
+
case "ArrayBuffer":
|
|
1214
|
+
case "FileRef":
|
|
1215
|
+
return new Response(form(response));
|
|
1216
|
+
default:
|
|
1217
|
+
break;
|
|
1218
|
+
}
|
|
1219
|
+
}
|
|
1220
|
+
return Response.json(response, set);
|
|
1198
1221
|
case "ReadableStream":
|
|
1199
1222
|
if (!set.headers["content-type"]?.startsWith(
|
|
1200
1223
|
"text/event-stream"
|
|
@@ -1268,6 +1291,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1268
1291
|
if (response instanceof Cookie)
|
|
1269
1292
|
return new Response(response.value, set);
|
|
1270
1293
|
return new Response(response?.toString(), set);
|
|
1294
|
+
case "FormData":
|
|
1295
|
+
return new Response(response, set);
|
|
1271
1296
|
default:
|
|
1272
1297
|
if (response instanceof Response) {
|
|
1273
1298
|
let isCookieSet2 = false;
|
|
@@ -1308,6 +1333,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1308
1333
|
return response.then((x) => mapResponse(x, set));
|
|
1309
1334
|
if (response instanceof Error)
|
|
1310
1335
|
return errorToResponse(response, set);
|
|
1336
|
+
if ("toResponse" in response)
|
|
1337
|
+
return mapResponse(response.toResponse(), set);
|
|
1311
1338
|
if ("charCodeAt" in response) {
|
|
1312
1339
|
const code = response.charCodeAt(0);
|
|
1313
1340
|
if (code === 123 || code === 91) {
|
|
@@ -1327,13 +1354,24 @@ var mapResponse = (response, set, request) => {
|
|
|
1327
1354
|
return new Response(response);
|
|
1328
1355
|
case "Blob":
|
|
1329
1356
|
return handleFile(response, set);
|
|
1330
|
-
case "Object":
|
|
1331
1357
|
case "Array":
|
|
1332
|
-
return
|
|
1333
|
-
|
|
1334
|
-
|
|
1358
|
+
return Response.json(response);
|
|
1359
|
+
case "Object":
|
|
1360
|
+
for (const value in Object.values(response)) {
|
|
1361
|
+
switch (value?.constructor?.name) {
|
|
1362
|
+
case "Blob":
|
|
1363
|
+
case "File":
|
|
1364
|
+
case "ArrayBuffer":
|
|
1365
|
+
case "FileRef":
|
|
1366
|
+
return new Response(
|
|
1367
|
+
form(response),
|
|
1368
|
+
set
|
|
1369
|
+
);
|
|
1370
|
+
default:
|
|
1371
|
+
break;
|
|
1335
1372
|
}
|
|
1336
|
-
}
|
|
1373
|
+
}
|
|
1374
|
+
return Response.json(response, set);
|
|
1337
1375
|
case "ReadableStream":
|
|
1338
1376
|
request?.signal.addEventListener(
|
|
1339
1377
|
"abort",
|
|
@@ -1380,6 +1418,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1380
1418
|
if (response instanceof Cookie)
|
|
1381
1419
|
return new Response(response.value, set);
|
|
1382
1420
|
return new Response(response?.toString(), set);
|
|
1421
|
+
case "FormData":
|
|
1422
|
+
return new Response(response, set);
|
|
1383
1423
|
default:
|
|
1384
1424
|
if (response instanceof Response)
|
|
1385
1425
|
return new Response(response.body, {
|
|
@@ -1391,6 +1431,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1391
1431
|
return response.then((x) => mapResponse(x, set));
|
|
1392
1432
|
if (response instanceof Error)
|
|
1393
1433
|
return errorToResponse(response, set);
|
|
1434
|
+
if ("toResponse" in response)
|
|
1435
|
+
return mapResponse(response.toResponse(), set);
|
|
1394
1436
|
if ("charCodeAt" in response) {
|
|
1395
1437
|
const code = response.charCodeAt(0);
|
|
1396
1438
|
if (code === 123 || code === 91) {
|
|
@@ -1434,9 +1476,24 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1434
1476
|
return new Response(response, set);
|
|
1435
1477
|
case "Blob":
|
|
1436
1478
|
return handleFile(response, set);
|
|
1437
|
-
case "Object":
|
|
1438
1479
|
case "Array":
|
|
1439
1480
|
return Response.json(response, set);
|
|
1481
|
+
case "Object":
|
|
1482
|
+
for (const value in Object.values(response)) {
|
|
1483
|
+
switch (value?.constructor?.name) {
|
|
1484
|
+
case "Blob":
|
|
1485
|
+
case "File":
|
|
1486
|
+
case "ArrayBuffer":
|
|
1487
|
+
case "FileRef":
|
|
1488
|
+
return new Response(
|
|
1489
|
+
form(response),
|
|
1490
|
+
set
|
|
1491
|
+
);
|
|
1492
|
+
default:
|
|
1493
|
+
break;
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
return Response.json(response, set);
|
|
1440
1497
|
case "ReadableStream":
|
|
1441
1498
|
if (!set.headers["content-type"]?.startsWith(
|
|
1442
1499
|
"text/event-stream"
|
|
@@ -1508,6 +1565,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1508
1565
|
response.toString(),
|
|
1509
1566
|
set
|
|
1510
1567
|
);
|
|
1568
|
+
case "FormData":
|
|
1569
|
+
return new Response(response);
|
|
1511
1570
|
case "Cookie":
|
|
1512
1571
|
if (response instanceof Cookie)
|
|
1513
1572
|
return new Response(response.value, set);
|
|
@@ -1548,6 +1607,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1548
1607
|
return response.then((x) => mapEarlyResponse(x, set));
|
|
1549
1608
|
if (response instanceof Error)
|
|
1550
1609
|
return errorToResponse(response, set);
|
|
1610
|
+
if ("toResponse" in response)
|
|
1611
|
+
return mapEarlyResponse(response.toResponse(), set);
|
|
1551
1612
|
if ("charCodeAt" in response) {
|
|
1552
1613
|
const code = response.charCodeAt(0);
|
|
1553
1614
|
if (code === 123 || code === 91) {
|
|
@@ -1567,13 +1628,24 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1567
1628
|
return new Response(response);
|
|
1568
1629
|
case "Blob":
|
|
1569
1630
|
return handleFile(response, set);
|
|
1570
|
-
case "Object":
|
|
1571
1631
|
case "Array":
|
|
1572
|
-
return
|
|
1573
|
-
|
|
1574
|
-
|
|
1632
|
+
return Response.json(response);
|
|
1633
|
+
case "Object":
|
|
1634
|
+
for (const value in Object.values(response)) {
|
|
1635
|
+
switch (value?.constructor?.name) {
|
|
1636
|
+
case "Blob":
|
|
1637
|
+
case "File":
|
|
1638
|
+
case "ArrayBuffer":
|
|
1639
|
+
case "FileRef":
|
|
1640
|
+
return new Response(
|
|
1641
|
+
form(response),
|
|
1642
|
+
set
|
|
1643
|
+
);
|
|
1644
|
+
default:
|
|
1645
|
+
break;
|
|
1575
1646
|
}
|
|
1576
|
-
}
|
|
1647
|
+
}
|
|
1648
|
+
return Response.json(response, set);
|
|
1577
1649
|
case "ReadableStream":
|
|
1578
1650
|
request?.signal.addEventListener(
|
|
1579
1651
|
"abort",
|
|
@@ -1619,6 +1691,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1619
1691
|
if (response instanceof Cookie)
|
|
1620
1692
|
return new Response(response.value, set);
|
|
1621
1693
|
return new Response(response?.toString(), set);
|
|
1694
|
+
case "FormData":
|
|
1695
|
+
return new Response(response);
|
|
1622
1696
|
default:
|
|
1623
1697
|
if (response instanceof Response)
|
|
1624
1698
|
return new Response(response.body, {
|
|
@@ -1630,6 +1704,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1630
1704
|
return response.then((x) => mapEarlyResponse(x, set));
|
|
1631
1705
|
if (response instanceof Error)
|
|
1632
1706
|
return errorToResponse(response, set);
|
|
1707
|
+
if ("toResponse" in response)
|
|
1708
|
+
return mapEarlyResponse(response.toResponse(), set);
|
|
1633
1709
|
if ("charCodeAt" in response) {
|
|
1634
1710
|
const code = response.charCodeAt(0);
|
|
1635
1711
|
if (code === 123 || code === 91) {
|
|
@@ -1658,13 +1734,23 @@ var mapCompactResponse = (response, request) => {
|
|
|
1658
1734
|
return new Response(response);
|
|
1659
1735
|
case "Blob":
|
|
1660
1736
|
return handleFile(response);
|
|
1661
|
-
case "Object":
|
|
1662
1737
|
case "Array":
|
|
1663
|
-
return
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1738
|
+
return Response.json(response);
|
|
1739
|
+
case "Object":
|
|
1740
|
+
form:
|
|
1741
|
+
for (const value of Object.values(response))
|
|
1742
|
+
switch (value?.constructor?.name) {
|
|
1743
|
+
case "Blob":
|
|
1744
|
+
case "File":
|
|
1745
|
+
case "ArrayBuffer":
|
|
1746
|
+
case "FileRef":
|
|
1747
|
+
return new Response(form(response));
|
|
1748
|
+
case "Object":
|
|
1749
|
+
break form;
|
|
1750
|
+
default:
|
|
1751
|
+
break;
|
|
1752
|
+
}
|
|
1753
|
+
return Response.json(response);
|
|
1668
1754
|
case "ReadableStream":
|
|
1669
1755
|
request?.signal.addEventListener(
|
|
1670
1756
|
"abort",
|
|
@@ -1704,6 +1790,8 @@ var mapCompactResponse = (response, request) => {
|
|
|
1704
1790
|
case "Number":
|
|
1705
1791
|
case "Boolean":
|
|
1706
1792
|
return new Response(response.toString());
|
|
1793
|
+
case "FormData":
|
|
1794
|
+
return new Response(response);
|
|
1707
1795
|
default:
|
|
1708
1796
|
if (response instanceof Response)
|
|
1709
1797
|
return new Response(response.body, {
|
|
@@ -1715,6 +1803,8 @@ var mapCompactResponse = (response, request) => {
|
|
|
1715
1803
|
return response.then(mapCompactResponse);
|
|
1716
1804
|
if (response instanceof Error)
|
|
1717
1805
|
return errorToResponse(response);
|
|
1806
|
+
if ("toResponse" in response)
|
|
1807
|
+
return mapCompactResponse(response.toResponse());
|
|
1718
1808
|
if ("charCodeAt" in response) {
|
|
1719
1809
|
const code = response.charCodeAt(0);
|
|
1720
1810
|
if (code === 123 || code === 91) {
|
|
@@ -1871,7 +1961,7 @@ var getSchemaValidator = (s, {
|
|
|
1871
1961
|
models = {},
|
|
1872
1962
|
dynamic = false,
|
|
1873
1963
|
normalize = false,
|
|
1874
|
-
additionalProperties =
|
|
1964
|
+
additionalProperties = false
|
|
1875
1965
|
} = {}) => {
|
|
1876
1966
|
if (!s)
|
|
1877
1967
|
return void 0;
|
|
@@ -1892,7 +1982,7 @@ var getSchemaValidator = (s, {
|
|
|
1892
1982
|
Errors: (value) => import_value.Value.Errors(schema, value),
|
|
1893
1983
|
Code: () => ""
|
|
1894
1984
|
};
|
|
1895
|
-
if (normalize && schema.additionalProperties ===
|
|
1985
|
+
if (normalize && schema.additionalProperties === false)
|
|
1896
1986
|
validator.Clean = cleaner;
|
|
1897
1987
|
if (schema.config) {
|
|
1898
1988
|
validator.config = schema.config;
|
|
@@ -1914,7 +2004,7 @@ var getResponseSchemaValidator = (s, {
|
|
|
1914
2004
|
models = {},
|
|
1915
2005
|
dynamic = false,
|
|
1916
2006
|
normalize = false,
|
|
1917
|
-
additionalProperties =
|
|
2007
|
+
additionalProperties = false
|
|
1918
2008
|
}) => {
|
|
1919
2009
|
if (!s)
|
|
1920
2010
|
return;
|
|
@@ -1935,7 +2025,7 @@ var getResponseSchemaValidator = (s, {
|
|
|
1935
2025
|
Code: () => ""
|
|
1936
2026
|
};
|
|
1937
2027
|
const compiledValidator = import_compiler.TypeCompiler.Compile(schema, references);
|
|
1938
|
-
if (normalize && schema.additionalProperties ===
|
|
2028
|
+
if (normalize && schema.additionalProperties === false)
|
|
1939
2029
|
compiledValidator.Clean = cleaner;
|
|
1940
2030
|
return compiledValidator;
|
|
1941
2031
|
};
|
|
@@ -2422,12 +2512,25 @@ var cloneInference = (inference) => ({
|
|
|
2422
2512
|
set: inference.trace.set
|
|
2423
2513
|
}
|
|
2424
2514
|
});
|
|
2425
|
-
var redirect = (url, status = 301) =>
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2515
|
+
var redirect = (url, status = 301) => Response.redirect(url, status);
|
|
2516
|
+
var ELYSIA_FORM_DATA = Symbol("ElysiaFormData");
|
|
2517
|
+
var form = (items) => {
|
|
2518
|
+
const formData = new FormData();
|
|
2519
|
+
for (const [key, value] of Object.entries(items)) {
|
|
2520
|
+
if (Array.isArray(value)) {
|
|
2521
|
+
for (const v of value) {
|
|
2522
|
+
if (value instanceof File)
|
|
2523
|
+
formData.append(key, value, value.name);
|
|
2524
|
+
formData.append(key, v);
|
|
2525
|
+
}
|
|
2526
|
+
continue;
|
|
2527
|
+
}
|
|
2528
|
+
if (value instanceof File)
|
|
2529
|
+
formData.append(key, value, value.name);
|
|
2530
|
+
formData.append(key, value);
|
|
2429
2531
|
}
|
|
2430
|
-
|
|
2532
|
+
return formData;
|
|
2533
|
+
};
|
|
2431
2534
|
|
|
2432
2535
|
// src/error.ts
|
|
2433
2536
|
var env = typeof Bun !== "undefined" ? Bun.env : typeof process !== "undefined" ? process?.env : void 0;
|
|
@@ -3218,7 +3321,7 @@ const traceDone = Promise.all([`;
|
|
|
3218
3321
|
if (validator) {
|
|
3219
3322
|
fnLiteral += "\n";
|
|
3220
3323
|
if (validator.headers) {
|
|
3221
|
-
if (hasProperty("default", validator.headers.
|
|
3324
|
+
if (hasProperty("default", validator.headers.schema))
|
|
3222
3325
|
for (const [key, value] of Object.entries(
|
|
3223
3326
|
import_value3.Value.Default(
|
|
3224
3327
|
// @ts-ignore
|
|
@@ -3226,7 +3329,7 @@ const traceDone = Promise.all([`;
|
|
|
3226
3329
|
{}
|
|
3227
3330
|
)
|
|
3228
3331
|
)) {
|
|
3229
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3332
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3230
3333
|
if (parsed)
|
|
3231
3334
|
fnLiteral += `c.headers['${key}'] ??= ${parsed}
|
|
3232
3335
|
`;
|
|
@@ -3248,7 +3351,7 @@ c.headers = headers.Decode(c.headers)
|
|
|
3248
3351
|
{}
|
|
3249
3352
|
)
|
|
3250
3353
|
)) {
|
|
3251
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3354
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3252
3355
|
if (parsed)
|
|
3253
3356
|
fnLiteral += `c.params['${key}'] ??= ${parsed}
|
|
3254
3357
|
`;
|
|
@@ -3272,11 +3375,26 @@ c.params = params.Decode(c.params)
|
|
|
3272
3375
|
{}
|
|
3273
3376
|
)
|
|
3274
3377
|
)) {
|
|
3275
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3378
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3276
3379
|
if (parsed)
|
|
3277
3380
|
fnLiteral += `c.query['${key}'] ??= ${parsed}
|
|
3278
3381
|
`;
|
|
3279
3382
|
}
|
|
3383
|
+
for (const [key, value] of Object.entries(
|
|
3384
|
+
// @ts-ignore
|
|
3385
|
+
validator.query.schema?.properties
|
|
3386
|
+
)) {
|
|
3387
|
+
const { type, anyOf } = value;
|
|
3388
|
+
if (type === "object" || type === "array") {
|
|
3389
|
+
fnLiteral += `c.query['${key}'] = JSON.parse(c.query['${key}'])
|
|
3390
|
+
`;
|
|
3391
|
+
continue;
|
|
3392
|
+
}
|
|
3393
|
+
if (anyOf) {
|
|
3394
|
+
fnLiteral += `if(typeof c.query['${key}'] === "object") c.query['${key}'] = JSON.parse(c.query['${key}'])
|
|
3395
|
+
`;
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3280
3398
|
fnLiteral += `if(query.Check(c.query) === false) {
|
|
3281
3399
|
${composeValidation("query")}
|
|
3282
3400
|
}`;
|
|
@@ -3288,21 +3406,32 @@ c.query = query.Decode(Object.assign({}, c.query))
|
|
|
3288
3406
|
if (validator.body) {
|
|
3289
3407
|
if (normalize)
|
|
3290
3408
|
fnLiteral += "c.body = body.Clean(c.body);\n";
|
|
3291
|
-
if (hasProperty("default", validator.body.schema))
|
|
3409
|
+
if (hasProperty("default", validator.body.schema)) {
|
|
3292
3410
|
fnLiteral += `if(body.Check(c.body) === false) {
|
|
3293
|
-
|
|
3411
|
+
if (typeof c.body === 'object') {
|
|
3412
|
+
c.body = Object.assign(${JSON.stringify(
|
|
3294
3413
|
import_value3.Value.Default(
|
|
3295
3414
|
// @ts-ignore
|
|
3296
3415
|
validator.body.schema,
|
|
3297
|
-
|
|
3416
|
+
{}
|
|
3298
3417
|
) ?? {}
|
|
3299
3418
|
)}, c.body)
|
|
3300
|
-
|
|
3301
|
-
|
|
3419
|
+
} else {`;
|
|
3420
|
+
const defaultValue = import_value3.Value.Default(
|
|
3421
|
+
// @ts-ignore
|
|
3422
|
+
validator.body.schema,
|
|
3423
|
+
void 0
|
|
3424
|
+
);
|
|
3425
|
+
if (typeof defaultValue === "string")
|
|
3426
|
+
fnLiteral += `c.body = '${defaultValue}'`;
|
|
3427
|
+
else
|
|
3428
|
+
fnLiteral += `c.body = ${defaultValue}`;
|
|
3429
|
+
fnLiteral += `}
|
|
3430
|
+
if(body.Check(c.body) === false) {
|
|
3302
3431
|
${composeValidation("body")}
|
|
3303
3432
|
}
|
|
3304
3433
|
}`;
|
|
3305
|
-
else
|
|
3434
|
+
} else
|
|
3306
3435
|
fnLiteral += `if(body.Check(c.body) === false) {
|
|
3307
3436
|
${composeValidation("body")}
|
|
3308
3437
|
}`;
|
|
@@ -3311,7 +3440,11 @@ c.query = query.Decode(Object.assign({}, c.query))
|
|
|
3311
3440
|
c.body = body.Decode(c.body)
|
|
3312
3441
|
`;
|
|
3313
3442
|
}
|
|
3314
|
-
if (isNotEmpty(
|
|
3443
|
+
if (isNotEmpty(
|
|
3444
|
+
// @ts-ignore
|
|
3445
|
+
cookieValidator?.schema?.properties ?? // @ts-ignore
|
|
3446
|
+
cookieValidator?.schema?.schema ?? {}
|
|
3447
|
+
)) {
|
|
3315
3448
|
fnLiteral += `const cookieValue = {}
|
|
3316
3449
|
for(const [key, value] of Object.entries(c.cookie))
|
|
3317
3450
|
cookieValue[key] = value.value
|
|
@@ -4091,11 +4224,11 @@ var createDynamicHandler = (app) => async (request) => {
|
|
|
4091
4224
|
break;
|
|
4092
4225
|
case "multipart/form-data":
|
|
4093
4226
|
body = {};
|
|
4094
|
-
const
|
|
4095
|
-
for (const key of
|
|
4227
|
+
const form2 = await request.formData();
|
|
4228
|
+
for (const key of form2.keys()) {
|
|
4096
4229
|
if (body[key])
|
|
4097
4230
|
continue;
|
|
4098
|
-
const value =
|
|
4231
|
+
const value = form2.getAll(key);
|
|
4099
4232
|
if (value.length === 1)
|
|
4100
4233
|
body[key] = value[0];
|
|
4101
4234
|
else
|
|
@@ -4137,11 +4270,11 @@ var createDynamicHandler = (app) => async (request) => {
|
|
|
4137
4270
|
break;
|
|
4138
4271
|
case "multipart/form-data":
|
|
4139
4272
|
body = {};
|
|
4140
|
-
const
|
|
4141
|
-
for (const key of
|
|
4273
|
+
const form2 = await request.formData();
|
|
4274
|
+
for (const key of form2.keys()) {
|
|
4142
4275
|
if (body[key])
|
|
4143
4276
|
continue;
|
|
4144
|
-
const value =
|
|
4277
|
+
const value = form2.getAll(key);
|
|
4145
4278
|
if (value.length === 1)
|
|
4146
4279
|
body[key] = value[0];
|
|
4147
4280
|
else
|
|
@@ -4531,7 +4664,7 @@ var validateFile = (options, value) => {
|
|
|
4531
4664
|
}
|
|
4532
4665
|
return true;
|
|
4533
4666
|
};
|
|
4534
|
-
var
|
|
4667
|
+
var File2 = import_typebox2.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type("File", validateFile);
|
|
4535
4668
|
var Files = import_typebox2.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type(
|
|
4536
4669
|
"Files",
|
|
4537
4670
|
(options, value) => {
|
|
@@ -4677,7 +4810,7 @@ var ElysiaType = {
|
|
|
4677
4810
|
return JSON.stringify(value);
|
|
4678
4811
|
});
|
|
4679
4812
|
},
|
|
4680
|
-
File,
|
|
4813
|
+
File: File2,
|
|
4681
4814
|
Files: (options = {}) => t2.Transform(Files(options)).Decode((value) => {
|
|
4682
4815
|
if (Array.isArray(value))
|
|
4683
4816
|
return value;
|
|
@@ -4958,8 +5091,11 @@ var Elysia = class _Elysia {
|
|
|
4958
5091
|
aot: true,
|
|
4959
5092
|
strictPath: false,
|
|
4960
5093
|
global: false,
|
|
4961
|
-
cookie: {
|
|
5094
|
+
cookie: {
|
|
5095
|
+
path: "/"
|
|
5096
|
+
},
|
|
4962
5097
|
analytic: false,
|
|
5098
|
+
forceDynamicQuery: true,
|
|
4963
5099
|
...config,
|
|
4964
5100
|
experimental: config?.experimental ?? {},
|
|
4965
5101
|
seed: config?.seed === void 0 ? "" : config?.seed
|
|
@@ -6639,6 +6775,7 @@ ${staticRouter.map[loosePath].code}`;
|
|
|
6639
6775
|
StatusMap,
|
|
6640
6776
|
ValidationError,
|
|
6641
6777
|
error,
|
|
6778
|
+
form,
|
|
6642
6779
|
getResponseSchemaValidator,
|
|
6643
6780
|
getSchemaValidator,
|
|
6644
6781
|
mapCompactResponse,
|
package/dist/cjs/sucrose.js
CHANGED
|
@@ -69,8 +69,10 @@ var separateFunction = (code) => {
|
|
|
69
69
|
}
|
|
70
70
|
const start = code.indexOf("(");
|
|
71
71
|
if (start !== -1) {
|
|
72
|
-
const
|
|
72
|
+
const sep = code.indexOf("\n", 2);
|
|
73
|
+
const parameter = code.slice(0, sep);
|
|
73
74
|
const end = parameter.lastIndexOf(")") + 1;
|
|
75
|
+
const body = code.slice(sep + 1);
|
|
74
76
|
return [
|
|
75
77
|
parameter.slice(start, end),
|
|
76
78
|
"{" + body,
|
|
@@ -350,6 +352,8 @@ var validateInferencedQueries = (queries) => {
|
|
|
350
352
|
return false;
|
|
351
353
|
if (query.indexOf(" ") !== -1)
|
|
352
354
|
return false;
|
|
355
|
+
if (query.indexOf("(") !== -1)
|
|
356
|
+
return false;
|
|
353
357
|
}
|
|
354
358
|
return true;
|
|
355
359
|
};
|
package/dist/cjs/type-system.js
CHANGED
|
@@ -298,6 +298,7 @@ var InvertedStatusMap = Object.fromEntries(
|
|
|
298
298
|
Object.entries(StatusMap).map(([k, v]) => [v, k])
|
|
299
299
|
);
|
|
300
300
|
var encoder = new TextEncoder();
|
|
301
|
+
var ELYSIA_FORM_DATA = Symbol("ElysiaFormData");
|
|
301
302
|
|
|
302
303
|
// src/error.ts
|
|
303
304
|
var env = typeof Bun !== "undefined" ? Bun.env : typeof process !== "undefined" ? process?.env : void 0;
|
|
@@ -458,7 +459,7 @@ var validateFile = (options, value) => {
|
|
|
458
459
|
}
|
|
459
460
|
return true;
|
|
460
461
|
};
|
|
461
|
-
var
|
|
462
|
+
var File2 = import_typebox2.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type("File", validateFile);
|
|
462
463
|
var Files = import_typebox2.TypeRegistry.Get("Files") ?? import_system.TypeSystem.Type(
|
|
463
464
|
"Files",
|
|
464
465
|
(options, value) => {
|
|
@@ -604,7 +605,7 @@ var ElysiaType = {
|
|
|
604
605
|
return JSON.stringify(value);
|
|
605
606
|
});
|
|
606
607
|
},
|
|
607
|
-
File,
|
|
608
|
+
File: File2,
|
|
608
609
|
Files: (options = {}) => t.Transform(Files(options)).Decode((value) => {
|
|
609
610
|
if (Array.isArray(value))
|
|
610
611
|
return value;
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/// <reference types="bun-types" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="bun-types" />
|
|
4
|
+
/// <reference types="bun-types" />
|
|
4
5
|
import type { Elysia } from '.';
|
|
5
|
-
import type { Serve, Server, WebSocketHandler } from 'bun';
|
|
6
|
+
import type { BunFile, Serve, Server, WebSocketHandler } from 'bun';
|
|
6
7
|
import type { TSchema, TObject, StaticDecode, TAnySchema } from '@sinclair/typebox';
|
|
7
8
|
import type { TypeCheck } from '@sinclair/typebox/compiler';
|
|
8
9
|
import type { OpenAPIV3 } from 'openapi-types';
|
|
@@ -176,8 +177,8 @@ export interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Defi
|
|
|
176
177
|
query: UnwrapSchema<Schema['query'], Definitions>;
|
|
177
178
|
params: UnwrapSchema<Schema['params'], Definitions>;
|
|
178
179
|
cookie: UnwrapSchema<Schema['cookie'], Definitions>;
|
|
179
|
-
response: Schema['response'] extends TSchema | string ? UnwrapSchema<Schema['response'], Definitions> : Schema['response'] extends SuccessfulResponse<TAnySchema | string> ? {
|
|
180
|
-
[k in keyof Schema['response']]: UnwrapSchema<Schema['response'][k], Definitions>;
|
|
180
|
+
response: Schema['response'] extends TSchema | string ? CoExist<UnwrapSchema<Schema['response'], Definitions>, File, BunFile> : Schema['response'] extends SuccessfulResponse<TAnySchema | string> ? {
|
|
181
|
+
[k in keyof Schema['response']]: CoExist<UnwrapSchema<Schema['response'][k], Definitions>, File, BunFile>;
|
|
181
182
|
} : unknown | void;
|
|
182
183
|
}
|
|
183
184
|
export interface UnwrapGroupGuardRoute<in out Schema extends InputSchema<any>, in out Definitions extends Record<string, unknown> = {}, Path extends string = ''> {
|
|
@@ -235,6 +236,12 @@ export type Handler<in out Route extends RouteSchema = {}, in out Singleton exte
|
|
|
235
236
|
derive: {};
|
|
236
237
|
resolve: {};
|
|
237
238
|
}, Path extends string = ''> = (context: Context<Route, Singleton, Path>) => Route['response'] extends SuccessfulResponse ? Response | MaybePromise<Route['response'][keyof Route['response']]> : Response | MaybePromise<Route['response']>;
|
|
239
|
+
export type Replace<Original, Target, With> = Original extends Record<string, unknown> ? {
|
|
240
|
+
[K in keyof Original]: Original[K] extends Target ? With : Original[K];
|
|
241
|
+
} : Original extends Target ? With : Original;
|
|
242
|
+
export type CoExist<Original, Target, With> = Original extends Record<string, unknown> ? {
|
|
243
|
+
[K in keyof Original]: Original[K] extends Target ? Original[K] | With : Original[K];
|
|
244
|
+
} : Original extends Target ? Original | With : Original;
|
|
238
245
|
export type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBase = {
|
|
239
246
|
decorator: {};
|
|
240
247
|
store: {};
|
|
@@ -572,7 +579,7 @@ type _CreateEden<Path extends string, Property extends Record<string, unknown> =
|
|
|
572
579
|
[x in Path]: Property;
|
|
573
580
|
};
|
|
574
581
|
export type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' ? _CreateEden<'index', Property> : _CreateEden<Path, Property>;
|
|
575
|
-
export type ComposeElysiaResponse<Response, Handle> = Handle extends (...a: any[]) => infer A ? _ComposeElysiaResponse<Response, Awaited<A>> : _ComposeElysiaResponse<Response, Awaited<Handle>>;
|
|
582
|
+
export type ComposeElysiaResponse<Response, Handle> = Handle extends (...a: any[]) => infer A ? _ComposeElysiaResponse<Response, Replace<Awaited<A>, BunFile, File>> : _ComposeElysiaResponse<Response, Replace<Awaited<Handle>, BunFile, File>>;
|
|
576
583
|
type _ComposeElysiaResponse<Response, Handle> = Prettify<unknown extends Response ? {
|
|
577
584
|
200: Exclude<Handle, {
|
|
578
585
|
[ELYSIA_RESPONSE]: any;
|
package/dist/cjs/utils.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="bun-types" />
|
|
3
|
+
/// <reference types="bun-types" />
|
|
4
|
+
/// <reference types="bun-types" />
|
|
1
5
|
import { TSchema } from '@sinclair/typebox';
|
|
2
6
|
import { TypeCheck } from '@sinclair/typebox/compiler';
|
|
3
|
-
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, LifeCycleType, HookContainer } from './types';
|
|
7
|
+
import type { LifeCycleStore, LocalHook, MaybeArray, InputSchema, LifeCycleType, HookContainer, Replace } from './types';
|
|
4
8
|
import type { CookieOptions } from './cookies';
|
|
5
9
|
import { Sucrose } from './sucrose';
|
|
10
|
+
import { BunFile } from 'bun';
|
|
6
11
|
export declare const replaceUrlPath: (url: string, pathname: string) => string;
|
|
7
12
|
export declare const mergeDeep: <A extends Record<string, any>, B extends Record<string, any>>(target: A, source: B, { skipKeys }?: {
|
|
8
13
|
skipKeys?: string[];
|
|
@@ -16,13 +21,13 @@ export declare const mergeResponse: (a: InputSchema['response'], b: InputSchema[
|
|
|
16
21
|
export declare const mergeHook: (a?: LifeCycleStore, b?: LocalHook<any, any, any, any, any, any, any>, { allowMacro }?: {
|
|
17
22
|
allowMacro?: boolean;
|
|
18
23
|
}) => LifeCycleStore;
|
|
19
|
-
export declare const getSchemaValidator: <T extends string | TSchema | undefined>(s: T, { models, dynamic, normalize, additionalProperties }?: {
|
|
24
|
+
export declare const getSchemaValidator: <T extends string | TSchema | undefined>(s: T, { models, dynamic, normalize, additionalProperties, }?: {
|
|
20
25
|
models?: Record<string, TSchema>;
|
|
21
26
|
additionalProperties?: boolean;
|
|
22
27
|
dynamic?: boolean;
|
|
23
28
|
normalize?: boolean;
|
|
24
29
|
}) => T extends TSchema ? TypeCheck<TSchema> : undefined;
|
|
25
|
-
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, dynamic, normalize, additionalProperties }: {
|
|
30
|
+
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, dynamic, normalize, additionalProperties, }: {
|
|
26
31
|
models?: Record<string, TSchema>;
|
|
27
32
|
additionalProperties?: boolean;
|
|
28
33
|
dynamic?: boolean;
|
|
@@ -210,5 +215,12 @@ export declare const cloneInference: (inference: {
|
|
|
210
215
|
* @param url URL to redirect to
|
|
211
216
|
* @param HTTP status code to send,
|
|
212
217
|
*/
|
|
213
|
-
export declare const redirect: (url: string, status?:
|
|
218
|
+
export declare const redirect: (url: string, status?: 301 | 302 | 303 | 307 | 308) => import("undici-types").Response;
|
|
214
219
|
export type redirect = typeof redirect;
|
|
220
|
+
export declare const ELYSIA_FORM_DATA: unique symbol;
|
|
221
|
+
export type ELYSIA_FORM_DATA = typeof ELYSIA_FORM_DATA;
|
|
222
|
+
type ElysiaFormData<T extends Record<string | number, unknown>> = FormData & {
|
|
223
|
+
[ELYSIA_FORM_DATA]: Replace<T, BunFile, File>;
|
|
224
|
+
};
|
|
225
|
+
export declare const form: <const T extends Record<string | number, unknown>>(items: T) => ElysiaFormData<T>;
|
|
226
|
+
export {};
|