2026-05-10 23:12:26 +02:00
|
|
|
import { readFile } from 'node:fs/promises';
|
2026-05-10 23:51:24 +02:00
|
|
|
import { parseIngestReportSnapshot, type IngestReportSnapshot } from '@ktx/context/ingest';
|
2026-05-10 23:12:26 +02:00
|
|
|
|
|
|
|
|
export async function readIngestReportSnapshotFile(reportFile: string): Promise<IngestReportSnapshot> {
|
|
|
|
|
const raw = await readFile(reportFile, 'utf-8');
|
|
|
|
|
let parsed: unknown;
|
|
|
|
|
try {
|
|
|
|
|
parsed = JSON.parse(raw);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
|
|
|
throw new Error(`Invalid JSON in ingest report file ${reportFile}: ${message}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return parseIngestReportSnapshot(parsed);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
|
|
|
throw new Error(`Invalid ingest report file ${reportFile}: ${message}`);
|
|
|
|
|
}
|
|
|
|
|
}
|