From 5fb247911a43bb0562e2d11366eecea78102d5a4 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Thu, 28 Dec 2023 21:46:25 -0800 Subject: [PATCH 1/4] chore(typescript): update to typescript@5.3.3 --- package.json | 2 +- src/asynciterable/fromdomstream.ts | 8 ++++---- src/asynciterable/todomstream.ts | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index ab6734f7..0a14bdf9 100644 --- a/package.json +++ b/package.json @@ -99,7 +99,7 @@ "ts-jest": "28.0.7", "ts-node": "8.6.2", "typedoc": "0.16.10", - "typescript": "4.6.2", + "typescript": "5.3.3", "validate-commit-msg": "2.14.0", "web-stream-tools": "0.0.1", "web-streams-polyfill": "2.1.0", diff --git a/src/asynciterable/fromdomstream.ts b/src/asynciterable/fromdomstream.ts index 6fe26ef8..835afd65 100644 --- a/src/asynciterable/fromdomstream.ts +++ b/src/asynciterable/fromdomstream.ts @@ -63,7 +63,7 @@ async function* _consumeReader( /** @ignore */ async function* defaultReaderToAsyncIterator(reader: ReadableStreamDefaultReader) { - let r: ReadableStreamDefaultReadResult; + let r: ReadableStreamReadResult; while (!(r = await reader.read()).done) { yield r.value; } @@ -71,7 +71,7 @@ async function* defaultReaderToAsyncIterator(reader: ReadableStreamDefa /** @ignore */ async function* byobReaderToAsyncIterator(reader: ReadableStreamReader) { - let r: ReadableStreamDefaultReadResult; + let r: ReadableStreamReadResult; let value: number | ArrayBufferLike = yield null!; while (!(r = await readNext(reader, value, 0)).done) { value = yield r.value; @@ -83,7 +83,7 @@ async function readNext( reader: ReadableStreamReader, bufferOrLen: ArrayBufferLike | number, offset: number -): Promise> { +): Promise> { let size: number; let buffer: ArrayBufferLike; @@ -106,7 +106,7 @@ async function readInto( buffer: ArrayBufferLike, offset: number, size: number -): Promise> { +): Promise> { let innerOffset = offset; if (innerOffset >= size) { return { done: false, value: new Uint8Array(buffer, 0, size) }; diff --git a/src/asynciterable/todomstream.ts b/src/asynciterable/todomstream.ts index cb052851..83a06a0e 100644 --- a/src/asynciterable/todomstream.ts +++ b/src/asynciterable/todomstream.ts @@ -49,12 +49,12 @@ class UnderlyingAsyncIterableDefaultSource extends AbstractUnderl super(source); } // eslint-disable-next-line consistent-return - async pull(controller: ReadableStreamDefaultController) { + async pull(controller: ReadableStreamController) { const source = this._source; if (source) { const r = await source.next(controller.desiredSize); if (!r.done) { - return controller.enqueue(r.value); + return (controller as ReadableStreamDefaultController).enqueue(r.value); } } controller.close(); @@ -85,7 +85,9 @@ class UnderlyingAsyncIterableByteSource) { if (!(controller as any).byobRequest) { - return await this.fallbackDefaultSource.pull(controller); + return await this.fallbackDefaultSource.pull( + controller as ReadableStreamDefaultController + ); } if (this._source) { const { view } = (controller as any).byobRequest; From 267598ae8984b55e643dc523d1b1f6f641af3c5f Mon Sep 17 00:00:00 2001 From: ptaylor Date: Thu, 28 Dec 2023 22:20:22 -0800 Subject: [PATCH 2/4] chore(dependencies): update @types/node --- package.json | 2 +- src/asynciterable/asasynciterable.ts | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0a14bdf9..0eb8dba5 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "CHANGELOG.md" ], "dependencies": { - "@types/node": "^13.7.4", + "@types/node": ">=13.7.4", "tslib": "^2.3.0" }, "devDependencies": { diff --git a/src/asynciterable/asasynciterable.ts b/src/asynciterable/asasynciterable.ts index 2897b564..38e7738f 100644 --- a/src/asynciterable/asasynciterable.ts +++ b/src/asynciterable/asasynciterable.ts @@ -2,19 +2,19 @@ import { AsyncIterableX } from './asynciterablex'; import { OperatorAsyncFunction, UnaryFunction } from '../interfaces'; import { Transform, TransformCallback, TransformOptions } from 'stream'; -export interface AsyncIterableTransform extends AsyncIterableX, Transform { +export interface AsyncIterableTransform extends AsyncIterableX, NodeJS.ReadableStream, NodeJS.WritableStream { pipe(...operations: UnaryFunction, R>[]): R; pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX; pipe(writable: R, options?: { end?: boolean }): R; - [Symbol.asyncIterator](): AsyncIterableIterator; + [Symbol.asyncIterator](): AsyncIterableIterator; } const asyncIterableMixin = Symbol('asyncIterableMixin'); -export class AsyncIterableTransform extends Transform { +export class AsyncIterableTransform { private static [asyncIterableMixin] = false; constructor(options?: TransformOptions) { - super(options); + Transform.call(this as any, options); // If this is the first time AsyncIterableTransform is being constructed, // mixin the methods from the AsyncIterableX's prototype. if (!AsyncIterableTransform[asyncIterableMixin]) { @@ -35,6 +35,11 @@ export class AsyncIterableTransform extends Transform { } } +(AsyncIterableTransform as any).prototype = Object.create( + Transform.prototype, + Object.getOwnPropertyDescriptors(AsyncIterableTransform.prototype) +); + export function asAsyncIterable(options: TransformOptions = {}) { return new AsyncIterableTransform(options); } From 57181f328733971d2f8417f185ec6473069917fd Mon Sep 17 00:00:00 2001 From: ptaylor Date: Thu, 28 Dec 2023 22:25:20 -0800 Subject: [PATCH 3/4] fix(withabort): add ts-ignore to withabort operator impl --- src/asynciterable/operators/withabort.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/asynciterable/operators/withabort.ts b/src/asynciterable/operators/withabort.ts index 7eec37b6..00fb7fdd 100644 --- a/src/asynciterable/operators/withabort.ts +++ b/src/asynciterable/operators/withabort.ts @@ -16,6 +16,7 @@ export class WithAbortAsyncIterable extends AsyncIterableX { } [Symbol.asyncIterator](): AsyncIterator { + // @ts-ignore return this._source[Symbol.asyncIterator](this._signal); } } From cdd7942ae24473ca44b15f04f75ecdb0f15c56f4 Mon Sep 17 00:00:00 2001 From: ptaylor Date: Thu, 28 Dec 2023 22:38:31 -0800 Subject: [PATCH 4/4] convert AsyncIterableTransform to a constructor function --- src/asynciterable/asasynciterable.ts | 62 ++++++++++++++++------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/asynciterable/asasynciterable.ts b/src/asynciterable/asasynciterable.ts index 38e7738f..59313f38 100644 --- a/src/asynciterable/asasynciterable.ts +++ b/src/asynciterable/asasynciterable.ts @@ -2,7 +2,11 @@ import { AsyncIterableX } from './asynciterablex'; import { OperatorAsyncFunction, UnaryFunction } from '../interfaces'; import { Transform, TransformCallback, TransformOptions } from 'stream'; -export interface AsyncIterableTransform extends AsyncIterableX, NodeJS.ReadableStream, NodeJS.WritableStream { +export interface AsyncIterableTransform + extends AsyncIterableX, + NodeJS.ReadableStream, + NodeJS.WritableStream { + new (options?: TransformOptions): AsyncIterableTransform; pipe(...operations: UnaryFunction, R>[]): R; pipe(...operations: OperatorAsyncFunction[]): AsyncIterableX; pipe(writable: R, options?: { end?: boolean }): R; @@ -11,35 +15,39 @@ export interface AsyncIterableTransform extends AsyncIterableX, NodeJS.Rea const asyncIterableMixin = Symbol('asyncIterableMixin'); -export class AsyncIterableTransform { - private static [asyncIterableMixin] = false; - constructor(options?: TransformOptions) { - Transform.call(this as any, options); - // If this is the first time AsyncIterableTransform is being constructed, - // mixin the methods from the AsyncIterableX's prototype. - if (!AsyncIterableTransform[asyncIterableMixin]) { - AsyncIterableTransform[asyncIterableMixin] = true; - Object.defineProperties( - AsyncIterableTransform.prototype, - Object.getOwnPropertyDescriptors(AsyncIterableX.prototype) - ); - } - } - /** @nocollapse */ - _flush(callback: TransformCallback): void { - callback(); - } - /** @nocollapse */ - _transform(chunk: any, _encoding: string, callback: TransformCallback): void { - callback(null, chunk); +export function AsyncIterableTransform( + this: AsyncIterableTransform, + options?: TransformOptions +) { + Transform.call(this as any, options); + // If this is the first time AsyncIterableTransform is being constructed, + // mixin the methods from the AsyncIterableX's prototype. + if (!AsyncIterableTransform[asyncIterableMixin]) { + AsyncIterableTransform[asyncIterableMixin] = true; + Object.defineProperties( + AsyncIterableTransform.prototype, + Object.getOwnPropertyDescriptors(AsyncIterableX.prototype) + ); } } -(AsyncIterableTransform as any).prototype = Object.create( - Transform.prototype, - Object.getOwnPropertyDescriptors(AsyncIterableTransform.prototype) -); +AsyncIterableTransform.prototype = Object.create(Transform.prototype); + +AsyncIterableTransform[asyncIterableMixin] = false; + +/** @nocollapse */ +AsyncIterableTransform.prototype._flush = function (callback: TransformCallback): void { + callback(); +}; +/** @nocollapse */ +AsyncIterableTransform.prototype._transform = function ( + chunk: any, + _encoding: string, + callback: TransformCallback +): void { + callback(null, chunk); +}; export function asAsyncIterable(options: TransformOptions = {}) { - return new AsyncIterableTransform(options); + return Reflect.construct(AsyncIterableTransform, [options]) as AsyncIterableTransform; }