The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as AWSBindings from "../AWSBindings.ts"; |
| 4 | import type { TargetGroup } from "./TargetGroup.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared scaffolding for the VPC Lattice runtime bindings. |
| 8 | * |
| 9 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 10 | * thin `Layer.effect(Cap, makeVpcLatticeTargetGroupHttpBinding({ … }))` over |
| 11 | * the builder below. Everything except the operation, the IAM action list, |
| 12 | * and the injected `targetGroupIdentifier` is boilerplate. |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Build the impl Effect for a target-group-scoped VPC Lattice operation: the |
| 17 | * runtime callable injects the bound {@link TargetGroup}'s ID as |
| 18 | * `targetGroupIdentifier` and the deploy-time half grants `actions` on the |
| 19 | * target group's ARN. |
| 20 | */ |
| 21 | export const makeVpcLatticeTargetGroupHttpBinding = < |
| 22 | I extends { targetGroupIdentifier?: string }, |
| 23 | A, |
| 24 | E, |
| 25 | R, |
| 26 | >(options: { |
| 27 | /** Fully-qualified binding tag, e.g. `AWS.VpcLattice.ListTargets`. */ |
| 28 | tag: string; |
| 29 | /** |
| 30 | * The distilled operation; `targetGroupIdentifier` is injected from the |
| 31 | * target group. |
| 32 | */ |
| 33 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 34 | /** IAM actions granted on the target group ARN. */ |
| 35 | actions: readonly string[]; |
| 36 | }) => |
| 37 | Effect.gen(function* () { |
| 38 | const bind = yield* AWSBindings.Bind; |
| 39 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 40 | |
| 41 | return Effect.fn(function* (targetGroup: TargetGroup) { |
| 42 | const targetGroupIdentifier = yield* targetGroup.targetGroupId; |
| 43 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 44 | yield* bind`${options.tag}(${targetGroup})`({ |
| 45 | policyStatements: [ |
| 46 | { |
| 47 | Effect: "Allow", |
| 48 | Action: [...options.actions], |
| 49 | Resource: [Output.interpolate`${targetGroup.targetGroupArn}`], |
| 50 | }, |
| 51 | ], |
| 52 | }); |
| 53 | } |
| 54 | return Effect.fn(`${options.tag}(${targetGroup.LogicalId})`)(function* ( |
| 55 | request: Omit<I, "targetGroupIdentifier">, |
| 56 | ) { |
| 57 | return yield* op({ |
| 58 | ...request, |
| 59 | targetGroupIdentifier: yield* targetGroupIdentifier, |
| 60 | } as I); |
| 61 | }); |
| 62 | }); |
| 63 | }); |