From 17c1644d90569aace6b4d2d4ba4d76eada135762 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Wed, 12 Nov 2025 23:15:55 -0800 Subject: [PATCH] Loosen type definition to `AsyncIterable` This change reflects the actual runtime check that is being performed (i.e., that `Symbol.asyncIterator` is implemented) and allows users to pass (runtime-valid) `async function*` transformation functions without any type errors. --- src/core.js | 8 ++++---- test/core.test.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/core.js b/src/core.js index ce917f8..53bb1c3 100644 --- a/src/core.js +++ b/src/core.js @@ -230,14 +230,14 @@ export class CSVReader { * A function to process a row of CSV data from `CSVReader`. * @callback TransformationFunction * @param {Array} row A row of input CSV data before transformation. - * @returns {MaybePromise>} + * @returns {MaybePromise>} */ /** * A function to process multiple rows of CSV data from `CSVReader`. * @callback TransformationFunctionBatch * @param {Array>} rows Multiple rows of input CSV data. - * @returns {MaybePromise>} + * @returns {MaybePromise>} */ /** @@ -246,7 +246,7 @@ export class CSVReader { * @param {Array} row The row passed to the transformation function which threw the error. * @param {Error} error The error thrown by the transformation function. * @param {TransformationFunction} fn The transformation function itself. This argument can be used to retry a transformation. - * @returns {MaybePromise>} + * @returns {MaybePromise>} */ /** @@ -255,7 +255,7 @@ export class CSVReader { * @param {Array>} rows The rows of input CSV data passed to the transformation function which threw the error. * @param {Error} error The error thrown by the transformation function. * @param {TransformationFunctionBatch} fn The transformation function itself. This argument can be used to retry a transformation. - * @returns {MaybePromise>} + * @returns {MaybePromise>} */ /** diff --git a/test/core.test.js b/test/core.test.js index 9bd6c0b..0f8ac08 100644 --- a/test/core.test.js +++ b/test/core.test.js @@ -582,6 +582,27 @@ suite('CSVTransformer', { concurrency: true }, () => { ])); deepStrictEqual(fn.mock.callCount(), 2); }); + test('handles AsyncGenerator (async function*)', { concurrency: true }, async (t) => { + await createCSVMockStream([ + ['columnA'], + ['1'], + ['2'] + ]) + .pipeThrough(new CSVTransformer(async function* (row) { + yield [`${row[0]}a`]; + yield [`${row[0]}b`]; + yield [`${row[0]}c`]; + })) + .pipeTo(csvStreamEqualWritable([ + ['columnA'], + ['1a'], + ['1b'], + ['1c'], + ['2a'], + ['2b'], + ['2c'] + ])); + }); test('handles ReadableStream', { concurrency: true }, async (t) => { await createCSVMockStream([ ['columnA'], -- 2.47.3