@arikajs/validation 0.0.2

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 (107) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +271 -0
  3. package/dist/ErrorBag.d.ts +28 -0
  4. package/dist/ErrorBag.d.ts.map +1 -0
  5. package/dist/ErrorBag.js +49 -0
  6. package/dist/ErrorBag.js.map +1 -0
  7. package/dist/Rule.d.ts +11 -0
  8. package/dist/Rule.d.ts.map +1 -0
  9. package/dist/Rule.js +3 -0
  10. package/dist/Rule.js.map +1 -0
  11. package/dist/Rules/Email.d.ts +6 -0
  12. package/dist/Rules/Email.d.ts.map +1 -0
  13. package/dist/Rules/Email.js +18 -0
  14. package/dist/Rules/Email.js.map +1 -0
  15. package/dist/Rules/Max.d.ts +8 -0
  16. package/dist/Rules/Max.d.ts.map +1 -0
  17. package/dist/Rules/Max.js +24 -0
  18. package/dist/Rules/Max.js.map +1 -0
  19. package/dist/Rules/Min.d.ts +8 -0
  20. package/dist/Rules/Min.d.ts.map +1 -0
  21. package/dist/Rules/Min.js +24 -0
  22. package/dist/Rules/Min.js.map +1 -0
  23. package/dist/Rules/Number.d.ts +6 -0
  24. package/dist/Rules/Number.d.ts.map +1 -0
  25. package/dist/Rules/Number.js +15 -0
  26. package/dist/Rules/Number.js.map +1 -0
  27. package/dist/Rules/Required.d.ts +6 -0
  28. package/dist/Rules/Required.d.ts.map +1 -0
  29. package/dist/Rules/Required.js +22 -0
  30. package/dist/Rules/Required.js.map +1 -0
  31. package/dist/Rules/RequiredIf.d.ts +11 -0
  32. package/dist/Rules/RequiredIf.d.ts.map +1 -0
  33. package/dist/Rules/RequiredIf.js +25 -0
  34. package/dist/Rules/RequiredIf.js.map +1 -0
  35. package/dist/Rules/String.d.ts +6 -0
  36. package/dist/Rules/String.d.ts.map +1 -0
  37. package/dist/Rules/String.js +15 -0
  38. package/dist/Rules/String.js.map +1 -0
  39. package/dist/ValidationError.d.ts +5 -0
  40. package/dist/ValidationError.d.ts.map +1 -0
  41. package/dist/ValidationError.js +12 -0
  42. package/dist/ValidationError.js.map +1 -0
  43. package/dist/Validator.d.ts +31 -0
  44. package/dist/Validator.d.ts.map +1 -0
  45. package/dist/Validator.js +193 -0
  46. package/dist/Validator.js.map +1 -0
  47. package/dist/index.d.ts +11 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +27 -0
  50. package/dist/index.js.map +1 -0
  51. package/dist/src/ErrorBag.d.ts +28 -0
  52. package/dist/src/ErrorBag.d.ts.map +1 -0
  53. package/dist/src/ErrorBag.js +49 -0
  54. package/dist/src/ErrorBag.js.map +1 -0
  55. package/dist/src/Rule.d.ts +11 -0
  56. package/dist/src/Rule.d.ts.map +1 -0
  57. package/dist/src/Rule.js +3 -0
  58. package/dist/src/Rule.js.map +1 -0
  59. package/dist/src/Rules/Email.d.ts +6 -0
  60. package/dist/src/Rules/Email.d.ts.map +1 -0
  61. package/dist/src/Rules/Email.js +18 -0
  62. package/dist/src/Rules/Email.js.map +1 -0
  63. package/dist/src/Rules/Max.d.ts +8 -0
  64. package/dist/src/Rules/Max.d.ts.map +1 -0
  65. package/dist/src/Rules/Max.js +24 -0
  66. package/dist/src/Rules/Max.js.map +1 -0
  67. package/dist/src/Rules/Min.d.ts +8 -0
  68. package/dist/src/Rules/Min.d.ts.map +1 -0
  69. package/dist/src/Rules/Min.js +24 -0
  70. package/dist/src/Rules/Min.js.map +1 -0
  71. package/dist/src/Rules/Number.d.ts +6 -0
  72. package/dist/src/Rules/Number.d.ts.map +1 -0
  73. package/dist/src/Rules/Number.js +15 -0
  74. package/dist/src/Rules/Number.js.map +1 -0
  75. package/dist/src/Rules/Required.d.ts +6 -0
  76. package/dist/src/Rules/Required.d.ts.map +1 -0
  77. package/dist/src/Rules/Required.js +22 -0
  78. package/dist/src/Rules/Required.js.map +1 -0
  79. package/dist/src/Rules/RequiredIf.d.ts +11 -0
  80. package/dist/src/Rules/RequiredIf.d.ts.map +1 -0
  81. package/dist/src/Rules/RequiredIf.js +25 -0
  82. package/dist/src/Rules/RequiredIf.js.map +1 -0
  83. package/dist/src/Rules/String.d.ts +6 -0
  84. package/dist/src/Rules/String.d.ts.map +1 -0
  85. package/dist/src/Rules/String.js +15 -0
  86. package/dist/src/Rules/String.js.map +1 -0
  87. package/dist/src/ValidationError.d.ts +5 -0
  88. package/dist/src/ValidationError.d.ts.map +1 -0
  89. package/dist/src/ValidationError.js +12 -0
  90. package/dist/src/ValidationError.js.map +1 -0
  91. package/dist/src/Validator.d.ts +31 -0
  92. package/dist/src/Validator.d.ts.map +1 -0
  93. package/dist/src/Validator.js +193 -0
  94. package/dist/src/Validator.js.map +1 -0
  95. package/dist/src/index.d.ts +11 -0
  96. package/dist/src/index.d.ts.map +1 -0
  97. package/dist/src/index.js +27 -0
  98. package/dist/src/index.js.map +1 -0
  99. package/dist/tests/AdvancedValidation.test.d.ts +2 -0
  100. package/dist/tests/AdvancedValidation.test.d.ts.map +1 -0
  101. package/dist/tests/AdvancedValidation.test.js +97 -0
  102. package/dist/tests/AdvancedValidation.test.js.map +1 -0
  103. package/dist/tests/Validator.test.d.ts +2 -0
  104. package/dist/tests/Validator.test.d.ts.map +1 -0
  105. package/dist/tests/Validator.test.js +133 -0
  106. package/dist/tests/Validator.test.js.map +1 -0
  107. package/package.json +43 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ArikaJs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,271 @@
