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
| 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 BatchWriteItemTables = [Table, ...Table[]]; |
| 7 | |
| 8 | type BatchWriteRequests = NonNullable<DynamoDB.BatchWriteItemInput["RequestItems"]>[string]; |
| 9 | |
| 10 | export const sortBatchWriteItemTables = (tables: BatchWriteItemTables) => |
| 11 | [...new Map(tables.map((table) => [table.LogicalId, table] as const)).values()].sort((a, b) => |
| 12 | a.LogicalId.localeCompare(b.LogicalId), |
| 13 | ) as BatchWriteItemTables; |
| 14 | |
| 15 | export interface BatchWriteItemRequest extends Omit<DynamoDB.BatchWriteItemInput, "RequestItems"> { |
| 16 | RequestItems: Record<string, BatchWriteRequests>; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Runtime binding for `dynamodb:BatchWriteItem`. |
| 21 | * |
| 22 | * Bind this operation to one or more tables and key the request by each bound |
| 23 | * table's `LogicalId`. |
| 24 | * ### Writing Data |
| 25 | * **Example:** Write Items Across Multiple Tables |
| 26 | * ```typescript |
| 27 | * const batchWriteItem = yield* AWS.DynamoDB.BatchWriteItem(sourceTable, archiveTable); |
| 28 | * |
| 29 | * const response = yield* batchWriteItem({ |
| 30 | * RequestItems: { |
| 31 | * [sourceTable.LogicalId]: [ |
| 32 | * { |
| 33 | * PutRequest: { |
| 34 | * Item: { |
| 35 | * pk: { S: "user#1" }, |
| 36 | * sk: { S: "profile" }, |
| 37 | * }, |
| 38 | * }, |
| 39 | * }, |
| 40 | * ], |
| 41 | * }, |
| 42 | * }); |
| 43 | * ``` |
| 44 | * |
| 45 | * @binding |
| 46 | */ |
| 47 | export interface BatchWriteItem extends Binding.Service< |
| 48 | BatchWriteItem, |
| 49 | "AWS.DynamoDB.BatchWriteItem", |
| 50 | ( |
| 51 | ...tables: BatchWriteItemTables |
| 52 | ) => Effect.Effect< |
| 53 | ( |
| 54 | request: BatchWriteItemRequest, |
| 55 | ) => Effect.Effect<DynamoDB.BatchWriteItemOutput, DynamoDB.BatchWriteItemError> |
| 56 | > |
| 57 | > {} |
| 58 | |
| 59 | export const BatchWriteItem = Binding.Service<BatchWriteItem>("AWS.DynamoDB.BatchWriteItem"); |