bun-types 1.0.25 → 1.0.26

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/globals.d.ts ADDED
@@ -0,0 +1,2000 @@
1
+ export {};
2
+
3
+ type _ReadableStream<T> = typeof globalThis extends {
4
+ onerror: any;
5
+ ReadableStream: infer T;
6
+ }
7
+ ? T
8
+ : import("stream/web").ReadableStream<T>;
9
+ type _WritableStream<T> = typeof globalThis extends {
10
+ onerror: any;
11
+ WritableStream: infer T;
12
+ }
13
+ ? T
14
+ : import("stream/web").WritableStream<T>;
15
+
16
+ type _TextEncoder = typeof globalThis extends {
17
+ onerror: any;
18
+ TextEncoder: infer T;
19
+ }
20
+ ? T
21
+ : Bun.TextEncoder;
22
+
23
+ type _TextDecoder = typeof globalThis extends {
24
+ onerror: any;
25
+ TextDecoder: infer T;
26
+ }
27
+ ? T
28
+ : Bun.TextDecoder;
29
+
30
+ type _Performance = typeof globalThis extends {
31
+ onerror: any;
32
+ }
33
+ ? {}
34
+ : import("perf_hooks").Performance;
35
+
36
+ type _Worker = typeof globalThis extends { onerror: any; Worker: infer T } ? T : Bun.Worker;
37
+
38
+ type _Event = typeof globalThis extends { onerror: any; Event: any }
39
+ ? {}
40
+ : {
41
+ /** This is not used in Node.js and is provided purely for completeness. */
42
+ readonly bubbles: boolean;
43
+ /** Alias for event.stopPropagation(). This is not used in Node.js and is provided purely for completeness. */
44
+ cancelBubble: () => void;
45
+ /** True if the event was created with the cancelable option */
46
+ readonly cancelable: boolean;
47
+ /** This is not used in Node.js and is provided purely for completeness. */
48
+ readonly composed: boolean;
49
+ /** Returns an array containing the current EventTarget as the only entry or empty if the event is not being dispatched. This is not used in Node.js and is provided purely for completeness. */
50
+ composedPath(): [EventTarget?];
51
+ /** Alias for event.target. */
52
+ readonly currentTarget: EventTarget | null;
53
+ /** Is true if cancelable is true and event.preventDefault() has been called. */
54
+ readonly defaultPrevented: boolean;
55
+ /** This is not used in Node.js and is provided purely for completeness. */
56
+ readonly eventPhase: 0 | 2;
57
+ /** The `AbortSignal` "abort" event is emitted with `isTrusted` set to `true`. The value is `false` in all other cases. */
58
+ readonly isTrusted: boolean;
59
+ /** Sets the `defaultPrevented` property to `true` if `cancelable` is `true`. */
60
+ preventDefault(): void;
61
+ /** This is not used in Node.js and is provided purely for completeness. */
62
+ returnValue: boolean;
63
+ /** Alias for event.target. */
64
+ readonly srcElement: EventTarget | null;
65
+ /** Stops the invocation of event listeners after the current one completes. */
66
+ stopImmediatePropagation(): void;
67
+ /** This is not used in Node.js and is provided purely for completeness. */
68
+ stopPropagation(): void;
69
+ /** The `EventTarget` dispatching the event */
70
+ readonly target: EventTarget | null;
71
+ /** The millisecond timestamp when the Event object was created. */
72
+ readonly timeStamp: number;
73
+ /** Returns the type of event, e.g. "click", "hashchange", or "submit". */
74
+ readonly type: string;
75
+ };
76
+
77
+ type _EventTarget = typeof globalThis extends {
78
+ onerror: any;
79
+ EventTarget: any;
80
+ }
81
+ ? {}
82
+ : {
83
+ /**
84
+ * Adds a new handler for the `type` event. Any given `listener` is added only once per `type` and per `capture` option value.
85
+ *
86
+ * If the `once` option is true, the `listener` is removed after the next time a `type` event is dispatched.
87
+ *
88
+ * The `capture` option is not used by Node.js in any functional way other than tracking registered event listeners per the `EventTarget` specification.
89
+ * Specifically, the `capture` option is used as part of the key when registering a `listener`.
90
+ * Any individual `listener` may be added once with `capture = false`, and once with `capture = true`.
91
+ */
92
+ addEventListener(
93
+ type: string,
94
+ listener: EventListener | EventListenerObject,
95
+ options?: AddEventListenerOptions | boolean,
96
+ ): void;
97
+ /** Dispatches a synthetic event event to target and returns true if either event's cancelable attribute value is false or its preventDefault() method was not invoked, and false otherwise. */
98
+ dispatchEvent(event: Event): boolean;
99
+ /** Removes the event listener in target's event listener list with the same type, callback, and options. */
100
+ removeEventListener(
101
+ type: string,
102
+ listener: EventListener | EventListenerObject,
103
+ options?: Bun.EventListenerOptions | boolean,
104
+ ): void;
105
+ };
106
+
107
+ type _Crypto = typeof globalThis extends {
108
+ onerror: any;
109
+ Crypto: infer T;
110
+ }
111
+ ? T
112
+ : import("crypto").webcrypto.Crypto;
113
+
114
+ type _SubtleCrypto = typeof globalThis extends {
115
+ onerror: any;
116
+ SubtleCrypto: infer T;
117
+ }
118
+ ? T
119
+ : import("crypto").webcrypto.SubtleCrypto;
120
+
121
+ type _CryptoKey = typeof globalThis extends {
122
+ onerror: any;
123
+ CryptoKey: infer T;
124
+ }
125
+ ? T
126
+ : import("crypto").webcrypto.CryptoKey;
127
+
128
+ type _Body = typeof globalThis extends { onerror: any }
129
+ ? {}
130
+ : {
131
+ readonly body: ReadableStream | null;
132
+ readonly bodyUsed: boolean;
133
+ readonly arrayBuffer: () => Promise<ArrayBuffer>;
134
+ readonly blob: () => Promise<Blob>;
135
+ readonly formData: () => Promise<FormData>;
136
+ readonly json: () => Promise<unknown>;
137
+ readonly text: () => Promise<string>;
138
+ };
139
+
140
+ import type { MessagePort } from "worker_threads";
141
+ import type { TextEncoder as NodeTextEncoder, TextDecoder as NodeTextDecoder } from "util";
142
+ import type { WebSocket as _WebSocket } from "ws";
143
+
144
+ declare module "*.txt" {
145
+ var text: string;
146
+ export = text;
147
+ }
148
+
149
+ declare module "*.toml" {
150
+ var contents: any;
151
+ export = contents;
152
+ }
153
+
154
+ declare global {
155
+ var Bun: typeof import("bun");
156
+
157
+ namespace NodeJS {
158
+ interface Process {
159
+ readonly version: string;
160
+ browser: boolean;
161
+
162
+ /** Whether you are using Bun */
163
+ isBun: 1; // FIXME: this should actually return a boolean
164
+ /** The current git sha of Bun **/
165
+ revision: string;
166
+ reallyExit(code?: number): never;
167
+ dlopen(module: { exports: any }, filename: string, flags?: number): void;
168
+ }
169
+ }
170
+
171
+ namespace Bun {
172
+ type ArrayBufferView = NodeJS.TypedArray | DataView;
173
+ type StringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike;
174
+ type PathLike = string | NodeJS.TypedArray | ArrayBufferLike | URL;
175
+ type BodyInit = ReadableStream | XMLHttpRequestBodyInit | URLSearchParams;
176
+ type XMLHttpRequestBodyInit = Blob | BufferSource | string | FormData;
177
+ type ReadableStreamController<T> = ReadableStreamDefaultController<T>;
178
+ type ReadableStreamDefaultReadResult<T> =
179
+ | ReadableStreamDefaultReadValueResult<T>
180
+ | ReadableStreamDefaultReadDoneResult;
181
+ type ReadableStreamReader<T> = ReadableStreamDefaultReader<T>;
182
+ type Transferable = ArrayBuffer | MessagePort;
183
+ type MessageEventSource = undefined;
184
+ type Encoding = "utf-8" | "windows-1252" | "utf-16";
185
+ type UncaughtExceptionOrigin = "uncaughtException" | "unhandledRejection";
186
+ type MultipleResolveType = "resolve" | "reject";
187
+ type BeforeExitListener = (code: number) => void;
188
+ type DisconnectListener = () => void;
189
+ type ExitListener = (code: number) => void;
190
+ type RejectionHandledListener = (promise: Promise<unknown>) => void;
191
+ type FormDataEntryValue = File | string;
192
+ type WarningListener = (warning: Error) => void;
193
+ type MessageListener = (message: unknown, sendHandle: unknown) => void;
194
+ type SignalsListener = (signal: NodeJS.Signals) => void;
195
+ type BlobPart = string | Blob | BufferSource;
196
+ type TimerHandler = (...args: any[]) => void;
197
+ type BufferSource = NodeJS.TypedArray | DataView | ArrayBufferLike;
198
+ type DOMHighResTimeStamp = number;
199
+ type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
200
+
201
+ type BlobOrStringOrBuffer = string | NodeJS.TypedArray | ArrayBufferLike | Blob;
202
+
203
+ type Platform =
204
+ | "aix"
205
+ | "android"
206
+ | "darwin"
207
+ | "freebsd"
208
+ | "haiku"
209
+ | "linux"
210
+ | "openbsd"
211
+ | "sunos"
212
+ | "win32"
213
+ | "cygwin"
214
+ | "netbsd";
215
+ type Architecture = "arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x64";
216
+
217
+ type UncaughtExceptionListener = (error: Error, origin: UncaughtExceptionOrigin) => void;
218
+ /**
219
+ * Most of the time the unhandledRejection will be an Error, but this should not be relied upon
220
+ * as *anything* can be thrown/rejected, it is therefore unsafe to assume that the value is an Error.
221
+ */
222
+ type UnhandledRejectionListener = (reason: unknown, promise: Promise<unknown>) => void;
223
+
224
+ type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<unknown>, value: unknown) => void;
225
+
226
+ type HeadersInit = Headers | Record<string, string> | Array<[string, string]> | IterableIterator<[string, string]>;
227
+
228
+ type ResponseType = "basic" | "cors" | "default" | "error" | "opaque" | "opaqueredirect";
229
+
230
+ interface TextEncoder extends NodeTextEncoder {
231
+ new (encoding?: Bun.Encoding, options?: { fatal?: boolean; ignoreBOM?: boolean }): TextEncoder;
232
+ /**
233
+ * UTF-8 encodes the `src` string to the `dest` Uint8Array and returns an object
234
+ * containing the read Unicode code units and written UTF-8 bytes.
235
+ *
236
+ * ```js
237
+ * const encoder = new TextEncoder();
238
+ * const src = 'this is some data';
239
+ * const dest = new Uint8Array(10);
240
+ * const { read, written } = encoder.encodeInto(src, dest);
241
+ * ```
242
+ * @param src The text to encode.
243
+ * @param dest The array to hold the encode result.
244
+ */
245
+ encodeInto(src?: string, dest?: Bun.BufferSource): import("util").EncodeIntoResult;
246
+ }
247
+
248
+ interface TextDecoder extends NodeTextDecoder {
249
+ new (encoding?: Bun.Encoding, options?: { fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
250
+ }
251
+
252
+ interface ErrorEventInit extends EventInit {
253
+ colno?: number;
254
+ error?: any;
255
+ filename?: string;
256
+ lineno?: number;
257
+ message?: string;
258
+ }
259
+
260
+ interface CloseEventInit extends EventInit {
261
+ code?: number;
262
+ reason?: string;
263
+ wasClean?: boolean;
264
+ }
265
+
266
+ interface MessageEventInit<T = any> extends EventInit {
267
+ data?: T;
268
+ lastEventId?: string;
269
+ origin?: string;
270
+ source?: Bun.MessageEventSource | null;
271
+ }
272
+
273
+ interface EventInit {
274
+ bubbles?: boolean;
275
+ cancelable?: boolean;
276
+ composed?: boolean;
277
+ }
278
+
279
+ interface EventListenerOptions {
280
+ capture?: boolean;
281
+ }
282
+
283
+ interface CustomEventInit<T = any> extends Bun.EventInit {
284
+ detail?: T;
285
+ }
286
+
287
+ /** A message received by a target object. */
288
+ interface MessageEvent<T = any> extends Event {
289
+ /** Returns the data of the message. */
290
+ readonly data: T;
291
+ /** Returns the last event ID string, for server-sent events. */
292
+ readonly lastEventId: string;
293
+ /** Returns the origin of the message, for server-sent events and cross-document messaging. */
294
+ readonly origin: string;
295
+ /** Returns the MessagePort array sent with the message, for cross-document messaging and channel messaging. */
296
+ readonly ports: readonly MessagePort[]; // ReadonlyArray<typeof import("worker_threads").MessagePort["prototype"]>;
297
+ readonly source: Bun.MessageEventSource | null;
298
+ }
299
+
300
+ interface ReadableStreamDefaultReadManyResult<T> {
301
+ done: boolean;
302
+ /** Number of bytes */
303
+ size: number;
304
+ value: T[];
305
+ }
306
+
307
+ interface ResponseInit {
308
+ headers?: HeadersInit;
309
+ /** @default 200 */
310
+ status?: number;
311
+
312
+ /** @default "OK" */
313
+ statusText?: string;
314
+ }
315
+
316
+ interface EventSourceEventMap {
317
+ error: Event;
318
+ message: MessageEvent;
319
+ open: Event;
320
+ }
321
+
322
+ interface EventInit {
323
+ bubbles?: boolean;
324
+ cancelable?: boolean;
325
+ composed?: boolean;
326
+ }
327
+
328
+ interface EventListenerOptions {
329
+ /** Not directly used by Node.js. Added for API completeness. Default: `false`. */
330
+ capture?: boolean;
331
+ }
332
+
333
+ interface AddEventListenerOptions extends EventListenerOptions {
334
+ /** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */
335
+ once?: boolean;
336
+ /** When `true`, serves as a hint that the listener will not call the `Event` object's `preventDefault()` method. Default: false. */
337
+ passive?: boolean;
338
+ signal?: AbortSignal;
339
+ }
340
+
341
+ interface EventListener {
342
+ (evt: Event): void;
343
+ }
344
+
345
+ interface EventListenerObject {
346
+ handleEvent(object: Event): void;
347
+ }
348
+
349
+ interface FetchEvent extends Event {
350
+ readonly request: Request;
351
+ readonly url: string;
352
+
353
+ waitUntil(promise: Promise<any>): void;
354
+ respondWith(response: Response | Promise<Response>): void;
355
+ }
356
+
357
+ interface EventMap {
358
+ fetch: FetchEvent;
359
+ message: MessageEvent;
360
+ messageerror: MessageEvent;
361
+ // exit: Event;
362
+ }
363
+
364
+ interface StructuredSerializeOptions {
365
+ transfer?: Bun.Transferable[];
366
+ }
367
+
368
+ interface EventSource extends EventTarget {
369
+ new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource;
370
+
371
+ onerror: ((this: EventSource, ev: Event) => any) | null;
372
+ onmessage: ((this: EventSource, ev: MessageEvent) => any) | null;
373
+ onopen: ((this: EventSource, ev: Event) => any) | null;
374
+ /** Returns the state of this EventSource object's connection. It can have the values described below. */
375
+ readonly readyState: number;
376
+ /** Returns the URL providing the event stream. */
377
+ readonly url: string;
378
+ /** Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise.
379
+ *
380
+ * Not supported in Bun
381
+ */
382
+ readonly withCredentials: boolean;
383
+ /** Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. */
384
+ close(): void;
385
+ readonly CLOSED: 2;
386
+ readonly CONNECTING: 0;
387
+ readonly OPEN: 1;
388
+ addEventListener<K extends keyof EventSourceEventMap>(
389
+ type: K,
390
+ listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
391
+ options?: boolean | AddEventListenerOptions,
392
+ ): void;
393
+ addEventListener(
394
+ type: string,
395
+ listener: (this: EventSource, event: MessageEvent) => any,
396
+ options?: boolean | AddEventListenerOptions,
397
+ ): void;
398
+ addEventListener(
399
+ type: string,
400
+ listener: EventListenerOrEventListenerObject,
401
+ options?: boolean | AddEventListenerOptions,
402
+ ): void;
403
+ removeEventListener<K extends keyof EventSourceEventMap>(
404
+ type: K,
405
+ listener: (this: EventSource, ev: EventSourceEventMap[K]) => any,
406
+ options?: boolean | EventListenerOptions,
407
+ ): void;
408
+ removeEventListener(
409
+ type: string,
410
+ listener: (this: EventSource, event: MessageEvent) => any,
411
+ options?: boolean | EventListenerOptions,
412
+ ): void;
413
+ removeEventListener(
414
+ type: string,
415
+ listener: EventListenerOrEventListenerObject,
416
+ options?: boolean | EventListenerOptions,
417
+ ): void;
418
+
419
+ /**
420
+ * Keep the event loop alive while connection is open or reconnecting
421
+ *
422
+ * Not available in browsers
423
+ */
424
+ ref(): void;
425
+
426
+ /**
427
+ * Do not keep the event loop alive while connection is open or reconnecting
428
+ *
429
+ * Not available in browsers
430
+ */
431
+ unref(): void;
432
+ }
433
+
434
+ interface TransformerFlushCallback<O> {
435
+ (controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
436
+ }
437
+
438
+ interface TransformerStartCallback<O> {
439
+ (controller: TransformStreamDefaultController<O>): any;
440
+ }
441
+
442
+ interface TransformerTransformCallback<I, O> {
443
+ (chunk: I, controller: TransformStreamDefaultController<O>): void | PromiseLike<void>;
444
+ }
445
+
446
+ interface UnderlyingSinkAbortCallback {
447
+ (reason?: any): void | PromiseLike<void>;
448
+ }
449
+
450
+ interface UnderlyingSinkCloseCallback {
451
+ (): void | PromiseLike<void>;
452
+ }
453
+
454
+ interface UnderlyingSinkStartCallback {
455
+ (controller: WritableStreamDefaultController): any;
456
+ }
457
+
458
+ interface UnderlyingSinkWriteCallback<W> {
459
+ (chunk: W, controller: WritableStreamDefaultController): void | PromiseLike<void>;
460
+ }
461
+
462
+ interface UnderlyingSourceCancelCallback {
463
+ (reason?: any): void | PromiseLike<void>;
464
+ }
465
+
466
+ interface UnderlyingSink<W = any> {
467
+ abort?: UnderlyingSinkAbortCallback;
468
+ close?: UnderlyingSinkCloseCallback;
469
+ start?: UnderlyingSinkStartCallback;
470
+ type?: undefined | "default" | "bytes";
471
+ write?: UnderlyingSinkWriteCallback<W>;
472
+ }
473
+
474
+ interface UnderlyingSource<R = any> {
475
+ cancel?: UnderlyingSourceCancelCallback;
476
+ pull?: UnderlyingSourcePullCallback<R>;
477
+ start?: UnderlyingSourceStartCallback<R>;
478
+ /**
479
+ * Mode "bytes" is not currently supported.
480
+ */
481
+ type?: undefined;
482
+ }
483
+
484
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
485
+ interface DirectUnderlyingSource<R = any> {
486
+ cancel?: UnderlyingSourceCancelCallback;
487
+ pull: (controller: ReadableStreamDirectController) => void | PromiseLike<void>;
488
+ type: "direct";
489
+ }
490
+
491
+ interface UnderlyingSourcePullCallback<R> {
492
+ (controller: ReadableStreamController<R>): void | PromiseLike<void>;
493
+ }
494
+
495
+ interface UnderlyingSourceStartCallback<R> {
496
+ (controller: ReadableStreamController<R>): any;
497
+ }
498
+
499
+ interface GenericTransformStream {
500
+ readonly readable: ReadableStream;
501
+ readonly writable: WritableStream;
502
+ }
503
+
504
+ interface AbstractWorkerEventMap {
505
+ error: ErrorEvent;
506
+ }
507
+
508
+ interface WorkerEventMap extends AbstractWorkerEventMap {
509
+ message: MessageEvent;
510
+ messageerror: MessageEvent;
511
+ close: CloseEvent;
512
+ open: Event;
513
+ }
514
+
515
+ type WorkerType = "classic" | "module";
516
+
517
+ interface AbstractWorker {
518
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ServiceWorker/error_event) */
519
+ onerror: ((this: AbstractWorker, ev: ErrorEvent) => any) | null;
520
+ addEventListener<K extends keyof AbstractWorkerEventMap>(
521
+ type: K,
522
+ listener: (this: AbstractWorker, ev: AbstractWorkerEventMap[K]) => any,
523
+ options?: boolean | AddEventListenerOptions,
524
+ ): void;
525
+ addEventListener(
526
+ type: string,
527
+ listener: EventListenerOrEventListenerObject,
528
+ options?: boolean | AddEventListenerOptions,
529
+ ): void;
530
+ removeEventListener<K extends keyof AbstractWorkerEventMap>(
531
+ type: K,
532
+ listener: (this: AbstractWorker, ev: AbstractWorkerEventMap[K]) => any,
533
+ options?: boolean | EventListenerOptions,
534
+ ): void;
535
+ removeEventListener(
536
+ type: string,
537
+ listener: EventListenerOrEventListenerObject,
538
+ options?: boolean | EventListenerOptions,
539
+ ): void;
540
+ }
541
+
542
+ /**
543
+ * Bun's Web Worker constructor supports some extra options on top of the API browsers have.
544
+ */
545
+ interface WorkerOptions {
546
+ /**
547
+ * A string specifying an identifying name for the DedicatedWorkerGlobalScope representing the scope of
548
+ * the worker, which is mainly useful for debugging purposes.
549
+ */
550
+ name?: string;
551
+
552
+ /**
553
+ * Use less memory, but make the worker slower.
554
+ *
555
+ * Internally, this sets the heap size configuration in JavaScriptCore to be
556
+ * the small heap instead of the large heap.
557
+ */
558
+ smol?: boolean;
559
+
560
+ /**
561
+ * When `true`, the worker will keep the parent thread alive until the worker is terminated or `unref`'d.
562
+ * When `false`, the worker will not keep the parent thread alive.
563
+ *
564
+ * By default, this is `false`.
565
+ */
566
+ ref?: boolean;
567
+
568
+ /**
569
+ * In Bun, this does nothing.
570
+ */
571
+ type?: Bun.WorkerType | undefined;
572
+
573
+ /**
574
+ * List of arguments which would be stringified and appended to
575
+ * `Bun.argv` / `process.argv` in the worker. This is mostly similar to the `data`
576
+ * but the values will be available on the global `Bun.argv` as if they
577
+ * were passed as CLI options to the script.
578
+ */
579
+ argv?: any[] | undefined;
580
+
581
+ /** If `true` and the first argument is a string, interpret the first argument to the constructor as a script that is executed once the worker is online. */
582
+ // eval?: boolean | undefined;
583
+
584
+ /**
585
+ * If set, specifies the initial value of process.env inside the Worker thread. As a special value, worker.SHARE_ENV may be used to specify that the parent thread and the child thread should share their environment variables; in that case, changes to one thread's process.env object affect the other thread as well. Default: process.env.
586
+ */
587
+ env?: Record<string, string> | typeof import("node:worker_threads")["SHARE_ENV"] | undefined;
588
+
589
+ /**
590
+ * In Bun, this does nothing.
591
+ */
592
+ credentials?: import("undici-types").RequestCredentials | undefined;
593
+
594
+ /**
595
+ * @default true
596
+ */
597
+ // trackUnmanagedFds?: boolean;
598
+
599
+ // resourceLimits?: import("worker_threads").ResourceLimits;
600
+ }
601
+
602
+ interface Worker extends EventTarget, AbstractWorker {
603
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Worker/message_event) */
604
+ onmessage: ((this: Worker, ev: MessageEvent) => any) | null;
605
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/Worker/messageerror_event) */
606
+ onmessageerror: ((this: Worker, ev: MessageEvent) => any) | null;
607
+ /**
608
+ * Clones message and transmits it to worker's global environment. transfer can be passed as a list of objects that are to be transferred rather than cloned.
609
+ *
610
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Worker/postMessage)
611
+ */
612
+ postMessage(message: any, transfer: Transferable[]): void;
613
+ postMessage(message: any, options?: StructuredSerializeOptions): void;
614
+ /**
615
+ * Aborts worker's associated global environment.
616
+ *
617
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/Worker/terminate)
618
+ */
619
+ terminate(): void;
620
+ addEventListener<K extends keyof WorkerEventMap>(
621
+ type: K,
622
+ listener: (this: Worker, ev: WorkerEventMap[K]) => any,
623
+ options?: boolean | AddEventListenerOptions,
624
+ ): void;
625
+ addEventListener(
626
+ type: string,
627
+ listener: EventListenerOrEventListenerObject,
628
+ options?: boolean | AddEventListenerOptions,
629
+ ): void;
630
+ removeEventListener<K extends keyof WorkerEventMap>(
631
+ type: K,
632
+ listener: (this: Worker, ev: WorkerEventMap[K]) => any,
633
+ options?: boolean | EventListenerOptions,
634
+ ): void;
635
+ removeEventListener(
636
+ type: string,
637
+ listener: EventListenerOrEventListenerObject,
638
+ options?: boolean | EventListenerOptions,
639
+ ): void;
640
+
641
+ /**
642
+ * Opposite of `unref()`, calling `ref()` on a previously `unref()`ed worker does _not_ let the program exit if it's the only active handle left (the default
643
+ * behavior). If the worker is `ref()`ed, calling `ref()` again has
644
+ * no effect.
645
+ * @since v10.5.0
646
+ */
647
+ ref(): void;
648
+ /**
649
+ * Calling `unref()` on a worker allows the thread to exit if this is the only
650
+ * active handle in the event system. If the worker is already `unref()`ed calling`unref()` again has no effect.
651
+ * @since v10.5.0
652
+ */
653
+ unref(): void;
654
+
655
+ /**
656
+ * An integer identifier for the referenced thread. Inside the worker thread,
657
+ * it is available as `require('node:worker_threads').threadId`.
658
+ * This value is unique for each `Worker` instance inside a single process.
659
+ * @since v10.5.0
660
+ */
661
+ threadId: number;
662
+ }
663
+ }
664
+
665
+ interface ReadableStream<R = any> extends _ReadableStream<R> {}
666
+ var ReadableStream: typeof globalThis extends {
667
+ onerror: any;
668
+ ReadableStream: infer T;
669
+ }
670
+ ? T
671
+ : {
672
+ prototype: ReadableStream;
673
+ new <R = any>(underlyingSource?: Bun.UnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
674
+ new <R = any>(
675
+ underlyingSource?: Bun.DirectUnderlyingSource<R>,
676
+ strategy?: QueuingStrategy<R>,
677
+ ): ReadableStream<R>;
678
+ };
679
+
680
+ interface WritableStream<W = any> extends _WritableStream<W> {}
681
+ var WritableStream: typeof globalThis extends {
682
+ onerror: any;
683
+ WritableStream: infer T;
684
+ }
685
+ ? T
686
+ : {
687
+ prototype: WritableStream;
688
+ new <W = any>(underlyingSink?: Bun.UnderlyingSink<W>, strategy?: QueuingStrategy<W>): WritableStream<W>;
689
+ };
690
+
691
+ interface Worker extends _Worker {}
692
+ var Worker: typeof globalThis extends {
693
+ onerror: any;
694
+ Worker: infer T;
695
+ }
696
+ ? T
697
+ : {
698
+ prototype: Worker;
699
+ new (scriptURL: string | URL, options?: Bun.WorkerOptions | undefined): Worker;
700
+ /**
701
+ * This is the cloned value of the `data` property passed to `new Worker()`
702
+ *
703
+ * This is Bun's equivalent of `workerData` in Node.js.
704
+ */
705
+ data: any;
706
+ };
707
+
708
+ interface WebSocket extends _WebSocket {}
709
+ var WebSocket: typeof globalThis extends {
710
+ onerror: any;
711
+ WebSocket: infer T;
712
+ }
713
+ ? T
714
+ : typeof _WebSocket;
715
+
716
+ interface Crypto extends _Crypto {}
717
+ var Crypto: typeof globalThis extends {
718
+ onerror: any;
719
+ Crypto: infer T;
720
+ }
721
+ ? T
722
+ : {
723
+ prototype: Crypto;
724
+ new (): Crypto;
725
+ };
726
+
727
+ var crypto: typeof globalThis extends {
728
+ onerror: any;
729
+ crypto: infer T;
730
+ }
731
+ ? T
732
+ : Crypto;
733
+
734
+ /**
735
+ * An implementation of the [WHATWG Encoding Standard](https://encoding.spec.whatwg.org/) `TextEncoder` API. All
736
+ * instances of `TextEncoder` only support UTF-8 encoding.
737
+ *
738
+ * ```js
739
+ * const encoder = new TextEncoder();
740
+ * const uint8array = encoder.encode('this is some data');
741
+ * ```
742
+ */
743
+ interface TextEncoder extends _TextEncoder {}
744
+ var TextEncoder: typeof globalThis extends {
745
+ onerror: any;
746
+ TextEncoder: infer T;
747
+ }
748
+ ? T
749
+ : typeof TextEncoder;
750
+
751
+ interface TextDecoder extends _TextDecoder {}
752
+ var TextDecoder: typeof globalThis extends {
753
+ onerror: any;
754
+ TextDecoder: infer T;
755
+ }
756
+ ? T
757
+ : typeof TextDecoder;
758
+
759
+ interface Performance extends _Performance {}
760
+ var performance: typeof globalThis extends {
761
+ onerror: any;
762
+ performance: infer T;
763
+ }
764
+ ? T
765
+ : Performance;
766
+
767
+ interface Event extends _Event {}
768
+ var Event: typeof globalThis extends { onerror: any; Event: infer T }
769
+ ? T
770
+ : {
771
+ prototype: Event;
772
+ new (type: string, eventInitDict?: Bun.EventInit): Event;
773
+ };
774
+ interface EventTarget extends _EventTarget {}
775
+ var EventTarget: typeof globalThis extends {
776
+ onerror: any;
777
+ EventTarget: infer T;
778
+ }
779
+ ? T
780
+ : {
781
+ prototype: EventTarget;
782
+ new (): EventTarget;
783
+ };
784
+
785
+ interface Body extends _Body {}
786
+
787
+ interface File extends Blob {
788
+ /**
789
+ * Create a new [File](https://developer.mozilla.org/en-US/docs/Web/API/File)
790
+ *
791
+ * @param `parts` - An array of strings, numbers, BufferSource, or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects
792
+ * @param `name` - The name of the file
793
+ * @param `options` - An object containing properties to be added to the [File](https://developer.mozilla.org/en-US/docs/Web/API/File)
794
+ */
795
+ new (parts: Bun.BlobPart[], name: string, options?: BlobPropertyBag & { lastModified?: Date | number }): File;
796
+ readonly lastModified: number;
797
+ readonly name: string;
798
+ }
799
+ var File: typeof globalThis extends { onerror: any; File: infer T } ? T : typeof File;
800
+
801
+ interface FetchRequestInit extends RequestInit {
802
+ /**
803
+ * Log the raw HTTP request & response to stdout. This API may be
804
+ * removed in a future version of Bun without notice.
805
+ * This is a custom property that is not part of the Fetch API specification.
806
+ * It exists mostly as a debugging tool
807
+ */
808
+ verbose?: boolean;
809
+ /**
810
+ * Override http_proxy or HTTPS_PROXY
811
+ * This is a custom property that is not part of the Fetch API specification.
812
+ */
813
+ proxy?: string;
814
+
815
+ /**
816
+ * Override the default TLS options
817
+ */
818
+ tls?: {
819
+ rejectUnauthorized?: boolean | undefined; // Defaults to true
820
+ checkServerIdentity?: any; // TODO: change `any` to `checkServerIdentity`
821
+ };
822
+ }
823
+
824
+ /**
825
+ * ShadowRealms are a distinct global environment, with its own global object
826
+ * containing its own intrinsics and built-ins (standard objects that are not
827
+ * bound to global variables, like the initial value of Object.prototype).
828
+ *
829
+ * @example
830
+ *
831
+ * ```js
832
+ * const red = new ShadowRealm();
833
+ *
834
+ * // realms can import modules that will execute within it's own environment.
835
+ * // When the module is resolved, it captured the binding value, or creates a new
836
+ * // wrapped function that is connected to the callable binding.
837
+ * const redAdd = await red.importValue('./inside-code.js', 'add');
838
+ *
839
+ * // redAdd is a wrapped function exotic object that chains it's call to the
840
+ * // respective imported binding.
841
+ * let result = redAdd(2, 3);
842
+ *
843
+ * console.assert(result === 5); // yields true
844
+ *
845
+ * // The evaluate method can provide quick code evaluation within the constructed
846
+ * // shadowRealm without requiring any module loading, while it still requires CSP
847
+ * // relaxing.
848
+ * globalThis.someValue = 1;
849
+ * red.evaluate('globalThis.someValue = 2'); // Affects only the ShadowRealm's global
850
+ * console.assert(globalThis.someValue === 1);
851
+ *
852
+ * // The wrapped functions can also wrap other functions the other way around.
853
+ * const setUniqueValue =
854
+ * await red.importValue('./inside-code.js', 'setUniqueValue');
855
+ *
856
+ * // setUniqueValue = (cb) => (cb(globalThis.someValue) * 2);
857
+ *
858
+ * result = setUniqueValue((x) => x ** 3);
859
+ *
860
+ * console.assert(result === 16); // yields true
861
+ * ```
862
+ */
863
+ interface ShadowRealm {
864
+ /**
865
+ * Creates a new [ShadowRealm](https://github.com/tc39/proposal-shadowrealm/blob/main/explainer.md#introduction)
866
+ *
867
+ * @example
868
+ *
869
+ * ```js
870
+ * const red = new ShadowRealm();
871
+ *
872
+ * // realms can import modules that will execute within it's own environment.
873
+ * // When the module is resolved, it captured the binding value, or creates a new
874
+ * // wrapped function that is connected to the callable binding.
875
+ * const redAdd = await red.importValue('./inside-code.js', 'add');
876
+ *
877
+ * // redAdd is a wrapped function exotic object that chains it's call to the
878
+ * // respective imported binding.
879
+ * let result = redAdd(2, 3);
880
+ *
881
+ * console.assert(result === 5); // yields true
882
+ *
883
+ * // The evaluate method can provide quick code evaluation within the constructed
884
+ * // shadowRealm without requiring any module loading, while it still requires CSP
885
+ * // relaxing.
886
+ * globalThis.someValue = 1;
887
+ * red.evaluate('globalThis.someValue = 2'); // Affects only the ShadowRealm's global
888
+ * console.assert(globalThis.someValue === 1);
889
+ *
890
+ * // The wrapped functions can also wrap other functions the other way around.
891
+ * const setUniqueValue =
892
+ * await red.importValue('./inside-code.js', 'setUniqueValue');
893
+ *
894
+ * // setUniqueValue = (cb) => (cb(globalThis.someValue) * 2);
895
+ *
896
+ * result = setUniqueValue((x) => x ** 3);
897
+ *
898
+ * console.assert(result === 16); // yields true
899
+ * ```
900
+ */
901
+ importValue(specifier: string, bindingName: string): Promise<any>;
902
+ evaluate(sourceText: string): any;
903
+ }
904
+
905
+ var ShadowRealm: {
906
+ prototype: ShadowRealm;
907
+ new (): ShadowRealm;
908
+ };
909
+
910
+ /**
911
+ * Send a HTTP(s) request
912
+ *
913
+ * @param request Request object
914
+ * @param init A structured value that contains settings for the fetch() request.
915
+ *
916
+ * @returns A promise that resolves to {@link Response} object.
917
+ */
918
+
919
+ // tslint:disable-next-line:unified-signatures
920
+ function fetch(request: Request, init?: RequestInit): Promise<Response>;
921
+ /**
922
+ * Send a HTTP(s) request
923
+ *
924
+ * @param url URL string
925
+ * @param init A structured value that contains settings for the fetch() request.
926
+ *
927
+ * @returns A promise that resolves to {@link Response} object.
928
+ */
929
+ function fetch(url: string | URL | Request, init?: FetchRequestInit): Promise<Response>;
930
+
931
+ function queueMicrotask(callback: (...args: any[]) => void): void;
932
+ /**
933
+ * Log an error using the default exception handler
934
+ * @param error Error or string
935
+ */
936
+ function reportError(error: any): void;
937
+
938
+ interface Timer {
939
+ ref(): Timer;
940
+ unref(): Timer;
941
+ hasRef(): boolean;
942
+
943
+ [Symbol.toPrimitive](): number;
944
+ }
945
+
946
+ /**
947
+ * Cancel a repeating timer by its timer ID.
948
+ * @param id timer id
949
+ */
950
+ function clearInterval(id?: number | Timer): void;
951
+ /**
952
+ * Cancel a delayed function call by its timer ID.
953
+ * @param id timer id
954
+ */
955
+ function clearTimeout(id?: number | Timer): void;
956
+ /**
957
+ * Cancel an immediate function call by its immediate ID.
958
+ * @param id immediate id
959
+ */
960
+ function clearImmediate(id?: number | Timer): void;
961
+ /**
962
+ * Run a function immediately after main event loop is vacant
963
+ * @param handler function to call
964
+ */
965
+ function setImmediate(handler: Bun.TimerHandler, ...arguments: any[]): Timer;
966
+ /**
967
+ * Run a function every `interval` milliseconds
968
+ * @param handler function to call
969
+ * @param interval milliseconds to wait between calls
970
+ */
971
+ function setInterval(handler: Bun.TimerHandler, interval?: number, ...arguments: any[]): Timer;
972
+ /**
973
+ * Run a function after `timeout` (milliseconds)
974
+ * @param handler function to call
975
+ * @param timeout milliseconds to wait between calls
976
+ */
977
+ function setTimeout(handler: Bun.TimerHandler, timeout?: number, ...arguments: any[]): Timer;
978
+
979
+ function addEventListener<K extends keyof EventMap>(
980
+ type: K,
981
+ listener: (this: object, ev: EventMap[K]) => any,
982
+ options?: boolean | AddEventListenerOptions,
983
+ ): void;
984
+ function addEventListener(
985
+ type: string,
986
+ listener: Bun.EventListenerOrEventListenerObject,
987
+ options?: boolean | AddEventListenerOptions,
988
+ ): void;
989
+ function removeEventListener<K extends keyof EventMap>(
990
+ type: K,
991
+ listener: (this: object, ev: EventMap[K]) => any,
992
+ options?: boolean | Bun.EventListenerOptions,
993
+ ): void;
994
+ function removeEventListener(
995
+ type: string,
996
+ listener: Bun.EventListenerOrEventListenerObject,
997
+ options?: boolean | Bun.EventListenerOptions,
998
+ ): void;
999
+
1000
+ /**
1001
+ * Events providing information related to errors in scripts or in files.
1002
+ */
1003
+ interface ErrorEvent extends Event {
1004
+ readonly colno: number;
1005
+ readonly error: any;
1006
+ readonly filename: string;
1007
+ readonly lineno: number;
1008
+ readonly message: string;
1009
+ }
1010
+
1011
+ var ErrorEvent: {
1012
+ prototype: ErrorEvent;
1013
+ new (type: string, eventInitDict?: Bun.ErrorEventInit): ErrorEvent;
1014
+ };
1015
+
1016
+ /** A CloseEvent is sent to clients using WebSockets when the connection is closed. This is delivered to the listener indicated by the WebSocket object's onclose attribute. */
1017
+ interface CloseEvent extends Event {
1018
+ /** Returns the WebSocket connection close code provided by the server. */
1019
+ readonly code: number;
1020
+ /** Returns the WebSocket connection close reason provided by the server. */
1021
+ readonly reason: string;
1022
+ /** Returns true if the connection closed cleanly; false otherwise. */
1023
+ readonly wasClean: boolean;
1024
+ }
1025
+
1026
+ var CloseEvent: {
1027
+ prototype: CloseEvent;
1028
+ new (type: string, eventInitDict?: Bun.CloseEventInit): CloseEvent;
1029
+ };
1030
+
1031
+ interface MessageEvent<T = any> extends Bun.MessageEvent<T> {}
1032
+ var MessageEvent: typeof globalThis extends {
1033
+ onerror: any;
1034
+ MessageEvent: infer T;
1035
+ }
1036
+ ? T
1037
+ : {
1038
+ prototype: MessageEvent;
1039
+ new <T>(type: string, eventInitDict?: Bun.MessageEventInit<T>): MessageEvent<T>;
1040
+ };
1041
+
1042
+ interface CustomEvent<T = any> extends Event {
1043
+ /** Returns any custom data event was created with. Typically used for synthetic events. */
1044
+ readonly detail: T;
1045
+ }
1046
+
1047
+ var CustomEvent: {
1048
+ prototype: CustomEvent;
1049
+ new <T>(type: string, eventInitDict?: Bun.CustomEventInit<T>): CustomEvent<T>;
1050
+ };
1051
+
1052
+ /**
1053
+ * The URL interface represents an object providing static methods used for
1054
+ * creating object URLs.
1055
+ */
1056
+ interface URL {
1057
+ new (url: string | URL, base?: string | URL): URL;
1058
+ /** Not implemented yet */
1059
+ createObjectURL(obj: Blob): string;
1060
+ /** Not implemented yet */
1061
+ revokeObjectURL(url: string): void;
1062
+
1063
+ /**
1064
+ * Check if `url` is a valid URL string
1065
+ *
1066
+ * @param url URL string to parse
1067
+ * @param base URL to resolve against
1068
+ */
1069
+ canParse(url: string, base?: string): boolean;
1070
+ }
1071
+ var URL: typeof globalThis extends {
1072
+ onerror: any;
1073
+ URL: infer T;
1074
+ }
1075
+ ? T
1076
+ : typeof URL;
1077
+
1078
+ interface URLSearchParams {
1079
+ new (init?: string | string[][] | Record<string, string> | URLSearchParams | undefined): URLSearchParams;
1080
+ toString(): string;
1081
+ }
1082
+ var URLSearchParams: typeof globalThis extends {
1083
+ onerror: any;
1084
+ URLSearchParams: infer T;
1085
+ }
1086
+ ? T
1087
+ : typeof URLSearchParams;
1088
+
1089
+ interface EventListener {
1090
+ (evt: Event): void;
1091
+ }
1092
+
1093
+ interface EventListenerObject {
1094
+ handleEvent(object: Event): void;
1095
+ }
1096
+
1097
+ interface FetchEvent extends Event {
1098
+ readonly request: Request;
1099
+ readonly url: string;
1100
+
1101
+ waitUntil(promise: Promise<any>): void;
1102
+ respondWith(response: Response | Promise<Response>): void;
1103
+ }
1104
+
1105
+ interface EventMap {
1106
+ fetch: FetchEvent;
1107
+ message: MessageEvent;
1108
+ messageerror: MessageEvent;
1109
+ // exit: Event;
1110
+ }
1111
+
1112
+ interface AddEventListenerOptions extends Bun.EventListenerOptions {
1113
+ once?: boolean;
1114
+ passive?: boolean;
1115
+ signal?: AbortSignal;
1116
+ }
1117
+
1118
+ /**
1119
+ * Low-level JavaScriptCore API for accessing the native ES Module loader (not a Bun API)
1120
+ *
1121
+ * Before using this, be aware of a few things:
1122
+ *
1123
+ * **Using this incorrectly will crash your application**.
1124
+ *
1125
+ * This API may change any time JavaScriptCore is updated.
1126
+ *
1127
+ * Bun may rewrite ESM import specifiers to point to bundled code. This will
1128
+ * be confusing when using this API, as it will return a string like
1129
+ * "/node_modules.server.bun".
1130
+ *
1131
+ * Bun may inject additional imports into your code. This usually has a `bun:` prefix.
1132
+ */
1133
+ var Loader: {
1134
+ /**
1135
+ * ESM module registry
1136
+ *
1137
+ * This lets you implement live reload in Bun. If you
1138
+ * delete a module specifier from this map, the next time it's imported, it
1139
+ * will be re-transpiled and loaded again.
1140
+ *
1141
+ * The keys are the module specifiers and the
1142
+ * values are metadata about the module.
1143
+ *
1144
+ * The keys are an implementation detail for Bun that will change between
1145
+ * versions.
1146
+ *
1147
+ * - Userland modules are an absolute file path
1148
+ * - Virtual modules have a `bun:` prefix or `node:` prefix
1149
+ * - JS polyfills start with `"/bun-vfs/"`. `"buffer"` is an example of a JS polyfill
1150
+ * - If you have a `node_modules.bun` file, many modules will point to that file
1151
+ *
1152
+ * Virtual modules and JS polyfills are embedded in bun's binary. They don't
1153
+ * point to anywhere in your local filesystem.
1154
+ */
1155
+ registry: Map<
1156
+ string,
1157
+ {
1158
+ key: string;
1159
+ /**
1160
+ * This refers to the state the ESM module is in
1161
+ *
1162
+ * TODO: make an enum for this number
1163
+ */
1164
+ state: number;
1165
+ fetch: Promise<any>;
1166
+ instantiate: Promise<any>;
1167
+ satisfy: Promise<any>;
1168
+ dependencies: Array<(typeof Loader)["registry"] extends Map<any, infer V> ? V : any>;
1169
+ /**
1170
+ * Your application will probably crash if you mess with this.
1171
+ */
1172
+ module: {
1173
+ dependenciesMap: (typeof Loader)["registry"];
1174
+ };
1175
+ linkError?: any;
1176
+ linkSucceeded: boolean;
1177
+ evaluated: boolean;
1178
+ then?: any;
1179
+ isAsync: boolean;
1180
+ }
1181
+ >;
1182
+ /**
1183
+ * For an already-evaluated module, return the dependencies as module specifiers
1184
+ *
1185
+ * This list is already sorted and uniqued.
1186
+ *
1187
+ * @example
1188
+ *
1189
+ * For this code:
1190
+ * ```js
1191
+ * // /foo.js
1192
+ * import classNames from 'classnames';
1193
+ * import React from 'react';
1194
+ * import {createElement} from 'react';
1195
+ * ```
1196
+ *
1197
+ * This would return:
1198
+ * ```js
1199
+ * Loader.dependencyKeysIfEvaluated("/foo.js")
1200
+ * ["bun:wrap", "/path/to/node_modules/classnames/index.js", "/path/to/node_modules/react/index.js"]
1201
+ * ```
1202
+ *
1203
+ * @param specifier - module specifier as it appears in transpiled source code
1204
+ */
1205
+ dependencyKeysIfEvaluated: (specifier: string) => string[];
1206
+ /**
1207
+ * The function JavaScriptCore internally calls when you use an import statement.
1208
+ *
1209
+ * This may return a path to `node_modules.server.bun`, which will be confusing.
1210
+ *
1211
+ * Consider {@link Bun.resolve} or {@link ImportMeta.resolve}
1212
+ * instead.
1213
+ *
1214
+ * @param specifier - module specifier as it appears in transpiled source code
1215
+ * @param referrer - module specifier that is resolving this specifier
1216
+ */
1217
+ resolve: (specifier: string, referrer: string) => string;
1218
+ };
1219
+
1220
+ interface QueuingStrategy<T = any> {
1221
+ highWaterMark?: number;
1222
+ size?: QueuingStrategySize<T>;
1223
+ }
1224
+
1225
+ interface QueuingStrategyInit {
1226
+ /**
1227
+ * Creates a new ByteLengthQueuingStrategy with the provided high water mark.
1228
+ *
1229
+ * 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.
1230
+ */
1231
+ highWaterMark: number;
1232
+ }
1233
+
1234
+ /** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
1235
+ interface ByteLengthQueuingStrategy extends QueuingStrategy<ArrayBufferView> {
1236
+ readonly highWaterMark: number;
1237
+ // changed from QueuingStrategySize<BufferSource>
1238
+ // to avoid conflict with lib.dom.d.ts
1239
+ readonly size: QueuingStrategySize<ArrayBufferView>;
1240
+ }
1241
+
1242
+ var ByteLengthQueuingStrategy: {
1243
+ prototype: ByteLengthQueuingStrategy;
1244
+ new (init: QueuingStrategyInit): ByteLengthQueuingStrategy;
1245
+ };
1246
+
1247
+ interface ReadableStreamDefaultController<R = any> {
1248
+ readonly desiredSize: number | null;
1249
+ close(): void;
1250
+ enqueue(chunk?: R): void;
1251
+ error(e?: any): void;
1252
+ }
1253
+
1254
+ interface ReadableStreamDirectController {
1255
+ close(error?: Error): void;
1256
+ write(data: Bun.BufferSource | ArrayBuffer | string): number | Promise<number>;
1257
+ end(): number | Promise<number>;
1258
+ flush(): number | Promise<number>;
1259
+ start(): void;
1260
+ }
1261
+
1262
+ var ReadableStreamDefaultController: {
1263
+ prototype: ReadableStreamDefaultController;
1264
+ new (): ReadableStreamDefaultController;
1265
+ };
1266
+
1267
+ interface ReadableStreamDefaultReader<R = any> extends ReadableStreamGenericReader {
1268
+ read(): Promise<Bun.ReadableStreamDefaultReadResult<R>>;
1269
+ /**
1270
+ * Only available in Bun. If there are multiple chunks in the queue, this will return all of them at the same time.
1271
+ * Will only return a promise if the data is not immediately available.
1272
+ */
1273
+ readMany(): Promise<Bun.ReadableStreamDefaultReadManyResult<R>> | Bun.ReadableStreamDefaultReadManyResult<R>;
1274
+ releaseLock(): void;
1275
+ }
1276
+
1277
+ var ReadableStreamDefaultReader: {
1278
+ prototype: ReadableStreamDefaultReader;
1279
+ new <R = any>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
1280
+ };
1281
+
1282
+ interface ReadableStreamGenericReader {
1283
+ readonly closed: Promise<undefined>;
1284
+ cancel(reason?: any): Promise<void>;
1285
+ }
1286
+
1287
+ interface ReadableStreamDefaultReadDoneResult {
1288
+ done: true;
1289
+ value?: undefined;
1290
+ }
1291
+
1292
+ interface ReadableStreamDefaultReadValueResult<T> {
1293
+ done: false;
1294
+ value: T;
1295
+ }
1296
+
1297
+ interface ReadableWritablePair<R = any, W = any> {
1298
+ readable: ReadableStream<R>;
1299
+ /**
1300
+ * 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.
1301
+ *
1302
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
1303
+ */
1304
+ writable: WritableStream<W>;
1305
+ }
1306
+
1307
+ interface WritableStreamDefaultController {
1308
+ error(e?: any): void;
1309
+ }
1310
+
1311
+ var WritableStreamDefaultController: {
1312
+ prototype: WritableStreamDefaultController;
1313
+ new (): WritableStreamDefaultController;
1314
+ };
1315
+
1316
+ /** 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. */
1317
+ interface WritableStreamDefaultWriter<W = any> {
1318
+ readonly closed: Promise<undefined>;
1319
+ readonly desiredSize: number | null;
1320
+ readonly ready: Promise<undefined>;
1321
+ abort(reason?: any): Promise<void>;
1322
+ close(): Promise<void>;
1323
+ releaseLock(): void;
1324
+ write(chunk?: W): Promise<void>;
1325
+ }
1326
+
1327
+ var WritableStreamDefaultWriter: {
1328
+ prototype: WritableStreamDefaultWriter;
1329
+ new <W = any>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>;
1330
+ };
1331
+
1332
+ interface TransformStream<I = any, O = any> {
1333
+ readonly readable: ReadableStream<O>;
1334
+ readonly writable: WritableStream<I>;
1335
+ }
1336
+
1337
+ var TransformStream: {
1338
+ prototype: TransformStream;
1339
+ new <I = any, O = any>(
1340
+ transformer?: Transformer<I, O>,
1341
+ writableStrategy?: QueuingStrategy<I>,
1342
+ readableStrategy?: QueuingStrategy<O>,
1343
+ ): TransformStream<I, O>;
1344
+ };
1345
+
1346
+ interface TransformStreamDefaultController<O = any> {
1347
+ readonly desiredSize: number | null;
1348
+ enqueue(chunk?: O): void;
1349
+ error(reason?: any): void;
1350
+ terminate(): void;
1351
+ }
1352
+
1353
+ var TransformStreamDefaultController: {
1354
+ prototype: TransformStreamDefaultController;
1355
+ new (): TransformStreamDefaultController;
1356
+ };
1357
+
1358
+ interface StreamPipeOptions {
1359
+ preventAbort?: boolean;
1360
+ preventCancel?: boolean;
1361
+ /**
1362
+ * 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.
1363
+ *
1364
+ * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
1365
+ *
1366
+ * Errors and closures of the source and destination streams propagate as follows:
1367
+ *
1368
+ * 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.
1369
+ *
1370
+ * 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.
1371
+ *
1372
+ * 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.
1373
+ *
1374
+ * 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.
1375
+ *
1376
+ * 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.
1377
+ */
1378
+ preventClose?: boolean;
1379
+ signal?: AbortSignal;
1380
+ }
1381
+
1382
+ /** This Streams API interface provides a built-in byte length queuing strategy that can be used when constructing streams. */
1383
+ interface CountQueuingStrategy extends QueuingStrategy {
1384
+ readonly highWaterMark: number;
1385
+ readonly size: QueuingStrategySize;
1386
+ }
1387
+
1388
+ var CountQueuingStrategy: {
1389
+ prototype: CountQueuingStrategy;
1390
+ new (init: QueuingStrategyInit): CountQueuingStrategy;
1391
+ };
1392
+
1393
+ interface QueuingStrategySize<T = any> {
1394
+ (chunk?: T): number;
1395
+ }
1396
+
1397
+ interface Transformer<I = any, O = any> {
1398
+ flush?: Bun.TransformerFlushCallback<O>;
1399
+ readableType?: undefined;
1400
+ start?: Bun.TransformerStartCallback<O>;
1401
+ transform?: Bun.TransformerTransformCallback<I, O>;
1402
+ writableType?: undefined;
1403
+ }
1404
+
1405
+ interface Dict<T> {
1406
+ [key: string]: T | undefined;
1407
+ }
1408
+
1409
+ interface ReadOnlyDict<T> {
1410
+ readonly [key: string]: T | undefined;
1411
+ }
1412
+
1413
+ interface ErrnoException extends Error {
1414
+ errno?: number | undefined;
1415
+ code?: string | undefined;
1416
+ path?: string | undefined;
1417
+ syscall?: string | undefined;
1418
+ }
1419
+
1420
+ /** An abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API. */
1421
+ interface DOMException extends Error {
1422
+ readonly message: string;
1423
+ readonly name: string;
1424
+ readonly INDEX_SIZE_ERR: 1;
1425
+ readonly DOMSTRING_SIZE_ERR: 2;
1426
+ readonly HIERARCHY_REQUEST_ERR: 3;
1427
+ readonly WRONG_DOCUMENT_ERR: 4;
1428
+ readonly INVALID_CHARACTER_ERR: 5;
1429
+ readonly NO_DATA_ALLOWED_ERR: 6;
1430
+ readonly NO_MODIFICATION_ALLOWED_ERR: 7;
1431
+ readonly NOT_FOUND_ERR: 8;
1432
+ readonly NOT_SUPPORTED_ERR: 9;
1433
+ readonly INUSE_ATTRIBUTE_ERR: 10;
1434
+ readonly INVALID_STATE_ERR: 11;
1435
+ readonly SYNTAX_ERR: 12;
1436
+ readonly INVALID_MODIFICATION_ERR: 13;
1437
+ readonly NAMESPACE_ERR: 14;
1438
+ readonly INVALID_ACCESS_ERR: 15;
1439
+ readonly VALIDATION_ERR: 16;
1440
+ readonly TYPE_MISMATCH_ERR: 17;
1441
+ readonly SECURITY_ERR: 18;
1442
+ readonly NETWORK_ERR: 19;
1443
+ readonly ABORT_ERR: 20;
1444
+ readonly URL_MISMATCH_ERR: 21;
1445
+ readonly QUOTA_EXCEEDED_ERR: 22;
1446
+ readonly TIMEOUT_ERR: 23;
1447
+ readonly INVALID_NODE_TYPE_ERR: 24;
1448
+ readonly DATA_CLONE_ERR: 25;
1449
+ }
1450
+
1451
+ var DOMException: typeof globalThis extends {
1452
+ onerror: any;
1453
+ DOMException: infer T;
1454
+ }
1455
+ ? T
1456
+ : {
1457
+ prototype: DOMException;
1458
+ new (message?: string, name?: string): DOMException;
1459
+ };
1460
+
1461
+ function alert(message?: string): void;
1462
+ function confirm(message?: string): boolean;
1463
+ function prompt(message?: string, _default?: string): string | null;
1464
+
1465
+ var SubtleCrypto: typeof globalThis extends {
1466
+ onerror: any;
1467
+ SubtleCrypto: infer T;
1468
+ }
1469
+ ? T
1470
+ : {
1471
+ prototype: _SubtleCrypto;
1472
+ new (): _SubtleCrypto;
1473
+ };
1474
+
1475
+ interface CryptoKey extends _CryptoKey {}
1476
+ var CryptoKey: {
1477
+ prototype: CryptoKey;
1478
+ new (): CryptoKey;
1479
+ };
1480
+
1481
+ interface Position {
1482
+ lineText: string;
1483
+ file: string;
1484
+ namespace: string;
1485
+ line: number;
1486
+ column: number;
1487
+ length: number;
1488
+ offset: number;
1489
+ }
1490
+
1491
+ class ResolveMessage {
1492
+ readonly name: "ResolveMessage";
1493
+ readonly position: Position | null;
1494
+ readonly code: string;
1495
+ readonly message: string;
1496
+ readonly referrer: string;
1497
+ readonly specifier: string;
1498
+ readonly importKind:
1499
+ | "entry_point"
1500
+ | "stmt"
1501
+ | "require"
1502
+ | "import"
1503
+ | "dynamic"
1504
+ | "require_resolve"
1505
+ | "at"
1506
+ | "at_conditional"
1507
+ | "url"
1508
+ | "internal";
1509
+ readonly level: "error" | "warning" | "info" | "debug" | "verbose";
1510
+
1511
+ toString(): string;
1512
+ }
1513
+
1514
+ class BuildMessage {
1515
+ readonly name: "BuildMessage";
1516
+ readonly position: Position | null;
1517
+ readonly message: string;
1518
+ readonly level: "error" | "warning" | "info" | "debug" | "verbose";
1519
+ }
1520
+
1521
+ // Declare "static" methods in Error
1522
+ interface ErrorConstructor {
1523
+ /** Create .stack property on a target object */
1524
+ // eslint-disable-next-line @typescript-eslint/ban-types
1525
+ captureStackTrace(targetObject: object, constructorOpt?: Function): void;
1526
+
1527
+ /**
1528
+ * Optional override for formatting stack traces
1529
+ *
1530
+ * @see https://v8.dev/docs/stack-trace-api#customizing-stack-traces
1531
+ */
1532
+ prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
1533
+
1534
+ stackTraceLimit: number;
1535
+ }
1536
+
1537
+ interface ArrayBufferConstructor {
1538
+ new (byteLength: number, options: { maxByteLength?: number }): ArrayBuffer;
1539
+ }
1540
+
1541
+ interface ArrayBuffer {
1542
+ /**
1543
+ * Read-only. The length of the ArrayBuffer (in bytes).
1544
+ */
1545
+ readonly byteLength: number;
1546
+ /**
1547
+ * Resize an ArrayBuffer in-place.
1548
+ */
1549
+ resize(byteLength: number): ArrayBuffer;
1550
+
1551
+ /**
1552
+ * Returns a section of an ArrayBuffer.
1553
+ */
1554
+ slice(begin: number, end?: number): ArrayBuffer;
1555
+ readonly [Symbol.toStringTag]: string;
1556
+ }
1557
+
1558
+ interface SharedArrayBuffer {
1559
+ /**
1560
+ * Grow the SharedArrayBuffer in-place.
1561
+ */
1562
+ grow(size: number): SharedArrayBuffer;
1563
+ }
1564
+
1565
+ interface ArrayConstructor {
1566
+ /**
1567
+ * Create an array from an iterable or async iterable object.
1568
+ * Values from the iterable are awaited.
1569
+ *
1570
+ * ```ts
1571
+ * await Array.fromAsync([1]); // [1]
1572
+ * await Array.fromAsync([Promise.resolve(1)]); // [1]
1573
+ * await Array.fromAsync((async function*() { yield 1 })()); // [1]
1574
+ * ```
1575
+ *
1576
+ * @param arrayLike - The iterable or async iterable to convert to an array.
1577
+ * @returns A {@link Promise} whose fulfillment is a new {@link Array} instance containing the values from the iterator.
1578
+ */
1579
+ fromAsync<T>(arrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>): Promise<Awaited<T>[]>;
1580
+
1581
+ /**
1582
+ * Create an array from an iterable or async iterable object.
1583
+ * Values from the iterable are awaited. Results of the map function are also awaited.
1584
+ *
1585
+ * ```ts
1586
+ * await Array.fromAsync([1]); // [1]
1587
+ * await Array.fromAsync([Promise.resolve(1)]); // [1]
1588
+ * await Array.fromAsync((async function*() { yield 1 })()); // [1]
1589
+ * await Array.fromAsync([1], (n) => n + 1); // [2]
1590
+ * await Array.fromAsync([1], (n) => Promise.resolve(n + 1)); // [2]
1591
+ * ```
1592
+ *
1593
+ * @param arrayLike - The iterable or async iterable to convert to an array.
1594
+ * @param mapFn - A mapper function that transforms each element of `arrayLike` after awaiting them.
1595
+ * @param thisArg - The `this` to which `mapFn` is bound.
1596
+ * @returns A {@link Promise} whose fulfillment is a new {@link Array} instance containing the values from the iterator.
1597
+ */
1598
+ fromAsync<T, U>(
1599
+ arrayLike: AsyncIterable<T> | Iterable<T> | ArrayLike<T>,
1600
+ mapFn?: (value: T, index: number) => U,
1601
+ thisArg?: any,
1602
+ ): Promise<Awaited<U>[]>;
1603
+ }
1604
+
1605
+ interface ConsoleOptions {
1606
+ stdout: import("stream").Writable;
1607
+ stderr?: import("stream").Writable;
1608
+ ignoreErrors?: boolean;
1609
+ colorMode?: boolean | "auto";
1610
+ inspectOptions?: import("util").InspectOptions;
1611
+ groupIndentation?: number;
1612
+ }
1613
+
1614
+ interface Console {
1615
+ /**
1616
+ * Asynchronously read lines from standard input (fd 0)
1617
+ *
1618
+ * ```ts
1619
+ * for await (const line of console) {
1620
+ * console.log(line);
1621
+ * }
1622
+ * ```
1623
+ */
1624
+ [Symbol.asyncIterator](): AsyncIterableIterator<string>;
1625
+
1626
+ /**
1627
+ * Write text or bytes to stdout
1628
+ *
1629
+ * Unlike {@link console.log}, this does no formatting and doesn't add a
1630
+ * newline or spaces between arguments. You can pass it strings or bytes or
1631
+ * any combination of the two.
1632
+ *
1633
+ * ```ts
1634
+ * console.write("hello world!", "\n"); // "hello world\n"
1635
+ * ```
1636
+ *
1637
+ * @param data - The data to write
1638
+ * @returns The number of bytes written
1639
+ *
1640
+ * This function is not available in the browser.
1641
+ */
1642
+ write(...data: Array<string | ArrayBufferView | ArrayBuffer>): number;
1643
+
1644
+ /**
1645
+ * Clear the console
1646
+ */
1647
+ clear(): void;
1648
+
1649
+ assert(condition?: boolean, ...data: any[]): void;
1650
+
1651
+ /**
1652
+ * Increment a [count](https://www.youtube.com/watch?v=2AoxCkySv34&t=22s)
1653
+ * @param label label counter
1654
+ */
1655
+ count(label?: string): void;
1656
+ countReset(label?: string): void;
1657
+ debug(...data: any[]): void;
1658
+ dir(item?: any, options?: any): void;
1659
+ dirxml(...data: any[]): void;
1660
+ /**
1661
+ * Log to stderr in your terminal
1662
+ *
1663
+ * Appears in red
1664
+ *
1665
+ * @param data something to display
1666
+ */
1667
+ error(...data: any[]): void;
1668
+ /** Does nothing currently */
1669
+ group(...data: any[]): void;
1670
+ /** Does nothing currently */
1671
+ groupCollapsed(...data: any[]): void;
1672
+ /** Does nothing currently */
1673
+ groupEnd(): void;
1674
+ info(...data: any[]): void;
1675
+ log(...data: any[]): void;
1676
+ /** Does nothing currently */
1677
+ table(tabularData?: any, properties?: string[]): void;
1678
+ /**
1679
+ * Begin a timer to log with {@link console.timeEnd}
1680
+ *
1681
+ * @param label - The label to use for the timer
1682
+ *
1683
+ * ```ts
1684
+ * console.time("how long????");
1685
+ * for (let i = 0; i < 999999; i++) {
1686
+ * // do stuff
1687
+ * let x = i * i;
1688
+ * }
1689
+ * console.timeEnd("how long????");
1690
+ * ```
1691
+ */
1692
+ time(label?: string): void;
1693
+ /**
1694
+ * End a timer to log with {@link console.time}
1695
+ *
1696
+ * @param label - The label to use for the timer
1697
+ *
1698
+ * ```ts
1699
+ * console.time("how long????");
1700
+ * for (let i = 0; i < 999999; i++) {
1701
+ * // do stuff
1702
+ * let x = i * i;
1703
+ * }
1704
+ * console.timeEnd("how long????");
1705
+ * ```
1706
+ */
1707
+ timeEnd(label?: string): void;
1708
+ timeLog(label?: string, ...data: any[]): void;
1709
+ timeStamp(label?: string): void;
1710
+ trace(...data: any[]): void;
1711
+ warn(...data: any[]): void;
1712
+
1713
+ /**
1714
+ * Creates a new Console with one or two writable stream instances. stdout is a writable stream to print log or info output. stderr is used for warning or error output. If stderr is not provided, stdout is used for stderr.
1715
+ */
1716
+ // Console: {
1717
+ // new (options: ConsoleOptions): Console;
1718
+ // new (
1719
+ // stdout: import("stream").Writable,
1720
+ // stderr?: import("stream").Writable,
1721
+ // ignoreErrors?: boolean,
1722
+ // ): Console;
1723
+ // };
1724
+ }
1725
+
1726
+ var console: Console;
1727
+
1728
+ interface ImportMeta {
1729
+ /**
1730
+ * `file://` url string for the current module.
1731
+ *
1732
+ * @example
1733
+ * ```ts
1734
+ * console.log(import.meta.url);
1735
+ * "file:///Users/me/projects/my-app/src/my-app.ts"
1736
+ * ```
1737
+ */
1738
+ url: string;
1739
+ /**
1740
+ * Absolute path to the source file
1741
+ */
1742
+ readonly path: string;
1743
+ /**
1744
+ * Absolute path to the directory containing the source file.
1745
+ *
1746
+ * Does not have a trailing slash
1747
+ */
1748
+ readonly dir: string;
1749
+ /**
1750
+ * Filename of the source file
1751
+ */
1752
+ readonly file: string;
1753
+ /**
1754
+ * The environment variables of the process
1755
+ *
1756
+ * ```ts
1757
+ * import.meta.env === process.env
1758
+ * ```
1759
+ */
1760
+ readonly env: NodeJS.ProcessEnv;
1761
+ /**
1762
+ * Resolve a module ID the same as if you imported it
1763
+ *
1764
+ * On failure, throws a `ResolveMessage`
1765
+ */
1766
+ resolve(moduleId: string): Promise<string>;
1767
+ /**
1768
+ * Resolve a `moduleId` as though it were imported from `parent`
1769
+ *
1770
+ * On failure, throws a `ResolveMessage`
1771
+ */
1772
+ // tslint:disable-next-line:unified-signatures
1773
+ resolve(moduleId: string, parent: string): Promise<string>;
1774
+
1775
+ /**
1776
+ * Resolve a module ID the same as if you imported it
1777
+ *
1778
+ * The `parent` argument is optional, and defaults to the current module's path.
1779
+ */
1780
+ resolveSync(moduleId: string, parent?: string): string;
1781
+
1782
+ /**
1783
+ * Load a CommonJS module
1784
+ *
1785
+ * Internally, this is a synchronous version of ESModule's `import()`, with extra code for handling:
1786
+ * - CommonJS modules
1787
+ * - *.node files
1788
+ * - *.json files
1789
+ *
1790
+ * Warning: **This API is not stable** and may change in the future. Use at your
1791
+ * own risk. Usually, you should use `require` instead and Bun's transpiler
1792
+ * will automatically rewrite your code to use `import.meta.require` if
1793
+ * relevant.
1794
+ */
1795
+ require: NodeJS.Require;
1796
+
1797
+ /**
1798
+ * Did the current file start the process?
1799
+ *
1800
+ * @example
1801
+ * ```ts
1802
+ * if (import.meta.main) {
1803
+ * console.log("I started the process!");
1804
+ * }
1805
+ * ```
1806
+ *
1807
+ * @example
1808
+ * ```ts
1809
+ * console.log(
1810
+ * import.meta.main === (import.meta.path === Bun.main)
1811
+ * )
1812
+ * ```
1813
+ */
1814
+ readonly main: boolean;
1815
+
1816
+ /** Alias of `import.meta.dir`. Exists for Node.js compatibility */
1817
+ dirname: string;
1818
+
1819
+ /** Alias of `import.meta.path`. Exists for Node.js compatibility */
1820
+ filename: string;
1821
+ }
1822
+
1823
+ /**
1824
+ * NodeJS-style `require` function
1825
+ *
1826
+ * Internally, uses `import.meta.require`
1827
+ *
1828
+ * @param moduleId - The module ID to resolve
1829
+ */
1830
+ var require: NodeJS.Require;
1831
+
1832
+ /** Same as module.exports */
1833
+ var exports: any;
1834
+
1835
+ interface NodeModule {
1836
+ exports: any;
1837
+ }
1838
+
1839
+ var module: NodeModule;
1840
+
1841
+ /**
1842
+ * Creates a deep clone of an object.
1843
+ *
1844
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/structuredClone)
1845
+ */
1846
+ function structuredClone<T>(value: T, options?: Bun.StructuredSerializeOptions): T;
1847
+
1848
+ /**
1849
+ * Post a message to the parent thread.
1850
+ *
1851
+ * Only useful in a worker thread; calling this from the main thread does nothing.
1852
+ */
1853
+ function postMessage(message: any, transfer?: Bun.Transferable[]): void;
1854
+
1855
+ interface EventSourceInit {
1856
+ withCredentials?: boolean;
1857
+ }
1858
+
1859
+ interface EventSource extends Bun.EventSource {}
1860
+ var EventSource: typeof globalThis extends {
1861
+ onerror: any;
1862
+ EventSource: infer T;
1863
+ }
1864
+ ? T
1865
+ : EventSource;
1866
+
1867
+ interface PromiseConstructor {
1868
+ /**
1869
+ * Create a deferred promise, with exposed `resolve` and `reject` methods which can be called
1870
+ * separately.
1871
+ *
1872
+ * This is useful when you want to return a Promise and have code outside the Promise
1873
+ * resolve or reject it.
1874
+ *
1875
+ * ## Example
1876
+ * ```ts
1877
+ * const { promise, resolve, reject } = Promise.withResolvers();
1878
+ *
1879
+ * setTimeout(() => {
1880
+ * resolve("Hello world!");
1881
+ * }, 1000);
1882
+ *
1883
+ * await promise; // "Hello world!"
1884
+ * ```
1885
+ *
1886
+ * `Promise.withResolvers()` is a [stage3 proposal](https://github.com/tc39/proposal-promise-with-resolvers).
1887
+ */
1888
+ withResolvers<T>(): {
1889
+ promise: Promise<T>;
1890
+ resolve: (value?: T | PromiseLike<T>) => void;
1891
+ reject: (reason?: any) => void;
1892
+ };
1893
+ }
1894
+
1895
+ interface Navigator {
1896
+ readonly userAgent: string;
1897
+ readonly platform: "MacIntel" | "Win32" | "Linux x86_64";
1898
+ readonly hardwareConcurrency: number;
1899
+ }
1900
+
1901
+ var navigator: Navigator;
1902
+
1903
+ interface BlobPropertyBag {
1904
+ /** Set a default "type". Not yet implemented. */
1905
+ type?: string;
1906
+ /** Not implemented in Bun yet. */
1907
+ // endings?: "transparent" | "native";
1908
+ }
1909
+
1910
+ interface Blob {
1911
+ /**
1912
+ * Create a new [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
1913
+ *
1914
+ * @param `parts` - An array of strings, numbers, BufferSource, or [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects
1915
+ * @param `options` - An object containing properties to be added to the [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob)
1916
+ */
1917
+ new (parts?: Bun.BlobPart[], options?: BlobPropertyBag): Blob;
1918
+ /**
1919
+ * Read the data from the blob as a JSON object.
1920
+ *
1921
+ * This first decodes the data from UTF-8, then parses it as JSON.
1922
+ */
1923
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
1924
+ json(): Promise<any>;
1925
+
1926
+ /**
1927
+ * Read the data from the blob as a {@link FormData} object.
1928
+ *
1929
+ * This first decodes the data from UTF-8, then parses it as a
1930
+ * `multipart/form-data` body or a `application/x-www-form-urlencoded` body.
1931
+ *
1932
+ * The `type` property of the blob is used to determine the format of the
1933
+ * body.
1934
+ *
1935
+ * This is a non-standard addition to the `Blob` API, to make it conform more
1936
+ * closely to the `BodyMixin` API.
1937
+ */
1938
+ formData(): Promise<FormData>;
1939
+ }
1940
+ var Blob: typeof globalThis extends {
1941
+ onerror: any;
1942
+ Blob: infer T;
1943
+ }
1944
+ ? T
1945
+ : typeof Blob;
1946
+
1947
+ var Response: typeof globalThis extends {
1948
+ onerror: any;
1949
+ Response: infer T;
1950
+ }
1951
+ ? T
1952
+ : typeof import("./fetch").Response;
1953
+
1954
+ var Request: typeof globalThis extends {
1955
+ onerror: any;
1956
+ Request: infer T;
1957
+ }
1958
+ ? T
1959
+ : {
1960
+ prototype: Request;
1961
+ new (requestInfo: string, requestInit?: RequestInit): Request;
1962
+ new (requestInfo: RequestInit & { url: string }): Request;
1963
+ new (requestInfo: Request, requestInit?: RequestInit): Request;
1964
+ };
1965
+
1966
+ interface Headers {
1967
+ /**
1968
+ * Convert {@link Headers} to a plain JavaScript object.
1969
+ *
1970
+ * About 10x faster than `Object.fromEntries(headers.entries())`
1971
+ *
1972
+ * Called when you run `JSON.stringify(headers)`
1973
+ *
1974
+ * Does not preserve insertion order. Well-known header names are lowercased. Other header names are left as-is.
1975
+ */
1976
+ toJSON(): Record<string, string>;
1977
+ /**
1978
+ * Get the total number of headers
1979
+ */
1980
+ readonly count: number;
1981
+ /**
1982
+ * Get all headers matching the name
1983
+ *
1984
+ * Only supports `"Set-Cookie"`. All other headers are empty arrays.
1985
+ *
1986
+ * @param name - The header name to get
1987
+ *
1988
+ * @returns An array of header values
1989
+ *
1990
+ * @example
1991
+ * ```ts
1992
+ * const headers = new Headers();
1993
+ * headers.append("Set-Cookie", "foo=bar");
1994
+ * headers.append("Set-Cookie", "baz=qux");
1995
+ * headers.getAll("Set-Cookie"); // ["foo=bar", "baz=qux"]
1996
+ * ```
1997
+ */
1998
+ getAll(name: "set-cookie" | "Set-Cookie"): string[];
1999
+ }
2000
+ }