The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Effect from "effect/Effect"; |
| 2 | import * as AWSBindings from "../AWSBindings.ts"; |
| 3 | import type { ResolverEndpoint } from "./ResolverEndpoint.ts"; |
| 4 | import type { ResolverRule } from "./ResolverRule.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared scaffolding for AWS Route 53 Resolver HTTP bindings. |
| 8 | * |
| 9 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 10 | * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the two |
| 11 | * builders below. Everything except the operation and the IAM action is |
| 12 | * boilerplate: |
| 13 | * |
| 14 | * - {@link makeRoute53ResolverEndpointHttpBinding} — operations scoped to one |
| 15 | * bound {@link ResolverEndpoint}. The runtime callable injects the |
| 16 | * endpoint's ID as the request's `ResolverEndpointId`; the deploy-time half |
| 17 | * grants `actions` on the endpoint ARN. |
| 18 | * - {@link makeRoute53ResolverRuleHttpBinding} — operations scoped to one |
| 19 | * bound {@link ResolverRule}; injects `ResolverRuleId` and grants `actions` |
| 20 | * on the rule ARN. |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * Build the impl Effect for an operation scoped to a single bound |
| 25 | * {@link ResolverEndpoint}. The runtime callable injects the endpoint's ID as |
| 26 | * the request's `ResolverEndpointId`; the deploy-time half grants `actions` |
| 27 | * on the endpoint ARN. |
| 28 | */ |
| 29 | export const makeRoute53ResolverEndpointHttpBinding = < |
| 30 | I extends { ResolverEndpointId?: string }, |
| 31 | A, |
| 32 | E, |
| 33 | R, |
| 34 | >(options: { |
| 35 | /** Fully-qualified binding tag, e.g. `AWS.Route53Resolver.GetResolverEndpoint`. */ |
| 36 | tag: string; |
| 37 | /** The distilled operation; `ResolverEndpointId` is injected from the resource. */ |
| 38 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 39 | /** IAM actions granted on the resolver endpoint ARN. */ |
| 40 | actions: readonly string[]; |
| 41 | }) => |
| 42 | Effect.gen(function* () { |
| 43 | const bind = yield* AWSBindings.Bind; |
| 44 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 45 | |
| 46 | return Effect.fn(function* (endpoint: ResolverEndpoint) { |
| 47 | const ResolverEndpointId = yield* endpoint.resolverEndpointId; |
| 48 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 49 | yield* bind`${options.tag}(${endpoint})`({ |
| 50 | policyStatements: [ |
| 51 | { |
| 52 | Effect: "Allow", |
| 53 | Action: [...options.actions], |
| 54 | Resource: [endpoint.resolverEndpointArn], |
| 55 | }, |
| 56 | ], |
| 57 | }); |
| 58 | } |
| 59 | return Effect.fn(`${options.tag}(${endpoint.LogicalId})`)(function* ( |
| 60 | request?: Omit<I, "ResolverEndpointId">, |
| 61 | ) { |
| 62 | return yield* op({ |
| 63 | ...request, |
| 64 | ResolverEndpointId: yield* ResolverEndpointId, |
| 65 | } as I); |
| 66 | }); |
| 67 | }); |
| 68 | }); |
| 69 | |
| 70 | /** |
| 71 | * Build the impl Effect for an operation scoped to a single bound |
| 72 | * {@link ResolverRule}. The runtime callable injects the rule's ID as the |
| 73 | * request's `ResolverRuleId`; the deploy-time half grants `actions` on the |
| 74 | * rule ARN. |
| 75 | */ |
| 76 | export const makeRoute53ResolverRuleHttpBinding = < |
| 77 | I extends { ResolverRuleId?: string }, |
| 78 | A, |
| 79 | E, |
| 80 | R, |
| 81 | >(options: { |
| 82 | /** Fully-qualified binding tag, e.g. `AWS.Route53Resolver.GetResolverRule`. */ |
| 83 | tag: string; |
| 84 | /** The distilled operation; `ResolverRuleId` is injected from the resource. */ |
| 85 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 86 | /** IAM actions granted on the resolver rule ARN. */ |
| 87 | actions: readonly string[]; |
| 88 | }) => |
| 89 | Effect.gen(function* () { |
| 90 | const bind = yield* AWSBindings.Bind; |
| 91 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 92 | |
| 93 | return Effect.fn(function* (rule: ResolverRule) { |
| 94 | const ResolverRuleId = yield* rule.resolverRuleId; |
| 95 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 96 | yield* bind`${options.tag}(${rule})`({ |
| 97 | policyStatements: [ |
| 98 | { |
| 99 | Effect: "Allow", |
| 100 | Action: [...options.actions], |
| 101 | Resource: [rule.resolverRuleArn], |
| 102 | }, |
| 103 | ], |
| 104 | }); |
| 105 | } |
| 106 | return Effect.fn(`${options.tag}(${rule.LogicalId})`)(function* ( |
| 107 | request?: Omit<I, "ResolverRuleId">, |
| 108 | ) { |
| 109 | return yield* op({ |
| 110 | ...request, |
| 111 | ResolverRuleId: yield* ResolverRuleId, |
| 112 | } as I); |
| 113 | }); |
| 114 | }); |
| 115 | }); |