]> git.ardis.lu - csvio/commitdiff
Loosen type definition to `AsyncIterable`
authorArdis Lu <ardisglu@gmail.com>
Thu, 13 Nov 2025 07:15:55 +0000 (23:15 -0800)
committerArdis Lu <ardisglu@gmail.com>
Thu, 13 Nov 2025 07:15:55 +0000 (23:15 -0800)
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
test/core.test.js

index ce917f814df5aa7373833bf3db2760cad2d1a26b..53bb1c38fc79c9c5d8646fe2c0be414a47101512 100644 (file)
@@ -230,14 +230,14 @@ export class CSVReader {
  * A function to process a row of CSV data from `CSVReader`.
  * @callback TransformationFunction
  * @param {Array<any>} row A row of input CSV data before transformation.
- * @returns {MaybePromise<TransformationOutput|ReadableStream<TransformationOutput>>}
+ * @returns {MaybePromise<TransformationOutput|AsyncIterable<TransformationOutput>>}
  */
 
 /**
  * A function to process multiple rows of CSV data from `CSVReader`.
  * @callback TransformationFunctionBatch
  * @param {Array<Array<any>>} rows Multiple rows of input CSV data.
- * @returns {MaybePromise<TransformationOutput|ReadableStream<TransformationOutput>>}
+ * @returns {MaybePromise<TransformationOutput|AsyncIterable<TransformationOutput>>}
  */
 
 /**
@@ -246,7 +246,7 @@ export class CSVReader {
  * @param {Array<any>} 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<TransformationOutput|ReadableStream<TransformationOutput>>}
+ * @returns {MaybePromise<TransformationOutput|AsyncIterable<TransformationOutput>>}
  */
 
 /**
@@ -255,7 +255,7 @@ export class CSVReader {
  * @param {Array<Array<any>>} 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<TransformationOutput|ReadableStream<TransformationOutput>>}
+ * @returns {MaybePromise<TransformationOutput|AsyncIterable<TransformationOutput>>}
  */
 
 /**
index 9bd6c0b9713f7e3691b7ae876ff65ef4c67ca49b..0f8ac081b9e6ad4d7271a32315d30c60d1333531 100644 (file)
@@ -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'],
This page took 0.055367 seconds and 4 git commands to generate.