finish file server

This commit is contained in:
marlonerler
2024-07-04 16:11:02 +02:00
parent 8fa8bc6ed0
commit c97e3b5450
829 changed files with 143867 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
# TypeScript types for Bun
<p align="center">
<a href="https://bun.sh"><img src="https://bun.sh/logo@2x.png" alt="Logo"></a>
</p>
These are the type definitions for Bun's JavaScript runtime APIs.
# Installation
Install the `@types/bun` npm package:
```bash
# yarn/npm/pnpm work too
# @types/bun is an ordinary npm package
bun add -D @types/bun
```
That's it! VS Code and TypeScript automatically load `@types/*` packages into your project, so the `Bun` global and all `bun:*` modules should be available immediately.
# Contributing
The `@types/bun` package is a shim that loads `bun-types`. The `bun-types` package lives in the Bun repo under `packages/bun-types`. It is generated via [./scripts/bundle.ts](./scripts/bundle.ts).
To add a new file, add it under `packages/bun-types`. Then add a [triple-slash directive](https://www.typescriptlang.org/docs/handbook/triple-slash-directives.html) pointing to it inside [./index.d.ts](./index.d.ts).
```diff
+ /// <reference path="./newfile.d.ts" />
```
[`./bundle.ts`](./bundle.ts) merges the types in this folder into a single file. To run it:
```bash
bun build
```
+5389
View File
File diff suppressed because it is too large Load Diff
+79
View File
@@ -0,0 +1,79 @@
declare module "bun" {
/**
* @deprecated Renamed to `ErrorLike`
*/
type Errorlike = ErrorLike;
interface TLSOptions {
/**
* File path to a TLS key
*
* To enable TLS, this option is required.
*
* @deprecated since v0.6.3 - Use `key: Bun.file(path)` instead.
*/
keyFile?: string;
/**
* File path to a TLS certificate
*
* To enable TLS, this option is required.
*
* @deprecated since v0.6.3 - Use `cert: Bun.file(path)` instead.
*/
certFile?: string;
/**
* File path to a .pem file for a custom root CA
*
* @deprecated since v0.6.3 - Use `ca: Bun.file(path)` instead.
*/
caFile?: string;
}
}
declare namespace NodeJS {
interface Process {
/**
* @deprecated This is deprecated; use the "node:assert" module instead.
*/
assert(value: unknown, message?: string | Error): asserts value;
}
}
declare namespace Bun {
interface MessageEvent {
/** @deprecated */
initMessageEvent(
type: string,
bubbles?: boolean,
cancelable?: boolean,
data?: any,
origin?: string,
lastEventId?: string,
source?: null,
): void;
}
}
interface CustomEvent<T = any> {
/** @deprecated */
initCustomEvent(
type: string,
bubbles?: boolean,
cancelable?: boolean,
detail?: T,
): void;
}
interface DOMException {
/** @deprecated */
readonly code: number;
}
/**
* @deprecated Renamed to `BuildMessage`
*/
declare var BuildError: typeof BuildMessage;
/**
* @deprecated Renamed to `ResolveMessage`
*/
declare var ResolveError: typeof ResolveMessage;
+58
View File
@@ -0,0 +1,58 @@
type _Response = typeof globalThis extends { onmessage: any }
? {}
: import("undici-types").Response;
export interface Response extends _Response {}
export declare class Response {
constructor(
body?: Bun.BodyInit | null | undefined,
init?: Bun.ResponseInit | undefined,
);
/**
* Create a new {@link Response} with a JSON body
*
* @param body - The body of the response
* @param options - options to pass to the response
*
* @example
*
* ```ts
* const response = Response.json({hi: "there"});
* console.assert(
* await response.text(),
* `{"hi":"there"}`
* );
* ```
* -------
*
* This is syntactic sugar for:
* ```js
* new Response(JSON.stringify(body), {headers: { "Content-Type": "application/json" }})
* ```
* @link https://github.com/whatwg/fetch/issues/1389
*/
static json(body?: any, options?: Bun.ResponseInit | number): Response;
/**
* Create a new {@link Response} that redirects to url
*
* @param url - the URL to redirect to
* @param status - the HTTP status code to use for the redirect
*/
// tslint:disable-next-line:unified-signatures
static redirect(url: string, status?: number): Response;
/**
* Create a new {@link Response} that redirects to url
*
* @param url - the URL to redirect to
* @param options - options to pass to the response
*/
// tslint:disable-next-line:unified-signatures
static redirect(url: string, options?: Bun.ResponseInit): Response;
/**
* Create a new {@link Response} that has a network error
*/
static error(): Response;
}
+1050
View File
File diff suppressed because it is too large Load Diff
+2077
View File
File diff suppressed because it is too large Load Diff
+131
View File
@@ -0,0 +1,131 @@
declare namespace HTMLRewriterTypes {
interface HTMLRewriterElementContentHandlers {
element?(element: Element): void | Promise<void>;
comments?(comment: Comment): void | Promise<void>;
text?(text: Text): void | Promise<void>;
}
interface HTMLRewriterDocumentContentHandlers {
doctype?(doctype: Doctype): void | Promise<void>;
comments?(comment: Comment): void | Promise<void>;
text?(text: Text): void | Promise<void>;
end?(end: DocumentEnd): void | Promise<void>;
}
interface Text {
readonly text: string;
readonly lastInTextNode: boolean;
readonly removed: boolean;
before(content: Content, options?: ContentOptions): Text;
after(content: Content, options?: ContentOptions): Text;
replace(content: Content, options?: ContentOptions): Text;
remove(): Text;
}
interface Doctype {
readonly name: string | null;
readonly publicId: string | null;
readonly systemId: string | null;
}
interface DocumentEnd {
append(content: Content, options?: ContentOptions): DocumentEnd;
}
interface ContentOptions {
html?: boolean;
}
type Content = string;
interface Comment {
text: string;
readonly removed: boolean;
before(content: Content, options?: ContentOptions): Comment;
after(content: Content, options?: ContentOptions): Comment;
replace(content: Content, options?: ContentOptions): Comment;
remove(): Comment;
}
interface Element {
tagName: string;
readonly attributes: IterableIterator<string[]>;
readonly removed: boolean;
/** Whether the element is explicitly self-closing, e.g. `<foo />` */
readonly selfClosing: boolean;
/**
* Whether the element can have inner content. Returns `true` unless
* - the element is an [HTML void element](https://html.spec.whatwg.org/multipage/syntax.html#void-elements)
* - or it's self-closing in a foreign context (eg. in SVG, MathML).
*/
readonly canHaveContent: boolean;
readonly namespaceURI: string;
getAttribute(name: string): string | null;
hasAttribute(name: string): boolean;
setAttribute(name: string, value: string): Element;
removeAttribute(name: string): Element;
before(content: Content, options?: ContentOptions): Element;
after(content: Content, options?: ContentOptions): Element;
prepend(content: Content, options?: ContentOptions): Element;
append(content: Content, options?: ContentOptions): Element;
replace(content: Content, options?: ContentOptions): Element;
remove(): Element;
removeAndKeepContent(): Element;
setInnerContent(content: Content, options?: ContentOptions): Element;
onEndTag(handler: (tag: EndTag) => void | Promise<void>): void;
}
interface EndTag {
name: string;
before(content: Content, options?: ContentOptions): EndTag;
after(content: Content, options?: ContentOptions): EndTag;
remove(): EndTag;
}
}
/**
* [HTMLRewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter?bun) is a fast API for transforming HTML.
*
* Bun leverages a native implementation powered by [lol-html](https://github.com/cloudflare/lol-html).
*
* HTMLRewriter can be used to transform HTML in a variety of ways, including:
* * Rewriting URLs
* * Adding meta tags
* * Removing elements
* * Adding elements to the head
*
* @example
* ```ts
* const rewriter = new HTMLRewriter().on('a[href]', {
* element(element: Element) {
* // Rewrite all the URLs to this youtube video
* element.setAttribute('href', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ');
* }
* });
* rewriter.transform(await fetch("https://remix.run"));
* ```
*/
declare class HTMLRewriter {
constructor();
on(
selector: string,
handlers: HTMLRewriterTypes.HTMLRewriterElementContentHandlers,
): HTMLRewriter;
onDocument(
handlers: HTMLRewriterTypes.HTMLRewriterDocumentContentHandlers,
): HTMLRewriter;
/**
* @param input - The HTML to transform
* @returns A new {@link Response} with the transformed HTML
*/
transform(input: Response | Blob | Bun.BufferSource): Response;
/**
* @param input - The HTML string to transform
* @returns A new {@link String} containing the transformed HTML
*/
transform(input: string): string;
/**
* @param input - The HTML to transform as a {@link ArrayBuffer}
* @returns A new {@link ArrayBuffer} with the transformed HTML
*/
transform(input: ArrayBuffer): ArrayBuffer;
}
+22
View File
@@ -0,0 +1,22 @@
// Project: https://github.com/oven-sh/bun
// Definitions by: Jarred Sumner <https://github.com/Jarred-Sumner>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference lib="esnext" />
/// <reference types="node" />
/// <reference types="ws" />
// contributors: uncomment this to detect conflicts with lib.dom.d.ts
//// <reference lib="dom" />
/// <reference path="./globals.d.ts" />
/// <reference path="./bun.d.ts" />
/// <reference path="./overrides.d.ts" />
/// <reference path="./fetch.d.ts" />
/// <reference path="./ffi.d.ts" />
/// <reference path="./test.d.ts" />
/// <reference path="./html-rewriter.d.ts" />
/// <reference path="./jsc.d.ts" />
/// <reference path="./sqlite.d.ts" />
/// <reference path="./wasm.d.ts" />
/// <reference path="./deprecated.d.ts" />
+224
View File
@@ -0,0 +1,224 @@
declare module "bun:jsc" {
/**
* This used to be called "describe" but it could be confused with the test runner.
*/
function jscDescribe(value: any): string;
function jscDescribeArray(args: any[]): string;
function gcAndSweep(): number;
function fullGC(): number;
function edenGC(): number;
function heapSize(): number;
function heapStats(): {
heapSize: number;
heapCapacity: number;
extraMemorySize: number;
objectCount: number;
protectedObjectCount: number;
globalObjectCount: number;
protectedGlobalObjectCount: number;
objectTypeCounts: Record<string, number>;
protectedObjectTypeCounts: Record<string, number>;
};
function memoryUsage(): {
current: number;
peak: number;
currentCommit: number;
peakCommit: number;
pageFaults: number;
};
function getRandomSeed(): number;
function setRandomSeed(value: number): void;
function isRope(input: string): boolean;
function callerSourceOrigin(): string;
function noFTL(func: (...args: any[]) => any): (...args: any[]) => any;
function noOSRExitFuzzing(
func: (...args: any[]) => any,
): (...args: any[]) => any;
function optimizeNextInvocation(func: (...args: any[]) => any): void;
function numberOfDFGCompiles(func: (...args: any[]) => any): number;
function releaseWeakRefs(): void;
function totalCompileTime(func: (...args: any[]) => any): number;
function reoptimizationRetryCount(func: (...args: any[]) => any): number;
function drainMicrotasks(): void;
/**
* Convert a JavaScript value to a binary representation that can be sent to another Bun instance.
*
* Internally, this uses the serialization format from WebKit/Safari.
*
* @param value A JavaScript value, usually an object or array, to be converted.
* @returns A SharedArrayBuffer that can be sent to another Bun instance.
*/
function serialize(
value: any,
options?: { binaryType?: "arraybuffer" },
): SharedArrayBuffer;
/**
* Convert a JavaScript value to a binary representation that can be sent to another Bun instance.
*
* Internally, this uses the serialization format from WebKit/Safari.
*
* @param value A JavaScript value, usually an object or array, to be converted.
* @returns A Buffer that can be sent to another Bun instance.
*/
function serialize(
value: any,
options?: { binaryType: "nodebuffer" },
): Buffer;
/**
* Convert an ArrayBuffer or Buffer to a JavaScript value compatible with the HTML Structured Clone Algorithm.
*
* @param value A serialized value, usually an ArrayBuffer or Buffer, to be converted.
*/
function deserialize(
value: ArrayBufferLike | NodeJS.TypedArray | Buffer,
): any;
/**
* Set the timezone used by Intl, Date, etc.
*
* @param timeZone A string representing the time zone to use, such as "America/Los_Angeles"
*
* @returns The normalized time zone string
*
* You can also set process.env.TZ to the time zone you want to use.
* You can also view the current timezone with `Intl.DateTimeFormat().resolvedOptions().timeZone`
*/
function setTimeZone(timeZone: string): string;
/**
* Run JavaScriptCore's sampling profiler for a particular function
*
* This is pretty low-level.
*
* Things to know:
* - LLint means "Low Level Interpreter", which is the interpreter that runs before any JIT compilation
* - Baseline is the first JIT compilation tier. It's the least optimized, but the fastest to compile
* - DFG means "Data Flow Graph", which is the second JIT compilation tier. It has some optimizations, but is slower to compile
* - FTL means "Faster Than Light", which is the third JIT compilation tier. It has the most optimizations, but is the slowest to compile
*/
function profile(
callback: CallableFunction,
sampleInterval?: number,
): {
/**
* A formatted summary of the top functions
*
* Example output:
* ```js
*
* Sampling rate: 100.000000 microseconds. Total samples: 6858
* Top functions as <numSamples 'functionName#hash:sourceID'>
* 2948 '#<nil>:8'
* 393 'visit#<nil>:8'
* 263 'push#<nil>:8'
* 164 'scan_ref_scoped#<nil>:8'
* 164 'walk#<nil>:8'
* 144 'pop#<nil>:8'
* 107 'extract_candidates#<nil>:8'
* 94 'get#<nil>:8'
* 82 'Function#<nil>:4294967295'
* 79 'set#<nil>:8'
* 67 'forEach#<nil>:5'
* 58 'collapse#<nil>:8'
* ```
*/
functions: string;
/**
* A formatted summary of the top bytecodes
*
* Example output:
* ```js
* Tier breakdown:
* -----------------------------------
* LLInt: 106 (1.545640%)
* Baseline: 2355 (34.339458%)
* DFG: 3290 (47.973170%)
* FTL: 833 (12.146398%)
* js builtin: 132 (1.924759%)
* Wasm: 0 (0.000000%)
* Host: 111 (1.618548%)
* RegExp: 15 (0.218723%)
* C/C++: 0 (0.000000%)
* Unknown Executable: 148 (2.158064%)
*
* Hottest bytecodes as <numSamples 'functionName#hash:JITType:bytecodeIndex'>
* 273 'visit#<nil>:DFG:bc#63'
* 121 'walk#<nil>:DFG:bc#7'
* 119 '#<nil>:Baseline:bc#1'
* 82 'Function#<nil>:None:<nil>'
* 66 '#<nil>:DFG:bc#11'
* 65 '#<nil>:DFG:bc#33'
* 58 '#<nil>:Baseline:bc#7'
* 53 '#<nil>:Baseline:bc#23'
* 50 'forEach#<nil>:DFG:bc#83'
* 49 'pop#<nil>:FTL:bc#65'
* 47 '#<nil>:DFG:bc#99'
* 45 '#<nil>:DFG:bc#16'
* 44 '#<nil>:DFG:bc#7'
* 44 '#<nil>:Baseline:bc#30'
* 44 'push#<nil>:FTL:bc#214'
* 41 '#<nil>:DFG:bc#50'
* 39 'get#<nil>:DFG:bc#27'
* 39 '#<nil>:Baseline:bc#0'
* 36 '#<nil>:DFG:bc#27'
* 36 'Dictionary#<nil>:DFG:bc#41'
* 36 'visit#<nil>:DFG:bc#81'
* 36 'get#<nil>:FTL:bc#11'
* 32 'push#<nil>:FTL:bc#49'
* 31 '#<nil>:DFG:bc#76'
* 31 '#<nil>:DFG:bc#10'
* 31 '#<nil>:DFG:bc#73'
* 29 'set#<nil>:DFG:bc#28'
* 28 'in_boolean_context#<nil>:DFG:bc#104'
* 28 '#<nil>:Baseline:<nil>'
* 28 'regExpSplitFast#<nil>:None:<nil>'
* 26 'visit#<nil>:DFG:bc#95'
* 26 'pop#<nil>:FTL:bc#120'
* 25 '#<nil>:DFG:bc#23'
* 25 'push#<nil>:FTL:bc#152'
* 24 'push#<nil>:FTL:bc#262'
* 24 '#<nil>:FTL:bc#10'
* 23 'is_identifier_char#<nil>:DFG:bc#22'
* 23 'visit#<nil>:DFG:bc#22'
* 22 '#<nil>:FTL:bc#27'
* 22 'indexOf#<nil>:None:<nil>'
* ```
*/
bytecodes: string;
/**
* Stack traces of the top functions
*/
stackTraces: string[];
};
/**
* This returns objects which native code has explicitly protected from being
* garbage collected
*
* By calling this function you create another reference to the object, which
* will further prevent it from being garbage collected
*
* This function is mostly a debugging tool for bun itself.
*
* Warning: not all objects returned are supposed to be observable from JavaScript
*/
function getProtectedObjects(): any[];
/**
* Start a remote debugging socket server on the given port.
*
* This exposes JavaScriptCore's built-in debugging server.
*
* This is untested. May not be supported yet on macOS
*/
function startRemoteDebugger(host?: string, port?: number): void;
/**
* Run JavaScriptCore's sampling profiler
*/
function startSamplingProfiler(optionalDirectory?: string): void;
}
+74
View File
@@ -0,0 +1,74 @@
export {};
import type { Env, PathLike, BunFile } from "bun";
declare global {
namespace NodeJS {
interface ProcessVersions extends Dict<string> {
bun: string;
}
interface ProcessEnv extends Env {}
}
}
declare module "fs/promises" {
function exists(path: PathLike): Promise<boolean>;
}
declare module "tls" {
interface BunConnectionOptions
extends Omit<ConnectionOptions, "key" | "ca" | "tls" | "cert"> {
/**
* Optionally override the trusted CA certificates. Default is to trust
* the well-known CAs curated by Mozilla. Mozilla's CAs are completely
* replaced when CAs are explicitly specified using this option.
*/
ca?:
| string
| Buffer
| NodeJS.TypedArray
| BunFile
| Array<string | Buffer | BunFile>
| undefined;
/**
* Cert chains in PEM format. One cert chain should be provided per
* private key. Each cert chain should consist of the PEM formatted
* certificate for a provided private key, followed by the PEM
* formatted intermediate certificates (if any), in order, and not
* including the root CA (the root CA must be pre-known to the peer,
* see ca). When providing multiple cert chains, they do not have to
* be in the same order as their private keys in key. If the
* intermediate certificates are not provided, the peer will not be
* able to validate the certificate, and the handshake will fail.
*/
cert?:
| string
| Buffer
| NodeJS.TypedArray
| BunFile
| Array<string | Buffer | NodeJS.TypedArray | BunFile>
| undefined;
/**
* Private keys in PEM format. PEM allows the option of private keys
* being encrypted. Encrypted keys will be decrypted with
* options.passphrase. Multiple keys using different algorithms can be
* provided either as an array of unencrypted key strings or buffers,
* or an array of objects in the form {pem: <string|buffer>[,
* passphrase: <string>]}. The object form can only occur in an array.
* object.passphrase is optional. Encrypted keys will be decrypted with
* object.passphrase if provided, or options.passphrase if it is not.
*/
key?:
| string
| Buffer
| BunFile
| NodeJS.TypedArray
| Array<string | Buffer | BunFile | NodeJS.TypedArray | KeyObject>
| undefined;
}
function connect(
options: BunConnectionOptions,
secureConnectListener?: () => void,
): TLSSocket;
}
+32
View File
@@ -0,0 +1,32 @@
{
"version": "1.1.17",
"name": "bun-types",
"license": "MIT",
"main": "",
"types": "index.d.ts",
"description": "Type definitions for Bun, an incredibly fast JavaScript runtime",
"repository": {
"type": "git",
"url": "https://github.com/oven-sh/bun",
"directory": "packages/bun-types"
},
"files": ["*.d.ts"],
"homepage": "https://bun.sh",
"dependencies": {
"@types/node": "~20.12.8",
"@types/ws": "~8.5.10"
},
"devDependencies": {
"@biomejs/biome": "^1.5.3",
"@definitelytyped/dtslint": "^0.0.199",
"@definitelytyped/eslint-plugin": "^0.0.197",
"typescript": "^5.0.2"
},
"scripts": {
"prebuild": "echo $(pwd)",
"build": "bun scripts/build.ts && bun run fmt",
"test": "tsc",
"fmt": "echo $(which biome) && biome format --write ."
},
"keywords": ["bun", "bun.js", "types"]
}
+1157
View File
File diff suppressed because it is too large Load Diff
+2208
View File
File diff suppressed because it is too large Load Diff
+291
View File
@@ -0,0 +1,291 @@
export {};
type _Global<T extends Bun.WebAssembly.ValueType = Bun.WebAssembly.ValueType> =
typeof globalThis extends {
onerror: any;
WebAssembly: { Global: infer T };
}
? T
: Bun.WebAssembly.Global<T>;
type _CompileError = typeof globalThis extends {
onerror: any;
WebAssembly: { CompileError: infer T };
}
? T
: Bun.WebAssembly.CompileError;
type _LinkError = typeof globalThis extends {
onerror: any;
WebAssembly: { LinkError: infer T };
}
? T
: Bun.WebAssembly.LinkError;
type _RuntimeError = typeof globalThis extends {
onerror: any;
WebAssembly: { RuntimeError: infer T };
}
? T
: Bun.WebAssembly.RuntimeError;
type _Memory = typeof globalThis extends {
onerror: any;
WebAssembly: { Memory: infer T };
}
? T
: Bun.WebAssembly.Memory;
type _Instance = typeof globalThis extends {
onerror: any;
WebAssembly: { Instance: infer T };
}
? T
: Bun.WebAssembly.Instance;
type _Module = typeof globalThis extends {
onerror: any;
WebAssembly: { Module: infer T };
}
? T
: Bun.WebAssembly.Module;
type _Table = typeof globalThis extends {
onerror: any;
WebAssembly: { Table: infer T };
}
? T
: Bun.WebAssembly.Table;
declare global {
namespace Bun {
namespace WebAssembly {
type ImportExportKind = "function" | "global" | "memory" | "table";
type TableKind = "anyfunc" | "externref";
// eslint-disable-next-line @typescript-eslint/ban-types
type ExportValue =
| Function
| Global
| WebAssembly.Memory
| WebAssembly.Table;
type Exports = Record<string, ExportValue>;
type ImportValue = ExportValue | number;
type Imports = Record<string, ModuleImports>;
type ModuleImports = Record<string, ImportValue>;
interface ValueTypeMap {
// eslint-disable-next-line @typescript-eslint/ban-types
anyfunc: Function;
externref: any;
f32: number;
f64: number;
i32: number;
i64: bigint;
v128: never;
}
type ValueType = keyof ValueTypeMap;
interface GlobalDescriptor<T extends ValueType = ValueType> {
mutable?: boolean;
value: T;
}
interface Global<T extends ValueType = ValueType> {
// <T extends ValueType = ValueType> {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/value) */
value: ValueTypeMap[T];
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global/valueOf) */
valueOf(): ValueTypeMap[T];
}
interface CompileError extends Error {}
interface LinkError extends Error {}
interface RuntimeError extends Error {}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) */
interface Instance {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance/exports) */
readonly exports: Exports;
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) */
interface Memory {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/buffer) */
readonly buffer: ArrayBuffer;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory/grow) */
grow(delta: number): number;
}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) */
interface Module {}
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) */
interface Table {
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/length) */
readonly length: number;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/get) */
get(index: number): any;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/grow) */
grow(delta: number, value?: any): number;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table/set) */
set(index: number, value?: any): void;
}
interface MemoryDescriptor {
initial: number;
maximum?: number;
shared?: boolean;
}
interface ModuleExportDescriptor {
kind: ImportExportKind;
name: string;
}
interface ModuleImportDescriptor {
kind: ImportExportKind;
module: string;
name: string;
}
interface TableDescriptor {
element: TableKind;
initial: number;
maximum?: number;
}
interface WebAssemblyInstantiatedSource {
instance: Instance;
module: Module;
}
}
}
namespace WebAssembly {
interface ValueTypeMap extends Bun.WebAssembly.ValueTypeMap {}
interface GlobalDescriptor<
T extends keyof ValueTypeMap = keyof ValueTypeMap,
> extends Bun.WebAssembly.GlobalDescriptor<T> {}
interface MemoryDescriptor extends Bun.WebAssembly.MemoryDescriptor {}
interface ModuleExportDescriptor
extends Bun.WebAssembly.ModuleExportDescriptor {}
interface ModuleImportDescriptor
extends Bun.WebAssembly.ModuleImportDescriptor {}
interface TableDescriptor extends Bun.WebAssembly.TableDescriptor {}
interface WebAssemblyInstantiatedSource
extends Bun.WebAssembly.WebAssemblyInstantiatedSource {}
interface LinkError extends _LinkError {}
var LinkError: {
prototype: LinkError;
new (message?: string): LinkError;
(message?: string): LinkError;
};
interface CompileError extends _CompileError {}
var CompileError: typeof globalThis extends {
onerror: any;
WebAssembly: { CompileError: infer T };
}
? T
: {
prototype: CompileError;
new (message?: string): CompileError;
(message?: string): CompileError;
};
interface RuntimeError extends _RuntimeError {}
var RuntimeError: {
prototype: RuntimeError;
new (message?: string): RuntimeError;
(message?: string): RuntimeError;
};
interface Global<T extends keyof ValueTypeMap = keyof ValueTypeMap>
extends _Global<T> {}
var Global: typeof globalThis extends {
onerror: any;
WebAssembly: { Global: infer T };
}
? T
: {
prototype: Global;
new <T extends Bun.WebAssembly.ValueType = Bun.WebAssembly.ValueType>(
descriptor: GlobalDescriptor<T>,
v?: ValueTypeMap[T],
): Global<T>;
};
interface Instance extends _Instance {}
var Instance: typeof globalThis extends {
onerror: any;
WebAssembly: { Instance: infer T };
}
? T
: {
prototype: Instance;
new (
module: Module,
importObject?: Bun.WebAssembly.Imports,
): Instance;
};
interface Memory extends _Memory {}
var Memory: {
prototype: Memory;
new (descriptor: MemoryDescriptor): Memory;
};
interface Module extends _Module {}
var Module: typeof globalThis extends {
onerror: any;
WebAssembly: { Module: infer T };
}
? T
: {
prototype: Module;
new (bytes: Bun.BufferSource): Module;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/customSections) */
customSections(
moduleObject: Module,
sectionName: string,
): ArrayBuffer[];
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/exports) */
exports(moduleObject: Module): ModuleExportDescriptor[];
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module/imports) */
imports(moduleObject: Module): ModuleImportDescriptor[];
};
interface Table extends _Table {}
var Table: {
prototype: Table;
new (descriptor: TableDescriptor, value?: any): Table;
};
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) */
function compile(bytes: Bun.BufferSource): Promise<Module>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) */
function compileStreaming(
source: Response | PromiseLike<Response>,
): Promise<Module>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) */
function instantiate(
bytes: Bun.BufferSource,
importObject?: Bun.WebAssembly.Imports,
): Promise<WebAssemblyInstantiatedSource>;
function instantiate(
moduleObject: Module,
importObject?: Bun.WebAssembly.Imports,
): Promise<Instance>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming) */
function instantiateStreaming(
source: Response | PromiseLike<Response>,
importObject?: Bun.WebAssembly.Imports,
): Promise<WebAssemblyInstantiatedSource>;
/** [MDN Reference](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate) */
function validate(bytes: Bun.BufferSource): boolean;
}
}