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 |
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 |
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 |
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 |
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 |
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 |
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 |
A decorator that can be applied to class properties
PropertyDecorator
# composed(args, separatoropt, hashopt, prefixopt, suffixopt) → {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 |
A decorator that can be applied to class properties
PropertyDecorator
# composedFrom(args, hashResultopt, separatoropt, typeopt, prefixopt, suffixopt) → {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 |
A decorator that can be applied to class properties
PropertyDecorator
# composedFromKeys(args, separatoropt, hashopt, prefixopt, suffixopt) → {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 |
A decorator that can be applied to class properties
PropertyDecorator
# 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 |
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
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
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 |
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 |
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 |
StandardOperationHandler.<any, any, V, any, any>
|
The method called upon the operation |
|
data |
V
|
<optional> |
Optional metadata to pass to the handler |
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 |
StandardOperationHandler.<any, any, V, any, any>
|
UpdateOperationHandler.<any, any, V, any, any>
|
The method called upon the operation |
|
data |
V
|
<optional> |
Optional metadata to pass to the handler |
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 |
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 |
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 |
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
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 |
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 |
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.
A decorator function that can be applied to class properties
PropertyDecorator
# 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.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
operation |
Array.<OperationKeys>
|
The operations to act on. Defaults to |
|
format |
string
|
<optional> |
The timestamp format. Defaults to |
A decorator function that can be applied to class properties
PropertyDecorator
# transient() → {PropertyDecorator}
Decorator that indicates a property should not be persisted to the database
Creates a decorator that marks a property as transient
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
A composite decorator that sets the type to Number, manages version updates, and adds versioning metadata
PropertyDecorator