@decaf-ts/decorator-validation 1.4.21 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/LICENSE.md +0 -0
  2. package/README.md +0 -0
  3. package/dist/decorator-validation.bundle.min.js +1 -1
  4. package/dist/decorator-validation.bundle.min.js.LICENSE.txt +0 -0
  5. package/dist/esm/decorator-validation.bundle.min.esm.js +1 -1
  6. package/dist/esm/decorator-validation.bundle.min.esm.js.LICENSE.txt +0 -0
  7. package/lib/esm/index.d.ts +1 -1
  8. package/lib/esm/index.js +1 -1
  9. package/lib/esm/model/Model.d.ts +1 -2
  10. package/lib/esm/model/Model.js +3 -4
  11. package/lib/esm/model/ModelErrorDefinition.d.ts +0 -0
  12. package/lib/esm/model/ModelErrorDefinition.js +0 -0
  13. package/lib/esm/model/Registry.d.ts +0 -0
  14. package/lib/esm/model/Registry.js +0 -0
  15. package/lib/esm/model/constants.d.ts +0 -0
  16. package/lib/esm/model/constants.js +0 -0
  17. package/lib/esm/model/construction.d.ts +0 -0
  18. package/lib/esm/model/construction.js +0 -0
  19. package/lib/esm/model/decorators.d.ts +0 -0
  20. package/lib/esm/model/decorators.js +0 -0
  21. package/lib/esm/model/index.d.ts +0 -0
  22. package/lib/esm/model/index.js +0 -0
  23. package/lib/esm/model/types.d.ts +0 -0
  24. package/lib/esm/model/types.js +0 -0
  25. package/lib/esm/model/utils.d.ts +0 -0
  26. package/lib/esm/model/utils.js +0 -0
  27. package/lib/esm/model/validation.d.ts +0 -0
  28. package/lib/esm/model/validation.js +3 -2
  29. package/lib/esm/utils/constants.d.ts +0 -0
  30. package/lib/esm/utils/constants.js +0 -0
  31. package/lib/esm/utils/dates.d.ts +0 -0
  32. package/lib/esm/utils/dates.js +0 -0
  33. package/lib/esm/utils/decorators.d.ts +0 -0
  34. package/lib/esm/utils/decorators.js +0 -0
  35. package/lib/esm/utils/hashing.d.ts +0 -0
  36. package/lib/esm/utils/hashing.js +0 -0
  37. package/lib/esm/utils/index.d.ts +0 -0
  38. package/lib/esm/utils/index.js +0 -0
  39. package/lib/esm/utils/registry.d.ts +0 -0
  40. package/lib/esm/utils/registry.js +0 -0
  41. package/lib/esm/utils/serialization.d.ts +0 -0
  42. package/lib/esm/utils/serialization.js +0 -0
  43. package/lib/esm/utils/strings.d.ts +0 -0
  44. package/lib/esm/utils/strings.js +0 -0
  45. package/lib/esm/validation/Validation.d.ts +0 -0
  46. package/lib/esm/validation/Validation.js +0 -0
  47. package/lib/esm/validation/Validators/DateValidator.d.ts +7 -5
  48. package/lib/esm/validation/Validators/DateValidator.js +6 -5
  49. package/lib/esm/validation/Validators/EmailValidator.d.ts +3 -4
  50. package/lib/esm/validation/Validators/EmailValidator.js +7 -5
  51. package/lib/esm/validation/Validators/ListValidator.d.ts +7 -5
  52. package/lib/esm/validation/Validators/ListValidator.js +4 -5
  53. package/lib/esm/validation/Validators/MaxLengthValidator.d.ts +7 -5
  54. package/lib/esm/validation/Validators/MaxLengthValidator.js +4 -5
  55. package/lib/esm/validation/Validators/MaxValidator.d.ts +7 -5
  56. package/lib/esm/validation/Validators/MaxValidator.js +5 -5
  57. package/lib/esm/validation/Validators/MinLengthValidator.d.ts +7 -5
  58. package/lib/esm/validation/Validators/MinLengthValidator.js +5 -6
  59. package/lib/esm/validation/Validators/MinValidator.d.ts +7 -5
  60. package/lib/esm/validation/Validators/MinValidator.js +5 -5
  61. package/lib/esm/validation/Validators/PasswordValidator.d.ts +3 -4
  62. package/lib/esm/validation/Validators/PasswordValidator.js +6 -4
  63. package/lib/esm/validation/Validators/PatternValidator.d.ts +7 -5
  64. package/lib/esm/validation/Validators/PatternValidator.js +5 -5
  65. package/lib/esm/validation/Validators/RequiredValidator.d.ts +3 -3
  66. package/lib/esm/validation/Validators/RequiredValidator.js +7 -5
  67. package/lib/esm/validation/Validators/StepValidator.d.ts +7 -4
  68. package/lib/esm/validation/Validators/StepValidator.js +5 -5
  69. package/lib/esm/validation/Validators/TypeValidator.d.ts +9 -7
  70. package/lib/esm/validation/Validators/TypeValidator.js +4 -4
  71. package/lib/esm/validation/Validators/URLValidator.d.ts +9 -3
  72. package/lib/esm/validation/Validators/URLValidator.js +3 -3
  73. package/lib/esm/validation/Validators/Validator.d.ts +6 -3
  74. package/lib/esm/validation/Validators/Validator.js +0 -0
  75. package/lib/esm/validation/Validators/ValidatorRegistry.d.ts +0 -0
  76. package/lib/esm/validation/Validators/ValidatorRegistry.js +0 -0
  77. package/lib/esm/validation/Validators/constants.d.ts +0 -0
  78. package/lib/esm/validation/Validators/constants.js +0 -0
  79. package/lib/esm/validation/Validators/decorators.d.ts +0 -0
  80. package/lib/esm/validation/Validators/decorators.js +0 -0
  81. package/lib/esm/validation/Validators/index.d.ts +0 -0
  82. package/lib/esm/validation/Validators/index.js +0 -0
  83. package/lib/esm/validation/Validators/types.d.ts +0 -0
  84. package/lib/esm/validation/Validators/types.js +0 -0
  85. package/lib/esm/validation/decorators.d.ts +0 -0
  86. package/lib/esm/validation/decorators.js +7 -7
  87. package/lib/esm/validation/index.d.ts +0 -0
  88. package/lib/esm/validation/index.js +0 -0
  89. package/lib/esm/validation/types.d.ts +0 -0
  90. package/lib/esm/validation/types.js +0 -0
  91. package/lib/index.cjs +1 -1
  92. package/lib/index.d.ts +1 -1
  93. package/lib/model/Model.cjs +3 -4
  94. package/lib/model/Model.d.ts +1 -2
  95. package/lib/model/ModelErrorDefinition.cjs +0 -0
  96. package/lib/model/ModelErrorDefinition.d.ts +0 -0
  97. package/lib/model/Registry.cjs +0 -0
  98. package/lib/model/Registry.d.ts +0 -0
  99. package/lib/model/constants.cjs +0 -0
  100. package/lib/model/constants.d.ts +0 -0
  101. package/lib/model/construction.cjs +0 -0
  102. package/lib/model/construction.d.ts +0 -0
  103. package/lib/model/decorators.cjs +0 -0
  104. package/lib/model/decorators.d.ts +0 -0
  105. package/lib/model/index.cjs +0 -0
  106. package/lib/model/index.d.ts +0 -0
  107. package/lib/model/types.cjs +0 -0
  108. package/lib/model/types.d.ts +0 -0
  109. package/lib/model/utils.cjs +0 -0
  110. package/lib/model/utils.d.ts +0 -0
  111. package/lib/model/validation.cjs +3 -2
  112. package/lib/model/validation.d.ts +0 -0
  113. package/lib/utils/constants.cjs +0 -0
  114. package/lib/utils/constants.d.ts +0 -0
  115. package/lib/utils/dates.cjs +0 -0
  116. package/lib/utils/dates.d.ts +0 -0
  117. package/lib/utils/decorators.cjs +0 -0
  118. package/lib/utils/decorators.d.ts +0 -0
  119. package/lib/utils/hashing.cjs +0 -0
  120. package/lib/utils/hashing.d.ts +0 -0
  121. package/lib/utils/index.cjs +0 -0
  122. package/lib/utils/index.d.ts +0 -0
  123. package/lib/utils/registry.cjs +0 -0
  124. package/lib/utils/registry.d.ts +0 -0
  125. package/lib/utils/serialization.cjs +0 -0
  126. package/lib/utils/serialization.d.ts +0 -0
  127. package/lib/utils/strings.cjs +0 -0
  128. package/lib/utils/strings.d.ts +0 -0
  129. package/lib/validation/Validation.cjs +0 -0
  130. package/lib/validation/Validation.d.ts +0 -0
  131. package/lib/validation/Validators/DateValidator.cjs +5 -4
  132. package/lib/validation/Validators/DateValidator.d.ts +7 -5
  133. package/lib/validation/Validators/EmailValidator.cjs +6 -4
  134. package/lib/validation/Validators/EmailValidator.d.ts +3 -4
  135. package/lib/validation/Validators/ListValidator.cjs +4 -5
  136. package/lib/validation/Validators/ListValidator.d.ts +7 -5
  137. package/lib/validation/Validators/MaxLengthValidator.cjs +4 -5
  138. package/lib/validation/Validators/MaxLengthValidator.d.ts +7 -5
  139. package/lib/validation/Validators/MaxValidator.cjs +4 -4
  140. package/lib/validation/Validators/MaxValidator.d.ts +7 -5
  141. package/lib/validation/Validators/MinLengthValidator.cjs +4 -5
  142. package/lib/validation/Validators/MinLengthValidator.d.ts +7 -5
  143. package/lib/validation/Validators/MinValidator.cjs +4 -4
  144. package/lib/validation/Validators/MinValidator.d.ts +7 -5
  145. package/lib/validation/Validators/PasswordValidator.cjs +6 -4
  146. package/lib/validation/Validators/PasswordValidator.d.ts +3 -4
  147. package/lib/validation/Validators/PatternValidator.cjs +4 -4
  148. package/lib/validation/Validators/PatternValidator.d.ts +7 -5
  149. package/lib/validation/Validators/RequiredValidator.cjs +6 -4
  150. package/lib/validation/Validators/RequiredValidator.d.ts +3 -3
  151. package/lib/validation/Validators/StepValidator.cjs +4 -4
  152. package/lib/validation/Validators/StepValidator.d.ts +7 -4
  153. package/lib/validation/Validators/TypeValidator.cjs +4 -4
  154. package/lib/validation/Validators/TypeValidator.d.ts +9 -7
  155. package/lib/validation/Validators/URLValidator.cjs +3 -3
  156. package/lib/validation/Validators/URLValidator.d.ts +9 -3
  157. package/lib/validation/Validators/Validator.cjs +0 -0
  158. package/lib/validation/Validators/Validator.d.ts +6 -3
  159. package/lib/validation/Validators/ValidatorRegistry.cjs +0 -0
  160. package/lib/validation/Validators/ValidatorRegistry.d.ts +0 -0
  161. package/lib/validation/Validators/constants.cjs +0 -0
  162. package/lib/validation/Validators/constants.d.ts +0 -0
  163. package/lib/validation/Validators/decorators.cjs +0 -0
  164. package/lib/validation/Validators/index.cjs +0 -0
  165. package/lib/validation/Validators/types.cjs +0 -0
  166. package/lib/validation/decorators.cjs +7 -7
  167. package/lib/validation/decorators.d.ts +0 -0
  168. package/lib/validation/index.cjs +0 -0
  169. package/lib/validation/index.d.ts +0 -0
  170. package/lib/validation/types.cjs +0 -0
  171. package/lib/validation/types.d.ts +0 -0
  172. package/package.json +1 -1
  173. package/lib/validation/Validators/decorators.d.ts +0 -12
