* 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>>}
*/
/**
* @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>>}
*/
/**
* @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>>}
*/
/**
]));
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'],