@decaf-ts/decorator-validation 1.4.21 → 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.
Files changed (173) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/package.json +15 -9
  4. package/dist/decorator-validation.bundle.min.js +0 -2
  5. package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -14
  6. package/dist/esm/decorator-validation.bundle.min.esm.js +0 -2
  7. package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -14
  8. package/lib/esm/index.d.ts +0 -42
  9. package/lib/esm/index.js +0 -42
  10. package/lib/esm/model/Model.d.ts +0 -139
  11. package/lib/esm/model/Model.js +0 -297
  12. package/lib/esm/model/ModelErrorDefinition.d.ts +0 -22
  13. package/lib/esm/model/ModelErrorDefinition.js +0 -52
  14. package/lib/esm/model/Registry.d.ts +0 -59
  15. package/lib/esm/model/Registry.js +0 -73
  16. package/lib/esm/model/constants.d.ts +0 -56
  17. package/lib/esm/model/constants.js +0 -69
  18. package/lib/esm/model/construction.d.ts +0 -29
  19. package/lib/esm/model/construction.js +0 -63
  20. package/lib/esm/model/decorators.d.ts +0 -25
  21. package/lib/esm/model/decorators.js +0 -62
  22. package/lib/esm/model/index.d.ts +0 -9
  23. package/lib/esm/model/index.js +0 -9
  24. package/lib/esm/model/types.d.ts +0 -79
  25. package/lib/esm/model/types.js +0 -1
  26. package/lib/esm/model/utils.d.ts +0 -11
  27. package/lib/esm/model/utils.js +0 -25
  28. package/lib/esm/model/validation.d.ts +0 -14
  29. package/lib/esm/model/validation.js +0 -134
  30. package/lib/esm/utils/constants.d.ts +0 -26
  31. package/lib/esm/utils/constants.js +0 -27
  32. package/lib/esm/utils/dates.d.ts +0 -76
  33. package/lib/esm/utils/dates.js +0 -243
  34. package/lib/esm/utils/decorators.d.ts +0 -2
  35. package/lib/esm/utils/decorators.js +0 -18
  36. package/lib/esm/utils/hashing.d.ts +0 -52
  37. package/lib/esm/utils/hashing.js +0 -99
  38. package/lib/esm/utils/index.d.ts +0 -7
  39. package/lib/esm/utils/index.js +0 -7
  40. package/lib/esm/utils/registry.d.ts +0 -68
  41. package/lib/esm/utils/registry.js +0 -1
  42. package/lib/esm/utils/serialization.d.ts +0 -79
  43. package/lib/esm/utils/serialization.js +0 -88
  44. package/lib/esm/utils/strings.d.ts +0 -25
  45. package/lib/esm/utils/strings.js +0 -31
  46. package/lib/esm/validation/Validation.d.ts +0 -51
  47. package/lib/esm/validation/Validation.js +0 -71
  48. package/lib/esm/validation/Validators/DateValidator.d.ts +0 -28
  49. package/lib/esm/validation/Validators/DateValidator.js +0 -53
  50. package/lib/esm/validation/Validators/EmailValidator.d.ts +0 -28
  51. package/lib/esm/validation/Validators/EmailValidator.js +0 -48
  52. package/lib/esm/validation/Validators/ListValidator.d.ts +0 -28
  53. package/lib/esm/validation/Validators/ListValidator.js +0 -66
  54. package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +0 -29
  55. package/lib/esm/validation/Validators/MaxLengthValidator.js +0 -53
  56. package/lib/esm/validation/Validators/MaxValidator.d.ts +0 -28
  57. package/lib/esm/validation/Validators/MaxValidator.js +0 -57
  58. package/lib/esm/validation/Validators/MinLengthValidator.d.ts +0 -29
  59. package/lib/esm/validation/Validators/MinLengthValidator.js +0 -53
  60. package/lib/esm/validation/Validators/MinValidator.d.ts +0 -28
  61. package/lib/esm/validation/Validators/MinValidator.js +0 -57
  62. package/lib/esm/validation/Validators/PasswordValidator.d.ts +0 -28
  63. package/lib/esm/validation/Validators/PasswordValidator.js +0 -48
  64. package/lib/esm/validation/Validators/PatternValidator.d.ts +0 -37
  65. package/lib/esm/validation/Validators/PatternValidator.js +0 -70
  66. package/lib/esm/validation/Validators/RequiredValidator.d.ts +0 -27
  67. package/lib/esm/validation/Validators/RequiredValidator.js +0 -55
  68. package/lib/esm/validation/Validators/StepValidator.d.ts +0 -28
  69. package/lib/esm/validation/Validators/StepValidator.js +0 -52
  70. package/lib/esm/validation/Validators/TypeValidator.d.ts +0 -27
  71. package/lib/esm/validation/Validators/TypeValidator.js +0 -60
  72. package/lib/esm/validation/Validators/URLValidator.d.ts +0 -26
  73. package/lib/esm/validation/Validators/URLValidator.js +0 -46
  74. package/lib/esm/validation/Validators/Validator.d.ts +0 -40
  75. package/lib/esm/validation/Validators/Validator.js +0 -47
  76. package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -47
  77. package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -80
  78. package/lib/esm/validation/Validators/constants.d.ts +0 -96
  79. package/lib/esm/validation/Validators/constants.js +0 -134
  80. package/lib/esm/validation/Validators/decorators.d.ts +0 -12
  81. package/lib/esm/validation/Validators/decorators.js +0 -25
  82. package/lib/esm/validation/Validators/index.d.ts +0 -52
  83. package/lib/esm/validation/Validators/index.js +0 -52
  84. package/lib/esm/validation/Validators/types.d.ts +0 -51
  85. package/lib/esm/validation/Validators/types.js +0 -1
  86. package/lib/esm/validation/decorators.d.ts +0 -178
  87. package/lib/esm/validation/decorators.js +0 -288
  88. package/lib/esm/validation/index.d.ts +0 -4
  89. package/lib/esm/validation/index.js +0 -4
  90. package/lib/esm/validation/types.d.ts +0 -46
  91. package/lib/esm/validation/types.js +0 -1
  92. package/lib/index.cjs +0 -59
  93. package/lib/index.d.ts +0 -42
  94. package/lib/model/Model.cjs +0 -301
  95. package/lib/model/Model.d.ts +0 -139
  96. package/lib/model/ModelErrorDefinition.cjs +0 -56
  97. package/lib/model/ModelErrorDefinition.d.ts +0 -22
  98. package/lib/model/Registry.cjs +0 -78
  99. package/lib/model/Registry.d.ts +0 -59
  100. package/lib/model/constants.cjs +0 -72
  101. package/lib/model/constants.d.ts +0 -56
  102. package/lib/model/construction.cjs +0 -68
  103. package/lib/model/construction.d.ts +0 -29
  104. package/lib/model/decorators.cjs +0 -67
  105. package/lib/model/decorators.d.ts +0 -25
  106. package/lib/model/index.cjs +0 -25
  107. package/lib/model/index.d.ts +0 -9
  108. package/lib/model/types.cjs +0 -2
  109. package/lib/model/types.d.ts +0 -79
  110. package/lib/model/utils.cjs +0 -29
  111. package/lib/model/utils.d.ts +0 -11
  112. package/lib/model/validation.cjs +0 -137
  113. package/lib/model/validation.d.ts +0 -14
  114. package/lib/utils/constants.cjs +0 -30
  115. package/lib/utils/constants.d.ts +0 -26
  116. package/lib/utils/dates.cjs +0 -251
  117. package/lib/utils/dates.d.ts +0 -76
  118. package/lib/utils/decorators.cjs +0 -22
  119. package/lib/utils/decorators.d.ts +0 -2
  120. package/lib/utils/hashing.cjs +0 -106
  121. package/lib/utils/hashing.d.ts +0 -52
  122. package/lib/utils/index.cjs +0 -23
  123. package/lib/utils/index.d.ts +0 -7
  124. package/lib/utils/registry.cjs +0 -2
  125. package/lib/utils/registry.d.ts +0 -68
  126. package/lib/utils/serialization.cjs +0 -93
  127. package/lib/utils/serialization.d.ts +0 -79
  128. package/lib/utils/strings.cjs +0 -35
  129. package/lib/utils/strings.d.ts +0 -25
  130. package/lib/validation/Validation.cjs +0 -75
  131. package/lib/validation/Validation.d.ts +0 -51
  132. package/lib/validation/Validators/DateValidator.cjs +0 -56
  133. package/lib/validation/Validators/DateValidator.d.ts +0 -28
  134. package/lib/validation/Validators/EmailValidator.cjs +0 -51
  135. package/lib/validation/Validators/EmailValidator.d.ts +0 -28
  136. package/lib/validation/Validators/ListValidator.cjs +0 -69
  137. package/lib/validation/Validators/ListValidator.d.ts +0 -28
  138. package/lib/validation/Validators/MaxLengthValidator.cjs +0 -56
  139. package/lib/validation/Validators/MaxLengthValidator.d.ts +0 -29
  140. package/lib/validation/Validators/MaxValidator.cjs +0 -60
  141. package/lib/validation/Validators/MaxValidator.d.ts +0 -28
  142. package/lib/validation/Validators/MinLengthValidator.cjs +0 -56
  143. package/lib/validation/Validators/MinLengthValidator.d.ts +0 -29
  144. package/lib/validation/Validators/MinValidator.cjs +0 -60
  145. package/lib/validation/Validators/MinValidator.d.ts +0 -28
  146. package/lib/validation/Validators/PasswordValidator.cjs +0 -51
  147. package/lib/validation/Validators/PasswordValidator.d.ts +0 -28
  148. package/lib/validation/Validators/PatternValidator.cjs +0 -73
  149. package/lib/validation/Validators/PatternValidator.d.ts +0 -37
  150. package/lib/validation/Validators/RequiredValidator.cjs +0 -58
  151. package/lib/validation/Validators/RequiredValidator.d.ts +0 -27
  152. package/lib/validation/Validators/StepValidator.cjs +0 -55
  153. package/lib/validation/Validators/StepValidator.d.ts +0 -28
  154. package/lib/validation/Validators/TypeValidator.cjs +0 -63
  155. package/lib/validation/Validators/TypeValidator.d.ts +0 -27
  156. package/lib/validation/Validators/URLValidator.cjs +0 -49
  157. package/lib/validation/Validators/URLValidator.d.ts +0 -26
  158. package/lib/validation/Validators/Validator.cjs +0 -51
  159. package/lib/validation/Validators/Validator.d.ts +0 -40
  160. package/lib/validation/Validators/ValidatorRegistry.cjs +0 -85
  161. package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -47
  162. package/lib/validation/Validators/constants.cjs +0 -137
  163. package/lib/validation/Validators/constants.d.ts +0 -96
  164. package/lib/validation/Validators/decorators.cjs +0 -28
  165. package/lib/validation/Validators/decorators.d.ts +0 -12
  166. package/lib/validation/Validators/index.cjs +0 -69
  167. package/lib/validation/Validators/types.cjs +0 -2
  168. package/lib/validation/decorators.cjs +0 -304
  169. package/lib/validation/decorators.d.ts +0 -178
  170. package/lib/validation/index.cjs +0 -20
  171. package/lib/validation/index.d.ts +0 -4
  172. package/lib/validation/types.cjs +0 -2
  173. package/lib/validation/types.d.ts +0 -46
