MCPcopy
hub / github.com/Effect-TS/effect / get

Function get

packages/experimental/src/Persistence.ts:383–407  ·  view source on GitHub ↗
(method: string, key: string)

Source from the content-addressed store, hash-verified

381 Effect.map(Effect.clock, (clock) => {
382 const store = KeyValueStore.prefix(backing, storeId)
383 const get = (method: string, key: string) =>
384 Effect.flatMap(
385 Effect.mapError(
386 store.get(key),
387 (error) => PersistenceBackingError.make(method, error)
388 ),
389 Option.match({
390 onNone: () => Effect.succeedNone,
391 onSome: (s) =>
392 Effect.flatMap(
393 Effect.try({
394 try: () => JSON.parse(s),
395 catch: (error) => PersistenceBackingError.make(method, error)
396 }),
397 (_) => {
398 if (!Array.isArray(_)) return Effect.succeedNone
399 const [value, expires] = _ as [unknown, number | null]
400 if (expires !== null && expires <= clock.unsafeCurrentTimeMillis()) {
401 return Effect.as(Effect.ignore(store.remove(key)), Option.none())
402 }
403 return Effect.succeed(Option.some(value))
404 }
405 )
406 })
407 )
408 return identity<BackingPersistenceStore>({
409 get: (key) => get("get", key),
410 getMany: (keys) => Effect.forEach(keys, (key) => get("getMany", key), { concurrency: "unbounded" }),

Callers 1

Persistence.tsFile · 0.70

Calls 5

parseMethod · 0.80
getMethod · 0.65
makeMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected