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 | import * as Output from "alchemy/Output"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as AWSBindings from "../AWSBindings.ts"; |
| 4 | import type { KxEnvironment } from "./KxEnvironment.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared scaffolding for Amazon FinSpace Managed kdb HTTP bindings. |
| 8 | * |
| 9 | * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a |
| 10 | * thin `Layer.effect(Cap, makeFinSpaceKxHttpBinding({ … }))` over the builder |
| 11 | * below. Everything except the operation and the IAM action list is |
| 12 | * boilerplate. |
| 13 | */ |
| 14 | |
| 15 | /** |
| 16 | * Build the impl Effect for a kdb operation scoped to a {@link KxEnvironment}. |
| 17 | * |
| 18 | * Every Managed kdb data-plane operation is addressed by `environmentId`, |
| 19 | * and kdb sub-resources (databases, clusters, dataviews, users, changesets) |
| 20 | * live under the environment's ARN |
| 21 | * (`arn:…:kxEnvironment/{envId}/kxDatabase/{db}`, …). The deploy-time half |
| 22 | * therefore grants `actions` on the bound environment's ARN plus its `/*` |
| 23 | * sub-resource wildcard; the runtime callable injects the environment's id |
| 24 | * into every request. |
| 25 | */ |
| 26 | export const makeFinSpaceKxHttpBinding = <I extends { environmentId: string }, A, E, R>(options: { |
| 27 | /** Fully-qualified binding tag, e.g. `AWS.FinSpace.GetKxConnectionString`. */ |
| 28 | tag: string; |
| 29 | /** The distilled operation. */ |
| 30 | operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>; |
| 31 | /** IAM actions granted on the environment ARN and its sub-resources. */ |
| 32 | actions: readonly string[]; |
| 33 | }) => |
| 34 | Effect.gen(function* () { |
| 35 | const bind = yield* AWSBindings.Bind; |
| 36 | const op = yield* AWSBindings.withCredentials(options.operation); |
| 37 | |
| 38 | return Effect.fn(function* <K extends KxEnvironment>(environment: K) { |
| 39 | // Outputs yield a DEFERRED effect — resolve again per invocation below. |
| 40 | const EnvironmentId = yield* environment.environmentId; |
| 41 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 42 | yield* bind`${options.tag}(${environment})`({ |
| 43 | policyStatements: [ |
| 44 | { |
| 45 | Effect: "Allow", |
| 46 | Action: [...options.actions], |
| 47 | Resource: [ |
| 48 | Output.interpolate`${environment.environmentArn}`, |
| 49 | Output.interpolate`${environment.environmentArn}/*`, |
| 50 | ], |
| 51 | }, |
| 52 | ], |
| 53 | }); |
| 54 | } |
| 55 | return Effect.fn(`${options.tag}(${environment.LogicalId})`)(function* ( |
| 56 | request?: Omit<I, "environmentId">, |
| 57 | ) { |
| 58 | return yield* op({ |
| 59 | ...request, |
| 60 | environmentId: yield* EnvironmentId, |
| 61 | } as I); |
| 62 | }); |
| 63 | }); |
| 64 | }); |