| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as Layer from "effect/Layer"; |
| 3 | import { makeLocalDnsBinding } from "./DnsLocal.ts"; |
| 4 | import { ReadWriteDns } from "./ReadWriteDns.ts"; |
| 5 | import { dnsReadWriteClient } from "./ReadWriteDnsHttp.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Local implementation of the {@link ReadWriteDns} binding — performs the full |
| 9 | * Cloudflare DNS record CRUD surface over the HTTP API using the **current |
| 10 | * credentials** instead of a scoped API token ({@link ReadWriteDnsHttp}). DNS |
| 11 | * is a zone-management capability with no native Worker binding. |
| 12 | * |
| 13 | * Provide it on an {@link Action} (or any deploy-time Effect) so you can manage |
| 14 | * a zone's DNS records with the same read + write client you'd use inside a |
| 15 | * Worker: |
| 16 | * |
| 17 | * @example Seeding and reading records from an Action |
| 18 | * ```typescript |
| 19 | * const Seed = Alchemy.Action( |
| 20 | * "Seed", |
| 21 | * Effect.gen(function* () { |
| 22 | * const dns = yield* Cloudflare.DNS.ReadWriteDns(zone); |
| 23 | * return Effect.fn(function* () { |
| 24 | * const created = yield* dns.createDnsRecord({ |
| 25 | * type: "TXT", |
| 26 | * name: "_seed.example.com", |
| 27 | * content: '"hello"', |
| 28 | * ttl: 60, |
| 29 | * }); |
| 30 | * const record = yield* dns.getDnsRecord(created.id); |
| 31 | * yield* dns.deleteDnsRecord(created.id); |
| 32 | * return record; |
| 33 | * }); |
| 34 | * }).pipe(Effect.provide(Cloudflare.DNS.ReadWriteDnsLocal)), |
| 35 | * ); |
| 36 | * ``` |
| 37 | * |
| 38 | * The zone id is resolved at apply time through the ambient |
| 39 | * {@link RuntimeContext} (in an Action, that's the resolve context the engine |
| 40 | * provides around the body), so `ReadWriteDns(zone)` works even though the zone |
| 41 | * may be created/adopted in the same deploy. |
| 42 | */ |
| 43 | export const ReadWriteDnsLocal = Layer.effect( |
| 44 | ReadWriteDns, |
| 45 | Effect.suspend(() => makeLocalDnsBinding({ makeClient: dnsReadWriteClient })), |
| 46 | ); |