| 21 | } |
| 22 | |
| 23 | function normalizeCacheEntry(entry, legacyFields = []) { |
| 24 | if (!entry) { |
| 25 | return null; |
| 26 | } |
| 27 | if (entry.schemaVersion === CACHE_SCHEMA_VERSION && Object.hasOwn(entry, "value")) { |
| 28 | return entry; |
| 29 | } |
| 30 | const updatedAt = entry.updatedAt ?? entry.Date; |
| 31 | if (!updatedAt) { |
| 32 | return null; |
| 33 | } |
| 34 | const legacyField = legacyFields.find((field) => Object.hasOwn(entry, field)); |
| 35 | if (!legacyField) { |
| 36 | return null; |
| 37 | } |
| 38 | return { |
| 39 | value: entry[legacyField], |
| 40 | updatedAt, |
| 41 | schemaVersion: CACHE_SCHEMA_VERSION, |
| 42 | }; |
| 43 | } |
| 44 | |
| 45 | function enqueueCacheWrite(key, write) { |
| 46 | const previousWrite = writeQueues.get(key) ?? Promise.resolve(); |