reslib 1.1.0 → 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 (60) 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 +36 -4
  19. package/build/translations/index.js +2 -2
  20. package/build/translations/validator.en.d.ts +69 -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 +13 -13
  42. package/build/validator/rules/format.js +3 -3
  43. package/build/validator/rules/index.js +3 -3
  44. package/build/validator/rules/multiRules.d.ts +10 -10
  45. package/build/validator/rules/multiRules.js +2 -2
  46. package/build/validator/rules/numeric.d.ts +8 -8
  47. package/build/validator/rules/numeric.js +2 -2
  48. package/build/validator/rules/object.js +2 -2
  49. package/build/validator/rules/string.d.ts +6 -6
  50. package/build/validator/rules/string.js +2 -2
  51. package/build/validator/rules/target.d.ts +8 -8
  52. package/build/validator/rules/target.js +2 -2
  53. package/build/validator/rules.types.d.ts +167 -0
  54. package/build/validator/rules.types.js +1 -0
  55. package/build/validator/types.d.ts +832 -1286
  56. package/build/validator/validator.d.ts +554 -867
  57. package/build/validator/validator.js +2 -2
  58. package/lib/cjs/exception.js +1 -0
  59. package/lib/esm/exception.mjs +2 -0
  60. package/package.json +6 -1
