| 1 | import * as Kinesis from "@distilled.cloud/aws/kinesis"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Stream } from "./Stream.ts"; |
| 5 | |
| 6 | export interface PutRecordRequest extends Omit< |
| 7 | Kinesis.PutRecordInput, |
| 8 | "StreamName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `kinesis:PutRecord`. |
| 13 | * |
| 14 | * Bind this operation to a `Stream` in the function's init phase to get a |
| 15 | * callable that writes single records — the stream name is injected |
| 16 | * automatically and `kinesis:PutRecord` is granted on the stream. Provide the |
| 17 | * implementation with `Effect.provide(AWS.Kinesis.PutRecordHttp)`. |
| 18 | * ### Writing Records |
| 19 | * **Example:** Put a Record from a Handler |
| 20 | * ```typescript |
| 21 | * export default MyFunction.make( |
| 22 | * { main: import.meta.url, functionUrl: true }, |
| 23 | * Effect.gen(function* () { |
| 24 | * const stream = yield* AWS.Kinesis.Stream("OrdersStream"); |
| 25 | * // init — bind the operation to the stream |
| 26 | * const putRecord = yield* AWS.Kinesis.PutRecord(stream); |
| 27 | * |
| 28 | * return { |
| 29 | * fetch: Effect.gen(function* () { |
| 30 | * // runtime — write a record |
| 31 | * yield* putRecord({ |
| 32 | * PartitionKey: "order-123", |
| 33 | * Data: new TextEncoder().encode(JSON.stringify({ orderId: "123" })), |
| 34 | * }); |
| 35 | * return HttpServerResponse.text("sent"); |
| 36 | * }).pipe(Effect.orDie), |
| 37 | * }; |
| 38 | * }).pipe(Effect.provide(AWS.Kinesis.PutRecordHttp)), |
| 39 | * ); |
| 40 | * ``` |
| 41 | * |
| 42 | * @binding |
| 43 | */ |
| 44 | export interface PutRecord extends Binding.Service< |
| 45 | PutRecord, |
| 46 | "AWS.Kinesis.PutRecord", |
| 47 | ( |
| 48 | stream: Stream, |
| 49 | ) => Effect.Effect< |
| 50 | ( |
| 51 | request: PutRecordRequest, |
| 52 | ) => Effect.Effect<Kinesis.PutRecordOutput, Kinesis.PutRecordError> |
| 53 | > |
| 54 | > {} |
| 55 | |
| 56 | export const PutRecord = Binding.Service<PutRecord>("AWS.Kinesis.PutRecord"); |