t3-code-android-nightly/.repos/alchemy-effect/packages/alchemy/test/Prisma/fixtures/readwrite-compute.ts
Julius Marminge 6f9cea00ae
chore(refs): sync Effect and Alchemy references to 4.0.1 and beta.80 (#16170)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-05 13:22:30 -07:00

48 lines
1.8 KiB
TypeScript

import { Compute } from "@/Prisma/Compute.ts";
import {
ReadWriteBucket,
ReadWriteBucketBinding,
} from "@/Prisma/ReadWriteBucket.ts";
import * as Effect from "effect/Effect";
import { HttpServerRequest } from "effect/http/HttpServerRequest";
import * as HttpServerResponse from "effect/http/HttpServerResponse";
import { TestBucket, TestProject } from "./bucket.ts";
import { readRoutes } from "./read-routes.ts";
import { writeRoutes } from "./write-routes.ts";
/** Read + write access via the native Compute binding (`ReadWriteBucketBinding`). */
export default Compute(
"PrismaReadWriteBucketCompute",
Effect.gen(function* () {
const project = yield* TestProject;
return {
project,
appName: "alchemy-bucket-binding-readwrite",
main: import.meta.filename,
port: 8080,
timeoutSeconds: 240,
destroyOldDeployment: true,
};
}),
Effect.gen(function* () {
const bucket = yield* TestBucket;
const store = yield* ReadWriteBucket(bucket);
// A second bind of the same bucket and access level must resolve to the
// SAME bucket-key logical id (pinned by the identity tests) and reuse
// that resource; registering a conflicting duplicate would fail the
// deploy.
yield* ReadWriteBucket(bucket);
return {
fetch: Effect.gen(function* () {
const request = yield* HttpServerRequest;
const url = new URL(request.url, "http://x");
// The ReadWrite client composes both halves; route to whichever
// matches so we exercise read *and* write through one client.
const handled =
(yield* writeRoutes(store, request, url)) ??
(yield* readRoutes(store, url));
return handled ?? HttpServerResponse.text("Not Found", { status: 404 });
}),
};
}).pipe(Effect.provide(ReadWriteBucketBinding)),
);