@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 130 lines 4.95 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 { Job } from "./Job.ts";
5 import type { Project } from "./Project.ts";
6 import type { Recipe } from "./Recipe.ts";
7
8 /**
9 * Shared scaffolding for AWS Glue DataBrew HTTP bindings.
10 *
11 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
12 * thin `Layer.effect(Cap, make…HttpBinding({ … }))` over one of the builders
13 * below. Every DataBrew data-plane operation addresses its resource by a
14 * `Name` path parameter and authorizes against that resource's ARN, so each
15 * builder injects the bound resource's name and grants `actions` on its ARN;
16 * everything except the operation and the IAM action is boilerplate.
17 */
18
19 /**
20 * Build the impl Effect for a job-anchored operation: the runtime callable
21 * injects the bound {@link Job}'s name as `Name` and the deploy-time half
22 * grants `actions` on the job ARN.
23 */
24 export const makeDataBrewJobHttpBinding = <I extends { Name?: string }, A, E, R>(options: {
25 /** Fully-qualified binding tag, e.g. `AWS.DataBrew.StartJobRun`. */
26 tag: string;
27 /** The distilled operation; `Name` is injected from the job. */
28 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
29 /** IAM actions granted on the job ARN. */
30 actions: readonly string[];
31 }) =>
32 Effect.gen(function* () {
33 const bind = yield* AWSBindings.Bind;
34 const op = yield* AWSBindings.withCredentials(options.operation);
35
36 return Effect.fn(function* <J extends Job>(job: J) {
37 // Outputs yield a DEFERRED effect — resolve again per invocation below.
38 const JobName = yield* job.jobName;
39 if (!globalThis.__ALCHEMY_RUNTIME__) {
40 yield* bind`${options.tag}(${job})`({
41 policyStatements: [
42 {
43 Effect: "Allow",
44 Action: [...options.actions],
45 Resource: [Output.interpolate`${job.jobArn}`],
46 },
47 ],
48 });
49 }
50 return Effect.fn(`${options.tag}(${job.LogicalId})`)(function* (request?: Omit<I, "Name">) {
51 return yield* op({ ...request, Name: yield* JobName } as I);
52 });
53 });
54 });
55
56 /**
57 * Build the impl Effect for a project-anchored operation: the runtime
58 * callable injects the bound {@link Project}'s name as `Name` and the
59 * deploy-time half grants `actions` on the project ARN.
60 */
61 export const makeDataBrewProjectHttpBinding = <I extends { Name?: string }, A, E, R>(options: {
62 /** Fully-qualified binding tag, e.g. `AWS.DataBrew.StartProjectSession`. */
63 tag: string;
64 /** The distilled operation; `Name` is injected from the project. */
65 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
66 /** IAM actions granted on the project ARN. */
67 actions: readonly string[];
68 }) =>
69 Effect.gen(function* () {
70 const bind = yield* AWSBindings.Bind;
71 const op = yield* AWSBindings.withCredentials(options.operation);
72
73 return Effect.fn(function* <P extends Project>(project: P) {
74 const ProjectName = yield* project.projectName;
75 if (!globalThis.__ALCHEMY_RUNTIME__) {
76 yield* bind`${options.tag}(${project})`({
77 policyStatements: [
78 {
79 Effect: "Allow",
80 Action: [...options.actions],
81 Resource: [Output.interpolate`${project.projectArn}`],
82 },
83 ],
84 });
85 }
86 return Effect.fn(`${options.tag}(${project.LogicalId})`)(function* (
87 request?: Omit<I, "Name">,
88 ) {
89 return yield* op({ ...request, Name: yield* ProjectName } as I);
90 });
91 });
92 });
93
94 /**
95 * Build the impl Effect for a recipe-anchored operation: the runtime
96 * callable injects the bound {@link Recipe}'s name as `Name` and the
97 * deploy-time half grants `actions` on the recipe ARN.
98 */
99 export const makeDataBrewRecipeHttpBinding = <I extends { Name?: string }, A, E, R>(options: {
100 /** Fully-qualified binding tag, e.g. `AWS.DataBrew.PublishRecipe`. */
101 tag: string;
102 /** The distilled operation; `Name` is injected from the recipe. */
103 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
104 /** IAM actions granted on the recipe ARN. */
105 actions: readonly string[];
106 }) =>
107 Effect.gen(function* () {
108 const bind = yield* AWSBindings.Bind;
109 const op = yield* AWSBindings.withCredentials(options.operation);
110
111 return Effect.fn(function* <Rec extends Recipe>(recipe: Rec) {
112 const RecipeName = yield* recipe.recipeName;
113 if (!globalThis.__ALCHEMY_RUNTIME__) {
114 yield* bind`${options.tag}(${recipe})`({
115 policyStatements: [
116 {
117 Effect: "Allow",
118 Action: [...options.actions],
119 Resource: [Output.interpolate`${recipe.recipeArn}`],
120 },
121 ],
122 });
123 }
124 return Effect.fn(`${options.tag}(${recipe.LogicalId})`)(function* (
125 request?: Omit<I, "Name">,
126 ) {
127 return yield* op({ ...request, Name: yield* RecipeName } as I);
128 });
129 });
130 });