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.
@@ -0,0 +1,126 @@
1
+ declare namespace HTMLRewriterTypes {
2
+ interface HTMLRewriterElementContentHandlers {
3
+ element?(element: Element): void | Promise<void>;
4
+ comments?(comment: Comment): void | Promise<void>;
5
+ text?(text: Text): void | Promise<void>;
6
+ }
7
+
8
+ interface HTMLRewriterDocumentContentHandlers {
9
+ doctype?(doctype: Doctype): void | Promise<void>;
10
+ comments?(comment: Comment): void | Promise<void>;
11
+ text?(text: Text): void | Promise<void>;
12
+ end?(end: DocumentEnd): void | Promise<void>;
13
+ }
14
+
15
+ interface Text {
16
+ readonly text: string;
17
+ readonly lastInTextNode: boolean;
18
+ readonly removed: boolean;
19
+ before(content: Content, options?: ContentOptions): Text;
20
+ after(content: Content, options?: ContentOptions): Text;
21
+ replace(content: Content, options?: ContentOptions): Text;
22
+ remove(): Text;
23
+ }
24
+
25
+ interface Doctype {
26
+ readonly name: string | null;
27
+ readonly publicId: string | null;
28
+ readonly systemId: string | null;
29
+ }
30
+
31
+ interface DocumentEnd {
32
+ append(content: Content, options?: ContentOptions): DocumentEnd;
33
+ }
34
+
35
+ interface ContentOptions {
36
+ html?: boolean;
37
+ }
38
+ type Content = string;
39
+
40
+ interface Comment {
41
+ text: string;
42
+ readonly removed: boolean;
43
+ before(content: Content, options?: ContentOptions): Comment;
44
+ after(content: Content, options?: ContentOptions): Comment;
45
+ replace(content: Content, options?: ContentOptions): Comment;
46
+ remove(): Comment;
47
+ }
48
+
49
+ interface Element {
50
+ tagName: string;
51
+ readonly attributes: IterableIterator<string[]>;
52
+ readonly removed: boolean;
53
+ /** Whether the element is explicitly self-closing, e.g. `<foo />` */
54
+ readonly selfClosing: boolean;
55
+ /**
56
+ * Whether the element can have inner content. Returns `true` unless
57
+ * - the element is an [HTML void element](https://html.spec.whatwg.org/multipage/syntax.html#void-elements)
58
+ * - or it's self-closing in a foreign context (eg. in SVG, MathML).
59
+ */
60
+ readonly canHaveContent: boolean;
61
+ readonly namespaceURI: string;
62
+ getAttribute(name: string): string | null;
63
+ hasAttribute(name: string): boolean;
64
+ setAttribute(name: string, value: string): Element;
65
+ removeAttribute(name: string): Element;
66
+ before(content: Content, options?: ContentOptions): Element;
67
+ after(content: Content, options?: ContentOptions): Element;
68
+ prepend(content: Content, options?: ContentOptions): Element;
69
+ append(content: Content, options?: ContentOptions): Element;
70
+ replace(content: Content, options?: ContentOptions): Element;
71
+ remove(): Element;
72
+ removeAndKeepContent(): Element;
73
+ setInnerContent(content: Content, options?: ContentOptions): Element;
74
+ onEndTag(handler: (tag: EndTag) => void | Promise<void>): void;
75
+ }
76
+
77
+ interface EndTag {
78
+ name: string;
79
+ before(content: Content, options?: ContentOptions): EndTag;
80
+ after(content: Content, options?: ContentOptions): EndTag;
81
+ remove(): EndTag;
82
+ }
83
+ }
84
+
85
+ /**
86
+ * [HTMLRewriter](https://developers.cloudflare.com/workers/runtime-apis/html-rewriter?bun) is a fast API for transforming HTML.
87
+ *
88
+ * Bun leverages a native implementation powered by [lol-html](https://github.com/cloudflare/lol-html).
89
+ *
90
+ * HTMLRewriter can be used to transform HTML in a variety of ways, including:
91
+ * * Rewriting URLs
92
+ * * Adding meta tags
93
+ * * Removing elements
94
+ * * Adding elements to the head
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * const rewriter = new HTMLRewriter().on('a[href]', {
99
+ * element(element: Element) {
100
+ * // Rewrite all the URLs to this youtube video
101
+ * element.setAttribute('href', 'https://www.youtube.com/watch?v=dQw4w9WgXcQ');
102
+ * }
103
+ * });
104
+ * rewriter.transform(await fetch("https://remix.run"));
105
+ * ```
106
+ */
107
+ declare class HTMLRewriter {
108
+ constructor();
109
+ on(selector: string, handlers: HTMLRewriterTypes.HTMLRewriterElementContentHandlers): HTMLRewriter;
110
+ onDocument(handlers: HTMLRewriterTypes.HTMLRewriterDocumentContentHandlers): HTMLRewriter;
111
+ /**
112
+ * @param input - The HTML to transform
113
+ * @returns A new {@link Response} with the transformed HTML
114
+ */
115
+ transform(input: Response | Blob | Bun.BufferSource): Response;
116
+ /**
117
+ * @param input - The HTML string to transform
118
+ * @returns A new {@link String} containing the transformed HTML
119
+ */
120
+ transform(input: string): string;
121
+ /**
122
+ * @param input - The HTML to transform as a {@link ArrayBuffer}
123
+ * @returns A new {@link ArrayBuffer} with the transformed HTML
124
+ */
125
+ transform(input: ArrayBuffer): ArrayBuffer;
126
+ }
package/index.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ // Project: https://github.com/oven-sh/bun
2
+ // Definitions by: Jarred Sumner <https://github.com/Jarred-Sumner>
3
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
4
+
5
+ /// <reference lib="esnext" />
6
+ /// <reference types="node" />
7
+ /// <reference types="ws" />
8
+
9
+ // contributors: uncomment this to detect conflicts with lib.dom.d.ts
10
+ /// <reference lib="dom" />
11
+
12
+ /// <reference path="./globals.d.ts" />
13
+ /// <reference path="./bun.d.ts" />
14
+ /// <reference path="./ffi.d.ts" />
15
+ /// <reference path="./test.d.ts" />
16
+ /// <reference path="./html-rewriter.d.ts" />
17
+ /// <reference path="./jsc.d.ts" />
18
+ /// <reference path="./sqlite.d.ts" />
19
+ /// <reference path="./wasm.d.ts" />
20
+ /// <reference path="./deprecated.d.ts" />
package/jsc.d.ts ADDED
@@ -0,0 +1,214 @@
1
+ declare module "bun:jsc" {
2
+ /**
3
+ * This used to be called "describe" but it could be confused with the test runner.
4
+ */
5
+ function jscDescribe(value: any): string;
6
+ function jscDescribeArray(args: any[]): string;
7
+ function gcAndSweep(): number;
8
+ function fullGC(): number;
9
+ function edenGC(): number;
10
+ function heapSize(): number;
11
+ function heapStats(): {
12
+ heapSize: number;
13
+ heapCapacity: number;
14
+ extraMemorySize: number;
15
+ objectCount: number;
16
+ protectedObjectCount: number;
17
+ globalObjectCount: number;
18
+ protectedGlobalObjectCount: number;
19
+ objectTypeCounts: Record<string, number>;
20
+ protectedObjectTypeCounts: Record<string, number>;
21
+ };
22
+ function memoryUsage(): {
23
+ current: number;
24
+ peak: number;
25
+ currentCommit: number;
26
+ peakCommit: number;
27
+ pageFaults: number;
28
+ };
29
+ function getRandomSeed(): number;
30
+ function setRandomSeed(value: number): void;
31
+ function isRope(input: string): boolean;
32
+ function callerSourceOrigin(): string;
33
+ function noFTL(func: (...args: any[]) => any): (...args: any[]) => any;
34
+ function noOSRExitFuzzing(func: (...args: any[]) => any): (...args: any[]) => any;
35
+ function optimizeNextInvocation(func: (...args: any[]) => any): void;
36
+ function numberOfDFGCompiles(func: (...args: any[]) => any): number;
37
+ function releaseWeakRefs(): void;
38
+ function totalCompileTime(func: (...args: any[]) => any): number;
39
+ function reoptimizationRetryCount(func: (...args: any[]) => any): number;
40
+ function drainMicrotasks(): void;
41
+
42
+ /**
43
+ * Convert a JavaScript value to a binary representation that can be sent to another Bun instance.
44
+ *
45
+ * Internally, this uses the serialization format from WebKit/Safari.
46
+ *
47
+ * @param value A JavaScript value, usually an object or array, to be converted.
48
+ * @returns A SharedArrayBuffer that can be sent to another Bun instance.
49
+ */
50
+ function serialize(value: any, options?: { binaryType?: "arraybuffer" }): SharedArrayBuffer;
51
+
52
+ /**
53
+ * Convert a JavaScript value to a binary representation that can be sent to another Bun instance.
54
+ *
55
+ * Internally, this uses the serialization format from WebKit/Safari.
56
+ *
57
+ * @param value A JavaScript value, usually an object or array, to be converted.
58
+ * @returns A Buffer that can be sent to another Bun instance.
59
+ */
60
+ function serialize(value: any, options?: { binaryType: "nodebuffer" }): Buffer;
61
+
62
+ /**
63
+ * Convert an ArrayBuffer or Buffer to a JavaScript value compatible with the HTML Structured Clone Algorithm.
64
+ *
65
+ * @param value A serialized value, usually an ArrayBuffer or Buffer, to be converted.
66
+ */
67
+ function deserialize(value: ArrayBufferLike | NodeJS.TypedArray | Buffer): any;
68
+
69
+ /**
70
+ * Set the timezone used by Intl, Date, etc.
71
+ *
72
+ * @param timeZone A string representing the time zone to use, such as "America/Los_Angeles"
73
+ *
74
+ * @returns The normalized time zone string
75
+ *
76
+ * You can also set process.env.TZ to the time zone you want to use.
77
+ * You can also view the current timezone with `Intl.DateTimeFormat().resolvedOptions().timeZone`
78
+ */
79
+ function setTimeZone(timeZone: string): string;
80
+
81
+ /**
82
+ * Run JavaScriptCore's sampling profiler for a particular function
83
+ *
84
+ * This is pretty low-level.
85
+ *
86
+ * Things to know:
87
+ * - LLint means "Low Level Interpreter", which is the interpreter that runs before any JIT compilation
88
+ * - Baseline is the first JIT compilation tier. It's the least optimized, but the fastest to compile
89
+ * - DFG means "Data Flow Graph", which is the second JIT compilation tier. It has some optimizations, but is slower to compile
90
+ * - FTL means "Faster Than Light", which is the third JIT compilation tier. It has the most optimizations, but is the slowest to compile
91
+ */
92
+ function profile(
93
+ callback: CallableFunction,
94
+ sampleInterval?: number,
95
+ ): {
96
+ /**
97
+ * A formatted summary of the top functions
98
+ *
99
+ * Example output:
100
+ * ```js
101
+ *
102
+ * Sampling rate: 100.000000 microseconds. Total samples: 6858
103
+ * Top functions as <numSamples 'functionName#hash:sourceID'>
104
+ * 2948 '#<nil>:8'
105
+ * 393 'visit#<nil>:8'
106
+ * 263 'push#<nil>:8'
107
+ * 164 'scan_ref_scoped#<nil>:8'
108
+ * 164 'walk#<nil>:8'
109
+ * 144 'pop#<nil>:8'
110
+ * 107 'extract_candidates#<nil>:8'
111
+ * 94 'get#<nil>:8'
112
+ * 82 'Function#<nil>:4294967295'
113
+ * 79 'set#<nil>:8'
114
+ * 67 'forEach#<nil>:5'
115
+ * 58 'collapse#<nil>:8'
116
+ * ```
117
+ */
118
+ functions: string;
119
+ /**
120
+ * A formatted summary of the top bytecodes
121
+ *
122
+ * Example output:
123
+ * ```js
124
+ * Tier breakdown:
125
+ * -----------------------------------
126
+ * LLInt: 106 (1.545640%)
127
+ * Baseline: 2355 (34.339458%)
128
+ * DFG: 3290 (47.973170%)
129
+ * FTL: 833 (12.146398%)
130
+ * js builtin: 132 (1.924759%)
131
+ * Wasm: 0 (0.000000%)
132
+ * Host: 111 (1.618548%)
133
+ * RegExp: 15 (0.218723%)
134
+ * C/C++: 0 (0.000000%)
135
+ * Unknown Executable: 148 (2.158064%)
136
+ *
137
+ * Hottest bytecodes as <numSamples 'functionName#hash:JITType:bytecodeIndex'>
138
+ * 273 'visit#<nil>:DFG:bc#63'
139
+ * 121 'walk#<nil>:DFG:bc#7'
140
+ * 119 '#<nil>:Baseline:bc#1'
141
+ * 82 'Function#<nil>:None:<nil>'
142
+ * 66 '#<nil>:DFG:bc#11'
143
+ * 65 '#<nil>:DFG:bc#33'
144
+ * 58 '#<nil>:Baseline:bc#7'
145
+ * 53 '#<nil>:Baseline:bc#23'
146
+ * 50 'forEach#<nil>:DFG:bc#83'
147
+ * 49 'pop#<nil>:FTL:bc#65'
148
+ * 47 '#<nil>:DFG:bc#99'
149
+ * 45 '#<nil>:DFG:bc#16'
150
+ * 44 '#<nil>:DFG:bc#7'
151
+ * 44 '#<nil>:Baseline:bc#30'
152
+ * 44 'push#<nil>:FTL:bc#214'
153
+ * 41 '#<nil>:DFG:bc#50'
154
+ * 39 'get#<nil>:DFG:bc#27'
155
+ * 39 '#<nil>:Baseline:bc#0'
156
+ * 36 '#<nil>:DFG:bc#27'
157
+ * 36 'Dictionary#<nil>:DFG:bc#41'
158
+ * 36 'visit#<nil>:DFG:bc#81'
159
+ * 36 'get#<nil>:FTL:bc#11'
160
+ * 32 'push#<nil>:FTL:bc#49'
161
+ * 31 '#<nil>:DFG:bc#76'
162
+ * 31 '#<nil>:DFG:bc#10'
163
+ * 31 '#<nil>:DFG:bc#73'
164
+ * 29 'set#<nil>:DFG:bc#28'
165
+ * 28 'in_boolean_context#<nil>:DFG:bc#104'
166
+ * 28 '#<nil>:Baseline:<nil>'
167
+ * 28 'regExpSplitFast#<nil>:None:<nil>'
168
+ * 26 'visit#<nil>:DFG:bc#95'
169
+ * 26 'pop#<nil>:FTL:bc#120'
170
+ * 25 '#<nil>:DFG:bc#23'
171
+ * 25 'push#<nil>:FTL:bc#152'
172
+ * 24 'push#<nil>:FTL:bc#262'
173
+ * 24 '#<nil>:FTL:bc#10'
174
+ * 23 'is_identifier_char#<nil>:DFG:bc#22'
175
+ * 23 'visit#<nil>:DFG:bc#22'
176
+ * 22 '#<nil>:FTL:bc#27'
177
+ * 22 'indexOf#<nil>:None:<nil>'
178
+ * ```
179
+ */
180
+ bytecodes: string;
181
+
182
+ /**
183
+ * Stack traces of the top functions
184
+ */
185
+ stackTraces: string[];
186
+ };
187
+
188
+ /**
189
+ * This returns objects which native code has explicitly protected from being
190
+ * garbage collected
191
+ *
192
+ * By calling this function you create another reference to the object, which
193
+ * will further prevent it from being garbage collected
194
+ *
195
+ * This function is mostly a debugging tool for bun itself.
196
+ *
197
+ * Warning: not all objects returned are supposed to be observable from JavaScript
198
+ */
199
+ function getProtectedObjects(): any[];
200
+
201
+ /**
202
+ * Start a remote debugging socket server on the given port.
203
+ *
204
+ * This exposes JavaScriptCore's built-in debugging server.
205
+ *
206
+ * This is untested. May not be supported yet on macOS
207
+ */
208
+ function startRemoteDebugger(host?: string, port?: number): void;
209
+
210
+ /**
211
+ * Run JavaScriptCore's sampling profiler
212
+ */
213
+ function startSamplingProfiler(optionalDirectory?: string): void;
214
+ }
package/overrides.d.ts ADDED
@@ -0,0 +1,64 @@
1
+ export {};
2
+
3
+ import type { Env, PathLike, BunFile } from "bun";
4
+
5
+ declare global {
6
+ namespace NodeJS {
7
+ interface ProcessVersions extends Dict<string> {
8
+ bun: string;
9
+ }
10
+ interface ProcessEnv extends Env {}
11
+ }
12
+ }
13
+
14
+ declare module "fs/promises" {
15
+ function exists(path: PathLike): Promise<boolean>;
16
+ }
17
+
18
+ declare module "tls" {
19
+ interface BunConnectionOptions extends Omit<ConnectionOptions, "key" | "ca" | "tls" | "cert"> {
20
+ /**
21
+ * Optionally override the trusted CA certificates. Default is to trust
22
+ * the well-known CAs curated by Mozilla. Mozilla's CAs are completely
23
+ * replaced when CAs are explicitly specified using this option.
24
+ */
25
+ ca?: string | Buffer | NodeJS.TypedArray | BunFile | Array<string | Buffer | BunFile> | undefined;
26
+ /**
27
+ * Cert chains in PEM format. One cert chain should be provided per
28
+ * private key. Each cert chain should consist of the PEM formatted
29
+ * certificate for a provided private key, followed by the PEM
30
+ * formatted intermediate certificates (if any), in order, and not
31
+ * including the root CA (the root CA must be pre-known to the peer,
32
+ * see ca). When providing multiple cert chains, they do not have to
33
+ * be in the same order as their private keys in key. If the
34
+ * intermediate certificates are not provided, the peer will not be
35
+ * able to validate the certificate, and the handshake will fail.
36
+ */
37
+ cert?:
38
+ | string
39
+ | Buffer
40
+ | NodeJS.TypedArray
41
+ | BunFile
42
+ | Array<string | Buffer | NodeJS.TypedArray | BunFile>
43
+ | undefined;
44
+ /**
45
+ * Private keys in PEM format. PEM allows the option of private keys
46
+ * being encrypted. Encrypted keys will be decrypted with
47
+ * options.passphrase. Multiple keys using different algorithms can be
48
+ * provided either as an array of unencrypted key strings or buffers,
49
+ * or an array of objects in the form {pem: <string|buffer>[,
50
+ * passphrase: <string>]}. The object form can only occur in an array.
51
+ * object.passphrase is optional. Encrypted keys will be decrypted with
52
+ * object.passphrase if provided, or options.passphrase if it is not.
53
+ */
54
+ key?:
55
+ | string
56
+ | Buffer
57
+ | BunFile
58
+ | NodeJS.TypedArray
59
+ | Array<string | Buffer | BunFile | NodeJS.TypedArray | KeyObject>
60
+ | undefined;
61
+ }
62
+
63
+ function connect(options: BunConnectionOptions, secureConnectListener?: () => void): TLSSocket;
64
+ }
package/package.json CHANGED
@@ -1,25 +1,38 @@
1
1
  {
2
+ "version": "1.0.26",
2
3
  "name": "bun-types",
3
- "version": "1.0.25",
4
4
  "license": "MIT",
5
+ "main": "",
6
+ "types": "index.d.ts",
5
7
  "description": "Type definitions for Bun, an incredibly fast JavaScript runtime",
6
- "types": "types.d.ts",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/oven-sh/bun",
11
+ "directory": "packages/bun-types"
12
+ },
7
13
  "files": [
8
- "types.d.ts",
9
- "README.md",
10
- "tsconfig.json"
14
+ "*.d.ts"
11
15
  ],
12
- "private": false,
16
+ "homepage": "https://bun.sh",
17
+ "dependencies": {
18
+ "@types/node": "~20.11.3",
19
+ "@types/ws": "~8.5.10"
20
+ },
21
+ "devDependencies": {
22
+ "@biomejs/biome": "^1.5.3",
23
+ "@definitelytyped/dtslint": "^0.0.199",
24
+ "@definitelytyped/eslint-plugin": "^0.0.197",
25
+ "typescript": "^5.0.2"
26
+ },
27
+ "scripts": {
28
+ "prebuild": "echo $(pwd)",
29
+ "build": "bun scripts/build.ts && bun run fmt",
30
+ "test": "tsc",
31
+ "fmt": "echo $(which biome) && biome format --write ."
32
+ },
13
33
  "keywords": [
14
34
  "bun",
15
35
  "bun.js",
16
36
  "types"
17
- ],
18
- "repository": "https://github.com/oven-sh/bun",
19
- "homepage": "https://bun.sh",
20
- "dependencies": {
21
- "@types/node": "*",
22
- "@types/ws": "*",
23
- "undici-types": "^5.26.4"
24
- }
25
- }
37
+ ]
38
+ }