kanun 1.0.5 → 1.0.7
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/dist/index.cjs +17 -7
- package/dist/index.d.ts +5 -0
- package/dist/index.js +17 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1470,8 +1470,9 @@ var validateAttributes = class {
|
|
|
1470
1470
|
}
|
|
1471
1471
|
getAttributeValue(attribute) {
|
|
1472
1472
|
const dataValue = deepFind(this.data, attribute);
|
|
1473
|
-
|
|
1474
|
-
|
|
1473
|
+
const fileValue = deepFind(this.context.requestFiles ?? {}, attribute);
|
|
1474
|
+
if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
|
|
1475
|
+
return dataValue;
|
|
1475
1476
|
}
|
|
1476
1477
|
getDistinctValues(primaryAttribute) {
|
|
1477
1478
|
const gathered = validationData.initializeAndGatherData(primaryAttribute, this.data);
|
|
@@ -2067,11 +2068,12 @@ var Password$1 = class Password$1 extends IRuleContract {
|
|
|
2067
2068
|
* Determine if the validation rule passes.
|
|
2068
2069
|
*/
|
|
2069
2070
|
passes(value, attribute) {
|
|
2070
|
-
const
|
|
2071
|
+
const passwordRules = [
|
|
2071
2072
|
"string",
|
|
2072
2073
|
`min:${this.minLength}`,
|
|
2073
2074
|
...this.customRules
|
|
2074
|
-
]
|
|
2075
|
+
];
|
|
2076
|
+
const validator = new BaseValidator(this.data, { [attribute]: passwordRules }, this.validator.customMessages, this.validator.customAttributes).setLang(this.lang);
|
|
2075
2077
|
if (!validator.validate()) {
|
|
2076
2078
|
const errors = validator.errors().addErrorTypes().get(attribute);
|
|
2077
2079
|
for (const key in errors) this.validator.errors().add(attribute, errors[key]);
|
|
@@ -2299,6 +2301,7 @@ var BaseValidator = class BaseValidator {
|
|
|
2299
2301
|
*/
|
|
2300
2302
|
withContext(context = {}) {
|
|
2301
2303
|
this.context = context;
|
|
2304
|
+
this.addRules(this.initalRules);
|
|
2302
2305
|
return this;
|
|
2303
2306
|
}
|
|
2304
2307
|
/**
|
|
@@ -2549,7 +2552,8 @@ var BaseValidator = class BaseValidator {
|
|
|
2549
2552
|
* Parse the given rules add assign them to the current rules
|
|
2550
2553
|
*/
|
|
2551
2554
|
addRules(rules) {
|
|
2552
|
-
const
|
|
2555
|
+
const availableData = mergeDeep(this.getContext().requestFiles ?? {}, this.data);
|
|
2556
|
+
const response = validationRuleParser.explodeRules(dotify(rules, true), availableData);
|
|
2553
2557
|
this.rules = response.rules;
|
|
2554
2558
|
this.implicitAttributes = response.implicitAttributes;
|
|
2555
2559
|
}
|
|
@@ -2656,11 +2660,17 @@ var BaseValidator = class BaseValidator {
|
|
|
2656
2660
|
}
|
|
2657
2661
|
/**
|
|
2658
2662
|
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
2663
|
+
* When the data value is empty (null or empty string), prefer a file from requestFiles
|
|
2664
|
+
* because framework body-parsers commonly set file input fields to '' or null.
|
|
2665
|
+
*
|
|
2666
|
+
* @param attribute
|
|
2667
|
+
* @returns
|
|
2659
2668
|
*/
|
|
2660
2669
|
getAttributeValue(attribute) {
|
|
2661
2670
|
const dataValue = deepFind(this.data, attribute);
|
|
2662
|
-
|
|
2663
|
-
|
|
2671
|
+
const fileValue = deepFind(this.getContext().requestFiles ?? {}, attribute);
|
|
2672
|
+
if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
|
|
2673
|
+
return dataValue;
|
|
2664
2674
|
}
|
|
2665
2675
|
/**
|
|
2666
2676
|
* Get the primary attribute name
|
package/dist/index.d.ts
CHANGED
|
@@ -610,6 +610,11 @@ declare class BaseValidator<D extends GenericObject = GenericObject> {
|
|
|
610
610
|
private isNotNullIfMarkedAsNullable;
|
|
611
611
|
/**
|
|
612
612
|
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
613
|
+
* When the data value is empty (null or empty string), prefer a file from requestFiles
|
|
614
|
+
* because framework body-parsers commonly set file input fields to '' or null.
|
|
615
|
+
*
|
|
616
|
+
* @param attribute
|
|
617
|
+
* @returns
|
|
613
618
|
*/
|
|
614
619
|
private getAttributeValue;
|
|
615
620
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1440,8 +1440,9 @@ var validateAttributes = class {
|
|
|
1440
1440
|
}
|
|
1441
1441
|
getAttributeValue(attribute) {
|
|
1442
1442
|
const dataValue = deepFind(this.data, attribute);
|
|
1443
|
-
|
|
1444
|
-
|
|
1443
|
+
const fileValue = deepFind(this.context.requestFiles ?? {}, attribute);
|
|
1444
|
+
if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
|
|
1445
|
+
return dataValue;
|
|
1445
1446
|
}
|
|
1446
1447
|
getDistinctValues(primaryAttribute) {
|
|
1447
1448
|
const gathered = validationData.initializeAndGatherData(primaryAttribute, this.data);
|
|
@@ -2037,11 +2038,12 @@ var Password$1 = class Password$1 extends IRuleContract {
|
|
|
2037
2038
|
* Determine if the validation rule passes.
|
|
2038
2039
|
*/
|
|
2039
2040
|
passes(value, attribute) {
|
|
2040
|
-
const
|
|
2041
|
+
const passwordRules = [
|
|
2041
2042
|
"string",
|
|
2042
2043
|
`min:${this.minLength}`,
|
|
2043
2044
|
...this.customRules
|
|
2044
|
-
]
|
|
2045
|
+
];
|
|
2046
|
+
const validator = new BaseValidator(this.data, { [attribute]: passwordRules }, this.validator.customMessages, this.validator.customAttributes).setLang(this.lang);
|
|
2045
2047
|
if (!validator.validate()) {
|
|
2046
2048
|
const errors = validator.errors().addErrorTypes().get(attribute);
|
|
2047
2049
|
for (const key in errors) this.validator.errors().add(attribute, errors[key]);
|
|
@@ -2269,6 +2271,7 @@ var BaseValidator = class BaseValidator {
|
|
|
2269
2271
|
*/
|
|
2270
2272
|
withContext(context = {}) {
|
|
2271
2273
|
this.context = context;
|
|
2274
|
+
this.addRules(this.initalRules);
|
|
2272
2275
|
return this;
|
|
2273
2276
|
}
|
|
2274
2277
|
/**
|
|
@@ -2519,7 +2522,8 @@ var BaseValidator = class BaseValidator {
|
|
|
2519
2522
|
* Parse the given rules add assign them to the current rules
|
|
2520
2523
|
*/
|
|
2521
2524
|
addRules(rules) {
|
|
2522
|
-
const
|
|
2525
|
+
const availableData = mergeDeep(this.getContext().requestFiles ?? {}, this.data);
|
|
2526
|
+
const response = validationRuleParser.explodeRules(dotify(rules, true), availableData);
|
|
2523
2527
|
this.rules = response.rules;
|
|
2524
2528
|
this.implicitAttributes = response.implicitAttributes;
|
|
2525
2529
|
}
|
|
@@ -2626,11 +2630,17 @@ var BaseValidator = class BaseValidator {
|
|
|
2626
2630
|
}
|
|
2627
2631
|
/**
|
|
2628
2632
|
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
2633
|
+
* When the data value is empty (null or empty string), prefer a file from requestFiles
|
|
2634
|
+
* because framework body-parsers commonly set file input fields to '' or null.
|
|
2635
|
+
*
|
|
2636
|
+
* @param attribute
|
|
2637
|
+
* @returns
|
|
2629
2638
|
*/
|
|
2630
2639
|
getAttributeValue(attribute) {
|
|
2631
2640
|
const dataValue = deepFind(this.data, attribute);
|
|
2632
|
-
|
|
2633
|
-
|
|
2641
|
+
const fileValue = deepFind(this.getContext().requestFiles ?? {}, attribute);
|
|
2642
|
+
if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
|
|
2643
|
+
return dataValue;
|
|
2634
2644
|
}
|
|
2635
2645
|
/**
|
|
2636
2646
|
* Get the primary attribute name
|