| 1 | import type * as DynamoDB from "@distilled.cloud/aws/dynamodb"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Table } from "./Table.ts"; |
| 5 | |
| 6 | export interface UpdateItemRequest extends Omit< |
| 7 | DynamoDB.UpdateItemInput, |
| 8 | "TableName" |
| 9 | > {} |
| 10 | |
| 11 | /** |
| 12 | * Runtime binding for `dynamodb:UpdateItem`. |
| 13 | * |
| 14 | * Bind this operation to a `Table` inside a function runtime to get a callable |
| 15 | * that applies an update expression to a single item, automatically injecting |
| 16 | * the table name. Provide the `UpdateItemHttp` layer on the Function to |
| 17 | * satisfy the binding. |
| 18 | * ### Writing Data |
| 19 | * **Example:** Update an Item with an Update Expression |
| 20 | * ```typescript |
| 21 | * const updateItem = yield* AWS.DynamoDB.UpdateItem(table); |
| 22 | * |
| 23 | * const response = yield* updateItem({ |
| 24 | * Key: { |
| 25 | * pk: { S: "user#123" }, |
| 26 | * sk: { S: "profile" }, |
| 27 | * }, |
| 28 | * UpdateExpression: "SET #name = :name", |
| 29 | * ExpressionAttributeNames: { "#name": "name" }, |
| 30 | * ExpressionAttributeValues: { ":name": { S: "Alice" } }, |
| 31 | * ReturnValues: "ALL_NEW", |
| 32 | * }); |
| 33 | * ``` |
| 34 | * |
| 35 | * @binding |
| 36 | */ |
| 37 | export interface UpdateItem extends Binding.Service< |
| 38 | UpdateItem, |
| 39 | "AWS.DynamoDB.UpdateItem", |
| 40 | <T extends Table>( |
| 41 | table: T, |
| 42 | ) => Effect.Effect< |
| 43 | ( |
| 44 | request: UpdateItemRequest, |
| 45 | ) => Effect.Effect<DynamoDB.UpdateItemOutput, DynamoDB.UpdateItemError> |
| 46 | > |
| 47 | > {} |
| 48 | export const UpdateItem = Binding.Service<UpdateItem>( |
| 49 | "AWS.DynamoDB.UpdateItem", |
| 50 | ); |