@decaf-ts/decorator-validation 1.5.8 → 1.5.10
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.js +1 -1
- package/dist/decorator-validation.js.LICENSE.txt +0 -0
- package/dist/esm/decorator-validation.js +1 -1
- package/dist/esm/decorator-validation.js.LICENSE.txt +0 -0
- package/{lib/esm → dist/types}/index.d.ts +1 -1
- package/{lib/esm → dist/types}/model/Model.d.ts +1 -0
- package/{lib/esm → dist/types}/model/ModelErrorDefinition.d.ts +0 -0
- package/{lib/esm → dist/types}/model/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/model/construction.d.ts +0 -0
- package/{lib/esm → dist/types}/model/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/model/index.d.ts +0 -1
- package/{lib/esm → dist/types}/model/types.d.ts +0 -0
- package/{lib/esm → dist/types}/model/validation.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/dates.d.ts +0 -0
- package/{lib/esm → dist/types}/utils/decorators.d.ts +0 -0
- package/{lib → dist/types}/utils/hashing.d.ts +0 -14
- package/{lib → dist/types}/utils/index.d.ts +1 -0
- package/{lib/esm → dist/types}/utils/registry.d.ts +0 -0
- package/{lib → dist/types}/utils/serialization.d.ts +4 -30
- package/{lib/esm → dist/types}/utils/strings.d.ts +0 -0
- package/dist/types/utils/types.d.ts +29 -0
- package/{lib → dist/types}/validation/Validation.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/DateValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/EmailValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/ListValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/MaxLengthValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MaxValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MinLengthValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/MinValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/PasswordValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/PatternValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/RequiredValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/StepValidator.d.ts +1 -1
- package/{lib → dist/types}/validation/Validators/TypeValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/URLValidator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/Validator.d.ts +1 -1
- package/{lib/esm → dist/types}/validation/Validators/ValidatorRegistry.d.ts +2 -2
- package/{lib/esm → dist/types}/validation/Validators/constants.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/Validators/decorators.d.ts +0 -0
- package/dist/types/validation/Validators/index.d.ts +17 -0
- package/{lib/esm → dist/types}/validation/decorators.d.ts +0 -0
- package/{lib/esm → dist/types}/validation/index.d.ts +0 -0
- package/{lib/validation/Validators → dist/types/validation}/types.d.ts +49 -3
- package/lib/esm/index.js +3 -1
- package/lib/esm/model/Model.js +8 -1
- package/lib/esm/model/ModelErrorDefinition.js +2 -0
- package/lib/esm/model/constants.js +2 -0
- package/lib/esm/model/construction.js +2 -0
- package/lib/esm/model/decorators.js +2 -0
- package/lib/esm/model/index.js +2 -1
- package/lib/esm/model/types.js +2 -0
- package/lib/esm/model/validation.js +2 -0
- package/lib/esm/utils/constants.js +2 -0
- package/lib/esm/utils/dates.js +2 -0
- package/lib/esm/utils/decorators.js +2 -0
- package/lib/esm/utils/hashing.js +2 -17
- package/lib/esm/utils/index.js +3 -0
- package/lib/esm/utils/registry.js +2 -0
- package/lib/esm/utils/serialization.js +4 -1
- package/lib/esm/utils/strings.js +2 -0
- package/lib/esm/utils/types.js +3 -0
- package/lib/esm/validation/Validation.js +2 -0
- package/lib/esm/validation/Validators/DateValidator.js +2 -0
- package/lib/esm/validation/Validators/EmailValidator.js +2 -0
- package/lib/esm/validation/Validators/ListValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MaxValidator.js +2 -0
- package/lib/esm/validation/Validators/MinLengthValidator.js +2 -0
- package/lib/esm/validation/Validators/MinValidator.js +2 -0
- package/lib/esm/validation/Validators/PasswordValidator.js +2 -0
- package/lib/esm/validation/Validators/PatternValidator.js +2 -0
- package/lib/esm/validation/Validators/RequiredValidator.js +2 -0
- package/lib/esm/validation/Validators/StepValidator.js +2 -0
- package/lib/esm/validation/Validators/TypeValidator.js +2 -0
- package/lib/esm/validation/Validators/URLValidator.js +2 -0
- package/lib/esm/validation/Validators/Validator.js +2 -0
- package/lib/esm/validation/Validators/ValidatorRegistry.js +2 -0
- package/lib/esm/validation/Validators/constants.js +2 -0
- package/lib/esm/validation/Validators/decorators.js +2 -0
- package/lib/esm/validation/Validators/index.js +2 -35
- package/lib/esm/validation/decorators.js +2 -0
- package/lib/esm/validation/index.js +2 -0
- package/lib/esm/validation/types.js +2 -0
- package/lib/index.cjs +61 -0
- package/lib/model/Model.cjs +397 -0
- package/lib/model/ModelErrorDefinition.cjs +58 -0
- package/lib/model/constants.cjs +74 -0
- package/lib/model/construction.cjs +70 -0
- package/lib/model/decorators.cjs +69 -0
- package/lib/model/index.cjs +25 -0
- package/lib/model/types.cjs +4 -0
- package/lib/model/validation.cjs +140 -0
- package/lib/utils/constants.cjs +32 -0
- package/lib/utils/dates.cjs +253 -0
- package/lib/utils/decorators.cjs +24 -0
- package/lib/utils/hashing.cjs +90 -0
- package/lib/utils/index.cjs +26 -0
- package/lib/utils/registry.cjs +4 -0
- package/lib/utils/serialization.cjs +96 -0
- package/lib/utils/strings.cjs +37 -0
- package/lib/utils/types.cjs +4 -0
- package/lib/validation/Validation.cjs +77 -0
- package/lib/validation/Validators/DateValidator.cjs +59 -0
- package/lib/validation/Validators/EmailValidator.cjs +55 -0
- package/lib/validation/Validators/ListValidator.cjs +72 -0
- package/lib/validation/Validators/MaxLengthValidator.cjs +57 -0
- package/lib/validation/Validators/MaxValidator.cjs +62 -0
- package/lib/validation/Validators/MinLengthValidator.cjs +57 -0
- package/lib/validation/Validators/MinValidator.cjs +62 -0
- package/lib/validation/Validators/PasswordValidator.cjs +55 -0
- package/lib/validation/Validators/PatternValidator.cjs +75 -0
- package/lib/validation/Validators/RequiredValidator.cjs +62 -0
- package/lib/validation/Validators/StepValidator.cjs +57 -0
- package/lib/validation/Validators/TypeValidator.cjs +65 -0
- package/lib/validation/Validators/URLValidator.cjs +54 -0
- package/lib/validation/Validators/Validator.cjs +53 -0
- package/lib/validation/Validators/ValidatorRegistry.cjs +87 -0
- package/lib/validation/Validators/constants.cjs +139 -0
- package/lib/validation/Validators/decorators.cjs +30 -0
- package/lib/validation/Validators/index.cjs +35 -0
- package/lib/validation/decorators.cjs +306 -0
- package/lib/validation/{index.js → index.cjs} +6 -4
- package/lib/validation/types.cjs +4 -0
- package/package.json +2 -2
- package/lib/esm/model/utils.d.ts +0 -2
- package/lib/esm/model/utils.js +0 -8
- package/lib/esm/utils/hashing.d.ts +0 -52
- package/lib/esm/utils/index.d.ts +0 -7
- package/lib/esm/utils/serialization.d.ts +0 -79
- package/lib/esm/validation/Validation.d.ts +0 -51
- package/lib/esm/validation/Validators/DateValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/ListValidator.d.ts +0 -28
- package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -29
- package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -37
- package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -25
- package/lib/esm/validation/Validators/index.d.ts +0 -52
- package/lib/esm/validation/Validators/types.js +0 -1
- package/lib/esm/validation/types.d.ts +0 -46
- package/lib/index.d.ts +0 -42
- package/lib/index.js +0 -59
- package/lib/model/Model.d.ts +0 -203
- package/lib/model/Model.js +0 -389
- package/lib/model/ModelErrorDefinition.d.ts +0 -22
- package/lib/model/ModelErrorDefinition.js +0 -56
- package/lib/model/constants.d.ts +0 -56
- package/lib/model/constants.js +0 -72
- package/lib/model/construction.d.ts +0 -29
- package/lib/model/construction.js +0 -68
- package/lib/model/decorators.d.ts +0 -25
- package/lib/model/decorators.js +0 -67
- package/lib/model/index.d.ts +0 -8
- package/lib/model/index.js +0 -24
- package/lib/model/types.d.ts +0 -79
- package/lib/model/types.js +0 -2
- package/lib/model/utils.d.ts +0 -2
- package/lib/model/utils.js +0 -11
- package/lib/model/validation.d.ts +0 -14
- package/lib/model/validation.js +0 -138
- package/lib/utils/constants.d.ts +0 -26
- package/lib/utils/constants.js +0 -30
- package/lib/utils/dates.d.ts +0 -76
- package/lib/utils/dates.js +0 -251
- package/lib/utils/decorators.d.ts +0 -2
- package/lib/utils/decorators.js +0 -22
- package/lib/utils/hashing.js +0 -106
- package/lib/utils/index.js +0 -23
- package/lib/utils/registry.d.ts +0 -68
- package/lib/utils/registry.js +0 -2
- package/lib/utils/serialization.js +0 -93
- package/lib/utils/strings.d.ts +0 -25
- package/lib/utils/strings.js +0 -35
- package/lib/validation/Validation.js +0 -75
- package/lib/validation/Validators/DateValidator.js +0 -57
- package/lib/validation/Validators/EmailValidator.js +0 -53
- package/lib/validation/Validators/ListValidator.js +0 -70
- package/lib/validation/Validators/MaxLengthValidator.js +0 -55
- package/lib/validation/Validators/MaxValidator.d.ts +0 -28
- package/lib/validation/Validators/MaxValidator.js +0 -60
- package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
- package/lib/validation/Validators/MinLengthValidator.js +0 -55
- package/lib/validation/Validators/MinValidator.d.ts +0 -28
- package/lib/validation/Validators/MinValidator.js +0 -60
- package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
- package/lib/validation/Validators/PasswordValidator.js +0 -53
- package/lib/validation/Validators/PatternValidator.js +0 -73
- package/lib/validation/Validators/RequiredValidator.d.ts +0 -28
- package/lib/validation/Validators/RequiredValidator.js +0 -60
- package/lib/validation/Validators/StepValidator.d.ts +0 -29
- package/lib/validation/Validators/StepValidator.js +0 -55
- package/lib/validation/Validators/TypeValidator.js +0 -63
- package/lib/validation/Validators/URLValidator.d.ts +0 -27
- package/lib/validation/Validators/URLValidator.js +0 -52
- package/lib/validation/Validators/Validator.d.ts +0 -41
- package/lib/validation/Validators/Validator.js +0 -51
- package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
- package/lib/validation/Validators/ValidatorRegistry.js +0 -85
- package/lib/validation/Validators/constants.d.ts +0 -96
- package/lib/validation/Validators/constants.js +0 -137
- package/lib/validation/Validators/decorators.d.ts +0 -12
- package/lib/validation/Validators/decorators.js +0 -28
- package/lib/validation/Validators/index.d.ts +0 -52
- package/lib/validation/Validators/index.js +0 -69
- package/lib/validation/Validators/types.js +0 -2
- package/lib/validation/decorators.d.ts +0 -178
- package/lib/validation/decorators.js +0 -304
- package/lib/validation/index.d.ts +0 -4
- package/lib/validation/types.d.ts +0 -46
- package/lib/validation/types.js +0 -2
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.PatternValidator = exports.regexpParser = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
exports.regexpParser = new RegExp("^/(.+)/([gimus]*)$");
|
|
17
|
-
/**
|
|
18
|
-
* @summary Pattern Validator
|
|
19
|
-
*
|
|
20
|
-
* @param {string} [key] defaults to {@link ValidationKeys#PATTERN}
|
|
21
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
22
|
-
*
|
|
23
|
-
* @class PatternValidator
|
|
24
|
-
* @extends Validator
|
|
25
|
-
*
|
|
26
|
-
* @category Validators
|
|
27
|
-
*/
|
|
28
|
-
let PatternValidator = class PatternValidator extends Validator_1.Validator {
|
|
29
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.PATTERN) {
|
|
30
|
-
super(message, "string");
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* @summary parses and validates a pattern
|
|
34
|
-
*
|
|
35
|
-
* @param {string} pattern
|
|
36
|
-
* @private
|
|
37
|
-
*/
|
|
38
|
-
getPattern(pattern) {
|
|
39
|
-
if (!exports.regexpParser.test(pattern))
|
|
40
|
-
return new RegExp(pattern);
|
|
41
|
-
const match = pattern.match(exports.regexpParser);
|
|
42
|
-
return new RegExp(match[1], match[2]);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @summary Validates a Model
|
|
46
|
-
*
|
|
47
|
-
* @param {string} value
|
|
48
|
-
* @param {PatternValidatorOptions} options
|
|
49
|
-
*
|
|
50
|
-
* @return {string | undefined}
|
|
51
|
-
*
|
|
52
|
-
* @override
|
|
53
|
-
*
|
|
54
|
-
* @see Validator#hasErrors
|
|
55
|
-
*/
|
|
56
|
-
hasErrors(value, options) {
|
|
57
|
-
if (!value)
|
|
58
|
-
return;
|
|
59
|
-
let { pattern } = options;
|
|
60
|
-
if (!pattern)
|
|
61
|
-
throw new Error("Missing Pattern");
|
|
62
|
-
pattern = typeof pattern === "string" ? this.getPattern(pattern) : pattern;
|
|
63
|
-
pattern.lastIndex = 0; // resets pattern position for repeat validation requests
|
|
64
|
-
return !pattern.test(value)
|
|
65
|
-
? this.getMessage(options.message || this.message)
|
|
66
|
-
: undefined;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
exports.PatternValidator = PatternValidator;
|
|
70
|
-
exports.PatternValidator = PatternValidator = __decorate([
|
|
71
|
-
(0, decorators_1.validator)(constants_1.ValidationKeys.PATTERN),
|
|
72
|
-
__metadata("design:paramtypes", [String])
|
|
73
|
-
], PatternValidator);
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { ValidatorOptions } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Required Validator
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
7
|
-
*
|
|
8
|
-
* @class RequiredValidator
|
|
9
|
-
* @extends Validator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class RequiredValidator extends Validator {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {ValidatorOptions} [options={}]
|
|
20
|
-
*
|
|
21
|
-
* @return {string | undefined}
|
|
22
|
-
*
|
|
23
|
-
* @override
|
|
24
|
-
*
|
|
25
|
-
* @see Validator#hasErrors
|
|
26
|
-
*/
|
|
27
|
-
hasErrors(value: any, options?: ValidatorOptions): string | undefined;
|
|
28
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RequiredValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
/**
|
|
17
|
-
* @summary Required Validator
|
|
18
|
-
*
|
|
19
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
20
|
-
*
|
|
21
|
-
* @class RequiredValidator
|
|
22
|
-
* @extends Validator
|
|
23
|
-
*
|
|
24
|
-
* @category Validators
|
|
25
|
-
*/
|
|
26
|
-
let RequiredValidator = class RequiredValidator extends Validator_1.Validator {
|
|
27
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.REQUIRED) {
|
|
28
|
-
super(message);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @summary Validates a model
|
|
32
|
-
*
|
|
33
|
-
* @param {string} value
|
|
34
|
-
* @param {ValidatorOptions} [options={}]
|
|
35
|
-
*
|
|
36
|
-
* @return {string | undefined}
|
|
37
|
-
*
|
|
38
|
-
* @override
|
|
39
|
-
*
|
|
40
|
-
* @see Validator#hasErrors
|
|
41
|
-
*/
|
|
42
|
-
hasErrors(value, options = {}) {
|
|
43
|
-
switch (typeof value) {
|
|
44
|
-
case "boolean":
|
|
45
|
-
case "number":
|
|
46
|
-
return typeof value === "undefined"
|
|
47
|
-
? this.getMessage(options.message || this.message)
|
|
48
|
-
: undefined;
|
|
49
|
-
default:
|
|
50
|
-
return !value
|
|
51
|
-
? this.getMessage(options.message || this.message)
|
|
52
|
-
: undefined;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.RequiredValidator = RequiredValidator;
|
|
57
|
-
exports.RequiredValidator = RequiredValidator = __decorate([
|
|
58
|
-
(0, decorators_1.validator)(constants_1.ValidationKeys.REQUIRED),
|
|
59
|
-
__metadata("design:paramtypes", [String])
|
|
60
|
-
], RequiredValidator);
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Validator } from "./Validator";
|
|
2
|
-
import { StepValidatorOptions } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary Step Validator
|
|
5
|
-
*
|
|
6
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
7
|
-
*
|
|
8
|
-
* @class StepValidator
|
|
9
|
-
* @extends Validator
|
|
10
|
-
*
|
|
11
|
-
* @category Validators
|
|
12
|
-
*/
|
|
13
|
-
export declare class StepValidator extends Validator<StepValidatorOptions> {
|
|
14
|
-
constructor(message?: string);
|
|
15
|
-
/**
|
|
16
|
-
* @summary Validates a model
|
|
17
|
-
*
|
|
18
|
-
* @param {string} value
|
|
19
|
-
* @param {number} step
|
|
20
|
-
* @param {StepValidatorOptions} options
|
|
21
|
-
*
|
|
22
|
-
* @return {string | undefined}
|
|
23
|
-
*
|
|
24
|
-
* @override
|
|
25
|
-
*
|
|
26
|
-
* @see Validator#hasErrors
|
|
27
|
-
*/
|
|
28
|
-
hasErrors(value: number | string, options: StepValidatorOptions): string | undefined;
|
|
29
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.StepValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
/**
|
|
17
|
-
* @summary Step Validator
|
|
18
|
-
*
|
|
19
|
-
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
20
|
-
*
|
|
21
|
-
* @class StepValidator
|
|
22
|
-
* @extends Validator
|
|
23
|
-
*
|
|
24
|
-
* @category Validators
|
|
25
|
-
*/
|
|
26
|
-
let StepValidator = class StepValidator extends Validator_1.Validator {
|
|
27
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.STEP) {
|
|
28
|
-
super(message, "number", "string");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @summary Validates a model
|
|
32
|
-
*
|
|
33
|
-
* @param {string} value
|
|
34
|
-
* @param {number} step
|
|
35
|
-
* @param {StepValidatorOptions} options
|
|
36
|
-
*
|
|
37
|
-
* @return {string | undefined}
|
|
38
|
-
*
|
|
39
|
-
* @override
|
|
40
|
-
*
|
|
41
|
-
* @see Validator#hasErrors
|
|
42
|
-
*/
|
|
43
|
-
hasErrors(value, options) {
|
|
44
|
-
if (typeof value === "undefined")
|
|
45
|
-
return;
|
|
46
|
-
return Number(value) % Number(options.step) !== 0
|
|
47
|
-
? this.getMessage(options.message || this.message, options.step)
|
|
48
|
-
: undefined;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
exports.StepValidator = StepValidator;
|
|
52
|
-
exports.StepValidator = StepValidator = __decorate([
|
|
53
|
-
(0, decorators_1.validator)(constants_1.ValidationKeys.STEP),
|
|
54
|
-
__metadata("design:paramtypes", [String])
|
|
55
|
-
], StepValidator);
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.TypeValidator = void 0;
|
|
13
|
-
const Validator_1 = require("./Validator");
|
|
14
|
-
const constants_1 = require("./constants");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
const Validation_1 = require("../Validation");
|
|
17
|
-
const constants_2 = require("../../utils/constants");
|
|
18
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
19
|
-
/**
|
|
20
|
-
* @summary Required Validator
|
|
21
|
-
*
|
|
22
|
-
* @class RequiredValidator
|
|
23
|
-
* @extends Validator
|
|
24
|
-
*
|
|
25
|
-
* @category Validators
|
|
26
|
-
*/
|
|
27
|
-
let TypeValidator = class TypeValidator extends Validator_1.Validator {
|
|
28
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.TYPE) {
|
|
29
|
-
super(message);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* @summary Validates a model
|
|
33
|
-
* @param {string} value
|
|
34
|
-
* @param {TypeValidatorOptions} options
|
|
35
|
-
*
|
|
36
|
-
* @return {string | undefined}
|
|
37
|
-
*
|
|
38
|
-
* @override
|
|
39
|
-
*
|
|
40
|
-
* @see Validator#hasErrors
|
|
41
|
-
*/
|
|
42
|
-
hasErrors(value, options) {
|
|
43
|
-
if (value === undefined)
|
|
44
|
-
return; // Don't try and enforce type if undefined
|
|
45
|
-
const { types, message } = options;
|
|
46
|
-
if (!reflection_1.Reflection.evaluateDesignTypes(value, types))
|
|
47
|
-
return this.getMessage(message || this.message, typeof types === "string"
|
|
48
|
-
? types
|
|
49
|
-
: Array.isArray(types)
|
|
50
|
-
? types.join(", ")
|
|
51
|
-
: types.name, typeof value);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
exports.TypeValidator = TypeValidator;
|
|
55
|
-
exports.TypeValidator = TypeValidator = __decorate([
|
|
56
|
-
(0, decorators_1.validator)(constants_1.ValidationKeys.TYPE),
|
|
57
|
-
__metadata("design:paramtypes", [String])
|
|
58
|
-
], TypeValidator);
|
|
59
|
-
Validation_1.Validation.register({
|
|
60
|
-
validator: TypeValidator,
|
|
61
|
-
validationKey: constants_2.ModelKeys.TYPE,
|
|
62
|
-
save: false,
|
|
63
|
-
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { PatternValidator } from "./PatternValidator";
|
|
2
|
-
import { PatternValidatorOptions } from "./types";
|
|
3
|
-
/**
|
|
4
|
-
* @summary URL Validator
|
|
5
|
-
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
6
|
-
*
|
|
7
|
-
* @class URLValidator
|
|
8
|
-
* @extends PatternValidator
|
|
9
|
-
*
|
|
10
|
-
* @category Validators
|
|
11
|
-
*/
|
|
12
|
-
export declare class URLValidator 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 Validator#hasErrors
|
|
25
|
-
*/
|
|
26
|
-
hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
|
|
27
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
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;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.URLValidator = void 0;
|
|
13
|
-
const constants_1 = require("./constants");
|
|
14
|
-
const PatternValidator_1 = require("./PatternValidator");
|
|
15
|
-
const decorators_1 = require("./decorators");
|
|
16
|
-
/**
|
|
17
|
-
* @summary URL Validator
|
|
18
|
-
* @description Pattern from {@link https://gist.github.com/dperini/729294}
|
|
19
|
-
*
|
|
20
|
-
* @class URLValidator
|
|
21
|
-
* @extends PatternValidator
|
|
22
|
-
*
|
|
23
|
-
* @category Validators
|
|
24
|
-
*/
|
|
25
|
-
let URLValidator = class URLValidator extends PatternValidator_1.PatternValidator {
|
|
26
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.URL) {
|
|
27
|
-
super(message);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @summary Validates a model
|
|
31
|
-
*
|
|
32
|
-
* @param {string} value
|
|
33
|
-
* @param {PatternValidatorOptions} [options={}]
|
|
34
|
-
*
|
|
35
|
-
* @return {string | undefined}
|
|
36
|
-
*
|
|
37
|
-
* @override
|
|
38
|
-
*
|
|
39
|
-
* @see Validator#hasErrors
|
|
40
|
-
*/
|
|
41
|
-
hasErrors(value, options = {}) {
|
|
42
|
-
return super.hasErrors(value, {
|
|
43
|
-
...options,
|
|
44
|
-
pattern: options.pattern || constants_1.DEFAULT_PATTERNS.URL,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
exports.URLValidator = URLValidator;
|
|
49
|
-
exports.URLValidator = URLValidator = __decorate([
|
|
50
|
-
(0, decorators_1.validator)(constants_1.ValidationKeys.URL),
|
|
51
|
-
__metadata("design:paramtypes", [String])
|
|
52
|
-
], URLValidator);
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ValidatorOptions } from "./types";
|
|
2
|
-
/**
|
|
3
|
-
* @summary Base Implementation for Validators
|
|
4
|
-
* @description Provides the underlying functionality for {@link Validator}s
|
|
5
|
-
*
|
|
6
|
-
* @param {string} validationKey the key to register the validator under
|
|
7
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT}
|
|
8
|
-
* @param {string[]} [acceptedTypes] defines the value types this validator can validate
|
|
9
|
-
*
|
|
10
|
-
* @class Validator
|
|
11
|
-
* @abstract
|
|
12
|
-
* @category Validators
|
|
13
|
-
*/
|
|
14
|
-
export declare abstract class Validator<V extends ValidatorOptions = ValidatorOptions> {
|
|
15
|
-
readonly message: string;
|
|
16
|
-
readonly acceptedTypes?: string[];
|
|
17
|
-
protected constructor(message?: string, ...acceptedTypes: string[]);
|
|
18
|
-
/**
|
|
19
|
-
* @summary builds the error message
|
|
20
|
-
* @param {string} message
|
|
21
|
-
* @param {any[]} args
|
|
22
|
-
* @protected
|
|
23
|
-
*/
|
|
24
|
-
protected getMessage(message: string, ...args: any[]): string;
|
|
25
|
-
/**
|
|
26
|
-
* @summary Validates type
|
|
27
|
-
* @param {any} unbound
|
|
28
|
-
* @private
|
|
29
|
-
*/
|
|
30
|
-
private checkTypeAndHasErrors;
|
|
31
|
-
/**
|
|
32
|
-
* @summary Validates an attribute
|
|
33
|
-
* @param {any} value
|
|
34
|
-
* @param {ValidatorOptions} [options] Validate options for customizing the model validation behavior
|
|
35
|
-
*
|
|
36
|
-
* @abstract
|
|
37
|
-
*
|
|
38
|
-
* @see Model#hasErrors
|
|
39
|
-
*/
|
|
40
|
-
abstract hasErrors(value: any, options?: V): string | undefined;
|
|
41
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Validator = void 0;
|
|
4
|
-
const constants_1 = require("./constants");
|
|
5
|
-
const strings_1 = require("../../utils/strings");
|
|
6
|
-
const reflection_1 = require("@decaf-ts/reflection");
|
|
7
|
-
/**
|
|
8
|
-
* @summary Base Implementation for Validators
|
|
9
|
-
* @description Provides the underlying functionality for {@link Validator}s
|
|
10
|
-
*
|
|
11
|
-
* @param {string} validationKey the key to register the validator under
|
|
12
|
-
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT}
|
|
13
|
-
* @param {string[]} [acceptedTypes] defines the value types this validator can validate
|
|
14
|
-
*
|
|
15
|
-
* @class Validator
|
|
16
|
-
* @abstract
|
|
17
|
-
* @category Validators
|
|
18
|
-
*/
|
|
19
|
-
class Validator {
|
|
20
|
-
constructor(message = constants_1.DEFAULT_ERROR_MESSAGES.DEFAULT, ...acceptedTypes) {
|
|
21
|
-
this.message = message;
|
|
22
|
-
if (acceptedTypes.length)
|
|
23
|
-
this.acceptedTypes = acceptedTypes;
|
|
24
|
-
if (this.acceptedTypes)
|
|
25
|
-
this.hasErrors = this.checkTypeAndHasErrors(this.hasErrors.bind(this));
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @summary builds the error message
|
|
29
|
-
* @param {string} message
|
|
30
|
-
* @param {any[]} args
|
|
31
|
-
* @protected
|
|
32
|
-
*/
|
|
33
|
-
getMessage(message, ...args) {
|
|
34
|
-
return (0, strings_1.sf)(message, ...args);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @summary Validates type
|
|
38
|
-
* @param {any} unbound
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
checkTypeAndHasErrors(unbound) {
|
|
42
|
-
return function (value, ...args) {
|
|
43
|
-
if (value === undefined || !this.acceptedTypes)
|
|
44
|
-
return unbound(value, ...args);
|
|
45
|
-
if (!reflection_1.Reflection.checkTypes(value, this.acceptedTypes))
|
|
46
|
-
return this.getMessage(constants_1.DEFAULT_ERROR_MESSAGES.TYPE, this.acceptedTypes.join(", "), typeof value);
|
|
47
|
-
return unbound(value, ...args);
|
|
48
|
-
}.bind(this);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.Validator = Validator;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { ValidatorDefinition } from "./types";
|
|
2
|
-
import { IValidatorRegistry } from "./types";
|
|
3
|
-
import type { Validator } from "./Validator";
|
|
4
|
-
/**
|
|
5
|
-
* @summary Duck typing for Validators
|
|
6
|
-
* @function isValidator
|
|
7
|
-
* @param val
|
|
8
|
-
*/
|
|
9
|
-
export declare function isValidator(val: any): any;
|
|
10
|
-
/**
|
|
11
|
-
* @summary Base Implementation of a Validator Registry
|
|
12
|
-
*
|
|
13
|
-
* @prop {Validator[]} [validators] the initial validators to register
|
|
14
|
-
*
|
|
15
|
-
* @class ValidatorRegistry
|
|
16
|
-
* @implements IValidatorRegistry<T>
|
|
17
|
-
*
|
|
18
|
-
* @category Validation
|
|
19
|
-
*/
|
|
20
|
-
export declare class ValidatorRegistry<T extends Validator> implements IValidatorRegistry<T> {
|
|
21
|
-
private cache;
|
|
22
|
-
private customKeyCache;
|
|
23
|
-
constructor(...validators: (ValidatorDefinition | Validator)[]);
|
|
24
|
-
/**
|
|
25
|
-
* @summary retrieves the custom keys
|
|
26
|
-
*/
|
|
27
|
-
getCustomKeys(): {
|
|
28
|
-
[indexer: string]: string;
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* @summary retrieves the registered validators keys
|
|
32
|
-
*/
|
|
33
|
-
getKeys(): string[];
|
|
34
|
-
/**
|
|
35
|
-
* @summary Retrieves a validator
|
|
36
|
-
*
|
|
37
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
38
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
39
|
-
*/
|
|
40
|
-
get<T extends Validator>(validatorKey: string): T | undefined;
|
|
41
|
-
/**
|
|
42
|
-
* @summary Registers the provided validators onto the registry
|
|
43
|
-
*
|
|
44
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
45
|
-
*/
|
|
46
|
-
register<T extends Validator>(...validator: (ValidatorDefinition | T)[]): void;
|
|
47
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValidatorRegistry = void 0;
|
|
4
|
-
exports.isValidator = isValidator;
|
|
5
|
-
/**
|
|
6
|
-
* @summary Duck typing for Validators
|
|
7
|
-
* @function isValidator
|
|
8
|
-
* @param val
|
|
9
|
-
*/
|
|
10
|
-
function isValidator(val) {
|
|
11
|
-
return val.constructor && val["hasErrors"];
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* @summary Base Implementation of a Validator Registry
|
|
15
|
-
*
|
|
16
|
-
* @prop {Validator[]} [validators] the initial validators to register
|
|
17
|
-
*
|
|
18
|
-
* @class ValidatorRegistry
|
|
19
|
-
* @implements IValidatorRegistry<T>
|
|
20
|
-
*
|
|
21
|
-
* @category Validation
|
|
22
|
-
*/
|
|
23
|
-
class ValidatorRegistry {
|
|
24
|
-
constructor(...validators) {
|
|
25
|
-
this.cache = {};
|
|
26
|
-
this.customKeyCache = {};
|
|
27
|
-
this.register(...validators);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* @summary retrieves the custom keys
|
|
31
|
-
*/
|
|
32
|
-
getCustomKeys() {
|
|
33
|
-
return Object.assign({}, this.customKeyCache);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* @summary retrieves the registered validators keys
|
|
37
|
-
*/
|
|
38
|
-
getKeys() {
|
|
39
|
-
return Object.keys(this.cache);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* @summary Retrieves a validator
|
|
43
|
-
*
|
|
44
|
-
* @param {string} validatorKey one of the {@link ValidationKeys}
|
|
45
|
-
* @return {Validator | undefined} the registered Validator or undefined if there is nono matching the provided key
|
|
46
|
-
*/
|
|
47
|
-
get(validatorKey) {
|
|
48
|
-
if (!(validatorKey in this.cache))
|
|
49
|
-
return undefined;
|
|
50
|
-
const classOrInstance = this.cache[validatorKey];
|
|
51
|
-
if (isValidator(classOrInstance))
|
|
52
|
-
return classOrInstance;
|
|
53
|
-
const constructor = classOrInstance.default || classOrInstance;
|
|
54
|
-
const instance = new constructor();
|
|
55
|
-
this.cache[validatorKey] = instance;
|
|
56
|
-
return instance;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* @summary Registers the provided validators onto the registry
|
|
60
|
-
*
|
|
61
|
-
* @param {T[] | ValidatorDefinition[]} validator
|
|
62
|
-
*/
|
|
63
|
-
register(...validator) {
|
|
64
|
-
validator.forEach((v) => {
|
|
65
|
-
if (isValidator(v)) {
|
|
66
|
-
// const k =
|
|
67
|
-
if (v.validationKey in this.cache)
|
|
68
|
-
return;
|
|
69
|
-
this.cache[v.validationKey] = v;
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const { validationKey, validator, save } = v;
|
|
73
|
-
if (validationKey in this.cache)
|
|
74
|
-
return;
|
|
75
|
-
this.cache[validationKey] = validator;
|
|
76
|
-
if (!save)
|
|
77
|
-
return;
|
|
78
|
-
const obj = {};
|
|
79
|
-
obj[validationKey.toUpperCase()] = validationKey;
|
|
80
|
-
this.customKeyCache = Object.assign({}, this.customKeyCache, obj);
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.ValidatorRegistry = ValidatorRegistry;
|