@types/node 24.12.0 → 25.5.0

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 (98) hide show
  1. node v24.12/README.md → node/README.md +2 -2
  2. node v24.12/assert/strict.d.ts → node/assert/strict.d.ts +5 -11
  3. node v24.12/assert.d.ts → node/assert.d.ts +11 -171
  4. node v24.12/async_hooks.d.ts → node/async_hooks.d.ts +8 -8
  5. node v24.12/buffer.buffer.d.ts → node/buffer.buffer.d.ts +1 -7
  6. node v24.12/buffer.d.ts → node/buffer.d.ts +44 -168
  7. node v24.12/child_process.d.ts → node/child_process.d.ts +21 -64
  8. node/cluster.d.ts +486 -0
  9. node/console.d.ts +151 -0
  10. node v24.12/constants.d.ts → node/constants.d.ts +3 -4
  11. node v24.12/crypto.d.ts → node/crypto.d.ts +287 -1639
  12. node v24.12/dgram.d.ts → node/dgram.d.ts +15 -51
  13. node v24.12/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +4 -4
  14. node v24.12/dns/promises.d.ts → node/dns/promises.d.ts +3 -3
  15. node v24.12/dns.d.ts → node/dns.d.ts +131 -132
  16. node v24.12/domain.d.ts → node/domain.d.ts +13 -17
  17. node v24.12/events.d.ts → node/events.d.ts +866 -795
  18. node v24.12/fs/promises.d.ts → node/fs/promises.d.ts +7 -8
  19. node v24.12/fs.d.ts → node/fs.d.ts +419 -455
  20. node v24.12/globals.d.ts → node/globals.d.ts +6 -26
  21. node/globals.typedarray.d.ts +101 -0
  22. node v24.12/http.d.ts → node/http.d.ts +310 -276
  23. node v24.12/http2.d.ts → node/http2.d.ts +528 -804
  24. node v24.12/https.d.ts → node/https.d.ts +63 -243
  25. node v24.12/index.d.ts → node/index.d.ts +15 -1
  26. node/inspector/promises.d.ts +41 -0
  27. node v24.12/inspector.d.ts → node/inspector.d.ts +42 -50
  28. node v24.12/inspector.generated.d.ts → node/inspector.generated.d.ts +572 -417
  29. node v24.12/module.d.ts → node/module.d.ts +47 -195
  30. node v24.12/net.d.ts → node/net.d.ts +68 -189
  31. node v24.12/os.d.ts → node/os.d.ts +6 -6
  32. node v24.12/package.json → node/package.json +3 -3
  33. node/path/posix.d.ts +8 -0
  34. node/path/win32.d.ts +8 -0
  35. node/path.d.ts +187 -0
  36. node/perf_hooks.d.ts +643 -0
  37. node v24.12/process.d.ts → node/process.d.ts +219 -127
  38. node v24.12/punycode.d.ts → node/punycode.d.ts +5 -5
  39. node v24.12/querystring.d.ts → node/querystring.d.ts +4 -4
  40. node/quic.d.ts +910 -0
  41. node v24.12/readline/promises.d.ts → node/readline/promises.d.ts +3 -3
  42. node v24.12/readline.d.ts → node/readline.d.ts +68 -120
  43. node v24.12/repl.d.ts → node/repl.d.ts +75 -98
  44. node v24.12/sea.d.ts → node/sea.d.ts +1 -1
  45. node v24.12/sqlite.d.ts → node/sqlite.d.ts +137 -30
  46. node v24.12/stream/consumers.d.ts → node/stream/consumers.d.ts +10 -10
  47. node/stream/promises.d.ts +211 -0
  48. node/stream/web.d.ts +296 -0
  49. node v24.12/stream.d.ts → node/stream.d.ts +565 -478
  50. node v24.12/string_decoder.d.ts → node/string_decoder.d.ts +4 -4
  51. node/test/reporters.d.ts +96 -0
  52. node v24.12/test.d.ts → node/test.d.ts +134 -199
  53. node v24.12/timers/promises.d.ts → node/timers/promises.d.ts +4 -4
  54. node v24.12/timers.d.ts → node/timers.d.ts +4 -130
  55. node v24.12/tls.d.ts → node/tls.d.ts +109 -179
  56. node v24.12/trace_events.d.ts → node/trace_events.d.ts +9 -9
  57. node v24.12/ts5.6/buffer.buffer.d.ts → node/ts5.6/buffer.buffer.d.ts +1 -7
  58. node v24.12/ts5.6/index.d.ts → node/ts5.6/index.d.ts +15 -1
  59. node v24.12/ts5.7/index.d.ts → node/ts5.7/index.d.ts +15 -1
  60. node v24.12/tty.d.ts → node/tty.d.ts +58 -16
  61. node/url.d.ts +541 -0
  62. node/util/types.d.ts +558 -0
  63. node v24.12/util.d.ts → node/util.d.ts +150 -796
  64. node v24.12/v8.d.ts → node/v8.d.ts +31 -21
  65. node v24.12/vm.d.ts → node/vm.d.ts +43 -30
  66. node v24.12/wasi.d.ts → node/wasi.d.ts +4 -4
  67. node v24.12/web-globals/abortcontroller.d.ts → node/web-globals/abortcontroller.d.ts +27 -2
  68. node/web-globals/blob.d.ts +23 -0
  69. node/web-globals/console.d.ts +9 -0
  70. node v24.12/web-globals/crypto.d.ts → node/web-globals/crypto.d.ts +7 -0
  71. node/web-globals/encoding.d.ts +11 -0
  72. node v24.12/web-globals/events.d.ts → node/web-globals/events.d.ts +9 -0
  73. node v24.12/web-globals/fetch.d.ts → node/web-globals/fetch.d.ts +7 -0
  74. node/web-globals/importmeta.d.ts +13 -0
  75. node/web-globals/messaging.d.ts +23 -0
  76. node/web-globals/performance.d.ts +45 -0
  77. node/web-globals/streams.d.ts +115 -0
  78. node/web-globals/timers.d.ts +44 -0
  79. node/web-globals/url.d.ts +24 -0
  80. node v24.12/worker_threads.d.ts → node/worker_threads.d.ts +186 -363
  81. node v24.12/zlib.d.ts → node/zlib.d.ts +8 -71
  82. node v24.12/cluster.d.ts +0 -578
  83. node v24.12/console.d.ts +0 -453
  84. node v24.12/globals.typedarray.d.ts +0 -41
  85. node v24.12/path.d.ts +0 -200
  86. node v24.12/perf_hooks.d.ts +0 -1042
  87. node v24.12/stream/promises.d.ts +0 -90
  88. node v24.12/stream/web.d.ts +0 -573
  89. node v24.12/url.d.ts +0 -1057
  90. node v24.12/web-globals/streams.d.ts +0 -22
  91. {node v24.12 → node}/LICENSE +0 -0
  92. {node v24.12 → node}/compatibility/iterators.d.ts +0 -0
  93. {node v24.12 → node}/ts5.6/compatibility/float16array.d.ts +0 -0
  94. {node v24.12 → node}/ts5.6/globals.typedarray.d.ts +0 -0
  95. {node v24.12 → node}/ts5.7/compatibility/float16array.d.ts +0 -0
  96. {node v24.12 → node}/web-globals/domexception.d.ts +0 -0
  97. {node v24.12 → node}/web-globals/navigator.d.ts +0 -0
  98. {node v24.12 → node}/web-globals/storage.d.ts +0 -0
