bun-types 1.1.45-canary.20250118T140543 → 1.1.45-canary.20250120T140547
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/bun.d.ts +294 -0
- package/docs/api/fetch.md +1 -1
- package/docs/api/spawn.md +1 -1
- package/docs/cli/publish.md +1 -1
- package/docs/runtime/debugger.md +3 -3
- package/docs/test/dom.md +1 -1
- package/package.json +1 -1
package/bun.d.ts
CHANGED
|
@@ -2037,6 +2037,300 @@ declare module "bun" {
|
|
|
2037
2037
|
*/
|
|
2038
2038
|
stat(path: string, options?: S3Options): Promise<S3Stats>;
|
|
2039
2039
|
};
|
|
2040
|
+
/**
|
|
2041
|
+
* Configuration options for SQL client connection and behavior
|
|
2042
|
+
* @example
|
|
2043
|
+
* const config: SQLOptions = {
|
|
2044
|
+
* host: 'localhost',
|
|
2045
|
+
* port: 5432,
|
|
2046
|
+
* user: 'dbuser',
|
|
2047
|
+
* password: 'secretpass',
|
|
2048
|
+
* database: 'myapp',
|
|
2049
|
+
* idleTimeout: 30000,
|
|
2050
|
+
* max: 20,
|
|
2051
|
+
* onconnect: (client) => {
|
|
2052
|
+
* console.log('Connected to database');
|
|
2053
|
+
* }
|
|
2054
|
+
* };
|
|
2055
|
+
*/
|
|
2056
|
+
type SQLOptions = {
|
|
2057
|
+
/** Connection URL (can be string or URL object) */
|
|
2058
|
+
url: URL | string;
|
|
2059
|
+
/** Database server hostname */
|
|
2060
|
+
host: string;
|
|
2061
|
+
/** Database server port number */
|
|
2062
|
+
port: number | string;
|
|
2063
|
+
/** Database user for authentication */
|
|
2064
|
+
user: string;
|
|
2065
|
+
/** Database password for authentication */
|
|
2066
|
+
password: string;
|
|
2067
|
+
/** Name of the database to connect to */
|
|
2068
|
+
database: string;
|
|
2069
|
+
/** Database adapter/driver to use */
|
|
2070
|
+
adapter: string;
|
|
2071
|
+
/** Maximum time in milliseconds to wait for connection to become available */
|
|
2072
|
+
idleTimeout: number;
|
|
2073
|
+
/** Maximum time in milliseconds to wait when establishing a connection */
|
|
2074
|
+
connectionTimeout: number;
|
|
2075
|
+
/** Maximum lifetime in milliseconds of a connection */
|
|
2076
|
+
maxLifetime: number;
|
|
2077
|
+
/** Whether to use TLS/SSL for the connection */
|
|
2078
|
+
tls: boolean;
|
|
2079
|
+
/** Callback function executed when a connection is established */
|
|
2080
|
+
onconnect: (client: SQL) => void;
|
|
2081
|
+
/** Callback function executed when a connection is closed */
|
|
2082
|
+
onclose: (client: SQL) => void;
|
|
2083
|
+
/** Maximum number of connections in the pool */
|
|
2084
|
+
max: number;
|
|
2085
|
+
};
|
|
2086
|
+
|
|
2087
|
+
/**
|
|
2088
|
+
* Represents a SQL query that can be executed, with additional control methods
|
|
2089
|
+
* Extends Promise to allow for async/await usage
|
|
2090
|
+
*/
|
|
2091
|
+
interface SQLQuery extends Promise<any> {
|
|
2092
|
+
/** Indicates if the query is currently executing */
|
|
2093
|
+
active: boolean;
|
|
2094
|
+
/** Indicates if the query has been cancelled */
|
|
2095
|
+
cancelled: boolean;
|
|
2096
|
+
/** Cancels the executing query */
|
|
2097
|
+
cancel(): SQLQuery;
|
|
2098
|
+
/** Executes the query */
|
|
2099
|
+
execute(): SQLQuery;
|
|
2100
|
+
/** Returns the raw query result */
|
|
2101
|
+
raw(): SQLQuery;
|
|
2102
|
+
/** Returns only the values from the query result */
|
|
2103
|
+
values(): SQLQuery;
|
|
2104
|
+
}
|
|
2105
|
+
|
|
2106
|
+
/**
|
|
2107
|
+
* Callback function type for transaction contexts
|
|
2108
|
+
* @param sql Function to execute SQL queries within the transaction
|
|
2109
|
+
*/
|
|
2110
|
+
type SQLContextCallback = (
|
|
2111
|
+
sql: (strings: string, ...values: any[]) => SQLQuery | Array<SQLQuery>,
|
|
2112
|
+
) => Promise<any>;
|
|
2113
|
+
|
|
2114
|
+
/**
|
|
2115
|
+
* Main SQL client interface providing connection and transaction management
|
|
2116
|
+
*/
|
|
2117
|
+
interface SQL {
|
|
2118
|
+
/** Creates a new SQL client instance
|
|
2119
|
+
* @example
|
|
2120
|
+
* const sql = new SQL("postgres://localhost:5432/mydb");
|
|
2121
|
+
* const sql = new SQL(new URL("postgres://localhost:5432/mydb"));
|
|
2122
|
+
*/
|
|
2123
|
+
new (connectionString: string | URL): SQL;
|
|
2124
|
+
/** Creates a new SQL client instance with options
|
|
2125
|
+
* @example
|
|
2126
|
+
* const sql = new SQL("postgres://localhost:5432/mydb", { idleTimeout: 1000 });
|
|
2127
|
+
*/
|
|
2128
|
+
new (connectionString: string | URL, options: SQLOptions): SQL;
|
|
2129
|
+
/** Creates a new SQL client instance with options
|
|
2130
|
+
* @example
|
|
2131
|
+
* const sql = new SQL({ url: "postgres://localhost:5432/mydb", idleTimeout: 1000 });
|
|
2132
|
+
*/
|
|
2133
|
+
new (options?: SQLOptions): SQL;
|
|
2134
|
+
/** Executes a SQL query using template literals
|
|
2135
|
+
* @example
|
|
2136
|
+
* const [user] = await sql`select * from users where id = ${1}`;
|
|
2137
|
+
*/
|
|
2138
|
+
(strings: string, ...values: any[]): SQLQuery;
|
|
2139
|
+
/** Commits a distributed transaction also know as prepared transaction in postgres or XA transaction in MySQL
|
|
2140
|
+
* @example
|
|
2141
|
+
* await sql.commitDistributed("my_distributed_transaction");
|
|
2142
|
+
*/
|
|
2143
|
+
commitDistributed(name: string): Promise<undefined>;
|
|
2144
|
+
/** Rolls back a distributed transaction also know as prepared transaction in postgres or XA transaction in MySQL
|
|
2145
|
+
* @example
|
|
2146
|
+
* await sql.rollbackDistributed("my_distributed_transaction");
|
|
2147
|
+
*/
|
|
2148
|
+
rollbackDistributed(name: string): Promise<undefined>;
|
|
2149
|
+
/** Waits for the database connection to be established
|
|
2150
|
+
* @example
|
|
2151
|
+
* await sql.connect();
|
|
2152
|
+
*/
|
|
2153
|
+
connect(): Promise<SQL>;
|
|
2154
|
+
/** Closes the database connection with optional timeout in seconds
|
|
2155
|
+
* @example
|
|
2156
|
+
* await sql.close({ timeout: 1 });
|
|
2157
|
+
*/
|
|
2158
|
+
close(options?: { timeout?: number }): Promise<undefined>;
|
|
2159
|
+
/** Closes the database connection with optional timeout in seconds
|
|
2160
|
+
* @alias close
|
|
2161
|
+
* @example
|
|
2162
|
+
* await sql.end({ timeout: 1 });
|
|
2163
|
+
*/
|
|
2164
|
+
end(options?: { timeout?: number }): Promise<undefined>;
|
|
2165
|
+
/** Flushes any pending operations */
|
|
2166
|
+
flush(): void;
|
|
2167
|
+
/** The reserve method pulls out a connection from the pool, and returns a client that wraps the single connection.
|
|
2168
|
+
* This can be used for running queries on an isolated connection.
|
|
2169
|
+
* Calling reserve in a reserved Sql will return a new reserved connection, not the same connection (behavior matches postgres package).
|
|
2170
|
+
* @example
|
|
2171
|
+
* const reserved = await sql.reserve();
|
|
2172
|
+
* await reserved`select * from users`;
|
|
2173
|
+
* await reserved.release();
|
|
2174
|
+
* // with in a production scenario would be something more like
|
|
2175
|
+
* const reserved = await sql.reserve();
|
|
2176
|
+
* try {
|
|
2177
|
+
* // ... queries
|
|
2178
|
+
* } finally {
|
|
2179
|
+
* await reserved.release();
|
|
2180
|
+
* }
|
|
2181
|
+
* //To make it simpler bun supportsSymbol.dispose and Symbol.asyncDispose
|
|
2182
|
+
* {
|
|
2183
|
+
* // always release after context (safer)
|
|
2184
|
+
* using reserved = await sql.reserve()
|
|
2185
|
+
* await reserved`select * from users`
|
|
2186
|
+
* }
|
|
2187
|
+
*/
|
|
2188
|
+
reserve(): Promise<ReservedSQL>;
|
|
2189
|
+
/** Begins a new transaction
|
|
2190
|
+
* Will reserve a connection for the transaction and supply a scoped sql instance for all transaction uses in the callback function. sql.begin will resolve with the returned value from the callback function.
|
|
2191
|
+
* BEGIN is automatically sent with the optional options, and if anything fails ROLLBACK will be called so the connection can be released and execution can continue.
|
|
2192
|
+
* @example
|
|
2193
|
+
* const [user, account] = await sql.begin(async sql => {
|
|
2194
|
+
* const [user] = await sql`
|
|
2195
|
+
* insert into users (
|
|
2196
|
+
* name
|
|
2197
|
+
* ) values (
|
|
2198
|
+
* 'Murray'
|
|
2199
|
+
* )
|
|
2200
|
+
* returning *
|
|
2201
|
+
* `
|
|
2202
|
+
* const [account] = await sql`
|
|
2203
|
+
* insert into accounts (
|
|
2204
|
+
* user_id
|
|
2205
|
+
* ) values (
|
|
2206
|
+
* ${ user.user_id }
|
|
2207
|
+
* )
|
|
2208
|
+
* returning *
|
|
2209
|
+
* `
|
|
2210
|
+
* return [user, account]
|
|
2211
|
+
* })
|
|
2212
|
+
*/
|
|
2213
|
+
begin(fn: SQLContextCallback): Promise<any>;
|
|
2214
|
+
/** Begins a new transaction with options
|
|
2215
|
+
* Will reserve a connection for the transaction and supply a scoped sql instance for all transaction uses in the callback function. sql.begin will resolve with the returned value from the callback function.
|
|
2216
|
+
* BEGIN is automatically sent with the optional options, and if anything fails ROLLBACK will be called so the connection can be released and execution can continue.
|
|
2217
|
+
* @example
|
|
2218
|
+
* const [user, account] = await sql.begin("read write", async sql => {
|
|
2219
|
+
* const [user] = await sql`
|
|
2220
|
+
* insert into users (
|
|
2221
|
+
* name
|
|
2222
|
+
* ) values (
|
|
2223
|
+
* 'Murray'
|
|
2224
|
+
* )
|
|
2225
|
+
* returning *
|
|
2226
|
+
* `
|
|
2227
|
+
* const [account] = await sql`
|
|
2228
|
+
* insert into accounts (
|
|
2229
|
+
* user_id
|
|
2230
|
+
* ) values (
|
|
2231
|
+
* ${ user.user_id }
|
|
2232
|
+
* )
|
|
2233
|
+
* returning *
|
|
2234
|
+
* `
|
|
2235
|
+
* return [user, account]
|
|
2236
|
+
* })
|
|
2237
|
+
*/
|
|
2238
|
+
begin(options: string, fn: SQLContextCallback): Promise<any>;
|
|
2239
|
+
/** Alternative method to begin a transaction
|
|
2240
|
+
* Will reserve a connection for the transaction and supply a scoped sql instance for all transaction uses in the callback function. sql.transaction will resolve with the returned value from the callback function.
|
|
2241
|
+
* BEGIN is automatically sent with the optional options, and if anything fails ROLLBACK will be called so the connection can be released and execution can continue.
|
|
2242
|
+
* @alias begin
|
|
2243
|
+
* @example
|
|
2244
|
+
* const [user, account] = await sql.transaction(async sql => {
|
|
2245
|
+
* const [user] = await sql`
|
|
2246
|
+
* insert into users (
|
|
2247
|
+
* name
|
|
2248
|
+
* ) values (
|
|
2249
|
+
* 'Murray'
|
|
2250
|
+
* )
|
|
2251
|
+
* returning *
|
|
2252
|
+
* `
|
|
2253
|
+
* const [account] = await sql`
|
|
2254
|
+
* insert into accounts (
|
|
2255
|
+
* user_id
|
|
2256
|
+
* ) values (
|
|
2257
|
+
* ${ user.user_id }
|
|
2258
|
+
* )
|
|
2259
|
+
* returning *
|
|
2260
|
+
* `
|
|
2261
|
+
* return [user, account]
|
|
2262
|
+
* })
|
|
2263
|
+
*/
|
|
2264
|
+
transaction(fn: SQLContextCallback): Promise<any>;
|
|
2265
|
+
/** Alternative method to begin a transaction with options
|
|
2266
|
+
* Will reserve a connection for the transaction and supply a scoped sql instance for all transaction uses in the callback function. sql.transaction will resolve with the returned value from the callback function.
|
|
2267
|
+
* BEGIN is automatically sent with the optional options, and if anything fails ROLLBACK will be called so the connection can be released and execution can continue.
|
|
2268
|
+
* @alias begin
|
|
2269
|
+
* @example
|
|
2270
|
+
* const [user, account] = await sql.transaction("read write", async sql => {
|
|
2271
|
+
* const [user] = await sql`
|
|
2272
|
+
* insert into users (
|
|
2273
|
+
* name
|
|
2274
|
+
* ) values (
|
|
2275
|
+
* 'Murray'
|
|
2276
|
+
* )
|
|
2277
|
+
* returning *
|
|
2278
|
+
* `
|
|
2279
|
+
* const [account] = await sql`
|
|
2280
|
+
* insert into accounts (
|
|
2281
|
+
* user_id
|
|
2282
|
+
* ) values (
|
|
2283
|
+
* ${ user.user_id }
|
|
2284
|
+
* )
|
|
2285
|
+
* returning *
|
|
2286
|
+
* `
|
|
2287
|
+
* return [user, account]
|
|
2288
|
+
* })
|
|
2289
|
+
*/
|
|
2290
|
+
transaction(options: string, fn: SQLContextCallback): Promise<any>;
|
|
2291
|
+
/** Begins a distributed transaction
|
|
2292
|
+
* Also know as Two-Phase Commit, in a distributed transaction, Phase 1 involves the coordinator preparing nodes by ensuring data is written and ready to commit, while Phase 2 finalizes with nodes committing or rolling back based on the coordinator's decision, ensuring durability and releasing locks.
|
|
2293
|
+
* In PostgreSQL and MySQL distributed transactions persist beyond the original session, allowing privileged users or coordinators to commit/rollback them, ensuring support for distributed transactions, recovery, and administrative tasks.
|
|
2294
|
+
* beginDistributed will automatic rollback if any exception are not caught, and you can commit and rollback later if everything goes well.
|
|
2295
|
+
* PostgreSQL natively supports distributed transactions using PREPARE TRANSACTION, while MySQL uses XA Transactions, and MSSQL also supports distributed/XA transactions. However, in MSSQL, distributed transactions are tied to the original session, the DTC coordinator, and the specific connection.
|
|
2296
|
+
* These transactions are automatically committed or rolled back following the same rules as regular transactions, with no option for manual intervention from other sessions, in MSSQL distributed transactions are used to coordinate transactions using Linked Servers.
|
|
2297
|
+
* @example
|
|
2298
|
+
* await sql.beginDistributed("numbers", async sql => {
|
|
2299
|
+
* await sql`create table if not exists numbers (a int)`;
|
|
2300
|
+
* await sql`insert into numbers values(1)`;
|
|
2301
|
+
* });
|
|
2302
|
+
* // later you can call
|
|
2303
|
+
* await sql.commitDistributed("numbers");
|
|
2304
|
+
* // or await sql.rollbackDistributed("numbers");
|
|
2305
|
+
*/
|
|
2306
|
+
beginDistributed(name: string, fn: SQLContextCallback): Promise<any>;
|
|
2307
|
+
/** Alternative method to begin a distributed transaction
|
|
2308
|
+
* @alias beginDistributed
|
|
2309
|
+
*/
|
|
2310
|
+
distributed(name: string, fn: SQLContextCallback): Promise<any>;
|
|
2311
|
+
/** Current client options */
|
|
2312
|
+
options: SQLOptions;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* Represents a reserved connection from the connection pool
|
|
2317
|
+
* Extends SQL with additional release functionality
|
|
2318
|
+
*/
|
|
2319
|
+
interface ReservedSQL extends SQL {
|
|
2320
|
+
/** Releases the client back to the connection pool */
|
|
2321
|
+
release(): void;
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
/**
|
|
2325
|
+
* Represents a client within a transaction context
|
|
2326
|
+
* Extends SQL with savepoint functionality
|
|
2327
|
+
*/
|
|
2328
|
+
interface TransactionSQL extends SQL {
|
|
2329
|
+
/** Creates a savepoint within the current transaction */
|
|
2330
|
+
savepoint(name: string, fn: SQLContextCallback): Promise<undefined>;
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
var sql: SQL;
|
|
2040
2334
|
|
|
2041
2335
|
/**
|
|
2042
2336
|
* This lets you use macros as regular imports
|
package/docs/api/fetch.md
CHANGED
|
@@ -195,7 +195,7 @@ This will print the request and response headers to your terminal:
|
|
|
195
195
|
```sh
|
|
196
196
|
[fetch] > HTTP/1.1 GET http://example.com/
|
|
197
197
|
[fetch] > Connection: keep-alive
|
|
198
|
-
[fetch] > User-Agent: Bun/1.1.45-canary.
|
|
198
|
+
[fetch] > User-Agent: Bun/1.1.45-canary.20250120T140547
|
|
199
199
|
[fetch] > Accept: */*
|
|
200
200
|
[fetch] > Host: example.com
|
|
201
201
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/api/spawn.md
CHANGED
|
@@ -110,7 +110,7 @@ You can read results from the subprocess via the `stdout` and `stderr` propertie
|
|
|
110
110
|
```ts
|
|
111
111
|
const proc = Bun.spawn(["bun", "--version"]);
|
|
112
112
|
const text = await new Response(proc.stdout).text();
|
|
113
|
-
console.log(text); // => "1.1.45-canary.
|
|
113
|
+
console.log(text); // => "1.1.45-canary.20250120T140547"
|
|
114
114
|
```
|
|
115
115
|
|
|
116
116
|
Configure the output stream by passing one of the following values to `stdout/stderr`:
|
package/docs/cli/publish.md
CHANGED
package/docs/runtime/debugger.md
CHANGED
|
@@ -124,11 +124,11 @@ await fetch("https://example.com", {
|
|
|
124
124
|
This prints the `fetch` request as a single-line `curl` command to let you copy-paste into your terminal to replicate the request.
|
|
125
125
|
|
|
126
126
|
```sh
|
|
127
|
-
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.1.45-canary.
|
|
127
|
+
[fetch] $ curl --http1.1 "https://example.com/" -X POST -H "content-type: application/json" -H "Connection: keep-alive" -H "User-Agent: Bun/1.1.45-canary.20250120T140547" -H "Accept: */*" -H "Host: example.com" -H "Accept-Encoding: gzip, deflate, br" --compressed -H "Content-Length: 13" --data-raw "{\"foo\":\"bar\"}"
|
|
128
128
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
129
129
|
[fetch] > content-type: application/json
|
|
130
130
|
[fetch] > Connection: keep-alive
|
|
131
|
-
[fetch] > User-Agent: Bun/1.1.45-canary.
|
|
131
|
+
[fetch] > User-Agent: Bun/1.1.45-canary.20250120T140547
|
|
132
132
|
[fetch] > Accept: */*
|
|
133
133
|
[fetch] > Host: example.com
|
|
134
134
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
|
@@ -170,7 +170,7 @@ This prints the following to the console:
|
|
|
170
170
|
[fetch] > HTTP/1.1 POST https://example.com/
|
|
171
171
|
[fetch] > content-type: application/json
|
|
172
172
|
[fetch] > Connection: keep-alive
|
|
173
|
-
[fetch] > User-Agent: Bun/1.1.45-canary.
|
|
173
|
+
[fetch] > User-Agent: Bun/1.1.45-canary.20250120T140547
|
|
174
174
|
[fetch] > Accept: */*
|
|
175
175
|
[fetch] > Host: example.com
|
|
176
176
|
[fetch] > Accept-Encoding: gzip, deflate, br
|
package/docs/test/dom.md
CHANGED
package/package.json
CHANGED