@idlebox/stripe-node-types 24.0.14 → 24.0.15

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