| 77 | & Partial<Omit<KeyValueStore.KeyValueStore, "set">> |
| 78 | & { readonly set: (key: string, value: string) => Effect.Effect<void, PlatformError.PlatformError> } |
| 79 | ) => KeyValueStore.KeyValueStore = (impl) => { |
| 80 | const encoder = new TextEncoder() |
| 81 | return make({ |
| 82 | ...impl, |
| 83 | getUint8Array: (key) => |
| 84 | impl.get(key).pipe( |
| 85 | Effect.map(Option.map((value) => |
| 86 | Either.match(Encoding.decodeBase64(value), { |
| 87 | onLeft: () => encoder.encode(value), |
| 88 | onRight: identity |
| 89 | }) |
| 90 | )) |
| 91 | ), |
| 92 | set: (key, value) => |
| 93 | typeof value === "string" |
| 94 | ? impl.set(key, value) |
| 95 | : Effect.suspend(() => impl.set(key, Encoding.encodeBase64(value))) |
| 96 | }) |
| 97 | } |
| 98 | |
| 99 | /** @internal */ |
| 100 | export const prefix = dual< |