| 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) => |
| 7 | Layer.succeed(Endpoint.Endpoint, Effect.succeed(endpoint)); |
| 8 | |
| 9 | /** |
| 10 | * Derive a custom endpoint (if any) from the surrounding |
| 11 | * {@link AWSEnvironment}. If the environment has no `endpoint` set, this |
| 12 | * Layer is empty (the SDK uses its default endpoint resolver). |
| 13 | */ |
| 14 | export const fromEnvironment: Layer.Layer<never, never, AWSEnvironment> = |
| 15 | Layer.effect( |
| 16 | Endpoint.Endpoint, |
| 17 | Effect.gen(function* () { |
| 18 | return Effect.map( |
| 19 | yield* AWSEnvironment, |
| 20 | (env) => env.endpoint ?? undefined!, |
| 21 | ); |
| 22 | }), |
| 23 | ); |
| 24 | |
| 25 | /** |
| 26 | * Explicitly "no custom endpoint" — the SDK falls back to its default |
| 27 | * endpoint resolver. |
| 28 | * |
| 29 | * Use this (never `Layer.empty`) when an AWS call is made from *inside* |
| 30 | * the construction of {@link AWSEnvironment}: leaving `Endpoint` |
| 31 | * unprovided lets the call fall through to {@link fromEnvironment}, |
| 32 | * whose service Effect re-enters the in-flight `AWSEnvironment` cache and |
| 33 | * deadlocks the fiber with no I/O and no timer pending. |
| 34 | */ |
| 35 | export const none = Layer.succeed(Endpoint.Endpoint, Effect.succeed(undefined)); |