Core module for the Decaf TypeScript framework
Interfaces
- AttributeOption
Operator
Option Interface- ConditionBuilderOption
Exposes the available operations for building database query conditions
- CountOption
Count Option Interface
- DistinctOption
Distinct Option Interface
- ErrorParser
Defines a contract for objects that can parse generic Error objects into BaseError instances
- Executor
Defines a contract for objects that can execute an operation and return a result
- FromOption
From Option Interface
- GroupByOption
GroupBy Option interface
- InsertOption
Insert Option Interface
- IntoOption
Into Option Interface
- LimitOption
Limit Option interface
- MaxOption
Max Option Interface
- MinOption
Min Option Interface
- Observable
Defines a contract for objects that implement the Observer pattern, allowing them to register observers, remove observers, and notify all registered observers of state changes
- Observer
Defines a contract for objects that implement the Observer pattern, allowing them to be notified of changes in Observable objects
- OffsetOption
Offset Option interface
- OrderAndGroupOption
Groups several order and grouping options
- OrderByOption
OrderBy Option interface
- Paginatable
Defines a contract for objects that can paginate their results, allowing for efficient data retrieval in chunks
- Queriable
Defines a contract for objects that can be queried with various conditions, selections, and ordering
- RamFlags
Interface that extends the base repository flags with RAM-specific flags. Contains user identification information needed for tracking entity creation and updates.
- RawExecutor
Defines a contract for objects that can execute raw queries of a specific type and return results
- SelectOption
Select Option Interface
- SequenceOptions
Defines the configuration options for creating and managing sequences
- ThenByOption
OrderBy Option interface
- ValuesOption
Valuest Option Interface
- WhereOption
Where Option interface
Members
# static constant BigIntSequence
Configuration for BigInt sequences starting at 0 and incrementing by 1
Predefined options for BigInt sequences
CascadeMetadata
# static constant DefaultCascade
Provides the default cascade behavior where updates cascade but deletes do not.
Default cascade configuration for entity relationships.
# static constant DefaultSequenceOptions
Provides a standard configuration for number sequences starting at 0 and incrementing by 1
Default options for sequences
# static constant NumericSequence
Configuration for standard number sequences starting at 0 and incrementing by 1
Predefined options for numeric sequences
# static constant RamFlavour
A constant string that uniquely identifies the RAM adapter in the system. Used for adapter type identification and configuration.
Identifier for the RAM adapter
# static constant VERSION
A constant representing the version of the core package
Stores the current package version
# static constant commomTypes
An array of strings representing common JavaScript types that are not custom model types
List of common JavaScript types
string
# static readonly exports.Cascade
Defines the available cascade behaviors for entity relationships.
Enumeration of cascade operation types.
string
# static readonly exports.GroupOperator
Enum defining the available operators for grouping multiple conditions in database queries
Logical operators for combining query conditions
string
# static readonly exports.Operator
Enum defining the available operators for comparing values in database queries
Comparison operators for query conditions
string
# static readonly exports.OrderDirection
Defines the available sort directions for ordering query results.
Enumeration of possible sort directions.
string
# static readonly exports.PersistenceKeys
Enum containing string constants used throughout the persistence layer for metadata, relations, and other persistence-related operations
Persistence-related constant keys
Methods
# static cacheModelForPopulate(context, parentModel, propertyKey, pkValue, cacheValue) → {Promise.<any>}
Stores a model in the context cache for efficient retrieval during relationship population
Caches a model for later population
Parameters:
Name | Type | Description |
---|---|---|
context |
Context.<F>
|
The context for the operation |
parentModel |
M
|
The parent model that contains the relationship |
propertyKey |
The property key of the relationship |
|
pkValue |
string
|
number
|
The primary key value of the related model |
cacheValue |
any
|
The model instance to cache |
A promise that resolves with the result of the cache operation
Promise.<any>
# static createOrUpdate(model, context, repositoryopt) → {Promise.<M>}
Determines whether to create a new model or update an existing one based on the presence of a primary key
Creates or updates a model instance
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
model |
M
|
The model instance to create or update |
|
context |
Context.<F>
|
The context for the operation |
|
repository |
Repo.<M, F, Context.<F>>
|
<optional> |
Optional repository to use for the operation |
A promise that resolves to the created or updated model
Promise.<M>
# static createdByOnCreateUpdate(this, context, data, key, model) → {Promise.<void>}
Internal function used by the createdBy and updatedBy decorators to set ownership information
Handles user identification for ownership tracking
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The metadata for the property |
key |
The property key to store the user identifier |
|
model |
M
|
The model instance being created or updated |
A promise that rejects with an AuthorizationError if user identification is not supported
Promise.<void>
# static createdByOnRamCreateUpdate(this, context, data, key, model) → {Promise.<void>}
Automatically populates a model field with the UUID from the context during create or update operations. This function is designed to be used as a handler for RAM operations to track entity creation.
Sets the created by field on a model during RAM create/update operations
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The operation context containing user identification |
data |
V
|
The relations metadata |
key |
The property key to set with the UUID |
|
model |
M
|
The model instance being created/updated |
A promise that resolves when the field has been set
Promise.<void>
# static generateInjectableNameForRepository(model, flavouropt) → {string}
Creates a standardized name for repository injectables based on model and adapter flavour.
Generates a unique injectable name for a repository.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
model |
Constructor.<T>
|
T
|
The model constructor or instance. |
|
flavour |
string
|
<optional> |
Optional adapter flavour. If not provided, it will be retrieved from the model metadata. |
If no flavour is provided and none can be retrieved from the model.
InternalError
The generated injectable name.
string
# static getPopulateKey(tableName, fieldName, id) → {string}
Creates a unique key for storing and retrieving populated model relationships in the cache
Generates a key for caching populated model relationships
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string
|
The name of the table or model |
fieldName |
string
|
The name of the field or property |
id |
string
|
number
|
The identifier of the related model |
A dot-separated string that uniquely identifies the relationship
string
# static getTableName(model) → {string}
Retrieves the table name associated with a model by checking metadata or falling back to the constructor name
Gets the table name for a model
Parameters:
Name | Type | Description |
---|---|---|
model |
M
|
Constructor.<M>
|
The model instance or constructor to get the table name for |
The table name for the model
string
# static oneToManyOnCreate(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-many relationship when creating a model, either by referencing existing models or creating new ones
Handles one-to-many relationship creation
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static oneToManyOnDelete(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-many relationship when deleting a model, deleting all related models if cascade delete is enabled
Handles one-to-many relationship deletion
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static oneToManyOnUpdate(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-many relationship when updating a model, delegating to oneToManyOnCreate if cascade update is enabled
Handles one-to-many relationship updates
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static oneToOneOnCreate(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-one relationship when creating a model, either by referencing an existing model or creating a new one
Handles one-to-one relationship creation
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
string
|
The property key of the relationship |
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static oneToOneOnDelete(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-one relationship when deleting a model, deleting the related model if cascade is enabled
Handles one-to-one relationship deletion
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static oneToOneOnUpdate(this, context, data, key, model) → {Promise.<void>}
Processes a one-to-one relationship when updating a model, either by referencing an existing model or updating the related model
Handles one-to-one relationship updates
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static populate(this, context, data, key, model) → {Promise.<void>}
Retrieves and attaches related models to a model's relationship property
Populates a model's relationship
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The relations metadata |
key |
The property key of the relationship |
|
model |
M
|
The model instance |
A promise that resolves when the operation is complete
Promise.<void>
# static repositoryFromTypeMetadata(model, propertyKey) → {Repo.<M>}
Examines a model property's type metadata to determine the appropriate repository for related models
Retrieves a repository for a model property based on its type metadata
Parameters:
Name | Type | Description |
---|---|---|
model |
any
|
The model instance containing the property |
propertyKey |
The property key to examine |
A repository for the model type associated with the property
Repo.<M>
# static sequenceNameForModel(model, …args) → {string}
Creates a standardized sequence name by combining the table name with additional arguments
Generates a sequence name for a model
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
model |
M
|
Constructor.<M>
|
The model instance or constructor to generate the sequence name for |
|
args |
string
|
<repeatable> |
Additional string arguments to append to the sequence name |
The generated sequence name
string
# static uniqueOnCreateUpdate(this, context, data, key, model) → {Promise.<void>}
Internal function used by the unique decorator to check if a property value already exists in the database
Enforces uniqueness constraint during model creation and update
Parameters:
Name | Type | Description |
---|---|---|
this |
R
|
The repository instance |
context |
Context.<F>
|
The context for the operation |
data |
V
|
The metadata for the property |
key |
The property key to check for uniqueness |
|
model |
M
|
The model instance being created or updated |
A promise that resolves when the check is complete or rejects with a ConflictError
Promise.<void>
Type Definitions
object
# CascadeMetadata
Defines how update and delete operations should cascade to related entities.
Metadata for cascade operations on related entities.
Properties:
string
|
number
|
bigint
|
Array.<string>
|
Array.<number>
|
Array.<bigint>
# EventIds
A union type that defines the possible formats for event identifiers in the persistence layer. These can be single values (string, number, bigint) or arrays of these types.
Type representing possible ID formats for database events
Constructor.<M>
|
string
# FromSelector
Defines the type for specifying the table or model to query from
Type for selecting the data source in a query
number
# LimitSelector
Defines the type for specifying the maximum number of results to return
Type for limiting query results
object
# NamedIndexMetadata
Extends IndexMetadata with a suffix to identify the index.
Metadata for a named index that extends IndexMetadata.
Properties:
Name | Type | Description |
---|---|---|
suffix |
string
|
The suffix to append to the index name. |
suffix |
string
|
# ObserverFilter(table, event, id, table, event, id) → {boolean}
A function type that defines a predicate used to determine whether an observer should be notified about a specific database event. The filter examines the table name, event type, and affected IDs.
Function type for filtering observer notifications
Parameters:
Name | Type | Description |
---|---|---|
table |
string
|
The name of the database table where the event occurred |
event |
OperationKeys
|
BulkCrudOperationKeys
|
string
|
The type of operation that triggered the event |
id |
EventIds
|
The identifier(s) of the affected record(s) |
table |
string
|
|
event |
OperationKeys
|
BulkCrudOperationKeys
|
string
|
|
id |
EventIds
|
True if the observer should be notified, false otherwise
boolean
number
# OffsetSelector
Defines the type for specifying the number of results to skip
Type for offsetting query results
Object
# RawRamQuery
Defines the structure of a query for retrieving data from the in-memory storage. It specifies what fields to select, which model to query, filtering conditions, sorting criteria, and pagination options.
Query specification for RAM adapter
Properties:
Name | Type | Attributes | Description |
---|---|---|---|
select |
Fields to select from the model, or undefined for all fields |
||
from |
Constructor.<M>
|
The model constructor to query |
|
where |
function
|
Predicate function for filtering entities |
|
sort |
function
|
<optional> |
Optional comparator function for sorting results |
limit |
number
|
<optional> |
Optional maximum number of results to return |
skip |
number
|
<optional> |
Optional number of results to skip (for pagination) |
select |
undefined
|
Array
|
||
from |
Constructor.<M>
|
||
where |
function
|
||
sort |
function
|
<optional> |
|
limit |
number
|
<optional> |
|
skip |
number
|
<optional> |