@decaf-ts/decorator-validation 1.5.1 → 1.5.2
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/package.json +15 -9
- package/dist/decorator-validation.bundle.min.js +0 -2
- package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -14
- package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
- package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -14
- package/lib/esm/index.d.ts +0 -42
- package/lib/esm/index.js +0 -42
- package/lib/esm/model/Model.d.ts +0 -138
- package/lib/esm/model/Model.js +0 -296
- package/lib/esm/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/esm/model/ModelErrorDefinition.js +0 -52
- package/lib/esm/model/Registry.d.ts +0 -59
- package/lib/esm/model/Registry.js +0 -73
- package/lib/esm/model/constants.d.ts +0 -56
- package/lib/esm/model/constants.js +0 -69
- package/lib/esm/model/construction.d.ts +0 -29
- package/lib/esm/model/construction.js +0 -63
- package/lib/esm/model/decorators.d.ts +0 -25
- package/lib/esm/model/decorators.js +0 -62
- package/lib/esm/model/index.d.ts +0 -9
- package/lib/esm/model/index.js +0 -9
- package/lib/esm/model/types.d.ts +0 -79
- package/lib/esm/model/types.js +0 -1
- package/lib/esm/model/utils.d.ts +0 -11
- package/lib/esm/model/utils.js +0 -25
- package/lib/esm/model/validation.d.ts +0 -14
- package/lib/esm/model/validation.js +0 -135
- package/lib/esm/utils/constants.d.ts +0 -26
- package/lib/esm/utils/constants.js +0 -27
- package/lib/esm/utils/dates.d.ts +0 -76
- package/lib/esm/utils/dates.js +0 -243
- package/lib/esm/utils/decorators.d.ts +0 -2
- package/lib/esm/utils/decorators.js +0 -18
- package/lib/esm/utils/hashing.d.ts +0 -52
- package/lib/esm/utils/hashing.js +0 -99
- package/lib/esm/utils/index.d.ts +0 -7
- package/lib/esm/utils/index.js +0 -7
- package/lib/esm/utils/registry.d.ts +0 -68
- package/lib/esm/utils/registry.js +0 -1
- package/lib/esm/utils/serialization.d.ts +0 -79
- package/lib/esm/utils/serialization.js +0 -88
- package/lib/esm/utils/strings.d.ts +0 -25
- package/lib/esm/utils/strings.js +0 -31
- package/lib/esm/validation/Validation.d.ts +0 -51
- package/lib/esm/validation/Validation.js +0 -71
- package/lib/esm/validation/Validators/DateValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/DateValidator.js +0 -54
- package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/EmailValidator.js +0 -50
- package/lib/esm/validation/Validators/ListValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/ListValidator.js +0 -65
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/MaxLengthValidator.js +0 -52
- package/lib/esm/validation/Validators/MaxValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/MaxValidator.js +0 -57
- package/lib/esm/validation/Validators/MinLengthValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/MinLengthValidator.js +0 -52
- package/lib/esm/validation/Validators/MinValidator.d.ts +0 -30
- package/lib/esm/validation/Validators/MinValidator.js +0 -57
- package/lib/esm/validation/Validators/PasswordValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/PasswordValidator.js +0 -50
- package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -39
- package/lib/esm/validation/Validators/PatternValidator.js +0 -70
- package/lib/esm/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/esm/validation/Validators/RequiredValidator.js +0 -57
- package/lib/esm/validation/Validators/StepValidator.d.ts +0 -31
- package/lib/esm/validation/Validators/StepValidator.js +0 -52
- package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/TypeValidator.js +0 -60
- package/lib/esm/validation/Validators/URLValidator.d.ts +0 -32
- package/lib/esm/validation/Validators/URLValidator.js +0 -46
- package/lib/esm/validation/Validators/Validator.d.ts +0 -43
- package/lib/esm/validation/Validators/Validator.js +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -80
- package/lib/esm/validation/Validators/constants.d.ts +0 -96
- package/lib/esm/validation/Validators/constants.js +0 -134
- package/lib/esm/validation/Validators/decorators.d.ts +0 -12
- package/lib/esm/validation/Validators/decorators.js +0 -25
- package/lib/esm/validation/Validators/index.d.ts +0 -52
- package/lib/esm/validation/Validators/index.js +0 -52
- package/lib/esm/validation/Validators/types.d.ts +0 -51
- package/lib/esm/validation/Validators/types.js +0 -1
- package/lib/esm/validation/decorators.d.ts +0 -178
- package/lib/esm/validation/decorators.js +0 -288
- package/lib/esm/validation/index.d.ts +0 -4
- package/lib/esm/validation/index.js +0 -4
- package/lib/esm/validation/types.d.ts +0 -46
- package/lib/esm/validation/types.js +0 -1
- package/lib/index.cjs +0 -59
- package/lib/index.d.ts +0 -42
- package/lib/model/Model.cjs +0 -300
- package/lib/model/Model.d.ts +0 -138
- package/lib/model/ModelErrorDefinition.cjs +0 -56
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/Registry.cjs +0 -78
- package/lib/model/Registry.d.ts +0 -59
- package/lib/model/constants.cjs +0 -72
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/construction.cjs +0 -68
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/decorators.cjs +0 -67
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/index.cjs +0 -25
- package/lib/model/index.d.ts +0 -9
- package/lib/model/types.cjs +0 -2
- package/lib/model/types.d.ts +0 -79
- package/lib/model/utils.cjs +0 -29
- package/lib/model/utils.d.ts +0 -11
- package/lib/model/validation.cjs +0 -138
- package/lib/model/validation.d.ts +0 -14
- package/lib/utils/constants.cjs +0 -30
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/dates.cjs +0 -251
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/decorators.cjs +0 -22
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/hashing.cjs +0 -106
- package/lib/utils/hashing.d.ts +0 -52
- package/lib/utils/index.cjs +0 -23
- package/lib/utils/index.d.ts +0 -7
- package/lib/utils/registry.cjs +0 -2
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/serialization.cjs +0 -93
- package/lib/utils/serialization.d.ts +0 -79
- package/lib/utils/strings.cjs +0 -35
- package/lib/utils/strings.d.ts +0 -25
- package/lib/validation/Validation.cjs +0 -75
- package/lib/validation/Validation.d.ts +0 -51
- package/lib/validation/Validators/DateValidator.cjs +0 -57
- package/lib/validation/Validators/DateValidator.d.ts +0 -30
- package/lib/validation/Validators/EmailValidator.cjs +0 -53
- package/lib/validation/Validators/EmailValidator.d.ts +0 -27
- package/lib/validation/Validators/ListValidator.cjs +0 -68
- package/lib/validation/Validators/ListValidator.d.ts +0 -30
- package/lib/validation/Validators/MaxLengthValidator.cjs +0 -55
- package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -31
- package/lib/validation/Validators/MaxValidator.cjs +0 -60
- package/lib/validation/Validators/MaxValidator.d.ts +0 -30
- package/lib/validation/Validators/MinLengthValidator.cjs +0 -55
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -31
- package/lib/validation/Validators/MinValidator.cjs +0 -60
- package/lib/validation/Validators/MinValidator.d.ts +0 -30
- package/lib/validation/Validators/PasswordValidator.cjs +0 -53
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -27
- package/lib/validation/Validators/PatternValidator.cjs +0 -73
- package/lib/validation/Validators/PatternValidator.d.ts +0 -39
- package/lib/validation/Validators/RequiredValidator.cjs +0 -60
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -27
- package/lib/validation/Validators/StepValidator.cjs +0 -55
- package/lib/validation/Validators/StepValidator.d.ts +0 -31
- package/lib/validation/Validators/TypeValidator.cjs +0 -63
- package/lib/validation/Validators/TypeValidator.d.ts +0 -29
- package/lib/validation/Validators/URLValidator.cjs +0 -49
- package/lib/validation/Validators/URLValidator.d.ts +0 -32
- package/lib/validation/Validators/Validator.cjs +0 -51
- package/lib/validation/Validators/Validator.d.ts +0 -43
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -85
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/constants.cjs +0 -137
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/Validators/decorators.cjs +0 -28
- package/lib/validation/Validators/index.cjs +0 -69
- package/lib/validation/Validators/types.cjs +0 -2
- package/lib/validation/decorators.cjs +0 -304
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/index.cjs +0 -20
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.cjs +0 -2
- package/lib/validation/types.d.ts +0 -46
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Minimum Length Validator
|
|
15
|
-
* @description Validates strings and Arrays on their minimum length
|
|
16
|
-
*
|
|
17
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
18
|
-
*
|
|
19
|
-
* @class MinLengthValidator
|
|
20
|
-
* @extends Validator
|
|
21
|
-
*
|
|
22
|
-
* @category Validators
|
|
23
|
-
*/
|
|
24
|
-
let MinLengthValidator = class MinLengthValidator extends Validator {
|
|
25
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
|
|
26
|
-
super(message, String.name, Array.name);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @param {string | Array} value
|
|
31
|
-
* @param {MinLengthValidatorOptions} options
|
|
32
|
-
*
|
|
33
|
-
* @return {string | undefined}
|
|
34
|
-
*
|
|
35
|
-
* @memberOf MinLengthValidator
|
|
36
|
-
* @override
|
|
37
|
-
*
|
|
38
|
-
* @see Validator#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
hasErrors(value, options) {
|
|
41
|
-
if (typeof value === "undefined")
|
|
42
|
-
return;
|
|
43
|
-
return value.length < options.minLength
|
|
44
|
-
? this.getMessage(options.message || this.message, options.minLength)
|
|
45
|
-
: undefined;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
MinLengthValidator = __decorate([
|
|
49
|
-
validator(ValidationKeys.MIN_LENGTH),
|
|
50
|
-
__metadata("design:paramtypes", [String])
|
|
51
|
-
], MinLengthValidator);
|
|
52
|
-
export { MinLengthValidator };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
-
export interface MinValidatorOptions extends ValidatorOptions {
|
|
3
|
-
min: number | Date | string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* @summary Min Validator
|
|
7
|
-
*
|
|
8
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
9
|
-
*
|
|
10
|
-
* @class MinValidator
|
|
11
|
-
* @extends Validator
|
|
12
|
-
*
|
|
13
|
-
* @category Validators
|
|
14
|
-
*/
|
|
15
|
-
export declare class MinValidator extends Validator<MinValidatorOptions> {
|
|
16
|
-
constructor(message?: string);
|
|
17
|
-
/**
|
|
18
|
-
* @summary Validates Model
|
|
19
|
-
*
|
|
20
|
-
* @param {string} value
|
|
21
|
-
* @param {MaxValidatorOptions} options
|
|
22
|
-
*
|
|
23
|
-
* @return {string | undefined}
|
|
24
|
-
*
|
|
25
|
-
* @override
|
|
26
|
-
*
|
|
27
|
-
* @see Validator#hasErrors
|
|
28
|
-
*/
|
|
29
|
-
hasErrors(value: number | Date | string, options: MinValidatorOptions): string | undefined;
|
|
30
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Min Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
17
|
-
*
|
|
18
|
-
* @class MinValidator
|
|
19
|
-
* @extends Validator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let MinValidator = class MinValidator extends Validator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.MIN) {
|
|
25
|
-
super(message, "number", "Date", "string");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates Model
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {MaxValidatorOptions} options
|
|
32
|
-
*
|
|
33
|
-
* @return {string | undefined}
|
|
34
|
-
*
|
|
35
|
-
* @override
|
|
36
|
-
*
|
|
37
|
-
* @see Validator#hasErrors
|
|
38
|
-
*/
|
|
39
|
-
hasErrors(value, options) {
|
|
40
|
-
if (typeof value === "undefined")
|
|
41
|
-
return;
|
|
42
|
-
let { min } = options;
|
|
43
|
-
if (value instanceof Date && !(min instanceof Date)) {
|
|
44
|
-
min = new Date(min);
|
|
45
|
-
if (Number.isNaN(min.getDate()))
|
|
46
|
-
throw new Error("Invalid Min param defined");
|
|
47
|
-
}
|
|
48
|
-
return value < min
|
|
49
|
-
? this.getMessage(options.message || this.message, min)
|
|
50
|
-
: undefined;
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
MinValidator = __decorate([
|
|
54
|
-
validator(ValidationKeys.MIN),
|
|
55
|
-
__metadata("design:paramtypes", [String])
|
|
56
|
-
], MinValidator);
|
|
57
|
-
export { MinValidator };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Handles Password Validation
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [errorMessage] defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
6
|
-
*
|
|
7
|
-
* @class PasswordValidator
|
|
8
|
-
* @extends PatternValidator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class PasswordValidator extends PatternValidator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
19
|
-
*
|
|
20
|
-
* @return {string | undefined}
|
|
21
|
-
*
|
|
22
|
-
* @override
|
|
23
|
-
*
|
|
24
|
-
* @see PatternValidator#hasErrors
|
|
25
|
-
*/
|
|
26
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
27
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { PatternValidator } from "./PatternValidator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Handles Password Validation
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [errorMessage] defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
17
|
-
*
|
|
18
|
-
* @class PasswordValidator
|
|
19
|
-
* @extends PatternValidator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let PasswordValidator = class PasswordValidator extends PatternValidator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.PASSWORD) {
|
|
25
|
-
super(message);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
32
|
-
*
|
|
33
|
-
* @return {string | undefined}
|
|
34
|
-
*
|
|
35
|
-
* @override
|
|
36
|
-
*
|
|
37
|
-
* @see PatternValidator#hasErrors
|
|
38
|
-
*/
|
|
39
|
-
hasErrors(value, options = {}) {
|
|
40
|
-
return super.hasErrors(value, {
|
|
41
|
-
...options,
|
|
42
|
-
message: options.message || this.message,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
PasswordValidator = __decorate([
|
|
47
|
-
validator(ValidationKeys.PASSWORD),
|
|
48
|
-
__metadata("design:paramtypes", [Object])
|
|
49
|
-
], PasswordValidator);
|
|
50
|
-
export { PasswordValidator };
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
-
export interface PatternValidatorOptions extends ValidatorOptions {
|
|
3
|
-
pattern?: RegExp | string;
|
|
4
|
-
}
|
|
5
|
-
export declare const regexpParser: RegExp;
|
|
6
|
-
/**
|
|
7
|
-
* @summary Pattern Validator
|
|
8
|
-
*
|
|
9
|
-
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
10
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
11
|
-
*
|
|
12
|
-
* @class PatternValidator
|
|
13
|
-
* @extends Validator
|
|
14
|
-
*
|
|
15
|
-
* @category Validators
|
|
16
|
-
*/
|
|
17
|
-
export declare class PatternValidator extends Validator<PatternValidatorOptions> {
|
|
18
|
-
constructor(message?: string);
|
|
19
|
-
/**
|
|
20
|
-
* @summary parses and validates a pattern
|
|
21
|
-
*
|
|
22
|
-
* @param {string} pattern
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
private getPattern;
|
|
26
|
-
/**
|
|
27
|
-
* @summary Validates a Model
|
|
28
|
-
*
|
|
29
|
-
* @param {string} value
|
|
30
|
-
* @param {PatternValidatorOptions} options
|
|
31
|
-
*
|
|
32
|
-
* @return {string | undefined}
|
|
33
|
-
*
|
|
34
|
-
* @override
|
|
35
|
-
*
|
|
36
|
-
* @see Validator#hasErrors
|
|
37
|
-
*/
|
|
38
|
-
hasErrors(value: string, options: PatternValidatorOptions): string | undefined;
|
|
39
|
-
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
export const regexpParser = new RegExp("^/(.+)/([gimus]*)$");
|
|
14
|
-
/**
|
|
15
|
-
* @summary Pattern Validator
|
|
16
|
-
*
|
|
17
|
-
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
18
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
19
|
-
*
|
|
20
|
-
* @class PatternValidator
|
|
21
|
-
* @extends Validator
|
|
22
|
-
*
|
|
23
|
-
* @category Validators
|
|
24
|
-
*/
|
|
25
|
-
let PatternValidator = class PatternValidator extends Validator {
|
|
26
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.PATTERN) {
|
|
27
|
-
super(message, "string");
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @summary parses and validates a pattern
|
|
31
|
-
*
|
|
32
|
-
* @param {string} pattern
|
|
33
|
-
* @private
|
|
34
|
-
*/
|
|
35
|
-
getPattern(pattern) {
|
|
36
|
-
if (!regexpParser.test(pattern))
|
|
37
|
-
return new RegExp(pattern);
|
|
38
|
-
const match = pattern.match(regexpParser);
|
|
39
|
-
return new RegExp(match[1], match[2]);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @summary Validates a Model
|
|
43
|
-
*
|
|
44
|
-
* @param {string} value
|
|
45
|
-
* @param {PatternValidatorOptions} options
|
|
46
|
-
*
|
|
47
|
-
* @return {string | undefined}
|
|
48
|
-
*
|
|
49
|
-
* @override
|
|
50
|
-
*
|
|
51
|
-
* @see Validator#hasErrors
|
|
52
|
-
*/
|
|
53
|
-
hasErrors(value, options) {
|
|
54
|
-
if (!value)
|
|
55
|
-
return;
|
|
56
|
-
let { pattern } = options;
|
|
57
|
-
if (!pattern)
|
|
58
|
-
throw new Error("Missing Pattern");
|
|
59
|
-
pattern = typeof pattern === "string" ? this.getPattern(pattern) : pattern;
|
|
60
|
-
pattern.lastIndex = 0; // resets pattern position for repeat validation requests
|
|
61
|
-
return !pattern.test(value)
|
|
62
|
-
? this.getMessage(options.message || this.message)
|
|
63
|
-
: undefined;
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
PatternValidator = __decorate([
|
|
67
|
-
validator(ValidationKeys.PATTERN),
|
|
68
|
-
__metadata("design:paramtypes", [String])
|
|
69
|
-
], PatternValidator);
|
|
70
|
-
export { PatternValidator };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Required Validator
|
|
4
|
-
*
|
|
5
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
6
|
-
*
|
|
7
|
-
* @class RequiredValidator
|
|
8
|
-
* @extends Validator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class RequiredValidator extends Validator {
|
|
13
|
-
constructor(message?: string);
|
|
14
|
-
/**
|
|
15
|
-
* @summary Validates a model
|
|
16
|
-
*
|
|
17
|
-
* @param {string} value
|
|
18
|
-
* @param {ValidatorOptions} [options={}]
|
|
19
|
-
*
|
|
20
|
-
* @return {string | undefined}
|
|
21
|
-
*
|
|
22
|
-
* @override
|
|
23
|
-
*
|
|
24
|
-
* @see Validator#hasErrors
|
|
25
|
-
*/
|
|
26
|
-
hasErrors(value: any, options?: ValidatorOptions): string | undefined;
|
|
27
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Required Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
17
|
-
*
|
|
18
|
-
* @class RequiredValidator
|
|
19
|
-
* @extends Validator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let RequiredValidator = class RequiredValidator extends Validator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
|
|
25
|
-
super(message);
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {ValidatorOptions} [options={}]
|
|
32
|
-
*
|
|
33
|
-
* @return {string | undefined}
|
|
34
|
-
*
|
|
35
|
-
* @override
|
|
36
|
-
*
|
|
37
|
-
* @see Validator#hasErrors
|
|
38
|
-
*/
|
|
39
|
-
hasErrors(value, options = {}) {
|
|
40
|
-
switch (typeof value) {
|
|
41
|
-
case "boolean":
|
|
42
|
-
case "number":
|
|
43
|
-
return typeof value === "undefined"
|
|
44
|
-
? this.getMessage(options.message || this.message)
|
|
45
|
-
: undefined;
|
|
46
|
-
default:
|
|
47
|
-
return !value
|
|
48
|
-
? this.getMessage(options.message || this.message)
|
|
49
|
-
: undefined;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
RequiredValidator = __decorate([
|
|
54
|
-
validator(ValidationKeys.REQUIRED),
|
|
55
|
-
__metadata("design:paramtypes", [String])
|
|
56
|
-
], RequiredValidator);
|
|
57
|
-
export { RequiredValidator };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
-
export interface StepValidatorOptions extends ValidatorOptions {
|
|
3
|
-
step: number | string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* @summary Step Validator
|
|
7
|
-
*
|
|
8
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
9
|
-
*
|
|
10
|
-
* @class StepValidator
|
|
11
|
-
* @extends Validator
|
|
12
|
-
*
|
|
13
|
-
* @category Validators
|
|
14
|
-
*/
|
|
15
|
-
export declare class StepValidator extends Validator<StepValidatorOptions> {
|
|
16
|
-
constructor(message?: string);
|
|
17
|
-
/**
|
|
18
|
-
* @summary Validates a model
|
|
19
|
-
*
|
|
20
|
-
* @param {string} value
|
|
21
|
-
* @param {number} step
|
|
22
|
-
* @param {StepValidatorOptions} options
|
|
23
|
-
*
|
|
24
|
-
* @return {string | undefined}
|
|
25
|
-
*
|
|
26
|
-
* @override
|
|
27
|
-
*
|
|
28
|
-
* @see Validator#hasErrors
|
|
29
|
-
*/
|
|
30
|
-
hasErrors(value: number | string, options: StepValidatorOptions): string | undefined;
|
|
31
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary Step Validator
|
|
15
|
-
*
|
|
16
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
17
|
-
*
|
|
18
|
-
* @class StepValidator
|
|
19
|
-
* @extends Validator
|
|
20
|
-
*
|
|
21
|
-
* @category Validators
|
|
22
|
-
*/
|
|
23
|
-
let StepValidator = class StepValidator extends Validator {
|
|
24
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.STEP) {
|
|
25
|
-
super(message, "number", "string");
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary Validates a model
|
|
29
|
-
*
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {number} step
|
|
32
|
-
* @param {StepValidatorOptions} options
|
|
33
|
-
*
|
|
34
|
-
* @return {string | undefined}
|
|
35
|
-
*
|
|
36
|
-
* @override
|
|
37
|
-
*
|
|
38
|
-
* @see Validator#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
hasErrors(value, options) {
|
|
41
|
-
if (typeof value === "undefined")
|
|
42
|
-
return;
|
|
43
|
-
return Number(value) % Number(options.step) !== 0
|
|
44
|
-
? this.getMessage(options.message || this.message, options.step)
|
|
45
|
-
: undefined;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
StepValidator = __decorate([
|
|
49
|
-
validator(ValidationKeys.STEP),
|
|
50
|
-
__metadata("design:paramtypes", [String])
|
|
51
|
-
], StepValidator);
|
|
52
|
-
export { StepValidator };
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator, ValidatorOptions } from "./Validator";
|
|
2
|
-
export interface TypeValidatorOptions extends ValidatorOptions {
|
|
3
|
-
types: string | string[] | {
|
|
4
|
-
name: string;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
/**
|
|
8
|
-
* @summary Required Validator
|
|
9
|
-
*
|
|
10
|
-
* @class RequiredValidator
|
|
11
|
-
* @extends Validator
|
|
12
|
-
*
|
|
13
|
-
* @category Validators
|
|
14
|
-
*/
|
|
15
|
-
export declare class TypeValidator extends Validator<TypeValidatorOptions> {
|
|
16
|
-
constructor(message?: string);
|
|
17
|
-
/**
|
|
18
|
-
* @summary Validates a model
|
|
19
|
-
* @param {string} value
|
|
20
|
-
* @param {TypeValidatorOptions} options
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: any, options: TypeValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Validator } from "./Validator";
|
|
11
|
-
import { DEFAULT_ERROR_MESSAGES, ValidationKeys } from "./constants";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
import { Validation } from "../Validation";
|
|
14
|
-
import { ModelKeys } from "../../utils/constants";
|
|
15
|
-
import { Reflection } from "@decaf-ts/reflection";
|
|
16
|
-
/**
|
|
17
|
-
* @summary Required Validator
|
|
18
|
-
*
|
|
19
|
-
* @class RequiredValidator
|
|
20
|
-
* @extends Validator
|
|
21
|
-
*
|
|
22
|
-
* @category Validators
|
|
23
|
-
*/
|
|
24
|
-
let TypeValidator = class TypeValidator extends Validator {
|
|
25
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.TYPE) {
|
|
26
|
-
super(message);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* @summary Validates a model
|
|
30
|
-
* @param {string} value
|
|
31
|
-
* @param {TypeValidatorOptions} options
|
|
32
|
-
*
|
|
33
|
-
* @return {string | undefined}
|
|
34
|
-
*
|
|
35
|
-
* @override
|
|
36
|
-
*
|
|
37
|
-
* @see Validator#hasErrors
|
|
38
|
-
*/
|
|
39
|
-
hasErrors(value, options) {
|
|
40
|
-
if (value === undefined)
|
|
41
|
-
return; // Don't try and enforce type if undefined
|
|
42
|
-
const { types, message } = options;
|
|
43
|
-
if (!Reflection.evaluateDesignTypes(value, types))
|
|
44
|
-
return this.getMessage(message || this.message, typeof types === "string"
|
|
45
|
-
? types
|
|
46
|
-
: Array.isArray(types)
|
|
47
|
-
? types.join(", ")
|
|
48
|
-
: types.name, typeof value);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
TypeValidator = __decorate([
|
|
52
|
-
validator(ValidationKeys.TYPE),
|
|
53
|
-
__metadata("design:paramtypes", [String])
|
|
54
|
-
], TypeValidator);
|
|
55
|
-
export { TypeValidator };
|
|
56
|
-
Validation.register({
|
|
57
|
-
validator: TypeValidator,
|
|
58
|
-
validationKey: ModelKeys.TYPE,
|
|
59
|
-
save: false,
|
|
60
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* @summary URL Validator
|
|
10
|
-
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
11
|
-
*
|
|
12
|
-
* @class URLValidator
|
|
13
|
-
* @extends PatternValidator
|
|
14
|
-
*
|
|
15
|
-
* @category Validators
|
|
16
|
-
*/
|
|
17
|
-
export declare class URLValidator extends PatternValidator {
|
|
18
|
-
constructor(message?: string);
|
|
19
|
-
/**
|
|
20
|
-
* @summary Validates a model
|
|
21
|
-
*
|
|
22
|
-
* @param {string} value
|
|
23
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
24
|
-
*
|
|
25
|
-
* @return {string | undefined}
|
|
26
|
-
*
|
|
27
|
-
* @override
|
|
28
|
-
*
|
|
29
|
-
* @see Validator#hasErrors
|
|
30
|
-
*/
|
|
31
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
32
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { ValidationKeys, DEFAULT_ERROR_MESSAGES, DEFAULT_PATTERNS, } from "./constants";
|
|
11
|
-
import { PatternValidator } from "./PatternValidator";
|
|
12
|
-
import { validator } from "./decorators";
|
|
13
|
-
/**
|
|
14
|
-
* @summary URL Validator
|
|
15
|
-
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
16
|
-
*
|
|
17
|
-
* @class URLValidator
|
|
18
|
-
* @extends PatternValidator
|
|
19
|
-
*
|
|
20
|
-
* @category Validators
|
|
21
|
-
*/
|
|
22
|
-
let URLValidator = class URLValidator extends PatternValidator {
|
|
23
|
-
constructor(message = DEFAULT_ERROR_MESSAGES.URL) {
|
|
24
|
-
super(message);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @summary Validates a model
|
|
28
|
-
*
|
|
29
|
-
* @param {string} value
|
|
30
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
31
|
-
*
|
|
32
|
-
* @return {string | undefined}
|
|
33
|
-
*
|
|
34
|
-
* @override
|
|
35
|
-
*
|
|
36
|
-
* @see Validator#hasErrors
|
|
37
|
-
*/
|
|
38
|
-
hasErrors(value, options = {}) {
|
|
39
|
-
return super.hasErrors(value, { ...options, pattern: options.pattern || DEFAULT_PATTERNS.URL });
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
URLValidator = __decorate([
|
|
43
|
-
validator(ValidationKeys.URL),
|
|
44
|
-
__metadata("design:paramtypes", [String])
|
|
45
|
-
], URLValidator);
|
|
46
|
-
export { URLValidator };
|