Module

db-decorators

Database decorators for TypeScript applications

View Source index.ts, line 10

Interfaces

BulkCrudOperator

Extends the basic CRUD operations to support bulk operations on multiple models at once

Contextual

Provides context management for database operations

CrudOperator

Exposes a standard Create, Read, Update, Delete API for database operations

IRepository

Interface holding basic CRUD APIs for database models, providing standard operations and metadata

RepositoryFlags

Defines the configuration options that control repository behavior during operations. These flags manage context relationships, validation behavior, operation metadata, and error handling.

Members

# static constant DBKeys

Collection of keys used for reflection metadata in database operations

Database reflection keys

View Source model/constants.ts, line 3

# static constant DBOperations

Maps out groups of CRUD operations for easier mapping of decorators

Grouped CRUD operations for decorator mapping

View Source operations/constants.ts, line 46

# static constant DEFAULT_TIMESTAMP_FORMAT

Standard date format string used for timestamp fields in database models

Default format for timestamp fields

View Source model/constants.ts, line 32

# static constant DefaultContextFactory

A factory function that creates new Context instances with the provided repository flags. It automatically adds a timestamp to the context and returns a properly typed context instance.

Default factory for creating context instances.

View Source repository/Context.ts, line 5

# static constant DefaultRepositoryFlags

Provides default values for repository operation flags, excluding the timestamp property. These flags control behavior such as context handling, validation, error handling, and more.

Default configuration flags for repository operations.

View Source repository/constants.ts, line 2

# static constant DefaultSeparator

The default separator character used when concatenating multiple fields into a single index

Default separator character for composite indexes

View Source model/constants.ts, line 25

# static constant VERSION

Stores the semantic version number of the package

Current version of the reflection package

View Source index.ts, line 15

string

# static readonly exports.BulkCrudOperationKeys

Enum defining bulk CRUD operations for handling multiple records at once

Bulk database operation key constants

View Source operations/constants.ts, line 39

string

# static readonly exports.ModelOperations

Enum defining operations naming

Database operation key naming constants

View Source operations/constants.ts, line 27

string

# static readonly exports.OperationKeys

Enum defining CRUD operations and their lifecycle phases

Database operation key constants

View Source operations/constants.ts, line 9

Methods

# static composedFromCreateUpdate(context, data, key, model) → {void}

Callback function used by composed decorators to generate a property value from other properties

Composes a property value from other properties during create or update operations

Parameters:
Name Type Description
context C

The operation context

data V

Metadata for the composition

key

The property key to set the composed value on

model M

The model being processed

View Source model/decorators.ts, line 43

void

# static hasErrors(previousVersionopt, …exclusions) → {ModelErrorDefinition|undefined}

Validates the current model state and optionally compares with a previous version

Validates the model and checks for errors

Parameters:
Name Type Attributes Description
previousVersion M | any <optional>

Optional previous version of the model for comparison

exclusions Array.<any> <repeatable>

Properties to exclude from validation

View Source overrides/overrides.ts, line 11

Error definition if validation fails, undefined otherwise

ModelErrorDefinition | undefined

# static hashOnCreateUpdate(context, data, key, model, oldModelopt) → {void}

Callback function used by the hash decorator to apply hashing to a property value

Hashes a property value during create or update operations

Parameters:
Name Type Attributes Description
context C

The operation context

data V

Metadata for the operation

key

The property key to hash

model M

The model being processed

oldModel M <optional>

The previous model state (for updates)

View Source model/decorators.ts, line 8

void

# static prefixMethod(obj, after, prefix, afterNameopt)

Util method to change a method of an object prefixing it with another

Parameters:
Name Type Attributes Description
obj any

The Base Object

after function

The original method

prefix function

The Prefix method. The output will be used as arguments in the original method

afterName string <optional>

When the after function anme cannot be extracted, pass it here

View Source repository/wrappers.ts, line 5

# static updateKey(key) → {string}

Builds the key to store as metadata under Reflections for update validation by prefixing the provided key with the update validation prefix.

Generates a key for update validation metadata.

Parameters:
Name Type Description
key string

The base key to be prefixed

View Source validation/validation.ts, line 4

The complete metadata key for update validation

string

# static validateCompare(oldModel, newModel, async, …propsToIgnore) → {ModelErrorDefinition|undefined}

Compares an old and new model version to validate update operations

Validates changes between two model versions

