| 141 | } |
| 142 | |
| 143 | export function readHealth(raw: unknown): ProjectHealth { |
| 144 | const record = isRecord(raw) ? raw : {}; |
| 145 | const status = record['status']; |
| 146 | return { |
| 147 | status: status === 'healthy' || status === 'missing' || status === 'corrupt' ? status : 'unknown', |
| 148 | nodes: optionalNumber(record['nodes']), |
| 149 | edges: optionalNumber(record['edges']), |
| 150 | sizeBytes: optionalNumber(record['size_bytes']), |
| 151 | indexedAt: typeof record['indexed_at'] === 'string' && Number.isFinite(Date.parse(record['indexed_at'])) ? record['indexed_at'] : null, |
| 152 | watchRegistered: typeof record['watch_registered'] === 'boolean' ? record['watch_registered'] : null, |
| 153 | watcherRunning: typeof record['watcher_running'] === 'boolean' ? record['watcher_running'] : null, |
| 154 | reason: text(record['reason']), |
| 155 | }; |
| 156 | } |
| 157 | |
| 158 | /** Megabytes with one decimal, for a size the server gave in bytes. */ |
| 159 | export function megabytes(bytes: number): string { |