The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 07:15 UTC
| 1 | import type { PublicOrigin } from "@alchemy.run/cloudflare/Hyperdrive"; |
| 2 | import * as hyperdrive from "@distilled.cloud/cloudflare/hyperdrive"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Redacted from "effect/Redacted"; |
| 5 | import * as Schedule from "effect/Schedule"; |
| 6 | |
| 7 | /** |
| 8 | * Create a Hyperdrive configuration OUTSIDE the stack — standing in for one |
| 9 | * made in the dashboard or by another system — and delete it when the |
| 10 | * scope closes, so a failing test never leaks it. |
| 11 | */ |
| 12 | export const outOfBandConfig = (accountId: string, name: string, origin: PublicOrigin) => |
| 13 | Effect.acquireRelease( |
| 14 | hyperdrive |
| 15 | .createConfig({ |
| 16 | accountId, |
| 17 | name, |
| 18 | origin: { |
| 19 | scheme: origin.scheme, |
| 20 | host: origin.host, |
| 21 | port: origin.port ?? 5432, |
| 22 | database: origin.database, |
| 23 | user: origin.user, |
| 24 | password: Redacted.value(origin.password), |
| 25 | }, |
| 26 | }) |
| 27 | .pipe( |
| 28 | // A just-provisioned Neon database is briefly unreachable. |
| 29 | Effect.retry({ |
| 30 | while: (error) => error._tag === "HyperdriveOriginUnavailable", |
| 31 | schedule: Schedule.spaced("3 seconds"), |
| 32 | times: 20, |
| 33 | }), |
| 34 | ), |
| 35 | (config) => |
| 36 | hyperdrive.deleteConfig({ accountId, hyperdriveId: config.id }).pipe( |
| 37 | Effect.catchTag("HyperdriveConfigNotFound", () => Effect.void), |
| 38 | Effect.orDie, |
| 39 | ), |
| 40 | ); |