@decaf-ts/decorator-validation 1.19.0 → 1.21.0

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 (168) hide show
  1. package/lib/cjs/index.cjs +1 -1
  2. package/lib/esm/index.js +1 -1
  3. package/lib/types/constants/index.d.cts +2 -2
  4. package/lib/types/constants/index.d.mts +2 -2
  5. package/lib/types/index.d.cts +7 -7
  6. package/lib/types/index.d.mts +7 -7
  7. package/lib/types/model/Builder.d.cts +3 -3
  8. package/lib/types/model/Builder.d.mts +3 -3
  9. package/lib/types/model/Model.d.cts +4 -4
  10. package/lib/types/model/Model.d.mts +4 -4
  11. package/lib/types/model/ModelErrorDefinition.d.cts +1 -1
  12. package/lib/types/model/ModelErrorDefinition.d.mts +1 -1
  13. package/lib/types/model/ModelRegistry.d.cts +3 -3
  14. package/lib/types/model/ModelRegistry.d.mts +3 -3
  15. package/lib/types/model/construction.d.cts +1 -1
  16. package/lib/types/model/construction.d.mts +1 -1
  17. package/lib/types/model/index.d.cts +10 -10
  18. package/lib/types/model/index.d.mts +10 -10
  19. package/lib/types/model/types.d.cts +3 -3
  20. package/lib/types/model/types.d.mts +3 -3
  21. package/lib/types/model/utils.d.cts +1 -1
  22. package/lib/types/model/utils.d.mts +1 -1
  23. package/lib/types/model/validation.d.cts +3 -3
  24. package/lib/types/model/validation.d.mts +3 -3
  25. package/lib/types/overrides/Metadata.d.cts +3 -3
  26. package/lib/types/overrides/Metadata.d.mts +3 -3
  27. package/lib/types/overrides/index.d.cts +3 -3
  28. package/lib/types/overrides/index.d.mts +3 -3
  29. package/lib/types/overrides/types.d.cts +1 -1
  30. package/lib/types/overrides/types.d.mts +1 -1
  31. package/lib/types/types/index.d.cts +1 -1
  32. package/lib/types/types/index.d.mts +1 -1
  33. package/lib/types/types/validation.d.cts +2 -2
  34. package/lib/types/types/validation.d.mts +2 -2
  35. package/lib/types/utils/index.d.cts +11 -11
  36. package/lib/types/utils/index.d.mts +11 -11
  37. package/lib/types/utils/serialization.d.cts +1 -1
  38. package/lib/types/utils/serialization.d.mts +1 -1
  39. package/lib/types/utils/serializers.d.cts +2 -2
  40. package/lib/types/utils/serializers.d.mts +2 -2
  41. package/lib/types/utils/types.d.cts +1 -1
  42. package/lib/types/utils/types.d.mts +1 -1
  43. package/lib/types/validation/Validation.d.cts +2 -2
  44. package/lib/types/validation/Validation.d.mts +2 -2
  45. package/lib/types/validation/Validators/AsyncValidator.d.cts +3 -3
  46. package/lib/types/validation/Validators/AsyncValidator.d.mts +3 -3
  47. package/lib/types/validation/Validators/BaseValidator.d.cts +3 -3
  48. package/lib/types/validation/Validators/BaseValidator.d.mts +3 -3
  49. package/lib/types/validation/Validators/DateValidator.d.cts +2 -2
  50. package/lib/types/validation/Validators/DateValidator.d.mts +2 -2
  51. package/lib/types/validation/Validators/DiffValidator.d.cts +3 -3
  52. package/lib/types/validation/Validators/DiffValidator.d.mts +3 -3
  53. package/lib/types/validation/Validators/EmailValidator.d.cts +2 -2
  54. package/lib/types/validation/Validators/EmailValidator.d.mts +2 -2
  55. package/lib/types/validation/Validators/EqualsValidator.d.cts +3 -3
  56. package/lib/types/validation/Validators/EqualsValidator.d.mts +3 -3
  57. package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.cts +3 -3
  58. package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.mts +3 -3
  59. package/lib/types/validation/Validators/GreaterThanValidator.d.cts +3 -3
  60. package/lib/types/validation/Validators/GreaterThanValidator.d.mts +3 -3
  61. package/lib/types/validation/Validators/LessThanOrEqualValidator.d.cts +3 -3
  62. package/lib/types/validation/Validators/LessThanOrEqualValidator.d.mts +3 -3
  63. package/lib/types/validation/Validators/LessThanValidator.d.cts +3 -3
  64. package/lib/types/validation/Validators/LessThanValidator.d.mts +3 -3
  65. package/lib/types/validation/Validators/ListValidator.d.cts +2 -2
  66. package/lib/types/validation/Validators/ListValidator.d.mts +2 -2
  67. package/lib/types/validation/Validators/MaxLengthValidator.d.cts +2 -2
  68. package/lib/types/validation/Validators/MaxLengthValidator.d.mts +2 -2
  69. package/lib/types/validation/Validators/MaxValidator.d.cts +2 -2
  70. package/lib/types/validation/Validators/MaxValidator.d.mts +2 -2
  71. package/lib/types/validation/Validators/MinLengthValidator.d.cts +2 -2
  72. package/lib/types/validation/Validators/MinLengthValidator.d.mts +2 -2
  73. package/lib/types/validation/Validators/MinValidator.d.cts +2 -2
  74. package/lib/types/validation/Validators/MinValidator.d.mts +2 -2
  75. package/lib/types/validation/Validators/OptionValidator.d.cts +2 -2
  76. package/lib/types/validation/Validators/OptionValidator.d.mts +2 -2
  77. package/lib/types/validation/Validators/PasswordValidator.d.cts +2 -2
  78. package/lib/types/validation/Validators/PasswordValidator.d.mts +2 -2
  79. package/lib/types/validation/Validators/PatternValidator.d.cts +2 -2
  80. package/lib/types/validation/Validators/PatternValidator.d.mts +2 -2
  81. package/lib/types/validation/Validators/RequiredValidator.d.cts +2 -2
  82. package/lib/types/validation/Validators/RequiredValidator.d.mts +2 -2
  83. package/lib/types/validation/Validators/StepValidator.d.cts +2 -2
  84. package/lib/types/validation/Validators/StepValidator.d.mts +2 -2
  85. package/lib/types/validation/Validators/TypeValidator.d.cts +2 -2
  86. package/lib/types/validation/Validators/TypeValidator.d.mts +2 -2
  87. package/lib/types/validation/Validators/URLValidator.d.cts +2 -2
  88. package/lib/types/validation/Validators/URLValidator.d.mts +2 -2
  89. package/lib/types/validation/Validators/Validator.d.cts +3 -3
  90. package/lib/types/validation/Validators/Validator.d.mts +3 -3
  91. package/lib/types/validation/Validators/ValidatorRegistry.d.cts +3 -3
  92. package/lib/types/validation/Validators/ValidatorRegistry.d.mts +3 -3
  93. package/lib/types/validation/Validators/decorators.d.cts +1 -1
  94. package/lib/types/validation/Validators/decorators.d.mts +1 -1
  95. package/lib/types/validation/Validators/index.d.cts +26 -26
  96. package/lib/types/validation/Validators/index.d.mts +26 -26
  97. package/lib/types/validation/decorators.d.cts +2 -2
  98. package/lib/types/validation/decorators.d.mts +2 -2
  99. package/lib/types/validation/index.d.cts +4 -4
  100. package/lib/types/validation/index.d.mts +4 -4
  101. package/lib/types/validation/types.d.cts +2 -2
  102. package/lib/types/validation/types.d.mts +2 -2
  103. package/package.json +1 -1
  104. package/lib/types/constants/errors.d.ts +0 -17
  105. package/lib/types/constants/index.d.ts +0 -2
  106. package/lib/types/constants/validation.d.ts +0 -16
  107. package/lib/types/index.d.ts +0 -20
  108. package/lib/types/model/Builder.d.ts +0 -86
  109. package/lib/types/model/Model.d.ts +0 -286
  110. package/lib/types/model/ModelErrorDefinition.d.ts +0 -22
  111. package/lib/types/model/ModelRegistry.d.ts +0 -181
  112. package/lib/types/model/constants.d.ts +0 -65
  113. package/lib/types/model/construction.d.ts +0 -46
  114. package/lib/types/model/decorators.d.ts +0 -47
  115. package/lib/types/model/index.d.ts +0 -10
  116. package/lib/types/model/types.d.ts +0 -145
  117. package/lib/types/model/utils.d.ts +0 -13
  118. package/lib/types/model/validation.d.ts +0 -92
  119. package/lib/types/overrides/Metadata.d.ts +0 -132
  120. package/lib/types/overrides/index.d.ts +0 -4
  121. package/lib/types/overrides/overrides.d.ts +0 -1
  122. package/lib/types/overrides/types.d.ts +0 -17
  123. package/lib/types/types/index.d.ts +0 -1
  124. package/lib/types/types/validation.d.ts +0 -28
  125. package/lib/types/utils/DateBuilder.d.ts +0 -121
  126. package/lib/types/utils/PathProxy.d.ts +0 -43
  127. package/lib/types/utils/constants.d.ts +0 -32
  128. package/lib/types/utils/dates.d.ts +0 -86
  129. package/lib/types/utils/equality.d.ts +0 -56
  130. package/lib/types/utils/hashing.d.ts +0 -82
  131. package/lib/types/utils/index.d.ts +0 -11
  132. package/lib/types/utils/registry.d.ts +0 -68
  133. package/lib/types/utils/serialization.d.ts +0 -12
  134. package/lib/types/utils/serializers.d.ts +0 -41
  135. package/lib/types/utils/strings.d.ts +0 -25
  136. package/lib/types/utils/types.d.ts +0 -35
  137. package/lib/types/validation/Validation.d.ts +0 -53
  138. package/lib/types/validation/Validators/AsyncValidator.d.ts +0 -72
  139. package/lib/types/validation/Validators/BaseValidator.d.ts +0 -118
  140. package/lib/types/validation/Validators/DateValidator.d.ts +0 -60
  141. package/lib/types/validation/Validators/DiffValidator.d.ts +0 -29
  142. package/lib/types/validation/Validators/EmailValidator.d.ts +0 -60
  143. package/lib/types/validation/Validators/EqualsValidator.d.ts +0 -29
  144. package/lib/types/validation/Validators/GreaterThanOrEqualValidator.d.ts +0 -29
  145. package/lib/types/validation/Validators/GreaterThanValidator.d.ts +0 -29
  146. package/lib/types/validation/Validators/LessThanOrEqualValidator.d.ts +0 -29
  147. package/lib/types/validation/Validators/LessThanValidator.d.ts +0 -29
  148. package/lib/types/validation/Validators/ListValidator.d.ts +0 -66
  149. package/lib/types/validation/Validators/MaxLengthValidator.d.ts +0 -29
  150. package/lib/types/validation/Validators/MaxValidator.d.ts +0 -74
  151. package/lib/types/validation/Validators/MinLengthValidator.d.ts +0 -29
  152. package/lib/types/validation/Validators/MinValidator.d.ts +0 -74
  153. package/lib/types/validation/Validators/OptionValidator.d.ts +0 -29
  154. package/lib/types/validation/Validators/PasswordValidator.d.ts +0 -28
  155. package/lib/types/validation/Validators/PatternValidator.d.ts +0 -103
  156. package/lib/types/validation/Validators/RequiredValidator.d.ts +0 -74
  157. package/lib/types/validation/Validators/StepValidator.d.ts +0 -29
  158. package/lib/types/validation/Validators/TypeValidator.d.ts +0 -79
  159. package/lib/types/validation/Validators/URLValidator.d.ts +0 -61
  160. package/lib/types/validation/Validators/Validator.d.ts +0 -65
  161. package/lib/types/validation/Validators/ValidatorRegistry.d.ts +0 -41
  162. package/lib/types/validation/Validators/constants.d.ts +0 -157
  163. package/lib/types/validation/Validators/decorators.d.ts +0 -12
  164. package/lib/types/validation/Validators/index.d.ts +0 -26
  165. package/lib/types/validation/Validators/utils.d.ts +0 -75
  166. package/lib/types/validation/decorators.d.ts +0 -313
  167. package/lib/types/validation/index.d.ts +0 -9
  168. package/lib/types/validation/types.d.ts +0 -309
