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

Function layerStorage

packages/platform/src/internal/keyValueStore.ts:276–333  ·  view source on GitHub ↗
(evaluate: LazyArg<Storage>)

Source from the content-addressed store, hash-verified

274
275/** @internal */
276export const layerStorage = (evaluate: LazyArg<Storage>) =>
277 Layer.sync(keyValueStoreTag, () => {
278 const storage = evaluate()
279 return makeStringOnly({
280 get: (key: string) =>
281 Effect.try({
282 try: () => Option.fromNullable(storage.getItem(key)),
283 catch: () =>
284 storageError({
285 pathOrDescriptor: key,
286 method: "get",
287 description: `Unable to get item with key ${key}`
288 })
289 }),
290
291 set: (key: string, value: string) =>
292 Effect.try({
293 try: () => storage.setItem(key, value),
294 catch: () =>
295 storageError({
296 pathOrDescriptor: key,
297 method: "set",
298 description: `Unable to set item with key ${key}`
299 })
300 }),
301
302 remove: (key: string) =>
303 Effect.try({
304 try: () => storage.removeItem(key),
305 catch: () =>
306 storageError({
307 pathOrDescriptor: key,
308 method: "remove",
309 description: `Unable to remove item with key ${key}`
310 })
311 }),
312
313 clear: Effect.try({
314 try: () => storage.clear(),
315 catch: () =>
316 storageError({
317 pathOrDescriptor: "clear",
318 method: "clear",
319 description: `Unable to clear storage`
320 })
321 }),
322
323 size: Effect.try({
324 try: () => storage.length,
325 catch: () =>
326 storageError({
327 pathOrDescriptor: "size",
328 method: "size",
329 description: `Unable to get size`
330 })
331 })
332 })
333 })

Callers

nothing calls this directly

Calls 4

makeStringOnlyFunction · 0.85
storageErrorFunction · 0.85
syncMethod · 0.80
clearMethod · 0.80

Tested by

no test coverage detected