web-streams-polyfill 3.0.3 → 4.0.0-beta.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 (46) hide show
  1. package/CHANGELOG.md +33 -2
  2. package/LICENSE +1 -1
  3. package/README.md +56 -41
  4. package/dist/polyfill.es5.js +8 -0
  5. package/dist/polyfill.js +6 -3999
  6. package/dist/ponyfill.es5.js +8 -0
  7. package/dist/ponyfill.es5.mjs +8 -0
  8. package/dist/ponyfill.js +6 -3971
  9. package/dist/ponyfill.mjs +6 -3949
  10. package/package.json +52 -28
  11. package/types/polyfill.d.ts +62 -0
  12. package/{dist/types/ts3.6/polyfill.d.ts → types/ponyfill.d.ts} +32 -16
  13. package/{dist/types → types}/tsdoc-metadata.json +1 -1
  14. package/dist/polyfill.es2018.js +0 -3868
  15. package/dist/polyfill.es2018.js.map +0 -1
  16. package/dist/polyfill.es2018.min.js +0 -2
  17. package/dist/polyfill.es2018.min.js.map +0 -1
  18. package/dist/polyfill.es2018.mjs +0 -3846
  19. package/dist/polyfill.es2018.mjs.map +0 -1
  20. package/dist/polyfill.es6.js +0 -3879
  21. package/dist/polyfill.es6.js.map +0 -1
  22. package/dist/polyfill.es6.min.js +0 -2
  23. package/dist/polyfill.es6.min.js.map +0 -1
  24. package/dist/polyfill.es6.mjs +0 -3857
  25. package/dist/polyfill.es6.mjs.map +0 -1
  26. package/dist/polyfill.js.map +0 -1
  27. package/dist/polyfill.min.js +0 -2
  28. package/dist/polyfill.min.js.map +0 -1
  29. package/dist/polyfill.mjs +0 -3979
  30. package/dist/polyfill.mjs.map +0 -1
  31. package/dist/ponyfill.es2018.js +0 -3840
  32. package/dist/ponyfill.es2018.js.map +0 -1
  33. package/dist/ponyfill.es2018.mjs +0 -3818
  34. package/dist/ponyfill.es2018.mjs.map +0 -1
  35. package/dist/ponyfill.es6.js +0 -3851
  36. package/dist/ponyfill.es6.js.map +0 -1
  37. package/dist/ponyfill.es6.mjs +0 -3829
  38. package/dist/ponyfill.es6.mjs.map +0 -1
  39. package/dist/ponyfill.js.map +0 -1
  40. package/dist/ponyfill.mjs.map +0 -1
  41. package/dist/types/polyfill.d.ts +0 -751
  42. package/es2018/package.json +0 -7
  43. package/es6/package.json +0 -7
  44. package/ponyfill/es2018/package.json +0 -6
  45. package/ponyfill/es6/package.json +0 -6
  46. package/ponyfill/package.json +0 -6
