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

Function layerStorage

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

Source from the content-addressed store, hash-verified

256
257/** @internal */
258export const layerStorage = (evaluate: LazyArg<Storage>) =>
259 Layer.sync(keyValueStoreTag, () => {
260 const storage = evaluate()
261 return makeStringOnly({
262 get: (key: string) =>
263 Effect.try({
264 try: () => Option.fromNullable(storage.getItem(key)),
265 catch: () =>
266 storageError({
267 pathOrDescriptor: key,
268 method: "get",
269 description: `Unable to get item with key ${key}`
270 })
271 }),
272
273 set: (key: string, value: string) =>
274 Effect.try({
275 try: () => storage.setItem(key, value),
276 catch: () =>
277 storageError({
278 pathOrDescriptor: key,
279 method: "set",
280 description: `Unable to set item with key ${key}`
281 })
282 }),
283
284 remove: (key: string) =>
285 Effect.try({
286 try: () => storage.removeItem(key),
287 catch: () =>
288 storageError({
289 pathOrDescriptor: key,
290 method: "remove",
291 description: `Unable to remove item with key ${key}`
292 })
293 }),
294
295 clear: Effect.try({
296 try: () => storage.clear(),
297 catch: () =>
298 storageError({
299 pathOrDescriptor: "clear",
300 method: "clear",
301 description: `Unable to clear storage`
302 })
303 }),
304
305 size: Effect.try({
306 try: () => storage.length,
307 catch: () =>
308 storageError({
309 pathOrDescriptor: "size",
310 method: "size",
311 description: `Unable to get size`
312 })
313 })
314 })
315 })

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…