sequenceDiagram participant Caller participant validateCompare participant Reflection participant Validation Caller->>validateCompare: oldModel, newModel, propsToIgnore validateCompare->>Reflection: get decorated properties Reflection-->>validateCompare: property decorators loop For each decorated property validateCompare->>Validation: get validator Validation-->>validateCompare: validator validateCompare->>validateCompare: validate property update end loop For nested models validateCompare->>validateCompare: validate nested models end validateCompare-->>Caller: validation errors or undefined
Parameters:
Name Type Attributes Description
oldModel M

The original model version

newModel M

The updated model version

async boolean

A flag indicating whether validation should be asynchronous.

propsToIgnore Array.<string> <repeatable>

Properties to exclude from validation

View Source model/validation.ts, line 129

Error definition if validation fails, undefined otherwise

ModelErrorDefinition | undefined

# static versionCreateUpdate(operation) → {function}

Factory function that generates a callback for incrementing version numbers

Creates a function that updates a version property during operations

sequenceDiagram participant Caller participant versionCreateUpdate Caller->>versionCreateUpdate: operation versionCreateUpdate-->>Caller: callback function Note over Caller,versionCreateUpdate: When callback is executed: Caller->>versionCreateUpdate: context, data, key, model alt operation is CREATE versionCreateUpdate->>versionCreateUpdate: set version to 1 else operation is UPDATE versionCreateUpdate->>versionCreateUpdate: increment version else invalid operation versionCreateUpdate->>versionCreateUpdate: throw error end versionCreateUpdate-->>Caller: void
Parameters:
Name Type Description
operation CrudOperations

The type of operation (CREATE or UPDATE)

View Source model/decorators.ts, line 171

A callback function that updates the version property

function

# static wrapMethodWithContext(obj, before, method, after, methodNameopt)

Util method to wrap a method of an object with additional logic

Parameters:
Name Type Attributes Description
obj any

The Base Object

before function

the method to be prefixed

method function

the method to be wrapped

after function

The method to be suffixed

methodName string <optional>

When the after function anme cannot be extracted, pass it here

View Source repository/wrappers.ts, line 55

Type Definitions

string

# BulkCrudOperations

Union type of the four bulk database operations for handling multiple records at once

Type for bulk CRUD operations

View Source operations/constants.ts, line 77

Object

# ComposedFromMetadata

Configuration options for property composition from other properties

Metadata for composed property decorators

Properties:
Name Type Attributes Description
args Array.<string>

Property names to compose from

separator string

Character used to join the composed values

hashResult boolean

Whether to hash the composed result

type "keys" | "values"

Whether to use property keys or values

prefix string <optional>

Optional prefix to add to the composed value

suffix string <optional>

Optional suffix to add to the composed value

args Array
separator string
hashResult boolean
type "keys" | "values"
prefix string <optional>
suffix string <optional>
filterEmpty boolean | Array

View Source model/decorators.ts, line 283

# ContextFactory(arg)

Defines a function type that creates context instances with specific repository flags.

Factory type for creating context instances.

Parameters:
Name Type Description
arg Partial.<Omit.<FlagsOf.<C>, "timestamp">>

View Source repository/Context.ts, line 180

string

# CrudOperations

Union type of the four basic database operations: create, read, update, delete

Type for basic CRUD operations

View Source operations/constants.ts, line 69

# GeneralOperationHandler() → {Promise.<void>|void}

Function signature for handlers that process operations like create and read

General handler type for database operations

View Source operations/types.ts, line 38

Nothing or a Promise resolving to nothing

Promise.<void> | void

# GeneralUpdateOperationHandler()

Function signature for handlers that process update operations with both new and old model states

General handler type for group update database operations

View Source operations/types.ts, line 51

StandardOperationHandler.<M, R, V> | UpdateOperationHandler.<M, R, V> | IdOperationHandler.<M, R, V> | GroupOperationHandler.<M, R, V> | GroupUpdateOperationHandler.<M, R, V>

# OperationHandler

Represents any type of operation handler function that can be used with database operations

Union type for all operation handler types

View Source operations/types.ts, line 22

Object

# OperationMetadata

Contains information about an operation, its handler, and associated metadata

Metadata for database operations

Properties:
Name Type Attributes Description
operation OperationKeys

The type of operation

handler string

The name of the handler function

metadata V <optional>

Optional metadata associated with the operation

operation OperationKeys
handler string
metadata V <optional>

View Source operations/types.ts, line 8