MCPcopy Create free account
hub / github.com/anomalyco/opencode / localStorageWithPrefix

Function localStorageWithPrefix

packages/app/src/utils/persist.ts:379–423  ·  view source on GitHub ↗
(prefix: string)

Source from the content-addressed store, hash-verified

377}
378
379function localStorageWithPrefix(prefix: string): SyncStorage {
380 const base = `${prefix}:`
381 const scope = `prefix:${prefix}`
382 const item = (key: string) => base + key
383 return {
384 getItem: (key) => {
385 const name = item(key)
386 const cached = cacheGet(name)
387 if (fallbackDisabled(scope)) return cached ?? null
388
389 const stored = (() => {
390 try {
391 return localStorage.getItem(name)
392 } catch {
393 fallbackSet(scope)
394 return null
395 }
396 })()
397 if (stored === null) return cached ?? null
398 cacheSet(name, stored)
399 return stored
400 },
401 setItem: (key, value) => {
402 const name = item(key)
403 if (fallbackDisabled(scope)) return
404 try {
405 if (write(localStorage, name, value)) return
406 } catch {
407 fallbackSet(scope)
408 return
409 }
410 fallbackSet(scope)
411 },
412 removeItem: (key) => {
413 const name = item(key)
414 cacheDelete(name)
415 if (fallbackDisabled(scope)) return
416 try {
417 localStorage.removeItem(name)
418 } catch {
419 fallbackSet(scope)
420 }
421 },
422 }
423}
424
425function localStorageDirect(): SyncStorage {
426 const scope = "direct"

Callers 2

removePersistedFunction · 0.85
persistedFunction · 0.85

Calls 9

cacheGetFunction · 0.85
fallbackDisabledFunction · 0.85
fallbackSetFunction · 0.85
cacheSetFunction · 0.85
cacheDeleteFunction · 0.85
getItemMethod · 0.80
removeItemMethod · 0.80
itemFunction · 0.70
writeFunction · 0.70

Tested by

no test coverage detected