@warlock.js/core 2.7.3 → 2.7.5
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/cjs/builder/build-cli-app.d.ts.map +1 -1
- package/cjs/builder/build-cli-app.js +17 -17
- package/cjs/builder/build-cli-app.js.map +1 -1
- package/cjs/builder/build-http-app.d.ts.map +1 -1
- package/cjs/builder/build-http-app.js +1 -4
- package/cjs/builder/build-http-app.js.map +1 -1
- package/cjs/config/get-warlock-config.d.ts +2 -1
- package/cjs/config/get-warlock-config.d.ts.map +1 -1
- package/cjs/config/get-warlock-config.js +6 -11
- package/cjs/config/get-warlock-config.js.map +1 -1
- package/cjs/config/index.d.ts +1 -0
- package/cjs/config/index.d.ts.map +1 -1
- package/cjs/console/commands/index.js +1 -1
- package/cjs/console/commands/index.js.map +1 -1
- package/cjs/esbuild/execute-ts-file.d.ts.map +1 -1
- package/cjs/esbuild/execute-ts-file.js +6 -2
- package/cjs/esbuild/execute-ts-file.js.map +1 -1
- package/cjs/http/response.d.ts.map +1 -1
- package/cjs/http/response.js +4 -6
- package/cjs/http/response.js.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/output/output.d.ts +7 -0
- package/cjs/output/output.d.ts.map +1 -1
- package/cjs/output/output.js +12 -3
- package/cjs/output/output.js.map +1 -1
- package/cjs/router/router.d.ts.map +1 -1
- package/cjs/router/router.js +5 -1
- package/cjs/router/router.js.map +1 -1
- package/cjs/starters/build-http-production.js +1 -1
- package/cjs/starters/build-http-production.js.map +1 -1
- package/cjs/utils/sluggable.d.ts.map +1 -1
- package/cjs/utils/sluggable.js +2 -1
- package/cjs/utils/sluggable.js.map +1 -1
- package/cjs/validator/locales.js +2 -2
- package/cjs/validator/locales.js.map +1 -1
- package/cjs/validator/v/rules.d.ts.map +1 -1
- package/cjs/validator/v/rules.js +65 -65
- package/cjs/validator/v/rules.js.map +1 -1
- package/cjs/validator/v/utils.d.ts.map +1 -1
- package/cjs/validator/v/utils.js +3 -1
- package/cjs/validator/v/utils.js.map +1 -1
- package/esm/builder/build-cli-app.d.ts.map +1 -1
- package/esm/builder/build-cli-app.js +17 -17
- package/esm/builder/build-cli-app.js.map +1 -1
- package/esm/builder/build-http-app.d.ts.map +1 -1
- package/esm/builder/build-http-app.js +1 -4
- package/esm/builder/build-http-app.js.map +1 -1
- package/esm/config/get-warlock-config.d.ts +2 -1
- package/esm/config/get-warlock-config.d.ts.map +1 -1
- package/esm/config/get-warlock-config.js +6 -11
- package/esm/config/get-warlock-config.js.map +1 -1
- package/esm/config/index.d.ts +1 -0
- package/esm/config/index.d.ts.map +1 -1
- package/esm/console/commands/index.js +1 -1
- package/esm/console/commands/index.js.map +1 -1
- package/esm/esbuild/execute-ts-file.d.ts.map +1 -1
- package/esm/esbuild/execute-ts-file.js +6 -2
- package/esm/esbuild/execute-ts-file.js.map +1 -1
- package/esm/http/response.d.ts.map +1 -1
- package/esm/http/response.js +4 -6
- package/esm/http/response.js.map +1 -1
- package/esm/index.js +1 -1
- package/esm/output/output.d.ts +7 -0
- package/esm/output/output.d.ts.map +1 -1
- package/esm/output/output.js +12 -3
- package/esm/output/output.js.map +1 -1
- package/esm/router/router.d.ts.map +1 -1
- package/esm/router/router.js +5 -1
- package/esm/router/router.js.map +1 -1
- package/esm/starters/build-http-production.js +1 -1
- package/esm/starters/build-http-production.js.map +1 -1
- package/esm/utils/sluggable.d.ts.map +1 -1
- package/esm/utils/sluggable.js +2 -1
- package/esm/utils/sluggable.js.map +1 -1
- package/esm/validator/locales.js +2 -2
- package/esm/validator/locales.js.map +1 -1
- package/esm/validator/v/rules.d.ts.map +1 -1
- package/esm/validator/v/rules.js +65 -65
- package/esm/validator/v/rules.js.map +1 -1
- package/esm/validator/v/utils.d.ts.map +1 -1
- package/esm/validator/v/utils.js +3 -1
- package/esm/validator/v/utils.js.map +1 -1
- package/package.json +3 -3
package/esm/validator/v/rules.js
CHANGED
|
@@ -15,7 +15,7 @@ const requiredWithRule = {
|
|
|
15
15
|
description: "The field is required if another field is present",
|
|
16
16
|
sortOrder: -2,
|
|
17
17
|
requiresValue: false,
|
|
18
|
-
|
|
18
|
+
defaultErrorMessage: "The :input is required",
|
|
19
19
|
async validate(value, context) {
|
|
20
20
|
const otherField = this.context.options.field;
|
|
21
21
|
const fieldValue = get(context.allValues, otherField);
|
|
@@ -33,7 +33,7 @@ const requiredIfAbsentRule = {
|
|
|
33
33
|
description: "The field is required if another field is absent",
|
|
34
34
|
sortOrder: -2,
|
|
35
35
|
requiresValue: false,
|
|
36
|
-
|
|
36
|
+
defaultErrorMessage: "The :input is required",
|
|
37
37
|
async validate(value, context) {
|
|
38
38
|
const otherField = this.context.options.field;
|
|
39
39
|
const fieldValue = get(context.allValues || {}, otherField);
|
|
@@ -49,7 +49,7 @@ const requiredIfSiblingFieldAllAbsentRule = {
|
|
|
49
49
|
description: "The field is required if all other fields are absent",
|
|
50
50
|
sortOrder: -2,
|
|
51
51
|
requiresValue: false,
|
|
52
|
-
|
|
52
|
+
defaultErrorMessage: "The :input is required",
|
|
53
53
|
async validate(value, context) {
|
|
54
54
|
const fields = this.context.options.fields;
|
|
55
55
|
let isPresent = false;
|
|
@@ -71,7 +71,7 @@ const requiredIfEmptyRule = {
|
|
|
71
71
|
description: "The field is required if another field is empty",
|
|
72
72
|
sortOrder: -2,
|
|
73
73
|
requiresValue: false,
|
|
74
|
-
|
|
74
|
+
defaultErrorMessage: "The :input is required",
|
|
75
75
|
async validate(value, context) {
|
|
76
76
|
const otherField = this.context.options.field;
|
|
77
77
|
const fieldValue = get(context.allValues, otherField);
|
|
@@ -87,7 +87,7 @@ const requiredIfSiblingFieldEmptyRule = {
|
|
|
87
87
|
description: "The field is required if another field in same parent context is empty",
|
|
88
88
|
sortOrder: -2,
|
|
89
89
|
requiresValue: false,
|
|
90
|
-
|
|
90
|
+
defaultErrorMessage: "The :input is required",
|
|
91
91
|
async validate(value, context) {
|
|
92
92
|
const otherField = this.context.options.field;
|
|
93
93
|
const fieldValue = get(context.parent, otherField);
|
|
@@ -102,7 +102,7 @@ const requiredIfFieldRule = {
|
|
|
102
102
|
description: "The field is required if another field has a specific value",
|
|
103
103
|
sortOrder: -2,
|
|
104
104
|
requiresValue: false,
|
|
105
|
-
|
|
105
|
+
defaultErrorMessage: "The :input is required",
|
|
106
106
|
async validate(value, context) {
|
|
107
107
|
const otherField = this.context.options.field;
|
|
108
108
|
const otherFieldValue = this.context.options.value;
|
|
@@ -121,7 +121,7 @@ const requiredIfSiblingFieldRule = {
|
|
|
121
121
|
description: "The field is required if another field in same parent context has a specific value",
|
|
122
122
|
sortOrder: -2,
|
|
123
123
|
requiresValue: false,
|
|
124
|
-
|
|
124
|
+
defaultErrorMessage: "The :input is required",
|
|
125
125
|
async validate(value, context) {
|
|
126
126
|
const otherField = this.context.options.field;
|
|
127
127
|
const otherFieldValue = this.context.options.value;
|
|
@@ -138,7 +138,7 @@ const requiredUnlessSiblingFieldRule = {
|
|
|
138
138
|
description: "The field is required unless another field in same parent context has a specific value",
|
|
139
139
|
sortOrder: -2,
|
|
140
140
|
requiresValue: false,
|
|
141
|
-
|
|
141
|
+
defaultErrorMessage: "The :input is required",
|
|
142
142
|
async validate(value, context) {
|
|
143
143
|
const otherField = this.context.options.field;
|
|
144
144
|
const otherFieldValue = this.context.options.value;
|
|
@@ -162,7 +162,7 @@ const objectRule = {
|
|
|
162
162
|
};
|
|
163
163
|
const stringRule = {
|
|
164
164
|
name: "string",
|
|
165
|
-
|
|
165
|
+
defaultErrorMessage: "The :input must be a string",
|
|
166
166
|
async validate(value, context) {
|
|
167
167
|
if (typeof value === "string") {
|
|
168
168
|
return VALID_RULE;
|
|
@@ -172,7 +172,7 @@ const stringRule = {
|
|
|
172
172
|
};
|
|
173
173
|
const numberRule = {
|
|
174
174
|
name: "number",
|
|
175
|
-
|
|
175
|
+
defaultErrorMessage: "The :input must be a number",
|
|
176
176
|
async validate(value, context) {
|
|
177
177
|
if (typeof value === "number") {
|
|
178
178
|
return VALID_RULE;
|
|
@@ -182,7 +182,7 @@ const numberRule = {
|
|
|
182
182
|
};
|
|
183
183
|
const booleanRule = {
|
|
184
184
|
name: "boolean",
|
|
185
|
-
|
|
185
|
+
defaultErrorMessage: "The :input must be a boolean",
|
|
186
186
|
async validate(value, context) {
|
|
187
187
|
if (typeof value === "boolean") {
|
|
188
188
|
return VALID_RULE;
|
|
@@ -192,7 +192,7 @@ const booleanRule = {
|
|
|
192
192
|
};
|
|
193
193
|
const intRule = {
|
|
194
194
|
name: "int",
|
|
195
|
-
|
|
195
|
+
defaultErrorMessage: "The :input must be an integer",
|
|
196
196
|
async validate(value, context) {
|
|
197
197
|
if (Number.isInteger(value)) {
|
|
198
198
|
return VALID_RULE;
|
|
@@ -202,7 +202,7 @@ const intRule = {
|
|
|
202
202
|
};
|
|
203
203
|
const floatRule = {
|
|
204
204
|
name: "float",
|
|
205
|
-
|
|
205
|
+
defaultErrorMessage: "The :input must be a float",
|
|
206
206
|
async validate(value, context) {
|
|
207
207
|
if (Number.isFinite(value) && !Number.isInteger(value)) {
|
|
208
208
|
return VALID_RULE;
|
|
@@ -212,7 +212,7 @@ const floatRule = {
|
|
|
212
212
|
};
|
|
213
213
|
const inRule = {
|
|
214
214
|
name: "in",
|
|
215
|
-
|
|
215
|
+
defaultErrorMessage: "The :input must be one of the following values: :options",
|
|
216
216
|
async validate(value, context) {
|
|
217
217
|
if (this.context.options.values.includes(value)) {
|
|
218
218
|
return VALID_RULE;
|
|
@@ -222,7 +222,7 @@ const inRule = {
|
|
|
222
222
|
};
|
|
223
223
|
const enumRule = {
|
|
224
224
|
name: "enum",
|
|
225
|
-
|
|
225
|
+
defaultErrorMessage: "The :input must be one of the following values: :options",
|
|
226
226
|
async validate(value, context) {
|
|
227
227
|
const enumObject = this.context.options.enum;
|
|
228
228
|
const enumValues = Object.values(enumObject);
|
|
@@ -235,7 +235,7 @@ const enumRule = {
|
|
|
235
235
|
};
|
|
236
236
|
const withoutWhitespaceRule = {
|
|
237
237
|
name: "withoutWhitespace",
|
|
238
|
-
|
|
238
|
+
defaultErrorMessage: "The :input must not contain whitespace",
|
|
239
239
|
async validate(value, context) {
|
|
240
240
|
if (!/\s/.test(value)) {
|
|
241
241
|
return VALID_RULE;
|
|
@@ -245,7 +245,7 @@ const withoutWhitespaceRule = {
|
|
|
245
245
|
};
|
|
246
246
|
const minWordsRule = {
|
|
247
247
|
name: "minWords",
|
|
248
|
-
|
|
248
|
+
defaultErrorMessage: `The :input must be at least :minWords words`,
|
|
249
249
|
async validate(value, context) {
|
|
250
250
|
if (value?.split(" ").length >= this.context.options.minWords) {
|
|
251
251
|
return VALID_RULE;
|
|
@@ -255,7 +255,7 @@ const minWordsRule = {
|
|
|
255
255
|
};
|
|
256
256
|
const maxWordsRule = {
|
|
257
257
|
name: "maxWords",
|
|
258
|
-
|
|
258
|
+
defaultErrorMessage: `The :input must be at most :maxWords words`,
|
|
259
259
|
async validate(value, context) {
|
|
260
260
|
if (value?.split(" ").length <= this.context.options.maxWords) {
|
|
261
261
|
return VALID_RULE;
|
|
@@ -265,7 +265,7 @@ const maxWordsRule = {
|
|
|
265
265
|
};
|
|
266
266
|
const wordsRule = {
|
|
267
267
|
name: "words",
|
|
268
|
-
|
|
268
|
+
defaultErrorMessage: `The :input must be exactly :words words`,
|
|
269
269
|
async validate(value, context) {
|
|
270
270
|
if (value?.split(" ").length === this.context.options.words) {
|
|
271
271
|
return VALID_RULE;
|
|
@@ -275,7 +275,7 @@ const wordsRule = {
|
|
|
275
275
|
};
|
|
276
276
|
const minLengthRule = {
|
|
277
277
|
name: "minLength",
|
|
278
|
-
|
|
278
|
+
defaultErrorMessage: `The :input must be at least :minLength characters long`,
|
|
279
279
|
async validate(value, context) {
|
|
280
280
|
if (value?.length >= this.context.options.minLength) {
|
|
281
281
|
return VALID_RULE;
|
|
@@ -285,7 +285,7 @@ const minLengthRule = {
|
|
|
285
285
|
};
|
|
286
286
|
const maxLengthRule = {
|
|
287
287
|
name: "maxLength",
|
|
288
|
-
|
|
288
|
+
defaultErrorMessage: `The :input must not exceed :maxLength characters`,
|
|
289
289
|
async validate(value, context) {
|
|
290
290
|
if (value?.length <= this.context.options.maxLength) {
|
|
291
291
|
return VALID_RULE;
|
|
@@ -295,7 +295,7 @@ const maxLengthRule = {
|
|
|
295
295
|
};
|
|
296
296
|
const lengthRule = {
|
|
297
297
|
name: "length",
|
|
298
|
-
|
|
298
|
+
defaultErrorMessage: `The :input must be exactly :length characters long`,
|
|
299
299
|
async validate(value, context) {
|
|
300
300
|
if (value?.length === this.context.options.length) {
|
|
301
301
|
return VALID_RULE;
|
|
@@ -305,7 +305,7 @@ const lengthRule = {
|
|
|
305
305
|
};
|
|
306
306
|
const minRule = {
|
|
307
307
|
name: "min",
|
|
308
|
-
|
|
308
|
+
defaultErrorMessage: `The :input must be at least :min`,
|
|
309
309
|
async validate(value, context) {
|
|
310
310
|
if (value >= this.context.options.min) {
|
|
311
311
|
return VALID_RULE;
|
|
@@ -315,7 +315,7 @@ const minRule = {
|
|
|
315
315
|
};
|
|
316
316
|
const maxRule = {
|
|
317
317
|
name: "max",
|
|
318
|
-
|
|
318
|
+
defaultErrorMessage: `The :input must equal to or less than :max`,
|
|
319
319
|
async validate(value, context) {
|
|
320
320
|
if (value <= this.context.options.max) {
|
|
321
321
|
return VALID_RULE;
|
|
@@ -325,7 +325,7 @@ const maxRule = {
|
|
|
325
325
|
};
|
|
326
326
|
const equalRule = {
|
|
327
327
|
name: "equal",
|
|
328
|
-
|
|
328
|
+
defaultErrorMessage: `The :input must be equal to :value`,
|
|
329
329
|
async validate(input, context) {
|
|
330
330
|
if (input === this.context.options.value) {
|
|
331
331
|
return VALID_RULE;
|
|
@@ -335,7 +335,7 @@ const equalRule = {
|
|
|
335
335
|
};
|
|
336
336
|
const emailRule = {
|
|
337
337
|
name: "email",
|
|
338
|
-
|
|
338
|
+
defaultErrorMessage: "The :input must be a valid email address",
|
|
339
339
|
async validate(value, context) {
|
|
340
340
|
if (isEmail(value)) {
|
|
341
341
|
return VALID_RULE;
|
|
@@ -345,7 +345,7 @@ const emailRule = {
|
|
|
345
345
|
};
|
|
346
346
|
const scalarRule = {
|
|
347
347
|
name: "scalar",
|
|
348
|
-
|
|
348
|
+
defaultErrorMessage: "The :input must be a scalar value",
|
|
349
349
|
async validate(value, context) {
|
|
350
350
|
// a valid value considered to beb either a string, number, or boolean
|
|
351
351
|
if (["string", "number", "boolean"].includes(typeof value)) {
|
|
@@ -357,7 +357,7 @@ const scalarRule = {
|
|
|
357
357
|
const unknownKeyRule = {
|
|
358
358
|
name: "unknownKey",
|
|
359
359
|
sortOrder: -1,
|
|
360
|
-
|
|
360
|
+
defaultErrorMessage: "The :input contains unknown properties",
|
|
361
361
|
async validate(value, context) {
|
|
362
362
|
const schema = this.context.options.schema;
|
|
363
363
|
const allowedKeys = this.context.options.allowedKeys || [];
|
|
@@ -377,7 +377,7 @@ const unknownKeyRule = {
|
|
|
377
377
|
};
|
|
378
378
|
const matchesRule = {
|
|
379
379
|
name: "matches",
|
|
380
|
-
|
|
380
|
+
defaultErrorMessage: "The :input must match the :field",
|
|
381
381
|
async validate(value, context) {
|
|
382
382
|
const otherField = this.context.options.field;
|
|
383
383
|
if (value === get(context.allValues, otherField)) {
|
|
@@ -388,7 +388,7 @@ const matchesRule = {
|
|
|
388
388
|
};
|
|
389
389
|
const dateRule = {
|
|
390
390
|
name: "date",
|
|
391
|
-
|
|
391
|
+
defaultErrorMessage: "The :input must be a valid date",
|
|
392
392
|
async validate(value, context) {
|
|
393
393
|
const format = this.context.options.format;
|
|
394
394
|
// use dayjs for date validation
|
|
@@ -409,7 +409,7 @@ const dateRule = {
|
|
|
409
409
|
const minDateRule = {
|
|
410
410
|
name: "minDate",
|
|
411
411
|
description: "The field must be at least the given date",
|
|
412
|
-
|
|
412
|
+
defaultErrorMessage: `The :input must be at least :minDate`,
|
|
413
413
|
async validate(value, context) {
|
|
414
414
|
if (value >= this.context.options.minDate) {
|
|
415
415
|
return VALID_RULE;
|
|
@@ -420,7 +420,7 @@ const minDateRule = {
|
|
|
420
420
|
// Must be used with Date mutator
|
|
421
421
|
const maxDateRule = {
|
|
422
422
|
name: "maxDate",
|
|
423
|
-
|
|
423
|
+
defaultErrorMessage: `The :input must be at most :maxDate`,
|
|
424
424
|
async validate(value, context) {
|
|
425
425
|
if (value <= this.context.options.maxDate) {
|
|
426
426
|
return VALID_RULE;
|
|
@@ -430,7 +430,7 @@ const maxDateRule = {
|
|
|
430
430
|
};
|
|
431
431
|
const urlRule = {
|
|
432
432
|
name: "url",
|
|
433
|
-
|
|
433
|
+
defaultErrorMessage: "The :input must be a valid URL",
|
|
434
434
|
async validate(value, context) {
|
|
435
435
|
try {
|
|
436
436
|
new URL(value);
|
|
@@ -443,7 +443,7 @@ const urlRule = {
|
|
|
443
443
|
};
|
|
444
444
|
const ipRule = {
|
|
445
445
|
name: "ip",
|
|
446
|
-
|
|
446
|
+
defaultErrorMessage: "The :input must be a valid IP address",
|
|
447
447
|
async validate(value, context) {
|
|
448
448
|
const result = isIP(value);
|
|
449
449
|
if (result !== 0) {
|
|
@@ -454,7 +454,7 @@ const ipRule = {
|
|
|
454
454
|
};
|
|
455
455
|
const ip4Rule = {
|
|
456
456
|
name: "ip4",
|
|
457
|
-
|
|
457
|
+
defaultErrorMessage: "The :input must be a valid IPv4 address",
|
|
458
458
|
async validate(value, context) {
|
|
459
459
|
const result = isIP(value);
|
|
460
460
|
if (result === 4) {
|
|
@@ -465,7 +465,7 @@ const ip4Rule = {
|
|
|
465
465
|
};
|
|
466
466
|
const ip6Rule = {
|
|
467
467
|
name: "ip6",
|
|
468
|
-
|
|
468
|
+
defaultErrorMessage: "The :input must be a valid IPv6 address",
|
|
469
469
|
async validate(value, context) {
|
|
470
470
|
const result = isIP(value);
|
|
471
471
|
if (result === 6) {
|
|
@@ -476,7 +476,7 @@ const ip6Rule = {
|
|
|
476
476
|
};
|
|
477
477
|
const isNumericRule = {
|
|
478
478
|
name: "isNumeric",
|
|
479
|
-
|
|
479
|
+
defaultErrorMessage: "The :input must be a numeric value",
|
|
480
480
|
async validate(value, context) {
|
|
481
481
|
if (isNumeric(value)) {
|
|
482
482
|
return VALID_RULE;
|
|
@@ -486,7 +486,7 @@ const isNumericRule = {
|
|
|
486
486
|
};
|
|
487
487
|
const startsWithRule = {
|
|
488
488
|
name: "startsWith",
|
|
489
|
-
|
|
489
|
+
defaultErrorMessage: "The :input must start with :value",
|
|
490
490
|
async validate(value, context) {
|
|
491
491
|
if (value.startsWith(this.context.options.value)) {
|
|
492
492
|
return VALID_RULE;
|
|
@@ -496,7 +496,7 @@ const startsWithRule = {
|
|
|
496
496
|
};
|
|
497
497
|
const endsWithRule = {
|
|
498
498
|
name: "endsWith",
|
|
499
|
-
|
|
499
|
+
defaultErrorMessage: "The :input must end with :value",
|
|
500
500
|
async validate(value, context) {
|
|
501
501
|
if (value.endsWith(this.context.options.value)) {
|
|
502
502
|
return VALID_RULE;
|
|
@@ -506,7 +506,7 @@ const endsWithRule = {
|
|
|
506
506
|
};
|
|
507
507
|
const containsRule = {
|
|
508
508
|
name: "contains",
|
|
509
|
-
|
|
509
|
+
defaultErrorMessage: "The :input must contain :value",
|
|
510
510
|
async validate(value, context) {
|
|
511
511
|
if (value.includes(this.context.options.value)) {
|
|
512
512
|
return VALID_RULE;
|
|
@@ -516,7 +516,7 @@ const containsRule = {
|
|
|
516
516
|
};
|
|
517
517
|
const notContainsRule = {
|
|
518
518
|
name: "notContains",
|
|
519
|
-
|
|
519
|
+
defaultErrorMessage: "The :input must not contain :value",
|
|
520
520
|
async validate(value, context) {
|
|
521
521
|
if (!value.includes(this.context.options.value)) {
|
|
522
522
|
return VALID_RULE;
|
|
@@ -526,7 +526,7 @@ const notContainsRule = {
|
|
|
526
526
|
};
|
|
527
527
|
const alphaRule = {
|
|
528
528
|
name: "alpha",
|
|
529
|
-
|
|
529
|
+
defaultErrorMessage: "The :input must contain only alphabetic characters",
|
|
530
530
|
async validate(value, context) {
|
|
531
531
|
if (/^[a-zA-Z]+$/.test(value)) {
|
|
532
532
|
return VALID_RULE;
|
|
@@ -546,7 +546,7 @@ const alphaNumericRule = {
|
|
|
546
546
|
};
|
|
547
547
|
const patternRule = {
|
|
548
548
|
name: "pattern",
|
|
549
|
-
|
|
549
|
+
defaultErrorMessage: "The :input does not match the pattern",
|
|
550
550
|
async validate(value, context) {
|
|
551
551
|
if (this.context.options.pattern.test(value)) {
|
|
552
552
|
return VALID_RULE;
|
|
@@ -556,7 +556,7 @@ const patternRule = {
|
|
|
556
556
|
};
|
|
557
557
|
const moduloRule = {
|
|
558
558
|
name: "modulo",
|
|
559
|
-
|
|
559
|
+
defaultErrorMessage: "The :input must be a multiple of :value",
|
|
560
560
|
async validate(value, context) {
|
|
561
561
|
if (value % this.context.options.value === 0) {
|
|
562
562
|
return VALID_RULE;
|
|
@@ -567,7 +567,7 @@ const moduloRule = {
|
|
|
567
567
|
const isCreditCardRule = {
|
|
568
568
|
name: "isCreditCard",
|
|
569
569
|
description: "The field must be a valid credit card number",
|
|
570
|
-
|
|
570
|
+
defaultErrorMessage: "The :input must be a valid credit card number",
|
|
571
571
|
async validate(value, context) {
|
|
572
572
|
// Luhn algorithm
|
|
573
573
|
const cardNumber = value.toString().replace(/\D/g, "");
|
|
@@ -592,7 +592,7 @@ const isCreditCardRule = {
|
|
|
592
592
|
};
|
|
593
593
|
const positiveRule = {
|
|
594
594
|
name: "positive",
|
|
595
|
-
|
|
595
|
+
defaultErrorMessage: "The :input must be a positive number",
|
|
596
596
|
async validate(value, context) {
|
|
597
597
|
if (value > 0) {
|
|
598
598
|
return VALID_RULE;
|
|
@@ -604,7 +604,7 @@ const positiveRule = {
|
|
|
604
604
|
const uniqueArrayRule = {
|
|
605
605
|
name: "uniqueArray",
|
|
606
606
|
description: "The array must contain unique values",
|
|
607
|
-
|
|
607
|
+
defaultErrorMessage: "The :input must contain unique values",
|
|
608
608
|
async validate(value, context) {
|
|
609
609
|
const uniqueValues = new Set(value);
|
|
610
610
|
if (uniqueValues.size === value.length) {
|
|
@@ -615,7 +615,7 @@ const uniqueArrayRule = {
|
|
|
615
615
|
};
|
|
616
616
|
const uploadableRule = {
|
|
617
617
|
name: "uploadable",
|
|
618
|
-
|
|
618
|
+
defaultErrorMessage: "The :input must be a valid uploadable hash id",
|
|
619
619
|
async validate(value, context) {
|
|
620
620
|
const hashExists = await Upload.aggregate().where("hash", value).exists();
|
|
621
621
|
if (hashExists) {
|
|
@@ -626,7 +626,7 @@ const uploadableRule = {
|
|
|
626
626
|
};
|
|
627
627
|
const fileRule = {
|
|
628
628
|
name: "file",
|
|
629
|
-
|
|
629
|
+
defaultErrorMessage: "The :input must be a file",
|
|
630
630
|
async validate(value, context) {
|
|
631
631
|
if (value instanceof UploadedFile) {
|
|
632
632
|
return VALID_RULE;
|
|
@@ -636,7 +636,7 @@ const fileRule = {
|
|
|
636
636
|
};
|
|
637
637
|
const fileTypeRule = {
|
|
638
638
|
name: "fileType",
|
|
639
|
-
|
|
639
|
+
defaultErrorMessage: "The :input must be a :types file",
|
|
640
640
|
async validate(value, context) {
|
|
641
641
|
let mimeTypes = this.context.options.mimeTypes;
|
|
642
642
|
if (typeof mimeTypes === "string") {
|
|
@@ -664,7 +664,7 @@ const fileExtensionRule = {
|
|
|
664
664
|
};
|
|
665
665
|
const maxFileSizeRule = {
|
|
666
666
|
name: "maxFileSize",
|
|
667
|
-
|
|
667
|
+
defaultErrorMessage: "The :input must not exceed :maxFileSize",
|
|
668
668
|
async validate(value, context) {
|
|
669
669
|
if (value.size <= this.context.options.maxFileSize) {
|
|
670
670
|
return VALID_RULE;
|
|
@@ -674,7 +674,7 @@ const maxFileSizeRule = {
|
|
|
674
674
|
};
|
|
675
675
|
const minFileSizeRule = {
|
|
676
676
|
name: "minFileSize",
|
|
677
|
-
|
|
677
|
+
defaultErrorMessage: "The :input must be at least :minFileSize",
|
|
678
678
|
async validate(value, context) {
|
|
679
679
|
if (value.size >= this.context.options.minFileSize) {
|
|
680
680
|
return VALID_RULE;
|
|
@@ -684,7 +684,7 @@ const minFileSizeRule = {
|
|
|
684
684
|
};
|
|
685
685
|
const imageRule = {
|
|
686
686
|
name: "image",
|
|
687
|
-
|
|
687
|
+
defaultErrorMessage: "The :input must be an image",
|
|
688
688
|
async validate(value, context) {
|
|
689
689
|
if (value instanceof UploadedFile && value.isImage) {
|
|
690
690
|
return VALID_RULE;
|
|
@@ -694,7 +694,7 @@ const imageRule = {
|
|
|
694
694
|
};
|
|
695
695
|
const minWidthRule = {
|
|
696
696
|
name: "minWidth",
|
|
697
|
-
|
|
697
|
+
defaultErrorMessage: "The :input must be at least :minWidth pixels wide",
|
|
698
698
|
async validate(value, context) {
|
|
699
699
|
const dimensions = await value.dimensions();
|
|
700
700
|
if (dimensions.width >= this.context.options.minWidth) {
|
|
@@ -705,7 +705,7 @@ const minWidthRule = {
|
|
|
705
705
|
};
|
|
706
706
|
const maxWidthRule = {
|
|
707
707
|
name: "maxWidth",
|
|
708
|
-
|
|
708
|
+
defaultErrorMessage: "The :input must be at most :maxWidth pixels wide",
|
|
709
709
|
async validate(value, context) {
|
|
710
710
|
const dimensions = await value.dimensions();
|
|
711
711
|
if (dimensions.width <= this.context.options.maxWidth) {
|
|
@@ -716,7 +716,7 @@ const maxWidthRule = {
|
|
|
716
716
|
};
|
|
717
717
|
const minHeightRule = {
|
|
718
718
|
name: "minHeight",
|
|
719
|
-
|
|
719
|
+
defaultErrorMessage: "The :input must be at least :minHeight pixels tall",
|
|
720
720
|
async validate(value, context) {
|
|
721
721
|
const dimensions = await value.dimensions();
|
|
722
722
|
if (dimensions.height >= this.context.options.minHeight) {
|
|
@@ -727,7 +727,7 @@ const minHeightRule = {
|
|
|
727
727
|
};
|
|
728
728
|
const maxHeightRule = {
|
|
729
729
|
name: "maxHeight",
|
|
730
|
-
|
|
730
|
+
defaultErrorMessage: "The :input must be at most :maxHeight pixels tall",
|
|
731
731
|
async validate(value, context) {
|
|
732
732
|
const dimensions = await value.dimensions();
|
|
733
733
|
if (dimensions.height <= this.context.options.maxHeight) {
|
|
@@ -793,7 +793,7 @@ const colorValidationRegex = {
|
|
|
793
793
|
};
|
|
794
794
|
const rgbColorRule = {
|
|
795
795
|
name: "rgbColor",
|
|
796
|
-
|
|
796
|
+
defaultErrorMessage: "The :input must be a valid RGB color",
|
|
797
797
|
async validate(value, context) {
|
|
798
798
|
if (value.match(colorValidationRegex.rgb)) {
|
|
799
799
|
return VALID_RULE;
|
|
@@ -803,7 +803,7 @@ const rgbColorRule = {
|
|
|
803
803
|
};
|
|
804
804
|
const rgbaColorRule = {
|
|
805
805
|
name: "rgbaColor",
|
|
806
|
-
|
|
806
|
+
defaultErrorMessage: "The :input must be a valid RGBA color",
|
|
807
807
|
async validate(value, context) {
|
|
808
808
|
if (value.match(colorValidationRegex.rgba)) {
|
|
809
809
|
return VALID_RULE;
|
|
@@ -813,7 +813,7 @@ const rgbaColorRule = {
|
|
|
813
813
|
};
|
|
814
814
|
const hexColorRule = {
|
|
815
815
|
name: "hexColor",
|
|
816
|
-
|
|
816
|
+
defaultErrorMessage: "The :input must be a valid hex color",
|
|
817
817
|
async validate(value, context) {
|
|
818
818
|
if (value.match(colorValidationRegex.hex)) {
|
|
819
819
|
return VALID_RULE;
|
|
@@ -823,7 +823,7 @@ const hexColorRule = {
|
|
|
823
823
|
};
|
|
824
824
|
const hslColorRule = {
|
|
825
825
|
name: "hslColor",
|
|
826
|
-
|
|
826
|
+
defaultErrorMessage: "The :input must be a valid HSL color",
|
|
827
827
|
async validate(value, context) {
|
|
828
828
|
if (value.match(colorValidationRegex.hsl)) {
|
|
829
829
|
return VALID_RULE;
|
|
@@ -833,7 +833,7 @@ const hslColorRule = {
|
|
|
833
833
|
};
|
|
834
834
|
const lightColorRule = {
|
|
835
835
|
name: "lightColor",
|
|
836
|
-
|
|
836
|
+
defaultErrorMessage: "The :input must be a light color",
|
|
837
837
|
async validate(value, context) {
|
|
838
838
|
if (value.match(colorValidationRegex.light)) {
|
|
839
839
|
return VALID_RULE;
|
|
@@ -843,7 +843,7 @@ const lightColorRule = {
|
|
|
843
843
|
};
|
|
844
844
|
const darkColorRule = {
|
|
845
845
|
name: "darkColor",
|
|
846
|
-
|
|
846
|
+
defaultErrorMessage: "The :input must be a dark color",
|
|
847
847
|
async validate(value, context) {
|
|
848
848
|
if (value.match(colorValidationRegex.dark)) {
|
|
849
849
|
return VALID_RULE;
|
|
@@ -853,7 +853,7 @@ const darkColorRule = {
|
|
|
853
853
|
};
|
|
854
854
|
const colorRule = {
|
|
855
855
|
name: "color",
|
|
856
|
-
|
|
856
|
+
defaultErrorMessage: "The :input must be a valid color",
|
|
857
857
|
async validate(value, context) {
|
|
858
858
|
if (value.match(colorValidationRegex.hex) ||
|
|
859
859
|
value.match(colorValidationRegex.rgb) ||
|
|
@@ -866,7 +866,7 @@ const colorRule = {
|
|
|
866
866
|
};
|
|
867
867
|
const forbiddenRule = {
|
|
868
868
|
name: "forbidden",
|
|
869
|
-
|
|
869
|
+
defaultErrorMessage: "The :input is forbidden",
|
|
870
870
|
async validate(_value, context) {
|
|
871
871
|
return invalidRule(this, context);
|
|
872
872
|
},
|