(id: string)
| 147 | } |
| 148 | |
| 149 | async function readUpdate(id: string): Promise<Uint8Array | null> { |
| 150 | try { |
| 151 | const data = new Uint8Array(await fs.readFile(docPath(id))) |
| 152 | if (isExpectedTaskDoc(id, data)) return data |
| 153 | |
| 154 | const legacyData = await readLegacyUpdate(id) |
| 155 | if (legacyData) { |
| 156 | await writeMigratedDoc(id, legacyData) |
| 157 | return legacyData |
| 158 | } |
| 159 | |
| 160 | return data |
| 161 | } catch (error) { |
| 162 | if ((error as NodeJS.ErrnoException).code === "ENOENT") { |
| 163 | const legacyData = await readLegacyUpdate(id) |
| 164 | if (legacyData) { |
| 165 | await writeMigratedDoc(id, legacyData) |
| 166 | return legacyData |
| 167 | } |
| 168 | return null |
| 169 | } |
| 170 | throw error |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | async function saveUpdate(id: string, data: Uint8Array): Promise<void> { |
| 175 | const previous = saveQueues.get(id) ?? Promise.resolve() |
no test coverage detected