balda-js 0.0.43 → 0.0.44
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/lib/index.cjs +110 -25
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +8 -4
- package/lib/index.d.ts +8 -4
- package/lib/index.js +110 -25
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.cjs
CHANGED
|
@@ -6,7 +6,7 @@ var path = require('path');
|
|
|
6
6
|
var Ajv = require('ajv');
|
|
7
7
|
var addFormats = require('ajv-formats');
|
|
8
8
|
var zod = require('zod');
|
|
9
|
-
var fs = require('fs
|
|
9
|
+
var fs = require('fs');
|
|
10
10
|
var http = require('http');
|
|
11
11
|
|
|
12
12
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
@@ -2411,14 +2411,14 @@ var RouteNotFoundError = class extends BaldaError {
|
|
|
2411
2411
|
}
|
|
2412
2412
|
};
|
|
2413
2413
|
var NativeFile = class {
|
|
2414
|
-
|
|
2414
|
+
file(path2, options) {
|
|
2415
2415
|
switch (runtime.type) {
|
|
2416
|
+
// We do not use Bun api since we need this operation to be sync
|
|
2416
2417
|
case "bun":
|
|
2417
|
-
return Bun.file(path2).arrayBuffer();
|
|
2418
2418
|
case "node":
|
|
2419
|
-
return fs__default.default.
|
|
2419
|
+
return fs__default.default.readFileSync(path2, options);
|
|
2420
2420
|
case "deno":
|
|
2421
|
-
return Deno.
|
|
2421
|
+
return Deno.readFileSync(path2);
|
|
2422
2422
|
default:
|
|
2423
2423
|
throw new Error("Unsupported runtime");
|
|
2424
2424
|
}
|
|
@@ -2428,22 +2428,115 @@ var nativeFile = new NativeFile();
|
|
|
2428
2428
|
|
|
2429
2429
|
// src/plugins/static/static_constants.ts
|
|
2430
2430
|
var mimeTypes = /* @__PURE__ */ new Map([
|
|
2431
|
+
// text/web
|
|
2431
2432
|
[".html", "text/html"],
|
|
2433
|
+
[".htm", "text/html"],
|
|
2432
2434
|
[".css", "text/css"],
|
|
2433
2435
|
[".js", "application/javascript"],
|
|
2436
|
+
[".mjs", "application/javascript"],
|
|
2437
|
+
[".cjs", "application/javascript"],
|
|
2438
|
+
[".ts", "application/typescript"],
|
|
2439
|
+
[".jsx", "text/jsx"],
|
|
2440
|
+
[".tsx", "text/tsx"],
|
|
2441
|
+
[".json", "application/json"],
|
|
2442
|
+
[".xml", "application/xml"],
|
|
2443
|
+
[".yaml", "application/yaml"],
|
|
2444
|
+
[".yml", "application/yaml"],
|
|
2445
|
+
[".csv", "text/csv"],
|
|
2446
|
+
[".txt", "text/plain"],
|
|
2447
|
+
[".md", "text/markdown"],
|
|
2448
|
+
[".markdown", "text/markdown"],
|
|
2449
|
+
// image
|
|
2434
2450
|
[".png", "image/png"],
|
|
2435
2451
|
[".jpg", "image/jpeg"],
|
|
2452
|
+
[".jpeg", "image/jpeg"],
|
|
2436
2453
|
[".gif", "image/gif"],
|
|
2437
2454
|
[".svg", "image/svg+xml"],
|
|
2438
|
-
[".json", "application/json"],
|
|
2439
|
-
[".txt", "text/plain"],
|
|
2440
2455
|
[".ico", "image/x-icon"],
|
|
2441
2456
|
[".webp", "image/webp"],
|
|
2457
|
+
[".avif", "image/avif"],
|
|
2458
|
+
[".bmp", "image/bmp"],
|
|
2459
|
+
[".tiff", "image/tiff"],
|
|
2460
|
+
[".tif", "image/tiff"],
|
|
2461
|
+
[".heic", "image/heic"],
|
|
2462
|
+
[".heif", "image/heif"],
|
|
2463
|
+
// video
|
|
2442
2464
|
[".mp4", "video/mp4"],
|
|
2465
|
+
[".webm", "video/webm"],
|
|
2466
|
+
[".avi", "video/x-msvideo"],
|
|
2467
|
+
[".mov", "video/quicktime"],
|
|
2468
|
+
[".mkv", "video/x-matroska"],
|
|
2469
|
+
[".wmv", "video/x-ms-wmv"],
|
|
2470
|
+
[".flv", "video/x-flv"],
|
|
2471
|
+
[".m4v", "video/x-m4v"],
|
|
2472
|
+
[".mpeg", "video/mpeg"],
|
|
2473
|
+
[".mpg", "video/mpeg"],
|
|
2474
|
+
[".3gp", "video/3gpp"],
|
|
2475
|
+
// audio
|
|
2443
2476
|
[".mp3", "audio/mpeg"],
|
|
2444
2477
|
[".wav", "audio/wav"],
|
|
2445
2478
|
[".ogg", "audio/ogg"],
|
|
2446
|
-
[".
|
|
2479
|
+
[".flac", "audio/flac"],
|
|
2480
|
+
[".aac", "audio/aac"],
|
|
2481
|
+
[".m4a", "audio/mp4"],
|
|
2482
|
+
[".wma", "audio/x-ms-wma"],
|
|
2483
|
+
[".opus", "audio/opus"],
|
|
2484
|
+
[".mid", "audio/midi"],
|
|
2485
|
+
[".midi", "audio/midi"],
|
|
2486
|
+
// font
|
|
2487
|
+
[".woff", "font/woff"],
|
|
2488
|
+
[".woff2", "font/woff2"],
|
|
2489
|
+
[".ttf", "font/ttf"],
|
|
2490
|
+
[".otf", "font/otf"],
|
|
2491
|
+
[".eot", "application/vnd.ms-fontobject"],
|
|
2492
|
+
// document
|
|
2493
|
+
[".pdf", "application/pdf"],
|
|
2494
|
+
[".doc", "application/msword"],
|
|
2495
|
+
[
|
|
2496
|
+
".docx",
|
|
2497
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
|
2498
|
+
],
|
|
2499
|
+
[".xls", "application/vnd.ms-excel"],
|
|
2500
|
+
[
|
|
2501
|
+
".xlsx",
|
|
2502
|
+
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
2503
|
+
],
|
|
2504
|
+
[".ppt", "application/vnd.ms-powerpoint"],
|
|
2505
|
+
[
|
|
2506
|
+
".pptx",
|
|
2507
|
+
"application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
|
2508
|
+
],
|
|
2509
|
+
[".odt", "application/vnd.oasis.opendocument.text"],
|
|
2510
|
+
[".ods", "application/vnd.oasis.opendocument.spreadsheet"],
|
|
2511
|
+
[".odp", "application/vnd.oasis.opendocument.presentation"],
|
|
2512
|
+
[".rtf", "application/rtf"],
|
|
2513
|
+
[".epub", "application/epub+zip"],
|
|
2514
|
+
// archives
|
|
2515
|
+
[".zip", "application/zip"],
|
|
2516
|
+
[".tar", "application/x-tar"],
|
|
2517
|
+
[".gz", "application/gzip"],
|
|
2518
|
+
[".gzip", "application/gzip"],
|
|
2519
|
+
[".bz2", "application/x-bzip2"],
|
|
2520
|
+
[".xz", "application/x-xz"],
|
|
2521
|
+
[".rar", "application/vnd.rar"],
|
|
2522
|
+
[".7z", "application/x-7z-compressed"],
|
|
2523
|
+
// other
|
|
2524
|
+
[".wasm", "application/wasm"],
|
|
2525
|
+
[".map", "application/json"],
|
|
2526
|
+
[".webmanifest", "application/manifest+json"],
|
|
2527
|
+
[".ics", "text/calendar"],
|
|
2528
|
+
[".vcf", "text/vcard"],
|
|
2529
|
+
[".sql", "application/sql"],
|
|
2530
|
+
[".sh", "application/x-sh"],
|
|
2531
|
+
[".bat", "application/x-msdos-program"],
|
|
2532
|
+
[".exe", "application/x-msdownload"],
|
|
2533
|
+
[".dll", "application/x-msdownload"],
|
|
2534
|
+
[".bin", "application/octet-stream"],
|
|
2535
|
+
[".iso", "application/x-iso9660-image"],
|
|
2536
|
+
[".dmg", "application/x-apple-diskimage"],
|
|
2537
|
+
[".apk", "application/vnd.android.package-archive"],
|
|
2538
|
+
[".jar", "application/java-archive"],
|
|
2539
|
+
[".swf", "application/x-shockwave-flash"]
|
|
2447
2540
|
]);
|
|
2448
2541
|
|
|
2449
2542
|
// src/plugins/static/static.ts
|
|
@@ -2490,7 +2583,7 @@ async function staticFileHandler(req, res, path2) {
|
|
|
2490
2583
|
}
|
|
2491
2584
|
const contentType = getContentType(nativePath.extName(resolvedPath));
|
|
2492
2585
|
res.setHeader("Content-Type", contentType);
|
|
2493
|
-
const fileContent =
|
|
2586
|
+
const fileContent = nativeFile.file(resolvedPath);
|
|
2494
2587
|
res.raw(fileContent);
|
|
2495
2588
|
}
|
|
2496
2589
|
function getContentType(ext) {
|
|
@@ -2541,13 +2634,7 @@ var Response2 = class {
|
|
|
2541
2634
|
return this.text(body);
|
|
2542
2635
|
}
|
|
2543
2636
|
if (typeof body === "number" || typeof body === "boolean" || typeof body === "bigint") {
|
|
2544
|
-
return this.
|
|
2545
|
-
}
|
|
2546
|
-
if (body instanceof Date) {
|
|
2547
|
-
return this.text(body.toISOString());
|
|
2548
|
-
}
|
|
2549
|
-
if (body instanceof RegExp) {
|
|
2550
|
-
return this.text(body.toString());
|
|
2637
|
+
return this.raw(body);
|
|
2551
2638
|
}
|
|
2552
2639
|
if (typeof Buffer !== "undefined" && body instanceof Buffer) {
|
|
2553
2640
|
return this.download(new Uint8Array(body));
|
|
@@ -2562,9 +2649,6 @@ var Response2 = class {
|
|
|
2562
2649
|
return this.text(String(body));
|
|
2563
2650
|
}
|
|
2564
2651
|
}
|
|
2565
|
-
if (typeof body === "function") {
|
|
2566
|
-
return this.text(body.toString());
|
|
2567
|
-
}
|
|
2568
2652
|
if (typeof body === "symbol") {
|
|
2569
2653
|
return this.text(body.toString());
|
|
2570
2654
|
}
|
|
@@ -2599,8 +2683,8 @@ var Response2 = class {
|
|
|
2599
2683
|
/**
|
|
2600
2684
|
* Send a response with the given HTML, status defaults to 200
|
|
2601
2685
|
*/
|
|
2602
|
-
html(
|
|
2603
|
-
this.body =
|
|
2686
|
+
html(htmlString) {
|
|
2687
|
+
this.body = htmlString;
|
|
2604
2688
|
this.headers = {
|
|
2605
2689
|
...this.headers,
|
|
2606
2690
|
"Content-Type": "text/html"
|
|
@@ -2627,11 +2711,12 @@ var Response2 = class {
|
|
|
2627
2711
|
};
|
|
2628
2712
|
}
|
|
2629
2713
|
/**
|
|
2630
|
-
* Send a response with the given file, status defaults to 200
|
|
2714
|
+
* Send a response with the given file content, status defaults to 200
|
|
2715
|
+
* @param options only affects node and bun environment
|
|
2631
2716
|
*/
|
|
2632
|
-
file(pathToFile) {
|
|
2717
|
+
file(pathToFile, options) {
|
|
2633
2718
|
const mimeType = getContentType(pathToFile);
|
|
2634
|
-
this.body = nativeFile.file(pathToFile);
|
|
2719
|
+
this.body = nativeFile.file(pathToFile, options);
|
|
2635
2720
|
this.headers = {
|
|
2636
2721
|
...this.headers,
|
|
2637
2722
|
"Content-Type": mimeType
|
|
@@ -4815,7 +4900,7 @@ var ServerNode = class {
|
|
|
4815
4900
|
body = body;
|
|
4816
4901
|
} else if (typeof body === "string") {
|
|
4817
4902
|
body = body;
|
|
4818
|
-
} else if (responseResult.headers["Content-Type"] === "application/json") {
|
|
4903
|
+
} else if (responseResult.headers["Content-Type"] === "application/json" && typeof body !== "string") {
|
|
4819
4904
|
body = JSON.stringify(body);
|
|
4820
4905
|
} else {
|
|
4821
4906
|
body = String(body);
|