The best way to control Claude Code, Codex and more from any computer or phone
| 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 { Instance } from "./Instance.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Shared HTTP scaffolding for Cloud Spanner instance bindings. |
| 8 | * NOT exported from index.ts. |
| 9 | */ |
| 10 | export const makeSpannerInstanceHttpBinding = <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* (instance: Instance) { |
| 19 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 20 | yield* bind`${options.tag}(${instance})`({ |
| 21 | iam: [grantFor(options.iam, instance.name)], |
| 22 | }); |
| 23 | } |
| 24 | const name = yield* instance.name; |
| 25 | return Effect.fn(`${options.tag}(${instance.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 | }); |