@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 63 lines 2 KB
Raw
1 import type * as bigquery from "@distilled.cloud/gcp/bigquery_v2";
2 import * as Binding from "alchemy/Binding";
3 import type { RuntimeContext } from "alchemy/RuntimeContext";
4 import * as Data from "effect/Data";
5 import type * as Effect from "effect/Effect";
6 import type { Table } from "./Table.ts";
7
8 /** Per-row errors from a `tabledata.insertAll` request. */
9 export class InsertRowsFailed extends Data.TaggedError("GCP.BigQuery.InsertRowsFailed")<{
10 insertErrors: ReadonlyArray<{
11 /** Index of the rejected row in the request. */
12 index: number | undefined;
13 errors: ReadonlyArray<bigquery.ErrorProto>;
14 }>;
15 }> {}
16
17 export interface InsertRowsOptions {
18 /**
19 * Per-row `insertId`s for best-effort de-duplication; must match `rows`
20 * in length.
21 */
22 insertIds?: string[];
23 }
24
25 /** Write-only client for one BigQuery table. */
26 export interface WriteTableClient {
27 /**
28 * Stream rows into the table (`tabledata.insertAll`). Values are plain
29 * JavaScript (`Date` → timestamp, `Uint8Array` → bytes, `bigint` →
30 * integer string). Fails with {@link InsertRowsFailed} when any row is
31 * rejected.
32 */
33 insert(
34 rows: ReadonlyArray<Record<string, unknown>>,
35 options?: InsertRowsOptions,
36 ): Effect.Effect<void, bigquery.InsertAllTabledataError | InsertRowsFailed, RuntimeContext>;
37 }
38
39 /**
40 * Write access to a BigQuery {@link Table}: streaming `insert`. Grants
41 * `roles/bigquery.dataEditor` on the table only.
42 *
43 * ### Writing rows
44 * **Example:** Stream rows with de-duplication ids
45 * ```typescript
46 * const events = yield* GCP.BigQuery.WriteTable(table);
47 * yield* events.insert(
48 * [{ id: "a", score: 1, at: new Date() }],
49 * { insertIds: ["a"] },
50 * );
51 * // …provided with Effect.provide(GCP.BigQuery.WriteTableHttp)
52 * ```
53 *
54 * @binding
55 * @category BigQuery
56 */
57 export interface WriteTable extends Binding.Service<
58 WriteTable,
59 "GCP.BigQuery.WriteTable",
60 (table: Table) => Effect.Effect<WriteTableClient>
61 > {}
62
63 export const WriteTable = Binding.Service<WriteTable>("GCP.BigQuery.WriteTable");