(path: string)
| 331 | } |
| 332 | |
| 333 | async function scanWire(path: string): Promise<{ count: number; protocolVersion: string }> { |
| 334 | const stream = createReadStream(path, { encoding: 'utf8' }); |
| 335 | const rl = createInterface({ input: stream, crlfDelay: Infinity }); |
| 336 | let count = 0; |
| 337 | let protocolVersion: string | null = null; |
| 338 | for await (const line of rl) { |
| 339 | if (line.length === 0) continue; |
| 340 | if (protocolVersion === null) { |
| 341 | // Strict: the first non-empty line MUST be a well-formed |
| 342 | // `metadata` record. Otherwise the list-view health would say |
| 343 | // "ok" while the wire-reader rejects the file on open. |
| 344 | let parsed: { type?: unknown; protocol_version?: unknown }; |
| 345 | try { |
| 346 | parsed = JSON.parse(line) as typeof parsed; |
| 347 | } catch { |
| 348 | throw new Error(`wire metadata is not valid JSON at line 1`); |
| 349 | } |
| 350 | if (parsed.type !== 'metadata' || typeof parsed.protocol_version !== 'string') { |
| 351 | throw new Error(`wire is missing a metadata header on line 1`); |
| 352 | } |
| 353 | protocolVersion = parsed.protocol_version; |
| 354 | } |
| 355 | count += 1; |
| 356 | } |
| 357 | if (protocolVersion === null) { |
| 358 | throw new Error('wire file is empty'); |
| 359 | } |
| 360 | return { count, protocolVersion }; |
| 361 | } |
| 362 | |
| 363 | function parseTs(input: string | undefined): number { |
| 364 | if (!input) return 0; |
no outgoing calls
no test coverage detected