@decaf-ts/decorator-validation 1.5.5 → 1.5.7
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/dist/decorator-validation.js +1 -1
- package/dist/esm/decorator-validation.js +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -3
- package/lib/esm/model/Model.js +0 -2
- package/lib/esm/model/ModelErrorDefinition.js +0 -2
- package/lib/esm/model/Registry.js +0 -2
- package/lib/esm/model/constants.js +0 -2
- package/lib/esm/model/construction.js +0 -2
- package/lib/esm/model/decorators.js +0 -2
- package/lib/esm/model/index.js +0 -2
- package/lib/esm/model/types.js +0 -2
- package/lib/esm/model/utils.js +0 -2
- package/lib/esm/model/validation.js +0 -2
- package/lib/esm/utils/constants.js +0 -2
- package/lib/esm/utils/dates.js +0 -2
- package/lib/esm/utils/decorators.js +0 -2
- package/lib/esm/utils/hashing.js +0 -2
- package/lib/esm/utils/index.js +0 -2
- package/lib/esm/utils/registry.js +0 -2
- package/lib/esm/utils/serialization.js +0 -2
- package/lib/esm/utils/strings.js +0 -2
- package/lib/esm/validation/Validation.js +0 -2
- package/lib/esm/validation/Validators/DateValidator.js +0 -2
- package/lib/esm/validation/Validators/EmailValidator.js +0 -2
- package/lib/esm/validation/Validators/ListValidator.js +0 -2
- package/lib/esm/validation/Validators/MaxLengthValidator.js +0 -2
- package/lib/esm/validation/Validators/MaxValidator.js +0 -2
- package/lib/esm/validation/Validators/MinLengthValidator.js +0 -2
- package/lib/esm/validation/Validators/MinValidator.js +0 -2
- package/lib/esm/validation/Validators/PasswordValidator.js +0 -2
- package/lib/esm/validation/Validators/PatternValidator.js +0 -2
- package/lib/esm/validation/Validators/RequiredValidator.js +0 -2
- package/lib/esm/validation/Validators/StepValidator.js +0 -2
- package/lib/esm/validation/Validators/TypeValidator.js +0 -2
- package/lib/esm/validation/Validators/URLValidator.js +0 -2
- package/lib/esm/validation/Validators/Validator.js +0 -2
- package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -2
- package/lib/esm/validation/Validators/constants.js +0 -2
- package/lib/esm/validation/Validators/decorators.js +0 -2
- package/lib/esm/validation/Validators/index.js +0 -2
- package/lib/esm/validation/Validators/types.js +0 -2
- package/lib/esm/validation/decorators.js +0 -2
- package/lib/esm/validation/index.js +0 -2
- package/lib/esm/validation/types.js +0 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +59 -0
- package/lib/model/Model.js +300 -0
- package/lib/model/ModelErrorDefinition.js +56 -0
- package/lib/model/Registry.js +78 -0
- package/lib/model/constants.js +72 -0
- package/lib/model/construction.js +68 -0
- package/lib/model/decorators.js +67 -0
- package/lib/{validation/index.cjs → model/index.js} +9 -6
- package/lib/model/types.js +2 -0
- package/lib/model/utils.js +29 -0
- package/lib/model/validation.js +138 -0
- package/lib/utils/constants.js +30 -0
- package/lib/utils/dates.js +251 -0
- package/lib/utils/decorators.js +22 -0
- package/lib/utils/hashing.js +106 -0
- package/lib/utils/index.js +23 -0
- package/lib/utils/registry.js +2 -0
- package/lib/utils/serialization.js +93 -0
- package/lib/utils/strings.js +35 -0
- package/lib/validation/Validation.js +75 -0
- package/lib/validation/Validators/DateValidator.js +57 -0
- package/lib/validation/Validators/EmailValidator.js +53 -0
- package/lib/validation/Validators/ListValidator.js +70 -0
- package/lib/validation/Validators/MaxLengthValidator.js +55 -0
- package/lib/validation/Validators/MaxValidator.js +60 -0
- package/lib/validation/Validators/MinLengthValidator.js +55 -0
- package/lib/validation/Validators/MinValidator.js +60 -0
- package/lib/validation/Validators/PasswordValidator.js +53 -0
- package/lib/validation/Validators/PatternValidator.js +73 -0
- package/lib/validation/Validators/RequiredValidator.js +60 -0
- package/lib/validation/Validators/StepValidator.js +55 -0
- package/lib/validation/Validators/TypeValidator.js +63 -0
- package/lib/validation/Validators/URLValidator.js +52 -0
- package/lib/validation/Validators/Validator.js +51 -0
- package/lib/validation/Validators/ValidatorRegistry.js +85 -0
- package/lib/validation/Validators/constants.js +137 -0
- package/lib/validation/Validators/decorators.js +28 -0
- package/lib/validation/Validators/index.js +69 -0
- package/lib/validation/Validators/types.js +2 -0
- package/lib/validation/decorators.js +304 -0
- package/lib/validation/index.js +20 -0
- package/lib/validation/types.js +2 -0
- package/package.json +1 -1
- package/lib/index.cjs +0 -61
- package/lib/model/Model.cjs +0 -302
- package/lib/model/ModelErrorDefinition.cjs +0 -58
- package/lib/model/Registry.cjs +0 -80
- package/lib/model/constants.cjs +0 -74
- package/lib/model/construction.cjs +0 -70
- package/lib/model/decorators.cjs +0 -69
- package/lib/model/index.cjs +0 -27
- package/lib/model/types.cjs +0 -4
- package/lib/model/utils.cjs +0 -31
- package/lib/model/validation.cjs +0 -140
- package/lib/utils/constants.cjs +0 -32
- package/lib/utils/dates.cjs +0 -253
- package/lib/utils/decorators.cjs +0 -24
- package/lib/utils/hashing.cjs +0 -108
- package/lib/utils/index.cjs +0 -25
- package/lib/utils/registry.cjs +0 -4
- package/lib/utils/serialization.cjs +0 -95
- package/lib/utils/strings.cjs +0 -37
- package/lib/validation/Validation.cjs +0 -77
- package/lib/validation/Validators/DateValidator.cjs +0 -59
- package/lib/validation/Validators/EmailValidator.cjs +0 -55
- package/lib/validation/Validators/ListValidator.cjs +0 -72
- package/lib/validation/Validators/MaxLengthValidator.cjs +0 -57
- package/lib/validation/Validators/MaxValidator.cjs +0 -62
- package/lib/validation/Validators/MinLengthValidator.cjs +0 -57
- package/lib/validation/Validators/MinValidator.cjs +0 -62
- package/lib/validation/Validators/PasswordValidator.cjs +0 -55
- package/lib/validation/Validators/PatternValidator.cjs +0 -75
- package/lib/validation/Validators/RequiredValidator.cjs +0 -62
- package/lib/validation/Validators/StepValidator.cjs +0 -57
- package/lib/validation/Validators/TypeValidator.cjs +0 -65
- package/lib/validation/Validators/URLValidator.cjs +0 -54
- package/lib/validation/Validators/Validator.cjs +0 -53
- package/lib/validation/Validators/ValidatorRegistry.cjs +0 -87
- package/lib/validation/Validators/constants.cjs +0 -139
- package/lib/validation/Validators/decorators.cjs +0 -30
- package/lib/validation/Validators/index.cjs +0 -71
- package/lib/validation/Validators/types.d.ts +0 -88
- package/lib/validation/decorators.cjs +0 -306
- package/lib/validation/types.cjs +0 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Validators = void 0;
|
|
18
|
+
const DateValidator_1 = require("./DateValidator");
|
|
19
|
+
const TypeValidator_1 = require("./TypeValidator");
|
|
20
|
+
const PasswordValidator_1 = require("./PasswordValidator");
|
|
21
|
+
const StepValidator_1 = require("./StepValidator");
|
|
22
|
+
const URLValidator_1 = require("./URLValidator");
|
|
23
|
+
const PatternValidator_1 = require("./PatternValidator");
|
|
24
|
+
const MinValidator_1 = require("./MinValidator");
|
|
25
|
+
const MinLengthValidator_1 = require("./MinLengthValidator");
|
|
26
|
+
const MaxValidator_1 = require("./MaxValidator");
|
|
27
|
+
const MaxLengthValidator_1 = require("./MaxLengthValidator");
|
|
28
|
+
const RequiredValidator_1 = require("./RequiredValidator");
|
|
29
|
+
const EmailValidator_1 = require("./EmailValidator");
|
|
30
|
+
const ListValidator_1 = require("./ListValidator");
|
|
31
|
+
__exportStar(require("./constants"), exports);
|
|
32
|
+
__exportStar(require("./DateValidator"), exports);
|
|
33
|
+
__exportStar(require("./decorators"), exports);
|
|
34
|
+
__exportStar(require("./EmailValidator"), exports);
|
|
35
|
+
__exportStar(require("./ListValidator"), exports);
|
|
36
|
+
__exportStar(require("./MaxLengthValidator"), exports);
|
|
37
|
+
__exportStar(require("./MaxValidator"), exports);
|
|
38
|
+
__exportStar(require("./MinLengthValidator"), exports);
|
|
39
|
+
__exportStar(require("./MinValidator"), exports);
|
|
40
|
+
__exportStar(require("./PasswordValidator"), exports);
|
|
41
|
+
__exportStar(require("./PatternValidator"), exports);
|
|
42
|
+
__exportStar(require("./RequiredValidator"), exports);
|
|
43
|
+
__exportStar(require("./StepValidator"), exports);
|
|
44
|
+
__exportStar(require("./types"), exports);
|
|
45
|
+
__exportStar(require("./TypeValidator"), exports);
|
|
46
|
+
__exportStar(require("./URLValidator"), exports);
|
|
47
|
+
__exportStar(require("./Validator"), exports);
|
|
48
|
+
__exportStar(require("./ValidatorRegistry"), exports);
|
|
49
|
+
/**
|
|
50
|
+
* @summary constant holding all {@link Validator}s
|
|
51
|
+
* @constant Validators
|
|
52
|
+
* @memberOf module:decorator-validation.Validation.Validators
|
|
53
|
+
* @category Validation
|
|
54
|
+
*/
|
|
55
|
+
exports.Validators = {
|
|
56
|
+
DateValidator: DateValidator_1.DateValidator,
|
|
57
|
+
EmailValidator: EmailValidator_1.EmailValidator,
|
|
58
|
+
ListValidator: ListValidator_1.ListValidator,
|
|
59
|
+
MaxLengthValidator: MaxLengthValidator_1.MaxLengthValidator,
|
|
60
|
+
MaxValidator: MaxValidator_1.MaxValidator,
|
|
61
|
+
MinLengthValidator: MinLengthValidator_1.MinLengthValidator,
|
|
62
|
+
MinValidator: MinValidator_1.MinValidator,
|
|
63
|
+
PasswordValidator: PasswordValidator_1.PasswordValidator,
|
|
64
|
+
PatternValidator: PatternValidator_1.PatternValidator,
|
|
65
|
+
RequiredValidator: RequiredValidator_1.RequiredValidator,
|
|
66
|
+
StepValidator: StepValidator_1.StepValidator,
|
|
67
|
+
TypeValidator: TypeValidator_1.TypeValidator,
|
|
68
|
+
URLValidator: URLValidator_1.URLValidator,
|
|
69
|
+
};
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.required = required;
|
|
4
|
+
exports.min = min;
|
|
5
|
+
exports.max = max;
|
|
6
|
+
exports.step = step;
|
|
7
|
+
exports.minlength = minlength;
|
|
8
|
+
exports.maxlength = maxlength;
|
|
9
|
+
exports.pattern = pattern;
|
|
10
|
+
exports.email = email;
|
|
11
|
+
exports.url = url;
|
|
12
|
+
exports.type = type;
|
|
13
|
+
exports.date = date;
|
|
14
|
+
exports.password = password;
|
|
15
|
+
exports.list = list;
|
|
16
|
+
exports.set = set;
|
|
17
|
+
require("reflect-metadata");
|
|
18
|
+
const constants_1 = require("./Validators/constants");
|
|
19
|
+
const strings_1 = require("../utils/strings");
|
|
20
|
+
const dates_1 = require("../utils/dates");
|
|
21
|
+
const decorators_1 = require("../utils/decorators");
|
|
22
|
+
const Validation_1 = require("./Validation");
|
|
23
|
+
/**
|
|
24
|
+
* @summary Marks the property as required.
|
|
25
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}
|
|
26
|
+
*
|
|
27
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
|
|
28
|
+
*
|
|
29
|
+
* @function required
|
|
30
|
+
*
|
|
31
|
+
* @category Decorators
|
|
32
|
+
*/
|
|
33
|
+
function required(message = constants_1.DEFAULT_ERROR_MESSAGES.REQUIRED) {
|
|
34
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.REQUIRED), {
|
|
35
|
+
message: message,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @summary Defines a minimum value for the property
|
|
40
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN}
|
|
41
|
+
*
|
|
42
|
+
* @param {number | Date} value
|
|
43
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
|
|
44
|
+
*
|
|
45
|
+
* @function min
|
|
46
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
47
|
+
* @category Decorators
|
|
48
|
+
*/
|
|
49
|
+
function min(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN) {
|
|
50
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MIN), {
|
|
51
|
+
min: value,
|
|
52
|
+
message: message,
|
|
53
|
+
types: [Number.name, Date.name],
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @summary Defines a maximum value for the property
|
|
58
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
|
|
59
|
+
*
|
|
60
|
+
* @param {number | Date} value
|
|
61
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
|
|
62
|
+
*
|
|
63
|
+
* @function max
|
|
64
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
65
|
+
* @category Decorators
|
|
66
|
+
*/
|
|
67
|
+
function max(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX) {
|
|
68
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MAX), {
|
|
69
|
+
max: value,
|
|
70
|
+
message: message,
|
|
71
|
+
types: [Number.name, Date.name],
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* @summary Defines a step value for the property
|
|
76
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
|
|
77
|
+
*
|
|
78
|
+
* @param {number} value
|
|
79
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
|
|
80
|
+
*
|
|
81
|
+
* @function step
|
|
82
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
83
|
+
* @category Decorators
|
|
84
|
+
*/
|
|
85
|
+
function step(value, message = constants_1.DEFAULT_ERROR_MESSAGES.STEP) {
|
|
86
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.STEP), {
|
|
87
|
+
step: value,
|
|
88
|
+
message: message,
|
|
89
|
+
types: [Number.name],
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @summary Defines a minimum length for the property
|
|
94
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
|
|
95
|
+
*
|
|
96
|
+
* @param {string} value
|
|
97
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
|
|
98
|
+
*
|
|
99
|
+
* @function minlength
|
|
100
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
101
|
+
* @category Decorators
|
|
102
|
+
*/
|
|
103
|
+
function minlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
|
|
104
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MIN_LENGTH), {
|
|
105
|
+
minLength: value,
|
|
106
|
+
message: message,
|
|
107
|
+
types: [String.name, Array.name, Set.name],
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* @summary Defines a maximum length for the property
|
|
112
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
|
|
113
|
+
*
|
|
114
|
+
* @param {string} value
|
|
115
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
|
|
116
|
+
*
|
|
117
|
+
* @function maxlength
|
|
118
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
119
|
+
* @category Decorators
|
|
120
|
+
*/
|
|
121
|
+
function maxlength(value, message = constants_1.DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
|
|
122
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.MAX_LENGTH), {
|
|
123
|
+
maxLength: value,
|
|
124
|
+
message: message,
|
|
125
|
+
types: [String.name, Array.name, Set.name],
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* @summary Defines a RegExp pattern the property must respect
|
|
130
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
|
|
131
|
+
*
|
|
132
|
+
* @param {string} value
|
|
133
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
|
|
134
|
+
*
|
|
135
|
+
* @function pattern
|
|
136
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
137
|
+
* @category Decorators
|
|
138
|
+
*/
|
|
139
|
+
function pattern(value, message = constants_1.DEFAULT_ERROR_MESSAGES.PATTERN) {
|
|
140
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.PATTERN), {
|
|
141
|
+
pattern: typeof value === "string" ? value : value.toString(),
|
|
142
|
+
message: message,
|
|
143
|
+
types: [String.name],
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* @summary Defines the property as an email
|
|
148
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
|
|
149
|
+
*
|
|
150
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
|
|
151
|
+
*
|
|
152
|
+
* @function email
|
|
153
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
154
|
+
* @category Decorators
|
|
155
|
+
*/
|
|
156
|
+
function email(message = constants_1.DEFAULT_ERROR_MESSAGES.EMAIL) {
|
|
157
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.EMAIL), {
|
|
158
|
+
pattern: constants_1.DEFAULT_PATTERNS.EMAIL,
|
|
159
|
+
message: message,
|
|
160
|
+
types: [String.name],
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* @summary Defines the property as an URL
|
|
165
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
|
|
166
|
+
*
|
|
167
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
|
|
168
|
+
*
|
|
169
|
+
* @function url
|
|
170
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
171
|
+
* @category Decorators
|
|
172
|
+
*/
|
|
173
|
+
function url(message = constants_1.DEFAULT_ERROR_MESSAGES.URL) {
|
|
174
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.URL), {
|
|
175
|
+
pattern: constants_1.DEFAULT_PATTERNS.URL,
|
|
176
|
+
message: message,
|
|
177
|
+
types: [String.name],
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @summary Enforces type verification
|
|
182
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
|
|
183
|
+
*
|
|
184
|
+
* @param {string[] | string} types accepted types
|
|
185
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
|
|
186
|
+
*
|
|
187
|
+
* @function type
|
|
188
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
189
|
+
* @category Decorators
|
|
190
|
+
*/
|
|
191
|
+
function type(types, message = constants_1.DEFAULT_ERROR_MESSAGES.TYPE) {
|
|
192
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.TYPE), {
|
|
193
|
+
customTypes: types,
|
|
194
|
+
message: message,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @summary Date Handler Decorator
|
|
199
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
|
|
200
|
+
*
|
|
201
|
+
* Will enforce serialization according to the selected format
|
|
202
|
+
*
|
|
203
|
+
* @param {string} format accepted format according to {@link formatDate}
|
|
204
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
|
|
205
|
+
* @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link DateValidator}
|
|
206
|
+
*
|
|
207
|
+
* @function date
|
|
208
|
+
*
|
|
209
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
210
|
+
* @category Decorators
|
|
211
|
+
*/
|
|
212
|
+
function date(format = "dd/MM/yyyy", message = constants_1.DEFAULT_ERROR_MESSAGES.DATE) {
|
|
213
|
+
return (target, propertyKey) => {
|
|
214
|
+
(0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.DATE), {
|
|
215
|
+
format: format,
|
|
216
|
+
message: message,
|
|
217
|
+
types: [Date.name],
|
|
218
|
+
})(target, propertyKey);
|
|
219
|
+
const values = new WeakMap();
|
|
220
|
+
Object.defineProperty(target, propertyKey, {
|
|
221
|
+
configurable: false,
|
|
222
|
+
set(newValue) {
|
|
223
|
+
const descriptor = Object.getOwnPropertyDescriptor(this, propertyKey);
|
|
224
|
+
if (!descriptor || descriptor.configurable)
|
|
225
|
+
Object.defineProperty(this, propertyKey, {
|
|
226
|
+
enumerable: true,
|
|
227
|
+
configurable: false,
|
|
228
|
+
get: () => values.get(this),
|
|
229
|
+
set: (newValue) => {
|
|
230
|
+
let val;
|
|
231
|
+
try {
|
|
232
|
+
val = (0, dates_1.parseDate)(format, newValue);
|
|
233
|
+
values.set(this, val);
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
console.error((0, strings_1.sf)("Failed to parse date: {0}", e.message || e));
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
this[propertyKey] = newValue;
|
|
241
|
+
},
|
|
242
|
+
get() {
|
|
243
|
+
console.log("here");
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @summary Password Handler Decorator
|
|
250
|
+
* @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
|
|
251
|
+
*
|
|
252
|
+
* @param {RegExp} [pattern] defaults to {@link PasswordPatterns#CHAR8_ONE_OF_EACH}
|
|
253
|
+
* @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
|
|
254
|
+
* @param {Constructor<Validator>} [validator] Defaults to {@link PasswordValidator}
|
|
255
|
+
*
|
|
256
|
+
* @function password
|
|
257
|
+
*
|
|
258
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
259
|
+
* @category Decorators
|
|
260
|
+
*/
|
|
261
|
+
function password(pattern = constants_1.DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_EACH, message = constants_1.DEFAULT_ERROR_MESSAGES.PASSWORD) {
|
|
262
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.PASSWORD), {
|
|
263
|
+
pattern: pattern,
|
|
264
|
+
message: message,
|
|
265
|
+
types: [String.name],
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* @summary List Decorator
|
|
270
|
+
* @description Also sets the {@link type} to the provided collection
|
|
271
|
+
*
|
|
272
|
+
* @param {ModelConstructor} clazz
|
|
273
|
+
* @param {string} [collection] The collection being used. defaults to Array
|
|
274
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
275
|
+
* @param {Constructor<Validator>} [validator] defaults to {@link ListValidator}
|
|
276
|
+
*
|
|
277
|
+
* @function list
|
|
278
|
+
*
|
|
279
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
280
|
+
* @category Decorators
|
|
281
|
+
*/
|
|
282
|
+
function list(clazz, collection = "Array", message = constants_1.DEFAULT_ERROR_MESSAGES.LIST) {
|
|
283
|
+
return (0, decorators_1.propMetadata)(Validation_1.Validation.key(constants_1.ValidationKeys.LIST), {
|
|
284
|
+
clazz: Array.isArray(clazz) ? clazz.map((c) => c.name) : [clazz.name],
|
|
285
|
+
type: collection,
|
|
286
|
+
message: message,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* @summary Set Decorator
|
|
291
|
+
* @description Wrapper for {@link list} with the 'Set' Collection
|
|
292
|
+
*
|
|
293
|
+
* @param {ModelConstructor} clazz
|
|
294
|
+
* @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
|
|
295
|
+
* @param {Constructor<Validator>} [validator]
|
|
296
|
+
*
|
|
297
|
+
* @function set
|
|
298
|
+
*
|
|
299
|
+
* @memberOf module:decorator-validation.Decorators.Validation
|
|
300
|
+
* @category Decorators
|
|
301
|
+
*/
|
|
302
|
+
function set(clazz, message = constants_1.DEFAULT_ERROR_MESSAGES.LIST) {
|
|
303
|
+
return list(clazz, "Set", message);
|
|
304
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Validators"), exports);
|
|
18
|
+
__exportStar(require("./decorators"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./Validation"), exports);
|
package/package.json
CHANGED
package/lib/index.cjs
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module decorator-validation
|
|
4
|
-
*/
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
-
}
|
|
11
|
-
Object.defineProperty(o, k2, desc);
|
|
12
|
-
}) : (function(o, m, k, k2) {
|
|
13
|
-
if (k2 === undefined) k2 = k;
|
|
14
|
-
o[k2] = m[k];
|
|
15
|
-
}));
|
|
16
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.VERSION = void 0;
|
|
21
|
-
/**
|
|
22
|
-
* @summary Model definition functionality
|
|
23
|
-
* @description defines the base class and related functionality
|
|
24
|
-
*
|
|
25
|
-
* @namespace Model
|
|
26
|
-
* @memberOf module:decorator-validation
|
|
27
|
-
*/
|
|
28
|
-
/**
|
|
29
|
-
* @summary Holds all the supported decorators
|
|
30
|
-
* @namespace Decorators
|
|
31
|
-
* @memberOf module:decorator-validation
|
|
32
|
-
*/
|
|
33
|
-
/**
|
|
34
|
-
* @summary Validation related functionality
|
|
35
|
-
* @description Defines the Model validation apis and base classes for validators
|
|
36
|
-
*
|
|
37
|
-
* @namespace Validation
|
|
38
|
-
* @memberOf module:decorator-validation
|
|
39
|
-
*/
|
|
40
|
-
/**
|
|
41
|
-
* @namespace Dates
|
|
42
|
-
* @memberOf module:decorator-validation
|
|
43
|
-
*/
|
|
44
|
-
/**
|
|
45
|
-
* @namespace Hashing
|
|
46
|
-
* @memberOf module:decorator-validation
|
|
47
|
-
*/
|
|
48
|
-
/**
|
|
49
|
-
* @namespace Serialization
|
|
50
|
-
* @memberOf module:decorator-validation
|
|
51
|
-
*/
|
|
52
|
-
/**
|
|
53
|
-
* @namespace Format
|
|
54
|
-
* @memberOf module:decorator-validation
|
|
55
|
-
*/
|
|
56
|
-
__exportStar(require("./utils/index.cjs"), exports);
|
|
57
|
-
__exportStar(require("./validation/index.cjs"), exports);
|
|
58
|
-
__exportStar(require("./model/index.cjs"), exports);
|
|
59
|
-
exports.VERSION = "1.5.4";
|
|
60
|
-
|
|
61
|
-
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNyYy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUE7O0dBRUc7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRUg7Ozs7OztHQU1HO0FBRUg7Ozs7R0FJRztBQUVIOzs7Ozs7R0FNRztBQUVIOzs7R0FHRztBQUVIOzs7R0FHRztBQUVIOzs7R0FHRztBQUVIOzs7R0FHRztBQUVILDBDQUF3QjtBQUN4QiwrQ0FBNkI7QUFDN0IsMENBQXdCO0FBRVgsUUFBQSxPQUFPLEdBQUcsT0FBTyxDQUFDIiwiZmlsZSI6ImluZGV4LmpzIiwic291cmNlc0NvbnRlbnQiOlsiLyoqXG4gKiBAbW9kdWxlIGRlY29yYXRvci12YWxpZGF0aW9uXG4gKi9cblxuLyoqXG4gKiBAc3VtbWFyeSBNb2RlbCBkZWZpbml0aW9uIGZ1bmN0aW9uYWxpdHlcbiAqIEBkZXNjcmlwdGlvbiBkZWZpbmVzIHRoZSBiYXNlIGNsYXNzIGFuZCByZWxhdGVkIGZ1bmN0aW9uYWxpdHlcbiAqXG4gKiBAbmFtZXNwYWNlIE1vZGVsXG4gKiBAbWVtYmVyT2YgbW9kdWxlOmRlY29yYXRvci12YWxpZGF0aW9uXG4gKi9cblxuLyoqXG4gKiBAc3VtbWFyeSBIb2xkcyBhbGwgdGhlIHN1cHBvcnRlZCBkZWNvcmF0b3JzXG4gKiBAbmFtZXNwYWNlIERlY29yYXRvcnNcbiAqIEBtZW1iZXJPZiBtb2R1bGU6ZGVjb3JhdG9yLXZhbGlkYXRpb25cbiAqL1xuXG4vKipcbiAqIEBzdW1tYXJ5IFZhbGlkYXRpb24gcmVsYXRlZCBmdW5jdGlvbmFsaXR5XG4gKiBAZGVzY3JpcHRpb24gRGVmaW5lcyB0aGUgTW9kZWwgdmFsaWRhdGlvbiBhcGlzIGFuZCBiYXNlIGNsYXNzZXMgZm9yIHZhbGlkYXRvcnNcbiAqXG4gKiBAbmFtZXNwYWNlIFZhbGlkYXRpb25cbiAqIEBtZW1iZXJPZiBtb2R1bGU6ZGVjb3JhdG9yLXZhbGlkYXRpb25cbiAqL1xuXG4vKipcbiAqIEBuYW1lc3BhY2UgRGF0ZXNcbiAqIEBtZW1iZXJPZiBtb2R1bGU6ZGVjb3JhdG9yLXZhbGlkYXRpb25cbiAqL1xuXG4vKipcbiAqIEBuYW1lc3BhY2UgSGFzaGluZ1xuICogQG1lbWJlck9mIG1vZHVsZTpkZWNvcmF0b3ItdmFsaWRhdGlvblxuICovXG5cbi8qKlxuICogQG5hbWVzcGFjZSBTZXJpYWxpemF0aW9uXG4gKiBAbWVtYmVyT2YgbW9kdWxlOmRlY29yYXRvci12YWxpZGF0aW9uXG4gKi9cblxuLyoqXG4gKiBAbmFtZXNwYWNlIEZvcm1hdFxuICogQG1lbWJlck9mIG1vZHVsZTpkZWNvcmF0b3ItdmFsaWRhdGlvblxuICovXG5cbmV4cG9ydCAqIGZyb20gXCIuL3V0aWxzXCI7XG5leHBvcnQgKiBmcm9tIFwiLi92YWxpZGF0aW9uXCI7XG5leHBvcnQgKiBmcm9tIFwiLi9tb2RlbFwiO1xuXG5leHBvcnQgY29uc3QgVkVSU0lPTiA9IFwiMS41LjRcIjtcbiJdfQ==
|