(raw: string, source: string)
| 96 | } |
| 97 | |
| 98 | export function parseBatchRows(raw: string, source: string): Record<string, unknown>[] { |
| 99 | const parsed = parseJson(raw, source); |
| 100 | const rows = Array.isArray(parsed) ? parsed : isRecord(parsed) ? parsed.rows : undefined; |
| 101 | |
| 102 | if (!Array.isArray(rows)) { |
| 103 | throw new BatchRenderInputError( |
| 104 | "Invalid batch payload", |
| 105 | '--batch must be a JSON array of objects, or an object with a "rows" array.', |
| 106 | ); |
| 107 | } |
| 108 | if (rows.length === 0) { |
| 109 | throw new BatchRenderInputError("Empty batch", `${source} contains zero rows.`); |
| 110 | } |
| 111 | |
| 112 | return rows.map((row, index) => { |
| 113 | if (!isRecord(row)) { |
| 114 | throw new BatchRenderInputError( |
| 115 | "Invalid batch row", |
| 116 | `Row ${index} must be a JSON object of variable values.`, |
| 117 | ); |
| 118 | } |
| 119 | return row; |
| 120 | }); |
| 121 | } |
| 122 | |
| 123 | function placeholderValue(row: Record<string, unknown>, key: string, index: number): string { |
| 124 | if (key === "index") return String(index); |
no test coverage detected