@decaf-ts/decorator-validation 1.6.3 → 1.6.4
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 +31 -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 +31 -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
|
@@ -10,73 +10,16 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
11
|
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @description Regular expression for parsing string patterns with flags
|
|
15
|
-
* @summary This regular expression is used to parse string patterns in the format "/pattern/flags".
|
|
16
|
-
* It captures the pattern and flags separately, allowing the creation of a RegExp object
|
|
17
|
-
* with the appropriate flags.
|
|
18
|
-
*
|
|
19
|
-
* @const {RegExp}
|
|
20
|
-
* @memberOf module:decorator-validation
|
|
21
|
-
* @category Validation
|
|
22
|
-
*/
|
|
23
13
|
export const regexpParser = new RegExp("^/(.+)/([gimus]*)$");
|
|
24
14
|
/**
|
|
25
|
-
* @
|
|
26
|
-
* @summary The PatternValidator checks if a string value matches a specified regular expression pattern.
|
|
27
|
-
* It supports both RegExp objects and string representations of patterns, including those with flags.
|
|
28
|
-
* This validator is the foundation for specialized validators like EmailValidator and URLValidator,
|
|
29
|
-
* and is typically used with the @pattern decorator.
|
|
15
|
+
* @summary Pattern Validator
|
|
30
16
|
*
|
|
31
|
-
* @param {string} [
|
|
17
|
+
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
18
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
32
19
|
*
|
|
33
20
|
* @class PatternValidator
|
|
34
21
|
* @extends Validator
|
|
35
22
|
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* // Create a pattern validator with default error message
|
|
39
|
-
* const patternValidator = new PatternValidator();
|
|
40
|
-
*
|
|
41
|
-
* // Create a pattern validator with custom error message
|
|
42
|
-
* const customPatternValidator = new PatternValidator("Value must match the required format");
|
|
43
|
-
*
|
|
44
|
-
* // Validate using a RegExp object
|
|
45
|
-
* const regexOptions = { pattern: /^[A-Z][a-z]+$/ };
|
|
46
|
-
* patternValidator.hasErrors("Hello", regexOptions); // undefined (valid)
|
|
47
|
-
* patternValidator.hasErrors("hello", regexOptions); // Returns error message (invalid)
|
|
48
|
-
*
|
|
49
|
-
* // Validate using a string pattern
|
|
50
|
-
* const stringOptions = { pattern: "^\\d{3}-\\d{2}-\\d{4}$" };
|
|
51
|
-
* patternValidator.hasErrors("123-45-6789", stringOptions); // undefined (valid)
|
|
52
|
-
*
|
|
53
|
-
* // Validate using a string pattern with flags
|
|
54
|
-
* const flagOptions = { pattern: "/^hello$/i" };
|
|
55
|
-
* patternValidator.hasErrors("Hello", flagOptions); // undefined (valid)
|
|
56
|
-
* ```
|
|
57
|
-
*
|
|
58
|
-
* @mermaid
|
|
59
|
-
* sequenceDiagram
|
|
60
|
-
* participant C as Client
|
|
61
|
-
* participant V as PatternValidator
|
|
62
|
-
*
|
|
63
|
-
* C->>V: new PatternValidator(message)
|
|
64
|
-
* C->>V: hasErrors(value, options)
|
|
65
|
-
* alt value is empty
|
|
66
|
-
* V-->>C: undefined (valid)
|
|
67
|
-
* else pattern is missing
|
|
68
|
-
* V-->>C: Error: Missing Pattern
|
|
69
|
-
* else pattern is string
|
|
70
|
-
* V->>V: getPattern(pattern)
|
|
71
|
-
* end
|
|
72
|
-
* V->>V: Reset pattern.lastIndex
|
|
73
|
-
* V->>V: Test value against pattern
|
|
74
|
-
* alt pattern test passes
|
|
75
|
-
* V-->>C: undefined (valid)
|
|
76
|
-
* else pattern test fails
|
|
77
|
-
* V-->>C: Error message
|
|
78
|
-
* end
|
|
79
|
-
*
|
|
80
23
|
* @category Validators
|
|
81
24
|
*/
|
|
82
25
|
let PatternValidator = class PatternValidator extends Validator {
|
|
@@ -84,12 +27,9 @@ let PatternValidator = class PatternValidator extends Validator {
|
|
|
84
27
|
super(message, "string");
|
|
85
28
|
}
|
|
86
29
|
/**
|
|
87
|
-
* @
|
|
88
|
-
* @summary Parses a string representation of a regular expression and converts it to a RegExp object.
|
|
89
|
-
* It handles both simple string patterns and patterns with flags in the format "/pattern/flags".
|
|
30
|
+
* @summary parses and validates a pattern
|
|
90
31
|
*
|
|
91
|
-
* @param {string} pattern
|
|
92
|
-
* @return {RegExp} A RegExp object created from the string pattern
|
|
32
|
+
* @param {string} pattern
|
|
93
33
|
* @private
|
|
94
34
|
*/
|
|
95
35
|
getPattern(pattern) {
|
|
@@ -99,18 +39,12 @@ let PatternValidator = class PatternValidator extends Validator {
|
|
|
99
39
|
return new RegExp(match[1], match[2]);
|
|
100
40
|
}
|
|
101
41
|
/**
|
|
102
|
-
* @
|
|
103
|
-
* @summary Validates that the provided string matches the pattern specified in the options.
|
|
104
|
-
* If the pattern is provided as a string, it's converted to a RegExp object using the getPattern method.
|
|
105
|
-
* The method resets the pattern's lastIndex property to ensure consistent validation results
|
|
106
|
-
* for patterns with the global flag.
|
|
107
|
-
*
|
|
108
|
-
* @param {string} value - The string to validate against the pattern
|
|
109
|
-
* @param {PatternValidatorOptions} options - Configuration options containing the pattern
|
|
42
|
+
* @summary Validates a Model
|
|
110
43
|
*
|
|
111
|
-
* @
|
|
44
|
+
* @param {string} value
|
|
45
|
+
* @param {PatternValidatorOptions} options
|
|
112
46
|
*
|
|
113
|
-
* @
|
|
47
|
+
* @return {string | undefined}
|
|
114
48
|
*
|
|
115
49
|
* @override
|
|
116
50
|
*
|
|
@@ -134,4 +68,4 @@ PatternValidator = __decorate([
|
|
|
134
68
|
__metadata("design:paramtypes", [String])
|
|
135
69
|
], PatternValidator);
|
|
136
70
|
export { PatternValidator };
|
|
137
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUGF0dGVyblZhbGlkYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy92YWxpZGF0aW9uL1ZhbGlkYXRvcnMvUGF0dGVyblZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBQ3hDLE9BQU8sRUFBRSxzQkFBc0IsRUFBRSxjQUFjLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDckUsT0FBTyxFQUFFLFNBQVMsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUd6QyxNQUFNLENBQUMsTUFBTSxZQUFZLEdBQVcsSUFBSSxNQUFNLENBQUMsb0JBQW9CLENBQUMsQ0FBQztBQUVyRTs7Ozs7Ozs7OztHQVVHO0FBRUksSUFBTSxnQkFBZ0IsR0FBdEIsTUFBTSxnQkFBaUIsU0FBUSxTQUFrQztJQUN0RSxZQUFZLFVBQWtCLHNCQUFzQixDQUFDLE9BQU87UUFDMUQsS0FBSyxDQUFDLE9BQU8sRUFBRSxRQUFRLENBQUMsQ0FBQztJQUMzQixDQUFDO0lBRUQ7Ozs7O09BS0c7SUFDSyxVQUFVLENBQUMsT0FBZTtRQUNoQyxJQUFJLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUM7WUFBRSxPQUFPLElBQUksTUFBTSxDQUFDLE9BQU8sQ0FBQyxDQUFDO1FBQzVEL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XJuO1xuICAgIHBhdHRlcm4ubGFzdEluZGV4ID0gMDsgLy8gcmVzZXRzIHBhdHRlcm4gcG9zaXRpb24gZm9yIHJlcGVhdCB2YWxpZGF0aW9uIHJlcXVlc3RzXG4gICAgcmV0dXJuICFwYXR0ZXJuLnRlc3QodmFsdWUpXG4gICAgICA/IHRoaXMuZ2V0TWVzc2FnZShvcHRpb25zLm1lc3NhZ2UgfHwgdGhpcy5tZXNzYWdlKVxuICAgICAgOiB1bmRlZmluZWQ7XG4gIH1cbn1cbiJdfQ==
|
|
@@ -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
|
*
|
|
@@ -11,55 +11,13 @@ import { Validator } from "./Validator";
|
|
|
11
11
|
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
|
-
* @
|
|
15
|
-
* @summary The RequiredValidator ensures that a value is provided and not empty.
|
|
16
|
-
* It handles different types of values appropriately: for booleans and numbers,
|
|
17
|
-
* it checks if they're undefined; for other types (strings, arrays, objects),
|
|
18
|
-
* it checks if they're falsy. This validator is typically used with the @required decorator
|
|
19
|
-
* and is often the first validation applied to important fields.
|
|
14
|
+
* @summary Required Validator
|
|
20
15
|
*
|
|
21
|
-
* @param {string} [message]
|
|
16
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
22
17
|
*
|
|
23
18
|
* @class RequiredValidator
|
|
24
19
|
* @extends Validator
|
|
25
20
|
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```typescript
|
|
28
|
-
* // Create a required validator with default error message
|
|
29
|
-
* const requiredValidator = new RequiredValidator();
|
|
30
|
-
*
|
|
31
|
-
* // Create a required validator with custom error message
|
|
32
|
-
* const customRequiredValidator = new RequiredValidator("This field is mandatory");
|
|
33
|
-
*
|
|
34
|
-
* // Validate different types of values
|
|
35
|
-
* requiredValidator.hasErrors("Hello"); // undefined (valid)
|
|
36
|
-
* requiredValidator.hasErrors(""); // Returns error message (invalid)
|
|
37
|
-
* requiredValidator.hasErrors(0); // undefined (valid - 0 is a valid number)
|
|
38
|
-
* requiredValidator.hasErrors(null); // Returns error message (invalid)
|
|
39
|
-
* requiredValidator.hasErrors([]); // undefined (valid - empty array is still an array)
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @mermaid
|
|
43
|
-
* sequenceDiagram
|
|
44
|
-
* participant C as Client
|
|
45
|
-
* participant V as RequiredValidator
|
|
46
|
-
*
|
|
47
|
-
* C->>V: new RequiredValidator(message)
|
|
48
|
-
* C->>V: hasErrors(value, options)
|
|
49
|
-
* alt typeof value is boolean or number
|
|
50
|
-
* alt value is undefined
|
|
51
|
-
* V-->>C: Error message
|
|
52
|
-
* else value is defined
|
|
53
|
-
* V-->>C: undefined (valid)
|
|
54
|
-
* end
|
|
55
|
-
* else other types
|
|
56
|
-
* alt value is falsy (null, undefined, empty string)
|
|
57
|
-
* V-->>C: Error message
|
|
58
|
-
* else value is truthy
|
|
59
|
-
* V-->>C: undefined (valid)
|
|
60
|
-
* end
|
|
61
|
-
* end
|
|
62
|
-
*
|
|
63
21
|
* @category Validators
|
|
64
22
|
*/
|
|
65
23
|
let RequiredValidator = class RequiredValidator extends Validator {
|
|
@@ -67,16 +25,12 @@ let RequiredValidator = class RequiredValidator extends Validator {
|
|
|
67
25
|
super(message);
|
|
68
26
|
}
|
|
69
27
|
/**
|
|
70
|
-
* @
|
|
71
|
-
* @summary Validates that the provided value exists and is not empty.
|
|
72
|
-
* The validation logic varies by type:
|
|
73
|
-
* - For booleans and numbers: checks if the value is undefined
|
|
74
|
-
* - For other types (strings, arrays, objects): checks if the value is falsy
|
|
28
|
+
* @summary Validates a model
|
|
75
29
|
*
|
|
76
|
-
* @param {
|
|
77
|
-
* @param {ValidatorOptions} [options={}]
|
|
30
|
+
* @param {string} value
|
|
31
|
+
* @param {ValidatorOptions} [options={}]
|
|
78
32
|
*
|
|
79
|
-
* @return {string | undefined}
|
|
33
|
+
* @return {string | undefined}
|
|
80
34
|
*
|
|
81
35
|
* @override
|
|
82
36
|
*
|
|
@@ -101,4 +55,4 @@ RequiredValidator = __decorate([
|
|
|
101
55
|
__metadata("design:paramtypes", [String])
|
|
102
56
|
], RequiredValidator);
|
|
103
57
|
export { RequiredValidator };
|
|
104
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
58
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUmVxdWlyZWRWYWxpZGF0b3IuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvdmFsaWRhdGlvbi9WYWxpZGF0b3JzL1JlcXVpcmVkVmFsaW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ge3N0cmluZyB8IHVuZGVmaW5lZH1cbiAgICpcbiAgICogQG92ZXJyaWRlXG4gICAqXG4gICAqIEBzZWUgVmFsaWRhdG9yI2hhc0Vycm9yc1xuICAgKi9cbiAgcHVibGljIGhhc0Vycm9ycyhcbiAgICB2YWx1ZTogYW55LFxuICAgIG9wdGlvbnM6IFZhbGlkYXRvck9wdGlvbnMgPSB7fVxuICApOiBzdHJpbmcgfCB1bmRlZmluZWQge1xuICAgIHN3aXRjaCAodHlwZW9mIHZhbHVlKSB7XG4gICAgICBjYXNlIFwiYm9vbGVhblwiOlxuICAgICAgY2FzZSBcIm51bWJlclwiOlxuICAgICAgICByZXR1cm4gdHlwZW9mIHZhbHVlID09PSBcInVuZGVmaW5lZFwiXG4gICAgICAgICAgPyB0aGlzLmdldE1lc3NhZ2Uob3B0aW9ucy5tZXNzYWdlIHx8IHRoaXMubWVzc2FnZSlcbiAgICAgICAgICA6IHVuZGVmaW5lZDtcbiAgICAgIGRlZmF1bHQ6XG4gICAgICAgIHJldHVybiAhdmFsdWVcbiAgICAgICAgICA/IHRoaXMuZ2V0TWVzc2FnZShvcHRpb25zLm1lc3NhZ2UgfHwgdGhpcy5tZXNzYWdlKVxuICAgICAgICAgIDogdW5kZWZpbmVkO1xuICAgIH1cbiAgfVxufVxuIl19
|
|
@@ -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
|
*
|
|
@@ -14,61 +14,11 @@ import { Validation } from "../Validation";
|
|
|
14
14
|
import { ModelKeys } from "../../utils/constants";
|
|
15
15
|
import { Reflection } from "@decaf-ts/reflection";
|
|
16
16
|
/**
|
|
17
|
-
* @
|
|
18
|
-
* @summary The TypeValidator ensures that a value matches one of the specified types.
|
|
19
|
-
* It can validate against a single type, multiple types, or a type with a specific name.
|
|
20
|
-
* This validator is typically used with the @type decorator and is fundamental for
|
|
21
|
-
* ensuring type safety in validated models.
|
|
17
|
+
* @summary Required Validator
|
|
22
18
|
*
|
|
23
|
-
* @
|
|
24
|
-
*
|
|
25
|
-
* @class TypeValidator
|
|
19
|
+
* @class RequiredValidator
|
|
26
20
|
* @extends Validator
|
|
27
21
|
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* // Create a type validator with default error message
|
|
31
|
-
* const typeValidator = new TypeValidator();
|
|
32
|
-
*
|
|
33
|
-
* // Create a type validator with custom error message
|
|
34
|
-
* const customTypeValidator = new TypeValidator("Value must be of type {0}, but got {1}");
|
|
35
|
-
*
|
|
36
|
-
* // Validate against a single type
|
|
37
|
-
* const stringOptions = { types: "string" };
|
|
38
|
-
* typeValidator.hasErrors("hello", stringOptions); // undefined (valid)
|
|
39
|
-
* typeValidator.hasErrors(123, stringOptions); // Returns error message (invalid)
|
|
40
|
-
*
|
|
41
|
-
* // Validate against multiple types
|
|
42
|
-
* const multiOptions = { types: ["string", "number"] };
|
|
43
|
-
* typeValidator.hasErrors("hello", multiOptions); // undefined (valid)
|
|
44
|
-
* typeValidator.hasErrors(123, multiOptions); // undefined (valid)
|
|
45
|
-
* typeValidator.hasErrors(true, multiOptions); // Returns error message (invalid)
|
|
46
|
-
*
|
|
47
|
-
* // Validate against a class type
|
|
48
|
-
* const classOptions = { types: { name: "Date" } };
|
|
49
|
-
* typeValidator.hasErrors(new Date(), classOptions); // undefined (valid)
|
|
50
|
-
* ```
|
|
51
|
-
*
|
|
52
|
-
* @mermaid
|
|
53
|
-
* sequenceDiagram
|
|
54
|
-
* participant C as Client
|
|
55
|
-
* participant V as TypeValidator
|
|
56
|
-
* participant R as Reflection
|
|
57
|
-
*
|
|
58
|
-
* C->>V: new TypeValidator(message)
|
|
59
|
-
* C->>V: hasErrors(value, options)
|
|
60
|
-
* alt value is undefined
|
|
61
|
-
* V-->>C: undefined (valid)
|
|
62
|
-
* else value is defined
|
|
63
|
-
* V->>R: evaluateDesignTypes(value, types)
|
|
64
|
-
* alt type evaluation passes
|
|
65
|
-
* V-->>C: undefined (valid)
|
|
66
|
-
* else type evaluation fails
|
|
67
|
-
* V->>V: Format error message with type info
|
|
68
|
-
* V-->>C: Error message
|
|
69
|
-
* end
|
|
70
|
-
* end
|
|
71
|
-
*
|
|
72
22
|
* @category Validators
|
|
73
23
|
*/
|
|
74
24
|
let TypeValidator = class TypeValidator extends Validator {
|
|
@@ -76,15 +26,11 @@ let TypeValidator = class TypeValidator extends Validator {
|
|
|
76
26
|
super(message);
|
|
77
27
|
}
|
|
78
28
|
/**
|
|
79
|
-
* @
|
|
80
|
-
* @
|
|
81
|
-
*
|
|
82
|
-
* The method skips validation for undefined values to avoid conflicts with the RequiredValidator.
|
|
83
|
-
*
|
|
84
|
-
* @param {any} value - The value to validate
|
|
85
|
-
* @param {TypeValidatorOptions} options - Configuration options containing the expected types
|
|
29
|
+
* @summary Validates a model
|
|
30
|
+
* @param {string} value
|
|
31
|
+
* @param {TypeValidatorOptions} options
|
|
86
32
|
*
|
|
87
|
-
* @return {string | undefined}
|
|
33
|
+
* @return {string | undefined}
|
|
88
34
|
*
|
|
89
35
|
* @override
|
|
90
36
|
*
|
|
@@ -107,17 +53,9 @@ TypeValidator = __decorate([
|
|
|
107
53
|
__metadata("design:paramtypes", [String])
|
|
108
54
|
], TypeValidator);
|
|
109
55
|
export { TypeValidator };
|
|
110
|
-
/**
|
|
111
|
-
* @description Register the TypeValidator with the Validation registry
|
|
112
|
-
* @summary This registration associates the TypeValidator with the ModelKeys.TYPE key,
|
|
113
|
-
* allowing it to be used for validating design types. The save flag is set to false
|
|
114
|
-
* to prevent the validator from being saved in the standard validator registry.
|
|
115
|
-
*
|
|
116
|
-
* @memberOf module:decorator-validation
|
|
117
|
-
*/
|
|
118
56
|
Validation.register({
|
|
119
57
|
validator: TypeValidator,
|
|
120
58
|
validationKey: ModelKeys.TYPE,
|
|
121
59
|
save: false,
|
|
122
60
|
});
|
|
123
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
61
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVHlwZVZhbGlkYXRvci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3NyYy92YWxpZGF0aW9uL1ZhbGlkYXRvcnMvVHlwZVZhbGlkYXRvci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7Ozs7Ozs7QUFBQSxPQUFPLEVBQUUsU0FBUyxFQUFFLE1BQU0sYUFBYSxDQUFDO0FBQ3hDLE9BQU8sRUFBRSxzQkFBc0IsRUFBRSxjQUFjLEVBQUUsTUFBTSxhQUFhLENBQUM7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biAgICAgICAgICAgIDogdHlwZXMubmFtZSxcbiAgICAgICAgdHlwZW9mIHZhbHVlXG4gICAgICApO1xuICB9XG59XG5cblZhbGlkYXRpb24ucmVnaXN0ZXIoe1xuICB2YWxpZGF0b3I6IFR5cGVWYWxpZGF0b3IsXG4gIHZhbGlkYXRpb25LZXk6IE1vZGVsS2V5cy5UWVBFLFxuICBzYXZlOiBmYWxzZSxcbn0gYXMgVmFsaWRhdG9yRGVmaW5pdGlvbik7XG4iXX0=
|
|
@@ -1,61 +1,27 @@
|
|
|
1
1
|
import { PatternValidator } from "./PatternValidator";
|
|
2
2
|
import { PatternValidatorOptions } from "../types";
|
|
3
3
|
/**
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* It extends the PatternValidator and uses a robust URL regex pattern to validate web addresses.
|
|
7
|
-
* The pattern is sourced from {@link https://gist.github.com/dperini/729294} and is widely
|
|
8
|
-
* recognized for its accuracy in validating URLs. This validator is typically used with the @url decorator.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
4
|
+
* @summary URL Validator
|
|
5
|
+
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
11
6
|
*
|
|
12
7
|
* @class URLValidator
|
|
13
8
|
* @extends PatternValidator
|
|
14
9
|
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```typescript
|
|
17
|
-
* // Create a URL validator with default error message
|
|
18
|
-
* const urlValidator = new URLValidator();
|
|
19
|
-
*
|
|
20
|
-
* // Create a URL validator with custom error message
|
|
21
|
-
* const customUrlValidator = new URLValidator("Please enter a valid web address");
|
|
22
|
-
*
|
|
23
|
-
* // Validate a URL
|
|
24
|
-
* const result = urlValidator.hasErrors("https://example.com"); // undefined (valid)
|
|
25
|
-
* const invalidResult = urlValidator.hasErrors("not-a-url"); // Returns error message (invalid)
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @mermaid
|
|
29
|
-
* sequenceDiagram
|
|
30
|
-
* participant C as Client
|
|
31
|
-
* participant U as URLValidator
|
|
32
|
-
* participant P as PatternValidator
|
|
33
|
-
*
|
|
34
|
-
* C->>U: new URLValidator(message)
|
|
35
|
-
* U->>P: super(message)
|
|
36
|
-
* C->>U: hasErrors(value, options)
|
|
37
|
-
* U->>P: super.hasErrors(value, options with URL pattern)
|
|
38
|
-
* P-->>U: validation result
|
|
39
|
-
* U-->>C: validation result
|
|
40
|
-
*
|
|
41
10
|
* @category Validators
|
|
42
11
|
*/
|
|
43
12
|
export declare class URLValidator extends PatternValidator {
|
|
44
13
|
constructor(message?: string);
|
|
45
14
|
/**
|
|
46
|
-
* @
|
|
47
|
-
* @summary Validates that the provided string matches the URL pattern.
|
|
48
|
-
* This method extends the PatternValidator's hasErrors method by ensuring
|
|
49
|
-
* the URL pattern is used, even if not explicitly provided in the options.
|
|
15
|
+
* @summary Validates a model
|
|
50
16
|
*
|
|
51
|
-
* @param {string} value
|
|
52
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
17
|
+
* @param {string} value
|
|
18
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
53
19
|
*
|
|
54
|
-
* @return {string | undefined}
|
|
20
|
+
* @return {string | undefined}
|
|
55
21
|
*
|
|
56
22
|
* @override
|
|
57
23
|
*
|
|
58
|
-
* @see
|
|
24
|
+
* @see Validator#hasErrors
|
|
59
25
|
*/
|
|
60
26
|
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
61
27
|
}
|