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 { Domain } from "./Domain.ts"; |
| 4 | |
| 5 | /** |
| 6 | * Shared scaffolding for SimpleDB per-operation bindings. |
| 7 | * |
| 8 | * INTERNAL — deliberately not exported from the service `index.ts`. |
| 9 | * |
| 10 | * Every SimpleDB data-plane operation follows the same shape: it targets a |
| 11 | * single {@link Domain}, requires the IAM action `sdb:{Operation}` on |
| 12 | * `arn:aws:sdb:{region}:{account}:domain/{domainName}`, and (except for |
| 13 | * `Select`) injects the domain's physical `DomainName` into the request. |
| 14 | * `makeSimpleDbBinding` encodes that once so each `{Op}Http.ts` is a thin |
| 15 | * call into it; `registerSimpleDbBinding` is the deploy-time IAM half on its |
| 16 | * own for operations (like `Select`) that need a custom runtime client. |
| 17 | */ |
| 18 | |
| 19 | /** |
| 20 | * Deploy-time half of a SimpleDB binding: grants `sdb:{operation}` on the |
| 21 | * domain's ARN to the host Function. No-op at runtime. |
| 22 | */ |
| 23 | export const RegisterSimpleDbBinding = Effect.gen(function* () { |
| 24 | const bind = yield* AWSBindings.Bind; |
| 25 | return Effect.fn(function* (operation: string, domain: Domain) { |
| 26 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 27 | yield* bind`AWS.SimpleDB.${operation}(${domain})`({ |
| 28 | policyStatements: [ |
| 29 | { |
| 30 | Effect: "Allow", |
| 31 | Action: [`sdb:${operation}`], |
| 32 | Resource: [domain.domainArn], |
| 33 | }, |
| 34 | ], |
| 35 | }); |
| 36 | } |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | /** |
| 41 | * Builds the full binding implementation for a SimpleDB operation whose |
| 42 | * request carries a `DomainName` member: registers the IAM grant and returns |
| 43 | * a runtime client that closes over the domain's physical name and injects |
| 44 | * it into every request. |
| 45 | */ |
| 46 | export const makeSimpleDbBinding = <Req extends { DomainName: string }, A, E, R>(options: { |
| 47 | readonly operation: string; |
| 48 | readonly method: Effect.Effect<(input: Req) => Effect.Effect<A, E>, never, R>; |
| 49 | }) => |
| 50 | Effect.gen(function* () { |
| 51 | const registerSimpleDbBinding = yield* RegisterSimpleDbBinding; |
| 52 | const call = yield* AWSBindings.withCredentials(options.method); |
| 53 | return Effect.fn(function* (domain: Domain) { |
| 54 | const domainName = yield* domain.domainName; |
| 55 | yield* registerSimpleDbBinding(options.operation, domain); |
| 56 | return Effect.fn(`AWS.SimpleDB.${options.operation}(${domain.LogicalId})`)(function* ( |
| 57 | request?: Omit<Req, "DomainName">, |
| 58 | ) { |
| 59 | const name = yield* domainName; |
| 60 | return yield* call({ ...request, DomainName: name } as Req); |
| 61 | }); |
| 62 | }); |
| 63 | }); |