bun-types 1.2.10-canary.20250413T140542 → 1.2.10-canary.20250415T140641

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/shell.d.ts ADDED
@@ -0,0 +1,355 @@
1
+ declare module "bun" {
2
+ type ShellFunction = (input: Uint8Array) => Uint8Array;
3
+
4
+ type ShellExpression =
5
+ | { toString(): string }
6
+ | Array<ShellExpression>
7
+ | string
8
+ | { raw: string }
9
+ | Subprocess
10
+ | SpawnOptions.Readable
11
+ | SpawnOptions.Writable
12
+ | ReadableStream;
13
+
14
+ /**
15
+ * The Bun shell
16
+ *
17
+ * @category Process Management
18
+ */
19
+ function $(strings: TemplateStringsArray, ...expressions: ShellExpression[]): $.ShellPromise;
20
+
21
+ namespace $ {
22
+ const Shell: new () => typeof $;
23
+
24
+ /**
25
+ * Perform bash-like brace expansion on the given pattern.
26
+ * @param pattern - Brace pattern to expand
27
+ *
28
+ * @example
29
+ * ```js
30
+ * const result = braces('index.{js,jsx,ts,tsx}');
31
+ * console.log(result) // ['index.js', 'index.jsx', 'index.ts', 'index.tsx']
32
+ * ```
33
+ */
34
+ function braces(pattern: string): string[];
35
+
36
+ /**
37
+ * Escape strings for input into shell commands.
38
+ * @param input
39
+ */
40
+ function escape(input: string): string;
41
+
42
+ /**
43
+ *
44
+ * Change the default environment variables for shells created by this instance.
45
+ *
46
+ * @param newEnv Default environment variables to use for shells created by this instance.
47
+ * @default process.env
48
+ *
49
+ * ## Example
50
+ *
51
+ * ```js
52
+ * import {$} from 'bun';
53
+ * $.env({ BUN: "bun" });
54
+ * await $`echo $BUN`;
55
+ * // "bun"
56
+ * ```
57
+ */
58
+ function env(newEnv?: Record<string, string | undefined>): typeof $;
59
+
60
+ /**
61
+ *
62
+ * @param newCwd Default working directory to use for shells created by this instance.
63
+ */
64
+ function cwd(newCwd?: string): typeof $;
65
+
66
+ /**
67
+ * Configure the shell to not throw an exception on non-zero exit codes.
68
+ */
69
+ function nothrow(): typeof $;
70
+
71
+ /**
72
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
73
+ */
74
+ function throws(shouldThrow: boolean): typeof $;
75
+
76
+ class ShellPromise extends Promise<ShellOutput> {
77
+ get stdin(): WritableStream;
78
+
79
+ /**
80
+ * Change the current working directory of the shell.
81
+ * @param newCwd - The new working directory
82
+ */
83
+ cwd(newCwd: string): this;
84
+ /**
85
+ * Set environment variables for the shell.
86
+ * @param newEnv - The new environment variables
87
+ *
88
+ * @example
89
+ * ```ts
90
+ * await $`echo $FOO`.env({ ...process.env, FOO: "LOL!" })
91
+ * expect(stdout.toString()).toBe("LOL!");
92
+ * ```
93
+ */
94
+ env(newEnv: Record<string, string> | undefined): this;
95
+ /**
96
+ * By default, the shell will write to the current process's stdout and stderr, as well as buffering that output.
97
+ *
98
+ * This configures the shell to only buffer the output.
99
+ */
100
+ quiet(): this;
101
+
102
+ /**
103
+ * Read from stdout as a string, line by line
104
+ *
105
+ * Automatically calls {@link quiet} to disable echoing to stdout.
106
+ */
107
+ lines(): AsyncIterable<string>;
108
+
109
+ /**
110
+ * Read from stdout as a string
111
+ *
112
+ * Automatically calls {@link quiet} to disable echoing to stdout.
113
+ * @param encoding - The encoding to use when decoding the output
114
+ * @returns A promise that resolves with stdout as a string
115
+ * @example
116
+ *
117
+ * ## Read as UTF-8 string
118
+ *
119
+ * ```ts
120
+ * const output = await $`echo hello`.text();
121
+ * console.log(output); // "hello\n"
122
+ * ```
123
+ *
124
+ * ## Read as base64 string
125
+ *
126
+ * ```ts
127
+ * const output = await $`echo ${atob("hello")}`.text("base64");
128
+ * console.log(output); // "hello\n"
129
+ * ```
130
+ *
131
+ */
132
+ text(encoding?: BufferEncoding): Promise<string>;
133
+
134
+ /**
135
+ * Read from stdout as a JSON object
136
+ *
137
+ * Automatically calls {@link quiet}
138
+ *
139
+ * @returns A promise that resolves with stdout as a JSON object
140
+ * @example
141
+ *
142
+ * ```ts
143
+ * const output = await $`echo '{"hello": 123}'`.json();
144
+ * console.log(output); // { hello: 123 }
145
+ * ```
146
+ *
147
+ */
148
+ json(): Promise<any>;
149
+
150
+ /**
151
+ * Read from stdout as an ArrayBuffer
152
+ *
153
+ * Automatically calls {@link quiet}
154
+ * @returns A promise that resolves with stdout as an ArrayBuffer
155
+ * @example
156
+ *
157
+ * ```ts
158
+ * const output = await $`echo hello`.arrayBuffer();
159
+ * console.log(output); // ArrayBuffer { byteLength: 6 }
160
+ * ```
161
+ */
162
+ arrayBuffer(): Promise<ArrayBuffer>;
163
+
164
+ /**
165
+ * Read from stdout as a Blob
166
+ *
167
+ * Automatically calls {@link quiet}
168
+ * @returns A promise that resolves with stdout as a Blob
169
+ * @example
170
+ * ```ts
171
+ * const output = await $`echo hello`.blob();
172
+ * console.log(output); // Blob { size: 6, type: "" }
173
+ * ```
174
+ */
175
+ blob(): Promise<Blob>;
176
+
177
+ /**
178
+ * Configure the shell to not throw an exception on non-zero exit codes. Throwing can be re-enabled with `.throws(true)`.
179
+ *
180
+ * By default, the shell with throw an exception on commands which return non-zero exit codes.
181
+ */
182
+ nothrow(): this;
183
+
184
+ /**
185
+ * Configure whether or not the shell should throw an exception on non-zero exit codes.
186
+ *
187
+ * By default, this is configured to `true`.
188
+ */
189
+ throws(shouldThrow: boolean): this;
190
+ }
191
+
192
+ class ShellError extends Error implements ShellOutput {
193
+ readonly stdout: Buffer;
194
+ readonly stderr: Buffer;
195
+ readonly exitCode: number;
196
+
197
+ /**
198
+ * Read from stdout as a string
199
+ *
200
+ * @param encoding - The encoding to use when decoding the output
201
+ * @returns Stdout as a string with the given encoding
202
+ * @example
203
+ *
204
+ * ## Read as UTF-8 string
205
+ *
206
+ * ```ts
207
+ * const output = await $`echo hello`;
208
+ * console.log(output.text()); // "hello\n"
209
+ * ```
210
+ *
211
+ * ## Read as base64 string
212
+ *
213
+ * ```ts
214
+ * const output = await $`echo ${atob("hello")}`;
215
+ * console.log(output.text("base64")); // "hello\n"
216
+ * ```
217
+ *
218
+ */
219
+ text(encoding?: BufferEncoding): string;
220
+
221
+ /**
222
+ * Read from stdout as a JSON object
223
+ *
224
+ * @returns Stdout as a JSON object
225
+ * @example
226
+ *
227
+ * ```ts
228
+ * const output = await $`echo '{"hello": 123}'`;
229
+ * console.log(output.json()); // { hello: 123 }
230
+ * ```
231
+ *
232
+ */
233
+ json(): any;
234
+
235
+ /**
236
+ * Read from stdout as an ArrayBuffer
237
+ *
238
+ * @returns Stdout as an ArrayBuffer
239
+ * @example
240
+ *
241
+ * ```ts
242
+ * const output = await $`echo hello`;
243
+ * console.log(output.arrayBuffer()); // ArrayBuffer { byteLength: 6 }
244
+ * ```
245
+ */
246
+ arrayBuffer(): ArrayBuffer;
247
+
248
+ /**
249
+ * Read from stdout as a Blob
250
+ *
251
+ * @returns Stdout as a blob
252
+ * @example
253
+ * ```ts
254
+ * const output = await $`echo hello`;
255
+ * console.log(output.blob()); // Blob { size: 6, type: "" }
256
+ * ```
257
+ */
258
+ blob(): Blob;
259
+
260
+ /**
261
+ * Read from stdout as an Uint8Array
262
+ *
263
+ * @returns Stdout as an Uint8Array
264
+ * @example
265
+ *```ts
266
+ * const output = await $`echo hello`;
267
+ * console.log(output.bytes()); // Uint8Array { byteLength: 6 }
268
+ * ```
269
+ */
270
+ bytes(): Uint8Array;
271
+ }
272
+
273
+ interface ShellOutput {
274
+ readonly stdout: Buffer;
275
+ readonly stderr: Buffer;
276
+ readonly exitCode: number;
277
+
278
+ /**
279
+ * Read from stdout as a string
280
+ *
281
+ * @param encoding - The encoding to use when decoding the output
282
+ * @returns Stdout as a string with the given encoding
283
+ * @example
284
+ *
285
+ * ## Read as UTF-8 string
286
+ *
287
+ * ```ts
288
+ * const output = await $`echo hello`;
289
+ * console.log(output.text()); // "hello\n"
290
+ * ```
291
+ *
292
+ * ## Read as base64 string
293
+ *
294
+ * ```ts
295
+ * const output = await $`echo ${atob("hello")}`;
296
+ * console.log(output.text("base64")); // "hello\n"
297
+ * ```
298
+ *
299
+ */
300
+ text(encoding?: BufferEncoding): string;
301
+
302
+ /**
303
+ * Read from stdout as a JSON object
304
+ *
305
+ * @returns Stdout as a JSON object
306
+ * @example
307
+ *
308
+ * ```ts
309
+ * const output = await $`echo '{"hello": 123}'`;
310
+ * console.log(output.json()); // { hello: 123 }
311
+ * ```
312
+ *
313
+ */
314
+ json(): any;
315
+
316
+ /**
317
+ * Read from stdout as an ArrayBuffer
318
+ *
319
+ * @returns Stdout as an ArrayBuffer
320
+ * @example
321
+ *
322
+ * ```ts
323
+ * const output = await $`echo hello`;
324
+ * console.log(output.arrayBuffer()); // ArrayBuffer { byteLength: 6 }
325
+ * ```
326
+ */
327
+ arrayBuffer(): ArrayBuffer;
328
+
329
+ /**
330
+ * Read from stdout as an Uint8Array
331
+ *
332
+ * @returns Stdout as an Uint8Array
333
+ * @example
334
+ *
335
+ * ```ts
336
+ * const output = await $`echo hello`;
337
+ * console.log(output.bytes()); // Uint8Array { byteLength: 6 }
338
+ * ```
339
+ */
340
+ bytes(): Uint8Array;
341
+
342
+ /**
343
+ * Read from stdout as a Blob
344
+ *
345
+ * @returns Stdout as a blob
346
+ * @example
347
+ * ```ts
348
+ * const output = await $`echo hello`;
349
+ * console.log(output.blob()); // Blob { size: 6, type: "" }
350
+ * ```
351
+ */
352
+ blob(): Blob;
353
+ }
354
+ }
355
+ }
package/sqlite.d.ts CHANGED
@@ -13,15 +13,15 @@
13
13
  *
