bun-types 0.0.78 → 0.1.2
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/package.json +1 -1
- package/types.d.ts +2492 -95
package/types.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ declare module "bun" {
|
|
|
66
66
|
* });
|
|
67
67
|
* ```
|
|
68
68
|
*/
|
|
69
|
-
export function serve(options: Serve):
|
|
69
|
+
export function serve(options: Serve): Server;
|
|
70
70
|
|
|
71
71
|
/**
|
|
72
72
|
* Synchronously resolve a `moduleId` as though it were imported from `parent`
|
|
@@ -192,6 +192,178 @@ declare module "bun" {
|
|
|
192
192
|
syscall?: string | undefined;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
|
+
/**
|
|
196
|
+
* Concatenate an array of typed arrays into a single `ArrayBuffer`. This is a fast path.
|
|
197
|
+
*
|
|
198
|
+
* You can do this manually if you'd like, but this function will generally
|
|
199
|
+
* be a little faster.
|
|
200
|
+
*
|
|
201
|
+
* If you want a `Uint8Array` instead, consider `Buffer.concat`.
|
|
202
|
+
*
|
|
203
|
+
* @param buffers An array of typed arrays to concatenate.
|
|
204
|
+
* @returns An `ArrayBuffer` with the data from all the buffers.
|
|
205
|
+
*
|
|
206
|
+
* Here is similar code to do it manually, except about 30% slower:
|
|
207
|
+
* ```js
|
|
208
|
+
* var chunks = [...];
|
|
209
|
+
* var size = 0;
|
|
210
|
+
* for (const chunk of chunks) {
|
|
211
|
+
* size += chunk.byteLength;
|
|
212
|
+
* }
|
|
213
|
+
* var buffer = new ArrayBuffer(size);
|
|
214
|
+
* var view = new Uint8Array(buffer);
|
|
215
|
+
* var offset = 0;
|
|
216
|
+
* for (const chunk of chunks) {
|
|
217
|
+
* view.set(chunk, offset);
|
|
218
|
+
* offset += chunk.byteLength;
|
|
219
|
+
* }
|
|
220
|
+
* return buffer;
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* This function is faster because it uses uninitialized memory when copying. Since the entire
|
|
224
|
+
* length of the buffer is known, it is safe to use uninitialized memory.
|
|
225
|
+
*/
|
|
226
|
+
export function concatArrayBuffers(
|
|
227
|
+
buffers: Array<ArrayBufferView | ArrayBufferLike>
|
|
228
|
+
): ArrayBuffer;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
232
|
+
*
|
|
233
|
+
* Concatenate the chunks into a single {@link ArrayBuffer}.
|
|
234
|
+
*
|
|
235
|
+
* Each chunk must be a TypedArray or an ArrayBuffer. If you need to support
|
|
236
|
+
* chunks of different types, consider {@link readableStreamToBlob}
|
|
237
|
+
*
|
|
238
|
+
* @param stream The stream to consume.
|
|
239
|
+
* @returns A promise that resolves with the concatenated chunks or the concatenated chunks as an `ArrayBuffer`.
|
|
240
|
+
*/
|
|
241
|
+
export function readableStreamToArrayBuffer(
|
|
242
|
+
stream: ReadableStream
|
|
243
|
+
): Promise<ArrayBuffer> | ArrayBuffer;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
247
|
+
*
|
|
248
|
+
* Concatenate the chunks into a single {@link Blob}.
|
|
249
|
+
*
|
|
250
|
+
* @param stream The stream to consume.
|
|
251
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link Blob}.
|
|
252
|
+
*/
|
|
253
|
+
export function readableStreamToBlob(stream: ReadableStream): Promise<Blob>;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
257
|
+
*
|
|
258
|
+
* 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}.
|
|
259
|
+
*
|
|
260
|
+
* @param stream The stream to consume.
|
|
261
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
262
|
+
*/
|
|
263
|
+
export function readableStreamToText(stream: ReadableStream): Promise<string>;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
267
|
+
*
|
|
268
|
+
* 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}.
|
|
269
|
+
*
|
|
270
|
+
* @param stream The stream to consume.
|
|
271
|
+
* @returns A promise that resolves with the concatenated chunks as a {@link String}.
|
|
272
|
+
*/
|
|
273
|
+
export function readableStreamToJSON(stream: ReadableStream): Promise<any>;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Consume all data from a {@link ReadableStream} until it closes or errors.
|
|
277
|
+
*
|
|
278
|
+
* @param stream The stream to consume
|
|
279
|
+
* @returns A promise that resolves with the chunks as an array
|
|
280
|
+
*
|
|
281
|
+
*/
|
|
282
|
+
export function readableStreamToArray<T>(
|
|
283
|
+
stream: ReadableStream
|
|
284
|
+
): Promise<T[]> | T[];
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Escape the following characters in a string:
|
|
288
|
+
*
|
|
289
|
+
* - `"` becomes `"""`
|
|
290
|
+
* - `&` becomes `"&"`
|
|
291
|
+
* - `'` becomes `"'"`
|
|
292
|
+
* - `<` becomes `"<"`
|
|
293
|
+
* - `>` becomes `">"`
|
|
294
|
+
*
|
|
295
|
+
* This function is optimized for large input. On an M1X, it processes 480 MB/s -
|
|
296
|
+
* 20 GB/s, depending on how much data is being escaped and whether there is non-ascii
|
|
297
|
+
* text.
|
|
298
|
+
*
|
|
299
|
+
* Non-string types will be converted to a string before escaping.
|
|
300
|
+
*/
|
|
301
|
+
export function escapeHTML(input: string | object | number | boolean): string;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Convert a filesystem path to a file:// URL.
|
|
305
|
+
*
|
|
306
|
+
* @param path The path to convert.
|
|
307
|
+
* @returns A {@link URL} with the file:// scheme.
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```js
|
|
311
|
+
* const url = Bun.pathToFileURL("/foo/bar.txt");
|
|
312
|
+
* console.log(url.href); // "file:///foo/bar.txt"
|
|
313
|
+
*```
|
|
314
|
+
*
|
|
315
|
+
* Internally, this function uses WebKit's URL API to
|
|
316
|
+
* convert the path to a file:// URL.
|
|
317
|
+
*/
|
|
318
|
+
export function pathToFileURL(path: string): URL;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Convert a {@link URL} to a filesystem path.
|
|
322
|
+
* @param url The URL to convert.
|
|
323
|
+
* @returns A filesystem path.
|
|
324
|
+
* @throws If the URL is not a URL.
|
|
325
|
+
* @example
|
|
326
|
+
* ```js
|
|
327
|
+
* const path = Bun.fileURLToPath(new URL("file:///foo/bar.txt"));
|
|
328
|
+
* console.log(path); // "/foo/bar.txt"
|
|
329
|
+
* ```
|
|
330
|
+
*/
|
|
331
|
+
export function fileURLToPath(url: URL): string;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Fast incremental writer that becomes an `ArrayBuffer` on end().
|
|
335
|
+
*/
|
|
336
|
+
export class ArrayBufferSink {
|
|
337
|
+
constructor();
|
|
338
|
+
|
|
339
|
+
start(options?: {
|
|
340
|
+
asUint8Array?: boolean;
|
|
341
|
+
/**
|
|
342
|
+
* Preallocate an internal buffer of this size
|
|
343
|
+
* This can significantly improve performance when the chunk size is small
|
|
344
|
+
*/
|
|
345
|
+
highWaterMark?: number;
|
|
346
|
+
/**
|
|
347
|
+
* On {@link ArrayBufferSink.flush}, return the written data as a `Uint8Array`.
|
|
348
|
+
* Writes will restart from the beginning of the buffer.
|
|
349
|
+
*/
|
|
350
|
+
stream?: boolean;
|
|
351
|
+
}): void;
|
|
352
|
+
|
|
353
|
+
write(chunk: string | ArrayBufferView | ArrayBuffer): number;
|
|
354
|
+
/**
|
|
355
|
+
* Flush the internal buffer
|
|
356
|
+
*
|
|
357
|
+
* If {@link ArrayBufferSink.start} was passed a `stream` option, this will return a `ArrayBuffer`
|
|
358
|
+
* If {@link ArrayBufferSink.start} was passed a `stream` option and `asUint8Array`, this will return a `Uint8Array`
|
|
359
|
+
* Otherwise, this will return the number of bytes written since the last flush
|
|
360
|
+
*
|
|
361
|
+
* This API might change later to separate Uint8ArraySink and ArrayBufferSink
|
|
362
|
+
*/
|
|
363
|
+
flush(): number | Uint8Array | ArrayBuffer;
|
|
364
|
+
end(): ArrayBuffer | Uint8Array;
|
|
365
|
+
}
|
|
366
|
+
|
|
195
367
|
/**
|
|
196
368
|
* [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) powered by the fastest system calls available for operating on files.
|
|
197
369
|
*
|
|
@@ -365,7 +537,17 @@ declare module "bun" {
|
|
|
365
537
|
* const query = UserQuery;
|
|
366
538
|
* ```
|
|
367
539
|
*/
|
|
368
|
-
macros
|
|
540
|
+
macros?: MacroMap;
|
|
541
|
+
|
|
542
|
+
autoImportJSX?: boolean;
|
|
543
|
+
allowBunRuntime?: boolean;
|
|
544
|
+
exports?: {
|
|
545
|
+
eliminate?: string[];
|
|
546
|
+
replace?: Record<string, string>;
|
|
547
|
+
};
|
|
548
|
+
treeShaking?: boolean;
|
|
549
|
+
trimUnusedImports?: boolean;
|
|
550
|
+
jsxOptimizationInline?: boolean;
|
|
369
551
|
}
|
|
370
552
|
|
|
371
553
|
/**
|
|
@@ -403,7 +585,27 @@ declare module "bun" {
|
|
|
403
585
|
* @param code The code to transpile
|
|
404
586
|
*
|
|
405
587
|
*/
|
|
406
|
-
transformSync(
|
|
588
|
+
transformSync(
|
|
589
|
+
code: StringOrBuffer,
|
|
590
|
+
loader: JavaScriptLoader,
|
|
591
|
+
ctx: object
|
|
592
|
+
): string;
|
|
593
|
+
/**
|
|
594
|
+
* Transpile code from TypeScript or JSX into valid JavaScript.
|
|
595
|
+
* This function does not resolve imports.
|
|
596
|
+
* @param code The code to transpile
|
|
597
|
+
* @param ctx An object to pass to macros
|
|
598
|
+
*
|
|
599
|
+
*/
|
|
600
|
+
transformSync(code: StringOrBuffer, ctx: object): string;
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Transpile code from TypeScript or JSX into valid JavaScript.
|
|
604
|
+
* This function does not resolve imports.
|
|
605
|
+
* @param code The code to transpile
|
|
606
|
+
*
|
|
607
|
+
*/
|
|
608
|
+
transformSync(code: StringOrBuffer, loader: JavaScriptLoader): string;
|
|
407
609
|
|
|
408
610
|
/**
|
|
409
611
|
* Get a list of import paths and paths from a TypeScript, JSX, TSX, or JavaScript file.
|
|
@@ -521,9 +723,10 @@ declare module "bun" {
|
|
|
521
723
|
* Respond to {@link Request} objects with a {@link Response} object.
|
|
522
724
|
*
|
|
523
725
|
*/
|
|
524
|
-
fetch(request: Request): Response | Promise<Response>;
|
|
726
|
+
fetch(this: Server, request: Request): Response | Promise<Response>;
|
|
525
727
|
|
|
526
728
|
error?: (
|
|
729
|
+
this: Server,
|
|
527
730
|
request: Errorlike
|
|
528
731
|
) => Response | Promise<Response> | undefined | Promise<undefined>;
|
|
529
732
|
}
|
|
@@ -571,6 +774,41 @@ declare module "bun" {
|
|
|
571
774
|
serverNames: Record<string, SSLOptions & SSLAdvancedOptions>;
|
|
572
775
|
};
|
|
573
776
|
|
|
777
|
+
/**
|
|
778
|
+
* HTTP & HTTPS Server
|
|
779
|
+
*
|
|
780
|
+
* To start the server, see {@link serve}
|
|
781
|
+
*
|
|
782
|
+
* Often, you don't need to interact with this object directly. It exists to help you with the following tasks:
|
|
783
|
+
* - Stop the server
|
|
784
|
+
* - How many requests are currently being handled?
|
|
785
|
+
*
|
|
786
|
+
* For performance, Bun pre-allocates most of the data for 2048 concurrent requests.
|
|
787
|
+
* That means starting a new server allocates about 500 KB of memory. Try to
|
|
788
|
+
* avoid starting and stopping the server often (unless it's a new instance of bun).
|
|
789
|
+
*
|
|
790
|
+
* Powered by a fork of [uWebSockets](https://github.com/uNetworking/uWebSockets). Thank you @alexhultman.
|
|
791
|
+
*
|
|
792
|
+
*/
|
|
793
|
+
interface Server {
|
|
794
|
+
/**
|
|
795
|
+
* Stop listening to prevent new connections from being accepted.
|
|
796
|
+
*
|
|
797
|
+
* It does not close existing connections.
|
|
798
|
+
*
|
|
799
|
+
* It may take a second or two to actually stop.
|
|
800
|
+
*/
|
|
801
|
+
stop(): void;
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* How many requests are in-flight right now?
|
|
805
|
+
*/
|
|
806
|
+
readonly pendingRequests: number;
|
|
807
|
+
readonly port: number;
|
|
808
|
+
readonly hostname: string;
|
|
809
|
+
readonly development: boolean;
|
|
810
|
+
}
|
|
811
|
+
|
|
574
812
|
export type Serve = SSLServeOptions | ServeOptions;
|
|
575
813
|
|
|
576
814
|
/**
|
|
@@ -730,6 +968,8 @@ declare module "bun" {
|
|
|
730
968
|
}
|
|
731
969
|
export const unsafe: unsafe;
|
|
732
970
|
|
|
971
|
+
type DigestEncoding = "hex" | "base64";
|
|
972
|
+
|
|
733
973
|
/**
|
|
734
974
|
* Are ANSI colors enabled for stdin and stdout?
|
|
735
975
|
*
|
|
@@ -747,94 +987,1779 @@ declare module "bun" {
|
|
|
747
987
|
export const main: string;
|
|
748
988
|
|
|
749
989
|
/**
|
|
750
|
-
* Manually trigger the garbage collector
|
|
751
|
-
*
|
|
752
|
-
* This does two things:
|
|
753
|
-
* 1. It tells JavaScriptCore to run the garbage collector
|
|
754
|
-
* 2. It tells [mimalloc](https://github.com/microsoft/mimalloc) to clean up fragmented memory. Mimalloc manages the heap not used in JavaScriptCore.
|
|
990
|
+
* Manually trigger the garbage collector
|
|
991
|
+
*
|
|
992
|
+
* This does two things:
|
|
993
|
+
* 1. It tells JavaScriptCore to run the garbage collector
|
|
994
|
+
* 2. It tells [mimalloc](https://github.com/microsoft/mimalloc) to clean up fragmented memory. Mimalloc manages the heap not used in JavaScriptCore.
|
|
995
|
+
*
|
|
996
|
+
* @param force Synchronously run the garbage collector
|
|
997
|
+
*/
|
|
998
|
+
export function gc(force: boolean): void;
|
|
999
|
+
|
|
1000
|
+
/**
|
|
1001
|
+
* JavaScriptCore engine's internal heap snapshot
|
|
1002
|
+
*
|
|
1003
|
+
* I don't know how to make this something Chrome or Safari can read.
|
|
1004
|
+
*
|
|
1005
|
+
* If you have any ideas, please file an issue https://github.com/Jarred-Sumner/bun
|
|
1006
|
+
*/
|
|
1007
|
+
interface HeapSnapshot {
|
|
1008
|
+
/** "2" */
|
|
1009
|
+
version: string;
|
|
1010
|
+
|
|
1011
|
+
/** "Inspector" */
|
|
1012
|
+
type: string;
|
|
1013
|
+
|
|
1014
|
+
nodes: number[];
|
|
1015
|
+
|
|
1016
|
+
nodeClassNames: string[];
|
|
1017
|
+
edges: number[];
|
|
1018
|
+
edgeTypes: string[];
|
|
1019
|
+
edgeNames: string[];
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
/**
|
|
1023
|
+
* Nanoseconds since Bun.js was started as an integer.
|
|
1024
|
+
*
|
|
1025
|
+
* This uses a high-resolution monotonic system timer.
|
|
1026
|
+
*
|
|
1027
|
+
* After 14 weeks of consecutive uptime, this function
|
|
1028
|
+
* wraps
|
|
1029
|
+
*/
|
|
1030
|
+
export function nanoseconds(): number;
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Generate a heap snapshot for seeing where the heap is being used
|
|
1034
|
+
*/
|
|
1035
|
+
export function generateHeapSnapshot(): HeapSnapshot;
|
|
1036
|
+
|
|
1037
|
+
/**
|
|
1038
|
+
* The next time JavaScriptCore is idle, clear unused memory and attempt to reduce the heap size.
|
|
1039
|
+
*/
|
|
1040
|
+
export function shrink(): void;
|
|
1041
|
+
|
|
1042
|
+
/**
|
|
1043
|
+
* Open a file in your local editor. Auto-detects via `$VISUAL` || `$EDITOR`
|
|
1044
|
+
*
|
|
1045
|
+
* @param path path to open
|
|
1046
|
+
*/
|
|
1047
|
+
export function openInEditor(path: string, options?: EditorOptions): void;
|
|
1048
|
+
|
|
1049
|
+
interface EditorOptions {
|
|
1050
|
+
editor?: "vscode" | "subl";
|
|
1051
|
+
line?: number;
|
|
1052
|
+
column?: number;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* This class only exists in types
|
|
1057
|
+
*/
|
|
1058
|
+
abstract class CryptoHashInterface<T> {
|
|
1059
|
+
/**
|
|
1060
|
+
* Update the hash with data
|
|
1061
|
+
*
|
|
1062
|
+
* @param data
|
|
1063
|
+
*/
|
|
1064
|
+
update(data: StringOrBuffer): T;
|
|
1065
|
+
|
|
1066
|
+
/**
|
|
1067
|
+
* Finalize the hash
|
|
1068
|
+
*
|
|
1069
|
+
* @param encoding `DigestEncoding` to return the hash in. If none is provided, it will return a `Uint8Array`.
|
|
1070
|
+
*/
|
|
1071
|
+
digest(encoding: DigestEncoding): string;
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* Finalize the hash
|
|
1075
|
+
*
|
|
1076
|
+
* @param hashInto `TypedArray` to write the hash into. Faster than creating a new one each time
|
|
1077
|
+
*/
|
|
1078
|
+
digest(hashInto?: TypedArray): TypedArray;
|
|
1079
|
+
|
|
1080
|
+
/**
|
|
1081
|
+
* Run the hash over the given data
|
|
1082
|
+
*
|
|
1083
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster.
|
|
1084
|
+
*
|
|
1085
|
+
* @param hashInto `TypedArray` to write the hash into. Faster than creating a new one each time
|
|
1086
|
+
*/
|
|
1087
|
+
static hash(input: StringOrBuffer, hashInto?: TypedArray): TypedArray;
|
|
1088
|
+
|
|
1089
|
+
/**
|
|
1090
|
+
* Run the hash over the given data
|
|
1091
|
+
*
|
|
1092
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` is faster.
|
|
1093
|
+
*
|
|
1094
|
+
* @param encoding `DigestEncoding` to return the hash in
|
|
1095
|
+
*/
|
|
1096
|
+
static hash(input: StringOrBuffer, encoding: DigestEncoding): string;
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
*
|
|
1101
|
+
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
1102
|
+
*
|
|
1103
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
1104
|
+
* @param hashInto optional `Uint8Array` to write the hash to. 32 bytes minimum.
|
|
1105
|
+
*
|
|
1106
|
+
* This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
|
|
1107
|
+
*
|
|
1108
|
+
* The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
|
|
1109
|
+
*
|
|
1110
|
+
* The equivalent `openssl` command is:
|
|
1111
|
+
*
|
|
1112
|
+
* ```bash
|
|
1113
|
+
* # You will need OpenSSL 3 or later
|
|
1114
|
+
* openssl sha512-256 /path/to/file
|
|
1115
|
+
*```
|
|
1116
|
+
*/
|
|
1117
|
+
export function sha(input: StringOrBuffer, hashInto?: Uint8Array): Uint8Array;
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
*
|
|
1121
|
+
* Hash `input` using [SHA-2 512/256](https://en.wikipedia.org/wiki/SHA-2#Comparison_of_SHA_functions)
|
|
1122
|
+
*
|
|
1123
|
+
* @param input `string`, `Uint8Array`, or `ArrayBuffer` to hash. `Uint8Array` or `ArrayBuffer` will be faster
|
|
1124
|
+
* @param encoding `DigestEncoding` to return the hash in
|
|
1125
|
+
*
|
|
1126
|
+
* This hashing function balances speed with cryptographic strength. This does not encrypt or decrypt data.
|
|
1127
|
+
*
|
|
1128
|
+
* The implementation uses [BoringSSL](https://boringssl.googlesource.com/boringssl) (used in Chromium & Go)
|
|
1129
|
+
*
|
|
1130
|
+
* The equivalent `openssl` command is:
|
|
1131
|
+
*
|
|
1132
|
+
* ```bash
|
|
1133
|
+
* # You will need OpenSSL 3 or later
|
|
1134
|
+
* openssl sha512-256 /path/to/file
|
|
1135
|
+
*```
|
|
1136
|
+
*/
|
|
1137
|
+
export function sha(input: StringOrBuffer, encoding: DigestEncoding): string;
|
|
1138
|
+
|
|
1139
|
+
/**
|
|
1140
|
+
* This is not the default because it's not cryptographically secure and it's slower than {@link SHA512}
|
|
1141
|
+
*
|
|
1142
|
+
* Consider using the ugly-named {@link SHA512_256} instead
|
|
1143
|
+
*/
|
|
1144
|
+
export class SHA1 extends CryptoHashInterface<SHA1> {
|
|
1145
|
+
constructor();
|
|
1146
|
+
|
|
1147
|
+
/**
|
|
1148
|
+
* The number of bytes the hash will produce
|
|
1149
|
+
*/
|
|
1150
|
+
static readonly byteLength: 20;
|
|
1151
|
+
}
|
|
1152
|
+
export class MD5 extends CryptoHashInterface<MD5> {
|
|
1153
|
+
constructor();
|
|
1154
|
+
|
|
1155
|
+
/**
|
|
1156
|
+
* The number of bytes the hash will produce
|
|
1157
|
+
*/
|
|
1158
|
+
static readonly byteLength: 16;
|
|
1159
|
+
}
|
|
1160
|
+
export class MD4 extends CryptoHashInterface<MD4> {
|
|
1161
|
+
constructor();
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* The number of bytes the hash will produce
|
|
1165
|
+
*/
|
|
1166
|
+
static readonly byteLength: 16;
|
|
1167
|
+
}
|
|
1168
|
+
export class SHA224 extends CryptoHashInterface<SHA224> {
|
|
1169
|
+
constructor();
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* The number of bytes the hash will produce
|
|
1173
|
+
*/
|
|
1174
|
+
static readonly byteLength: 28;
|
|
1175
|
+
}
|
|
1176
|
+
export class SHA512 extends CryptoHashInterface<SHA512> {
|
|
1177
|
+
constructor();
|
|
1178
|
+
|
|
1179
|
+
/**
|
|
1180
|
+
* The number of bytes the hash will produce
|
|
1181
|
+
*/
|
|
1182
|
+
static readonly byteLength: 64;
|
|
1183
|
+
}
|
|
1184
|
+
export class SHA384 extends CryptoHashInterface<SHA384> {
|
|
1185
|
+
constructor();
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* The number of bytes the hash will produce
|
|
1189
|
+
*/
|
|
1190
|
+
static readonly byteLength: 48;
|
|
1191
|
+
}
|
|
1192
|
+
export class SHA256 extends CryptoHashInterface<SHA256> {
|
|
1193
|
+
constructor();
|
|
1194
|
+
|
|
1195
|
+
/**
|
|
1196
|
+
* The number of bytes the hash will produce
|
|
1197
|
+
*/
|
|
1198
|
+
static readonly byteLength: 32;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* See also {@link sha}
|
|
1202
|
+
*/
|
|
1203
|
+
export class SHA512_256 extends CryptoHashInterface<SHA512_256> {
|
|
1204
|
+
constructor();
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* The number of bytes the hash will produce
|
|
1208
|
+
*/
|
|
1209
|
+
static readonly byteLength: 32;
|
|
1210
|
+
}
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
type TypedArray =
|
|
1214
|
+
| Uint8Array
|
|
1215
|
+
| Int8Array
|
|
1216
|
+
| Uint8ClampedArray
|
|
1217
|
+
| Int16Array
|
|
1218
|
+
| Uint16Array
|
|
1219
|
+
| Int32Array
|
|
1220
|
+
| Uint32Array
|
|
1221
|
+
| Float32Array
|
|
1222
|
+
| Float64Array;
|
|
1223
|
+
type TimeLike = string | number | Date;
|
|
1224
|
+
type StringOrBuffer = string | TypedArray | ArrayBufferLike;
|
|
1225
|
+
type PathLike = string | TypedArray | ArrayBufferLike;
|
|
1226
|
+
type PathOrFileDescriptor = PathLike | number;
|
|
1227
|
+
type NoParamCallback = VoidFunction;
|
|
1228
|
+
type BufferEncoding =
|
|
1229
|
+
| "buffer"
|
|
1230
|
+
| "utf8"
|
|
1231
|
+
| "utf-8"
|
|
1232
|
+
| "ascii"
|
|
1233
|
+
| "utf16le"
|
|
1234
|
+
| "ucs2"
|
|
1235
|
+
| "ucs-2"
|
|
1236
|
+
| "latin1"
|
|
1237
|
+
| "binary";
|
|
1238
|
+
|
|
1239
|
+
interface BufferEncodingOption {
|
|
1240
|
+
encoding?: BufferEncoding;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
declare var Bun: typeof import("bun");
|
|
1244
|
+
|
|
1245
|
+
|
|
1246
|
+
// ./ffi.d.ts
|
|
1247
|
+
|
|
1248
|
+
/**
|
|
1249
|
+
* `bun:ffi` lets you efficiently call C functions & FFI functions from JavaScript
|
|
1250
|
+
* without writing bindings yourself.
|
|
1251
|
+
*
|
|
1252
|
+
* ```js
|
|
1253
|
+
* import {dlopen, CString, ptr} from 'bun:ffi';
|
|
1254
|
+
*
|
|
1255
|
+
* const lib = dlopen('libsqlite3', {
|
|
1256
|
+
* });
|
|
1257
|
+
* ```
|
|
1258
|
+
*
|
|
1259
|
+
* This is powered by just-in-time compiling C wrappers
|
|
1260
|
+
* that convert JavaScript types to C types and back. Internally,
|
|
1261
|
+
* bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
|
|
1262
|
+
* goes to Fabrice Bellard and TinyCC maintainers for making this possible.
|
|
1263
|
+
*
|
|
1264
|
+
*/
|
|
1265
|
+
declare module "bun:ffi" {
|
|
1266
|
+
export enum FFIType {
|
|
1267
|
+
char = 0,
|
|
1268
|
+
/**
|
|
1269
|
+
* 8-bit signed integer
|
|
1270
|
+
*
|
|
1271
|
+
* Must be a value between -127 and 127
|
|
1272
|
+
*
|
|
1273
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1274
|
+
*
|
|
1275
|
+
* In C:
|
|
1276
|
+
* ```c
|
|
1277
|
+
* signed char
|
|
1278
|
+
* char // on x64 & aarch64 macOS
|
|
1279
|
+
* ```
|
|
1280
|
+
*
|
|
1281
|
+
* In JavaScript:
|
|
1282
|
+
* ```js
|
|
1283
|
+
* var num = 0;
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
int8_t = 1,
|
|
1287
|
+
/**
|
|
1288
|
+
* 8-bit signed integer
|
|
1289
|
+
*
|
|
1290
|
+
* Must be a value between -127 and 127
|
|
1291
|
+
*
|
|
1292
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1293
|
+
*
|
|
1294
|
+
* In C:
|
|
1295
|
+
* ```c
|
|
1296
|
+
* signed char
|
|
1297
|
+
* char // on x64 & aarch64 macOS
|
|
1298
|
+
* ```
|
|
1299
|
+
*
|
|
1300
|
+
* In JavaScript:
|
|
1301
|
+
* ```js
|
|
1302
|
+
* var num = 0;
|
|
1303
|
+
* ```
|
|
1304
|
+
*/
|
|
1305
|
+
i8 = 1,
|
|
1306
|
+
|
|
1307
|
+
/**
|
|
1308
|
+
* 8-bit unsigned integer
|
|
1309
|
+
*
|
|
1310
|
+
* Must be a value between 0 and 255
|
|
1311
|
+
*
|
|
1312
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1313
|
+
*
|
|
1314
|
+
* In C:
|
|
1315
|
+
* ```c
|
|
1316
|
+
* unsigned char
|
|
1317
|
+
* ```
|
|
1318
|
+
*
|
|
1319
|
+
* In JavaScript:
|
|
1320
|
+
* ```js
|
|
1321
|
+
* var num = 0;
|
|
1322
|
+
* ```
|
|
1323
|
+
*/
|
|
1324
|
+
uint8_t = 2,
|
|
1325
|
+
/**
|
|
1326
|
+
* 8-bit unsigned integer
|
|
1327
|
+
*
|
|
1328
|
+
* Must be a value between 0 and 255
|
|
1329
|
+
*
|
|
1330
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1331
|
+
*
|
|
1332
|
+
* In C:
|
|
1333
|
+
* ```c
|
|
1334
|
+
* unsigned char
|
|
1335
|
+
* ```
|
|
1336
|
+
*
|
|
1337
|
+
* In JavaScript:
|
|
1338
|
+
* ```js
|
|
1339
|
+
* var num = 0;
|
|
1340
|
+
* ```
|
|
1341
|
+
*/
|
|
1342
|
+
u8 = 2,
|
|
1343
|
+
|
|
1344
|
+
/**
|
|
1345
|
+
* 16-bit signed integer
|
|
1346
|
+
*
|
|
1347
|
+
* Must be a value between -32768 and 32767
|
|
1348
|
+
*
|
|
1349
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1350
|
+
*
|
|
1351
|
+
* In C:
|
|
1352
|
+
* ```c
|
|
1353
|
+
* in16_t
|
|
1354
|
+
* short // on arm64 & x64
|
|
1355
|
+
* ```
|
|
1356
|
+
*
|
|
1357
|
+
* In JavaScript:
|
|
1358
|
+
* ```js
|
|
1359
|
+
* var num = 0;
|
|
1360
|
+
* ```
|
|
1361
|
+
*/
|
|
1362
|
+
int16_t = 3,
|
|
1363
|
+
/**
|
|
1364
|
+
* 16-bit signed integer
|
|
1365
|
+
*
|
|
1366
|
+
* Must be a value between -32768 and 32767
|
|
1367
|
+
*
|
|
1368
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1369
|
+
*
|
|
1370
|
+
* In C:
|
|
1371
|
+
* ```c
|
|
1372
|
+
* in16_t
|
|
1373
|
+
* short // on arm64 & x64
|
|
1374
|
+
* ```
|
|
1375
|
+
*
|
|
1376
|
+
* In JavaScript:
|
|
1377
|
+
* ```js
|
|
1378
|
+
* var num = 0;
|
|
1379
|
+
* ```
|
|
1380
|
+
*/
|
|
1381
|
+
i16 = 3,
|
|
1382
|
+
|
|
1383
|
+
/**
|
|
1384
|
+
* 16-bit unsigned integer
|
|
1385
|
+
*
|
|
1386
|
+
* Must be a value between 0 and 65535, inclusive.
|
|
1387
|
+
*
|
|
1388
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1389
|
+
*
|
|
1390
|
+
* In C:
|
|
1391
|
+
* ```c
|
|
1392
|
+
* uint16_t
|
|
1393
|
+
* unsigned short // on arm64 & x64
|
|
1394
|
+
* ```
|
|
1395
|
+
*
|
|
1396
|
+
* In JavaScript:
|
|
1397
|
+
* ```js
|
|
1398
|
+
* var num = 0;
|
|
1399
|
+
* ```
|
|
1400
|
+
*/
|
|
1401
|
+
uint16_t = 4,
|
|
1402
|
+
/**
|
|
1403
|
+
* 16-bit unsigned integer
|
|
1404
|
+
*
|
|
1405
|
+
* Must be a value between 0 and 65535, inclusive.
|
|
1406
|
+
*
|
|
1407
|
+
* When passing to a FFI function (C ABI), type coercsion is not performed.
|
|
1408
|
+
*
|
|
1409
|
+
* In C:
|
|
1410
|
+
* ```c
|
|
1411
|
+
* uint16_t
|
|
1412
|
+
* unsigned short // on arm64 & x64
|
|
1413
|
+
* ```
|
|
1414
|
+
*
|
|
1415
|
+
* In JavaScript:
|
|
1416
|
+
* ```js
|
|
1417
|
+
* var num = 0;
|
|
1418
|
+
* ```
|
|
1419
|
+
*/
|
|
1420
|
+
u16 = 4,
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* 32-bit signed integer
|
|
1424
|
+
*
|
|
1425
|
+
*/
|
|
1426
|
+
int32_t = 5,
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* 32-bit signed integer
|
|
1430
|
+
*
|
|
1431
|
+
* Alias of {@link FFIType.int32_t}
|
|
1432
|
+
*/
|
|
1433
|
+
i32 = 5,
|
|
1434
|
+
/**
|
|
1435
|
+
* 32-bit signed integer
|
|
1436
|
+
*
|
|
1437
|
+
* The same as `int` in C
|
|
1438
|
+
*
|
|
1439
|
+
* ```c
|
|
1440
|
+
* int
|
|
1441
|
+
* ```
|
|
1442
|
+
*/
|
|
1443
|
+
int = 5,
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* 32-bit unsigned integer
|
|
1447
|
+
*
|
|
1448
|
+
* The same as `unsigned int` in C (on x64 & arm64)
|
|
1449
|
+
*
|
|
1450
|
+
* C:
|
|
1451
|
+
* ```c
|
|
1452
|
+
* unsigned int
|
|
1453
|
+
* ```
|
|
1454
|
+
* JavaScript:
|
|
1455
|
+
* ```js
|
|
1456
|
+
* ptr(new Uint32Array(1))
|
|
1457
|
+
* ```
|
|
1458
|
+
*/
|
|
1459
|
+
uint32_t = 6,
|
|
1460
|
+
/**
|
|
1461
|
+
* 32-bit unsigned integer
|
|
1462
|
+
*
|
|
1463
|
+
* Alias of {@link FFIType.uint32_t}
|
|
1464
|
+
*/
|
|
1465
|
+
u32 = 6,
|
|
1466
|
+
|
|
1467
|
+
/**
|
|
1468
|
+
* int64 is a 64-bit signed integer
|
|
1469
|
+
*
|
|
1470
|
+
* This is not implemented yet!
|
|
1471
|
+
*/
|
|
1472
|
+
int64_t = 7,
|
|
1473
|
+
/**
|
|
1474
|
+
* i64 is a 64-bit signed integer
|
|
1475
|
+
*
|
|
1476
|
+
* This is not implemented yet!
|
|
1477
|
+
*/
|
|
1478
|
+
i64 = 7,
|
|
1479
|
+
|
|
1480
|
+
/**
|
|
1481
|
+
* 64-bit unsigned integer
|
|
1482
|
+
*
|
|
1483
|
+
* This is not implemented yet!
|
|
1484
|
+
*/
|
|
1485
|
+
uint64_t = 8,
|
|
1486
|
+
/**
|
|
1487
|
+
* 64-bit unsigned integer
|
|
1488
|
+
*
|
|
1489
|
+
* This is not implemented yet!
|
|
1490
|
+
*/
|
|
1491
|
+
u64 = 8,
|
|
1492
|
+
|
|
1493
|
+
/**
|
|
1494
|
+
* Doubles are not supported yet!
|
|
1495
|
+
*/
|
|
1496
|
+
double = 9,
|
|
1497
|
+
/**
|
|
1498
|
+
* Doubles are not supported yet!
|
|
1499
|
+
*/
|
|
1500
|
+
f64 = 9,
|
|
1501
|
+
/**
|
|
1502
|
+
* Floats are not supported yet!
|
|
1503
|
+
*/
|
|
1504
|
+
float = 10,
|
|
1505
|
+
/**
|
|
1506
|
+
* Floats are not supported yet!
|
|
1507
|
+
*/
|
|
1508
|
+
f32 = 10,
|
|
1509
|
+
|
|
1510
|
+
/**
|
|
1511
|
+
* Booelan value
|
|
1512
|
+
*
|
|
1513
|
+
* Must be `true` or `false`. `0` and `1` type coercion is not supported.
|
|
1514
|
+
*
|
|
1515
|
+
* In C, this corresponds to:
|
|
1516
|
+
* ```c
|
|
1517
|
+
* bool
|
|
1518
|
+
* _Bool
|
|
1519
|
+
* ```
|
|
1520
|
+
*
|
|
1521
|
+
*
|
|
1522
|
+
*/
|
|
1523
|
+
bool = 11,
|
|
1524
|
+
|
|
1525
|
+
/**
|
|
1526
|
+
* Pointer value
|
|
1527
|
+
*
|
|
1528
|
+
* See {@link Bun.FFI.ptr} for more information
|
|
1529
|
+
*
|
|
1530
|
+
* In C:
|
|
1531
|
+
* ```c
|
|
1532
|
+
* void*
|
|
1533
|
+
* ```
|
|
1534
|
+
*
|
|
1535
|
+
* In JavaScript:
|
|
1536
|
+
* ```js
|
|
1537
|
+
* ptr(new Uint8Array(1))
|
|
1538
|
+
* ```
|
|
1539
|
+
*/
|
|
1540
|
+
ptr = 12,
|
|
1541
|
+
/**
|
|
1542
|
+
* Pointer value
|
|
1543
|
+
*
|
|
1544
|
+
* alias of {@link FFIType.ptr}
|
|
1545
|
+
*/
|
|
1546
|
+
pointer = 12,
|
|
1547
|
+
|
|
1548
|
+
/**
|
|
1549
|
+
* void value
|
|
1550
|
+
*
|
|
1551
|
+
* void arguments are not supported
|
|
1552
|
+
*
|
|
1553
|
+
* void return type is the default return type
|
|
1554
|
+
*
|
|
1555
|
+
* In C:
|
|
1556
|
+
* ```c
|
|
1557
|
+
* void
|
|
1558
|
+
* ```
|
|
1559
|
+
*
|
|
1560
|
+
*/
|
|
1561
|
+
void = 13,
|
|
1562
|
+
|
|
1563
|
+
/**
|
|
1564
|
+
* When used as a `returns`, this will automatically become a {@link CString}.
|
|
1565
|
+
*
|
|
1566
|
+
* When used in `args` it is equivalent to {@link FFIType.pointer}
|
|
1567
|
+
*
|
|
1568
|
+
*/
|
|
1569
|
+
cstring = 14,
|
|
1570
|
+
|
|
1571
|
+
/**
|
|
1572
|
+
* Attempt to coerce `BigInt` into a `Number` if it fits. This improves performance
|
|
1573
|
+
* but means you might get a `BigInt` or you might get a `number`.
|
|
1574
|
+
*
|
|
1575
|
+
* In C, this always becomes `int64_t`
|
|
1576
|
+
*
|
|
1577
|
+
* In JavaScript, this could be number or it could be BigInt, depending on what
|
|
1578
|
+
* value is passed in.
|
|
1579
|
+
*
|
|
1580
|
+
*/
|
|
1581
|
+
i64_fast = 15,
|
|
1582
|
+
|
|
1583
|
+
/**
|
|
1584
|
+
* Attempt to coerce `BigInt` into a `Number` if it fits. This improves performance
|
|
1585
|
+
* but means you might get a `BigInt` or you might get a `number`.
|
|
1586
|
+
*
|
|
1587
|
+
* In C, this always becomes `uint64_t`
|
|
1588
|
+
*
|
|
1589
|
+
* In JavaScript, this could be number or it could be BigInt, depending on what
|
|
1590
|
+
* value is passed in.
|
|
1591
|
+
*
|
|
1592
|
+
*/
|
|
1593
|
+
u64_fast = 16,
|
|
1594
|
+
}
|
|
1595
|
+
export type FFITypeOrString =
|
|
1596
|
+
| FFIType
|
|
1597
|
+
| "char"
|
|
1598
|
+
| "int8_t"
|
|
1599
|
+
| "i8"
|
|
1600
|
+
| "uint8_t"
|
|
1601
|
+
| "u8"
|
|
1602
|
+
| "int16_t"
|
|
1603
|
+
| "i16"
|
|
1604
|
+
| "uint16_t"
|
|
1605
|
+
| "u16"
|
|
1606
|
+
| "int32_t"
|
|
1607
|
+
| "i32"
|
|
1608
|
+
| "int"
|
|
1609
|
+
| "uint32_t"
|
|
1610
|
+
| "u32"
|
|
1611
|
+
| "int64_t"
|
|
1612
|
+
| "i64"
|
|
1613
|
+
| "uint64_t"
|
|
1614
|
+
| "u64"
|
|
1615
|
+
| "double"
|
|
1616
|
+
| "f64"
|
|
1617
|
+
| "float"
|
|
1618
|
+
| "f32"
|
|
1619
|
+
| "bool"
|
|
1620
|
+
| "ptr"
|
|
1621
|
+
| "pointer"
|
|
1622
|
+
| "void"
|
|
1623
|
+
| "cstring";
|
|
1624
|
+
|
|
1625
|
+
interface FFIFunction {
|
|
1626
|
+
/**
|
|
1627
|
+
* Arguments to a FFI function (C ABI)
|
|
1628
|
+
*
|
|
1629
|
+
* Defaults to an empty array, which means no arguments.
|
|
1630
|
+
*
|
|
1631
|
+
* To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see {@link ptr}.
|
|
1632
|
+
*
|
|
1633
|
+
* @example
|
|
1634
|
+
* From JavaScript:
|
|
1635
|
+
* ```js
|
|
1636
|
+
* const lib = dlopen('add', {
|
|
1637
|
+
* // FFIType can be used or you can pass string labels.
|
|
1638
|
+
* args: [FFIType.i32, "i32"],
|
|
1639
|
+
* returns: "i32",
|
|
1640
|
+
* });
|
|
1641
|
+
* lib.symbols.add(1, 2)
|
|
1642
|
+
* ```
|
|
1643
|
+
* In C:
|
|
1644
|
+
* ```c
|
|
1645
|
+
* int add(int a, int b) {
|
|
1646
|
+
* return a + b;
|
|
1647
|
+
* }
|
|
1648
|
+
* ```
|
|
1649
|
+
*/
|
|
1650
|
+
args?: FFITypeOrString[];
|
|
1651
|
+
/**
|
|
1652
|
+
* Return type to a FFI function (C ABI)
|
|
1653
|
+
*
|
|
1654
|
+
* Defaults to {@link FFIType.void}
|
|
1655
|
+
*
|
|
1656
|
+
* To pass a pointer, use "ptr" or "pointer" as the type name. To get a pointer, see {@link ptr}.
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* From JavaScript:
|
|
1660
|
+
* ```js
|
|
1661
|
+
* const lib = dlopen('z', {
|
|
1662
|
+
* version: {
|
|
1663
|
+
* returns: "ptr",
|
|
1664
|
+
* }
|
|
1665
|
+
* });
|
|
1666
|
+
* console.log(new CString(lib.symbols.version()));
|
|
1667
|
+
* ```
|
|
1668
|
+
* In C:
|
|
1669
|
+
* ```c
|
|
1670
|
+
* char* version()
|
|
1671
|
+
* {
|
|
1672
|
+
* return "1.0.0";
|
|
1673
|
+
* }
|
|
1674
|
+
* ```
|
|
1675
|
+
*/
|
|
1676
|
+
returns?: FFITypeOrString;
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* Function pointer to the native function
|
|
1680
|
+
*
|
|
1681
|
+
* If provided, instead of using dlsym() to lookup the function, Bun will use this instead.
|
|
1682
|
+
* This pointer should not be null (0).
|
|
1683
|
+
*
|
|
1684
|
+
* This is useful if the library has already been loaded
|
|
1685
|
+
* or if the module is also using Node-API.
|
|
1686
|
+
*/
|
|
1687
|
+
ptr?: number | bigint;
|
|
1688
|
+
}
|
|
1689
|
+
|
|
1690
|
+
type Symbols = Record<string, FFIFunction>;
|
|
1691
|
+
|
|
1692
|
+
// /**
|
|
1693
|
+
// * Compile a callback function
|
|
1694
|
+
// *
|
|
1695
|
+
// * Returns a function pointer
|
|
1696
|
+
// *
|
|
1697
|
+
// */
|
|
1698
|
+
// export function callback(ffi: FFIFunction, cb: Function): number;
|
|
1699
|
+
|
|
1700
|
+
export interface Library {
|
|
1701
|
+
symbols: Record<
|
|
1702
|
+
string,
|
|
1703
|
+
CallableFunction & {
|
|
1704
|
+
/**
|
|
1705
|
+
* The function without a wrapper
|
|
1706
|
+
*/
|
|
1707
|
+
native: CallableFunction;
|
|
1708
|
+
}
|
|
1709
|
+
>;
|
|
1710
|
+
|
|
1711
|
+
/**
|
|
1712
|
+
* `dlclose` the library, unloading the symbols and freeing allocated memory.
|
|
1713
|
+
*
|
|
1714
|
+
* Once called, the library is no longer usable.
|
|
1715
|
+
*
|
|
1716
|
+
* Calling a function from a library that has been closed is undefined behavior.
|
|
1717
|
+
*/
|
|
1718
|
+
close(): void;
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Open a library using `"bun:ffi"`
|
|
1723
|
+
*
|
|
1724
|
+
* @param name The name of the library or file path. This will be passed to `dlopen()`
|
|
1725
|
+
* @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
|
|
1726
|
+
*
|
|
1727
|
+
* @example
|
|
1728
|
+
*
|
|
1729
|
+
* ```js
|
|
1730
|
+
* import {dlopen} from 'bun:ffi';
|
|
1731
|
+
*
|
|
1732
|
+
* const lib = dlopen("duckdb.dylib", {
|
|
1733
|
+
* get_version: {
|
|
1734
|
+
* returns: "cstring",
|
|
1735
|
+
* args: [],
|
|
1736
|
+
* },
|
|
1737
|
+
* });
|
|
1738
|
+
* lib.symbols.get_version();
|
|
1739
|
+
* // "1.0.0"
|
|
1740
|
+
* ```
|
|
1741
|
+
*
|
|
1742
|
+
* This is powered by just-in-time compiling C wrappers
|
|
1743
|
+
* that convert JavaScript types to C types and back. Internally,
|
|
1744
|
+
* bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
|
|
1745
|
+
* goes to Fabrice Bellard and TinyCC maintainers for making this possible.
|
|
1746
|
+
*
|
|
1747
|
+
*/
|
|
1748
|
+
export function dlopen(name: string, symbols: Symbols): Library;
|
|
1749
|
+
|
|
1750
|
+
/**
|
|
1751
|
+
* Turn a native library's function pointer into a JavaScript function
|
|
1752
|
+
*
|
|
1753
|
+
* Libraries using Node-API & bun:ffi in the same module could use this to skip an extra dlopen() step.
|
|
1754
|
+
*
|
|
1755
|
+
* @param fn {@link FFIFunction} declaration. `ptr` is required
|
|
1756
|
+
*
|
|
1757
|
+
* @example
|
|
1758
|
+
*
|
|
1759
|
+
* ```js
|
|
1760
|
+
* import {CFunction} from 'bun:ffi';
|
|
1761
|
+
*
|
|
1762
|
+
* const getVersion = new CFunction({
|
|
1763
|
+
* returns: "cstring",
|
|
1764
|
+
* args: [],
|
|
1765
|
+
* ptr: myNativeLibraryGetVersion,
|
|
1766
|
+
* });
|
|
1767
|
+
* getVersion();
|
|
1768
|
+
* getVersion.close();
|
|
1769
|
+
* ```
|
|
1770
|
+
*
|
|
1771
|
+
* This is powered by just-in-time compiling C wrappers
|
|
1772
|
+
* that convert JavaScript types to C types and back. Internally,
|
|
1773
|
+
* bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
|
|
1774
|
+
* goes to Fabrice Bellard and TinyCC maintainers for making this possible.
|
|
1775
|
+
*
|
|
1776
|
+
*/
|
|
1777
|
+
export function CFunction(
|
|
1778
|
+
fn: FFIFunction & { ptr: number | bigint }
|
|
1779
|
+
): CallableFunction & {
|
|
1780
|
+
/**
|
|
1781
|
+
* Free the memory allocated by the wrapping function
|
|
1782
|
+
*/
|
|
1783
|
+
close(): void;
|
|
1784
|
+
};
|
|
1785
|
+
|
|
1786
|
+
/**
|
|
1787
|
+
* Link a map of symbols to JavaScript functions
|
|
1788
|
+
*
|
|
1789
|
+
* This lets you use native libraries that were already loaded somehow. You usually will want {@link dlopen} instead.
|
|
1790
|
+
*
|
|
1791
|
+
* You could use this with Node-API to skip loading a second time.
|
|
1792
|
+
*
|
|
1793
|
+
* @param symbols Map of symbols to load where the key is the symbol name and the value is the {@link FFIFunction}
|
|
1794
|
+
*
|
|
1795
|
+
* @example
|
|
1796
|
+
*
|
|
1797
|
+
* ```js
|
|
1798
|
+
* import { linkSymbols } from "bun:ffi";
|
|
1799
|
+
*
|
|
1800
|
+
* const [majorPtr, minorPtr, patchPtr] = getVersionPtrs();
|
|
1801
|
+
*
|
|
1802
|
+
* const lib = linkSymbols({
|
|
1803
|
+
* // Unlike with dlopen(), the names here can be whatever you want
|
|
1804
|
+
* getMajor: {
|
|
1805
|
+
* returns: "cstring",
|
|
1806
|
+
* args: [],
|
|
1807
|
+
*
|
|
1808
|
+
* // Since this doesn't use dlsym(), you have to provide a valid ptr
|
|
1809
|
+
* // That ptr could be a number or a bigint
|
|
1810
|
+
* // An invalid pointer will crash your program.
|
|
1811
|
+
* ptr: majorPtr,
|
|
1812
|
+
* },
|
|
1813
|
+
* getMinor: {
|
|
1814
|
+
* returns: "cstring",
|
|
1815
|
+
* args: [],
|
|
1816
|
+
* ptr: minorPtr,
|
|
1817
|
+
* },
|
|
1818
|
+
* getPatch: {
|
|
1819
|
+
* returns: "cstring",
|
|
1820
|
+
* args: [],
|
|
1821
|
+
* ptr: patchPtr,
|
|
1822
|
+
* },
|
|
1823
|
+
* });
|
|
1824
|
+
*
|
|
1825
|
+
* const [major, minor, patch] = [
|
|
1826
|
+
* lib.symbols.getMajor(),
|
|
1827
|
+
* lib.symbols.getMinor(),
|
|
1828
|
+
* lib.symbols.getPatch(),
|
|
1829
|
+
* ];
|
|
1830
|
+
* ```
|
|
1831
|
+
*
|
|
1832
|
+
* This is powered by just-in-time compiling C wrappers
|
|
1833
|
+
* that convert JavaScript types to C types and back. Internally,
|
|
1834
|
+
* bun uses [tinycc](https://github.com/TinyCC/tinycc), so a big thanks
|
|
1835
|
+
* goes to Fabrice Bellard and TinyCC maintainers for making this possible.
|
|
1836
|
+
*
|
|
1837
|
+
*/
|
|
1838
|
+
export function linkSymbols(symbols: Symbols): Library;
|
|
1839
|
+
|
|
1840
|
+
/**
|
|
1841
|
+
* Read a pointer as a {@link Buffer}
|
|
1842
|
+
*
|
|
1843
|
+
* If `byteLength` is not provided, the pointer is assumed to be 0-terminated.
|
|
1844
|
+
*
|
|
1845
|
+
* @param ptr The memory address to read
|
|
1846
|
+
* @param byteOffset bytes to skip before reading
|
|
1847
|
+
* @param byteLength bytes to read
|
|
1848
|
+
*
|
|
1849
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1850
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1851
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1852
|
+
* undefined behavior. Use with care!
|
|
1853
|
+
*
|
|
1854
|
+
*/
|
|
1855
|
+
export function toBuffer(
|
|
1856
|
+
ptr: number,
|
|
1857
|
+
byteOffset?: number,
|
|
1858
|
+
byteLength?: number
|
|
1859
|
+
): Buffer;
|
|
1860
|
+
|
|
1861
|
+
/**
|
|
1862
|
+
* Read a pointer as an {@link ArrayBuffer}
|
|
1863
|
+
*
|
|
1864
|
+
* If `byteLength` is not provided, the pointer is assumed to be 0-terminated.
|
|
1865
|
+
*
|
|
1866
|
+
* @param ptr The memory address to read
|
|
1867
|
+
* @param byteOffset bytes to skip before reading
|
|
1868
|
+
* @param byteLength bytes to read
|
|
1869
|
+
*
|
|
1870
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1871
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1872
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1873
|
+
* undefined behavior. Use with care!
|
|
1874
|
+
*/
|
|
1875
|
+
export function toArrayBuffer(
|
|
1876
|
+
ptr: number,
|
|
1877
|
+
byteOffset?: number,
|
|
1878
|
+
byteLength?: number
|
|
1879
|
+
): ArrayBuffer;
|
|
1880
|
+
|
|
1881
|
+
/**
|
|
1882
|
+
* Get the pointer backing a {@link TypedArray} or {@link ArrayBuffer}
|
|
1883
|
+
*
|
|
1884
|
+
* Use this to pass {@link TypedArray} or {@link ArrayBuffer} to C functions.
|
|
1885
|
+
*
|
|
1886
|
+
* This is for use with FFI functions. For performance reasons, FFI will
|
|
1887
|
+
* not automatically convert typed arrays to C pointers.
|
|
1888
|
+
*
|
|
1889
|
+
* @param {TypedArray|ArrayBuffer|DataView} view the typed array or array buffer to get the pointer for
|
|
1890
|
+
* @param {number} byteOffset optional offset into the view in bytes
|
|
1891
|
+
*
|
|
1892
|
+
* @example
|
|
1893
|
+
*
|
|
1894
|
+
* From JavaScript:
|
|
1895
|
+
* ```js
|
|
1896
|
+
* const array = new Uint8Array(10);
|
|
1897
|
+
* const rawPtr = ptr(array);
|
|
1898
|
+
* myFFIFunction(rawPtr);
|
|
1899
|
+
* ```
|
|
1900
|
+
* To C:
|
|
1901
|
+
* ```c
|
|
1902
|
+
* void myFFIFunction(char* rawPtr) {
|
|
1903
|
+
* // Do something with rawPtr
|
|
1904
|
+
* }
|
|
1905
|
+
* ```
|
|
1906
|
+
*
|
|
1907
|
+
*/
|
|
1908
|
+
export function ptr(
|
|
1909
|
+
view: TypedArray | ArrayBufferLike | DataView,
|
|
1910
|
+
byteOffset?: number
|
|
1911
|
+
): number;
|
|
1912
|
+
|
|
1913
|
+
/**
|
|
1914
|
+
* Get a string from a UTF-8 encoded C string
|
|
1915
|
+
* If `byteLength` is not provided, the string is assumed to be null-terminated.
|
|
1916
|
+
*
|
|
1917
|
+
* @example
|
|
1918
|
+
* ```js
|
|
1919
|
+
* var ptr = lib.symbols.getVersion();
|
|
1920
|
+
* console.log(new CString(ptr));
|
|
1921
|
+
* ```
|
|
1922
|
+
*
|
|
1923
|
+
* @example
|
|
1924
|
+
* ```js
|
|
1925
|
+
* var ptr = lib.symbols.getVersion();
|
|
1926
|
+
* // print the first 4 characters
|
|
1927
|
+
* console.log(new CString(ptr, 0, 4));
|
|
1928
|
+
* ```
|
|
1929
|
+
*
|
|
1930
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1931
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1932
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1933
|
+
* undefined behavior. Use with care!
|
|
1934
|
+
*/
|
|
1935
|
+
|
|
1936
|
+
export class CString extends String {
|
|
1937
|
+
/**
|
|
1938
|
+
* Get a string from a UTF-8 encoded C string
|
|
1939
|
+
* If `byteLength` is not provided, the string is assumed to be null-terminated.
|
|
1940
|
+
*
|
|
1941
|
+
* @param ptr The pointer to the C string
|
|
1942
|
+
* @param byteOffset bytes to skip before reading
|
|
1943
|
+
* @param byteLength bytes to read
|
|
1944
|
+
*
|
|
1945
|
+
*
|
|
1946
|
+
* @example
|
|
1947
|
+
* ```js
|
|
1948
|
+
* var ptr = lib.symbols.getVersion();
|
|
1949
|
+
* console.log(new CString(ptr));
|
|
1950
|
+
* ```
|
|
1951
|
+
*
|
|
1952
|
+
* @example
|
|
1953
|
+
* ```js
|
|
1954
|
+
* var ptr = lib.symbols.getVersion();
|
|
1955
|
+
* // print the first 4 characters
|
|
1956
|
+
* console.log(new CString(ptr, 0, 4));
|
|
1957
|
+
* ```
|
|
1958
|
+
*
|
|
1959
|
+
* While there are some checks to catch invalid pointers, this is a difficult
|
|
1960
|
+
* thing to do safely. Passing an invalid pointer can crash the program and
|
|
1961
|
+
* reading beyond the bounds of the pointer will crash the program or cause
|
|
1962
|
+
* undefined behavior. Use with care!
|
|
1963
|
+
*/
|
|
1964
|
+
constructor(ptr: number, byteOffset?: number, byteLength?: number);
|
|
1965
|
+
|
|
1966
|
+
/**
|
|
1967
|
+
* The ptr to the C string
|
|
1968
|
+
*
|
|
1969
|
+
* This `CString` instance is a clone of the string, so it
|
|
1970
|
+
* is safe to continue using this instance after the `ptr` has been
|
|
1971
|
+
* freed.
|
|
1972
|
+
*/
|
|
1973
|
+
ptr: number;
|
|
1974
|
+
byteOffset?: number;
|
|
1975
|
+
byteLength?: number;
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* Get the {@link ptr} as an `ArrayBuffer`
|
|
1979
|
+
*
|
|
1980
|
+
* `null` or empty ptrs returns an `ArrayBuffer` with `byteLength` 0
|
|
1981
|
+
*/
|
|
1982
|
+
get arrayBuffer(): ArrayBuffer;
|
|
1983
|
+
}
|
|
1984
|
+
|
|
1985
|
+
/**
|
|
1986
|
+
* View the generated C code for FFI bindings
|
|
1987
|
+
*
|
|
1988
|
+
* You probably won't need this unless there's a bug in the FFI bindings
|
|
1989
|
+
* generator or you're just curious.
|
|
1990
|
+
*/
|
|
1991
|
+
export function viewSource(symbols: Symbols, is_callback?: false): string[];
|
|
1992
|
+
export function viewSource(callback: FFIFunction, is_callback: true): string;
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Platform-specific file extension name for dynamic libraries
|
|
1996
|
+
*
|
|
1997
|
+
* "." is not included
|
|
1998
|
+
*
|
|
1999
|
+
* @example
|
|
2000
|
+
* ```js
|
|
2001
|
+
* "dylib" // macOS
|
|
2002
|
+
* ```
|
|
2003
|
+
*
|
|
2004
|
+
* @example
|
|
2005
|
+
* ```js
|
|
2006
|
+
* "so" // linux
|
|
2007
|
+
* ```
|
|
2008
|
+
*/
|
|
2009
|
+
export const suffix: string;
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
|
|
2013
|
+
// ./sqlite.d.ts
|
|
2014
|
+
|
|
2015
|
+
/**
|
|
2016
|
+
* Fast SQLite3 driver for Bun.js
|
|
2017
|
+
* @since v0.0.83
|
|
2018
|
+
*
|
|
2019
|
+
* @example
|
|
2020
|
+
* ```ts
|
|
2021
|
+
* import { Database } from 'bun:sqlite';
|
|
2022
|
+
*
|
|
2023
|
+
* var db = new Database('app.db');
|
|
2024
|
+
* db.query('SELECT * FROM users WHERE name = ?').all('John');
|
|
2025
|
+
* // => [{ id: 1, name: 'John' }]
|
|
2026
|
+
* ```
|
|
2027
|
+
*
|
|
2028
|
+
* The following types can be used when binding parameters:
|
|
2029
|
+
*
|
|
2030
|
+
* | JavaScript type | SQLite type |
|
|
2031
|
+
* | -------------- | ----------- |
|
|
2032
|
+
* | `string` | `TEXT` |
|
|
2033
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
2034
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
2035
|
+
* | `Uint8Array` | `BLOB` |
|
|
2036
|
+
* | `Buffer` | `BLOB` |
|
|
2037
|
+
* | `bigint` | `INTEGER` |
|
|
2038
|
+
* | `null` | `NULL` |
|
|
2039
|
+
*/
|
|
2040
|
+
declare module "bun:sqlite" {
|
|
2041
|
+
export class Database {
|
|
2042
|
+
/**
|
|
2043
|
+
* Open or create a SQLite3 database
|
|
2044
|
+
*
|
|
2045
|
+
* @param filename The filename of the database to open. Pass an empty string (`""` or undefined) or `":memory:"` for an in-memory database.
|
|
2046
|
+
* @param options defaults to `{readwrite: true, create: true}`. If a number, then it's treated as `SQLITE_OPEN_*` constant flags.
|
|
2047
|
+
*
|
|
2048
|
+
* @example
|
|
2049
|
+
*
|
|
2050
|
+
* ```ts
|
|
2051
|
+
* const db = new Database("mydb.sqlite");
|
|
2052
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
2053
|
+
* db.run("INSERT INTO foo VALUES (?)", "baz");
|
|
2054
|
+
* console.log(db.query("SELECT * FROM foo").all());
|
|
2055
|
+
* ```
|
|
2056
|
+
*
|
|
2057
|
+
* @example
|
|
2058
|
+
*
|
|
2059
|
+
* Open an in-memory database
|
|
2060
|
+
*
|
|
2061
|
+
* ```ts
|
|
2062
|
+
* const db = new Database(":memory:");
|
|
2063
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
2064
|
+
* db.run("INSERT INTO foo VALUES (?)", "hiiiiii");
|
|
2065
|
+
* console.log(db.query("SELECT * FROM foo").all());
|
|
2066
|
+
* ```
|
|
2067
|
+
*
|
|
2068
|
+
* @example
|
|
2069
|
+
*
|
|
2070
|
+
* Open read-only
|
|
2071
|
+
*
|
|
2072
|
+
* ```ts
|
|
2073
|
+
* const db = new Database("mydb.sqlite", {readonly: true});
|
|
2074
|
+
* ```
|
|
2075
|
+
*/
|
|
2076
|
+
constructor(
|
|
2077
|
+
filename?: string,
|
|
2078
|
+
options?:
|
|
2079
|
+
| number
|
|
2080
|
+
| {
|
|
2081
|
+
/**
|
|
2082
|
+
* Open the database as read-only (no write operations, no create).
|
|
2083
|
+
*
|
|
2084
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READONLY}
|
|
2085
|
+
*/
|
|
2086
|
+
readonly?: boolean;
|
|
2087
|
+
/**
|
|
2088
|
+
* Allow creating a new database
|
|
2089
|
+
*
|
|
2090
|
+
* Equivalent to {@link constants.SQLITE_OPEN_CREATE}
|
|
2091
|
+
*/
|
|
2092
|
+
create?: boolean;
|
|
2093
|
+
/**
|
|
2094
|
+
* Open the database as read-write
|
|
2095
|
+
*
|
|
2096
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
|
|
2097
|
+
*/
|
|
2098
|
+
readwrite?: boolean;
|
|
2099
|
+
}
|
|
2100
|
+
);
|
|
2101
|
+
|
|
2102
|
+
/**
|
|
2103
|
+
* This is an alias of `new Database()`
|
|
2104
|
+
*
|
|
2105
|
+
* See {@link Database}
|
|
2106
|
+
*/
|
|
2107
|
+
static open(
|
|
2108
|
+
filename: string,
|
|
2109
|
+
options?:
|
|
2110
|
+
| number
|
|
2111
|
+
| {
|
|
2112
|
+
/**
|
|
2113
|
+
* Open the database as read-only (no write operations, no create).
|
|
2114
|
+
*
|
|
2115
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READONLY}
|
|
2116
|
+
*/
|
|
2117
|
+
readonly?: boolean;
|
|
2118
|
+
/**
|
|
2119
|
+
* Allow creating a new database
|
|
2120
|
+
*
|
|
2121
|
+
* Equivalent to {@link constants.SQLITE_OPEN_CREATE}
|
|
2122
|
+
*/
|
|
2123
|
+
create?: boolean;
|
|
2124
|
+
/**
|
|
2125
|
+
* Open the database as read-write
|
|
2126
|
+
*
|
|
2127
|
+
* Equivalent to {@link constants.SQLITE_OPEN_READWRITE}
|
|
2128
|
+
*/
|
|
2129
|
+
readwrite?: boolean;
|
|
2130
|
+
}
|
|
2131
|
+
): Database;
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
* Execute a SQL query **without returning any results**.
|
|
2135
|
+
*
|
|
2136
|
+
* This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
|
|
2137
|
+
*
|
|
2138
|
+
* @example
|
|
2139
|
+
* ```ts
|
|
2140
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
2141
|
+
* db.run("INSERT INTO foo VALUES (?)", "baz");
|
|
2142
|
+
* ```
|
|
2143
|
+
*
|
|
2144
|
+
* Useful for queries like:
|
|
2145
|
+
* - `CREATE TABLE`
|
|
2146
|
+
* - `INSERT INTO`
|
|
2147
|
+
* - `UPDATE`
|
|
2148
|
+
* - `DELETE FROM`
|
|
2149
|
+
* - `DROP TABLE`
|
|
2150
|
+
* - `PRAGMA`
|
|
2151
|
+
* - `ATTACH DATABASE`
|
|
2152
|
+
* - `DETACH DATABASE`
|
|
2153
|
+
* - `REINDEX`
|
|
2154
|
+
* - `VACUUM`
|
|
2155
|
+
* - `EXPLAIN ANALYZE`
|
|
2156
|
+
* - `CREATE INDEX`
|
|
2157
|
+
* - `CREATE TRIGGER`
|
|
2158
|
+
* - `CREATE VIEW`
|
|
2159
|
+
* - `CREATE VIRTUAL TABLE`
|
|
2160
|
+
* - `CREATE TEMPORARY TABLE`
|
|
2161
|
+
*
|
|
2162
|
+
* @param sql The SQL query to run
|
|
2163
|
+
*
|
|
2164
|
+
* @param bindings Optional bindings for the query
|
|
2165
|
+
*
|
|
2166
|
+
* @returns `Database` instance
|
|
2167
|
+
*
|
|
2168
|
+
* Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
|
|
2169
|
+
*
|
|
2170
|
+
* * The following types can be used when binding parameters:
|
|
2171
|
+
*
|
|
2172
|
+
* | JavaScript type | SQLite type |
|
|
2173
|
+
* | -------------- | ----------- |
|
|
2174
|
+
* | `string` | `TEXT` |
|
|
2175
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
2176
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
2177
|
+
* | `Uint8Array` | `BLOB` |
|
|
2178
|
+
* | `Buffer` | `BLOB` |
|
|
2179
|
+
* | `bigint` | `INTEGER` |
|
|
2180
|
+
* | `null` | `NULL` |
|
|
2181
|
+
*/
|
|
2182
|
+
run<ParamsType = SQLQueryBindings>(
|
|
2183
|
+
sqlQuery: string,
|
|
2184
|
+
...bindings: ParamsType[]
|
|
2185
|
+
): void;
|
|
2186
|
+
/**
|
|
2187
|
+
This is an alias of {@link Database.prototype.run}
|
|
2188
|
+
*/
|
|
2189
|
+
exec<ParamsType = SQLQueryBindings>(
|
|
2190
|
+
sqlQuery: string,
|
|
2191
|
+
...bindings: ParamsType[]
|
|
2192
|
+
): void;
|
|
2193
|
+
|
|
2194
|
+
/**
|
|
2195
|
+
* Compile a SQL query and return a {@link Statement} object. This is the
|
|
2196
|
+
* same as {@link prepare} except that it caches the compiled query.
|
|
2197
|
+
*
|
|
2198
|
+
* This **does not execute** the query, but instead prepares it for later
|
|
2199
|
+
* execution and caches the compiled query if possible.
|
|
2200
|
+
*
|
|
2201
|
+
* @example
|
|
2202
|
+
* ```ts
|
|
2203
|
+
* // compile the query
|
|
2204
|
+
* const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
|
|
2205
|
+
* // run the query
|
|
2206
|
+
* stmt.all("baz");
|
|
2207
|
+
*
|
|
2208
|
+
* // run the query again
|
|
2209
|
+
* stmt.all();
|
|
2210
|
+
* ```
|
|
2211
|
+
*
|
|
2212
|
+
* @param sql The SQL query to compile
|
|
2213
|
+
*
|
|
2214
|
+
* @returns `Statment` instance
|
|
2215
|
+
*
|
|
2216
|
+
* Under the hood, this calls `sqlite3_prepare_v3`.
|
|
2217
|
+
*
|
|
2218
|
+
*/
|
|
2219
|
+
query<ParamsType = SQLQueryBindings, ReturnType = any>(
|
|
2220
|
+
sqlQuery: string
|
|
2221
|
+
): Statement<ParamsType, ReturnType>;
|
|
2222
|
+
|
|
2223
|
+
/**
|
|
2224
|
+
* Compile a SQL query and return a {@link Statement} object.
|
|
2225
|
+
*
|
|
2226
|
+
* This does not cache the compiled query and does not execute the query.
|
|
2227
|
+
*
|
|
2228
|
+
* @example
|
|
2229
|
+
* ```ts
|
|
2230
|
+
* // compile the query
|
|
2231
|
+
* const stmt = db.query("SELECT * FROM foo WHERE bar = ?");
|
|
2232
|
+
* // run the query
|
|
2233
|
+
* stmt.all("baz");
|
|
2234
|
+
* ```
|
|
2235
|
+
*
|
|
2236
|
+
* @param sql The SQL query to compile
|
|
2237
|
+
* @param params Optional bindings for the query
|
|
2238
|
+
*
|
|
2239
|
+
* @returns `Statment` instance
|
|
2240
|
+
*
|
|
2241
|
+
* Under the hood, this calls `sqlite3_prepare_v3`.
|
|
2242
|
+
*
|
|
2243
|
+
*/
|
|
2244
|
+
prepare<ParamsType = SQLQueryBindings, ReturnType = any>(
|
|
2245
|
+
sql: string,
|
|
2246
|
+
...params: ParamsType[]
|
|
2247
|
+
): Statement<ParamsType, ReturnType>;
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* Is the database in a transaction?
|
|
2251
|
+
*
|
|
2252
|
+
* @returns `true` if the database is in a transaction, `false` otherwise
|
|
2253
|
+
*
|
|
2254
|
+
* @example
|
|
2255
|
+
* ```ts
|
|
2256
|
+
* db.run("CREATE TABLE foo (bar TEXT)");
|
|
2257
|
+
* db.run("INSERT INTO foo VALUES (?)", "baz");
|
|
2258
|
+
* db.run("BEGIN");
|
|
2259
|
+
* db.run("INSERT INTO foo VALUES (?)", "qux");
|
|
2260
|
+
* console.log(db.inTransaction());
|
|
2261
|
+
* ```
|
|
2262
|
+
*/
|
|
2263
|
+
get inTransaction(): boolean;
|
|
2264
|
+
|
|
2265
|
+
/**
|
|
2266
|
+
* Close the database connection.
|
|
2267
|
+
*
|
|
2268
|
+
* It is safe to call this method multiple times. If the database is already
|
|
2269
|
+
* closed, this is a no-op. Running queries after the database has been
|
|
2270
|
+
* closed will throw an error.
|
|
2271
|
+
*
|
|
2272
|
+
* @example
|
|
2273
|
+
* ```ts
|
|
2274
|
+
* db.close();
|
|
2275
|
+
* ```
|
|
2276
|
+
* This is called automatically when the database instance is garbage collected.
|
|
2277
|
+
*
|
|
2278
|
+
* Internally, this calls `sqlite3_close_v2`.
|
|
2279
|
+
*/
|
|
2280
|
+
close(): void;
|
|
2281
|
+
|
|
2282
|
+
/**
|
|
2283
|
+
* The filename passed when `new Database()` was called
|
|
2284
|
+
* @example
|
|
2285
|
+
* ```ts
|
|
2286
|
+
* const db = new Database("mydb.sqlite");
|
|
2287
|
+
* console.log(db.filename);
|
|
2288
|
+
* // => "mydb.sqlite"
|
|
2289
|
+
* ```
|
|
2290
|
+
*/
|
|
2291
|
+
readonly filename: string;
|
|
2292
|
+
|
|
2293
|
+
/**
|
|
2294
|
+
* The underlying `sqlite3` database handle
|
|
2295
|
+
*
|
|
2296
|
+
* In native code, this is not a file descriptor, but an index into an array of database handles
|
|
2297
|
+
*/
|
|
2298
|
+
readonly handle: number;
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* Load a SQLite3 extension
|
|
2302
|
+
*
|
|
2303
|
+
* macOS requires a custom SQLite3 library to be linked because the Apple build of SQLite for macOS disables loading extensions. See {@link Database.setCustomSQLite}
|
|
2304
|
+
*
|
|
2305
|
+
* Bun chooses the Apple build of SQLite on macOS because it brings a ~50% performance improvement.
|
|
2306
|
+
*
|
|
2307
|
+
* @param extension name/path of the extension to load
|
|
2308
|
+
* @param entryPoint optional entry point of the extension
|
|
2309
|
+
*/
|
|
2310
|
+
loadExtension(extension, entryPoint?: string): void;
|
|
2311
|
+
|
|
2312
|
+
/**
|
|
2313
|
+
* Change the dynamic library path to SQLite
|
|
2314
|
+
*
|
|
2315
|
+
* @note macOS-only
|
|
2316
|
+
*
|
|
2317
|
+
* This only works before SQLite is loaded, so
|
|
2318
|
+
* that's before you call `new Database()`.
|
|
2319
|
+
*
|
|
2320
|
+
* It can only be run once because this will load
|
|
2321
|
+
* the SQLite library into the process.
|
|
2322
|
+
*
|
|
2323
|
+
* @param path The path to the SQLite library
|
|
2324
|
+
*
|
|
2325
|
+
*/
|
|
2326
|
+
static setCustomSQLite(path: string): boolean;
|
|
2327
|
+
|
|
2328
|
+
/**
|
|
2329
|
+
* Creates a function that always runs inside a transaction. When the
|
|
2330
|
+
* function is invoked, it will begin a new transaction. When the function
|
|
2331
|
+
* returns, the transaction will be committed. If an exception is thrown,
|
|
2332
|
+
* the transaction will be rolled back (and the exception will propagate as
|
|
2333
|
+
* usual).
|
|
2334
|
+
*
|
|
2335
|
+
* @param insideTransaction The callback which runs inside a transaction
|
|
2336
|
+
*
|
|
2337
|
+
* @example
|
|
2338
|
+
* ```ts
|
|
2339
|
+
* // setup
|
|
2340
|
+
* import { Database } from "bun:sqlite";
|
|
2341
|
+
* const db = Database.open(":memory:");
|
|
2342
|
+
* db.exec(
|
|
2343
|
+
* "CREATE TABLE cats (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, age INTEGER)"
|
|
2344
|
+
* );
|
|
2345
|
+
*
|
|
2346
|
+
* const insert = db.prepare("INSERT INTO cats (name, age) VALUES ($name, $age)");
|
|
2347
|
+
* const insertMany = db.transaction((cats) => {
|
|
2348
|
+
* for (const cat of cats) insert.run(cat);
|
|
2349
|
+
* });
|
|
2350
|
+
*
|
|
2351
|
+
* insertMany([
|
|
2352
|
+
* { $name: "Joey", $age: 2 },
|
|
2353
|
+
* { $name: "Sally", $age: 4 },
|
|
2354
|
+
* { $name: "Junior", $age: 1 },
|
|
2355
|
+
* ]);
|
|
2356
|
+
* ```
|
|
2357
|
+
*/
|
|
2358
|
+
transaction(insideTransaction: (...args: any) => void): CallableFunction & {
|
|
2359
|
+
/**
|
|
2360
|
+
* uses "BEGIN DEFERRED"
|
|
2361
|
+
*/
|
|
2362
|
+
deferred: (...args: any) => void;
|
|
2363
|
+
/**
|
|
2364
|
+
* uses "BEGIN IMMEDIATE"
|
|
2365
|
+
*/
|
|
2366
|
+
immediate: (...args: any) => void;
|
|
2367
|
+
/**
|
|
2368
|
+
* uses "BEGIN EXCLUSIVE"
|
|
2369
|
+
*/
|
|
2370
|
+
exclusive: (...args: any) => void;
|
|
2371
|
+
};
|
|
2372
|
+
}
|
|
2373
|
+
|
|
2374
|
+
/**
|
|
2375
|
+
* A prepared statement.
|
|
2376
|
+
*
|
|
2377
|
+
* This is returned by {@link Database.prepare} and {@link Database.query}.
|
|
2378
|
+
*
|
|
2379
|
+
* @example
|
|
2380
|
+
* ```ts
|
|
2381
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2382
|
+
* stmt.all("baz");
|
|
2383
|
+
* // => [{bar: "baz"}]
|
|
2384
|
+
* ```
|
|
2385
|
+
*
|
|
2386
|
+
* @example
|
|
2387
|
+
* ```ts
|
|
2388
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2389
|
+
* stmt.get("baz");
|
|
2390
|
+
* // => {bar: "baz"}
|
|
2391
|
+
* ```
|
|
2392
|
+
*
|
|
2393
|
+
* @example
|
|
2394
|
+
* ```ts
|
|
2395
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2396
|
+
* stmt.run("baz");
|
|
2397
|
+
* // => undefined
|
|
2398
|
+
* ```
|
|
2399
|
+
*/
|
|
2400
|
+
export class Statement<ParamsType = SQLQueryBindings, ReturnType = any> {
|
|
2401
|
+
/**
|
|
2402
|
+
* Creates a new prepared statement from native code.
|
|
2403
|
+
*
|
|
2404
|
+
* This is used internally by the {@link Database} class. Probably you don't need to call this yourself.
|
|
2405
|
+
*/
|
|
2406
|
+
constructor(nativeHandle: any);
|
|
2407
|
+
|
|
2408
|
+
/**
|
|
2409
|
+
* Execute the prepared statement and return all results as objects.
|
|
2410
|
+
*
|
|
2411
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
2412
|
+
*
|
|
2413
|
+
* @example
|
|
2414
|
+
* ```ts
|
|
2415
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2416
|
+
*
|
|
2417
|
+
* stmt.all("baz");
|
|
2418
|
+
* // => [{bar: "baz"}]
|
|
2419
|
+
*
|
|
2420
|
+
* stmt.all();
|
|
2421
|
+
* // => [{bar: "baz"}]
|
|
2422
|
+
*
|
|
2423
|
+
* stmt.all("foo");
|
|
2424
|
+
* // => [{bar: "foo"}]
|
|
2425
|
+
* ```
|
|
2426
|
+
*/
|
|
2427
|
+
all(...params: ParamsType[]): ReturnType[];
|
|
2428
|
+
|
|
2429
|
+
/**
|
|
2430
|
+
* Execute the prepared statement and return **the first** result.
|
|
2431
|
+
*
|
|
2432
|
+
* If no result is returned, this returns `null`.
|
|
2433
|
+
*
|
|
2434
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
2435
|
+
*
|
|
2436
|
+
* @example
|
|
2437
|
+
* ```ts
|
|
2438
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2439
|
+
*
|
|
2440
|
+
* stmt.all("baz");
|
|
2441
|
+
* // => [{bar: "baz"}]
|
|
2442
|
+
*
|
|
2443
|
+
* stmt.all();
|
|
2444
|
+
* // => [{bar: "baz"}]
|
|
2445
|
+
*
|
|
2446
|
+
* stmt.all("foo");
|
|
2447
|
+
* // => [{bar: "foo"}]
|
|
2448
|
+
* ```
|
|
2449
|
+
*
|
|
2450
|
+
* The following types can be used when binding parameters:
|
|
2451
|
+
*
|
|
2452
|
+
* | JavaScript type | SQLite type |
|
|
2453
|
+
* | -------------- | ----------- |
|
|
2454
|
+
* | `string` | `TEXT` |
|
|
2455
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
2456
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
2457
|
+
* | `Uint8Array` | `BLOB` |
|
|
2458
|
+
* | `Buffer` | `BLOB` |
|
|
2459
|
+
* | `bigint` | `INTEGER` |
|
|
2460
|
+
* | `null` | `NULL` |
|
|
2461
|
+
*
|
|
2462
|
+
*/
|
|
2463
|
+
get(...params: ParamsType[]): ReturnType | null;
|
|
2464
|
+
|
|
2465
|
+
/**
|
|
2466
|
+
* Execute the prepared statement. This returns `undefined`.
|
|
2467
|
+
*
|
|
2468
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
2469
|
+
*
|
|
2470
|
+
* @example
|
|
2471
|
+
* ```ts
|
|
2472
|
+
* const stmt = db.prepare("UPDATE foo SET bar = ?");
|
|
2473
|
+
* stmt.run("baz");
|
|
2474
|
+
* // => undefined
|
|
2475
|
+
*
|
|
2476
|
+
* stmt.run();
|
|
2477
|
+
* // => undefined
|
|
2478
|
+
*
|
|
2479
|
+
* stmt.run("foo");
|
|
2480
|
+
* // => undefined
|
|
2481
|
+
* ```
|
|
2482
|
+
*
|
|
2483
|
+
* The following types can be used when binding parameters:
|
|
2484
|
+
*
|
|
2485
|
+
* | JavaScript type | SQLite type |
|
|
2486
|
+
* | -------------- | ----------- |
|
|
2487
|
+
* | `string` | `TEXT` |
|
|
2488
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
2489
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
2490
|
+
* | `Uint8Array` | `BLOB` |
|
|
2491
|
+
* | `Buffer` | `BLOB` |
|
|
2492
|
+
* | `bigint` | `INTEGER` |
|
|
2493
|
+
* | `null` | `NULL` |
|
|
2494
|
+
*
|
|
2495
|
+
*/
|
|
2496
|
+
run(...params: ParamsType[]): void;
|
|
2497
|
+
|
|
2498
|
+
/**
|
|
2499
|
+
* Execute the prepared statement and return the results as an array of arrays.
|
|
2500
|
+
*
|
|
2501
|
+
* This is a little faster than {@link all}.
|
|
2502
|
+
*
|
|
2503
|
+
* @param params optional values to bind to the statement. If omitted, the statement is run with the last bound values or no parameters if there are none.
|
|
2504
|
+
*
|
|
2505
|
+
* @example
|
|
2506
|
+
* ```ts
|
|
2507
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2508
|
+
*
|
|
2509
|
+
* stmt.values("baz");
|
|
2510
|
+
* // => [['baz']]
|
|
2511
|
+
*
|
|
2512
|
+
* stmt.values();
|
|
2513
|
+
* // => [['baz']]
|
|
2514
|
+
*
|
|
2515
|
+
* stmt.values("foo");
|
|
2516
|
+
* // => [['foo']]
|
|
2517
|
+
* ```
|
|
2518
|
+
*
|
|
2519
|
+
* The following types can be used when binding parameters:
|
|
2520
|
+
*
|
|
2521
|
+
* | JavaScript type | SQLite type |
|
|
2522
|
+
* | -------------- | ----------- |
|
|
2523
|
+
* | `string` | `TEXT` |
|
|
2524
|
+
* | `number` | `INTEGER` or `DECIMAL` |
|
|
2525
|
+
* | `boolean` | `INTEGER` (1 or 0) |
|
|
2526
|
+
* | `Uint8Array` | `BLOB` |
|
|
2527
|
+
* | `Buffer` | `BLOB` |
|
|
2528
|
+
* | `bigint` | `INTEGER` |
|
|
2529
|
+
* | `null` | `NULL` |
|
|
2530
|
+
*
|
|
2531
|
+
*/
|
|
2532
|
+
values(
|
|
2533
|
+
...params: ParamsType[]
|
|
2534
|
+
): Array<Array<string | bigint | number | boolean | Uint8Array>>;
|
|
2535
|
+
|
|
2536
|
+
/**
|
|
2537
|
+
* The names of the columns returned by the prepared statement.
|
|
2538
|
+
* @example
|
|
2539
|
+
* ```ts
|
|
2540
|
+
* const stmt = db.prepare("SELECT bar FROM foo WHERE bar = ?");
|
|
2541
|
+
*
|
|
2542
|
+
* console.log(stmt.columnNames);
|
|
2543
|
+
* // => ["bar"]
|
|
2544
|
+
* ```
|
|
2545
|
+
*/
|
|
2546
|
+
readonly columnNames: string[];
|
|
2547
|
+
|
|
2548
|
+
/**
|
|
2549
|
+
* The number of parameters expected in the prepared statement.
|
|
2550
|
+
* @example
|
|
2551
|
+
* ```ts
|
|
2552
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?");
|
|
2553
|
+
* console.log(stmt.paramsCount);
|
|
2554
|
+
* // => 1
|
|
2555
|
+
* ```
|
|
2556
|
+
* @example
|
|
2557
|
+
* ```ts
|
|
2558
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ? AND baz = ?");
|
|
2559
|
+
* console.log(stmt.paramsCount);
|
|
2560
|
+
* // => 2
|
|
2561
|
+
* ```
|
|
2562
|
+
*
|
|
2563
|
+
*/
|
|
2564
|
+
readonly paramsCount: number;
|
|
2565
|
+
|
|
2566
|
+
/**
|
|
2567
|
+
* Finalize the prepared statement, freeing the resources used by the
|
|
2568
|
+
* statement and preventing it from being executed again.
|
|
2569
|
+
*
|
|
2570
|
+
* This is called automatically when the prepared statement is garbage collected.
|
|
2571
|
+
*
|
|
2572
|
+
* It is safe to call this multiple times. Calling this on a finalized
|
|
2573
|
+
* statement has no effect.
|
|
2574
|
+
*
|
|
2575
|
+
* Internally, this calls `sqlite3_finalize`.
|
|
2576
|
+
*/
|
|
2577
|
+
finalize(): void;
|
|
2578
|
+
|
|
2579
|
+
/**
|
|
2580
|
+
* Return the expanded SQL string for the prepared statement.
|
|
2581
|
+
*
|
|
2582
|
+
* Internally, this calls `sqlite3_expanded_sql()` on the underlying `sqlite3_stmt`.
|
|
2583
|
+
*
|
|
2584
|
+
* @example
|
|
2585
|
+
* ```ts
|
|
2586
|
+
* const stmt = db.prepare("SELECT * FROM foo WHERE bar = ?", "baz");
|
|
2587
|
+
* console.log(stmt.toString());
|
|
2588
|
+
* // => "SELECT * FROM foo WHERE bar = 'baz'"
|
|
2589
|
+
* console.log(stmt);
|
|
2590
|
+
* // => "SELECT * FROM foo WHERE bar = 'baz'"
|
|
2591
|
+
* ```
|
|
2592
|
+
*/
|
|
2593
|
+
toString(): string;
|
|
2594
|
+
|
|
2595
|
+
/**
|
|
2596
|
+
* Native object representing the underlying `sqlite3_stmt`
|
|
2597
|
+
*
|
|
2598
|
+
* This is left untyped because the ABI of the native bindings may change at any time.
|
|
2599
|
+
*/
|
|
2600
|
+
readonly native: any;
|
|
2601
|
+
}
|
|
2602
|
+
|
|
2603
|
+
/**
|
|
2604
|
+
* Constants from `sqlite3.h`
|
|
2605
|
+
*
|
|
2606
|
+
* This list isn't exhaustive, but some of the ones which are relevant
|
|
2607
|
+
*/
|
|
2608
|
+
export const constants: {
|
|
2609
|
+
/**
|
|
2610
|
+
* Open the database as read-only (no write operations, no create).
|
|
2611
|
+
* @value 0x00000001
|
|
2612
|
+
*/
|
|
2613
|
+
SQLITE_OPEN_READONLY: number;
|
|
2614
|
+
/**
|
|
2615
|
+
* Open the database for reading and writing
|
|
2616
|
+
* @value 0x00000002
|
|
2617
|
+
*/
|
|
2618
|
+
SQLITE_OPEN_READWRITE: number;
|
|
2619
|
+
/**
|
|
2620
|
+
* Allow creating a new database
|
|
2621
|
+
* @value 0x00000004
|
|
2622
|
+
*/
|
|
2623
|
+
SQLITE_OPEN_CREATE: number;
|
|
2624
|
+
/**
|
|
2625
|
+
*
|
|
2626
|
+
* @value 0x00000008
|
|
2627
|
+
*/
|
|
2628
|
+
SQLITE_OPEN_DELETEONCLOSE: number;
|
|
2629
|
+
/**
|
|
2630
|
+
*
|
|
2631
|
+
* @value 0x00000010
|
|
2632
|
+
*/
|
|
2633
|
+
SQLITE_OPEN_EXCLUSIVE: number;
|
|
2634
|
+
/**
|
|
2635
|
+
*
|
|
2636
|
+
* @value 0x00000020
|
|
2637
|
+
*/
|
|
2638
|
+
SQLITE_OPEN_AUTOPROXY: number;
|
|
2639
|
+
/**
|
|
2640
|
+
*
|
|
2641
|
+
* @value 0x00000040
|
|
2642
|
+
*/
|
|
2643
|
+
SQLITE_OPEN_URI: number;
|
|
2644
|
+
/**
|
|
2645
|
+
*
|
|
2646
|
+
* @value 0x00000080
|
|
2647
|
+
*/
|
|
2648
|
+
SQLITE_OPEN_MEMORY: number;
|
|
2649
|
+
/**
|
|
2650
|
+
*
|
|
2651
|
+
* @value 0x00000100
|
|
2652
|
+
*/
|
|
2653
|
+
SQLITE_OPEN_MAIN_DB: number;
|
|
2654
|
+
/**
|
|
2655
|
+
*
|
|
2656
|
+
* @value 0x00000200
|
|
2657
|
+
*/
|
|
2658
|
+
SQLITE_OPEN_TEMP_DB: number;
|
|
2659
|
+
/**
|
|
2660
|
+
*
|
|
2661
|
+
* @value 0x00000400
|
|
2662
|
+
*/
|
|
2663
|
+
SQLITE_OPEN_TRANSIENT_DB: number;
|
|
2664
|
+
/**
|
|
2665
|
+
*
|
|
2666
|
+
* @value 0x00000800
|
|
2667
|
+
*/
|
|
2668
|
+
SQLITE_OPEN_MAIN_JOURNAL: number;
|
|
2669
|
+
/**
|
|
2670
|
+
*
|
|
2671
|
+
* @value 0x00001000
|
|
2672
|
+
*/
|
|
2673
|
+
SQLITE_OPEN_TEMP_JOURNAL: number;
|
|
2674
|
+
/**
|
|
2675
|
+
*
|
|
2676
|
+
* @value 0x00002000
|
|
2677
|
+
*/
|
|
2678
|
+
SQLITE_OPEN_SUBJOURNAL: number;
|
|
2679
|
+
/**
|
|
2680
|
+
*
|
|
2681
|
+
* @value 0x00004000
|
|
2682
|
+
*/
|
|
2683
|
+
SQLITE_OPEN_SUPER_JOURNAL: number;
|
|
2684
|
+
/**
|
|
2685
|
+
*
|
|
2686
|
+
* @value 0x00008000
|
|
2687
|
+
*/
|
|
2688
|
+
SQLITE_OPEN_NOMUTEX: number;
|
|
2689
|
+
/**
|
|
2690
|
+
*
|
|
2691
|
+
* @value 0x00010000
|
|
2692
|
+
*/
|
|
2693
|
+
SQLITE_OPEN_FULLMUTEX: number;
|
|
2694
|
+
/**
|
|
2695
|
+
*
|
|
2696
|
+
* @value 0x00020000
|
|
2697
|
+
*/
|
|
2698
|
+
SQLITE_OPEN_SHAREDCACHE: number;
|
|
2699
|
+
/**
|
|
2700
|
+
*
|
|
2701
|
+
* @value 0x00040000
|
|
2702
|
+
*/
|
|
2703
|
+
SQLITE_OPEN_PRIVATECACHE: number;
|
|
2704
|
+
/**
|
|
2705
|
+
*
|
|
2706
|
+
* @value 0x00080000
|
|
2707
|
+
*/
|
|
2708
|
+
SQLITE_OPEN_WAL: number;
|
|
2709
|
+
/**
|
|
2710
|
+
*
|
|
2711
|
+
* @value 0x01000000
|
|
2712
|
+
*/
|
|
2713
|
+
SQLITE_OPEN_NOFOLLOW: number;
|
|
2714
|
+
/**
|
|
2715
|
+
*
|
|
2716
|
+
* @value 0x02000000
|
|
2717
|
+
*/
|
|
2718
|
+
SQLITE_OPEN_EXRESCODE: number;
|
|
2719
|
+
/**
|
|
2720
|
+
*
|
|
2721
|
+
* @value 0x01
|
|
2722
|
+
*/
|
|
2723
|
+
SQLITE_PREPARE_PERSISTENT: number;
|
|
2724
|
+
/**
|
|
2725
|
+
*
|
|
2726
|
+
* @value 0x02
|
|
2727
|
+
*/
|
|
2728
|
+
SQLITE_PREPARE_NORMALIZE: number;
|
|
2729
|
+
/**
|
|
2730
|
+
*
|
|
2731
|
+
* @value 0x04
|
|
2732
|
+
*/
|
|
2733
|
+
SQLITE_PREPARE_NO_VTAB: number;
|
|
2734
|
+
};
|
|
2735
|
+
|
|
2736
|
+
/**
|
|
2737
|
+
* The native module implementing the sqlite3 C bindings
|
|
755
2738
|
*
|
|
756
|
-
*
|
|
757
|
-
|
|
758
|
-
export function gc(force: boolean): void;
|
|
759
|
-
|
|
760
|
-
/**
|
|
761
|
-
* JavaScriptCore engine's internal heap snapshot
|
|
2739
|
+
* It is lazily-initialized, so this will return `undefined` until the first
|
|
2740
|
+
* call to new Database().
|
|
762
2741
|
*
|
|
763
|
-
*
|
|
2742
|
+
* The native module makes no gurantees about ABI stability, so it is left
|
|
2743
|
+
* untyped
|
|
764
2744
|
*
|
|
765
|
-
* If you
|
|
766
|
-
|
|
767
|
-
interface HeapSnapshot {
|
|
768
|
-
/** "2" */
|
|
769
|
-
version: string;
|
|
770
|
-
|
|
771
|
-
/** "Inspector" */
|
|
772
|
-
type: string;
|
|
773
|
-
|
|
774
|
-
nodes: number[];
|
|
775
|
-
|
|
776
|
-
nodeClassNames: string[];
|
|
777
|
-
edges: number[];
|
|
778
|
-
edgeTypes: string[];
|
|
779
|
-
edgeNames: string[];
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
/**
|
|
783
|
-
* Generate a heap snapshot for seeing where the heap is being used
|
|
784
|
-
*/
|
|
785
|
-
export function generateHeapSnapshot(): HeapSnapshot;
|
|
786
|
-
|
|
787
|
-
/**
|
|
788
|
-
* The next time JavaScriptCore is idle, clear unused memory and attempt to reduce the heap size.
|
|
789
|
-
*/
|
|
790
|
-
export function shrink(): void;
|
|
791
|
-
|
|
792
|
-
/**
|
|
793
|
-
* Open a file in your local editor. Auto-detects via `$VISUAL` || `$EDITOR`
|
|
2745
|
+
* If you need to use it directly for some reason, please let us know because
|
|
2746
|
+
* that probably points to a deficiency in this API.
|
|
794
2747
|
*
|
|
795
|
-
* @param path path to open
|
|
796
2748
|
*/
|
|
797
|
-
export
|
|
798
|
-
|
|
799
|
-
interface EditorOptions {
|
|
800
|
-
editor?: "vscode" | "subl";
|
|
801
|
-
line?: number;
|
|
802
|
-
column?: number;
|
|
803
|
-
}
|
|
804
|
-
}
|
|
2749
|
+
export var native: any;
|
|
805
2750
|
|
|
806
|
-
type
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
| Float32Array
|
|
815
|
-
| Float64Array;
|
|
816
|
-
type TimeLike = string | number | Date;
|
|
817
|
-
type StringOrBuffer = string | TypedArray | ArrayBufferLike;
|
|
818
|
-
type PathLike = string | TypedArray | ArrayBufferLike;
|
|
819
|
-
type PathOrFileDescriptor = PathLike | number;
|
|
820
|
-
type NoParamCallback = VoidFunction;
|
|
821
|
-
type BufferEncoding =
|
|
822
|
-
| "buffer"
|
|
823
|
-
| "utf8"
|
|
824
|
-
| "utf-8"
|
|
825
|
-
| "ascii"
|
|
826
|
-
| "utf16le"
|
|
827
|
-
| "ucs2"
|
|
828
|
-
| "ucs-2"
|
|
829
|
-
| "latin1"
|
|
830
|
-
| "binary";
|
|
2751
|
+
export type SQLQueryBindings =
|
|
2752
|
+
| string
|
|
2753
|
+
| bigint
|
|
2754
|
+
| TypedArray
|
|
2755
|
+
| number
|
|
2756
|
+
| boolean
|
|
2757
|
+
| null
|
|
2758
|
+
| Record<string, string | bigint | TypedArray | number | boolean | null>;
|
|
831
2759
|
|
|
832
|
-
|
|
833
|
-
encoding?: BufferEncoding;
|
|
2760
|
+
export default Database;
|
|
834
2761
|
}
|
|
835
2762
|
|
|
836
|
-
declare var Bun: typeof import("bun");
|
|
837
|
-
|
|
838
2763
|
|
|
839
2764
|
// ./fs.d.ts
|
|
840
2765
|
|
|
@@ -4724,7 +6649,7 @@ interface Process {
|
|
|
4724
6649
|
setuid(id: number | string): void;
|
|
4725
6650
|
}
|
|
4726
6651
|
|
|
4727
|
-
declare
|
|
6652
|
+
declare var process: Process;
|
|
4728
6653
|
|
|
4729
6654
|
interface BlobInterface {
|
|
4730
6655
|
text(): Promise<string>;
|
|
@@ -4765,7 +6690,7 @@ interface Headers {
|
|
|
4765
6690
|
): void;
|
|
4766
6691
|
}
|
|
4767
6692
|
|
|
4768
|
-
declare
|
|
6693
|
+
declare var Headers: {
|
|
4769
6694
|
prototype: Headers;
|
|
4770
6695
|
new (init?: HeadersInit): Headers;
|
|
4771
6696
|
};
|
|
@@ -5009,8 +6934,13 @@ type ReferrerPolicy =
|
|
|
5009
6934
|
| "unsafe-url";
|
|
5010
6935
|
type RequestInfo = Request | string;
|
|
5011
6936
|
|
|
5012
|
-
type BodyInit = XMLHttpRequestBodyInit;
|
|
6937
|
+
type BodyInit = ReadableStream | XMLHttpRequestBodyInit;
|
|
5013
6938
|
type XMLHttpRequestBodyInit = Blob | BufferSource | string;
|
|
6939
|
+
type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
|
|
6940
|
+
type ReadableStreamDefaultReadResult<T> =
|
|
6941
|
+
| ReadableStreamDefaultReadValueResult<T>
|
|
6942
|
+
| ReadableStreamDefaultReadDoneResult;
|
|
6943
|
+
type ReadableStreamReader<T> = ReadableStreamDefaultReader<T>;
|
|
5014
6944
|
|
|
5015
6945
|
interface RequestInit {
|
|
5016
6946
|
/**
|
|
@@ -5223,7 +7153,7 @@ interface Crypto {
|
|
|
5223
7153
|
randomUUID(): string;
|
|
5224
7154
|
}
|
|
5225
7155
|
|
|
5226
|
-
declare
|
|
7156
|
+
declare var crypto: Crypto;
|
|
5227
7157
|
|
|
5228
7158
|
/**
|
|
5229
7159
|
* [`atob`](https://developer.mozilla.org/en-US/docs/Web/API/atob) converts ascii text into base64.
|
|
@@ -5603,7 +7533,7 @@ interface EventTarget {
|
|
|
5603
7533
|
): void;
|
|
5604
7534
|
}
|
|
5605
7535
|
|
|
5606
|
-
declare
|
|
7536
|
+
declare var EventTarget: {
|
|
5607
7537
|
prototype: EventTarget;
|
|
5608
7538
|
new (): EventTarget;
|
|
5609
7539
|
};
|
|
@@ -5707,7 +7637,7 @@ interface Event {
|
|
|
5707
7637
|
readonly NONE: number;
|
|
5708
7638
|
}
|
|
5709
7639
|
|
|
5710
|
-
declare
|
|
7640
|
+
declare var Event: {
|
|
5711
7641
|
prototype: Event;
|
|
5712
7642
|
new (type: string, eventInitDict?: EventInit): Event;
|
|
5713
7643
|
readonly AT_TARGET: number;
|
|
@@ -5727,7 +7657,7 @@ interface ErrorEvent extends Event {
|
|
|
5727
7657
|
readonly message: string;
|
|
5728
7658
|
}
|
|
5729
7659
|
|
|
5730
|
-
declare
|
|
7660
|
+
declare var ErrorEvent: {
|
|
5731
7661
|
prototype: ErrorEvent;
|
|
5732
7662
|
new (type: string, eventInitDict?: ErrorEventInit): ErrorEvent;
|
|
5733
7663
|
};
|
|
@@ -5775,7 +7705,7 @@ interface URLSearchParams {
|
|
|
5775
7705
|
): void;
|
|
5776
7706
|
}
|
|
5777
7707
|
|
|
5778
|
-
declare
|
|
7708
|
+
declare var URLSearchParams: {
|
|
5779
7709
|
prototype: URLSearchParams;
|
|
5780
7710
|
new (
|
|
5781
7711
|
init?: string[][] | Record<string, string> | string | URLSearchParams
|
|
@@ -5783,7 +7713,7 @@ declare let URLSearchParams: {
|
|
|
5783
7713
|
toString(): string;
|
|
5784
7714
|
};
|
|
5785
7715
|
|
|
5786
|
-
declare
|
|
7716
|
+
declare var URL: {
|
|
5787
7717
|
prototype: URL;
|
|
5788
7718
|
new (url: string | URL, base?: string | URL): URL;
|
|
5789
7719
|
/** Not implemented yet */
|
|
@@ -5802,7 +7732,7 @@ interface EventListenerObject {
|
|
|
5802
7732
|
handleEvent(object: Event): void;
|
|
5803
7733
|
}
|
|
5804
7734
|
|
|
5805
|
-
declare
|
|
7735
|
+
declare var AbortController: {
|
|
5806
7736
|
prototype: AbortController;
|
|
5807
7737
|
new (): AbortController;
|
|
5808
7738
|
};
|
|
@@ -5859,7 +7789,7 @@ interface AbortSignal extends EventTarget {
|
|
|
5859
7789
|
): void;
|
|
5860
7790
|
}
|
|
5861
7791
|
|
|
5862
|
-
declare
|
|
7792
|
+
declare var AbortSignal: {
|
|
5863
7793
|
prototype: AbortSignal;
|
|
5864
7794
|
new (): AbortSignal;
|
|
5865
7795
|
};
|
|
@@ -5878,6 +7808,409 @@ type DOMHighResTimeStamp = number;
|
|
|
5878
7808
|
// type EpochTimeStamp = number;
|
|
5879
7809
|
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
|
5880
7810
|
|
|
7811
|
+
/**
|
|
7812
|
+
* Low-level JavaScriptCore API for accessing the native ES Module loader (not a Bun API)
|
|
7813
|
+
*
|
|
7814
|
+
* Before using this, be aware of a few things:
|
|
7815
|
+
*
|
|
7816
|
+
* **Using this incorrectly will crash your application**.
|
|
7817
|
+
*
|
|
7818
|
+
* This API may change any time JavaScriptCore is updated.
|
|
7819
|
+
*
|
|
7820
|
+
* Bun may rewrite ESM import specifiers to point to bundled code. This will
|
|
7821
|
+
* be confusing when using this API, as it will return a string like
|
|
7822
|
+
* "/node_modules.server.bun".
|
|
7823
|
+
*
|
|
7824
|
+
* Bun may inject additional imports into your code. This usually has a `bun:` prefix.
|
|
7825
|
+
*
|
|
7826
|
+
*/
|
|
7827
|
+
declare var Loader: {
|
|
7828
|
+
/**
|
|
7829
|
+
* ESM module registry
|
|
7830
|
+
*
|
|
7831
|
+
* This lets you implement live reload in Bun. If you
|
|
7832
|
+
* delete a module specifier from this map, the next time it's imported, it
|
|
7833
|
+
* will be re-transpiled and loaded again.
|
|
7834
|
+
*
|
|
7835
|
+
* The keys are the module specifiers and the
|
|
7836
|
+
* values are metadata about the module.
|
|
7837
|
+
*
|
|
7838
|
+
* The keys are an implementation detail for Bun that will change between
|
|
7839
|
+
* versions.
|
|
7840
|
+
*
|
|
7841
|
+
* - Userland modules are an absolute file path
|
|
7842
|
+
* - Virtual modules have a `bun:` prefix or `node:` prefix
|
|
7843
|
+
* - JS polyfills start with `"/bun-vfs/"`. `"buffer"` is an example of a JS polyfill
|
|
7844
|
+
* - If you have a `node_modules.bun` file, many modules will point to that file
|
|
7845
|
+
*
|
|
7846
|
+
* Virtual modules and JS polyfills are embedded in bun's binary. They don't
|
|
7847
|
+
* point to anywhere in your local filesystem.
|
|
7848
|
+
*
|
|
7849
|
+
*
|
|
7850
|
+
*/
|
|
7851
|
+
registry: Map<
|
|
7852
|
+
string,
|
|
7853
|
+
{
|
|
7854
|
+
/**
|
|
7855
|
+
* This refers to the state the ESM module is in
|
|
7856
|
+
*
|
|
7857
|
+
* TODO: make an enum for this number
|
|
7858
|
+
*
|
|
7859
|
+
*
|
|
7860
|
+
*/
|
|
7861
|
+
state: number;
|
|
7862
|
+
dependencies: string[];
|
|
7863
|
+
/**
|
|
7864
|
+
* Your application will probably crash if you mess with this.
|
|
7865
|
+
*/
|
|
7866
|
+
module: any;
|
|
7867
|
+
}
|
|
7868
|
+
>;
|
|
7869
|
+
/**
|
|
7870
|
+
* For an already-evaluated module, return the dependencies as module specifiers
|
|
7871
|
+
*
|
|
7872
|
+
* This list is already sorted and uniqued.
|
|
7873
|
+
*
|
|
7874
|
+
* @example
|
|
7875
|
+
*
|
|
7876
|
+
* For this code:
|
|
7877
|
+
* ```js
|
|
7878
|
+
* // /foo.js
|
|
7879
|
+
* import classNames from 'classnames';
|
|
7880
|
+
* import React from 'react';
|
|
7881
|
+
* import {createElement} from 'react';
|
|
7882
|
+
* ```
|
|
7883
|
+
*
|
|
7884
|
+
* This would return:
|
|
7885
|
+
* ```js
|
|
7886
|
+
* Loader.dependencyKeysIfEvaluated("/foo.js")
|
|
7887
|
+
* ["bun:wrap", "/path/to/node_modules/classnames/index.js", "/path/to/node_modules/react/index.js"]
|
|
7888
|
+
* ```
|
|
7889
|
+
*
|
|
7890
|
+
* @param specifier - module specifier as it appears in transpiled source code
|
|
7891
|
+
*
|
|
7892
|
+
*/
|
|
7893
|
+
dependencyKeysIfEvaluated: (specifier: string) => string[];
|
|
7894
|
+
/**
|
|
7895
|
+
* The function JavaScriptCore internally calls when you use an import statement.
|
|
7896
|
+
*
|
|
7897
|
+
* This may return a path to `node_modules.server.bun`, which will be confusing.
|
|
7898
|
+
*
|
|
7899
|
+
* Consider {@link Bun.resolve} or {@link ImportMeta.resolve}
|
|
7900
|
+
* instead.
|
|
7901
|
+
*
|
|
7902
|
+
* @param specifier - module specifier as it appears in transpiled source code
|
|
7903
|
+
*/
|
|
7904
|
+
resolve: (specifier: string) => Promise<string>;
|
|
7905
|
+
/**
|
|
7906
|
+
* Synchronously resolve a module specifier
|
|
7907
|
+
*
|
|
7908
|
+
* This may return a path to `node_modules.server.bun`, which will be confusing.
|
|
7909
|
+
*
|
|
7910
|
+
* Consider {@link Bun.resolveSync}
|
|
7911
|
+
* instead.
|
|
7912
|
+
*/
|
|
7913
|
+
resolveSync: (specifier: string, from: string) => string;
|
|
7914
|
+
};
|
|
7915
|
+
|
|
7916
|
+
/** This Streams API interface represents a readable stream of byte data. The Fetch API offers a concrete instance of a ReadableStream through the body property of a Response object. */
|
|
7917
|
+
interface ReadableStream<R = any> {
|
|
7918
|
+
readonly locked: boolean;
|
|
7919
|
+
cancel(reason?: any): Promise<void>;
|
|
7920
|
+
getReader(): ReadableStreamDefaultReader<R>;
|
|
7921
|
+
pipeThrough<T>(
|
|
7922
|
+
transform: ReadableWritablePair<T, R>,
|
|
7923
|
+
options?: StreamPipeOptions
|
|
7924
|
+
): ReadableStream<T>;
|
|
7925
|
+
pipeTo(
|
|
7926
|
+
destination: WritableStream<R>,
|
|
7927
|
+
options?: StreamPipeOptions
|
|
7928
|
+
): Promise<void>;
|
|
7929
|
+
tee(): [ReadableStream<R>, ReadableStream<R>];
|
|
7930
|
+
forEach(
|
|
7931
|
+
callbackfn: (value: any, key: number, parent: ReadableStream<R>) => void,
|
|
7932
|
+
thisArg?: any
|
|
7933
|
+
): void;
|
|
7934
|
+
}
|
|
7935
|
+
|
|
7936
|
+
declare var ReadableStream: {
|
|
7937
|
+
prototype: ReadableStream;
|
|
7938
|
+
new <R = any>(
|
|
7939
|
+
underlyingSource?: DirectUnderlyingSource<R> | UnderlyingSource<R>,
|
|
7940
|
+
strategy?: QueuingStrategy<R>
|
|
7941
|
+
): ReadableStream<R>;
|
|
7942
|
+
};
|
|
7943
|
+
|
|
7944
|
+
interface QueuingStrategy<T = any> {
|
|
7945
|
+
highWaterMark?: number;
|
|
7946
|
+
size?: QueuingStrategySize<T>;
|
|
7947
|
+
}
|
|
7948
|
+
|
|
7949
|
+
interface QueuingStrategyInit {
|
|
7950
|
+
/**
|
|
7951
|
+
* Creates a new ByteLengthQueuingStrategy with the provided high water mark.
|
|
7952
|
+
*
|
|
7953
|
+
* Note that the provided high water mark will not be validated ahead of time. Instead, if it is negative, NaN, or not a number, the resulting ByteLengthQueuingStrategy will cause the corresponding stream constructor to throw.
|
|
7954
|
+
*/
|
|
7955
|
+
highWaterMark: number;
|
|
7956
|
+
}
|
|
7957
|
+
|
|
7958
|
+
/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
|
|
7959
|
+
interface ByteLengthQueuingStrategy extends QueuingStrategy<ArrayBufferView> {
|
|
7960
|
+
readonly highWaterMark: number;
|
|
7961
|
+
readonly size: QueuingStrategySize<ArrayBufferView>;
|
|
7962
|
+
}
|
|
7963
|
+
|
|
7964
|
+
declare var ByteLengthQueuingStrategy: {
|
|
7965
|
+
prototype: ByteLengthQueuingStrategy;
|
|
7966
|
+
new (init: QueuingStrategyInit): ByteLengthQueuingStrategy;
|
|
7967
|
+
};
|
|
7968
|
+
|
|
7969
|
+
interface ReadableStreamDefaultController<R = any> {
|
|
7970
|
+
readonly desiredSize: number | null;
|
|
7971
|
+
close(): void;
|
|
7972
|
+
enqueue(chunk?: R): void;
|
|
7973
|
+
error(e?: any): void;
|
|
7974
|
+
}
|
|
7975
|
+
|
|
7976
|
+
interface ReadableStreamDirectController {
|
|
7977
|
+
close(error?: Error): void;
|
|
7978
|
+
write(data: ArrayBufferView | ArrayBuffer | string): number | Promise<number>;
|
|
7979
|
+
end(): number | Promise<number>;
|
|
7980
|
+
flush(): number | Promise<number>;
|
|
7981
|
+
start(): void;
|
|
7982
|
+
}
|
|
7983
|
+
|
|
7984
|
+
declare var ReadableStreamDefaultController: {
|
|
7985
|
+
prototype: ReadableStreamDefaultController;
|
|
7986
|
+
new (): ReadableStreamDefaultController;
|
|
7987
|
+
};
|
|
7988
|
+
|
|
7989
|
+
interface ReadableStreamDefaultReader<R = any>
|
|
7990
|
+
extends ReadableStreamGenericReader {
|
|
7991
|
+
read(): Promise<ReadableStreamDefaultReadResult<R>>;
|
|
7992
|
+
releaseLock(): void;
|
|
7993
|
+
}
|
|
7994
|
+
|
|
7995
|
+
declare var ReadableStreamDefaultReader: {
|
|
7996
|
+
prototype: ReadableStreamDefaultReader;
|
|
7997
|
+
new <R = any>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
|
|
7998
|
+
};
|
|
7999
|
+
|
|
8000
|
+
interface ReadableStreamGenericReader {
|
|
8001
|
+
readonly closed: Promise<undefined>;
|
|
8002
|
+
cancel(reason?: any): Promise<void>;
|
|
8003
|
+
}
|
|
8004
|
+
|
|
8005
|
+
interface ReadableStreamDefaultReadDoneResult {
|
|
8006
|
+
done: true;
|
|
8007
|
+
value?: undefined;
|
|
8008
|
+
}
|
|
8009
|
+
|
|
8010
|
+
interface ReadableStreamDefaultReadValueResult<T> {
|
|
8011
|
+
done: false;
|
|
8012
|
+
value: T;
|
|
8013
|
+
}
|
|
8014
|
+
|
|
8015
|
+
interface ReadableWritablePair<R = any, W = any> {
|
|
8016
|
+
readable: ReadableStream<R>;
|
|
8017
|
+
/**
|
|
8018
|
+
* Provides a convenient, chainable way of piping this readable stream through a transform stream (or any other { writable, readable } pair). It simply pipes the stream into the writable side of the supplied pair, and returns the readable side for further use.
|
|
8019
|
+
*
|
|
8020
|
+
* Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
|
|
8021
|
+
*/
|
|
8022
|
+
writable: WritableStream<W>;
|
|
8023
|
+
}
|
|
8024
|
+
|
|
8025
|
+
/** This Streams API interface provides a standard abstraction for writing streaming data to a destination, known as a sink. This object comes with built-in backpressure and queuing. */
|
|
8026
|
+
interface WritableStream<W = any> {
|
|
8027
|
+
readonly locked: boolean;
|
|
8028
|
+
abort(reason?: any): Promise<void>;
|
|
8029
|
+
close(): Promise<void>;
|
|
8030
|
+
getWriter(): WritableStreamDefaultWriter<W>;
|
|
8031
|
+
}
|
|
8032
|
+
|
|
8033
|
+
declare var WritableStream: {
|
|
8034
|
+
prototype: WritableStream;
|
|
8035
|
+
new <W = any>(
|
|
8036
|
+
underlyingSink?: UnderlyingSink<W>,
|
|
8037
|
+
strategy?: QueuingStrategy<W>
|
|
8038
|
+
): WritableStream<W>;
|
|
8039
|
+
};
|
|
8040
|
+
|
|
8041
|
+
/** This Streams API interface represents a controller allowing control of a WritableStream's state. When constructing a WritableStream, the underlying sink is given a corresponding WritableStreamDefaultController instance to manipulate. */
|
|
8042
|
+
interface WritableStreamDefaultController {
|
|
8043
|
+
error(e?: any): void;
|
|
8044
|
+
}
|
|
8045
|
+
|
|
8046
|
+
declare var WritableStreamDefaultController: {
|
|
8047
|
+
prototype: WritableStreamDefaultController;
|
|
8048
|
+
new (): WritableStreamDefaultController;
|
|
8049
|
+
};
|
|
8050
|
+
|
|
8051
|
+
/** This Streams API interface is the object returned by WritableStream.getWriter() and once created locks the < writer to the WritableStream ensuring that no other streams can write to the underlying sink. */
|
|
8052
|
+
interface WritableStreamDefaultWriter<W = any> {
|
|
8053
|
+
readonly closed: Promise<undefined>;
|
|
8054
|
+
readonly desiredSize: number | null;
|
|
8055
|
+
readonly ready: Promise<undefined>;
|
|
8056
|
+
abort(reason?: any): Promise<void>;
|
|
8057
|
+
close(): Promise<void>;
|
|
8058
|
+
releaseLock(): void;
|
|
8059
|
+
write(chunk?: W): Promise<void>;
|
|
8060
|
+
}
|
|
8061
|
+
|
|
8062
|
+
declare var WritableStreamDefaultWriter: {
|
|
8063
|
+
prototype: WritableStreamDefaultWriter;
|
|
8064
|
+
new <W = any>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>;
|
|
8065
|
+
};
|
|
8066
|
+
|
|
8067
|
+
interface TransformerFlushCallback<O> {
|
|
8068
|
+
(controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
|
|
8069
|
+
}
|
|
8070
|
+
|
|
8071
|
+
interface TransformerStartCallback<O> {
|
|
8072
|
+
(controller: TransformStreamDefaultController<O>): any;
|
|
8073
|
+
}
|
|
8074
|
+
|
|
8075
|
+
interface TransformerTransformCallback<I, O> {
|
|
8076
|
+
(
|
|
8077
|
+
chunk: I,
|
|
8078
|
+
controller: TransformStreamDefaultController<O>
|
|
8079
|
+
): void | PromiseLike<void>;
|
|
8080
|
+
}
|
|
8081
|
+
|
|
8082
|
+
interface UnderlyingSinkAbortCallback {
|
|
8083
|
+
(reason?: any): void | PromiseLike<void>;
|
|
8084
|
+
}
|
|
8085
|
+
|
|
8086
|
+
interface UnderlyingSinkCloseCallback {
|
|
8087
|
+
(): void | PromiseLike<void>;
|
|
8088
|
+
}
|
|
8089
|
+
|
|
8090
|
+
interface UnderlyingSinkStartCallback {
|
|
8091
|
+
(controller: WritableStreamDefaultController): any;
|
|
8092
|
+
}
|
|
8093
|
+
|
|
8094
|
+
interface UnderlyingSinkWriteCallback<W> {
|
|
8095
|
+
(
|
|
8096
|
+
chunk: W,
|
|
8097
|
+
controller: WritableStreamDefaultController
|
|
8098
|
+
): void | PromiseLike<void>;
|
|
8099
|
+
}
|
|
8100
|
+
|
|
8101
|
+
interface UnderlyingSourceCancelCallback {
|
|
8102
|
+
(reason?: any): void | PromiseLike<void>;
|
|
8103
|
+
}
|
|
8104
|
+
|
|
8105
|
+
interface UnderlyingSink<W = any> {
|
|
8106
|
+
abort?: UnderlyingSinkAbortCallback;
|
|
8107
|
+
close?: UnderlyingSinkCloseCallback;
|
|
8108
|
+
start?: UnderlyingSinkStartCallback;
|
|
8109
|
+
type?: undefined | "default" | "bytes";
|
|
8110
|
+
write?: UnderlyingSinkWriteCallback<W>;
|
|
8111
|
+
}
|
|
8112
|
+
|
|
8113
|
+
interface UnderlyingSource<R = any> {
|
|
8114
|
+
cancel?: UnderlyingSourceCancelCallback;
|
|
8115
|
+
pull?: UnderlyingSourcePullCallback<R>;
|
|
8116
|
+
start?: UnderlyingSourceStartCallback<R>;
|
|
8117
|
+
type?: undefined;
|
|
8118
|
+
}
|
|
8119
|
+
|
|
8120
|
+
interface DirectUnderlyingSource<R = any> {
|
|
8121
|
+
cancel?: UnderlyingSourceCancelCallback;
|
|
8122
|
+
pull: (
|
|
8123
|
+
controller: ReadableStreamDirectController
|
|
8124
|
+
) => void | PromiseLike<void>;
|
|
8125
|
+
type: "direct";
|
|
8126
|
+
}
|
|
8127
|
+
|
|
8128
|
+
interface UnderlyingSourcePullCallback<R> {
|
|
8129
|
+
(controller: ReadableStreamController<R>): void | PromiseLike<void>;
|
|
8130
|
+
}
|
|
8131
|
+
|
|
8132
|
+
interface UnderlyingSourceStartCallback<R> {
|
|
8133
|
+
(controller: ReadableStreamController<R>): any;
|
|
8134
|
+
}
|
|
8135
|
+
|
|
8136
|
+
interface GenericTransformStream {
|
|
8137
|
+
readonly readable: ReadableStream;
|
|
8138
|
+
readonly writable: WritableStream;
|
|
8139
|
+
}
|
|
8140
|
+
|
|
8141
|
+
interface TransformStream<I = any, O = any> {
|
|
8142
|
+
readonly readable: ReadableStream<O>;
|
|
8143
|
+
readonly writable: WritableStream<I>;
|
|
8144
|
+
}
|
|
8145
|
+
|
|
8146
|
+
declare var TransformStream: {
|
|
8147
|
+
prototype: TransformStream;
|
|
8148
|
+
new <I = any, O = any>(
|
|
8149
|
+
transformer?: Transformer<I, O>,
|
|
8150
|
+
writableStrategy?: QueuingStrategy<I>,
|
|
8151
|
+
readableStrategy?: QueuingStrategy<O>
|
|
8152
|
+
): TransformStream<I, O>;
|
|
8153
|
+
};
|
|
8154
|
+
|
|
8155
|
+
interface TransformStreamDefaultController<O = any> {
|
|
8156
|
+
readonly desiredSize: number | null;
|
|
8157
|
+
enqueue(chunk?: O): void;
|
|
8158
|
+
error(reason?: any): void;
|
|
8159
|
+
terminate(): void;
|
|
8160
|
+
}
|
|
8161
|
+
|
|
8162
|
+
declare var TransformStreamDefaultController: {
|
|
8163
|
+
prototype: TransformStreamDefaultController;
|
|
8164
|
+
new (): TransformStreamDefaultController;
|
|
8165
|
+
};
|
|
8166
|
+
|
|
8167
|
+
interface StreamPipeOptions {
|
|
8168
|
+
preventAbort?: boolean;
|
|
8169
|
+
preventCancel?: boolean;
|
|
8170
|
+
/**
|
|
8171
|
+
* Pipes this readable stream to a given writable stream destination. The way in which the piping process behaves under various error conditions can be customized with a number of passed options. It returns a promise that fulfills when the piping process completes successfully, or rejects if any errors were encountered.
|
|
8172
|
+
*
|
|
8173
|
+
* Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
|
|
8174
|
+
*
|
|
8175
|
+
* Errors and closures of the source and destination streams propagate as follows:
|
|
8176
|
+
*
|
|
8177
|
+
* An error in this source readable stream will abort destination, unless preventAbort is truthy. The returned promise will be rejected with the source's error, or with any error that occurs during aborting the destination.
|
|
8178
|
+
*
|
|
8179
|
+
* An error in destination will cancel this source readable stream, unless preventCancel is truthy. The returned promise will be rejected with the destination's error, or with any error that occurs during canceling the source.
|
|
8180
|
+
*
|
|
8181
|
+
* When this source readable stream closes, destination will be closed, unless preventClose is truthy. The returned promise will be fulfilled once this process completes, unless an error is encountered while closing the destination, in which case it will be rejected with that error.
|
|
8182
|
+
*
|
|
8183
|
+
* If destination starts out closed or closing, this source readable stream will be canceled, unless preventCancel is true. The returned promise will be rejected with an error indicating piping to a closed stream failed, or with any error that occurs during canceling the source.
|
|
8184
|
+
*
|
|
8185
|
+
* The signal option can be set to an AbortSignal to allow aborting an ongoing pipe operation via the corresponding AbortController. In this case, this source readable stream will be canceled, and destination aborted, unless the respective options preventCancel or preventAbort are set.
|
|
8186
|
+
*/
|
|
8187
|
+
preventClose?: boolean;
|
|
8188
|
+
signal?: AbortSignal;
|
|
8189
|
+
}
|
|
8190
|
+
|
|
8191
|
+
/** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
|
|
8192
|
+
interface CountQueuingStrategy extends QueuingStrategy {
|
|
8193
|
+
readonly highWaterMark: number;
|
|
8194
|
+
readonly size: QueuingStrategySize;
|
|
8195
|
+
}
|
|
8196
|
+
|
|
8197
|
+
declare var CountQueuingStrategy: {
|
|
8198
|
+
prototype: CountQueuingStrategy;
|
|
8199
|
+
new (init: QueuingStrategyInit): CountQueuingStrategy;
|
|
8200
|
+
};
|
|
8201
|
+
|
|
8202
|
+
interface QueuingStrategySize<T = any> {
|
|
8203
|
+
(chunk?: T): number;
|
|
8204
|
+
}
|
|
8205
|
+
|
|
8206
|
+
interface Transformer<I = any, O = any> {
|
|
8207
|
+
flush?: TransformerFlushCallback<O>;
|
|
8208
|
+
readableType?: undefined;
|
|
8209
|
+
start?: TransformerStartCallback<O>;
|
|
8210
|
+
transform?: TransformerTransformCallback<I, O>;
|
|
8211
|
+
writableType?: undefined;
|
|
8212
|
+
}
|
|
8213
|
+
|
|
5881
8214
|
|
|
5882
8215
|
// ./path.d.ts
|
|
5883
8216
|
|
|
@@ -6109,7 +8442,7 @@ declare module "node:path/win32" {
|
|
|
6109
8442
|
*/
|
|
6110
8443
|
|
|
6111
8444
|
declare module "bun:test" {
|
|
6112
|
-
export function describe(label: string, body: () =>
|
|
8445
|
+
export function describe(label: string, body: () => void): any;
|
|
6113
8446
|
export function it(label: string, test: () => void | Promise<any>): any;
|
|
6114
8447
|
export function test(label: string, test: () => void | Promise<any>): any;
|
|
6115
8448
|
|
|
@@ -6126,3 +8459,67 @@ declare module "test" {
|
|
|
6126
8459
|
export = BunTestModule;
|
|
6127
8460
|
}
|
|
6128
8461
|
|
|
8462
|
+
|
|
8463
|
+
// ./jsc.d.ts
|
|
8464
|
+
|
|
8465
|
+
declare module "bun:jsc" {
|
|
8466
|
+
export function describe(value: any): string;
|
|
8467
|
+
export function describeArray(args: any[]): string;
|
|
8468
|
+
export function gcAndSweep(): void;
|
|
8469
|
+
export function fullGC(): void;
|
|
8470
|
+
export function edenGC(): void;
|
|
8471
|
+
export function heapSize(): number;
|
|
8472
|
+
export function heapStats(): {
|
|
8473
|
+
heapSize: number;
|
|
8474
|
+
heapCapacity: number;
|
|
8475
|
+
extraMemorySize: number;
|
|
8476
|
+
objectCount: number;
|
|
8477
|
+
protectedObjectCount: number;
|
|
8478
|
+
globalObjectCount: number;
|
|
8479
|
+
protectedGlobalObjectCount: number;
|
|
8480
|
+
objectTypeCounts: Record<string, number>;
|
|
8481
|
+
protectedObjectTypeCounts: Record<string, number>;
|
|
8482
|
+
};
|
|
8483
|
+
export function memoryUsage(): {
|
|
8484
|
+
current: number;
|
|
8485
|
+
peak: number;
|
|
8486
|
+
currentCommit: number;
|
|
8487
|
+
peakCommit: number;
|
|
8488
|
+
pageFaults: number;
|
|
8489
|
+
};
|
|
8490
|
+
export function getRandomSeed(): number;
|
|
8491
|
+
export function setRandomSeed(value: number): void;
|
|
8492
|
+
export function isRope(input: string): boolean;
|
|
8493
|
+
export function callerSourceOrigin(): string;
|
|
8494
|
+
export function noFTL(func: Function): Function;
|
|
8495
|
+
export function noOSRExitFuzzing(func: Function): Function;
|
|
8496
|
+
export function optimizeNextInvocation(func: Function): Function;
|
|
8497
|
+
export function numberOfDFGCompiles(func: Function): number;
|
|
8498
|
+
export function releaseWeakRefs(): void;
|
|
8499
|
+
export function totalCompileTime(func: Function): number;
|
|
8500
|
+
export function reoptimizationRetryCount(func: Function): number;
|
|
8501
|
+
export function drainMicrotasks(): void;
|
|
8502
|
+
|
|
8503
|
+
/**
|
|
8504
|
+
* This returns objects which native code has explicitly protected from being
|
|
8505
|
+
* garbage collected
|
|
8506
|
+
*
|
|
8507
|
+
* By calling this function you create another reference to the object, which
|
|
8508
|
+
* will further prevent it from being garbage collected
|
|
8509
|
+
*
|
|
8510
|
+
* This function is mostly a debugging tool for bun itself.
|
|
8511
|
+
*
|
|
8512
|
+
* Warning: not all objects returned are supposed to be observable from JavaScript
|
|
8513
|
+
*/
|
|
8514
|
+
export function getProtectedObjects(): any[];
|
|
8515
|
+
|
|
8516
|
+
/**
|
|
8517
|
+
* Start a remote debugging socket server on the given port.
|
|
8518
|
+
*
|
|
8519
|
+
* This exposes JavaScriptCore's built-in debugging server.
|
|
8520
|
+
*
|
|
8521
|
+
* This is untested. May not be supported yet on macOS
|
|
8522
|
+
*/
|
|
8523
|
+
export function startRemoteDebugger(host?: string, port?: number): void;
|
|
8524
|
+
}
|
|
8525
|
+
|