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, 04:45 UTC
| 1 | import { describeDataPlane } from "alchemy/Provider"; |
| 2 | import type { ProviderMode } from "alchemy/ProviderMode"; |
| 3 | import * as Data from "effect/Data"; |
| 4 | import * as Effect from "effect/Effect"; |
| 5 | |
| 6 | /** |
| 7 | * A token-scoped `*Http` binding bound to a resource that `alchemy dev` |
| 8 | * emulates locally. The HTTP client calls the real Cloudflare API with a |
| 9 | * real token, which can't reach the local simulator's `dev:` resources. |
| 10 | */ |
| 11 | export class HttpBindingUnsupportedInDev extends Data.TaggedError( |
| 12 | "Cloudflare.HttpBindingUnsupportedInDev", |
| 13 | )<{ |
| 14 | message: string; |
| 15 | logicalId: string; |
| 16 | }> {} |
| 17 | |
| 18 | /** |
| 19 | * Fail an `*Http` binding at deploy time when its resource is emulated |
| 20 | * locally. Resources opted out with `Alchemy.remote()` and types with no |
| 21 | * local provider run live, so their HTTP bindings keep working in dev. |
| 22 | */ |
| 23 | export const requireLiveResource = Effect.fn(function* (resource: { |
| 24 | readonly Type: string; |
| 25 | readonly LogicalId: string; |
| 26 | readonly Mode?: ProviderMode | undefined; |
| 27 | }) { |
| 28 | const plane = yield* describeDataPlane(resource); |
| 29 | if (plane.kind === "local" || plane.kind === "undeclared") { |
| 30 | return yield* Effect.die( |
| 31 | new HttpBindingUnsupportedInDev({ |
| 32 | logicalId: resource.LogicalId, |
| 33 | message: |
| 34 | `${resource.Type} ${resource.LogicalId} is emulated locally, and Cloudflare HTTP bindings ` + |
| 35 | "(`*Http`) are not supported against local resources in `alchemy dev`. Use the native " + |
| 36 | "binding (`*Binding`) on a Worker, or opt the resource out of local emulation with " + |
| 37 | "`Alchemy.remote()`.", |
| 38 | }), |
| 39 | ); |
| 40 | } |
| 41 | }); |