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

main
ts 39 lines 1.18 KB
Raw
1 import * as Cloudflare from "@alchemy.run/cloudflare";
2 import * as Alchemy from "alchemy";
3 import * as Effect from "effect/Effect";
4 import * as pathe from "pathe";
5 import { TestDatabase } from "./database.ts";
6 import D1EffectWorker from "./effect-worker.ts";
7
8 /**
9 * Async (non-Effect) Worker bound to the shared {@link TestDatabase} via its
10 * `env`. `InferEnv` maps the `Cloudflare.D1.Database` marker to the native
11 * `cf.D1Database`, so `env.DB` is the runtime binding inside `async-worker.ts`.
12 */
13 export const AsyncWorker = Cloudflare.Worker("D1AsyncWorker", {
14 main: pathe.resolve(import.meta.dirname, "async-worker.ts"),
15 env: {
16 DB: TestDatabase,
17 },
18 });
19
20 export type AsyncWorkerEnv = Cloudflare.InferEnv<typeof AsyncWorker>;
21
22 /**
23 * One stack deploying both invocation styles against ONE shared D1 database.
24 */
25 export default Alchemy.Stack(
26 "D1BindingStack",
27 {
28 providers: Cloudflare.providers(),
29 state: Cloudflare.state(),
30 },
31 Effect.gen(function* () {
32 const effectWorker = yield* D1EffectWorker;
33 const asyncWorker = yield* AsyncWorker;
34 return {
35 effectWorkerUrl: effectWorker.url.as<string>(),
36 asyncWorkerUrl: asyncWorker.url.as<string>(),
37 };
38 }),
39 );