AbstractReadonlycreatedThe timestamp marking when the entity was created
ReadonlyidA unique identifier for the entity itself, automatically generated upon creation.
ReadonlytypeThe type of the entity. Set automatically to the class name at runtime.
Each entity must narrow this field to a string literal matching the class name
via declare readonly type: "ClassName". This enables compile-time type safety
for query filters and return type narrowing.
ReadonlyupdatedThe timestamp marking the last update to the entity. Initially set to the same value as createdAt.
Same as the static update method but on an instance. Returns the full updated instance.
For @ObjectAttribute fields, the returned instance deep merges the partial update
with the existing object value — omitted fields are preserved, and fields set to null
are removed.
Optionaloptions: { referentialIntegrityCheck?: boolean }const updatedInstance = await instance.update({ email: "newemail@example.com", profileId: 789 });
const updatedInstance = await instance.update({ email: "newemail@example.com", someKey: null });
StaticcreateCreate an entity. If foreign keys are included in the attributes then links will be denormalized accordingly
Attributes of the model to create
Optionaloptions: { referentialIntegrityCheck?: boolean }Optional operation options including referentialIntegrityCheck flag
The new Entity
StaticdeleteDelete an entity by ID
The id of the entity to update
StaticfindFind an entity by Id and optionally include associations.
Entity Id.
Optionaloptions: undefinedNo options provided, returns the entity without included associations.
An entity without included associations serialized.
Find an entity by Id and optionally include associations.
Entity Id.
No options provided, returns the entity without included associations.
An entity without included associations serialized.
StaticmetadataReturns serialized table metadata containing only serializable values. This method returns a plain object representation of the table metadata, with functions, class instances, and other non-serializable data converted to their string representations or omitted.
A plain object representation of the table metadata
StaticpartitionStaticqueryQuery an EntityPartition by EntityId (string) or by PartitionKey/SortKey conditions (object). QueryByIndex not supported with this overload. Use Query with keys and indexName option if needed.
Filter key validation: Filter keys are strongly typed to only accept valid attribute
names from the entity and its declared relationships (@HasMany, @HasOne, @BelongsTo,
@HasAndBelongsToMany). The type field only accepts the entity itself or its related
entity names — entities from other tables or unrelated entities are rejected.
When type is specified as a single value in a $or block, filter keys are narrowed to
that entity's attributes.
Sort key validation: Both skCondition (string form) and sk (object key form) only
accept the entity itself or its related entity names, matching dyna-record's single-table
sort key format where SK values always start with an entity class name. Unrelated entities
and entities from other tables are rejected at compile time.
SK-scoped filter: When skCondition narrows to specific entities, the filter
parameter is scoped to only those entities' attributes. For example,
skCondition: { $beginsWith: "Order" } restricts the filter to Order's attributes —
using attributes from other entities (e.g., lastFour from PaymentMethod) produces a
compile error.
$beginsWith prefix matching: $beginsWith accepts partial entity name prefixes
that match multiple entity types. For example, $beginsWith: "Inv" matches both
"Invoice" and "Inventory". The return type and filter are scoped to the union of
all matching entities.
Return type narrowing: The return type narrows automatically based on:
type: type: "Order" → Array<EntityAttributesInstance<Order>>type array: type: ["Order", "PaymentMethod"] → union of both{ orderDate: "2023" } → narrows to entities that have orderDate$or elements: each block narrows by type (if present) or by filter keys; return type is the union$or both narrow, the return type is their intersection. Empty intersection → never[].skCondition option: always intersected with filter narrowing. skCondition: "Order" or { $beginsWith: "Order" } → narrows to Order. { $beginsWith: "Inv" } → narrows to all entities starting with "Inv".Customer | Order | PaymentMethod | ContactInformation)Note: When using the object key form ({ pk: "...", sk: "Order" }), the sk value is
validated against entity names but does not narrow the return type due to a TypeScript
inference limitation. Use filter: { type: "Order" } or the skCondition option for
return type narrowing.
The entity type being queried.
The inferred sort key condition type, captured via const generic for literal type inference.
The inferred filter type, captured via const generic. Constrained by SKScopedFilterParams — when SK narrows, only matched entities' attributes are accepted.
Entity Id (string) or an object with PartitionKey and optional SortKey conditions.
Optionaloptions: Omit<QueryOptions, "filter" | "indexName" | "skCondition"> & {QueryOptions. Supports typed filter, consistentRead and skCondition. indexName is not supported.
Typed filter conditions. Keys are validated against partition entity attributes, scoped by skCondition when present. The type field accepts valid entity class names within the SK scope.
Sort key condition. Accepts entity names, entity-name-prefixed strings, or $beginsWith with exact names or partial prefixes. Narrows the return type and scopes the filter to matched entities.
Optionalfilter?: SKScopedFilterParams<T, SK>Typed filter conditions. Keys are validated against partition entity attributes, scoped by skCondition when present. The type field accepts valid entity class names within the SK scope.
Optionalfilter?: FTyped filter conditions. Keys are validated against partition entity attributes, scoped by skCondition when present. The type field accepts valid entity class names within the SK scope.
OptionalskCondition?: SKSort key condition. Accepts entity names, entity-name-prefixed strings, or $beginsWith with exact names or partial prefixes. Narrows the return type and scopes the filter to matched entities.
A promise resolving to query results. The return type narrows based on the filter's type value, filter keys, and skCondition.
const orders = await Customer.query("123", { skCondition: "Order" });
// orders is Array<EntityAttributesInstance<Order>>
const orders = await Customer.query("123", { skCondition: { $beginsWith: "Order" } });
// orders is Array<EntityAttributesInstance<Order>>
const results = await Customer.query("123", { skCondition: { $beginsWith: "C" } });
// results includes Customer and ContactInformation (both start with "C")
// filter accepts attributes from both entities
const orders = await Customer.query("123", {
skCondition: { $beginsWith: "Order" },
filter: { type: "Order", orderDate: "2023-01-01" }
});
// orders is Array<EntityAttributesInstance<Order>>
// filter: { lastFour: "1234" } would be a compile error (PaymentMethod attribute)
const results = await Customer.query({ pk: "Customer#123", sk: "Order" });
// results is QueryResults<Customer> — use filter type for narrowing
Query an EntityPartition by EntityId (string) or by PartitionKey/SortKey conditions (object). QueryByIndex not supported with this overload. Use Query with keys and indexName option if needed.
Filter key validation: Filter keys are strongly typed to only accept valid attribute
names from the entity and its declared relationships (@HasMany, @HasOne, @BelongsTo,
@HasAndBelongsToMany). The type field only accepts the entity itself or its related
entity names — entities from other tables or unrelated entities are rejected.
When type is specified as a single value in a $or block, filter keys are narrowed to
that entity's attributes.
Sort key validation: Both skCondition (string form) and sk (object key form) only
accept the entity itself or its related entity names, matching dyna-record's single-table
sort key format where SK values always start with an entity class name. Unrelated entities
and entities from other tables are rejected at compile time.
SK-scoped filter: When skCondition narrows to specific entities, the filter
parameter is scoped to only those entities' attributes. For example,
skCondition: { $beginsWith: "Order" } restricts the filter to Order's attributes —
using attributes from other entities (e.g., lastFour from PaymentMethod) produces a
compile error.
$beginsWith prefix matching: $beginsWith accepts partial entity name prefixes
that match multiple entity types. For example, $beginsWith: "Inv" matches both
"Invoice" and "Inventory". The return type and filter are scoped to the union of
all matching entities.
Return type narrowing: The return type narrows automatically based on:
type: type: "Order" → Array<EntityAttributesInstance<Order>>type array: type: ["Order", "PaymentMethod"] → union of both{ orderDate: "2023" } → narrows to entities that have orderDate$or elements: each block narrows by type (if present) or by filter keys; return type is the union$or both narrow, the return type is their intersection. Empty intersection → never[].skCondition option: always intersected with filter narrowing. skCondition: "Order" or { $beginsWith: "Order" } → narrows to Order. { $beginsWith: "Inv" } → narrows to all entities starting with "Inv".Customer | Order | PaymentMethod | ContactInformation)Note: When using the object key form ({ pk: "...", sk: "Order" }), the sk value is
validated against entity names but does not narrow the return type due to a TypeScript
inference limitation. Use filter: { type: "Order" } or the skCondition option for
return type narrowing.
The entity type being queried.
The inferred filter type, captured via const generic. Constrained by SKScopedFilterParams — when SK narrows, only matched entities' attributes are accepted.
Entity Id (string) or an object with PartitionKey and optional SortKey conditions.
Optionaloptions: Omit<OptionsWithoutIndex<T>, "skCondition"> & { filter?: F }QueryOptions. Supports typed filter, consistentRead and skCondition. indexName is not supported.
Typed filter conditions. Keys are validated against partition entity attributes, scoped by skCondition when present. The type field accepts valid entity class names within the SK scope.
Sort key condition. Accepts entity names, entity-name-prefixed strings, or $beginsWith with exact names or partial prefixes. Narrows the return type and scopes the filter to matched entities.
Optionalfilter?: FTyped filter conditions. Keys are validated against partition entity attributes, scoped by skCondition when present. The type field accepts valid entity class names within the SK scope.
A promise resolving to query results. The return type narrows based on the filter's type value, filter keys, and skCondition.
const orders = await Customer.query("123", { skCondition: "Order" });
// orders is Array<EntityAttributesInstance<Order>>
const orders = await Customer.query("123", { skCondition: { $beginsWith: "Order" } });
// orders is Array<EntityAttributesInstance<Order>>
const results = await Customer.query("123", { skCondition: { $beginsWith: "C" } });
// results includes Customer and ContactInformation (both start with "C")
// filter accepts attributes from both entities
const orders = await Customer.query("123", {
skCondition: { $beginsWith: "Order" },
filter: { type: "Order", orderDate: "2023-01-01" }
});
// orders is Array<EntityAttributesInstance<Order>>
// filter: { lastFour: "1234" } would be a compile error (PaymentMethod attribute)
const results = await Customer.query({ pk: "Customer#123", sk: "Order" });
// results is QueryResults<Customer> — use filter type for narrowing
Query by PartitionKey and optional SortKey/Filter/Index conditions with an index When querying on an index, any of the entities attributes can be part of the key condition
Any attribute defined on the entity that is part of an index's keys
QueryBuilderOptions
StatictableTakes a table item and serializes it to an entity instance
StaticupdateUpdate an entity. If foreign keys are included in the attributes then:
The id of the entity to update
Attributes to update
Optionaloptions: { referentialIntegrityCheck?: boolean }Optional operation options including referentialIntegrityCheck flag
await User.update("userId", { email: "newemail@example.com", profileId: 789 });
await User.update("userId", { email: "newemail@example.com", someKey: null });
Serves as an abstract base class for entities in the ORM system. It defines standard fields such as
id,type,createdAt, andupdatedAt, and provides static methods for CRUD operations and queries. This class encapsulates common behaviors and properties that all entities share, leveraging decorators for attribute metadata and supporting operations like finding, creating, updating, and deleting entities.Table classes should extend this class, and each entity should extend the table class
Entities extending
DynaRecordcan utilize these operations to interact with their corresponding records in the database, including handling relationships between different entities.Example