Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/csv-generate/dist/cjs/sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ const generate = function (options) {
}
chunks.push(chunk);
};
// Surface validation errors synchronously instead of emitting stream errors.
generator.destroy = function (err) {
throw err;
};
while (work) {
generator.__read(options.highWaterMark);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/csv-generate/dist/esm/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5399,6 +5399,10 @@ const generate = function (options) {
}
chunks.push(chunk);
};
// Surface validation errors synchronously instead of emitting stream errors.
generator.destroy = function (err) {
throw err;
};
while (work) {
generator.__read(options.highWaterMark);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/csv-generate/dist/iife/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5402,6 +5402,10 @@ var csv_generate_sync = (function (exports) {
}
chunks.push(chunk);
};
// Surface validation errors synchronously instead of emitting stream errors.
generator.destroy = function (err) {
throw err;
};
while (work) {
generator.__read(options.highWaterMark);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/csv-generate/dist/umd/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5405,6 +5405,10 @@
}
chunks.push(chunk);
};
// Surface validation errors synchronously instead of emitting stream errors.
generator.destroy = function (err) {
throw err;
};
while (work) {
generator.__read(options.highWaterMark);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/csv-generate/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ const generate = function (options) {
}
chunks.push(chunk);
};
// Surface validation errors synchronously instead of emitting stream errors.
generator.destroy = function (err) {
throw err;
};
while (work) {
generator.__read(options.highWaterMark);
}
Expand Down
33 changes: 33 additions & 0 deletions packages/csv-generate/test/api.sync.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import assert from "node:assert/strict";
import "should";
import { generate } from "../lib/sync.js";

Expand All @@ -17,6 +18,38 @@ describe("api sync", function () {
);
});

for (const value of [true, undefined, {}]) {
it(`throws for unsupported column value ${JSON.stringify(value)}`, function () {
(() => generate({ length: 1, columns: [() => value] })).should.throw(
/^INVALID_VALUE:/,
);
});
}

it("throws instead of returning partially generated records", function () {
(() =>
generate({
length: 2,
columns: [({ state }) => (state.count_created === 0 ? "ok" : true)],
})).should.throw(/^INVALID_VALUE:/);
});

it("preserves errors thrown by column functions", function () {
const error = new Error("column failed");
assert.throws(
() =>
generate({
length: 1,
columns: [
() => {
throw error;
},
],
}),
(caught) => caught === error,
);
});

it("accept length as an integer", function () {
const data = generate(1000);
data.split(/\n/).length.should.eql(1000);
Expand Down