1import * as sqs from "@distilled.cloud/aws/sqs";
2import * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { Queue } from "./Queue.ts";
5
6export interface SendMessageBatchRequest extends Omit<
7 sqs.SendMessageBatchRequest,
8 "QueueUrl"
9> {}
10
11/**
12 * Runtime binding for `sqs:SendMessageBatch`.
13 *
14 * Bind this operation to a {@link Queue} inside a function runtime to send up
15 * to 10 messages per call with per-entry success/failure results. The binding
16 * grants the host function `sqs:SendMessage` on the queue. Provide the
17 * `SendMessageBatchHttp` layer on the Function to implement the binding.
18 *
19 * For an unbounded stream of messages with automatic batching and bounded
20 * retry of transient per-entry failures, prefer {@link QueueSink}.
21 * ### Sending Message Batches
22 * **Example:** Send a Batch of Messages
23 * ```typescript
24 * // init (provide SQS.SendMessageBatchHttp on the Function)
25 * const sendMessageBatch = yield* SQS.SendMessageBatch(queue);
26 *
27 * // runtime
28 * const result = yield* sendMessageBatch({
29 * Entries: messages.map((body, index) => ({
30 * Id: `${index}`,
31 * MessageBody: body,
32 * })),
33 * });
34 * // result.Successful / result.Failed
35 * ```
36 *
37 * @binding
38 */
39export interface SendMessageBatch extends Binding.Service<
40 SendMessageBatch,
41 "AWS.SQS.SendMessageBatch",
42 (
43 queue: Queue,
44 ) => Effect.Effect<
45 (
46 request: SendMessageBatchRequest,
47 ) => Effect.Effect<sqs.SendMessageBatchResult, sqs.SendMessageBatchError>
48 >
49> {}
50
51export const SendMessageBatch = Binding.Service<SendMessageBatch>(
52 "AWS.SQS.SendMessageBatch",
53);