The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type * as Kinesis from "@distilled.cloud/aws/kinesis"; |
| 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 { Stream } from "./Stream.ts"; |
| 7 | |
| 8 | export type StreamSinkRecord = Kinesis.PutRecordsRequestEntry; |
| 9 | |
| 10 | export type StreamSinkError = Kinesis.PutRecordsError | BatchRetryExhaustedError<StreamSinkRecord>; |
| 11 | |
| 12 | /** |
| 13 | * A partition-aware sink for batching `PutRecords` requests into a stream |
| 14 | * (500 records / 5 MiB per call). |
| 15 | * |
| 16 | * Each input element is a raw `PutRecordsRequestEntry`, so callers stay in |
| 17 | * control of `PartitionKey` and optional `ExplicitHashKey`. |
| 18 | * |
| 19 | * Records the API reports as failed (`FailedRecordCount > 0`, per-record |
| 20 | * `ErrorCode` — throughput exceeded or internal failure) are re-submitted on |
| 21 | * a bounded schedule; exhausting retries fails the sink with a typed |
| 22 | * `BatchRetryExhaustedError` carrying the stranded records. |
| 23 | * |
| 24 | * Provide the implementation with `Effect.provide(AWS.Kinesis.StreamSinkHttp)`. |
| 25 | * ### Writing Streams of Records |
| 26 | * **Example:** Run an Effect Stream into a Kinesis Stream |
| 27 | * ```typescript |
| 28 | * // init — bind the sink to the stream |
| 29 | * const sink = yield* AWS.Kinesis.StreamSink(stream); |
| 30 | * |
| 31 | * // runtime — batches into PutRecords calls of up to 500 records / 5 MiB |
| 32 | * yield* Stream.fromIterable( |
| 33 | * orders.map((order) => ({ |
| 34 | * PartitionKey: order.id, |
| 35 | * Data: new TextEncoder().encode(JSON.stringify(order)), |
| 36 | * })), |
| 37 | * ).pipe(Stream.run(sink)); |
| 38 | * ``` |
| 39 | * |
| 40 | * @binding |
| 41 | */ |
| 42 | export interface StreamSink extends Binding.Service< |
| 43 | StreamSink, |
| 44 | "AWS.Kinesis.StreamSink", |
| 45 | ( |
| 46 | stream: Stream, |
| 47 | ) => Effect.Effect< |
| 48 | Sink.Sink<void, StreamSinkRecord, readonly StreamSinkRecord[], StreamSinkError> |
| 49 | > |
| 50 | > {} |
| 51 | |
| 52 | export const StreamSink = Binding.Service<StreamSink>("AWS.Kinesis.StreamSink"); |