(filePath: string)
| 39 | } |
| 40 | |
| 41 | export function readReported(filePath: string): ReportedFingerprintsFile { |
| 42 | if (!existsSync(filePath)) return emptyFile(); |
| 43 | try { |
| 44 | const raw = readFileSync(filePath, 'utf8'); |
| 45 | const parsed = JSON.parse(raw) as unknown; |
| 46 | if ( |
| 47 | typeof parsed !== 'object' || |
| 48 | parsed === null || |
| 49 | (parsed as { schemaVersion?: unknown }).schemaVersion !== 1 || |
| 50 | !Array.isArray((parsed as { entries?: unknown }).entries) |
| 51 | ) { |
| 52 | return emptyFile(); |
| 53 | } |
| 54 | const entries = ((parsed as ReportedFingerprintsFile).entries ?? []).filter( |
| 55 | (e): e is ReportedFingerprint => |
| 56 | typeof e === 'object' && |
| 57 | e !== null && |
| 58 | typeof e.fingerprint === 'string' && |
| 59 | typeof e.ts === 'number' && |
| 60 | typeof e.issueUrl === 'string', |
| 61 | ); |
| 62 | return { schemaVersion: 1, entries }; |
| 63 | } catch { |
| 64 | return emptyFile(); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Write `content` to `path` atomically via a temp file + rename. `renameSync` |
no test coverage detected