@decaf-ts/decorator-validation 1.4.21 → 1.5.1
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/LICENSE.md +0 -0
- package/README.md +0 -0
- package/dist/decorator-validation.bundle.min.js +1 -1
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -0
- package/dist/esm/decorator-validation.bundle.min.esm.js +1 -1
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -0
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/model/Model.d.ts +1 -2
- package/lib/esm/model/Model.js +3 -4
- package/lib/esm/model/ModelErrorDefinition.d.ts +0 -0
- package/lib/esm/model/ModelErrorDefinition.js +0 -0
- package/lib/esm/model/Registry.d.ts +0 -0
- package/lib/esm/model/Registry.js +0 -0
- package/lib/esm/model/constants.d.ts +0 -0
- package/lib/esm/model/constants.js +0 -0
- package/lib/esm/model/construction.d.ts +0 -0
- package/lib/esm/model/construction.js +0 -0
- package/lib/esm/model/decorators.d.ts +0 -0
- package/lib/esm/model/decorators.js +0 -0
- package/lib/esm/model/index.d.ts +0 -0
- package/lib/esm/model/index.js +0 -0
- package/lib/esm/model/types.d.ts +0 -0
- package/lib/esm/model/types.js +0 -0
- package/lib/esm/model/utils.d.ts +0 -0
- package/lib/esm/model/utils.js +0 -0
- package/lib/esm/model/validation.d.ts +0 -0
- package/lib/esm/model/validation.js +3 -2
- package/lib/esm/utils/constants.d.ts +0 -0
- package/lib/esm/utils/constants.js +0 -0
- package/lib/esm/utils/dates.d.ts +0 -0
- package/lib/esm/utils/dates.js +0 -0
- package/lib/esm/utils/decorators.d.ts +0 -0
- package/lib/esm/utils/decorators.js +0 -0
- package/lib/esm/utils/hashing.d.ts +0 -0
- package/lib/esm/utils/hashing.js +0 -0
- package/lib/esm/utils/index.d.ts +0 -0
- package/lib/esm/utils/index.js +0 -0
- package/lib/esm/utils/registry.d.ts +0 -0
- package/lib/esm/utils/registry.js +0 -0
- package/lib/esm/utils/serialization.d.ts +0 -0
- package/lib/esm/utils/serialization.js +0 -0
- package/lib/esm/utils/strings.d.ts +0 -0
- package/lib/esm/utils/strings.js +0 -0
- package/lib/esm/validation/Validation.d.ts +0 -0
- package/lib/esm/validation/Validation.js +0 -0
- package/lib/esm/validation/Validators/DateValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/DateValidator.js +6 -5
- package/lib/esm/validation/Validators/EmailValidator.d.ts +3 -4
- package/lib/esm/validation/Validators/EmailValidator.js +7 -5
- package/lib/esm/validation/Validators/ListValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/ListValidator.js +4 -5
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MaxLengthValidator.js +4 -5
- package/lib/esm/validation/Validators/MaxValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MaxValidator.js +5 -5
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MinLengthValidator.js +5 -6
- package/lib/esm/validation/Validators/MinValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/MinValidator.js +5 -5
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +3 -4
- package/lib/esm/validation/Validators/PasswordValidator.js +6 -4
- package/lib/esm/validation/Validators/PatternValidator.d.ts +7 -5
- package/lib/esm/validation/Validators/PatternValidator.js +5 -5
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +3 -3
- package/lib/esm/validation/Validators/RequiredValidator.js +7 -5
- package/lib/esm/validation/Validators/StepValidator.d.ts +7 -4
- package/lib/esm/validation/Validators/StepValidator.js +5 -5
- package/lib/esm/validation/Validators/TypeValidator.d.ts +9 -7
- package/lib/esm/validation/Validators/TypeValidator.js +4 -4
- package/lib/esm/validation/Validators/URLValidator.d.ts +9 -3
- package/lib/esm/validation/Validators/URLValidator.js +3 -3
- package/lib/esm/validation/Validators/Validator.d.ts +6 -3
- package/lib/esm/validation/Validators/Validator.js +0 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -0
- package/lib/esm/validation/Validators/constants.d.ts +0 -0
- package/lib/esm/validation/Validators/constants.js +0 -0
- package/lib/esm/validation/Validators/decorators.d.ts +0 -0
- package/lib/esm/validation/Validators/decorators.js +0 -0
- package/lib/esm/validation/Validators/index.d.ts +0 -0
- package/lib/esm/validation/Validators/index.js +0 -0
- package/lib/esm/validation/Validators/types.d.ts +0 -0
- package/lib/esm/validation/Validators/types.js +0 -0
- package/lib/esm/validation/decorators.d.ts +0 -0
- package/lib/esm/validation/decorators.js +7 -7
- package/lib/esm/validation/index.d.ts +0 -0
- package/lib/esm/validation/index.js +0 -0
- package/lib/esm/validation/types.d.ts +0 -0
- package/lib/esm/validation/types.js +0 -0
- package/lib/index.cjs +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/model/Model.cjs +3 -4
- package/lib/model/Model.d.ts +1 -2
- package/lib/model/ModelErrorDefinition.cjs +0 -0
- package/lib/model/ModelErrorDefinition.d.ts +0 -0
- package/lib/model/Registry.cjs +0 -0
- package/lib/model/Registry.d.ts +0 -0
- package/lib/model/constants.cjs +0 -0
- package/lib/model/constants.d.ts +0 -0
- package/lib/model/construction.cjs +0 -0
- package/lib/model/construction.d.ts +0 -0
- package/lib/model/decorators.cjs +0 -0
- package/lib/model/decorators.d.ts +0 -0
- package/lib/model/index.cjs +0 -0
- package/lib/model/index.d.ts +0 -0
- package/lib/model/types.cjs +0 -0
- package/lib/model/types.d.ts +0 -0
- package/lib/model/utils.cjs +0 -0
- package/lib/model/utils.d.ts +0 -0
- package/lib/model/validation.cjs +3 -2
- package/lib/model/validation.d.ts +0 -0
- package/lib/utils/constants.cjs +0 -0
- package/lib/utils/constants.d.ts +0 -0
- package/lib/utils/dates.cjs +0 -0
- package/lib/utils/dates.d.ts +0 -0
- package/lib/utils/decorators.cjs +0 -0
- package/lib/utils/decorators.d.ts +0 -0
- package/lib/utils/hashing.cjs +0 -0
- package/lib/utils/hashing.d.ts +0 -0
- package/lib/utils/index.cjs +0 -0
- package/lib/utils/index.d.ts +0 -0
- package/lib/utils/registry.cjs +0 -0
- package/lib/utils/registry.d.ts +0 -0
- package/lib/utils/serialization.cjs +0 -0
- package/lib/utils/serialization.d.ts +0 -0
- package/lib/utils/strings.cjs +0 -0
- package/lib/utils/strings.d.ts +0 -0
- package/lib/validation/Validation.cjs +0 -0
- package/lib/validation/Validation.d.ts +0 -0
- package/lib/validation/Validators/DateValidator.cjs +5 -4
- package/lib/validation/Validators/DateValidator.d.ts +7 -5
- package/lib/validation/Validators/EmailValidator.cjs +6 -4
- package/lib/validation/Validators/EmailValidator.d.ts +3 -4
- package/lib/validation/Validators/ListValidator.cjs +4 -5
- package/lib/validation/Validators/ListValidator.d.ts +7 -5
- package/lib/validation/Validators/MaxLengthValidator.cjs +4 -5
- package/lib/validation/Validators/MaxLengthValidator.d.ts +7 -5
- package/lib/validation/Validators/MaxValidator.cjs +4 -4
- package/lib/validation/Validators/MaxValidator.d.ts +7 -5
- package/lib/validation/Validators/MinLengthValidator.cjs +4 -5
- package/lib/validation/Validators/MinLengthValidator.d.ts +7 -5
- package/lib/validation/Validators/MinValidator.cjs +4 -4
- package/lib/validation/Validators/MinValidator.d.ts +7 -5
- package/lib/validation/Validators/PasswordValidator.cjs +6 -4
- package/lib/validation/Validators/PasswordValidator.d.ts +3 -4
- package/lib/validation/Validators/PatternValidator.cjs +4 -4
- package/lib/validation/Validators/PatternValidator.d.ts +7 -5
- package/lib/validation/Validators/RequiredValidator.cjs +6 -4
- package/lib/validation/Validators/RequiredValidator.d.ts +3 -3
- package/lib/validation/Validators/StepValidator.cjs +4 -4
- package/lib/validation/Validators/StepValidator.d.ts +7 -4
- package/lib/validation/Validators/TypeValidator.cjs +4 -4
- package/lib/validation/Validators/TypeValidator.d.ts +9 -7
- package/lib/validation/Validators/URLValidator.cjs +3 -3
- package/lib/validation/Validators/URLValidator.d.ts +9 -3
- package/lib/validation/Validators/Validator.cjs +0 -0
- package/lib/validation/Validators/Validator.d.ts +6 -3
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -0
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -0
- package/lib/validation/Validators/constants.cjs +0 -0
- package/lib/validation/Validators/constants.d.ts +0 -0
- package/lib/validation/Validators/decorators.cjs +0 -0
- package/lib/validation/Validators/index.cjs +0 -0
- package/lib/validation/Validators/types.cjs +0 -0
- package/lib/validation/decorators.cjs +7 -7
- package/lib/validation/decorators.d.ts +0 -0
- package/lib/validation/index.cjs +0 -0
- package/lib/validation/index.d.ts +0 -0
- package/lib/validation/types.cjs +0 -0
- package/lib/validation/types.d.ts +0 -0
- package/package.json +1 -1
- package/lib/validation/Validators/decorators.d.ts +0 -12
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface MaxValidatorOptions extends ValidatorOptions {
|
|
3
|
+
max: number | Date | string;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Max Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class MaxValidator extends Validator {
|
|
15
|
+
export declare class MaxValidator extends Validator<MaxValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates a Model
|
|
16
19
|
*
|
|
17
20
|
* @param {string} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {MaxValidatorOptions} options
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -24,5 +26,5 @@ export declare class MaxValidator extends Validator {
|
|
|
24
26
|
*
|
|
25
27
|
* @see Validator#hasErrors
|
|
26
28
|
*/
|
|
27
|
-
hasErrors(value: number | Date | string,
|
|
29
|
+
hasErrors(value: number | Date | string, options: MaxValidatorOptions): string | undefined;
|
|
28
30
|
}
|
|
@@ -31,8 +31,7 @@ let MinLengthValidator = class MinLengthValidator extends Validator_1.Validator
|
|
|
31
31
|
/**
|
|
32
32
|
*
|
|
33
33
|
* @param {string | Array} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {MinLengthValidatorOptions} options
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -41,11 +40,11 @@ let MinLengthValidator = class MinLengthValidator extends Validator_1.Validator
|
|
|
41
40
|
*
|
|
42
41
|
* @see Validator#hasErrors
|
|
43
42
|
*/
|
|
44
|
-
hasErrors(value,
|
|
43
|
+
hasErrors(value, options) {
|
|
45
44
|
if (typeof value === "undefined")
|
|
46
45
|
return;
|
|
47
|
-
return value.length <
|
|
48
|
-
? this.getMessage(message || this.message,
|
|
46
|
+
return value.length < options.minLength
|
|
47
|
+
? this.getMessage(options.message || this.message, options.minLength)
|
|
49
48
|
: undefined;
|
|
50
49
|
}
|
|
51
50
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface MinLengthValidatorOptions extends ValidatorOptions {
|
|
3
|
+
minLength: number;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Minimum Length Validator
|
|
4
7
|
* @description Validates strings and Arrays on their minimum length
|
|
@@ -10,13 +13,12 @@ import { Validator } from "./Validator";
|
|
|
10
13
|
*
|
|
11
14
|
* @category Validators
|
|
12
15
|
*/
|
|
13
|
-
export declare class MinLengthValidator extends Validator {
|
|
16
|
+
export declare class MinLengthValidator extends Validator<MinLengthValidatorOptions> {
|
|
14
17
|
constructor(message?: string);
|
|
15
18
|
/**
|
|
16
19
|
*
|
|
17
20
|
* @param {string | Array} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {MinLengthValidatorOptions} options
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -25,5 +27,5 @@ export declare class MinLengthValidator extends Validator {
|
|
|
25
27
|
*
|
|
26
28
|
* @see Validator#hasErrors
|
|
27
29
|
*/
|
|
28
|
-
hasErrors(value: string | any[],
|
|
30
|
+
hasErrors(value: string | any[], options: MinLengthValidatorOptions): string | undefined;
|
|
29
31
|
}
|
|
@@ -31,8 +31,7 @@ let MinValidator = class MinValidator extends Validator_1.Validator {
|
|
|
31
31
|
* @summary Validates Model
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {MaxValidatorOptions} options
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,16 +39,17 @@ let MinValidator = class MinValidator extends Validator_1.Validator {
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options) {
|
|
44
43
|
if (typeof value === "undefined")
|
|
45
44
|
return;
|
|
45
|
+
let { min } = options;
|
|
46
46
|
if (value instanceof Date && !(min instanceof Date)) {
|
|
47
47
|
min = new Date(min);
|
|
48
48
|
if (Number.isNaN(min.getDate()))
|
|
49
49
|
throw new Error("Invalid Min param defined");
|
|
50
50
|
}
|
|
51
51
|
return value < min
|
|
52
|
-
? this.getMessage(message || this.message, min)
|
|
52
|
+
? this.getMessage(options.message || this.message, min)
|
|
53
53
|
: undefined;
|
|
54
54
|
}
|
|
55
55
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface MinValidatorOptions extends ValidatorOptions {
|
|
3
|
+
min: number | Date | string;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Min Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class MinValidator extends Validator {
|
|
15
|
+
export declare class MinValidator extends Validator<MinValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates Model
|
|
16
19
|
*
|
|
17
20
|
* @param {string} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {MaxValidatorOptions} options
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -24,5 +26,5 @@ export declare class MinValidator extends Validator {
|
|
|
24
26
|
*
|
|
25
27
|
* @see Validator#hasErrors
|
|
26
28
|
*/
|
|
27
|
-
hasErrors(value: number | Date | string,
|
|
29
|
+
hasErrors(value: number | Date | string, options: MinValidatorOptions): string | undefined;
|
|
28
30
|
}
|
|
@@ -31,8 +31,7 @@ let PasswordValidator = class PasswordValidator extends PatternValidator_1.Patte
|
|
|
31
31
|
* @summary Validates a model
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,8 +39,11 @@ let PasswordValidator = class PasswordValidator extends PatternValidator_1.Patte
|
|
|
40
39
|
*
|
|
41
40
|
* @see PatternValidator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
44
|
-
return super.hasErrors(value,
|
|
42
|
+
hasErrors(value, options = {}) {
|
|
43
|
+
return super.hasErrors(value, {
|
|
44
|
+
...options,
|
|
45
|
+
message: options.message || this.message,
|
|
46
|
+
});
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
exports.PasswordValidator = PasswordValidator;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
1
|
+
import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
|
|
2
2
|
/**
|
|
3
3
|
* @summary Handles Password Validation
|
|
4
4
|
*
|
|
@@ -15,8 +15,7 @@ export declare class PasswordValidator extends PatternValidator {
|
|
|
15
15
|
* @summary Validates a model
|
|
16
16
|
*
|
|
17
17
|
* @param {string} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
18
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
20
19
|
*
|
|
21
20
|
* @return {string | undefined}
|
|
22
21
|
*
|
|
@@ -24,5 +23,5 @@ export declare class PasswordValidator extends PatternValidator {
|
|
|
24
23
|
*
|
|
25
24
|
* @see PatternValidator#hasErrors
|
|
26
25
|
*/
|
|
27
|
-
hasErrors(value: string,
|
|
26
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
28
27
|
}
|
|
@@ -45,8 +45,7 @@ let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
|
45
45
|
* @summary Validates a Model
|
|
46
46
|
*
|
|
47
47
|
* @param {string} value
|
|
48
|
-
* @param {
|
|
49
|
-
* @param {string} [message]
|
|
48
|
+
* @param {PatternValidatorOptions} options
|
|
50
49
|
*
|
|
51
50
|
* @return {string | undefined}
|
|
52
51
|
*
|
|
@@ -54,15 +53,16 @@ let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
|
54
53
|
*
|
|
55
54
|
* @see Validator#hasErrors
|
|
56
55
|
*/
|
|
57
|
-
hasErrors(value,
|
|
56
|
+
hasErrors(value, options) {
|
|
58
57
|
if (!value)
|
|
59
58
|
return;
|
|
59
|
+
let { pattern } = options;
|
|
60
60
|
if (!pattern)
|
|
61
61
|
throw new Error("Missing Pattern");
|
|
62
62
|
pattern = typeof pattern === "string" ? this.getPattern(pattern) : pattern;
|
|
63
63
|
pattern.lastIndex = 0; // resets pattern position for repeat validation requests
|
|
64
64
|
return !pattern.test(value)
|
|
65
|
-
? this.getMessage(message || this.message)
|
|
65
|
+
? this.getMessage(options.message || this.message)
|
|
66
66
|
: undefined;
|
|
67
67
|
}
|
|
68
68
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface PatternValidatorOptions extends ValidatorOptions {
|
|
3
|
+
pattern?: RegExp | string;
|
|
4
|
+
}
|
|
2
5
|
export declare const regexpParser: RegExp;
|
|
3
6
|
/**
|
|
4
7
|
* @summary Pattern Validator
|
|
@@ -11,7 +14,7 @@ export declare const regexpParser: RegExp;
|
|
|
11
14
|
*
|
|
12
15
|
* @category Validators
|
|
13
16
|
*/
|
|
14
|
-
export declare class PatternValidator extends Validator {
|
|
17
|
+
export declare class PatternValidator extends Validator<PatternValidatorOptions> {
|
|
15
18
|
constructor(message?: string);
|
|
16
19
|
/**
|
|
17
20
|
* @summary parses and validates a pattern
|
|
@@ -24,8 +27,7 @@ export declare class PatternValidator extends Validator {
|
|
|
24
27
|
* @summary Validates a Model
|
|
25
28
|
*
|
|
26
29
|
* @param {string} value
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {string} [message]
|
|
30
|
+
* @param {PatternValidatorOptions} options
|
|
29
31
|
*
|
|
30
32
|
* @return {string | undefined}
|
|
31
33
|
*
|
|
@@ -33,5 +35,5 @@ export declare class PatternValidator extends Validator {
|
|
|
33
35
|
*
|
|
34
36
|
* @see Validator#hasErrors
|
|
35
37
|
*/
|
|
36
|
-
hasErrors(value: string,
|
|
38
|
+
hasErrors(value: string, options: PatternValidatorOptions): string | undefined;
|
|
37
39
|
}
|
|
@@ -31,7 +31,7 @@ let RequiredValidator = class RequiredValidator extends Validator_1.Validator {
|
|
|
31
31
|
* @summary Validates a model
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
34
|
+
* @param {ValidatorOptions} [options={}]
|
|
35
35
|
*
|
|
36
36
|
* @return {string | undefined}
|
|
37
37
|
*
|
|
@@ -39,15 +39,17 @@ let RequiredValidator = class RequiredValidator extends Validator_1.Validator {
|
|
|
39
39
|
*
|
|
40
40
|
* @see Validator#hasErrors
|
|
41
41
|
*/
|
|
42
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options = {}) {
|
|
43
43
|
switch (typeof value) {
|
|
44
44
|
case "boolean":
|
|
45
45
|
case "number":
|
|
46
46
|
return typeof value === "undefined"
|
|
47
|
-
? this.getMessage(message || this.message)
|
|
47
|
+
? this.getMessage(options.message || this.message)
|
|
48
48
|
: undefined;
|
|
49
49
|
default:
|
|
50
|
-
return !value
|
|
50
|
+
return !value
|
|
51
|
+
? this.getMessage(options.message || this.message)
|
|
52
|
+
: undefined;
|
|
51
53
|
}
|
|
52
54
|
}
|
|
53
55
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
2
|
/**
|
|
3
3
|
* @summary Required Validator
|
|
4
4
|
*
|
|
@@ -15,7 +15,7 @@ export declare class RequiredValidator extends Validator {
|
|
|
15
15
|
* @summary Validates a model
|
|
16
16
|
*
|
|
17
17
|
* @param {string} value
|
|
18
|
-
* @param {
|
|
18
|
+
* @param {ValidatorOptions} [options={}]
|
|
19
19
|
*
|
|
20
20
|
* @return {string | undefined}
|
|
21
21
|
*
|
|
@@ -23,5 +23,5 @@ export declare class RequiredValidator extends Validator {
|
|
|
23
23
|
*
|
|
24
24
|
* @see Validator#hasErrors
|
|
25
25
|
*/
|
|
26
|
-
hasErrors(value: any,
|
|
26
|
+
hasErrors(value: any, options?: ValidatorOptions): string | undefined;
|
|
27
27
|
}
|
|
@@ -32,7 +32,7 @@ let StepValidator = class StepValidator extends Validator_1.Validator {
|
|
|
32
32
|
*
|
|
33
33
|
* @param {string} value
|
|
34
34
|
* @param {number} step
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {StepValidatorOptions} options
|
|
36
36
|
*
|
|
37
37
|
* @return {string | undefined}
|
|
38
38
|
*
|
|
@@ -40,11 +40,11 @@ let StepValidator = class StepValidator extends Validator_1.Validator {
|
|
|
40
40
|
*
|
|
41
41
|
* @see Validator#hasErrors
|
|
42
42
|
*/
|
|
43
|
-
hasErrors(value,
|
|
43
|
+
hasErrors(value, options) {
|
|
44
44
|
if (typeof value === "undefined")
|
|
45
45
|
return;
|
|
46
|
-
return Number(value) % Number(step) !== 0
|
|
47
|
-
? this.getMessage(message || this.message, step)
|
|
46
|
+
return Number(value) % Number(options.step) !== 0
|
|
47
|
+
? this.getMessage(options.message || this.message, options.step)
|
|
48
48
|
: undefined;
|
|
49
49
|
}
|
|
50
50
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface StepValidatorOptions extends ValidatorOptions {
|
|
3
|
+
step: number | string;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Step Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,14 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class StepValidator extends Validator {
|
|
15
|
+
export declare class StepValidator extends Validator<StepValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates a model
|
|
16
19
|
*
|
|
17
20
|
* @param {string} value
|
|
18
21
|
* @param {number} step
|
|
19
|
-
* @param {
|
|
22
|
+
* @param {StepValidatorOptions} options
|
|
20
23
|
*
|
|
21
24
|
* @return {string | undefined}
|
|
22
25
|
*
|
|
@@ -24,5 +27,5 @@ export declare class StepValidator extends Validator {
|
|
|
24
27
|
*
|
|
25
28
|
* @see Validator#hasErrors
|
|
26
29
|
*/
|
|
27
|
-
hasErrors(value: number | string,
|
|
30
|
+
hasErrors(value: number | string, options: StepValidatorOptions): string | undefined;
|
|
28
31
|
}
|
|
@@ -31,8 +31,7 @@ let TypeValidator = class TypeValidator extends Validator_1.Validator {
|
|
|
31
31
|
/**
|
|
32
32
|
* @summary Validates a model
|
|
33
33
|
* @param {string} value
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {string} [message]
|
|
34
|
+
* @param {TypeValidatorOptions} options
|
|
36
35
|
*
|
|
37
36
|
* @return {string | undefined}
|
|
38
37
|
*
|
|
@@ -40,9 +39,10 @@ let TypeValidator = class TypeValidator extends Validator_1.Validator {
|
|
|
40
39
|
*
|
|
41
40
|
* @see Validator#hasErrors
|
|
42
41
|
*/
|
|
43
|
-
hasErrors(value,
|
|
42
|
+
hasErrors(value, options) {
|
|
44
43
|
if (value === undefined)
|
|
45
|
-
return; //
|
|
44
|
+
return; // Don't try and enforce type if undefined
|
|
45
|
+
const { types, message } = options;
|
|
46
46
|
if (!reflection_1.Reflection.evaluateDesignTypes(value, types))
|
|
47
47
|
return this.getMessage(message || this.message, typeof types === "string"
|
|
48
48
|
? types
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface TypeValidatorOptions extends ValidatorOptions {
|
|
3
|
+
types: string | string[] | {
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* @summary Required Validator
|
|
4
9
|
*
|
|
@@ -7,13 +12,12 @@ import { Validator } from "./Validator";
|
|
|
7
12
|
*
|
|
8
13
|
* @category Validators
|
|
9
14
|
*/
|
|
10
|
-
export declare class TypeValidator extends Validator {
|
|
15
|
+
export declare class TypeValidator extends Validator<TypeValidatorOptions> {
|
|
11
16
|
constructor(message?: string);
|
|
12
17
|
/**
|
|
13
18
|
* @summary Validates a model
|
|
14
19
|
* @param {string} value
|
|
15
|
-
* @param {
|
|
16
|
-
* @param {string} [message]
|
|
20
|
+
* @param {TypeValidatorOptions} options
|
|
17
21
|
*
|
|
18
22
|
* @return {string | undefined}
|
|
19
23
|
*
|
|
@@ -21,7 +25,5 @@ export declare class TypeValidator extends Validator {
|
|
|
21
25
|
*
|
|
22
26
|
* @see Validator#hasErrors
|
|
23
27
|
*/
|
|
24
|
-
hasErrors(value: any,
|
|
25
|
-
name: string;
|
|
26
|
-
}, message?: string): string | undefined;
|
|
28
|
+
hasErrors(value: any, options: TypeValidatorOptions): string | undefined;
|
|
27
29
|
}
|
|
@@ -30,7 +30,7 @@ let URLValidator = class URLValidator extends PatternValidator_1.PatternValidato
|
|
|
30
30
|
* @summary Validates a model
|
|
31
31
|
*
|
|
32
32
|
* @param {string} value
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
34
34
|
*
|
|
35
35
|
* @return {string | undefined}
|
|
36
36
|
*
|
|
@@ -38,8 +38,8 @@ let URLValidator = class URLValidator extends PatternValidator_1.PatternValidato
|
|
|
38
38
|
*
|
|
39
39
|
* @see Validator#hasErrors
|
|
40
40
|
*/
|
|
41
|
-
hasErrors(value,
|
|
42
|
-
return super.hasErrors(value, pattern || constants_1.DEFAULT_PATTERNS.URL
|
|
41
|
+
hasErrors(value, options = {}) {
|
|
42
|
+
return super.hasErrors(value, { ...options, pattern: options.pattern || constants_1.DEFAULT_PATTERNS.URL });
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
exports.URLValidator = URLValidator;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
1
|
+
import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
|
|
2
|
+
import { ValidatorOptions } from "./Validator";
|
|
3
|
+
export interface URLValidatorOptions extends ValidatorOptions {
|
|
4
|
+
types: string | string[] | {
|
|
5
|
+
name: string;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
9
|
* @summary URL Validator
|
|
4
10
|
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
@@ -14,7 +20,7 @@ export declare class URLValidator extends PatternValidator {
|
|
|
14
20
|
* @summary Validates a model
|
|
15
21
|
*
|
|
16
22
|
* @param {string} value
|
|
17
|
-
* @param {
|
|
23
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
18
24
|
*
|
|
19
25
|
* @return {string | undefined}
|
|
20
26
|
*
|
|
@@ -22,5 +28,5 @@ export declare class URLValidator extends PatternValidator {
|
|
|
22
28
|
*
|
|
23
29
|
* @see Validator#hasErrors
|
|
24
30
|
*/
|
|
25
|
-
hasErrors(value: string,
|
|
31
|
+
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
26
32
|
}
|
|
File without changes
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export type ValidatorOptions = {
|
|
2
|
+
message?: string;
|
|
3
|
+
};
|
|
1
4
|
/**
|
|
2
5
|
* @summary Base Implementation for Validators
|
|
3
6
|
* @description Provides the underlying functionality for {@link Validator}s
|
|
@@ -10,7 +13,7 @@
|
|
|
10
13
|
* @abstract
|
|
11
14
|
* @category Validators
|
|
12
15
|
*/
|
|
13
|
-
export declare abstract class Validator {
|
|
16
|
+
export declare abstract class Validator<V extends ValidatorOptions = ValidatorOptions> {
|
|
14
17
|
readonly message: string;
|
|
15
18
|
readonly acceptedTypes?: string[];
|
|
16
19
|
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
@@ -30,11 +33,11 @@ export declare abstract class Validator {
|
|
|
30
33
|
/**
|
|
31
34
|
* @summary Validates an attribute
|
|
32
35
|
* @param {any} value
|
|
33
|
-
* @param {
|
|
36
|
+
* @param {ValidatorOptions} [options] Validate options for customizing the model validation behavior
|
|
34
37
|
*
|
|
35
38
|
* @abstract
|
|
36
39
|
*
|
|
37
40
|
* @see Model#hasErrors
|
|
38
41
|
*/
|
|
39
|
-
abstract hasErrors(value: any,
|
|
42
|
+
abstract hasErrors(value: any, options?: V): string | undefined;
|
|
40
43
|
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -48,7 +48,7 @@ function required(message = constants_1.DEFAULT_ERROR_MESSAGES.REQUIRED) {
|
|
|
48
48
|
*/
|
|
49
49
|
function min(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN) {
|
|
50
50
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MIN), {
|
|
51
|
-
|
|
51
|
+
min: value,
|
|
52
52
|
message: message,
|
|
53
53
|
types: [Number.name, Date.name],
|
|
54
54
|
});
|
|
@@ -66,7 +66,7 @@ function min(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN) {
|
|
|
66
66
|
*/
|
|
67
67
|
function max(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX) {
|
|
68
68
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MAX), {
|
|
69
|
-
|
|
69
|
+
max: value,
|
|
70
70
|
message: message,
|
|
71
71
|
types: [Number.name, Date.name],
|
|
72
72
|
});
|
|
@@ -84,7 +84,7 @@ function max(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX) {
|
|
|
84
84
|
*/
|
|
85
85
|
function step(value, message = constants_1.DEFAULT_ERROR_MESSAGES.STEP) {
|
|
86
86
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.STEP), {
|
|
87
|
-
|
|
87
|
+
step: value,
|
|
88
88
|
message: message,
|
|
89
89
|
types: [Number.name],
|
|
90
90
|
});
|
|
@@ -102,7 +102,7 @@ function step(value, message = constants_1.DEFAULT_ERROR_MESSAGES.STEP) {
|
|
|
102
102
|
*/
|
|
103
103
|
function minlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
|
|
104
104
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MIN_LENGTH), {
|
|
105
|
-
|
|
105
|
+
minLength: value,
|
|
106
106
|
message: message,
|
|
107
107
|
types: [String.name, Array.name, Set.name],
|
|
108
108
|
});
|
|
@@ -120,7 +120,7 @@ function minlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN_LENGT
|
|
|
120
120
|
*/
|
|
121
121
|
function maxlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
|
|
122
122
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MAX_LENGTH), {
|
|
123
|
-
|
|
123
|
+
maxLength: value,
|
|
124
124
|
message: message,
|
|
125
125
|
types: [String.name, Array.name, Set.name],
|
|
126
126
|
});
|
|
@@ -138,7 +138,7 @@ function maxlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX_LENGT
|
|
|
138
138
|
*/
|
|
139
139
|
function pattern(value, message = constants_1.DEFAULT_ERROR_MESSAGES.PATTERN) {
|
|
140
140
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.PATTERN), {
|
|
141
|
-
|
|
141
|
+
pattern: typeof value === "string" ? value : value.toString(),
|
|
142
142
|
message: message,
|
|
143
143
|
types: [String.name],
|
|
144
144
|
});
|
|
@@ -281,7 +281,7 @@ function password(pattern = constants_1.DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_E
|
|
|
281
281
|
*/
|
|
282
282
|
function list(clazz, collection = "Array", message = constants_1.DEFAULT_ERROR_MESSAGES.LIST) {
|
|
283
283
|
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.LIST), {
|
|
284
|
-
|
|
284
|
+
clazz: Array.isArray(clazz) ? clazz.map((c) => c.name) : [clazz.name],
|
|
285
285
|
type: collection,
|
|
286
286
|
message: message,
|
|
287
287
|
});
|
|
File without changes
|
package/lib/validation/index.cjs
CHANGED
|
File without changes
|
|
File without changes
|
package/lib/validation/types.cjs
CHANGED
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Marks the class as a validator for a certain key.
|
|
4
|
-
* @description Registers the class in the {@link Validation} with the provided key
|
|
5
|
-
*
|
|
6
|
-
* @param {string} keys the validation key
|
|
7
|
-
*
|
|
8
|
-
* @function validator
|
|
9
|
-
*
|
|
10
|
-
* @category Decorators
|
|
11
|
-
*/
|
|
12
|
-
export declare function validator<T extends Validator>(...keys: string[]): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
|