DynamoEntity
Core class that represents a DynamoDB entity.
Type Parameters
Section titled “Type Parameters”Schema
Section titled “Schema”Schema extends ZodObject
The Zod schema representing the entity’s structure.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new DynamoEntity<Schema>(config): DynamoEntity<Schema>;Parameters
Section titled “Parameters”config
Section titled “config”DynamoEntityConfig<Schema>
Returns
Section titled “Returns”DynamoEntity<Schema>
Accessors
Section titled “Accessors”schema
Section titled “schema”Get Signature
Section titled “Get Signature”get schema(): Schema;Gets the Zod schema defining the structure of this entity.
Returns
Section titled “Returns”Schema
secondaryIndexKeyBuilders
Section titled “secondaryIndexKeyBuilders”Get Signature
Section titled “Get Signature”get secondaryIndexKeyBuilders(): object;Gets the key builders for the secondary indexes defined on this entity.
Returns
Section titled “Returns”object
gsi: GlobalSecondaryIndexKeyBuilders<EntitySchema<Schema>>;lsi: LocalSecondaryIndexKeyBuilders<EntitySchema<Schema>>;Get Signature
Section titled “Get Signature”get table(): DynamoTable;Gets the DynamoDB table associated with this entity.
Returns
Section titled “Returns”Methods
Section titled “Methods”buildAllKeys()
Section titled “buildAllKeys()”buildAllKeys(item): DynamoKey;Builds all keys (primary and secondary index keys) for the given item.
Parameters
Section titled “Parameters”Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”buildGlobalSecondaryIndexKey()
Section titled “buildGlobalSecondaryIndexKey()”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.
Parameters
Section titled “Parameters”indexName
Section titled “indexName”string
Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”buildLocalSecondaryIndexKey()
Section titled “buildLocalSecondaryIndexKey()”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.
Parameters
Section titled “Parameters”indexName
Section titled “indexName”string
Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”buildPartitionKey()
Section titled “buildPartitionKey()”buildPartitionKey(item): | DynamoKeyableValue | undefined;Builds the partition key for the given item using the entity’s partition key builder.
Parameters
Section titled “Parameters”Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”| DynamoKeyableValue
| undefined
buildPrimaryKey()
Section titled “buildPrimaryKey()”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.
Parameters
Section titled “Parameters”Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”buildPrimaryOrIndexKey()
Section titled “buildPrimaryOrIndexKey()”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.
Parameters
Section titled “Parameters”keyInput
Section titled “keyInput”EntityKeyInput<EntitySchema<Schema>>
Returns
Section titled “Returns”Throws
Section titled “Throws”DocumentBuilderError if the index name is missing or not defined on the entity.
buildSortKey()
Section titled “buildSortKey()”buildSortKey(item): | DynamoKeyableValue | undefined;Builds the sort key for the given item using the entity’s sort key builder.
Parameters
Section titled “Parameters”Partial<EntitySchema<Schema>>
Returns
Section titled “Returns”| DynamoKeyableValue
| undefined
paginate()
Section titled “paginate()”paginate<CommandOutput>(paginatable): AsyncGenerator<CommandOutput, void, unknown>;Paginates through results of a paginatable command for this entity’s table.
Type Parameters
Section titled “Type Parameters”CommandOutput
Section titled “CommandOutput”CommandOutput
Parameters
Section titled “Parameters”paginatable
Section titled “paginatable”BasePaginatable<CommandOutput, Schema>
Returns
Section titled “Returns”AsyncGenerator<CommandOutput, void, unknown>
send()
Section titled “send()”send<CommandOutput>(command): Promise<CommandOutput>;Sends a command to be executed against this entity’s table.
Type Parameters
Section titled “Type Parameters”CommandOutput
Section titled “CommandOutput”CommandOutput
Parameters
Section titled “Parameters”command
Section titled “command”BaseCommand<CommandOutput, Schema>
Returns
Section titled “Returns”Promise<CommandOutput>