14
14
  * The following types can be used when binding parameters:
15
15
  *
16
- * | JavaScript type | SQLite type |
17
- * | -------------- | ----------- |
18
- * | `string` | `TEXT` |
19
- * | `number` | `INTEGER` or `DECIMAL` |
20
- * | `boolean` | `INTEGER` (1 or 0) |
21
- * | `Uint8Array` | `BLOB` |
22
- * | `Buffer` | `BLOB` |
23
- * | `bigint` | `INTEGER` |
24
- * | `null` | `NULL` |
16
+ * | JavaScript type | SQLite type |
17
+ * | --------------- | ---------------------- |
18
+ * | `string` | `TEXT` |
19
+ * | `number` | `INTEGER` or `DECIMAL` |
20
+ * | `boolean` | `INTEGER` (1 or 0) |
21
+ * | `Uint8Array` | `BLOB` |
22
+ * | `Buffer` | `BLOB` |
23
+ * | `bigint` | `INTEGER` |
24
+ * | `null` | `NULL` |
25
25
  */
26
26
  declare module "bun:sqlite" {
27
27
  /**
@@ -159,6 +159,20 @@ declare module "bun:sqlite" {
159
159
  *
160
160
  * This does not cache the query, so if you want to run a query multiple times, you should use {@link prepare} instead.
161
161
  *
162
+ * Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
163
+ *
164
+ * The following types can be used when binding parameters:
165
+ *
166
+ * | JavaScript type | SQLite type |
167
+ * | --------------- | ---------------------- |
168
+ * | `string` | `TEXT` |
169
+ * | `number` | `INTEGER` or `DECIMAL` |
170
+ * | `boolean` | `INTEGER` (1 or 0) |
171
+ * | `Uint8Array` | `BLOB` |
172
+ * | `Buffer` | `BLOB` |
173
+ * | `bigint` | `INTEGER` |
174
+ * | `null` | `NULL` |
175
+ *
162
176
  * @example
163
177
  * ```ts
164
178
  * db.run("CREATE TABLE foo (bar TEXT)");
@@ -184,30 +198,15 @@ declare module "bun:sqlite" {
184
198
  * - `CREATE TEMPORARY TABLE`
185
199
  *
186
200
  * @param sql The SQL query to run
187
- *
188
201
  * @param bindings Optional bindings for the query
189
202
  *
190
203
  * @returns `Database` instance
191
- *
192
- * Under the hood, this calls `sqlite3_prepare_v3` followed by `sqlite3_step` and `sqlite3_finalize`.
193
- *
194
- * * The following types can be used when binding parameters:
195
- *
196
- * | JavaScript type | SQLite type |
197
- * | -------------- | ----------- |
198
- * | `string` | `TEXT` |
199
- * | `number` | `INTEGER` or `DECIMAL` |
200
- * | `boolean` | `INTEGER` (1 or 0) |
201
- * | `Uint8Array` | `BLOB` |
202
- * | `Buffer` | `BLOB` |
203
- * | `bigint` | `INTEGER` |
204
- * | `null` | `NULL` |
205
204
  */
206
- run<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): Changes;
205
+ run<ParamsType extends SQLQueryBindings[]>(sql: string, ...bindings: ParamsType[]): Changes;
207
206
  /**
208
- This is an alias of {@link Database.prototype.run}
207
+ * This is an alias of {@link Database.run}
209
208
  */