@@ -28,8 +28,7 @@ let TypeValidator = class TypeValidator extends Validator {
28
28
  /**
29
29
  * @summary Validates a model
30
30
  * @param {string} value
31
- * @param {string | string[] | {name: string}} types
32
- * @param {string} [message]
31
+ * @param {TypeValidatorOptions} options
33
32
  *
34
33
  * @return {string | undefined}
35
34
  *
@@ -37,9 +36,10 @@ let TypeValidator = class TypeValidator extends Validator {
37
36
  *
38
37
  * @see Validator#hasErrors
39
38
  */
40
- hasErrors(value, types, message) {
39
+ hasErrors(value, options) {
41
40
  if (value === undefined)
42
- return; // Dont try and enforce type if undefined
41
+ return; // Don't try and enforce type if undefined
42
+ const { types, message } = options;
43
43
  if (!Reflection.evaluateDesignTypes(value, types))
44
44
  return this.getMessage(message || this.message, typeof types === "string"
45
45
  ? types
@@ -1,4 +1,10 @@
1
- import { PatternValidator } from "./PatternValidator";
1
+ import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
2
+ import { ValidatorOptions } from "./Validator";
3
+ export interface URLValidatorOptions extends ValidatorOptions {
4
+ types: string | string[] | {
5
+ name: string;
6
+ };
7
+ }
2
8
  /**
3
9
  * @summary URL Validator
4
10
  * @description Pattern from {@link https://gist.github.com/dperini/729294}
@@ -14,7 +20,7 @@ export declare class URLValidator extends PatternValidator {
14
20
  * @summary Validates a model
15
21
  *
16
22
  * @param {string} value
17
- * @param {string} [message]
23
+ * @param {PatternValidatorOptions} [options={}]
18
24
  *
19
25
  * @return {string | undefined}
20
26
  *
@@ -22,5 +28,5 @@ export declare class URLValidator extends PatternValidator {
22
28
  *
23
29
  * @see Validator#hasErrors
24
30
  */
25
- hasErrors(value: string, pattern?: RegExp, message?: string): string | undefined;
31
+ hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
26
32
  }
@@ -27,7 +27,7 @@ let URLValidator = class URLValidator extends PatternValidator {
27
27
  * @summary Validates a model
28
28
  *
29
29
  * @param {string} value
30
- * @param {string} [message]
30
+ * @param {PatternValidatorOptions} [options={}]
31
31
  *
32
32
  * @return {string | undefined}
33
33
  *
@@ -35,8 +35,8 @@ let URLValidator = class URLValidator extends PatternValidator {
35
35
  *
36
36
  * @see Validator#hasErrors
37
37
  */
38
- hasErrors(value, pattern, message) {
39
- return super.hasErrors(value, pattern || DEFAULT_PATTERNS.URL, message);
38
+ hasErrors(value, options = {}) {
39
+ return super.hasErrors(value, { ...options, pattern: options.pattern || DEFAULT_PATTERNS.URL });
40
40
  }
41
41
  };
42
42
  URLValidator = __decorate([
@@ -1,3 +1,6 @@
1
+ export type ValidatorOptions = {
2
+ message?: string;
3
+ };
1
4
  /**
2
5
  * @summary Base Implementation for Validators
3
6
  * @description Provides the underlying functionality for {@link Validator}s
@@ -10,7 +13,7 @@
10
13
  * @abstract
11
14
  * @category Validators
12
15
  */
13
- export declare abstract class Validator {
16
+ export declare abstract class Validator<V extends ValidatorOptions = ValidatorOptions> {
14
17
  readonly message: string;
15
18
  readonly acceptedTypes?: string[];
16
19
  protected constructor(message?: string, ...acceptedTypes: string[]);
@@ -30,11 +33,11 @@ export declare abstract class Validator {
30
33
  /**
31
34
  * @summary Validates an attribute
32
35
  * @param {any} value
33
- * @param {any[]} args
36
+ * @param {ValidatorOptions} [options] Validate options for customizing the model validation behavior
34
37
  *
35
38
  * @abstract
36
39
  *
37
40
  * @see Model#hasErrors
38
41
  */
39
- abstract hasErrors(value: any, ...args: any[]): string | undefined;
42
+ abstract hasErrors(value: any, options?: V): string | undefined;
40
43
  }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -32,7 +32,7 @@ export function required(message = DEFAULT_ERROR_MESSAGES.REQUIRED) {
32
32
  */
33
33
  export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
34
34
  return propMetadata(Validation.key(ValidationKeys.MIN), {
35
- value: value,
35
+ min: value,
36
36
  message: message,
37
37
  types: [Number.name, Date.name],
38
38
  });
@@ -50,7 +50,7 @@ export function min(value, message = DEFAULT_ERROR_MESSAGES.MIN) {
50
50
  */
51
51
  export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
52
52
  return propMetadata(Validation.key(ValidationKeys.MAX), {
53
- value: value,
53
+ max: value,
54
54
  message: message,
55
55
  types: [Number.name, Date.name],
56
56
  });
@@ -68,7 +68,7 @@ export function max(value, message = DEFAULT_ERROR_MESSAGES.MAX) {
68
68
  */
69
69
  export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
70
70
  return propMetadata(Validation.key(ValidationKeys.STEP), {
71
- value: value,
71
+ step: value,
72
72
  message: message,
73
73
  types: [Number.name],
74
74
  });
@@ -86,7 +86,7 @@ export function step(value, message = DEFAULT_ERROR_MESSAGES.STEP) {
86
86
  */
87
87
  export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
88
88
  return propMetadata(Validation.key(ValidationKeys.MIN_LENGTH), {
89
- value: value,
89
+ minLength: value,
90
90
  message: message,
91
91
  types: [String.name, Array.name, Set.name],
92
92
  });
@@ -104,7 +104,7 @@ export function minlength(value, message = DEFAULT_ERROR_MESSAGES.MIN_LENGTH) {
104
104
  */
105
105
  export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
106
106
  return propMetadata(Validation.key(ValidationKeys.MAX_LENGTH), {
107
- value: value,
107
+ maxLength: value,
108
108
  message: message,
109
109
  types: [String.name, Array.name, Set.name],
110
110
  });
@@ -122,7 +122,7 @@ export function maxlength(value, message = DEFAULT_ERROR_MESSAGES.MAX_LENGTH) {
122
122
  */
123
123
  export function pattern(value, message = DEFAULT_ERROR_MESSAGES.PATTERN) {
124
124
  return propMetadata(Validation.key(ValidationKeys.PATTERN), {
125
- value: typeof value === "string" ? value : value.toString(),
125
+ pattern: typeof value === "string" ? value : value.toString(),
126
126
  message: message,
127
127
  types: [String.name],
128
128
  });
@@ -265,7 +265,7 @@ export function password(pattern = DEFAULT_PATTERNS.PASSWORD.CHAR8_ONE_OF_EACH,
265
265
  */
266
266
  export function list(clazz, collection = "Array", message = DEFAULT_ERROR_MESSAGES.LIST) {
267
267
  return propMetadata(Validation.key(ValidationKeys.LIST), {
268
- class: Array.isArray(clazz) ? clazz.map((c) => c.name) : [clazz.name],
268
+ clazz: Array.isArray(clazz) ? clazz.map((c) => c.name) : [clazz.name],
269
269
  type: collection,
270
270
  message: message,
271
271
  });
File without changes
File without changes
File without changes
File without changes
package/lib/index.cjs CHANGED
@@ -56,4 +56,4 @@ exports.VERSION = void 0;
56
56
  __exportStar(require("./utils/index.cjs"), exports);
57
57
  __exportStar(require("./validation/index.cjs"), exports);
58
58
  __exportStar(require("./model/index.cjs"), exports);
59
- exports.VERSION = "1.4.20";
59
+ exports.VERSION = "1.5.0";
package/lib/index.d.ts CHANGED
@@ -39,4 +39,4 @@
39
39
  export * from "./utils";
40
40
  export * from "./validation";
41
41
  export * from "./model";
42
- export declare const VERSION = "1.4.20";
42
+ export declare const VERSION = "1.5.0";
@@ -78,7 +78,6 @@ class Model {
78
78
  * @summary Deserializes a Model
79
79
  * @param {string} str
80
80
  *
81
- * @param args
82
81
  * @throws {Error} If it fails to parse the string, or if it fails to build the model
83
82
  */
84
83
  static deserialize(str) {
@@ -153,7 +152,7 @@ class Model {
153
152
  if (allDecorators.length) {
154
153
  const listDec = allDecorators.find((d) => d.key === constants_2.ValidationKeys.LIST);
155
154
  if (listDec) {
156
- const clazzName = listDec.props.class.find((t) => !constants_3.jsTypes.includes(t.toLowerCase()));
155
+ const clazzName = listDec.props.clazz.find((t) => !constants_3.jsTypes.includes(t.toLowerCase()));
157
156
  if (c === "Array")
158
157
  self[prop] = self[prop].map((el) => {
159
158
  return ["object", "function"].includes(typeof el) &&
@@ -274,8 +273,8 @@ class Model {
274
273
  static equals(obj1, obj2, ...exceptions) {
275
274
  return (0, reflection_1.isEqual)(obj1, obj2, ...exceptions);
276
275
  }
277
- static hasErrors(model, ...exceptions) {
278
- return (0, validation_1.validate)(model, ...exceptions);
276
+ static hasErrors(model, ...propsToIgnore) {
277
+ return (0, validation_1.validate)(model, ...propsToIgnore);
279
278
  }
280
279
  static serialize(model) {
281
280
  const metadata = Reflect.getMetadata(Model.key(constants_1.ModelKeys.SERIALIZATION), model.constructor);
@@ -55,7 +55,6 @@ export declare abstract class Model implements Validatable, Serializable, Hashab
55
55
  * @summary Deserializes a Model
56
56
  * @param {string} str
57
57
  *
58
- * @param args
59
58
  * @throws {Error} If it fails to parse the string, or if it fails to build the model
60
59
  */
61
60
  static deserialize(str: string): any;
@@ -127,7 +126,7 @@ export declare abstract class Model implements Validatable, Serializable, Hashab
127
126
  static getMetadata<V extends Model>(model: V): any;
128
127
  static getAttributes<V extends Model>(model: Constructor<V> | V): string[];
129
128
  static equals<V extends Model>(obj1: V, obj2: V, ...exceptions: any[]): boolean;
130
- static hasErrors<V extends Model>(model: V, ...exceptions: any[]): ModelErrorDefinition | undefined;
129
+ static hasErrors<V extends Model>(model: V, ...propsToIgnore: string[]): ModelErrorDefinition | undefined;
131
130
  static serialize<V extends Model>(model: V): any;
132
131
  static hash<V extends Model>(model: V): any;
133
132
  /**
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -46,9 +46,10 @@ function validate(obj, ...propsToIgnore) {
46
46
  if (!validator) {
47
47
  throw new Error(`Missing validator for ${decorator.key}`);
48
48
  }
49
- const err = validator.hasErrors(obj[prop.toString()], ...(decorator.key === constants_1.ModelKeys.TYPE
49
+ const decoratorProps = decorator.key === constants_1.ModelKeys.TYPE
50
50
  ? [decorator.props]
51
- : Object.values(decorator.props)));
51
+ : (decorator.props || {});
52
+ const err = validator.hasErrors(obj[prop.toString()], decoratorProps);
52
53
  if (err) {
53
54
  errs = errs || {};
54
55
  errs[decorator.key] = err;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -31,8 +31,7 @@ let DateValidator = class DateValidator extends Validator_1.Validator {
31
31
  * @summary Validates a model
32
32
  *
33
33
  * @param {Date | string} value
34
- * @param {string} format
35
- * @param {string} [message]
34
+ * @param {DateValidatorOptions} [options]
36
35
  *
37
36
  * @return {string | undefined}
38
37
  *
@@ -40,13 +39,15 @@ let DateValidator = class DateValidator extends Validator_1.Validator {
40
39
  *
41
40
  * @see Validator#hasErrors
42
41
  */
43
- hasErrors(value, format, message) {
42
+ hasErrors(value, options = {}) {
44
43
  if (value === undefined)
45
44
  return;
46
45
  if (typeof value === "string")
47
46
  value = new Date(value);
48
- if (Number.isNaN(value.getDate()))
47
+ if (Number.isNaN(value.getDate())) {
48
+ const { message = "" } = options;
49
49
  return this.getMessage(message || this.message);
50
+ }
50
51
  }
51
52
  };
52
53
  exports.DateValidator = DateValidator;
@@ -1,4 +1,7 @@
1
- import { Validator } from "./Validator";
1
+ import { Validator, ValidatorOptions } from "./Validator";
2
+ export interface DateValidatorOptions extends ValidatorOptions {
3
+ format?: string;
4
+ }
2
5
  /**
3
6
  * @summary Date Validator
4
7
  *
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
9
12
  *
10
13
  * @category Validators
11
14
  */
12
- export declare class DateValidator extends Validator {
15
+ export declare class DateValidator extends Validator<DateValidatorOptions> {
13
16
  constructor(message?: string);
14
17
  /**
15
18
  * @summary Validates a model
16
19
  *
17
20
  * @param {Date | string} value
18
- * @param {string} format
19
- * @param {string} [message]
21
+ * @param {DateValidatorOptions} [options]
20
22
  *
21
23
  * @return {string | undefined}
22
24
  *
@@ -24,5 +26,5 @@ export declare class DateValidator extends Validator {
24
26
  *
25
27
  * @see Validator#hasErrors
26
28
  */
27
- hasErrors(value: Date | string, format: string, message?: string): string | undefined;
29
+ hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
28
30
  }
@@ -31,8 +31,7 @@ let EmailValidator = class EmailValidator extends PatternValidator_1.PatternVali
31
31
  * @summary Validates a model
32
32
  *
33
33
  * @param {string} value
34
- * @param {RegExp} [pattern]
35
- * @param {string} [message]
34
+ * @param {PatternValidatorOptions} [options]
36
35
  *
37
36
  * @return {string | undefined}
38
37
  *
@@ -40,8 +39,11 @@ let EmailValidator = class EmailValidator extends PatternValidator_1.PatternVali
40
39
  *
41
40
  * @see Validator#hasErrors
42
41
  */
43
- hasErrors(value, pattern, message) {
44
- return super.hasErrors(value, pattern || constants_1.DEFAULT_PATTERNS.EMAIL, message);
42
+ hasErrors(value, options = {}) {
43
+ return super.hasErrors(value, {
44
+ ...options,
45
+ pattern: options?.pattern || constants_1.DEFAULT_PATTERNS.EMAIL,
46
+ });
45
47
  }
46
48
  };
47
49
  exports.EmailValidator = EmailValidator;
@@ -1,4 +1,4 @@
1
- import { PatternValidator } from "./PatternValidator";
1
+ import { PatternValidator, PatternValidatorOptions } from "./PatternValidator";
2
2
  /**
3
3
  * @summary Email Validator
4
4
  *
@@ -15,8 +15,7 @@ export declare class EmailValidator extends PatternValidator {
15
15
  * @summary Validates a model
16
16
  *
17
17
  * @param {string} value
18
- * @param {RegExp} [pattern]
19
- * @param {string} [message]
18
+ * @param {PatternValidatorOptions} [options]
20
19
  *
21
20
  * @return {string | undefined}
22
21
  *
@@ -24,5 +23,5 @@ export declare class EmailValidator extends PatternValidator {
24
23
  *
25
24
  * @see Validator#hasErrors
26
25
  */
27
- hasErrors(value: string, pattern?: RegExp, message?: string): string | undefined;
26
+ hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
28
27
  }
@@ -31,8 +31,7 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
31
31
  * @summary Validates a model
32
32
  *
33
33
  * @param {any[] | Set<any>} value
34
- * @param {string} clazz
35
- * @param {string} [message]
34
+ * @param {ListValidatorOptions} options
36
35
  *
37
36
  * @return {string | undefined}
38
37
  *
@@ -40,10 +39,10 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
40
39
  *
41
40
  * @see Validator#hasErrors
42
41
  */
43
- hasErrors(value, clazz, message) {
42
+ hasErrors(value, options) {
44
43
  if (!value || (Array.isArray(value) ? !value.length : !value.size))
45
44
  return;
46
- clazz = Array.isArray(clazz) ? clazz : [clazz];
45
+ const clazz = Array.isArray(options.clazz) ? options.clazz : [options.clazz];
47
46
  let val, isValid = true;
48
47
  for (let i = 0; i < (Array.isArray(value) ? value.length : value.size); i++) {
49
48
  val = value[i];
@@ -59,7 +58,7 @@ let ListValidator = class ListValidator extends Validator_1.Validator {
59
58
  }
60
59
  return isValid
61
60
  ? undefined
62
- : this.getMessage(message || this.message, clazz);
61
+ : this.getMessage(options.message || this.message, clazz);
63
62
  }
64
63
  };
65
64
  exports.ListValidator = ListValidator;
@@ -1,4 +1,7 @@
1
- import { Validator } from "./Validator";
1
+ import { Validator, ValidatorOptions } from "./Validator";
2
+ export interface ListValidatorOptions extends ValidatorOptions {
3
+ clazz: string[];
4
+ }
2
5
  /**
3
6
  * @summary List Validator
4
7
  *
@@ -9,14 +12,13 @@ import { Validator } from "./Validator";
9
12
  *
10
13
  * @category Validators
11
14
  */
12
- export declare class ListValidator extends Validator {
15
+ export declare class ListValidator extends Validator<ListValidatorOptions> {
13
16
  constructor(message?: string);
14
17
  /**
15
18
  * @summary Validates a model
16
19
  *
17
20
  * @param {any[] | Set<any>} value
18
- * @param {string} clazz
19
- * @param {string} [message]
21
+ * @param {ListValidatorOptions} options
20
22
  *
21
23
  * @return {string | undefined}
22
24
  *
@@ -24,5 +26,5 @@ export declare class ListValidator extends Validator {
24
26
  *
25
27
  * @see Validator#hasErrors
26
28
  */
27
- hasErrors(value: any[] | Set<any>, clazz: string[], message?: string): string | undefined;
29
+ hasErrors(value: any[] | Set<any>, options: ListValidatorOptions): string | undefined;
28
30
  }
@@ -32,8 +32,7 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator_1.Validator
32
32
  * @summary Validates a model
33
33
  *
34
34
  * @param {string} value
35
- * @param {number} maxlength
36
- * @param {string} [message]
35
+ * @param {MaxLengthValidatorOptions} options
37
36
  *
38
37
  * @return {string | undefined}
39
38
  *
@@ -41,11 +40,11 @@ let MaxLengthValidator = class MaxLengthValidator extends Validator_1.Validator
41
40
  *
42
41
  * @see Validator#hasErrors
43
42
  */
44
- hasErrors(value, maxlength, message) {
43
+ hasErrors(value, options) {
45
44
  if (typeof value === "undefined")
46
45
  return;
47
- return value.length > maxlength
48
- ? this.getMessage(message || this.message, maxlength)
46
+ return value.length > options.maxLength
47
+ ? this.getMessage(options.message || this.message, options.maxLength)
49
48
  : undefined;
50
49
  }
51
50
  };
@@ -1,4 +1,7 @@
1
- import { Validator } from "./Validator";
1
+ import { Validator, ValidatorOptions } from "./Validator";
2
+ export interface MaxLengthValidatorOptions extends ValidatorOptions {
3
+ maxLength: number;
4
+ }
2
5
  /**
3
6
  * @summary Maximum Length Validator
4
7
  * @description Validates strings and Arrays on their maximum length
@@ -10,14 +13,13 @@ import { Validator } from "./Validator";
10
13
  *
11
14
  * @category Validators
12
15
  */
13
- export declare class MaxLengthValidator extends Validator {
16
+ export declare class MaxLengthValidator extends Validator<MaxLengthValidatorOptions> {
14
17
  constructor(message?: string);
15
18
  /**
16
19
  * @summary Validates a model
17
20
  *
18
21
  * @param {string} value
19
- * @param {number} maxlength
20
- * @param {string} [message]
22
+ * @param {MaxLengthValidatorOptions} options
21
23
  *
22
24
  * @return {string | undefined}
23
25
  *
@@ -25,5 +27,5 @@ export declare class MaxLengthValidator extends Validator {
25
27
  *
26
28
  * @see Validator#hasErrors
27
29
  */
28
- hasErrors(value: string | any[], maxlength: number, message?: string): string | undefined;
30
+ hasErrors(value: string | any[], options: MaxLengthValidatorOptions): string | undefined;
29
31
  }
@@ -31,8 +31,7 @@ let MaxValidator = class MaxValidator extends Validator_1.Validator {
31
31
  * @summary Validates a Model
32
32
  *
33
33
  * @param {string} value
34
- * @param {number | Date | string} max
35
- * @param {string} [message]
34
+ * @param {MaxValidatorOptions} options
36
35
  *
37
36
  * @return {string | undefined}
38
37
  *
@@ -40,16 +39,17 @@ let MaxValidator = class MaxValidator extends Validator_1.Validator {
40
39
  *
41
40
  * @see Validator#hasErrors
42
41
  */
43
- hasErrors(value, max, message) {
42
+ hasErrors(value, options) {
44
43
  if (typeof value === "undefined")
45
44
  return;
45
+ let { max } = options;
46
46
  if (value instanceof Date && !(max instanceof Date)) {
47
47
  max = new Date(max);
48
48
  if (Number.isNaN(max.getDate()))
49
49
  throw new Error("Invalid Max param defined");
50
50
  }
51
51
  return value > max
52
- ? this.getMessage(message || this.message, max)
52
+ ? this.getMessage(options.message || this.message, max)
53
53
  : undefined;
54
54
  }
55
55
  };