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 { Service } from "./Service.ts"; |
| 5 | import type { ServicesConnector } from "./ServicesConnector.ts"; |
| 6 | |
| 7 | /** |
| 8 | * Shared HTTP scaffolding for Firebase Data Connect bindings. |
| 9 | * NOT exported from index.ts. |
| 10 | */ |
| 11 | export const makeServiceHttpBinding = <I extends { name: string }, A, E>(options: { |
| 12 | tag: string; |
| 13 | iam: BindingIam; |
| 14 | operation: GcpHttpOp<I, A, E>; |
| 15 | }) => |
| 16 | Effect.gen(function* () { |
| 17 | const bind = yield* GCPBindings.Bind; |
| 18 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 19 | return Effect.fn(function* (service: Service) { |
| 20 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 21 | yield* bind`${options.tag}(${service})`({ |
| 22 | iam: [grantFor(options.iam, service.name)], |
| 23 | }); |
| 24 | } |
| 25 | const name = yield* service.name; |
| 26 | return Effect.fn(`${options.tag}(${service.LogicalId})`)(function* ( |
| 27 | request: Omit<I, "name">, |
| 28 | ) { |
| 29 | return yield* run({ |
| 30 | ...request, |
| 31 | name: yield* name, |
| 32 | } as I); |
| 33 | }); |
| 34 | }); |
| 35 | }); |
| 36 | |
| 37 | export const makeConnectorHttpBinding = <I extends { name: string }, A, E>(options: { |
| 38 | tag: string; |
| 39 | iam: BindingIam; |
| 40 | operation: GcpHttpOp<I, A, E>; |
| 41 | }) => |
| 42 | Effect.gen(function* () { |
| 43 | const bind = yield* GCPBindings.Bind; |
| 44 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 45 | return Effect.fn(function* (connector: ServicesConnector) { |
| 46 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 47 | yield* bind`${options.tag}(${connector})`({ |
| 48 | iam: [grantFor(options.iam, connector.name)], |
| 49 | }); |
| 50 | } |
| 51 | const name = yield* connector.name; |
| 52 | return Effect.fn(`${options.tag}(${connector.LogicalId})`)(function* ( |
| 53 | request: Omit<I, "name">, |
| 54 | ) { |
| 55 | return yield* run({ |
| 56 | ...request, |
| 57 | name: yield* name, |
| 58 | } as I); |
| 59 | }); |
| 60 | }); |
| 61 | }); |