reslib 1.0.3 → 2.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 (62) hide show
  1. package/README.md +9 -5
  2. package/build/auth/index.js +2 -2
  3. package/build/countries/index.js +2 -2
  4. package/build/currency/index.js +2 -2
  5. package/build/currency/session.js +2 -2
  6. package/build/exception/index.d.ts +1901 -0
  7. package/build/exception/index.js +5 -0
  8. package/build/i18n/index.d.ts +12 -4
  9. package/build/i18n/index.js +2 -2
  10. package/build/inputFormatter/index.js +2 -2
  11. package/build/logger/index.js +2 -2
  12. package/build/resources/ResourcePaginationHelper.js +1 -1
  13. package/build/resources/decorators/index.js +1 -1
  14. package/build/resources/fields/index.d.ts +5 -5
  15. package/build/resources/fields/index.js +1 -1
  16. package/build/resources/index.d.ts +1 -1
  17. package/build/resources/index.js +3 -3
  18. package/build/translations/index.d.ts +40 -4
  19. package/build/translations/index.js +2 -2
  20. package/build/translations/validator.en.d.ts +73 -4
  21. package/build/translations/validator.en.js +2 -2
  22. package/build/types/index.d.ts +21 -0
  23. package/build/utils/date/dateHelper.js +2 -2
  24. package/build/utils/date/index.js +2 -2
  25. package/build/utils/index.d.ts +2 -2
  26. package/build/utils/index.js +3 -3
  27. package/build/utils/interpolate.js +1 -1
  28. package/build/utils/isTime.js +1 -1
  29. package/build/utils/numbers.js +2 -2
  30. package/build/utils/object.js +1 -1
  31. package/build/validator/errors/index.d.ts +299 -0
  32. package/build/validator/errors/index.js +1 -0
  33. package/build/validator/index.d.ts +1 -0
  34. package/build/validator/index.js +3 -3
  35. package/build/validator/rules/array.js +2 -2
  36. package/build/validator/rules/boolean.js +2 -2
  37. package/build/validator/rules/date.js +2 -2
  38. package/build/validator/rules/default.js +2 -2
  39. package/build/validator/rules/enum.js +2 -2
  40. package/build/validator/rules/file.js +2 -2
  41. package/build/validator/rules/format.d.ts +182 -13
  42. package/build/validator/rules/format.js +3 -3
  43. package/build/validator/rules/index.d.ts +1 -0
  44. package/build/validator/rules/index.js +3 -3
  45. package/build/validator/rules/multiRules.d.ts +10 -10
  46. package/build/validator/rules/multiRules.js +2 -2
  47. package/build/validator/rules/numeric.d.ts +8 -8
  48. package/build/validator/rules/numeric.js +2 -2
  49. package/build/validator/rules/object.d.ts +71 -0
  50. package/build/validator/rules/object.js +5 -0
  51. package/build/validator/rules/string.d.ts +6 -6
  52. package/build/validator/rules/string.js +2 -2
  53. package/build/validator/rules/target.d.ts +8 -8
  54. package/build/validator/rules/target.js +2 -2
  55. package/build/validator/rules.types.d.ts +167 -0
  56. package/build/validator/rules.types.js +1 -0
  57. package/build/validator/types.d.ts +832 -1286
  58. package/build/validator/validator.d.ts +554 -867
  59. package/build/validator/validator.js +2 -2
  60. package/lib/cjs/exception.js +1 -0
  61. package/lib/esm/exception.mjs +2 -0
  62. package/package.json +254 -244
@@ -144,7 +144,7 @@ import { IsUrlOptions } from '../../utils/uri';
144
144
  *
145
145
  * @returns {PropertyDecorator} A property decorator that validates email format
146
146
  *
147
- * @throws {ValidationError} When validation fails, containing localized error message
147
+ * @throws {ValidatorError} When validation fails, containing localized error message
148
148
  *
149
149
  * @example
