MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / parseBatchRows

Function parseBatchRows

packages/cli/src/commands/batchRender.ts:98–121  ·  view source on GitHub ↗
(raw: string, source: string)

Source from the content-addressed store, hash-verified

96}
97
98export 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
123function placeholderValue(row: Record<string, unknown>, key: string, index: number): string {
124 if (key === "index") return String(index);

Callers 2

prepareBatchRenderFunction · 0.85

Calls 2

parseJsonFunction · 0.70
isRecordFunction · 0.70

Tested by

no test coverage detected