import { BaseCommand, BasePaginatable, WriteTransactable, PreparedWriteTransaction, BatchWritePreparable, PreparedBatchWrite, BatchGetPreparable, PreparedBatchGet, GetTransactable, PreparedGetTransaction } from '../commands/index.js'; import { DynamoKeyBuilder, GlobalSecondaryIndexKeyBuilders, LocalSecondaryIndexKeyBuilders, DynamoKeyableValue, DynamoKey, DynamoIndexKey } from './key.js'; import { DynamoTable } from './table.js'; import { ObjectLikeZodType, EntitySchema, IndexName } from './index.js'; /** * Configuration type for creating a DynamoEntity. * * @template Schema - The Zod schema representing the entity's structure. * * @property table - The DynamoTable instance associated with the entity. * @property schema - The Zod schema defining the entity's structure. * @property partitionKey - Key builder function to build the partition key from an entity item. * @property sortKey - Key builder function to build the sort key from an entity item. * @property globalSecondaryIndexes - Mapping of global secondary index names to their key builders. * @property localSecondaryIndexes - Mapping of local secondary index names to their key builders. */ type DynamoEntityConfig = { table: DynamoTable; schema: Schema; partitionKey?: DynamoKeyBuilder>; sortKey?: DynamoKeyBuilder>; globalSecondaryIndexes?: GlobalSecondaryIndexKeyBuilders>; localSecondaryIndexes?: LocalSecondaryIndexKeyBuilders>; }; /** * Input type for building *either* a DynamoDB primary key or secondary index key. * * This is used in cases where the user may want to specify either a full primary key * or a secondary index key to identify an item. */ type EntityKeyInput = { key: Partial; } | { index: { [index: IndexName]: Partial; }; }; /** * Core class that represents a DynamoDB entity. * * @template Schema - The Zod schema representing the entity's structure. */ declare class DynamoEntity { #private; constructor(config: DynamoEntityConfig); /** * Gets the DynamoDB table associated with this entity. */ get table(): DynamoTable; /** * Gets the Zod schema defining the structure of this entity. */ get schema(): Schema; /** * Gets the key builders for the secondary indexes defined on this entity. */ get secondaryIndexKeyBuilders(): { gsi: GlobalSecondaryIndexKeyBuilders>; lsi: LocalSecondaryIndexKeyBuilders>; }; /** * Builds the partition key for the given item using the entity's partition key builder. */ buildPartitionKey(item: Partial>): DynamoKeyableValue | undefined; /** * Builds the sort key for the given item using the entity's sort key builder. */ buildSortKey(item: Partial>): DynamoKeyableValue | undefined; /** * Builds the primary key for the given item, including both partition and sort keys if defined. * * If the entity does not have partition or sort key builders defined, the item is returned as-is. */ buildPrimaryKey(item: Partial>): DynamoKey; /** * Builds the key for a global secondary index for the given item. * * If the specified index does not exist or its key builders are not defined, * the item is returned as-is. */ buildGlobalSecondaryIndexKey(indexName: IndexName, item: Partial>): DynamoIndexKey; /** * Builds the key for a local secondary index for the given item. * * If the specified index does not exist or its key builders are not defined, * the item is returned as-is. */ buildLocalSecondaryIndexKey(indexName: IndexName, item: Partial>): DynamoIndexKey; /** * Builds either a primary key or a secondary index key based on the provided input. * * If the input contains a `key`, the primary key is built. * If the input contains an `index`, the corresponding secondary index key is built. * * Works similarly to the other key building methods and will pass-through the key or index * input if the entity does not have the necessary key builders defined. * * @throws DocumentBuilderError if the index name is missing or not defined on the entity. */ buildPrimaryOrIndexKey(keyInput: EntityKeyInput>): DynamoKey | DynamoIndexKey; /** * Builds all keys (primary and secondary index keys) for the given item. */ buildAllKeys(item: Partial>): DynamoKey; /** * Sends a command to be executed against this entity's table. */ send(command: BaseCommand): Promise; /** * Paginates through results of a paginatable command for this entity's table. */ paginate(paginatable: BasePaginatable): AsyncGenerator; /** * Prepares a set of write operations bound to this entity for use in a table-level * `TableTransactWrite` command. */ prepare(writes: WriteTransactable[]): PreparedWriteTransaction; /** * Prepares a batch write command bound to this entity for use in a table-level * `TableBatchWrite` command. */ prepare(batchWrite: BatchWritePreparable): PreparedBatchWrite; /** * Prepares a batch get command bound to this entity for use in a table-level * `TableBatchGet` command. */ prepare(batchGet: BatchGetPreparable): PreparedBatchGet; /** * Prepares a get command bound to this entity for use in a table-level * `TableTransactGet` command. */ prepare(get: GetTransactable): PreparedGetTransaction; } export { DynamoEntity }; export type { DynamoEntityConfig, EntityKeyInput };