reslib 1.0.3 → 1.1.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.
- package/build/auth/index.js +1 -1
- package/build/countries/index.js +1 -1
- package/build/currency/index.js +1 -1
- package/build/currency/session.js +2 -2
- package/build/i18n/index.js +1 -1
- package/build/inputFormatter/index.js +1 -1
- package/build/logger/index.js +1 -1
- package/build/resources/index.js +1 -1
- package/build/translations/index.d.ts +4 -0
- package/build/translations/index.js +1 -1
- package/build/translations/validator.en.d.ts +4 -0
- package/build/translations/validator.en.js +1 -1
- package/build/utils/date/dateHelper.js +1 -1
- package/build/utils/date/index.js +1 -1
- package/build/utils/index.js +2 -2
- package/build/utils/numbers.js +1 -1
- package/build/validator/index.js +3 -3
- package/build/validator/rules/array.js +1 -1
- package/build/validator/rules/boolean.js +1 -1
- package/build/validator/rules/date.js +1 -1
- package/build/validator/rules/default.js +1 -1
- package/build/validator/rules/enum.js +1 -1
- package/build/validator/rules/file.js +2 -2
- package/build/validator/rules/format.d.ts +169 -0
- package/build/validator/rules/format.js +3 -3
- package/build/validator/rules/index.d.ts +1 -0
- package/build/validator/rules/index.js +3 -3
- package/build/validator/rules/multiRules.js +1 -1
- package/build/validator/rules/numeric.js +1 -1
- package/build/validator/rules/object.d.ts +71 -0
- package/build/validator/rules/object.js +5 -0
- package/build/validator/rules/string.js +1 -1
- package/build/validator/rules/target.js +1 -1
- package/build/validator/validator.js +1 -1
- package/package.json +249 -244
|
@@ -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
|
*
|
|
@@ -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
|
}
|