| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makeLocalDnsBinding } from "./DnsLocal.ts"; |
| 4 | import { ReadDns } from "./ReadDns.ts"; |
| 5 | import { dnsReadClient } from "./ReadDnsHttp.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Local implementation of the {@link ReadDns} binding — reads Cloudflare DNS |
| 9 | * records over the HTTP API using the **current credentials** instead of a |
| 10 | * scoped API token ({@link ReadDnsHttp}). DNS is a zone-management capability |
| 11 | * with no native Worker binding. |
| 12 | * |
| 13 | * Provide it on an {@link Action} (or any deploy-time Effect) so you can read a |
| 14 | * zone's DNS records with the same `getDnsRecord`/`listDnsRecords` client you'd |
| 15 | * use inside a Worker: |
| 16 | * |
| 17 | * @example Reading records from an Action |
| 18 | * ```typescript |
| 19 | * const Check = Alchemy.Action( |
| 20 | * "Check", |
| 21 | * Effect.gen(function* () { |
| 22 | * const dns = yield* Cloudflare.DNS.ReadDns(zone); |
| 23 | * return Effect.fn(function* () { |
| 24 | * return yield* dns.listDnsRecords({ type: "TXT" }); |
| 25 | * }); |
| 26 | * }).pipe(Effect.provide(Cloudflare.DNS.ReadDnsLocal)), |
| 27 | * ); |
| 28 | * ``` |
| 29 | * |
| 30 | * The zone id is resolved at apply time through the ambient |
| 31 | * {@link RuntimeContext} (in an Action, that's the resolve context the engine |
| 32 | * provides around the body), so `ReadDns(zone)` works even though the zone may |
| 33 | * be created/adopted in the same deploy. |
| 34 | */ |
| 35 | export const ReadDnsLocal = Layer.effect( |
| 36 | ReadDns, |
| 37 | Effect.suspend(() => makeLocalDnsBinding({ makeClient: dnsReadClient })), |
| 38 | ); |