@decaf-ts/decorator-validation 1.15.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,68 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Basic interface for Registries
|
|
4
|
+
*
|
|
5
|
+
* @interface IRegistry
|
|
6
|
+
*
|
|
7
|
+
* @category Model
|
|
8
|
+
*/
|
|
9
|
+
export interface IRegistry<T> {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Registers an Object
|
|
12
|
+
*
|
|
13
|
+
* @param {T} obj
|
|
14
|
+
* @param {any[]} args
|
|
15
|
+
*
|
|
16
|
+
* @method
|
|
17
|
+
*/
|
|
18
|
+
register(obj: T | any, ...args: any[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* @summary Retrieves an Object if it can find it
|
|
21
|
+
*
|
|
22
|
+
* @param {any} key
|
|
23
|
+
* @param {any[]} args
|
|
24
|
+
* @return {T | undefined}
|
|
25
|
+
*
|
|
26
|
+
* @method
|
|
27
|
+
*/
|
|
28
|
+
get(key: any, ...args: any[]): T | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @summary Basic Builder Registry Interface
|
|
32
|
+
*
|
|
33
|
+
* @template T
|
|
34
|
+
* @interface BuilderRegistry<T>
|
|
35
|
+
*
|
|
36
|
+
* @category Model
|
|
37
|
+
*/
|
|
38
|
+
export interface BuilderRegistry<T> extends IRegistry<Constructor<T>> {
|
|
39
|
+
/**
|
|
40
|
+
* @summary Retrieves an Builder Object by name if it can
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name
|
|
43
|
+
* @param {any[]} args
|
|
44
|
+
*
|
|
45
|
+
* @method
|
|
46
|
+
*/
|
|
47
|
+
get(name: string, ...args: any[]): Constructor<T> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @summary Registers a constructor by name
|
|
50
|
+
*
|
|
51
|
+
* @param {Constructor<T>} [constructor]
|
|
52
|
+
* @param {name} name
|
|
53
|
+
* @param {any[]} args
|
|
54
|
+
*
|
|
55
|
+
* @method
|
|
56
|
+
*/
|
|
57
|
+
register(constructor: Constructor<T>, name?: string, ...args: any[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Builds an Object by name
|
|
60
|
+
*
|
|
61
|
+
* @param {{}} obj
|
|
62
|
+
* @param {any[]} args
|
|
63
|
+
* @return T
|
|
64
|
+
*
|
|
65
|
+
* @method
|
|
66
|
+
*/
|
|
67
|
+
build(obj: Record<string, any> | T, ...args: any[]): T;
|
|
68
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
/**
|
|
3
|
+
* @summary Basic interface for Registries
|
|
4
|
+
*
|
|
5
|
+
* @interface IRegistry
|
|
6
|
+
*
|
|
7
|
+
* @category Model
|
|
8
|
+
*/
|
|
9
|
+
export interface IRegistry<T> {
|
|
10
|
+
/**
|
|
11
|
+
* @summary Registers an Object
|
|
12
|
+
*
|
|
13
|
+
* @param {T} obj
|
|
14
|
+
* @param {any[]} args
|
|
15
|
+
*
|
|
16
|
+
* @method
|
|
17
|
+
*/
|
|
18
|
+
register(obj: T | any, ...args: any[]): void;
|
|
19
|
+
/**
|
|
20
|
+
* @summary Retrieves an Object if it can find it
|
|
21
|
+
*
|
|
22
|
+
* @param {any} key
|
|
23
|
+
* @param {any[]} args
|
|
24
|
+
* @return {T | undefined}
|
|
25
|
+
*
|
|
26
|
+
* @method
|
|
27
|
+
*/
|
|
28
|
+
get(key: any, ...args: any[]): T | undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @summary Basic Builder Registry Interface
|
|
32
|
+
*
|
|
33
|
+
* @template T
|
|
34
|
+
* @interface BuilderRegistry<T>
|
|
35
|
+
*
|
|
36
|
+
* @category Model
|
|
37
|
+
*/
|
|
38
|
+
export interface BuilderRegistry<T> extends IRegistry<Constructor<T>> {
|
|
39
|
+
/**
|
|
40
|
+
* @summary Retrieves an Builder Object by name if it can
|
|
41
|
+
*
|
|
42
|
+
* @param {string} name
|
|
43
|
+
* @param {any[]} args
|
|
44
|
+
*
|
|
45
|
+
* @method
|
|
46
|
+
*/
|
|
47
|
+
get(name: string, ...args: any[]): Constructor<T> | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* @summary Registers a constructor by name
|
|
50
|
+
*
|
|
51
|
+
* @param {Constructor<T>} [constructor]
|
|
52
|
+
* @param {name} name
|
|
53
|
+
* @param {any[]} args
|
|
54
|
+
*
|
|
55
|
+
* @method
|
|
56
|
+
*/
|
|
57
|
+
register(constructor: Constructor<T>, name?: string, ...args: any[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* @summary Builds an Object by name
|
|
60
|
+
*
|
|
61
|
+
* @param {{}} obj
|
|
62
|
+
* @param {any[]} args
|
|
63
|
+
* @return T
|
|
64
|
+
*
|
|
65
|
+
* @method
|
|
66
|
+
*/
|
|
67
|
+
build(obj: Record<string, any> | T, ...args: any[]): T;
|
|
68
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { Serializer } from "./types.cjs";
|
|
3
|
+
export declare class Serialization {
|
|
4
|
+
private static current;
|
|
5
|
+
private static cache;
|
|
6
|
+
private constructor();
|
|
7
|
+
private static get;
|
|
8
|
+
static register(key: string, func: Constructor<Serializer<any>>, setDefault?: boolean): void;
|
|
9
|
+
static serialize(obj: any, method?: string, ...args: any[]): any;
|
|
10
|
+
static deserialize(obj: string, method?: string, ...args: any[]): any;
|
|
11
|
+
static setDefault(method: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Constructor } from "@decaf-ts/decoration";
|
|
2
|
+
import { Serializer } from "./types.js";
|
|
3
|
+
export declare class Serialization {
|
|
4
|
+
private static current;
|
|
5
|
+
private static cache;
|
|
6
|
+
private constructor();
|
|
7
|
+
private static get;
|
|
8
|
+
static register(key: string, func: Constructor<Serializer<any>>, setDefault?: boolean): void;
|
|
9
|
+
static serialize(obj: any, method?: string, ...args: any[]): any;
|
|
10
|
+
static deserialize(obj: string, method?: string, ...args: any[]): any;
|
|
11
|
+
static setDefault(method: string): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Serializer } from "./types.cjs";
|
|
2
|
+
import { Model } from "../model/Model.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
5
|
+
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
6
|
+
* and therefore should not be used for hashing purposes
|
|
7
|
+
*
|
|
8
|
+
* To keep dependencies low, we will not implement this, but we recommend
|
|
9
|
+
* implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries
|
|
10
|
+
*
|
|
11
|
+
* @class JSONSerializer
|
|
12
|
+
* @implements Serializer
|
|
13
|
+
*
|
|
14
|
+
* @category Model
|
|
15
|
+
*/
|
|
16
|
+
export declare class JSONSerializer<T extends Model<boolean>> implements Serializer<T> {
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* @summary prepares the model for serialization
|
|
20
|
+
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
21
|
+
* so the object can be recognized upon deserialization
|
|
22
|
+
*
|
|
23
|
+
* @param {T} model
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
protected preSerialize(model: T, ...args: any[]): Record<string, any>;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Rebuilds a model from a serialization
|
|
29
|
+
* @param {string} str
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} If it fails to parse the string, or to build the model
|
|
32
|
+
*/
|
|
33
|
+
deserialize(str: string, ...args: any[]): T;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Serializes a model
|
|
36
|
+
* @param {T} model
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} if fails to serialize
|
|
39
|
+
*/
|
|
40
|
+
serialize(model: T, ...args: any[]): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Serializer } from "./types.js";
|
|
2
|
+
import { Model } from "../model/Model.js";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Concrete implementation of a {@link Serializer} in JSON format
|
|
5
|
+
* @description JS's native JSON.stringify (used here) is not deterministic
|
|
6
|
+
* and therefore should not be used for hashing purposes
|
|
7
|
+
*
|
|
8
|
+
* To keep dependencies low, we will not implement this, but we recommend
|
|
9
|
+
* implementing a similar {@link JSONSerializer} using 'deterministic-json' libraries
|
|
10
|
+
*
|
|
11
|
+
* @class JSONSerializer
|
|
12
|
+
* @implements Serializer
|
|
13
|
+
*
|
|
14
|
+
* @category Model
|
|
15
|
+
*/
|
|
16
|
+
export declare class JSONSerializer<T extends Model<boolean>> implements Serializer<T> {
|
|
17
|
+
constructor();
|
|
18
|
+
/**
|
|
19
|
+
* @summary prepares the model for serialization
|
|
20
|
+
* @description returns a shallow copy of the object, containing an enumerable {@link ModelKeys#ANCHOR} property
|
|
21
|
+
* so the object can be recognized upon deserialization
|
|
22
|
+
*
|
|
23
|
+
* @param {T} model
|
|
24
|
+
* @protected
|
|
25
|
+
*/
|
|
26
|
+
protected preSerialize(model: T, ...args: any[]): Record<string, any>;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Rebuilds a model from a serialization
|
|
29
|
+
* @param {string} str
|
|
30
|
+
*
|
|
31
|
+
* @throws {Error} If it fails to parse the string, or to build the model
|
|
32
|
+
*/
|
|
33
|
+
deserialize(str: string, ...args: any[]): T;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Serializes a model
|
|
36
|
+
* @param {T} model
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} if fails to serialize
|
|
39
|
+
*/
|
|
40
|
+
serialize(model: T, ...args: any[]): string;
|
|
41
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
3
|
+
*
|
|
4
|
+
* @param {string} string
|
|
5
|
+
* @param {Array<string | number>} [args] replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
6
|
+
* @return {string} formatted string
|
|
7
|
+
*
|
|
8
|
+
* @function stringFormat
|
|
9
|
+
* @memberOf module:decorator-validation
|
|
10
|
+
* @category Model
|
|
11
|
+
*/
|
|
12
|
+
export declare function stringFormat(string: string, ...args: (string | number)[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
15
|
+
* @description alias for {@link stringFormat}
|
|
16
|
+
*
|
|
17
|
+
* @param {string} string
|
|
18
|
+
* @param {string} args replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
19
|
+
* @return {string} formatted string
|
|
20
|
+
*
|
|
21
|
+
* @function sf
|
|
22
|
+
* @memberOf module:decorator-validation
|
|
23
|
+
* @category Model
|
|
24
|
+
*/
|
|
25
|
+
export declare const sf: typeof stringFormat;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
3
|
+
*
|
|
4
|
+
* @param {string} string
|
|
5
|
+
* @param {Array<string | number>} [args] replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
6
|
+
* @return {string} formatted string
|
|
7
|
+
*
|
|
8
|
+
* @function stringFormat
|
|
9
|
+
* @memberOf module:decorator-validation
|
|
10
|
+
* @category Model
|
|
11
|
+
*/
|
|
12
|
+
export declare function stringFormat(string: string, ...args: (string | number)[]): string;
|
|
13
|
+
/**
|
|
14
|
+
* @summary Util function to provide string format functionality similar to C#'s string.format
|
|
15
|
+
* @description alias for {@link stringFormat}
|
|
16
|
+
*
|
|
17
|
+
* @param {string} string
|
|
18
|
+
* @param {string} args replacements made by order of appearance (replacement0 wil replace {0} and so on)
|
|
19
|
+
* @return {string} formatted string
|
|
20
|
+
*
|
|
21
|
+
* @function sf
|
|
22
|
+
* @memberOf module:decorator-validation
|
|
23
|
+
* @category Model
|
|
24
|
+
*/
|
|
25
|
+
export declare const sf: typeof stringFormat;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Model } from "../model/index.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* @description Interface for serializing and deserializing model objects
|
|
4
|
+
* @summary Defines the contract for classes that can convert model objects to and from string representations.
|
|
5
|
+
* Serializers are used to persist models or transmit them over networks.
|
|
6
|
+
*
|
|
7
|
+
* @interface Serializer
|
|
8
|
+
* @template T Type of model that can be serialized, must extend Model
|
|
9
|
+
* @memberOf module:decorator-validation
|
|
10
|
+
* @category Model
|
|
11
|
+
*/
|
|
12
|
+
export interface Serializer<M extends Model> {
|
|
13
|
+
/**
|
|
14
|
+
* @description Converts a model object to a string representation
|
|
15
|
+
* @summary Serializes a model instance into a string format that can be stored or transmitted.
|
|
16
|
+
* Additional arguments can be provided to customize the serialization process.
|
|
17
|
+
*
|
|
18
|
+
* @param {T} model - The model instance to serialize
|
|
19
|
+
* @param {...any} args - Additional arguments for the serialization process
|
|
20
|
+
* @return {string} The serialized representation of the model
|
|
21
|
+
* @throws {Error} If the model cannot be serialized
|
|
22
|
+
*/
|
|
23
|
+
serialize(model: M, ...args: any[]): string;
|
|
24
|
+
/**
|
|
25
|
+
* @description Reconstructs a model object from its string representation
|
|
26
|
+
* @summary Deserializes a string back into a model instance.
|
|
27
|
+
* Additional arguments can be provided to customize the deserialization process.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} str - The serialized string to convert back to a model
|
|
30
|
+
* @param {...any} args - Additional arguments for the deserialization process
|
|
31
|
+
* @return {T} The reconstructed model instance
|
|
32
|
+
* @throws {Error} If the string cannot be deserialized into a valid model
|
|
33
|
+
*/
|
|
34
|
+
deserialize(str: string, ...args: any[]): M;
|
|
35
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Model } from "../model/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* @description Interface for serializing and deserializing model objects
|
|
4
|
+
* @summary Defines the contract for classes that can convert model objects to and from string representations.
|
|
5
|
+
* Serializers are used to persist models or transmit them over networks.
|
|
6
|
+
*
|
|
7
|
+
* @interface Serializer
|
|
8
|
+
* @template T Type of model that can be serialized, must extend Model
|
|
9
|
+
* @memberOf module:decorator-validation
|
|
10
|
+
* @category Model
|
|
11
|
+
*/
|
|
12
|
+
export interface Serializer<M extends Model> {
|
|
13
|
+
/**
|
|
14
|
+
* @description Converts a model object to a string representation
|
|
15
|
+
* @summary Serializes a model instance into a string format that can be stored or transmitted.
|
|
16
|
+
* Additional arguments can be provided to customize the serialization process.
|
|
17
|
+
*
|
|
18
|
+
* @param {T} model - The model instance to serialize
|
|
19
|
+
* @param {...any} args - Additional arguments for the serialization process
|
|
20
|
+
* @return {string} The serialized representation of the model
|
|
21
|
+
* @throws {Error} If the model cannot be serialized
|
|
22
|
+
*/
|
|
23
|
+
serialize(model: M, ...args: any[]): string;
|
|
24
|
+
/**
|
|
25
|
+
* @description Reconstructs a model object from its string representation
|
|
26
|
+
* @summary Deserializes a string back into a model instance.
|
|
27
|
+
* Additional arguments can be provided to customize the deserialization process.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} str - The serialized string to convert back to a model
|
|
30
|
+
* @param {...any} args - Additional arguments for the deserialization process
|
|
31
|
+
* @return {T} The reconstructed model instance
|
|
32
|
+
* @throws {Error} If the string cannot be deserialized into a valid model
|
|
33
|
+
*/
|
|
34
|
+
deserialize(str: string, ...args: any[]): M;
|
|
35
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Validator } from "./Validators/Validator.cjs";
|
|
2
|
+
import { IValidatorRegistry, ValidatorDefinition } from "./types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Static class acting as a namespace for the Validation
|
|
5
|
+
*
|
|
6
|
+
* @class Validation
|
|
7
|
+
* @static
|
|
8
|
+
*
|
|
9
|
+
* @category Validation
|
|
10
|
+
*/
|
|
11
|
+
export declare class Validation {
|
|
12
|
+
private static actingValidatorRegistry?;
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* @summary Defines the acting ValidatorRegistry
|
|
16
|
+
*
|
|
17
|
+
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
18
|
+
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
19
|
+
*/
|
|
20
|
+
static setRegistry(validatorRegistry: IValidatorRegistry<Validator>, migrationHandler?: (validator: Validator) => Validator): void;
|
|
21
|
+
/**
|
|
22
|
+
* @summary Returns the current ValidatorRegistry
|
|
23
|
+
*
|
|
24
|
+
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
25
|
+
*/
|
|
26
|
+
private static getRegistry;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Retrieves a validator
|
|
29
|
+
*
|
|
30
|
+
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
31
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
32
|
+
*/
|
|
33
|
+
static get<T extends Validator>(validatorKey: string): T | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Registers the provided validators onto the registry
|
|
36
|
+
*
|
|
37
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
38
|
+
*/
|
|
39
|
+
static register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* @summary Builds the key to store as Metadata under Reflections
|
|
42
|
+
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
43
|
+
*
|
|
44
|
+
* @param {string} key
|
|
45
|
+
*/
|
|
46
|
+
static key(key: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* @summary Returns all registered validation keys
|
|
49
|
+
*/
|
|
50
|
+
static keys(): string[];
|
|
51
|
+
static registerDecorator(key: string, decorator: (...args: any[]) => PropertyDecorator): void;
|
|
52
|
+
static decoratorFromKey(key: string): any;
|
|
53
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Validator } from "./Validators/Validator.js";
|
|
2
|
+
import { IValidatorRegistry, ValidatorDefinition } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @summary Static class acting as a namespace for the Validation
|
|
5
|
+
*
|
|
6
|
+
* @class Validation
|
|
7
|
+
* @static
|
|
8
|
+
*
|
|
9
|
+
* @category Validation
|
|
10
|
+
*/
|
|
11
|
+
export declare class Validation {
|
|
12
|
+
private static actingValidatorRegistry?;
|
|
13
|
+
private constructor();
|
|
14
|
+
/**
|
|
15
|
+
* @summary Defines the acting ValidatorRegistry
|
|
16
|
+
*
|
|
17
|
+
* @param {IValidatorRegistry} validatorRegistry the new implementation of the validator Registry
|
|
18
|
+
* @param {function(Validator): Validator} [migrationHandler] the method to map the validator if required;
|
|
19
|
+
*/
|
|
20
|
+
static setRegistry(validatorRegistry: IValidatorRegistry<Validator>, migrationHandler?: (validator: Validator) => Validator): void;
|
|
21
|
+
/**
|
|
22
|
+
* @summary Returns the current ValidatorRegistry
|
|
23
|
+
*
|
|
24
|
+
* @return IValidatorRegistry, defaults to {@link ValidatorRegistry}
|
|
25
|
+
*/
|
|
26
|
+
private static getRegistry;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Retrieves a validator
|
|
29
|
+
*
|
|
30
|
+
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
31
|
+
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
32
|
+
*/
|
|
33
|
+
static get<T extends Validator>(validatorKey: string): T | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* @summary Registers the provided validators onto the registry
|
|
36
|
+
*
|
|
37
|
+
* @param {T[] | ValidatorDefinition[]} validator
|
|
38
|
+
*/
|
|
39
|
+
static register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
40
|
+
/**
|
|
41
|
+
* @summary Builds the key to store as Metadata under Reflections
|
|
42
|
+
* @description concatenates {@link ValidationKeys#REFLECT} with the provided key
|
|
43
|
+
*
|
|
44
|
+
* @param {string} key
|
|
45
|
+
*/
|
|
46
|
+
static key(key: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* @summary Returns all registered validation keys
|
|
49
|
+
*/
|
|
50
|
+
static keys(): string[];
|
|
51
|
+
static registerDecorator(key: string, decorator: (...args: any[]) => PropertyDecorator): void;
|
|
52
|
+
static decoratorFromKey(key: string): any;
|
|
53
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ValidatorOptions } from "../types.cjs";
|
|
2
|
+
import type { PathProxy } from "../../utils/index.cjs";
|
|
3
|
+
import { BaseValidator } from "./BaseValidator.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* Abstract class for defining asynchronous validators.
|
|
7
|
+
*
|
|
8
|
+
* This class extends the base `Validator` and enforces that any implementation
|
|
9
|
+
* of `hasErrors` must be asynchronous, always returning a Promise.
|
|
10
|
+
*
|
|
11
|
+
* Use this when the validation process involves asynchronous operations,
|
|
12
|
+
* such as API calls, database lookups, or time-based checks (e.g., timeouts).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Example of an asynchronous validator that compares value against a timeout
|
|
17
|
+
* class TimeoutValidator extends AsyncValidator<{ timeout?: number }> {
|
|
18
|
+
* constructor(message: string = "Validation failed due to timeout") {
|
|
19
|
+
* super(message);
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* async hasErrors(value: number, options?: { timeout?: number }) {
|
|
23
|
+
* const delay = options?.timeout ?? 100;
|
|
24
|
+
*
|
|
25
|
+
* // async call
|
|
26
|
+
* await new Promise(res => setTimeout(res, delay));
|
|
27
|
+
*
|
|
28
|
+
* if (value > delay) {
|
|
29
|
+
* // Rejects the validation after waiting the delay if value is greater
|
|
30
|
+
* return Promise.resolve(this.getMessage());
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Passes the validation after waiting the delay
|
|
34
|
+
* return Promise.resolve(undefined);
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // Example usage:
|
|
39
|
+
* const validator = new TimeoutValidator();
|
|
40
|
+
*
|
|
41
|
+
* async function runValidation() {
|
|
42
|
+
* const error = await validator.hasErrors(50, { timeout: 100 });
|
|
43
|
+
* if (error) {
|
|
44
|
+
* return console.error('Validation error:', error);
|
|
45
|
+
* }
|
|
46
|
+
* console.log('Value is valid');
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* await runValidation();
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* - If `value > timeout`, the validator waits for the delay and then rejects with an error.
|
|
53
|
+
* - If `value <= timeout`, the validator waits for the delay and resolves successfully with `undefined`.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link Validator} For the base synchronous validator.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class AsyncValidator<V extends ValidatorOptions> extends BaseValidator<V, true> {
|
|
58
|
+
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
59
|
+
/**
|
|
60
|
+
* @description
|
|
61
|
+
* Asynchronously validates a value.
|
|
62
|
+
*
|
|
63
|
+
* @template V - Type of the option object that can be passed to the validator
|
|
64
|
+
* @param {any} value - The value to validate
|
|
65
|
+
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
66
|
+
* @param {PathProxy<any>} proxy -
|
|
67
|
+
* @return Promise<string | undefined> Error message if validation fails, undefined if validation passes
|
|
68
|
+
*
|
|
69
|
+
* @see {@link Validator}
|
|
70
|
+
*/
|
|
71
|
+
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): Promise<string | undefined>;
|
|
72
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { ValidatorOptions } from "../types.js";
|
|
2
|
+
import type { PathProxy } from "../../utils/index.js";
|
|
3
|
+
import { BaseValidator } from "./BaseValidator.js";
|
|
4
|
+
/**
|
|
5
|
+
* @description
|
|
6
|
+
* Abstract class for defining asynchronous validators.
|
|
7
|
+
*
|
|
8
|
+
* This class extends the base `Validator` and enforces that any implementation
|
|
9
|
+
* of `hasErrors` must be asynchronous, always returning a Promise.
|
|
10
|
+
*
|
|
11
|
+
* Use this when the validation process involves asynchronous operations,
|
|
12
|
+
* such as API calls, database lookups, or time-based checks (e.g., timeouts).
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Example of an asynchronous validator that compares value against a timeout
|
|
17
|
+
* class TimeoutValidator extends AsyncValidator<{ timeout?: number }> {
|
|
18
|
+
* constructor(message: string = "Validation failed due to timeout") {
|
|
19
|
+
* super(message);
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* async hasErrors(value: number, options?: { timeout?: number }) {
|
|
23
|
+
* const delay = options?.timeout ?? 100;
|
|
24
|
+
*
|
|
25
|
+
* // async call
|
|
26
|
+
* await new Promise(res => setTimeout(res, delay));
|
|
27
|
+
*
|
|
28
|
+
* if (value > delay) {
|
|
29
|
+
* // Rejects the validation after waiting the delay if value is greater
|
|
30
|
+
* return Promise.resolve(this.getMessage());
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* // Passes the validation after waiting the delay
|
|
34
|
+
* return Promise.resolve(undefined);
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
*
|
|
38
|
+
* // Example usage:
|
|
39
|
+
* const validator = new TimeoutValidator();
|
|
40
|
+
*
|
|
41
|
+
* async function runValidation() {
|
|
42
|
+
* const error = await validator.hasErrors(50, { timeout: 100 });
|
|
43
|
+
* if (error) {
|
|
44
|
+
* return console.error('Validation error:', error);
|
|
45
|
+
* }
|
|
46
|
+
* console.log('Value is valid');
|
|
47
|
+
* }
|
|
48
|
+
*
|
|
49
|
+
* await runValidation();
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* - If `value > timeout`, the validator waits for the delay and then rejects with an error.
|
|
53
|
+
* - If `value <= timeout`, the validator waits for the delay and resolves successfully with `undefined`.
|
|
54
|
+
*
|
|
55
|
+
* @see {@link Validator} For the base synchronous validator.
|
|
56
|
+
*/
|
|
57
|
+
export declare abstract class AsyncValidator<V extends ValidatorOptions> extends BaseValidator<V, true> {
|
|
58
|
+
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
59
|
+
/**
|
|
60
|
+
* @description
|
|
61
|
+
* Asynchronously validates a value.
|
|
62
|
+
*
|
|
63
|
+
* @template V - Type of the option object that can be passed to the validator
|
|
64
|
+
* @param {any} value - The value to validate
|
|
65
|
+
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
66
|
+
* @param {PathProxy<any>} proxy -
|
|
67
|
+
* @return Promise<string | undefined> Error message if validation fails, undefined if validation passes
|
|
68
|
+
*
|
|
69
|
+
* @see {@link Validator}
|
|
70
|
+
*/
|
|
71
|
+
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): Promise<string | undefined>;
|
|
72
|
+
}
|