@@ -0,0 +1,167 @@
1
+ import { ClassConstructor } from '../types';
2
+ /**
3
+ * ## Validator Rule Name
4
+ *
5
+ * Represents a valid reference key for any registered validation rule.
6
+ *
7
+ * This type acts as the central vocabulary for the validation system, generated
8
+ * directly from the keys of `ValidatorRuleParamTypes`. It ensures that any rule
9
+ * name used in your code (whether as a string literal or object key) corresponds
10
+ * to a known, well-defined validation rule.
11
+ *
12
+ * ### Usage
13
+ * You encounter `ValidatorRuleName` in two primary contexts:
14
+ * 1. **String Rules**: When using "Named Rules" for parameterless validation.
15
+ * 2. **Object Rules**: As the key in a rule object to specify which rule to apply.
16
+ *
17
+ * ### Examples
18
+ * ```typescript
19
+ * // As a type annotation:
20
+ * const myRules: ValidatorRuleName[] = ["Required", "Email"];
21
+ *
22
+ * // In object rules:
23
+ * const ruleObj = {
24
+ * MinLength: [5], // "MinLength" is a ValidatorRuleName
25
+ * Required: [] // "Required" is a ValidatorRuleName
26
+ * };
27
+ *
28
+ * // In custom lookups (e.g., getting a rule function):
29
+ * const ruleFn = Validator.getRule("Email");
30
+ * ```
31
+ *
32
+ * ### Type Safety
33
+ * Because this is a string union type derived from the keys of the parameter map,
34
+ * TypeScript will produce an error if you try to use a misspelled or non-existent rule definition.
35
+ *
36
+ * ```typescript
37
+ * const valid: ValidatorRuleName = "Required"; // ✅
38
+ * const invalid: ValidatorRuleName = "Reguired"; // ❌ Type error: '"Reguired"' is not assignable...
39
+ * ```
40
+ *
41
+ * @public
42
+ * @see {@link ValidatorRuleParamTypes} - The source definition map.
43
+ */
44
+ export type ValidatorRuleName = keyof ValidatorRuleParamTypes & string;
45
+ /**
46
+ * ## Validation Rules Parameter Map
47
+ *
48
+ * Central type definition mapping validation rule names to their parameter signatures.
49
+ * This interface serves as the authoritative source for all built-in validation rules,
50
+ * defining the exact parameter types each rule accepts.
51
+ *
52
+ * ### Purpose
53
+ * Provides compile-time type safety for validation rule parameters across the entire
54
+ * validation system. Each property represents a built-in validation rule and its
55
+ * expected parameter structure. This is a static interface with no generics.
56
+ *
57
+ * ### Type Structure
58
+ * - **Key**: Rule name (string literal from {@link ValidatorRuleName})
59
+ * - **Value**: Parameter array type (extends {@link ValidatorRuleParams})
60
+ *
61
+ * ### Parameter Type Patterns
62
+ * - **Empty Arrays `[]`**: Rules that take no parameters (e.g., "Required", "Email")
63
+ * - **Complex Parameters**: Rules with mixed required/optional parameters
64
+ *
65
+ * ### Usage in Type System
66
+ * This interface is used throughout the validator to:
67
+ * - Type-check rule parameters at compile time
68
+ * - Generate {@link ValidatorRuleName} union type
69
+ * - Create {@link ValidatorRuleFunctionsMap} registry type
70
+ * - Validate rule definitions in rule implementation files
71
+ *
72
+ * ### Rule Categories
73
+ *
74
+ * #### Presence Validation
75
+ * - **Required**: Ensures value is present and not empty
76
+ * - **Nullable**: Allows null/undefined values (skips validation)
77
+ * - **Optional**: Allows undefined values (skips validation)
78
+ * - **Empty**: Allows empty strings (validation skipped if "")
79
+ *
80
+ * #### Type Validation
81
+ * - **String**: Validates value is a string
82
+ * - **Number**: Validates value is a number
83
+ * - **NonNullString**: Validates value is a non-null string
84
+ *
85
+ * #### String Validation
86
+ * - **MinLength**: Minimum character length requirement
87
+ * - **MaxLength**: Maximum character length limit
88
+ * - **Length**: Exact length or length range (min and optional max)
89
+ * - **FileName**: Valid file name format
90
+ *
91
+ * #### Numeric Validation
92
+ * - **NumberGT**: Value must be greater than specified number
93
+ * - **NumberGTE**: Value must be >= specified number
94
+ * - **NumberLT**: Value must be less than specified number
95
+ * - **NumberLTE**: Value must be <= specified number
96
+ * - **NumberEQ**: Value must equal specified number
97
+ * - **NumberNE**: Value must differ from specified number
98
+ *
99
+ * #### Format Validation
100
+ * - **Email**: Valid email address format
101
+ * - **Url**: Valid URL format
102
+ * - **PhoneNumber**: Valid phone number (with optional country code)
103
+ * - **EmailOrPhoneNumber**: Valid email or phone number
104
+ *
105
+ * ### Parameter Examples
106
+ * ```typescript
107
+ * // Rules with no parameters
108
+ * Required: ValidatorRuleParams<[]>; // "Required"
109
+ * Email: ValidatorRuleParams<[]>; // "Email"
110
+ *
111
+ * // Rules with single parameters
112
+ * MinLength: ValidatorRuleParams<[number]>; // {MinLength:[5]}
113
+ * NumberEQ: ValidatorRuleParams<[number]>; // "NumberEQ[42]"
114
+ *
115
+ * // Rules with optional parameters
116
+ * PhoneNumber: ValidatorRuleParams<[CountryCode?]>; // "PhoneNumber" or "PhoneNumber[US]"
117
+ *
118
+ * // Rules with multiple parameters
119
+ * Length: ValidatorRuleParams<[number, number?]>; // "Length[5]" or "Length[5,10]"
120
+ * ```
121
+ *
122
+ * ### Extending the Rules Map
123
+ * When adding new validation rules:
124
+ * 1. Add the rule name and parameter type to this interface
125
+ * 2. Implement the rule function in the appropriate rule file
126
+ * 3. Register the rule in the validator's rule registry
127
+ * 4. Update rule name unions and type definitions as needed
128
+ *
129
+ * ### Relationship to Validation System
130
+ * - **Foundation**: Base type for all rule definitions
131
+ * - **Type Safety**: Ensures parameter type checking
132
+ * - **Rule Discovery**: Used to generate valid rule names
133
+ * - **Function Signatures**: Defines parameter types for rule functions
134
+ * - **Runtime Validation**: Parameters validated against these types
135
+ *
136
+ * @public
137
+ * @template Context - Type of the optional validation context
138
+ * @see {@link ValidatorRuleName} - Union type derived from this interface's keys
139
+ * @see {@link ValidatorRuleFunctionsMap} - Registry type using this interface
140
+ * @see {@link ValidatorRuleParams} - Base parameter type for all rules
141
+ * @see {@link Validator} - Main validator class that uses these rules
142
+ */
143
+ export interface ValidatorRuleParamTypes<Context = unknown> {
144
+ }
145
+ /**
146
+ * ## Validator Class Input
147
+ *
148
+ * Represents a partial data object corresponding to a target class structure.
149
+ * Used for describing the input data for class-based validation without requiring
150
+ * a full instance of the class.
151
+ *
152
+ * @template TClass - The class constructor
153
+ *
154
+ * @public
155
+ */
156
+ export type ValidatorClassInput<TClass extends ClassConstructor = ClassConstructor> = Partial<Record<ValidatorClassKeys<TClass>, any>>;
157
+ /**
158
+ * ## Validator Class Keys
159
+ *
160
+ * Type alias for extracting the valid property keys from a target class or constructor.
161
+ * Used to ensure type safety when referencing properties of validated class instances.
162
+ *
163
+ * @template TClass - The class constructor
164
+ *
165
+ * @public
166
+ */
167
+ export type ValidatorClassKeys<TClass extends ClassConstructor> = keyof InstanceType<TClass>;
@@ -0,0 +1 @@
1
+ 'use strict';