@forge/migrations
3.1.1-next.1-experimental-e03cc853.2.0-next.2
out/migration/ndjson-reader.js+
out/migration/ndjson-reader.jsNew file+30
Index: package/out/migration/ndjson-reader.js
===================================================================
--- package/out/migration/ndjson-reader.js
+++ package/out/migration/ndjson-reader.js
@@ -0,0 +1,30 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.assertValidStartRow = assertValidStartRow;
+exports.readNdjson = readNdjson;
+const errors_1 = require("./errors");
+function assertValidStartRow(startRow) {
+ if (!Number.isInteger(startRow) || startRow < 0) {
+ throw errors_1.APIError.forUnexpected('rowIndex must be a non-negative integer');
+ }
+}
+function* readNdjson(body, { startRow = 0 } = {}) {
+ assertValidStartRow(startRow);
+ let row = 0;
+ for (const line of body.split('\n')) {
+ if (line.trim() === '') {
+ continue;
+ }
+ if (row++ < startRow) {
+ continue;
+ }
+ let parsed;
+ try {
+ parsed = JSON.parse(line);
+ }
+ catch {
+ throw errors_1.APIError.forUnexpected(`Row ${row - 1} was not valid JSON: ${line}`);
+ }
+ yield parsed;
+ }
+}