The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as DynamoDB from "@distilled.cloud/aws/dynamodb"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export type TransactWriteItemsTables = [Table, ...Table[]]; |
| 7 | |
| 8 | type NativeTransactWriteItem = NonNullable< |
| 9 | DynamoDB.TransactWriteItemsInput["TransactItems"] |
| 10 | >[number]; |
| 11 | |
| 12 | type NativeConditionCheck = NonNullable<NativeTransactWriteItem["ConditionCheck"]>; |
| 13 | type NativeDelete = NonNullable<NativeTransactWriteItem["Delete"]>; |
| 14 | type NativePut = NonNullable<NativeTransactWriteItem["Put"]>; |
| 15 | type NativeUpdate = NonNullable<NativeTransactWriteItem["Update"]>; |
| 16 | |
| 17 | export interface BoundConditionCheck extends Omit<NativeConditionCheck, "TableName"> { |
| 18 | Table: string; |
| 19 | } |
| 20 | |
| 21 | export interface BoundDelete extends Omit<NativeDelete, "TableName"> { |
| 22 | Table: string; |
| 23 | } |
| 24 | |
| 25 | export interface BoundPut extends Omit<NativePut, "TableName"> { |
| 26 | Table: string; |
| 27 | } |
| 28 | |
| 29 | export interface BoundUpdate extends Omit<NativeUpdate, "TableName"> { |
| 30 | Table: string; |
| 31 | } |
| 32 | |
| 33 | export interface BoundTransactWriteItem { |
| 34 | ConditionCheck?: BoundConditionCheck; |
| 35 | Delete?: BoundDelete; |
| 36 | Put?: BoundPut; |
| 37 | Update?: BoundUpdate; |
| 38 | } |
| 39 | |
| 40 | export interface TransactWriteItemsRequest extends Omit< |
| 41 | DynamoDB.TransactWriteItemsInput, |
| 42 | "TransactItems" |
| 43 | > { |
| 44 | TransactItems: Array<BoundTransactWriteItem>; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Runtime binding for `dynamodb:TransactWriteItems`. |
| 49 | * |
| 50 | * Bind this operation to one or more tables and identify each item's target |
| 51 | * table by the bound table's `LogicalId`. |
| 52 | * ### Writing Data |
| 53 | * **Example:** Write Items Transactionally |
| 54 | * ```typescript |
| 55 | * const transactWriteItems = yield* AWS.DynamoDB.TransactWriteItems( |
| 56 | * sourceTable, |
| 57 | * archiveTable, |
| 58 | * ); |
| 59 | * |
| 60 | * yield* transactWriteItems({ |
| 61 | * TransactItems: [ |
| 62 | * { |
| 63 | * Put: { |
| 64 | * Table: sourceTable.LogicalId, |
| 65 | * Item: { pk: { S: "user#1" }, sk: { S: "profile" } }, |
| 66 | * }, |
| 67 | * }, |
| 68 | * ], |
| 69 | * }); |
| 70 | * ``` |
| 71 | * |
| 72 | * @binding |
| 73 | */ |
| 74 | export interface TransactWriteItems extends Binding.Service< |
| 75 | TransactWriteItems, |
| 76 | "AWS.DynamoDB.TransactWriteItems", |
| 77 | ( |
| 78 | ...tables: TransactWriteItemsTables |
| 79 | ) => Effect.Effect< |
| 80 | ( |
| 81 | request: TransactWriteItemsRequest, |
| 82 | ) => Effect.Effect<DynamoDB.TransactWriteItemsOutput, DynamoDB.TransactWriteItemsError> |
| 83 | > |
| 84 | > {} |
| 85 | |
| 86 | export const TransactWriteItems = Binding.Service<TransactWriteItems>( |
| 87 | "AWS.DynamoDB.TransactWriteItems", |
| 88 | ); |