()
| 423 | } |
| 424 | |
| 425 | function localStorageDirect(): SyncStorage { |
| 426 | const scope = "direct" |
| 427 | return { |
| 428 | getItem: (key) => { |
| 429 | const cached = cacheGet(key) |
| 430 | if (fallbackDisabled(scope)) return cached ?? null |
| 431 | |
| 432 | const stored = (() => { |
| 433 | try { |
| 434 | return localStorage.getItem(key) |
| 435 | } catch { |
| 436 | fallbackSet(scope) |
| 437 | return null |
| 438 | } |
| 439 | })() |
| 440 | if (stored === null) return cached ?? null |
| 441 | cacheSet(key, stored) |
| 442 | return stored |
| 443 | }, |
| 444 | setItem: (key, value) => { |
| 445 | if (fallbackDisabled(scope)) return |
| 446 | try { |
| 447 | if (write(localStorage, key, value)) return |
| 448 | } catch { |
| 449 | fallbackSet(scope) |
| 450 | return |
| 451 | } |
| 452 | fallbackSet(scope) |
| 453 | }, |
| 454 | removeItem: (key) => { |
| 455 | cacheDelete(key) |
| 456 | if (fallbackDisabled(scope)) return |
| 457 | try { |
| 458 | localStorage.removeItem(key) |
| 459 | } catch { |
| 460 | fallbackSet(scope) |
| 461 | } |
| 462 | }, |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | const DRAFT_PERSISTED_KEYS = ["prompt", "comments", "model-selection", "file-view", "layout"] |
| 467 |
no test coverage detected