| 1 | import * as sns from "@distilled.cloud/aws/sns"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Topic } from "./Topic.ts"; |
| 5 | |
| 6 | export interface PublishBatchRequest extends Omit< |
| 7 | sns.PublishBatchInput, |
| 8 | "TopicArn" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `sns:PublishBatch`. |
| 13 | * |
| 14 | * Bind this operation to a {@link Topic} inside a function runtime to publish |
| 15 | * up to 10 messages per call with per-entry success/failure results. The |
| 16 | * binding grants the host function `sns:Publish` on the topic. Provide the |
| 17 | * `PublishBatchHttp` 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 TopicSink}. |
| 21 | * ### Publishing Message Batches |
| 22 | * **Example:** Publish a Batch of Messages |
| 23 | * ```typescript |
| 24 | * // init (provide SNS.PublishBatchHttp on the Function) |
| 25 | * const publishBatch = yield* SNS.PublishBatch(topic); |
| 26 | * |
| 27 | * // runtime |
| 28 | * const response = yield* publishBatch({ |
| 29 | * PublishBatchRequestEntries: messages.map((message, index) => ({ |
| 30 | * Id: `${index}`, |
| 31 | * Message: message, |
| 32 | * })), |
| 33 | * }); |
| 34 | * // response.Successful / response.Failed |
| 35 | * ``` |
| 36 | * |
| 37 | * @binding |
| 38 | */ |
| 39 | export interface PublishBatch extends Binding.Service< |
| 40 | PublishBatch, |
| 41 | "AWS.SNS.PublishBatch", |
| 42 | ( |
| 43 | topic: Topic, |
| 44 | ) => Effect.Effect< |
| 45 | ( |
| 46 | request: PublishBatchRequest, |
| 47 | ) => Effect.Effect<sns.PublishBatchResponse, sns.PublishBatchError> |
| 48 | > |
| 49 | > {} |
| 50 | |
| 51 | export const PublishBatch = Binding.Service<PublishBatch>( |
| 52 | "AWS.SNS.PublishBatch", |
| 53 | ); |