| 1 | import * as DynamoDB from "@distilled.cloud/aws/dynamodb"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export interface PutItemRequest extends Omit< |
| 7 | DynamoDB.PutItemInput, |
| 8 | "TableName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `dynamodb:PutItem`. |
| 13 | * |
| 14 | * Bind this operation to a `Table` inside a function runtime to get a callable |
| 15 | * that writes a single item, automatically injecting the table name and |
| 16 | * granting the host `dynamodb:PutItem` on the table. Provide the `PutItemHttp` |
| 17 | * layer on the Function to satisfy the binding. |
| 18 | * ### Writing Data |
| 19 | * **Example:** Write a Single Item |
| 20 | * ```typescript |
| 21 | * // inside the Function's Effect.gen, with Effect.provide(DynamoDB.PutItemHttp) |
| 22 | * const putItem = yield* AWS.DynamoDB.PutItem(table); |
| 23 | * |
| 24 | * yield* putItem({ |
| 25 | * Item: { |
| 26 | * pk: { S: "user#123" }, |
| 27 | * sk: { S: "profile" }, |
| 28 | * name: { S: "Alice" }, |
| 29 | * }, |
| 30 | * }); |
| 31 | * ``` |
| 32 | * |
| 33 | * @binding |
| 34 | */ |
| 35 | export interface PutItem extends Binding.Service< |
| 36 | PutItem, |
| 37 | "AWS.DynamoDB.PutItem", |
| 38 | <T extends Table>( |
| 39 | table: T, |
| 40 | ) => Effect.Effect< |
| 41 | ( |
| 42 | request: PutItemRequest, |
| 43 | ) => Effect.Effect<DynamoDB.PutItemOutput, DynamoDB.PutItemError> |
| 44 | > |
| 45 | > {} |
| 46 | |
| 47 | export const PutItem = Binding.Service<PutItem>("AWS.DynamoDB.PutItem"); |