/**
* A row or rows of output CSV data, or `null` to not output anything.
- * @typedef {Array<Array<any>>|Array<any>|string|null} TransformationOutput
+ * @typedef {Array<Array<any>>|Array<any>|ArrayLike<any>|string|null} TransformationOutput
*/
/**
else if (this.#rawOutput || typeof row === 'string') {
controller.enqueue(row);
}
- else if (Array.isArray(row) && Array.isArray(row[0])) { // Multiple rows returned, enqueue each row separately
- row.forEach(r => controller.enqueue(JSON.stringify(r)));
+ else if (Array.isArray(row)) {
+ if (Array.isArray(row[0])) { // Multiple rows returned, enqueue each row separately
+ row.forEach(r => controller.enqueue(JSON.stringify(r)));
+ }
+ else { // One row returned
+ controller.enqueue(JSON.stringify(row));
+ }
}
- else {
- controller.enqueue(JSON.stringify(row));
+ else { // Assume ArrayLike output
+ controller.enqueue(JSON.stringify(Array.from(row)));
}
}
['abc', 'def']
]));
});
+ test('handles ArrayLike outputs', { concurrency: true }, async () => {
+ await createCSVMockStream([
+ ['columnA', 'columnB'],
+ ['a', 'b']
+ ])
+ .pipeThrough(new CSVTransformer(() => ({ length: 2, 0: 'a2', 1: 'b2' })))
+ .pipeTo(csvStreamEqualWritable([
+ ['columnA', 'columnB'],
+ ['a2', 'b2']
+ ]));
+ });
test('consumes input row without output row when null is returned', { concurrency: true }, async () => {
await createCSVMockStream([
['columnA', 'columnB'],