@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 42 lines 1.37 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts";
4 import type { Cluster } from "./Cluster.ts";
5
6 /**
7 * Shared HTTP scaffolding for Dataproc cluster bindings.
8 * NOT exported from index.ts.
9 */
10 export const makeDataprocClusterHttpBinding = <
11 I extends { projectId?: string; region?: string; clusterName?: string },
12 A,
13 E,
14 >(options: {
15 tag: string;
16 iam: BindingIam;
17 operation: GcpHttpOp<I, A, E>;
18 }) =>
19 Effect.gen(function* () {
20 const bind = yield* GCPBindings.Bind;
21 const run = yield* GCPBindings.withCredentials(options.operation);
22 return Effect.fn(function* (cluster: Cluster) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`${options.tag}(${cluster})`({
25 iam: [grantFor(options.iam, cluster.name)],
26 });
27 }
28 const clusterName = yield* cluster.clusterName;
29 const region = yield* cluster.region;
30 const project = yield* cluster.project;
31 return Effect.fn(`${options.tag}(${cluster.LogicalId})`)(function* (
32 request?: Omit<I, "projectId" | "region" | "clusterName">,
33 ) {
34 return yield* run({
35 ...(request as I),
36 clusterName: yield* clusterName,
37 region: yield* region,
38 projectId: yield* project,
39 } as I);
40 });
41 });
42 });