MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeR2BlobStore

Function makeR2BlobStore

packages/hosts/cloudflare/src/blob-store.ts:28–70  ·  view source on GitHub ↗
(bucket: R2Bucket)

Source from the content-addressed store, hash-verified

26 new StorageError({ message: `R2 blob ${op} failed`, cause });
27
28export const makeR2BlobStore = (bucket: R2Bucket): BlobStore => ({
29 get: (namespace, key) =>
30 Effect.tryPromise({
31 try: async () => {
32 const object = await bucket.get(objectName(namespace, key));
33 return object == null ? null : await object.text();
34 },
35 catch: storeError("get"),
36 }),
37 // R2 has no multi-get; fetch the (at most two — user + org partition)
38 // namespaces concurrently.
39 getMany: (namespaces, key) =>
40 Effect.tryPromise({
41 try: async () => {
42 const hits = new Map<string, string>();
43 await Promise.all(
44 namespaces.map(async (namespace) => {
45 const object = await bucket.get(objectName(namespace, key));
46 if (object != null) hits.set(namespace, await object.text());
47 }),
48 );
49 return hits;
50 },
51 catch: storeError("getMany"),
52 }),
53 put: (namespace, key, value) =>
54 Effect.tryPromise({
55 try: async () => {
56 await bucket.put(objectName(namespace, key), value);
57 },
58 catch: storeError("put"),
59 }),
60 delete: (namespace, key) =>
61 Effect.tryPromise({
62 try: () => bucket.delete(objectName(namespace, key)),
63 catch: storeError("delete"),
64 }),
65 has: (namespace, key) =>
66 Effect.tryPromise({
67 try: async () => (await bucket.head(objectName(namespace, key))) != null,
68 catch: storeError("has"),
69 }),
70});

Callers 3

blob-store.test.tsFile · 0.90
cloudDbProviderLayerFunction · 0.90
createD1ExecutorDbFunction · 0.90

Calls 7

objectNameFunction · 0.85
storeErrorFunction · 0.85
setMethod · 0.80
getMethod · 0.65
textMethod · 0.65
putMethod · 0.65
deleteMethod · 0.65

Tested by

no test coverage detected