Parse a JSONL batch file into entries, exiting with a clear error on a bad line.
(path: string)
| 693 | |
| 694 | /** Parse a JSONL batch file into entries, exiting with a clear error on a bad line. */ |
| 695 | function parseBatchFile(path: string): BatchEntry[] { |
| 696 | const lines = readFileSync(path, "utf8").split(/\r?\n/); |
| 697 | const entries: BatchEntry[] = []; |
| 698 | // fallow-ignore-next-line complexity |
| 699 | lines.forEach((line, idx) => { |
| 700 | const trimmed = line.trim(); |
| 701 | if (!trimmed) return; |
| 702 | let parsed: unknown; |
| 703 | try { |
| 704 | parsed = JSON.parse(trimmed); |
| 705 | } catch { |
| 706 | console.error(`[cloudrun render-batch] line ${idx + 1}: not valid JSON`); |
| 707 | process.exit(1); |
| 708 | } |
| 709 | if ( |
| 710 | !parsed || |
| 711 | typeof parsed !== "object" || |
| 712 | typeof (parsed as BatchEntry).outputKey !== "string" |
| 713 | ) { |
| 714 | console.error( |
| 715 | `[cloudrun render-batch] line ${idx + 1}: must be an object with a string "outputKey"`, |
| 716 | ); |
| 717 | process.exit(1); |
| 718 | } |
| 719 | entries.push(parsed as BatchEntry); |
| 720 | }); |
| 721 | return entries; |
| 722 | } |
| 723 | |
| 724 | // ── destroy ────────────────────────────────────────────────────────────── |
| 725 |