@decaf-ts/decorator-validation 1.14.0 → 1.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/constants/errors.cjs +1 -0
- package/lib/cjs/constants/errors.cjs.map +1 -0
- package/lib/cjs/constants/index.cjs +1 -0
- package/lib/cjs/constants/index.cjs.map +1 -0
- package/lib/cjs/constants/validation.cjs +1 -0
- package/lib/cjs/constants/validation.cjs.map +1 -0
- package/lib/cjs/index.cjs +2 -1
- package/lib/cjs/index.cjs.map +1 -0
- package/lib/cjs/model/Builder.cjs +49 -48
- package/lib/cjs/model/Builder.cjs.map +1 -0
- package/lib/cjs/model/Model.cjs +31 -30
- package/lib/cjs/model/Model.cjs.map +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs +1 -0
- package/lib/cjs/model/ModelErrorDefinition.cjs.map +1 -0
- package/lib/cjs/model/ModelRegistry.cjs +7 -6
- package/lib/cjs/model/ModelRegistry.cjs.map +1 -0
- package/lib/cjs/model/constants.cjs +2 -13
- package/lib/cjs/model/constants.cjs.map +1 -0
- package/lib/cjs/model/construction.cjs +5 -4
- package/lib/cjs/model/construction.cjs.map +1 -0
- package/lib/cjs/model/decorators.cjs +12 -11
- package/lib/cjs/model/decorators.cjs.map +1 -0
- package/lib/cjs/model/index.cjs +1 -0
- package/lib/cjs/model/index.cjs.map +1 -0
- package/lib/cjs/model/types.cjs +1 -0
- package/lib/cjs/model/types.cjs.map +1 -0
- package/lib/cjs/model/utils.cjs +1 -0
- package/lib/cjs/model/utils.cjs.map +1 -0
- package/lib/cjs/model/validation.cjs +33 -32
- package/lib/cjs/model/validation.cjs.map +1 -0
- package/lib/cjs/overrides/Metadata.cjs +1 -0
- package/lib/cjs/overrides/Metadata.cjs.map +1 -0
- package/lib/cjs/overrides/index.cjs +1 -0
- package/lib/cjs/overrides/index.cjs.map +1 -0
- package/lib/cjs/overrides/overrides.cjs +20 -19
- package/lib/cjs/overrides/overrides.cjs.map +1 -0
- package/lib/cjs/overrides/types.cjs +1 -0
- package/lib/cjs/overrides/types.cjs.map +1 -0
- package/lib/cjs/types/index.cjs +1 -0
- package/lib/cjs/types/index.cjs.map +1 -0
- package/lib/cjs/types/validation.cjs +1 -0
- package/lib/cjs/types/{validation.js.map → validation.cjs.map} +1 -1
- package/lib/cjs/utils/DateBuilder.cjs +1 -0
- package/lib/cjs/utils/DateBuilder.cjs.map +1 -0
- package/lib/cjs/utils/PathProxy.cjs +9 -8
- package/lib/cjs/utils/PathProxy.cjs.map +1 -0
- package/lib/cjs/utils/constants.cjs +2 -21
- package/lib/cjs/utils/constants.cjs.map +1 -0
- package/lib/cjs/utils/dates.cjs +9 -8
- package/lib/cjs/utils/dates.cjs.map +1 -0
- package/lib/cjs/utils/equality.cjs +1 -0
- package/lib/cjs/utils/equality.cjs.map +1 -0
- package/lib/cjs/utils/hashing.cjs +6 -3
- package/lib/cjs/utils/hashing.cjs.map +1 -0
- package/lib/cjs/utils/index.cjs +1 -0
- package/lib/cjs/utils/index.cjs.map +1 -0
- package/lib/cjs/utils/registry.cjs +1 -0
- package/lib/cjs/utils/registry.cjs.map +1 -0
- package/lib/cjs/utils/serialization.cjs +3 -2
- package/lib/cjs/utils/serialization.cjs.map +1 -0
- package/lib/cjs/utils/serializers.cjs +8 -7
- package/lib/cjs/utils/serializers.cjs.map +1 -0
- package/lib/cjs/utils/strings.cjs +1 -0
- package/lib/cjs/utils/strings.cjs.map +1 -0
- package/lib/cjs/utils/types.cjs +1 -0
- package/lib/cjs/utils/types.cjs.map +1 -0
- package/lib/cjs/validation/Validation.cjs +9 -8
- package/lib/cjs/validation/Validation.cjs.map +1 -0
- package/lib/cjs/validation/Validators/AsyncValidator.cjs +5 -4
- package/lib/cjs/validation/Validators/AsyncValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/BaseValidator.cjs +8 -7
- package/lib/cjs/validation/Validators/BaseValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DateValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/DateValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/DiffValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/DiffValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EmailValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/EmailValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/EqualsValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/EqualsValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/GreaterThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs +24 -18
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/LessThanValidator.cjs +21 -15
- package/lib/cjs/validation/Validators/LessThanValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ListValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/ListValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MaxLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MaxValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MaxValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs +19 -13
- package/lib/cjs/validation/Validators/MinLengthValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/MinValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/MinValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/OptionValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/OptionValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PasswordValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/PasswordValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/PatternValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/PatternValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/RequiredValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/RequiredValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/StepValidator.cjs +17 -11
- package/lib/cjs/validation/Validators/StepValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/TypeValidator.cjs +23 -17
- package/lib/cjs/validation/Validators/TypeValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/URLValidator.cjs +18 -12
- package/lib/cjs/validation/Validators/URLValidator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/Validator.cjs +5 -4
- package/lib/cjs/validation/Validators/Validator.cjs.map +1 -0
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs +4 -3
- package/lib/cjs/validation/Validators/ValidatorRegistry.cjs.map +1 -0
- package/lib/cjs/validation/Validators/constants.cjs +3 -2
- package/lib/cjs/validation/Validators/constants.cjs.map +1 -0
- package/lib/cjs/validation/Validators/decorators.cjs +5 -4
- package/lib/cjs/validation/Validators/decorators.cjs.map +1 -0
- package/lib/cjs/validation/Validators/index.cjs +1 -0
- package/lib/cjs/validation/Validators/index.cjs.map +1 -0
- package/lib/cjs/validation/Validators/utils.cjs +14 -13
- package/lib/cjs/validation/Validators/utils.cjs.map +1 -0
- package/lib/cjs/validation/decorators.cjs +70 -69
- package/lib/cjs/validation/decorators.cjs.map +1 -0
- package/lib/cjs/validation/index.cjs +1 -0
- package/lib/cjs/validation/index.cjs.map +1 -0
- package/lib/cjs/validation/types.cjs +2 -1
- package/lib/cjs/validation/types.cjs.map +1 -0
- package/lib/esm/index.js +1 -1
- package/lib/types/constants/errors.d.cts +17 -0
- package/lib/types/constants/errors.d.mts +17 -0
- package/lib/types/constants/index.d.cts +2 -0
- package/lib/types/constants/index.d.mts +2 -0
- package/lib/types/constants/validation.d.cts +16 -0
- package/lib/types/constants/validation.d.mts +16 -0
- package/lib/types/index.d.cts +20 -0
- package/lib/types/index.d.mts +20 -0
- package/lib/types/index.d.ts +1 -1
- package/lib/types/model/Builder.d.cts +86 -0
- package/lib/types/model/Builder.d.mts +86 -0
- package/lib/types/model/Model.d.cts +286 -0
- package/lib/types/model/Model.d.mts +286 -0
- package/lib/types/model/ModelErrorDefinition.d.cts +22 -0
- package/lib/types/model/ModelErrorDefinition.d.mts +22 -0
- package/lib/types/model/ModelRegistry.d.cts +181 -0
- package/lib/types/model/ModelRegistry.d.mts +181 -0
- package/lib/types/model/constants.d.cts +65 -0
- package/lib/types/model/constants.d.mts +65 -0
- package/lib/types/model/construction.d.cts +46 -0
- package/lib/types/model/construction.d.mts +46 -0
- package/lib/types/model/decorators.d.cts +47 -0
- package/lib/types/model/decorators.d.mts +47 -0
- package/lib/types/model/index.d.cts +10 -0
- package/lib/types/model/index.d.mts +10 -0
- package/lib/types/model/types.d.cts +145 -0
- package/lib/types/model/types.d.mts +145 -0
- package/lib/types/model/utils.d.cts +13 -0
- package/lib/types/model/utils.d.mts +13 -0
- package/lib/types/model/validation.d.cts +92 -0
- package/lib/types/model/validation.d.mts +92 -0
- package/lib/types/overrides/Metadata.d.cts +132 -0
- package/lib/types/overrides/Metadata.d.mts +132 -0
- package/lib/types/overrides/index.d.cts +4 -0
- package/lib/types/overrides/index.d.mts +4 -0
- package/lib/types/overrides/overrides.d.cts +1 -0
- package/lib/types/overrides/overrides.d.mts +1 -0
- package/lib/types/overrides/types.d.cts +17 -0
- package/lib/types/overrides/types.d.mts +17 -0
- package/lib/types/types/index.d.cts +1 -0
- package/lib/types/types/index.d.mts +1 -0
- package/lib/types/types/validation.d.cts +28 -0
- package/lib/types/types/validation.d.mts +28 -0
- package/lib/types/utils/DateBuilder.d.cts +121 -0
- package/lib/types/utils/DateBuilder.d.mts +121 -0
- package/lib/types/utils/PathProxy.d.cts +43 -0
- package/lib/types/utils/PathProxy.d.mts +43 -0
- package/lib/types/utils/constants.d.cts +32 -0
- package/lib/types/utils/constants.d.mts +32 -0
- package/lib/types/utils/dates.d.cts +86 -0
- package/lib/types/utils/dates.d.mts +86 -0
- package/lib/types/utils/equality.d.cts +56 -0
- package/lib/types/utils/equality.d.mts +56 -0
- package/lib/types/utils/hashing.d.cts +82 -0
- package/lib/types/utils/hashing.d.mts +82 -0
- package/lib/types/utils/index.d.cts +11 -0
- package/lib/types/utils/index.d.mts +11 -0
- package/lib/types/utils/registry.d.cts +68 -0
- package/lib/types/utils/registry.d.mts +68 -0
- package/lib/types/utils/serialization.d.cts +12 -0
- package/lib/types/utils/serialization.d.mts +12 -0
- package/lib/types/utils/serializers.d.cts +41 -0
- package/lib/types/utils/serializers.d.mts +41 -0
- package/lib/types/utils/strings.d.cts +25 -0
- package/lib/types/utils/strings.d.mts +25 -0
- package/lib/types/utils/types.d.cts +35 -0
- package/lib/types/utils/types.d.mts +35 -0
- package/lib/types/validation/Validation.d.cts +53 -0
- package/lib/types/validation/Validation.d.mts +53 -0
- package/lib/types/validation/Validators/AsyncValidator.d.cts +72 -0
- package/lib/types/validation/Validators/AsyncValidator.d.mts +72 -0
- package/lib/types/validation/Validators/BaseValidator.d.cts +118 -0
- package/lib/types/validation/Validators/BaseValidator.d.mts +118 -0
- package/lib/types/validation/Validators/DateValidator.d.cts +60 -0
- package/lib/types/validation/Validators/DateValidator.d.mts +60 -0
- package/lib/types/validation/Validators/DiffValidator.d.cts +29 -0
- package/lib/types/validation/Validators/DiffValidator.d.mts +29 -0
- package/lib/types/validation/Validators/EmailValidator.d.cts +60 -0
- package/lib/types/validation/Validators/EmailValidator.d.mts +60 -0
- package/lib/types/validation/Validators/EqualsValidator.d.cts +29 -0
- package/lib/types/validation/Validators/EqualsValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.cts +29 -0
- package/lib/types/validation/Validators/LessThanValidator.d.mts +29 -0
- package/lib/types/validation/Validators/ListValidator.d.cts +66 -0
- package/lib/types/validation/Validators/ListValidator.d.mts +66 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MaxValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MaxValidator.d.mts +74 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +29 -0
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +29 -0
- package/lib/types/validation/Validators/MinValidator.d.cts +74 -0
- package/lib/types/validation/Validators/MinValidator.d.mts +74 -0
- package/lib/types/validation/Validators/OptionValidator.d.cts +29 -0
- package/lib/types/validation/Validators/OptionValidator.d.mts +29 -0
- package/lib/types/validation/Validators/PasswordValidator.d.cts +28 -0
- package/lib/types/validation/Validators/PasswordValidator.d.mts +28 -0
- package/lib/types/validation/Validators/PatternValidator.d.cts +103 -0
- package/lib/types/validation/Validators/PatternValidator.d.mts +103 -0
- package/lib/types/validation/Validators/RequiredValidator.d.cts +74 -0
- package/lib/types/validation/Validators/RequiredValidator.d.mts +74 -0
- package/lib/types/validation/Validators/StepValidator.d.cts +29 -0
- package/lib/types/validation/Validators/StepValidator.d.mts +29 -0
- package/lib/types/validation/Validators/TypeValidator.d.cts +79 -0
- package/lib/types/validation/Validators/TypeValidator.d.mts +79 -0
- package/lib/types/validation/Validators/URLValidator.d.cts +61 -0
- package/lib/types/validation/Validators/URLValidator.d.mts +61 -0
- package/lib/types/validation/Validators/Validator.d.cts +65 -0
- package/lib/types/validation/Validators/Validator.d.mts +65 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +41 -0
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +41 -0
- package/lib/types/validation/Validators/constants.d.cts +157 -0
- package/lib/types/validation/Validators/constants.d.mts +157 -0
- package/lib/types/validation/Validators/decorators.d.cts +12 -0
- package/lib/types/validation/Validators/decorators.d.mts +12 -0
- package/lib/types/validation/Validators/index.d.cts +26 -0
- package/lib/types/validation/Validators/index.d.mts +26 -0
- package/lib/types/validation/Validators/utils.d.cts +75 -0
- package/lib/types/validation/Validators/utils.d.mts +75 -0
- package/lib/types/validation/decorators.d.cts +313 -0
- package/lib/types/validation/decorators.d.mts +313 -0
- package/lib/types/validation/index.d.cts +9 -0
- package/lib/types/validation/index.d.mts +9 -0
- package/lib/types/validation/types.d.cts +309 -0
- package/lib/types/validation/types.d.mts +309 -0
- package/package.json +1 -1
- package/lib/cjs/constants/errors.js.map +0 -1
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/constants/validation.js.map +0 -1
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/model/Builder.js.map +0 -1
- package/lib/cjs/model/Model.js.map +0 -1
- package/lib/cjs/model/ModelErrorDefinition.js.map +0 -1
- package/lib/cjs/model/ModelRegistry.js.map +0 -1
- package/lib/cjs/model/constants.js.map +0 -1
- package/lib/cjs/model/construction.js.map +0 -1
- package/lib/cjs/model/decorators.js.map +0 -1
- package/lib/cjs/model/index.js.map +0 -1
- package/lib/cjs/model/types.js.map +0 -1
- package/lib/cjs/model/utils.js.map +0 -1
- package/lib/cjs/model/validation.js.map +0 -1
- package/lib/cjs/overrides/Metadata.js.map +0 -1
- package/lib/cjs/overrides/index.js.map +0 -1
- package/lib/cjs/overrides/overrides.js.map +0 -1
- package/lib/cjs/overrides/types.js.map +0 -1
- package/lib/cjs/types/index.js.map +0 -1
- package/lib/cjs/utils/DateBuilder.js.map +0 -1
- package/lib/cjs/utils/PathProxy.js.map +0 -1
- package/lib/cjs/utils/constants.js.map +0 -1
- package/lib/cjs/utils/dates.js.map +0 -1
- package/lib/cjs/utils/equality.js.map +0 -1
- package/lib/cjs/utils/hashing.js.map +0 -1
- package/lib/cjs/utils/index.js.map +0 -1
- package/lib/cjs/utils/registry.js.map +0 -1
- package/lib/cjs/utils/serialization.js.map +0 -1
- package/lib/cjs/utils/serializers.js.map +0 -1
- package/lib/cjs/utils/strings.js.map +0 -1
- package/lib/cjs/utils/types.js.map +0 -1
- package/lib/cjs/validation/Validation.js.map +0 -1
- package/lib/cjs/validation/Validators/AsyncValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/BaseValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DateValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/DiffValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EmailValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/EqualsValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/GreaterThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanOrEqualValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/LessThanValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/ListValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MaxValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinLengthValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/MinValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/OptionValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PasswordValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/PatternValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/RequiredValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/StepValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/TypeValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/URLValidator.js.map +0 -1
- package/lib/cjs/validation/Validators/Validator.js.map +0 -1
- package/lib/cjs/validation/Validators/ValidatorRegistry.js.map +0 -1
- package/lib/cjs/validation/Validators/constants.js.map +0 -1
- package/lib/cjs/validation/Validators/decorators.js.map +0 -1
- package/lib/cjs/validation/Validators/index.js.map +0 -1
- package/lib/cjs/validation/Validators/utils.js.map +0 -1
- package/lib/cjs/validation/decorators.js.map +0 -1
- package/lib/cjs/validation/index.js.map +0 -1
- package/lib/cjs/validation/types.js.map +0 -1
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { ComparisonValidatorOptions, DateValidatorOptions, ListValidatorOptions, ValidatorOptions } from "./types.cjs";
|
|
2
|
+
import { ModelConstructor } from "../model/types.cjs";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
/**
|
|
5
|
+
* @description Combined property decorator factory for metadata and attribute marking
|
|
6
|
+
* @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
|
|
7
|
+
*
|
|
8
|
+
* @template V
|
|
9
|
+
* @param {PropertyDecorator} decorator - The metadata key
|
|
10
|
+
* @param {string} key - The metadata key
|
|
11
|
+
* @param {V} value - The metadata value to associate with the property
|
|
12
|
+
* @return {Function} - Combined decorator function
|
|
13
|
+
* @function validationMetadata
|
|
14
|
+
* @category Property Decorators
|
|
15
|
+
*/
|
|
16
|
+
export declare function validationMetadata<V>(decorator: any, key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
|
|
17
|
+
export declare function innerValidationDecorator(dec: any, key: string, meta: any): (obj: any, prop: any) => void;
|
|
18
|
+
export declare function async(): (model: object) => void;
|
|
19
|
+
/**
|
|
20
|
+
* @description Property decorator that marks a field as required
|
|
21
|
+
* @summary Marks the property as required, causing validation to fail if the property is undefined, null, or empty.
|
|
22
|
+
* Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}.
|
|
23
|
+
* This decorator is commonly used as the first validation step for important fields.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
26
|
+
* @return {PropertyDecorator} A decorator function that can be applied to class properties
|
|
27
|
+
*
|
|
28
|
+
* @function required
|
|
29
|
+
* @category Property Decorators
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* class User {
|
|
34
|
+
* @required()
|
|
35
|
+
* username: string;
|
|
36
|
+
*
|
|
37
|
+
* @required("Email address is mandatory")
|
|
38
|
+
* email: string;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function required(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
43
|
+
/**
|
|
44
|
+
* @description Property decorator that enforces a minimum value constraint
|
|
45
|
+
* @summary Defines a minimum value for the property, causing validation to fail if the property value is less than the specified minimum.
|
|
46
|
+
* Validators to validate a decorated property must use key {@link ValidationKeys#MIN}.
|
|
47
|
+
* This decorator works with numeric values and dates.
|
|
48
|
+
*
|
|
49
|
+
* @param {number | Date | string} value - The minimum value allowed. For dates, can be a Date object or a string that can be converted to a date
|
|
50
|
+
* @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
51
|
+
* @return {PropertyDecorator} A decorator function that can be applied to class properties
|
|
52
|
+
*
|
|
53
|
+
* @function min
|
|
54
|
+
* @category Property Decorators
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* class Product {
|
|
59
|
+
* @min(0)
|
|
60
|
+
* price: number;
|
|
61
|
+
*
|
|
62
|
+
* @min(new Date(2023, 0, 1), "Date must be after January 1, 2023")
|
|
63
|
+
* releaseDate: Date;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function min(value: number | Date | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
68
|
+
/**
|
|
69
|
+
* @summary Defines a maximum value for the property
|
|
70
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
|
|
71
|
+
*
|
|
72
|
+
* @param {number | Date} value
|
|
73
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
74
|
+
*
|
|
75
|
+
* @function max
|
|
76
|
+
* @category Property Decorators
|
|
77
|
+
*/
|
|
78
|
+
export declare function max(value: number | Date | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
79
|
+
/**
|
|
80
|
+
* @summary Defines a step value for the property
|
|
81
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
|
|
82
|
+
*
|
|
83
|
+
* @param {number} value
|
|
84
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
85
|
+
*
|
|
86
|
+
* @function step
|
|
87
|
+
* @category Property Decorators
|
|
88
|
+
*/
|
|
89
|
+
export declare function step(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
90
|
+
/**
|
|
91
|
+
* @summary Defines a minimum length for the property
|
|
92
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
|
|
93
|
+
*
|
|
94
|
+
* @param {string} value
|
|
95
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
96
|
+
*
|
|
97
|
+
* @function minlength
|
|
98
|
+
* @category Property Decorators
|
|
99
|
+
*/
|
|
100
|
+
export declare function minlength(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
101
|
+
/**
|
|
102
|
+
* @summary Defines a maximum length for the property
|
|
103
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
|
|
104
|
+
*
|
|
105
|
+
* @param {string} value
|
|
106
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
107
|
+
*
|
|
108
|
+
* @function maxlength
|
|
109
|
+
* @category Property Decorators
|
|
110
|
+
*/
|
|
111
|
+
export declare function maxlength(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
112
|
+
/**
|
|
113
|
+
* @summary Defines a RegExp pattern the property must respect
|
|
114
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
|
|
115
|
+
*
|
|
116
|
+
* @param {string} value
|
|
117
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
118
|
+
*
|
|
119
|
+
* @function pattern
|
|
120
|
+
* @category Property Decorators
|
|
121
|
+
*/
|
|
122
|
+
export declare function pattern(value: RegExp | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
123
|
+
/**
|
|
124
|
+
* @summary Defines the property as an email
|
|
125
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
|
|
126
|
+
*
|
|
127
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
128
|
+
*
|
|
129
|
+
* @function email
|
|
130
|
+
* @category Property Decorators
|
|
131
|
+
*/
|
|
132
|
+
export declare function email(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
133
|
+
/**
|
|
134
|
+
* @summary Defines the property as an URL
|
|
135
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
|
|
136
|
+
*
|
|
137
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
138
|
+
*
|
|
139
|
+
* @function url
|
|
140
|
+
* @category Property Decorators
|
|
141
|
+
*/
|
|
142
|
+
export declare function url(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
143
|
+
export type TypeConstructor = Constructor | typeof BigInt;
|
|
144
|
+
export interface TypeMetadata extends ValidatorOptions {
|
|
145
|
+
customTypes: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @summary Enforces type verification
|
|
149
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
|
|
150
|
+
*
|
|
151
|
+
* @param {Constructor[] | Constructor} types accepted types
|
|
152
|
+
* @param {Constructor} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
153
|
+
*
|
|
154
|
+
* @function type
|
|
155
|
+
* @category Property Decorators
|
|
156
|
+
*/
|
|
157
|
+
export declare function type(types: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor), message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
158
|
+
export type DateMetadata = DateValidatorOptions;
|
|
159
|
+
/**
|
|
160
|
+
* @summary Date Handler Decorator
|
|
161
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
|
|
162
|
+
*
|
|
163
|
+
* Will enforce serialization according to the selected format
|
|
164
|
+
*
|
|
165
|
+
* @param {string} format accepted format according to {@link formatDate}
|
|
166
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
167
|
+
*
|
|
168
|
+
* @function date
|
|
169
|
+
*
|
|
170
|
+
* @category Property Decorators
|
|
171
|
+
*/
|
|
172
|
+
export declare function date(format?: string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
173
|
+
/**
|
|
174
|
+
* @summary Password Handler Decorator
|
|
175
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
|
|
176
|
+
*
|
|
177
|
+
* @param {RegExp} [pattern] defaults to {@link DEFAULT_PATTERNS#CHAR8_ONE_OF_EACH}
|
|
178
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
179
|
+
*
|
|
180
|
+
* @function password
|
|
181
|
+
*
|
|
182
|
+
* @category Property Decorators
|
|
183
|
+
*/
|
|
184
|
+
export declare function password(pattern?: RegExp, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
185
|
+
export interface ListMetadata extends ListValidatorOptions {
|
|
186
|
+
type: "Array" | "Set";
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @summary List Decorator
|
|
190
|
+
* @description Also sets the {@link type} to the provided collection
|
|
191
|
+
*
|
|
192
|
+
* @param {ModelConstructor} clazz
|
|
193
|
+
* @param {string} [collection] The collection being used. defaults to Array
|
|
194
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
195
|
+
*
|
|
196
|
+
* @function list
|
|
197
|
+
*
|
|
198
|
+
* @category Property Decorators
|
|
199
|
+
*/
|
|
200
|
+
export declare function list(clazz: Constructor | (() => Constructor) | (Constructor | (() => Constructor))[], collection?: "Array" | "Set", message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
201
|
+
/**
|
|
202
|
+
* @summary Set Decorator
|
|
203
|
+
* @description Wrapper for {@link list} with the 'Set' Collection
|
|
204
|
+
*
|
|
205
|
+
* @param {ModelConstructor} clazz
|
|
206
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
207
|
+
*
|
|
208
|
+
* @function set
|
|
209
|
+
*
|
|
210
|
+
* @category Property Decorators
|
|
211
|
+
*/
|
|
212
|
+
export declare function set(clazz: ModelConstructor<any>, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
213
|
+
/**
|
|
214
|
+
* @summary Declares that the decorated property must be equal to another specified property.
|
|
215
|
+
* @description Applies the {@link ValidationKeys.EQUALS} validator to ensure the decorated value matches the value of the given property.
|
|
216
|
+
*
|
|
217
|
+
* @param {string} propertyToCompare - The name of the property to compare equality against.
|
|
218
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
219
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
220
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.EQUALS] - Custom error message to be returned if validation fails.
|
|
221
|
+
*
|
|
222
|
+
* @returns {PropertyDecorator} A property decorator used to register the equality validation metadata.
|
|
223
|
+
*
|
|
224
|
+
* @function eq
|
|
225
|
+
* @category Property Decorators
|
|
226
|
+
*/
|
|
227
|
+
export declare function eq(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
228
|
+
/**
|
|
229
|
+
* @summary Declares that the decorated property must be different from another specified property.
|
|
230
|
+
* @description Applies the {@link ValidationKeys.DIFF} validator to ensure the decorated value is different from the value of the given property.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} propertyToCompare - The name of the property to compare difference against.
|
|
233
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
234
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
235
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.DIFF] - Custom error message to be returned if validation fails.
|
|
236
|
+
*
|
|
237
|
+
* @returns {PropertyDecorator} A property decorator used to register the difference validation metadata.
|
|
238
|
+
*
|
|
239
|
+
* @function diff
|
|
240
|
+
* @category Property Decorators
|
|
241
|
+
*/
|
|
242
|
+
export declare function diff(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
243
|
+
/**
|
|
244
|
+
* @summary Declares that the decorated property must be less than another specified property.
|
|
245
|
+
* @description Applies the {@link ValidationKeys.LESS_THAN} validator to ensure the decorated value is less than the value of the given property.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
248
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
249
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
250
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.LESS_THAN] - Custom error message to be returned if validation fails.
|
|
251
|
+
*
|
|
252
|
+
* @returns {PropertyDecorator} A property decorator used to register the less than validation metadata.
|
|
253
|
+
*
|
|
254
|
+
* @function lt
|
|
255
|
+
* @category Property Decorators
|
|
256
|
+
*/
|
|
257
|
+
export declare function lt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
258
|
+
/**
|
|
259
|
+
* @summary Declares that the decorated property must be equal or less than another specified property.
|
|
260
|
+
* @description Applies the {@link ValidationKeys.LESS_THAN_OR_EQUAL} validator to ensure the decorated value is equal or less than the value of the given property.
|
|
261
|
+
*
|
|
262
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
263
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
264
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
265
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.LESS_THAN_OR_EQUAL] - Custom error message to be returned if validation fails.
|
|
266
|
+
*
|
|
267
|
+
* @returns {PropertyDecorator} A property decorator used to register the less than or equal validation metadata.
|
|
268
|
+
*
|
|
269
|
+
* @function lte
|
|
270
|
+
* @category Property Decorators
|
|
271
|
+
*/
|
|
272
|
+
export declare function lte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
273
|
+
/**
|
|
274
|
+
* @summary Declares that the decorated property must be greater than another specified property.
|
|
275
|
+
* @description Applies the {@link ValidationKeys.GREATER_THAN} validator to ensure the decorated value is greater than the value of the given property.
|
|
276
|
+
*
|
|
277
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
278
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
279
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
280
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.GREATER_THAN] - Custom error message to be returned if validation fails.
|
|
281
|
+
*
|
|
282
|
+
* @returns {PropertyDecorator} A property decorator used to register the greater than validation metadata.
|
|
283
|
+
*
|
|
284
|
+
* @function gt
|
|
285
|
+
* @category Property Decorators
|
|
286
|
+
*/
|
|
287
|
+
export declare function gt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
288
|
+
/**
|
|
289
|
+
* @summary Declares that the decorated property must be equal or greater than another specified property.
|
|
290
|
+
* @description Applies the {@link ValidationKeys.GREATER_THAN_OR_EQUAL} validator to ensure the decorated value is equal or greater than the value of the given property.
|
|
291
|
+
*
|
|
292
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
293
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
294
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
295
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.GREATER_THAN_OR_EQUAL] - Custom error message to be returned if validation fails.
|
|
296
|
+
*
|
|
297
|
+
* @returns {PropertyDecorator} A property decorator used to register the greater than or equal validation metadata.
|
|
298
|
+
*
|
|
299
|
+
* @function gte
|
|
300
|
+
* @category Property Decorators
|
|
301
|
+
*/
|
|
302
|
+
export declare function gte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
303
|
+
/**
|
|
304
|
+
* @summary Defines a list or an object of accepted values for the property
|
|
305
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#ENUM}
|
|
306
|
+
*
|
|
307
|
+
* @param {any[] | Record<any, any>} value
|
|
308
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#ENUM}
|
|
309
|
+
*
|
|
310
|
+
* @function option
|
|
311
|
+
* @category Property Decorators
|
|
312
|
+
*/
|
|
313
|
+
export declare function option(value: any[] | Record<any, any>, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { ComparisonValidatorOptions, DateValidatorOptions, ListValidatorOptions, ValidatorOptions } from "./types.js";
|
|
2
|
+
import { ModelConstructor } from "../model/types.js";
|
|
3
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
4
|
+
/**
|
|
5
|
+
* @description Combined property decorator factory for metadata and attribute marking
|
|
6
|
+
* @summary Creates a decorator that both marks a property as a model attribute and assigns metadata to it
|
|
7
|
+
*
|
|
8
|
+
* @template V
|
|
9
|
+
* @param {PropertyDecorator} decorator - The metadata key
|
|
10
|
+
* @param {string} key - The metadata key
|
|
11
|
+
* @param {V} value - The metadata value to associate with the property
|
|
12
|
+
* @return {Function} - Combined decorator function
|
|
13
|
+
* @function validationMetadata
|
|
14
|
+
* @category Property Decorators
|
|
15
|
+
*/
|
|
16
|
+
export declare function validationMetadata<V>(decorator: any, key: string, value: V): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor | number) => void;
|
|
17
|
+
export declare function innerValidationDecorator(dec: any, key: string, meta: any): (obj: any, prop: any) => void;
|
|
18
|
+
export declare function async(): (model: object) => void;
|
|
19
|
+
/**
|
|
20
|
+
* @description Property decorator that marks a field as required
|
|
21
|
+
* @summary Marks the property as required, causing validation to fail if the property is undefined, null, or empty.
|
|
22
|
+
* Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}.
|
|
23
|
+
* This decorator is commonly used as the first validation step for important fields.
|
|
24
|
+
*
|
|
25
|
+
* @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
26
|
+
* @return {PropertyDecorator} A decorator function that can be applied to class properties
|
|
27
|
+
*
|
|
28
|
+
* @function required
|
|
29
|
+
* @category Property Decorators
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* class User {
|
|
34
|
+
* @required()
|
|
35
|
+
* username: string;
|
|
36
|
+
*
|
|
37
|
+
* @required("Email address is mandatory")
|
|
38
|
+
* email: string;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function required(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
43
|
+
/**
|
|
44
|
+
* @description Property decorator that enforces a minimum value constraint
|
|
45
|
+
* @summary Defines a minimum value for the property, causing validation to fail if the property value is less than the specified minimum.
|
|
46
|
+
* Validators to validate a decorated property must use key {@link ValidationKeys#MIN}.
|
|
47
|
+
* This decorator works with numeric values and dates.
|
|
48
|
+
*
|
|
49
|
+
* @param {number | Date | string} value - The minimum value allowed. For dates, can be a Date object or a string that can be converted to a date
|
|
50
|
+
* @param {string} [message] - The error message to display when validation fails. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
51
|
+
* @return {PropertyDecorator} A decorator function that can be applied to class properties
|
|
52
|
+
*
|
|
53
|
+
* @function min
|
|
54
|
+
* @category Property Decorators
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* class Product {
|
|
59
|
+
* @min(0)
|
|
60
|
+
* price: number;
|
|
61
|
+
*
|
|
62
|
+
* @min(new Date(2023, 0, 1), "Date must be after January 1, 2023")
|
|
63
|
+
* releaseDate: Date;
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare function min(value: number | Date | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
68
|
+
/**
|
|
69
|
+
* @summary Defines a maximum value for the property
|
|
70
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
|
|
71
|
+
*
|
|
72
|
+
* @param {number | Date} value
|
|
73
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
74
|
+
*
|
|
75
|
+
* @function max
|
|
76
|
+
* @category Property Decorators
|
|
77
|
+
*/
|
|
78
|
+
export declare function max(value: number | Date | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
79
|
+
/**
|
|
80
|
+
* @summary Defines a step value for the property
|
|
81
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
|
|
82
|
+
*
|
|
83
|
+
* @param {number} value
|
|
84
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
85
|
+
*
|
|
86
|
+
* @function step
|
|
87
|
+
* @category Property Decorators
|
|
88
|
+
*/
|
|
89
|
+
export declare function step(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
90
|
+
/**
|
|
91
|
+
* @summary Defines a minimum length for the property
|
|
92
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
|
|
93
|
+
*
|
|
94
|
+
* @param {string} value
|
|
95
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
96
|
+
*
|
|
97
|
+
* @function minlength
|
|
98
|
+
* @category Property Decorators
|
|
99
|
+
*/
|
|
100
|
+
export declare function minlength(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
101
|
+
/**
|
|
102
|
+
* @summary Defines a maximum length for the property
|
|
103
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
|
|
104
|
+
*
|
|
105
|
+
* @param {string} value
|
|
106
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
107
|
+
*
|
|
108
|
+
* @function maxlength
|
|
109
|
+
* @category Property Decorators
|
|
110
|
+
*/
|
|
111
|
+
export declare function maxlength(value: number, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
112
|
+
/**
|
|
113
|
+
* @summary Defines a RegExp pattern the property must respect
|
|
114
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
|
|
115
|
+
*
|
|
116
|
+
* @param {string} value
|
|
117
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
118
|
+
*
|
|
119
|
+
* @function pattern
|
|
120
|
+
* @category Property Decorators
|
|
121
|
+
*/
|
|
122
|
+
export declare function pattern(value: RegExp | string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
123
|
+
/**
|
|
124
|
+
* @summary Defines the property as an email
|
|
125
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
|
|
126
|
+
*
|
|
127
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
128
|
+
*
|
|
129
|
+
* @function email
|
|
130
|
+
* @category Property Decorators
|
|
131
|
+
*/
|
|
132
|
+
export declare function email(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
133
|
+
/**
|
|
134
|
+
* @summary Defines the property as an URL
|
|
135
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
|
|
136
|
+
*
|
|
137
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
138
|
+
*
|
|
139
|
+
* @function url
|
|
140
|
+
* @category Property Decorators
|
|
141
|
+
*/
|
|
142
|
+
export declare function url(message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
143
|
+
export type TypeConstructor = Constructor | typeof BigInt;
|
|
144
|
+
export interface TypeMetadata extends ValidatorOptions {
|
|
145
|
+
customTypes: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @summary Enforces type verification
|
|
149
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
|
|
150
|
+
*
|
|
151
|
+
* @param {Constructor[] | Constructor} types accepted types
|
|
152
|
+
* @param {Constructor} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
153
|
+
*
|
|
154
|
+
* @function type
|
|
155
|
+
* @category Property Decorators
|
|
156
|
+
*/
|
|
157
|
+
export declare function type(types: (TypeConstructor | (() => TypeConstructor))[] | TypeConstructor | (() => TypeConstructor), message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
158
|
+
export type DateMetadata = DateValidatorOptions;
|
|
159
|
+
/**
|
|
160
|
+
* @summary Date Handler Decorator
|
|
161
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
|
|
162
|
+
*
|
|
163
|
+
* Will enforce serialization according to the selected format
|
|
164
|
+
*
|
|
165
|
+
* @param {string} format accepted format according to {@link formatDate}
|
|
166
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
167
|
+
*
|
|
168
|
+
* @function date
|
|
169
|
+
*
|
|
170
|
+
* @category Property Decorators
|
|
171
|
+
*/
|
|
172
|
+
export declare function date(format?: string, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
173
|
+
/**
|
|
174
|
+
* @summary Password Handler Decorator
|
|
175
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
|
|
176
|
+
*
|
|
177
|
+
* @param {RegExp} [pattern] defaults to {@link DEFAULT_PATTERNS#CHAR8_ONE_OF_EACH}
|
|
178
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
179
|
+
*
|
|
180
|
+
* @function password
|
|
181
|
+
*
|
|
182
|
+
* @category Property Decorators
|
|
183
|
+
*/
|
|
184
|
+
export declare function password(pattern?: RegExp, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
185
|
+
export interface ListMetadata extends ListValidatorOptions {
|
|
186
|
+
type: "Array" | "Set";
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @summary List Decorator
|
|
190
|
+
* @description Also sets the {@link type} to the provided collection
|
|
191
|
+
*
|
|
192
|
+
* @param {ModelConstructor} clazz
|
|
193
|
+
* @param {string} [collection] The collection being used. defaults to Array
|
|
194
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
195
|
+
*
|
|
196
|
+
* @function list
|
|
197
|
+
*
|
|
198
|
+
* @category Property Decorators
|
|
199
|
+
*/
|
|
200
|
+
export declare function list(clazz: Constructor | (() => Constructor) | (Constructor | (() => Constructor))[], collection?: "Array" | "Set", message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
201
|
+
/**
|
|
202
|
+
* @summary Set Decorator
|
|
203
|
+
* @description Wrapper for {@link list} with the 'Set' Collection
|
|
204
|
+
*
|
|
205
|
+
* @param {ModelConstructor} clazz
|
|
206
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
207
|
+
*
|
|
208
|
+
* @function set
|
|
209
|
+
*
|
|
210
|
+
* @category Property Decorators
|
|
211
|
+
*/
|
|
212
|
+
export declare function set(clazz: ModelConstructor<any>, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
213
|
+
/**
|
|
214
|
+
* @summary Declares that the decorated property must be equal to another specified property.
|
|
215
|
+
* @description Applies the {@link ValidationKeys.EQUALS} validator to ensure the decorated value matches the value of the given property.
|
|
216
|
+
*
|
|
217
|
+
* @param {string} propertyToCompare - The name of the property to compare equality against.
|
|
218
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
219
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
220
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.EQUALS] - Custom error message to be returned if validation fails.
|
|
221
|
+
*
|
|
222
|
+
* @returns {PropertyDecorator} A property decorator used to register the equality validation metadata.
|
|
223
|
+
*
|
|
224
|
+
* @function eq
|
|
225
|
+
* @category Property Decorators
|
|
226
|
+
*/
|
|
227
|
+
export declare function eq(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
228
|
+
/**
|
|
229
|
+
* @summary Declares that the decorated property must be different from another specified property.
|
|
230
|
+
* @description Applies the {@link ValidationKeys.DIFF} validator to ensure the decorated value is different from the value of the given property.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} propertyToCompare - The name of the property to compare difference against.
|
|
233
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
234
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
235
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.DIFF] - Custom error message to be returned if validation fails.
|
|
236
|
+
*
|
|
237
|
+
* @returns {PropertyDecorator} A property decorator used to register the difference validation metadata.
|
|
238
|
+
*
|
|
239
|
+
* @function diff
|
|
240
|
+
* @category Property Decorators
|
|
241
|
+
*/
|
|
242
|
+
export declare function diff(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
243
|
+
/**
|
|
244
|
+
* @summary Declares that the decorated property must be less than another specified property.
|
|
245
|
+
* @description Applies the {@link ValidationKeys.LESS_THAN} validator to ensure the decorated value is less than the value of the given property.
|
|
246
|
+
*
|
|
247
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
248
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
249
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
250
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.LESS_THAN] - Custom error message to be returned if validation fails.
|
|
251
|
+
*
|
|
252
|
+
* @returns {PropertyDecorator} A property decorator used to register the less than validation metadata.
|
|
253
|
+
*
|
|
254
|
+
* @function lt
|
|
255
|
+
* @category Property Decorators
|
|
256
|
+
*/
|
|
257
|
+
export declare function lt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
258
|
+
/**
|
|
259
|
+
* @summary Declares that the decorated property must be equal or less than another specified property.
|
|
260
|
+
* @description Applies the {@link ValidationKeys.LESS_THAN_OR_EQUAL} validator to ensure the decorated value is equal or less than the value of the given property.
|
|
261
|
+
*
|
|
262
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
263
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
264
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
265
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.LESS_THAN_OR_EQUAL] - Custom error message to be returned if validation fails.
|
|
266
|
+
*
|
|
267
|
+
* @returns {PropertyDecorator} A property decorator used to register the less than or equal validation metadata.
|
|
268
|
+
*
|
|
269
|
+
* @function lte
|
|
270
|
+
* @category Property Decorators
|
|
271
|
+
*/
|
|
272
|
+
export declare function lte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
273
|
+
/**
|
|
274
|
+
* @summary Declares that the decorated property must be greater than another specified property.
|
|
275
|
+
* @description Applies the {@link ValidationKeys.GREATER_THAN} validator to ensure the decorated value is greater than the value of the given property.
|
|
276
|
+
*
|
|
277
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
278
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
279
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
280
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.GREATER_THAN] - Custom error message to be returned if validation fails.
|
|
281
|
+
*
|
|
282
|
+
* @returns {PropertyDecorator} A property decorator used to register the greater than validation metadata.
|
|
283
|
+
*
|
|
284
|
+
* @function gt
|
|
285
|
+
* @category Property Decorators
|
|
286
|
+
*/
|
|
287
|
+
export declare function gt(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
288
|
+
/**
|
|
289
|
+
* @summary Declares that the decorated property must be equal or greater than another specified property.
|
|
290
|
+
* @description Applies the {@link ValidationKeys.GREATER_THAN_OR_EQUAL} validator to ensure the decorated value is equal or greater than the value of the given property.
|
|
291
|
+
*
|
|
292
|
+
* @param {string} propertyToCompare - The name of the property to compare against.
|
|
293
|
+
* @param {ComparisonValidatorOptions} options - Options for the validator.
|
|
294
|
+
* @param {string} [options.label] - The label text displayed in the error message.
|
|
295
|
+
* @param {string} [options.message=DEFAULT_ERROR_MESSAGES.GREATER_THAN_OR_EQUAL] - Custom error message to be returned if validation fails.
|
|
296
|
+
*
|
|
297
|
+
* @returns {PropertyDecorator} A property decorator used to register the greater than or equal validation metadata.
|
|
298
|
+
*
|
|
299
|
+
* @function gte
|
|
300
|
+
* @category Property Decorators
|
|
301
|
+
*/
|
|
302
|
+
export declare function gte(propertyToCompare: string, options?: Omit<ComparisonValidatorOptions, "async" | "description">): (obj: any, prop: any) => void;
|
|
303
|
+
/**
|
|
304
|
+
* @summary Defines a list or an object of accepted values for the property
|
|
305
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#ENUM}
|
|
306
|
+
*
|
|
307
|
+
* @param {any[] | Record<any, any>} value
|
|
308
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#ENUM}
|
|
309
|
+
*
|
|
310
|
+
* @function option
|
|
311
|
+
* @category Property Decorators
|
|
312
|
+
*/
|
|
313
|
+
export declare function option(value: any[] | Record<any, any>, message?: string): (target: any, propertyKey?: any, descriptor?: TypedPropertyDescriptor<any>) => any;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Exports for the validation module.
|
|
3
|
+
* @summary This file exports all the necessary components for the validation functionality, including validators, decorators, types, and the Validation class.
|
|
4
|
+
* @module decorator-validation/validation
|
|
5
|
+
*/
|
|
6
|
+
export * from "./Validators/index.cjs";
|
|
7
|
+
export * from "./decorators.cjs";
|
|
8
|
+
export * from "./types.cjs";
|
|
9
|
+
export * from "./Validation.cjs";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description Exports for the validation module.
|
|
3
|
+
* @summary This file exports all the necessary components for the validation functionality, including validators, decorators, types, and the Validation class.
|
|
4
|
+
* @module decorator-validation/validation
|
|
5
|
+
*/
|
|
6
|
+
export * from "./Validators/index.js";
|
|
7
|
+
export * from "./decorators.js";
|
|
8
|
+
export * from "./types.js";
|
|
9
|
+
export * from "./Validation.js";
|