Skip to content

DynamoEntity

Core class that represents a DynamoDB entity.

Schema extends ZodObject

The Zod schema representing the entity’s structure.

new DynamoEntity<Schema>(config): DynamoEntity<Schema>;

DynamoEntityConfig<Schema>

DynamoEntity<Schema>

get schema(): Schema;

Gets the Zod schema defining the structure of this entity.

Schema


get secondaryIndexKeyBuilders(): object;

Gets the key builders for the secondary indexes defined on this entity.

object

gsi: GlobalSecondaryIndexKeyBuilders<EntitySchema<Schema>>;
lsi: LocalSecondaryIndexKeyBuilders<EntitySchema<Schema>>;

get table(): DynamoTable;

Gets the DynamoDB table associated with this entity.

DynamoTable

buildAllKeys(item): DynamoKey;

Builds all keys (primary and secondary index keys) for the given item.

Partial<EntitySchema<Schema>>

DynamoKey


buildGlobalSecondaryIndexKey(indexName, item): DynamoIndexKey;

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.

string

Partial<EntitySchema<Schema>>

DynamoIndexKey


buildLocalSecondaryIndexKey(indexName, item): 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.

string

Partial<EntitySchema<Schema>>

DynamoIndexKey


buildPartitionKey(item):
| DynamoKeyableValue
| undefined;

Builds the partition key for the given item using the entity’s partition key builder.

Partial<EntitySchema<Schema>>

| DynamoKeyableValue | undefined


buildPrimaryKey(item): DynamoKey;

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.

Partial<EntitySchema<Schema>>

DynamoKey


buildPrimaryOrIndexKey(keyInput):
| DynamoKey
| 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.

EntityKeyInput<EntitySchema<Schema>>

| DynamoKey | DynamoIndexKey

DocumentBuilderError if the index name is missing or not defined on the entity.


buildSortKey(item):
| DynamoKeyableValue
| undefined;

Builds the sort key for the given item using the entity’s sort key builder.

Partial<EntitySchema<Schema>>

| DynamoKeyableValue | undefined


paginate<CommandOutput>(paginatable): AsyncGenerator<CommandOutput, void, unknown>;

Paginates through results of a paginatable command for this entity’s table.

CommandOutput

BasePaginatable<CommandOutput, Schema>

AsyncGenerator<CommandOutput, void, unknown>


send<CommandOutput>(command): Promise<CommandOutput>;

Sends a command to be executed against this entity’s table.

CommandOutput

BaseCommand<CommandOutput, Schema>

Promise<CommandOutput>