Skip to content
Source
Sign inSign up

GetItem.ts

36 lines1.0 KB

1import type * as DynamoDB from "@distilled.cloud/aws/dynamodb";
2import * as Binding from "alchemy/Binding";
3import type * as Effect from "effect/Effect";
4import type { Table } from "./Table.ts";
5​
6export interface GetItemRequest extends Omit<DynamoDB.GetItemInput, "TableName"> {}
7​
8/**
9 * Runtime binding for `dynamodb:GetItem`.
10 *
11 * Bind this operation to a `Table` inside a function runtime to get a callable
12 * that automatically injects the table name.
13 * ### Reading Data
14 * **Example:** Read a Single Item
15 * ```typescript
16 * const getItem = yield* AWS.DynamoDB.GetItem(table);
17 *
18 * const response = yield* getItem({
19 * Key: {
20 * pk: { S: "user#123" },
21 * },
22 * });
23 * ```
24 *
25 * @binding
26 */
27export interface GetItem extends Binding.Service<
28 GetItem,
29 "AWS.DynamoDB.GetItem",
30 <T extends Table>(
31 table: T,
32 ) => Effect.Effect<
33 (request: GetItemRequest) => Effect.Effect<DynamoDB.GetItemOutput, DynamoDB.GetItemError>
34 >
35> {}
36export const GetItem = Binding.Service<GetItem>("AWS.DynamoDB.GetItem");