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

Function getMany

packages/platform/browser/src/BrowserPersistence.ts:152–184  ·  view source on GitHub ↗
(
  db: IDBDatabase,
  clock: Clock.Clock,
  storeId: string,
  keys: Arr.NonEmptyArray<string>
)

Source from the content-addressed store, hash-verified

150 )
151
152const getMany = (
153 db: IDBDatabase,
154 clock: Clock.Clock,
155 storeId: string,
156 keys: Arr.NonEmptyArray<string>
157): Effect.Effect<Arr.NonEmptyArray<object | undefined>, Persistence.PersistenceError> =>
158 withEntriesTransaction(
159 db,
160 "readwrite",
161 "Failed to getMany from backing store",
162 (entries, setResult, fail) => {
163 const now = clock.currentTimeMillisUnsafe()
164 const results = new Array<object | undefined>(keys.length)
165 setResult(results as any)
166
167 for (let i = 0; i < keys.length; i++) {
168 const key = keys[i]
169 const keyPath = [storeId, key]
170 const request = entries.get(keyPath)
171 request.onerror = () => fail(request.error)
172 request.onsuccess = () => {
173 const row = request.result as EntryRow | undefined
174 if (!row) return
175 else if (!isExpired(row, now)) {
176 results[i] = row.value
177 return
178 }
179 const deleteRequest = entries.delete(keyPath)
180 deleteRequest.onerror = () => fail(deleteRequest.error)
181 }
182 }
183 }
184 )
185
186const set = (
187 db: IDBDatabase,

Callers 1

layerBackingIndexedDbFunction · 0.85

Calls 6

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

Tested by

no test coverage detected