The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { Endpoint } from "@distilled.cloud/aws"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Layer from "effect/Layer"; |
| 4 | import { AWSEnvironment } from "./Environment.ts"; |
| 5 | |
| 6 | export const of = (endpoint: string) => Layer.succeed(Endpoint.Endpoint, Effect.succeed(endpoint)); |
| 7 | |
| 8 | /** |
| 9 | * Derive a custom endpoint (if any) from the surrounding |
| 10 | * {@link AWSEnvironment}. If the environment has no `endpoint` set, this |
| 11 | * Layer is empty (the SDK uses its default endpoint resolver). |
| 12 | */ |
| 13 | export const fromEnvironment: Layer.Layer<never, never, AWSEnvironment> = Layer.effect( |
| 14 | Endpoint.Endpoint, |
| 15 | Effect.gen(function* () { |
| 16 | return Effect.map(yield* AWSEnvironment, (env) => env.endpoint ?? undefined!); |
| 17 | }), |
| 18 | ); |
| 19 | |
| 20 | /** |
| 21 | * Explicitly "no custom endpoint" — the SDK falls back to its default |
| 22 | * endpoint resolver. |
| 23 | * |
| 24 | * Use this (never `Layer.empty`) when an AWS call is made from *inside* |
| 25 | * the construction of {@link AWSEnvironment}: leaving `Endpoint` |
| 26 | * unprovided lets the call fall through to {@link fromEnvironment}, |
| 27 | * whose service Effect re-enters the in-flight `AWSEnvironment` cache and |
| 28 | * deadlocks the fiber with no I/O and no timer pending. |
| 29 | */ |
| 30 | export const none = Layer.succeed(Endpoint.Endpoint, Effect.undefined); |