Module

core

Core module for the Decaf TypeScript framework

View Source index.ts, line 2

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

View Source interfaces/SequenceOptions.ts, line 26

CascadeMetadata

# static constant DefaultCascade

Provides the default cascade behavior where updates cascade but deletes do not.

Default cascade configuration for entity relationships.

View Source repository/constants.ts, line 30

# static constant DefaultSequenceOptions

Provides a standard configuration for number sequences starting at 0 and incrementing by 1

Default options for sequences

View Source interfaces/SequenceOptions.ts, line 2

# static constant NumericSequence

Configuration for standard number sequences starting at 0 and incrementing by 1

Predefined options for numeric sequences

View Source interfaces/SequenceOptions.ts, line 14

# 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

View Source ram/constants.ts, line 2

# static constant VERSION

A constant representing the version of the core package

Stores the current package version

View Source index.ts, line 21

# static constant commomTypes

An array of strings representing common JavaScript types that are not custom model types

List of common JavaScript types

View Source model/construction.ts, line 569

string

# static readonly exports.Cascade

Defines the available cascade behaviors for entity relationships.

Enumeration of cascade operation types.

View Source repository/constants.ts, line 23

string

# static readonly exports.GroupOperator

Enum defining the available operators for grouping multiple conditions in database queries

Logical operators for combining query conditions

View Source query/constants.ts, line 39

string

# static readonly exports.Operator

Enum defining the available operators for comparing values in database queries

Comparison operators for query conditions

View Source query/constants.ts, line 9

string

# static readonly exports.OrderDirection

Defines the available sort directions for ordering query results.

Enumeration of possible sort directions.

View Source repository/constants.ts, line 9

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

View Source persistence/constants.ts, line 9

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

View Source model/construction.ts, line 467

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

sequenceDiagram participant Caller participant createOrUpdate participant Repository participant Model Caller->>createOrUpdate: model, context, repository? alt repository not provided createOrUpdate->>Model: get(model.constructor.name) Model-->>createOrUpdate: constructor createOrUpdate->>Repository: forModel(constructor) Repository-->>createOrUpdate: repository end alt primary key undefined createOrUpdate->>Repository: create(model, context) Repository-->>createOrUpdate: created model else primary key defined createOrUpdate->>Repository: update(model, context) alt update successful Repository-->>createOrUpdate: updated model else NotFoundError createOrUpdate->>Repository: create(model, context) Repository-->>createOrUpdate: created model end end createOrUpdate-->>Caller: model
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

View Source model/construction.ts, line 7

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

View Source model/decorators.ts, line 93

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

View Source ram/handlers.ts, line 3

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.

View Source repository/utils.ts, line 8

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

View Source model/construction.ts, line 454

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

View Source identity/utils.ts, line 5

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

sequenceDiagram participant Caller participant oneToManyOnCreate participant repositoryFromTypeMetadata participant createOrUpdate participant findPrimaryKey participant cacheModelForPopulate Caller->>oneToManyOnCreate: this, context, data, key, model oneToManyOnCreate->>oneToManyOnCreate: check if propertyValues exists and has length oneToManyOnCreate->>oneToManyOnCreate: check if all elements have same type oneToManyOnCreate->>oneToManyOnCreate: create uniqueValues set alt arrayType is not "object" oneToManyOnCreate->>repositoryFromTypeMetadata: model, key repositoryFromTypeMetadata-->>oneToManyOnCreate: repo loop for each id in uniqueValues oneToManyOnCreate->>repo: read(id) repo-->>oneToManyOnCreate: read oneToManyOnCreate->>cacheModelForPopulate: context, model, key, id, read end oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...uniqueValues] else arrayType is "object" oneToManyOnCreate->>findPrimaryKey: propertyValues[0] findPrimaryKey-->>oneToManyOnCreate: pkName oneToManyOnCreate->>oneToManyOnCreate: create result set loop for each m in propertyValues oneToManyOnCreate->>createOrUpdate: m, context createOrUpdate-->>oneToManyOnCreate: record oneToManyOnCreate->>cacheModelForPopulate: context, model, key, record[pkName], record oneToManyOnCreate->>oneToManyOnCreate: add record[pkName] to result end oneToManyOnCreate->>oneToManyOnCreate: set model[key] = [...result] end oneToManyOnCreate-->>Caller: void
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

View Source model/construction.ts, line 258

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

