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

Function layerStorage

packages/effect/src/unstable/persistence/KeyValueStore.ts:825–887  ·  view source on GitHub ↗
(
  evaluate: LazyArg<Storage>
)

Source from the content-addressed store, hash-verified

823 * @since 4.0.0
824 */
825export const layerStorage = (
826 evaluate: LazyArg<Storage>
827): Layer.Layer<KeyValueStore> =>
828 Layer.sync(KeyValueStore)(() => {
829 const storage = evaluate()
830 return makeStringOnly({
831 get: (key: string) =>
832 Effect.try({
833 try: () => storage.getItem(key) ?? undefined,
834 catch: (cause) =>
835 new KeyValueStoreError({
836 key,
837 method: "get",
838 message: `Unable to get item with key ${key}`,
839 cause
840 })
841 }),
842
843 set: (key: string, value: string) =>
844 Effect.try({
845 try: () => storage.setItem(key, value),
846 catch: (cause) =>
847 new KeyValueStoreError({
848 key,
849 method: "set",
850 message: `Unable to set item with key ${key}`,
851 cause
852 })
853 }),
854
855 remove: (key: string) =>
856 Effect.try({
857 try: () => storage.removeItem(key),
858 catch: (cause) =>
859 new KeyValueStoreError({
860 key,
861 method: "remove",
862 message: `Unable to remove item with key ${key}`,
863 cause
864 })
865 }),
866
867 clear: Effect.try({
868 try: () => storage.clear(),
869 catch: (cause) =>
870 new KeyValueStoreError({
871 method: "clear",
872 message: `Unable to clear storage`,
873 cause
874 })
875 }),
876
877 size: Effect.try({
878 try: () => storage.length,
879 catch: (cause) =>
880 new KeyValueStoreError({
881 method: "size",
882 message: `Unable to get size`,

Callers

nothing calls this directly

Calls 4

makeStringOnlyFunction · 0.85
clearMethod · 0.80
evaluateFunction · 0.50
syncMethod · 0.45

Tested by

no test coverage detected