kanun 1.0.6 → 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 CHANGED
@@ -1470,8 +1470,9 @@ var validateAttributes = class {
1470
1470
  }
1471
1471
  getAttributeValue(attribute) {
1472
1472
  const dataValue = deepFind(this.data, attribute);
1473
- if (typeof dataValue !== "undefined") return dataValue;
1474
- return deepFind(this.context.requestFiles ?? {}, attribute);
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);
@@ -2659,11 +2660,17 @@ var BaseValidator = class BaseValidator {
2659
2660
  }
2660
2661
  /**
2661
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
2662
2668
  */
2663
2669
  getAttributeValue(attribute) {
2664
2670
  const dataValue = deepFind(this.data, attribute);
2665
- if (typeof dataValue !== "undefined") return dataValue;
2666
- return deepFind(this.getContext().requestFiles ?? {}, attribute);
2671
+ const fileValue = deepFind(this.getContext().requestFiles ?? {}, attribute);
2672
+ if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
2673
+ return dataValue;
2667
2674
  }
2668
2675
  /**
2669
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
- if (typeof dataValue !== "undefined") return dataValue;
1444
- return deepFind(this.context.requestFiles ?? {}, attribute);
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);
@@ -2629,11 +2630,17 @@ var BaseValidator = class BaseValidator {
2629
2630
  }
2630
2631
  /**
2631
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
2632
2638
  */
2633
2639
  getAttributeValue(attribute) {
2634
2640
  const dataValue = deepFind(this.data, attribute);
2635
- if (typeof dataValue !== "undefined") return dataValue;
2636
- return deepFind(this.getContext().requestFiles ?? {}, attribute);
2641
+ const fileValue = deepFind(this.getContext().requestFiles ?? {}, attribute);
2642
+ if (typeof fileValue !== "undefined" && (typeof dataValue === "undefined" || dataValue === null || dataValue === "")) return fileValue;
2643
+ return dataValue;
2637
2644
  }
2638
2645
  /**
2639
2646
  * Get the primary attribute name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kanun",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Framework-agnostic TypeScript-first validation library.",
5
5
  "type": "module",
6
6
  "files": [