The best way to control Claude Code, Codex and more from any computer or phone

main
ts 44 lines 1.81 KB
Raw
1 import { Compute } from "@alchemy.run/prisma/Compute";
2 import { ReadWriteBucket, ReadWriteBucketBinding } from "@alchemy.run/prisma/ReadWriteBucket";
3 import * as Effect from "effect/Effect";
4 import { HttpServerRequest } from "effect/http/HttpServerRequest";
5 import * as HttpServerResponse from "effect/http/HttpServerResponse";
6 import { TestBucket, TestProject } from "./bucket.ts";
7 import { readRoutes } from "./read-routes.ts";
8 import { writeRoutes } from "./write-routes.ts";
9
10 /** Read + write access via the native Compute binding (`ReadWriteBucketBinding`). */
11 export default Compute(
12 "PrismaReadWriteBucketCompute",
13 Effect.gen(function* () {
14 const project = yield* TestProject;
15 return {
16 project,
17 appName: "alchemy-bucket-binding-readwrite",
18 main: import.meta.filename,
19 port: 8080,
20 timeoutSeconds: 240,
21 destroyOldDeployment: true,
22 };
23 }),
24 Effect.gen(function* () {
25 const bucket = yield* TestBucket;
26 const store = yield* ReadWriteBucket(bucket);
27 // A second bind of the same bucket and access level must resolve to the
28 // SAME bucket-key logical id (pinned by the identity tests) and reuse
29 // that resource; registering a conflicting duplicate would fail the
30 // deploy.
31 yield* ReadWriteBucket(bucket);
32 return {
33 fetch: Effect.gen(function* () {
34 const request = yield* HttpServerRequest;
35 const url = new URL(request.url, "http://x");
36 // The ReadWrite client composes both halves; route to whichever
37 // matches so we exercise read *and* write through one client.
38 const handled =
39 (yield* writeRoutes(store, request, url)) ?? (yield* readRoutes(store, url));
40 return handled ?? HttpServerResponse.text("Not Found", { status: 404 });
41 }),
42 };
43 }).pipe(Effect.provide(ReadWriteBucketBinding)),
44 );