@decaf-ts/decorator-validation 1.15.0 → 1.17.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 +4 -4
- 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,118 @@
|
|
|
1
|
+
import { ValidatorOptions } from "../types.cjs";
|
|
2
|
+
import type { PathProxy } from "../../utils/index.cjs";
|
|
3
|
+
import type { ConditionalAsync } from "../../types/index.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @description Abstract base class for all validators in the validation framework.
|
|
6
|
+
* @summary The BaseValidator class provides the foundation for all synchronous and asynchronous validator implementations.
|
|
7
|
+
* It handles type checking, error message formatting, and defines the interface that all validators must implement.
|
|
8
|
+
* This class is designed to be extended by specific validator classes that define their own validation logic.
|
|
9
|
+
*
|
|
10
|
+
* @template V - Validator options type
|
|
11
|
+
* @template IsAsync - Whether the validator is async (true) or sync (false). Default `false`.
|
|
12
|
+
*
|
|
13
|
+
* @param {boolean} async - Defines if the validator is async (must match the subclass signature)
|
|
14
|
+
* @param {string} message - Default error message to display when validation fails (defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT})
|
|
15
|
+
* @param {string[]} acceptedTypes - Type names that this validator accepts (used for runtime type checking)
|
|
16
|
+
*
|
|
17
|
+
* @class BaseValidator
|
|
18
|
+
* @abstract
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Example of a synchronous validator
|
|
22
|
+
* class SyncValidator extends BaseValidator<SomeOptions, false> {
|
|
23
|
+
* constructor() {
|
|
24
|
+
* super(false, "Sync validation failed", String.name);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* public hasErrors(value: any, options?: SomeOptions): string | undefined {
|
|
28
|
+
* if (typeof value !== "string") return this.getMessage(this.message);
|
|
29
|
+
* return undefined;
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Example of an asynchronous custom validator
|
|
35
|
+
* class AsyncValidator extends BaseValidator<SomeOptions, true> {
|
|
36
|
+
* constructor() {
|
|
37
|
+
* super(true, "Async validation failed", String.name);
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* public async hasErrors(value: any, options?: SomeOptions): Promise<string | undefined> {
|
|
41
|
+
* const result = await someAsyncCheck(value);
|
|
42
|
+
* if (!result) return this.getMessage(this.message);
|
|
43
|
+
* return undefined;
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* @mermaid
|
|
48
|
+
* sequenceDiagram
|
|
49
|
+
* participant C as Client
|
|
50
|
+
* participant V as Validator Subclass
|
|
51
|
+
* participant B as BaseValidator
|
|
52
|
+
*
|
|
53
|
+
* C->>V: new CustomValidator(async, message)
|
|
54
|
+
* V->>B: super(async, message, acceptedTypes)
|
|
55
|
+
* B->>B: Store message, async flag, and accepted types
|
|
56
|
+
* B->>B: Optionally wrap hasErrors with type checking
|
|
57
|
+
* C->>V: hasErrors(value, options)
|
|
58
|
+
* alt value type not in acceptedTypes
|
|
59
|
+
* B-->>C: Type error message
|
|
60
|
+
* else value type is accepted
|
|
61
|
+
* V->>V: Custom validation logic
|
|
62
|
+
* V-->>C: Validation result
|
|
63
|
+
* end
|
|
64
|
+
*
|
|
65
|
+
* @category Validators
|
|
66
|
+
*/
|
|
67
|
+
export declare abstract class BaseValidator<V extends ValidatorOptions = ValidatorOptions, Async extends boolean = false> {
|
|
68
|
+
readonly message: string;
|
|
69
|
+
readonly acceptedTypes?: string[];
|
|
70
|
+
readonly async?: Async;
|
|
71
|
+
protected constructor(async: Async, message?: string, ...acceptedTypes: string[]);
|
|
72
|
+
/**
|
|
73
|
+
* @description Formats an error message with optional arguments
|
|
74
|
+
* @summary Creates a formatted error message by replacing placeholders with provided arguments.
|
|
75
|
+
* This method uses the string formatting utility to generate consistent error messages
|
|
76
|
+
* across all validators.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} message - The message template with placeholders
|
|
79
|
+
* @param {...any} args - Values to insert into the message template
|
|
80
|
+
* @return {string} The formatted error message
|
|
81
|
+
* @protected
|
|
82
|
+
*/
|
|
83
|
+
protected getMessage(message: string, ...args: any[]): string;
|
|
84
|
+
/**
|
|
85
|
+
* @description Creates a type-checking wrapper around the hasErrors method
|
|
86
|
+
* @summary Wraps the hasErrors method with type validation logic to ensure that
|
|
87
|
+
* the value being validated is of an accepted type before performing specific validation.
|
|
88
|
+
* This method is called during construction if acceptedTypes are provided.
|
|
89
|
+
*
|
|
90
|
+
* @param {Function} unbound - The original hasErrors method to be wrapped
|
|
91
|
+
* @return {Function} A new function that performs type checking before calling the original method
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
private checkTypeAndHasErrors;
|
|
95
|
+
/**
|
|
96
|
+
* @description Validates a value against specific validation rules
|
|
97
|
+
* @summary Abstract method that must be implemented by all validator subclasses.
|
|
98
|
+
* This method contains the core validation logic that determines whether a value
|
|
99
|
+
* is valid according to the specific rules of the validator. If the value is valid,
|
|
100
|
+
* the method returns undefined; otherwise, it returns an error message.
|
|
101
|
+
*
|
|
102
|
+
* @template V - Type of the options object that can be passed to the validator
|
|
103
|
+
* @param {any} value - The value to validate
|
|
104
|
+
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
105
|
+
* @param {PathProxy<any>} proxy -
|
|
106
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
107
|
+
*
|
|
108
|
+
* @abstract
|
|
109
|
+
*
|
|
110
|
+
* @see Model#validate
|
|
111
|
+
*/
|
|
112
|
+
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): ConditionalAsync<Async, string | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* @summary Duck typing for Validators
|
|
115
|
+
* @param val
|
|
116
|
+
*/
|
|
117
|
+
static isValidator(val: any): boolean;
|
|
118
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { ValidatorOptions } from "../types.js";
|
|
2
|
+
import type { PathProxy } from "../../utils/index.js";
|
|
3
|
+
import type { ConditionalAsync } from "../../types/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @description Abstract base class for all validators in the validation framework.
|
|
6
|
+
* @summary The BaseValidator class provides the foundation for all synchronous and asynchronous validator implementations.
|
|
7
|
+
* It handles type checking, error message formatting, and defines the interface that all validators must implement.
|
|
8
|
+
* This class is designed to be extended by specific validator classes that define their own validation logic.
|
|
9
|
+
*
|
|
10
|
+
* @template V - Validator options type
|
|
11
|
+
* @template IsAsync - Whether the validator is async (true) or sync (false). Default `false`.
|
|
12
|
+
*
|
|
13
|
+
* @param {boolean} async - Defines if the validator is async (must match the subclass signature)
|
|
14
|
+
* @param {string} message - Default error message to display when validation fails (defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT})
|
|
15
|
+
* @param {string[]} acceptedTypes - Type names that this validator accepts (used for runtime type checking)
|
|
16
|
+
*
|
|
17
|
+
* @class BaseValidator
|
|
18
|
+
* @abstract
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Example of a synchronous validator
|
|
22
|
+
* class SyncValidator extends BaseValidator<SomeOptions, false> {
|
|
23
|
+
* constructor() {
|
|
24
|
+
* super(false, "Sync validation failed", String.name);
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* public hasErrors(value: any, options?: SomeOptions): string | undefined {
|
|
28
|
+
* if (typeof value !== "string") return this.getMessage(this.message);
|
|
29
|
+
* return undefined;
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Example of an asynchronous custom validator
|
|
35
|
+
* class AsyncValidator extends BaseValidator<SomeOptions, true> {
|
|
36
|
+
* constructor() {
|
|
37
|
+
* super(true, "Async validation failed", String.name);
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* public async hasErrors(value: any, options?: SomeOptions): Promise<string | undefined> {
|
|
41
|
+
* const result = await someAsyncCheck(value);
|
|
42
|
+
* if (!result) return this.getMessage(this.message);
|
|
43
|
+
* return undefined;
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
*
|
|
47
|
+
* @mermaid
|
|
48
|
+
* sequenceDiagram
|
|
49
|
+
* participant C as Client
|
|
50
|
+
* participant V as Validator Subclass
|
|
51
|
+
* participant B as BaseValidator
|
|
52
|
+
*
|
|
53
|
+
* C->>V: new CustomValidator(async, message)
|
|
54
|
+
* V->>B: super(async, message, acceptedTypes)
|
|
55
|
+
* B->>B: Store message, async flag, and accepted types
|
|
56
|
+
* B->>B: Optionally wrap hasErrors with type checking
|
|
57
|
+
* C->>V: hasErrors(value, options)
|
|
58
|
+
* alt value type not in acceptedTypes
|
|
59
|
+
* B-->>C: Type error message
|
|
60
|
+
* else value type is accepted
|
|
61
|
+
* V->>V: Custom validation logic
|
|
62
|
+
* V-->>C: Validation result
|
|
63
|
+
* end
|
|
64
|
+
*
|
|
65
|
+
* @category Validators
|
|
66
|
+
*/
|
|
67
|
+
export declare abstract class BaseValidator<V extends ValidatorOptions = ValidatorOptions, Async extends boolean = false> {
|
|
68
|
+
readonly message: string;
|
|
69
|
+
readonly acceptedTypes?: string[];
|
|
70
|
+
readonly async?: Async;
|
|
71
|
+
protected constructor(async: Async, message?: string, ...acceptedTypes: string[]);
|
|
72
|
+
/**
|
|
73
|
+
* @description Formats an error message with optional arguments
|
|
74
|
+
* @summary Creates a formatted error message by replacing placeholders with provided arguments.
|
|
75
|
+
* This method uses the string formatting utility to generate consistent error messages
|
|
76
|
+
* across all validators.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} message - The message template with placeholders
|
|
79
|
+
* @param {...any} args - Values to insert into the message template
|
|
80
|
+
* @return {string} The formatted error message
|
|
81
|
+
* @protected
|
|
82
|
+
*/
|
|
83
|
+
protected getMessage(message: string, ...args: any[]): string;
|
|
84
|
+
/**
|
|
85
|
+
* @description Creates a type-checking wrapper around the hasErrors method
|
|
86
|
+
* @summary Wraps the hasErrors method with type validation logic to ensure that
|
|
87
|
+
* the value being validated is of an accepted type before performing specific validation.
|
|
88
|
+
* This method is called during construction if acceptedTypes are provided.
|
|
89
|
+
*
|
|
90
|
+
* @param {Function} unbound - The original hasErrors method to be wrapped
|
|
91
|
+
* @return {Function} A new function that performs type checking before calling the original method
|
|
92
|
+
* @private
|
|
93
|
+
*/
|
|
94
|
+
private checkTypeAndHasErrors;
|
|
95
|
+
/**
|
|
96
|
+
* @description Validates a value against specific validation rules
|
|
97
|
+
* @summary Abstract method that must be implemented by all validator subclasses.
|
|
98
|
+
* This method contains the core validation logic that determines whether a value
|
|
99
|
+
* is valid according to the specific rules of the validator. If the value is valid,
|
|
100
|
+
* the method returns undefined; otherwise, it returns an error message.
|
|
101
|
+
*
|
|
102
|
+
* @template V - Type of the options object that can be passed to the validator
|
|
103
|
+
* @param {any} value - The value to validate
|
|
104
|
+
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
105
|
+
* @param {PathProxy<any>} proxy -
|
|
106
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
107
|
+
*
|
|
108
|
+
* @abstract
|
|
109
|
+
*
|
|
110
|
+
* @see Model#validate
|
|
111
|
+
*/
|
|
112
|
+
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): ConditionalAsync<Async, string | undefined>;
|
|
113
|
+
/**
|
|
114
|
+
* @summary Duck typing for Validators
|
|
115
|
+
* @param val
|
|
116
|
+
*/
|
|
117
|
+
static isValidator(val: any): boolean;
|
|
118
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Validator } from "./Validator.cjs";
|
|
2
|
+
import { DateValidatorOptions } from "../types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Validator for checking if a value is a valid date
|
|
5
|
+
* @summary The DateValidator checks if a value is a valid date object or a string that can be converted to a valid date.
|
|
6
|
+
* It validates that the value represents a real date and not an invalid date like "2023-02-31".
|
|
7
|
+
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
8
|
+
* @class DateValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Create a date validator with default error message
|
|
15
|
+
* const dateValidator = new DateValidator();
|
|
16
|
+
*
|
|
17
|
+
* // Create a date validator with custom error message
|
|
18
|
+
* const customDateValidator = new DateValidator("Please enter a valid date");
|
|
19
|
+
*
|
|
20
|
+
* // Validate a date
|
|
21
|
+
* const result = dateValidator.hasErrors(new Date()); // undefined (valid)
|
|
22
|
+
* const invalidResult = dateValidator.hasErrors("not a date"); // Returns error message (invalid)
|
|
23
|
+
* ```
|
|
24
|
+
* @mermaid
|
|
25
|
+
* sequenceDiagram
|
|
26
|
+
* participant C as Client
|
|
27
|
+
* participant V as DateValidator
|
|
28
|
+
*
|
|
29
|
+
* C->>V: new DateValidator(message)
|
|
30
|
+
* C->>V: hasErrors(value, options)
|
|
31
|
+
* alt value is undefined
|
|
32
|
+
* V-->>C: undefined (valid)
|
|
33
|
+
* else value is string
|
|
34
|
+
* V->>V: Convert to Date
|
|
35
|
+
* end
|
|
36
|
+
* alt Date is invalid (NaN)
|
|
37
|
+
* V-->>C: Error message
|
|
38
|
+
* else Date is valid
|
|
39
|
+
* V-->>C: undefined (valid)
|
|
40
|
+
* end
|
|
41
|
+
*/
|
|
42
|
+
export declare class DateValidator extends Validator<DateValidatorOptions> {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
/**
|
|
45
|
+
* @description Checks if the provided value is a valid date
|
|
46
|
+
* @summary Validates that the given value is a valid date. If the value is a string,
|
|
47
|
+
* it attempts to convert it to a Date object. Returns an error message if the date is invalid,
|
|
48
|
+
* or undefined if the date is valid or if the value is undefined.
|
|
49
|
+
*
|
|
50
|
+
* @param {Date | string} value - The value to validate, can be a Date object or a string
|
|
51
|
+
* @param {DateValidatorOptions} [options={}] - Optional configuration options for the validator
|
|
52
|
+
*
|
|
53
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
54
|
+
*
|
|
55
|
+
* @override
|
|
56
|
+
*
|
|
57
|
+
* @see Validator#hasErrors
|
|
58
|
+
*/
|
|
59
|
+
hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { Validator } from "./Validator.js";
|
|
2
|
+
import { DateValidatorOptions } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Validator for checking if a value is a valid date
|
|
5
|
+
* @summary The DateValidator checks if a value is a valid date object or a string that can be converted to a valid date.
|
|
6
|
+
* It validates that the value represents a real date and not an invalid date like "2023-02-31".
|
|
7
|
+
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
8
|
+
* @class DateValidator
|
|
9
|
+
* @extends Validator
|
|
10
|
+
*
|
|
11
|
+
* @category Validators
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Create a date validator with default error message
|
|
15
|
+
* const dateValidator = new DateValidator();
|
|
16
|
+
*
|
|
17
|
+
* // Create a date validator with custom error message
|
|
18
|
+
* const customDateValidator = new DateValidator("Please enter a valid date");
|
|
19
|
+
*
|
|
20
|
+
* // Validate a date
|
|
21
|
+
* const result = dateValidator.hasErrors(new Date()); // undefined (valid)
|
|
22
|
+
* const invalidResult = dateValidator.hasErrors("not a date"); // Returns error message (invalid)
|
|
23
|
+
* ```
|
|
24
|
+
* @mermaid
|
|
25
|
+
* sequenceDiagram
|
|
26
|
+
* participant C as Client
|
|
27
|
+
* participant V as DateValidator
|
|
28
|
+
*
|
|
29
|
+
* C->>V: new DateValidator(message)
|
|
30
|
+
* C->>V: hasErrors(value, options)
|
|
31
|
+
* alt value is undefined
|
|
32
|
+
* V-->>C: undefined (valid)
|
|
33
|
+
* else value is string
|
|
34
|
+
* V->>V: Convert to Date
|
|
35
|
+
* end
|
|
36
|
+
* alt Date is invalid (NaN)
|
|
37
|
+
* V-->>C: Error message
|
|
38
|
+
* else Date is valid
|
|
39
|
+
* V-->>C: undefined (valid)
|
|
40
|
+
* end
|
|
41
|
+
*/
|
|
42
|
+
export declare class DateValidator extends Validator<DateValidatorOptions> {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
/**
|
|
45
|
+
* @description Checks if the provided value is a valid date
|
|
46
|
+
* @summary Validates that the given value is a valid date. If the value is a string,
|
|
47
|
+
* it attempts to convert it to a Date object. Returns an error message if the date is invalid,
|
|
48
|
+
* or undefined if the date is valid or if the value is undefined.
|
|
49
|
+
*
|
|
50
|
+
* @param {Date | string} value - The value to validate, can be a Date object or a string
|
|
51
|
+
* @param {DateValidatorOptions} [options={}] - Optional configuration options for the validator
|
|
52
|
+
*
|
|
53
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
54
|
+
*
|
|
55
|
+
* @override
|
|
56
|
+
*
|
|
57
|
+
* @see Validator#hasErrors
|
|
58
|
+
*/
|
|
59
|
+
hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.cjs";
|
|
2
|
+
import { DiffValidatorOptions } from "../types.cjs";
|
|
3
|
+
import type { PathProxy } from "../../utils/index.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Diff Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DiffValidator}
|
|
8
|
+
*
|
|
9
|
+
* @class DiffValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class DiffValidator extends Validator<DiffValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {DiffValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: DiffValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.js";
|
|
2
|
+
import { DiffValidatorOptions } from "../types.js";
|
|
3
|
+
import type { PathProxy } from "../../utils/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Diff Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DiffValidator}
|
|
8
|
+
*
|
|
9
|
+
* @class DiffValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class DiffValidator extends Validator<DiffValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {DiffValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: DiffValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PatternValidator } from "./PatternValidator.cjs";
|
|
2
|
+
import { PatternValidatorOptions } from "../types.cjs";
|
|
3
|
+
/**
|
|
4
|
+
* @description Validator for checking if a string is a valid email address
|
|
5
|
+
* @summary The EmailValidator checks if a string matches a standard email address pattern.
|
|
6
|
+
* It extends the PatternValidator and uses a predefined email regex pattern to validate email addresses.
|
|
7
|
+
* This validator is typically used with the @email decorator.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
10
|
+
*
|
|
11
|
+
* @class EmailValidator
|
|
12
|
+
* @extends PatternValidator
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Create an email validator with default error message
|
|
17
|
+
* const emailValidator = new EmailValidator();
|
|
18
|
+
*
|
|
19
|
+
* // Create an email validator with custom error message
|
|
20
|
+
* const customEmailValidator = new EmailValidator("Please enter a valid email address");
|
|
21
|
+
*
|
|
22
|
+
* // Validate an email
|
|
23
|
+
* const result = emailValidator.hasErrors("user@example.com"); // undefined (valid)
|
|
24
|
+
* const invalidResult = emailValidator.hasErrors("invalid-email"); // Returns error message (invalid)
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @mermaid
|
|
28
|
+
* sequenceDiagram
|
|
29
|
+
* participant C as Client
|
|
30
|
+
* participant E as EmailValidator
|
|
31
|
+
* participant P as PatternValidator
|
|
32
|
+
*
|
|
33
|
+
* C->>E: new EmailValidator(message)
|
|
34
|
+
* E->>P: super(message)
|
|
35
|
+
* C->>E: hasErrors(value, options)
|
|
36
|
+
* E->>P: super.hasErrors(value, options with EMAIL pattern)
|
|
37
|
+
* P-->>E: validation result
|
|
38
|
+
* E-->>C: validation result
|
|
39
|
+
*
|
|
40
|
+
* @category Validators
|
|
41
|
+
*/
|
|
42
|
+
export declare class EmailValidator extends PatternValidator {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
/**
|
|
45
|
+
* @description Checks if a string is a valid email address
|
|
46
|
+
* @summary Validates that the provided string matches the email pattern.
|
|
47
|
+
* This method extends the PatternValidator's hasErrors method by ensuring
|
|
48
|
+
* the email pattern is used, even if not explicitly provided in the options.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} value - The string to validate as an email address
|
|
51
|
+
* @param {PatternValidatorOptions} [options={}] - Optional configuration options
|
|
52
|
+
*
|
|
53
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
54
|
+
*
|
|
55
|
+
* @override
|
|
56
|
+
*
|
|
57
|
+
* @see PatternValidator#hasErrors
|
|
58
|
+
*/
|
|
59
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { PatternValidator } from "./PatternValidator.js";
|
|
2
|
+
import { PatternValidatorOptions } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* @description Validator for checking if a string is a valid email address
|
|
5
|
+
* @summary The EmailValidator checks if a string matches a standard email address pattern.
|
|
6
|
+
* It extends the PatternValidator and uses a predefined email regex pattern to validate email addresses.
|
|
7
|
+
* This validator is typically used with the @email decorator.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
10
|
+
*
|
|
11
|
+
* @class EmailValidator
|
|
12
|
+
* @extends PatternValidator
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Create an email validator with default error message
|
|
17
|
+
* const emailValidator = new EmailValidator();
|
|
18
|
+
*
|
|
19
|
+
* // Create an email validator with custom error message
|
|
20
|
+
* const customEmailValidator = new EmailValidator("Please enter a valid email address");
|
|
21
|
+
*
|
|
22
|
+
* // Validate an email
|
|
23
|
+
* const result = emailValidator.hasErrors("user@example.com"); // undefined (valid)
|
|
24
|
+
* const invalidResult = emailValidator.hasErrors("invalid-email"); // Returns error message (invalid)
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @mermaid
|
|
28
|
+
* sequenceDiagram
|
|
29
|
+
* participant C as Client
|
|
30
|
+
* participant E as EmailValidator
|
|
31
|
+
* participant P as PatternValidator
|
|
32
|
+
*
|
|
33
|
+
* C->>E: new EmailValidator(message)
|
|
34
|
+
* E->>P: super(message)
|
|
35
|
+
* C->>E: hasErrors(value, options)
|
|
36
|
+
* E->>P: super.hasErrors(value, options with EMAIL pattern)
|
|
37
|
+
* P-->>E: validation result
|
|
38
|
+
* E-->>C: validation result
|
|
39
|
+
*
|
|
40
|
+
* @category Validators
|
|
41
|
+
*/
|
|
42
|
+
export declare class EmailValidator extends PatternValidator {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
/**
|
|
45
|
+
* @description Checks if a string is a valid email address
|
|
46
|
+
* @summary Validates that the provided string matches the email pattern.
|
|
47
|
+
* This method extends the PatternValidator's hasErrors method by ensuring
|
|
48
|
+
* the email pattern is used, even if not explicitly provided in the options.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} value - The string to validate as an email address
|
|
51
|
+
* @param {PatternValidatorOptions} [options={}] - Optional configuration options
|
|
52
|
+
*
|
|
53
|
+
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
54
|
+
*
|
|
55
|
+
* @override
|
|
56
|
+
*
|
|
57
|
+
* @see PatternValidator#hasErrors
|
|
58
|
+
*/
|
|
59
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
60
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.cjs";
|
|
2
|
+
import { EqualsValidatorOptions } from "../types.cjs";
|
|
3
|
+
import type { PathProxy } from "../../utils/index.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Equals Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EQUALS}
|
|
8
|
+
*
|
|
9
|
+
* @class EqualsValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class EqualsValidator extends Validator<EqualsValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {EqualsValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: EqualsValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.js";
|
|
2
|
+
import { EqualsValidatorOptions } from "../types.js";
|
|
3
|
+
import type { PathProxy } from "../../utils/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Equals Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EQUALS}
|
|
8
|
+
*
|
|
9
|
+
* @class EqualsValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class EqualsValidator extends Validator<EqualsValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {EqualsValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: EqualsValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.cjs";
|
|
2
|
+
import { GreaterThanOrEqualValidatorOptions } from "../types.cjs";
|
|
3
|
+
import type { PathProxy } from "../../utils/PathProxy.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Greater Than or Equal Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#GREATER_THAN_OR_EQUAL}
|
|
8
|
+
*
|
|
9
|
+
* @class GreaterThanOrEqualValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class GreaterThanOrEqualValidator extends Validator<GreaterThanOrEqualValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {GreaterThanOrEqualValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: GreaterThanOrEqualValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Validator } from "./Validator.js";
|
|
2
|
+
import { GreaterThanOrEqualValidatorOptions } from "../types.js";
|
|
3
|
+
import type { PathProxy } from "../../utils/PathProxy.js";
|
|
4
|
+
/**
|
|
5
|
+
* @summary Greater Than or Equal Validator
|
|
6
|
+
*
|
|
7
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#GREATER_THAN_OR_EQUAL}
|
|
8
|
+
*
|
|
9
|
+
* @class GreaterThanOrEqualValidator
|
|
10
|
+
* @extends Validator
|
|
11
|
+
*
|
|
12
|
+
* @category Validators
|
|
13
|
+
*/
|
|
14
|
+
export declare class GreaterThanOrEqualValidator extends Validator<GreaterThanOrEqualValidatorOptions> {
|
|
15
|
+
constructor(message?: string);
|
|
16
|
+
/**
|
|
17
|
+
* @summary Validates a model
|
|
18
|
+
*
|
|
19
|
+
* @param {string} value
|
|
20
|
+
* @param {GreaterThanOrEqualValidatorOptions} options
|
|
21
|
+
* @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
|
|
22
|
+
*
|
|
23
|
+
* @return {string | undefined}
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @see Validator#hasErrors
|
|
27
|
+
*/
|
|
28
|
+
hasErrors(value: any, options: GreaterThanOrEqualValidatorOptions, accessor: PathProxy<any>): string | undefined;
|
|
29
|
+
}
|