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

main
ts 43 lines 1.46 KB
Raw
1 import { Credentials } from "@distilled.cloud/gcp/Credentials";
2 import * as Effect from "effect/Effect";
3 import * as HttpClient from "effect/http/HttpClient";
4 import * as GCPBindings from "../GCPBindings.ts";
5 import { type BindingIam, grantFor } from "../HttpBinding.ts";
6 import type { ConnectionsEntityTypesEntity } from "./ConnectionsEntityTypesEntity.ts";
7
8 type GcpHttpOp<I, A, E> = Effect.Effect<
9 (input: I) => Effect.Effect<A, E>,
10 never,
11 Credentials | HttpClient.HttpClient
12 > &
13 ((input: I) => Effect.Effect<A, E, Credentials | HttpClient.HttpClient>);
14
15 /**
16 * Shared HTTP scaffolding for Integration Connectors entity bindings.
17 * NOT exported from index.ts.
18 */
19 export const makeEntityHttpBinding = <I extends { name: string }, A, E>(options: {
20 tag: string;
21 iam: BindingIam;
22 operation: GcpHttpOp<I, A, E>;
23 }) =>
24 Effect.gen(function* () {
25 const bind = yield* GCPBindings.Bind;
26 const run = yield* GCPBindings.withCredentials(options.operation);
27 return Effect.fn(function* (entity: ConnectionsEntityTypesEntity) {
28 if (!globalThis.__ALCHEMY_RUNTIME__) {
29 yield* bind`${options.tag}(${entity})`({
30 iam: [grantFor(options.iam, entity.name)],
31 });
32 }
33 const name = yield* entity.name;
34 return Effect.fn(`${options.tag}(${entity.LogicalId})`)(function* (
35 request?: Omit<I, "name">,
36 ) {
37 return yield* run({
38 ...request,
39 name: yield* name,
40 } as I);
41 });
42 });
43 });