reslib 1.0.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 (200) hide show
  1. package/README.md +298 -0
  2. package/build/auth/index.d.ts +2034 -0
  3. package/build/auth/index.js +5 -0
  4. package/build/auth/types.d.ts +465 -0
  5. package/build/auth/types.js +1 -0
  6. package/build/countries/countries.d.ts +1454 -0
  7. package/build/countries/countries.js +1 -0
  8. package/build/countries/index.d.ts +159 -0
  9. package/build/countries/index.js +5 -0
  10. package/build/countries/types.d.ts +65 -0
  11. package/build/countries/types.js +1 -0
  12. package/build/currency/currencies.d.ts +8 -0
  13. package/build/currency/currencies.js +1 -0
  14. package/build/currency/index.d.ts +51 -0
  15. package/build/currency/index.js +5 -0
  16. package/build/currency/session.d.ts +23 -0
  17. package/build/currency/session.js +5 -0
  18. package/build/currency/types.d.ts +1039 -0
  19. package/build/currency/types.js +1 -0
  20. package/build/currency/utils.d.ts +25 -0
  21. package/build/currency/utils.js +1 -0
  22. package/build/i18n/index.d.ts +640 -0
  23. package/build/i18n/index.js +5 -0
  24. package/build/inputFormatter/index.d.ts +396 -0
  25. package/build/inputFormatter/index.js +5 -0
  26. package/build/inputFormatter/types.d.ts +544 -0
  27. package/build/inputFormatter/types.js +1 -0
  28. package/build/logger/index.d.ts +235 -0
  29. package/build/logger/index.js +5 -0
  30. package/build/observable/index.d.ts +329 -0
  31. package/build/observable/index.js +1 -0
  32. package/build/platform/index.d.ts +32 -0
  33. package/build/platform/index.js +1 -0
  34. package/build/resources/ResourcePaginationHelper.d.ts +537 -0
  35. package/build/resources/ResourcePaginationHelper.js +2 -0
  36. package/build/resources/decorators/create.decorator.d.ts +20 -0
  37. package/build/resources/decorators/create.decorator.js +1 -0
  38. package/build/resources/decorators/index.d.ts +41 -0
  39. package/build/resources/decorators/index.js +1 -0
  40. package/build/resources/fields/index.d.ts +33 -0
  41. package/build/resources/fields/index.js +1 -0
  42. package/build/resources/filters.d.ts +62 -0
  43. package/build/resources/filters.js +1 -0
  44. package/build/resources/index.d.ts +854 -0
  45. package/build/resources/index.js +6 -0
  46. package/build/resources/types/filters.d.ts +508 -0
  47. package/build/resources/types/filters.js +1 -0
  48. package/build/resources/types/index.d.ts +4138 -0
  49. package/build/resources/types/index.js +1 -0
  50. package/build/session/index.d.ts +1474 -0
  51. package/build/session/index.js +1 -0
  52. package/build/translations/auth.en.d.ts +3 -0
  53. package/build/translations/auth.en.js +1 -0
  54. package/build/translations/countries.en.d.ts +6 -0
  55. package/build/translations/countries.en.js +1 -0
  56. package/build/translations/currencies.en.d.ts +5 -0
  57. package/build/translations/currencies.en.js +1 -0
  58. package/build/translations/date.en.d.ts +19 -0
  59. package/build/translations/date.en.js +1 -0
  60. package/build/translations/index.d.ts +1583 -0
  61. package/build/translations/index.js +5 -0
  62. package/build/translations/resources.en.d.ts +6 -0
  63. package/build/translations/resources.en.js +1 -0
  64. package/build/translations/validator.en.d.ts +104 -0
  65. package/build/translations/validator.en.js +5 -0
  66. package/build/types/date.d.ts +44 -0
  67. package/build/types/date.js +1 -0
  68. package/build/types/dictionary.d.ts +29 -0
  69. package/build/types/dictionary.js +1 -0
  70. package/build/types/i18n.d.ts +121 -0
  71. package/build/types/i18n.js +1 -0
  72. package/build/types/index.d.ts +145 -0
  73. package/build/types/index.js +1 -0
  74. package/build/utils/areEquals.d.ts +19 -0
  75. package/build/utils/areEquals.js +1 -0
  76. package/build/utils/date/dateHelper.d.ts +371 -0
  77. package/build/utils/date/dateHelper.js +5 -0
  78. package/build/utils/date/index.d.ts +212 -0
  79. package/build/utils/date/index.js +5 -0
  80. package/build/utils/date/isDateObj.d.ts +14 -0
  81. package/build/utils/date/isDateObj.js +1 -0
  82. package/build/utils/debounce.d.ts +52 -0
  83. package/build/utils/debounce.js +1 -0
  84. package/build/utils/defaultArray.d.ts +18 -0
  85. package/build/utils/defaultArray.js +1 -0
  86. package/build/utils/defaultBool.d.ts +14 -0
  87. package/build/utils/defaultBool.js +1 -0
  88. package/build/utils/defaultStr.d.ts +17 -0
  89. package/build/utils/defaultStr.js +1 -0
  90. package/build/utils/defaultVal.d.ts +18 -0
  91. package/build/utils/defaultVal.js +1 -0
  92. package/build/utils/dom/index.d.ts +65 -0
  93. package/build/utils/dom/index.js +1 -0
  94. package/build/utils/dom/isDOMElement.d.ts +11 -0
  95. package/build/utils/dom/isDOMElement.js +1 -0
  96. package/build/utils/file/index.d.ts +26 -0
  97. package/build/utils/file/index.js +1 -0
  98. package/build/utils/global.d.ts +53 -0
  99. package/build/utils/global.js +1 -0
  100. package/build/utils/image.d.ts +56 -0
  101. package/build/utils/image.js +1 -0
  102. package/build/utils/index.d.ts +39 -0
  103. package/build/utils/index.js +6 -0
  104. package/build/utils/interpolate.d.ts +105 -0
  105. package/build/utils/interpolate.js +1 -0
  106. package/build/utils/isEmail.d.ts +57 -0
  107. package/build/utils/isEmail.js +1 -0
  108. package/build/utils/isEmpty.d.ts +18 -0
  109. package/build/utils/isEmpty.js +1 -0
  110. package/build/utils/isNonNullString.d.ts +17 -0
  111. package/build/utils/isNonNullString.js +1 -0
  112. package/build/utils/isNullable.d.ts +7 -0
  113. package/build/utils/isNullable.js +1 -0
  114. package/build/utils/isNumber.d.ts +36 -0
  115. package/build/utils/isNumber.js +1 -0
  116. package/build/utils/isPrimitive.d.ts +16 -0
  117. package/build/utils/isPrimitive.js +1 -0
  118. package/build/utils/isPromise.d.ts +14 -0
  119. package/build/utils/isPromise.js +1 -0
  120. package/build/utils/isRegex.d.ts +15 -0
  121. package/build/utils/isRegex.js +1 -0
  122. package/build/utils/isTime.d.ts +18 -0
  123. package/build/utils/isTime.js +1 -0
  124. package/build/utils/json.d.ts +224 -0
  125. package/build/utils/json.js +1 -0
  126. package/build/utils/numbers.d.ts +148 -0
  127. package/build/utils/numbers.js +5 -0
  128. package/build/utils/object.d.ts +567 -0
  129. package/build/utils/object.js +1 -0
  130. package/build/utils/sort.d.ts +67 -0
  131. package/build/utils/sort.js +1 -0
  132. package/build/utils/string.d.ts +165 -0
  133. package/build/utils/string.js +1 -0
  134. package/build/utils/stringify.d.ts +23 -0
  135. package/build/utils/stringify.js +1 -0
  136. package/build/utils/uniqid.d.ts +18 -0
  137. package/build/utils/uniqid.js +1 -0
  138. package/build/utils/uri/index.d.ts +333 -0
  139. package/build/utils/uri/index.js +2 -0
  140. package/build/validator/index.d.ts +4 -0
  141. package/build/validator/index.js +6 -0
  142. package/build/validator/rules/array.d.ts +848 -0
  143. package/build/validator/rules/array.js +5 -0
  144. package/build/validator/rules/boolean.d.ts +87 -0
  145. package/build/validator/rules/boolean.js +5 -0
  146. package/build/validator/rules/date.d.ts +551 -0
  147. package/build/validator/rules/date.js +5 -0
  148. package/build/validator/rules/default.d.ts +367 -0
  149. package/build/validator/rules/default.js +5 -0
  150. package/build/validator/rules/enum.d.ts +155 -0
  151. package/build/validator/rules/enum.js +5 -0
  152. package/build/validator/rules/file.d.ts +356 -0
  153. package/build/validator/rules/file.js +5 -0
  154. package/build/validator/rules/format.d.ts +2825 -0
  155. package/build/validator/rules/format.js +6 -0
  156. package/build/validator/rules/index.d.ts +16 -0
  157. package/build/validator/rules/index.js +6 -0
  158. package/build/validator/rules/multiRules.d.ts +475 -0
  159. package/build/validator/rules/multiRules.js +5 -0
  160. package/build/validator/rules/numeric.d.ts +1135 -0
  161. package/build/validator/rules/numeric.js +5 -0
  162. package/build/validator/rules/string.d.ts +504 -0
  163. package/build/validator/rules/string.js +5 -0
  164. package/build/validator/rules/target.d.ts +137 -0
  165. package/build/validator/rules/target.js +5 -0
  166. package/build/validator/rules/utils.d.ts +1 -0
  167. package/build/validator/rules/utils.js +1 -0
  168. package/build/validator/rulesMarkers.d.ts +11 -0
  169. package/build/validator/rulesMarkers.js +1 -0
  170. package/build/validator/types.d.ts +2906 -0
  171. package/build/validator/types.js +1 -0
  172. package/build/validator/validator.d.ts +3692 -0
  173. package/build/validator/validator.js +5 -0
  174. package/lib/cjs/auth.js +1 -0
  175. package/lib/cjs/countries.js +1 -0
  176. package/lib/cjs/currency.js +1 -0
  177. package/lib/cjs/i18n.js +1 -0
  178. package/lib/cjs/inputFormatter.js +1 -0
  179. package/lib/cjs/logger.js +1 -0
  180. package/lib/cjs/observable.js +1 -0
  181. package/lib/cjs/platform.js +1 -0
  182. package/lib/cjs/resources.js +1 -0
  183. package/lib/cjs/session.js +1 -0
  184. package/lib/cjs/types.js +1 -0
  185. package/lib/cjs/utils.js +1 -0
  186. package/lib/cjs/validator.js +1 -0
  187. package/lib/esm/auth.mjs +1 -0
  188. package/lib/esm/countries.mjs +1 -0
  189. package/lib/esm/currency.mjs +1 -0
  190. package/lib/esm/i18n.mjs +1 -0
  191. package/lib/esm/inputFormatter.mjs +1 -0
  192. package/lib/esm/logger.mjs +1 -0
  193. package/lib/esm/observable.mjs +1 -0
  194. package/lib/esm/platform.mjs +1 -0
  195. package/lib/esm/resources.mjs +1 -0
  196. package/lib/esm/session.mjs +1 -0
  197. package/lib/esm/types.mjs +1 -0
  198. package/lib/esm/utils.mjs +1 -0
  199. package/lib/esm/validator.mjs +1 -0
  200. package/package.json +244 -0