210
- exec<ParamsType extends SQLQueryBindings[]>(sqlQuery: string, ...bindings: ParamsType[]): Changes;
209
+ exec<ParamsType extends SQLQueryBindings[]>(sql: string, ...bindings: ParamsType[]): Changes;
211
210
 
212
211
  /**
213
212
  * Compile a SQL query and return a {@link Statement} object. This is the
@@ -216,6 +215,8 @@ declare module "bun:sqlite" {
216
215
  * This **does not execute** the query, but instead prepares it for later
217
216
  * execution and caches the compiled query if possible.
218
217
  *
218
+ * Under the hood, this calls `sqlite3_prepare_v3`.
219
+ *
219
220
  * @example
220
221
  * ```ts
221
222
  * // compile the query
@@ -228,21 +229,19 @@ declare module "bun:sqlite" {
228
229
  * ```
229
230
  *
230
231
  * @param sql The SQL query to compile
231
- *
232
232
  * @returns `Statment` instance
233
- *
234
- * Under the hood, this calls `sqlite3_prepare_v3`.
235
233
  */
236
234
  query<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
237
- sqlQuery: string,
238
- ): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
239
- Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
235
+ sql: string,
236
+ ): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
240
237
 
241
238
  /**
242
239
  * Compile a SQL query and return a {@link Statement} object.
243
240
  *
244
241
  * This does not cache the compiled query and does not execute the query.
245
242
  *
243
+ * Under the hood, this calls `sqlite3_prepare_v3`.
244
+ *
246
245
  * @example
247
246
  * ```ts
248
247
  * // compile the query
@@ -254,15 +253,12 @@ declare module "bun:sqlite" {
254
253
  * @param sql The SQL query to compile
255
254
  * @param params Optional bindings for the query
256
255
  *
257
- * @returns `Statment` instance
258
- *
259
- * Under the hood, this calls `sqlite3_prepare_v3`.
256
+ * @returns A {@link Statement} instance
260
257
  */
