@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

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