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

main
ts 53 lines 1.89 KB
Raw
1 import path from "node:path";
2 import { fileURLToPath } from "node:url";
3 import * as Cloudflare from "@alchemy.run/cloudflare";
4 import * as Planetscale from "@alchemy.run/planetscale";
5 import * as Effect from "effect/Effect";
6
7 /**
8 * Shared PlanetScale + Cloudflare wiring used by the MySQL Hyperdrive
9 * fixture worker. A long-lived staging MySQL database (named
10 * deterministically so reruns adopt the same resource) owns a feature
11 * branch (which applies the fixture migrations) + password. The Hyperdrive
12 * config points at the password's origin.
13 */
14 // This module is bundled into the worker (hyperdrive-worker.ts imports it),
15 // so this also evaluates at worker startup, where the bundler leaves
16 // `import.meta.url` undefined. The fallback is never read there — resource
17 // props are only consumed at deploy time.
18 const migrationsDir = import.meta.url
19 ? path.join(fileURLToPath(import.meta.url), "..", "migrations")
20 : ".";
21
22 export const PlanetscaleDb = Effect.gen(function* () {
23 const database = yield* Planetscale.MySQLDatabase("MySQLHyperdriveTestDb", {
24 name: "alchemy-mysql-hyperdrive",
25 region: { slug: "us-east" },
26 clusterSize: "PS_10",
27 });
28
29 const branch = yield* Planetscale.MySQLBranch("MySQLHyperdriveTestBranch", {
30 database,
31 parentBranch: "main",
32 isProduction: false,
33 migrations: migrationsDir,
34 });
35
36 const password = yield* Planetscale.MySQLPassword("MySQLHyperdriveTestPassword", {
37 database,
38 branch,
39 role: "admin",
40 });
41
42 return { database, branch, password };
43 });
44
45 export const Hyperdrive = Effect.gen(function* () {
46 const { password } = yield* PlanetscaleDb;
47 return yield* Cloudflare.Hyperdrive.Connection("MySQLHyperdriveTestEdge", {
48 origin: password.origin,
49 // The test asserts read-your-writes across separate HTTP requests;
50 // Hyperdrive's query cache (60s default) would serve stale SELECTs.
51 caching: { disabled: true },
52 });
53 });