@@ -1,72 +0,0 @@
1
- import type { ValidatorOptions } from "../types";
2
- import type { PathProxy } from "../../utils";
3
- import { BaseValidator } from "./BaseValidator";
4
- /**
5
- * @description
6
- * Abstract class for defining asynchronous validators.
7
- *
8
- * This class extends the base `Validator` and enforces that any implementation
9
- * of `hasErrors` must be asynchronous, always returning a Promise.
10
- *
11
- * Use this when the validation process involves asynchronous operations,
12
- * such as API calls, database lookups, or time-based checks (e.g., timeouts).
13
- *
14
- * @example
15
- * ```typescript
16
- * // Example of an asynchronous validator that compares value against a timeout
17
- * class TimeoutValidator extends AsyncValidator<{ timeout?: number }> {
18
- * constructor(message: string = "Validation failed due to timeout") {
19
- * super(message);
20
- * }
21
- *
22
- * async hasErrors(value: number, options?: { timeout?: number }) {
23
- * const delay = options?.timeout ?? 100;
24
- *
25
- * // async call
26
- * await new Promise(res => setTimeout(res, delay));
27
- *
28
- * if (value > delay) {
29
- * // Rejects the validation after waiting the delay if value is greater
30
- * return Promise.resolve(this.getMessage());
31
- * }
32
- *
33
- * // Passes the validation after waiting the delay
34
- * return Promise.resolve(undefined);
35
- * }
36
- * }
37
- *
38
- * // Example usage:
39
- * const validator = new TimeoutValidator();
40
- *
41
- * async function runValidation() {
42
- * const error = await validator.hasErrors(50, { timeout: 100 });
43
- * if (error) {
44
- * return console.error('Validation error:', error);
45
- * }
46
- * console.log('Value is valid');
47
- * }
48
- *
49
- * await runValidation();
50
- * ```
51
- *
52
- * - If `value > timeout`, the validator waits for the delay and then rejects with an error.
53
- * - If `value <= timeout`, the validator waits for the delay and resolves successfully with `undefined`.
54
- *
55
- * @see {@link Validator} For the base synchronous validator.
56
- */
57
- export declare abstract class AsyncValidator<V extends ValidatorOptions> extends BaseValidator<V, true> {
58
- protected constructor(message?: string, ...acceptedTypes: string[]);
59
- /**
60
- * @description
61
- * Asynchronously validates a value.
62
- *
63
- * @template V - Type of the option object that can be passed to the validator
64
- * @param {any} value - The value to validate
65
- * @param {V} [options] - Optional configuration options for customizing validation behavior
66
- * @param {PathProxy<any>} proxy -
67
- * @return Promise<string | undefined> Error message if validation fails, undefined if validation passes
68
- *
69
- * @see {@link Validator}
70
- */
71
- abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): Promise<string | undefined>;
72
- }
@@ -1,118 +0,0 @@
1
- import { ValidatorOptions } from "../types";
2
- import type { PathProxy } from "../../utils";
3
- import type { ConditionalAsync } from "../../types";
4
- /**
5
- * @description Abstract base class for all validators in the validation framework.
6
- * @summary The BaseValidator class provides the foundation for all synchronous and asynchronous validator implementations.
7
- * It handles type checking, error message formatting, and defines the interface that all validators must implement.
8
- * This class is designed to be extended by specific validator classes that define their own validation logic.
9
- *
10
- * @template V - Validator options type
11
- * @template IsAsync - Whether the validator is async (true) or sync (false). Default `false`.
12
- *
13
- * @param {boolean} async - Defines if the validator is async (must match the subclass signature)
14
- * @param {string} message - Default error message to display when validation fails (defaults to {@link DEFAULT_ERROR_MESSAGES#DEFAULT})
15
- * @param {string[]} acceptedTypes - Type names that this validator accepts (used for runtime type checking)
16
- *
17
- * @class BaseValidator
18
- * @abstract
19
- *
20
- * @example
21
- * // Example of a synchronous validator
22
- * class SyncValidator extends BaseValidator<SomeOptions, false> {
23
- * constructor() {
24
- * super(false, "Sync validation failed", String.name);
25
- * }
26
- *
27
- * public hasErrors(value: any, options?: SomeOptions): string | undefined {
28
- * if (typeof value !== "string") return this.getMessage(this.message);
29
- * return undefined;
30
- * }
31
- * }
32
- *
33
- * @example
34
- * // Example of an asynchronous custom validator
35
- * class AsyncValidator extends BaseValidator<SomeOptions, true> {
36
- * constructor() {
37
- * super(true, "Async validation failed", String.name);
38
- * }
39
- *
40
- * public async hasErrors(value: any, options?: SomeOptions): Promise<string | undefined> {
41
- * const result = await someAsyncCheck(value);
42
- * if (!result) return this.getMessage(this.message);
43
- * return undefined;
44
- * }
45
- * }
46
- *
47
- * @mermaid
48
- * sequenceDiagram
49
- * participant C as Client
50
- * participant V as Validator Subclass
51
- * participant B as BaseValidator
52
- *
53
- * C->>V: new CustomValidator(async, message)
54
- * V->>B: super(async, message, acceptedTypes)
55
- * B->>B: Store message, async flag, and accepted types
56
- * B->>B: Optionally wrap hasErrors with type checking
57
- * C->>V: hasErrors(value, options)
58
- * alt value type not in acceptedTypes
59
- * B-->>C: Type error message
60
- * else value type is accepted
61
- * V->>V: Custom validation logic
62
- * V-->>C: Validation result
63
- * end
64
- *
65
- * @category Validators
66
- */
67
- export declare abstract class BaseValidator<V extends ValidatorOptions = ValidatorOptions, Async extends boolean = false> {
68
- readonly message: string;
69
- readonly acceptedTypes?: string[];
70
- readonly async?: Async;
71
- protected constructor(async: Async, message?: string, ...acceptedTypes: string[]);
72
- /**
73
- * @description Formats an error message with optional arguments
74
- * @summary Creates a formatted error message by replacing placeholders with provided arguments.
75
- * This method uses the string formatting utility to generate consistent error messages
76
- * across all validators.
77
- *
78
- * @param {string} message - The message template with placeholders
79
- * @param {...any} args - Values to insert into the message template
80
- * @return {string} The formatted error message
81
- * @protected
82
- */
83
- protected getMessage(message: string, ...args: any[]): string;
84
- /**
85
- * @description Creates a type-checking wrapper around the hasErrors method
86
- * @summary Wraps the hasErrors method with type validation logic to ensure that
87
- * the value being validated is of an accepted type before performing specific validation.
88
- * This method is called during construction if acceptedTypes are provided.
89
- *
90
- * @param {Function} unbound - The original hasErrors method to be wrapped
91
- * @return {Function} A new function that performs type checking before calling the original method
92
- * @private
93
- */
94
- private checkTypeAndHasErrors;
95
- /**
96
- * @description Validates a value against specific validation rules
97
- * @summary Abstract method that must be implemented by all validator subclasses.
98
- * This method contains the core validation logic that determines whether a value
99
- * is valid according to the specific rules of the validator. If the value is valid,
100
- * the method returns undefined; otherwise, it returns an error message.
101
- *
102
- * @template V - Type of the options object that can be passed to the validator
103
- * @param {any} value - The value to validate
104
- * @param {V} [options] - Optional configuration options for customizing validation behavior
105
- * @param {PathProxy<any>} proxy -
106
- * @return {string | undefined} Error message if validation fails, undefined if validation passes
107
- *
108
- * @abstract
109
- *
110
- * @see Model#validate
111
- */
112
- abstract hasErrors(value: any, options?: V, proxy?: PathProxy<any>): ConditionalAsync<Async, string | undefined>;
113
- /**
114
- * @summary Duck typing for Validators
115
- * @param val
116
- */
117
- static isValidator(val: any): boolean;
118
- }
@@ -1,60 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { DateValidatorOptions } from "../types";
3
- /**
4
- * @description Validator for checking if a value is a valid date
5
- * @summary The DateValidator checks if a value is a valid date object or a string that can be converted to a valid date.
6
- * It validates that the value represents a real date and not an invalid date like "2023-02-31".
7
- * @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#DATE}
8
- * @class DateValidator
9
- * @extends Validator
10
- *
11
- * @category Validators
12
- * @example
13
- * ```typescript
14
- * // Create a date validator with default error message
15
- * const dateValidator = new DateValidator();
16
- *
17
- * // Create a date validator with custom error message
18
- * const customDateValidator = new DateValidator("Please enter a valid date");
19
- *
20
- * // Validate a date
21
- * const result = dateValidator.hasErrors(new Date()); // undefined (valid)
22
- * const invalidResult = dateValidator.hasErrors("not a date"); // Returns error message (invalid)
23
- * ```
24
- * @mermaid
25
- * sequenceDiagram
26
- * participant C as Client
27
- * participant V as DateValidator
28
- *
29
- * C->>V: new DateValidator(message)
30
- * C->>V: hasErrors(value, options)
31
- * alt value is undefined
32
- * V-->>C: undefined (valid)
33
- * else value is string
34
- * V->>V: Convert to Date
35
- * end
36
- * alt Date is invalid (NaN)
37
- * V-->>C: Error message
38
- * else Date is valid
39
- * V-->>C: undefined (valid)
40
- * end
41
- */
42
- export declare class DateValidator extends Validator<DateValidatorOptions> {
43
- constructor(message?: string);
44
- /**
45
- * @description Checks if the provided value is a valid date
46
- * @summary Validates that the given value is a valid date. If the value is a string,
47
- * it attempts to convert it to a Date object. Returns an error message if the date is invalid,
48
- * or undefined if the date is valid or if the value is undefined.
49
- *
50
- * @param {Date | string} value - The value to validate, can be a Date object or a string
51
- * @param {DateValidatorOptions} [options={}] - Optional configuration options for the validator
52
- *
53
- * @return {string | undefined} Error message if validation fails, undefined if validation passes
54
- *
55
- * @override
56
- *
57
- * @see Validator#hasErrors
58
- */
59
- hasErrors(value: Date | string, options?: DateValidatorOptions): string | undefined;
60
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { DiffValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils";
4
- /**
5
- * @summary Diff Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#DiffValidator}
8
- *
9
- * @class DiffValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class DiffValidator extends Validator<DiffValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {DiffValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: DiffValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,60 +0,0 @@
1
- import { PatternValidator } from "./PatternValidator";
2
- import { PatternValidatorOptions } from "../types";
3
- /**
4
- * @description Validator for checking if a string is a valid email address
5
- * @summary The EmailValidator checks if a string matches a standard email address pattern.
6
- * It extends the PatternValidator and uses a predefined email regex pattern to validate email addresses.
7
- * This validator is typically used with the @email decorator.
8
- *
9
- * @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#EMAIL}
10
- *
11
- * @class EmailValidator
12
- * @extends PatternValidator
13
- *
14
- * @example
15
- * ```typescript
16
- * // Create an email validator with default error message
17
- * const emailValidator = new EmailValidator();
18
- *
19
- * // Create an email validator with custom error message
20
- * const customEmailValidator = new EmailValidator("Please enter a valid email address");
21
- *
22
- * // Validate an email
23
- * const result = emailValidator.hasErrors("user@example.com"); // undefined (valid)
24
- * const invalidResult = emailValidator.hasErrors("invalid-email"); // Returns error message (invalid)
25
- * ```
26
- *
27
- * @mermaid
28
- * sequenceDiagram
29
- * participant C as Client
30
- * participant E as EmailValidator
31
- * participant P as PatternValidator
32
- *
33
- * C->>E: new EmailValidator(message)
34
- * E->>P: super(message)
35
- * C->>E: hasErrors(value, options)
36
- * E->>P: super.hasErrors(value, options with EMAIL pattern)
37
- * P-->>E: validation result
38
- * E-->>C: validation result
39
- *
40
- * @category Validators
41
- */
42
- export declare class EmailValidator extends PatternValidator {
43
- constructor(message?: string);
44
- /**
45
- * @description Checks if a string is a valid email address
46
- * @summary Validates that the provided string matches the email pattern.
47
- * This method extends the PatternValidator's hasErrors method by ensuring
48
- * the email pattern is used, even if not explicitly provided in the options.
49
- *
50
- * @param {string} value - The string to validate as an email address
51
- * @param {PatternValidatorOptions} [options={}] - Optional configuration options
52
- *
53
- * @return {string | undefined} Error message if validation fails, undefined if validation passes
54
- *
55
- * @override
56
- *
57
- * @see PatternValidator#hasErrors
58
- */
59
- hasErrors(value: string, options?: PatternValidatorOptions): string | undefined;
60
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { EqualsValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils";
4
- /**
5
- * @summary Equals Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#EQUALS}
8
- *
9
- * @class EqualsValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class EqualsValidator extends Validator<EqualsValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {EqualsValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: EqualsValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { GreaterThanOrEqualValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils/PathProxy";
4
- /**
5
- * @summary Greater Than or Equal Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#GREATER_THAN_OR_EQUAL}
8
- *
9
- * @class GreaterThanOrEqualValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class GreaterThanOrEqualValidator extends Validator<GreaterThanOrEqualValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {GreaterThanOrEqualValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: GreaterThanOrEqualValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { GreaterThanValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils/PathProxy";
4
- /**
5
- * @summary Greater Than Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#GREATER_THAN}
8
- *
9
- * @class GreaterThanValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class GreaterThanValidator extends Validator<GreaterThanValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {GreaterThanValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: GreaterThanValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import type { LessThanOrEqualValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils/PathProxy";
4
- /**
5
- * @summary Less Than or Equal Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LESS_THAN_OR_EQUAL}
8
- *
9
- * @class LessThanOrEqualValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class LessThanOrEqualValidator extends Validator<LessThanOrEqualValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {LessThanOrEqualValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: LessThanOrEqualValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { LessThanValidatorOptions } from "../types";
3
- import type { PathProxy } from "../../utils/PathProxy";
4
- /**
5
- * @summary Less Than Validator
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#LESS_THAN}
8
- *
9
- * @class LessThanValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class LessThanValidator extends Validator<LessThanValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {LessThanValidatorOptions} options
21
- * @param {PathProxy<any>} accessor - Proxy-like object used to resolve values from nested structures via path strings.
22
- *
23
- * @return {string | undefined}
24
- *
25
- * @override
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: any, options: LessThanValidatorOptions, accessor: PathProxy<any>): string | undefined;
29
- }
@@ -1,66 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { ListValidatorOptions } from "../types";
3
- /**
4
- * @description Validator for checking if elements in a list or set match expected types
5
- * @summary The ListValidator validates that all elements in an array or Set match the expected types.
6
- * It checks each element against a list of allowed class types and ensures type consistency.
7
- * This validator is typically used with the @list decorator.
8
- *
9
- * @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#LIST}
10
- *
11
- * @class ListValidator
12
- * @extends Validator
13
- *
14
- * @example
15
- * ```typescript
16
- * // Create a list validator with default error message
17
- * const listValidator = new ListValidator();
18
- *
19
- * // Create a list validator with custom error message
20
- * const customListValidator = new ListValidator("All items must be of the specified type");
21
- *
22
- * // Validate a list
23
- * const options = { clazz: ["String", "Number"] };
24
- * const result = listValidator.hasErrors(["test", 123], options); // undefined (valid)
25
- * const invalidResult = listValidator.hasErrors([new Date()], options); // Returns error message (invalid)
26
- * ```
27
- *
28
- * @mermaid
29
- * sequenceDiagram
30
- * participant C as Client
31
- * participant V as ListValidator
32
- *
33
- * C->>V: new ListValidator(message)
34
- * C->>V: hasErrors(value, options)
35
- * alt value is empty
36
- * V-->>C: undefined (valid)
37
- * else value has elements
38
- * V->>V: Check each element's type
39
- * alt All elements match allowed types
40
- * V-->>C: undefined (valid)
41
- * else Some elements don't match
42
- * V-->>C: Error message
43
- * end
44
- * end
45
- *
46
- * @category Validators
47
- */
48
- export declare class ListValidator extends Validator<ListValidatorOptions> {
49
- constructor(message?: string);
50
- /**
51
- * @description Checks if all elements in a list or set match the expected types
52
- * @summary Validates that each element in the provided array or Set matches one of the
53
- * class types specified in the options. For object types, it checks the constructor name,
54
- * and for primitive types, it compares against the lowercase type name.
55
- *
56
- * @param {any[] | Set<any>} value - The array or Set to validate
57
- * @param {ListValidatorOptions} options - Configuration options containing the allowed class types
58
- *
59
- * @return {string | undefined} Error message if validation fails, undefined if validation passes
60
- *
61
- * @override
62
- *
63
- * @see Validator#hasErrors
64
- */
65
- hasErrors(value: any[] | Set<any>, options: ListValidatorOptions): string | undefined;
66
- }
@@ -1,29 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { MaxLengthValidatorOptions } from "../types";
3
- /**
4
- * @summary Maximum Length Validator
5
- * @description Validates strings and Arrays on their maximum length
6
- *
7
- * @param {string} [message] defaults to {@link DEFAULT_ERROR_MESSAGES#MAX_LENGTH}
8
- *
9
- * @class MinLengthValidator
10
- * @extends Validator
11
- *
12
- * @category Validators
13
- */
14
- export declare class MaxLengthValidator extends Validator<MaxLengthValidatorOptions> {
15
- constructor(message?: string);
16
- /**
17
- * @summary Validates a model
18
- *
19
- * @param {string} value
20
- * @param {MaxLengthValidatorOptions} options
21
- *
22
- * @return {string | undefined}
23
- *
24
- * @override
25
- *
26
- * @see Validator#hasErrors
27
- */
28
- hasErrors(value: string | any[], options: MaxLengthValidatorOptions): string | undefined;
29
- }
@@ -1,74 +0,0 @@
1
- import { Validator } from "./Validator";
2
- import { MaxValidatorOptions } from "../types";
3
- /**
4
- * @description Validator for checking if a value is less than or equal to a maximum
5
- * @summary The MaxValidator checks if a numeric value, date, or string is less than or equal to
6
- * a specified maximum value. It supports comparing numbers directly, dates chronologically,
7
- * and strings lexicographically. This validator is typically used with the @max decorator.
8
- *
9
- * @param {string} [message] - Custom error message to display when validation fails, defaults to {@link DEFAULT_ERROR_MESSAGES#MAX}
10
- *
11
- * @class MaxValidator
12
- * @extends Validator
13
- *
14
- * @example
15
- * ```typescript
16
- * // Create a max validator with default error message
17
- * const maxValidator = new MaxValidator();
18
- *
19
- * // Create a max validator with custom error message
20
- * const customMaxValidator = new MaxValidator("Value must not exceed {0}");
21
- *
22
- * // Validate a number
23
- * const numOptions = { max: 100, message: "Number too large" };
24
- * const numResult = maxValidator.hasErrors(50, numOptions); // undefined (valid)
25
- * const invalidNumResult = maxValidator.hasErrors(150, numOptions); // Returns error message (invalid)
26
- *
27
- * // Validate a date
28
- * const dateOptions = { max: new Date(2023, 11, 31) };
29
- * const dateResult = maxValidator.hasErrors(new Date(2023, 5, 15), dateOptions); // undefined (valid)
30
- * ```
31
- *
32
- * @mermaid
33
- * sequenceDiagram
34
- * participant C as Client
35
- * participant V as MaxValidator
36
- *
37
- * C->>V: new MaxValidator(message)
38
- * C->>V: hasErrors(value, options)
39
- * alt value is undefined
40
- * V-->>C: undefined (valid)
41
- * else value is Date and max is not Date
42
- * V->>V: Convert max to Date
43
- * alt conversion fails
44
- * V-->>C: Error: Invalid Max param
45
- * end
46
- * end
47
- * alt value > max
48
- * V-->>C: Error message
49
- * else value <= max
50
- * V-->>C: undefined (valid)
51
- * end
52
- *
53
- * @category Validators
54
- */
55
- export declare class MaxValidator extends Validator<MaxValidatorOptions> {
56
- constructor(message?: string);
57
- /**
58
- * @description Checks if a value is less than or equal to a maximum
59
- * @summary Validates that the provided value does not exceed the maximum value
60
- * specified in the options. For dates, it performs chronological comparison,
61
- * converting string representations to Date objects if necessary. For numbers
62
- * and strings, it performs direct comparison.
63
- *
64
- * @param {number | Date | string} value - The value to validate
65
- * @param {MaxValidatorOptions} options - Configuration options containing the maximum value
66
- *
67
- * @return {string | undefined} Error message if validation fails, undefined if validation passes
68
- *
69
- * @override
70
- *
71
- * @see Validator#hasErrors
72
- */
73
- hasErrors(value: number | Date | string, options: MaxValidatorOptions): string | undefined;
74
- }