From: Ardis Lu Date: Thu, 13 Nov 2025 07:15:55 +0000 (-0800) Subject: Loosen type definition to `AsyncIterable` X-Git-Tag: v0.1.10~4 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=17c1644d90569aace6b4d2d4ba4d76eada135762;p=csvio 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. --- 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'],