1import type * as DynamoDB from "@distilled.cloud/aws/dynamodb";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Table } from "./Table.ts";
5
6export type BatchGetItemTables = [Table, ...Table[]];
7
8type BatchGetItemKeysAndAttributes = NonNullable<
9 DynamoDB.BatchGetItemInput["RequestItems"]
10>[string];
11
12export 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 */
44export 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> {}
55export const BatchGetItem = Binding.Service<BatchGetItem>(
56 "AWS.DynamoDB.BatchGetItem",
57);