* Validate that a parsed object has the shape of a CacheEntry. * Guards against truncated writes, schema changes, or manual edits.
(value: unknown)
| 95 | * Guards against truncated writes, schema changes, or manual edits. |
| 96 | */ |
| 97 | function isValidCacheEntry(value: unknown): value is CacheEntry { |
| 98 | if (typeof value !== 'object' || value === null) return false; |
| 99 | const obj = value as Record<string, unknown>; |
| 100 | return ( |
| 101 | typeof obj.endpoint === 'string' && |
| 102 | typeof obj.url === 'string' && |
| 103 | typeof obj.cachedAt === 'string' && |
| 104 | typeof obj.data === 'object' && |
| 105 | obj.data !== null |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Safely remove a cache file (e.g. when it's corrupted). |