@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, 06:00 UTC

main
ts 54 lines 1.84 KB
Raw
1 import { Credentials } from "@distilled.cloud/gcp/Credentials";
2 import type { Output } from "alchemy/Output";
3 import * as Effect from "effect/Effect";
4 import * as HttpClient from "effect/http/HttpClient";
5 import * as GCPBindings from "../GCPBindings.ts";
6 import { type BindingIam, grantFor } from "../HttpBinding.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 type NamedResource = {
16 readonly name: Output<string, never>;
17 readonly LogicalId: string;
18 };
19
20 /**
21 * Shared HTTP scaffolding for Managed Kafka named-resource bindings.
22 * Distilled ops are OperationMethods: yield them once at Layer
23 * construction (after providing Credentials + HttpClient) so the inner
24 * runtime Effect is `Effect<A, E>` and does not leak `GcpOpContext`.
25 * NOT exported from index.ts.
26 */
27 export const makeManagedKafkaHttpBinding =
28 <Resource extends NamedResource>() =>
29 <I extends { name?: string }, A, E>(options: {
30 tag: string;
31 iam: BindingIam;
32 operation: GcpHttpOp<I, A, E>;
33 }) =>
34 Effect.gen(function* () {
35 const bind = yield* GCPBindings.Bind;
36 const run = yield* GCPBindings.withCredentials(options.operation);
37 return Effect.fn(function* (resource: Resource) {
38 if (!globalThis.__ALCHEMY_RUNTIME__) {
39 yield* bind`${options.tag}(${resource})`({
40 iam: [grantFor(options.iam, resource.name)],
41 });
42 }
43 const name = yield* resource.name;
44 return Effect.fn(`${options.tag}(${resource.LogicalId})`)(function* (
45 request?: Omit<I, "name">,
46 ) {
47 const resourceName = yield* name;
48 return yield* run({
49 ...request,
50 name: resourceName,
51 } as I);
52 });
53 });
54 });