* SQLite-backed storage adapter for the offline transactions outbox. * Stores pending mutations in the main process SQLite database via IPC, * so they survive app restarts (unlike IndexedDB in Electron).
| 35 | * so they survive app restarts (unlike IndexedDB in Electron). |
| 36 | */ |
| 37 | class ElectronSQLiteStorageAdapter implements StorageAdapter { |
| 38 | private prefix: string |
| 39 | |
| 40 | constructor(prefix = 'offline-tx:') { |
| 41 | this.prefix = prefix |
| 42 | } |
| 43 | |
| 44 | private prefixedKey(key: string): string { |
| 45 | return `${this.prefix}${key}` |
| 46 | } |
| 47 | |
| 48 | async get(key: string): Promise<string | null> { |
| 49 | return window.electronAPI.kv.get(this.prefixedKey(key)) |
| 50 | } |
| 51 | |
| 52 | async set(key: string, value: string): Promise<void> { |
| 53 | await window.electronAPI.kv.set(this.prefixedKey(key), value) |
| 54 | } |
| 55 | |
| 56 | async delete(key: string): Promise<void> { |
| 57 | await window.electronAPI.kv.delete(this.prefixedKey(key)) |
| 58 | } |
| 59 | |
| 60 | async keys(): Promise<Array<string>> { |
| 61 | const allKeys = await window.electronAPI.kv.keys() |
| 62 | return allKeys |
| 63 | .filter((k) => k.startsWith(this.prefix)) |
| 64 | .map((k) => k.slice(this.prefix.length)) |
| 65 | } |
| 66 | |
| 67 | async clear(): Promise<void> { |
| 68 | const keys = await this.keys() |
| 69 | for (const key of keys) { |
| 70 | await window.electronAPI.kv.delete(this.prefixedKey(key)) |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Fetch with retry and exponential backoff. |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…