omegon 0.8.4 → 0.9.1

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 (139) hide show
  1. package/extensions/cleave/dispatcher.ts +213 -20
  2. package/extensions/cleave/rpc-child.ts +269 -0
  3. package/extensions/cleave/types.ts +52 -0
  4. package/node_modules/@types/node/README.md +3 -3
  5. package/node_modules/@types/node/assert/strict.d.ts +11 -5
  6. package/node_modules/@types/node/assert.d.ts +173 -50
  7. package/node_modules/@types/node/async_hooks.d.ts +8 -28
  8. package/node_modules/@types/node/buffer.buffer.d.ts +7 -1
  9. package/node_modules/@types/node/buffer.d.ts +168 -44
  10. package/node_modules/@types/node/child_process.d.ts +70 -27
  11. package/node_modules/@types/node/cluster.d.ts +332 -240
  12. package/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
  13. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  14. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  15. package/node_modules/@types/node/compatibility/iterators.d.ts +0 -1
  16. package/node_modules/@types/node/console.d.ts +350 -49
  17. package/node_modules/@types/node/constants.d.ts +4 -3
  18. package/node_modules/@types/node/crypto.d.ts +1110 -630
  19. package/node_modules/@types/node/dgram.d.ts +51 -15
  20. package/node_modules/@types/node/diagnostics_channel.d.ts +6 -4
  21. package/node_modules/@types/node/dns/promises.d.ts +4 -4
  22. package/node_modules/@types/node/dns.d.ts +133 -132
  23. package/node_modules/@types/node/domain.d.ts +17 -13
  24. package/node_modules/@types/node/events.d.ts +663 -734
  25. package/node_modules/@types/node/fs/promises.d.ts +9 -43
  26. package/node_modules/@types/node/fs.d.ts +411 -628
  27. package/node_modules/@types/node/globals.d.ts +30 -8
  28. package/node_modules/@types/node/globals.typedarray.d.ts +0 -63
  29. package/node_modules/@types/node/http.d.ts +265 -364
  30. package/node_modules/@types/node/http2.d.ts +715 -551
  31. package/node_modules/@types/node/https.d.ts +239 -65
  32. package/node_modules/@types/node/index.d.ts +6 -24
  33. package/node_modules/@types/node/inspector.d.ts +53 -69
  34. package/node_modules/@types/node/inspector.generated.d.ts +410 -759
  35. package/node_modules/@types/node/module.d.ts +186 -52
  36. package/node_modules/@types/node/net.d.ts +194 -70
  37. package/node_modules/@types/node/os.d.ts +11 -12
  38. package/node_modules/@types/node/package.json +3 -13
  39. package/node_modules/@types/node/path.d.ts +133 -120
  40. package/node_modules/@types/node/perf_hooks.d.ts +643 -318
  41. package/node_modules/@types/node/process.d.ts +132 -223
  42. package/node_modules/@types/node/punycode.d.ts +5 -5
  43. package/node_modules/@types/node/querystring.d.ts +4 -4
  44. package/node_modules/@types/node/readline/promises.d.ts +3 -3
  45. package/node_modules/@types/node/readline.d.ts +120 -68
  46. package/node_modules/@types/node/repl.d.ts +100 -87
  47. package/node_modules/@types/node/sea.d.ts +1 -10
  48. package/node_modules/@types/node/sqlite.d.ts +19 -363
  49. package/node_modules/@types/node/stream/consumers.d.ts +10 -10
  50. package/node_modules/@types/node/stream/promises.d.ts +15 -136
  51. package/node_modules/@types/node/stream/web.d.ts +502 -176
  52. package/node_modules/@types/node/stream.d.ts +475 -581
  53. package/node_modules/@types/node/string_decoder.d.ts +4 -4
  54. package/node_modules/@types/node/test.d.ts +196 -308
  55. package/node_modules/@types/node/timers/promises.d.ts +4 -4
  56. package/node_modules/@types/node/timers.d.ts +132 -4
  57. package/node_modules/@types/node/tls.d.ts +226 -110
  58. package/node_modules/@types/node/trace_events.d.ts +9 -9
  59. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +7 -1
  60. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +0 -2
  61. package/node_modules/@types/node/ts5.6/index.d.ts +6 -26
  62. package/node_modules/@types/node/tty.d.ts +16 -58
  63. package/node_modules/@types/node/url.d.ts +573 -130
  64. package/node_modules/@types/node/util.d.ts +1100 -181
  65. package/node_modules/@types/node/v8.d.ts +8 -76
  66. package/node_modules/@types/node/vm.d.ts +72 -280
  67. package/node_modules/@types/node/wasi.d.ts +4 -25
  68. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +2 -27
  69. package/node_modules/@types/node/web-globals/events.d.ts +0 -9
  70. package/node_modules/@types/node/web-globals/fetch.d.ts +0 -14
  71. package/node_modules/@types/node/web-globals/navigator.d.ts +0 -3
  72. package/node_modules/@types/node/worker_threads.d.ts +335 -268
  73. package/node_modules/@types/node/zlib.d.ts +74 -9
  74. package/node_modules/undici-types/agent.d.ts +12 -13
  75. package/node_modules/undici-types/api.d.ts +26 -26
  76. package/node_modules/undici-types/balanced-pool.d.ts +12 -13
  77. package/node_modules/undici-types/client.d.ts +19 -19
  78. package/node_modules/undici-types/connector.d.ts +2 -2
  79. package/node_modules/undici-types/cookies.d.ts +0 -2
  80. package/node_modules/undici-types/diagnostics-channel.d.ts +10 -18
  81. package/node_modules/undici-types/dispatcher.d.ts +103 -123
  82. package/node_modules/undici-types/env-http-proxy-agent.d.ts +3 -4
  83. package/node_modules/undici-types/errors.d.ts +54 -66
  84. package/node_modules/undici-types/eventsource.d.ts +4 -9
  85. package/node_modules/undici-types/fetch.d.ts +20 -22
  86. package/node_modules/undici-types/file.d.ts +39 -0
  87. package/node_modules/undici-types/filereader.d.ts +54 -0
  88. package/node_modules/undici-types/formdata.d.ts +7 -7
  89. package/node_modules/undici-types/global-dispatcher.d.ts +4 -4
  90. package/node_modules/undici-types/global-origin.d.ts +5 -5
  91. package/node_modules/undici-types/handlers.d.ts +8 -8
  92. package/node_modules/undici-types/header.d.ts +1 -157
  93. package/node_modules/undici-types/index.d.ts +47 -64
  94. package/node_modules/undici-types/interceptors.d.ts +8 -64
  95. package/node_modules/undici-types/mock-agent.d.ts +18 -36
  96. package/node_modules/undici-types/mock-client.d.ts +4 -6
  97. package/node_modules/undici-types/mock-errors.d.ts +3 -3
  98. package/node_modules/undici-types/mock-interceptor.d.ts +20 -21
  99. package/node_modules/undici-types/mock-pool.d.ts +4 -6
  100. package/node_modules/undici-types/package.json +1 -1
  101. package/node_modules/undici-types/patch.d.ts +4 -0
  102. package/node_modules/undici-types/pool-stats.d.ts +8 -8
  103. package/node_modules/undici-types/pool.d.ts +13 -15
  104. package/node_modules/undici-types/proxy-agent.d.ts +4 -5
  105. package/node_modules/undici-types/readable.d.ts +16 -19
  106. package/node_modules/undici-types/retry-agent.d.ts +1 -1
  107. package/node_modules/undici-types/retry-handler.d.ts +10 -19
  108. package/node_modules/undici-types/util.d.ts +3 -3
  109. package/node_modules/undici-types/webidl.d.ts +29 -142
  110. package/node_modules/undici-types/websocket.d.ts +10 -46
  111. package/package.json +2 -1
  112. package/scripts/check-vendor-dist.mjs +56 -0
  113. package/skills/cleave/SKILL.md +62 -2
  114. package/node_modules/@types/node/inspector/promises.d.ts +0 -41
  115. package/node_modules/@types/node/path/posix.d.ts +0 -8
  116. package/node_modules/@types/node/path/win32.d.ts +0 -8
  117. package/node_modules/@types/node/quic.d.ts +0 -910
  118. package/node_modules/@types/node/test/reporters.d.ts +0 -96
  119. package/node_modules/@types/node/ts5.6/compatibility/float16array.d.ts +0 -71
  120. package/node_modules/@types/node/ts5.7/compatibility/float16array.d.ts +0 -72
  121. package/node_modules/@types/node/ts5.7/index.d.ts +0 -117
  122. package/node_modules/@types/node/util/types.d.ts +0 -558
  123. package/node_modules/@types/node/web-globals/blob.d.ts +0 -23
  124. package/node_modules/@types/node/web-globals/console.d.ts +0 -9
  125. package/node_modules/@types/node/web-globals/crypto.d.ts +0 -39
  126. package/node_modules/@types/node/web-globals/encoding.d.ts +0 -11
  127. package/node_modules/@types/node/web-globals/importmeta.d.ts +0 -13
  128. package/node_modules/@types/node/web-globals/messaging.d.ts +0 -23
  129. package/node_modules/@types/node/web-globals/performance.d.ts +0 -45
  130. package/node_modules/@types/node/web-globals/streams.d.ts +0 -115
  131. package/node_modules/@types/node/web-globals/timers.d.ts +0 -44
  132. package/node_modules/@types/node/web-globals/url.d.ts +0 -24
  133. package/node_modules/undici-types/cache-interceptor.d.ts +0 -173
  134. package/node_modules/undici-types/client-stats.d.ts +0 -15
  135. package/node_modules/undici-types/h2c-client.d.ts +0 -73
  136. package/node_modules/undici-types/mock-call-history.d.ts +0 -111
  137. package/node_modules/undici-types/round-robin-pool.d.ts +0 -41
  138. package/node_modules/undici-types/snapshot-agent.d.ts +0 -109
  139. package/node_modules/undici-types/utility.d.ts +0 -7