@@ -1,69 +0,0 @@
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.cjs");
19
- const TypeValidator_1 = require("./TypeValidator.cjs");
20
- const PasswordValidator_1 = require("./PasswordValidator.cjs");
21
- const StepValidator_1 = require("./StepValidator.cjs");
22
- const URLValidator_1 = require("./URLValidator.cjs");
23
- const PatternValidator_1 = require("./PatternValidator.cjs");
24
- const MinValidator_1 = require("./MinValidator.cjs");
25
- const MinLengthValidator_1 = require("./MinLengthValidator.cjs");
26
- const MaxValidator_1 = require("./MaxValidator.cjs");
27
- const MaxLengthValidator_1 = require("./MaxLengthValidator.cjs");
28
- const RequiredValidator_1 = require("./RequiredValidator.cjs");
29
- const EmailValidator_1 = require("./EmailValidator.cjs");
30
- const ListValidator_1 = require("./ListValidator.cjs");
31
- __exportStar(require("./constants.cjs"), exports);
32
- __exportStar(require("./DateValidator.cjs"), exports);
33
- __exportStar(require("./decorators.cjs"), exports);
34
- __exportStar(require("./EmailValidator.cjs"), exports);
35
- __exportStar(require("./ListValidator.cjs"), exports);
36
- __exportStar(require("./MaxLengthValidator.cjs"), exports);
37
- __exportStar(require("./MaxValidator.cjs"), exports);
38
- __exportStar(require("./MinLengthValidator.cjs"), exports);
39
- __exportStar(require("./MinValidator.cjs"), exports);
40
- __exportStar(require("./PasswordValidator.cjs"), exports);
41
- __exportStar(require("./PatternValidator.cjs"), exports);
42
- __exportStar(require("./RequiredValidator.cjs"), exports);
43
- __exportStar(require("./StepValidator.cjs"), exports);
44
- __exportStar(require("./types.cjs"), exports);
45
- __exportStar(require("./TypeValidator.cjs"), exports);
46
- __exportStar(require("./URLValidator.cjs"), exports);
47
- __exportStar(require("./Validator.cjs"), exports);
48
- __exportStar(require("./ValidatorRegistry.cjs"), 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
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,304 +0,0 @@
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.cjs");
19
- const strings_1 = require("../utils/strings.cjs");
20
- const dates_1 = require("../utils/dates.cjs");
21
- const decorators_1 = require("../utils/decorators.cjs");
22
- const Validation_1 = require("./Validation.cjs");
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
- value: 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
- value: 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
- value: 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
- value: 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
- value: 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
- value: 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
- class: 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
- }
@@ -1,178 +0,0 @@
1
- import "reflect-metadata";
2
- import { ModelConstructor } from "../model/types";
3
- /**
4
- * @summary Marks the property as required.
5
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#REQUIRED}
6
- *
7
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#REQUIRED}
8
- *
9
- * @function required
10
- *
11
- * @category Decorators
12
- */
13
- export declare function required(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
14
- /**
15
- * @summary Defines a minimum value for the property
16
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN}
17
- *
18
- * @param {number | Date} value
19
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN}
20
- *
21
- * @function min
22
- * @memberOf module:decorator-validation.Decorators.Validation
23
- * @category Decorators
24
- */
25
- export declare function min(value: number | Date | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
26
- /**
27
- * @summary Defines a maximum value for the property
28
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX}
29
- *
30
- * @param {number | Date} value
31
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
32
- *
33
- * @function max
34
- * @memberOf module:decorator-validation.Decorators.Validation
35
- * @category Decorators
36
- */
37
- export declare function max(value: number | Date | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
38
- /**
39
- * @summary Defines a step value for the property
40
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#STEP}
41
- *
42
- * @param {number} value
43
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#STEP}
44
- *
45
- * @function step
46
- * @memberOf module:decorator-validation.Decorators.Validation
47
- * @category Decorators
48
- */
49
- export declare function step(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
50
- /**
51
- * @summary Defines a minimum length for the property
52
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#MIN_LENGTH}
53
- *
54
- * @param {string} value
55
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MIN_LENGTH}
56
- *
57
- * @function minlength
58
- * @memberOf module:decorator-validation.Decorators.Validation
59
- * @category Decorators
60
- */
61
- export declare function minlength(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
62
- /**
63
- * @summary Defines a maximum length for the property
64
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#MAX_LENGTH}
65
- *
66
- * @param {string} value
67
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
68
- *
69
- * @function maxlength
70
- * @memberOf module:decorator-validation.Decorators.Validation
71
- * @category Decorators
72
- */
73
- export declare function maxlength(value: number, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
74
- /**
75
- * @summary Defines a RegExp pattern the property must respect
76
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#PATTERN}
77
- *
78
- * @param {string} value
79
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PATTERN}
80
- *
81
- * @function pattern
82
- * @memberOf module:decorator-validation.Decorators.Validation
83
- * @category Decorators
84
- */
85
- export declare function pattern(value: RegExp | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
86
- /**
87
- * @summary Defines the property as an email
88
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#EMAIL}
89
- *
90
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
91
- *
92
- * @function email
93
- * @memberOf module:decorator-validation.Decorators.Validation
94
- * @category Decorators
95
- */
96
- export declare function email(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
97
- /**
98
- * @summary Defines the property as an URL
99
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#URL}
100
- *
101
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#URL}
102
- *
103
- * @function url
104
- * @memberOf module:decorator-validation.Decorators.Validation
105
- * @category Decorators
106
- */
107
- export declare function url(message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
108
- /**
109
- * @summary Enforces type verification
110
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#TYPE}
111
- *
112
- * @param {string[] | string} types accepted types
113
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#TYPE}
114
- *
115
- * @function type
116
- * @memberOf module:decorator-validation.Decorators.Validation
117
- * @category Decorators
118
- */
119
- export declare function type(types: string[] | string, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
120
- /**
121
- * @summary Date Handler Decorator
122
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#DATE}
123
- *
124
- * Will enforce serialization according to the selected format
125
- *
126
- * @param {string} format accepted format according to {@link formatDate}
127
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
128
- * @param {Constructor<Validator>} [validator] the Validator to be used. Defaults to {@link DateValidator}
129
- *
130
- * @function date
131
- *
132
- * @memberOf module:decorator-validation.Decorators.Validation
133
- * @category Decorators
134
- */
135
- export declare function date(format?: string, message?: string): (target: Record<string, any>, propertyKey?: any) => any;
136
- /**
137
- * @summary Password Handler Decorator
138
- * @description Validators to validate a decorated property must use key {@link ValidationKeys#PASSWORD}
139
- *
140
- * @param {RegExp} [pattern] defaults to {@link PasswordPatterns#CHAR8_ONE_OF_EACH}
141
- * @param {string} [message] the error message. Defaults to {@link DEFAULT_ERROR_MESSAGES#PASSWORD}
142
- * @param {Constructor<Validator>} [validator] Defaults to {@link PasswordValidator}
143
- *
144
- * @function password
145
- *
146
- * @memberOf module:decorator-validation.Decorators.Validation
147
- * @category Decorators
148
- */
149
- export declare function password(pattern?: RegExp, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
150
- /**
151
- * @summary List Decorator
152
- * @description Also sets the {@link type} to the provided collection
153
- *
154
- * @param {ModelConstructor} clazz
155
- * @param {string} [collection] The collection being used. defaults to Array
156
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
157
- * @param {Constructor<Validator>} [validator] defaults to {@link ListValidator}
158
- *
159
- * @function list
160
- *
161
- * @memberOf module:decorator-validation.Decorators.Validation
162
- * @category Decorators
163
- */
164
- export declare function list(clazz: ModelConstructor<any> | ModelConstructor<any>[], collection?: "Array" | "Set", message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
165
- /**
166
- * @summary Set Decorator
167
- * @description Wrapper for {@link list} with the 'Set' Collection
168
- *
169
- * @param {ModelConstructor} clazz
170
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
171
- * @param {Constructor<Validator>} [validator]
172
- *
173
- * @function set
174
- *
175
- * @memberOf module:decorator-validation.Decorators.Validation
176
- * @category Decorators
177
- */
178
- export declare function set(clazz: ModelConstructor<any>, message?: string): (target: object, propertyKey?: string | symbol | unknown, descriptor?: PropertyDescriptor) => void;
@@ -1,20 +0,0 @@
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/index.cjs"), exports);
18
- __exportStar(require("./decorators.cjs"), exports);
19
- __exportStar(require("./types.cjs"), exports);
20
- __exportStar(require("./Validation.cjs"), exports);
@@ -1,4 +0,0 @@
1
- export * from "./Validators";
2
- export * from "./decorators";
3
- export * from "./types";
4
- export * from "./Validation";
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,46 +0,0 @@
1
- import { DecoratorMetadata } from "@decaf-ts/reflection";
2
- /**
3
- * @summary Type for validation decorator metadata
4
- * @memberOf module:decorator-validation.Reflection
5
- * @category Reflection
6
- */
7
- export type ValidationMetadata = {
8
- [indexer: string]: any;
9
- args?: any[];
10
- message: string;
11
- types?: string[];
12
- };
13
- /**
14
- * @summary Type for a validator property decorator definition
15
- * @memberOf module:decorator-validation.Validation
16
- * @category Validation
17
- */
18
- export type ValidationPropertyDecoratorDefinition = {
19
- prop: string | symbol;
20
- decorators: ValidationDecoratorDefinition[];
21
- };
22
- /**
23
- * @summary Type for a validator decorator definition
24
- * @memberOf module:decorator-validation.Validation
25
- * @category Validation
26
- */
27
- export type ValidationDecoratorDefinition = DecoratorMetadata & {
28
- props: ValidationElementDefinition;
29
- };
30
- /**
31
- * @summary Type for a validator element metadata
32
- * @memberOf module:decorator-validation.Validation
33
- * @category Validation
34
- */
35
- export type ValidationElementDefinition = {
36
- [indexer: string]: any;
37
- value?: string | number;
38
- message: string;
39
- types?: string[];
40
- };
41
- /**
42
- * @summary Type for a model errors
43
- * @memberOf module:decorator-validation.Validation
44
- * @category Validation
45
- */
46
- export type ModelErrors = Record<string, Record<string, string | undefined>>;