@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 67 lines 2.5 KB
Raw
1 import type * as sqs from "@distilled.cloud/aws/sqs";
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 { Queue } from "./Queue.ts";
7
8 /**
9 * A raw `SendMessageBatchRequestEntry` minus the batch-correlation `Id`,
10 * which the sink assigns per API call. Callers stay in control of
11 * `MessageBody`, `MessageGroupId`, `MessageDeduplicationId`, attributes, etc.
12 */
13 export interface QueueSinkEntry extends Omit<sqs.SendMessageBatchRequestEntry, "Id"> {}
14
15 export type QueueSinkError = sqs.SendMessageBatchError | BatchRetryExhaustedError<QueueSinkEntry>;
16
17 /**
18 * A batching sink over SQS `SendMessageBatch` (10 entries / 256 KiB per
19 * call). Per-entry failures with `SenderFault: false` (throttling, internal
20 * errors) 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 `sqs:SendMessage` and
25 * `sqs:SendMessageBatch` on the queue. Provide the `QueueSinkHttp` layer
26 * (which itself needs `SendMessageBatchHttp`) on the Function to implement
27 * the binding.
28 * ### Streaming Messages into a Queue
29 * **Example:** Run a Stream into a Queue
30 * ```typescript
31 * // init (provide SQS.QueueSinkHttp + SQS.SendMessageBatchHttp on the Function)
32 * const sink = yield* SQS.QueueSink(queue);
33 *
34 * // runtime: batching, size limits, and transient-failure retry are handled
35 * // by the sink — each element is a SendMessageBatchRequestEntry minus `Id`.
36 * yield* Stream.fromIterable(messages).pipe(
37 * Stream.map((message) => ({ MessageBody: message })),
38 * Stream.run(sink),
39 * );
40 * ```
41 *
42 * **Example:** Forward Event-Source Records into a Result Queue
43 * ```typescript
44 * const sink = yield* SQS.QueueSink(resultQueue);
45 *
46 * yield* SQS.consumeQueueMessages(
47 * sourceQueue,
48 * Effect.fn(function* (event) {
49 * yield* Stream.fromIterable(event.Records).pipe(
50 * Stream.map((record) => ({ MessageBody: record.body })),
51 * Stream.run(sink),
52 * );
53 * }),
54 * );
55 * ```
56 *
57 * @binding
58 */
59 export interface QueueSink extends Binding.Service<
60 QueueSink,
61 "AWS.SQS.QueueSink",
62 (
63 queue: Queue,
64 ) => Effect.Effect<Sink.Sink<void, QueueSinkEntry, readonly QueueSinkEntry[], QueueSinkError>>
65 > {}
66
67 export const QueueSink = Binding.Service<QueueSink>("AWS.SQS.QueueSink");