The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type * as sns from "@distilled.cloud/aws/sns"; |
| 2 | import * as Binding from "alchemy/Binding"; |
| 3 | import type { BatchRetryExhaustedError } from "alchemy/Util/BatchedSink"; |
| 4 | import type * as Effect from "effect/Effect"; |
| 5 | import type * as Sink from "effect/Sink"; |
| 6 | import type { Topic } from "./Topic.ts"; |
| 7 | |
| 8 | /** |
| 9 | * A raw `PublishBatchRequestEntry` minus the batch-correlation `Id`, which |
| 10 | * the sink assigns per API call. Callers stay in control of `Message`, |
| 11 | * `Subject`, `MessageGroupId`, `MessageDeduplicationId`, attributes, etc. |
| 12 | */ |
| 13 | export interface TopicSinkEntry extends Omit<sns.PublishBatchRequestEntry, "Id"> {} |
| 14 | |
| 15 | export type TopicSinkError = sns.PublishBatchError | BatchRetryExhaustedError<TopicSinkEntry>; |
| 16 | |
| 17 | /** |
| 18 | * A batching sink over SNS `PublishBatch` (10 entries / 256 KiB per call). |
| 19 | * Per-entry failures with `SenderFault: false` (throttling, internal errors) |
| 20 | * are retried on a bounded schedule; `SenderFault: true` failures are |
| 21 | * permanent and dropped. Exhausting retries fails the sink with a typed |
| 22 | * `BatchRetryExhaustedError` carrying the stranded entries. |
| 23 | * |
| 24 | * The binding grants the host function `sns:Publish` on the topic. Provide |
| 25 | * the `TopicSinkHttp` layer (which itself needs `PublishBatchHttp`) on the |
| 26 | * Function to implement the binding. |
| 27 | * ### Streaming Messages into a Topic |
| 28 | * **Example:** Run a Stream into a Topic |
| 29 | * ```typescript |
| 30 | * // init (provide SNS.TopicSinkHttp + SNS.PublishBatchHttp on the Function) |
| 31 | * const sink = yield* SNS.TopicSink(topic); |
| 32 | * |
| 33 | * // runtime: batching, size limits, and transient-failure retry are handled |
| 34 | * // by the sink — each element is a PublishBatchRequestEntry minus `Id`. |
| 35 | * yield* Stream.fromIterable(messages).pipe( |
| 36 | * Stream.map((message) => ({ Message: message })), |
| 37 | * Stream.run(sink), |
| 38 | * ); |
| 39 | * ``` |
| 40 | * |
| 41 | * @binding |
| 42 | */ |
| 43 | export interface TopicSink extends Binding.Service< |
| 44 | TopicSink, |
| 45 | "AWS.SNS.TopicSink", |
| 46 | ( |
| 47 | topic: Topic, |
| 48 | ) => Effect.Effect<Sink.Sink<void, TopicSinkEntry, readonly TopicSinkEntry[], TopicSinkError>> |
| 49 | > {} |
| 50 | |
| 51 | export const TopicSink = Binding.Service<TopicSink>("AWS.SNS.TopicSink"); |