MCPcopy Create free account
hub / github.com/Effect-TS/effect / get

Function get

packages/platform/browser/src/BrowserPersistence.ts:119–150  ·  view source on GitHub ↗
(
  db: IDBDatabase,
  clock: Clock.Clock,
  storeId: string,
  key: string
)

Source from the content-addressed store, hash-verified

117const isExpired = (row: EntryRow, now: number): boolean => row.expires !== null && row.expires <= now
118
119const get = (
120 db: IDBDatabase,
121 clock: Clock.Clock,
122 storeId: string,
123 key: string
124): Effect.Effect<object | undefined, Persistence.PersistenceError> =>
125 withEntriesTransaction<object | undefined>(
126 db,
127 "readwrite",
128 `Failed to get key ${key} from backing store`,
129 (
130 entries,
131 setResult,
132 fail
133 ) => {
134 const now = clock.currentTimeMillisUnsafe()
135 const id: [string, string] = [storeId, key]
136 const request = entries.get(id)
137 request.onerror = () => fail(request.error)
138 request.onsuccess = () => {
139 const row = request.result as EntryRow | undefined
140 if (!row || !isExpired(row, now)) {
141 setResult(row?.value)
142 return
143 }
144
145 const deleteRequest = entries.delete(id)
146 deleteRequest.onerror = () => fail(deleteRequest.error)
147 deleteRequest.onsuccess = () => setResult(undefined)
148 }
149 }
150 )
151
152const getMany = (
153 db: IDBDatabase,

Callers 1

layerBackingIndexedDbFunction · 0.70

Calls 6

withEntriesTransactionFunction · 0.85
isExpiredFunction · 0.85
setResultFunction · 0.85
failFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected