bun-types 0.0.74 → 0.0.76

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/types.d.ts +213 -134
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  },
9
9
  "repository": "https://github.com/jarred-sumner/bun",
10
10
  "readme": "This package is a temporary workaround until https://github.com/DefinitelyTyped/DefinitelyTyped/pull/59670 is merged.",
11
- "version": "0.0.74",
11
+ "version": "0.0.76",
12
12
  "types": "types.d.ts",
13
13
  "scripts": {
14
14
  "prepublishOnly": "cp ../../types/bun/bun.d.ts types.d.ts"
package/types.d.ts CHANGED
@@ -231,11 +231,13 @@ declare global {
231
231
 
232
232
  interface ImportMeta {
233
233
  /**
234
- * Absolute path to the source file
235
- *
236
- * This is an alias of `import.meta.path`
234
+ * `file://` url string for the current module.
237
235
  *
238
- * A future version of this may be an absolute URL.
236
+ * @example
237
+ * ```ts
238
+ * console.log(import.meta.url);
239
+ * "file:///Users/me/projects/my-app/src/my-app.ts"
240
+ * ```
239
241
  */
240
242
  url: string;
241
243
  /**
@@ -993,6 +995,19 @@ declare global {
993
995
  | Float32Array
994
996
  | Float64Array;
995
997
 
998
+ const performance: {
999
+ /**
1000
+ * Seconds since Bun.js started
1001
+ *
1002
+ * Uses a high-precision system timer to measure the time elapsed since the
1003
+ * Bun.js runtime was initialized. The value is represented as a double
1004
+ * precision floating point number. The value is monotonically increasing
1005
+ * during the lifetime of the runtime.
1006
+ *
1007
+ */
1008
+ now: () => number;
1009
+ };
1010
+
996
1011
  namespace Bun {
997
1012
  type HashFunction = (
998
1013
  data: string | ArrayBufferView | ArrayBuffer,
@@ -1189,20 +1204,56 @@ declare global {
1189
1204
  | "entry-point";
1190
1205
  }
1191
1206
 
1192
- interface HTTP {
1207
+ interface ServeOptions {
1193
1208
  /**
1194
1209
  * What port should the server listen on?
1195
1210
  * @default process.env.PORT || "3000"
1196
1211
  */
1197
1212
  port?: string | number;
1213
+
1198
1214
  /**
1199
1215
  * What hostname should the server listen on?
1200
- * @default "0.0.0.0" // listen on all interfaces
1201
- * @example "127.0.0.1" // Only listen locally
1202
- * @example "remix.run" // Only listen on remix.run
1216
+ *
1217
+ * @default
1218
+ * ```js
1219
+ * "0.0.0.0" // listen on all interfaces
1220
+ * ```
1221
+ * @example
1222
+ * ```js
1223
+ * "127.0.0.1" // Only listen locally
1224
+ * ```
1225
+ * @example
1226
+ * ```js
1227
+ * "remix.run" // Only listen on remix.run
1228
+ * ````
1229
+ *
1230
+ * note: hostname should not include a {@link port}
1203
1231
  */
1204
1232
  hostname?: string;
1205
1233
 
1234
+ /**
1235
+ * What URI should be used to make {@link Request.url} absolute?
1236
+ *
1237
+ * By default, looks at {@link hostname}, {@link port}, and whether or not SSL is enabled to generate one
1238
+ *
1239
+ * @example
1240
+ *```js
1241
+ * "http://my-app.com"
1242
+ * ```
1243
+ *
1244
+ * @example
1245
+ *```js
1246
+ * "https://wongmjane.com/"
1247
+ * ```
1248
+ *
1249
+ * This should be the public, absolute URL – include the protocol and {@link hostname}. If the port isn't 80 or 443, then include the {@link port} too.
1250
+ *
1251
+ * @example
1252
+ * "http://localhost:3000"
1253
+ *
1254
+ */
1255
+ baseURI?: string;
1256
+
1206
1257
  /**
1207
1258
  * What is the maximum size of a request body? (in bytes)
1208
1259
  * @default 1024 * 1024 * 128 // 128MB
@@ -1261,7 +1312,7 @@ declare global {
1261
1312
  certFile: string;
1262
1313
  }
1263
1314
 
1264
- type SSLServeOptions = HTTP &
1315
+ type SSLServeOptions = ServeOptions &
1265
1316
  SSLOptions &
1266
1317
  SSLAdvancedOptions & {
1267
1318
  /**
@@ -1308,7 +1359,7 @@ declare global {
1308
1359
  * });
1309
1360
  * ```
1310
1361
  */
1311
- function serve(options: Serve): void;
1362
+ function serve(options: ServeOptions): void;
1312
1363
 
1313
1364
  /**
1314
1365
  *
@@ -1531,6 +1582,17 @@ declare global {
1531
1582
  */
1532
1583
  function mmap(path: PathLike, opts?: MMapOptions): Uint8Array;
1533
1584
 
1585
+ /** Write to stdout */
1586
+ const stdout: FileBlob;
1587
+ /** Write to stderr */
1588
+ const stderr: FileBlob;
1589
+ /**
1590
+ * Read from stdin
1591
+ *
1592
+ * This is read-only
1593
+ */
1594
+ const stdin: FileBlob;
1595
+
1534
1596
  interface unsafe {
1535
1597
  /**
1536
1598
  * Cast bytes to a `String` without copying. This is the fastest way to get a `String` from a `Uint8Array` or `ArrayBuffer`.
@@ -1558,6 +1620,22 @@ declare global {
1558
1620
  }
1559
1621
  let unsafe: unsafe;
1560
1622
 
1623
+ /**
1624
+ * Are ANSI colors enabled for stdin and stdout?
1625
+ *
1626
+ * Used for {@link console.log}
1627
+ */
1628
+ const enableANSIColors: boolean;
1629
+
1630
+ /**
1631
+ * What script launched bun?
1632
+ *
1633
+ * Absolute file path
1634
+ *
1635
+ * @example "/never-gonna-give-you-up.js"
1636
+ */
1637
+ const main: string;
1638
+
1561
1639
  /**
1562
1640
  * Manually trigger the garbage collector
1563
1641
  *
@@ -1569,6 +1647,33 @@ declare global {
1569
1647
  */
1570
1648
  function gc(force: boolean): void;
1571
1649
 
1650
+ /**
1651
+ * JavaScriptCore engine's internal heap snapshot
1652
+ *
1653
+ * I don't know how to make this something Chrome or Safari can read.
1654
+ *
1655
+ * If you have any ideas, please file an issue https://github.com/Jarred-Sumner/bun
1656
+ */
1657
+ interface HeapSnapshot {
1658
+ /** "2" */
1659
+ version: string;
1660
+
1661
+ /** "Inspector" */
1662
+ type: string;
1663
+
1664
+ nodes: number[];
1665
+
1666
+ nodeClassNames: string[];
1667
+ edges: number[];
1668
+ edgeTypes: string[];
1669
+ edgeNames: string[];
1670
+ }
1671
+
1672
+ /**
1673
+ * Generate a heap snapshot for seeing where the heap is being used
1674
+ */
1675
+ function generateHeapSnapshot(): HeapSnapshot;
1676
+
1572
1677
  /**
1573
1678
  * The next time JavaScriptCore is idle, clear unused memory and attempt to reduce the heap size.
1574
1679
  */
@@ -2147,10 +2252,10 @@ declare module "bun:test" {
2147
2252
  * It can be accessed using:
2148
2253
  *
2149
2254
  * ```js
2150
- * import path from 'path';
2255
+ * import path from 'path';
2151
2256
  * ```
2152
2257
  */
2153
- export namespace path {
2258
+ declare module "path/posix" {
2154
2259
  /**
2155
2260
  * A parsed path object generated by path.parse() or consumed by path.format().
2156
2261
  */
@@ -2198,117 +2303,93 @@ export namespace path {
2198
2303
  */
2199
2304
  name?: string | undefined;
2200
2305
  }
2201
- interface PlatformPath {
2202
- /**
2203
- * Normalize a string path, reducing '..' and '.' parts.
2204
- * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
2205
- *
2206
- * @param p string path to normalize.
2207
- */
2208
- normalize(p: string): string;
2209
- /**
2210
- * Join all arguments together and normalize the resulting path.
2211
- * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
2212
- *
2213
- * @param paths paths to join.
2214
- */
2215
- join(...paths: string[]): string;
2216
- /**
2217
- * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
2218
- *
2219
- * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
2220
- *
2221
- * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
2222
- * until an absolute path is found. If after using all {from} paths still no absolute path is found,
2223
- * the current working directory is used as well. The resulting path is normalized,
2224
- * and trailing slashes are removed unless the path gets resolved to the root directory.
2225
- *
2226
- * @param pathSegments string paths to join. Non-string arguments are ignored.
2227
- */
2228
- resolve(...pathSegments: string[]): string;
2229
- /**
2230
- * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
2231
- *
2232
- * @param path path to test.
2233
- */
2234
- isAbsolute(p: string): boolean;
2235
- /**
2236
- * Solve the relative path from {from} to {to}.
2237
- * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
2238
- */
2239
- relative(from: string, to: string): string;
2240
- /**
2241
- * Return the directory name of a path. Similar to the Unix dirname command.
2242
- *
2243
- * @param p the path to evaluate.
2244
- */
2245
- dirname(p: string): string;
2246
- /**
2247
- * Return the last portion of a path. Similar to the Unix basename command.
2248
- * Often used to extract the file name from a fully qualified path.
2249
- *
2250
- * @param p the path to evaluate.
2251
- * @param ext optionally, an extension to remove from the result.
2252
- */
2253
- basename(p: string, ext?: string): string;
2254
- /**
2255
- * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
2256
- * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
2257
- *
2258
- * @param p the path to evaluate.
2259
- */
2260
- extname(p: string): string;
2261
- /**
2262
- * The platform-specific file separator. '\\' or '/'.
2263
- */
2264
- readonly sep: string;
2265
- /**
2266
- * The platform-specific file delimiter. ';' or ':'.
2267
- */
2268
- readonly delimiter: string;
2269
- /**
2270
- * Returns an object from a path string - the opposite of format().
2271
- *
2272
- * @param pathString path to evaluate.
2273
- */
2274
- parse(p: string): ParsedPath;
2275
- /**
2276
- * Returns a path string from an object - the opposite of parse().
2277
- *
2278
- * @param pathString path to evaluate.
2279
- */
2280
- format(pP: FormatInputPathObject): string;
2281
- /**
2282
- * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
2283
- * If path is not a string, path will be returned without modifications.
2284
- * This method is meaningful only on Windows system.
2285
- * On POSIX systems, the method is non-operational and always returns path without modifications.
2286
- */
2287
- toNamespacedPath(path: string): string;
2288
- /**
2289
- * Posix specific pathing.
2290
- * Same as parent object on posix.
2291
- */
2292
- readonly posix: PlatformPath;
2293
- /**
2294
- * Windows specific pathing.
2295
- * Same as parent object on windows
2296
- */
2297
- readonly win32: PlatformPath;
2298
- }
2299
- }
2300
2306
 
2301
- /**
2302
- * The `path` module provides utilities for working with file and directory paths.
2303
- * It can be accessed using:
2304
- *
2305
- * ```js
2306
- * import path from 'path';
2307
- * ```
2308
- */
2309
- declare module "path" {
2310
- const path: path.PlatformPath;
2311
- export = path;
2307
+ /**
2308
+ * Normalize a string path, reducing '..' and '.' parts.
2309
+ * When multiple slashes are found, they're replaced by a single one; when the path contains a trailing slash, it is preserved. On Windows backslashes are used.
2310
+ *
2311
+ * @param p string path to normalize.
2312
+ */
2313
+ export function normalize(p: string): string;
2314
+ /**
2315
+ * Join all arguments together and normalize the resulting path.
2316
+ * Arguments must be strings. In v0.8, non-string arguments were silently ignored. In v0.10 and up, an exception is thrown.
2317
+ *
2318
+ * @param paths paths to join.
2319
+ */
2320
+ export function join(...paths: string[]): string;
2321
+ /**
2322
+ * The right-most parameter is considered {to}. Other parameters are considered an array of {from}.
2323
+ *
2324
+ * Starting from leftmost {from} parameter, resolves {to} to an absolute path.
2325
+ *
2326
+ * If {to} isn't already absolute, {from} arguments are prepended in right to left order,
2327
+ * until an absolute path is found. If after using all {from} paths still no absolute path is found,
2328
+ * the current working directory is used as well. The resulting path is normalized,
2329
+ * and trailing slashes are removed unless the path gets resolved to the root directory.
2330
+ *
2331
+ * @param pathSegments string paths to join. Non-string arguments are ignored.
2332
+ */
2333
+ export function resolve(...pathSegments: string[]): string;
2334
+ /**
2335
+ * Determines whether {path} is an absolute path. An absolute path will always resolve to the same location, regardless of the working directory.
2336
+ *
2337
+ * @param path path to test.
2338
+ */
2339
+ export function isAbsolute(p: string): boolean;
2340
+ /**
2341
+ * Solve the relative path from {from} to {to}.
2342
+ * At times we have two absolute paths, and we need to derive the relative path from one to the other. This is actually the reverse transform of path.resolve.
2343
+ */
2344
+ export function relative(from: string, to: string): string;
2345
+ /**
2346
+ * Return the directory name of a path. Similar to the Unix dirname command.
2347
+ *
2348
+ * @param p the path to evaluate.
2349
+ */
2350
+ export function dirname(p: string): string;
2351
+ /**
2352
+ * Return the last portion of a path. Similar to the Unix basename command.
2353
+ * Often used to extract the file name from a fully qualified path.
2354
+ *
2355
+ * @param p the path to evaluate.
2356
+ * @param ext optionally, an extension to remove from the result.
2357
+ */
2358
+ export function basename(p: string, ext?: string): string;
2359
+ /**
2360
+ * Return the extension of the path, from the last '.' to end of string in the last portion of the path.
2361
+ * If there is no '.' in the last portion of the path or the first character of it is '.', then it returns an empty string
2362
+ *
2363
+ * @param p the path to evaluate.
2364
+ */
2365
+ export function extname(p: string): string;
2366
+ /**
2367
+ * The platform-specific file separator. '\\' or '/'.
2368
+ */
2369
+ export const sep: string;
2370
+ /**
2371
+ * The platform-specific file delimiter. ';' or ':'.
2372
+ */
2373
+ export const delimiter: string;
2374
+ /**
2375
+ * Returns an object from a path string - the opposite of format().
2376
+ *
2377
+ * @param pathString path to evaluate.
2378
+ */
2379
+ export function parse(p: string): ParsedPath;
2380
+ /**
2381
+ * Returns a path string from an object - the opposite of parse().
2382
+ *
2383
+ * @param pathString path to evaluate.
2384
+ */
2385
+ export function format(pP: FormatInputPathObject): string;
2386
+ /**
2387
+ * On Windows systems only, returns an equivalent namespace-prefixed path for the given path.
2388
+ * If path is not a string, path will be returned without modifications.
2389
+ * This method is meaningful only on Windows system.
2390
+ * On POSIX systems, the method is non-operational and always returns path without modifications.
2391
+ */
2392
+ export function toNamespacedPath(path: string): string;
2312
2393
  }
2313
2394
 
2314
2395
  /**
@@ -2319,10 +2400,10 @@ declare module "path" {
2319
2400
  * import path from 'path';
2320
2401
  * ```
2321
2402
  */
2322
- declare module "path/posix" {
2323
- const path: path.PlatformPath;
2324
- export = path;
2403
+ declare module "path/win32" {
2404
+ export * from "path/posix";
2325
2405
  }
2406
+
2326
2407
  /**
2327
2408
  * The `path` module provides utilities for working with file and directory paths.
2328
2409
  * It can be accessed using:
@@ -2331,9 +2412,10 @@ declare module "path/posix" {
2331
2412
  * import path from 'path';
2332
2413
  * ```
2333
2414
  */
2334
- declare module "path/win32" {
2335
- const path: path.PlatformPath;
2336
- export = path;
2415
+ declare module "path" {
2416
+ export * from "path/posix";
2417
+ export * as posix from "path/posix";
2418
+ export * as win32 from "path/win32";
2337
2419
  }
2338
2420
 
2339
2421
  /**
@@ -2345,8 +2427,7 @@ declare module "path/win32" {
2345
2427
  * ```
2346
2428
  */
2347
2429
  declare module "node:path" {
2348
- const path: path.PlatformPath;
2349
- export = path;
2430
+ export * from "path";
2350
2431
  }
2351
2432
  /**
2352
2433
  * The `path` module provides utilities for working with file and directory paths.
@@ -2357,8 +2438,7 @@ declare module "node:path" {
2357
2438
  * ```
2358
2439
  */
2359
2440
  declare module "node:path/posix" {
2360
- const path: path.PlatformPath;
2361
- export = path;
2441
+ export * from "path/posix";
2362
2442
  }
2363
2443
  /**
2364
2444
  * The `path` module provides utilities for working with file and directory paths.
@@ -2369,8 +2449,7 @@ declare module "node:path/posix" {
2369
2449
  * ```
2370
2450
  */
2371
2451
  declare module "node:path/win32" {
2372
- const path: path.PlatformPath;
2373
- export = path;
2452
+ export * from "path/win32";
2374
2453
  }
2375
2454
 
2376
2455
  /**