(id: string, data: Uint8Array)
| 122 | const ensureRoot = () => fs.mkdir(rootDir, { recursive: true }) |
| 123 | |
| 124 | async function writeMigratedDoc(id: string, data: Uint8Array): Promise<void> { |
| 125 | await ensureRoot() |
| 126 | const filePath = docPath(id) |
| 127 | const tempPath = `${filePath}.tmp.${Date.now()}.${Math.random().toString(36).slice(2)}` |
| 128 | try { |
| 129 | await fs.writeFile(tempPath, data) |
| 130 | await fs.rename(tempPath, filePath) |
| 131 | } catch (error) { |
| 132 | await fs.unlink(tempPath).catch(() => undefined) |
| 133 | throw error |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | async function readLegacyUpdate(id: string): Promise<Uint8Array | null> { |
| 138 | const filePath = legacyDocPath(id) |
no test coverage detected