261
258
  prepare<ReturnType, ParamsType extends SQLQueryBindings | SQLQueryBindings[]>(
262
- sqlQuery: string,
259
+ sql: string,
263
260
  params?: ParamsType,
264
- ): // eslint-disable-next-line @definitelytyped/no-single-element-tuple-type
265
- Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
261
+ ): Statement<ReturnType, ParamsType extends any[] ? ParamsType : [ParamsType]>;
266
262
 
267
263
  /**
268
264
  * Is the database in a transaction?
@@ -646,15 +642,15 @@ declare module "bun:sqlite" {
646
642
  *
647
643
  * The following types can be used when binding parameters:
648
644
  *
649
- * | JavaScript type | SQLite type |
650
- * | -------------- | ----------- |
651
- * | `string` | `TEXT` |
652
- * | `number` | `INTEGER` or `DECIMAL` |
653
- * | `boolean` | `INTEGER` (1 or 0) |
654
- * | `Uint8Array` | `BLOB` |
655
- * | `Buffer` | `BLOB` |
656
- * | `bigint` | `INTEGER` |
657
- * | `null` | `NULL` |
645
+ * | JavaScript type | SQLite type |
646
+ * | --------------- | ---------------------- |
647
+ * | `string` | `TEXT` |
648
+ * | `number` | `INTEGER` or `DECIMAL` |
649
+ * | `boolean` | `INTEGER` (1 or 0) |
650
+ * | `Uint8Array` | `BLOB` |
651
+ * | `Buffer` | `BLOB` |
652
+ * | `bigint` | `INTEGER` |
653
+ * | `null` | `NULL` |
658
654
  */