@@ -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-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.
5
+ * There are many stream objects provided by Node.js. For instance, a [request to an HTTP server](https://nodejs.org/docs/latest-v22.x/api/http.html#class-httpincomingmessage)
6
+ * and [`process.stdout`](https://nodejs.org/docs/latest-v22.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-v25.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-v22.x/api/events.html#class-eventemitter).
9
9
  *
10
10
  * To access the `node:stream` module:
11
11
  *
@@ -15,33 +15,32 @@
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/v25.x/lib/stream.js)
18
+ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/stream.js)
19
19
  */
20
- declare module "node:stream" {
21
- import { Blob } from "node:buffer";
20
+ declare module "stream" {
22
21
  import { Abortable, EventEmitter } from "node:events";
23
- import * as promises from "node:stream/promises";
24
- import * as web from "node:stream/web";
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
+
25
28
  class Stream extends EventEmitter {
26
- /**
27
- * @since v0.9.4
28
- */
29
29
  pipe<T extends NodeJS.WritableStream>(
30
30
  destination: T,
31
- options?: Stream.PipeOptions,
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 },
32
38
  ): T;
33
39
  }
34
40
  namespace Stream {
35
- export { promises, Stream };
41
+ export { Stream, streamPromises as promises };
36
42
  }
37
43
  namespace Stream {
38
- interface PipeOptions {
39
- /**
40
- * End the writer when the reader ends.
41
- * @default true
42
- */
43
- end?: boolean | undefined;
44
- }
45
44
  interface StreamOptions<T extends Stream> extends Abortable {
46
45
  emitClose?: boolean | undefined;
47
46
  highWaterMark?: number | undefined;
@@ -54,49 +53,19 @@ declare module "node:stream" {
54
53
  encoding?: BufferEncoding | undefined;
55
54
  read?: ((this: T, size: number) => void) | undefined;
56
55
  }
57
- interface ReadableIteratorOptions {
56
+ interface ArrayOptions {
58
57
  /**
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.
58
+ * The maximum concurrent invocations of `fn` to call on the stream at once.
70
59
  * @default 1
71
60
  */
72
61
  concurrency?: number | 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": [];
62
+ /** Allows destroying the stream if the signal is aborted. */
63
+ signal?: AbortSignal | undefined;
94
64
  }
95
65
  /**
96
66
  * @since v0.9.4
97
67
  */
98
68
  class Readable extends Stream implements NodeJS.ReadableStream {
99
- constructor(options?: ReadableOptions);
100
69
  /**
101
70
  * A utility method for creating Readable Streams out of iterators.
102
71
  * @since v12.3.0, v10.17.0
@@ -109,7 +78,7 @@ declare module "node:stream" {
109
78
  * @since v17.0.0
110
79
  */
111
80
  static fromWeb(
112
- readableStream: web.ReadableStream,
81
+ readableStream: streamWeb.ReadableStream,
113
82
  options?: Pick<ReadableOptions, "encoding" | "highWaterMark" | "objectMode" | "signal">,
114
83
  ): Readable;
115
84
  /**
@@ -117,14 +86,16 @@ declare module "node:stream" {
117
86
  * @since v17.0.0
118
87
  */
119
88
  static toWeb(
120
- streamReadable: NodeJS.ReadableStream,
121
- options?: ReadableToWebOptions,
122
- ): web.ReadableStream;
89
+ streamReadable: Readable,
90
+ options?: {
91
+ strategy?: streamWeb.QueuingStrategy | undefined;
92
+ },
93
+ ): streamWeb.ReadableStream;
123
94
  /**
124
95
  * Returns whether the stream has been read from or cancelled.
125
96
  * @since v16.8.0
126
97
  */
127
- static isDisturbed(stream: NodeJS.ReadableStream | web.ReadableStream): boolean;
98
+ static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
128
99
  /**
129
100
  * Returns whether the stream was destroyed or errored before emitting `'end'`.
130
101
  * @since v16.8.0
@@ -147,16 +118,16 @@ declare module "node:stream" {
147
118
  */
148
119
  readonly readableEncoding: BufferEncoding | null;
149
120
  /**
150
- * Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v25.x/api/stream.html#event-end) event is emitted.
121
+ * Becomes `true` when [`'end'`](https://nodejs.org/docs/latest-v22.x/api/stream.html#event-end) event is emitted.
151
122
  * @since v12.9.0
152
123
  */
153
124
  readonly readableEnded: boolean;
154
125
  /**
155
126
  * This property reflects the current state of a `Readable` stream as described
156
- * in the [Three states](https://nodejs.org/docs/latest-v25.x/api/stream.html#three-states) section.
127
+ * in the [Three states](https://nodejs.org/docs/latest-v22.x/api/stream.html#three-states) section.
157
128
  * @since v9.4.0
158
129
  */
159
- readableFlowing: boolean | null;
130
+ readonly readableFlowing: boolean | null;
160
131
  /**
161
132
  * Returns the value of `highWaterMark` passed when creating this `Readable`.
162
133
  * @since v9.3.0
@@ -189,6 +160,7 @@ declare module "node:stream" {
189
160
  * @since v18.0.0
190
161
  */
191
162
  readonly errored: Error | null;
163
+ constructor(opts?: ReadableOptions);
192
164
  _construct?(callback: (error?: Error | null) => void): void;
193
165
  _read(size: number): void;
194
166
  /**
@@ -472,46 +444,16 @@ declare module "node:stream" {
472
444
  */
473
445
  wrap(stream: NodeJS.ReadableStream): this;
474
446
  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;
508
447
  /**
509
448
  * The iterator created by this method gives users the option to cancel the destruction
510
449
  * of the stream if the `for await...of` loop is exited by `return`, `break`, or `throw`,
511
450
  * or if the iterator should destroy the stream if the stream emitted an error during iteration.
512
451
  * @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`**.
513
455
  */
514
- iterator(options?: ReadableIteratorOptions): NodeJS.AsyncIterator<any>;
456
+ iterator(options?: { destroyOnReturn?: boolean }): NodeJS.AsyncIterator<any>;
515
457
  /**
516
458
  * This method allows mapping over the stream. The *fn* function will be called for every chunk in the stream.
517
459
  * If the *fn* function returns a promise - that promise will be `await`ed before being passed to the result stream.
@@ -519,7 +461,7 @@ declare module "node:stream" {
519
461
  * @param fn a function to map over every chunk in the stream. Async or not.
520
462
  * @returns a stream mapped with the function *fn*.
521
463
  */
522
- map(fn: (data: any, options?: Abortable) => any, options?: ReadableOperatorOptions): Readable;
464
+ map(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
523
465
  /**
524
466
  * This method allows filtering the stream. For each chunk in the stream the *fn* function will be called
525
467
  * and if it returns a truthy value, the chunk will be passed to the result stream.
@@ -529,8 +471,8 @@ declare module "node:stream" {
529
471
  * @returns a stream filtered with the predicate *fn*.
530
472
  */
531
473
  filter(
532
- fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
533
- options?: ReadableOperatorOptions,
474
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
475
+ options?: ArrayOptions,
534
476
  ): Readable;
535
477
  /**
536
478
  * This method allows iterating a stream. For each chunk in the stream the *fn* function will be called.
@@ -548,8 +490,8 @@ declare module "node:stream" {
548
490
  * @returns a promise for when the stream has finished.
549
491
  */
550
492
  forEach(
551
- fn: (data: any, options?: Abortable) => void | Promise<void>,
552
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
493
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => void | Promise<void>,
494
+ options?: ArrayOptions,
553
495
  ): Promise<void>;
554
496
  /**
555
497
  * This method allows easily obtaining the contents of a stream.
@@ -559,7 +501,7 @@ declare module "node:stream" {
559
501
  * @since v17.5.0
560
502
  * @returns a promise containing an array with the contents of the stream.
561
503
  */
562
- toArray(options?: Abortable): Promise<any[]>;
504
+ toArray(options?: Pick<ArrayOptions, "signal">): Promise<any[]>;
563
505
  /**
564
506
  * This method is similar to `Array.prototype.some` and calls *fn* on each chunk in the stream
565
507
  * until the awaited return value is `true` (or any truthy value). Once an *fn* call on a chunk
@@ -570,8 +512,8 @@ declare module "node:stream" {
570
512
  * @returns a promise evaluating to `true` if *fn* returned a truthy value for at least one of the chunks.
571
513
  */
572
514
  some(
573
- fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
574
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
515
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
516
+ options?: ArrayOptions,
575
517
  ): Promise<boolean>;
576
518
  /**
577
519
  * This method is similar to `Array.prototype.find` and calls *fn* on each chunk in the stream
@@ -584,12 +526,12 @@ declare module "node:stream" {
584
526
  * or `undefined` if no element was found.
585
527
  */
586
528
  find<T>(
587
- fn: (data: any, options?: Abortable) => data is T,
588
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
529
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => data is T,
530
+ options?: ArrayOptions,
589
531
  ): Promise<T | undefined>;
590
532
  find(
591
- fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
592
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
533
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
534
+ options?: ArrayOptions,
593
535
  ): Promise<any>;
594
536
  /**
595
537
  * This method is similar to `Array.prototype.every` and calls *fn* on each chunk in the stream
@@ -601,8 +543,8 @@ declare module "node:stream" {
601
543
  * @returns a promise evaluating to `true` if *fn* returned a truthy value for every one of the chunks.
602
544
  */
603
545
  every(
604
- fn: (data: any, options?: Abortable) => boolean | Promise<boolean>,
605
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
546
+ fn: (data: any, options?: Pick<ArrayOptions, "signal">) => boolean | Promise<boolean>,
547
+ options?: ArrayOptions,
606
548
  ): Promise<boolean>;
607
549
  /**
608
550
  * This method returns a new stream by applying the given callback to each chunk of the stream
@@ -614,24 +556,28 @@ declare module "node:stream" {
614
556
  * @param fn a function to map over every chunk in the stream. May be async. May be a stream or generator.
615
557
  * @returns a stream flat-mapped with the function *fn*.
616
558
  */
617
- flatMap(
618
- fn: (data: any, options?: Abortable) => any,
619
- options?: Pick<ReadableOperatorOptions, "concurrency" | "signal">,
620
- ): Readable;
559
+ flatMap(fn: (data: any, options?: Pick<ArrayOptions, "signal">) => any, options?: ArrayOptions): Readable;
621
560
  /**
622
561
  * This method returns a new stream with the first *limit* chunks dropped from the start.
623
562
  * @since v17.5.0
624
563
  * @param limit the number of chunks to drop from the readable.
625
564
  * @returns a stream with *limit* chunks dropped from the start.
626
565
  */
627
- drop(limit: number, options?: Abortable): Readable;
566
+ drop(limit: number, options?: Pick<ArrayOptions, "signal">): Readable;
628
567
  /**
629
568
  * This method returns a new stream with the first *limit* chunks.
630
569
  * @since v17.5.0
631
570
  * @param limit the number of chunks to take from the readable.
632
571
  * @returns a stream with *limit* chunks taken.
633
572
  */
634
- take(limit: number, options?: Abortable): Readable;
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;
635
581
  /**
636
582
  * This method calls *fn* on each chunk of the stream in order, passing it the result from the calculation
637
583
  * on the previous element. It returns a promise for the final value of the reduction.
@@ -646,11 +592,15 @@ declare module "node:stream" {
646
592
  * @param initial the initial value to use in the reduction.
647
593
  * @returns a promise for the final value of the reduction.
648
594
  */
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,
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,
652
602
  initial: T,
653
- options?: Abortable,
603
+ options?: Pick<ArrayOptions, "signal">,
654
604
  ): Promise<T>;
655
605
  _destroy(error: Error | null, callback: (error?: Error | null) => void): void;
656
606
  /**
@@ -666,61 +616,78 @@ declare module "node:stream" {
666
616
  */
667
617
  destroy(error?: Error): this;
668
618
  /**
669
- * @returns `AsyncIterator` to fully consume the stream.
670
- * @since v10.0.0
671
- */
619
+ * Event emitter
620
+ * The defined events on documents including:
621
+ * 1. close
622
+ * 2. data
623
+ * 3. end
624
+ * 4. error
625
+ * 5. pause
626
+ * 6. readable
627
+ * 7. resume
628
+ */
629
+ addListener(event: "close", listener: () => void): this;
630
+ addListener(event: "data", listener: (chunk: any) => void): this;
631
+ addListener(event: "end", listener: () => void): this;
632
+ addListener(event: "error", listener: (err: Error) => void): this;
633
+ addListener(event: "pause", listener: () => void): this;
634
+ addListener(event: "readable", listener: () => void): this;
635
+ addListener(event: "resume", listener: () => void): this;
636
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
637
+ emit(event: "close"): boolean;
638
+ emit(event: "data", chunk: any): boolean;
639
+ emit(event: "end"): boolean;
640
+ emit(event: "error", err: Error): boolean;
641
+ emit(event: "pause"): boolean;
642
+ emit(event: "readable"): boolean;
643
+ emit(event: "resume"): boolean;
644
+ emit(event: string | symbol, ...args: any[]): boolean;
645
+ on(event: "close", listener: () => void): this;
646
+ on(event: "data", listener: (chunk: any) => void): this;
647
+ on(event: "end", listener: () => void): this;
648
+ on(event: "error", listener: (err: Error) => void): this;
649
+ on(event: "pause", listener: () => void): this;
650
+ on(event: "readable", listener: () => void): this;
651
+ on(event: "resume", listener: () => void): this;
652
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
653
+ once(event: "close", listener: () => void): this;
654
+ once(event: "data", listener: (chunk: any) => void): this;
655
+ once(event: "end", listener: () => void): this;
656
+ once(event: "error", listener: (err: Error) => void): this;
657
+ once(event: "pause", listener: () => void): this;
658
+ once(event: "readable", listener: () => void): this;
659
+ once(event: "resume", listener: () => void): this;
660
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
661
+ prependListener(event: "close", listener: () => void): this;
662
+ prependListener(event: "data", listener: (chunk: any) => void): this;
663
+ prependListener(event: "end", listener: () => void): this;
664
+ prependListener(event: "error", listener: (err: Error) => void): this;
665
+ prependListener(event: "pause", listener: () => void): this;
666
+ prependListener(event: "readable", listener: () => void): this;
667
+ prependListener(event: "resume", listener: () => void): this;
668
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
669
+ prependOnceListener(event: "close", listener: () => void): this;
670
+ prependOnceListener(event: "data", listener: (chunk: any) => void): this;
671
+ prependOnceListener(event: "end", listener: () => void): this;
672
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
673
+ prependOnceListener(event: "pause", listener: () => void): this;
674
+ prependOnceListener(event: "readable", listener: () => void): this;
675
+ prependOnceListener(event: "resume", listener: () => void): this;
676
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
677
+ removeListener(event: "close", listener: () => void): this;
678
+ removeListener(event: "data", listener: (chunk: any) => void): this;
679
+ removeListener(event: "end", listener: () => void): this;
680
+ removeListener(event: "error", listener: (err: Error) => void): this;
681
+ removeListener(event: "pause", listener: () => void): this;
682
+ removeListener(event: "readable", listener: () => void): this;
683
+ removeListener(event: "resume", listener: () => void): this;
684
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
672
685
  [Symbol.asyncIterator](): NodeJS.AsyncIterator<any>;
673
686
  /**
674
- * Calls `readable.destroy()` with an `AbortError` and returns
675
- * a promise that fulfills when the stream is finished.
687
+ * Calls `readable.destroy()` with an `AbortError` and returns a promise that fulfills when the stream is finished.
676
688
  * @since v20.4.0
677
689
  */
678
690
  [Symbol.asyncDispose](): Promise<void>;
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
724
691
  }
725
692
  interface WritableOptions<T extends Writable = Writable> extends StreamOptions<T> {
726
693
  decodeStrings?: boolean | undefined;
@@ -736,47 +703,38 @@ declare module "node:stream" {
736
703
  writev?:
737
704
  | ((
738
705
  this: T,
739
- chunks: {
706
+ chunks: Array<{
740
707
  chunk: any;
741
708
  encoding: BufferEncoding;
742
- }[],
709
+ }>,
743
710
  callback: (error?: Error | null) => void,
744
711
  ) => void)
745
712
  | undefined;
746
713
  final?: ((this: T, callback: (error?: Error | null) => void) => void) | undefined;
747
714
  }
748
- interface WritableEventMap {
749
- "close": [];
750
- "drain": [];
751
- "error": [err: Error];
752
- "finish": [];
753
- "pipe": [src: Readable];
754
- "unpipe": [src: Readable];
755
- }
756
715
  /**
757
716
  * @since v0.9.4
758
717
  */
759
718
  class Writable extends Stream implements NodeJS.WritableStream {
760
- constructor(options?: WritableOptions);
761
719
  /**
762
720
  * A utility method for creating a `Writable` from a web `WritableStream`.
763
721
  * @since v17.0.0
764
722
  */
765
723
  static fromWeb(
766
- writableStream: web.WritableStream,
724
+ writableStream: streamWeb.WritableStream,
767
725
  options?: Pick<WritableOptions, "decodeStrings" | "highWaterMark" | "objectMode" | "signal">,
768
726
  ): Writable;
769
727
  /**
770
728
  * A utility method for creating a web `WritableStream` from a `Writable`.
771
729
  * @since v17.0.0
772
730
  */
773
- static toWeb(streamWritable: NodeJS.WritableStream): web.WritableStream;
731
+ static toWeb(streamWritable: Writable): streamWeb.WritableStream;
774
732
  /**
775
733
  * Is `true` if it is safe to call `writable.write()`, which means
776
734
  * the stream has not been destroyed, errored, or ended.
777
735
  * @since v11.4.0
778
736
  */
779
- writable: boolean;
737
+ readonly writable: boolean;
780
738
  /**
781
739
  * Returns whether the stream was destroyed or errored before emitting `'finish'`.
782
740
  * @since v18.0.0, v16.17.0
@@ -836,12 +794,13 @@ declare module "node:stream" {
836
794
  * @since v15.2.0, v14.17.0
837
795
  */
838
796
  readonly writableNeedDrain: boolean;
797
+ constructor(opts?: WritableOptions);
839
798
  _write(chunk: any, encoding: BufferEncoding, callback: (error?: Error | null) => void): void;
840
799
  _writev?(
841
- chunks: {
800
+ chunks: Array<{
842
801
  chunk: any;
843
802
  encoding: BufferEncoding;
844
- }[],
803
+ }>,
845
804
  callback: (error?: Error | null) => void,
846
805
  ): void;
847
806
  _construct?(callback: (error?: Error | null) => void): void;
@@ -1003,56 +962,64 @@ declare module "node:stream" {
1003
962
  */
1004
963
  destroy(error?: Error): this;
1005
964
  /**
1006
- * Calls `writable.destroy()` with an `AbortError` and returns
1007
- * a promise that fulfills when the stream is finished.
1008
- * @since v22.4.0, v20.16.0
1009
- */
1010
- [Symbol.asyncDispose](): Promise<void>;
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
965
+ * Event emitter
966
+ * The defined events on documents including:
967
+ * 1. close
968
+ * 2. drain
969
+ * 3. error
970
+ * 4. finish
971
+ * 5. pipe
972
+ * 6. unpipe
973
+ */
974
+ addListener(event: "close", listener: () => void): this;
975
+ addListener(event: "drain", listener: () => void): this;
976
+ addListener(event: "error", listener: (err: Error) => void): this;
977
+ addListener(event: "finish", listener: () => void): this;
978
+ addListener(event: "pipe", listener: (src: Readable) => void): this;
979
+ addListener(event: "unpipe", listener: (src: Readable) => void): this;
980
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
981
+ emit(event: "close"): boolean;
982
+ emit(event: "drain"): boolean;
983
+ emit(event: "error", err: Error): boolean;
984
+ emit(event: "finish"): boolean;
985
+ emit(event: "pipe", src: Readable): boolean;
986
+ emit(event: "unpipe", src: Readable): boolean;
987
+ emit(event: string | symbol, ...args: any[]): boolean;
988
+ on(event: "close", listener: () => void): this;
989
+ on(event: "drain", listener: () => void): this;
990
+ on(event: "error", listener: (err: Error) => void): this;
991
+ on(event: "finish", listener: () => void): this;
992
+ on(event: "pipe", listener: (src: Readable) => void): this;
993
+ on(event: "unpipe", listener: (src: Readable) => void): this;
994
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
995
+ once(event: "close", listener: () => void): this;
996
+ once(event: "drain", listener: () => void): this;
997
+ once(event: "error", listener: (err: Error) => void): this;
998
+ once(event: "finish", listener: () => void): this;
999
+ once(event: "pipe", listener: (src: Readable) => void): this;
1000
+ once(event: "unpipe", listener: (src: Readable) => void): this;
1001
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
1002
+ prependListener(event: "close", listener: () => void): this;
1003
+ prependListener(event: "drain", listener: () => void): this;
1004
+ prependListener(event: "error", listener: (err: Error) => void): this;
1005
+ prependListener(event: "finish", listener: () => void): this;
1006
+ prependListener(event: "pipe", listener: (src: Readable) => void): this;
1007
+ prependListener(event: "unpipe", listener: (src: Readable) => void): this;
1008
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1009
+ prependOnceListener(event: "close", listener: () => void): this;
1010
+ prependOnceListener(event: "drain", listener: () => void): this;
1011
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
1012
+ prependOnceListener(event: "finish", listener: () => void): this;
1013
+ prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
1014
+ prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1015
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1016
+ removeListener(event: "close", listener: () => void): this;
1017
+ removeListener(event: "drain", listener: () => void): this;
1018
+ removeListener(event: "error", listener: (err: Error) => void): this;
1019
+ removeListener(event: "finish", listener: () => void): this;
1020
+ removeListener(event: "pipe", listener: (src: Readable) => void): this;
1021
+ removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1022
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1056
1023
  }
1057
1024
  interface DuplexOptions<T extends Duplex = Duplex> extends ReadableOptions<T>, WritableOptions<T> {
1058
1025
  allowHalfOpen?: boolean | undefined;
@@ -1062,10 +1029,6 @@ declare module "node:stream" {
1062
1029
  writableHighWaterMark?: number | undefined;
1063
1030
  writableCorked?: number | undefined;
1064
1031
  }
1065
- interface DuplexToWebOptions {
1066
- type?: web.ReadableStreamType | undefined;
1067
- }
1068
- interface DuplexEventMap extends ReadableEventMap, WritableEventMap {}
1069
1032
  /**
1070
1033
  * Duplex streams are streams that implement both the `Readable` and `Writable` interfaces.
1071
1034
  *
@@ -1077,7 +1040,17 @@ declare module "node:stream" {
1077
1040
  * @since v0.9.4
1078
1041
  */
1079
1042
  class Duplex extends Stream implements NodeJS.ReadWriteStream {
1080
- constructor(options?: DuplexOptions);
1043
+ /**
1044
+ * If `false` then the stream will automatically end the writable side when the
1045
+ * readable side ends. Set initially by the `allowHalfOpen` constructor option,
1046
+ * which defaults to `true`.
1047
+ *
1048
+ * This can be changed manually to change the half-open behavior of an existing
1049
+ * `Duplex` stream instance, but must be changed before the `'end'` event is emitted.
1050
+ * @since v0.9.4
1051
+ */
1052
+ allowHalfOpen: boolean;
1053
+ constructor(opts?: DuplexOptions);
1081
1054
  /**
1082
1055
  * A utility method for creating duplex streams.
1083
1056
  *
@@ -1101,87 +1074,137 @@ declare module "node:stream" {
1101
1074
  */
1102
1075
  static from(
1103
1076
  src:
1104
- | NodeJS.ReadableStream
1105
- | NodeJS.WritableStream
1106
- | Blob
1077
+ | Stream
1078
+ | NodeBlob
1079
+ | ArrayBuffer
1107
1080
  | string
1108
1081
  | Iterable<any>
1109
1082
  | AsyncIterable<any>
1110
- | ((source: AsyncIterable<any>) => AsyncIterable<any>)
1111
- | ((source: AsyncIterable<any>) => Promise<void>)
1083
+ | AsyncGeneratorFunction
1112
1084
  | Promise<any>
1113
- | web.ReadableWritablePair
1114
- | web.ReadableStream
1115
- | web.WritableStream,
1085
+ | Object,
1116
1086
  ): Duplex;
1117
1087
  /**
1118
1088
  * A utility method for creating a web `ReadableStream` and `WritableStream` from a `Duplex`.
1119
1089
  * @since v17.0.0
1120
1090
  */
1121
- static toWeb(streamDuplex: NodeJS.ReadWriteStream, options?: DuplexToWebOptions): web.ReadableWritablePair;
1091
+ static toWeb(streamDuplex: Duplex): {
1092
+ readable: streamWeb.ReadableStream;
1093
+ writable: streamWeb.WritableStream;
1094
+ };
1122
1095
  /**
1123
1096
  * A utility method for creating a `Duplex` from a web `ReadableStream` and `WritableStream`.
1124
1097
  * @since v17.0.0
1125
1098
  */
1126
1099
  static fromWeb(
1127
- duplexStream: web.ReadableWritablePair,
1100
+ duplexStream: {
1101
+ readable: streamWeb.ReadableStream;
1102
+ writable: streamWeb.WritableStream;
1103
+ },
1128
1104
  options?: Pick<
1129
1105
  DuplexOptions,
1130
1106
  "allowHalfOpen" | "decodeStrings" | "encoding" | "highWaterMark" | "objectMode" | "signal"
1131
1107
  >,
1132
1108
  ): Duplex;
1133
1109
  /**
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
1110
+ * Event emitter
1111
+ * The defined events on documents including:
1112
+ * 1. close
1113
+ * 2. data
1114
+ * 3. drain
1115
+ * 4. end
1116
+ * 5. error
1117
+ * 6. finish
1118
+ * 7. pause
1119
+ * 8. pipe
1120
+ * 9. readable
1121
+ * 10. resume
1122
+ * 11. unpipe
1123
+ */
1124
+ addListener(event: "close", listener: () => void): this;
1125
+ addListener(event: "data", listener: (chunk: any) => void): this;
1126
+ addListener(event: "drain", listener: () => void): this;
1127
+ addListener(event: "end", listener: () => void): this;
1128
+ addListener(event: "error", listener: (err: Error) => void): this;
1129
+ addListener(event: "finish", listener: () => void): this;
1130
+ addListener(event: "pause", listener: () => void): this;
1131
+ addListener(event: "pipe", listener: (src: Readable) => void): this;
1132
+ addListener(event: "readable", listener: () => void): this;
1133
+ addListener(event: "resume", listener: () => void): this;
1134
+ addListener(event: "unpipe", listener: (src: Readable) => void): this;
1135
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1136
+ emit(event: "close"): boolean;
1137
+ emit(event: "data", chunk: any): boolean;
1138
+ emit(event: "drain"): boolean;
1139
+ emit(event: "end"): boolean;
1140
+ emit(event: "error", err: Error): boolean;
1141
+ emit(event: "finish"): boolean;
1142
+ emit(event: "pause"): boolean;
1143
+ emit(event: "pipe", src: Readable): boolean;
1144
+ emit(event: "readable"): boolean;
1145
+ emit(event: "resume"): boolean;
1146
+ emit(event: "unpipe", src: Readable): boolean;
1147
+ emit(event: string | symbol, ...args: any[]): boolean;
1148
+ on(event: "close", listener: () => void): this;
1149
+ on(event: "data", listener: (chunk: any) => void): this;
1150
+ on(event: "drain", listener: () => void): this;
1151
+ on(event: "end", listener: () => void): this;
1152
+ on(event: "error", listener: (err: Error) => void): this;
1153
+ on(event: "finish", listener: () => void): this;
1154
+ on(event: "pause", listener: () => void): this;
1155
+ on(event: "pipe", listener: (src: Readable) => void): this;
1156
+ on(event: "readable", listener: () => void): this;
1157
+ on(event: "resume", listener: () => void): this;
1158
+ on(event: "unpipe", listener: (src: Readable) => void): this;
1159
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
1160
+ once(event: "close", listener: () => void): this;
1161
+ once(event: "data", listener: (chunk: any) => void): this;
1162
+ once(event: "drain", listener: () => void): this;
1163
+ once(event: "end", listener: () => void): this;
1164
+ once(event: "error", listener: (err: Error) => void): this;
1165
+ once(event: "finish", listener: () => void): this;
1166
+ once(event: "pause", listener: () => void): this;
1167
+ once(event: "pipe", listener: (src: Readable) => void): this;
1168
+ once(event: "readable", listener: () => void): this;
1169
+ once(event: "resume", listener: () => void): this;
1170
+ once(event: "unpipe", listener: (src: Readable) => void): this;
1171
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
1172
+ prependListener(event: "close", listener: () => void): this;
1173
+ prependListener(event: "data", listener: (chunk: any) => void): this;
1174
+ prependListener(event: "drain", listener: () => void): this;
1175
+ prependListener(event: "end", listener: () => void): this;
1176
+ prependListener(event: "error", listener: (err: Error) => void): this;
1177
+ prependListener(event: "finish", listener: () => void): this;
1178
+ prependListener(event: "pause", listener: () => void): this;
1179
+ prependListener(event: "pipe", listener: (src: Readable) => void): this;
1180
+ prependListener(event: "readable", listener: () => void): this;
1181
+ prependListener(event: "resume", listener: () => void): this;
1182
+ prependListener(event: "unpipe", listener: (src: Readable) => void): this;
1183
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1184
+ prependOnceListener(event: "close", listener: () => void): this;
1185
+ prependOnceListener(event: "data", listener: (chunk: any) => void): this;
1186
+ prependOnceListener(event: "drain", listener: () => void): this;
1187
+ prependOnceListener(event: "end", listener: () => void): this;
1188
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
1189
+ prependOnceListener(event: "finish", listener: () => void): this;
1190
+ prependOnceListener(event: "pause", listener: () => void): this;
1191
+ prependOnceListener(event: "pipe", listener: (src: Readable) => void): this;
1192
+ prependOnceListener(event: "readable", listener: () => void): this;
1193
+ prependOnceListener(event: "resume", listener: () => void): this;
1194
+ prependOnceListener(event: "unpipe", listener: (src: Readable) => void): this;
1195
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1196
+ removeListener(event: "close", listener: () => void): this;
1197
+ removeListener(event: "data", listener: (chunk: any) => void): this;
1198
+ removeListener(event: "drain", listener: () => void): this;
1199
+ removeListener(event: "end", listener: () => void): this;
1200
+ removeListener(event: "error", listener: (err: Error) => void): this;
1201
+ removeListener(event: "finish", listener: () => void): this;
1202
+ removeListener(event: "pause", listener: () => void): this;
1203
+ removeListener(event: "pipe", listener: (src: Readable) => void): this;
1204
+ removeListener(event: "readable", listener: () => void): this;
1205
+ removeListener(event: "resume", listener: () => void): this;
1206
+ removeListener(event: "unpipe", listener: (src: Readable) => void): this;
1207
+ removeListener(event: string | symbol, listener: (...args: any[]) => void): this;
1185
1208
  }
1186
1209
  interface Duplex extends Readable, Writable {}
1187
1210
  /**
@@ -1222,7 +1245,7 @@ declare module "node:stream" {
1222
1245
  * @since v0.9.4
1223
1246
  */
1224
1247
  class Transform extends Duplex {
1225
- constructor(options?: TransformOptions);
1248
+ constructor(opts?: TransformOptions);
1226
1249
  _transform(chunk: any, encoding: BufferEncoding, callback: TransformCallback): void;
1227
1250
  _flush(callback: TransformCallback): void;
1228
1251
  }
@@ -1310,9 +1333,7 @@ declare module "node:stream" {
1310
1333
  * @param signal A signal representing possible cancellation
1311
1334
  * @param stream A stream to attach a signal to.
1312
1335
  */
1313
- function addAbortSignal<
1314
- T extends NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1315
- >(signal: AbortSignal, stream: T): T;
1336
+ function addAbortSignal<T extends Stream>(signal: AbortSignal, stream: T): T;
1316
1337
  /**
1317
1338
  * Returns the default highWaterMark used by streams.
1318
1339
  * Defaults to `65536` (64 KiB), or `16` for `objectMode`.
@@ -1356,7 +1377,7 @@ declare module "node:stream" {
1356
1377
  * Especially useful in error handling scenarios where a stream is destroyed
1357
1378
  * prematurely (like an aborted HTTP request), and will not emit `'end'` or `'finish'`.
1358
1379
  *
1359
- * The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streamfinishedstream-options).
1380
+ * The `finished` API provides [`promise version`](https://nodejs.org/docs/latest-v22.x/api/stream.html#streamfinishedstream-options).
1360
1381
  *
1361
1382
  * `stream.finished()` leaves dangling event listeners (in particular `'error'`, `'end'`, `'finish'` and `'close'`) after `callback` has been
1362
1383
  * invoked. The reason for this is so that unexpected `'error'` events (due to
@@ -1376,57 +1397,46 @@ declare module "node:stream" {
1376
1397
  * @returns A cleanup function which removes all registered listeners.
1377
1398
  */
1378
1399
  function finished(
1379
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1400
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1380
1401
  options: FinishedOptions,
1381
1402
  callback: (err?: NodeJS.ErrnoException | null) => void,
1382
1403
  ): () => void;
1383
1404
  function finished(
1384
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1405
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1385
1406
  callback: (err?: NodeJS.ErrnoException | null) => void,
1386
1407
  ): () => void;
1387
1408
  namespace finished {
1388
- import __promisify__ = promises.finished;
1389
- export { __promisify__ };
1409
+ function __promisify__(
1410
+ stream: NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream,
1411
+ options?: FinishedOptions,
1412
+ ): Promise<void>;
1390
1413
  }
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> =
1414
+ type PipelineSourceFunction<T> = () => Iterable<T> | AsyncIterable<T>;
1415
+ type PipelineSource<T> = Iterable<T> | AsyncIterable<T> | NodeJS.ReadableStream | PipelineSourceFunction<T>;
1416
+ type PipelineTransform<S extends PipelineTransformSource<any>, U> =
1407
1417
  | NodeJS.ReadWriteStream
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> ?
1418
+ | ((
1419
+ source: S extends (...args: any[]) => Iterable<infer ST> | AsyncIterable<infer ST> ? AsyncIterable<ST>
1420
+ : S,
1421
+ ) => AsyncIterable<U>);
1422
+ type PipelineTransformSource<T> = PipelineSource<T> | PipelineTransform<any, T>;
1423
+ type PipelineDestinationIterableFunction<T> = (source: AsyncIterable<T>) => AsyncIterable<any>;
1424
+ type PipelineDestinationPromiseFunction<T, P> = (source: AsyncIterable<T>) => Promise<P>;
1425
+ type PipelineDestination<S extends PipelineTransformSource<any>, P> = S extends
1426
+ PipelineTransformSource<infer ST> ?
1420
1427
  | NodeJS.WritableStream
1421
- | web.WritableStream<I>
1422
- | web.TransformStream<I, any>
1423
- | PipelineDestinationFunction<S, R>
1428
+ | PipelineDestinationIterableFunction<ST>
1429
+ | PipelineDestinationPromiseFunction<ST, P>
1424
1430
  : never;
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;
1431
+ type PipelineCallback<S extends PipelineDestination<any, any>> = S extends
1432
+ PipelineDestinationPromiseFunction<any, infer P> ? (err: NodeJS.ErrnoException | null, value: P) => void
1433
+ : (err: NodeJS.ErrnoException | null) => void;
1434
+ type PipelinePromise<S extends PipelineDestination<any, any>> = S extends
1435
+ PipelineDestinationPromiseFunction<any, infer P> ? Promise<P> : Promise<void>;
1436
+ interface PipelineOptions {
1437
+ signal?: AbortSignal | undefined;
1438
+ end?: boolean | undefined;
1439
+ }
1430
1440
  /**
1431
1441
  * A module method to pipe between streams and generators forwarding errors and
1432
1442
  * properly cleaning up and provide a callback when the pipeline is complete.
@@ -1455,7 +1465,7 @@ declare module "node:stream" {
1455
1465
  * );
1456
1466
  * ```
1457
1467
  *
1458
- * The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v25.x/api/stream.html#streampipelinesource-transforms-destination-options).
1468
+ * The `pipeline` API provides a [`promise version`](https://nodejs.org/docs/latest-v22.x/api/stream.html#streampipelinesource-transforms-destination-options).
1459
1469
  *
1460
1470
  * `stream.pipeline()` will call `stream.destroy(err)` on all streams except:
1461
1471
  *
@@ -1492,279 +1502,163 @@ declare module "node:stream" {
1492
1502
  * @since v10.0.0
1493
1503
  * @param callback Called when the pipeline is fully done.
1494
1504
  */
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>;
1505
+ function pipeline<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1506
+ source: A,
1507
+ destination: B,
1508
+ callback: PipelineCallback<B>,
1509
+ ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1500
1510
  function pipeline<
1501
- S extends PipelineSource<any>,
1502
- T extends PipelineTransform<S, any>,
1503
- D extends PipelineDestination<T, any>,
1511
+ A extends PipelineSource<any>,
1512
+ T1 extends PipelineTransform<A, any>,
1513
+ B extends PipelineDestination<T1, any>,
1504
1514
  >(
1505
- source: S,
1506
- transform: T,
1507
- destination: D,
1508
- callback: PipelineCallback<D>,
1509
- ): PipelineResult<D>;
1515
+ source: A,
1516
+ transform1: T1,
1517
+ destination: B,
1518
+ callback: PipelineCallback<B>,
1519
+ ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1510
1520
  function pipeline<
1511
- S extends PipelineSource<any>,
1512
- T1 extends PipelineTransform<S, any>,
1521
+ A extends PipelineSource<any>,
1522
+ T1 extends PipelineTransform<A, any>,
1513
1523
  T2 extends PipelineTransform<T1, any>,
1514
- D extends PipelineDestination<T2, any>,
1524
+ B extends PipelineDestination<T2, any>,
1515
1525
  >(
1516
- source: S,
1526
+ source: A,
1517
1527
  transform1: T1,
1518
1528
  transform2: T2,
1519
- destination: D,
1520
- callback: PipelineCallback<D>,
1521
- ): PipelineResult<D>;
1529
+ destination: B,
1530
+ callback: PipelineCallback<B>,
1531
+ ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1522
1532
  function pipeline<
1523
- S extends PipelineSource<any>,
1524
- T1 extends PipelineTransform<S, any>,
1533
+ A extends PipelineSource<any>,
1534
+ T1 extends PipelineTransform<A, any>,
1525
1535
  T2 extends PipelineTransform<T1, any>,
1526
1536
  T3 extends PipelineTransform<T2, any>,
1527
- D extends PipelineDestination<T3, any>,
1537
+ B extends PipelineDestination<T3, any>,
1528
1538
  >(
1529
- source: S,
1539
+ source: A,
1530
1540
  transform1: T1,
1531
1541
  transform2: T2,
1532
1542
  transform3: T3,
1533
- destination: D,
1534
- callback: PipelineCallback<D>,
1535
- ): PipelineResult<D>;
1543
+ destination: B,
1544
+ callback: PipelineCallback<B>,
1545
+ ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1536
1546
  function pipeline<
1537
- S extends PipelineSource<any>,
1538
- T1 extends PipelineTransform<S, any>,
1547
+ A extends PipelineSource<any>,
1548
+ T1 extends PipelineTransform<A, any>,
1539
1549
  T2 extends PipelineTransform<T1, any>,
1540
1550
  T3 extends PipelineTransform<T2, any>,
1541
1551
  T4 extends PipelineTransform<T3, any>,
1542
- D extends PipelineDestination<T4, any>,
1552
+ B extends PipelineDestination<T4, any>,
1543
1553
  >(
1544
- source: S,
1554
+ source: A,
1545
1555
  transform1: T1,
1546
1556
  transform2: T2,
1547
1557
  transform3: T3,
1548
1558
  transform4: T4,
1549
- destination: D,
1550
- callback: PipelineCallback<D>,
1551
- ): PipelineResult<D>;
1559
+ destination: B,
1560
+ callback: PipelineCallback<B>,
1561
+ ): B extends NodeJS.WritableStream ? B : NodeJS.WritableStream;
1552
1562
  function pipeline(
1553
- streams: ReadonlyArray<PipelineSource<any> | PipelineTransform<any, any> | PipelineDestination<any, any>>,
1563
+ streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1554
1564
  callback: (err: NodeJS.ErrnoException | null) => void,
1555
1565
  ): NodeJS.WritableStream;
1556
1566
  function pipeline(
1557
- ...streams: [
1558
- ...[PipelineSource<any>, ...PipelineTransform<any, any>[], PipelineDestination<any, any>],
1559
- callback: ((err: NodeJS.ErrnoException | null) => void),
1560
- ]
1567
+ stream1: NodeJS.ReadableStream,
1568
+ stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1569
+ ...streams: Array<
1570
+ NodeJS.ReadWriteStream | NodeJS.WritableStream | ((err: NodeJS.ErrnoException | null) => void)
1571
+ >
1561
1572
  ): NodeJS.WritableStream;
1562
1573
  namespace pipeline {
1563
- import __promisify__ = promises.pipeline;
1564
- export { __promisify__ };
1574
+ function __promisify__<A extends PipelineSource<any>, B extends PipelineDestination<A, any>>(
1575
+ source: A,
1576
+ destination: B,
1577
+ options?: PipelineOptions,
1578
+ ): PipelinePromise<B>;
1579
+ function __promisify__<
1580
+ A extends PipelineSource<any>,
1581
+ T1 extends PipelineTransform<A, any>,
1582
+ B extends PipelineDestination<T1, any>,
1583
+ >(
1584
+ source: A,
1585
+ transform1: T1,
1586
+ destination: B,
1587
+ options?: PipelineOptions,
1588
+ ): PipelinePromise<B>;
1589
+ function __promisify__<
1590
+ A extends PipelineSource<any>,
1591
+ T1 extends PipelineTransform<A, any>,
1592
+ T2 extends PipelineTransform<T1, any>,
1593
+ B extends PipelineDestination<T2, any>,
1594
+ >(
1595
+ source: A,
1596
+ transform1: T1,
1597
+ transform2: T2,
1598
+ destination: B,
1599
+ options?: PipelineOptions,
1600
+ ): PipelinePromise<B>;
1601
+ function __promisify__<
1602
+ A extends PipelineSource<any>,
1603
+ T1 extends PipelineTransform<A, any>,
1604
+ T2 extends PipelineTransform<T1, any>,
1605
+ T3 extends PipelineTransform<T2, any>,
1606
+ B extends PipelineDestination<T3, any>,
1607
+ >(
1608
+ source: A,
1609
+ transform1: T1,
1610
+ transform2: T2,
1611
+ transform3: T3,
1612
+ destination: B,
1613
+ options?: PipelineOptions,
1614
+ ): PipelinePromise<B>;
1615
+ function __promisify__<
1616
+ A extends PipelineSource<any>,
1617
+ T1 extends PipelineTransform<A, any>,
1618
+ T2 extends PipelineTransform<T1, any>,
1619
+ T3 extends PipelineTransform<T2, any>,
1620
+ T4 extends PipelineTransform<T3, any>,
1621
+ B extends PipelineDestination<T4, any>,
1622
+ >(
1623
+ source: A,
1624
+ transform1: T1,
1625
+ transform2: T2,
1626
+ transform3: T3,
1627
+ transform4: T4,
1628
+ destination: B,
1629
+ options?: PipelineOptions,
1630
+ ): PipelinePromise<B>;
1631
+ function __promisify__(
1632
+ streams: ReadonlyArray<NodeJS.ReadableStream | NodeJS.WritableStream | NodeJS.ReadWriteStream>,
1633
+ options?: PipelineOptions,
1634
+ ): Promise<void>;
1635
+ function __promisify__(
1636
+ stream1: NodeJS.ReadableStream,
1637
+ stream2: NodeJS.ReadWriteStream | NodeJS.WritableStream,
1638
+ ...streams: Array<NodeJS.ReadWriteStream | NodeJS.WritableStream | PipelineOptions>
1639
+ ): Promise<void>;
1640
+ }
1641
+ // TODO: this interface never existed; remove in next major
1642
+ interface Pipe {
1643
+ close(): void;
1644
+ hasRef(): boolean;
1645
+ ref(): void;
1646
+ unref(): void;
1565
1647
  }
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 */
1713
1648
  /**
1714
1649
  * Returns whether the stream has encountered an error.
1715
1650
  * @since v17.3.0, v16.14.0
1716
1651
  */
1717
- function isErrored(
1718
- stream: NodeJS.ReadableStream | NodeJS.WritableStream | web.ReadableStream | web.WritableStream,
1719
- ): boolean;
1652
+ function isErrored(stream: Readable | Writable | NodeJS.ReadableStream | NodeJS.WritableStream): boolean;
1720
1653
  /**
1721
1654
  * Returns whether the stream is readable.
1722
1655
  * @since v17.4.0, v16.14.0
1723
- * @returns Only returns `null` if `stream` is not a valid `Readable`, `Duplex` or `ReadableStream`.
1724
- */
1725
- function isReadable(stream: NodeJS.ReadableStream | web.ReadableStream): boolean | null;
1726
- /**
1727
- * Returns whether the stream is writable.
1728
- * @since v20.0.0
1729
- * @returns Only returns `null` if `stream` is not a valid `Writable`, `Duplex` or `WritableStream`.
1730
1656
  */
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
- }
1657
+ function isReadable(stream: Readable | NodeJS.ReadableStream): boolean;
1764
1658
  }
1765
1659
  export = Stream;
1766
1660
  }
1767
- declare module "stream" {
1768
- import stream = require("node:stream");
1661
+ declare module "node:stream" {
1662
+ import stream = require("stream");
1769
1663
  export = stream;
1770
1664
  }