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/index.mjs
CHANGED
|
@@ -353,8 +353,10 @@ var separateFunction = (code) => {
|
|
|
353
353
|
}
|
|
354
354
|
const start = code.indexOf("(");
|
|
355
355
|
if (start !== -1) {
|
|
356
|
-
const
|
|
356
|
+
const sep = code.indexOf("\n", 2);
|
|
357
|
+
const parameter = code.slice(0, sep);
|
|
357
358
|
const end = parameter.lastIndexOf(")") + 1;
|
|
359
|
+
const body = code.slice(sep + 1);
|
|
358
360
|
return [
|
|
359
361
|
parameter.slice(start, end),
|
|
360
362
|
"{" + body,
|
|
@@ -634,6 +636,8 @@ var validateInferencedQueries = (queries) => {
|
|
|
634
636
|
return false;
|
|
635
637
|
if (query.indexOf(" ") !== -1)
|
|
636
638
|
return false;
|
|
639
|
+
if (query.indexOf("(") !== -1)
|
|
640
|
+
return false;
|
|
637
641
|
}
|
|
638
642
|
return true;
|
|
639
643
|
};
|
|
@@ -995,6 +999,12 @@ var parseCookie = async (set, cookieString, {
|
|
|
995
999
|
throw new InvalidCookieSignature(name);
|
|
996
1000
|
}
|
|
997
1001
|
}
|
|
1002
|
+
if (value == null) {
|
|
1003
|
+
jar[name] = {
|
|
1004
|
+
value: v
|
|
1005
|
+
};
|
|
1006
|
+
continue;
|
|
1007
|
+
}
|
|
998
1008
|
const start = value.charCodeAt(0);
|
|
999
1009
|
if (start === 123 || start === 91)
|
|
1000
1010
|
try {
|
|
@@ -1135,9 +1145,21 @@ var mapResponse = (response, set, request) => {
|
|
|
1135
1145
|
return new Response(response, set);
|
|
1136
1146
|
case "Blob":
|
|
1137
1147
|
return handleFile(response, set);
|
|
1138
|
-
case "Object":
|
|
1139
1148
|
case "Array":
|
|
1140
1149
|
return Response.json(response, set);
|
|
1150
|
+
case "Object":
|
|
1151
|
+
for (const value in Object.values(response)) {
|
|
1152
|
+
switch (value?.constructor?.name) {
|
|
1153
|
+
case "Blob":
|
|
1154
|
+
case "File":
|
|
1155
|
+
case "ArrayBuffer":
|
|
1156
|
+
case "FileRef":
|
|
1157
|
+
return new Response(form(response));
|
|
1158
|
+
default:
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
return Response.json(response, set);
|
|
1141
1163
|
case "ReadableStream":
|
|
1142
1164
|
if (!set.headers["content-type"]?.startsWith(
|
|
1143
1165
|
"text/event-stream"
|
|
@@ -1211,6 +1233,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1211
1233
|
if (response instanceof Cookie)
|
|
1212
1234
|
return new Response(response.value, set);
|
|
1213
1235
|
return new Response(response?.toString(), set);
|
|
1236
|
+
case "FormData":
|
|
1237
|
+
return new Response(response, set);
|
|
1214
1238
|
default:
|
|
1215
1239
|
if (response instanceof Response) {
|
|
1216
1240
|
let isCookieSet2 = false;
|
|
@@ -1251,6 +1275,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1251
1275
|
return response.then((x) => mapResponse(x, set));
|
|
1252
1276
|
if (response instanceof Error)
|
|
1253
1277
|
return errorToResponse(response, set);
|
|
1278
|
+
if ("toResponse" in response)
|
|
1279
|
+
return mapResponse(response.toResponse(), set);
|
|
1254
1280
|
if ("charCodeAt" in response) {
|
|
1255
1281
|
const code = response.charCodeAt(0);
|
|
1256
1282
|
if (code === 123 || code === 91) {
|
|
@@ -1270,13 +1296,24 @@ var mapResponse = (response, set, request) => {
|
|
|
1270
1296
|
return new Response(response);
|
|
1271
1297
|
case "Blob":
|
|
1272
1298
|
return handleFile(response, set);
|
|
1273
|
-
case "Object":
|
|
1274
1299
|
case "Array":
|
|
1275
|
-
return
|
|
1276
|
-
|
|
1277
|
-
|
|
1300
|
+
return Response.json(response);
|
|
1301
|
+
case "Object":
|
|
1302
|
+
for (const value in Object.values(response)) {
|
|
1303
|
+
switch (value?.constructor?.name) {
|
|
1304
|
+
case "Blob":
|
|
1305
|
+
case "File":
|
|
1306
|
+
case "ArrayBuffer":
|
|
1307
|
+
case "FileRef":
|
|
1308
|
+
return new Response(
|
|
1309
|
+
form(response),
|
|
1310
|
+
set
|
|
1311
|
+
);
|
|
1312
|
+
default:
|
|
1313
|
+
break;
|
|
1278
1314
|
}
|
|
1279
|
-
}
|
|
1315
|
+
}
|
|
1316
|
+
return Response.json(response, set);
|
|
1280
1317
|
case "ReadableStream":
|
|
1281
1318
|
request?.signal.addEventListener(
|
|
1282
1319
|
"abort",
|
|
@@ -1323,6 +1360,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1323
1360
|
if (response instanceof Cookie)
|
|
1324
1361
|
return new Response(response.value, set);
|
|
1325
1362
|
return new Response(response?.toString(), set);
|
|
1363
|
+
case "FormData":
|
|
1364
|
+
return new Response(response, set);
|
|
1326
1365
|
default:
|
|
1327
1366
|
if (response instanceof Response)
|
|
1328
1367
|
return new Response(response.body, {
|
|
@@ -1334,6 +1373,8 @@ var mapResponse = (response, set, request) => {
|
|
|
1334
1373
|
return response.then((x) => mapResponse(x, set));
|
|
1335
1374
|
if (response instanceof Error)
|
|
1336
1375
|
return errorToResponse(response, set);
|
|
1376
|
+
if ("toResponse" in response)
|
|
1377
|
+
return mapResponse(response.toResponse(), set);
|
|
1337
1378
|
if ("charCodeAt" in response) {
|
|
1338
1379
|
const code = response.charCodeAt(0);
|
|
1339
1380
|
if (code === 123 || code === 91) {
|
|
@@ -1377,9 +1418,24 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1377
1418
|
return new Response(response, set);
|
|
1378
1419
|
case "Blob":
|
|
1379
1420
|
return handleFile(response, set);
|
|
1380
|
-
case "Object":
|
|
1381
1421
|
case "Array":
|
|
1382
1422
|
return Response.json(response, set);
|
|
1423
|
+
case "Object":
|
|
1424
|
+
for (const value in Object.values(response)) {
|
|
1425
|
+
switch (value?.constructor?.name) {
|
|
1426
|
+
case "Blob":
|
|
1427
|
+
case "File":
|
|
1428
|
+
case "ArrayBuffer":
|
|
1429
|
+
case "FileRef":
|
|
1430
|
+
return new Response(
|
|
1431
|
+
form(response),
|
|
1432
|
+
set
|
|
1433
|
+
);
|
|
1434
|
+
default:
|
|
1435
|
+
break;
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
return Response.json(response, set);
|
|
1383
1439
|
case "ReadableStream":
|
|
1384
1440
|
if (!set.headers["content-type"]?.startsWith(
|
|
1385
1441
|
"text/event-stream"
|
|
@@ -1451,6 +1507,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1451
1507
|
response.toString(),
|
|
1452
1508
|
set
|
|
1453
1509
|
);
|
|
1510
|
+
case "FormData":
|
|
1511
|
+
return new Response(response);
|
|
1454
1512
|
case "Cookie":
|
|
1455
1513
|
if (response instanceof Cookie)
|
|
1456
1514
|
return new Response(response.value, set);
|
|
@@ -1491,6 +1549,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1491
1549
|
return response.then((x) => mapEarlyResponse(x, set));
|
|
1492
1550
|
if (response instanceof Error)
|
|
1493
1551
|
return errorToResponse(response, set);
|
|
1552
|
+
if ("toResponse" in response)
|
|
1553
|
+
return mapEarlyResponse(response.toResponse(), set);
|
|
1494
1554
|
if ("charCodeAt" in response) {
|
|
1495
1555
|
const code = response.charCodeAt(0);
|
|
1496
1556
|
if (code === 123 || code === 91) {
|
|
@@ -1510,13 +1570,24 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1510
1570
|
return new Response(response);
|
|
1511
1571
|
case "Blob":
|
|
1512
1572
|
return handleFile(response, set);
|
|
1513
|
-
case "Object":
|
|
1514
1573
|
case "Array":
|
|
1515
|
-
return
|
|
1516
|
-
|
|
1517
|
-
|
|
1574
|
+
return Response.json(response);
|
|
1575
|
+
case "Object":
|
|
1576
|
+
for (const value in Object.values(response)) {
|
|
1577
|
+
switch (value?.constructor?.name) {
|
|
1578
|
+
case "Blob":
|
|
1579
|
+
case "File":
|
|
1580
|
+
case "ArrayBuffer":
|
|
1581
|
+
case "FileRef":
|
|
1582
|
+
return new Response(
|
|
1583
|
+
form(response),
|
|
1584
|
+
set
|
|
1585
|
+
);
|
|
1586
|
+
default:
|
|
1587
|
+
break;
|
|
1518
1588
|
}
|
|
1519
|
-
}
|
|
1589
|
+
}
|
|
1590
|
+
return Response.json(response, set);
|
|
1520
1591
|
case "ReadableStream":
|
|
1521
1592
|
request?.signal.addEventListener(
|
|
1522
1593
|
"abort",
|
|
@@ -1562,6 +1633,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1562
1633
|
if (response instanceof Cookie)
|
|
1563
1634
|
return new Response(response.value, set);
|
|
1564
1635
|
return new Response(response?.toString(), set);
|
|
1636
|
+
case "FormData":
|
|
1637
|
+
return new Response(response);
|
|
1565
1638
|
default:
|
|
1566
1639
|
if (response instanceof Response)
|
|
1567
1640
|
return new Response(response.body, {
|
|
@@ -1573,6 +1646,8 @@ var mapEarlyResponse = (response, set, request) => {
|
|
|
1573
1646
|
return response.then((x) => mapEarlyResponse(x, set));
|
|
1574
1647
|
if (response instanceof Error)
|
|
1575
1648
|
return errorToResponse(response, set);
|
|
1649
|
+
if ("toResponse" in response)
|
|
1650
|
+
return mapEarlyResponse(response.toResponse(), set);
|
|
1576
1651
|
if ("charCodeAt" in response) {
|
|
1577
1652
|
const code = response.charCodeAt(0);
|
|
1578
1653
|
if (code === 123 || code === 91) {
|
|
@@ -1601,13 +1676,23 @@ var mapCompactResponse = (response, request) => {
|
|
|
1601
1676
|
return new Response(response);
|
|
1602
1677
|
case "Blob":
|
|
1603
1678
|
return handleFile(response);
|
|
1604
|
-
case "Object":
|
|
1605
1679
|
case "Array":
|
|
1606
|
-
return
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1680
|
+
return Response.json(response);
|
|
1681
|
+
case "Object":
|
|
1682
|
+
form:
|
|
1683
|
+
for (const value of Object.values(response))
|
|
1684
|
+
switch (value?.constructor?.name) {
|
|
1685
|
+
case "Blob":
|
|
1686
|
+
case "File":
|
|
1687
|
+
case "ArrayBuffer":
|
|
1688
|
+
case "FileRef":
|
|
1689
|
+
return new Response(form(response));
|
|
1690
|
+
case "Object":
|
|
1691
|
+
break form;
|
|
1692
|
+
default:
|
|
1693
|
+
break;
|
|
1694
|
+
}
|
|
1695
|
+
return Response.json(response);
|
|
1611
1696
|
case "ReadableStream":
|
|
1612
1697
|
request?.signal.addEventListener(
|
|
1613
1698
|
"abort",
|
|
@@ -1647,6 +1732,8 @@ var mapCompactResponse = (response, request) => {
|
|
|
1647
1732
|
case "Number":
|
|
1648
1733
|
case "Boolean":
|
|
1649
1734
|
return new Response(response.toString());
|
|
1735
|
+
case "FormData":
|
|
1736
|
+
return new Response(response);
|
|
1650
1737
|
default:
|
|
1651
1738
|
if (response instanceof Response)
|
|
1652
1739
|
return new Response(response.body, {
|
|
@@ -1658,6 +1745,8 @@ var mapCompactResponse = (response, request) => {
|
|
|
1658
1745
|
return response.then(mapCompactResponse);
|
|
1659
1746
|
if (response instanceof Error)
|
|
1660
1747
|
return errorToResponse(response);
|
|
1748
|
+
if ("toResponse" in response)
|
|
1749
|
+
return mapCompactResponse(response.toResponse());
|
|
1661
1750
|
if ("charCodeAt" in response) {
|
|
1662
1751
|
const code = response.charCodeAt(0);
|
|
1663
1752
|
if (code === 123 || code === 91) {
|
|
@@ -1814,7 +1903,7 @@ var getSchemaValidator = (s, {
|
|
|
1814
1903
|
models = {},
|
|
1815
1904
|
dynamic = false,
|
|
1816
1905
|
normalize = false,
|
|
1817
|
-
additionalProperties =
|
|
1906
|
+
additionalProperties = false
|
|
1818
1907
|
} = {}) => {
|
|
1819
1908
|
if (!s)
|
|
1820
1909
|
return void 0;
|
|
@@ -1835,7 +1924,7 @@ var getSchemaValidator = (s, {
|
|
|
1835
1924
|
Errors: (value) => Value.Errors(schema, value),
|
|
1836
1925
|
Code: () => ""
|
|
1837
1926
|
};
|
|
1838
|
-
if (normalize && schema.additionalProperties ===
|
|
1927
|
+
if (normalize && schema.additionalProperties === false)
|
|
1839
1928
|
validator.Clean = cleaner;
|
|
1840
1929
|
if (schema.config) {
|
|
1841
1930
|
validator.config = schema.config;
|
|
@@ -1857,7 +1946,7 @@ var getResponseSchemaValidator = (s, {
|
|
|
1857
1946
|
models = {},
|
|
1858
1947
|
dynamic = false,
|
|
1859
1948
|
normalize = false,
|
|
1860
|
-
additionalProperties =
|
|
1949
|
+
additionalProperties = false
|
|
1861
1950
|
}) => {
|
|
1862
1951
|
if (!s)
|
|
1863
1952
|
return;
|
|
@@ -1878,7 +1967,7 @@ var getResponseSchemaValidator = (s, {
|
|
|
1878
1967
|
Code: () => ""
|
|
1879
1968
|
};
|
|
1880
1969
|
const compiledValidator = TypeCompiler.Compile(schema, references);
|
|
1881
|
-
if (normalize && schema.additionalProperties ===
|
|
1970
|
+
if (normalize && schema.additionalProperties === false)
|
|
1882
1971
|
compiledValidator.Clean = cleaner;
|
|
1883
1972
|
return compiledValidator;
|
|
1884
1973
|
};
|
|
@@ -2365,12 +2454,25 @@ var cloneInference = (inference) => ({
|
|
|
2365
2454
|
set: inference.trace.set
|
|
2366
2455
|
}
|
|
2367
2456
|
});
|
|
2368
|
-
var redirect = (url, status = 301) =>
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2457
|
+
var redirect = (url, status = 301) => Response.redirect(url, status);
|
|
2458
|
+
var ELYSIA_FORM_DATA = Symbol("ElysiaFormData");
|
|
2459
|
+
var form = (items) => {
|
|
2460
|
+
const formData = new FormData();
|
|
2461
|
+
for (const [key, value] of Object.entries(items)) {
|
|
2462
|
+
if (Array.isArray(value)) {
|
|
2463
|
+
for (const v of value) {
|
|
2464
|
+
if (value instanceof File)
|
|
2465
|
+
formData.append(key, value, value.name);
|
|
2466
|
+
formData.append(key, v);
|
|
2467
|
+
}
|
|
2468
|
+
continue;
|
|
2469
|
+
}
|
|
2470
|
+
if (value instanceof File)
|
|
2471
|
+
formData.append(key, value, value.name);
|
|
2472
|
+
formData.append(key, value);
|
|
2372
2473
|
}
|
|
2373
|
-
|
|
2474
|
+
return formData;
|
|
2475
|
+
};
|
|
2374
2476
|
|
|
2375
2477
|
// src/error.ts
|
|
2376
2478
|
var env = typeof Bun !== "undefined" ? Bun.env : typeof process !== "undefined" ? process?.env : void 0;
|
|
@@ -3161,7 +3263,7 @@ const traceDone = Promise.all([`;
|
|
|
3161
3263
|
if (validator) {
|
|
3162
3264
|
fnLiteral += "\n";
|
|
3163
3265
|
if (validator.headers) {
|
|
3164
|
-
if (hasProperty("default", validator.headers.
|
|
3266
|
+
if (hasProperty("default", validator.headers.schema))
|
|
3165
3267
|
for (const [key, value] of Object.entries(
|
|
3166
3268
|
Value3.Default(
|
|
3167
3269
|
// @ts-ignore
|
|
@@ -3169,7 +3271,7 @@ const traceDone = Promise.all([`;
|
|
|
3169
3271
|
{}
|
|
3170
3272
|
)
|
|
3171
3273
|
)) {
|
|
3172
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3274
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3173
3275
|
if (parsed)
|
|
3174
3276
|
fnLiteral += `c.headers['${key}'] ??= ${parsed}
|
|
3175
3277
|
`;
|
|
@@ -3191,7 +3293,7 @@ c.headers = headers.Decode(c.headers)
|
|
|
3191
3293
|
{}
|
|
3192
3294
|
)
|
|
3193
3295
|
)) {
|
|
3194
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3296
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3195
3297
|
if (parsed)
|
|
3196
3298
|
fnLiteral += `c.params['${key}'] ??= ${parsed}
|
|
3197
3299
|
`;
|
|
@@ -3215,11 +3317,26 @@ c.params = params.Decode(c.params)
|
|
|
3215
3317
|
{}
|
|
3216
3318
|
)
|
|
3217
3319
|
)) {
|
|
3218
|
-
const parsed = typeof value === "object" ? JSON.stringify(value) : `'${value}'
|
|
3320
|
+
const parsed = typeof value === "object" ? JSON.stringify(value) : typeof value === "string" ? `'${value}'` : value;
|
|
3219
3321
|
if (parsed)
|
|
3220
3322
|
fnLiteral += `c.query['${key}'] ??= ${parsed}
|
|
3221
3323
|
`;
|
|
3222
3324
|
}
|
|
3325
|
+
for (const [key, value] of Object.entries(
|
|
3326
|
+
// @ts-ignore
|
|
3327
|
+
validator.query.schema?.properties
|
|
3328
|
+
)) {
|
|
3329
|
+
const { type, anyOf } = value;
|
|
3330
|
+
if (type === "object" || type === "array") {
|
|
3331
|
+
fnLiteral += `c.query['${key}'] = JSON.parse(c.query['${key}'])
|
|
3332
|
+
`;
|
|
3333
|
+
continue;
|
|
3334
|
+
}
|
|
3335
|
+
if (anyOf) {
|
|
3336
|
+
fnLiteral += `if(typeof c.query['${key}'] === "object") c.query['${key}'] = JSON.parse(c.query['${key}'])
|
|
3337
|
+
`;
|
|
3338
|
+
}
|
|
3339
|
+
}
|
|
3223
3340
|
fnLiteral += `if(query.Check(c.query) === false) {
|
|
3224
3341
|
${composeValidation("query")}
|
|
3225
3342
|
}`;
|
|
@@ -3231,21 +3348,32 @@ c.query = query.Decode(Object.assign({}, c.query))
|
|
|
3231
3348
|
if (validator.body) {
|
|
3232
3349
|
if (normalize)
|
|
3233
3350
|
fnLiteral += "c.body = body.Clean(c.body);\n";
|
|
3234
|
-
if (hasProperty("default", validator.body.schema))
|
|
3351
|
+
if (hasProperty("default", validator.body.schema)) {
|
|
3235
3352
|
fnLiteral += `if(body.Check(c.body) === false) {
|
|
3236
|
-
|
|
3353
|
+
if (typeof c.body === 'object') {
|
|
3354
|
+
c.body = Object.assign(${JSON.stringify(
|
|
3237
3355
|
Value3.Default(
|
|
3238
3356
|
// @ts-ignore
|
|
3239
3357
|
validator.body.schema,
|
|
3240
|
-
|
|
3358
|
+
{}
|
|
3241
3359
|
) ?? {}
|
|
3242
3360
|
)}, c.body)
|
|
3243
|
-
|
|
3244
|
-
|
|
3361
|
+
} else {`;
|
|
3362
|
+
const defaultValue = Value3.Default(
|
|
3363
|
+
// @ts-ignore
|
|
3364
|
+
validator.body.schema,
|
|
3365
|
+
void 0
|
|
3366
|
+
);
|
|
3367
|
+
if (typeof defaultValue === "string")
|
|
3368
|
+
fnLiteral += `c.body = '${defaultValue}'`;
|
|
3369
|
+
else
|
|
3370
|
+
fnLiteral += `c.body = ${defaultValue}`;
|
|
3371
|
+
fnLiteral += `}
|
|
3372
|
+
if(body.Check(c.body) === false) {
|
|
3245
3373
|
${composeValidation("body")}
|
|
3246
3374
|
}
|
|
3247
3375
|
}`;
|
|
3248
|
-
else
|
|
3376
|
+
} else
|
|
3249
3377
|
fnLiteral += `if(body.Check(c.body) === false) {
|
|
3250
3378
|
${composeValidation("body")}
|
|
3251
3379
|
}`;
|
|
@@ -3254,7 +3382,11 @@ c.query = query.Decode(Object.assign({}, c.query))
|
|
|
3254
3382
|
c.body = body.Decode(c.body)
|
|
3255
3383
|
`;
|
|
3256
3384
|
}
|
|
3257
|
-
if (isNotEmpty(
|
|
3385
|
+
if (isNotEmpty(
|
|
3386
|
+
// @ts-ignore
|
|
3387
|
+
cookieValidator?.schema?.properties ?? // @ts-ignore
|
|
3388
|
+
cookieValidator?.schema?.schema ?? {}
|
|
3389
|
+
)) {
|
|
3258
3390
|
fnLiteral += `const cookieValue = {}
|
|
3259
3391
|
for(const [key, value] of Object.entries(c.cookie))
|
|
3260
3392
|
cookieValue[key] = value.value
|
|
@@ -4034,11 +4166,11 @@ var createDynamicHandler = (app) => async (request) => {
|
|
|
4034
4166
|
break;
|
|
4035
4167
|
case "multipart/form-data":
|
|
4036
4168
|
body = {};
|
|
4037
|
-
const
|
|
4038
|
-
for (const key of
|
|
4169
|
+
const form2 = await request.formData();
|
|
4170
|
+
for (const key of form2.keys()) {
|
|
4039
4171
|
if (body[key])
|
|
4040
4172
|
continue;
|
|
4041
|
-
const value =
|
|
4173
|
+
const value = form2.getAll(key);
|
|
4042
4174
|
if (value.length === 1)
|
|
4043
4175
|
body[key] = value[0];
|
|
4044
4176
|
else
|
|
@@ -4080,11 +4212,11 @@ var createDynamicHandler = (app) => async (request) => {
|
|
|
4080
4212
|
break;
|
|
4081
4213
|
case "multipart/form-data":
|
|
4082
4214
|
body = {};
|
|
4083
|
-
const
|
|
4084
|
-
for (const key of
|
|
4215
|
+
const form2 = await request.formData();
|
|
4216
|
+
for (const key of form2.keys()) {
|
|
4085
4217
|
if (body[key])
|
|
4086
4218
|
continue;
|
|
4087
|
-
const value =
|
|
4219
|
+
const value = form2.getAll(key);
|
|
4088
4220
|
if (value.length === 1)
|
|
4089
4221
|
body[key] = value[0];
|
|
4090
4222
|
else
|
|
@@ -4484,7 +4616,7 @@ var validateFile = (options, value) => {
|
|
|
4484
4616
|
}
|
|
4485
4617
|
return true;
|
|
4486
4618
|
};
|
|
4487
|
-
var
|
|
4619
|
+
var File2 = TypeRegistry.Get("Files") ?? TypeSystem.Type("File", validateFile);
|
|
4488
4620
|
var Files = TypeRegistry.Get("Files") ?? TypeSystem.Type(
|
|
4489
4621
|
"Files",
|
|
4490
4622
|
(options, value) => {
|
|
@@ -4630,7 +4762,7 @@ var ElysiaType = {
|
|
|
4630
4762
|
return JSON.stringify(value);
|
|
4631
4763
|
});
|
|
4632
4764
|
},
|
|
4633
|
-
File,
|
|
4765
|
+
File: File2,
|
|
4634
4766
|
Files: (options = {}) => t2.Transform(Files(options)).Decode((value) => {
|
|
4635
4767
|
if (Array.isArray(value))
|
|
4636
4768
|
return value;
|
|
@@ -4911,8 +5043,11 @@ var Elysia = class _Elysia {
|
|
|
4911
5043
|
aot: true,
|
|
4912
5044
|
strictPath: false,
|
|
4913
5045
|
global: false,
|
|
4914
|
-
cookie: {
|
|
5046
|
+
cookie: {
|
|
5047
|
+
path: "/"
|
|
5048
|
+
},
|
|
4915
5049
|
analytic: false,
|
|
5050
|
+
forceDynamicQuery: true,
|
|
4916
5051
|
...config,
|
|
4917
5052
|
experimental: config?.experimental ?? {},
|
|
4918
5053
|
seed: config?.seed === void 0 ? "" : config?.seed
|
|
@@ -6592,6 +6727,7 @@ export {
|
|
|
6592
6727
|
ValidationError,
|
|
6593
6728
|
Elysia as default,
|
|
6594
6729
|
error,
|
|
6730
|
+
form,
|
|
6595
6731
|
getResponseSchemaValidator,
|
|
6596
6732
|
getSchemaValidator,
|
|
6597
6733
|
mapCompactResponse,
|
package/dist/sucrose.mjs
CHANGED
|
@@ -32,8 +32,10 @@ var separateFunction = (code) => {
|
|
|
32
32
|
}
|
|
33
33
|
const start = code.indexOf("(");
|
|
34
34
|
if (start !== -1) {
|
|
35
|
-
const
|
|
35
|
+
const sep = code.indexOf("\n", 2);
|
|
36
|
+
const parameter = code.slice(0, sep);
|
|
36
37
|
const end = parameter.lastIndexOf(")") + 1;
|
|
38
|
+
const body = code.slice(sep + 1);
|
|
37
39
|
return [
|
|
38
40
|
parameter.slice(start, end),
|
|
39
41
|
"{" + body,
|
|
@@ -313,6 +315,8 @@ var validateInferencedQueries = (queries) => {
|
|
|
313
315
|
return false;
|
|
314
316
|
if (query.indexOf(" ") !== -1)
|
|
315
317
|
return false;
|
|
318
|
+
if (query.indexOf("(") !== -1)
|
|
319
|
+
return false;
|
|
316
320
|
}
|
|
317
321
|
return true;
|
|
318
322
|
};
|
package/dist/type-system.mjs
CHANGED
|
@@ -262,6 +262,7 @@ var InvertedStatusMap = Object.fromEntries(
|
|
|
262
262
|
Object.entries(StatusMap).map(([k, v]) => [v, k])
|
|
263
263
|
);
|
|
264
264
|
var encoder = new TextEncoder();
|
|
265
|
+
var ELYSIA_FORM_DATA = Symbol("ElysiaFormData");
|
|
265
266
|
|
|
266
267
|
// src/error.ts
|
|
267
268
|
var env = typeof Bun !== "undefined" ? Bun.env : typeof process !== "undefined" ? process?.env : void 0;
|
|
@@ -427,7 +428,7 @@ var validateFile = (options, value) => {
|
|
|
427
428
|
}
|
|
428
429
|
return true;
|
|
429
430
|
};
|
|
430
|
-
var
|
|
431
|
+
var File2 = TypeRegistry.Get("Files") ?? TypeSystem.Type("File", validateFile);
|
|
431
432
|
var Files = TypeRegistry.Get("Files") ?? TypeSystem.Type(
|
|
432
433
|
"Files",
|
|
433
434
|
(options, value) => {
|
|
@@ -573,7 +574,7 @@ var ElysiaType = {
|
|
|
573
574
|
return JSON.stringify(value);
|
|
574
575
|
});
|
|
575
576
|
},
|
|
576
|
-
File,
|
|
577
|
+
File: File2,
|
|
577
578
|
Files: (options = {}) => t.Transform(Files(options)).Decode((value) => {
|
|
578
579
|
if (Array.isArray(value))
|
|
579
580
|
return value;
|
package/dist/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/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 {};
|