@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
@@ -2,10 +2,10 @@
2
2
  * A stream is an abstract interface for working with streaming data in Node.js.
3
3
  * The `node:stream` module provides an API for implementing the stream interface.
4
4
  *
5
- * There are many stream objects provided by Node.js. For instance, a [request to an HTTP server](https://nodejs.org/docs/latest-v24.x/api/http.html#class-httpincomingmessage)
6
- * and [`process.stdout`](https://nodejs.org/docs/latest-v24.x/api/process.html#processstdout) are both stream instances.
5
+ * There are many stream objects provided by Node.js. For instance, a [request to an HTTP server](https://nodejs.org/docs/latest-v25.x/api/http.html#class-httpincomingmessage)
6
+ * and [`process.stdout`](https://nodejs.org/docs/latest-v25.x/api/process.html#processstdout) are both stream instances.
7
7
  *
8
- * Streams can be readable, writable, or both. All streams are instances of [`EventEmitter`](https://nodejs.org/docs/latest-v24.x/api/events.html#class-eventemitter).
8
+ * Streams can be readable, writable, or both. All streams are instances of [`EventEmitter`](https://nodejs.org/docs/latest-v25.x/api/events.html#class-eventemitter).
9
9
  *
10
10
  * To access the `node:stream` module:
11
11
  *
@@ -15,32 +15,33 @@
15
15
  *
16
16
  * The `node:stream` module is useful for creating new types of stream instances.
17
17
  * It is usually not necessary to use the `node:stream` module to consume streams.
18
- * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/stream.js)
18
+ * @see [source](https://github.com/nodejs/node/blob/v25.x/lib/stream.js)
19
19
  */
20
- declare module "stream" {
20
+ declare module "node:stream" {
21
+ import { Blob } from "node:buffer";
21
22
  import { Abortable, EventEmitter } from "node:events";
22
- import { Blob as NodeBlob } from "node:buffer";
23
- import * as streamPromises from "node:stream/promises";
24
- import * as streamWeb from "node:stream/web";
25
-
26
- type ComposeFnParam = (source: any) => void;
27
-
23
+ import * as promises from "node:stream/promises";
24
+ import * as web from "node:stream/web";
28
25
  class Stream extends EventEmitter {
26
+ /**
27
+ * @since v0.9.4
28
+ */
29
29
  pipe<T extends NodeJS.WritableStream>(
30
30
  destination: T,
31
- options?: {
32
- end?: boolean | undefined;
33
- },
34
- ): T;
35
- compose<T extends NodeJS.ReadableStream>(
36
- stream: T | ComposeFnParam | Iterable<T> | AsyncIterable<T>,
37
- options?: { signal: AbortSignal },
31
+ options?: Stream.PipeOptions,
38
32
  ): T;
39
33
  }
40
34
  namespace Stream {
41
- export { Stream, streamPromises as promises };
35
+ export { promises, Stream };
42
36
  }
43
37
  namespace Stream {
38
+ interface PipeOptions {
39
+ /**
40
+ * End the writer when the reader ends.
41
+ * @default true
42
+ */
43
+ end?: boolean | undefined;
44
+ }
44
45
  interface StreamOptions<T extends Stream> extends Abortable {
45
46
  emitClose?: boolean | undefined;
46
47
  highWaterMark?: number | undefined;
@@ -53,19 +54,49 @@ declare module "stream" {
53
54
  encoding?: BufferEncoding | undefined;
54
55
  read?: ((this: T, size: number) => void) | undefined;
55
56
  }
56
- interface ArrayOptions {
57
+ interface ReadableIteratorOptions {
57
58
  /**
58
- * The maximum concurrent invocations of `fn` to call on the stream at once.
59
+ * When set to `false`, calling `return` on the async iterator,
60
+ * or exiting a `for await...of` iteration using a `break`,
61
+ * `return`, or `throw` will not destroy the stream.
62
+ * @default true
63
+ */
64
+ destroyOnReturn?: boolean | undefined;
65
+ }
66
+ interface ReadableOperatorOptions extends Abortable {
67
+ /**
68
+ * The maximum concurrent invocations of `fn` to call
69
+ * on the stream at once.
59
70
  * @default 1
60
71
  */
61
72
  concurrency?: number | undefined;
62
- /** Allows destroying the stream if the signal is aborted. */
63
- signal?: AbortSignal | undefined;
73
+ /**
74
+ * How many items to buffer while waiting for user consumption
75
+ * of the output.
76
+ * @default concurrency * 2 - 1
77
+ */
78
+ highWaterMark?: number | undefined;
79
+ }
80
+ /** @deprecated Use `ReadableOperatorOptions` instead. */
81
+ interface ArrayOptions extends ReadableOperatorOptions {}
82
+ interface ReadableToWebOptions {
83
+ strategy?: web.QueuingStrategy | undefined;
84
+ type?: web.ReadableStreamType | undefined;
85
+ }
86
+ interface ReadableEventMap {
87
+ "close": [];
88
+ "data": [chunk: any];
89
+ "end": [];
90
+ "error": [err: Error];
91
+ "pause": [];
92
+ "readable": [];
93
+ "resume": [];
64
94
  }
65
95
  /**
66
96
  * @since v0.9.4
67
97
  */
68
98
  class Readable extends Stream implements NodeJS.ReadableStream {
99
+ constructor(options?: ReadableOptions);
69
100
  /**
70
101
  * A utility method for creating Readable Streams out of iterators.
71
102
  * @since v12.3.0, v10.17.0
@@ -78,7 +109,7 @@ declare module "stream" {
78
109
  * @since v17.0.0
79
110
  */
80
111
  static fromWeb(
81
- readableStream: streamWeb.ReadableStream,
112
+ readableStream: web.ReadableStream,
82
113
  options?: Pick<ReadableOptions, "encoding" | "highWaterMark" | "objectMode" | "signal">,
83
114
  ): Readable;
84
115
  /**
@@ -86,16 +117,14 @@ declare module "stream" {
86
117
  * @since v17.0.0
87
118
  */
88
119
  static toWeb(
89
- streamReadable: Readable,
90
- options?: {
91
- strategy?: streamWeb.QueuingStrategy | undefined;
92
- },
93
- ): streamWeb.ReadableStream;
120
+ streamReadable: NodeJS.ReadableStream,
121
+ options?: ReadableToWebOptions,
122
+ ): web.ReadableStream;
94
123
  /**
95
124
  * Returns whether the stream has been read from or cancelled.
96
125
  * @since v16.8.0
97
126
  */
98
- static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
127
+ static isDisturbed(stream: NodeJS.ReadableStream | web.ReadableStream): boolean;
99
128
  /**
100
129
  * Returns whether the stream was destroyed or errored before emitting `'end'`.
101
130
  * @since v16.8.0
@@ -118,16 +147,16 @@ declare module "stream" {
118
147
  */
119
148
  readonly readableEncoding: BufferEncoding | null;
120
149
  /**
121
- * Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v24.x/api/stream.html#event-end) event is emitted.
150
+ * Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v25.x/api/stream.html#event-end) event is emitted.
122
151
  * @since v12.9.0
123
152
  */
124
153
  readonly readableEnded: boolean;
125
154
  /**
126
155
  * This property reflects the current state of a `Readable` stream as described
127
- * in the [Three states](https://nodejs.org/docs/latest-v24.x/api/stream.html#three-states) section.
156
+ * in the [Three states](https://nodejs.org/docs/latest-v25.x/api/stream.html#three-states) section.
128
157
  * @since v9.4.0
129
158
  */
130
- readonly readableFlowing: boolean | null;
159
+ readableFlowing: boolean | null;
131
160
  /**
132
161
  * Returns the value of `highWaterMark` passed when creating this `Readable`.
133
162
  * @since v9.3.0
@@ -160,7 +189,6 @@ declare module "stream" {
160
189
  * @since v18.0.0
161
190
  */
162
191
  readonly errored: Error | null;
163
- constructor(opts?: ReadableOptions);
164
192
  _construct?(callback: (error?: Error | null) => void): void;
165
193
  _read(size: number): void;
166
194
  /**
@@ -444,16 +472,46 @@ declare module "stream" {
444
472
  */
445
473
  wrap(stream: NodeJS.ReadableStream): this;
446
474
  push(chunk: any, encoding?: BufferEncoding): boolean;
475
+ /**
476
+ * ```js
477
+ * import { Readable } from 'node:stream';
478
+ *
479
+ * async function* splitToWords(source) {
480
+ * for await (const chunk of source) {
481
+ * const words = String(chunk).split(' ');
482
+ *
483
+ * for (const word of words) {
484
+ * yield word;
485
+ * }
486
+ * }
487
+ * }
488
+ *
489
+ * const wordsStream = Readable.from(['text passed through', 'composed stream']).compose(splitToWords);
490
+ * const words = await wordsStream.toArray();
491
+ *
492
+ * console.log(words); // prints ['text', 'passed', 'through', 'composed', 'stream']
493
+ * ```
494
+ *
495
+ * `readable.compose(s)` is equivalent to `stream.compose(readable, s)`.
496
+ *
497
+ * This method also allows for an `AbortSignal` to be provided, which will destroy
498
+ * the composed stream when aborted.
499
+ *
500
+ * See [`stream.compose(...streams)`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streamcomposestreams) for more information.
501
+ * @since v19.1.0, v18.13.0
502
+ * @returns a stream composed with the stream `stream`.
503
+ */
504
+ compose(
505
+ stream: NodeJS.WritableStream | web.WritableStream | web.TransformStream | ((source: any) => void),
506
+ options?: Abortable,
507
+ ): Duplex;
447
508
  /**
448
509
  * The iterator created by this method gives users the option to cancel the destruction
449
510
  * of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
450
511
  * or if the iterator should destroy the stream if the stream emitted an error during iteration.
451
512
  * @since v16.3.0
452
- * @param options.destroyOnReturn When set to `false`, calling `return` on the async iterator,
453
- * or exiting a `for await...of` iteration using a `break`, `return`, or `throw` will not destroy the stream.
454
- * **Default: `true`**.
455
513
  */
456
- iterator(options?: { destroyOnReturn?: boolean }): NodeJS.AsyncIterator<any>;
514
+ iterator(options?: ReadableIteratorOptions): NodeJS.AsyncIterator<any>;
457
515
  /**
458
516
  * This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
459
517
  * If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
@@ -461,7 +519,7 @@ declare module "stream" {
461
519
  * @param fn a function to map over every chunk in the stream. Async or not.
462
520
  * @returns a stream mapped with the function *fn*.
463
521
  */
464
- map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
522
+ map(fn: (data: any, options?: Abortable) => any, options?: ReadableOperatorOptions): Readable;
465
523
  /**
466
524
  * This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
467
525
  * and if it returns a truthy value, the chunk will be passed to the result stream.
@@ -471,8 +529,8 @@ declare module "stream" {
471
529
  * @returns a stream filtered with the predicate *fn*.
472
530
  */
473
531
  filter(
474
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
475
- options?: ArrayOptions,
532
+ fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
533
+ options?: ReadableOperatorOptions,
476
534
  ): Readable;
477
535
  /**
478
536
  * This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
@@ -490,8 +548,8 @@ declare module "stream" {
490
548
  * @returns a promise for when the stream has finished.
491
549
  */
492
550
  forEach(
493
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>,
494
- options?: ArrayOptions,
551
+ fn: (data: any, options?: Abortable) => void | Promise<void>,
552
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
495
553
  ): Promise<void>;
496
554
  /**
497
555
  * This method allows easily obtaining the contents of a stream.
@@ -501,7 +559,7 @@ declare module "stream" {
501
559
  * @since v17.5.0
502
560
  * @returns a promise containing an array with the contents of the stream.
503
561
  */
504
- toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
562
+ toArray(options?: Abortable): Promise<any[]>;
505
563
  /**
506
564
  * This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
507
565
  * until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
@@ -512,8 +570,8 @@ declare module "stream" {
512
570
  * @returns a promise evaluating to `true` if *fn* returned a truthy value for at least one of the chunks.
513
571
  */
514
572
  some(
515
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
516
- options?: ArrayOptions,
573
+ fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
574
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
517
575
  ): Promise<boolean>;
518
576
  /**
519
577
  * This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
@@ -526,12 +584,12 @@ declare module "stream" {
526
584
  * or `undefined` if no element was found.
527
585
  */
528
586
  find<T>(
529
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T,
530
- options?: ArrayOptions,
587
+ fn: (data: any, options?: Abortable) => data is T,
588
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
531
589
  ): Promise<T | undefined>;
532
590
  find(
533
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
534
- options?: ArrayOptions,
591
+ fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
592
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
535
593
  ): Promise<any>;
536
594
  /**
537
595
  * This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
@@ -543,8 +601,8 @@ declare module "stream" {
543
601
  * @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
544
602
  */
545
603
  every(
546
- fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
547
- options?: ArrayOptions,
604
+ fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
605
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
548
606
  ): Promise<boolean>;
549
607
  /**
550
608
  * This method returns a new stream by applying the given callback to each chunk of the stream
@@ -556,28 +614,24 @@ declare module "stream" {
556
614
  * @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
557
615
  * @returns a stream flat-mapped with the function *fn*.
558
616
  */
559
- flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
617
+ flatMap(
618
+ fn: (data: any, options?: Abortable) => any,
619
+ options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
620
+ ): Readable;
560
621
  /**
561
622
  * This method returns a new stream with the first *limit* chunks dropped from the start.
562
623
  * @since v17.5.0
563
624
  * @param limit the number of chunks to drop from the readable.
564
625
  * @returns a stream with *limit* chunks dropped from the start.
565
626
  */
566
- drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
627
+ drop(limit: number, options?: Abortable): Readable;
567
628
  /**
568
629
  * This method returns a new stream with the first *limit* chunks.
569
630
  * @since v17.5.0
570
631
  * @param limit the number of chunks to take from the readable.
571
632
  * @returns a stream with *limit* chunks taken.
572
633
  */
573
- take(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
574
- /**
575
- * This method returns a new stream with chunks of the underlying stream paired with a counter
576
- * in the form `[index, chunk]`. The first index value is `0` and it increases by 1 for each chunk produced.
577
- * @since v17.5.0
578
- * @returns a stream of indexed pairs.
579
- */
580
- asIndexedPairs(options?: Pick<ArrayOptions, "signal">): Readable;
634
+ take(limit: number, options?: Abortable): Readable;
581
635
  /**
582
636
  * This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
583
637
  * on the previous element. It returns a promise for the final value of the reduction.
@@ -592,15 +646,11 @@ declare module "stream" {
592
646
  * @param initial the initial value to use in the reduction.
593
647
  * @returns a promise for the final value of the reduction.
594
648
  */
595
- reduce<T = any>(
596
- fn: (previous: any, data: any, options?: Pick<ArrayOptions, "signal">) => T,
597
- initial?: undefined,
598
- options?: Pick<ArrayOptions, "signal">,
599
- ): Promise<T>;
600
- reduce<T = any>(
601
- fn: (previous: T, data: any, options?: Pick<ArrayOptions, "signal">) => T,
649
+ reduce<T>(fn: (previous: any, data: any, options?: Abortable) => T): Promise<T>;
650
+ reduce<T>(
651
+ fn: (previous: T, data: any, options?: Abortable) => T,
602
652
  initial: T,
603
- options?: Pick<ArrayOptions, "signal">,
653
+ options?: Abortable,
604
654
  ): Promise<T>;
605
655
  _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
606
656
  /**
@@ -626,73 +676,51 @@ declare module "stream" {
626
676
  * @since v20.4.0
627
677
  */
628
678
  [Symbol.asyncDispose](): Promise<void>;
629
- /**
630
- * Event emitter
631
- * The defined events on documents including:
632
- * 1. close
633
- * 2. data
634
- * 3. end
635
- * 4. error
636
- * 5. pause
637
- * 6. readable
638
- * 7. resume
639
- */
640
- addListener(event: "close", listener: () => void): this;
641
- addListener(event: "data", listener: (chunk: any) => void): this;
642
- addListener(event: "end", listener: () => void): this;
643
- addListener(event: "error", listener: (err: Error) => void): this;
644
- addListener(event: "pause", listener: () => void): this;
645
- addListener(event: "readable", listener: () => void): this;
646
- addListener(event: "resume", listener: () => void): this;
647
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
648
- emit(event: "close"): boolean;
649
- emit(event: "data", chunk: any): boolean;
650
- emit(event: "end"): boolean;
651
- emit(event: "error", err: Error): boolean;
652
- emit(event: "pause"): boolean;
653
- emit(event: "readable"): boolean;
654
- emit(event: "resume"): boolean;
655
- emit(event: string | symbol, ...args: any[]): boolean;
656
- on(event: "close", listener: () => void): this;
657
- on(event: "data", listener: (chunk: any) => void): this;
658
- on(event: "end", listener: () => void): this;
659
- on(event: "error", listener: (err: Error) => void): this;
660
- on(event: "pause", listener: () => void): this;
661
- on(event: "readable", listener: () => void): this;
662
- on(event: "resume", listener: () => void): this;
663
- on(event: string | symbol, listener: (...args: any[]) => void): this;
664
- once(event: "close", listener: () => void): this;
665
- once(event: "data", listener: (chunk: any) => void): this;
666
- once(event: "end", listener: () => void): this;
667
- once(event: "error", listener: (err: Error) => void): this;
668
- once(event: "pause", listener: () => void): this;
669
- once(event: "readable", listener: () => void): this;
670
- once(event: "resume", listener: () => void): this;
671
- once(event: string | symbol, listener: (...args: any[]) => void): this;
672
- prependListener(event: "close", listener: () => void): this;
673
- prependListener(event: "data", listener: (chunk: any) => void): this;
674
- prependListener(event: "end", listener: () => void): this;
675
- prependListener(event: "error", listener: (err: Error) => void): this;
676
- prependListener(event: "pause", listener: () => void): this;
677
- prependListener(event: "readable", listener: () => void): this;
678
- prependListener(event: "resume", listener: () => void): this;
679
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
680
- prependOnceListener(event: "close", listener: () => void): this;
681
- prependOnceListener(event: "data", listener: (chunk: any) => void): this;
682
- prependOnceListener(event: "end", listener: () => void): this;
683
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
684
- prependOnceListener(event: "pause", listener: () => void): this;
685
- prependOnceListener(event: "readable", listener: () => void): this;
686
- prependOnceListener(event: "resume", listener: () => void): this;
687
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
688
- removeListener(event: "close", listener: () => void): this;
689
- removeListener(event: "data", listener: (chunk: any) => void): this;
690
- removeListener(event: "end", listener: () => void): this;
691
- removeListener(event: "error", listener: (err: Error) => void): this;
692
- removeListener(event: "pause", listener: () => void): this;
693
- removeListener(event: "readable", listener: () => void): this;
694
- removeListener(event: "resume", listener: () => void): this;
695
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
679
+ // #region InternalEventEmitter
680
+ addListener<E extends keyof ReadableEventMap>(
681
+ eventName: E,
682
+ listener: (...args: ReadableEventMap[E]) => void,
683
+ ): this;
684
+ addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
685
+ emit<E extends keyof ReadableEventMap>(eventName: E, ...args: ReadableEventMap[E]): boolean;
686
+ emit(eventName: string | symbol, ...args: any[]): boolean;
687
+ listenerCount<E extends keyof ReadableEventMap>(
688
+ eventName: E,
689
+ listener?: (...args: ReadableEventMap[E]) => void,
690
+ ): number;
691
+ listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
692
+ listeners<E extends keyof ReadableEventMap>(eventName: E): ((...args: ReadableEventMap[E]) => void)[];
693
+ listeners(eventName: string | symbol): ((...args: any[]) => void)[];
694
+ off<E extends keyof ReadableEventMap>(eventName: E, listener: (...args: ReadableEventMap[E]) => void): this;
695
+ off(eventName: string | symbol, listener: (...args: any[]) => void): this;
696
+ on<E extends keyof ReadableEventMap>(eventName: E, listener: (...args: ReadableEventMap[E]) => void): this;
697
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
698
+ once<E extends keyof ReadableEventMap>(
699
+ eventName: E,
700
+ listener: (...args: ReadableEventMap[E]) => void,
701
+ ): this;
702
+ once(eventName: string | symbol, listener: (...args: any[]) => void): this;
703
+ prependListener<E extends keyof ReadableEventMap>(
704
+ eventName: E,
705
+ listener: (...args: ReadableEventMap[E]) => void,
706
+ ): this;
707
+ prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
708
+ prependOnceListener<E extends keyof ReadableEventMap>(
709
+ eventName: E,
710
+ listener: (...args: ReadableEventMap[E]) => void,
711
+ ): this;
712
+ prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
713
+ rawListeners<E extends keyof ReadableEventMap>(eventName: E): ((...args: ReadableEventMap[E]) => void)[];
714
+ rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
715
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
716
+ removeAllListeners<E extends keyof ReadableEventMap>(eventName?: E): this;
717
+ removeAllListeners(eventName?: string | symbol): this;
718
+ removeListener<E extends keyof ReadableEventMap>(
719
+ eventName: E,
720
+ listener: (...args: ReadableEventMap[E]) => void,
721
+ ): this;
722
+ removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
723
+ // #endregion
696
724
  }
697
725
  interface WritableOptions<T extends Writable = Writable> extends StreamOptions<T> {
698
726
  decodeStrings?: boolean | undefined;
@@ -708,38 +736,47 @@ declare module "stream" {
708
736
  writev?:
709
737
  | ((
710
738
  this: T,
711
- chunks: Array<{
739
+ chunks: {
712
740
  chunk: any;
713
741
  encoding: BufferEncoding;
714
- }>,
742
+ }[],
715
743
  callback: (error?: Error | null) => void,
716
744
  ) => void)
717
745
  | undefined;
718
746
  final?: ((this: T, callback: (error?: Error | null) => void) => void) | undefined;
719
747
  }
748
+ interface WritableEventMap {
749
+ "close": [];
750
+ "drain": [];
751
+ "error": [err: Error];
752
+ "finish": [];
753
+ "pipe": [src: Readable];
754
+ "unpipe": [src: Readable];
755
+ }
720
756
  /**
721
757
  * @since v0.9.4
722
758
  */
723
759
  class Writable extends Stream implements NodeJS.WritableStream {
760
+ constructor(options?: WritableOptions);
724
761
  /**
725
762
  * A utility method for creating a `Writable` from a web `WritableStream`.
726
763
  * @since v17.0.0
727
764
  */
728
765
  static fromWeb(
729
- writableStream: streamWeb.WritableStream,
766
+ writableStream: web.WritableStream,
730
767
  options?: Pick<WritableOptions, "decodeStrings" | "highWaterMark" | "objectMode" | "signal">,
731
768
  ): Writable;
732
769
  /**
733
770
  * A utility method for creating a web `WritableStream` from a `Writable`.
734
771
  * @since v17.0.0
735
772
  */
736
- static toWeb(streamWritable: Writable): streamWeb.WritableStream;
773
+ static toWeb(streamWritable: NodeJS.WritableStream): web.WritableStream;
737
774
  /**
738
775
  * Is `true` if it is safe to call `writable.write()`, which means
739
776
  * the stream has not been destroyed, errored, or ended.
740
777
  * @since v11.4.0
741
778
  */
742
- readonly writable: boolean;
779
+ writable: boolean;
743
780
  /**
744
781
  * Returns whether the stream was destroyed or errored before emitting `'finish'`.
745
782
  * @since v18.0.0, v16.17.0
@@ -799,13 +836,12 @@ declare module "stream" {
799
836
  * @since v15.2.0, v14.17.0
800
837
  */
801
838
  readonly writableNeedDrain: boolean;
802
- constructor(opts?: WritableOptions);
803
839
  _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
804
840
  _writev?(
805
- chunks: Array<{
841
+ chunks: {
806
842
  chunk: any;
807
843
  encoding: BufferEncoding;
808
- }>,
844
+ }[],
809
845
  callback: (error?: Error | null) => void,
810
846
  ): void;
811
847
  _construct?(callback: (error?: Error | null) => void): void;
@@ -972,65 +1008,51 @@ declare module "stream" {
972
1008
  * @since v22.4.0, v20.16.0
973
1009
  */
974
1010
  [Symbol.asyncDispose](): Promise<void>;
975
- /**
976
- * Event emitter
977
- * The defined events on documents including:
978
- * 1. close
979
- * 2. drain
980
- * 3. error
981
- * 4. finish
982
- * 5. pipe
983
- * 6. unpipe
984
- */
985
- addListener(event: "close", listener: () => void): this;
986
- addListener(event: "drain", listener: () => void): this;
987
- addListener(event: "error", listener: (err: Error) => void): this;
988
- addListener(event: "finish", listener: () => void): this;
989
- addListener(event: "pipe", listener: (src: Readable) => void): this;
990
- addListener(event: "unpipe", listener: (src: Readable) => void): this;
991
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
992
- emit(event: "close"): boolean;
993
- emit(event: "drain"): boolean;
994
- emit(event: "error", err: Error): boolean;
995
- emit(event: "finish"): boolean;
996
- emit(event: "pipe", src: Readable): boolean;
997
- emit(event: "unpipe", src: Readable): boolean;
998
- emit(event: string | symbol, ...args: any[]): boolean;
999
- on(event: "close", listener: () => void): this;
1000
- on(event: "drain", listener: () => void): this;
1001
- on(event: "error", listener: (err: Error) => void): this;
1002
- on(event: "finish", listener: () => void): this;
1003
- on(event: "pipe", listener: (src: Readable) => void): this;
1004
- on(event: "unpipe", listener: (src: Readable) => void): this;
1005
- on(event: string | symbol, listener: (...args: any[]) => void): this;
1006
- once(event: "close", listener: () => void): this;
1007
- once(event: "drain", listener: () => void): this;
1008
- once(event: "error", listener: (err: Error) => void): this;
1009
- once(event: "finish", listener: () => void): this;
1010
- once(event: "pipe", listener: (src: Readable) => void): this;
1011
- once(event: "unpipe", listener: (src: Readable) => void): this;
1012
- once(event: string | symbol, listener: (...args: any[]) => void): this;
1013
- prependListener(event: "close", listener: () => void): this;
1014
- prependListener(event: "drain", listener: () => void): this;
1015
- prependListener(event: "error", listener: (err: Error) => void): this;
1016
- prependListener(event: "finish", listener: () => void): this;
1017
- prependListener(event: "pipe", listener: (src: Readable) => void): this;
1018
- prependListener(event: "unpipe", listener: (src: Readable) => void): this;
1019
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1020
- prependOnceListener(event: "close", listener: () => void): this;
1021
- prependOnceListener(event: "drain", listener: () => void): this;
1022
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
1023
- prependOnceListener(event: "finish", listener: () => void): this;
1024
- prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
1025
- prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1026
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1027
- removeListener(event: "close", listener: () => void): this;
1028
- removeListener(event: "drain", listener: () => void): this;
1029
- removeListener(event: "error", listener: (err: Error) => void): this;
1030
- removeListener(event: "finish", listener: () => void): this;
1031
- removeListener(event: "pipe", listener: (src: Readable) => void): this;
1032
- removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1033
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1011
+ // #region InternalEventEmitter
1012
+ addListener<E extends keyof WritableEventMap>(
1013
+ eventName: E,
1014
+ listener: (...args: WritableEventMap[E]) => void,
1015
+ ): this;
1016
+ addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1017
+ emit<E extends keyof WritableEventMap>(eventName: E, ...args: WritableEventMap[E]): boolean;
1018
+ emit(eventName: string | symbol, ...args: any[]): boolean;
1019
+ listenerCount<E extends keyof WritableEventMap>(
1020
+ eventName: E,
1021
+ listener?: (...args: WritableEventMap[E]) => void,
1022
+ ): number;
1023
+ listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
1024
+ listeners<E extends keyof WritableEventMap>(eventName: E): ((...args: WritableEventMap[E]) => void)[];
1025
+ listeners(eventName: string | symbol): ((...args: any[]) => void)[];
1026
+ off<E extends keyof WritableEventMap>(eventName: E, listener: (...args: WritableEventMap[E]) => void): this;
1027
+ off(eventName: string | symbol, listener: (...args: any[]) => void): this;
1028
+ on<E extends keyof WritableEventMap>(eventName: E, listener: (...args: WritableEventMap[E]) => void): this;
1029
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
1030
+ once<E extends keyof WritableEventMap>(
1031
+ eventName: E,
1032
+ listener: (...args: WritableEventMap[E]) => void,
1033
+ ): this;
1034
+ once(eventName: string | symbol, listener: (...args: any[]) => void): this;
1035
+ prependListener<E extends keyof WritableEventMap>(
1036
+ eventName: E,
1037
+ listener: (...args: WritableEventMap[E]) => void,
1038
+ ): this;
1039
+ prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1040
+ prependOnceListener<E extends keyof WritableEventMap>(
1041
+ eventName: E,
1042
+ listener: (...args: WritableEventMap[E]) => void,
1043
+ ): this;
1044
+ prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1045
+ rawListeners<E extends keyof WritableEventMap>(eventName: E): ((...args: WritableEventMap[E]) => void)[];
1046
+ rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
1047
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
1048
+ removeAllListeners<E extends keyof WritableEventMap>(eventName?: E): this;
1049
+ removeAllListeners(eventName?: string | symbol): this;
1050
+ removeListener<E extends keyof WritableEventMap>(
1051
+ eventName: E,
1052
+ listener: (...args: WritableEventMap[E]) => void,
1053
+ ): this;
1054
+ removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1055
+ // #endregion
1034
1056
  }
1035
1057
  interface DuplexOptions<T extends Duplex = Duplex> extends ReadableOptions<T>, WritableOptions<T> {
1036
1058
  allowHalfOpen?: boolean | undefined;
@@ -1040,6 +1062,10 @@ declare module "stream" {
1040
1062
  writableHighWaterMark?: number | undefined;
1041
1063
  writableCorked?: number | undefined;
1042
1064
  }
1065
+ interface DuplexToWebOptions {
1066
+ type?: web.ReadableStreamType | undefined;
1067
+ }
1068
+ interface DuplexEventMap extends ReadableEventMap, WritableEventMap {}
1043
1069
  /**
1044
1070
  * Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
1045
1071
  *
@@ -1051,17 +1077,7 @@ declare module "stream" {
1051
1077
  * @since v0.9.4
1052
1078
  */
1053
1079
  class Duplex extends Stream implements NodeJS.ReadWriteStream {
1054
- /**
1055
- * If `false` then the stream will automatically end the writable side when the
1056
- * readable side ends. Set initially by the `allowHalfOpen` constructor option,
1057
- * which defaults to `true`.
1058
- *
1059
- * This can be changed manually to change the half-open behavior of an existing
1060
- * `Duplex` stream instance, but must be changed before the `'end'` event is emitted.
1061
- * @since v0.9.4
1062
- */
1063
- allowHalfOpen: boolean;
1064
- constructor(opts?: DuplexOptions);
1080
+ constructor(options?: DuplexOptions);
1065
1081
  /**
1066
1082
  * A utility method for creating duplex streams.
1067
1083
  *
@@ -1085,137 +1101,87 @@ declare module "stream" {
1085
1101
  */
1086
1102
  static from(
1087
1103
  src:
1088
- | Stream
1089
- | NodeBlob
1090
- | ArrayBuffer
1104
+ | NodeJS.ReadableStream
1105
+ | NodeJS.WritableStream
1106
+ | Blob
1091
1107
  | string
1092
1108
  | Iterable<any>
1093
1109
  | AsyncIterable<any>
1094
- | AsyncGeneratorFunction
1110
+ | ((source: AsyncIterable<any>) => AsyncIterable<any>)
1111
+ | ((source: AsyncIterable<any>) => Promise<void>)
1095
1112
  | Promise<any>
1096
- | Object,
1113
+ | web.ReadableWritablePair
1114
+ | web.ReadableStream
1115
+ | web.WritableStream,
1097
1116
  ): Duplex;
1098
1117
  /**
1099
1118
  * A utility method for creating a web `ReadableStream` and `WritableStream` from a `Duplex`.
1100
1119
  * @since v17.0.0
1101
1120
  */
1102
- static toWeb(streamDuplex: Duplex): {
1103
- readable: streamWeb.ReadableStream;
1104
- writable: streamWeb.WritableStream;
1105
- };
1121
+ static toWeb(streamDuplex: NodeJS.ReadWriteStream, options?: DuplexToWebOptions): web.ReadableWritablePair;
1106
1122
  /**
1107
1123
  * A utility method for creating a `Duplex` from a web `ReadableStream` and `WritableStream`.
1108
1124
  * @since v17.0.0
1109
1125
  */
1110
1126
  static fromWeb(
1111
- duplexStream: {
1112
- readable: streamWeb.ReadableStream;
1113
- writable: streamWeb.WritableStream;
1114
- },
1127
+ duplexStream: web.ReadableWritablePair,
1115
1128
  options?: Pick<
1116
1129
  DuplexOptions,
1117
1130
  "allowHalfOpen" | "decodeStrings" | "encoding" | "highWaterMark" | "objectMode" | "signal"
1118
1131
  >,
1119
1132
  ): Duplex;
1120
1133
  /**
1121
- * Event emitter
1122
- * The defined events on documents including:
1123
- * 1. close
1124
- * 2. data
1125
- * 3. drain
1126
- * 4. end
1127
- * 5. error
1128
- * 6. finish
1129
- * 7. pause
1130
- * 8. pipe
1131
- * 9. readable
1132
- * 10. resume
1133
- * 11. unpipe
1134
- */
1135
- addListener(event: "close", listener: () => void): this;
1136
- addListener(event: "data", listener: (chunk: any) => void): this;
1137
- addListener(event: "drain", listener: () => void): this;
1138
- addListener(event: "end", listener: () => void): this;
1139
- addListener(event: "error", listener: (err: Error) => void): this;
1140
- addListener(event: "finish", listener: () => void): this;
1141
- addListener(event: "pause", listener: () => void): this;
1142
- addListener(event: "pipe", listener: (src: Readable) => void): this;
1143
- addListener(event: "readable", listener: () => void): this;
1144
- addListener(event: "resume", listener: () => void): this;
1145
- addListener(event: "unpipe", listener: (src: Readable) => void): this;
1146
- addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1147
- emit(event: "close"): boolean;
1148
- emit(event: "data", chunk: any): boolean;
1149
- emit(event: "drain"): boolean;
1150
- emit(event: "end"): boolean;
1151
- emit(event: "error", err: Error): boolean;
1152
- emit(event: "finish"): boolean;
1153
- emit(event: "pause"): boolean;
1154
- emit(event: "pipe", src: Readable): boolean;
1155
- emit(event: "readable"): boolean;
1156
- emit(event: "resume"): boolean;
1157
- emit(event: "unpipe", src: Readable): boolean;
1158
- emit(event: string | symbol, ...args: any[]): boolean;
1159
- on(event: "close", listener: () => void): this;
1160
- on(event: "data", listener: (chunk: any) => void): this;
1161
- on(event: "drain", listener: () => void): this;
1162
- on(event: "end", listener: () => void): this;
1163
- on(event: "error", listener: (err: Error) => void): this;
1164
- on(event: "finish", listener: () => void): this;
1165
- on(event: "pause", listener: () => void): this;
1166
- on(event: "pipe", listener: (src: Readable) => void): this;
1167
- on(event: "readable", listener: () => void): this;
1168
- on(event: "resume", listener: () => void): this;
1169
- on(event: "unpipe", listener: (src: Readable) => void): this;
1170
- on(event: string | symbol, listener: (...args: any[]) => void): this;
1171
- once(event: "close", listener: () => void): this;
1172
- once(event: "data", listener: (chunk: any) => void): this;
1173
- once(event: "drain", listener: () => void): this;
1174
- once(event: "end", listener: () => void): this;
1175
- once(event: "error", listener: (err: Error) => void): this;
1176
- once(event: "finish", listener: () => void): this;
1177
- once(event: "pause", listener: () => void): this;
1178
- once(event: "pipe", listener: (src: Readable) => void): this;
1179
- once(event: "readable", listener: () => void): this;
1180
- once(event: "resume", listener: () => void): this;
1181
- once(event: "unpipe", listener: (src: Readable) => void): this;
1182
- once(event: string | symbol, listener: (...args: any[]) => void): this;
1183
- prependListener(event: "close", listener: () => void): this;
1184
- prependListener(event: "data", listener: (chunk: any) => void): this;
1185
- prependListener(event: "drain", listener: () => void): this;
1186
- prependListener(event: "end", listener: () => void): this;
1187
- prependListener(event: "error", listener: (err: Error) => void): this;
1188
- prependListener(event: "finish", listener: () => void): this;
1189
- prependListener(event: "pause", listener: () => void): this;
1190
- prependListener(event: "pipe", listener: (src: Readable) => void): this;
1191
- prependListener(event: "readable", listener: () => void): this;
1192
- prependListener(event: "resume", listener: () => void): this;
1193
- prependListener(event: "unpipe", listener: (src: Readable) => void): this;
1194
- prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1195
- prependOnceListener(event: "close", listener: () => void): this;
1196
- prependOnceListener(event: "data", listener: (chunk: any) => void): this;
1197
- prependOnceListener(event: "drain", listener: () => void): this;
1198
- prependOnceListener(event: "end", listener: () => void): this;
1199
- prependOnceListener(event: "error", listener: (err: Error) => void): this;
1200
- prependOnceListener(event: "finish", listener: () => void): this;
1201
- prependOnceListener(event: "pause", listener: () => void): this;
1202
- prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
1203
- prependOnceListener(event: "readable", listener: () => void): this;
1204
- prependOnceListener(event: "resume", listener: () => void): this;
1205
- prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1206
- prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1207
- removeListener(event: "close", listener: () => void): this;
1208
- removeListener(event: "data", listener: (chunk: any) => void): this;
1209
- removeListener(event: "drain", listener: () => void): this;
1210
- removeListener(event: "end", listener: () => void): this;
1211
- removeListener(event: "error", listener: (err: Error) => void): this;
1212
- removeListener(event: "finish", listener: () => void): this;
1213
- removeListener(event: "pause", listener: () => void): this;
1214
- removeListener(event: "pipe", listener: (src: Readable) => void): this;
1215
- removeListener(event: "readable", listener: () => void): this;
1216
- removeListener(event: "resume", listener: () => void): this;
1217
- removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1218
- removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1134
+ * If `false` then the stream will automatically end the writable side when the
1135
+ * readable side ends. Set initially by the `allowHalfOpen` constructor option,
1136
+ * which defaults to `true`.
1137
+ *
1138
+ * This can be changed manually to change the half-open behavior of an existing
1139
+ * `Duplex` stream instance, but must be changed before the `'end'` event is emitted.
1140
+ * @since v0.9.4
1141
+ */
1142
+ allowHalfOpen: boolean;
1143
+ // #region InternalEventEmitter
1144
+ addListener<E extends keyof DuplexEventMap>(
1145
+ eventName: E,
1146
+ listener: (...args: DuplexEventMap[E]) => void,
1147
+ ): this;
1148
+ addListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1149
+ emit<E extends keyof DuplexEventMap>(eventName: E, ...args: DuplexEventMap[E]): boolean;
1150
+ emit(eventName: string | symbol, ...args: any[]): boolean;
1151
+ listenerCount<E extends keyof DuplexEventMap>(
1152
+ eventName: E,
1153
+ listener?: (...args: DuplexEventMap[E]) => void,
1154
+ ): number;
1155
+ listenerCount(eventName: string | symbol, listener?: (...args: any[]) => void): number;
1156
+ listeners<E extends keyof DuplexEventMap>(eventName: E): ((...args: DuplexEventMap[E]) => void)[];
1157
+ listeners(eventName: string | symbol): ((...args: any[]) => void)[];
1158
+ off<E extends keyof DuplexEventMap>(eventName: E, listener: (...args: DuplexEventMap[E]) => void): this;
1159
+ off(eventName: string | symbol, listener: (...args: any[]) => void): this;
1160
+ on<E extends keyof DuplexEventMap>(eventName: E, listener: (...args: DuplexEventMap[E]) => void): this;
1161
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
1162
+ once<E extends keyof DuplexEventMap>(eventName: E, listener: (...args: DuplexEventMap[E]) => void): this;
1163
+ once(eventName: string | symbol, listener: (...args: any[]) => void): this;
1164
+ prependListener<E extends keyof DuplexEventMap>(
1165
+ eventName: E,
1166
+ listener: (...args: DuplexEventMap[E]) => void,
1167
+ ): this;
1168
+ prependListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1169
+ prependOnceListener<E extends keyof DuplexEventMap>(
1170
+ eventName: E,
1171
+ listener: (...args: DuplexEventMap[E]) => void,
1172
+ ): this;
1173
+ prependOnceListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1174
+ rawListeners<E extends keyof DuplexEventMap>(eventName: E): ((...args: DuplexEventMap[E]) => void)[];
1175
+ rawListeners(eventName: string | symbol): ((...args: any[]) => void)[];
1176
+ // eslint-disable-next-line @definitelytyped/no-unnecessary-generics
1177
+ removeAllListeners<E extends keyof DuplexEventMap>(eventName?: E): this;
1178
+ removeAllListeners(eventName?: string | symbol): this;
1179
+ removeListener<E extends keyof DuplexEventMap>(
1180
+ eventName: E,
1181
+ listener: (...args: DuplexEventMap[E]) => void,
1182
+ ): this;
1183
+ removeListener(eventName: string | symbol, listener: (...args: any[]) => void): this;
1184
+ // #endregion
1219
1185
  }
1220
1186
  interface Duplex extends Readable, Writable {}
1221
1187
  /**
@@ -1256,7 +1222,7 @@ declare module "stream" {
1256
1222
  * @since v0.9.4
1257
1223
  */
1258
1224
  class Transform extends Duplex {
1259
- constructor(opts?: TransformOptions);
1225
+ constructor(options?: TransformOptions);
1260
1226
  _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1261
1227
  _flush(callback: TransformCallback): void;
1262
1228
  }
@@ -1344,7 +1310,9 @@ declare module "stream" {
1344
1310
  * @param signal A signal representing possible cancellation
1345
1311
  * @param stream A stream to attach a signal to.
1346
1312
  */
1347
- function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
1313
+ function addAbortSignal<
1314
+ T extends NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1315
+ >(signal: AbortSignal, stream: T): T;
1348
1316
  /**
1349
1317
  * Returns the default highWaterMark used by streams.
1350
1318
  * Defaults to `65536` (64 KiB), or `16` for `objectMode`.
@@ -1388,7 +1356,7 @@ declare module "stream" {
1388
1356
  * Especially useful in error handling scenarios where a stream is destroyed
1389
1357
  * prematurely (like an aborted HTTP request), and will not emit `'end'` or `'finish'`.
1390
1358
  *
1391
- * The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v24.x/api/stream.html#streamfinishedstream-options).
1359
+ * The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streamfinishedstream-options).
1392
1360
  *
1393
1361
  * `stream.finished()` leaves dangling event listeners (in particular `'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
1394
1362
  * invoked. The reason for this is so that unexpected `'error'` events (due to
@@ -1408,46 +1376,57 @@ declare module "stream" {
1408
1376
  * @returns A cleanup function which removes all registered listeners.
1409
1377
  */
1410
1378
  function finished(
1411
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1379
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1412
1380
  options: FinishedOptions,
1413
1381
  callback: (err?: NodeJS.ErrnoException | null) => void,
1414
1382
  ): () => void;
1415
1383
  function finished(
1416
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1384
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1417
1385
  callback: (err?: NodeJS.ErrnoException | null) => void,
1418
1386
  ): () => void;
1419
1387
  namespace finished {
1420
- function __promisify__(
1421
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1422
- options?: FinishedOptions,
1423
- ): Promise<void>;
1388
+ import __promisify__ = promises.finished;
1389
+ export { __promisify__ };
1424
1390
  }
1425
- type PipelineSourceFunction<T> = () => Iterable<T> | AsyncIterable<T>;
1426
- type PipelineSource<T> = Iterable<T> | AsyncIterable<T> | NodeJS.ReadableStream | PipelineSourceFunction<T>;
1427
- type PipelineTransform<S extends PipelineTransformSource<any>, U> =
1391
+ type PipelineSourceFunction<O> = (options?: Abortable) => Iterable<O> | AsyncIterable<O>;
1392
+ type PipelineSource<O> =
1393
+ | NodeJS.ReadableStream
1394
+ | web.ReadableStream<O>
1395
+ | web.TransformStream<any, O>
1396
+ | Iterable<O>
1397
+ | AsyncIterable<O>
1398
+ | PipelineSourceFunction<O>;
1399
+ type PipelineSourceArgument<T> = (T extends (...args: any[]) => infer R ? R : T) extends infer S
1400
+ ? S extends web.TransformStream<any, infer O> ? web.ReadableStream<O> : S
1401
+ : never;
1402
+ type PipelineTransformGenerator<S extends PipelineTransformSource<any>, O> = (
1403
+ source: PipelineSourceArgument<S>,
1404
+ options?: Abortable,
1405
+ ) => AsyncIterable<O>;
1406
+ type PipelineTransformStreams<I, O> =
1428
1407
  | NodeJS.ReadWriteStream
1429
- | ((
1430
- source: S extends (...args: any[]) => Iterable<infer ST> | AsyncIterable<infer ST> ? AsyncIterable<ST>
1431
- : S,
1432
- ) => AsyncIterable<U>);
1433
- type PipelineTransformSource<T> = PipelineSource<T> | PipelineTransform<any, T>;
1434
- type PipelineDestinationIterableFunction<T> = (source: AsyncIterable<T>) => AsyncIterable<any>;
1435
- type PipelineDestinationPromiseFunction<T, P> = (source: AsyncIterable<T>) => Promise<P>;
1436
- type PipelineDestination<S extends PipelineTransformSource<any>, P> = S extends
1437
- PipelineTransformSource<infer ST> ?
1408
+ | web.TransformStream<I, O>;
1409
+ type PipelineTransform<S extends PipelineTransformSource<any>, O> = S extends
1410
+ PipelineSource<infer I> | PipelineTransformStreams<any, infer I> | ((...args: any[]) => infer I)
1411
+ ? PipelineTransformStreams<I, O> | PipelineTransformGenerator<S, O>
1412
+ : never;
1413
+ type PipelineTransformSource<O> = PipelineSource<O> | PipelineTransform<any, O>;
1414
+ type PipelineDestinationFunction<S extends PipelineTransformSource<any>, R> = (
1415
+ source: PipelineSourceArgument<S>,
1416
+ options?: Abortable,
1417
+ ) => R;
1418
+ type PipelineDestination<S extends PipelineTransformSource<any>, R> = S extends
1419
+ PipelineSource<infer I> | PipelineTransform<any, infer I> ?
1438
1420
  | NodeJS.WritableStream
1439
- | PipelineDestinationIterableFunction<ST>
1440
- | PipelineDestinationPromiseFunction<ST, P>
1421
+ | web.WritableStream<I>
1422
+ | web.TransformStream<I, any>
1423
+ | PipelineDestinationFunction<S, R>
1441
1424
  : never;
1442
- type PipelineCallback<S extends PipelineDestination<any, any>> = S extends
1443
- PipelineDestinationPromiseFunction<any, infer P> ? (err: NodeJS.ErrnoException | null, value: P) => void
1444
- : (err: NodeJS.ErrnoException | null) => void;
1445
- type PipelinePromise<S extends PipelineDestination<any, any>> = S extends
1446
- PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>;
1447
- interface PipelineOptions {
1448
- signal?: AbortSignal | undefined;
1449
- end?: boolean | undefined;
1450
- }
1425
+ type PipelineCallback<S extends PipelineDestination<any, any>> = (
1426
+ err: NodeJS.ErrnoException | null,
1427
+ value: S extends (...args: any[]) => PromiseLike<infer R> ? R : undefined,
1428
+ ) => void;
1429
+ type PipelineResult<S extends PipelineDestination<any, any>> = S extends NodeJS.WritableStream ? S : Duplex;
1451
1430
  /**
1452
1431
  * A module method to pipe between streams and generators forwarding errors and
1453
1432
  * properly cleaning up and provide a callback when the pipeline is complete.
@@ -1476,7 +1455,7 @@ declare module "stream" {
1476
1455
  * );
1477
1456
  * ```
1478
1457
  *
1479
- * The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v24.x/api/stream.html#streampipelinesource-transforms-destination-options).
1458
+ * The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streampipelinesource-transforms-destination-options).
1480
1459
  *
1481
1460
  * `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
1482
1461
  *
@@ -1513,171 +1492,279 @@ declare module "stream" {
1513
1492
  * @since v10.0.0
1514
1493
  * @param callback Called when the pipeline is fully done.
1515
1494
  */
1516
- function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1517
- source: A,
1518
- destination: B,
1519
- callback: PipelineCallback<B>,
1520
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1495
+ function pipeline<S extends PipelineSource<any>, D extends PipelineDestination<S, any>>(
1496
+ source: S,
1497
+ destination: D,
1498
+ callback: PipelineCallback<D>,
1499
+ ): PipelineResult<D>;
1521
1500
  function pipeline<
1522
- A extends PipelineSource<any>,
1523
- T1 extends PipelineTransform<A, any>,
1524
- B extends PipelineDestination<T1, any>,
1501
+ S extends PipelineSource<any>,
1502
+ T extends PipelineTransform<S, any>,
1503
+ D extends PipelineDestination<T, any>,
1525
1504
  >(
1526
- source: A,
1527
- transform1: T1,
1528
- destination: B,
1529
- callback: PipelineCallback<B>,
1530
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1505
+ source: S,
1506
+ transform: T,
1507
+ destination: D,
1508
+ callback: PipelineCallback<D>,
1509
+ ): PipelineResult<D>;
1531
1510
  function pipeline<
1532
- A extends PipelineSource<any>,
1533
- T1 extends PipelineTransform<A, any>,
1511
+ S extends PipelineSource<any>,
1512
+ T1 extends PipelineTransform<S, any>,
1534
1513
  T2 extends PipelineTransform<T1, any>,
1535
- B extends PipelineDestination<T2, any>,
1514
+ D extends PipelineDestination<T2, any>,
1536
1515
  >(
1537
- source: A,
1516
+ source: S,
1538
1517
  transform1: T1,
1539
1518
  transform2: T2,
1540
- destination: B,
1541
- callback: PipelineCallback<B>,
1542
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1519
+ destination: D,
1520
+ callback: PipelineCallback<D>,
1521
+ ): PipelineResult<D>;
1543
1522
  function pipeline<
1544
- A extends PipelineSource<any>,
1545
- T1 extends PipelineTransform<A, any>,
1523
+ S extends PipelineSource<any>,
1524
+ T1 extends PipelineTransform<S, any>,
1546
1525
  T2 extends PipelineTransform<T1, any>,
1547
1526
  T3 extends PipelineTransform<T2, any>,
1548
- B extends PipelineDestination<T3, any>,
1527
+ D extends PipelineDestination<T3, any>,
1549
1528
  >(
1550
- source: A,
1529
+ source: S,
1551
1530
  transform1: T1,
1552
1531
  transform2: T2,
1553
1532
  transform3: T3,
1554
- destination: B,
1555
- callback: PipelineCallback<B>,
1556
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1533
+ destination: D,
1534
+ callback: PipelineCallback<D>,
1535
+ ): PipelineResult<D>;
1557
1536
  function pipeline<
1558
- A extends PipelineSource<any>,
1559
- T1 extends PipelineTransform<A, any>,
1537
+ S extends PipelineSource<any>,
1538
+ T1 extends PipelineTransform<S, any>,
1560
1539
  T2 extends PipelineTransform<T1, any>,
1561
1540
  T3 extends PipelineTransform<T2, any>,
1562
1541
  T4 extends PipelineTransform<T3, any>,
1563
- B extends PipelineDestination<T4, any>,
1542
+ D extends PipelineDestination<T4, any>,
1564
1543
  >(
1565
- source: A,
1544
+ source: S,
1566
1545
  transform1: T1,
1567
1546
  transform2: T2,
1568
1547
  transform3: T3,
1569
1548
  transform4: T4,
1570
- destination: B,
1571
- callback: PipelineCallback<B>,
1572
- ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1549
+ destination: D,
1550
+ callback: PipelineCallback<D>,
1551
+ ): PipelineResult<D>;
1573
1552
  function pipeline(
1574
- streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1553
+ streams: ReadonlyArray<PipelineSource<any> | PipelineTransform<any, any> | PipelineDestination<any, any>>,
1575
1554
  callback: (err: NodeJS.ErrnoException | null) => void,
1576
1555
  ): NodeJS.WritableStream;
1577
1556
  function pipeline(
1578
- stream1: NodeJS.ReadableStream,
1579
- stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1580
- ...streams: Array<
1581
- NodeJS.ReadWriteStream | NodeJS.WritableStream | ((err: NodeJS.ErrnoException | null) => void)
1582
- >
1557
+ ...streams: [
1558
+ ...[PipelineSource<any>, ...PipelineTransform<any, any>[], PipelineDestination<any, any>],
1559
+ callback: ((err: NodeJS.ErrnoException | null) => void),
1560
+ ]
1583
1561
  ): NodeJS.WritableStream;
1584
1562
  namespace pipeline {
1585
- function __promisify__<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1586
- source: A,
1587
- destination: B,
1588
- options?: PipelineOptions,
1589
- ): PipelinePromise<B>;
1590
- function __promisify__<
1591
- A extends PipelineSource<any>,
1592
- T1 extends PipelineTransform<A, any>,
1593
- B extends PipelineDestination<T1, any>,
1594
- >(
1595
- source: A,
1596
- transform1: T1,
1597
- destination: B,
1598
- options?: PipelineOptions,
1599
- ): PipelinePromise<B>;
1600
- function __promisify__<
1601
- A extends PipelineSource<any>,
1602
- T1 extends PipelineTransform<A, any>,
1603
- T2 extends PipelineTransform<T1, any>,
1604
- B extends PipelineDestination<T2, any>,
1605
- >(
1606
- source: A,
1607
- transform1: T1,
1608
- transform2: T2,
1609
- destination: B,
1610
- options?: PipelineOptions,
1611
- ): PipelinePromise<B>;
1612
- function __promisify__<
1613
- A extends PipelineSource<any>,
1614
- T1 extends PipelineTransform<A, any>,
1615
- T2 extends PipelineTransform<T1, any>,
1616
- T3 extends PipelineTransform<T2, any>,
1617
- B extends PipelineDestination<T3, any>,
1618
- >(
1619
- source: A,
1620
- transform1: T1,
1621
- transform2: T2,
1622
- transform3: T3,
1623
- destination: B,
1624
- options?: PipelineOptions,
1625
- ): PipelinePromise<B>;
1626
- function __promisify__<
1627
- A extends PipelineSource<any>,
1628
- T1 extends PipelineTransform<A, any>,
1629
- T2 extends PipelineTransform<T1, any>,
1630
- T3 extends PipelineTransform<T2, any>,
1631
- T4 extends PipelineTransform<T3, any>,
1632
- B extends PipelineDestination<T4, any>,
1633
- >(
1634
- source: A,
1635
- transform1: T1,
1636
- transform2: T2,
1637
- transform3: T3,
1638
- transform4: T4,
1639
- destination: B,
1640
- options?: PipelineOptions,
1641
- ): PipelinePromise<B>;
1642
- function __promisify__(
1643
- streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1644
- options?: PipelineOptions,
1645
- ): Promise<void>;
1646
- function __promisify__(
1647
- stream1: NodeJS.ReadableStream,
1648
- stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1649
- ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | PipelineOptions>
1650
- ): Promise<void>;
1651
- }
1652
- // TODO: this interface never existed; remove in next major
1653
- interface Pipe {
1654
- close(): void;
1655
- hasRef(): boolean;
1656
- ref(): void;
1657
- unref(): void;
1563
+ import __promisify__ = promises.pipeline;
1564
+ export { __promisify__ };
1658
1565
  }
1659
- // TODO: these should all take webstream arguments
1566
+ type ComposeSource<O> =
1567
+ | NodeJS.ReadableStream
1568
+ | web.ReadableStream<O>
1569
+ | Iterable<O>
1570
+ | AsyncIterable<O>
1571
+ | (() => AsyncIterable<O>);
1572
+ type ComposeTransformStreams<I, O> = NodeJS.ReadWriteStream | web.TransformStream<I, O>;
1573
+ type ComposeTransformGenerator<I, O> = (source: AsyncIterable<I>) => AsyncIterable<O>;
1574
+ type ComposeTransform<S extends ComposeTransformSource<any>, O> = S extends
1575
+ ComposeSource<infer I> | ComposeTransformStreams<any, infer I> | ComposeTransformGenerator<any, infer I>
1576
+ ? ComposeTransformStreams<I, O> | ComposeTransformGenerator<I, O>
1577
+ : never;
1578
+ type ComposeTransformSource<O> = ComposeSource<O> | ComposeTransform<any, O>;
1579
+ type ComposeDestination<S extends ComposeTransformSource<any>> = S extends ComposeTransformSource<infer I> ?
1580
+ | NodeJS.WritableStream
1581
+ | web.WritableStream<I>
1582
+ | web.TransformStream<I, any>
1583
+ | ((source: AsyncIterable<I>) => void)
1584
+ : never;
1585
+ /**
1586
+ * Combines two or more streams into a `Duplex` stream that writes to the
1587
+ * first stream and reads from the last. Each provided stream is piped into
1588
+ * the next, using `stream.pipeline`. If any of the streams error then all
1589
+ * are destroyed, including the outer `Duplex` stream.
1590
+ *
1591
+ * Because `stream.compose` returns a new stream that in turn can (and
1592
+ * should) be piped into other streams, it enables composition. In contrast,
1593
+ * when passing streams to `stream.pipeline`, typically the first stream is
1594
+ * a readable stream and the last a writable stream, forming a closed
1595
+ * circuit.
1596
+ *
1597
+ * If passed a `Function` it must be a factory method taking a `source`
1598
+ * `Iterable`.
1599
+ *
1600
+ * ```js
1601
+ * import { compose, Transform } from 'node:stream';
1602
+ *
1603
+ * const removeSpaces = new Transform({
1604
+ * transform(chunk, encoding, callback) {
1605
+ * callback(null, String(chunk).replace(' ', ''));
1606
+ * },
1607
+ * });
1608
+ *
1609
+ * async function* toUpper(source) {
1610
+ * for await (const chunk of source) {
1611
+ * yield String(chunk).toUpperCase();
1612
+ * }
1613
+ * }
1614
+ *
1615
+ * let res = '';
1616
+ * for await (const buf of compose(removeSpaces, toUpper).end('hello world')) {
1617
+ * res += buf;
1618
+ * }
1619
+ *
1620
+ * console.log(res); // prints 'HELLOWORLD'
1621
+ * ```
1622
+ *
1623
+ * `stream.compose` can be used to convert async iterables, generators and
1624
+ * functions into streams.
1625
+ *
1626
+ * * `AsyncIterable` converts into a readable `Duplex`. Cannot yield
1627
+ * `null`.
1628
+ * * `AsyncGeneratorFunction` converts into a readable/writable transform `Duplex`.
1629
+ * Must take a source `AsyncIterable` as first parameter. Cannot yield
1630
+ * `null`.
1631
+ * * `AsyncFunction` converts into a writable `Duplex`. Must return
1632
+ * either `null` or `undefined`.
1633
+ *
1634
+ * ```js
1635
+ * import { compose } from 'node:stream';
1636
+ * import { finished } from 'node:stream/promises';
1637
+ *
1638
+ * // Convert AsyncIterable into readable Duplex.
1639
+ * const s1 = compose(async function*() {
1640
+ * yield 'Hello';
1641
+ * yield 'World';
1642
+ * }());
1643
+ *
1644
+ * // Convert AsyncGenerator into transform Duplex.
1645
+ * const s2 = compose(async function*(source) {
1646
+ * for await (const chunk of source) {
1647
+ * yield String(chunk).toUpperCase();
1648
+ * }
1649
+ * });
1650
+ *
1651
+ * let res = '';
1652
+ *
1653
+ * // Convert AsyncFunction into writable Duplex.
1654
+ * const s3 = compose(async function(source) {
1655
+ * for await (const chunk of source) {
1656
+ * res += chunk;
1657
+ * }
1658
+ * });
1659
+ *
1660
+ * await finished(compose(s1, s2, s3));
1661
+ *
1662
+ * console.log(res); // prints 'HELLOWORLD'
1663
+ * ```
1664
+ *
1665
+ * For convenience, the `readable.compose(stream)` method is available on
1666
+ * `Readable` and `Duplex` streams as a wrapper for this function.
1667
+ * @since v16.9.0
1668
+ * @experimental
1669
+ */
1670
+ /* eslint-disable @definitelytyped/no-unnecessary-generics */
1671
+ function compose(stream: ComposeSource<any> | ComposeDestination<any>): Duplex;
1672
+ function compose<
1673
+ S extends ComposeSource<any> | ComposeTransform<any, any>,
1674
+ D extends ComposeTransform<S, any> | ComposeDestination<S>,
1675
+ >(
1676
+ source: S,
1677
+ destination: D,
1678
+ ): Duplex;
1679
+ function compose<
1680
+ S extends ComposeSource<any> | ComposeTransform<any, any>,
1681
+ T extends ComposeTransform<S, any>,
1682
+ D extends ComposeTransform<T, any> | ComposeDestination<T>,
1683
+ >(source: S, transform: T, destination: D): Duplex;
1684
+ function compose<
1685
+ S extends ComposeSource<any> | ComposeTransform<any, any>,
1686
+ T1 extends ComposeTransform<S, any>,
1687
+ T2 extends ComposeTransform<T1, any>,
1688
+ D extends ComposeTransform<T2, any> | ComposeDestination<T2>,
1689
+ >(source: S, transform1: T1, transform2: T2, destination: D): Duplex;
1690
+ function compose<
1691
+ S extends ComposeSource<any> | ComposeTransform<any, any>,
1692
+ T1 extends ComposeTransform<S, any>,
1693
+ T2 extends ComposeTransform<T1, any>,
1694
+ T3 extends ComposeTransform<T2, any>,
1695
+ D extends ComposeTransform<T3, any> | ComposeDestination<T3>,
1696
+ >(source: S, transform1: T1, transform2: T2, transform3: T3, destination: D): Duplex;
1697
+ function compose<
1698
+ S extends ComposeSource<any> | ComposeTransform<any, any>,
1699
+ T1 extends ComposeTransform<S, any>,
1700
+ T2 extends ComposeTransform<T1, any>,
1701
+ T3 extends ComposeTransform<T2, any>,
1702
+ T4 extends ComposeTransform<T3, any>,
1703
+ D extends ComposeTransform<T4, any> | ComposeDestination<T4>,
1704
+ >(source: S, transform1: T1, transform2: T2, transform3: T3, transform4: T4, destination: D): Duplex;
1705
+ function compose(
1706
+ ...streams: [
1707
+ ComposeSource<any>,
1708
+ ...ComposeTransform<any, any>[],
1709
+ ComposeDestination<any>,
1710
+ ]
1711
+ ): Duplex;
1712
+ /* eslint-enable @definitelytyped/no-unnecessary-generics */
1660
1713
  /**
1661
1714
  * Returns whether the stream has encountered an error.
1662
1715
  * @since v17.3.0, v16.14.0
1663
1716
  */
1664
- function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
1717
+ function isErrored(
1718
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1719
+ ): boolean;
1665
1720
  /**
1666
1721
  * Returns whether the stream is readable.
1667
1722
  * @since v17.4.0, v16.14.0
1668
1723
  * @returns Only returns `null` if `stream` is not a valid `Readable`, `Duplex` or `ReadableStream`.
1669
1724
  */
1670
- function isReadable(stream: Readable | NodeJS.ReadableStream): boolean | null;
1725
+ function isReadable(stream: NodeJS.ReadableStream | web.ReadableStream): boolean | null;
1671
1726
  /**
1672
1727
  * Returns whether the stream is writable.
1673
1728
  * @since v20.0.0
1674
1729
  * @returns Only returns `null` if `stream` is not a valid `Writable`, `Duplex` or `WritableStream`.
1675
1730
  */
1676
- function isWritable(stream: Writable | NodeJS.WritableStream): boolean | null;
1731
+ function isWritable(stream: NodeJS.WritableStream | web.WritableStream): boolean | null;
1732
+ }
1733
+ global {
1734
+ namespace NodeJS {
1735
+ // These interfaces are vestigial, and correspond roughly to the "streams2" interfaces
1736
+ // from early versions of Node.js, but they are still used widely across the ecosystem.
1737
+ // Accordingly, they are commonly used as "in-types" for @types/node APIs, so that
1738
+ // eg. streams returned from older libraries will still be considered valid input to
1739
+ // functions which accept stream arguments.
1740
+ // It's not possible to change or remove these without astronomical levels of breakage.
1741
+ interface ReadableStream extends EventEmitter {
1742
+ readable: boolean;
1743
+ read(size?: number): string | Buffer;
1744
+ setEncoding(encoding: BufferEncoding): this;
1745
+ pause(): this;
1746
+ resume(): this;
1747
+ isPaused(): boolean;
1748
+ pipe<T extends WritableStream>(destination: T, options?: { end?: boolean | undefined }): T;
1749
+ unpipe(destination?: WritableStream): this;
1750
+ unshift(chunk: string | Uint8Array, encoding?: BufferEncoding): void;
1751
+ wrap(oldStream: ReadableStream): this;
1752
+ [Symbol.asyncIterator](): AsyncIterableIterator<string | Buffer>;
1753
+ }
1754
+ interface WritableStream extends EventEmitter {
1755
+ writable: boolean;
1756
+ write(buffer: Uint8Array | string, cb?: (err?: Error | null) => void): boolean;
1757
+ write(str: string, encoding?: BufferEncoding, cb?: (err?: Error | null) => void): boolean;
1758
+ end(cb?: () => void): this;
1759
+ end(data: string | Uint8Array, cb?: () => void): this;
1760
+ end(str: string, encoding?: BufferEncoding, cb?: () => void): this;
1761
+ }
1762
+ interface ReadWriteStream extends ReadableStream, WritableStream {}
1763
+ }
1677
1764
  }
1678
1765
  export = Stream;
1679
1766
  }
1680
- declare module "node:stream" {
1681
- import stream = require("stream");
1767
+ declare module "stream" {
1768
+ import stream = require("node:stream");
1682
1769
  export = stream;
1683
1770
  }