sailfork / t3code-github / .repos/ alchemy-effect/ packages/ aws/ src/ DynamoDB/ GetItem.ts

import type * as DynamoDB from "@distilled.cloud/aws/dynamodb";
import * as Binding from "alchemy/Binding";
import type * as Effect from "effect/Effect";
import type { Table } from "./Table.ts";

export interface GetItemRequest extends Omit<DynamoDB.GetItemInput, "TableName"> {}

/**
 * Runtime binding for `dynamodb:GetItem`.
 *
 * Bind this operation to a `Table` inside a function runtime to get a callable
 * that automatically injects the table name.
 * ### Reading Data
 * **Example:** Read a Single Item
 * ```typescript
 * const getItem = yield* AWS.DynamoDB.GetItem(table);
 *
 * const response = yield* getItem({
 *   Key: {
 *     pk: { S: "user#123" },
 *   },
 * });
 * ```
 *
 * @binding
 */
export interface GetItem extends Binding.Service<
  GetItem,
  "AWS.DynamoDB.GetItem",
  <T extends Table>(
    table: T,
  ) => Effect.Effect<
    (request: GetItemRequest) => Effect.Effect<DynamoDB.GetItemOutput, DynamoDB.GetItemError>
  >
> {}
export const GetItem = Binding.Service<GetItem>("AWS.DynamoDB.GetItem");