sequenceDiagram participant Caller participant oneToManyOnDelete participant Repository participant repositoryFromTypeMetadata participant cacheModelForPopulate Caller->>oneToManyOnDelete: this, context, data, key, model oneToManyOnDelete->>oneToManyOnDelete: check if cascade.delete is CASCADE oneToManyOnDelete->>oneToManyOnDelete: check if values exists and has length oneToManyOnDelete->>oneToManyOnDelete: check if all elements have same type alt isInstantiated (arrayType is "object") oneToManyOnDelete->>Repository: forModel(values[0]) Repository-->>oneToManyOnDelete: repo else not instantiated oneToManyOnDelete->>repositoryFromTypeMetadata: model, key repositoryFromTypeMetadata-->>oneToManyOnDelete: repo end oneToManyOnDelete->>oneToManyOnDelete: create uniqueValues set loop for each id in uniqueValues oneToManyOnDelete->>repo: delete(id, context) repo-->>oneToManyOnDelete: deleted oneToManyOnDelete->>cacheModelForPopulate: context, model, key, id, deleted end oneToManyOnDelete->>oneToManyOnDelete: set model[key] = [...uniqueValues] oneToManyOnDelete-->>Caller: void
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

View Source model/construction.ts, line 381

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

sequenceDiagram participant Caller participant oneToManyOnUpdate participant oneToManyOnCreate Caller->>oneToManyOnUpdate: this, context, data, key, model oneToManyOnUpdate->>oneToManyOnUpdate: check if cascade.update is CASCADE alt cascade.update is CASCADE oneToManyOnUpdate->>oneToManyOnCreate: apply(this, [context, data, key, model]) oneToManyOnCreate-->>oneToManyOnUpdate: void end oneToManyOnUpdate-->>Caller: void
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

View Source model/construction.ts, line 338

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

sequenceDiagram participant Caller participant oneToOneOnCreate participant repositoryFromTypeMetadata participant Model participant Repository participant cacheModelForPopulate Caller->>oneToOneOnCreate: this, context, data, key, model oneToOneOnCreate->>oneToOneOnCreate: check if propertyValue exists alt propertyValue is not an object oneToOneOnCreate->>repositoryFromTypeMetadata: model, key repositoryFromTypeMetadata-->>oneToOneOnCreate: innerRepo oneToOneOnCreate->>innerRepo: read(propertyValue) innerRepo-->>oneToOneOnCreate: read oneToOneOnCreate->>cacheModelForPopulate: context, model, key, propertyValue, read oneToOneOnCreate->>oneToOneOnCreate: set model[key] = propertyValue else propertyValue is an object oneToOneOnCreate->>Model: get(data.class) Model-->>oneToOneOnCreate: constructor oneToOneOnCreate->>Repository: forModel(constructor) Repository-->>oneToOneOnCreate: repo oneToOneOnCreate->>repo: create(propertyValue) repo-->>oneToOneOnCreate: created oneToOneOnCreate->>findPrimaryKey: created findPrimaryKey-->>oneToOneOnCreate: pk oneToOneOnCreate->>cacheModelForPopulate: context, model, key, created[pk], created oneToOneOnCreate->>oneToOneOnCreate: set model[key] = created[pk] end oneToOneOnCreate-->>Caller: void
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

View Source model/construction.ts, line 68

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

sequenceDiagram participant Caller participant oneToOneOnDelete participant repositoryFromTypeMetadata participant cacheModelForPopulate Caller->>oneToOneOnDelete: this, context, data, key, model oneToOneOnDelete->>oneToOneOnDelete: check if propertyValue exists oneToOneOnDelete->>oneToOneOnDelete: check if cascade.update is CASCADE oneToOneOnDelete->>repositoryFromTypeMetadata: model, key repositoryFromTypeMetadata-->>oneToOneOnDelete: innerRepo alt propertyValue is not a Model instance oneToOneOnDelete->>innerRepo: delete(model[key], context) innerRepo-->>oneToOneOnDelete: deleted else propertyValue is a Model instance oneToOneOnDelete->>innerRepo: delete(model[key][innerRepo.pk], context) innerRepo-->>oneToOneOnDelete: deleted end oneToOneOnDelete->>cacheModelForPopulate: context, model, key, deleted[innerRepo.pk], deleted oneToOneOnDelete-->>Caller: void
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

View Source model/construction.ts, line 203

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

