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

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