Repository navigation
Expand file tree
/
Copy pathbuiltins.d.ts
More file actions
810 lines (752 loc) · 42.8 KB
/
Copy pathbuiltins.d.ts
File metadata and controls
810 lines (752 loc) · 42.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
/// <reference types="../../build/types/generated.d.ts" />
/// <reference types="../../build/types/ErrorCode.d.ts" />
/// <reference types="../../build/types/WebCoreJSBuiltins.d.ts" />
/// <reference types="../../build/types/Bindgen.d.ts" />
// Typedefs for JSC intrinsics. Instead of @, we use $
type TODO = any;
declare module "bun" {
interface Socket {
$write(data: string | BufferSource, encoding?: string): boolean | number;
$end(data?: string | BufferSource, encoding?: string): boolean;
}
}
/** $debug is a preprocessor macro that works like a templated console.log, and only runs in debug mode if you pass
* BUN_DEBUG_JS=<module>
*
* So to get node stream to log, you pass BUN_DEBUG_JS=stream or BUN_DEBUG_JS=node:stream
*
* This only works in debug builds, the log fn is completely removed in release builds.
*/
declare function $debug(...args: any[]): void;
/**
* Assert that a condition holds in debug builds.
*
* $assert is a preprocessor macro that only runs in debug mode. it throws an
* error if the first argument is falsy. The source code passed to `check` is
* inlined in the message, but in addition you can pass additional messages.
*
* @note gets removed in release builds. Do not put code with side effects in the `check`.
*/
declare function $assert(check: any, ...message: any[]): asserts check;
/** Asserts the input is a promise. Returns `true` if the promise is resolved */
declare function $isPromiseFulfilled(promise: Promise<any>): boolean;
/** Asserts the input is a promise. Returns `true` if the promise is rejected */
declare function $isPromiseRejected(promise: Promise<any>): boolean;
/** Asserts the input is a promise. Returns `true` if the promise is pending */
declare function $isPromisePending(promise: Promise<any>): boolean;
declare const IS_BUN_DEVELOPMENT: boolean;
/** False in an executable that was compiled ahead of time without `--compile-inspector` and without `--external`. */
declare const CAN_LOAD_CODE_AT_RUN_TIME: boolean;
/** Or it is a test run, which loads a native addon wherever the call stands. */
declare const CAN_LOAD_ADDONS_AT_RUN_TIME: boolean;
/** False in an executable that was compiled ahead of time from a program that never names `node:cluster`. */
declare const CAN_BE_CLUSTER_WORKER: boolean;
/** False in what was compiled ahead of time, but for a test run one of whose tests replaces a built-in function or adds a name to `Object.prototype` or `Function.prototype`, and for an executable whose text spells a new name on `Function.prototype` or on the prototype of another kind of function. Where it is false no program can tell which built-in functions Bun's own code calls, or which names it reads off its own objects. Where you count on one member of a built-in alone, ask `$findsDeclaredMember` of it instead. */
declare const CAN_REPLACE_BUILT_INS: boolean;
/** False in what was compiled ahead of time, but for a test run one of whose tests replaces a built-in function. Where it is false no program can tell which built-in functions Bun's own code calls, when, or with what. It says nothing of names that a program adds to a prototype: an executable may do that, and `CAN_REPLACE_BUILT_INS` is true there. */
declare const CAN_REPLACE_BUILT_IN_FUNCTIONS: boolean;
/** False in what was compiled ahead of time from a program that asks `process` only for what Bun gives it. Another name, or a conversion to a text or a number, is answered by what the program has laid on `EventEmitter.prototype`, with `process` as `this`. */
declare const PROCESS_REACHES_CODE_ON_ITS_PROTOTYPES: boolean;
/** False in what was compiled ahead of time from a program that cannot tell whether `node:events` was loaded: nothing in it loads the module or may hand `process` on, and it does not look at the prototype chain of `process`. */
declare const WARNINGS_LOAD_NODE_EVENTS: boolean;
/** False in what was compiled ahead of time from a program that cannot load `node:path`, `node:path/posix` or `node:path/win32`, by a written name or by one computed at run time. Such a program cannot have replaced a function of `node:path`. */
declare const CAN_LOAD_NODE_PATH: boolean;
/** True in an executable that was compiled ahead of time, false in `bun run`. Only for a choice between two ways that a program cannot tell apart. */
declare const IS_COMPILED_AHEAD_OF_TIME: boolean;
/** Calls `callee`. A compiled executable never inlines the call. Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`. */
declare function $callNoInline<This, Arguments extends unknown[], Result>(
callee: (this: This, ...args: Arguments) => Result,
thisValue: This,
...args: Arguments
): Result;
/**
* True only where a lookup of `name` on `object` finds the method or accessor that the class of `object` declares or inherits, as the source text defines it.
* That class may be an heir of the one you mean: name the one you mean as `Class`: then it is true only where the member found is declared by `Class` or by a class above it,
* and an heir that declares the name itself gets a no. False says nothing: ask the object and its prototypes then.
* On an object that the runtime builds (`process`, `Object.prototype`), without `Class`: true only where the object's own member of that name is still the one that it was built with.
* Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
*/
declare function $findsDeclaredMember(object: object, name: string, Class?: Function): boolean;
/**
* True only if looking up `name` on `object` finds nothing, on the object or on its prototype chain.
* Ask after `$isPlainInstanceOf` said yes: it goes by what the compiler has proven about `object`, not by the declared type.
* After a yes, `object[name]` is `undefined` and free, so keep the reads as plain Bun has them. It covers that one name only.
* It holds until user code runs again or a store uses a computed key.
* False means unknown: an object with extra own properties gets a no until the call site has seen its shape.
* Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
*/
declare function $findsNoMember(object: object, name: string): boolean;
/**
* True only where `object` was made by `Class` itself, not by an heir, no field that `Class` declares was made an accessor or defined anew under other attributes,
* and above the object stands the prototype of `Class`, with at most plain objects in between that hide no member of it.
* Then a read of a declared field runs no code of the program: read the fields in any order, as often as you like, or not at all.
* Stores into the fields and properties under other names leave it true. A deleted field is like one that was never stored: it is absent, and the answer stays true.
* Nothing is added above the object under the name of a field, a private symbol that only later stores lay included: where no prototype of the library holds the name, a read of a field that is absent finds nothing.
* A value that a prototype of the library holds under such a name is the library's own, as it stood where the file that declares the class ended: whoever stores another there makes the answer false.
* A yes also says that `object instanceof Class` is true and runs no code.
* A yes also says what `$isPrototypeChainPlain(Class)` says: on the prototype of `Class` and on those of the classes above it nobody but the library has defined an accessor or a property that is not writable, under any name,
* and no name was added to `Object.prototype`.
* An object that is laid between is heard by the names that it holds: under the name of a field it makes the answer false for every object, under the name of a member that a class above declares for the objects below it.
* Under any other name it may hold an accessor or a property that is not writable, and the answer stays true: a yes says nothing of a name that no class declares and no field bears.
* Where you spare a read or a store under such a name, ask `$findsNoMember(object, name)`.
* It says nothing about methods: ask `$findsDeclaredMember` for each one that you count on. It says nothing about frozen objects.
* A class that declares a member under `__proto__`, or one below such a class, is not among the classes: its objects get a no.
* A name under which `Class` or a class above it declares an accessor is a member, not a field, though a constructor stores under it.
* Lay such an accessor where the compiler sees it: a field over an accessor that it does not see makes the answer false for every object.
* It holds until code of the program runs again. False says nothing: take the road that reads everything then.
* `Class` is the binding of a class or constructor function that is evaluated once. Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
* A name under which the library itself lays an accessor on the objects of a class of its own, or of a class below it, is not among the fields: under it lies what the library laid, so a read or a store under it runs no code of the program.
* Whoever deletes that accessor, changes a half or an attribute of it, or lays one with a function of the program makes the answer false.
*/
declare function $isPlainInstanceOf(object: unknown, Class: Function): boolean;
/**
* `$isPlainInstanceOf` for a method that `Class` hands down: true also for an object that a class below `Class` has made, the library's or the program's,
* by `extends` or by `$toClass(Below, name, Class)`. All that a yes of `$isPlainInstanceOf` says holds of the fields that the object's own class declares or inherits.
* A class below on whose prototype an accessor lies, or may lie, under the name of a field of `Class` is not among the classes, be the accessor the program's or the library's,
* seen by the compiler or not (a half that a call hands back): its objects get a no and the other classes keep their yes. It says nothing about methods: an heir may declare its own:
* ask `$findsDeclaredMember(object, name, Class)` for each one that you count on.
* Each class has its own count: what ends the yes for the objects of a class ends it for those of the classes below it, and for no others.
* A class below may be one that a function makes: from its second evaluation on its objects get a no, those of the first evaluation too.
* `Class` is the file's own binding of the class or constructor function: one taken out of `require()` makes the answer false.
*/
declare function $isPlainHeirOf(object: unknown, Class: Function): boolean;
/**
* `$isPlainInstanceOf` for an object that a literal made: true while `object` is as the one object literal of `maker` bore it:
* it has the layout of that literal; each of its names is a data property; nothing was added under another name;
* it is not frozen, sealed or closed to new names; above it stands what stood there at its birth.
* Then a read of one of its names runs no code of the program: read them in any order, as often as you like, or not at all.
* A store of a value under one of its names leaves it true, a name that only the declared type of `maker`'s result names included: such a name has its place in the layout.
* A name of the literal that was deleted makes it false until a value is stored under it again. A name that only the declared type names may be absent: look for it as for any absent name.
* It says what the object is, not who made it: an object that another literal with the same names bore has the same layout and gets the same answer.
* It holds until code of the program runs again. False says nothing: take the road that reads everything then.
* The literal may be written with `__proto__: null`: then nothing stands above the object at its birth, and an object of the same names below `Object.prototype` gets a no. Any other `__proto__` makes the answer false.
* `maker` is the file's own binding of a function whose body holds one object literal and returns nothing else: one taken out of `require()` makes the answer false where code from disk is admitted.
* Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
*/
declare function $isAsBorn<Born>(object: unknown, maker: () => Born): object is Born;
/**
* `$isAsBorn` for an object that may have grown: values added under other names leave it true. Everything else makes it false as there, an accessor added under another name too.
* Then a read of a name of the literal runs no code of the program.
* It says nothing about any other name: not that it is absent, not what lies under it: look for such a name as for any other.
*/
declare function $isAsBornExceptForAddedNames<Born>(object: unknown, maker: () => Born): object is Born;
/**
* What a yes of `$isPlainInstanceOf` says of the chain above an object, asked without an object: `Class.prototype` is the object that it was, no link above it has changed,
* and on it and on the prototype objects above it nobody but the library has defined an accessor or a property that is not writable, under any name.
* A plain store of a function or a value there, over a member or under a new name, leaves it true.
* Whatever is defined there under `__proto__`, a value too, makes it false: behind a yes a read of `__proto__` off an object that holds no such name itself gives what stands above it.
* It is for a birth: behind `new.target === Class` the object is fresh, has no property of its own and stands directly below `Class.prototype`:
* then no store into it runs code of the program or is refused, and a read of a name that the library holds nowhere above finds nothing.
* Of several classes it says all that of each, by one test: what ends the yes for one of them ends it for all.
* It says nothing about an object: not that it stands below `Class.prototype`, not what it holds itself. It says nothing about methods.
* Of `Object.prototype` it says what `$isObjectPrototypeWithoutAddedNames()` says: no name was added there. A member of it that a test replaces leaves the answer as it is.
* It holds until code of the program runs again. False says nothing: take the road that asks everything then.
* `Class` is the file's own binding of a class or constructor function that is evaluated once. Only a compiled executable has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
*/
declare function $isPrototypeChainPlain(
Class: Function,
second?: Function,
third?: Function,
fourth?: Function,
): boolean;
/**
* True while no name was added to `Object.prototype`: then a name that an object of the library's own making does not hold is found nowhere.
* A compiled executable lets nobody add one, so there it is true and costs nothing. A compiled test run lets a test add one: from then on it is false for good.
* A member of `Object.prototype` that a test replaces does not make it false.
* It holds until code of the program runs again. Only compiled code has it: use it behind `IS_COMPILED_AHEAD_OF_TIME`.
*/
declare function $isObjectPrototypeWithoutAddedNames(): boolean;
/** Place this directly above a function declaration (like a decorator) to make it a getter. */
declare const $getter: never;
/** Assign to this directly above a function declaration (like a decorator) to override the function's display name. */
declare var $overriddenName: string;
/** ??? */
declare var $linkTimeConstant: never;
/** Assign to this directly above a function declaration (like a decorator) to set visibility */
declare var $visibility: "Public" | "Private" | "PrivateRecursive";
/** Assign to this directly above a function declaration (like a decorator) to make it a constructor. */
declare var $constructor;
/** Place this directly above a function declaration (like a decorator) to always inline the function */
declare var $alwaysInline;
/**
* Overrides **
*/
interface ReadableStream<R = any> extends _ReadableStream<R> {
/** The native source behind a Bun-created stream: `undefined` when there is none, `-1` once it is detached. */
$bunNativePtr: TODO | undefined;
}
declare var ReadableStream: {
prototype: ReadableStream;
new (
underlyingSource: import("node:stream/web").UnderlyingByteSource,
strategy?: { highWaterMark?: number },
): ReadableStream<Uint8Array>;
new <R = any>(
underlyingSource?: Omit<Bun.UnderlyingSource<R>, "type"> & { type?: "bytes" | undefined },
strategy?: QueuingStrategy<R>,
): ReadableStream<R>;
new <R = any>(underlyingSource?: Bun.DirectUnderlyingSource<R>, strategy?: QueuingStrategy<R>): ReadableStream<R>;
};
// The public constructor only accepts a known `Bun.Encoding`; builtins pass arbitrary labels and catch the throw.
declare var TextDecoder: {
prototype: TextDecoder;
new (label?: string, options?: { __proto__?: null; fatal?: boolean; ignoreBOM?: boolean }): TextDecoder;
};
interface Console {
$writer: ReturnType<typeof Bun.stdout.writer>;
}
// JSC defines their intrinsics in a nice list here:
// https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/bytecode/BytecodeIntrinsicRegistry.h
//
// And implemented here: (search for "emit_intrinsic_<name>", like "emit_intrinsic_arrayPush")
// https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp
/** returns `arguments[index]` */
declare function $argument<T = any>(index: number): any | undefined;
/** returns number of arguments */
declare function $argumentCount(): number;
/** array.push(item) */
declare function $arrayPush(array: T[], item: T): void;
/**
* Returns the internal Promise state as a small integer:
* `0` = pending, `1` = fulfilled, `2` = rejected.
*/
declare function $peekPromiseStatus(promise: Promise<any>): number;
/**
* Returns the settlement value of a settled Promise (the fulfillment value
* or the rejection reason). Returns `undefined` for a pending promise.
*/
declare function $peekPromiseSettledValue<V>(promise: Promise<V>): V | undefined;
/**
* Marks a promise as handled so it doesn't fire the unhandled-rejection
* tracker. Equivalent to JSC's `JSPromise::markAsHandled()`.
*/
declare function $pokePromiseAsHandled(promise: Promise<any>): void;
/**
* A promise that settles when a WHATWG ReadableStream/WritableStream reaches a terminal state.
* Does not lock the stream. Throws when given anything else.
*/
declare function $webStreamClosedPromise(stream: ReadableStream | WritableStream): Promise<void>;
/**
* Error a WHATWG ReadableStream/WritableStream as `controller.error(e)` would, including its
* no-op once the stream is no longer readable/writable. Throws for any other value.
*/
declare function $webStreamControllerError(stream: ReadableStream | WritableStream, error: unknown): void;
declare function $getInternalField<Fields extends any[], N extends keyof Fields>(
base: InternalFieldObject<Fields>,
number: N,
): Fields[N];
/**
* Use {@link $resolvePromise} when:
* - The value might be a promise or thenable
* - You need the full resolution algorithm (self-check, thenable unwrapping)
* - You're implementing user-facing APIs where the resolution value is unknown
*/
declare function $resolvePromise<T>(promise: Promise<T>, value: NoInfer<T>): void;
/**
* Reject a promise with a value
*/
declare function $rejectPromise(promise: Promise<unknown>, value: unknown): void;
/** A new pending promise. `$resolvePromise` / `$rejectPromise` require it to still be pending. */
declare function $newPromise<T = unknown>(): Promise<T>;
/** Like the resolving functions of a Promise executor: calls after the first one are ignored. */
declare function $resolvePromiseWithFirstResolvingFunctionCallCheck<T>(promise: Promise<T>, value: NoInfer<T>): void;
declare function $rejectPromiseWithFirstResolvingFunctionCallCheck(promise: Promise<unknown>, value: unknown): void;
declare function $loadEsmIntoCjs(...args: any[]): TODO;
declare function $getProxyInternalField(): TODO;
// Helper types for the `$isObject` / `$isCallable` / `$isArray` guards. Each guard has two overloads: a
// generic one that narrows the argument's own type and rejects `any`, and a plain one for `any`. A single generic
// predicate evaluates to `any` for an `any` argument, which TypeScript narrows to `never` in the false branch.
type $NotAny<T> = 0 extends 1 & T ? never : unknown;
/** Keeps the members of `T` that can be a `U`. */
type $GuardNarrow<T, U> = T extends U ? T : U extends T ? U : never;
type $AnyObject = Record<PropertyKey, any>;
/** `x.$$iterator` is `x[Symbol.iterator]` without a look at `Symbol`. Any value may be asked for it. */
declare interface Object {
$$asyncDispose: any;
$$asyncIterator: any;
$$dispose: any;
$$iterator: any;
}
type $AnyCallable = ((...args: any[]) => any) & $AnyObject;
/**
* True for object-like `JSCell`s. That is, this is roughly equivalent to this
* JS code:
* ```js
* typeof obj === "object" && obj !== null
* ```
*
* @param obj The object to check
* @returns `true` if `obj` is an object-like `JSCell`
*
* @see [JSCell.h](https://github.com/oven-sh/WebKit/blob/main/Source/JavaScriptCore/runtime/JSCell.h)
* @see [JIT implementation](https://github.com/oven-sh/WebKit/blob/433f7598bf3537a295d0af5ffd83b9a307abec4e/Source/JavaScriptCore/jit/JITOpcodes.cpp#L311)
*/
declare function $isObject<T>(obj: T & $NotAny<T>): obj is $GuardNarrow<T, object> & $NotAny<T>;
declare function $isObject(obj: any): obj is $AnyObject;
declare function $isArray<T>(
obj: T & $NotAny<T>,
): obj is ([Extract<T, readonly any[]>] extends [never] ? T & any[] : Extract<T, readonly any[]>) & $NotAny<T>;
declare function $isArray(obj: any): obj is any[];
declare function $isCallable<T>(fn: T & $NotAny<T>): fn is $GuardNarrow<T, CallableFunction> & $NotAny<T>;
declare function $isCallable(fn: any): fn is $AnyCallable;
declare function $isJSArray(obj: unknown): obj is any[];
declare function $isProxyObject(obj: unknown): boolean;
declare function $isRegExpObject(obj: unknown): obj is RegExp;
declare function $isMap<K, V>(obj: unknown): obj is Map<K, V>;
declare function $isSet<V>(obj: unknown): obj is Set<V>;
declare function $isUndefinedOrNull(obj: unknown): obj is null | undefined;
declare function $tailCallForwardArguments(fn: CallableFunction, thisValue: ThisType): any;
/**
* **NOTE** - use `throw new TypeError()` instead. it compiles to the same builtin
* @deprecated
*/
declare function $throwTypeError(message: string): never;
/**
* **NOTE** - use `throw new RangeError()` instead. it compiles to the same builtin
* @deprecated
*/
declare function $throwRangeError(message: string): never;
declare function $putByIdDirect(obj: any, key: PropertyKey, value: any): void;
/**
* Sets a private property on an object.
* Translates to the `op_put_by_id_direct` bytecode.
*
* @param obj The object to set the private property on
* @param key The key of the private property (without the "$" prefix)
* @param value The value to set the private property to
*/
declare function $putByIdDirectPrivate<T extends Record<`$${K}`, unknown>, K extends string>(
obj: T,
key: K,
value: T[`$${K}`],
): void;
declare function $putByValDirect(obj: any, key: PropertyKey, value: any): void;
declare function $putInternalField<Fields extends any[], N extends keyof Fields>(
base: InternalFieldObject<Fields>,
number: N,
value: Fields[N],
): void;
/**
* ## References
* - [WebKit - `emit_intrinsic_newArrayWithSize`](https://github.com/oven-sh/WebKit/blob/e1a802a2287edfe7f4046a9dd8307c8b59f5d816/Source/JavaScriptCore/bytecompiler/NodesCodegen.cpp#L2317)
*/
declare function $newArrayWithSize<T>(size: number): T[];
declare const $ModuleFetch: number;
declare const $ModuleLink: number;
declare const $proxyFieldTarget: TODO;
declare const $proxyFieldHandler: TODO;
declare const $processBindingConstants: {
os: typeof import("os").constants;
fs: typeof import("fs").constants;
crypto: typeof import("crypto").constants;
zlib: typeof import("zlib").constants;
};
declare const $asyncContext: InternalFieldObject<[import("./node/async_hooks").Frame | undefined]>;
// We define our intrinsics in ./BunBuiltinNames.h. Some of those are globals.
declare var $_events: TODO;
declare function $addAbortAlgorithmToSignal(signal: AbortSignal, algorithm: () => void): TODO;
declare function $autoAllocateChunkSize(): TODO;
declare function $basename(): TODO;
declare function $body(): TODO;
declare function $bunNativePtr(): TODO;
declare function $cancel(): TODO;
declare function $close(): TODO;
declare function $code(): TODO;
declare function $createFIFO(): TODO;
declare function $createUninitializedArrayBuffer(size: number): ArrayBuffer;
declare function $data(): TODO;
declare function $decode(): TODO;
declare function $dirname(): TODO;
declare function $encoding(): TODO;
declare function $end(): TODO;
declare function $errno(): TODO;
declare function $extname(): TODO;
declare function $fatal(): TODO;
declare function $format(): TODO;
// `requirer`: a CommonJS module; the registry is its Bun.ModuleGraph's loader's. Omitted: the global object's.
declare function $esmNamespaceForCjs(key: string, requirer?: JSCommonJSModule): any | undefined;
declare function $esmRegistryDelete(key: string, requirer?: JSCommonJSModule): boolean;
declare function $esmRegistryEvaluatedKeys(requirer?: JSCommonJSModule): string[];
declare function $esmRegistryHasEvaluated(key: string, requirer?: JSCommonJSModule): boolean;
declare function $requireCacheCompiledEntry(key: string, requirer?: JSCommonJSModule, onlyAsks?: boolean): any;
declare function $requireCacheDidDelete(key: string, requirer?: JSCommonJSModule): void;
declare function $requireCacheWillSet(key: string, value: unknown, requirer?: JSCommonJSModule): void;
/** Without a key: does this process hide any file from require.cache? */
declare function $isHiddenFromRequireCache(key?: string | symbol): boolean | undefined;
declare function $esmLoadSync(key: string, requirer?: JSCommonJSModule): any;
declare function $get(): TODO;
declare function $handleEvent(): TODO;
declare function $headers(): TODO;
declare function $highWaterMark(): TODO;
declare function $host(): TODO;
declare function $hostname(): TODO;
declare function $ignoreBOM(): TODO;
declare function $importer(): TODO;
declare function $internalRequire(id: string, parent: JSCommonJSModule, requireMap: RequireMap): TODO;
declare function $isAbortSignal(signal: unknown): signal is AbortSignal;
declare function $isAbsolute(): TODO;
declare function $join(): TODO;
declare function $main(): TODO;
declare function $makeDOMException(): TODO;
declare function $makeGetterTypeError(className: string, prop: string): Error;
declare function $method(): TODO;
declare function $normalize(): TODO;
declare function $parse(): TODO;
declare function $path(): TODO;
declare function $port(): TODO;
declare function $pull(): TODO;
declare function $read(): TODO;
declare function $readable(): TODO;
declare function $removeAbortAlgorithmFromSignal(signal: AbortSignal, algorithmIdentifier: number): TODO;
declare function $redirect(): TODO;
declare function $relative(): TODO;
declare function $require(): TODO;
/** Loads `id` into `mod`. Returns -1 when the module is ESM and must be loaded from the ESM registry. */
declare function $requireCommonJS(
id: string,
mod: JSCommonJSModule,
parentFilename: unknown,
userArgumentCount: number,
userOptions: unknown,
): JSCommonJSModule | -1;
declare function $requireESM(path: string, requirer?: JSCommonJSModule): any;
declare function $requireNativeModule(id: string): any;
declare const $requireMap: Map<string, JSCommonJSModule> & {
$traceRequire: ((parent: JSCommonJSModule, id: string, options: unknown) => unknown) | undefined;
};
declare const $internalModuleRegistry: InternalFieldObject<any[]>;
declare function $resolve(name: string, from: string): Promise<string>;
declare function $resolveSync(
name: string,
from: string,
isESM?: boolean,
isUserRequireResolve?: boolean,
paths?: string[],
parentModule?: JSCommonJSModule,
resolveFilenameOptions?: unknown,
): string;
declare function $self(): TODO;
declare function $size(): TODO;
declare function $start(): TODO;
declare function $status(): TODO;
declare function $stream(): TODO;
declare function $syscall(): TODO;
declare function $toNamespacedPath(): TODO;
declare function $url(): TODO;
declare function $writable(): TODO;
declare function $write(): TODO;
declare function $writer(): TODO;
declare function $written(): TODO;
declare function $createCommonJSModule(
id: string,
exports: any,
hasEvaluated: boolean,
parent: JSCommonJSModule | undefined,
): JSCommonJSModule;
declare function $evaluateCommonJSModule(
moduleToEvaluate: JSCommonJSModule,
sourceModule: JSCommonJSModule | undefined,
): JSCommonJSModule[];
declare function $evictIsolationSourceProviderCache(key?: string): void;
declare function $overridableRequire(this: JSCommonJSModule, id: string): any;
// The following I cannot find any definitions of, but they are functional.
declare function $toLength(length: number): number;
declare function $isTypedArrayView(obj: unknown): obj is ArrayBufferView | DataView | Uint8Array;
declare function $setStateToMax(target: any, state: number): void;
/** @deprecated, use new TypeError instead */
declare function $makeTypeError(message: string): TypeError;
declare const __internal: unique symbol;
interface InternalFieldObject<T extends any[]> {
[__internal]: T;
}
// You can also `@` on any method on a classes to avoid prototype pollution and secret internals.
declare interface CallableFunction {
$call: CallableFunction["call"];
$bind: CallableFunction["bind"];
$toString: CallableFunction["toString"];
}
// `apply` takes any array-like list; the standard library's declaration leaves out `arguments`.
declare interface CallableFunction {
$apply<T, R>(this: (this: T) => R, thisArg: T): R;
$apply<T, A extends any[], R>(this: (this: T, ...args: A) => R, thisArg: T, args: A): R;
$apply<T, R>(this: (this: T, ...args: any[]) => R, thisArg: T, args: IArguments | $AnyObject): R;
}
declare interface Promise<T> {
$then: Promise<T>["then"];
$catch: Promise<T>["catch"];
$finally: Promise<T>["finally"];
}
declare interface ArrayBufferConstructor {
$isView: ArrayBufferConstructor["isView"];
}
declare interface PromiseConstructor {
$all: PromiseConstructor["all"];
$allSettled: PromiseConstructor["allSettled"];
$any: PromiseConstructor["any"];
$race: PromiseConstructor["race"];
$reject: PromiseConstructor["reject"];
$resolve: PromiseConstructor["resolve"];
$try: PromiseConstructor["try"];
$withResolvers: PromiseConstructor["withResolvers"];
}
declare interface UnderlyingSource {
$lazy?: boolean;
$bunNativePtr?: undefined | TODO;
autoAllocateChunkSize?: number;
$stream?: ReadableStream;
}
declare interface AddEventListenerOptions {
/**
* Private symbol read by the native EventTarget. A listener registered with it still
* runs after another listener called `stopImmediatePropagation()`. Mirrors Node.js's
* internal `kResistStopPropagation`.
*/
$kResistStopPropagation?: boolean;
}
// Provided by the C++ Web Streams implementation.
declare class ReadableByteStreamController {
private constructor();
}
declare class ReadableStreamBYOBRequest {
private constructor();
}
declare class ReadableStreamBYOBReader {
constructor(stream: ReadableStream);
}
// Inlining our enum types
declare const $ImportKindIdToLabel: Array<import("bun").ImportKind>;
declare const $ImportKindLabelToId: Record<import("bun").ImportKind, number>;
declare const $LoaderIdToLabel: Array<import("bun").Loader>;
declare const $LoaderLabelToId: Record<import("bun").Loader, number>;
// not a builtin, but a build-time macro of our own
/** Returns a not implemented error that points to a github issue. */
declare function notImplementedIssue(issueNumber: number, description: string): Error;
/** Return a function that throws a not implemented error that points to a github issue */
declare function notImplementedIssueFn(issueNumber: number, description: string): (...args: any[]) => never;
declare type JSCSourceCodeObject = unique symbol;
declare interface Function {
path: string;
}
interface String {
$charCodeAt: String["charCodeAt"];
// add others as needed
}
interface Set<T> {
$add: Set<T>["add"];
$clear: Set<T>["clear"];
$delete: Set<T>["delete"];
$has: Set<T>["has"];
}
interface Map<K, V> {
$clear: Map<K, V>["clear"];
$delete: Map<K, V>["delete"];
$has: Map<K, V>["has"];
$set: Map<K, V>["set"];
$get: Map<K, V>["get"];
$forEach: Map<K, V>["forEach"];
$entries: Map<K, V>["entries"];
$keys: Map<K, V>["keys"];
$values: Map<K, V>["values"];
readonly $size: Map<K, V>["size"];
}
declare var $Array: ArrayConstructor;
declare var $Buffer: {
byteLength: typeof Buffer.byteLength;
new (array: Array): Buffer;
new (arrayBuffer: ArrayBuffer, byteOffset?: number, length?: number): Buffer;
new (view: ArrayBufferView, byteOffset?: number, length?: number): Buffer;
new (buffer: Buffer): Buffer;
new (size: number): Buffer;
new (string: string, encoding?: BufferEncoding): Buffer;
};
declare interface Error {
code?: string;
}
declare function $makeAbortError(message?: string, options?: ErrorOptions): Error;
/**
* -- Error Codes with manual messages
*/
declare function $ERR_INVALID_ARG_TYPE(argName: string, expectedType: string, actualValue: any): TypeError;
declare function $ERR_INVALID_ARG_TYPE(argName: string, expectedTypes: string[], actualValue: any): TypeError;
declare function $ERR_INVALID_ARG_VALUE(name: string, value: any, reason?: string): TypeError;
declare function $ERR_INVALID_ARG_VALUE_RangeError(name: string, value: any, reason?: string): RangeError;
declare function $ERR_UNKNOWN_ENCODING(enc: string): TypeError;
declare function $ERR_STREAM_DESTROYED(method: string): Error;
declare function $ERR_METHOD_NOT_IMPLEMENTED(method: string): Error;
declare function $ERR_STREAM_ALREADY_FINISHED(method: string): Error;
declare function $ERR_MISSING_ARGS(...args: [string, ...string[]]): TypeError;
/**
* `The "foo" or "bar" or "baz" argument must be specified`
*
* Panics if `oneOf` is empty.
*/
declare function $ERR_MISSING_ARGS(oneOf: string[]): TypeError;
declare function $ERR_INVALID_RETURN_VALUE(expected_type: string, name: string, actual_value: any): TypeError;
declare function $ERR_TLS_INVALID_PROTOCOL_VERSION(a: string, b: string): TypeError;
declare function $ERR_TLS_PROTOCOL_VERSION_CONFLICT(version: string, secureProtocol: string): TypeError;
declare function $ERR_INVALID_IP_ADDRESS(ip: any): TypeError;
declare function $ERR_INVALID_ADDRESS_FAMILY(addressType, host, port): RangeError;
declare function $ERR_OUT_OF_RANGE(name: string, reason: string, value): RangeError;
declare function $ERR_BUFFER_TOO_LARGE(len: number): RangeError;
declare function $ERR_BROTLI_INVALID_PARAM(p: number): RangeError;
declare function $ERR_TLS_CERT_ALTNAME_INVALID(reason: string, host: string, cert): Error;
declare function $ERR_USE_AFTER_CLOSE(name: string): Error;
declare function $ERR_HTTP2_INVALID_HEADER_VALUE(value: string, name: string): TypeError;
declare function $ERR_INVALID_HANDLE_TYPE(): TypeError;
declare function $ERR_INVALID_HTTP_TOKEN(name: string, value: string): TypeError;
declare function $ERR_HTTP2_STATUS_INVALID(code: number): RangeError;
declare function $ERR_HTTP2_INVALID_PSEUDOHEADER(name: string): TypeError;
declare function $ERR_HTTP2_STREAM_ERROR(code): Error;
declare function $ERR_HTTP2_SESSION_ERROR(code): Error;
declare function $ERR_HTTP2_TOO_MANY_ORIGINS(max: number): Error;
declare function $ERR_HTTP2_PAYLOAD_FORBIDDEN(status): Error;
declare function $ERR_HTTP2_INVALID_INFO_STATUS(code): RangeError;
declare function $ERR_INVALID_URL(input, base?): TypeError;
declare function $ERR_INVALID_CHAR(name, field?): TypeError;
declare function $ERR_HTTP_INVALID_HEADER_VALUE(value: string, name: string): TypeError;
declare function $ERR_HTTP_HEADERS_SENT(action: string): Error;
declare function $ERR_INVALID_PROTOCOL(proto, expected): TypeError;
declare function $ERR_INVALID_URL_SCHEME(expected: string): TypeError;
declare function $ERR_INVALID_STATE(message: string): Error;
declare function $ERR_INVALID_STATE_TypeError(message: string): TypeError;
declare function $ERR_INVALID_STATE_RangeError(message: string): RangeError;
declare function $ERR_UNESCAPED_CHARACTERS(arg): TypeError;
declare function $ERR_HTTP_INVALID_STATUS_CODE(code): RangeError;
declare function $ERR_HTTP_CONTENT_LENGTH_MISMATCH(actual: number, expected: number): Error;
declare function $ERR_UNHANDLED_ERROR(err?): Error;
declare function $ERR_BUFFER_OUT_OF_BOUNDS(name?: string): RangeError;
declare function $ERR_CHILD_PROCESS_IPC_REQUIRED(where): Error;
declare function $ERR_CHILD_PROCESS_STDIO_MAXBUFFER(message): Error;
declare function $ERR_INVALID_ASYNC_ID(name, value): RangeError;
declare function $ERR_ASYNC_TYPE(name): TypeError;
declare function $ERR_ASYNC_CALLBACK(name): TypeError;
declare function $ERR_AMBIGUOUS_ARGUMENT(arg, message): TypeError;
declare function $ERR_INVALID_FD_TYPE(type): TypeError;
declare function $ERR_IP_BLOCKED(ip): Error;
declare function $ERR_IPC_CHANNEL_CLOSED(): Error;
declare function $ERR_IPC_DISCONNECTED(): Error;
declare function $ERR_INSPECTOR_ALREADY_ACTIVATED(message?: string): Error;
declare function $ERR_INSPECTOR_NOT_ACTIVE(): Error;
declare function $ERR_INSPECTOR_ALREADY_CONNECTED(): Error;
declare function $ERR_INSPECTOR_NOT_CONNECTED(): Error;
declare function $ERR_INSPECTOR_NOT_WORKER(): Error;
declare function $ERR_INSPECTOR_COMMAND(message: string): Error;
declare function $ERR_WORKER_UNSUPPORTED_OPERATION(message: string): TypeError;
declare function $ERR_SERVER_NOT_RUNNING(): Error;
declare function $ERR_SOCKET_BAD_TYPE(): Error;
declare function $ERR_ZLIB_INITIALIZATION_FAILED(): Error;
declare function $ERR_IPC_ONE_PIPE(): Error;
declare function $ERR_SOCKET_ALREADY_BOUND(): Error;
declare function $ERR_SOCKET_BAD_BUFFER_SIZE(): Error;
declare function $ERR_SOCKET_DGRAM_IS_CONNECTED(): Error;
declare function $ERR_SOCKET_DGRAM_NOT_CONNECTED(): Error;
declare function $ERR_SOCKET_DGRAM_NOT_RUNNING(): Error;
declare function $ERR_INVALID_CURSOR_POS(): Error;
declare function $ERR_SCRIPT_EXECUTION_INTERRUPTED(): Error;
declare function $ERR_MULTIPLE_CALLBACK(): Error;
declare function $ERR_STREAM_PREMATURE_CLOSE(): Error;
declare function $ERR_STREAM_NULL_VALUES(): TypeError;
declare function $ERR_STREAM_ITER_MISSING_FLAG(): TypeError;
declare function $ERR_STREAM_CANNOT_PIPE(): Error;
declare function $ERR_STREAM_WRITE_AFTER_END(): Error;
declare function $ERR_STREAM_UNSHIFT_AFTER_END_EVENT(): Error;
declare function $ERR_STREAM_PUSH_AFTER_EOF(): Error;
declare function $ERR_STREAM_UNABLE_TO_PIPE(): Error;
declare function $ERR_ILLEGAL_CONSTRUCTOR(): TypeError;
declare function $ERR_SERVER_ALREADY_LISTEN(): Error;
declare function $ERR_SOCKET_CLOSED(): Error;
declare function $ERR_SOCKET_CLOSED_BEFORE_CONNECTION(): Error;
declare function $ERR_TLS_RENEGOTIATION_DISABLED(): Error;
declare function $ERR_TLS_RENEGOTIATION_UNSUPPORTED(): Error;
declare function $ERR_TLS_INVALID_STATE(): Error;
declare function $ERR_UNAVAILABLE_DURING_EXIT(): Error;
declare function $ERR_TLS_CERT_ALTNAME_FORMAT(): SyntaxError;
declare function $ERR_TLS_REQUIRED_SERVER_NAME(): Error;
declare function $ERR_TLS_SNI_FROM_SERVER(): Error;
declare function $ERR_SSL_NO_CIPHER_MATCH(): Error;
declare function $ERR_INVALID_URI(): URIError;
declare function $ERR_HTTP2_PSEUDOHEADER_NOT_ALLOWED(): TypeError;
declare function $ERR_HTTP2_INFO_STATUS_NOT_ALLOWED(): RangeError;
declare function $ERR_HTTP2_HEADERS_SENT(): Error;
declare function $ERR_HTTP2_INVALID_STREAM(): Error;
declare function $ERR_HTTP2_NO_SOCKET_MANIPULATION(): Error;
declare function $ERR_HTTP2_SOCKET_UNBOUND(): Error;
declare function $ERR_HTTP2_MAX_PENDING_SETTINGS_ACK(): Error;
declare function $ERR_HTTP2_INVALID_SESSION(): Error;
declare function $ERR_HTTP2_TRAILERS_ALREADY_SENT(): Error;
declare function $ERR_HTTP2_TRAILERS_NOT_READY(): Error;
declare function $ERR_HTTP2_SEND_FILE(): Error;
declare function $ERR_HTTP2_SEND_FILE_NOSEEK(): Error;
declare function $ERR_HTTP2_PUSH_DISABLED(): Error;
declare function $ERR_HTTP2_HEADERS_AFTER_RESPOND(): Error;
declare function $ERR_HTTP2_STATUS_101(): Error;
declare function $ERR_HTTP2_ALTSVC_INVALID_ORIGIN(): TypeError;
declare function $ERR_HTTP2_INVALID_ORIGIN(): TypeError;
declare function $ERR_HTTP2_ALTSVC_LENGTH(): TypeError;
declare function $ERR_HTTP2_PING_LENGTH(): RangeError;
declare function $ERR_HTTP2_OUT_OF_STREAMS(): Error;
declare function $ERR_HTTP_BODY_NOT_ALLOWED(): Error;
declare function $ERR_HTTP_TRAILER_INVALID(): Error;
declare function $ERR_HTTP_SOCKET_ASSIGNED(): Error;
declare function $ERR_DIR_CLOSED(): Error;
declare function $ERR_SOCKET_CONNECTION_TIMEOUT(): Error;
declare function $ERR_TLS_HANDSHAKE_TIMEOUT(): Error;
declare function $ERR_VM_MODULE_STATUS(reason: string): Error;
declare function $ERR_VM_MODULE_ALREADY_LINKED(): Error;
declare function $ERR_VM_MODULE_CANNOT_CREATE_CACHED_DATA(): Error;
declare function $ERR_VM_MODULE_NOT_MODULE(): Error;
declare function $ERR_VM_MODULE_DIFFERENT_CONTEXT(): Error;
declare function $ERR_VM_MODULE_LINK_FAILURE(message: string, cause: Error): Error;
declare function $ERR_TLS_ALPN_CALLBACK_WITH_PROTOCOLS(): TypeError;
declare function $ERR_TLS_ALPN_CALLBACK_INVALID_RESULT(message: string): TypeError;
declare function $ERR_HTTP2_TOO_MANY_CUSTOM_SETTINGS(): Error;
declare function $ERR_HTTP2_CONNECT_AUTHORITY(): Error;
declare function $ERR_HTTP2_CONNECT_SCHEME(): Error;
declare function $ERR_HTTP2_CONNECT_PATH(): Error;
declare function $ERR_HTTP2_TOO_MANY_INVALID_FRAMES(): Error;
declare function $ERR_HTTP2_PING_CANCEL(): Error;
/**
* Convert a function to a class-like object.
*
* This does:
* - Sets the name of the function to the given name
* - Sets .prototype to Object.create(base?.prototype, { constructor: { value: fn } })
* - Calls Object.setPrototypeOf(fn, base ?? Function.prototype)
*
* @param fn - The function to convert to a class
* @param name - The name of the class
* @param base - The base class to inherit from
*/
declare function $toClass(fn: Function, name: string, base?: Function | undefined | null);
declare function $min(a: number, b: number): number;
interface Set<T> {
$forEach: Set<T>["forEach"];
}
interface ObjectConstructor {
$create: typeof Object.create;
$getPrototypeOf: typeof Object.getPrototypeOf;
$defineProperty: typeof Object.defineProperty;
$defineProperties: typeof Object.defineProperties;
$getOwnPropertyDescriptor: typeof Object.getOwnPropertyDescriptor;
$getOwnPropertyNames: typeof Object.getOwnPropertyNames;
$getOwnPropertySymbols: typeof Object.getOwnPropertySymbols;
}
declare var $Map: MapConstructor;
declare var $Object: ObjectConstructor;
/** gets a property on an object */
declare function $getByIdDirect<T, K extends keyof T>(obj: T, key: K): T[K];
declare function $getPrototypeOf(value: unknown): object | null;
/**
* Gets a private property on an object.
* Translates to the `op_get_by_id_direct` bytecode.
*
* @param obj The object to get the private property from
* @param key The key of the private property (without the "$" prefix)
* @returns The value of the private property
*/
declare function $getByIdDirectPrivate<T = any, K extends string = string>(
obj: T,
key: K,
): K extends keyof T ? T[`$${K}`] : T extends { [P in `$${K}`]: infer V } ? V : never;
declare var $Promise: PromiseConstructor;
declare function $isPromise<T>(value: unknown): value is Promise<T>;