@decaf-ts/decorator-validation 1.6.3 → 1.6.5
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/dist/decorator-validation.cjs +1016 -1164
- package/dist/decorator-validation.esm.cjs +971 -1134
- package/lib/constants/index.cjs +18 -0
- package/lib/constants/index.d.ts +1 -0
- package/lib/constants/validation.cjs +14 -0
- package/lib/constants/validation.d.ts +10 -0
- package/lib/esm/constants/index.d.ts +1 -0
- package/lib/esm/constants/index.js +2 -0
- package/lib/esm/constants/validation.d.ts +10 -0
- package/lib/esm/constants/validation.js +11 -0
- package/lib/esm/index.d.ts +37 -5
- package/lib/esm/index.js +38 -6
- package/lib/esm/model/Model.d.ts +29 -100
- package/lib/esm/model/Model.js +37 -104
- package/lib/esm/model/constants.d.ts +3 -3
- package/lib/esm/model/constants.js +4 -4
- package/lib/esm/model/construction.d.ts +3 -3
- package/lib/esm/model/construction.js +4 -4
- package/lib/esm/model/decorators.d.ts +4 -4
- package/lib/esm/model/decorators.js +5 -6
- package/lib/esm/model/types.d.ts +11 -30
- package/lib/esm/model/types.js +1 -1
- package/lib/esm/model/validation.d.ts +2 -2
- package/lib/esm/model/validation.js +18 -7
- package/lib/esm/utils/constants.d.ts +9 -27
- package/lib/esm/utils/constants.js +10 -28
- package/lib/esm/utils/dates.d.ts +16 -26
- package/lib/esm/utils/dates.js +17 -27
- package/lib/esm/utils/decorators.d.ts +0 -41
- package/lib/esm/utils/decorators.js +1 -42
- package/lib/esm/utils/hashing.d.ts +6 -50
- package/lib/esm/utils/hashing.js +5 -49
- package/lib/esm/utils/index.d.ts +0 -1
- package/lib/esm/utils/index.js +1 -2
- package/lib/esm/utils/registry.d.ts +2 -2
- package/lib/esm/utils/registry.js +1 -1
- package/lib/esm/utils/serialization.d.ts +1 -1
- package/lib/esm/utils/serialization.js +2 -2
- package/lib/esm/utils/strings.d.ts +4 -4
- package/lib/esm/utils/strings.js +5 -5
- package/lib/esm/utils/types.d.ts +16 -123
- package/lib/esm/utils/types.js +1 -1
- package/lib/esm/validation/Validators/DateValidator.d.ts +8 -40
- package/lib/esm/validation/Validators/DateValidator.js +9 -41
- package/lib/esm/validation/Validators/DiffValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/DiffValidator.js +58 -0
- package/lib/esm/validation/Validators/EmailValidator.d.ts +7 -39
- package/lib/esm/validation/Validators/EmailValidator.js +8 -40
- package/lib/esm/validation/Validators/EqualsValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/EqualsValidator.js +63 -0
- package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/GreaterThanOrEqualValidator.js +65 -0
- package/lib/esm/validation/Validators/GreaterThanValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/GreaterThanValidator.js +62 -0
- package/lib/esm/validation/Validators/LessThanOrEqualValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/LessThanOrEqualValidator.js +65 -0
- package/lib/esm/validation/Validators/LessThanValidator.d.ts +27 -0
- package/lib/esm/validation/Validators/LessThanValidator.js +62 -0
- package/lib/esm/validation/Validators/ListValidator.d.ts +6 -44
- package/lib/esm/validation/Validators/ListValidator.js +7 -45
- package/lib/esm/validation/Validators/MaxValidator.d.ts +6 -52
- package/lib/esm/validation/Validators/MaxValidator.js +7 -53
- package/lib/esm/validation/Validators/MinValidator.d.ts +6 -52
- package/lib/esm/validation/Validators/MinValidator.js +7 -53
- package/lib/esm/validation/Validators/PatternValidator.d.ts +9 -75
- package/lib/esm/validation/Validators/PatternValidator.js +10 -76
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +6 -52
- package/lib/esm/validation/Validators/RequiredValidator.js +7 -53
- package/lib/esm/validation/Validators/TypeValidator.d.ts +6 -60
- package/lib/esm/validation/Validators/TypeValidator.js +7 -69
- package/lib/esm/validation/Validators/URLValidator.d.ts +7 -41
- package/lib/esm/validation/Validators/URLValidator.js +8 -42
- package/lib/esm/validation/Validators/Validator.d.ts +17 -77
- package/lib/esm/validation/Validators/Validator.js +11 -68
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +7 -1
- package/lib/esm/validation/Validators/ValidatorRegistry.js +11 -4
- package/lib/esm/validation/Validators/constants.d.ts +41 -0
- package/lib/esm/validation/Validators/constants.js +43 -1
- package/lib/esm/validation/Validators/index.d.ts +7 -0
- package/lib/esm/validation/Validators/index.js +8 -1
- package/lib/esm/validation/Validators/utils.d.ts +52 -0
- package/lib/esm/validation/Validators/utils.js +174 -0
- package/lib/esm/validation/decorators.d.ts +124 -50
- package/lib/esm/validation/decorators.js +173 -102
- package/lib/esm/validation/types.d.ts +46 -146
- package/lib/esm/validation/types.js +1 -1
- package/lib/index.cjs +39 -7
- package/lib/index.d.ts +37 -5
- package/lib/model/Model.cjs +39 -104
- package/lib/model/Model.d.ts +29 -100
- package/lib/model/constants.cjs +4 -4
- package/lib/model/constants.d.ts +3 -3
- package/lib/model/construction.cjs +4 -4
- package/lib/model/construction.d.ts +3 -3
- package/lib/model/decorators.cjs +5 -6
- package/lib/model/decorators.d.ts +4 -4
- package/lib/model/types.cjs +1 -1
- package/lib/model/types.d.ts +11 -30
- package/lib/model/validation.cjs +25 -14
- package/lib/model/validation.d.ts +2 -2
- package/lib/utils/constants.cjs +11 -29
- package/lib/utils/constants.d.ts +9 -27
- package/lib/utils/dates.cjs +17 -27
- package/lib/utils/dates.d.ts +16 -26
- package/lib/utils/decorators.cjs +1 -42
- package/lib/utils/decorators.d.ts +0 -41
- package/lib/utils/hashing.cjs +5 -49
- package/lib/utils/hashing.d.ts +6 -50
- package/lib/utils/index.cjs +1 -2
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/registry.cjs +1 -1
- package/lib/utils/registry.d.ts +2 -2
- package/lib/utils/serialization.cjs +2 -2
- package/lib/utils/serialization.d.ts +1 -1
- package/lib/utils/strings.cjs +5 -5
- package/lib/utils/strings.d.ts +4 -4
- package/lib/utils/types.cjs +1 -1
- package/lib/utils/types.d.ts +16 -123
- package/lib/validation/Validators/DateValidator.cjs +9 -41
- package/lib/validation/Validators/DateValidator.d.ts +8 -40
- package/lib/validation/Validators/DiffValidator.cjs +61 -0
- package/lib/validation/Validators/DiffValidator.d.ts +27 -0
- package/lib/validation/Validators/EmailValidator.cjs +8 -40
- package/lib/validation/Validators/EmailValidator.d.ts +7 -39
- package/lib/validation/Validators/EqualsValidator.cjs +66 -0
- package/lib/validation/Validators/EqualsValidator.d.ts +27 -0
- package/lib/validation/Validators/GreaterThanOrEqualValidator.cjs +68 -0
- package/lib/validation/Validators/GreaterThanOrEqualValidator.d.ts +27 -0
- package/lib/validation/Validators/GreaterThanValidator.cjs +65 -0
- package/lib/validation/Validators/GreaterThanValidator.d.ts +27 -0
- package/lib/validation/Validators/LessThanOrEqualValidator.cjs +68 -0
- package/lib/validation/Validators/LessThanOrEqualValidator.d.ts +27 -0
- package/lib/validation/Validators/LessThanValidator.cjs +65 -0
- package/lib/validation/Validators/LessThanValidator.d.ts +27 -0
- package/lib/validation/Validators/ListValidator.cjs +7 -45
- package/lib/validation/Validators/ListValidator.d.ts +6 -44
- package/lib/validation/Validators/MaxValidator.cjs +7 -53
- package/lib/validation/Validators/MaxValidator.d.ts +6 -52
- package/lib/validation/Validators/MinValidator.cjs +7 -53
- package/lib/validation/Validators/MinValidator.d.ts +6 -52
- package/lib/validation/Validators/PatternValidator.cjs +10 -76
- package/lib/validation/Validators/PatternValidator.d.ts +9 -75
- package/lib/validation/Validators/RequiredValidator.cjs +7 -53
- package/lib/validation/Validators/RequiredValidator.d.ts +6 -52
- package/lib/validation/Validators/TypeValidator.cjs +7 -69
- package/lib/validation/Validators/TypeValidator.d.ts +6 -60
- package/lib/validation/Validators/URLValidator.cjs +8 -42
- package/lib/validation/Validators/URLValidator.d.ts +7 -41
- package/lib/validation/Validators/Validator.cjs +11 -68
- package/lib/validation/Validators/Validator.d.ts +17 -77
- package/lib/validation/Validators/ValidatorRegistry.cjs +12 -4
- package/lib/validation/Validators/ValidatorRegistry.d.ts +7 -1
- package/lib/validation/Validators/constants.cjs +44 -2
- package/lib/validation/Validators/constants.d.ts +41 -0
- package/lib/validation/Validators/index.cjs +8 -1
- package/lib/validation/Validators/index.d.ts +7 -0
- package/lib/validation/Validators/utils.cjs +180 -0
- package/lib/validation/Validators/utils.d.ts +52 -0
- package/lib/validation/decorators.cjs +179 -102
- package/lib/validation/decorators.d.ts +124 -50
- package/lib/validation/types.cjs +1 -1
- package/lib/validation/types.d.ts +46 -146
- package/package.json +1 -1
- package/lib/esm/utils/Decoration.d.ts +0 -123
- package/lib/esm/utils/Decoration.js +0 -188
- package/lib/utils/Decoration.cjs +0 -192
- package/lib/utils/Decoration.d.ts +0 -123
|
@@ -13,73 +13,16 @@ exports.PatternValidator = exports.regexpParser = void 0;
|
|
|
13
13
|
const Validator_1 = require("./Validator.cjs");
|
|
14
14
|
const constants_1 = require("./constants.cjs");
|
|
15
15
|
const decorators_1 = require("./decorators.cjs");
|
|
16
|
-
/**
|
|
17
|
-
* @description Regular expression for parsing string patterns with flags
|
|
18
|
-
* @summary This regular expression is used to parse string patterns in the format "/pattern/flags".
|
|
19
|
-
* It captures the pattern and flags separately, allowing the creation of a RegExp object
|
|
20
|
-
* with the appropriate flags.
|
|
21
|
-
*
|
|
22
|
-
* @const {RegExp}
|
|
23
|
-
* @memberOf module:decorator-validation
|
|
24
|
-
* @category Validation
|
|
25
|
-
*/
|
|
26
16
|
exports.regexpParser = new RegExp("^/(.+)/([gimus]*)$");
|
|
27
17
|
/**
|
|
28
|
-
* @
|
|
29
|
-
* @summary The PatternValidator checks if a string value matches a specified regular expression pattern.
|
|
30
|
-
* It supports both RegExp objects and string representations of patterns, including those with flags.
|
|
31
|
-
* This validator is the foundation for specialized validators like EmailValidator and URLValidator,
|
|
32
|
-
* and is typically used with the @pattern decorator.
|
|
18
|
+
* @summary Pattern Validator
|
|
33
19
|
*
|
|
34
|
-
* @param {string} [
|
|
20
|
+
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
21
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
35
22
|
*
|
|
36
23
|
* @class PatternValidator
|
|
37
24
|
* @extends Validator
|
|
38
25
|
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* // Create a pattern validator with default error message
|
|
42
|
-
* const patternValidator = new PatternValidator();
|
|
43
|
-
*
|
|
44
|
-
* // Create a pattern validator with custom error message
|
|
45
|
-
* const customPatternValidator = new PatternValidator("Value must match the required format");
|
|
46
|
-
*
|
|
47
|
-
* // Validate using a RegExp object
|
|
48
|
-
* const regexOptions = { pattern: /^[A-Z][a-z]+$/ };
|
|
49
|
-
* patternValidator.hasErrors("Hello", regexOptions); // undefined (valid)
|
|
50
|
-
* patternValidator.hasErrors("hello", regexOptions); // Returns error message (invalid)
|
|
51
|
-
*
|
|
52
|
-
* // Validate using a string pattern
|
|
53
|
-
* const stringOptions = { pattern: "^\\d{3}-\\d{2}-\\d{4}$" };
|
|
54
|
-
* patternValidator.hasErrors("123-45-6789", stringOptions); // undefined (valid)
|
|
55
|
-
*
|
|
56
|
-
* // Validate using a string pattern with flags
|
|
57
|
-
* const flagOptions = { pattern: "/^hello$/i" };
|
|
58
|
-
* patternValidator.hasErrors("Hello", flagOptions); // undefined (valid)
|
|
59
|
-
* ```
|
|
60
|
-
*
|
|
61
|
-
* @mermaid
|
|
62
|
-
* sequenceDiagram
|
|
63
|
-
* participant C as Client
|
|
64
|
-
* participant V as PatternValidator
|
|
65
|
-
*
|
|
66
|
-
* C->>V: new PatternValidator(message)
|
|
67
|
-
* C->>V: hasErrors(value, options)
|
|
68
|
-
* alt value is empty
|
|
69
|
-
* V-->>C: undefined (valid)
|
|
70
|
-
* else pattern is missing
|
|
71
|
-
* V-->>C: Error: Missing Pattern
|
|
72
|
-
* else pattern is string
|
|
73
|
-
* V->>V: getPattern(pattern)
|
|
74
|
-
* end
|
|
75
|
-
* V->>V: Reset pattern.lastIndex
|
|
76
|
-
* V->>V: Test value against pattern
|
|
77
|
-
* alt pattern test passes
|
|
78
|
-
* V-->>C: undefined (valid)
|
|
79
|
-
* else pattern test fails
|
|
80
|
-
* V-->>C: Error message
|
|
81
|
-
* end
|
|
82
|
-
*
|
|
83
26
|
* @category Validators
|
|
84
27
|
*/
|
|
85
28
|
let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
@@ -87,12 +30,9 @@ let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
|
87
30
|
super(message, "string");
|
|
88
31
|
}
|
|
89
32
|
/**
|
|
90
|
-
* @
|
|
91
|
-
* @summary Parses a string representation of a regular expression and converts it to a RegExp object.
|
|
92
|
-
* It handles both simple string patterns and patterns with flags in the format "/pattern/flags".
|
|
33
|
+
* @summary parses and validates a pattern
|
|
93
34
|
*
|
|
94
|
-
* @param {string} pattern
|
|
95
|
-
* @return {RegExp} A RegExp object created from the string pattern
|
|
35
|
+
* @param {string} pattern
|
|
96
36
|
* @private
|
|
97
37
|
*/
|
|
98
38
|
getPattern(pattern) {
|
|
@@ -102,18 +42,12 @@ let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
|
102
42
|
return new RegExp(match[1], match[2]);
|
|
103
43
|
}
|
|
104
44
|
/**
|
|
105
|
-
* @
|
|
106
|
-
* @summary Validates that the provided string matches the pattern specified in the options.
|
|
107
|
-
* If the pattern is provided as a string, it's converted to a RegExp object using the getPattern method.
|
|
108
|
-
* The method resets the pattern's lastIndex property to ensure consistent validation results
|
|
109
|
-
* for patterns with the global flag.
|
|
110
|
-
*
|
|
111
|
-
* @param {string} value - The string to validate against the pattern
|
|
112
|
-
* @param {PatternValidatorOptions} options - Configuration options containing the pattern
|
|
45
|
+
* @summary Validates a Model
|
|
113
46
|
*
|
|
114
|
-
* @
|
|
47
|
+
* @param {string} value
|
|
48
|
+
* @param {PatternValidatorOptions} options
|
|
115
49
|
*
|
|
116
|
-
* @
|
|
50
|
+
* @return {string | undefined}
|
|
117
51
|
*
|
|
118
52
|
* @override
|
|
119
53
|
*
|
|
@@ -137,4 +71,4 @@ exports.PatternValidator = PatternValidator = __decorate([
|
|
|
137
71
|
(0, decorators_1.validator)(constants_1.ValidationKeys.PATTERN),
|
|
138
72
|
__metadata("design:paramtypes", [String])
|
|
139
73
|
], PatternValidator);
|
|
140
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
74
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUGF0dGVyblZhbGlkYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy92YWxpZGF0aW9uL1ZhbGlkYXRvcnMvUGF0dGVyblZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSwyQ0FBd0M7QUFDeEMsMkNBQXFFO0FBQ3JFLDZDQUF5QztBQUc1QixRQUFBLFlBQVksR0FBVyxJQUFJLE1BQU0sQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDO0FBRXJFOzs7Ozs7Ozs7O0dBVUc7QUFFSSxJQUFNLGdCQUFnQixHQUF0QixNQUFNLGdCQUFpQixTQUFRLHFCQUFrQztJQUN0RSxZQUFZLFVBQWtCLGtDQUFzQixDQUFDLE9BQU87UUFDMUQsS0FBSyxDQUFDLE9BQU8sRUFBRSxRQUFRLENBQUMsQ0FBQztJQUMzQixDQUFDO0lBRUQ7Ozs7O09BS0c7SUFDSyxVQUFVLENBQUMsT0FBZTtRQUNoQyxJQUFJLENBQUMsb0JBQVksQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDO1lBQUUsT0FBTyxJQUFJLE1BQU0sQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUM1RCxNQUFNLEtBQUssR0FBUSxPQUFPLENBQUMsS0FBSyxDQUFDLG9CQUFZLENBQUMsQ0FBQztRQUMvQyxPQUFPLElBQUksT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dGlvbiBmb3IgcmVwZWF0IHZhbGlkYXRpb24gcmVxdWVzdHNcbiAgICByZXR1cm4gIXBhdHRlcm4udGVzdCh2YWx1ZSlcbiAgICAgID8gdGhpcy5nZXRNZXNzYWdlKG9wdGlvbnMubWVzc2FnZSB8fCB0aGlzLm1lc3NhZ2UpXG4gICAgICA6IHVuZGVmaW5lZDtcbiAgfVxufVxuIl19
|
|
@@ -1,99 +1,33 @@
|
|
|
1
1
|
import { Validator } from "./Validator";
|
|
2
2
|
import { PatternValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Regular expression for parsing string patterns with flags
|
|
5
|
-
* @summary This regular expression is used to parse string patterns in the format "/pattern/flags".
|
|
6
|
-
* It captures the pattern and flags separately, allowing the creation of a RegExp object
|
|
7
|
-
* with the appropriate flags.
|
|
8
|
-
*
|
|
9
|
-
* @const {RegExp}
|
|
10
|
-
* @memberOf module:decorator-validation
|
|
11
|
-
* @category Validation
|
|
12
|
-
*/
|
|
13
3
|
export declare const regexpParser: RegExp;
|
|
14
4
|
/**
|
|
15
|
-
* @
|
|
16
|
-
* @summary The PatternValidator checks if a string value matches a specified regular expression pattern.
|
|
17
|
-
* It supports both RegExp objects and string representations of patterns, including those with flags.
|
|
18
|
-
* This validator is the foundation for specialized validators like EmailValidator and URLValidator,
|
|
19
|
-
* and is typically used with the @pattern decorator.
|
|
5
|
+
* @summary Pattern Validator
|
|
20
6
|
*
|
|
21
|
-
* @param {string} [
|
|
7
|
+
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
8
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
22
9
|
*
|
|
23
10
|
* @class PatternValidator
|
|
24
11
|
* @extends Validator
|
|
25
12
|
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // Create a pattern validator with default error message
|
|
29
|
-
* const patternValidator = new PatternValidator();
|
|
30
|
-
*
|
|
31
|
-
* // Create a pattern validator with custom error message
|
|
32
|
-
* const customPatternValidator = new PatternValidator("Value must match the required format");
|
|
33
|
-
*
|
|
34
|
-
* // Validate using a RegExp object
|
|
35
|
-
* const regexOptions = { pattern: /^[A-Z][a-z]+$/ };
|
|
36
|
-
* patternValidator.hasErrors("Hello", regexOptions); // undefined (valid)
|
|
37
|
-
* patternValidator.hasErrors("hello", regexOptions); // Returns error message (invalid)
|
|
38
|
-
*
|
|
39
|
-
* // Validate using a string pattern
|
|
40
|
-
* const stringOptions = { pattern: "^\\d{3}-\\d{2}-\\d{4}$" };
|
|
41
|
-
* patternValidator.hasErrors("123-45-6789", stringOptions); // undefined (valid)
|
|
42
|
-
*
|
|
43
|
-
* // Validate using a string pattern with flags
|
|
44
|
-
* const flagOptions = { pattern: "/^hello$/i" };
|
|
45
|
-
* patternValidator.hasErrors("Hello", flagOptions); // undefined (valid)
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @mermaid
|
|
49
|
-
* sequenceDiagram
|
|
50
|
-
* participant C as Client
|
|
51
|
-
* participant V as PatternValidator
|
|
52
|
-
*
|
|
53
|
-
* C->>V: new PatternValidator(message)
|
|
54
|
-
* C->>V: hasErrors(value, options)
|
|
55
|
-
* alt value is empty
|
|
56
|
-
* V-->>C: undefined (valid)
|
|
57
|
-
* else pattern is missing
|
|
58
|
-
* V-->>C: Error: Missing Pattern
|
|
59
|
-
* else pattern is string
|
|
60
|
-
* V->>V: getPattern(pattern)
|
|
61
|
-
* end
|
|
62
|
-
* V->>V: Reset pattern.lastIndex
|
|
63
|
-
* V->>V: Test value against pattern
|
|
64
|
-
* alt pattern test passes
|
|
65
|
-
* V-->>C: undefined (valid)
|
|
66
|
-
* else pattern test fails
|
|
67
|
-
* V-->>C: Error message
|
|
68
|
-
* end
|
|
69
|
-
*
|
|
70
13
|
* @category Validators
|
|
71
14
|
*/
|
|
72
15
|
export declare class PatternValidator extends Validator<PatternValidatorOptions> {
|
|
73
16
|
constructor(message?: string);
|
|
74
17
|
/**
|
|
75
|
-
* @
|
|
76
|
-
* @summary Parses a string representation of a regular expression and converts it to a RegExp object.
|
|
77
|
-
* It handles both simple string patterns and patterns with flags in the format "/pattern/flags".
|
|
18
|
+
* @summary parses and validates a pattern
|
|
78
19
|
*
|
|
79
|
-
* @param {string} pattern
|
|
80
|
-
* @return {RegExp} A RegExp object created from the string pattern
|
|
20
|
+
* @param {string} pattern
|
|
81
21
|
* @private
|
|
82
22
|
*/
|
|
83
23
|
private getPattern;
|
|
84
24
|
/**
|
|
85
|
-
* @
|
|
86
|
-
* @summary Validates that the provided string matches the pattern specified in the options.
|
|
87
|
-
* If the pattern is provided as a string, it's converted to a RegExp object using the getPattern method.
|
|
88
|
-
* The method resets the pattern's lastIndex property to ensure consistent validation results
|
|
89
|
-
* for patterns with the global flag.
|
|
90
|
-
*
|
|
91
|
-
* @param {string} value - The string to validate against the pattern
|
|
92
|
-
* @param {PatternValidatorOptions} options - Configuration options containing the pattern
|
|
25
|
+
* @summary Validates a Model
|
|
93
26
|
*
|
|
94
|
-
* @
|
|
27
|
+
* @param {string} value
|
|
28
|
+
* @param {PatternValidatorOptions} options
|
|
95
29
|
*
|
|
96
|
-
* @
|
|
30
|
+
* @return {string | undefined}
|
|
97
31
|
*
|
|
98
32
|
* @override
|
|
99
33
|
*
|
|
@@ -14,55 +14,13 @@ const Validator_1 = require("./Validator.cjs");
|
|
|
14
14
|
const constants_1 = require("./constants.cjs");
|
|
15
15
|
const decorators_1 = require("./decorators.cjs");
|
|
16
16
|
/**
|
|
17
|
-
* @
|
|
18
|
-
* @summary The RequiredValidator ensures that a value is provided and not empty.
|
|
19
|
-
* It handles different types of values appropriately: for booleans and numbers,
|
|
20
|
-
* it checks if they're undefined; for other types (strings, arrays, objects),
|
|
21
|
-
* it checks if they're falsy. This validator is typically used with the @required decorator
|
|
22
|
-
* and is often the first validation applied to important fields.
|
|
17
|
+
* @summary Required Validator
|
|
23
18
|
*
|
|
24
|
-
* @param {string} [message]
|
|
19
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
25
20
|
*
|
|
26
21
|
* @class RequiredValidator
|
|
27
22
|
* @extends Validator
|
|
28
23
|
*
|
|
29
|
-
* @example
|
|
30
|
-
* ```typescript
|
|
31
|
-
* // Create a required validator with default error message
|
|
32
|
-
* const requiredValidator = new RequiredValidator();
|
|
33
|
-
*
|
|
34
|
-
* // Create a required validator with custom error message
|
|
35
|
-
* const customRequiredValidator = new RequiredValidator("This field is mandatory");
|
|
36
|
-
*
|
|
37
|
-
* // Validate different types of values
|
|
38
|
-
* requiredValidator.hasErrors("Hello"); // undefined (valid)
|
|
39
|
-
* requiredValidator.hasErrors(""); // Returns error message (invalid)
|
|
40
|
-
* requiredValidator.hasErrors(0); // undefined (valid - 0 is a valid number)
|
|
41
|
-
* requiredValidator.hasErrors(null); // Returns error message (invalid)
|
|
42
|
-
* requiredValidator.hasErrors([]); // undefined (valid - empty array is still an array)
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @mermaid
|
|
46
|
-
* sequenceDiagram
|
|
47
|
-
* participant C as Client
|
|
48
|
-
* participant V as RequiredValidator
|
|
49
|
-
*
|
|
50
|
-
* C->>V: new RequiredValidator(message)
|
|
51
|
-
* C->>V: hasErrors(value, options)
|
|
52
|
-
* alt typeof value is boolean or number
|
|
53
|
-
* alt value is undefined
|
|
54
|
-
* V-->>C: Error message
|
|
55
|
-
* else value is defined
|
|
56
|
-
* V-->>C: undefined (valid)
|
|
57
|
-
* end
|
|
58
|
-
* else other types
|
|
59
|
-
* alt value is falsy (null, undefined, empty string)
|
|
60
|
-
* V-->>C: Error message
|
|
61
|
-
* else value is truthy
|
|
62
|
-
* V-->>C: undefined (valid)
|
|
63
|
-
* end
|
|
64
|
-
* end
|
|
65
|
-
*
|
|
66
24
|
* @category Validators
|
|
67
25
|
*/
|
|
68
26
|
let RequiredValidator = class RequiredValidator extends Validator_1.Validator {
|
|
@@ -70,16 +28,12 @@ let RequiredValidator = class RequiredValidator extends Validator_1.Validator {
|
|
|
70
28
|
super(message);
|
|
71
29
|
}
|
|
72
30
|
/**
|
|
73
|
-
* @
|
|
74
|
-
* @summary Validates that the provided value exists and is not empty.
|
|
75
|
-
* The validation logic varies by type:
|
|
76
|
-
* - For booleans and numbers: checks if the value is undefined
|
|
77
|
-
* - For other types (strings, arrays, objects): checks if the value is falsy
|
|
31
|
+
* @summary Validates a model
|
|
78
32
|
*
|
|
79
|
-
* @param {
|
|
80
|
-
* @param {ValidatorOptions} [options={}]
|
|
33
|
+
* @param {string} value
|
|
34
|
+
* @param {ValidatorOptions} [options={}]
|
|
81
35
|
*
|
|
82
|
-
* @return {string | undefined}
|
|
36
|
+
* @return {string | undefined}
|
|
83
37
|
*
|
|
84
38
|
* @override
|
|
85
39
|
*
|
|
@@ -104,4 +58,4 @@ exports.RequiredValidator = RequiredValidator = __decorate([
|
|
|
104
58
|
(0, decorators_1.validator)(constants_1.ValidationKeys.REQUIRED),
|
|
105
59
|
__metadata("design:paramtypes", [String])
|
|
106
60
|
], RequiredValidator);
|
|
107
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
61
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVxdWlyZWRWYWxpZGF0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvdmFsaWRhdGlvbi9WYWxpZGF0b3JzL1JlcXVpcmVkVmFsaWRhdG9yLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7Ozs7Ozs7OztBQUFBLDJDQUF3QztBQUN4QywyQ0FBcUU7QUFDckUsNkNBQXlDO0FBR3pDOzs7Ozs7Ozs7R0FTRztBQUVJLElBQU0saUJBQWlCLEdBQXZCLE1BQU0saUJBQWtCLFNBQVEscUJBQVM7SUFDOUMsWUFBWSxVQUFrQixrQ0FBc0IsQ0FBQyxRQUFRO1FBQzNELE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gICAgICAgcmV0dXJuIHR5cGVvZiB2YWx1ZSA9PT0gXCJ1bmRlZmluZWRcIlxuICAgICAgICAgID8gdGhpcy5nZXRNZXNzYWdlKG9wdGlvbnMubWVzc2FnZSB8fCB0aGlzLm1lc3NhZ2UpXG4gICAgICAgICAgOiB1bmRlZmluZWQ7XG4gICAgICBkZWZhdWx0OlxuICAgICAgICByZXR1cm4gIXZhbHVlXG4gICAgICAgICAgPyB0aGlzLmdldE1lc3NhZ2Uob3B0aW9ucy5tZXNzYWdlIHx8IHRoaXMubWVzc2FnZSlcbiAgICAgICAgICA6IHVuZGVmaW5lZDtcbiAgICB9XG4gIH1cbn1cbiJdfQ==
|
|
@@ -1,70 +1,24 @@
|
|
|
1
1
|
import { Validator } from "./Validator";
|
|
2
2
|
import { ValidatorOptions } from "../types";
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @summary The RequiredValidator ensures that a value is provided and not empty.
|
|
6
|
-
* It handles different types of values appropriately: for booleans and numbers,
|
|
7
|
-
* it checks if they're undefined; for other types (strings, arrays, objects),
|
|
8
|
-
* it checks if they're falsy. This validator is typically used with the @required decorator
|
|
9
|
-
* and is often the first validation applied to important fields.
|
|
4
|
+
* @summary Required Validator
|
|
10
5
|
*
|
|
11
|
-
* @param {string} [message]
|
|
6
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
12
7
|
*
|
|
13
8
|
* @class RequiredValidator
|
|
14
9
|
* @extends Validator
|
|
15
10
|
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* // Create a required validator with default error message
|
|
19
|
-
* const requiredValidator = new RequiredValidator();
|
|
20
|
-
*
|
|
21
|
-
* // Create a required validator with custom error message
|
|
22
|
-
* const customRequiredValidator = new RequiredValidator("This field is mandatory");
|
|
23
|
-
*
|
|
24
|
-
* // Validate different types of values
|
|
25
|
-
* requiredValidator.hasErrors("Hello"); // undefined (valid)
|
|
26
|
-
* requiredValidator.hasErrors(""); // Returns error message (invalid)
|
|
27
|
-
* requiredValidator.hasErrors(0); // undefined (valid - 0 is a valid number)
|
|
28
|
-
* requiredValidator.hasErrors(null); // Returns error message (invalid)
|
|
29
|
-
* requiredValidator.hasErrors([]); // undefined (valid - empty array is still an array)
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @mermaid
|
|
33
|
-
* sequenceDiagram
|
|
34
|
-
* participant C as Client
|
|
35
|
-
* participant V as RequiredValidator
|
|
36
|
-
*
|
|
37
|
-
* C->>V: new RequiredValidator(message)
|
|
38
|
-
* C->>V: hasErrors(value, options)
|
|
39
|
-
* alt typeof value is boolean or number
|
|
40
|
-
* alt value is undefined
|
|
41
|
-
* V-->>C: Error message
|
|
42
|
-
* else value is defined
|
|
43
|
-
* V-->>C: undefined (valid)
|
|
44
|
-
* end
|
|
45
|
-
* else other types
|
|
46
|
-
* alt value is falsy (null, undefined, empty string)
|
|
47
|
-
* V-->>C: Error message
|
|
48
|
-
* else value is truthy
|
|
49
|
-
* V-->>C: undefined (valid)
|
|
50
|
-
* end
|
|
51
|
-
* end
|
|
52
|
-
*
|
|
53
11
|
* @category Validators
|
|
54
12
|
*/
|
|
55
13
|
export declare class RequiredValidator extends Validator {
|
|
56
14
|
constructor(message?: string);
|
|
57
15
|
/**
|
|
58
|
-
* @
|
|
59
|
-
* @summary Validates that the provided value exists and is not empty.
|
|
60
|
-
* The validation logic varies by type:
|
|
61
|
-
* - For booleans and numbers: checks if the value is undefined
|
|
62
|
-
* - For other types (strings, arrays, objects): checks if the value is falsy
|
|
16
|
+
* @summary Validates a model
|
|
63
17
|
*
|
|
64
|
-
* @param {
|
|
65
|
-
* @param {ValidatorOptions} [options={}]
|
|
18
|
+
* @param {string} value
|
|
19
|
+
* @param {ValidatorOptions} [options={}]
|
|
66
20
|
*
|
|
67
|
-
* @return {string | undefined}
|
|
21
|
+
* @return {string | undefined}
|
|
68
22
|
*
|
|
69
23
|
* @override
|
|
70
24
|
*
|
|
@@ -17,61 +17,11 @@ const Validation_1 = require("../Validation.cjs");
|
|
|
17
17
|
const constants_2 = require("../../utils/constants.cjs");
|
|
18
18
|
const reflection_1 = require("@decaf-ts/reflection");
|
|
19
19
|
/**
|
|
20
|
-
* @
|
|
21
|
-
* @summary The TypeValidator ensures that a value matches one of the specified types.
|
|
22
|
-
* It can validate against a single type, multiple types, or a type with a specific name.
|
|
23
|
-
* This validator is typically used with the @type decorator and is fundamental for
|
|
24
|
-
* ensuring type safety in validated models.
|
|
20
|
+
* @summary Required Validator
|
|
25
21
|
*
|
|
26
|
-
* @
|
|
27
|
-
*
|
|
28
|
-
* @class TypeValidator
|
|
22
|
+
* @class RequiredValidator
|
|
29
23
|
* @extends Validator
|
|
30
24
|
*
|
|
31
|
-
* @example
|
|
32
|
-
* ```typescript
|
|
33
|
-
* // Create a type validator with default error message
|
|
34
|
-
* const typeValidator = new TypeValidator();
|
|
35
|
-
*
|
|
36
|
-
* // Create a type validator with custom error message
|
|
37
|
-
* const customTypeValidator = new TypeValidator("Value must be of type {0}, but got {1}");
|
|
38
|
-
*
|
|
39
|
-
* // Validate against a single type
|
|
40
|
-
* const stringOptions = { types: "string" };
|
|
41
|
-
* typeValidator.hasErrors("hello", stringOptions); // undefined (valid)
|
|
42
|
-
* typeValidator.hasErrors(123, stringOptions); // Returns error message (invalid)
|
|
43
|
-
*
|
|
44
|
-
* // Validate against multiple types
|
|
45
|
-
* const multiOptions = { types: ["string", "number"] };
|
|
46
|
-
* typeValidator.hasErrors("hello", multiOptions); // undefined (valid)
|
|
47
|
-
* typeValidator.hasErrors(123, multiOptions); // undefined (valid)
|
|
48
|
-
* typeValidator.hasErrors(true, multiOptions); // Returns error message (invalid)
|
|
49
|
-
*
|
|
50
|
-
* // Validate against a class type
|
|
51
|
-
* const classOptions = { types: { name: "Date" } };
|
|
52
|
-
* typeValidator.hasErrors(new Date(), classOptions); // undefined (valid)
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* @mermaid
|
|
56
|
-
* sequenceDiagram
|
|
57
|
-
* participant C as Client
|
|
58
|
-
* participant V as TypeValidator
|
|
59
|
-
* participant R as Reflection
|
|
60
|
-
*
|
|
61
|
-
* C->>V: new TypeValidator(message)
|
|
62
|
-
* C->>V: hasErrors(value, options)
|
|
63
|
-
* alt value is undefined
|
|
64
|
-
* V-->>C: undefined (valid)
|
|
65
|
-
* else value is defined
|
|
66
|
-
* V->>R: evaluateDesignTypes(value, types)
|
|
67
|
-
* alt type evaluation passes
|
|
68
|
-
* V-->>C: undefined (valid)
|
|
69
|
-
* else type evaluation fails
|
|
70
|
-
* V->>V: Format error message with type info
|
|
71
|
-
* V-->>C: Error message
|
|
72
|
-
* end
|
|
73
|
-
* end
|
|
74
|
-
*
|
|
75
25
|
* @category Validators
|
|
76
26
|
*/
|
|
77
27
|
let TypeValidator = class TypeValidator extends Validator_1.Validator {
|
|
@@ -79,15 +29,11 @@ let TypeValidator = class TypeValidator extends Validator_1.Validator {
|
|
|
79
29
|
super(message);
|
|
80
30
|
}
|
|
81
31
|
/**
|
|
82
|
-
* @
|
|
83
|
-
* @
|
|
84
|
-
*
|
|
85
|
-
* The method skips validation for undefined values to avoid conflicts with the RequiredValidator.
|
|
86
|
-
*
|
|
87
|
-
* @param {any} value - The value to validate
|
|
88
|
-
* @param {TypeValidatorOptions} options - Configuration options containing the expected types
|
|
32
|
+
* @summary Validates a model
|
|
33
|
+
* @param {string} value
|
|
34
|
+
* @param {TypeValidatorOptions} options
|
|
89
35
|
*
|
|
90
|
-
* @return {string | undefined}
|
|
36
|
+
* @return {string | undefined}
|
|
91
37
|
*
|
|
92
38
|
* @override
|
|
93
39
|
*
|
|
@@ -110,17 +56,9 @@ exports.TypeValidator = TypeValidator = __decorate([
|
|
|
110
56
|
(0, decorators_1.validator)(constants_1.ValidationKeys.TYPE),
|
|
111
57
|
__metadata("design:paramtypes", [String])
|
|
112
58
|
], TypeValidator);
|
|
113
|
-
/**
|
|
114
|
-
* @description Register the TypeValidator with the Validation registry
|
|
115
|
-
* @summary This registration associates the TypeValidator with the ModelKeys.TYPE key,
|
|
116
|
-
* allowing it to be used for validating design types. The save flag is set to false
|
|
117
|
-
* to prevent the validator from being saved in the standard validator registry.
|
|
118
|
-
*
|
|
119
|
-
* @memberOf module:decorator-validation
|
|
120
|
-
*/
|
|
121
59
|
Validation_1.Validation.register({
|
|
122
60
|
validator: TypeValidator,
|
|
123
61
|
validationKey: constants_2.ModelKeys.TYPE,
|
|
124
62
|
save: false,
|
|
125
63
|
});
|
|
126
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHlwZVZhbGlkYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy92YWxpZGF0aW9uL1ZhbGlkYXRvcnMvVHlwZVZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7Ozs7QUFBQSwyQ0FBd0M7QUFDeEMsMkNBQXFFO0FBQ3JFLDZDQUF5QztBQUN6Qyw4Q0FBMkM7QUFFM0MscURBQWtEO0FBQ2xELHFEQUFrRDtBQUVsRDs7Ozs7OztHQU9HO0FBRUksSUFBTSxhQUFhLEdBQW5CLE1BQU0sYUFBYyxTQUFRLHFCQUErQjtJQUNoRSxZQUFZLFVBQWtCLGtDQUFzQixDQUFDLElBQUk7UUFDdkQsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDO0lBQ2pCLENBQUM7SUFFRDs7Ozs7Ozs7OztPQVVHO0lBQ0ksU0FBUyxDQUNkLEtBQVUsRUFDVixPQUE2QjtRQUU3QixJQUFJLEtBQUssS0FBSyxTQUFTO1lBQUUsT0FBTyxDQUFDLDBDQUEwQztRQUMzRSxNQUFNLEVBQUUsS0FBSyxFQUFFLE9BQU8sRUFBRSxHQUFHLE9BQU8sQ0FBQzt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ZmluZWQge1xuICAgIGlmICh2YWx1ZSA9PT0gdW5kZWZpbmVkKSByZXR1cm47IC8vIERvbid0IHRyeSBhbmQgZW5mb3JjZSB0eXBlIGlmIHVuZGVmaW5lZFxuICAgIGNvbnN0IHsgdHlwZXMsIG1lc3NhZ2UgfSA9IG9wdGlvbnM7XG4gICAgaWYgKCFSZWZsZWN0aW9uLmV2YWx1YXRlRGVzaWduVHlwZXModmFsdWUsIHR5cGVzKSlcbiAgICAgIHJldHVybiB0aGlzLmdldE1lc3NhZ2UoXG4gICAgICAgIG1lc3NhZ2UgfHwgdGhpcy5tZXNzYWdlLFxuICAgICAgICB0eXBlb2YgdHlwZXMgPT09IFwic3RyaW5nXCJcbiAgICAgICAgICA/IHR5cGVzXG4gICAgICAgICAgOiBBcnJheS5pc0FycmF5KHR5cGVzKVxuICAgICAgICAgICAgPyB0eXBlcy5qb2luKFwiLCBcIilcbiAgICAgICAgICAgIDogdHlwZXMubmFtZSxcbiAgICAgICAgdHlwZW9mIHZhbHVlXG4gICAgICApO1xuICB9XG59XG5cblZhbGlkYXRpb24ucmVnaXN0ZXIoe1xuICB2YWxpZGF0b3I6IFR5cGVWYWxpZGF0b3IsXG4gIHZhbGlkYXRpb25LZXk6IE1vZGVsS2V5cy5UWVBFLFxuICBzYXZlOiBmYWxzZSxcbn0gYXMgVmFsaWRhdG9yRGVmaW5pdGlvbik7XG4iXX0=
|
|
@@ -1,75 +1,21 @@
|
|
|
1
1
|
import { Validator } from "./Validator";
|
|
2
2
|
import { TypeValidatorOptions } from "../types";
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @summary The TypeValidator ensures that a value matches one of the specified types.
|
|
6
|
-
* It can validate against a single type, multiple types, or a type with a specific name.
|
|
7
|
-
* This validator is typically used with the @type decorator and is fundamental for
|
|
8
|
-
* ensuring type safety in validated models.
|
|
4
|
+
* @summary Required Validator
|
|
9
5
|
*
|
|
10
|
-
* @
|
|
11
|
-
*
|
|
12
|
-
* @class TypeValidator
|
|
6
|
+
* @class RequiredValidator
|
|
13
7
|
* @extends Validator
|
|
14
8
|
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Create a type validator with default error message
|
|
18
|
-
* const typeValidator = new TypeValidator();
|
|
19
|
-
*
|
|
20
|
-
* // Create a type validator with custom error message
|
|
21
|
-
* const customTypeValidator = new TypeValidator("Value must be of type {0}, but got {1}");
|
|
22
|
-
*
|
|
23
|
-
* // Validate against a single type
|
|
24
|
-
* const stringOptions = { types: "string" };
|
|
25
|
-
* typeValidator.hasErrors("hello", stringOptions); // undefined (valid)
|
|
26
|
-
* typeValidator.hasErrors(123, stringOptions); // Returns error message (invalid)
|
|
27
|
-
*
|
|
28
|
-
* // Validate against multiple types
|
|
29
|
-
* const multiOptions = { types: ["string", "number"] };
|
|
30
|
-
* typeValidator.hasErrors("hello", multiOptions); // undefined (valid)
|
|
31
|
-
* typeValidator.hasErrors(123, multiOptions); // undefined (valid)
|
|
32
|
-
* typeValidator.hasErrors(true, multiOptions); // Returns error message (invalid)
|
|
33
|
-
*
|
|
34
|
-
* // Validate against a class type
|
|
35
|
-
* const classOptions = { types: { name: "Date" } };
|
|
36
|
-
* typeValidator.hasErrors(new Date(), classOptions); // undefined (valid)
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* @mermaid
|
|
40
|
-
* sequenceDiagram
|
|
41
|
-
* participant C as Client
|
|
42
|
-
* participant V as TypeValidator
|
|
43
|
-
* participant R as Reflection
|
|
44
|
-
*
|
|
45
|
-
* C->>V: new TypeValidator(message)
|
|
46
|
-
* C->>V: hasErrors(value, options)
|
|
47
|
-
* alt value is undefined
|
|
48
|
-
* V-->>C: undefined (valid)
|
|
49
|
-
* else value is defined
|
|
50
|
-
* V->>R: evaluateDesignTypes(value, types)
|
|
51
|
-
* alt type evaluation passes
|
|
52
|
-
* V-->>C: undefined (valid)
|
|
53
|
-
* else type evaluation fails
|
|
54
|
-
* V->>V: Format error message with type info
|
|
55
|
-
* V-->>C: Error message
|
|
56
|
-
* end
|
|
57
|
-
* end
|
|
58
|
-
*
|
|
59
9
|
* @category Validators
|
|
60
10
|
*/
|
|
61
11
|
export declare class TypeValidator extends Validator<TypeValidatorOptions> {
|
|
62
12
|
constructor(message?: string);
|
|
63
13
|
/**
|
|
64
|
-
* @
|
|
65
|
-
* @
|
|
66
|
-
*
|
|
67
|
-
* The method skips validation for undefined values to avoid conflicts with the RequiredValidator.
|
|
68
|
-
*
|
|
69
|
-
* @param {any} value - The value to validate
|
|
70
|
-
* @param {TypeValidatorOptions} options - Configuration options containing the expected types
|
|
14
|
+
* @summary Validates a model
|
|
15
|
+
* @param {string} value
|
|
16
|
+
* @param {TypeValidatorOptions} options
|
|
71
17
|
*
|
|
72
|
-
* @return {string | undefined}
|
|
18
|
+
* @return {string | undefined}
|
|
73
19
|
*
|
|
74
20
|
* @override
|
|
75
21
|
*
|