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

Function readCurrentAsync

packages/app/src/utils/persist.ts:275–290  ·  view source on GitHub ↗
(input: {
  storage: AsyncStorage
  key: string
  defaults: unknown
  migrate?: (value: unknown) => unknown
})

Source from the content-addressed store, hash-verified

273}
274
275async function readCurrentAsync(input: {
276 storage: AsyncStorage
277 key: string
278 defaults: unknown
279 migrate?: (value: unknown) => unknown
280}) {
281 const raw = await input.storage.getItem(input.key)
282 if (raw === null) return
283 const next = normalize(input.defaults, raw, input.migrate)
284 if (next === undefined) {
285 await input.storage.removeItem(input.key).catch(() => undefined)
286 return null
287 }
288 if (raw !== next) await input.storage.setItem(input.key, next)
289 return next
290}
291
292async function removeAsync(storage: AsyncStorage, key: string) {
293 try {

Callers 1

persistedFunction · 0.85

Calls 4

getItemMethod · 0.80
removeItemMethod · 0.80
setItemMethod · 0.80
normalizeFunction · 0.70

Tested by

no test coverage detected