@@ -6,7 +6,12 @@
6
6
  * import sqlite from 'node:sqlite';
7
7
  * ```
8
8
  *
9
- * This module is only available under the `node:` scheme.
9
+ * This module is only available under the `node:` scheme. The following will not
10
+ * work:
11
+ *
12
+ * ```js
13
+ * import sqlite from 'sqlite';
14
+ * ```
10
15
  *
11
16
  * The following example shows the basic usage of the `node:sqlite` module to open
12
17
  * an in-memory database, write data to the database, and then read the data back.
@@ -35,7 +40,7 @@
35
40
  * ```
36
41
  * @since v22.5.0
37
42
  * @experimental
38
- * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/sqlite.js)
43
+ * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/sqlite.js)
39
44
  */
40
45
  declare module "node:sqlite" {
41
46
  import { PathLike } from "node:fs";
@@ -120,9 +125,9 @@ declare module "node:sqlite" {
120
125
  allowUnknownNamedParameters?: boolean | undefined;
121
126
  /**
122
127
  * If `true`, enables the defensive flag. When the defensive flag is enabled,
123
- * language features that allow ordinary SQL to deliberately corrupt the database
124
- * file are disabled. The defensive flag can also be set using `enableDefensive()`.
125
- * @since v24.12.0
128
+ * language features that allow ordinary SQL to deliberately corrupt the database file are disabled.
129
+ * The defensive flag can also be set using `enableDefensive()`.
130
+ * @since v25.1.0
126
131
  * @default true
127
132
  */
128
133
  defensive?: boolean | undefined;
@@ -228,6 +233,28 @@ declare module "node:sqlite" {
228
233
  */
229
234
  inverse?: ((accumulator: T, ...args: SQLOutputValue[]) => T) | undefined;
230
235
  }
236
+ interface PrepareOptions {
237
+ /**
238
+ * If `true`, integer fields are read as `BigInt`s.
239
+ * @since v25.5.0
240
+ */
241
+ readBigInts?: boolean | undefined;
242
+ /**
243
+ * If `true`, results are returned as arrays.
244
+ * @since v25.5.0
245
+ */
246
+ returnArrays?: boolean | undefined;
247
+ /**
248
+ * If `true`, allows binding named parameters without the prefix character.
249
+ * @since v25.5.0
250
+ */
251
+ allowBareNamedParameters?: boolean | undefined;
252
+ /**
253
+ * If `true`, unknown named parameters are ignored.
254
+ * @since v25.5.0
255
+ */
256
+ allowUnknownNamedParameters?: boolean | undefined;
257
+ }
231
258
  /**
232
259
  * This class represents a single [connection](https://www.sqlite.org/c3ref/sqlite3.html) to a SQLite database. All APIs
233
260
  * exposed by this class execute synchronously.
@@ -299,11 +326,9 @@ declare module "node:sqlite" {
299
326
  enableLoadExtension(allow: boolean): void;
300
327
  /**
301
328
  * Enables or disables the defensive flag. When the defensive flag is active,
302
- * language features that allow ordinary SQL to deliberately corrupt the
303
- * database file are disabled.
304
- * See [`SQLITE_DBCONFIG_DEFENSIVE`](https://www.sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive)
305
- * in the SQLite documentation for details.
306
- * @since v24.12.0
329
+ * language features that allow ordinary SQL to deliberately corrupt the database file are disabled.
330
+ * See [`SQLITE_DBCONFIG_DEFENSIVE`](https://www.sqlite.org/c3ref/c_dbconfig_defensive.html#sqlitedbconfigdefensive) in the SQLite documentation for details.
331
+ * @since v25.1.0
307
332
  * @param active Whether to set the defensive flag.
308
333
  */
309
334
  enableDefensive(active: boolean): void;
@@ -333,7 +358,7 @@ declare module "node:sqlite" {
333
358
  * @param func The JavaScript function to call when the SQLite
334
359
  * function is invoked. The return value of this function should be a valid
335
360
  * SQLite data type: see
336
- * [Type conversion between JavaScript and SQLite](https://nodejs.org/docs/latest-v24.x/api/sqlite.html#type-conversion-between-javascript-and-sqlite).
361
+ * [Type conversion between JavaScript and SQLite](https://nodejs.org/docs/latest-v25.x/api/sqlite.html#type-conversion-between-javascript-and-sqlite).
337
362
  * The result defaults to `NULL` if the return value is `undefined`.
338
363
  */
339
364
  function(
@@ -422,25 +447,79 @@ declare module "node:sqlite" {
422
447
  * around [`sqlite3_prepare_v2()`](https://www.sqlite.org/c3ref/prepare.html).
423
448
  * @since v22.5.0
424
449
  * @param sql A SQL string to compile to a prepared statement.
450
+ * @param options Optional configuration for the prepared statement.
425
451
  * @return The prepared statement.
426
452
  */
427
- prepare(sql: string): StatementSync;
453
+ prepare(sql: string, options?: PrepareOptions): StatementSync;
428
454
  /**
429
- * Creates a new {@link SQLTagStore `SQLTagStore`}, which is an LRU (Least Recently Used) cache for
430
- * storing prepared statements. This allows for the efficient reuse of prepared
431
- * statements by tagging them with a unique identifier.
455
+ * Creates a new {@link SQLTagStore}, which is a Least Recently Used (LRU) cache
456
+ * for storing prepared statements. This allows for the efficient reuse of
457
+ * prepared statements by tagging them with a unique identifier.
432
458
  *
433
459
  * When a tagged SQL literal is executed, the `SQLTagStore` checks if a prepared
434
- * statement for that specific SQL string already exists in the cache. If it does,
435
- * the cached statement is used. If not, a new prepared statement is created,
436
- * executed, and then stored in the cache for future use. This mechanism helps to
437
- * avoid the overhead of repeatedly parsing and preparing the same SQL statements.
460
+ * statement for the corresponding SQL query string already exists in the cache.
461
+ * If it does, the cached statement is used. If not, a new prepared statement is
462
+ * created, executed, and then stored in the cache for future use. This mechanism
463
+ * helps to avoid the overhead of repeatedly parsing and preparing the same SQL
464
+ * statements.
465
+ *
466
+ * Tagged statements bind the placeholder values from the template literal as
467
+ * parameters to the underlying prepared statement. For example:
468
+ *
469
+ * ```js
470
+ * sqlTagStore.get`SELECT ${value}`;
471
+ * ```
472
+ *
473
+ * is equivalent to:
474
+ *
475
+ * ```js
476
+ * db.prepare('SELECT ?').get(value);
477
+ * ```
478
+ *
479
+ * However, in the first example, the tag store will cache the underlying prepared
480
+ * statement for future use.
481
+ *
482
+ * > **Note:** The `${value}` syntax in tagged statements _binds_ a parameter to
483
+ * > the prepared statement. This differs from its behavior in _untagged_ template
484
+ * > literals, where it performs string interpolation.
485
+ * >
486
+ * > ```js
487
+ * > // This a safe example of binding a parameter to a tagged statement.
488
+ * > sqlTagStore.run`INSERT INTO t1 (id) VALUES (${id})`;
489
+ * >
490
+ * > // This is an *unsafe* example of an untagged template string.
491
+ * > // `id` is interpolated into the query text as a string.
492
+ * > // This can lead to SQL injection and data corruption.
493
+ * > db.run(`INSERT INTO t1 (id) VALUES (${id})`);
494
+ * > ```
495
+ *
496
+ * The tag store will match a statement from the cache if the query strings
497
+ * (including the positions of any bound placeholders) are identical.
498
+ *
499
+ * ```js
500
+ * // The following statements will match in the cache:
501
+ * sqlTagStore.get`SELECT * FROM t1 WHERE id = ${id} AND active = 1`;
502
+ * sqlTagStore.get`SELECT * FROM t1 WHERE id = ${12345} AND active = 1`;
503
+ *
504
+ * // The following statements will not match, as the query strings
505
+ * // and bound placeholders differ:
506
+ * sqlTagStore.get`SELECT * FROM t1 WHERE id = ${id} AND active = 1`;
507
+ * sqlTagStore.get`SELECT * FROM t1 WHERE id = 12345 AND active = 1`;
508
+ *
509
+ * // The following statements will not match, as matches are case-sensitive:
510
+ * sqlTagStore.get`SELECT * FROM t1 WHERE id = ${id} AND active = 1`;
511
+ * sqlTagStore.get`select * from t1 where id = ${id} and active = 1`;
512
+ * ```
513
+ *
514
+ * The only way of binding parameters in tagged statements is with the `${value}`
515
+ * syntax. Do not add parameter binding placeholders (`?` etc.) to the SQL query
516
+ * string itself.
438
517
  *
439
518
  * ```js
440
519
  * import { DatabaseSync } from 'node:sqlite';
441
520
  *
442
521
  * const db = new DatabaseSync(':memory:');
443
- * const sql = db.createTagStore();
522
+ * const sql = db.createSQLTagStore();
444
523
  *
445
524
  * db.exec('CREATE TABLE users (id INT, name TEXT)');
446
525
  *
@@ -450,8 +529,8 @@ declare module "node:sqlite" {
450
529
  * sql.run`INSERT INTO users VALUES (2, 'Bob')`;
451
530
  *
452
531
  * // Using the 'get' method to retrieve a single row.
453
- * const id = 1;
454
- * const user = sql.get`SELECT * FROM users WHERE id = ${id}`;
532
+ * const name = 'Alice';
533
+ * const user = sql.get`SELECT * FROM users WHERE name = ${name}`;
455
534
  * console.log(user); // { id: 1, name: 'Alice' }
456
535
  *
457
536
  * // Using the 'all' method to retrieve all rows.
@@ -463,7 +542,6 @@ declare module "node:sqlite" {
463
542
  * // ]
464
543
  * ```
465
544
  * @since v24.9.0
466
- * @param maxSize The maximum number of prepared statements to cache. **Default**: `1000`.
467
545
  * @returns A new SQL tag store for caching prepared statements.
468
546
  */
469
547
  createTagStore(maxSize?: number): SQLTagStore;
@@ -551,21 +629,29 @@ declare module "node:sqlite" {
551
629
  * This class represents a single LRU (Least Recently Used) cache for storing
552
630
  * prepared statements.
553
631
  *
554
- * Instances of this class are created via the database.createTagStore() method,
555
- * not by using a constructor. The store caches prepared statements based on the
556
- * provided SQL query string. When the same query is seen again, the store
632
+ * Instances of this class are created via the `database.createTagStore()`
633
+ * method, not by using a constructor. The store caches prepared statements based
634
+ * on the provided SQL query string. When the same query is seen again, the store
557
635
  * retrieves the cached statement and safely applies the new values through
558
636
  * parameter binding, thereby preventing attacks like SQL injection.
559
637
  *
560
638
  * The cache has a maxSize that defaults to 1000 statements, but a custom size can
561
- * be provided (e.g., database.createTagStore(100)). All APIs exposed by this
639
+ * be provided (e.g., `database.createTagStore(100)`). All APIs exposed by this
562
640
  * class execute synchronously.
563
641
  * @since v24.9.0
564
642
  */
565
643
  interface SQLTagStore {
566
644
  /**
567
- * Executes the given SQL query and returns all resulting rows as an array of objects.
645
+ * Executes the given SQL query and returns all resulting rows as an array of
646
+ * objects.
647
+ *
648
+ * This function is intended to be used as a template literal tag, not to be
649
+ * called directly.
568
650
  * @since v24.9.0
651
+ * @param stringElements Template literal elements containing the SQL
652
+ * query.
653
+ * @param boundParameters Parameter values to be bound to placeholders in the template string.
654
+ * @returns An array of objects representing the rows returned by the query.
569
655
  */
570
656
  all(
571
657
  stringElements: TemplateStringsArray,
@@ -573,7 +659,15 @@ declare module "node:sqlite" {
573
659
  ): Record<string, SQLOutputValue>[];
574
660
  /**
575
661
  * Executes the given SQL query and returns the first resulting row as an object.
662
+ *
663
+ * This function is intended to be used as a template literal tag, not to be
664
+ * called directly.
576
665
  * @since v24.9.0
666
+ * @param stringElements Template literal elements containing the SQL
667
+ * query.
668
+ * @param boundParameters Parameter values to be bound to placeholders in the template string.
669
+ * @returns An object representing the first row returned by
670
+ * the query, or `undefined` if no rows are returned.
577
671
  */
578
672
  get(
579
673
  stringElements: TemplateStringsArray,
@@ -581,7 +675,14 @@ declare module "node:sqlite" {
581
675
  ): Record<string, SQLOutputValue> | undefined;
582
676
  /**
583
677
  * Executes the given SQL query and returns an iterator over the resulting rows.
678
+ *
679
+ * This function is intended to be used as a template literal tag, not to be
680
+ * called directly.
584
681
  * @since v24.9.0
682
+ * @param stringElements Template literal elements containing the SQL
683
+ * query.
684
+ * @param boundParameters Parameter values to be bound to placeholders in the template string.
685
+ * @returns An iterator that yields objects representing the rows returned by the query.
585
686
  */
586
687
  iterate(
587
688
  stringElements: TemplateStringsArray,
@@ -589,15 +690,21 @@ declare module "node:sqlite" {
589
690
  ): NodeJS.Iterator<Record<string, SQLOutputValue>>;
590
691
  /**
591
692
  * Executes the given SQL query, which is expected to not return any rows (e.g., INSERT, UPDATE, DELETE).
693
+ *
694
+ * This function is intended to be used as a template literal tag, not to be
695
+ * called directly.
592
696
  * @since v24.9.0
697
+ * @param stringElements Template literal elements containing the SQL
698
+ * query.
699
+ * @param boundParameters Parameter values to be bound to placeholders in the template string.
700
+ * @returns An object containing information about the execution, including `changes` and `lastInsertRowid`.
593
701
  */
594
702
  run(stringElements: TemplateStringsArray, ...boundParameters: SQLInputValue[]): StatementResultingChanges;
595
703
  /**
596
704
  * A read-only property that returns the number of prepared statements currently in the cache.
597
705
  * @since v24.9.0
598
- * @returns The maximum number of prepared statements the cache can hold.
599
706
  */
600
- size(): number;
707
+ readonly size: number;
601
708
  /**
602
709
  * A read-only property that returns the maximum number of prepared statements the cache can hold.
603
710
  * @since v24.9.0
@@ -3,36 +3,36 @@
3
3
  * streams.
4
4
  * @since v16.7.0
5
5
  */
6
- declare module "stream/consumers" {
7
- import { Blob as NodeBlob, NonSharedBuffer } from "node:buffer";
8
- import { ReadableStream as WebReadableStream } from "node:stream/web";
6
+ declare module "node:stream/consumers" {
7
+ import { Blob, NonSharedBuffer } from "node:buffer";
8
+ import { ReadableStream } from "node:stream/web";
9
9
  /**
10
10
  * @since v16.7.0
11
11
  * @returns Fulfills with an `ArrayBuffer` containing the full contents of the stream.
12
12
  */
13
- function arrayBuffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<ArrayBuffer>;
13
+ function arrayBuffer(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<ArrayBuffer>;
14
14
  /**
15
15
  * @since v16.7.0
16
16
  * @returns Fulfills with a `Blob` containing the full contents of the stream.
17
17
  */
18
- function blob(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<NodeBlob>;
18
+ function blob(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<Blob>;
19
19
  /**
20
20
  * @since v16.7.0
21
21
  * @returns Fulfills with a `Buffer` containing the full contents of the stream.
22
22
  */
23
- function buffer(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<NonSharedBuffer>;
23
+ function buffer(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<NonSharedBuffer>;
24
24
  /**
25
25
  * @since v16.7.0
26
26
  * @returns Fulfills with the contents of the stream parsed as a
27
27
  * UTF-8 encoded string that is then passed through `JSON.parse()`.
28
28
  */
29
- function json(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<unknown>;
29
+ function json(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<unknown>;
30
30
  /**
31
31
  * @since v16.7.0
32
32
  * @returns Fulfills with the contents of the stream parsed as a UTF-8 encoded string.
33
33
  */
34
- function text(stream: WebReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<string>;
34
+ function text(stream: ReadableStream | NodeJS.ReadableStream | AsyncIterable<any>): Promise<string>;
35
35
  }
36
- declare module "node:stream/consumers" {
37
- export * from "stream/consumers";
36
+ declare module "stream/consumers" {
37
+ export * from "node:stream/consumers";
38
38
  }
@@ -0,0 +1,211 @@
1
+ declare module "node:stream/promises" {
2
+ import { Abortable } from "node:events";
3
+ import {
4
+ FinishedOptions as _FinishedOptions,
5
+ PipelineDestination,
6
+ PipelineSource,
7
+ PipelineTransform,
8
+ } from "node:stream";
9
+ import { ReadableStream, WritableStream } from "node:stream/web";
10
+ interface FinishedOptions extends _FinishedOptions {
11
+ /**
12
+ * If true, removes the listeners registered by this function before the promise is fulfilled.
13
+ * @default false
14
+ */
15
+ cleanup?: boolean | undefined;
16
+ }
17
+ /**
18
+ * ```js
19
+ * import { finished } from 'node:stream/promises';
20
+ * import { createReadStream } from 'node:fs';
21
+ *
22
+ * const rs = createReadStream('archive.tar');
23
+ *
24
+ * async function run() {
25
+ * await finished(rs);
26
+ * console.log('Stream is done reading.');
27
+ * }
28
+ *
29
+ * run().catch(console.error);
30
+ * rs.resume(); // Drain the stream.
31
+ * ```
32
+ *
33
+ * The `finished` API also provides a [callback version](https://nodejs.org/docs/latest-v25.x/api/stream.html#streamfinishedstream-options-callback).
34
+ *
35
+ * `stream.finished()` leaves dangling event listeners (in particular
36
+ * `'error'`, `'end'`, `'finish'` and `'close'`) after the returned promise is
37
+ * resolved or rejected. The reason for this is so that unexpected `'error'`
38
+ * events (due to incorrect stream implementations) do not cause unexpected
39
+ * crashes. If this is unwanted behavior then `options.cleanup` should be set to
40
+ * `true`:
41
+ *
42
+ * ```js
43
+ * await finished(rs, { cleanup: true });
44
+ * ```
45
+ * @since v15.0.0
46
+ * @returns Fulfills when the stream is no longer readable or writable.
47
+ */
48
+ function finished(
49
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | ReadableStream | WritableStream,
50
+ options?: FinishedOptions,
51
+ ): Promise<void>;
52
+ interface PipelineOptions extends Abortable {
53
+ end?: boolean | undefined;
54
+ }
55
+ type PipelineResult<S extends PipelineDestination<any, any>> = S extends (...args: any[]) => PromiseLike<infer R>
56
+ ? Promise<R>
57
+ : Promise<void>;
58
+ /**
59
+ * ```js
60
+ * import { pipeline } from 'node:stream/promises';
61
+ * import { createReadStream, createWriteStream } from 'node:fs';
62
+ * import { createGzip } from 'node:zlib';
63
+ *
64
+ * await pipeline(
65
+ * createReadStream('archive.tar'),
66
+ * createGzip(),
67
+ * createWriteStream('archive.tar.gz'),
68
+ * );
69
+ * console.log('Pipeline succeeded.');
70
+ * ```
71
+ *
72
+ * To use an `AbortSignal`, pass it inside an options object, as the last argument.
73
+ * When the signal is aborted, `destroy` will be called on the underlying pipeline,
74
+ * with an `AbortError`.
75
+ *
76
+ * ```js
77
+ * import { pipeline } from 'node:stream/promises';
78
+ * import { createReadStream, createWriteStream } from 'node:fs';
79
+ * import { createGzip } from 'node:zlib';
80
+ *
81
+ * const ac = new AbortController();
82
+ * const { signal } = ac;
83
+ * setImmediate(() => ac.abort());
84
+ * try {
85
+ * await pipeline(
86
+ * createReadStream('archive.tar'),
87
+ * createGzip(),
88
+ * createWriteStream('archive.tar.gz'),
89
+ * { signal },
90
+ * );
91
+ * } catch (err) {
92
+ * console.error(err); // AbortError
93
+ * }
94
+ * ```
95
+ *
96
+ * The `pipeline` API also supports async generators:
97
+ *
98
+ * ```js
99
+ * import { pipeline } from 'node:stream/promises';
100
+ * import { createReadStream, createWriteStream } from 'node:fs';
101
+ *
102
+ * await pipeline(
103
+ * createReadStream('lowercase.txt'),
104
+ * async function* (source, { signal }) {
105
+ * source.setEncoding('utf8'); // Work with strings rather than `Buffer`s.
106
+ * for await (const chunk of source) {
107
+ * yield await processChunk(chunk, { signal });
108
+ * }
109
+ * },
110
+ * createWriteStream('uppercase.txt'),
111
+ * );
112
+ * console.log('Pipeline succeeded.');
113
+ * ```
114
+ *
115
+ * Remember to handle the `signal` argument passed into the async generator.
116
+ * Especially in the case where the async generator is the source for the
117
+ * pipeline (i.e. first argument) or the pipeline will never complete.
118
+ *
119
+ * ```js
120
+ * import { pipeline } from 'node:stream/promises';
121
+ * import fs from 'node:fs';
122
+ * await pipeline(
123
+ * async function* ({ signal }) {
124
+ * await someLongRunningfn({ signal });
125
+ * yield 'asd';
126
+ * },
127
+ * fs.createWriteStream('uppercase.txt'),
128
+ * );
129
+ * console.log('Pipeline succeeded.');
130
+ * ```
131
+ *
132
+ * The `pipeline` API provides [callback version](https://nodejs.org/docs/latest-v25.x/api/stream.html#streampipelinesource-transforms-destination-callback):
133
+ * @since v15.0.0
134
+ * @returns Fulfills when the pipeline is complete.
135
+ */
136
+ function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
137
+ source: A,
138
+ destination: B,
139
+ options?: PipelineOptions,
140
+ ): PipelineResult<B>;
141
+ function pipeline<
142
+ A extends PipelineSource<any>,
143
+ T1 extends PipelineTransform<A, any>,
144
+ B extends PipelineDestination<T1, any>,
145
+ >(
146
+ source: A,
147
+ transform1: T1,
148
+ destination: B,
149
+ options?: PipelineOptions,
150
+ ): PipelineResult<B>;
151
+ function pipeline<
152
+ A extends PipelineSource<any>,
153
+ T1 extends PipelineTransform<A, any>,
154
+ T2 extends PipelineTransform<T1, any>,
155
+ B extends PipelineDestination<T2, any>,
156
+ >(
157
+ source: A,
158
+ transform1: T1,
159
+ transform2: T2,
160
+ destination: B,
161
+ options?: PipelineOptions,
162
+ ): PipelineResult<B>;
163
+ function pipeline<
164
+ A extends PipelineSource<any>,
165
+ T1 extends PipelineTransform<A, any>,
166
+ T2 extends PipelineTransform<T1, any>,
167
+ T3 extends PipelineTransform<T2, any>,
168
+ B extends PipelineDestination<T3, any>,
169
+ >(
170
+ source: A,
171
+ transform1: T1,
172
+ transform2: T2,
173
+ transform3: T3,
174
+ destination: B,
175
+ options?: PipelineOptions,
176
+ ): PipelineResult<B>;
177
+ function pipeline<
178
+ A extends PipelineSource<any>,
179
+ T1 extends PipelineTransform<A, any>,
180
+ T2 extends PipelineTransform<T1, any>,
181
+ T3 extends PipelineTransform<T2, any>,
182
+ T4 extends PipelineTransform<T3, any>,
183
+ B extends PipelineDestination<T4, any>,
184
+ >(
185
+ source: A,
186
+ transform1: T1,
187
+ transform2: T2,
188
+ transform3: T3,
189
+ transform4: T4,
190
+ destination: B,
191
+ options?: PipelineOptions,
192
+ ): PipelineResult<B>;
193
+ function pipeline(
194
+ streams: readonly [PipelineSource<any>, ...PipelineTransform<any, any>[], PipelineDestination<any, any>],
195
+ options?: PipelineOptions,
196
+ ): Promise<void>;
197
+ function pipeline(
198
+ ...streams: [PipelineSource<any>, ...PipelineTransform<any, any>[], PipelineDestination<any, any>]
199
+ ): Promise<void>;
200
+ function pipeline(
201
+ ...streams: [
202
+ PipelineSource<any>,
203
+ ...PipelineTransform<any, any>[],
204
+ PipelineDestination<any, any>,
205
+ options: PipelineOptions,
206
+ ]
207
+ ): Promise<void>;
208
+ }
209
+ declare module "stream/promises" {
210
+ export * from "node:stream/promises";
211
+ }