| 1 | import type * as DynamoDB from "@distilled.cloud/aws/dynamodb"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export type BatchGetItemTables = [Table, ...Table[]]; |
| 7 | |
| 8 | type BatchGetItemKeysAndAttributes = NonNullable< |
| 9 | DynamoDB.BatchGetItemInput["RequestItems"] |
| 10 | >[string]; |
| 11 | |
| 12 | export interface BatchGetItemRequest extends Omit< |
| 13 | DynamoDB.BatchGetItemInput, |
| 14 | "RequestItems" |
| 15 | > { |
| 16 | RequestItems: Record<string, BatchGetItemKeysAndAttributes>; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Runtime binding for `dynamodb:BatchGetItem`. |
| 21 | * |
| 22 | * Bind this operation to one or more tables and key the request by each bound |
| 23 | * table's `LogicalId`. The binding resolves those logical IDs to physical table |
| 24 | * names at runtime. |
| 25 | * ### Reading Data |
| 26 | * **Example:** Read Items Across Multiple Tables |
| 27 | * ```typescript |
| 28 | * const batchGetItem = yield* BatchGetItem(sourceTable, archiveTable); |
| 29 | * |
| 30 | * const response = yield* batchGetItem({ |
| 31 | * RequestItems: { |
| 32 | * [sourceTable.LogicalId]: { |
| 33 | * Keys: [{ pk: { S: "user#1" }, sk: { S: "profile" } }], |
| 34 | * }, |
| 35 | * [archiveTable.LogicalId]: { |
| 36 | * Keys: [{ pk: { S: "user#1" }, sk: { S: "profile" } }], |
| 37 | * }, |
| 38 | * }, |
| 39 | * }); |
| 40 | * ``` |
| 41 | * |
| 42 | * @binding |
| 43 | */ |
| 44 | export interface BatchGetItem extends Binding.Service< |
| 45 | BatchGetItem, |
| 46 | "AWS.DynamoDB.BatchGetItem", |
| 47 | ( |
| 48 | ...tables: BatchGetItemTables |
| 49 | ) => Effect.Effect< |
| 50 | ( |
| 51 | request: BatchGetItemRequest, |
| 52 | ) => Effect.Effect<DynamoDB.BatchGetItemOutput, DynamoDB.BatchGetItemError> |
| 53 | > |
| 54 | > {} |
| 55 | export const BatchGetItem = Binding.Service<BatchGetItem>( |
| 56 | "AWS.DynamoDB.BatchGetItem", |
| 57 | ); |