* input data, the error that was thrown, and the transformation function itself will be passed to the `onError` function. The default value is
* `null` (errors will not be caught).
* @property {number} [maxBatchSize=1] Set to the maximum number of rows that will be passed to the transformation function per function call
- * (greedy). The default value is `1`.
- *
- * NOTE: If this value is set to any value (including `1`), then value passed to `fn()` will be a 2-D array of type `Array<Array<string>>`.
+ * (greedy).
* @property {number} [maxConcurrent=1] The maximum concurrent executions of the transformation function (greedy). The transformation function
* will be automatically turned into a promise if it isn't already async. Execution is blocked until all promises in a concurrent group settle
* (i.e., if one transformation in a group is hanging, further rows will NOT be processed even if all other transformations in the group are
* to catch errors thrown by the transformation function. The input data, the error that was thrown, and the transformation function itself will
* be passed to the `onError` function. The default value is `null` (errors will not be caught).
* @property {number} maxBatchSize Set to the maximum number of rows that will be passed to the transformation function per function call
- * (greedy). The default value is `1`.
+ * (greedy).
*
* NOTE: If this value is set to any value (including `1`), then value passed to `fn()` will be a 2-D array of type `Array<Array<string>>`.
* @property {number} [maxConcurrent=1] The maximum concurrent executions of the transformation function (greedy). The transformation function
this.#rawInput = options.rawInput ?? false;
this.#rawOutput = options.rawOutput ?? false;
this.#onError = options.onError ?? null;
- this.#maxBatchSize = options.maxBatchSize ?? 1;
+ this.#maxBatchSize = options.maxBatchSize ?? null;
this.#maxConcurrent = options.maxConcurrent ?? 1;
this.#fn = fn;
return;
}
- if (this.#maxBatchSize > 1) {
+ if (this.#maxBatchSize !== null) {
this.#batch.push(row);
if (this.#batch.length === this.#maxBatchSize) {
this.#concurrent.push(this.#wrappedFn(this.#batch));
{ name: 'Error', message: 'Not an error type' }
);
});
+ test('creates batch of 1 when maxBatchSize is equal to 1', { concurrency: true }, async () => {
+ await createCSVMockStream([
+ ['columnA', 'columnB'],
+ ['1', '2'],
+ ['3', '4'],
+ ['5', '6']
+ ])
+ .pipeThrough(new CSVTransformer(b => b.map(r => r.map(f => Number(f) * 2)), { maxBatchSize: 1 }))
+ .pipeTo(csvStreamEqualWritable([
+ ['columnA', 'columnB'],
+ [2, 4],
+ [6, 8],
+ [10, 12]
+ ]));
+ });
test('creates one batch when maxBatchSize is greater than CSV row length', { concurrency: true }, async () => {
await createCSVMockStream([
['columnA', 'columnB'],