bun-types 1.2.21-canary.20250819T140628 → 1.2.21-canary.20250821T140634

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 CHANGED
@@ -14,7 +14,6 @@
14
14
  * This module aliases `globalThis.Bun`.
15
15
  */
16
16
  declare module "bun" {
17
- type DistributedOmit<T, K extends PropertyKey> = T extends T ? Omit<T, K> : never;
18
17
  type PathLike = string | NodeJS.TypedArray | ArrayBufferLike | URL;
19
18
  type ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> =
20
19
  | NodeJS.TypedArray<TArrayBuffer>
@@ -68,38 +67,30 @@ declare module "bun" {
68
67
  ? T
69
68
  : Otherwise // Not defined in lib dom (or anywhere else), so no conflict. We can safely use our own definition
70
69
  : Otherwise; // Lib dom not loaded anyway, so no conflict. We can safely use our own definition
71
- }
72
-
73
- /** @deprecated This type is unused in Bun's types and might be removed in the near future */
74
- type Platform =
75
- | "aix"
76
- | "android"
77
- | "darwin"
78
- | "freebsd"
79
- | "haiku"
80
- | "linux"
81
- | "openbsd"
82
- | "sunos"
83
- | "win32"
84
- | "cygwin"
85
- | "netbsd";
86
-
87
- /** @deprecated This type is unused in Bun's types and might be removed in the near future */
88
- type Architecture = "arm" | "arm64" | "ia32" | "mips" | "mipsel" | "ppc" | "ppc64" | "s390" | "s390x" | "x64";
89
70
 
90
- /** @deprecated This type is unused in Bun's types and might be removed in the near future */
91
- type UncaughtExceptionListener = (error: Error, origin: UncaughtExceptionOrigin) => void;
92
-
93
- /**
94
- * Most of the time the unhandledRejection will be an Error, but this should not be relied upon
95
- * as *anything* can be thrown/rejected, it is therefore unsafe to assume that the value is an Error.
96
- *
97
- * @deprecated This type is unused in Bun's types and might be removed in the near future
98
- */
99
- type UnhandledRejectionListener = (reason: unknown, promise: Promise<unknown>) => void;
71
+ /**
72
+ * Like Omit, but correctly distributes over unions. Most useful for removing
73
+ * properties from union options objects, like {@link Bun.SQL.Options}
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * type X = Bun.DistributedOmit<{type?: 'a', url?: string} | {type?: 'b', flag?: boolean}, "url">
78
+ * // `{type?: 'a'} | {type?: 'b', flag?: boolean}` (Omit applied to each union item instead of entire type)
79
+ *
80
+ * type X = Omit<{type?: 'a', url?: string} | {type?: 'b', flag?: boolean}, "url">;
81
+ * // `{type?: "a" | "b" | undefined}` (Missing `flag` property and no longer a union)
82
+ * ```
83
+ */
84
+ type DistributedOmit<T, K extends PropertyKey> = T extends T ? Omit<T, K> : never;
100
85
 
101
- /** @deprecated This type is unused in Bun's types and might be removed in the near future */
102
- type MultipleResolveListener = (type: MultipleResolveType, promise: Promise<unknown>, value: unknown) => void;
86
+ type KeysInBoth<A, B> = Extract<keyof A, keyof B>;
87
+ type MergeInner<A, B> = Omit<A, KeysInBoth<A, B>> &
88
+ Omit<B, KeysInBoth<A, B>> & {
89
+ [Key in KeysInBoth<A, B>]: A[Key] | B[Key];
90
+ };
91
+ type Merge<A, B> = MergeInner<A, B> & MergeInner<B, A>;
92
+ type DistributedMerge<T, Else = T> = T extends T ? Merge<T, Exclude<Else, T>> : never;
93
+ }
103
94
 
