| 132 | * `BlobStore` interface. |
| 133 | */ |
| 134 | export const makeInMemoryBlobStore = (): BlobStore => { |
| 135 | const store = new Map<string, string>(); |
| 136 | const k = (ns: string, key: string) => `${ns}::${key}`; |
| 137 | return { |
| 138 | get: (ns, key) => Effect.sync(() => store.get(k(ns, key)) ?? null), |
| 139 | getMany: (namespaces, key) => |
| 140 | Effect.sync(() => { |
| 141 | const hits = new Map<string, string>(); |
| 142 | for (const ns of namespaces) { |
| 143 | const v = store.get(k(ns, key)); |
| 144 | if (v !== undefined) hits.set(ns, v); |
| 145 | } |
| 146 | return hits; |
| 147 | }), |
| 148 | put: (ns, key, value) => |
| 149 | Effect.sync(() => { |
| 150 | store.set(k(ns, key), value); |
| 151 | }), |
| 152 | delete: (ns, key) => |
| 153 | Effect.sync(() => { |
| 154 | store.delete(k(ns, key)); |
| 155 | }), |
| 156 | has: (ns, key) => Effect.sync(() => store.has(k(ns, key))), |
| 157 | }; |
| 158 | }; |
| 159 | |
| 160 | /** Hex SHA-256 of a UTF-8 string — the content-address key plugins use for |
| 161 | * write-once blobs (`put(key(hash), …)` is then idempotent and orphaned |