(path: string)
| 75 | * (forward-compatible: a schema bump on the writer doesn't break older readers). |
| 76 | */ |
| 77 | export function readJsonl<T = unknown>(path: string): T[] { |
| 78 | if (!existsSync(path)) return []; |
| 79 | let raw: string; |
| 80 | try { |
| 81 | raw = readFileSync(path, "utf-8"); |
| 82 | } catch { |
| 83 | return []; |
| 84 | } |
| 85 | const out: T[] = []; |
| 86 | for (const line of raw.split("\n")) { |
| 87 | const trimmed = line.trim(); |
| 88 | if (!trimmed) continue; |
| 89 | try { |
| 90 | out.push(JSON.parse(trimmed) as T); |
| 91 | } catch { |
| 92 | // Malformed line (partial tail / corruption) — skip, keep reading. |
| 93 | } |
| 94 | } |
| 95 | return out; |
| 96 | } |
no test coverage detected