@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
|
@@ -7,7 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
10
|
+
import { DEFAULT_ERROR_MESSAGES, DEFAULT_PATTERNS, ValidationKeys } from "./constants";
|
|
11
11
|
import { PatternValidator } from "./PatternValidator";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
@@ -28,8 +28,7 @@ let EmailValidator = class EmailValidator extends PatternValidator {
|
|
|
28
28
|
* @summary Validates a model
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {PatternValidatorOptions} [options]
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,8 +36,11 @@ let EmailValidator = class EmailValidator extends PatternValidator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Validator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
41
|
-
return super.hasErrors(value,
|
|
39
|
+
hasErrors(value, options = {}) {
|
|
40
|
+
return super.hasErrors(value, {
|
|
41
|
+
...options,
|
|
42
|
+
pattern: options?.pattern || DEFAULT_PATTERNS.EMAIL,
|
|
43
|
+
});
|
|
42
44
|
}
|
|
43
45
|
};
|
|
44
46
|
EmailValidator = __decorate([
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface ListValidatorOptions extends ValidatorOptions {
|
|
3
|
+
clazz: string[];
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary List Validator
|
|
4
7
|
*
|
|
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
|
|
|
9
12
|
*
|
|
10
13
|
* @category Validators
|
|
11
14
|
*/
|
|
12
|
-
export declare class ListValidator extends Validator {
|
|
15
|
+
export declare class ListValidator extends Validator<ListValidatorOptions> {
|
|
13
16
|
constructor(message?: string);
|
|
14
17
|
/**
|
|
15
18
|
* @summary Validates a model
|
|
16
19
|
*
|
|
17
20
|
* @param {any[] | Set<any>} value
|
|
18
|
-
* @param {
|
|
19
|
-
* @param {string} [message]
|
|
21
|
+
* @param {ListValidatorOptions} options
|
|
20
22
|
*
|
|
21
23
|
* @return {string | undefined}
|
|
22
24
|
*
|
|
@@ -24,5 +26,5 @@ export declare class ListValidator extends Validator {
|
|
|
24
26
|
*
|
|
25
27
|
* @see Validator#hasErrors
|
|
26
28
|
*/
|
|
27
|
-
hasErrors(value: any[] | Set<any>,
|
|
29
|
+
hasErrors(value: any[] | Set<any>, options: ListValidatorOptions): string | undefined;
|
|
28
30
|
}
|
|
@@ -28,8 +28,7 @@ let ListValidator = class ListValidator extends Validator {
|
|
|
28
28
|
* @summary Validates a model
|
|
29
29
|
*
|
|
30
30
|
* @param {any[] | Set<any>} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {ListValidatorOptions} options
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,10 +36,10 @@ let ListValidator = class ListValidator extends Validator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Validator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
39
|
+
hasErrors(value, options) {
|
|
41
40
|
if (!value || (Array.isArray(value) ? !value.length : !value.size))
|
|
42
41
|
return;
|
|
43
|
-
clazz = Array.isArray(clazz) ? clazz : [clazz];
|
|
42
|
+
const clazz = Array.isArray(options.clazz) ? options.clazz : [options.clazz];
|
|
44
43
|
let val, isValid = true;
|
|
45
44
|
for (let i = 0; i < (Array.isArray(value) ? value.length : value.size); i++) {
|
|
46
45
|
val = value[i];
|
|
@@ -56,7 +55,7 @@ let ListValidator = class ListValidator extends Validator {
|
|
|
56
55
|
}
|
|
57
56
|
return isValid
|
|
58
57
|
? undefined
|
|
59
|
-
: this.getMessage(message || this.message, clazz);
|
|
58
|
+
: this.getMessage(options.message || this.message, clazz);
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
61
|
ListValidator = __decorate([
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
1
|
+
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
+
export interface MaxLengthValidatorOptions extends ValidatorOptions {
|
|
3
|
+
maxLength: number;
|
|
4
|
+
}
|
|
2
5
|
/**
|
|
3
6
|
* @summary Maximum Length Validator
|
|
4
7
|
* @description Validates strings and Arrays on their maximum length
|
|
@@ -10,14 +13,13 @@ import { Validator } from "./Validator";
|
|
|
10
13
|
*
|
|
11
14
|
* @category Validators
|
|
12
15
|
*/
|
|
13
|
-
export declare class MaxLengthValidator extends Validator {
|
|
16
|
+
export declare class MaxLengthValidator extends Validator<MaxLengthValidatorOptions> {
|
|
14
17
|
constructor(message?: string);
|
|
15
18
|
/**
|
|
16
19
|
* @summary Validates a model
|
|
17
20
|
*
|
|
18
21
|
* @param {string} value
|
|
19
|
-
* @param {
|
|
20
|
-
* @param {string} [message]
|
|
22
|
+
* @param {MaxLengthValidatorOptions} options
|
|
21
23
|
*
|
|
22
24
|
* @return {string | undefined}
|
|
23
25
|
*
|
|
@@ -25,5 +27,5 @@ export declare class MaxLengthValidator extends Validator {
|
|
|
25
27
|
*
|
|
26
28
|
* @see Validator#hasErrors
|
|
27
29
|
*/
|
|
28
|
-
hasErrors(value: string | any[],
|
|
30
|
+
hasErrors(value: string | any[], options: MaxLengthValidatorOptions): string | undefined;
|
|
29
31
|
}
|
|
@@ -29,8 +29,7 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator {
|
|
|
29
29
|
* @summary Validates a model
|
|
30
30
|
*
|
|
31
31
|
* @param {string} value
|
|
32
|
-
* @param {
|
|
33
|
-
* @param {string} [message]
|
|
32
|
+
* @param {MaxLengthValidatorOptions} options
|
|
34
33
|
*
|
|
35
34
|
* @return {string | undefined}
|
|
36
35
|
*
|
|
@@ -38,11 +37,11 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator {
|
|
|
38
37
|
*
|
|
39
38
|
* @see Validator#hasErrors
|
|
40
39
|
*/
|
|
41
|
-
hasErrors(value,
|
|
40
|
+
hasErrors(value, options) {
|
|
42
41
|
if (typeof value === "undefined")
|
|
43
42
|
return;
|
|
44
|
-
return value.length >
|
|
45
|
-
? this.getMessage(message || this.message,
|
|
43
|
+
return value.length > options.maxLength
|
|
44
|
+
? this.getMessage(options.message || this.message, options.maxLength)
|
|
46
45
|
: undefined;
|
|
47
46
|
}
|
|
48
47
|
};
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
14
|
* @summary Max Validator
|
|
@@ -28,8 +28,7 @@ let MaxValidator = class MaxValidator extends Validator {
|
|
|
28
28
|
* @summary Validates a Model
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {MaxValidatorOptions} options
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,16 +36,17 @@ let MaxValidator = class MaxValidator extends Validator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Validator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
39
|
+
hasErrors(value, options) {
|
|
41
40
|
if (typeof value === "undefined")
|
|
42
41
|
return;
|
|
42
|
+
let { max } = options;
|
|
43
43
|
if (value instanceof Date && !(max instanceof Date)) {
|
|
44
44
|
max = new Date(max);
|
|
45
45
|
if (Number.isNaN(max.getDate()))
|
|
46
46
|
throw new Error("Invalid Max param defined");
|
|
47
47
|
}
|
|
48
48
|
return value > max
|
|
49
|
-
? this.getMessage(message || this.message, max)
|
|
49
|
+
? this.getMessage(options.message || this.message, max)
|
|
50
50
|
: undefined;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
14
|
* @summary Minimum Length Validator
|
|
@@ -28,8 +28,7 @@ let MinLengthValidator = class MinLengthValidator extends Validator {
|
|
|
28
28
|
/**
|
|
29
29
|
*
|
|
30
30
|
* @param {string | Array} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {MinLengthValidatorOptions} options
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -38,11 +37,11 @@ let MinLengthValidator = class MinLengthValidator extends Validator {
|
|
|
38
37
|
*
|
|
39
38
|
* @see Validator#hasErrors
|
|
40
39
|
*/
|
|
41
|
-
hasErrors(value,
|
|
40
|
+
hasErrors(value, options) {
|
|
42
41
|
if (typeof value === "undefined")
|
|
43
42
|
return;
|
|
44
|
-
return value.length <
|
|
45
|
-
? this.getMessage(message || this.message,
|
|
43
|
+
return value.length < options.minLength
|
|
44
|
+
? this.getMessage(options.message || this.message, options.minLength)
|
|
46
45
|
: undefined;
|
|
47
46
|
}
|
|
48
47
|
};
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
14
|
* @summary Min Validator
|
|
@@ -28,8 +28,7 @@ let MinValidator = class MinValidator extends Validator {
|
|
|
28
28
|
* @summary Validates Model
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {MaxValidatorOptions} options
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,16 +36,17 @@ let MinValidator = class MinValidator extends Validator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see Validator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
39
|
+
hasErrors(value, options) {
|
|
41
40
|
if (typeof value === "undefined")
|
|
42
41
|
return;
|
|
42
|
+
let { min } = options;
|
|
43
43
|
if (value instanceof Date && !(min instanceof Date)) {
|
|
44
44
|
min = new Date(min);
|
|
45
45
|
if (Number.isNaN(min.getDate()))
|
|
46
46
|
throw new Error("Invalid Min param defined");
|
|
47
47
|
}
|
|
48
48
|
return value < min
|
|
49
|
-
? this.getMessage(message || this.message, min)
|
|
49
|
+
? this.getMessage(options.message || this.message, min)
|
|
50
50
|
: undefined;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
@@ -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
|
}
|
|
@@ -28,8 +28,7 @@ let PasswordValidator = class PasswordValidator extends PatternValidator {
|
|
|
28
28
|
* @summary Validates a model
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [message]
|
|
31
|
+
* @param {PatternValidatorOptions} [options={}]
|
|
33
32
|
*
|
|
34
33
|
* @return {string | undefined}
|
|
35
34
|
*
|
|
@@ -37,8 +36,11 @@ let PasswordValidator = class PasswordValidator extends PatternValidator {
|
|
|
37
36
|
*
|
|
38
37
|
* @see PatternValidator#hasErrors
|
|
39
38
|
*/
|
|
40
|
-
hasErrors(value,
|
|
41
|
-
return super.hasErrors(value,
|
|
39
|
+
hasErrors(value, options = {}) {
|
|
40
|
+
return super.hasErrors(value, {
|
|
41
|
+
...options,
|
|
42
|
+
message: options.message || this.message,
|
|
43
|
+
});
|
|
42
44
|
}
|
|
43
45
|
};
|
|
44
46
|
PasswordValidator = __decorate([
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
export const regexpParser = new RegExp("^/(.+)/([gimus]*)$");
|
|
14
14
|
/**
|
|
@@ -42,8 +42,7 @@ let PatternValidator = class PatternValidator extends Validator {
|
|
|
42
42
|
* @summary Validates a Model
|
|
43
43
|
*
|
|
44
44
|
* @param {string} value
|
|
45
|
-
* @param {
|
|
46
|
-
* @param {string} [message]
|
|
45
|
+
* @param {PatternValidatorOptions} options
|
|
47
46
|
*
|
|
48
47
|
* @return {string | undefined}
|
|
49
48
|
*
|
|
@@ -51,15 +50,16 @@ let PatternValidator = class PatternValidator extends Validator {
|
|
|
51
50
|
*
|
|
52
51
|
* @see Validator#hasErrors
|
|
53
52
|
*/
|
|
54
|
-
hasErrors(value,
|
|
53
|
+
hasErrors(value, options) {
|
|
55
54
|
if (!value)
|
|
56
55
|
return;
|
|
56
|
+
let { pattern } = options;
|
|
57
57
|
if (!pattern)
|
|
58
58
|
throw new Error("Missing Pattern");
|
|
59
59
|
pattern = typeof pattern === "string" ? this.getPattern(pattern) : pattern;
|
|
60
60
|
pattern.lastIndex = 0; // resets pattern position for repeat validation requests
|
|
61
61
|
return !pattern.test(value)
|
|
62
|
-
? this.getMessage(message || this.message)
|
|
62
|
+
? this.getMessage(options.message || this.message)
|
|
63
63
|
: undefined;
|
|
64
64
|
}
|
|
65
65
|
};
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
14
|
* @summary Required Validator
|
|
@@ -28,7 +28,7 @@ let RequiredValidator = class RequiredValidator extends Validator {
|
|
|
28
28
|
* @summary Validates a model
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {ValidatorOptions} [options={}]
|
|
32
32
|
*
|
|
33
33
|
* @return {string | undefined}
|
|
34
34
|
*
|
|
@@ -36,15 +36,17 @@ let RequiredValidator = class RequiredValidator extends Validator {
|
|
|
36
36
|
*
|
|
37
37
|
* @see Validator#hasErrors
|
|
38
38
|
*/
|
|
39
|
-
hasErrors(value,
|
|
39
|
+
hasErrors(value, options = {}) {
|
|
40
40
|
switch (typeof value) {
|
|
41
41
|
case "boolean":
|
|
42
42
|
case "number":
|
|
43
43
|
return typeof value === "undefined"
|
|
44
|
-
? this.getMessage(message || this.message)
|
|
44
|
+
? this.getMessage(options.message || this.message)
|
|
45
45
|
: undefined;
|
|
46
46
|
default:
|
|
47
|
-
return !value
|
|
47
|
+
return !value
|
|
48
|
+
? this.getMessage(options.message || this.message)
|
|
49
|
+
: undefined;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
52
|
};
|
|
@@ -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
|
}
|
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { Validator } from "./Validator";
|
|
11
|
-
import {
|
|
11
|
+
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
12
|
import { validator } from "./decorators";
|
|
13
13
|
/**
|
|
14
14
|
* @summary Step Validator
|
|
@@ -29,7 +29,7 @@ let StepValidator = class StepValidator extends Validator {
|
|
|
29
29
|
*
|
|
30
30
|
* @param {string} value
|
|
31
31
|
* @param {number} step
|
|
32
|
-
* @param {
|
|
32
|
+
* @param {StepValidatorOptions} options
|
|
33
33
|
*
|
|
34
34
|
* @return {string | undefined}
|
|
35
35
|
*
|
|
@@ -37,11 +37,11 @@ let StepValidator = class StepValidator extends Validator {
|
|
|
37
37
|
*
|
|
38
38
|
* @see Validator#hasErrors
|
|
39
39
|
*/
|
|
40
|
-
hasErrors(value,
|
|
40
|
+
hasErrors(value, options) {
|
|
41
41
|
if (typeof value === "undefined")
|
|
42
42
|
return;
|
|
43
|
-
return Number(value) % Number(step) !== 0
|
|
44
|
-
? this.getMessage(message || this.message, step)
|
|
43
|
+
return Number(value) % Number(options.step) !== 0
|
|
44
|
+
? this.getMessage(options.message || this.message, options.step)
|
|
45
45
|
: undefined;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
@@ -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
|
}
|