@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 42 lines 1.52 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 { grantFor, type BindingIam } from "../HttpBinding.ts";
6 import type { Job } from "./Job.ts";
7
8 /**
9 * Shared HTTP scaffolding for Cloud Scheduler job 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 makeJobHttpBinding = <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* (job: Job) {
30 if (!globalThis.__ALCHEMY_RUNTIME__) {
31 yield* bind`${options.tag}(${job})`({ iam: [grantFor(options.iam, job.name)] });
32 }
33 const name = yield* job.name;
34 return Effect.fn(`${options.tag}(${job.LogicalId})`)(function* (request?: Omit<I, "name">) {
35 const jobName = yield* name;
36 return yield* run({
37 ...request,
38 name: jobName,
39 } as I);
40 });
41 });
42 });