package/package.json CHANGED
@@ -1,39 +1,64 @@
1
1
  {
2
2
  "name": "web-streams-polyfill",
3
- "version": "3.0.3",
3
+ "version": "4.0.0-beta.1",
4
4
  "description": "Web Streams, based on the WHATWG spec reference implementation",
5
- "main": "dist/polyfill",
6
- "browser": "dist/polyfill.min.js",
7
- "module": "dist/polyfill.mjs",
8
- "types": "dist/types/polyfill.d.ts",
5
+ "main": "dist/ponyfill.js",
6
+ "module": "dist/ponyfill.mjs",
7
+ "exports": {
8
+ ".": {
9
+ "import": "./dist/ponyfill.mjs",
10
+ "require": "./dist/ponyfill.js"
11
+ },
12
+ "./es5": {
13
+ "import": "./dist/ponyfill.es5.mjs",
14
+ "require": "./dist/ponyfill.es5.js"
15
+ },
16
+ "./polyfill": "./dist/polyfill.js",
17
+ "./polyfill/es5": "./dist/polyfill.es5.js",
18
+ "./dist/*": "./dist/*",
19
+ "./types/*": "./types/*",
20
+ "./package": "./package.json",
21
+ "./package.json": "./package.json"
22
+ },
23
+ "types": "types/ponyfill.d.ts",
9
24
  "typesVersions": {
10
25
  ">=3.6": {
11
- "dist/types/*": [
12
- "dist/types/ts3.6/*"
26
+ ".": [
27
+ "./types/ponyfill.d.ts"
28
+ ],
29
+ "./es5": [
30
+ "./types/ponyfill.d.ts"
31
+ ],
32
+ "./polyfill": [
33
+ "./types/polyfill.d.ts"
34
+ ],
35
+ "./polyfill/es5": [
36
+ "./types/polyfill.d.ts"
13
37
  ]
14
38
  }
15
39
  },
16
40
  "scripts": {
17
- "test": "npm run test:types && npm run test:unit && npm run test:wpt",
41
+ "test": "npm run test:types && npm run test:unit && npm run test:wpt && npm run test:bundlers",
18
42
  "test:wpt": "node --expose_gc ./test/run-web-platform-tests.js",
43
+ "test:bundlers": "npm run test:rollup && npm run test:webpack",
44
+ "test:rollup": "cd test/rollup && npm ci && npm test",
45
+ "test:webpack": "cd test/webpack && npm ci && npm test",
19
46
  "pretest:wpt": "git submodule update --init --recursive",
20
47
  "test:types": "tsc -p ./test/types/tsconfig.json",
21
48
  "test:unit": "jasmine --config=test/unit/jasmine.json",
22
49
  "lint": "eslint \"src/**/*.ts\"",
23
50
  "build": "npm run build:bundle && npm run build:types",
24
51
  "build:bundle": "rollup -c",
25
- "build:types": "tsc --project . --emitDeclarationOnly --declarationDir ./lib && api-extractor run && node ./build/downlevel-dts.js",
26
- "accept:types": "tsc --project . --emitDeclarationOnly --declarationDir ./lib && api-extractor run --local && node ./build/downlevel-dts.js",
52
+ "build:types": "tsc --project . --emitDeclarationOnly --declarationDir ./lib && api-extractor run",
53
+ "accept:types": "tsc --project . --emitDeclarationOnly --declarationDir ./lib && api-extractor run --local",
27
54
  "prepare": "npm run build"
28
55
  },
29
56
  "files": [
30
57
  "dist",
31
- "es6",
32
- "es2018",
33
- "ponyfill"
58
+ "types"
34
59
  ],
35
60
  "engines": {
36
- "node": ">= 8"
61
+ "node": ">= 12"
37
62
  },
38
63
  "repository": {
39
64
  "type": "git",
@@ -54,23 +79,22 @@
54
79
  },
55
80
  "homepage": "https://github.com/MattiasBuelens/web-streams-polyfill#readme",
56
81
  "devDependencies": {
57
- "@microsoft/api-extractor": "^7.13.4",
82
+ "@microsoft/api-extractor": "^7.18.7",
58
83
  "@rollup/plugin-inject": "^4.0.2",
59
- "@rollup/plugin-replace": "^2.4.2",
60
- "@rollup/plugin-strip": "^2.0.0",
61
- "@rollup/plugin-typescript": "^8.2.1",
62
- "@types/node": "^14.14.37",
63
- "@typescript-eslint/eslint-plugin": "^4.21.0",
64
- "@typescript-eslint/parser": "^4.21.0",
84
+ "@rollup/plugin-replace": "^3.0.0",
85
+ "@rollup/plugin-strip": "^2.1.0",
86
+ "@rollup/plugin-typescript": "^8.2.5",
87
+ "@types/node": "^14.17.12",
88
+ "@typescript-eslint/eslint-plugin": "^4.29.3",
89
+ "@typescript-eslint/parser": "^4.29.3",
65
90
  "@ungap/promise-all-settled": "^1.1.2",
66
- "eslint": "^7.23.0",
67
- "jasmine": "^3.7.0",
68
- "micromatch": "^4.0.2",
69
- "rollup": "^2.44.0",
91
+ "eslint": "^7.32.0",
92
+ "jasmine": "^3.9.0",
93
+ "micromatch": "^4.0.4",
94
+ "rollup": "^2.56.3",
70
95
  "rollup-plugin-terser": "^7.0.2",
71
- "ts-morph": "^10.0.2",
72
- "tslib": "^2.2.0",
73
- "typescript": "^4.2.4",
96
+ "tslib": "^2.3.0",
97
+ "typescript": "~4.3.5",
74
98
  "wpt-runner": "^3.2.1"
75
99
  }
76
100
  }
@@ -0,0 +1,62 @@
1
+ /// <reference lib="dom" />
2
+ /// <reference lib="es2018.asynciterable" />
3
+
4
+ import type {
5
+ ReadableStreamAsyncIterator,
6
+ ReadableStreamBYOBReader,
7
+ ReadableStreamBYOBReadResult,
8
+ ReadableStreamIteratorOptions
9
+ } from './ponyfill';
10
+
11
+ export type {
12
+ ReadableStreamAsyncIterator,
13
+ ReadableStreamBYOBReader,
14
+ ReadableStreamBYOBReadResult,
15
+ ReadableStreamIteratorOptions
16
+ };
17
+
18
+ declare global {
19
+ interface ReadableStream<R = any> {
20
+ /**
21
+ * Creates a {@link ReadableStreamBYOBReader} and locks the stream to the new reader.
22
+ *
23
+ * This call behaves the same way as the no-argument variant, except that it only works on readable byte streams,
24
+ * i.e. streams which were constructed specifically with the ability to handle "bring your own buffer" reading.
25
+ * The returned BYOB reader provides the ability to directly read individual chunks from the stream via its
26
+ * {@link ReadableStreamBYOBReader.read | read()} method, into developer-supplied buffers, allowing more precise
27
+ * control over allocation.
28
+ */
29
+ getReader({ mode }: {
30
+ mode: 'byob';
31
+ }): ReadableStreamBYOBReader;
32
+
33
+ /**
34
+ * Creates a {@link ReadableStreamDefaultReader} and locks the stream to the new reader.
35
+ * While the stream is locked, no other reader can be acquired until this one is released.
36
+ *
37
+ * This functionality is especially useful for creating abstractions that desire the ability to consume a stream
38
+ * in its entirety. By getting a reader for the stream, you can ensure nobody else can interleave reads with yours
39
+ * or cancel the stream, which would interfere with your abstraction.
40
+ */
41
+ getReader(): ReadableStreamDefaultReader<R>;
42
+
43
+ /**
44
+ * Asynchronously iterates over the chunks in the stream's internal queue.
45
+ *
46
+ * Asynchronously iterating over the stream will lock it, preventing any other consumer from acquiring a reader.
47
+ * The lock will be released if the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method
48
+ * is called, e.g. by breaking out of the loop.
49
+ *
50
+ * By default, calling the async iterator's {@link ReadableStreamAsyncIterator.return | return()} method will also
51
+ * cancel the stream. To prevent this, use the stream's {@link ReadableStream.values | values()} method, passing
52
+ * `true` for the `preventCancel` option.
53
+ */
54
+ values(options?: ReadableStreamIteratorOptions): ReadableStreamAsyncIterator<R>;
55
+
56
+ /**
57
+ * {@inheritDoc ReadableStream.values}
58
+ */
59
+ [Symbol.asyncIterator]: (options?: ReadableStreamIteratorOptions) => ReadableStreamAsyncIterator<R>;
60
+ }
61
+ }
62
+
@@ -87,9 +87,11 @@ export declare interface QueuingStrategyInit {
87
87
  highWaterMark: number;
88
88
  }
89
89
 
90
- declare type QueuingStrategySizeCallback<T = any> = (chunk: T) => number;
91
-
92
- declare type ReadableByteStream = ReadableStream<Uint8Array>;
90
+ /**
91
+ * {@inheritDoc QueuingStrategy.size}
92
+ * @public
93
+ */
94
+ export declare type QueuingStrategySizeCallback<T = any> = (chunk: T) => number;
93
95
 
94
96
  /**
95
97
  * Allows control of a {@link ReadableStream | readable byte stream}'s state and internal queue.
@@ -144,7 +146,7 @@ export declare class ReadableStream<R = any> {
144
146
  * The supplied `reason` argument will be given to the underlying source's {@link UnderlyingSource.cancel | cancel()}
145
147
  * method, which might or might not use it.
146
148
  */
147
- cancel(reason?: any): Promise<undefined>;
149
+ cancel(reason?: any): Promise<void>;
148
150
  /**
149
151
  * Creates a {@link ReadableStreamBYOBReader} and locks the stream to the new reader.
150
152
  *
@@ -173,7 +175,10 @@ export declare class ReadableStream<R = any> {
173
175
  *
174
176
  * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
175
177
  */
176
- pipeThrough<T>(transform: ReadableWritablePair<T, R>, options?: StreamPipeOptions): ReadableStream<T>;
178
+ pipeThrough<RS extends ReadableStream>(transform: {
179
+ readable: RS;
180
+ writable: WritableStream<R>;
181
+ }, options?: StreamPipeOptions): RS;
177
182
  /**
178
183
  * Pipes this readable stream to a given writable stream. The way in which the piping process behaves under
179
184
  * various error conditions can be customized with a number of passed options. It returns a promise that fulfills
@@ -181,7 +186,7 @@ export declare class ReadableStream<R = any> {
181
186
  *
182
187
  * Piping a stream will lock it for the duration of the pipe, preventing any other consumer from acquiring a reader.
183
188
  */
184
- pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<undefined>;
189
+ pipeTo(destination: WritableStream<R>, options?: StreamPipeOptions): Promise<void>;
185
190
  /**
186
191
  * Tees this readable stream, returning a two-element array containing the two resulting branches as
187
192
  * new {@link ReadableStream} instances.
@@ -218,7 +223,7 @@ export declare class ReadableStream<R = any> {
218
223
  * @public
219
224
  */
220
225
  export declare interface ReadableStreamAsyncIterator<R> extends AsyncIterator<R> {
221
- next(): Promise<IteratorResult<R>>;
226
+ next(): Promise<IteratorResult<R, undefined>>;
222
227
  return(value?: any): Promise<IteratorResult<any>>;
223
228
  }
224
229
 
@@ -228,7 +233,7 @@ export declare interface ReadableStreamAsyncIterator<R> extends AsyncIterator<R>
228
233
  * @public
229
234
  */
230
235
  export declare class ReadableStreamBYOBReader {
231
- constructor(stream: ReadableByteStream);
236
+ constructor(stream: ReadableStream<Uint8Array>);
232
237
  /**
233
238
  * Returns a promise that will be fulfilled when the stream becomes closed, or rejected if the stream ever errors or
234
239
  * the reader's lock is released before the stream finishes closing.
@@ -237,7 +242,7 @@ export declare class ReadableStreamBYOBReader {
237
242
  /**
238
243
  * If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
239
244
  */
240
- cancel(reason?: any): Promise<undefined>;
245
+ cancel(reason?: any): Promise<void>;
241
246
  /**
242
247
  * Attempts to reads bytes into view, and returns a promise resolved with the result.
243
248
  *
@@ -262,8 +267,11 @@ export declare class ReadableStreamBYOBReader {
262
267
  * @public
263
268
  */
264
269
  export declare type ReadableStreamBYOBReadResult<T extends ArrayBufferView> = {
265
- done: boolean;
270
+ done: false;
266
271
  value: T;
272
+ } | {
273
+ done: true;
274
+ value: T | undefined;
267
275
  };
268
276
 
269
277
  /**
@@ -337,7 +345,7 @@ export declare class ReadableStreamDefaultReader<R = any> {
337
345
  /**
338
346
  * If the reader is active, behaves the same as {@link ReadableStream.cancel | stream.cancel(reason)}.
339
347
  */
340
- cancel(reason?: any): Promise<undefined>;
348
+ cancel(reason?: any): Promise<void>;
341
349
  /**
342
350
  * Returns a promise that allows access to the next chunk from the stream's internal queue, if available.
343
351
  *
@@ -366,7 +374,7 @@ export declare type ReadableStreamDefaultReadResult<T> = {
366
374
  value: T;
367
375
  } | {
368
376
  done: true;
369
- value: undefined;
377
+ value?: undefined;
370
378
  };
371
379
 
372
380
  /**
@@ -649,7 +657,7 @@ export declare class WritableStream<W = any> {
649
657
  * that there was an error doing so. Additionally, it will reject with a `TypeError` (without attempting to cancel
650
658
  * the stream) if the stream is currently locked.
651
659
  */
652
- abort(reason?: any): Promise<undefined>;
660
+ abort(reason?: any): Promise<void>;
653
661
  /**
654
662
  * Closes the stream. The underlying sink will finish processing any previously-written chunks, before invoking its
655
663
  * close behavior. During this time any further attempts to write will fail (without erroring the stream).
@@ -677,6 +685,14 @@ export declare class WritableStream<W = any> {
677
685
  */
678
686
  export declare class WritableStreamDefaultController<W = any> {
679
687
  private constructor();
688
+ /**
689
+ * The reason which was passed to `WritableStream.abort(reason)` when the stream was aborted.
690
+ */
691
+ get abortReason(): any;
692
+ /**
693
+ * An `AbortSignal` that can be used to abort the pending write or close operation when the stream is aborted.
694
+ */
695
+ get signal(): AbortSignal;
680
696
  /**
681
697
  * Closes the controlled writable stream, making all future interactions with it fail with the given error `e`.
682
698
  *
@@ -720,11 +736,11 @@ export declare class WritableStreamDefaultWriter<W = any> {
720
736
  /**
721
737
  * If the reader is active, behaves the same as {@link WritableStream.abort | stream.abort(reason)}.
722
738
  */
723
- abort(reason?: any): Promise<undefined>;
739
+ abort(reason?: any): Promise<void>;
724
740
  /**
725
741
  * If the reader is active, behaves the same as {@link WritableStream.close | stream.close()}.
726
742
  */
727
- close(): Promise<undefined>;
743
+ close(): Promise<void>;
728
744
  /**
729
745
  * Releases the writer’s lock on the corresponding stream. After the lock is released, the writer is no longer active.
730
746
  * If the associated stream is errored when the lock is released, the writer will appear errored in the same way from
@@ -745,7 +761,7 @@ export declare class WritableStreamDefaultWriter<W = any> {
745
761
  * Note that what "success" means is up to the underlying sink; it might indicate simply that the chunk has been
746
762
  * accepted, and not necessarily that it is safely saved to its ultimate destination.
747
763
  */
748
- write(chunk: W): Promise<undefined>;
764
+ write(chunk: W): Promise<void>;
749
765
  }
750
766
 
751
767
  export { }
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.13.4"
8
+ "packageVersion": "7.18.7"
9
9
  }
10
10
  ]
11
11
  }