@yume-chan/stream-extra 2.5.3 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/LICENSE +1 -1
  2. package/esm/buffered-transform.d.ts +2 -2
  3. package/esm/buffered-transform.d.ts.map +1 -1
  4. package/esm/buffered-transform.js +1 -1
  5. package/esm/buffered-transform.js.map +1 -1
  6. package/esm/buffered.d.ts +1 -1
  7. package/esm/buffered.d.ts.map +1 -1
  8. package/esm/buffered.js.map +1 -1
  9. package/esm/concat.d.ts +25 -16
  10. package/esm/concat.d.ts.map +1 -1
  11. package/esm/concat.js +124 -93
  12. package/esm/concat.js.map +1 -1
  13. package/esm/consumable/readable.d.ts +2 -2
  14. package/esm/consumable/readable.d.ts.map +1 -1
  15. package/esm/consumable/readable.js +1 -1
  16. package/esm/consumable/readable.js.map +1 -1
  17. package/esm/consumable/wrap-byte-readable.d.ts +5 -2
  18. package/esm/consumable/wrap-byte-readable.d.ts.map +1 -1
  19. package/esm/consumable/wrap-byte-readable.js +12 -6
  20. package/esm/consumable/wrap-byte-readable.js.map +1 -1
  21. package/esm/consumable/wrap-writable.d.ts +1 -1
  22. package/esm/consumable/wrap-writable.d.ts.map +1 -1
  23. package/esm/consumable/wrap-writable.js +1 -1
  24. package/esm/consumable/wrap-writable.js.map +1 -1
  25. package/esm/consumable/writable.d.ts +2 -2
  26. package/esm/consumable/writable.d.ts.map +1 -1
  27. package/esm/consumable/writable.js +1 -1
  28. package/esm/consumable/writable.js.map +1 -1
  29. package/esm/consumable.d.ts +4 -0
  30. package/esm/consumable.d.ts.map +1 -1
  31. package/esm/consumable.js +5 -0
  32. package/esm/consumable.js.map +1 -1
  33. package/esm/distribution.d.ts +1 -1
  34. package/esm/distribution.d.ts.map +1 -1
  35. package/esm/distribution.js +1 -1
  36. package/esm/distribution.js.map +1 -1
  37. package/esm/duplex.d.ts +2 -2
  38. package/esm/duplex.d.ts.map +1 -1
  39. package/esm/duplex.js +1 -1
  40. package/esm/duplex.js.map +1 -1
  41. package/esm/global/abort-signal.d.ts +87 -0
  42. package/esm/global/abort-signal.d.ts.map +1 -0
  43. package/esm/global/abort-signal.js +4 -0
  44. package/esm/global/abort-signal.js.map +1 -0
  45. package/esm/global/compression.d.ts +15 -0
  46. package/esm/global/compression.d.ts.map +1 -0
  47. package/esm/global/compression.js +4 -0
  48. package/esm/global/compression.js.map +1 -0
  49. package/esm/global/encoding.d.ts +25 -0
  50. package/esm/global/encoding.d.ts.map +1 -0
  51. package/esm/global/encoding.js +4 -0
  52. package/esm/global/encoding.js.map +1 -0
  53. package/esm/global/event.d.ts +191 -0
  54. package/esm/global/event.d.ts.map +1 -0
  55. package/esm/global/event.js +4 -0
  56. package/esm/global/event.js.map +1 -0
  57. package/esm/global/index.d.ts +7 -0
  58. package/esm/global/index.d.ts.map +1 -0
  59. package/esm/global/index.js +7 -0
  60. package/esm/global/index.js.map +1 -0
  61. package/esm/{types.d.ts → global/streams.d.ts} +136 -222
  62. package/esm/global/streams.d.ts.map +1 -0
  63. package/esm/{stream.js → global/streams.js} +16 -8
  64. package/esm/global/streams.js.map +1 -0
  65. package/esm/global/timer.d.ts +13 -0
  66. package/esm/global/timer.d.ts.map +1 -0
  67. package/esm/global/timer.js +4 -0
  68. package/esm/global/timer.js.map +1 -0
  69. package/esm/global/utils.d.ts +9 -0
  70. package/esm/global/utils.d.ts.map +1 -0
  71. package/esm/global/utils.js +5 -0
  72. package/esm/global/utils.js.map +1 -0
  73. package/esm/index.d.ts +2 -2
  74. package/esm/index.d.ts.map +1 -1
  75. package/esm/index.js +2 -2
  76. package/esm/index.js.map +1 -1
  77. package/esm/inspect.d.ts +6 -2
  78. package/esm/inspect.d.ts.map +1 -1
  79. package/esm/inspect.js +10 -4
  80. package/esm/inspect.js.map +1 -1
  81. package/esm/maybe-consumable/wrap-writable.d.ts +1 -1
  82. package/esm/maybe-consumable/wrap-writable.d.ts.map +1 -1
  83. package/esm/maybe-consumable/wrap-writable.js +1 -1
  84. package/esm/maybe-consumable/wrap-writable.js.map +1 -1
  85. package/esm/maybe-consumable/writable.d.ts +2 -2
  86. package/esm/maybe-consumable/writable.d.ts.map +1 -1
  87. package/esm/maybe-consumable/writable.js +1 -1
  88. package/esm/maybe-consumable/writable.js.map +1 -1
  89. package/esm/pipe-from.d.ts +3 -3
  90. package/esm/pipe-from.d.ts.map +1 -1
  91. package/esm/pipe-from.js +1 -1
  92. package/esm/pipe-from.js.map +1 -1
  93. package/esm/push-readable.d.ts +20 -3
  94. package/esm/push-readable.d.ts.map +1 -1
  95. package/esm/push-readable.js +180 -180
  96. package/esm/push-readable.js.map +1 -1
  97. package/esm/split-string.d.ts +6 -2
  98. package/esm/split-string.d.ts.map +1 -1
  99. package/esm/split-string.js +28 -7
  100. package/esm/split-string.js.map +1 -1
  101. package/esm/struct-deserialize.js.map +1 -1
  102. package/esm/struct-serialize.d.ts +1 -1
  103. package/esm/struct-serialize.d.ts.map +1 -1
  104. package/esm/struct-serialize.js +1 -1
  105. package/esm/struct-serialize.js.map +1 -1
  106. package/esm/task-queue.d.ts +8 -0
  107. package/esm/task-queue.d.ts.map +1 -0
  108. package/esm/task-queue.js +50 -0
  109. package/esm/task-queue.js.map +1 -0
  110. package/esm/try-close.d.ts +3 -5
  111. package/esm/try-close.d.ts.map +1 -1
  112. package/esm/try-close.js.map +1 -1
  113. package/esm/wrap-readable.d.ts +2 -2
  114. package/esm/wrap-readable.d.ts.map +1 -1
  115. package/esm/wrap-readable.js +1 -1
  116. package/esm/wrap-readable.js.map +1 -1
  117. package/esm/wrap-writable.d.ts +2 -2
  118. package/esm/wrap-writable.d.ts.map +1 -1
  119. package/esm/wrap-writable.js +1 -1
  120. package/esm/wrap-writable.js.map +1 -1
  121. package/package.json +8 -8
  122. package/src/buffered-transform.ts +8 -7
  123. package/src/buffered.ts +4 -1
  124. package/src/concat.ts +161 -118
  125. package/src/consumable/readable.ts +2 -2
  126. package/src/consumable/wrap-byte-readable.ts +20 -7
  127. package/src/consumable/wrap-writable.ts +1 -1
  128. package/src/consumable/writable.ts +2 -2
  129. package/src/consumable.ts +8 -0
  130. package/src/distribution.ts +1 -1
  131. package/src/duplex.ts +2 -2
  132. package/src/global/abort-signal.ts +129 -0
  133. package/src/global/compression.ts +28 -0
  134. package/src/global/encoding.ts +36 -0
  135. package/src/global/event.ts +221 -0
  136. package/src/global/index.ts +6 -0
  137. package/src/{types.ts → global/streams.ts} +266 -244
  138. package/src/global/timer.ts +18 -0
  139. package/src/global/utils.ts +14 -0
  140. package/src/index.ts +2 -2
  141. package/src/inspect.ts +18 -4
  142. package/src/maybe-consumable/wrap-writable.ts +1 -1
  143. package/src/maybe-consumable/writable.ts +3 -3
  144. package/src/pipe-from.ts +2 -2
  145. package/src/push-readable.ts +226 -198
  146. package/src/split-string.ts +41 -7
  147. package/src/struct-deserialize.ts +1 -1
  148. package/src/struct-serialize.ts +1 -1
  149. package/src/task-queue.ts +69 -0
  150. package/src/try-close.ts +0 -12
  151. package/src/wrap-readable.ts +2 -2
  152. package/src/wrap-writable.ts +5 -2
  153. package/tsconfig.build.json +1 -6
  154. package/CHANGELOG.md +0 -102
  155. package/esm/encoding.d.ts +0 -21
  156. package/esm/encoding.d.ts.map +0 -1
  157. package/esm/encoding.js +0 -4
  158. package/esm/encoding.js.map +0 -1
  159. package/esm/stream.d.ts +0 -25
  160. package/esm/stream.d.ts.map +0 -1
  161. package/esm/stream.js.map +0 -1
  162. package/esm/types.d.ts.map +0 -1
  163. package/esm/types.js +0 -3
  164. package/esm/types.js.map +0 -1
  165. package/src/encoding.ts +0 -39
  166. package/src/stream.ts +0 -106
  167. package/tsconfig.build.tsbuildinfo +0 -1
