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 * as Region from "@distilled.cloud/aws/Region"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { AWSEnvironment } from "./Environment.ts"; |
| 5 | |
| 6 | export { AWS_REGION, type RegionID } from "./Environment.ts"; |
| 7 | export { Region } from "@distilled.cloud/aws/Region"; |
| 8 | |
| 9 | declare module "@distilled.cloud/aws/Region" { |
| 10 | interface Region { |
| 11 | readonly kind: "Environment"; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | export const of = (region: string) => Layer.succeed(Region.Region, Effect.succeed(region)); |
| 16 | |
| 17 | export const fromEnvOrElse = (region: string) => |
| 18 | Layer.succeed(Region.Region, Effect.succeed(process.env.AWS_REGION ?? region)); |
| 19 | |
| 20 | // Deferred with `Effect.suspend` so it does not dereference `AWSEnvironment` |
| 21 | // during module evaluation. `Region.ts` and `Environment.ts` are part of an |
| 22 | // import cycle (AuthProvider → Region → Environment → AuthProvider); touching |
| 23 | // `AWSEnvironment` eagerly at top level hits a temporal-dead-zone error when |
| 24 | // this module is evaluated mid-cycle. |
| 25 | export const CurrentRegion = Effect.suspend(() => |
| 26 | AWSEnvironment.use((env) => Effect.map(env, ({ region }) => region)), |
| 27 | ); |
| 28 | |
| 29 | /** |
| 30 | * Derive the AWS region from the surrounding {@link AWSEnvironment}. |
| 31 | */ |
| 32 | export const fromEnvironment = Layer.effect( |
| 33 | Region.Region, |
| 34 | Effect.gen(function* () { |
| 35 | const env = yield* AWSEnvironment; |
| 36 | return Effect.map(env, (env) => env.region); |
| 37 | }), |
| 38 | ); |