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

main
ts 34 lines 1.12 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 { Connection } from "./Connection.ts";
5
6 /**
7 * Shared HTTP scaffolding for BigQuery Connection bindings.
8 * NOT exported from index.ts.
9 */
10 export const makeConnectionHttpBinding = <I extends { name?: string }, A, E>(options: {
11 tag: string;
12 iam: BindingIam;
13 operation: GcpHttpOp<I, A, E>;
14 }) =>
15 Effect.gen(function* () {
16 const bind = yield* GCPBindings.Bind;
17 const run = yield* GCPBindings.withCredentials(options.operation);
18 return Effect.fn(function* (connection: Connection) {
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`${options.tag}(${connection})`({
21 iam: [grantFor(options.iam, connection.name)],
22 });
23 }
24 const name = yield* connection.name;
25 return Effect.fn(`${options.tag}(${connection.LogicalId})`)(function* (
26 request?: Omit<I, "name">,
27 ) {
28 return yield* run({
29 ...(request as I),
30 name: yield* name,
31 } as I);
32 });
33 });
34 });