Skip to content

Commit 212e7af

Browse files
authored
refactor(git)!: BlobStoreR2 requires ReadWriteBucket instead of providing the binding (#2102)
1 parent 612459d commit 212e7af

6 files changed

Lines changed: 24 additions & 9 deletions

File tree

‎examples/cloudflare-git-service/src/api/host.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as Effect from "effect/Effect";
99
*/
1010
import * as HttpRouter from "effect/http/HttpRouter";
1111
import { HttpServerRequest } from "effect/http/HttpServerRequest";
12+
import * as Layer from "effect/Layer";
1213
import { Auth, AuthDb } from "./auth.ts";
1314
import { HttpLive } from "./git.ts";
1415

@@ -31,5 +32,7 @@ export default class GitHost extends Cloudflare.Worker<GitHost>()(
3132
}),
3233
),
3334
};
34-
}).pipe(Effect.provide(CloudflareD1(AuthDb))),
35+
}).pipe(
36+
Effect.provide(Layer.mergeAll(CloudflareD1(AuthDb), Cloudflare.R2.ReadWriteBucketBinding)),
37+
),
3538
) {}

‎packages/alchemy/src/Git/BlobStore.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ import * as Stream from "effect/Stream";
3030
* Layer.provide(Git.BlobStoreR2(MyBucket)),
3131
* // ...
3232
* );
33+
*
34+
* // The Worker picks the ReadWriteBucket implementation.
35+
* export default class GitHost extends Cloudflare.Worker<GitHost>()(
36+
* "GitHost",
37+
* { main: import.meta.url, ...Git.GIT_WORKER_OPTIONS },
38+
* Effect.gen(function* () {
39+
* return { fetch: yield* HttpRouter.toHttpEffect(GitLive) };
40+
* }).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
41+
* ) {}
3342
* ```
3443
*/
3544
import * as Cloudflare from "../Cloudflare/index.ts";
@@ -223,19 +232,22 @@ export const makeBlobStoreR2 = (bucket: ReadWriteBucketClient): BlobStoreShape =
223232

224233
/**
225234
* R2-backed {@link BlobStore}: packs, bundles, oversize objects, and
226-
* push spill live in the given bucket. Registers the bucket binding on
227-
* the host Worker.
235+
* push spill live in the given bucket. Requires the
236+
* `Cloudflare.R2.ReadWriteBucket` capability; provide an implementation
237+
* (`Cloudflare.R2.ReadWriteBucketBinding` or `ReadWriteBucketHttp`) on the
238+
* Worker.
228239
*
229240
* @layer
230241
* @provides Git.BlobStore
231242
*/
232243
export const BlobStoreR2 = (
233244
bucket: Parameters<typeof Cloudflare.R2.ReadWriteBucket>[0],
234-
): Layer.Layer<BlobStore> =>
245+
): Layer.Layer<BlobStore, never, Cloudflare.R2.ReadWriteBucket> =>
235246
Layer.effect(
236247
BlobStore,
237248
Effect.gen(function* () {
238249
const client = yield* Cloudflare.R2.ReadWriteBucket(bucket);
239250
return makeBlobStoreR2(client);
240251
}),
241-
).pipe(Layer.provide(Cloudflare.R2.ReadWriteBucketBinding)) as never;
252+
// `bucket` may be a declaration Effect, which widens the inferred requirement.
253+
) as Layer.Layer<BlobStore, never, Cloudflare.R2.ReadWriteBucket>;

‎packages/alchemy/test/Git/fixtures/lambda-stack.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default class LambdaGitHost extends Cloudflare.Worker<LambdaGitHost>()(
4545
Effect.gen(function* () {
4646
const fetch = yield* HttpRouter.toHttpEffect(GitLive);
4747
return { fetch };
48-
}),
48+
}).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
4949
) {}
5050

5151
export const makeLambdaTestStack = (name: string) =>

‎packages/alchemy/test/Git/fixtures/loader-stack.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class LoaderGitHost extends Cloudflare.Worker<LoaderGitHost>()(
4242
Effect.gen(function* () {
4343
const fetch = yield* HttpRouter.toHttpEffect(GitLive);
4444
return { fetch };
45-
}),
45+
}).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
4646
) {}
4747

4848
export const makeLoaderTestStack = (name: string) =>

‎packages/alchemy/test/Git/fixtures/protected-stack.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export default class ProtectedGitHost extends Cloudflare.Worker<ProtectedGitHost
210210
Effect.gen(function* () {
211211
const fetch = yield* HttpRouter.toHttpEffect(ProtectedGitLive);
212212
return { fetch };
213-
}),
213+
}).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
214214
) {}
215215

216216
/** Deployable stack for the protected-branch test. */

‎packages/alchemy/test/Git/fixtures/stack.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default class TestGitHost extends Cloudflare.Worker<TestGitHost>()(
6767
Effect.gen(function* () {
6868
const fetch = yield* HttpRouter.toHttpEffect(GitLive);
6969
return { fetch };
70-
}),
70+
}).pipe(Effect.provide(Cloudflare.R2.ReadWriteBucketBinding)),
7171
) {}
7272

7373
/**

0 commit comments

Comments
 (0)