@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 34 lines 1.18 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { grantFor, type BindingIam, type GcpHttpOp } from "../HttpBinding.ts";
4 import type { CatalogsServingConfig } from "./CatalogsServingConfig.ts";
5
6 /**
7 * Shared HTTP scaffolding for Retail serving-config bindings.
8 * NOT exported from index.ts.
9 */
10 export const makeServingConfigHttpBinding = <I extends { placement: string }, A, E>(options: {
11 tag: string;
12 iam: BindingIam;
13 operation: GcpHttpOp<I, A, E>;
14 }) =>
15 Effect.gen(function* () {
16 const bind = yield* GCPBindings.Bind;
17 const run = yield* GCPBindings.withCredentials(options.operation);
18 return Effect.fn(function* (servingConfig: CatalogsServingConfig) {
19 if (!globalThis.__ALCHEMY_RUNTIME__) {
20 yield* bind`${options.tag}(${servingConfig})`({
21 iam: [grantFor(options.iam, servingConfig.name)],
22 });
23 }
24 const name = yield* servingConfig.name;
25 return Effect.fn(`${options.tag}(${servingConfig.LogicalId})`)(function* (
26 request: Omit<I, "placement">,
27 ) {
28 return yield* run({
29 ...request,
30 placement: yield* name,
31 } as I);
32 });
33 });
34 });