* Recover all records from the WAL file. * Handles partial writes and decode errors gracefully. * Updates the recovery state (accessible via getStats). * @returns Recovery result with records, errors, and partial tail
()
| 203 | * @returns Recovery result with records, errors, and partial tail |
| 204 | */ |
| 205 | recover(): RecoverResult<T | InvalidEntry<string>> { |
| 206 | if (!fs.existsSync(this.#file)) { |
| 207 | this.#lastRecoveryState = { records: [], errors: [], partialTail: null }; |
| 208 | return this.#lastRecoveryState; |
| 209 | } |
| 210 | const txt = fs.readFileSync(this.#file, 'utf8'); |
| 211 | this.#lastRecoveryState = recoverFromContent<T | InvalidEntry<string>>( |
| 212 | txt, |
| 213 | this.#decode, |
| 214 | ); |
| 215 | |
| 216 | return this.#lastRecoveryState; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Repack the WAL by recovering all valid records and rewriting cleanly. |
no test coverage detected