| 1 | import type * as s3tables from "@distilled.cloud/aws/s3tables"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | /** |
| 7 | * `UpdateTableMetadataLocation` request with `tableBucketARN`, `namespace`, |
| 8 | * and `name` injected from the bound {@link Table}. |
| 9 | */ |
| 10 | export interface UpdateTableMetadataLocationRequest extends Omit< |
| 11 | s3tables.UpdateTableMetadataLocationRequest, |
| 12 | "tableBucketARN" | "namespace" | "name" |
| 13 | > {} |
| 14 | |
| 15 | /** |
| 16 | * Runtime binding for the `UpdateTableMetadataLocation` operation (IAM |
| 17 | * action `s3tables:UpdateTableMetadataLocation` on the table ARN). |
| 18 | * |
| 19 | * Commits a new Iceberg metadata file for the bound {@link Table} — the |
| 20 | * write half of the Iceberg commit protocol: read the current version with |
| 21 | * {@link GetTableMetadataLocation}, write a new metadata file into the |
| 22 | * table's warehouse, then commit it here with the observed `versionToken`. |
| 23 | * A stale token fails with the typed `ConflictException` (another writer |
| 24 | * committed first). Provide the implementation with |
| 25 | * `Effect.provide(AWS.S3Tables.UpdateTableMetadataLocationHttp)`. |
| 26 | * ### The Iceberg Commit Protocol |
| 27 | * **Example:** Commit a new metadata file |
| 28 | * ```typescript |
| 29 | * const getTableMetadataLocation = |
| 30 | * yield* AWS.S3Tables.GetTableMetadataLocation(table); |
| 31 | * const updateTableMetadataLocation = |
| 32 | * yield* AWS.S3Tables.UpdateTableMetadataLocation(table); |
| 33 | * |
| 34 | * const { versionToken, warehouseLocation } = |
| 35 | * yield* getTableMetadataLocation(); |
| 36 | * // ... write `${warehouseLocation}/metadata/00001-….metadata.json` ... |
| 37 | * yield* updateTableMetadataLocation({ |
| 38 | * versionToken, |
| 39 | * metadataLocation: `${warehouseLocation}/metadata/00001-….metadata.json`, |
| 40 | * }); |
| 41 | * ``` |
| 42 | * |
| 43 | * @binding |
| 44 | */ |
| 45 | export interface UpdateTableMetadataLocation extends Binding.Service< |
| 46 | UpdateTableMetadataLocation, |
| 47 | "AWS.S3Tables.UpdateTableMetadataLocation", |
| 48 | ( |
| 49 | table: Table, |
| 50 | ) => Effect.Effect< |
| 51 | ( |
| 52 | request: UpdateTableMetadataLocationRequest, |
| 53 | ) => Effect.Effect< |
| 54 | s3tables.UpdateTableMetadataLocationResponse, |
| 55 | s3tables.UpdateTableMetadataLocationError |
| 56 | > |
| 57 | > |
| 58 | > {} |
| 59 | export const UpdateTableMetadataLocation = |
| 60 | Binding.Service<UpdateTableMetadataLocation>( |
| 61 | "AWS.S3Tables.UpdateTableMetadataLocation", |
| 62 | ); |