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

main
ts 49 lines 1.65 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 { ConnectionsGitRepositoryLink } from "./ConnectionsGitRepositoryLink.ts";
7
8 /**
9 * Shared HTTP scaffolding for Developer Connect git repository link
10 * bindings. NOT exported from index.ts.
11 *
12 * Distilled ops are `OperationMethod`s: yield them once at Layer
13 * construction (after providing Credentials + HttpClient) so the inner
14 * runtime Effect is `Effect<A, E>` and does not leak `GcpOpContext`.
15 */
16 export const makeGitRepositoryLinkHttpBinding = <
17 I extends { gitRepositoryLink: string },
18 A,
19 E,
20 >(options: {
21 tag: string;
22 iam: BindingIam;
23 operation: Effect.Effect<
24 (input: I) => Effect.Effect<A, E>,
25 never,
26 Credentials | HttpClient.HttpClient
27 >;
28 }) =>
29 Effect.gen(function* () {
30 const bind = yield* GCPBindings.Bind;
31 const run = yield* GCPBindings.withCredentials(options.operation);
32 return Effect.fn(function* <T extends ConnectionsGitRepositoryLink>(link: T) {
33 if (!globalThis.__ALCHEMY_RUNTIME__) {
34 yield* bind`${options.tag}(${link})`({
35 iam: [grantFor(options.iam, link.name)],
36 });
37 }
38 const name = yield* link.name;
39 return Effect.fn(`${options.tag}(${link.LogicalId})`)(function* (
40 request?: Omit<I, "gitRepositoryLink">,
41 ) {
42 const gitRepositoryLink = yield* name;
43 return yield* run({
44 ...request,
45 gitRepositoryLink,
46 } as I);
47 });
48 });
49 });