1import * as DynamoDB from "@distilled.cloud/aws/dynamodb";
2import * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Table } from "./Table.ts";
5
6export type BatchExecuteStatementTables = [Table, ...Table[]];
7
8export const sortBatchExecuteStatementTables = (
9 tables: BatchExecuteStatementTables,
10) =>
11 [
12 ...new Map(
13 tables.map((table) => [table.LogicalId, table] as const),
14 ).values(),
15 ].sort((a, b) =>
16 a.LogicalId.localeCompare(b.LogicalId),
17 ) as BatchExecuteStatementTables;
18
19export interface BatchExecuteStatementRequest
20 extends DynamoDB.BatchExecuteStatementInput {}
21
22/**
23 * Runtime binding for DynamoDB PartiQL `BatchExecuteStatement`.
24 *
25 * The request is passed through unchanged, but IAM is scoped to the explicitly
26 * bound tables and their indexes.
27 * ### PartiQL
28 * **Example:** Execute a Batch of Statements
29 * ```typescript
30 * const batchExecuteStatement = yield* AWS.DynamoDB.BatchExecuteStatement(
31 * sourceTable,
32 * archiveTable,
33 * );
34 *
35 * const response = yield* batchExecuteStatement({
36 * Statements: [
37 * {
38 * Statement: `SELECT * FROM "${yield* sourceTable.tableName}" WHERE pk=?`,
39 * Parameters: [{ S: "user#1" }],
40 * },
41 * ],
42 * });
43 * ```
44 *
45 * @binding
46 */
47export interface BatchExecuteStatement extends Binding.Service<
48 BatchExecuteStatement,
49 "AWS.DynamoDB.BatchExecuteStatement",
50 (
51 ...tables: BatchExecuteStatementTables
52 ) => Effect.Effect<
53 (
54 request: BatchExecuteStatementRequest,
55 ) => Effect.Effect<
56 DynamoDB.BatchExecuteStatementOutput,
57 DynamoDB.BatchExecuteStatementError
58 >
59 >
60> {}
61
62export const BatchExecuteStatement = Binding.Service<BatchExecuteStatement>(
63 "AWS.DynamoDB.BatchExecuteStatement",
64);