The best way to control Claude Code, Codex and more from any computer or phone

main
ts 62 lines 2.12 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 { SearchJob } from "./SearchJob.ts";
5
6 /**
7 * Shared scaffolding for BackupSearch HTTP bindings.
8 *
9 * NOT exported from `index.ts` — every `{Op}Http.ts` in this service is a
10 * thin `Layer.effect(Cap, makeSearchJobScopedHttpBinding({ … }))` over the
11 * builder below. Everything except the operation and the IAM action list is
12 * boilerplate.
13 *
14 * BackupSearch IAM actions live under the `backup-search:` service prefix.
15 */
16
17 /**
18 * Build the impl Effect for a search-job-scoped operation: the runtime
19 * callable injects the bound {@link SearchJob}'s identifier as
20 * `SearchJobIdentifier` and the deploy-time half grants `actions` on the
21 * search job ARN.
22 */
23 export const makeSearchJobScopedHttpBinding = <
24 I extends { SearchJobIdentifier: string },
25 A,
26 E,
27 R,
28 >(options: {
29 /** Fully-qualified binding tag, e.g. `AWS.BackupSearch.ListSearchJobResults`. */
30 tag: string;
31 /** The distilled operation; `SearchJobIdentifier` is injected from the resource. */
32 operation: Effect.Effect<(input: I) => Effect.Effect<A, E>, never, R>;
33 /** IAM actions granted on the search job ARN. */
34 actions: readonly string[];
35 }) =>
36 Effect.gen(function* () {
37 const bind = yield* AWSBindings.Bind;
38 const op = yield* AWSBindings.withCredentials(options.operation);
39
40 return Effect.fn(function* (searchJob: SearchJob) {
41 const SearchJobIdentifier = yield* searchJob.searchJobIdentifier;
42 if (!globalThis.__ALCHEMY_RUNTIME__) {
43 yield* bind`${options.tag}(${searchJob})`({
44 policyStatements: [
45 {
46 Effect: "Allow",
47 Action: [...options.actions],
48 Resource: [Output.interpolate`${searchJob.searchJobArn}`],
49 },
50 ],
51 });
52 }
53 return Effect.fn(`${options.tag}(${searchJob.LogicalId})`)(function* (
54 request?: Omit<I, "SearchJobIdentifier">,
55 ) {
56 return yield* op({
57 ...request,
58 SearchJobIdentifier: yield* SearchJobIdentifier,
59 } as I);
60 });
61 });
62 });