bun-types 1.2.20-canary.20250731T140826 → 1.2.20-canary.20250802T140550
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/bun.d.ts +58 -76
- package/deprecated.d.ts +57 -1
- package/docs/api/fetch.md +1 -1
- package/docs/api/http.md +64 -0
- package/docs/api/spawn.md +1 -1
- package/docs/api/streams.md +2 -2
- package/docs/cli/pm.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/guides/ecosystem/nuxt.md +1 -1
- package/docs/guides/install/add-peer.md +2 -2
- package/docs/guides/install/from-npm-install-to-bun-install.md +1 -1
- package/docs/guides/test/run-tests.md +3 -3
- package/docs/guides/test/snapshot.md +3 -3
- package/docs/guides/test/update-snapshots.md +1 -1
- package/docs/guides/util/detect-bun.md +1 -1
- package/docs/guides/util/version.md +1 -1
- package/docs/installation.md +4 -4
- package/docs/runtime/debugger.md +3 -3
- package/docs/test/dom.md +1 -1
- package/docs/test/writing.md +51 -3
- package/fetch.d.ts +12 -10
- package/globals.d.ts +5 -5
- package/overrides.d.ts +4 -1
- package/package.json +7 -7
- package/s3.d.ts +2 -2
- package/shell.d.ts +2 -4
- package/sqlite.d.ts +17 -8
- package/test-globals.d.ts +1 -0
- package/test.d.ts +27 -0
- package/vendor/expect-type/branding.d.ts +283 -0
- package/vendor/expect-type/index.d.ts +1207 -0
- package/vendor/expect-type/messages.d.ts +395 -0
- package/vendor/expect-type/overloads.d.ts +669 -0
- package/vendor/expect-type/utils.d.ts +431 -0
package/bun.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare module "bun" {
|
|
|
21
21
|
| DataView<TArrayBuffer>;
|
|
22
22
|
type BufferSource = NodeJS.TypedArray | DataView | ArrayBufferLike;
|
|
23
23
|
type StringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike;
|
|
24
|
-
type XMLHttpRequestBodyInit = Blob | BufferSource |
|
|
24
|
+
type XMLHttpRequestBodyInit = Blob | BufferSource | FormData | URLSearchParams | string;
|
|
25
25
|
type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
|
|
26
26
|
type ReadableStreamDefaultReadResult<T> =
|
|
27
27
|
| ReadableStreamDefaultReadValueResult<T>
|
|
@@ -826,7 +826,7 @@ declare module "bun" {
|
|
|
826
826
|
buffers: Array<ArrayBufferView | ArrayBufferLike>,
|
|
827
827
|
maxLength: number,
|
|
828
828
|
asUint8Array: true,
|
|
829
|
-
): Uint8Array
|
|
829
|
+
): Uint8Array<ArrayBuffer>;
|
|
830
830
|
|
|
831
831
|
/**
|
|
832
832
|
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
@@ -843,35 +843,6 @@ declare module "bun" {
|
|
|
843
843
|
stream: ReadableStream<ArrayBufferView | ArrayBufferLike>,
|
|
844
844
|
): Promise<ArrayBuffer> | ArrayBuffer;
|
|
845
845
|
|
|
846
|
-
/**
|
|
847
|
-
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
848
|
-
*
|
|
849
|
-
* Concatenate the chunks into a single {@link ArrayBuffer}.
|
|
850
|
-
*
|
|
851
|
-
* Each chunk must be a TypedArray or an ArrayBuffer. If you need to support
|
|
852
|
-
* chunks of different types, consider {@link readableStreamToBlob}
|
|
853
|
-
*
|
|
854
|
-
* @param stream The stream to consume.
|
|
855
|
-
* @returns A promise that resolves with the concatenated chunks or the concatenated chunks as a {@link Uint8Array}.
|
|
856
|
-
*
|
|
857
|
-
* @deprecated Use {@link ReadableStream.bytes}
|
|
858
|
-
*/
|
|
859
|
-
function readableStreamToBytes(
|
|
860
|
-
stream: ReadableStream<ArrayBufferView | ArrayBufferLike>,
|
|
861
|
-
): Promise<Uint8Array> | Uint8Array;
|
|
862
|
-
|
|
863
|
-
/**
|
|
864
|
-
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
865
|
-
*
|
|
866
|
-
* Concatenate the chunks into a single {@link Blob}.
|
|
867
|
-
*
|
|
868
|
-
* @param stream The stream to consume.
|
|
869
|
-
* @returns A promise that resolves with the concatenated chunks as a {@link Blob}.
|
|
870
|
-
*
|
|
871
|
-
* @deprecated Use {@link ReadableStream.blob}
|
|
872
|
-
*/
|
|
873
|
-
function readableStreamToBlob(stream: ReadableStream): Promise<Blob>;
|
|
874
|
-
|
|
875
846
|
/**
|
|
876
847
|
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
877
848
|
*
|
|
@@ -904,30 +875,6 @@ declare module "bun" {
|
|
|
904
875
|
multipartBoundaryExcludingDashes?: string | NodeJS.TypedArray | ArrayBufferView,
|
|
905
876
|
): Promise<FormData>;
|
|
906
877
|
|
|
907
|
-
/**
|
|
908
|
-
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
909
|
-
*
|
|
910
|
-
* Concatenate the chunks into a single string. Chunks must be a TypedArray or an ArrayBuffer. If you need to support chunks of different types, consider {@link readableStreamToBlob}.
|
|
911
|
-
*
|
|
912
|
-
* @param stream The stream to consume.
|
|
913
|
-
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
914
|
-
*
|
|
915
|
-
* @deprecated Use {@link ReadableStream.text}
|
|
916
|
-
*/
|
|
917
|
-
function readableStreamToText(stream: ReadableStream): Promise<string>;
|
|
918
|
-
|
|
919
|
-
/**
|
|
920
|
-
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
921
|
-
*
|
|
922
|
-
* Concatenate the chunks into a single string and parse as JSON. Chunks must be a TypedArray or an ArrayBuffer. If you need to support chunks of different types, consider {@link readableStreamToBlob}.
|
|
923
|
-
*
|
|
924
|
-
* @param stream The stream to consume.
|
|
925
|
-
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
926
|
-
*
|
|
927
|
-
* @deprecated Use {@link ReadableStream.json}
|
|
928
|
-
*/
|
|
929
|
-
function readableStreamToJSON(stream: ReadableStream): Promise<any>;
|
|
930
|
-
|
|
931
878
|
/**
|
|
932
879
|
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
933
880
|
*
|
|
@@ -1027,8 +974,8 @@ declare module "bun" {
|
|
|
1027
974
|
*
|
|
1028
975
|
* This API might change later to separate Uint8ArraySink and ArrayBufferSink
|
|
1029
976
|
*/
|
|
1030
|
-
flush(): number | Uint8Array | ArrayBuffer;
|
|
1031
|
-
end(): ArrayBuffer | Uint8Array
|
|
977
|
+
flush(): number | Uint8Array<ArrayBuffer> | ArrayBuffer;
|
|
978
|
+
end(): ArrayBuffer | Uint8Array<ArrayBuffer>;
|
|
1032
979
|
}
|
|
1033
980
|
|
|
1034
981
|
/** DNS Related APIs */
|
|
@@ -1595,13 +1542,18 @@ declare module "bun" {
|
|
|
1595
1542
|
* Executes a SQL query using template literals
|
|
1596
1543
|
* @example
|
|
1597
1544
|
* ```ts
|
|
1598
|
-
* const [user] = await sql
|
|
1545
|
+
* const [user] = await sql<Users[]>`select * from users where id = ${1}`;
|
|
1599
1546
|
* ```
|
|
1600
1547
|
*/
|
|
1601
1548
|
<T = any>(strings: TemplateStringsArray, ...values: unknown[]): SQL.Query<T>;
|
|
1602
1549
|
|
|
1603
1550
|
/**
|
|
1604
1551
|
* Execute a SQL query using a string
|
|
1552
|
+
*
|
|
1553
|
+
* @example
|
|
1554
|
+
* ```ts
|
|
1555
|
+
* const users = await sql<User[]>`SELECT * FROM users WHERE id = ${1}`;
|
|
1556
|
+
* ```
|
|
1605
1557
|
*/
|
|
1606
1558
|
<T = any>(string: string): SQL.Query<T>;
|
|
1607
1559
|
|
|
@@ -1620,6 +1572,23 @@ declare module "bun" {
|
|
|
1620
1572
|
* const result = await sql`insert into users ${sql(user)} returning *`;
|
|
1621
1573
|
* ```
|
|
1622
1574
|
*/
|
|
1575
|
+
<T extends { [Key in PropertyKey]: unknown }>(obj: T | T[] | readonly T[]): SQL.Helper<T>;
|
|
1576
|
+
|
|
1577
|
+
/**
|
|
1578
|
+
* Helper function for inserting an object into a query, supporting specific columns
|
|
1579
|
+
*
|
|
1580
|
+
* @example
|
|
1581
|
+
* ```ts
|
|
1582
|
+
* // Insert an object
|
|
1583
|
+
* const result = await sql`insert into users ${sql(users)} returning *`;
|
|
1584
|
+
*
|
|
1585
|
+
* // Or pick specific columns
|
|
1586
|
+
* const result = await sql`insert into users ${sql(users, "id", "name")} returning *`;
|
|
1587
|
+
*
|
|
1588
|
+
* // Or a single object
|
|
1589
|
+
* const result = await sql`insert into users ${sql(user)} returning *`;
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
1623
1592
|
<T extends { [Key in PropertyKey]: unknown }, Keys extends keyof T = keyof T>(
|
|
1624
1593
|
obj: T | T[] | readonly T[],
|
|
1625
1594
|
...columns: readonly Keys[]
|
|
@@ -3682,7 +3651,7 @@ declare module "bun" {
|
|
|
3682
3651
|
|
|
3683
3652
|
/**
|
|
3684
3653
|
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
3685
|
-
* (Cannot
|
|
3654
|
+
* (Cannot use unix with port + hostname)
|
|
3686
3655
|
*/
|
|
3687
3656
|
unix?: never;
|
|
3688
3657
|
|
|
@@ -3705,9 +3674,21 @@ declare module "bun" {
|
|
|
3705
3674
|
interface UnixServeOptions extends GenericServeOptions {
|
|
3706
3675
|
/**
|
|
3707
3676
|
* If set, the HTTP server will listen on a unix socket instead of a port.
|
|
3708
|
-
* (Cannot be used with hostname+port)
|
|
3709
3677
|
*/
|
|
3710
3678
|
unix: string;
|
|
3679
|
+
|
|
3680
|
+
/**
|
|
3681
|
+
* If set, the HTTP server will listen on this port
|
|
3682
|
+
* (Cannot use port with unix)
|
|
3683
|
+
*/
|
|
3684
|
+
port?: never;
|
|
3685
|
+
|
|
3686
|
+
/**
|
|
3687
|
+
* If set, the HTTP server will listen on this hostname
|
|
3688
|
+
* (Cannot use hostname with unix)
|
|
3689
|
+
*/
|
|
3690
|
+
hostname?: never;
|
|
3691
|
+
|
|
3711
3692
|
/**
|
|
3712
3693
|
* Handle HTTP requests
|
|
3713
3694
|
*
|
|
@@ -4635,7 +4616,7 @@ declare module "bun" {
|
|
|
4635
4616
|
*
|
|
4636
4617
|
* @param path The path to the file as a byte buffer (the buffer is copied) if the path starts with `s3://` it will behave like {@link S3File}
|
|
4637
4618
|
*/
|
|
4638
|
-
function file(path: ArrayBufferLike | Uint8Array
|
|
4619
|
+
function file(path: ArrayBufferLike | Uint8Array<ArrayBuffer>, options?: BlobPropertyBag): BunFile;
|
|
4639
4620
|
|
|
4640
4621
|
/**
|
|
4641
4622
|
* [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files.
|
|
@@ -4658,7 +4639,7 @@ declare module "bun" {
|
|
|
4658
4639
|
*
|
|
4659
4640
|
* This can be 3.5x faster than `new Uint8Array(size)`, but if you send uninitialized memory to your users (even unintentionally), it can potentially leak anything recently in memory.
|
|
4660
4641
|
*/
|
|
4661
|
-
function allocUnsafe(size: number): Uint8Array
|
|
4642
|
+
function allocUnsafe(size: number): Uint8Array<ArrayBuffer>;
|
|
4662
4643
|
|
|
4663
4644
|
/**
|
|
4664
4645
|
* Options for `Bun.inspect`
|
|
@@ -4941,7 +4922,7 @@ declare module "bun" {
|
|
|
4941
4922
|
*
|
|
4942
4923
|
* To close the file, set the array to `null` and it will be garbage collected eventually.
|
|
4943
4924
|
*/
|
|
4944
|
-
function mmap(path: PathLike, opts?: MMapOptions): Uint8Array
|
|
4925
|
+
function mmap(path: PathLike, opts?: MMapOptions): Uint8Array<ArrayBuffer>;
|
|
4945
4926
|
|
|
4946
4927
|
/**
|
|
4947
4928
|
* Write to stdout
|
|
@@ -4971,8 +4952,8 @@ declare module "bun" {
|
|
|
4971
4952
|
| { r: number; g: number; b: number; a?: number }
|
|
4972
4953
|
| [number, number, number]
|
|
4973
4954
|
| [number, number, number, number]
|
|
4974
|
-
| Uint8Array
|
|
4975
|
-
| Uint8ClampedArray
|
|
4955
|
+
| Uint8Array<ArrayBuffer>
|
|
4956
|
+
| Uint8ClampedArray<ArrayBuffer>
|
|
4976
4957
|
| Float32Array
|
|
4977
4958
|
| Float64Array
|
|
4978
4959
|
| string
|
|
@@ -5095,7 +5076,7 @@ declare module "bun" {
|
|
|
5095
5076
|
*
|
|
5096
5077
|
* **The input buffer must not be garbage collected**. That means you will need to hold on to it for the duration of the string's lifetime.
|
|
5097
5078
|
*/
|
|
5098
|
-
function arrayBufferToString(buffer: Uint8Array | ArrayBufferLike): string;
|
|
5079
|
+
function arrayBufferToString(buffer: Uint8Array<ArrayBuffer> | ArrayBufferLike): string;
|
|
5099
5080
|
|
|
5100
5081
|
/**
|
|
5101
5082
|
* Cast bytes to a `String` without copying. This is the fastest way to get a `String` from a `Uint16Array`
|
|
@@ -5644,9 +5625,9 @@ declare module "bun" {
|
|
|
5644
5625
|
* @returns The output buffer with the compressed data
|
|
5645
5626
|
*/
|
|
5646
5627
|
function deflateSync(
|
|
5647
|
-
data: Uint8Array | string | ArrayBuffer,
|
|
5628
|
+
data: Uint8Array<ArrayBuffer> | string | ArrayBuffer,
|
|
5648
5629
|
options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
|
|
5649
|
-
): Uint8Array
|
|
5630
|
+
): Uint8Array<ArrayBuffer>;
|
|
5650
5631
|
/**
|
|
5651
5632
|
* Compresses a chunk of data with `zlib` GZIP algorithm.
|
|
5652
5633
|
* @param data The buffer of data to compress
|
|
@@ -5654,27 +5635,27 @@ declare module "bun" {
|
|
|
5654
5635
|
* @returns The output buffer with the compressed data
|
|
5655
5636
|
*/
|
|
5656
5637
|
function gzipSync(
|
|
5657
|
-
data: Uint8Array | string | ArrayBuffer,
|
|
5638
|
+
data: Uint8Array<ArrayBuffer> | string | ArrayBuffer,
|
|
5658
5639
|
options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
|
|
5659
|
-
): Uint8Array
|
|
5640
|
+
): Uint8Array<ArrayBuffer>;
|
|
5660
5641
|
/**
|
|
5661
5642
|
* Decompresses a chunk of data with `zlib` INFLATE algorithm.
|
|
5662
5643
|
* @param data The buffer of data to decompress
|
|
5663
5644
|
* @returns The output buffer with the decompressed data
|
|
5664
5645
|
*/
|
|
5665
5646
|
function inflateSync(
|
|
5666
|
-
data: Uint8Array | string | ArrayBuffer,
|
|
5647
|
+
data: Uint8Array<ArrayBuffer> | string | ArrayBuffer,
|
|
5667
5648
|
options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
|
|
5668
|
-
): Uint8Array
|
|
5649
|
+
): Uint8Array<ArrayBuffer>;
|
|
5669
5650
|
/**
|
|
5670
5651
|
* Decompresses a chunk of data with `zlib` GUNZIP algorithm.
|
|
5671
5652
|
* @param data The buffer of data to decompress
|
|
5672
5653
|
* @returns The output buffer with the decompressed data
|
|
5673
5654
|
*/
|
|
5674
5655
|
function gunzipSync(
|
|
5675
|
-
data: Uint8Array | string | ArrayBuffer,
|
|
5656
|
+
data: Uint8Array<ArrayBuffer> | string | ArrayBuffer,
|
|
5676
5657
|
options?: ZlibCompressionOptions | LibdeflateCompressionOptions,
|
|
5677
|
-
): Uint8Array
|
|
5658
|
+
): Uint8Array<ArrayBuffer>;
|
|
5678
5659
|
|
|
5679
5660
|
/**
|
|
5680
5661
|
* Compresses a chunk of data with the Zstandard (zstd) compression algorithm.
|
|
@@ -6651,7 +6632,7 @@ declare module "bun" {
|
|
|
6651
6632
|
interface BinaryTypeList {
|
|
6652
6633
|
arraybuffer: ArrayBuffer;
|
|
6653
6634
|
buffer: Buffer;
|
|
6654
|
-
uint8array: Uint8Array
|
|
6635
|
+
uint8array: Uint8Array<ArrayBuffer>;
|
|
6655
6636
|
// TODO: DataView
|
|
6656
6637
|
// dataview: DataView;
|
|
6657
6638
|
}
|
|
@@ -6829,6 +6810,7 @@ declare module "bun" {
|
|
|
6829
6810
|
* The unix socket to listen on or connect to
|
|
6830
6811
|
*/
|
|
6831
6812
|
unix: string;
|
|
6813
|
+
|
|
6832
6814
|
/**
|
|
6833
6815
|
* TLS Configuration with which to create the socket
|
|
6834
6816
|
*/
|
|
@@ -7223,7 +7205,7 @@ declare module "bun" {
|
|
|
7223
7205
|
}
|
|
7224
7206
|
|
|
7225
7207
|
type ReadableToIO<X extends Readable> = X extends "pipe" | undefined
|
|
7226
|
-
? ReadableStream<Uint8Array
|
|
7208
|
+
? ReadableStream<Uint8Array<ArrayBuffer>>
|
|
7227
7209
|
: X extends BunFile | ArrayBufferView | number
|
|
7228
7210
|
? number
|
|
7229
7211
|
: undefined;
|
package/deprecated.d.ts
CHANGED
|
@@ -1,4 +1,57 @@
|
|
|
1
1
|
declare module "bun" {
|
|
2
|
+
/**
|
|
3
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
4
|
+
*
|
|
5
|
+
* Concatenate the chunks into a single {@link ArrayBuffer}.
|
|
6
|
+
*
|
|
7
|
+
* Each chunk must be a TypedArray or an ArrayBuffer. If you need to support
|
|
8
|
+
* chunks of different types, consider {@link readableStreamToBlob}
|
|
9
|
+
*
|
|
10
|
+
* @param stream The stream to consume.
|
|
11
|
+
* @returns A promise that resolves with the concatenated chunks or the concatenated chunks as a {@link Uint8Array}.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Use {@link ReadableStream.bytes}
|
|
14
|
+
*/
|
|
15
|
+
function readableStreamToBytes(
|
|
16
|
+
stream: ReadableStream<ArrayBufferView | ArrayBufferLike>,
|
|
17
|
+
): Promise<Uint8Array<ArrayBuffer>> | Uint8Array<ArrayBuffer>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
21
|
+
*
|
|
22
|
+
* Concatenate the chunks into a single {@link Blob}.
|
|
23
|
+
*
|
|
24
|
+
* @param stream The stream to consume.
|
|
25
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link Blob}.
|
|
26
|
+
*
|
|
27
|
+
* @deprecated Use {@link ReadableStream.blob}
|
|
28
|
+
*/
|
|
29
|
+
function readableStreamToBlob(stream: ReadableStream): Promise<Blob>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
33
|
+
*
|
|
34
|
+
* Concatenate the chunks into a single string. Chunks must be a TypedArray or an ArrayBuffer. If you need to support chunks of different types, consider {@link readableStreamToBlob}.
|
|
35
|
+
*
|
|
36
|
+
* @param stream The stream to consume.
|
|
37
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
38
|
+
*
|
|
39
|
+
* @deprecated Use {@link ReadableStream.text}
|
|
40
|
+
*/
|
|
41
|
+
function readableStreamToText(stream: ReadableStream): Promise<string>;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
45
|
+
*
|
|
46
|
+
* Concatenate the chunks into a single string and parse as JSON. Chunks must be a TypedArray or an ArrayBuffer. If you need to support chunks of different types, consider {@link readableStreamToBlob}.
|
|
47
|
+
*
|
|
48
|
+
* @param stream The stream to consume.
|
|
49
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Use {@link ReadableStream.json}
|
|
52
|
+
*/
|
|
53
|
+
function readableStreamToJSON(stream: ReadableStream): Promise<any>;
|
|
54
|
+
|
|
2
55
|
interface BunMessageEvent<T> {
|
|
3
56
|
/**
|
|
4
57
|
* @deprecated
|
|
@@ -31,6 +84,9 @@ declare module "bun" {
|
|
|
31
84
|
*/
|
|
32
85
|
type Errorlike = ErrorLike;
|
|
33
86
|
|
|
87
|
+
/** @deprecated This is unused in Bun's types and may be removed in the future */
|
|
88
|
+
type ShellFunction = (input: Uint8Array<ArrayBuffer>) => Uint8Array<ArrayBuffer>;
|
|
89
|
+
|
|
34
90
|
interface TLSOptions {
|
|
35
91
|
/**
|
|
36
92
|
* File path to a TLS key
|
|
@@ -59,7 +115,7 @@ declare module "bun" {
|
|
|
59
115
|
}
|
|
60
116
|
|
|
61
117
|
/** @deprecated This type is unused in Bun's declarations and may be removed in the future */
|
|
62
|
-
type ReadableIO = ReadableStream<Uint8Array
|
|
118
|
+
type ReadableIO = ReadableStream<Uint8Array<ArrayBuffer>> | number | undefined;
|
|
63
119
|
}
|
|
64
120
|
|
|
65
121
|
declare namespace NodeJS {
|
package/docs/api/fetch.md
CHANGED
|
@@ -337,7 +337,7 @@ This will print the request and response headers to your terminal:
|
|
|
337
337
|
```sh
|
|
338
338
|
[fetch] > HTTP/1.1 GET http://example.com/
|
|
339
339
|
[fetch] > Connection: keep-alive
|
|
340
|
-
[fetch] > User-Agent: Bun/1.2.20-canary.
|
|
340
|
+
[fetch] > User-Agent: Bun/1.2.20-canary.20250802T140550
|
|
341
341
|
[fetch] > Accept: */*
|
|
342
342
|
[fetch] > Host: example.com
|
|
343
343
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/api/http.md
CHANGED
|
@@ -164,6 +164,70 @@ Static responses do not allocate additional memory after initialization. You can
|
|
|
164
164
|
|
|
165
165
|
Static route responses are cached for the lifetime of the server object. To reload static routes, call `server.reload(options)`.
|
|
166
166
|
|
|
167
|
+
### File Responses vs Static Responses
|
|
168
|
+
|
|
169
|
+
When serving files in routes, there are two distinct behaviors depending on whether you buffer the file content or serve it directly:
|
|
170
|
+
|
|
171
|
+
```ts
|
|
172
|
+
Bun.serve({
|
|
173
|
+
routes: {
|
|
174
|
+
// Static route - content is buffered in memory at startup
|
|
175
|
+
"/logo.png": new Response(await Bun.file("./logo.png").bytes()),
|
|
176
|
+
|
|
177
|
+
// File route - content is read from filesystem on each request
|
|
178
|
+
"/download.zip": new Response(Bun.file("./download.zip")),
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
**Static routes** (`new Response(await file.bytes())`) buffer content in memory at startup:
|
|
184
|
+
|
|
185
|
+
- **Zero filesystem I/O** during requests - content served entirely from memory
|
|
186
|
+
- **ETag support** - Automatically generates and validates ETags for caching
|
|
187
|
+
- **If-None-Match** - Returns `304 Not Modified` when client ETag matches
|
|
188
|
+
- **No 404 handling** - Missing files cause startup errors, not runtime 404s
|
|
189
|
+
- **Memory usage** - Full file content stored in RAM
|
|
190
|
+
- **Best for**: Small static assets, API responses, frequently accessed files
|
|
191
|
+
|
|
192
|
+
**File routes** (`new Response(Bun.file(path))`) read from filesystem per request:
|
|
193
|
+
|
|
194
|
+
- **Filesystem reads** on each request - checks file existence and reads content
|
|
195
|
+
- **Built-in 404 handling** - Returns `404 Not Found` if file doesn't exist or becomes inaccessible
|
|
196
|
+
- **Last-Modified support** - Uses file modification time for `If-Modified-Since` headers
|
|
197
|
+
- **If-Modified-Since** - Returns `304 Not Modified` when file hasn't changed since client's cached version
|
|
198
|
+
- **Range request support** - Automatically handles partial content requests with `Content-Range` headers
|
|
199
|
+
- **Streaming transfers** - Uses buffered reader with backpressure handling for efficient memory usage
|
|
200
|
+
- **Memory efficient** - Only buffers small chunks during transfer, not entire file
|
|
201
|
+
- **Best for**: Large files, dynamic content, user uploads, files that change frequently
|
|
202
|
+
|
|
203
|
+
### HTTP Caching Behavior
|
|
204
|
+
|
|
205
|
+
Both route types implement HTTP caching standards but with different strategies:
|
|
206
|
+
|
|
207
|
+
#### Static Routes Caching
|
|
208
|
+
|
|
209
|
+
- **ETag generation**: Automatically computes ETag hash from content at startup
|
|
210
|
+
- **If-None-Match**: Validates client ETag against server ETag
|
|
211
|
+
- **304 responses**: Returns `304 Not Modified` with empty body when ETags match
|
|
212
|
+
- **Cache headers**: Inherits any `Cache-Control` headers you provide in the Response
|
|
213
|
+
- **Consistency**: ETag remains constant until server restart or route reload
|
|
214
|
+
|
|
215
|
+
#### File Routes Caching
|
|
216
|
+
|
|
217
|
+
- **Last-Modified**: Uses file's `mtime` for `Last-Modified` header
|
|
218
|
+
- **If-Modified-Since**: Compares client date with file modification time
|
|
219
|
+
- **304 responses**: Returns `304 Not Modified` when file unchanged since client's cached version
|
|
220
|
+
- **Content-Length**: Automatically set based on current file size
|
|
221
|
+
- **Dynamic validation**: Checks file modification time on each request
|
|
222
|
+
|
|
223
|
+
#### Status Code Handling
|
|
224
|
+
|
|
225
|
+
Both route types automatically adjust status codes:
|
|
226
|
+
|
|
227
|
+
- **200 → 204**: Empty files (0 bytes) return `204 No Content` instead of `200 OK`
|
|
228
|
+
- **200 → 304**: Successful cache validation returns `304 Not Modified`
|
|
229
|
+
- **File routes only**: Missing or inaccessible files return `404 Not Found`
|
|
230
|
+
|
|
167
231
|
```ts
|
|
168
232
|
const server = Bun.serve({
|
|
169
233
|
static: {
|
package/docs/api/spawn.md
CHANGED
|
@@ -140,7 +140,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
140
140
|
```ts
|
|
141
141
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
142
142
|
const text = await proc.stdout.text();
|
|
143
|
-
console.log(text); // => "1.2.20-canary.
|
|
143
|
+
console.log(text); // => "1.2.20-canary.20250802T140550\n"
|
|
144
144
|
```
|
|
145
145
|
|
|
146
146
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
package/docs/api/streams.md
CHANGED
|
@@ -208,8 +208,8 @@ export class ArrayBufferSink {
|
|
|
208
208
|
*
|
|
209
209
|
* This API might change later to separate Uint8ArraySink and ArrayBufferSink
|
|
210
210
|
*/
|
|
211
|
-
flush(): number | Uint8Array | ArrayBuffer;
|
|
212
|
-
end(): ArrayBuffer | Uint8Array
|
|
211
|
+
flush(): number | Uint8Array<ArrayBuffer> | ArrayBuffer;
|
|
212
|
+
end(): ArrayBuffer | Uint8Array<ArrayBuffer>;
|
|
213
213
|
}
|
|
214
214
|
```
|
|
215
215
|
|
package/docs/cli/pm.md
CHANGED
|
@@ -213,7 +213,7 @@ To display current package version and help:
|
|
|
213
213
|
|
|
214
214
|
```bash
|
|
215
215
|
$ bun pm version
|
|
216
|
-
bun pm version v1.2.20-canary.
|
|
216
|
+
bun pm version v1.2.20-canary.20250802T140550 (ca7428e9)
|
|
217
217
|
Current package version: v1.0.0
|
|
218
218
|
|
|
219
219
|
Increment:
|
package/docs/cli/publish.md
CHANGED
|
@@ -9,7 +9,7 @@ $ bunx nuxi init my-nuxt-app
|
|
|
9
9
|
✔ Which package manager would you like to use?
|
|
10
10
|
bun
|
|
11
11
|
◐ Installing dependencies...
|
|
12
|
-
bun install v1.2.20-canary.
|
|
12
|
+
bun install v1.2.20-canary.20250802T140550 (16b4bf34)
|
|
13
13
|
+ @nuxt/devtools@0.8.2
|
|
14
14
|
+ nuxt@3.7.0
|
|
15
15
|
785 packages installed [2.67s]
|
|
@@ -15,7 +15,7 @@ This will add the package to `peerDependencies` in `package.json`.
|
|
|
15
15
|
```json-diff
|
|
16
16
|
{
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
+ "@types/bun": "^1.2.20-canary.
|
|
18
|
+
+ "@types/bun": "^1.2.20-canary.20250802T140550"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
```
|
|
@@ -27,7 +27,7 @@ Running `bun install` will install peer dependencies by default, unless marked o
|
|
|
27
27
|
```json-diff
|
|
28
28
|
{
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"@types/bun": "^1.2.20-canary.
|
|
30
|
+
"@types/bun": "^1.2.20-canary.20250802T140550"
|
|
31
31
|
},
|
|
32
32
|
"peerDependenciesMeta": {
|
|
33
33
|
+ "@types/bun": {
|
|
@@ -97,7 +97,7 @@ $ bun update
|
|
|
97
97
|
$ bun update @types/bun --latest
|
|
98
98
|
|
|
99
99
|
# Update a dependency to a specific version
|
|
100
|
-
$ bun update @types/bun@1.2.20-canary.
|
|
100
|
+
$ bun update @types/bun@1.2.20-canary.20250802T140550
|
|
101
101
|
|
|
102
102
|
# Update all dependencies to the latest versions
|
|
103
103
|
$ bun update --latest
|
|
@@ -21,7 +21,7 @@ Here's what the output of a typical test run looks like. In this case, there are
|
|
|
21
21
|
|
|
22
22
|
```sh
|
|
23
23
|
$ bun test
|
|
24
|
-
bun test v1.2.20-canary.
|
|
24
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
25
25
|
|
|
26
26
|
test.test.js:
|
|
27
27
|
✓ add [0.87ms]
|
|
@@ -47,7 +47,7 @@ To only run certain test files, pass a positional argument to `bun test`. The ru
|
|
|
47
47
|
|
|
48
48
|
```sh
|
|
49
49
|
$ bun test test3
|
|
50
|
-
bun test v1.2.20-canary.
|
|
50
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
51
51
|
|
|
52
52
|
test3.test.js:
|
|
53
53
|
✓ add [1.40ms]
|
|
@@ -85,7 +85,7 @@ Adding `-t add` will only run tests with "add" in the name. This works with test
|
|
|
85
85
|
|
|
86
86
|
```sh
|
|
87
87
|
$ bun test -t add
|
|
88
|
-
bun test v1.2.20-canary.
|
|
88
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
89
89
|
|
|
90
90
|
test.test.js:
|
|
91
91
|
✓ add [1.79ms]
|
|
@@ -18,7 +18,7 @@ The first time this test is executed, Bun will evaluate the value passed into `e
|
|
|
18
18
|
|
|
19
19
|
```sh
|
|
20
20
|
$ bun test test/snap
|
|
21
|
-
bun test v1.2.20-canary.
|
|
21
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
22
22
|
|
|
23
23
|
test/snap.test.ts:
|
|
24
24
|
✓ snapshot [1.48ms]
|
|
@@ -61,7 +61,7 @@ Later, when this test file is executed again, Bun will read the snapshot file an
|
|
|
61
61
|
|
|
62
62
|
```sh
|
|
63
63
|
$ bun test
|
|
64
|
-
bun test v1.2.20-canary.
|
|
64
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
65
65
|
|
|
66
66
|
test/snap.test.ts:
|
|
67
67
|
✓ snapshot [1.05ms]
|
|
@@ -78,7 +78,7 @@ To update snapshots, use the `--update-snapshots` flag.
|
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
80
|
$ bun test --update-snapshots
|
|
81
|
-
bun test v1.2.20-canary.
|
|
81
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
82
82
|
|
|
83
83
|
test/snap.test.ts:
|
|
84
84
|
✓ snapshot [0.86ms]
|
|
@@ -29,7 +29,7 @@ To regenerate snapshots, use the `--update-snapshots` flag.
|
|
|
29
29
|
|
|
30
30
|
```sh
|
|
31
31
|
$ bun test --update-snapshots
|
|
32
|
-
bun test v1.2.20-canary.
|
|
32
|
+
bun test v1.2.20-canary.20250802T140550 (9c68abdb)
|
|
33
33
|
|
|
34
34
|
test/snap.test.ts:
|
|
35
35
|
✓ snapshot [0.86ms]
|
|
@@ -14,7 +14,7 @@ if (typeof Bun !== "undefined") {
|
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
17
|
-
In TypeScript environments, the previous approach will result in a type error unless
|
|
17
|
+
In TypeScript environments, the previous approach will result in a type error unless `@types/bun` is installed. To avoid this, you can check `process.versions` instead.
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
if (process.versions.bun) {
|
package/docs/installation.md
CHANGED
|
@@ -14,7 +14,7 @@ Kernel version 5.6 or higher is strongly recommended, but the minimum is 5.1. Us
|
|
|
14
14
|
```bash#macOS/Linux_(curl)
|
|
15
15
|
$ curl -fsSL https://bun.com/install | bash # for macOS, Linux, and WSL
|
|
16
16
|
# to install a specific version
|
|
17
|
-
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.20-canary.
|
|
17
|
+
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.20-canary.20250802T140550"
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
```bash#npm
|
|
@@ -189,10 +189,10 @@ Since Bun is a single binary, you can install older versions of Bun by re-runnin
|
|
|
189
189
|
|
|
190
190
|
### Installing a specific version of Bun on Linux/Mac
|
|
191
191
|
|
|
192
|
-
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.20-canary.
|
|
192
|
+
To install a specific version of Bun, you can pass the git tag of the version you want to install to the install script, such as `bun-v1.2.0` or `bun-v1.2.20-canary.20250802T140550`.
|
|
193
193
|
|
|
194
194
|
```sh
|
|
195
|
-
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.20-canary.
|
|
195
|
+
$ curl -fsSL https://bun.com/install | bash -s "bun-v1.2.20-canary.20250802T140550"
|
|
196
196
|
```
|
|
197
197
|
|
|
198
198
|
### Installing a specific version of Bun on Windows
|
|
@@ -201,7 +201,7 @@ On Windows, you can install a specific version of Bun by passing the version num
|
|
|
201
201
|
|
|
202
202
|
```sh
|
|
203
203
|
# PowerShell:
|
|
204
|
-
$ iex "& {$(irm https://bun.com/install.ps1)} -Version 1.2.20-canary.
|
|
204
|
+
$ iex "& {$(irm https://bun.com/install.ps1)} -Version 1.2.20-canary.20250802T140550"
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
## Downloading Bun binaries directly
|
package/docs/runtime/debugger.md
CHANGED
|
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
|
|
|
124
124
|
This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
|
|
125
125
|
|
|
126
126
|
```sh
|
|
127
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.20-canary.
|
|
127
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.2.20-canary.20250802T140550" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
128
128
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
129
129
|
[fetch] > content-type: application/json
|
|
130
130
|
[fetch] > Connection: keep-alive
|
|
131
|
-
[fetch] > User-Agent: Bun/1.2.20-canary.
|
|
131
|
+
[fetch] > User-Agent: Bun/1.2.20-canary.20250802T140550
|
|
132
132
|
[fetch] > Accept: */*
|
|
133
133
|
[fetch] > Host: example.com
|
|
134
134
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -170,7 +170,7 @@ This prints the following to the console:
|
|
|
170
170
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
171
171
|
[fetch] > content-type: application/json
|
|
172
172
|
[fetch] > Connection: keep-alive
|
|
173
|
-
[fetch] > User-Agent: Bun/1.2.20-canary.
|
|
173
|
+
[fetch] > User-Agent: Bun/1.2.20-canary.20250802T140550
|
|
174
174
|
[fetch] > Accept: */*
|
|
175
175
|
[fetch] > Host: example.com
|
|
176
176
|
[fetch] > Accept-Encoding: gzip, deflate, br
|