Database decorators for TypeScript applications
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
# static constant DBOperations
Maps out groups of CRUD operations for easier mapping of decorators
Grouped CRUD operations for decorator mapping
# static constant DEFAULT_TIMESTAMP_FORMAT
Standard date format string used for timestamp fields in database models
Default format for timestamp fields
# 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.
# 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.
# static constant DefaultSeparator
The default separator character used when concatenating multiple fields into a single index
Default separator character for composite indexes
# static constant VERSION
Stores the semantic version number of the package
Current version of the reflection package
string
# static readonly exports.BulkCrudOperationKeys
Enum defining bulk CRUD operations for handling multiple records at once
Bulk database operation key constants
string
# static readonly exports.ModelOperations
Enum defining operations naming
Database operation key naming constants
string
# static readonly exports.OperationKeys
Enum defining CRUD operations and their lifecycle phases
Database operation key constants
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 |
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 |
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) |
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 |
# 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 |
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
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 |
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
Parameters:
| Name | Type | Description |
|---|---|---|
operation |
CrudOperations
|
The type of operation (CREATE or UPDATE) |
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 |
Type Definitions
string
# BulkCrudOperations
Union type of the four bulk database operations for handling multiple records at once
Type for bulk CRUD operations
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
|
# 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">>
|
string
# CrudOperations
Union type of the four basic database operations: create, read, update, delete
Type for basic CRUD operations
# GeneralOperationHandler() → {Promise.<void>|void}
Function signature for handlers that process operations like create and read
General handler type for database operations
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
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
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> |