Skip to content

Commit f306544

Browse files
robhoganfacebook-github-bot
authored andcommitted
Add Flow lib defs for Node.js streams fromWeb/toWeb (#54615)
Summary: Since v17 (and stable since v22.17), Node.js has helper methods for converting [Node streams](https://nodejs.org/api/stream.html) to/from [Web streams](https://developer.mozilla.org/en-US/docs/Web/API/Streams_API) (e.g., as returned by global `fetch`). This adds the Flow typings. - Node docs: https://nodejs.org/api/stream.html#streamreadablefromwebreadablestream-options Changelog: [General][Internal] Monorepo Flow typings Differential Revision: D87543561
1 parent f0a7ecd commit f306544

1 file changed

Lines changed: 42 additions & 7 deletions

File tree

flow-typed/environment/node.js

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2536,11 +2536,6 @@ type readableStreamOptions = {
25362536
...
25372537
};
25382538
declare class stream$Readable extends stream$Stream {
2539-
static from(
2540-
iterable: Iterable<any> | AsyncIterable<any>,
2541-
options?: readableStreamOptions,
2542-
): stream$Readable;
2543-
25442539
constructor(options?: readableStreamOptions): void;
25452540
destroy(error?: Error): this;
25462541
isPaused(): boolean;
@@ -2641,6 +2636,21 @@ type duplexStreamOptions = writableStreamOptions &
26412636
...
26422637
};
26432638
declare class stream$Duplex extends stream$Readable mixins stream$Writable {
2639+
static fromWeb(
2640+
pair: Readonly<{
2641+
readable: ReadableStream,
2642+
writable: WritableStream,
2643+
...
2644+
}>,
2645+
options?: duplexStreamOptions,
2646+
): stream$Duplex;
2647+
2648+
static toWeb(streamDuplex: stream$Duplex): {
2649+
readable: ReadableStream,
2650+
writable: WritableStream,
2651+
...
2652+
};
2653+
26442654
constructor(options?: duplexStreamOptions): void;
26452655
}
26462656
type transformStreamOptions = duplexStreamOptions & {
@@ -2665,8 +2675,27 @@ declare class stream$PassThrough extends stream$Transform {}
26652675

26662676
declare module 'stream' {
26672677
declare var Stream: typeof stream$Stream;
2668-
declare var Readable: typeof stream$Readable;
2669-
declare var Writable: typeof stream$Writable;
2678+
declare class Readable extends stream$Readable {
2679+
static from(
2680+
iterable: Iterable<any> | AsyncIterable<any>,
2681+
options?: readableStreamOptions,
2682+
): Readable;
2683+
2684+
static fromWeb(
2685+
readableStream: ReadableStream,
2686+
options?: readableStreamOptions,
2687+
): Readable;
2688+
2689+
static toWeb(streamReadable: stream$Readable): ReadableStream;
2690+
}
2691+
declare class Writable extends stream$Writable {
2692+
static fromWeb(
2693+
writableStream: WritableStream,
2694+
options?: writableStreamOptions,
2695+
): Writable;
2696+
2697+
static toWeb(streamWritable: stream$Writable): WritableStream;
2698+
}
26702699
declare var Duplex: typeof stream$Duplex;
26712700
declare var Transform: typeof stream$Transform;
26722701
declare var PassThrough: typeof stream$PassThrough;
@@ -2795,6 +2824,12 @@ declare module 'stream' {
27952824
declare var promises: StreamPromise;
27962825
}
27972826

2827+
declare namespace NodeJS {
2828+
interface ReadableStream extends stream$Readable {}
2829+
interface WritableStream extends stream$Writable {}
2830+
interface ReadWriteStream extends stream$Duplex {}
2831+
}
2832+
27982833
declare class tty$ReadStream extends net$Socket {
27992834
constructor(fd: number, options?: Object): void;
28002835
isRaw: boolean;

0 commit comments

Comments
 (0)