Methods
# cleanupTemporaryContext()
Safely removes temporary metadata from an object
.Safely removes temporary metadata from an object
# date(format, messageopt)
Date Handler Decorator
Validators to validate a decorated property must use key ValidationKeys#DATE
Will enforce serialization according to the selected format
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
format |
string
|
accepted format according to |
|
message |
string
|
<optional> |
the error message. Defaults to |
# description(description)
Applies descriptive metadata to a class, property or method
Parameters:
Name | Type | Description |
---|---|---|
description |
string
|
the description to apply |
# diff(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be different from another specified property.
Applies the ValidationKeys.DIFF
validator to ensure the decorated value is different from the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare difference against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.DIFF | Custom error message to return if validation fails. |
A property decorator used to register the difference validation metadata.
PropertyDecorator
# email(messageopt)
Defines the property as an email
Validators to validate a decorated property must use key ValidationKeys#EMAIL
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string
|
<optional> |
the error message. Defaults to |
# eq(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be equal to another specified property.
Applies the ValidationKeys.EQUALS
validator to ensure the decorated value matches the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare equality against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.EQUALS | Custom error message to return if validation fails. |
A property decorator used to register the equality validation metadata.
PropertyDecorator
# getNestedValidationErrors(nestedModel, parentModel, isAsync)
Executes validation with temporary context and returns the validation result
.Executes validation with temporary context and returns the validation result
Parameters:
Name | Type | Description |
---|---|---|
nestedModel |
The instance to validate |
|
parentModel |
Reference to a parent object for nested validation |
|
isAsync |
Whether to perform async validation |
Validation result from hasErrors()
# getValidatableProperties(model, propsToIgnore) → {Array.<ValidationPropertyDecoratorDefinition>}
Iterates through the own enumerable properties of a model instance, filtering out any properties
listed in the propsToIgnore
array. For each remaining property, it checks whether validation
decorators are present using getValidationDecorators
, and if so, collects them in the result array.
Retrieves all validatable property decorators from a given model, excluding specified properties.
Parameters:
Name | Type | Description |
---|---|---|
model |
M
|
An instance of a class extending |
propsToIgnore |
Array.<string>
|
An array of property names that should be excluded from validation inspection. |
An array of validation decorator definitions
associated with the model's properties, excluding those listed in propsToIgnore
.
Array.<ValidationPropertyDecoratorDefinition>
# getValidationDecorators(model, prop, reflectKey)
Retrieves the validation metadata decorators associated with a specific property of a model, using the reflective metadata key.
Retrieves the validation metadata decorators associated with a specific property of a model, using the reflective metadata key.
Parameters:
Name | Type | Description |
---|---|---|
model |
The model instance or class containing the decorated property. |
|
prop |
string
|
The name of the property whose decorators should be retrieved. |
reflectKey |
string
|
The metadata key used to retrieve the decorators.
Defaults to |
The validation decorators applied to the property
# gt(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be greater than another specified property.
Applies the ValidationKeys.GREATER_THAN
validator to ensure the decorated value is greater than the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.GREATER_THAN | Custom error message to return if validation fails. |
A property decorator used to register the greater than validation metadata.
PropertyDecorator
# gte(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be equal or greater than another specified property.
Applies the ValidationKeys.GREATER_THAN_OR_EQUAL
validator to ensure the decorated value is equal or greater than the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.GREATER_THAN_OR_EQUAL | Custom error message to return if validation fails. |
A property decorator used to register the greater than or equal validation metadata.
PropertyDecorator
# hashedBy(algorithm)
Defines the hashing algorithm to use on the model
- Registers the class under the model registry so it can be easily rebuilt;
- Overrides the class constructor;
- Runs the global
ModelBuilderFunction
if defined; - Runs the optional
InstanceCallback
if provided;
Parameters:
Name | Type | Description |
---|---|---|
algorithm |
string
|
the algorithm to use |
# list(clazz, collectionopt, messageopt)
List Decorator
Also sets the type
to the provided collection
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
clazz |
ModelConstructor
|
||
collection |
string
|
<optional> |
The collection being used. defaults to Array |
message |
string
|
<optional> |
defaults to |
# lt(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be less than another specified property.
Applies the ValidationKeys.LESS_THAN
validator to ensure the decorated value is less than the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.LESS_THAN | Custom error message to return if validation fails. |
A property decorator used to register the less than validation metadata.
PropertyDecorator
# lte(propertyToCompare, messageopt) → {PropertyDecorator}
Declares that the decorated property must be equal or less than another specified property.
Applies the ValidationKeys.LESS_THAN_OR_EQUAL
validator to ensure the decorated value is equal or less than the value of the given property.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
propertyToCompare |
string
|
The name of the property to compare against. |
||
message |
string
|
<optional> |
DEFAULT_ERROR_MESSAGES.LESS_THAN_OR_EQUAL | Custom error message to return if validation fails. |
A property decorator used to register the less than or equal validation metadata.
PropertyDecorator
# max(value, messageopt)
Defines a maximum value for the property
Validators to validate a decorated property must use key ValidationKeys#MAX
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
number
|
Date
|
||
message |
string
|
<optional> |
the error message. Defaults to |
# maxlength(value, messageopt)
Defines a maximum length for the property
Validators to validate a decorated property must use key ValidationKeys#MAX_LENGTH
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
string
|
||
message |
string
|
<optional> |
the error message. Defaults to |
# min(value, messageopt) → {PropertyDecorator}
Defines a minimum value for the property, causing validation to fail if the property value is less than the specified minimum.
Validators to validate a decorated property must use key ValidationKeys#MIN
.
This decorator works with numeric values and dates.
Property decorator that enforces a minimum value constraint
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
number
|
Date
|
string
|
The minimum value allowed. For dates, can be a Date object or a string that can be converted to a date |
|
message |
string
|
<optional> |
The error message to display when validation fails. Defaults to |
A decorator function that can be applied to class properties
PropertyDecorator
Example
```typescript
class Product {
# minlength(value, messageopt)
Defines a minimum length for the property
Validators to validate a decorated property must use key ValidationKeys#MIN_LENGTH
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
string
|
||
message |
string
|
<optional> |
the error message. Defaults to |
# model(instanceCallbackopt)
Defines a class as a Model class
- Registers the class under the model registry so it can be easily rebuilt;
- Overrides the class constructor;
- Runs the global
ModelBuilderFunction
if defined; - Runs the optional
InstanceCallback
if provided;
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
instanceCallback |
InstanceCallback
|
<optional> |
optional callback that will be called with the instance upon instantiation. defaults to undefined |
# password(patternopt, messageopt)
Password Handler Decorator
Validators to validate a decorated property must use key ValidationKeys#PASSWORD
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
pattern |
RegExp
|
<optional> |
defaults to |
message |
string
|
<optional> |
the error message. Defaults to |
# pattern(value, messageopt)
Defines a RegExp pattern the property must respect
Validators to validate a decorated property must use key ValidationKeys#PATTERN
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
string
|
||
message |
string
|
<optional> |
the error message. Defaults to |
# prop(keyopt) → {function}
Creates a decorator that marks class properties as model attributes
Property decorator factory for model attributes
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
key |
string
|
<optional> |
ModelKeys.ATTRIBUTE | The metadata key under which to store the property name |
- Decorator function that registers the property
function
# propMetadata(key, value) → {function}
Creates a decorator that both marks a property as a model attribute and assigns metadata to it
Combined property decorator factory for metadata and attribute marking
Parameters:
Name | Type | Description |
---|---|---|
key |
string
|
The metadata key |
value |
V
|
The metadata value to associate with the property |
- Combined decorator function
function
# required(messageopt) → {PropertyDecorator}
Marks the property as required, causing validation to fail if the property is undefined, null, or empty.
Validators to validate a decorated property must use key ValidationKeys#REQUIRED
.
This decorator is commonly used as the first validation step for important fields.
Property decorator that marks a field as required
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
Example
```typescript
class User {
# serializedBy(serializer)
Defines the serialization algorithm to use on the model
Parameters:
Name | Type | Description |
---|---|---|
serializer |
string
|
the algorithm to use |
# set(clazz, messageopt)
Set Decorator
Wrapper for list
with the 'Set' Collection
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
clazz |
ModelConstructor
|
||
message |
string
|
<optional> |
defaults to |
# setTemporaryContext()
Safely sets temporary metadata on an object
.Safely sets temporary metadata on an object
# step(value, messageopt)
Defines a step value for the property
Validators to validate a decorated property must use key ValidationKeys#STEP
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
value |
number
|
||
message |
string
|
<optional> |
the error message. Defaults to |
# toConditionalPromise(value, async)
Wraps a value in a Promise if the async
flag is true.
Wraps a value in a Promise if the async
flag is true.
Parameters:
Name | Type | Description |
---|---|---|
value |
The value to return directly or wrap in a Promise. |
|
async |
If true, the value is wrapped in a resolved Promise. If false or undefined, the value is returned as-is. |
The original value or a Promise resolving to it, depending on the async
flag.
# type(types, messageopt)
Enforces type verification
Validators to validate a decorated property must use key ValidationKeys#TYPE
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
types |
Array.<string>
|
string
|
accepted types |
|
message |
string
|
<optional> |
the error message. Defaults to |
# url(messageopt)
Defines the property as an URL
Validators to validate a decorated property must use key ValidationKeys#URL
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
message |
string
|
<optional> |
the error message. Defaults to |
# validateDecorators(model, prop, value, decorators, asyncopt) → {ConditionalAsync.<Async, Record.<string, string>>|undefined}
Iterates over an array of decorator metadata objects and applies each validation rule to the
provided value. For list decorators (ValidationKeys.LIST
), it performs element-wise validation,
supporting nested model validation and type checks. If the async
flag is set, asynchronous
validation is supported using Promise.all
. The result is a record mapping validation keys to
error messages, or undefined
if no errors are found.
Executes validation logic for a set of decorators applied to a model's property, handling both synchronous and asynchronous validations, including support for nested validations and lists.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
model |
M
|
The model instance that the validation is associated with. |
|
prop |
string
|
The model field name |
|
value |
any
|
The value to be validated against the provided decorators. |
|
decorators |
Array.<DecoratorMetadataAsync>
|
An array of metadata objects representing validation decorators. |
|
async |
Async
|
<optional> |
Optional flag indicating whether validation should be performed asynchronously. |
Returns either a record of validation errors (keyed by the decorator key) or undefined
if no errors are found.
If async
is true, the return value is a Promise resolving to the same structure.
ConditionalAsync.<Async, Record.<string, string>>
|
undefined
# validationMetadata(decorator, key, value) → {function}
Creates a decorator that both marks a property as a model attribute and assigns metadata to it
Combined property decorator factory for metadata and attribute marking
Parameters:
Name | Type | Description |
---|---|---|
decorator |
PropertyDecorator
|
The metadata key |
key |
string
|
The metadata key |
value |
V
|
The metadata value to associate with the property |
- Combined decorator function
function
# validator(keys)
Marks the class as a validator for a certain key.
Registers the class in the Validation
with the provided key
Parameters:
Name | Type | Description |
---|---|---|
keys |
string
|
the validation key |
Type Definitions
object
# PathProxy
Proxy object that provides path-based access to nested properties
.Proxy object that provides path-based access to nested properties
Properties:
Name | Type | Description |
---|---|---|
getValueFromPath |
function
|