150
150
  * ```typescript
@@ -168,6 +168,64 @@ import { IsUrlOptions } from '../../utils/uri';
168
168
  * @public
169
169
  */
170
170
  export declare const IsEmail: (options?: IsEmailOptions | undefined) => PropertyDecorator;
171
+ /**
172
+ * ## IsMongoId Decorator
173
+ *
174
+ * Property decorator that validates a property value is a valid MongoDB ObjectId.
175
+ * MongoDB ObjectIds are 12-byte values typically represented as 24-character hexadecimal strings.
176
+ *
177
+ * ### Usage
178
+ * ```typescript
179
+ * class Document {
180
+ * @IsMongoId()
181
+ * _id: string;
182
+ * }
183
+ * ```
184
+ *
185
+ * ### Validation Behavior
186
+ * - **Passes**: When value is a valid 24-character hexadecimal string
187
+ * - **Fails**: When value is not a string, wrong length, or contains non-hex characters
188
+ *
189
+ * ### Error Messages
190
+ * - Default: "This field must be a valid MongoDB ObjectId"
191
+ * - I18n key: "validator.mongoId"
192
+ *
193
+ * ### Related Decorators
194
+ * - Often used for database document IDs and references
195
+ *
196
+ * @returns A property decorator function
197
+ * @public
198
+ */
199
+ export declare const IsMongoId: () => PropertyDecorator;
200
+ /**
201
+ * ## IsHexadecimal Decorator
202
+ *
203
+ * Property decorator that validates a property value is a valid hexadecimal string.
204
+ * Accepts hexadecimal strings with or without "0x" or "0X" prefix.
205
+ *
206
+ * ### Usage
207
+ * ```typescript
208
+ * class Color {
209
+ * @IsHexadecimal()
210
+ * hexValue: string;
211
+ * }
212
+ * ```
213
+ *
214
+ * ### Validation Behavior
215
+ * - **Passes**: When value is a valid hexadecimal string (e.g., "1a2b3c", "0xFFFF")
216
+ * - **Fails**: When value contains non-hex characters or is not a string
217
+ *
218
+ * ### Error Messages
219
+ * - Default: "This field must be a valid hexadecimal value"
220
+ * - I18n key: "validator.hexadecimal"
221
+ *
222
+ * ### Related Decorators
223
+ * - Often used for color codes, hash values, and binary data representations
224
+ *
225
+ * @returns A property decorator function
226
+ * @public
227
+ */
228
+ export declare const IsHexadecimal: () => PropertyDecorator;
171
229
  /**
172
230
  * @summary IsUrl Decorator
173
231
  *
@@ -308,7 +366,7 @@ export declare const IsEmail: (options?: IsEmailOptions | undefined) => Property
308
366
  * @param options.allowedProtocols - Array of allowed protocols without colons
309
367
  * @returns A property decorator that validates URL format
310
368
  *
311
- * @throws {ValidationError} When validation fails, containing localized error message
369
+ * @throws {ValidatorError} When validation fails, containing localized error message
312
370
  *
313
371
  * @example
314
372
  * ```typescript
@@ -469,7 +527,7 @@ export declare const IsUrl: (options?: IsUrlOptions | undefined) => PropertyDeco
469
527
  * @param options.countryCode - Country code to validate against specific country's format
470
528
  * @returns A property decorator that validates phone number format
471
529
  *
472
- * @throws {ValidationError} When validation fails, containing localized error message
530
+ * @throws {ValidatorError} When validation fails, containing localized error message
473
531
  *
474
532
  * @example
475
533
  * ```typescript
@@ -636,7 +694,7 @@ export declare const IsPhoneNumber: (countryCode?: "AF" | "AL" | "DZ" | "AS" | "
636
694
  * @param options.phoneNumber - Phone validation options with country code
637
695
  * @returns A property decorator that validates email or phone number format
638
696
  *
639
- * @throws {ValidationError} When validation fails, containing localized error message
697
+ * @throws {ValidatorError} When validation fails, containing localized error message
640
698
  *
641
699
  * @example
642
700
  * ```typescript