1
+ ## Arika Validation
2
+
3
+ `@arikajs/validation` provides a powerful, expressive validation system for the ArikaJS framework.
4
+
5
+ It allows developers to validate incoming data using declarative rules, handle errors consistently, and integrate validation seamlessly into controllers and middleware.
6
+
7
+ ```ts
8
+ import { Validator } from '@arikajs/validation';
9
+
10
+ const validator = new Validator(
11
+ {
12
+ email: 'test@example.com',
13
+ password: 'secret123'
14
+ },
15
+ {
16
+ email: 'required|email',
17
+ password: 'required|min:8'
18
+ }
19
+ );
20
+
21
+ if (validator.fails()) {
22
+ console.log(validator.errors());
23
+ }
24
+ ```
25
+
26
+ ---
27
+
28
+ ### Status
29
+
30
+ - **Stage**: Experimental / v0.x
31
+ - **Scope (v0.x)**:
32
+ - Rule-based validation syntax
33
+ - Custom rule support
34
+ - Multiple error messages per field
35
+ - Async validation support
36
+ - JS & TS friendly API
37
+ - **Out of scope (for this package)**:
38
+ - Parsing HTTP requests
39
+ - Rendering views
40
+ - Authentication logic
41
+
42
+ ---
43
+
44
+ ## 🎯 Purpose
45
+
46
+ Validation protects application logic from invalid or unsafe input. This package is responsible for:
47
+ - Validating request data (body, query, params)
48
+ - Providing rule-based validation
49
+ - Supporting custom validation rules
50
+ - Returning structured validation errors
51
+ - Integrating cleanly with HTTP and controllers
52
+
53
+ ---
54
+
55
+ ## 🧠 Responsibilities
56
+
57
+ ### ✅ What Arika Validation Does
58
+ - Validate plain JavaScript objects
59
+ - Support string-based validation rules
60
+ - Provide reusable rule classes
61
+ - Collect and format validation errors
62
+ - Allow synchronous and asynchronous rules
63
+ - Integrate with controllers & middleware
64
+
65
+ ### ❌ What Arika Validation Does NOT Do
66
+ - Parse HTTP requests
67
+ - Render views
68
+ - Handle authentication or authorization
69
+ - Perform database operations
70
+
71
+ ---
72
+
73
+ ## Features
74
+
75
+ - **Rule-based validation syntax**
76
+ - Intuitive pipe-based rules like `required|email|min:8`.
77
+ - **Custom rule support**
78
+ - Easily extend the validator with your own logic.
79
+ - **Multiple error messages per field**
80
+ - Comprehensive feedback for users.
81
+ - **Async validation support**
82
+ - Validate against databases or external services.
83
+ - **Framework-agnostic core**
84
+ - Use it anywhere, not just in ArikaJS.
85
+ - **JS & TS friendly API**
86
+ - Written in TypeScript with full type definitions.
87
+
88
+ ---
89
+
90
+ ## Installation
91
+
92
+ ```bash
93
+ npm install @arikajs/validation
94
+ # or
95
+ yarn add @arikajs/validation
96
+ # or
97
+ pnpm add @arikajs/validation
98
+ ```
99
+
100
+ ---
101
+
102
+ ## 🔎 Validation Rules
103
+
104
+ Rules are defined using a pipe-based syntax:
105
+
106
+ ```ts
107
+ email: 'required|email'
108
+ password: 'required|min:8|max:32'
109
+ ```
110
+
111
+ ### 📦 Built-in Rules (v0.x)
112
+
113
+ | Rule | Description |
114
+ | :--- | :--- |
115
+ | `required` | Field must be present and not empty |
116
+ | `nullable` | Field can be null or empty |
117
+ | `bail` | Stop validation after first failure for a field |
118
+ | `email` | Must be a valid email address |
119
+ | `min:value` | Minimum length (string) or value (number) |
120
+ | `max:value` | Maximum length (string) or value (number) |
121
+ | `string` | Must be a string |
122
+ | `number` | Must be numeric |
123
+ | `required_if:field,value` | Required if another field matches a value |
124
+
125
+ ### 🚀 Advanced Features
126
+
127
+ - **Nested Object Validation**: Use dot notation to validate deep structures (`user.email`).
128
+ - **Array Wildcard Validation**: Use `*` to validate all elements in an array (`users.*.email`).
129
+ - **Bail Validation**: Stop executing rules for a field after the first failure.
130
+ - **Validated Data**: Use `validator.validated()` to get only the data that passed validation.
131
+ - **Conditional Rules**: Rules that only run based on the values of other fields.
132
+
133
+ ---
134
+
135
+ ## 🧱 Custom Rules
136
+
137
+ ### Creating a Rule
138
+
139
+ ```ts
140
+ import { Rule } from '@arikajs/validation';
141
+
142
+ export class Uppercase implements Rule {
143
+ validate(value: any): boolean {
144
+ return typeof value === 'string' && value === value.toUpperCase();
145
+ }
146
+
147
+ message(): string {
148
+ return 'The value must be uppercase.';
149
+ }
150
+ }
151
+ ```
152
+
153
+ ### Registering a Rule
154
+
155
+ ```ts
156
+ validator.extend('uppercase', new Uppercase());
157
+ ```
158
+
159
+ ### Usage
160
+
161
+ ```ts
162
+ name: 'required|uppercase'
163
+ ```
164
+
165
+ ---
166
+
167
+ ## ❌ Validation Errors
168
+
169
+ ### Checking Failure
170
+
171
+ ```ts
172
+ if (validator.fails()) {
173
+ throw new ValidationError(validator.errors());
174
+ }
175
+ ```
176
+
177
+ ### Error Structure
178
+
179
+ ```json
180
+ {
181
+ "email": ["The email field is required."],
182
+ "password": ["The password must be at least 8 characters."]
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## 🔌 Framework Integration
189
+
190
+ ### Controller Usage
191
+ *(Provided by `@arikajs/http`)*
192
+
193
+ ```ts
194
+ request.validate({
195
+ email: 'required|email',
196
+ password: 'required|min:8'
197
+ });
198
+ ```
199
+
200
+ ### Middleware Usage
201
+
202
+ ```ts
203
+ export async function validateLogin(request, next) {
204
+ const validator = new Validator(request.body, {
205
+ email: 'required|email',
206
+ password: 'required'
207
+ });
208
+
209
+ if (validator.fails()) {
210
+ return response.status(422).json(validator.errors());
211
+ }
212
+
213
+ return next(request);
214
+ }
215
+ ```
216
+
217
+ ---
218
+
219
+ ## ⚙️ Advanced Usage
220
+
221
+ ### Async Validation
222
+
223
+ ```ts
224
+ class UniqueEmail {
225
+ async validate(value) {
226
+ return !(await userRepo.exists(value));
227
+ }
228
+
229
+ message() {
230
+ return 'Email already taken.';
231
+ }
232
+ }
233
+ ```
234
+
235
+ ---
236
+
237
+ ## 🧱 Project Structure
238
+
239
+ - `src/`
240
+ - `Validator.ts` – Main validation engine
241
+ - `Rule.ts` – Rule interface
242
+ - `Rules/` – Built-in rules
243
+ - `Required.ts`, `Email.ts`, `Min.ts`, `Max.ts`
244
+ - `ErrorBag.ts` – Error collection
245
+ - `ValidationError.ts` – Error exception
246
+ - `index.ts` – Public exports
247
+ - `tests/` – Unit tests
248
+ - `package.json`
249
+ - `tsconfig.json`
250
+ - `README.md`
251
+ - `LICENSE`
252
+
253
+ ---
254
+
255
+ ## Versioning & Stability
256
+
257
+ - Current version: **v0.x** (experimental)
258
+ - API may change until **v1.0**
259
+ - Will follow semantic versioning after stabilization
260
+
261
+ ---
262
+
263
+ ## 📜 License
264
+
265
+ `@arikajs/validation` is open-sourced software licensed under the **MIT License**.
266
+
267
+ ---
268
+
269
+ ## 🧠 Philosophy
270
+
271
+ > “Validation is not restriction — it is protection.”
@@ -0,0 +1,28 @@
1
+ export declare class ErrorBag {
2
+ private errors;
3
+ /**
4
+ * Add an error message for a specific field.
5
+ */
6
+ add(field: string, message: string): void;
7
+ /**
8
+ * Determine if the error bag is empty.
9
+ */
10
+ isEmpty(): boolean;
11
+ /**
12
+ * Determine if there are any errors.
13
+ */
14
+ isNotEmpty(): boolean;
15
+ /**
16
+ * Get all error messages.
17
+ */
18
+ all(): Record<string, string[]>;
19
+ /**
20
+ * Get the first error message for a specific field.
21
+ */
22
+ first(field: string): string | null;
23
+ /**
24
+ * Determine if a field has an error.
25
+ */
26
+ has(field: string): boolean;
27
+ }
28
+ //# sourceMappingURL=ErrorBag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBag.d.ts","sourceRoot":"","sources":["../src/ErrorBag.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAgC;IAE9C;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAOhD;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;OAEG;IACI,UAAU,IAAI,OAAO;IAI5B;;OAEG;IACI,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAItC;;OAEG;IACI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI1C;;OAEG;IACI,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;CAGrC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorBag = void 0;
4
+ class ErrorBag {
5
+ constructor() {
6
+ this.errors = {};
7
+ }
8
+ /**
9
+ * Add an error message for a specific field.
10
+ */
11
+ add(field, message) {
12
+ if (!this.errors[field]) {
13
+ this.errors[field] = [];
14
+ }
15
+ this.errors[field].push(message);
16
+ }
17
+ /**
18
+ * Determine if the error bag is empty.
19
+ */
20
+ isEmpty() {
21
+ return Object.keys(this.errors).length === 0;
22
+ }
23
+ /**
24
+ * Determine if there are any errors.
25
+ */
26
+ isNotEmpty() {
27
+ return !this.isEmpty();
28
+ }
29
+ /**
30
+ * Get all error messages.
31
+ */
32
+ all() {
33
+ return this.errors;
34
+ }
35
+ /**
36
+ * Get the first error message for a specific field.
37
+ */
38
+ first(field) {
39
+ return this.errors[field] ? this.errors[field][0] : null;
40
+ }
41
+ /**
42
+ * Determine if a field has an error.
43
+ */
44
+ has(field) {
45
+ return !!this.errors[field];
46
+ }
47
+ }
48
+ exports.ErrorBag = ErrorBag;
49
+ //# sourceMappingURL=ErrorBag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ErrorBag.js","sourceRoot":"","sources":["../src/ErrorBag.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAQ;IAArB;QACY,WAAM,GAA6B,EAAE,CAAC;IA8ClD,CAAC;IA5CG;;OAEG;IACI,GAAG,CAAC,KAAa,EAAE,OAAe;QACrC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACtB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACI,OAAO;QACV,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,UAAU;QACb,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,GAAG;QACN,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAa;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,CAAC;IAED;;OAEG;IACI,GAAG,CAAC,KAAa;QACpB,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACJ;AA/CD,4BA+CC"}
package/dist/Rule.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ export interface Rule {
2
+ /**
3
+ * Determine if the validation rule passes.
4
+ */
5
+ validate(value: any, attribute: string, params?: string[]): boolean | Promise<boolean>;
6
+ /**
7
+ * Get the validation error message.
8
+ */
9
+ message(): string;
10
+ }
11
+ //# sourceMappingURL=Rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule.d.ts","sourceRoot":"","sources":["../src/Rule.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,IAAI;IACjB;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEvF;;OAEG;IACH,OAAO,IAAI,MAAM,CAAC;CACrB"}
package/dist/Rule.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule.js","sourceRoot":"","sources":["../src/Rule.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class Email implements Rule {
3
+ validate(value: any): boolean;
4
+ message(): string;
5
+ }
6
+ //# sourceMappingURL=Email.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Email.d.ts","sourceRoot":"","sources":["../../src/Rules/Email.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,KAAM,YAAW,IAAI;IAC9B,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAQ7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Email = void 0;
4
+ class Email {
5
+ validate(value) {
6
+ if (!value)
7
+ return true; // Let 'required' handle empty values
8
+ if (typeof value !== 'string')
9
+ return false;
10
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
11
+ return emailRegex.test(value);
12
+ }
13
+ message() {
14
+ return 'The :attribute must be a valid email address.';
15
+ }
16
+ }
17
+ exports.Email = Email;
18
+ //# sourceMappingURL=Email.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Email.js","sourceRoot":"","sources":["../../src/Rules/Email.ts"],"names":[],"mappings":";;;AAEA,MAAa,KAAK;IACd,QAAQ,CAAC,KAAU;QACf,IAAI,CAAC,KAAK;YAAE,OAAO,IAAI,CAAC,CAAC,qCAAqC;QAC9D,IAAI,OAAO,KAAK,KAAK,QAAQ;YAAE,OAAO,KAAK,CAAC;QAE5C,MAAM,UAAU,GAAG,4BAA4B,CAAC;QAChD,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;IAED,OAAO;QACH,OAAO,+CAA+C,CAAC;IAC3D,CAAC;CACJ;AAZD,sBAYC"}
@@ -0,0 +1,8 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class Max implements Rule {
3
+ private max;
4
+ constructor(max: number);
5
+ validate(value: any): boolean;
6
+ message(): string;
7
+ }
8
+ //# sourceMappingURL=Max.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Max.d.ts","sourceRoot":"","sources":["../../src/Rules/Max.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,GAAI,YAAW,IAAI;IAC5B,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,EAAE,MAAM;IAIvB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAc7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Max = void 0;
4
+ class Max {
5
+ constructor(max) {
6
+ this.max = max;
7
+ }
8
+ validate(value) {
9
+ if (value === null || value === undefined)
10
+ return true;
11
+ if (typeof value === 'number') {
12
+ return value <= this.max;
13
+ }
14
+ if (typeof value === 'string' || Array.isArray(value)) {
15
+ return value.length <= this.max;
16
+ }
17
+ return false;
18
+ }
19
+ message() {
20
+ return `The :attribute must not be greater than ${this.max}.`;
21
+ }
22
+ }
23
+ exports.Max = Max;
24
+ //# sourceMappingURL=Max.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Max.js","sourceRoot":"","sources":["../../src/Rules/Max.ts"],"names":[],"mappings":";;;AAEA,MAAa,GAAG;IAGZ,YAAY,GAAW;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,KAAU;QACf,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAEvD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC;QAC7B,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC;QACpC,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO;QACH,OAAO,2CAA2C,IAAI,CAAC,GAAG,GAAG,CAAC;IAClE,CAAC;CACJ;AAxBD,kBAwBC"}
@@ -0,0 +1,8 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class Min implements Rule {
3
+ private min;
4
+ constructor(min: number);
5
+ validate(value: any): boolean;
6
+ message(): string;
7
+ }
8
+ //# sourceMappingURL=Min.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Min.d.ts","sourceRoot":"","sources":["../../src/Rules/Min.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,GAAI,YAAW,IAAI;IAC5B,OAAO,CAAC,GAAG,CAAS;gBAER,GAAG,EAAE,MAAM;IAIvB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAc7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Min = void 0;
4
+ class Min {
5
+ constructor(min) {
6
+ this.min = min;
7
+ }
8
+ validate(value) {
9
+ if (value === null || value === undefined)
10
+ return true;
11
+ if (typeof value === 'number') {
12
+ return value >= this.min;
13
+ }
14
+ if (typeof value === 'string' || Array.isArray(value)) {
15
+ return value.length >= this.min;
16
+ }
17
+ return false;
18
+ }
19
+ message() {
20
+ return `The :attribute must be at least ${this.min}.`;
21
+ }
22
+ }
23
+ exports.Min = Min;
24
+ //# sourceMappingURL=Min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Min.js","sourceRoot":"","sources":["../../src/Rules/Min.ts"],"names":[],"mappings":";;;AAEA,MAAa,GAAG;IAGZ,YAAY,GAAW;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,QAAQ,CAAC,KAAU;QACf,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QAEvD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC5B,OAAO,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC;QAC7B,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACpD,OAAO,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,GAAG,CAAC;QACpC,CAAC;QAED,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,OAAO;QACH,OAAO,mCAAmC,IAAI,CAAC,GAAG,GAAG,CAAC;IAC1D,CAAC;CACJ;AAxBD,kBAwBC"}
@@ -0,0 +1,6 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class IsNumber implements Rule {
3
+ validate(value: any): boolean;
4
+ message(): string;
5
+ }
6
+ //# sourceMappingURL=Number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Number.d.ts","sourceRoot":"","sources":["../../src/Rules/Number.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,QAAS,YAAW,IAAI;IACjC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAK7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsNumber = void 0;
4
+ class IsNumber {
5
+ validate(value) {
6
+ if (value === null || value === undefined)
7
+ return true;
8
+ return typeof value === 'number' && !isNaN(value);
9
+ }
10
+ message() {
11
+ return 'The :attribute must be a number.';
12
+ }
13
+ }
14
+ exports.IsNumber = IsNumber;
15
+ //# sourceMappingURL=Number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Number.js","sourceRoot":"","sources":["../../src/Rules/Number.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IACjB,QAAQ,CAAC,KAAU;QACf,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;YAAE,OAAO,IAAI,CAAC;QACvD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACH,OAAO,kCAAkC,CAAC;IAC9C,CAAC;CACJ;AATD,4BASC"}
@@ -0,0 +1,6 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class Required implements Rule {
3
+ validate(value: any): boolean;
4
+ message(): string;
5
+ }
6
+ //# sourceMappingURL=Required.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Required.d.ts","sourceRoot":"","sources":["../../src/Rules/Required.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,QAAS,YAAW,IAAI;IACjC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAgB7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Required = void 0;
4
+ class Required {
5
+ validate(value) {
6
+ if (value === null || value === undefined) {
7
+ return false;
8
+ }
9
+ if (typeof value === 'string' && value.trim() === '') {
10
+ return false;
11
+ }
12
+ if (Array.isArray(value) && value.length === 0) {
13
+ return false;
14
+ }
15
+ return true;
16
+ }
17
+ message() {
18
+ return 'The :attribute field is required.';
19
+ }
20
+ }
21
+ exports.Required = Required;
22
+ //# sourceMappingURL=Required.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Required.js","sourceRoot":"","sources":["../../src/Rules/Required.ts"],"names":[],"mappings":";;;AAEA,MAAa,QAAQ;IACjB,QAAQ,CAAC,KAAU;QACf,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;YACxC,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YACnD,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO,mCAAmC,CAAC;IAC/C,CAAC;CACJ;AApBD,4BAoBC"}
@@ -0,0 +1,11 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class RequiredIf implements Rule {
3
+ private otherField;
4
+ private otherValue;
5
+ private data;
6
+ constructor(otherField: string, otherValue: any, data: any);
7
+ validate(value: any): Promise<boolean>;
8
+ message(): string;
9
+ private getDataValue;
10
+ }
11
+ //# sourceMappingURL=RequiredIf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequiredIf.d.ts","sourceRoot":"","sources":["../../src/Rules/RequiredIf.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,UAAW,YAAW,IAAI;IACnC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,IAAI,CAAM;gBAEN,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG;IAMpD,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAU5C,OAAO,IAAI,MAAM;IAIjB,OAAO,CAAC,YAAY;CAGvB"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RequiredIf = void 0;
4
+ class RequiredIf {
5
+ constructor(otherField, otherValue, data) {
6
+ this.otherField = otherField;
7
+ this.otherValue = otherValue;
8
+ this.data = data;
9
+ }
10
+ async validate(value) {
11
+ const otherValue = this.getDataValue(this.otherField);
12
+ if (String(otherValue) === String(this.otherValue)) {
13
+ return value !== null && value !== undefined && value !== '';
14
+ }
15
+ return true;
16
+ }
17
+ message() {
18
+ return `The :attribute field is required when ${this.otherField} is ${this.otherValue}.`;
19
+ }
20
+ getDataValue(key) {
21
+ return key.split('.').reduce((o, i) => (o ? o[i] : undefined), this.data);
22
+ }
23
+ }
24
+ exports.RequiredIf = RequiredIf;
25
+ //# sourceMappingURL=RequiredIf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RequiredIf.js","sourceRoot":"","sources":["../../src/Rules/RequiredIf.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IAKnB,YAAY,UAAkB,EAAE,UAAe,EAAE,IAAS;QACtD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,KAAU;QACrB,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAEtD,IAAI,MAAM,CAAC,UAAU,CAAC,KAAK,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YACjD,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC;QACjE,CAAC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO;QACH,OAAO,yCAAyC,IAAI,CAAC,UAAU,OAAO,IAAI,CAAC,UAAU,GAAG,CAAC;IAC7F,CAAC;IAEO,YAAY,CAAC,GAAW;QAC5B,OAAO,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC9E,CAAC;CACJ;AA5BD,gCA4BC"}
@@ -0,0 +1,6 @@
1
+ import { Rule } from '../Rule';
2
+ export declare class IsString implements Rule {
3
+ validate(value: any): boolean;
4
+ message(): string;
5
+ }
6
+ //# sourceMappingURL=String.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"String.d.ts","sourceRoot":"","sources":["../../src/Rules/String.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAE/B,qBAAa,QAAS,YAAW,IAAI;IACjC,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO;IAK7B,OAAO,IAAI,MAAM;CAGpB"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IsString = void 0;
4
+ class IsString {
5
+ validate(value) {
6
+ if (value === null || value === undefined)
7
+ return true;
8
+ return typeof value === 'string';
9
+ }
10
+ message() {
11
+ return 'The :attribute must be a string.';
12
+ }
13
+ }
14
+ exports.IsString = IsString;
15
+ //# sourceMappingURL=String.js.map