Global

Methods

# after(opopt, handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after specified database operations

Base decorator for handling post-operation behaviors

Parameters:
Name Type Attributes Default Description
op Array.<OperationKeys> | DBOperations <optional>
DBOperations.ALL

One or more operation types to handle

handler OperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 302

A decorator that can be applied to class properties

PropertyDecorator
Example
// Example usage:
class MyModel {
  

# afterAny(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after any database operation

Decorator for handling post-operation for all operation types

Parameters:
Name Type Attributes Description
handler StandardOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 289

A decorator that can be applied to class properties

PropertyDecorator

# afterCreate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after create operations

Decorator for handling post-create operations

Parameters:
Name Type Attributes Description
handler StandardOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 250

A decorator that can be applied to class properties

PropertyDecorator

# afterCreateUpdate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after both create and update operations

Decorator for handling post-create and post-update operations

Parameters:
Name Type Attributes Description
handler StandardOperationHandler.<any, any, V, any, any> | UpdateOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 224

A decorator that can be applied to class properties

PropertyDecorator

# afterDelete(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after delete operations

Decorator for handling post-delete operations

Parameters:
Name Type Attributes Description
handler StandardOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 276

A decorator that can be applied to class properties

PropertyDecorator

# afterRead(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after read operations

Decorator for handling post-read operations

Parameters:
Name Type Attributes Description
handler StandardOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 263

A decorator that can be applied to class properties

PropertyDecorator

# afterUpdate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute after update operations

Decorator for handling post-update operations

Parameters:
Name Type Attributes Description
handler UpdateOperationHandler.<any, any, V, any, any>

The method called after the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 237

A decorator that can be applied to class properties

PropertyDecorator

# composed(args, separatoropt, hashopt, prefixopt, suffixopt, groupsort) → {PropertyDecorator}

Decorator that generates a property value by joining the values of other properties

Creates a decorator that composes a property value from property values

Parameters:
Name Type Attributes Default Description
args Array.<string>

Property names whose values will be composed

separator string <optional>
DefaultSeparator

Character used to join the property values

hash boolean <optional>
false

Whether to hash the composed result

prefix string <optional>
""

Optional prefix to add to the composed value

suffix string <optional>
""

Optional suffix to add to the composed value

groupsort GroupSort

GroupSort configuration

View Source model/decorators.ts, line 129

A decorator that can be applied to class properties

PropertyDecorator

# composedFrom(args, hashResultopt, separatoropt, typeopt, prefixopt, suffixopt, groupsort) → {PropertyDecorator}

Base function for creating property composition decorators

Creates a decorator that composes a property value from other properties

Parameters:
Name Type Attributes Default Description
args Array.<string>

Property names to compose from

hashResult boolean <optional>
false

Whether to hash the composed result

separator string <optional>
DefaultSeparator

Character used to join the composed values

type "keys" | "values" <optional>
"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

groupsort GroupSort

GroupSort configuration

View Source model/decorators.ts, line 82

A decorator that can be applied to class properties

PropertyDecorator

# composedFromKeys(args, separatoropt, hashopt, prefixopt, suffixopt, groupsort) → {PropertyDecorator}

Decorator that generates a property value by joining the names of other properties

Creates a decorator that composes a property value from property keys

Parameters:
Name Type Attributes Default Description
args Array.<string>

Property names to compose from

separator string <optional>
DefaultSeparator

Character used to join the property names

hash boolean <optional>
false

Whether to hash the composed result

prefix string <optional>
""

Optional prefix to add to the composed value

suffix string <optional>
""

Optional suffix to add to the composed value

groupsort GroupSort

GroupSort configuration

View Source model/decorators.ts, line 113

A decorator that can be applied to class properties

PropertyDecorator

# getHandlersDecorators(model, decorators, prefix) → {Array.<DecoratorObject>}

Retrieves a list of decorator objects representing operation handlers for a given model and decorators

Retrieves decorator objects for handling database operations

Parameters:
Name Type Description
model Model

The model for which to retrieve decorator objects

decorators Record.<string, Array.<DecoratorMetadata>>

The decorators associated with the model properties

prefix string

The operation prefix (e.g., 'on', 'after')

View Source operations/decorators.ts, line 24

An array of decorator objects representing operation handlers

Array.<DecoratorObject>

# getValidatableUpdateProps(model, propsToIgnore) → {Array.<ValidationPropertyDecoratorDefinition>}

Iterates over the model's own enumerable properties and filters out those specified in the propsToIgnore array. For each remaining property, retrieves validation decorators specific to update operations using the UpdateValidationKeys.REFLECT key. Additionally, it explicitly checks for and appends any LIST type decorators to ensure proper validation of collection types.

Retrieves validation decorator definitions from a model for update operations, including support for special handling of list decorators.

Parameters:
Name Type Description
model M

The model instance whose properties are being inspected for update-related validations.

propsToIgnore Array.<string>

A list of property names to exclude from the validation decorator retrieval process.

View Source model/validation.ts, line 6

An array of validation decorator definitions, including both update-specific and list-type decorators, excluding those for ignored properties.

Array.<ValidationPropertyDecoratorDefinition>

# groupDecorators(decorators) → {Array.<DecoratorObject>}

Groups decorator objects by their group property, combining data and properties within each group

Groups decorators based on their group property

Parameters:
Name Type Description
decorators Array.<DecoratorObject>

The array of decorator objects to group

View Source operations/decorators.ts, line 64

An array of grouped decorator objects

Array.<DecoratorObject>

# handle(op, handler) → {PropertyDecorator}

Registers an operation handler for a specific operation key on a target property

Internal function to register operation handlers

Parameters:
Name Type Description
op OperationKeys

The operation key to handle

handler OperationHandler.<any, any, any, any, any>

The handler function to register

View Source operations/decorators.ts, line 10

A decorator that registers the handler

PropertyDecorator

# hash() → {PropertyDecorator}

Decorator that automatically hashes a property value during create and update operations

Creates a decorator that hashes a property value

View Source model/decorators.ts, line 34

A decorator that can be applied to class properties

PropertyDecorator

# id() → {PropertyDecorator}

Creates a composite decorator that marks a property as required, readonly, and as the ID field for database operations

Decorator that marks a property as an ID field

View Source identity/decorators.ts, line 7

A decorator that can be applied to class properties

PropertyDecorator

# on(opopt, handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during specified database operations

Base decorator for handling database operations

Parameters:
Name Type Attributes Default Description
op Array.<OperationKeys> | DBOperations <optional>
DBOperations.ALL

One or more operation types to handle

handler OperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 204

A decorator that can be applied to class properties

PropertyDecorator
Example
// Example usage:
class MyModel {
  

# onAny(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during any database operation

Decorator for handling all operation types

Parameters:
Name Type Attributes Description
handler OperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 191

A decorator that can be applied to class properties

PropertyDecorator

# onCreate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during create operations

Decorator for handling create operations

Parameters:
Name Type Attributes Description
handler GeneralOperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 152

A decorator that can be applied to class properties

PropertyDecorator

# onCreateUpdate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during both create and update operations

Decorator for handling create and update operations

Parameters:
Name Type Attributes Description
handler GeneralOperationHandler.<any, any, V, any, any> | GeneralUpdateOperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 126

A decorator that can be applied to class properties

PropertyDecorator

# onDelete(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during delete operations

Decorator for handling delete operations

Parameters:
Name Type Attributes Description
handler OperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 178

A decorator that can be applied to class properties

PropertyDecorator

# onRead(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during read operations

Decorator for handling read operations

Parameters:
Name Type Attributes Description
handler IdOperationHandler.<any, any, V, any, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 165

A decorator that can be applied to class properties

PropertyDecorator

# onUpdate(handler, dataopt) → {PropertyDecorator}

Defines a behavior to execute during update operations

Decorator for handling update operations

Parameters:
Name Type Attributes Description
handler UpdateOperationHandler.<any, any, V, any>

The method called upon the operation

data V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 139

A decorator that can be applied to class properties

PropertyDecorator

# operation(baseOp, operationopt, handler, dataToAddopt) → {PropertyDecorator}

Creates decorators that register handlers for database operations

Core decorator factory for operation handlers

sequenceDiagram participant Client participant Decorator as @operation participant Operations as Operations Registry participant Handler Client->>Decorator: Apply to property Decorator->>Operations: Register handler Decorator->>Decorator: Store metadata Note over Client,Handler: Later, during operation execution Client->>Operations: Execute operation Operations->>Handler: Call registered handler Handler-->>Operations: Return result Operations-->>Client: Return final result
Parameters:
Name Type Attributes Default Description
baseOp OperationKeys.ON | OperationKeys.AFTER

Whether the handler runs during or after the operation

operation Array.<OperationKeys> <optional>
DBOperations.ALL

The specific operations to handle

handler OperationHandler.<any, any, V, any, any>

The handler function to execute

dataToAdd V <optional>

Optional metadata to pass to the handler

View Source operations/decorators.ts, line 322

A decorator that can be applied to class properties

PropertyDecorator

# readonly(messageopt) → {PropertyDecorator}

Marks the property as readonly, causing validation errors if attempts are made to modify it during updates.

Prevents a property from being modified after initial creation.

Parameters:
Name Type Attributes Description
message string <optional>

The error message to display when validation fails. Defaults to DEFAULT_ERROR_MESSAGES.READONLY.INVALID

View Source validation/decorators.ts, line 11

A decorator function that can be applied to class properties

PropertyDecorator

# serialize() → {PropertyDecorator}

Decorator that automatically converts complex objects to JSON strings before storing in the database and back to objects when retrieving them.

Enables automatic JSON serialization and deserialization for complex object properties.

sequenceDiagram participant C as Client participant M as Model participant S as SerializeDecorator participant DB as Database Note over C,DB: Create/Update Flow C->>M: Set complex object property M->>S: Process property (create/update) S->>M: Convert to JSON string M->>DB: Store serialized data Note over C,DB: Retrieval Flow C->>M: Request model M->>DB: Fetch data DB->>M: Return with serialized property M->>S: Process property (after all ops) S->>M: Parse JSON back to object M->>C: Return model with deserialized property

View Source validation/decorators.ts, line 172

A decorator function that can be applied to class properties

PropertyDecorator

# serializeAfterAll(context, data, key, model) → {Promise.<void>}

Converts a JSON string property back to its original complex object form after retrieving it from the database.

Handler function that deserializes a property from JSON string after database operations.

Parameters:
Name Type Description
context C

The repository context

data V

The data being processed

key

The property key to deserialize

model M

The model instance being processed

View Source validation/decorators.ts, line 145

A promise that resolves when the property has been deserialized

Promise.<void>

# serializeOnCreateUpdate(context, data, key, model) → {Promise.<void>}

Converts a complex object property to a JSON string before storing it in the database.

Handler function that serializes a property to JSON string during create and update operations.

Parameters:
Name Type Description
context C

The repository context

data V

The data being processed

key

The property key to serialize

model M

The model instance being processed

View Source validation/decorators.ts, line 119

A promise that resolves when the property has been serialized

Promise.<void>

# sortDecorators(decorators) → {Array.<DecoratorObject>}

Sorts an array of decorator objects by the priority of their first data element

Sorts decorator objects based on their priority

Parameters:
Name Type Description
decorators Array.<DecoratorObject>

The array of decorator objects to sort

View Source operations/decorators.ts, line 109

The sorted array of decorator objects

Array.<DecoratorObject>

# timestamp(operation, formatopt) → {PropertyDecorator}

Marks the property as a timestamp, making it required and ensuring it's a valid date. The property will be automatically updated with the current timestamp during specified operations.

Date Format:

     Using similar formatting as Moment.js, Class DateTimeFormatter (Java), and Class SimpleDateFormat (Java),
     I implemented a comprehensive solution formatDate(date, patternStr) where the code is easy to read and modify.
     You can display date, time, AM/PM, etc.

     Date and Time Patterns
     yy = 2-digit year; yyyy = full year
     M = digit month; MM = 2-digit month; MMM = short month name; MMMM = full month name
     EEEE = full weekday name; EEE = short weekday name
     d = digit day; dd = 2-digit day
     h = hours am/pm; hh = 2-digit hours am/pm; H = hours; HH = 2-digit hours
     m = minutes; mm = 2-digit minutes; aaa = AM/PM
     s = seconds; ss = 2-digit seconds
     S = miliseconds

Automatically manages timestamp properties for tracking creation and update times.

sequenceDiagram participant C as Client participant M as Model participant T as TimestampDecorator participant V as Validator C->>M: Create/Update model M->>T: Process timestamp property T->>M: Apply required validation T->>M: Apply date format validation alt Update operation T->>V: Register timestamp validator V->>M: Validate timestamp is newer end T->>M: Set current timestamp M->>C: Return updated model
Parameters:
Name Type Attributes Description
operation Array.<OperationKeys>

The operations to act on. Defaults to DBOperations.CREATE_UPDATE

format string <optional>

The timestamp format. Defaults to DEFAULT_TIMESTAMP_FORMAT

View Source validation/decorators.ts, line 45

A decorator function that can be applied to class properties

PropertyDecorator

# timestampHandler(context, data, key, model) → {Promise.<void>}

Updates a model property with the current timestamp from the repository context.

Handler function that sets a timestamp property to the current timestamp.

Parameters:
Name Type Description
context C

The repository context containing the current timestamp

data V

The data being processed

key

The property key to update

model M

The model instance being updated

View Source validation/decorators.ts, line 27

A promise that resolves when the timestamp has been set

Promise.<void>

# transient() → {PropertyDecorator}

Decorator that indicates a property should not be persisted to the database

Creates a decorator that marks a property as transient

View Source model/decorators.ts, line 207

A decorator that can be applied to class properties

PropertyDecorator

# version() → {PropertyDecorator}

This decorator applies multiple sub-decorators to handle version management during create and update operations

Creates a decorator for versioning a property in a model

View Source model/decorators.ts, line 194

A composite decorator that sets the type to Number, manages version updates, and adds versioning metadata

PropertyDecorator

Type Definitions

Object

# DecoratorObject

Defines the structure of an object used to represent a decorator in the context of database operations.

DecoratorObject type definition

Properties:
Name Type Description
handler OperationHandler.<any, any, any, any, any>

The handler function to be executed during the operation

data object

Optional metadata to be passed to the handler function

prop string

The property key to which the decorator is applied

handler OperationHandler.<any, any, any, any, any>
data Array
prop Array

View Source operations/decorators.ts, line 410

Object

# GroupSort

Defines the structure for specifying group sorting options

Represents sorting parameters for grouping decorators

Properties:
Name Type Attributes Description
priority number

The priority of the sorting operation, lower numbers represent higher priority

group string <optional>

Optional property to group decorators, used for grouping related operations

groupPriority number <optional>

Optional property to specify the priority within a group, lower numbers represent higher priority within the group

priority number
group string <optional>
groupPriority number <optional>

View Source operations/decorators.ts, line 395