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
| 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 { TransferJob } from "./TransferJob.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Shared HTTP scaffolding for Storage Transfer 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 makeTransferJobHttpBinding = <I extends { jobName?: 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 | projectInBody?: boolean; |
| 26 | }) => |
| 27 | Effect.gen(function* () { |
| 28 | const bind = yield* GCPBindings.Bind; |
| 29 | const run = yield* GCPBindings.withCredentials(options.operation); |
| 30 | return Effect.fn(function* (job: TransferJob) { |
| 31 | if (!globalThis.__ALCHEMY_RUNTIME__) { |
| 32 | yield* bind`${options.tag}(${job})`({ iam: [grantFor(options.iam, job.name)] }); |
| 33 | } |
| 34 | const name = yield* job.name; |
| 35 | const project = yield* job.project; |
| 36 | return Effect.fn(`${options.tag}(${job.LogicalId})`)(function* ( |
| 37 | request?: Omit<I, "jobName">, |
| 38 | ) { |
| 39 | const jobName = yield* name; |
| 40 | const projectId = yield* project; |
| 41 | const input = { |
| 42 | ...request, |
| 43 | jobName, |
| 44 | } as I; |
| 45 | if (options.projectInBody) { |
| 46 | const withBody = input as I & { |
| 47 | body?: { projectId?: string }; |
| 48 | }; |
| 49 | withBody.body = { |
| 50 | ...withBody.body, |
| 51 | projectId: withBody.body?.projectId ?? projectId, |
| 52 | }; |
| 53 | } |
| 54 | return yield* run(input); |
| 55 | }); |
| 56 | }); |
| 57 | }); |