sequenceDiagram participant Caller participant oneToOneOnUpdate participant repositoryFromTypeMetadata participant createOrUpdate participant findPrimaryKey participant cacheModelForPopulate Caller->>oneToOneOnUpdate: this, context, data, key, model oneToOneOnUpdate->>oneToOneOnUpdate: check if propertyValue exists oneToOneOnUpdate->>oneToOneOnUpdate: check if cascade.update is CASCADE alt propertyValue is not an object oneToOneOnUpdate->>repositoryFromTypeMetadata: model, key repositoryFromTypeMetadata-->>oneToOneOnUpdate: innerRepo oneToOneOnUpdate->>innerRepo: read(propertyValue) innerRepo-->>oneToOneOnUpdate: read oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, propertyValue, read oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = propertyValue else propertyValue is an object oneToOneOnUpdate->>createOrUpdate: model[key], context createOrUpdate-->>oneToOneOnUpdate: updated oneToOneOnUpdate->>findPrimaryKey: updated findPrimaryKey-->>oneToOneOnUpdate: pk oneToOneOnUpdate->>cacheModelForPopulate: context, model, key, updated[pk], updated oneToOneOnUpdate->>oneToOneOnUpdate: set model[key] = updated[pk] end oneToOneOnUpdate-->>Caller: void
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

View Source model/construction.ts, line 138

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

sequenceDiagram participant Caller participant populate participant fetchPopulateValues participant getPopulateKey participant Context participant repositoryFromTypeMetadata Caller->>populate: this, context, data, key, model populate->>populate: check if data.populate is true populate->>populate: get nested value and check if it exists populate->>fetchPopulateValues: context, model, key, isArr ? nested : [nested] fetchPopulateValues->>fetchPopulateValues: initialize variables loop for each proKeyValue in propKeyValues fetchPopulateValues->>getPopulateKey: model.constructor.name, propName, proKeyValue getPopulateKey-->>fetchPopulateValues: cacheKey alt try to get from cache fetchPopulateValues->>Context: get(cacheKey) Context-->>fetchPopulateValues: val else catch error fetchPopulateValues->>repositoryFromTypeMetadata: model, propName repositoryFromTypeMetadata-->>fetchPopulateValues: repo fetchPopulateValues->>repo: read(proKeyValue) repo-->>fetchPopulateValues: val end fetchPopulateValues->>fetchPopulateValues: add val to results end fetchPopulateValues-->>populate: results populate->>populate: set model[key] = isArr ? res : res[0] populate-->>Caller: void
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

View Source model/construction.ts, line 485

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

sequenceDiagram participant Caller participant repositoryFromTypeMetadata participant Reflect participant Validation participant Model participant Repository Caller->>repositoryFromTypeMetadata: model, propertyKey repositoryFromTypeMetadata->>Validation: key(Array.isArray(model[propertyKey]) ? ValidationKeys.LIST : ValidationKeys.TYPE) Validation-->>repositoryFromTypeMetadata: validationKey repositoryFromTypeMetadata->>Reflect: getMetadata(validationKey, model, propertyKey) Reflect-->>repositoryFromTypeMetadata: types repositoryFromTypeMetadata->>repositoryFromTypeMetadata: determine customTypes based on property type repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if types and customTypes exist repositoryFromTypeMetadata->>repositoryFromTypeMetadata: create allowedTypes array repositoryFromTypeMetadata->>repositoryFromTypeMetadata: find constructorName not in commomTypes repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructorName exists repositoryFromTypeMetadata->>Model: get(constructorName) Model-->>repositoryFromTypeMetadata: constructor repositoryFromTypeMetadata->>repositoryFromTypeMetadata: check if constructor exists repositoryFromTypeMetadata->>Repository: forModel(constructor) Repository-->>repositoryFromTypeMetadata: repo repositoryFromTypeMetadata-->>Caller: repo
Parameters:
Name Type Description
model any

The model instance containing the property

propertyKey

The property key to examine

View Source model/construction.ts, line 587

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

View Source identity/utils.ts, line 25

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

View Source model/decorators.ts, line 49

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:
Name Type Description
update Cascade

Determines cascade behavior for update operations.

delete Cascade

Determines cascade behavior for delete operations.

update Cascade
delete Cascade

View Source repository/types.ts, line 5

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

View Source persistence/types.ts, line 5

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

View Source query/selectors.ts, line 6

number

# LimitSelector

Defines the type for specifying the maximum number of results to return

Type for limiting query results

View Source query/selectors.ts, line 16

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

View Source repository/types.ts, line 17

# 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

View Source persistence/types.ts, line 13

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

View Source query/selectors.ts, line 23

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>

View Source ram/types.ts, line 9