@@ -1,154 +1,147 @@
1
1
  /// <reference lib="es2018.asynciterable" />
2
2
 
3
- /**
4
- * A signal object that allows you to communicate with a request and abort it if required
5
- * via its associated `AbortController` object.
6
- *
7
- * @remarks
8
- * This interface is compatible with the `AbortSignal` interface defined in TypeScript's DOM types.
9
- * It is redefined here, so it can be polyfilled without a DOM, for example with
10
- * {@link https://www.npmjs.com/package/abortcontroller-polyfill | abortcontroller-polyfill} in a Node environment.
11
- *
12
- * @public
13
- */
14
- export declare interface AbortSignal {
15
- /**
16
- * Whether the request is aborted.
17
- */
18
- readonly aborted: boolean;
19
- /**
20
- * If aborted, returns the reason for aborting.
21
- */
22
- readonly reason?: unknown;
23
- /**
24
- * Add an event listener to be triggered when this signal becomes aborted.
25
- */
26
- addEventListener(type: "abort", listener: () => void): void;
27
- /**
28
- * Remove an event listener that was previously added with {@link AbortSignal.addEventListener}.
29
- */
30
- removeEventListener(type: "abort", listener: () => void): void;
31
- throwIfAborted(): void;
3
+ import { tryCancel } from "../try-close.js";
4
+
5
+ import type { AbortSignal } from "./abort-signal.js";
6
+ import type { GlobalPrototypeOr, GlobalValueOr } from "./utils.js";
7
+ import { getGlobalValue } from "./utils.js";
8
+
9
+ export interface QueuingStrategySize<T = unknown> {
10
+ (chunk: T): number;
32
11
  }
33
12
 
34
- /**
35
- * A queuing strategy that counts the number of bytes in each chunk.
36
- *
37
- * @public
38
- */
39
- export declare class ByteLengthQueuingStrategy
40
- implements QueuingStrategy<ArrayBufferView>
41
- {
42
- constructor(options: QueuingStrategyInit);
43
- /**
44
- * Returns the high water mark provided to the constructor.
45
- */
46
- get highWaterMark(): number;
47
- /**
48
- * Measures the size of `chunk` by returning the value of its `byteLength` property.
49
- */
50
- get size(): (chunk: ArrayBufferView) => number;
13
+ export interface QueuingStrategy<T = unknown> {
14
+ highWaterMark?: number;
15
+ size?: QueuingStrategySize<T>;
51
16
  }
52
17
 
53
18
  /**
54
- * A queuing strategy that counts the number of chunks.
19
+ * The **`ByteLengthQueuingStrategy`** interface of the Streams API provides a built-in byte length queuing strategy that can be used when constructing streams.
55
20
  *
56
- * @public
21
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy)
57
22
  */
58
- export declare class CountQueuingStrategy implements QueuingStrategy<unknown> {
59
- constructor(options: QueuingStrategyInit);
23
+ interface _ByteLengthQueuingStrategy extends QueuingStrategy<ArrayBufferView> {
60
24
  /**
61
- * Returns the high water mark provided to the constructor.
25
+ * The read-only **`ByteLengthQueuingStrategy.highWaterMark`** property returns the total number of bytes that can be contained in the internal queue before backpressure is applied.
26
+ *
27
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy/highWaterMark)
62
28
  */
63
- get highWaterMark(): number;
29
+ readonly highWaterMark: number;
30
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/ByteLengthQueuingStrategy/size) */
31
+ readonly size: QueuingStrategySize<ArrayBufferView>;
32
+ }
33
+
34
+ export type ByteLengthQueuingStrategy = GlobalPrototypeOr<
35
+ "ByteLengthQueuingStrategy",
36
+ _ByteLengthQueuingStrategy
37
+ >;
38
+
39
+ export interface QueuingStrategyInit {
64
40
  /**
65
- * Measures the size of `chunk` by always returning 1.
66
- * This ensures that the total queue size is a count of the number of chunks in the queue.
41
+ * Creates a new ByteLengthQueuingStrategy with the provided high water mark.
42
+ *
43
+ * Note that the provided high water mark will not be validated ahead of time. Instead, if it is negative, NaN, or not a number, the resulting ByteLengthQueuingStrategy will cause the corresponding stream constructor to throw.
67
44
  */
68
- get size(): (chunk: unknown) => 1;
45
+ highWaterMark: number;
46
+ }
47
+
48
+ interface _ByteLengthQueuingStrategyConstructor {
49
+ prototype: ByteLengthQueuingStrategy;
50
+ new (init: QueuingStrategyInit): ByteLengthQueuingStrategy;
69
51
  }
70
52
 
53
+ type ByteLengthQueuingStrategyConstructor = GlobalValueOr<
54
+ "ByteLengthQueuingStrategy",
55
+ _ByteLengthQueuingStrategyConstructor
56
+ >;
57
+
58
+ export const ByteLengthQueuingStrategy =
59
+ getGlobalValue<ByteLengthQueuingStrategyConstructor>(
60
+ "ByteLengthQueuingStrategy",
61
+ );
62
+
71
63
  /**
72
- * A queuing strategy.
64
+ * The **`CountQueuingStrategy`** interface of the Streams API provides a built-in chunk counting queuing strategy that can be used when constructing streams.
73
65
  *
74
- * @public
66
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy)
75
67
  */
76
- export declare interface QueuingStrategy<T> {
77
- /**
78
- * A non-negative number indicating the high water mark of the stream using this queuing strategy.
79
- */
80
- highWaterMark?: number;
68
+ interface _CountQueuingStrategy extends QueuingStrategy {
81
69
  /**
82
- * A function that computes and returns the finite non-negative size of the given chunk value.
70
+ * The read-only **`CountQueuingStrategy.highWaterMark`** property returns the total number of chunks that can be contained in the internal queue before backpressure is applied.
71
+ *
72
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy/highWaterMark)
83
73
  */
84
- size?: QueuingStrategySizeCallback<T>;
74
+ readonly highWaterMark: number;
75
+ /** [MDN Reference](https://developer.mozilla.org/docs/Web/API/CountQueuingStrategy/size) */
76
+ readonly size: QueuingStrategySize;
85
77
  }
86
78
 
87
- /**
88
- * @public
89
- */
90
- export declare interface QueuingStrategyInit {
91
- /**
92
- * {@inheritDoc QueuingStrategy.highWaterMark}
93
- */
94
- highWaterMark: number;
79
+ export type CountQueuingStrategy = GlobalPrototypeOr<
80
+ "CountQueuingStrategy",
81
+ _CountQueuingStrategy
82
+ >;
83
+
84
+ interface _CountQueuingStrategyConstructor {
85
+ prototype: CountQueuingStrategy;
86
+ new (init: QueuingStrategyInit): CountQueuingStrategy;
95
87
  }
96
88
 
97
- /**
98
- * {@inheritDoc QueuingStrategy.size}
99
- * @public
100
- */
101
- export declare type QueuingStrategySizeCallback<T> = (chunk: T) => number;
89
+ type CountQueuingStrategyConstructor = GlobalValueOr<
90
+ "CountQueuingStrategy",
91
+ _CountQueuingStrategyConstructor
92
+ >;
93
+
94
+ export const CountQueuingStrategy =
95
+ getGlobalValue<CountQueuingStrategyConstructor>("CountQueuingStrategy");
102
96
 
103
97
  /**
104
- * Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
98
+ * The **`ReadableByteStreamController`** interface of the Streams API represents a controller for a readable byte stream. It allows control of the state and internal queue of a ReadableStream with an underlying byte source, and enables efficient zero-copy transfer of data from the underlying source to a consumer when the stream's internal queue is empty.
105
99
  *
106
- * @public
100
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController)
107
101
  */
108
- export declare class ReadableByteStreamController {
109
- private constructor();
102
+ interface _ReadableByteStreamController {
110
103
  /**
111
- * Returns the current BYOB pull request, or `null` if there isn't one.
104
+ * The **`byobRequest`** read-only property of the ReadableByteStreamController interface returns the current BYOB request, or null if there are no pending requests.
105
+ *
106
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/byobRequest)
112
107
  */
113
- get byobRequest(): ReadableStreamBYOBRequest | null;
108
+ readonly byobRequest: ReadableStreamBYOBRequest | null;
114
109
  /**
115
- * Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
116
- * over-full. An underlying byte source ought to use this information to determine when and how to apply backpressure.
110
+ * The **`desiredSize`** read-only property of the ReadableByteStreamController interface returns the number of bytes required to fill the stream's internal queue to its "desired size".
111
+ *
112
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/desiredSize)
117
113
  */
118
- get desiredSize(): number | null;
114
+ readonly desiredSize: number | null;
119
115
  /**
120
- * Closes the controlled readable stream. Consumers will still be able to read any previously-enqueued chunks from
121
- * the stream, but once those are read, the stream will become closed.
116
+ * The **`close()`** method of the ReadableByteStreamController interface closes the associated stream.
117
+ *
118
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/close)
122
119
  */
123
120
  close(): void;
124
121
  /**
125
- * Enqueues the given chunk chunk in the controlled readable stream.
126
- * The chunk has to be an `ArrayBufferView` instance, or else a `TypeError` will be thrown.
122
+ * The **`enqueue()`** method of the ReadableByteStreamController interface enqueues a given chunk on the associated readable byte stream (the chunk is transferred into the stream's internal queues).
123
+ *
124
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/enqueue)
127
125
  */
128
- enqueue(chunk: ArrayBufferView): void;
126
+ enqueue(chunk: ArrayBufferView<ArrayBuffer>): void;
129
127
  /**
130
- * Errors the controlled readable stream, making all future interactions with it fail with the given error `e`.
128
+ * The **`error()`** method of the ReadableByteStreamController interface causes any future interactions with the associated stream to error with the specified reason.
129
+ *
130
+ * [MDN Reference](https://developer.mozilla.org/docs/Web/API/ReadableByteStreamController/error)
131
131
  */
132
132
  error(e?: unknown): void;
133
133
  }
134
134
 
135
+ export type ReadableByteStreamController = GlobalPrototypeOr<
136
+ "ReadableByteStreamController",
137
+ _ReadableByteStreamController
138
+ >;
139
+
140
+ // Can't use built-in definition: https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1265
135
141
  /**
136
142
  * A readable stream represents a source of data, from which you can read.
137
- *
138
- * @public
139
143
  */
140
- export declare class ReadableStream<out R> implements AsyncIterable<R> {
141
- constructor(
142
- underlyingSource: UnderlyingByteSource,
143
- strategy?: {
144
- highWaterMark?: number;
145
- size?: undefined;
146
- },
147
- );
148
- constructor(
149
- underlyingSource?: UnderlyingSource<R>,
150
- strategy?: QueuingStrategy<R>,
151
- );
144
+ export interface ReadableStream<out R> extends AsyncIterable<R> {
152
145
  /**
153
146
  * Whether or not the readable stream is locked to a {@link ReadableStreamDefaultReader | reader}.
154
147
  */
@@ -227,44 +220,107 @@ export declare class ReadableStream<out R> implements AsyncIterable<R> {
227
220
  * cancel the stream. To prevent this, use the stream's {@link ReadableStream.values | values()} method, passing
228
221
  * `true` for the `preventCancel` option.
229
222
  */
230
- values(
231
- options?: ReadableStreamIteratorOptions,
232
- ): ReadableStreamAsyncIterator<R>;
223
+ values(options?: ReadableStreamIteratorOptions): AsyncIterableIterator<R>;
233
224
  /**
234
225
  * {@inheritDoc ReadableStream.values}
235
226
  */
236
227
  [Symbol.asyncIterator](
237
228
  options?: ReadableStreamIteratorOptions,
238
- ): ReadableStreamAsyncIterator<R>;
229
+ ): AsyncIterableIterator<R>;
230
+ }
231
+
232
+ // Can't use built-in definition: https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/2456
233
+ interface ReadableStreamConstructor {
234
+ prototype: ReadableStream<unknown>;
235
+ new <R = Uint8Array<ArrayBuffer>>(
236
+ underlyingSource: UnderlyingByteSource,
237
+ strategy?: {
238
+ highWaterMark?: number;
239
+ size?: undefined;
240
+ },
241
+ ): ReadableStream<R>;
242
+ new <R>(
243
+ underlyingSource?: UnderlyingSource<R>,
244
+ strategy?: QueuingStrategy<R>,
245
+ ): ReadableStream<R>;
239
246
  /**
240
247
  * Creates a new ReadableStream wrapping the provided iterable or async iterable.
241
248
  *
242
249
  * This can be used to adapt various kinds of objects into a readable stream,
243
250
  * such as an array, an async generator, or a Node.js readable stream.
244
251
  */
245
- static from<R>(
246
- asyncIterable: Iterable<R> | AsyncIterable<R>,
247
- ): ReadableStream<R>;
252
+ from<R>(asyncIterable: Iterable<R> | AsyncIterable<R>): ReadableStream<R>;
248
253
  }
249
254
 
250
- /**
251
- * An async iterator returned by {@link ReadableStream.values}.
252
- *
253
- * @public
254
- */
255
- export declare interface ReadableStreamAsyncIterator<R>
256
- extends AsyncIterableIterator<R> {
257
- next(): Promise<IteratorResult<R, void>>;
258
- return(value?: R): Promise<IteratorResult<R>>;
259
- }
255
+ export const ReadableStream = /* #__PURE__ */ (() => {
256
+ const ReadableStream =
257
+ getGlobalValue<ReadableStreamConstructor>("ReadableStream");
258
+
259
+ /* node:coverage disable */
260
+ if (!ReadableStream.from) {
261
+ ReadableStream.from = function (iterable) {
262
+ const iterator =
263
+ Symbol.asyncIterator in iterable
264
+ ? iterable[Symbol.asyncIterator]()
265
+ : iterable[Symbol.iterator]();
266
+
267
+ return new ReadableStream({
268
+ async pull(controller) {
269
+ const result = await iterator.next();
270
+ if (result.done) {
271
+ controller.close();
272
+ return;
273
+ }
274
+ controller.enqueue(result.value);
275
+ },
276
+ async cancel(reason) {
277
+ await iterator.return?.(reason);
278
+ },
279
+ });
280
+ };
281
+ }
282
+
283
+ if (
284
+ !ReadableStream.prototype[Symbol.asyncIterator] ||
285
+ !ReadableStream.prototype.values
286
+ ) {
287
+ ReadableStream.prototype.values = async function* <R>(
288
+ this: ReadableStream<R>,
289
+ options?: ReadableStreamIteratorOptions,
290
+ ) {
291
+ const reader = this.getReader();
292
+ try {
293
+ while (true) {
294
+ const { done, value } = await reader.read();
295
+ if (done) {
296
+ return;
297
+ }
298
+ yield value;
299
+ }
300
+ } finally {
301
+ // Calling `iterator.return` will enter this `finally` block.
302
+ // We don't need to care about the parameter to `iterator.return`,
303
+ // it will be returned as the final `result.value` automatically.
304
+ if (!options?.preventCancel) {
305
+ await tryCancel(reader);
306
+ }
307
+ reader.releaseLock();
308
+ }
309
+ };
310
+
311
+ ReadableStream.prototype[Symbol.asyncIterator] =
312
+ // eslint-disable-next-line @typescript-eslint/unbound-method
313
+ ReadableStream.prototype.values;
314
+ }
315
+ /* node:coverage enable */
316
+
317
+ return ReadableStream;
318
+ })();
260
319
 
261
320
  /**
262
321
  * A BYOB reader vended by a {@link ReadableStream}.
263
- *
264
- * @public
265
322
  */
266
- export declare class ReadableStreamBYOBReader {
267
- constructor(stream: ReadableStream<Uint8Array>);
323
+ export interface ReadableStreamBYOBReader {
268
324
  /**
269
325
  * Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
270
326
  * the reader's lock is released before the stream finishes closing.
@@ -295,20 +351,26 @@ export declare class ReadableStreamBYOBReader {
295
351
  releaseLock(): void;
296
352
  }
297
353
 
354
+ interface ReadableStreamBYOBReaderConstructor {
355
+ prototype: ReadableStreamBYOBReader;
356
+ new (stream: ReadableStream<Uint8Array>): ReadableStreamBYOBReader;
357
+ }
358
+
359
+ export const ReadableStreamBYOBReader =
360
+ getGlobalValue<ReadableStreamBYOBReaderConstructor>(
361
+ "ReadableStreamBYOBReader",
362
+ );
363
+
298
364
  /**
299
365
  * Options for {@link ReadableStreamBYOBReader.read | reading} a stream
300
366
  * with a {@link ReadableStreamBYOBReader | BYOB reader}.
301
- *
302
- * @public
303
367
  */
304
- export declare interface ReadableStreamBYOBReaderReadOptions {
368
+ export interface ReadableStreamBYOBReaderReadOptions {
305
369
  min?: number | undefined;
306
370
  }
307
371
 
308
372
  /**
309
373
  * A result returned by {@link ReadableStreamBYOBReader.read}.
310
- *
311
- * @public
312
374
  */
313
375
  export declare type ReadableStreamBYOBReadResult<T extends ArrayBufferView> =
314
376
  | {
@@ -322,11 +384,8 @@ export declare type ReadableStreamBYOBReadResult<T extends ArrayBufferView> =
322
384
 
323
385
  /**
324
386
  * A pull-into request in a {@link ReadableByteStreamController}.
325
- *
326
- * @public
327
387
  */
328
- export declare class ReadableStreamBYOBRequest {
329
- private constructor();
388
+ export interface ReadableStreamBYOBRequest {
330
389
  /**
331
390
  * Returns the view for writing in to, or `null` if the BYOB request has already been responded to.
332
391
  */
@@ -351,11 +410,8 @@ export declare class ReadableStreamBYOBRequest {
351
410
 
352
411
  /**
353
412
  * Allows control of a {@link ReadableStream | readable stream}'s state and internal queue.
354
- *
355
- * @public
356
413
  */
357
- export declare class ReadableStreamDefaultController<R> {
358
- private constructor();
414
+ export interface ReadableStreamDefaultController<R> {
359
415
  /**
360
416
  * Returns the desired size to fill the controlled stream's internal queue. It can be negative, if the queue is
361
417
  * over-full. An underlying source ought to use this information to determine when and how to apply backpressure.
@@ -378,11 +434,8 @@ export declare class ReadableStreamDefaultController<R> {
378
434
 
379
435
  /**
380
436
  * A default reader vended by a {@link ReadableStream}.
381
- *
382
- * @public
383
437
  */
384
- export declare class ReadableStreamDefaultReader<out R> {
385
- constructor(stream: ReadableStream<R>);
438
+ export interface ReadableStreamDefaultReader<out R> {
386
439
  /**
387
440
  * Returns a promise that will be fulfilled when the stream becomes closed,
388
441
  * or rejected if the stream ever errors or the reader's lock is released before the stream finishes closing.
@@ -410,22 +463,18 @@ export declare class ReadableStreamDefaultReader<out R> {
410
463
  releaseLock(): void;
411
464
  }
412
465
 
413
- /**
414
- * A common interface for a `ReadableStreamDefaultReader` implementation.
415
- *
416
- * @public
417
- */
418
- export declare interface ReadableStreamDefaultReaderLike<R> {
419
- readonly closed: Promise<undefined>;
420
- cancel(reason?: unknown): Promise<void>;
421
- read(): Promise<ReadableStreamDefaultReadResult<R>>;
422
- releaseLock(): void;
466
+ interface ReadableStreamDefaultReaderConstructor {
467
+ prototype: ReadableStreamDefaultReader<never>;
468
+ new <R>(stream: ReadableStream<R>): ReadableStreamDefaultReader<R>;
423
469
  }
424
470
 
471
+ export const ReadableStreamDefaultReader =
472
+ getGlobalValue<ReadableStreamDefaultReaderConstructor>(
473
+ "ReadableStreamDefaultReader",
474
+ );
475
+
425
476
  /**
426
477
  * A result returned by {@link ReadableStreamDefaultReader.read}.
427
- *
428
- * @public
429
478
  */
430
479
  export declare type ReadableStreamDefaultReadResult<T> =
431
480
  | {
@@ -434,45 +483,29 @@ export declare type ReadableStreamDefaultReadResult<T> =
434
483
  }
435
484
  | {
436
485
  done: true;
437
- value?: undefined;
486
+ value: undefined;
438
487
  };
439
488
 
440
489
  /**
441
490
  * Options for {@link ReadableStream.values | async iterating} a stream.
442
- *
443
- * @public
444
491
  */
445
- export declare interface ReadableStreamIteratorOptions {
492
+ export interface ReadableStreamIteratorOptions {
446
493
  preventCancel?: boolean;
447
494
  }
448
495
 
449
- /**
450
- * A common interface for a `ReadableStream` implementation.
451
- *
452
- * @public
453
- */
454
- export declare interface ReadableStreamLike<R> {
455
- readonly locked: boolean;
456
- getReader(): ReadableStreamDefaultReaderLike<R>;
457
- }
458
-
459
496
  /**
460
497
  * A pair of a {@link ReadableStream | readable stream} and {@link WritableStream | writable stream} that can be passed
461
498
  * to {@link ReadableStream.pipeThrough}.
462
- *
463
- * @public
464
499
  */
465
- export declare interface ReadableWritablePair<R, W> {
500
+ export interface ReadableWritablePair<R, W> {
466
501
  readable: ReadableStream<R>;
467
502
  writable: WritableStream<W>;
468
503
  }
469
504
 
470
505
  /**
471
506
  * Options for {@link ReadableStream.pipeTo | piping} a stream.
472
- *
473
- * @public
474
507
  */
475
- export declare interface StreamPipeOptions {
508
+ export interface StreamPipeOptions {
476
509
  /**
477
510
  * If set to true, {@link ReadableStream.pipeTo} will not abort the writable stream if the readable stream errors.
478
511
  */
@@ -491,15 +524,13 @@ export declare interface StreamPipeOptions {
491
524
  * `AbortController`. In this case, the source readable stream will be canceled, and the destination writable stream
492
525
  * aborted, unless the respective options `preventCancel` or `preventAbort` are set.
493
526
  */
494
- signal?: AbortSignal;
527
+ signal?: AbortSignal | undefined;
495
528
  }
496
529
 
497
530
  /**
498
531
  * A transformer for constructing a {@link TransformStream}.
499
- *
500
- * @public
501
532
  */
502
- export declare interface Transformer<I, O> {
533
+ export interface Transformer<I, O> {
503
534
  /**
504
535
  * A function that is called immediately during creation of the {@link TransformStream}.
505
536
  */
@@ -521,23 +552,19 @@ export declare interface Transformer<I, O> {
521
552
  writableType?: undefined;
522
553
  }
523
554
 
524
- /** @public */
525
- export declare type TransformerCancelCallback = (
555
+ export type TransformerCancelCallback = (
526
556
  reason: unknown,
527
557
  ) => void | PromiseLike<void>;
528
558
 
529
- /** @public */
530
- export declare type TransformerFlushCallback<O> = (
559
+ export type TransformerFlushCallback<O> = (
531
560
  controller: TransformStreamDefaultController<O>,
532
561
  ) => void | PromiseLike<void>;
533
562
 
534
- /** @public */
535
- export declare type TransformerStartCallback<O> = (
563
+ export type TransformerStartCallback<O> = (
536
564
  controller: TransformStreamDefaultController<O>,
537
565
  ) => void | PromiseLike<void>;
538
566
 
539
- /** @public */
540
- export declare type TransformerTransformCallback<I, O> = (
567
+ export type TransformerTransformCallback<I, O> = (
541
568
  chunk: I,
542
569
  controller: TransformStreamDefaultController<O>,
543
570
  ) => void | PromiseLike<void>;
@@ -547,15 +574,8 @@ export declare type TransformerTransformCallback<I, O> = (
547
574
  * known as its writable side, and a {@link ReadableStream | readable stream}, known as its readable side.
548
575
  * In a manner specific to the transform stream in question, writes to the writable side result in new data being
549
576
  * made available for reading from the readable side.
550
- *
551
- * @public
552
577
  */
553
- export declare class TransformStream<I, O> {
554
- constructor(
555
- transformer?: Transformer<I, O>,
556
- writableStrategy?: QueuingStrategy<I>,
557
- readableStrategy?: QueuingStrategy<O>,
558
- );
578
+ export interface TransformStream<I, O> {
559
579
  /**
560
580
  * The readable side of the transform stream.
561
581
  */
@@ -566,13 +586,23 @@ export declare class TransformStream<I, O> {
566
586
  get writable(): WritableStream<I>;
567
587
  }
568
588
 
589
+ interface TransformStreamConstructor {
590
+ prototype: TransformStream<never, unknown>;
591
+
592
+ new <I, O>(
593
+ transformer?: Transformer<I, O>,
594
+ writableStrategy?: QueuingStrategy<I>,
595
+ readableStrategy?: QueuingStrategy<O>,
596
+ ): TransformStream<I, O>;
597
+ }
598
+
599
+ export const TransformStream =
600
+ getGlobalValue<TransformStreamConstructor>("TransformStream");
601
+
569
602
  /**
570
603
  * Allows control of the {@link ReadableStream} and {@link WritableStream} of the associated {@link TransformStream}.
571
- *
572
- * @public
573
604
  */
574
- export declare class TransformStreamDefaultController<O> {
575
- private constructor();
605
+ export interface TransformStreamDefaultController<O> {
576
606
  /**
577
607
  * Returns the desired size to fill the readable side’s internal queue. It can be negative, if the queue is over-full.
578
608
  */
@@ -595,10 +625,8 @@ export declare class TransformStreamDefaultController<O> {
595
625
 
596
626
  /**
597
627
  * An underlying byte source for constructing a {@link ReadableStream}.
598
- *
599
- * @public
600
628
  */
601
- export declare interface UnderlyingByteSource {
629
+ export interface UnderlyingByteSource {
602
630
  /**
603
631
  * {@inheritDoc UnderlyingSource.start}
604
632
  */
@@ -629,22 +657,18 @@ export declare interface UnderlyingByteSource {
629
657
  autoAllocateChunkSize?: number;
630
658
  }
631
659
 
632
- /** @public */
633
- export declare type UnderlyingByteSourcePullCallback = (
660
+ export type UnderlyingByteSourcePullCallback = (
634
661
  controller: ReadableByteStreamController,
635
662
  ) => void | PromiseLike<void>;
636
663
 
637
- /** @public */
638
- export declare type UnderlyingByteSourceStartCallback = (
664
+ export type UnderlyingByteSourceStartCallback = (
639
665
  controller: ReadableByteStreamController,
640
666
  ) => void | PromiseLike<void>;
641
667
 
642
668
  /**
643
669
  * An underlying sink for constructing a {@link WritableStream}.
644
- *
645
- * @public
646
670
  */
647
- export declare interface UnderlyingSink<in W> {
671
+ export interface UnderlyingSink<in W> {
648
672
  /**
649
673
  * A function that is called immediately during creation of the {@link WritableStream}.
650
674
  */
@@ -683,32 +707,25 @@ export declare interface UnderlyingSink<in W> {
683
707
  type?: undefined;
684
708
  }
685
709
 
686
- /** @public */
687
- export declare type UnderlyingSinkAbortCallback = (
710
+ export type UnderlyingSinkAbortCallback = (
688
711
  reason: unknown,
689
712
  ) => void | PromiseLike<void>;
690
713
 
691
- /** @public */
692
- export declare type UnderlyingSinkCloseCallback =
693
- () => void | PromiseLike<void>;
714
+ export type UnderlyingSinkCloseCallback = () => void | PromiseLike<void>;
694
715
 
695
- /** @public */
696
- export declare type UnderlyingSinkStartCallback = (
716
+ export type UnderlyingSinkStartCallback = (
697
717
  controller: WritableStreamDefaultController,
698
718
  ) => void | PromiseLike<void>;
699
719
 
700
- /** @public */
701
- export declare type UnderlyingSinkWriteCallback<W> = (
720
+ export type UnderlyingSinkWriteCallback<W> = (
702
721
  chunk: W,
703
722
  controller: WritableStreamDefaultController,
704
723
  ) => void | PromiseLike<void>;
705
724
 
706
725
  /**
707
726
  * An underlying source for constructing a {@link ReadableStream}.
708
- *
709
- * @public
710
727
  */
711
- export declare interface UnderlyingSource<R> {
728
+ export interface UnderlyingSource<R> {
712
729
  /**
713
730
  * A function that is called immediately during creation of the {@link ReadableStream}.
714
731
  */
@@ -730,31 +747,22 @@ export declare interface UnderlyingSource<R> {
730
747
  type?: undefined;
731
748
  }
732
749
 
733
- /** @public */
734
- export declare type UnderlyingSourceCancelCallback = (
750
+ export type UnderlyingSourceCancelCallback = (
735
751
  reason: unknown,
736
752
  ) => void | PromiseLike<void>;
737
753
 
738
- /** @public */
739
- export declare type UnderlyingSourcePullCallback<R> = (
754
+ export type UnderlyingSourcePullCallback<R> = (
740
755
  controller: ReadableStreamDefaultController<R>,
741
756
  ) => void | PromiseLike<void>;
742
757
 
743
- /** @public */
744
- export declare type UnderlyingSourceStartCallback<R> = (
758
+ export type UnderlyingSourceStartCallback<R> = (
745
759
  controller: ReadableStreamDefaultController<R>,
746
760
  ) => void | PromiseLike<void>;
747
761
 
748
762
  /**
749
763
  * A writable stream represents a destination for data, into which you can write.
750
- *
751
- * @public
752
764
  */
753
- export declare class WritableStream<in W> {
754
- constructor(
755
- underlyingSink?: UnderlyingSink<W>,
756
- strategy?: QueuingStrategy<W>,
757
- );
765
+ export interface WritableStream<in W> {
758
766
  /**
759
767
  * Returns whether or not the writable stream is locked to a writer.
760
768
  */
@@ -789,13 +797,22 @@ export declare class WritableStream<in W> {
789
797
  getWriter(): WritableStreamDefaultWriter<W>;
790
798
  }
791
799
 
800
+ interface WritableStreamConstructor {
801
+ prototype: WritableStream<never>;
802
+
803
+ new <W>(
804
+ underlyingSink?: UnderlyingSink<W>,
805
+ strategy?: QueuingStrategy<W>,
806
+ ): WritableStream<W>;
807
+ }
808
+
809
+ export const WritableStream =
810
+ getGlobalValue<WritableStreamConstructor>("WritableStream");
811
+
792
812
  /**
793
813
  * Allows control of a {@link WritableStream | writable stream}'s state and internal queue.
794
- *
795
- * @public
796
814
  */
797
- export declare class WritableStreamDefaultController {
798
- private constructor();
815
+ export interface WritableStreamDefaultController {
799
816
  /**
800
817
  * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
801
818
  *
@@ -820,11 +837,8 @@ export declare class WritableStreamDefaultController {
820
837
 
821
838
  /**
822
839
  * A default writer vended by a {@link WritableStream}.
823
- *
824
- * @public
825
840
  */
826
- export declare class WritableStreamDefaultWriter<in W> {
827
- constructor(stream: WritableStream<W>);
841
+ export interface WritableStreamDefaultWriter<in W> {
828
842
  /**
829
843
  * Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
830
844
  * the writer’s lock is released before the stream finishes closing.
@@ -879,4 +893,12 @@ export declare class WritableStreamDefaultWriter<in W> {
879
893
  write(chunk: W): Promise<void>;
880
894
  }
881
895
 
882
- export {};
896
+ interface WritableStreamDefaultWriterConstructor {
897
+ prototype: WritableStreamDefaultWriter<never>;
898
+ new <W>(stream: WritableStream<W>): WritableStreamDefaultWriter<W>;
899
+ }
900
+
901
+ export const WritableStreamDefaultWriter =
902
+ getGlobalValue<WritableStreamDefaultWriterConstructor>(
903
+ "WritableStreamDefaultWriter",
904
+ );