@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

main
ts 90 lines 3.13 KB
Raw
1 import * as Output from "alchemy/Output";
2 import * as Effect from "effect/Effect";
3 import * as AWSBindings from "../AWSBindings.ts";
4 import type { Cluster } from "./Cluster.ts";
5
6 /**
7 * Shared scaffolding for AWS DAX 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 builders
11 * below. Everything except the operation and the IAM action list is
12 * boilerplate.
13 */
14
15 /**
16 * Build the impl Effect for an account-level operation (cluster monitoring,
17 * event history). The deploy-time half grants `actions` on `*` — these
18 * read-only monitoring actions span every cluster/parameter-group in the
19 * account and the names they filter on are runtime data.
20 */
21 export const makeDaxAccountHttpBinding = <I, A, E, R>(options: {
22 /** Fully-qualified binding tag, e.g. `AWS.DAX.DescribeEvents`. */
23 tag: string;
24 /** The distilled operation, invoked with the caller's request as-is. */
25 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
26 /** IAM actions granted on `*`. */
27 actions: readonly string[];
28 }) =>
29 Effect.gen(function* () {
30 const bind = yield* AWSBindings.Bind;
31 const op = yield* AWSBindings.withCredentials(options.operation);
32
33 return Effect.fn(function* () {
34 if (!globalThis.__ALCHEMY_RUNTIME__) {
35 yield* bind`${options.tag}()`({
36 policyStatements: [
37 {
38 Effect: "Allow",
39 Action: [...options.actions],
40 Resource: ["*"],
41 },
42 ],
43 });
44 }
45 return Effect.fn(options.tag)(function* (request?: I) {
46 return yield* op((request ?? {}) as I);
47 });
48 });
49 });
50
51 /**
52 * Build the impl Effect for a cluster-scoped operation: the runtime callable
53 * injects the bound {@link Cluster}'s name as `ClusterName` and the
54 * deploy-time half grants `actions` on the cluster ARN.
55 */
56 export const makeDaxClusterHttpBinding = <I extends { ClusterName: string }, A, E, R>(options: {
57 /** Fully-qualified binding tag, e.g. `AWS.DAX.RebootNode`. */
58 tag: string;
59 /** The distilled operation; `ClusterName` is injected from the cluster. */
60 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
61 /** IAM actions granted on the cluster ARN. */
62 actions: readonly string[];
63 }) =>
64 Effect.gen(function* () {
65 const bind = yield* AWSBindings.Bind;
66 const op = yield* AWSBindings.withCredentials(options.operation);
67
68 return Effect.fn(function* (cluster: Cluster) {
69 const ClusterName = yield* cluster.clusterName;
70 if (!globalThis.__ALCHEMY_RUNTIME__) {
71 yield* bind`${options.tag}(${cluster})`({
72 policyStatements: [
73 {
74 Effect: "Allow",
75 Action: [...options.actions],
76 Resource: [Output.interpolate`${cluster.clusterArn}`],
77 },
78 ],
79 });
80 }
81 return Effect.fn(`${options.tag}(${cluster.LogicalId})`)(function* (
82 request: Omit<I, "ClusterName">,
83 ) {
84 return yield* op({
85 ...request,
86 ClusterName: yield* ClusterName,
87 } as I);
88 });
89 });
90 });