@@ -782,7 +840,7 @@ export declare const IsEmailOrPhone: (options?: {
782
840
  *
783
841
  * @returns A property decorator that validates file name format
784
842
  *
785
- * @throws {ValidationError} When validation fails, containing localized error message
843
+ * @throws {ValidatorError} When validation fails, containing localized error message
786
844
  *
787
845
  * @example
788
846
  * ```typescript
@@ -922,7 +980,7 @@ export declare const IsFileName: () => PropertyDecorator;
922
980
  *
923
981
  * @returns A property decorator that validates UUID format
924
982
  *
925
- * @throws {ValidationError} When validation fails, containing localized error message
983
+ * @throws {ValidatorError} When validation fails, containing localized error message
926
984
  *
927
985
  * @example
928
986
  * ```typescript
@@ -1068,7 +1126,7 @@ export declare const IsUUID: () => PropertyDecorator;
1068
1126
  *
1069
1127
  * @returns A property decorator that validates JSON format
1070
1128
  *
1071
- * @throws {ValidationError} When validation fails, containing localized error message
1129
+ * @throws {ValidatorError} When validation fails, containing localized error message
1072
1130
  *
1073
1131
  * @example
1074
1132
  * ```typescript
@@ -1206,7 +1264,7 @@ export declare const IsJSON: () => PropertyDecorator;
1206
1264
  *
1207
1265
  * @returns A property decorator that validates Base64 format
1208
1266
  *
1209
- * @throws {ValidationError} When validation fails, containing localized error message
1267
+ * @throws {ValidatorError} When validation fails, containing localized error message
1210
1268
  *
1211
1269
  * @example
1212
1270
  * ```typescript
@@ -1348,7 +1406,7 @@ export declare const IsBase64: () => PropertyDecorator;
1348
1406
  *
1349
1407
  * @returns A property decorator that validates hexadecimal color format
1350
1408
  *
1351
- * @throws {ValidationError} When validation fails, containing localized error message
1409
+ * @throws {ValidatorError} When validation fails, containing localized error message
1352
1410
  *
1353
1411
  * @example
1354
1412
  * ```typescript
@@ -1496,7 +1554,7 @@ export declare const IsHexColor: () => PropertyDecorator;
1496
1554
  *
1497
1555
  * @returns A property decorator that validates credit card number format and checksum
1498
1556
  *
1499
- * @throws {ValidationError} When validation fails, containing localized error message
1557
+ * @throws {ValidatorError} When validation fails, containing localized error message
1500
1558
  *
1501
1559
  * @example
1502
1560
  * ```typescript
@@ -1660,7 +1718,7 @@ export declare const IsCreditCard: () => PropertyDecorator;
1660
1718
  * @param ruleParams[0] - IP version: "4" (IPv4 only), "6" (IPv6 only), or "4/6" (both, default)
1661
1719
  * @returns A property decorator that validates IP address format
1662
1720
  *
1663
- * @throws {ValidationError} When validation fails, containing localized error message
1721
+ * @throws {ValidatorError} When validation fails, containing localized error message
1664
1722
  *
1665
1723
  * @example
1666
1724
  * ```typescript
@@ -1817,7 +1875,7 @@ export declare const IsIP: (...ruleParameters: string[]) => PropertyDecorator;
1817
1875
  *
1818
1876
  * @returns A property decorator that validates MAC address format
1819
1877
  *
1820
- * @throws {ValidationError} When validation fails, containing localized error message
1878
+ * @throws {ValidatorError} When validation fails, containing localized error message
1821
1879
  *
1822
1880
  * @example
1823
1881
  * ```typescript
@@ -1977,7 +2035,7 @@ export declare const IsMACAddress: () => PropertyDecorator;
1977
2035
  * @param ruleParams[1] - Optional custom error message key for i18n translation
1978
2036
  * @returns A property decorator that validates string patterns using regular expressions
1979
2037
  *
1980
- * @throws {ValidationError} When validation fails, containing localized error message
2038
+ * @throws {ValidatorError} When validation fails, containing localized error message
1981
2039
  *
1982
2040
  * @example
1983
2041
  * ```typescript
@@ -2821,5 +2879,116 @@ declare module '../types' {
2821
2879
  message?: string;
2822
2880
  }
2823
2881
  ]>;
2882
+ /**
2883
+ * @summary MongoId Rule
2884
+ *
2885
+ * @description Validates that the field under validation is a valid MongoDB ObjectId.
2886
+ * MongoDB ObjectIds are 12-byte values represented as 24-character hexadecimal strings.
2887
+ *
2888
+ * #### Validation Logic
2889
+ * - Must be exactly 24 characters long
2890
+ * - Must contain only hexadecimal characters (0-9, a-f, A-F)
2891
+ * - Does not accept "0x" prefix (unlike general hex validation)
2892
+ *
2893
+ * @example
2894
+ * ```typescript
2895
+ * // Valid MongoDB ObjectIds
2896
+ * await Validator.validate({
2897
+ * value: '507f1f77bcf86cd799439011',
2898
+ * rules: ['MongoId']
2899
+ * }); // ✓ Valid
2900
+ *
2901
+ * // Invalid examples
2902
+ * await Validator.validate({
2903
+ * value: '507f1f77bcf86cd79943901', // Too short
2904
+ * rules: ['MongoId']
2905
+ * }); // ✗ Invalid
2906
+ *
2907
+ * await Validator.validate({
2908
+ * value: '507f1f77bcf86cd799439011a', // Too long
2909
+ * rules: ['MongoId']
2910
+ * }); // ✗ Invalid
2911
+ *
2912
+ * await Validator.validate({
2913
+ * value: 'gggggggggggggggggggggggg', // Non-hex characters
2914
+ * rules: ['MongoId']
2915
+ * }); // ✗ Invalid
2916
+ *
2917
+ * // Class validation
2918
+ * class Document {
2919
+ * @IsMongoId()
2920
+ * _id: string;
2921
+ *
2922
+ * @IsMongoId()
2923
+ * userId: string;
2924
+ * }
2925
+ * ```
2926
+ *
2927
+ * @returns true if valid MongoDB ObjectId, rejecting with error message if invalid
2928
+ *
2929
+ * @public
2930
+ */
2931
+ MongoId: ValidatorRuleParams<[]>;
2932
+ /**
2933
+ * @summary Hexadecimal Rule
2934
+ *
2935
+ * @description Validates that the field under validation is a valid hexadecimal string.
2936
+ * Accepts hexadecimal strings with or without "0x" or "0X" prefix.
2937
+ *
2938
+ * #### Validation Logic
2939
+ * - Contains only characters 0-9, a-f, or A-F
2940
+ * - Can optionally start with "0x" or "0X" prefix
2941
+ * - Must have at least one hex digit after any prefix
2942
+ * - Can be of any length (after prefix)
2943
+ *
2944
+ * @example
2945
+ * ```typescript
2946
+ * // Valid hexadecimal strings
2947
+ * await Validator.validate({
2948
+ * value: '1a2b3c',
2949
+ * rules: ['Hexadecimal']
2950
+ * }); // ✓ Valid
2951
+ *
2952
+ * await Validator.validate({
2953
+ * value: '0xFFFF',
2954
+ * rules: ['Hexadecimal']
2955
+ * }); // ✓ Valid
2956
+ *
2957
+ * await Validator.validate({
2958
+ * value: '0X123ABC',
2959
+ * rules: ['Hexadecimal']
2960
+ * }); // ✓ Valid
2961
+ *
2962
+ * // Invalid examples
2963
+ * await Validator.validate({
2964
+ * value: 'GHI', // Non-hex characters
2965
+ * rules: ['Hexadecimal']
2966
+ * }); // ✗ Invalid
2967
+ *
2968
+ * await Validator.validate({
2969
+ * value: '0x', // No hex digits after prefix
2970
+ * rules: ['Hexadecimal']
2971
+ * }); // ✗ Invalid
2972
+ *
2973
+ * await Validator.validate({
2974
+ * value: '', // Empty string
2975
+ * rules: ['Hexadecimal']
2976
+ * }); // ✗ Invalid
2977
+ *
2978
+ * // Class validation
2979
+ * class Color {
2980
+ * @IsHexadecimal()
2981
+ * hexValue: string;
2982
+ *
2983
+ * @IsHexadecimal()
2984
+ * rgbValue?: string;
2985
+ * }
2986
+ * ```
2987
+ *
2988
+ * @returns true if valid hexadecimal string, rejecting with error message if invalid
2989
+ *
2990
+ * @public
2991
+ */
2992
+ Hexadecimal: ValidatorRuleParams<[]>;
2824
2993
  }
2825
2994
  }