659
655
  get(...params: ParamsType): ReturnType | null;
660
656
 
@@ -687,15 +683,15 @@ declare module "bun:sqlite" {
687
683
  *
688
684
  * The following types can be used when binding parameters:
689
685
  *
690
- * | JavaScript type | SQLite type |
691
- * | -------------- | ----------- |
692
- * | `string` | `TEXT` |
693
- * | `number` | `INTEGER` or `DECIMAL` |
694
- * | `boolean` | `INTEGER` (1 or 0) |
695
- * | `Uint8Array` | `BLOB` |
696
- * | `Buffer` | `BLOB` |
697
- * | `bigint` | `INTEGER` |
698
- * | `null` | `NULL` |
686
+ * | JavaScript type | SQLite type |
687
+ * | --------------- | ---------------------- |
688
+ * | `string` | `TEXT` |
689
+ * | `number` | `INTEGER` or `DECIMAL` |
690
+ * | `boolean` | `INTEGER` (1 or 0) |
691
+ * | `Uint8Array` | `BLOB` |
692
+ * | `Buffer` | `BLOB` |
693
+ * | `bigint` | `INTEGER` |
694
+ * | `null` | `NULL` |
699
695
  */
700
696
  run(...params: ParamsType): Changes;
701
697
 
@@ -727,15 +723,15 @@ declare module "bun:sqlite" {
727
723
  *
728
724
  * The following types can be used when binding parameters:
729
725
  *
730
- * | JavaScript type | SQLite type |
731
- * | ---------------|-------------|
732
- * | `string` | `TEXT` |
733
- * | `number` | `INTEGER` or `DECIMAL` |
734
- * | `boolean` | `INTEGER` (1 or 0) |
735
- * | `Uint8Array` | `BLOB` |
736
- * | `Buffer` | `BLOB` |
737
- * | `bigint` | `INTEGER` |
738
- * | `null` | `NULL` |
726
+ * | JavaScript type | SQLite type |
727
+ * | --------------- | ---------------------- |
728
+ * | `string` | `TEXT` |
729
+ * | `number` | `INTEGER` or `DECIMAL` |
730
+ * | `boolean` | `INTEGER` (1 or 0) |
731
+ * | `Uint8Array` | `BLOB` |
732
+ * | `Buffer` | `BLOB` |
733
+ * | `bigint` | `INTEGER` |
734
+ * | `null` | `NULL` |
739
735
  */
740
736
  values(...params: ParamsType): Array<Array<string | bigint | number | boolean | Uint8Array>>;
741
737
 
package/test.d.ts CHANGED
@@ -426,8 +426,13 @@ declare module "bun:test" {
426
426
  *
427
427
  * @param label the label for the test
428
428
  * @param fn the test function
429
+ * @param options the test timeout or options
429
430
  */
430
- failing(label: string, fn?: (() => void | Promise<unknown>) | ((done: (err?: unknown) => void) => void)): void;
431
+ failing(
432
+ label: string,
433
+ fn?: (() => void | Promise<unknown>) | ((done: (err?: unknown) => void) => void),
434
+ options?: number | TestOptions,
435
+ ): void;
431
436
  /**
432
437
  * Runs this test, if `condition` is true.
433
438
  *