@@ -0,0 +1,848 @@
1
+ /**
2
+ * ## IsArray Decorator
3
+ *
4
+ * Property decorator that validates a property value is an array.
5
+ * This is a fundamental array validation decorator that ensures the value
6
+ * is actually an array before applying other array-specific validations.
7
+ *
8
+ * ### Usage
9
+ * ```typescript
10
+ * class ProductList {
11
+ * @IsArray()
12
+ * products: Product[];
13
+ * }
14
+ * ```
15
+ *
16
+ * ### Validation Behavior
17
+ * - **Passes**: When value is an array (including empty arrays)
18
+ * - **Fails**: When value is not an array (null, undefined, object, string, number, etc.)
19
+ *
20
+ * ### Error Messages
21
+ * - Default: `"[PropertyName]: Must be an array"`
22
+ * - I18n key: `"validator.array"`
23
+ *
24
+ * ### Related Decorators
25
+ * - Often used as prerequisite for: `@ArrayMinLength`, `@ArrayMaxLength`, `@ArrayLength`, `@ArrayContains`, `@ArrayUnique`, `@ArrayAllStrings`, `@ArrayAllNumbers`
26
+ *
27
+ * @returns A property decorator function
28
+ * @public
29
+ */
30
+ export declare const IsArray: () => PropertyDecorator;
31
+ /**
32
+ * ## ArrayMinLength Decorator
33
+ *
34
+ * Property decorator that validates an array has at least the specified minimum number of elements.
35
+ * Ensures arrays meet minimum size requirements for business logic.
36
+ *
37
+ * ### Usage
38
+ * ```typescript
39
+ * class ShoppingCart {
40
+ * @IsArray()
41
+ * @ArrayMinLength(1)
42
+ * items: CartItem[];
43
+ * }
44
+ * ```
45
+ *
46
+ * ### Parameters
47
+ * - `minLength: number` - The minimum number of elements required
48
+ *
49
+ * ### Validation Behavior
50
+ * - **Passes**: When array length >= minimum length
51
+ * - **Fails**: When array length < minimum length
52
+ * - **Edge cases**: Empty arrays fail if minLength > 0
53
+ *
54
+ * ### Error Messages
55
+ * - Default: `"[PropertyName]: Must contain at least {minLength} items"`
56
+ * - I18n key: `"validator.arrayMinLength"`
57
+ *
58
+ * ### Performance
59
+ * - **O(1) operation**: Only checks array length property
60
+ * - Fast validation suitable for large arrays
61
+ *
62
+ * @param minLength - Minimum number of elements required
63
+ * @returns A property decorator function
64
+ * @public
65
+ */
66
+ export declare const ArrayMinLength: (minLength: number) => PropertyDecorator;
67
+ /**
68
+ * ## ArrayMaxLength Decorator
69
+ *
70
+ * Property decorator that validates an array does not exceed the specified maximum number of elements.
71
+ * Prevents arrays from growing beyond acceptable limits to avoid memory issues or performance problems.
72
+ *
73
+ * ### Usage
74
+ * ```typescript
75
+ * class FileUploads {
76
+ * @IsArray()
77
+ * @ArrayMaxLength(5)
78
+ * files: UploadedFile[];
79
+ * }
80
+ * ```
81
+ *
82
+ * ### Parameters
83
+ * - `maxLength: number` - The maximum number of elements allowed
84
+ *
85
+ * ### Validation Behavior
86
+ * - **Passes**: When array length <= maximum length
87
+ * - **Fails**: When array length > maximum length
88
+ * - **Edge cases**: Empty arrays always pass
89
+ *
90
+ * ### Error Messages
91
+ * - Default: `"[PropertyName]: Must not contain more than {maxLength} items"`
92
+ * - I18n key: `"validator.arrayMaxLength"`
93
+ *
94
+ * ### Performance
95
+ * - **O(1) operation**: Only checks array length property
96
+ * - Fast validation suitable for large arrays
97
+ *
98
+ * @param maxLength - Maximum number of elements allowed
99
+ * @returns A property decorator function
100
+ * @public
101
+ */
102
+ export declare const ArrayMaxLength: (maxLength: number) => PropertyDecorator;
103
+ /**
104
+ * ## ArrayLength Decorator
105
+ *
106
+ * Property decorator that validates an array has exactly the specified number of elements.
107
+ * Ensures arrays have a precise, required size for structured data requirements.
108
+ *
109
+ * ### Usage
110
+ * ```typescript
111
+ * class RGBColor {
112
+ * @IsArray()
113
+ * @ArrayLength(3)
114
+ * @ArrayAllNumbers()
115
+ * values: number[]; // [1, 2, 3]
116
+ * }
117
+ * ```
118
+ *
119
+ * ### Parameters
120
+ * - `length: number` - The exact number of elements required
121
+ *
122
+ * ### Validation Behavior
123
+ * - **Passes**: When array length === exact length
124
+ * - **Fails**: When array length !== exact length
125
+ * - **Edge cases**: Empty arrays fail unless length is 0
126
+ *
127
+ * ### Error Messages
128
+ * - Default: `"[PropertyName]: Must contain exactly {length} items"`
129
+ * - I18n key: `"validator.arrayLength"`
130
+ *
131
+ * ### Performance
132
+ * - **O(1) operation**: Only checks array length property
133
+ * - Fast validation suitable for large arrays
134
+ *
135
+ * @param length - Exact number of elements required
136
+ * @returns A property decorator function
137
+ * @public
138
+ */
139
+ export declare const ArrayLength: (length: number) => PropertyDecorator;
140
+ /**
141
+ * ## ArrayContains Decorator
142
+ *
143
+ * Property decorator that validates an array contains all of the specified required values.
144
+ * Ensures that certain elements are present in the array for business logic requirements.
145
+ *
146
+ * ### Usage
147
+ * ```typescript
148
+ * class UserPermissions {
149
+ * @IsArray()
150
+ * @ArrayContains(["read", "write"])
151
+ * permissions: string[];
152
+ * }
153
+ * ```
154
+ *
155
+ * ### Parameters
156
+ * - `...requiredValues: any[]` - Values that must all be present in the array
157
+ *
158
+ * ### Validation Behavior
159
+ * - **Passes**: When array contains ALL specified values
160
+ * - **Fails**: When array is missing ANY specified value
161
+ * - **Comparison**: Uses deep equality checking for objects
162
+ *
163
+ * ### Error Messages
164
+ * - Default: `"[PropertyName]: Must contain all required values: {missingValues}"`
165
+ * - I18n key: `"validator.arrayContains"`
166
+ *
167
+ * ### Performance
168
+ * - **O(n*m) operation**: n = array length, m = required values length
169
+ * - May be slow for complex objects due to deep equality checking
170
+ *
171
+ * @param requiredValues - Values that must be present in the array
172
+ * @returns A property decorator function
173
+ * @public
174
+ */
175
+ export declare const ArrayContains: (...ruleParameters: any[]) => PropertyDecorator;
176
+ /**
177
+ * ## ArrayUnique Decorator
178
+ *
179
+ * Property decorator that validates all elements in an array are unique (no duplicates).
180
+ * Ensures arrays contain distinct values only, commonly used for IDs and identifiers.
181
+ *
182
+ * ### Usage
183
+ * ```typescript
184
+ * class UserIds {
185
+ * @IsArray()
186
+ * @ArrayUnique()
187
+ * @ArrayAllStrings()
188
+ * userIds: string[];
189
+ * }
190
+ * ```
191
+ *
192
+ * ### Parameters
193
+ * - No parameters required
194
+ *
195
+ * ### Validation Behavior
196
+ * - **Passes**: When all array elements are unique
197
+ * - **Fails**: When any element appears more than once
198
+ * - **Empty/Single element arrays**: Always pass
199
+ *
200
+ * ### Uniqueness Checking
201
+ * - **Primitive types**: Compared by value
202
+ * - **Objects**: Compared by JSON string representation
203
+ * - **Null/undefined**: Treated as distinct values
204
+ *
205
+ * ### Error Messages
206
+ * - Default: `"[PropertyName]: Must contain only unique values"`
207
+ * - I18n key: `"validator.arrayUnique"`
208
+ *
209
+ * ### Performance
210
+ * - **O(n²) worst case**: Due to comparison operations
211
+ * - **Early exit**: Stops on first duplicate found
212
+ * - Uses Set for primitive type optimization
213
+ *
214
+ * @returns A property decorator function
215
+ * @public
216
+ */
217
+ export declare const ArrayUnique: () => PropertyDecorator;
218
+ /**
219
+ * ## ArrayAllStrings Decorator
220
+ *
221
+ * Property decorator that validates all elements in an array are strings.
222
+ * Ensures type homogeneity for string arrays used in text data collections.
223
+ *
224
+ * ### Usage
225
+ * ```typescript
226
+ * class TagList {
227
+ * @IsArray()
228
+ * @ArrayAllStrings()
229
+ * @ArrayUnique()
230
+ * tags: string[];
231
+ * }
232
+ * ```
233
+ *
234
+ * ### Parameters
235
+ * - No parameters required
236
+ *
237
+ * ### Validation Behavior
238
+ * - **Passes**: When all elements are strings (including empty strings)
239
+ * - **Fails**: When any element is not a string
240
+ * - **Empty arrays**: Always pass
241
+ *
242
+ * ### Error Messages
243
+ * - Default: `"[PropertyName]: All items must be strings"`
244
+ * - I18n key: `"validator.arrayAllStrings"`
245
+ *
246
+ * ### Performance
247
+ * - **O(n) operation**: Iterates through all array elements
248
+ * - **Early exit**: Stops on first non-string element
249
+ * - Uses fast `typeof` operator
250
+ *
251
+ * @returns A property decorator function
252
+ * @public
253
+ */
254
+ export declare const ArrayAllStrings: () => PropertyDecorator;
255
+ /**
256
+ * ## ArrayAllNumbers Decorator
257
+ *
258
+ * Property decorator that validates all elements in an array are numbers.
259
+ * Ensures type homogeneity for numeric arrays used in data collections.
260
+ *
261
+ * ### Usage
262
+ * ```typescript
263
+ * class SensorReadings {
264
+ * @IsArray()
265
+ * @ArrayAllNumbers()
266
+ * @ArrayMinLength(1)
267
+ * values: number[];
268
+ * }
269
+ * ```
270
+ *
271
+ * ### Parameters
272
+ * - No parameters required
273
+ *
274
+ * ### Validation Behavior
275
+ * - **Passes**: When all elements are numbers (excluding NaN)
276
+ * - **Fails**: When any element is not a number or is NaN
277
+ * - **Empty arrays**: Always pass
278
+ *
279
+ * ### Number Type Considerations
280
+ * - **Valid**: `42`, `3.14`, `-0`, `Infinity`, `-Infinity`
281
+ * - **Invalid**: `NaN`, strings `"42"`, booleans, objects, null, undefined
282
+ *
283
+ * ### Error Messages
284
+ * - Default: `"[PropertyName]: All items must be numbers"`
285
+ * - I18n key: `"validator.arrayAllNumbers"`
286
+ *
287
+ * ### Performance
288
+ * - **O(n) operation**: Iterates through all array elements
289
+ * - **Early exit**: Stops on first invalid element
290
+ * - Uses fast `typeof` and `Number.isNaN` checks
291
+ *
292
+ * @returns A property decorator function
293
+ * @public
294
+ */
295
+ export declare const ArrayAllNumbers: () => PropertyDecorator;
296
+ declare module '../types' {
297
+ interface ValidatorRuleParamTypes {
298
+ /**
299
+ * ## Array Validation Rule
300
+ *
301
+ * Validates that a property value is an array. This is a fundamental array validation rule
302
+ * that ensures the value is actually an array before applying other array-specific validations.
303
+ *
304
+ * ### Purpose
305
+ * Ensures the property value is an array type before applying array-specific validation rules.
306
+ * This rule is typically used as a prerequisite for other array validation rules.
307
+ *
308
+ * ### Parameter Structure
309
+ * - **No parameters required**: `ValidatorRuleParams<[]>`
310
+ * - Rule takes no arguments: `"Array"`
311
+ *
312
+ * ### Usage Examples
313
+ *
314
+ * #### Basic Usage
315
+ * ```typescript
316
+ * class ProductList {
317
+ * @IsArray()
318
+ * products: Product[];
319
+ * }
320
+ * ```
321
+ *
322
+ * #### Combined with Other Array Rules
323
+ * ```typescript
324
+ * class UserRoles {
325
+ * @IsArray()
326
+ * @ArrayMinLength(1)
327
+ * @ArrayAllStrings()
328
+ * roles: string[];
329
+ * }
330
+ * ```
331
+ *
332
+ * ### Validation Behavior
333
+ * - **Passes**: When value is an array (including empty arrays)
334
+ * - **Fails**: When value is not an array (null, undefined, object, string, number, etc.)
335
+ *
336
+ * ### Error Messages
337
+ * - Default: `"[PropertyName]: Must be an array"`
338
+ * - I18n key: `"validator.array"`
339
+ *
340
+ * ### Common Use Cases
341
+ * - Validating API responses that should return arrays
342
+ * - Ensuring form inputs that collect multiple values are arrays
343
+ * - Type guarding before applying array-specific operations
344
+ *
345
+ * ### Relationship to Other Rules
346
+ * - **Prerequisite for**: `ArrayMinLength`, `ArrayMaxLength`, `ArrayLength`, `ArrayContains`, `ArrayUnique`, `ArrayAllStrings`, `ArrayAllNumbers`
347
+ * - **Often combined with**: Array length and content validation rules
348
+ *
349
+ * @public
350
+ */
351
+ Array: ValidatorRuleParams<[]>;
352
+ /**
353
+ * ## Array Minimum Length Validation Rule
354
+ *
355
+ * Validates that an array has at least the specified minimum number of elements.
356
+ * This rule ensures arrays meet minimum size requirements.
357
+ *
358
+ * ### Purpose
359
+ * Enforces minimum array length constraints, commonly used for ensuring collections
360
+ * have sufficient elements for business logic requirements.
361
+ *
362
+ * ### Parameter Structure
363
+ * - **Single parameter**: `ValidatorRuleParams<[minLength: number]>`
364
+ * - **Parameter type**: `number` (minimum length required)
365
+ * - **Rule syntax**: `"ArrayMinLength[5]"` (minimum 5 elements)
366
+ *
367
+ * ### Usage Examples
368
+ *
369
+ * #### Basic Minimum Length
370
+ * ```typescript
371
+ * class ShoppingCart {
372
+ * @IsArray()
373
+ * @ArrayMinLength(1)
374
+ * items: CartItem[];
375
+ * }
376
+ * ```
377
+ *
378
+ * #### Combined with Maximum Length
379
+ * ```typescript
380
+ * class TeamMembers {
381
+ * @IsArray()
382
+ * @ArrayMinLength(2)
383
+ * @ArrayMaxLength(10)
384
+ * members: User[];
385
+ * }
386
+ * ```
387
+ *
388
+ * ### Validation Behavior
389
+ * - **Passes**: When array length >= minimum length
390
+ * - **Fails**: When array length < minimum length
391
+ * - **Edge cases**: Empty arrays fail if minLength > 0
392
+ *
393
+ * ### Parameter Validation
394
+ * - **Type checking**: Parameter must be a valid number
395
+ * - **Range validation**: Parameter must be >= 0
396
+ * - **Invalid parameters**: Throws error during rule parsing
397
+ *
398
+ * ### Error Messages
399
+ * - Default: `"[PropertyName]: Must contain at least {minLength} items"`
400
+ * - I18n key: `"validator.arrayMinLength"`
401
+ *
402
+ * ### Common Use Cases
403
+ * - Shopping carts requiring at least one item
404
+ * - Teams requiring minimum member counts
405
+ * - Collections needing baseline data
406
+ *
407
+ * ### Performance Notes
408
+ * - **O(1) operation**: Only checks array length property
409
+ * - **No iteration**: Does not traverse array elements
410
+ * - **Fast validation**: Suitable for large arrays
411
+ *
412
+ * @public
413
+ */
414
+ ArrayMinLength: ValidatorRuleParams<[minLength: number]>;
415
+ /**
416
+ * ## Array Maximum Length Validation Rule
417
+ *
418
+ * Validates that an array does not exceed the specified maximum number of elements.
419
+ * This rule prevents arrays from growing beyond acceptable limits.
420
+ *
421
+ * ### Purpose
422
+ * Enforces maximum array length constraints to prevent excessive data,
423
+ * memory issues, or performance problems with large collections.
424
+ *
425
+ * ### Parameter Structure
426
+ * - **Single parameter**: `ValidatorRuleParams<[maxLength: number]>`
427
+ * - **Parameter type**: `number` (maximum length allowed)
428
+ * - **Rule syntax**: `"ArrayMaxLength[100]"` (maximum 100 elements)
429
+ *
430
+ * ### Usage Examples
431
+ *
432
+ * #### Basic Maximum Length
433
+ * ```typescript
434
+ * class FileUploads {
435
+ * @IsArray()
436
+ * @ArrayMaxLength(5)
437
+ * files: UploadedFile[];
438
+ * }
439
+ * ```
440
+ *
441
+ * #### Combined with Minimum Length
442
+ * ```typescript
443
+ * class CommitteeMembers {
444
+ * @IsArray()
445
+ * @ArrayMinLength(3)
446
+ * @ArrayMaxLength(7)
447
+ * members: Person[];
448
+ * }
449
+ * ```
450
+ *
451
+ * ### Validation Behavior
452
+ * - **Passes**: When array length <= maximum length
453
+ * - **Fails**: When array length > maximum length
454
+ * - **Edge cases**: Empty arrays always pass
455
+ *
456
+ * ### Parameter Validation
457
+ * - **Type checking**: Parameter must be a valid number
458
+ * - **Range validation**: Parameter must be >= 0
459
+ * - **Invalid parameters**: Throws error during rule parsing
460
+ *
461
+ * ### Error Messages
462
+ * - Default: `"[PropertyName]: Must not contain more than {maxLength} items"`
463
+ * - I18n key: `"validator.arrayMaxLength"`
464
+ *
465
+ * ### Common Use Cases
466
+ * - Limiting file upload counts
467
+ * - Restricting participant numbers in events
468
+ * - Preventing memory issues with large datasets
469
+ * - Enforcing business rules on collection sizes
470
+ *
471
+ * ### Performance Notes
472
+ * - **O(1) operation**: Only checks array length property
473
+ * - **No iteration**: Does not traverse array elements
474
+ * - **Fast validation**: Suitable for large arrays
475
+ *
476
+ * @public
477
+ */
478
+ ArrayMaxLength: ValidatorRuleParams<[maxLength: number]>;
479
+ /**
480
+ * ## Array Exact Length Validation Rule
481
+ *
482
+ * Validates that an array has exactly the specified number of elements.
483
+ * This rule ensures arrays have a precise, required size.
484
+ *
485
+ * ### Purpose
486
+ * Enforces exact array length requirements where the number of elements
487
+ * must match a specific count exactly, not more or less.
488
+ *
489
+ * ### Parameter Structure
490
+ * - **Single parameter**: `ValidatorRuleParams<[length: number]>`
491
+ * - **Parameter type**: `number` (exact length required)
492
+ * - **Rule syntax**: `"ArrayLength[3]"` (exactly 3 elements required)
493
+ *
494
+ * ### Usage Examples
495
+ *
496
+ * #### Fixed-Size Collections
497
+ * ```typescript
498
+ * class RGBColor {
499
+ * @IsArray()
500
+ * @ArrayLength(3)
501
+ * @ArrayAllNumbers()
502
+ * values: number[]; // [r, g, b]
503
+ * }
504
+ * ```
505
+ *
506
+ * #### Structured Data Requirements
507
+ * ```typescript
508
+ * class Coordinate {
509
+ * @IsArray()
510
+ * @ArrayLength(2)
511
+ * @ArrayAllNumbers()
512
+ * point: number[]; // [x, y]
513
+ * }
514
+ * ```
515
+ *
516
+ * ### Validation Behavior
517
+ * - **Passes**: When array length === exact length
518
+ * - **Fails**: When array length !== exact length
519
+ * - **Edge cases**: Empty arrays fail unless length is 0
520
+ *
521
+ * ### Parameter Validation
522
+ * - **Type checking**: Parameter must be a valid number
523
+ * - **Range validation**: Parameter must be >= 0
524
+ * - **Invalid parameters**: Throws error during rule parsing
525
+ *
526
+ * ### Error Messages
527
+ * - Default: `"[PropertyName]: Must contain exactly {length} items"`
528
+ * - I18n key: `"validator.arrayLength"`
529
+ *
530
+ * ### Common Use Cases
531
+ * - Color values requiring specific channel counts
532
+ * - Geographic coordinates with fixed dimensions
533
+ * - Structured data with known field counts
534
+ * - Protocol buffers or fixed-schema data structures
535
+ *
536
+ * ### Performance Notes
537
+ * - **O(1) operation**: Only checks array length property
538
+ * - **No iteration**: Does not traverse array elements
539
+ * - **Fast validation**: Suitable for large arrays
540
+ *
541
+ * ### Comparison with Range Rules
542
+ * | Rule | Use Case | Example |
543
+ * |------|----------|---------|
544
+ * | `ArrayLength` | Exact count required | RGB values: exactly 3 numbers |
545
+ * | `ArrayMinLength` + `ArrayMaxLength` | Size range allowed | Team: 2-10 members |
546
+ *
547
+ * @public
548
+ */
549
+ ArrayLength: ValidatorRuleParams<[length: number]>;
550
+ /**
551
+ * ## Array Contains Validation Rule
552
+ *
553
+ * Validates that an array contains all of the specified required values.
554
+ * This rule ensures that certain elements are present in the array.
555
+ *
556
+ * ### Purpose
557
+ * Ensures that an array includes specific required elements, commonly used
558
+ * for validating that collections contain mandatory items or meet inclusion criteria.
559
+ *
560
+ * ### Parameter Structure
561
+ * - **Array parameter**: `ValidatorRuleParams<any[]>`
562
+ * - **Parameter type**: `any[]` (array of values that must be present)
563
+ * - **Rule syntax**: `"ArrayContains[value1, value2, ...]"`
564
+ *
565
+ * ### Usage Examples
566
+ *
567
+ * #### Required Permissions
568
+ * ```typescript
569
+ * class UserPermissions {
570
+ * @IsArray()
571
+ * @ArrayContains(["read", "write"])
572
+ * permissions: string[];
573
+ * }
574
+ * ```
575
+ *
576
+ * #### Mandatory Categories
577
+ * ```typescript
578
+ * class ProductTags {
579
+ * @IsArray()
580
+ * @ArrayContains(["electronics", "featured"])
581
+ * tags: string[];
582
+ * }
583
+ * ```
584
+ *
585
+ * ### Validation Behavior
586
+ * - **Passes**: When array contains ALL specified values
587
+ * - **Fails**: When array is missing ANY specified value
588
+ * - **Comparison**: Uses deep equality checking for objects
589
+ *
590
+ * ### Parameter Validation
591
+ * - **Type checking**: Parameter must be an array
592
+ * - **Empty arrays**: Valid but meaningless (no requirements)
593
+ * - **Invalid parameters**: Throws error during rule parsing
594
+ *
595
+ * ### Error Messages
596
+ * - Default: `"[PropertyName]: Must contain all required values: {missingValues}"`
597
+ * - I18n key: `"validator.arrayContains"`
598
+ *
599
+ * ### Common Use Cases
600
+ * - User permissions requiring specific access levels
601
+ * - Product categories needing mandatory tags
602
+ * - Configuration requiring essential settings
603
+ * - Business rules mandating certain options
604
+ *
605
+ * ### Performance Notes
606
+ * - **O(n*m) operation**: n = array length, m = required values length
607
+ * - **Nested loops**: Uses `some()` and `every()` for checking
608
+ * - **Deep equality**: May be slow for complex objects
609
+ *
610
+ * ### Important Considerations
611
+ * - **Deep equality**: Objects are compared by structure, not reference
612
+ * - **Primitive types**: Strings, numbers, booleans compared by value
613
+ * - **Null/undefined**: Treated as distinct values
614
+ * - **Order irrelevant**: Array order doesn't affect validation
615
+ *
616
+ * @public
617
+ */
618
+ ArrayContains: ValidatorRuleParams<any[]>;
619
+ /**
620
+ * ## Array Uniqueness Validation Rule
621
+ *
622
+ * Validates that all elements in an array are unique (no duplicates).
623
+ * This rule ensures arrays contain distinct values only.
624
+ *
625
+ * ### Purpose
626
+ * Prevents duplicate values in arrays where uniqueness is required,
627
+ * commonly used for IDs, usernames, email lists, or any collection
628
+ * where duplicates would cause issues.
629
+ *
630
+ * ### Parameter Structure
631
+ * - **No parameters required**: `ValidatorRuleParams<[]>`
632
+ * - Rule takes no arguments: `"ArrayUnique"`
633
+ *
634
+ * ### Usage Examples
635
+ *
636
+ * #### Unique Identifiers
637
+ * ```typescript
638
+ * class UserIds {
639
+ * @IsArray()
640
+ * @ArrayUnique()
641
+ * @ArrayAllStrings()
642
+ * userIds: string[];
643
+ * }
644
+ * ```
645
+ *
646
+ * #### Unique Email List
647
+ * ```typescript
648
+ * class InvitationList {
649
+ * @IsArray()
650
+ * @ArrayUnique()
651
+ * @ArrayAllStrings()
652
+ * emails: string[];
653
+ * }
654
+ * ```
655
+ *
656
+ * ### Validation Behavior
657
+ * - **Passes**: When all array elements are unique
658
+ * - **Fails**: When any element appears more than once
659
+ * - **Empty arrays**: Always pass (no duplicates possible)
660
+ * - **Single element**: Always pass (no duplicates possible)
661
+ *
662
+ * ### Uniqueness Checking
663
+ * - **Primitive types**: Compared by value (string, number, boolean)
664
+ * - **Objects**: Compared by reference (not deep equality)
665
+ * - **Null/undefined**: Treated as distinct values
666
+ * - **Mixed types**: Different types are considered unique
667
+ *
668
+ * ### Error Messages
669
+ * - Default: `"[PropertyName]: Must contain only unique values"`
670
+ * - I18n key: `"validator.arrayUnique"`
671
+ *
672
+ * ### Common Use Cases
673
+ * - User ID collections
674
+ * - Email address lists
675
+ * - Tag collections
676
+ * - Primary key arrays
677
+ * - Selection lists without duplicates
678
+ *
679
+ * ### Performance Notes
680
+ * - **O(n²) worst case**: Nested loops for comparison
681
+ * - **Early exit**: Stops on first duplicate found
682
+ * - **Memory efficient**: Uses Set for primitive type optimization
683
+ * - **Object comparison**: Reference-based (fast but shallow)
684
+ *
685
+ * ### Important Considerations
686
+ * - **Object uniqueness**: Based on reference, not content
687
+ * - **Deep equality**: Not performed for performance reasons
688
+ * - **Custom comparison**: Not supported (use custom rule if needed)
689
+ * - **Case sensitivity**: String comparison is case-sensitive
690
+ *
691
+ * ### Alternatives for Complex Uniqueness
692
+ * For content-based uniqueness of objects, consider custom validation rules:
693
+ * ```typescript
694
+ * const uniqueByProperty = ({ value }) => {
695
+ * const ids = value.map(item => item.id);
696
+ * return ids.length === new Set(ids).size || "Duplicate IDs found";
697
+ * };
698
+ * ```
699
+ *
700
+ * @public
701
+ */
702
+ ArrayUnique: ValidatorRuleParams<[]>;
703
+ /**
704
+ * ## Array All Strings Validation Rule
705
+ *
706
+ * Validates that all elements in an array are strings.
707
+ * This rule ensures type homogeneity for string arrays.
708
+ *
709
+ * ### Purpose
710
+ * Enforces that array elements are exclusively strings, commonly used
711
+ * for validating collections of text data, identifiers, or labels.
712
+ *
713
+ * ### Parameter Structure
714
+ * - **No parameters required**: `ValidatorRuleParams<[]>`
715
+ * - Rule takes no arguments: `"ArrayAllStrings"`
716
+ *
717
+ * ### Usage Examples
718
+ *
719
+ * #### String Collections
720
+ * ```typescript
721
+ * class TagList {
722
+ * @IsArray()
723
+ * @ArrayAllStrings()
724
+ * @ArrayUnique()
725
+ * tags: string[];
726
+ * }
727
+ * ```
728
+ *
729
+ * #### User Input Arrays
730
+ * ```typescript
731
+ * class SearchKeywords {
732
+ * @IsArray()
733
+ * @ArrayAllStrings()
734
+ * @ArrayMinLength(1)
735
+ * keywords: string[];
736
+ * }
737
+ * ```
738
+ *
739
+ * ### Validation Behavior
740
+ * - **Passes**: When all elements are strings (including empty strings)
741
+ * - **Fails**: When any element is not a string
742
+ * - **Empty arrays**: Always pass (no non-string elements)
743
+ * - **Type checking**: Uses `typeof item === 'string'`
744
+ *
745
+ * ### Error Messages
746
+ * - Default: `"[PropertyName]: All items must be strings"`
747
+ * - I18n key: `"validator.arrayAllStrings"`
748
+ *
749
+ * ### Common Use Cases
750
+ * - Tag collections
751
+ * - Keyword lists
752
+ * - User input arrays
753
+ * - Identifier collections
754
+ * - Text-based data arrays
755
+ *
756
+ * ### Performance Notes
757
+ * - **O(n) operation**: Iterates through all array elements
758
+ * - **Early exit**: Stops on first non-string element
759
+ * - **Type checking**: Uses fast `typeof` operator
760
+ *
761
+ * ### Related Rules
762
+ * - **ArrayAllNumbers**: For numeric arrays
763
+ * - **ArrayUnique**: For unique string arrays
764
+ * - **ArrayMinLength/ArrayMaxLength**: For size constraints
765
+ *
766
+ * @public
767
+ */
768
+ ArrayAllStrings: ValidatorRuleParams<[]>;
769
+ /**
770
+ * ## Array All Numbers Validation Rule
771
+ *
772
+ * Validates that all elements in an array are numbers.
773
+ * This rule ensures type homogeneity for numeric arrays.
774
+ *
775
+ * ### Purpose
776
+ * Enforces that array elements are exclusively numbers, commonly used
777
+ * for validating collections of numeric data, measurements, or calculations.
778
+ *
779
+ * ### Parameter Structure
780
+ * - **No parameters required**: `ValidatorRuleParams<[]>`
781
+ * - Rule takes no arguments: `"ArrayAllNumbers"`
782
+ *
783
+ * ### Usage Examples
784
+ *
785
+ * #### Numeric Data Collections
786
+ * ```typescript
787
+ * class SensorReadings {
788
+ * @IsArray()
789
+ * @ArrayAllNumbers()
790
+ * @ArrayMinLength(1)
791
+ * values: number[];
792
+ * }
793
+ * ```
794
+ *
795
+ * #### Coordinate Arrays
796
+ * ```typescript
797
+ * class PolygonPoints {
798
+ * @IsArray()
799
+ * @ArrayAllNumbers()
800
+ * @ArrayLength(6) // [x1,y1,x2,y2,x3,y3]
801
+ * coordinates: number[];
802
+ * }
803
+ * ```
804
+ *
805
+ * ### Validation Behavior
806
+ * - **Passes**: When all elements are numbers (including NaN, Infinity)
807
+ * - **Fails**: When any element is not a number
808
+ * - **Empty arrays**: Always pass (no non-number elements)
809
+ * - **Type checking**: Uses `typeof item === 'number'`
810
+ *
811
+ * ### Number Type Considerations
812
+ * - **Valid numbers**: `42`, `3.14`, `-0`, `NaN`, `Infinity`, `-Infinity`
813
+ * - **Invalid values**: Strings `"42"`, booleans, objects, null, undefined
814
+ * - **Numeric strings**: Not accepted (must be actual numbers)
815
+ *
816
+ * ### Error Messages
817
+ * - Default: `"[PropertyName]: All items must be numbers"`
818
+ * - I18n key: `"validator.arrayAllNumbers"`
819
+ *
820
+ * ### Common Use Cases
821
+ * - Sensor data collections
822
+ * - Measurement arrays
823
+ * - Coordinate systems
824
+ * - Statistical data
825
+ * - Mathematical calculations
826
+ *
827
+ * ### Performance Notes
828
+ * - **O(n) operation**: Iterates through all array elements
829
+ * - **Early exit**: Stops on first non-number element
830
+ * - **Type checking**: Uses fast `typeof` operator
831
+ *
832
+ * ### Related Rules
833
+ * - **ArrayAllStrings**: For string arrays
834
+ * - **ArrayUnique**: For unique number arrays
835
+ * - **ArrayMinLength/ArrayMaxLength**: For size constraints
836
+ * - **NumberGT/NumberLT**: For individual number validation
837
+ *
838
+ * ### Important Considerations
839
+ * - **NaN handling**: `NaN` values are considered valid numbers
840
+ * - **Infinity handling**: `Infinity` and `-Infinity` are valid numbers
841
+ * - **Type coercion**: No automatic conversion from strings to numbers
842
+ * - **Precision**: No validation of number precision or range
843
+ *
844
+ * @public
845
+ */
846
+ ArrayAllNumbers: ValidatorRuleParams<[]>;
847
+ }
848
+ }