@decaf-ts/decorator-validation 1.20.0 → 1.21.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/index.cjs +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/types/constants/index.d.cts +2 -2
- package/lib/types/constants/index.d.mts +2 -2
- package/lib/types/index.d.cts +7 -7
- package/lib/types/index.d.mts +7 -7
- package/lib/types/model/Builder.d.cts +3 -3
- package/lib/types/model/Builder.d.mts +3 -3
- package/lib/types/model/Model.d.cts +4 -4
- package/lib/types/model/Model.d.mts +4 -4
- package/lib/types/model/ModelErrorDefinition.d.cts +1 -1
- package/lib/types/model/ModelErrorDefinition.d.mts +1 -1
- package/lib/types/model/ModelRegistry.d.cts +3 -3
- package/lib/types/model/ModelRegistry.d.mts +3 -3
- package/lib/types/model/construction.d.cts +1 -1
- package/lib/types/model/construction.d.mts +1 -1
- package/lib/types/model/index.d.cts +10 -10
- package/lib/types/model/index.d.mts +10 -10
- package/lib/types/model/types.d.cts +3 -3
- package/lib/types/model/types.d.mts +3 -3
- package/lib/types/model/utils.d.cts +1 -1
- package/lib/types/model/utils.d.mts +1 -1
- package/lib/types/model/validation.d.cts +3 -3
- package/lib/types/model/validation.d.mts +3 -3
- package/lib/types/overrides/Metadata.d.cts +3 -3
- package/lib/types/overrides/Metadata.d.mts +3 -3
- package/lib/types/overrides/index.d.cts +3 -3
- package/lib/types/overrides/index.d.mts +3 -3
- package/lib/types/overrides/types.d.cts +1 -1
- package/lib/types/overrides/types.d.mts +1 -1
- package/lib/types/types/index.d.cts +1 -1
- package/lib/types/types/index.d.mts +1 -1
- package/lib/types/types/validation.d.cts +2 -2
- package/lib/types/types/validation.d.mts +2 -2
- package/lib/types/utils/index.d.cts +11 -11
- package/lib/types/utils/index.d.mts +11 -11
- package/lib/types/utils/serialization.d.cts +1 -1
- package/lib/types/utils/serialization.d.mts +1 -1
- package/lib/types/utils/serializers.d.cts +2 -2
- package/lib/types/utils/serializers.d.mts +2 -2
- package/lib/types/utils/types.d.cts +1 -1
- package/lib/types/utils/types.d.mts +1 -1
- package/lib/types/validation/Validation.d.cts +2 -2
- package/lib/types/validation/Validation.d.mts +2 -2
- package/lib/types/validation/Validators/AsyncValidator.d.cts +3 -3
- package/lib/types/validation/Validators/AsyncValidator.d.mts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.cts +3 -3
- package/lib/types/validation/Validators/BaseValidator.d.mts +3 -3
- package/lib/types/validation/Validators/DateValidator.d.cts +2 -2
- package/lib/types/validation/Validators/DateValidator.d.mts +2 -2
- package/lib/types/validation/Validators/DiffValidator.d.cts +3 -3
- package/lib/types/validation/Validators/DiffValidator.d.mts +3 -3
- package/lib/types/validation/Validators/EmailValidator.d.cts +2 -2
- package/lib/types/validation/Validators/EmailValidator.d.mts +2 -2
- package/lib/types/validation/Validators/EqualsValidator.d.cts +3 -3
- package/lib/types/validation/Validators/EqualsValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/GreaterThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.cts +3 -3
- package/lib/types/validation/Validators/LessThanValidator.d.mts +3 -3
- package/lib/types/validation/Validators/ListValidator.d.cts +2 -2
- package/lib/types/validation/Validators/ListValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MaxValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinLengthValidator.d.mts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.cts +2 -2
- package/lib/types/validation/Validators/MinValidator.d.mts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.cts +2 -2
- package/lib/types/validation/Validators/OptionValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PasswordValidator.d.mts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.cts +2 -2
- package/lib/types/validation/Validators/PatternValidator.d.mts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.cts +2 -2
- package/lib/types/validation/Validators/RequiredValidator.d.mts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.cts +2 -2
- package/lib/types/validation/Validators/StepValidator.d.mts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.cts +2 -2
- package/lib/types/validation/Validators/TypeValidator.d.mts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.cts +2 -2
- package/lib/types/validation/Validators/URLValidator.d.mts +2 -2
- package/lib/types/validation/Validators/Validator.d.cts +3 -3
- package/lib/types/validation/Validators/Validator.d.mts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.cts +3 -3
- package/lib/types/validation/Validators/ValidatorRegistry.d.mts +3 -3
- package/lib/types/validation/Validators/decorators.d.cts +1 -1
- package/lib/types/validation/Validators/decorators.d.mts +1 -1
- package/lib/types/validation/Validators/index.d.cts +26 -26
- package/lib/types/validation/Validators/index.d.mts +26 -26
- package/lib/types/validation/decorators.d.cts +2 -2
- package/lib/types/validation/decorators.d.mts +2 -2
- package/lib/types/validation/index.d.cts +4 -4
- package/lib/types/validation/index.d.mts +4 -4
- package/lib/types/validation/types.d.cts +2 -2
- package/lib/types/validation/types.d.mts +2 -2
- package/package.json +1 -1
- package/lib/types/constants/errors.d.ts +0 -17
- package/lib/types/constants/index.d.ts +0 -2
- package/lib/types/constants/validation.d.ts +0 -16
- package/lib/types/index.d.ts +0 -20
- package/lib/types/model/Builder.d.ts +0 -86
- package/lib/types/model/Model.d.ts +0 -286
- package/lib/types/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/types/model/ModelRegistry.d.ts +0 -181
- package/lib/types/model/constants.d.ts +0 -65
- package/lib/types/model/construction.d.ts +0 -46
- package/lib/types/model/decorators.d.ts +0 -47
- package/lib/types/model/index.d.ts +0 -10
- package/lib/types/model/types.d.ts +0 -145
- package/lib/types/model/utils.d.ts +0 -13
- package/lib/types/model/validation.d.ts +0 -92
- package/lib/types/overrides/Metadata.d.ts +0 -132
- package/lib/types/overrides/index.d.ts +0 -4
- package/lib/types/overrides/overrides.d.ts +0 -1
- package/lib/types/overrides/types.d.ts +0 -17
- package/lib/types/types/index.d.ts +0 -1
- package/lib/types/types/validation.d.ts +0 -28
- package/lib/types/utils/DateBuilder.d.ts +0 -121
- package/lib/types/utils/PathProxy.d.ts +0 -43
- package/lib/types/utils/constants.d.ts +0 -32
- package/lib/types/utils/dates.d.ts +0 -86
- package/lib/types/utils/equality.d.ts +0 -56
- package/lib/types/utils/hashing.d.ts +0 -82
- package/lib/types/utils/index.d.ts +0 -11
- package/lib/types/utils/registry.d.ts +0 -68
- package/lib/types/utils/serialization.d.ts +0 -12
- package/lib/types/utils/serializers.d.ts +0 -41
- package/lib/types/utils/strings.d.ts +0 -25
- package/lib/types/utils/types.d.ts +0 -35
- package/lib/types/validation/Validation.d.ts +0 -53
- package/lib/types/validation/Validators/AsyncValidator.d.ts +0 -72
- package/lib/types/validation/Validators/BaseValidator.d.ts +0 -118
- package/lib/types/validation/Validators/DateValidator.d.ts +0 -60
- package/lib/types/validation/Validators/DiffValidator.d.ts +0 -29
- package/lib/types/validation/Validators/EmailValidator.d.ts +0 -60
- package/lib/types/validation/Validators/EqualsValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/GreaterThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanOrEqualValidator.d.ts +0 -29
- package/lib/types/validation/Validators/LessThanValidator.d.ts +0 -29
- package/lib/types/validation/Validators/ListValidator.d.ts +0 -66
- package/lib/types/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MaxValidator.d.ts +0 -74
- package/lib/types/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/types/validation/Validators/MinValidator.d.ts +0 -74
- package/lib/types/validation/Validators/OptionValidator.d.ts +0 -29
- package/lib/types/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/types/validation/Validators/PatternValidator.d.ts +0 -103
- package/lib/types/validation/Validators/RequiredValidator.d.ts +0 -74
- package/lib/types/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/types/validation/Validators/TypeValidator.d.ts +0 -79
- package/lib/types/validation/Validators/URLValidator.d.ts +0 -61
- package/lib/types/validation/Validators/Validator.d.ts +0 -65
- package/lib/types/validation/Validators/ValidatorRegistry.d.ts +0 -41
- package/lib/types/validation/Validators/constants.d.ts +0 -157
- package/lib/types/validation/Validators/decorators.d.ts +0 -12
- package/lib/types/validation/Validators/index.d.ts +0 -26
- package/lib/types/validation/Validators/utils.d.ts +0 -75
- package/lib/types/validation/decorators.d.ts +0 -313
- package/lib/types/validation/index.d.ts +0 -9
- package/lib/types/validation/types.d.ts +0 -309
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MinLengthValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Minimum Length Validator
|
|
5
|
-
* @description Validates strings and Arrays on their minimum length
|
|
6
|
-
*
|
|
7
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
8
|
-
*
|
|
9
|
-
* @class MinLengthValidator
|
|
10
|
-
* @extends Validator
|
|
11
|
-
*
|
|
12
|
-
* @category Validators
|
|
13
|
-
*/
|
|
14
|
-
export declare class MinLengthValidator extends Validator<MinLengthValidatorOptions> {
|
|
15
|
-
constructor(message?: string);
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {string | Array} value
|
|
19
|
-
* @param {MinLengthValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @memberOf module:decorator-validation
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: string | any[], options: MinLengthValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { MinValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Validator for checking if a value is greater than or equal to a minimum
|
|
5
|
-
* @summary The MinValidator checks if a numeric value, date, or string is greater than or equal to
|
|
6
|
-
* a specified minimum value. It supports comparing numbers directly, dates chronologically,
|
|
7
|
-
* and strings lexicographically. This validator is typically used with the @min decorator.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
10
|
-
*
|
|
11
|
-
* @class MinValidator
|
|
12
|
-
* @extends Validator
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* // Create a min validator with default error message
|
|
17
|
-
* const minValidator = new MinValidator();
|
|
18
|
-
*
|
|
19
|
-
* // Create a min validator with custom error message
|
|
20
|
-
* const customMinValidator = new MinValidator("Value must be at least {0}");
|
|
21
|
-
*
|
|
22
|
-
* // Validate a number
|
|
23
|
-
* const numOptions = { min: 10, message: "Number too small" };
|
|
24
|
-
* const numResult = minValidator.hasErrors(50, numOptions); // undefined (valid)
|
|
25
|
-
* const invalidNumResult = minValidator.hasErrors(5, numOptions); // Returns error message (invalid)
|
|
26
|
-
*
|
|
27
|
-
* // Validate a date
|
|
28
|
-
* const dateOptions = { min: new Date(2023, 0, 1) };
|
|
29
|
-
* const dateResult = minValidator.hasErrors(new Date(2023, 5, 15), dateOptions); // undefined (valid)
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @mermaid
|
|
33
|
-
* sequenceDiagram
|
|
34
|
-
* participant C as Client
|
|
35
|
-
* participant V as MinValidator
|
|
36
|
-
*
|
|
37
|
-
* C->>V: new MinValidator(message)
|
|
38
|
-
* C->>V: hasErrors(value, options)
|
|
39
|
-
* alt value is undefined
|
|
40
|
-
* V-->>C: undefined (valid)
|
|
41
|
-
* else value is Date and min is not Date
|
|
42
|
-
* V->>V: Convert min to Date
|
|
43
|
-
* alt conversion fails
|
|
44
|
-
* V-->>C: Error: Invalid Min param
|
|
45
|
-
* end
|
|
46
|
-
* end
|
|
47
|
-
* alt value < min
|
|
48
|
-
* V-->>C: Error message
|
|
49
|
-
* else value >= min
|
|
50
|
-
* V-->>C: undefined (valid)
|
|
51
|
-
* end
|
|
52
|
-
*
|
|
53
|
-
* @category Validators
|
|
54
|
-
*/
|
|
55
|
-
export declare class MinValidator extends Validator<MinValidatorOptions> {
|
|
56
|
-
constructor(message?: string);
|
|
57
|
-
/**
|
|
58
|
-
* @description Checks if a value is greater than or equal to a minimum
|
|
59
|
-
* @summary Validates that the provided value is not less than the minimum value
|
|
60
|
-
* specified in the options. For dates, it performs chronological comparison,
|
|
61
|
-
* converting string representations to Date objects if necessary. For numbers
|
|
62
|
-
* and strings, it performs direct comparison.
|
|
63
|
-
*
|
|
64
|
-
* @param {number | Date | string} value - The value to validate
|
|
65
|
-
* @param {MinValidatorOptions} options - Configuration options containing the minimum value
|
|
66
|
-
*
|
|
67
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
68
|
-
*
|
|
69
|
-
* @override
|
|
70
|
-
*
|
|
71
|
-
* @see Validator#hasErrors
|
|
72
|
-
*/
|
|
73
|
-
hasErrors(value: number | Date | string, options: MinValidatorOptions): string | undefined;
|
|
74
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { EnumValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Option Validator
|
|
5
|
-
* @description Validates properties against an object or a list of accepted values
|
|
6
|
-
*
|
|
7
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#ENUM}
|
|
8
|
-
*
|
|
9
|
-
* @class OptionValidator
|
|
10
|
-
* @extends Validator
|
|
11
|
-
*
|
|
12
|
-
* @category Validators
|
|
13
|
-
*/
|
|
14
|
-
export declare class OptionValidator extends Validator<EnumValidatorOptions> {
|
|
15
|
-
constructor(message?: string);
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {any[] | Record<any, any>} value
|
|
19
|
-
* @param {EnumValidatorOptions} options
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @memberOf module:decorator-validation
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: any, options: EnumValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Handles Password Validation
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [errorMessage] defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
7
|
-
*
|
|
8
|
-
* @class PasswordValidator
|
|
9
|
-
* @extends PatternValidator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class PasswordValidator extends PatternValidator {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see PatternValidator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
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
|
-
export declare const regexpParser: RegExp;
|
|
14
|
-
/**
|
|
15
|
-
* @description Validator for checking if a string matches a regular expression pattern
|
|
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.
|
|
20
|
-
*
|
|
21
|
-
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
22
|
-
*
|
|
23
|
-
* @class PatternValidator
|
|
24
|
-
* @extends Validator
|
|
25
|
-
*
|
|
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
|
-
* @category Validators
|
|
71
|
-
*/
|
|
72
|
-
export declare class PatternValidator extends Validator<PatternValidatorOptions> {
|
|
73
|
-
constructor(message?: string);
|
|
74
|
-
/**
|
|
75
|
-
* @description Converts a string pattern to a RegExp object
|
|
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".
|
|
78
|
-
*
|
|
79
|
-
* @param {string} pattern - The string pattern to convert
|
|
80
|
-
* @return {RegExp} A RegExp object created from the string pattern
|
|
81
|
-
* @private
|
|
82
|
-
*/
|
|
83
|
-
private getPattern;
|
|
84
|
-
/**
|
|
85
|
-
* @description Checks if a string matches a regular expression pattern
|
|
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
|
|
93
|
-
*
|
|
94
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
95
|
-
*
|
|
96
|
-
* @throws {Error} If no pattern is provided in the options
|
|
97
|
-
*
|
|
98
|
-
* @override
|
|
99
|
-
*
|
|
100
|
-
* @see Validator#hasErrors
|
|
101
|
-
*/
|
|
102
|
-
hasErrors(value: string, options: PatternValidatorOptions): string | undefined;
|
|
103
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { ValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Validator for checking if a value is present and not empty
|
|
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.
|
|
10
|
-
*
|
|
11
|
-
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
12
|
-
*
|
|
13
|
-
* @class RequiredValidator
|
|
14
|
-
* @extends Validator
|
|
15
|
-
*
|
|
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
|
-
* @category Validators
|
|
54
|
-
*/
|
|
55
|
-
export declare class RequiredValidator extends Validator {
|
|
56
|
-
constructor(message?: string);
|
|
57
|
-
/**
|
|
58
|
-
* @description Checks if a value is present and not empty
|
|
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
|
|
63
|
-
*
|
|
64
|
-
* @param {any} value - The value to validate
|
|
65
|
-
* @param {ValidatorOptions} [options={}] - Optional configuration options
|
|
66
|
-
*
|
|
67
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
68
|
-
*
|
|
69
|
-
* @override
|
|
70
|
-
*
|
|
71
|
-
* @see Validator#hasErrors
|
|
72
|
-
*/
|
|
73
|
-
hasErrors(value: any, options?: ValidatorOptions): string | undefined;
|
|
74
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { StepValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Step Validator
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
7
|
-
*
|
|
8
|
-
* @class StepValidator
|
|
9
|
-
* @extends Validator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class StepValidator extends Validator<StepValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {number} step
|
|
20
|
-
* @param {StepValidatorOptions} options
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: number | string, options: StepValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { TypeValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Validator for checking if a value is of the expected type(s)
|
|
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.
|
|
9
|
-
*
|
|
10
|
-
* @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
11
|
-
*
|
|
12
|
-
* @class TypeValidator
|
|
13
|
-
* @extends Validator
|
|
14
|
-
*
|
|
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
|
-
* @category Validators
|
|
60
|
-
*/
|
|
61
|
-
export declare class TypeValidator extends Validator<TypeValidatorOptions> {
|
|
62
|
-
constructor(message?: string);
|
|
63
|
-
/**
|
|
64
|
-
* @description Checks if a value is of the expected type(s)
|
|
65
|
-
* @summary Validates that the provided value matches one of the specified types.
|
|
66
|
-
* It uses the Reflection utility to evaluate if the value's type matches the expected types.
|
|
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
|
|
71
|
-
*
|
|
72
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
73
|
-
*
|
|
74
|
-
* @override
|
|
75
|
-
*
|
|
76
|
-
* @see Validator#hasErrors
|
|
77
|
-
*/
|
|
78
|
-
hasErrors(value: any, options: TypeValidatorOptions): string | undefined;
|
|
79
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "../types";
|
|
3
|
-
/**
|
|
4
|
-
* @description Validator for checking if a string is a valid URL
|
|
5
|
-
* @summary The URLValidator checks if a string matches a standard URL pattern.
|
|
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}
|
|
11
|
-
*
|
|
12
|
-
* @class URLValidator
|
|
13
|
-
* @extends PatternValidator
|
|
14
|
-
*
|
|
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
|
-
* @category Validators
|
|
42
|
-
*/
|
|
43
|
-
export declare class URLValidator extends PatternValidator {
|
|
44
|
-
constructor(message?: string);
|
|
45
|
-
/**
|
|
46
|
-
* @description Checks if a string is a valid URL
|
|
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.
|
|
50
|
-
*
|
|
51
|
-
* @param {string} value - The string to validate as a URL
|
|
52
|
-
* @param {PatternValidatorOptions} [options={}] - Optional configuration options
|
|
53
|
-
*
|
|
54
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
55
|
-
*
|
|
56
|
-
* @override
|
|
57
|
-
*
|
|
58
|
-
* @see PatternValidator#hasErrors
|
|
59
|
-
*/
|
|
60
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
61
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { ValidatorOptions } from "../types";
|
|
2
|
-
import type { PathProxy } from "../../utils";
|
|
3
|
-
import { BaseValidator } from "./BaseValidator";
|
|
4
|
-
/**
|
|
5
|
-
* @description
|
|
6
|
-
* Abstract class for defining synchronous validators.
|
|
7
|
-
*
|
|
8
|
-
* This class extends the base {@link BaseValidator} and enforces that any implementation of `hasErrors` must be synchronous.
|
|
9
|
-
*
|
|
10
|
-
* Use this when the validation process is immediate and does not require asynchronous operations.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* // Example of a synchronous validator that checks if a number is greater than
|
|
15
|
-
* class GreaterThanValidator extends Validator<{ gt?: number }> {
|
|
16
|
-
* constructor(message: string = "Value must be greater than {0}") {
|
|
17
|
-
* super(message);
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* hasErrors(value: number, options?: { gt?: number }) {
|
|
21
|
-
* const minValue = options?.gt ?? 0;
|
|
22
|
-
* if (value <= minValue) {
|
|
23
|
-
* return this.getMessage();
|
|
24
|
-
* }
|
|
25
|
-
* return undefined;
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
*
|
|
29
|
-
* // Example usage:
|
|
30
|
-
* const validator = new GreaterThanValidator();
|
|
31
|
-
* const error = validator.hasErrors(10, { gt: 15 });
|
|
32
|
-
* if (error) {
|
|
33
|
-
* console.log('Value must be greater than 15')
|
|
34
|
-
* } else {
|
|
35
|
-
* console.log('Value is valid');
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* - If `value` is less than or equal to `gt`, returns the error message.
|
|
40
|
-
* - Otherwise, returns `undefined` indicating validation success.
|
|
41
|
-
*
|
|
42
|
-
* @see {@link BaseValidator} For the base validator.
|
|
43
|
-
* @see {@link ValidatorOptions} For the base validator options.
|
|
44
|
-
*/
|
|
45
|
-
export declare abstract class Validator<V extends ValidatorOptions = ValidatorOptions> extends BaseValidator<V, false> {
|
|
46
|
-
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
47
|
-
/**
|
|
48
|
-
* @description Validates a value against specific validation rules
|
|
49
|
-
* @summary Abstract method that must be implemented by all validator subclasses.
|
|
50
|
-
* This method contains the core validation logic that determines whether a value
|
|
51
|
-
* is valid according to the specific rules of the validator. If the value is valid,
|
|
52
|
-
* the method returns undefined; otherwise, it returns an error message.
|
|
53
|
-
*
|
|
54
|
-
* @template V - Type of the options object that can be passed to the validator
|
|
55
|
-
* @param {any} value - The value to validate
|
|
56
|
-
* @param {V} [options] - Optional configuration options for customizing validation behavior
|
|
57
|
-
* @param {PathProxy<any>} proxy -
|
|
58
|
-
* @return {string | undefined} Error message if validation fails, undefined if validation passes
|
|
59
|
-
*
|
|
60
|
-
* @abstract
|
|
61
|
-
*
|
|
62
|
-
* @see Model#validate
|
|
63
|
-
*/
|
|
64
|
-
abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): string | undefined;
|
|
65
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ValidatorDefinition } from "../types";
|
|
2
|
-
import { IValidatorRegistry } from "../types";
|
|
3
|
-
import { Validator } from "./Validator";
|
|
4
|
-
/**
|
|
5
|
-
* @summary Base Implementation of a Validator Registry
|
|
6
|
-
*
|
|
7
|
-
* @prop {Validator[]} [validators] the initial validators to register
|
|
8
|
-
*
|
|
9
|
-
* @class ValidatorRegistry
|
|
10
|
-
* @implements IValidatorRegistry<T>
|
|
11
|
-
*
|
|
12
|
-
* @category Validation
|
|
13
|
-
*/
|
|
14
|
-
export declare class ValidatorRegistry<T extends Validator> implements IValidatorRegistry<T> {
|
|
15
|
-
private cache;
|
|
16
|
-
private customKeyCache;
|
|
17
|
-
constructor(...validators: (ValidatorDefinition | Validator)[]);
|
|
18
|
-
/**
|
|
19
|
-
* @summary retrieves the custom keys
|
|
20
|
-
*/
|
|
21
|
-
getCustomKeys(): {
|
|
22
|
-
[indexer: string]: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* @summary retrieves the registered validators keys
|
|
26
|
-
*/
|
|
27
|
-
getKeys(): string[];
|
|
28
|
-
/**
|
|
29
|
-
* @summary Retrieves a validator
|
|
30
|
-
*
|
|
31
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
32
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
33
|
-
*/
|
|
34
|
-
get<T extends Validator>(validatorKey: string): T | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* @summary Registers the provided validators onto the registry
|
|
37
|
-
*
|
|
38
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
39
|
-
*/
|
|
40
|
-
register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
41
|
-
}
|