104
95
  interface ErrorEventInit extends EventInit {
105
96
  colno?: number;
@@ -1276,678 +1267,6 @@ declare module "bun" {
1276
1267
  stat(): Promise<import("node:fs").Stats>;
1277
1268
  }
1278
1269
 
1279
- namespace SQL {
1280
- type AwaitPromisesArray<T extends Array<PromiseLike<any>>> = {
1281
- [K in keyof T]: Awaited<T[K]>;
1282
- };
1283
-
1284
- type ContextCallbackResult<T> = T extends Array<PromiseLike<any>> ? AwaitPromisesArray<T> : Awaited<T>;
1285
- type ContextCallback<T, SQL> = (sql: SQL) => Promise<T>;
1286
-
1287
- /**
1288
- * Configuration options for SQL client connection and behavior
1289
- *
1290
- * @example
1291
- * ```ts
1292
- * const config: Bun.SQL.Options = {
1293
- * host: 'localhost',
1294
- * port: 5432,
1295
- * user: 'dbuser',
1296
- * password: 'secretpass',
1297
- * database: 'myapp',
1298
- * idleTimeout: 30,
1299
- * max: 20,
1300
- * onconnect: (client) => {
1301
- * console.log('Connected to database');
1302
- * }
1303
- * };
1304
- * ```
1305
- */
1306
- interface Options {
1307
- /**
1308
- * Connection URL (can be string or URL object)
1309
- */
1310
- url?: URL | string | undefined;
1311
-
1312
- /**
1313
- * Database server hostname
1314
- * @default "localhost"
1315
- */
1316
- host?: string | undefined;
1317
-
1318
- /**
1319
- * Database server hostname (alias for host)
1320
- * @deprecated Prefer {@link host}
1321
- * @default "localhost"
1322
- */
1323
- hostname?: string | undefined;
1324
-
1325
- /**
1326
- * Database server port number
1327
- * @default 5432
1328
- */
1329
- port?: number | string | undefined;
1330
-
1331
- /**
1332
- * Database user for authentication
1333
- * @default "postgres"
1334
- */
1335
- username?: string | undefined;
1336
-
1337
- /**
1338
- * Database user for authentication (alias for username)
1339
- * @deprecated Prefer {@link username}
1340
- * @default "postgres"
1341
- */
1342
- user?: string | undefined;
1343
-
1344
- /**
1345
- * Database password for authentication
1346
- * @default ""
1347
- */
1348
- password?: string | (() => MaybePromise<string>) | undefined;
1349
-
1350
- /**
1351
- * Database password for authentication (alias for password)
1352
- * @deprecated Prefer {@link password}
1353
- * @default ""
1354
- */
1355
- pass?: string | (() => MaybePromise<string>) | undefined;
1356
-
1357
- /**
1358
- * Name of the database to connect to
1359
- * @default The username value
1360
- */
1361
- database?: string | undefined;
1362
-
1363
- /**
1364
- * Name of the database to connect to (alias for database)
1365
- * @deprecated Prefer {@link database}
1366
- * @default The username value
1367
- */
1368
- db?: string | undefined;
1369
-
1370
- /**
1371
- * Database adapter/driver to use
1372
- * @default "postgres"
1373
- */
1374
- adapter?: "postgres" /*| "sqlite" | "mysql"*/ | (string & {}) | undefined;
1375
-
1376
- /**
1377
- * Maximum time in seconds to wait for connection to become available
1378
- * @default 0 (no timeout)
1379
- */
1380
- idleTimeout?: number | undefined;
1381
-
1382
- /**
1383
- * Maximum time in seconds to wait for connection to become available (alias for idleTimeout)
1384
- * @deprecated Prefer {@link idleTimeout}
1385
- * @default 0 (no timeout)
1386
- */
1387
- idle_timeout?: number | undefined;
1388
-
1389
- /**
1390
- * Maximum time in seconds to wait when establishing a connection
1391
- * @default 30
1392
- */
1393
- connectionTimeout?: number | undefined;
1394
-
1395
- /**
1396
- * Maximum time in seconds to wait when establishing a connection (alias for connectionTimeout)
1397
- * @deprecated Prefer {@link connectionTimeout}
1398
- * @default 30
1399
- */
1400
- connection_timeout?: number | undefined;
1401
-
1402
- /**
1403
- * Maximum time in seconds to wait when establishing a connection (alias for connectionTimeout)
1404
- * @deprecated Prefer {@link connectionTimeout}
1405
- * @default 30
1406
- */
1407
- connectTimeout?: number | undefined;
1408
-
1409
- /**
1410
- * Maximum time in seconds to wait when establishing a connection (alias for connectionTimeout)
1411
- * @deprecated Prefer {@link connectionTimeout}
1412
- * @default 30
1413
- */
1414
- connect_timeout?: number | undefined;
1415
-
1416
- /**
1417
- * Maximum lifetime in seconds of a connection
1418
- * @default 0 (no maximum lifetime)
1419
- */
1420
- maxLifetime?: number | undefined;
1421
-
1422
- /**
1423
- * Maximum lifetime in seconds of a connection (alias for maxLifetime)
1424
- * @deprecated Prefer {@link maxLifetime}
1425
- * @default 0 (no maximum lifetime)
1426
- */
1427
- max_lifetime?: number | undefined;
1428
-
1429
- /**
1430
- * Whether to use TLS/SSL for the connection
1431
- * @default false
1432
- */
1433
- tls?: TLSOptions | boolean | undefined;
1434
-
1435
- /**
1436
- * Whether to use TLS/SSL for the connection (alias for tls)
1437
- * @default false
1438
- */
1439
- ssl?: TLSOptions | boolean | undefined;
1440
-
1441
- // `.path` is currently unsupported in Bun, the implementation is incomplete.
1442
- //
1443
- // /**
1444
- // * Unix domain socket path for connection
1445
- // * @default ""
1446
- // */
1447
- // path?: string | undefined;
1448
-
1449
- /**
1450
- * Callback function executed when a connection is established
1451
- */
1452
- onconnect?: ((client: SQL) => void) | undefined;
1453
-
1454
- /**
1455
- * Callback function executed when a connection is closed
1456
- */
1457
- onclose?: ((client: SQL) => void) | undefined;
1458
-
1459
- /**
1460
- * Postgres client runtime configuration options
1461
- *
1462
- * @see https://www.postgresql.org/docs/current/runtime-config-client.html
1463
- */
1464
- connection?: Record<string, string | boolean | number> | undefined;
1465
-
1466
- /**
1467
- * Maximum number of connections in the pool
1468
- * @default 10
1469
- */
1470
- max?: number | undefined;
1471
-
1472
- /**
1473
- * By default values outside i32 range are returned as strings. If this is true, values outside i32 range are returned as BigInts.
1474
- * @default false
1475
- */
1476
- bigint?: boolean | undefined;
1477
-
1478
- /**
1479
- * Automatic creation of prepared statements
1480
- * @default true
1481
- */
1482
- prepare?: boolean | undefined;
1483
- }
1484
-
1485
- /**
1486
- * Represents a SQL query that can be executed, with additional control methods
1487
- * Extends Promise to allow for async/await usage
1488
- */
1489
- interface Query<T> extends Promise<T> {
1490
- /**
1491
- * Indicates if the query is currently executing
1492
- */
1493
- active: boolean;
1494
-
1495
- /**
1496
- * Indicates if the query has been cancelled
1497
- */
1498
- cancelled: boolean;
1499
-
1500
- /**
1501
- * Cancels the executing query
1502
- */
1503
- cancel(): Query<T>;
1504
-
1505
- /**
1506
- * Executes the query as a simple query, no parameters are allowed but can execute multiple commands separated by semicolons
1507
- */
1508
- simple(): Query<T>;
1509
-
1510
- /**
1511
- * Executes the query
1512
- */
1513
- execute(): Query<T>;
1514
-
1515
- /**
1516
- * Returns the raw query result
1517
- */
1518
- raw(): Query<T>;
1519
-
1520
- /**
1521
- * Returns only the values from the query result
1522
- */
1523
- values(): Query<T>;
1524
- }
1525
-
1526
- /**
1527
- * Callback function type for transaction contexts
1528
- * @param sql Function to execute SQL queries within the transaction
1529
- */
1530
- type TransactionContextCallback<T> = ContextCallback<T, TransactionSQL>;
1531
-
1532
- /**
1533
- * Callback function type for savepoint contexts
1534
- * @param sql Function to execute SQL queries within the savepoint
1535
- */
1536
- type SavepointContextCallback<T> = ContextCallback<T, SavepointSQL>;
1537
-
1538
- /**
1539
- * SQL.Helper represents a parameter or serializable
1540
- * value inside of a query.
1541
- *
1542
- * @example
1543
- * ```ts
1544
- * const helper = sql(users, 'id');
1545
- * await sql`insert into users ${helper}`;
1546
- * ```
1547
- */
1548
- interface Helper<T> {
1549
- readonly value: T[];
1550
- readonly columns: (keyof T)[];
1551
- }
1552
- }
1553
-
1554
- /**
1555
- * Main SQL client interface providing connection and transaction management
1556
- */
1557
- interface SQL extends AsyncDisposable {
1558
- /**
1559
- * Executes a SQL query using template literals
1560
- * @example
1561
- * ```ts
1562
- * const [user] = await sql<Users[]>`select * from users where id = ${1}`;
1563
- * ```
1564
- */
1565
- <T = any>(strings: TemplateStringsArray, ...values: unknown[]): SQL.Query<T>;
1566
-
1567
- /**
1568
- * Execute a SQL query using a string
1569
- *
1570
- * @example
1571
- * ```ts
1572
- * const users = await sql<User[]>`SELECT * FROM users WHERE id = ${1}`;
1573
- * ```
1574
- */
1575
- <T = any>(string: string): SQL.Query<T>;
1576
-
1577
- /**
1578
- * Helper function for inserting an object into a query
1579
- *
1580
- * @example
1581
- * ```ts
1582
- * // Insert an object
1583
- * const result = await sql`insert into users ${sql(users)} returning *`;
1584
- *
1585
- * // Or pick specific columns
1586
- * const result = await sql`insert into users ${sql(users, "id", "name")} returning *`;
1587
- *
1588
- * // Or a single object
1589
- * const result = await sql`insert into users ${sql(user)} returning *`;
1590
- * ```
1591
- */
1592
- <T extends { [Key in PropertyKey]: unknown }>(obj: T | T[] | readonly T[]): SQL.Helper<T>;
1593
-
1594
- /**
1595
- * Helper function for inserting an object into a query, supporting specific columns
1596
- *
1597
- * @example
1598
- * ```ts
1599
- * // Insert an object
1600
- * const result = await sql`insert into users ${sql(users)} returning *`;
1601
- *
1602
- * // Or pick specific columns
1603
- * const result = await sql`insert into users ${sql(users, "id", "name")} returning *`;
1604
- *
1605
- * // Or a single object
1606
- * const result = await sql`insert into users ${sql(user)} returning *`;
1607
- * ```
1608
- */
1609
- <T extends { [Key in PropertyKey]: unknown }, Keys extends keyof T = keyof T>(
1610
- obj: T | T[] | readonly T[],
1611
- ...columns: readonly Keys[]
1612
- ): SQL.Helper<Pick<T, Keys>>;
1613
-
1614
- /**
1615
- * Helper function for inserting any serializable value into a query
1616
- *
1617
- * @example
1618
- * ```ts
1619
- * const result = await sql`SELECT * FROM users WHERE id IN ${sql([1, 2, 3])}`;
1620
- * ```
1621
- */
1622
- <T>(value: T): SQL.Helper<T>;
1623
-
1624
- /**
1625
- * Commits a distributed transaction also know as prepared transaction in postgres or XA transaction in MySQL
1626
- *
1627
- * @param name - The name of the distributed transaction
1628
- *
1629
- * @example
1630
- * ```ts
1631
- * await sql.commitDistributed("my_distributed_transaction");
1632
- * ```
1633
- */
1634
- commitDistributed(name: string): Promise<void>;
1635
-
1636
- /**
1637
- * Rolls back a distributed transaction also know as prepared transaction in postgres or XA transaction in MySQL
1638
- *
1639
- * @param name - The name of the distributed transaction
1640
- *
1641
- * @example
1642
- * ```ts
1643
- * await sql.rollbackDistributed("my_distributed_transaction");
1644
- * ```
1645
- */
1646
- rollbackDistributed(name: string): Promise<void>;
1647
-
1648
- /** Waits for the database connection to be established
1649
- *
1650
- * @example
1651
- * ```ts
1652
- * await sql.connect();
1653
- * ```
1654
- */
1655
- connect(): Promise<SQL>;
1656
-
1657
- /**
1658
- * Closes the database connection with optional timeout in seconds. If timeout is 0, it will close immediately, if is not provided it will wait for all queries to finish before closing.
1659
- *
1660
- * @param options - The options for the close
1661
- *
1662
- * @example
1663
- * ```ts
1664
- * await sql.close({ timeout: 1 });
1665
- * ```
1666
- */
1667
- close(options?: { timeout?: number }): Promise<void>;
1668
-
1669
- /**
1670
- * Closes the database connection with optional timeout in seconds. If timeout is 0, it will close immediately, if is not provided it will wait for all queries to finish before closing.
1671
- * This is an alias of {@link SQL.close}
1672
- *
1673
- * @param options - The options for the close
1674
- *
1675
- * @example
1676
- * ```ts
1677
- * await sql.end({ timeout: 1 });
1678
- * ```
1679
- */
1680
- end(options?: { timeout?: number }): Promise<void>;
1681
-
1682
- /**
1683
- * Flushes any pending operations
1684
- *
1685
- * @example
1686
- * ```ts
1687
- * sql.flush();
1688
- * ```
1689
- */
1690
- flush(): void;
1691
-
1692
- /**
1693
- * The reserve method pulls out a connection from the pool, and returns a client that wraps the single connection.
1694
- *
1695
- * This can be used for running queries on an isolated connection.
1696
- * Calling reserve in a reserved Sql will return a new reserved connection, not the same connection (behavior matches postgres package).
1697
- *
1698
- * @example
1699
- * ```ts
1700
- * const reserved = await sql.reserve();
1701
- * await reserved`select * from users`;
1702
- * await reserved.release();
1703
- * // with in a production scenario would be something more like
1704
- * const reserved = await sql.reserve();
1705
- * try {
1706
- * // ... queries
1707
- * } finally {
1708
- * await reserved.release();
1709
- * }
1710
- *
1711
- * // Bun supports Symbol.dispose and Symbol.asyncDispose
1712
- * {
1713
- * // always release after context (safer)
1714
- * using reserved = await sql.reserve()
1715
- * await reserved`select * from users`
1716
- * }
1717
- * ```
1718
- */
1719
- reserve(): Promise<ReservedSQL>;
1720
-
1721
- /**
1722
- * Begins a new transaction.
1723
- *
1724
- * 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.
1725
- * 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.
1726
- * @example
1727
- * const [user, account] = await sql.begin(async sql => {
1728
- * const [user] = await sql`
1729
- * insert into users (
1730
- * name
1731
- * ) values (
1732
- * 'Murray'
1733
- * )
1734
- * returning *
1735
- * `
1736
- * const [account] = await sql`
1737
- * insert into accounts (
1738
- * user_id
1739
- * ) values (
1740
- * ${ user.user_id }
1741
- * )
1742
- * returning *
1743
- * `
1744
- * return [user, account]
1745
- * })
1746
- */
1747
- begin<const T>(fn: SQL.TransactionContextCallback<T>): Promise<SQL.ContextCallbackResult<T>>;
1748
-
1749
- /**
1750
- * Begins a new transaction with options.
1751
- *
1752
- * 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.
1753
- * 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.
1754
- * @example
1755
- * const [user, account] = await sql.begin("read write", async sql => {
1756
- * const [user] = await sql`
1757
- * insert into users (
1758
- * name
1759
- * ) values (
1760
- * 'Murray'
1761
- * )
1762
- * returning *
1763
- * `
1764
- * const [account] = await sql`
1765
- * insert into accounts (
1766
- * user_id
1767
- * ) values (
1768
- * ${ user.user_id }
1769
- * )
1770
- * returning *
1771
- * `
1772
- * return [user, account]
1773
- * })
1774
- */
1775
- begin<const T>(options: string, fn: SQL.TransactionContextCallback<T>): Promise<SQL.ContextCallbackResult<T>>;
1776
-
1777
- /**
1778
- * Alternative method to begin a transaction.
1779
- *
1780
- * 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.
1781
- * 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.
1782
- * @alias begin
1783
- * @example
1784
- * const [user, account] = await sql.transaction(async sql => {
1785
- * const [user] = await sql`
1786
- * insert into users (
1787
- * name
1788
- * ) values (
1789
- * 'Murray'
1790
- * )
1791
- * returning *
1792
- * `
1793
- * const [account] = await sql`
1794
- * insert into accounts (
1795
- * user_id
1796
- * ) values (
1797
- * ${ user.user_id }
1798
- * )
1799
- * returning *
1800
- * `
1801
- * return [user, account]
1802
- * })
1803
- */
1804
- transaction<const T>(fn: SQL.TransactionContextCallback<T>): Promise<SQL.ContextCallbackResult<T>>;
1805
-
1806
- /**
1807
- * Alternative method to begin a transaction with options
1808
- * 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.
1809
- * 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.
1810
- *
1811
- * @alias {@link begin}
1812
- *
1813
- * @example
1814
- * const [user, account] = await sql.transaction("read write", async sql => {
1815
- * const [user] = await sql`
1816
- * insert into users (
1817
- * name
1818
- * ) values (
1819
- * 'Murray'
1820
- * )
1821
- * returning *
1822
- * `
1823
- * const [account] = await sql`
1824
- * insert into accounts (
1825
- * user_id
1826
- * ) values (
1827
- * ${ user.user_id }
1828
- * )
1829
- * returning *
1830
- * `
1831
- * return [user, account]
1832
- * });
1833
- */
1834
- transaction<const T>(options: string, fn: SQL.TransactionContextCallback<T>): Promise<SQL.ContextCallbackResult<T>>;
1835
-
1836
- /**
1837
- * Begins a distributed transaction
1838
- * 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.
1839
- * 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.
1840
- * beginDistributed will automatic rollback if any exception are not caught, and you can commit and rollback later if everything goes well.
1841
- * 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.
1842
- * 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.
1843
- *
1844
- * @example
1845
- * await sql.beginDistributed("numbers", async sql => {
1846
- * await sql`create table if not exists numbers (a int)`;
1847
- * await sql`insert into numbers values(1)`;
1848
- * });
1849
- * // later you can call
1850
- * await sql.commitDistributed("numbers");
1851
- * // or await sql.rollbackDistributed("numbers");
1852
- */
1853
- beginDistributed<const T>(
1854
- name: string,
1855
- fn: SQL.TransactionContextCallback<T>,
1856
- ): Promise<SQL.ContextCallbackResult<T>>;
1857
-
1858
- /** Alternative method to begin a distributed transaction
1859
- * @alias {@link beginDistributed}
1860
- */
1861
- distributed<const T>(name: string, fn: SQL.TransactionContextCallback<T>): Promise<SQL.ContextCallbackResult<T>>;
1862
-
1863
- /**If you know what you're doing, you can use unsafe to pass any string you'd like.
1864
- * Please note that this can lead to SQL injection if you're not careful.
1865
- * You can also nest sql.unsafe within a safe sql expression. This is useful if only part of your fraction has unsafe elements.
1866
- * @example
1867
- * const result = await sql.unsafe(`select ${danger} from users where id = ${dragons}`)
1868
- */
1869
- unsafe<T = any>(string: string, values?: any[]): SQL.Query<T>;
1870
-
1871
- /**
1872
- * Reads a file and uses the contents as a query.
1873
- * Optional parameters can be used if the file includes $1, $2, etc
1874
- * @example
1875
- * const result = await sql.file("query.sql", [1, 2, 3]);
1876
- */
1877
- file<T = any>(filename: string, values?: any[]): SQL.Query<T>;
1878
-
1879
- /**
1880
- * Current client options
1881
- */
1882
- options: SQL.Options;
1883
- }
1884
-
1885
- const SQL: {
1886
- /**
1887
- * Creates a new SQL client instance
1888
- *
1889
- * @param connectionString - The connection string for the SQL client
1890
- *
1891
- * @example
1892
- * ```ts
1893
- * const sql = new SQL("postgres://localhost:5432/mydb");
1894
- * const sql = new SQL(new URL("postgres://localhost:5432/mydb"));
1895
- * ```
1896
- */
1897
- new (connectionString: string | URL): SQL;
1898
-
1899
- /**
1900
- * Creates a new SQL client instance with options
1901
- *
1902
- * @param connectionString - The connection string for the SQL client
1903
- * @param options - The options for the SQL client
1904
- *
1905
- * @example
1906
- * ```ts
1907
- * const sql = new SQL("postgres://localhost:5432/mydb", { idleTimeout: 1000 });
1908
- * ```
1909
- */
1910
- new (connectionString: string | URL, options: Omit<SQL.Options, "url">): SQL;
1911
-
1912
- /**
1913
- * Creates a new SQL client instance with options
1914
- *
1915
- * @param options - The options for the SQL client
1916
- *
1917
- * @example
1918
- * ```ts
1919
- * const sql = new SQL({ url: "postgres://localhost:5432/mydb", idleTimeout: 1000 });
1920
- * ```
1921
- */
1922
- new (options?: SQL.Options): SQL;
1923
- };
1924
-
1925
- /**
1926
- * Represents a reserved connection from the connection pool
1927
- * Extends SQL with additional release functionality
1928
- */
1929
- interface ReservedSQL extends SQL, Disposable {
1930
- /**
1931
- * Releases the client back to the connection pool
1932
- */
1933
- release(): void;
1934
- }
1935
-
1936
- /**
1937
- * Represents a client within a transaction context
1938
- * Extends SQL with savepoint functionality
1939
- */
1940
- interface TransactionSQL extends SQL {
1941
- /** Creates a savepoint within the current transaction */
1942
- savepoint<T>(name: string, fn: SQLSavepointContextCallback<T>): Promise<T>;
1943
- savepoint<T>(fn: SQLSavepointContextCallback<T>): Promise<T>;
1944
- }
1945
-
1946
- /**
1947
- * Represents a savepoint within a transaction
1948
- */
1949
- interface SavepointSQL extends SQL {}
1950
-
1951
1270
  type CSRFAlgorithm = "blake2b256" | "blake2b512" | "sha256" | "sha384" | "sha512" | "sha512-256";
1952
1271
 
1953
1272
  interface CSRFGenerateOptions {
@@ -1995,16 +1314,6 @@ declare module "bun" {
1995
1314
  maxAge?: number;
1996
1315
  }
1997
1316
 
1998
- /**
1999
- * SQL client
2000
- */
2001
- const sql: SQL;
2002
-
2003
- /**
2004
- * SQL client for PostgreSQL
2005
- */
2006
- const postgres: SQL;
2007
-
2008
1317
  /**
2009
1318
  * Generate and verify CSRF tokens
2010
1319
  *
@@ -2319,12 +1628,24 @@ declare module "bun" {
2319
1628
  kind: ImportKind;
2320
1629
  }
2321
1630
 
1631
+ namespace _BunBuildInterface {
1632
+ type Architecture = "x64" | "arm64";
1633
+ type Libc = "glibc" | "musl";
1634
+ type SIMD = "baseline" | "modern";
1635
+ type Target =
1636
+ | `bun-darwin-${Architecture}`
1637
+ | `bun-darwin-x64-${SIMD}`
1638
+ | `bun-linux-${Architecture}`
1639
+ | `bun-linux-${Architecture}-${Libc}`
1640
+ | "bun-windows-x64"
1641
+ | `bun-windows-x64-${SIMD}`
1642
+ | `bun-linux-x64-${SIMD}-${Libc}`;
1643
+ }
2322
1644
  /**
2323
1645
  * @see [Bun.build API docs](https://bun.com/docs/bundler#api)
2324
1646
  */
2325
- interface BuildConfig {
1647
+ interface BuildConfigBase {
2326
1648
  entrypoints: string[]; // list of file path
2327
- outdir?: string; // output directory
2328
1649
  /**
2329
1650
  * @default "browser"
2330
1651
  */
@@ -2362,7 +1683,6 @@ declare module "bun" {
2362
1683
  asset?: string;
2363
1684
  }; // | string;
2364
1685
  root?: string; // project root
2365
- splitting?: boolean; // default true, enable code splitting
2366
1686
  plugins?: BunPlugin[];
2367
1687
  // manifest?: boolean; // whether to return manifest
2368
1688
  external?: string[];
@@ -2511,8 +1831,57 @@ declare module "bun" {
2511
1831
  * ```
2512
1832
  */
2513
1833
  tsconfig?: string;
1834
+
1835
+ outdir?: string;
2514
1836
  }
2515
1837
 
1838
+ interface CompileBuildOptions {
1839
+ target?: _BunBuildInterface.Target;
1840
+ execArgv?: string[];
1841
+ executablePath?: string;
1842
+ outfile?: string;
1843
+ windows?: {
1844
+ hideConsole?: boolean;
1845
+ icon?: string;
1846
+ title?: string;
1847
+ };
1848
+ }
1849
+
1850
+ // Compile build config - uses outfile for executable output
1851
+ interface CompileBuildConfig extends BuildConfigBase {
1852
+ /**
1853
+ * Create a standalone executable
1854
+ *
1855
+ * When `true`, creates an executable for the current platform.
1856
+ * When a target string, creates an executable for that platform.
1857
+ *
1858
+ * @example
1859
+ * ```ts
1860
+ * // Create executable for current platform
1861
+ * await Bun.build({
1862
+ * entrypoints: ['./app.js'],
1863
+ * compile: {
1864
+ * target: 'linux-x64',
1865
+ * },
1866
+ * outfile: './my-app'
1867
+ * });
1868
+ *
1869
+ * // Cross-compile for Linux x64
1870
+ * await Bun.build({
1871
+ * entrypoints: ['./app.js'],
1872
+ * compile: 'linux-x64',
1873
+ * outfile: './my-app'
1874
+ * });
1875
+ * ```
1876
+ */
1877
+ compile: boolean | _BunBuildInterface.Target | CompileBuildOptions;
1878
+ }
1879
+
1880
+ /**
1881
+ * @see [Bun.build API docs](https://bun.com/docs/bundler#api)
1882
+ */
1883
+ type BuildConfig = BuildConfigBase | CompileBuildConfig;
1884
+
2516
1885
  /**
2517
1886
  * Hash and verify passwords using argon2 or bcrypt
2518
1887
  *
@@ -4383,11 +3752,11 @@ declare module "bun" {
4383
3752
  * The type of options that can be passed to {@link serve}, with support for `routes` and a safer requirement for `fetch`
4384
3753
  */
4385
3754
  type ServeFunctionOptions<T, R extends { [K in keyof R]: RouterTypes.RouteValue<Extract<K, string>> }> =
4386
- | (DistributedOmit<Exclude<Serve<T>, WebSocketServeOptions<T>>, "fetch"> & {
3755
+ | (__internal.DistributedOmit<Exclude<Serve<T>, WebSocketServeOptions<T>>, "fetch"> & {
4387
3756
  routes: R;
4388
3757
  fetch?: (this: Server, request: Request, server: Server) => Response | Promise<Response>;
4389
3758
  })
4390
- | (DistributedOmit<Exclude<Serve<T>, WebSocketServeOptions<T>>, "routes"> & {
3759
+ | (__internal.DistributedOmit<Exclude<Serve<T>, WebSocketServeOptions<T>>, "routes"> & {
4391
3760
  routes?: never;
4392
3761
  fetch: (this: Server, request: Request, server: Server) => Response | Promise<Response>;
4393
3762
  })