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 | /** |
| 2 | * Deno implementation of Effect's `AddressResolver` service. |
| 3 | * |
| 4 | * Domain names are looked up with the `Dns` service, and IPv6 literals with a |
| 5 | * named zone such as `fe80::1%eth0` get their scope ID from |
| 6 | * `Deno.networkInterfaces()`, queried each time to reflect interface changes. |
| 7 | * |
| 8 | * **Gotchas** |
| 9 | * |
| 10 | * Listing network interfaces requires the `--allow-sys` permission; without it, |
| 11 | * resolving a named zone fails with a `NetAddress.NetAddressError`. |
| 12 | * |
| 13 | * @stability experimental |
| 14 | * @since 4.0.0 |
| 15 | */ |
| 16 | import * as Effect from "effect/Effect" |
| 17 | import type * as Layer from "effect/Layer" |
| 18 | import * as AddressResolver from "effect/net/AddressResolver" |
| 19 | import type * as Dns from "effect/net/Dns" |
| 20 | import * as NetAddress from "effect/net/NetAddress" |
| 21 | |
| 22 | const scopeId: AddressResolver.ScopeIdLookup = (name) => |
| 23 | Effect.try({ |
| 24 | try: () => NetAddress.scopeIdFromInterface(Deno.networkInterfaces().filter((info) => info.name === name)), |
| 25 | catch: (cause) => new NetAddress.NetAddressError({ input: name, message: "cannot list network interfaces", cause }) |
| 26 | }) |
| 27 | |
| 28 | /** |
| 29 | * Layer that provides the Deno `AddressResolver` service using the `Dns` |
| 30 | * service. |
| 31 | * |
| 32 | * @stability experimental |
| 33 | * @category layers |
| 34 | * @since 4.0.0 |
| 35 | */ |
| 36 | export const layer: Layer.Layer<AddressResolver.AddressResolver, never, Dns.Dns> = AddressResolver.layer({ scopeId }) |