@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, 04:45 UTC

main
ts 42 lines 1.32 KB
Raw
1 import * as Effect from "effect/Effect";
2 import * as GCPBindings from "../GCPBindings.ts";
3 import { type BindingIam, type GcpHttpOp, grantFor } from "../HttpBinding.ts";
4 import type { Table } from "./Table.ts";
5
6 /**
7 * Shared HTTP scaffolding for BigQuery table bindings.
8 * NOT exported from index.ts.
9 */
10 export const makeTableHttpBinding = <
11 I extends { projectId: string; datasetId: string; tableId: string },
12 A,
13 E,
14 >(options: {
15 tag: string;
16 iam: BindingIam;
17 operation: GcpHttpOp<I, A, E>;
18 }) =>
19 Effect.gen(function* () {
20 const bind = yield* GCPBindings.Bind;
21 const run = yield* GCPBindings.withCredentials(options.operation);
22 return Effect.fn(function* (table: Table) {
23 if (!globalThis.__ALCHEMY_RUNTIME__) {
24 yield* bind`${options.tag}(${table})`({
25 iam: [grantFor(options.iam, table.name)],
26 });
27 }
28 const project = yield* table.project;
29 const datasetId = yield* table.datasetId;
30 const tableId = yield* table.tableId;
31 return Effect.fn(`${options.tag}(${table.LogicalId})`)(function* (
32 request?: Omit<I, "projectId" | "datasetId" | "tableId">,
33 ) {
34 return yield* run({
35 ...request,
36 projectId: yield* project,
37 datasetId: yield* datasetId,
38 tableId: yield* tableId,
39 } as I);
40 });
41 });
42 });