kanun 1.0.2 → 1.0.3
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 +15 -6
- package/dist/index.d.ts +4 -0
- package/dist/index.js +15 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2355,7 +2355,7 @@ var BaseValidator = class BaseValidator {
|
|
|
2355
2355
|
[rule, parameters] = validationRuleParser.parse(rule);
|
|
2356
2356
|
const keys = this.getExplicitKeys(attribute);
|
|
2357
2357
|
if (keys.length > 0 && parameters.length > 0) parameters = this.replaceAsterisksInParameters(parameters, keys);
|
|
2358
|
-
const value =
|
|
2358
|
+
const value = this.getAttributeValue(attribute);
|
|
2359
2359
|
const validatable = this.isValidatable(attribute, value, rule);
|
|
2360
2360
|
if (rule instanceof IRuleContract) return validatable ? this.validateUsingCustomRule(attribute, value, rule) : void 0;
|
|
2361
2361
|
const method = `validate${buildValidationMethodName(rule)}`;
|
|
@@ -2423,14 +2423,14 @@ var BaseValidator = class BaseValidator {
|
|
|
2423
2423
|
* Determine if the attribute is validatable.
|
|
2424
2424
|
*/
|
|
2425
2425
|
isValidatable(attribute, value, rule) {
|
|
2426
|
-
return this.presentOrRuleIsImplicit(attribute, value, rule) && this.passesOptionalCheck(attribute) && this.isNotNullIfMarkedAsNullable(attribute, rule);
|
|
2426
|
+
return this.presentOrRuleIsImplicit(attribute, value, rule) && this.passesOptionalCheck(attribute) && this.isNotNullIfMarkedAsNullable(attribute, value, rule);
|
|
2427
2427
|
}
|
|
2428
2428
|
/**
|
|
2429
2429
|
* Determine if the field is present, or the rule implies required.
|
|
2430
2430
|
*/
|
|
2431
2431
|
presentOrRuleIsImplicit(attribute, value, rule) {
|
|
2432
2432
|
if (typeof value === "string" && value.trim() === "") return isImplicitRule(rule);
|
|
2433
|
-
return typeof
|
|
2433
|
+
return typeof value !== "undefined" || isImplicitRule(rule);
|
|
2434
2434
|
}
|
|
2435
2435
|
/**
|
|
2436
2436
|
* Determine if the attribute passes any optional check.
|
|
@@ -2438,14 +2438,23 @@ var BaseValidator = class BaseValidator {
|
|
|
2438
2438
|
passesOptionalCheck(attribute) {
|
|
2439
2439
|
if (!validationRuleParser.hasRule(attribute, ["sometimes"], this.rules)) return true;
|
|
2440
2440
|
const data = validationData.initializeAndGatherData(attribute, this.data);
|
|
2441
|
-
|
|
2441
|
+
const requestFiles = validationData.initializeAndGatherData(attribute, this.getContext().requestFiles ?? {});
|
|
2442
|
+
return Object.prototype.hasOwnProperty.call(data, attribute) || Object.prototype.hasOwnProperty.call(this.data, attribute) || Object.prototype.hasOwnProperty.call(requestFiles, attribute) || Object.prototype.hasOwnProperty.call(this.getContext().requestFiles ?? {}, attribute);
|
|
2442
2443
|
}
|
|
2443
2444
|
/**
|
|
2444
2445
|
* Determine if the attribute fails the nullable check.
|
|
2445
2446
|
*/
|
|
2446
|
-
isNotNullIfMarkedAsNullable(attribute, rule) {
|
|
2447
|
+
isNotNullIfMarkedAsNullable(attribute, value, rule) {
|
|
2447
2448
|
if (isImplicitRule(rule) || !validationRuleParser.hasRule(attribute, ["nullable"], this.rules)) return true;
|
|
2448
|
-
return
|
|
2449
|
+
return value !== null;
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
2453
|
+
*/
|
|
2454
|
+
getAttributeValue(attribute) {
|
|
2455
|
+
const dataValue = deepFind(this.data, attribute);
|
|
2456
|
+
if (typeof dataValue !== "undefined") return dataValue;
|
|
2457
|
+
return deepFind(this.getContext().requestFiles ?? {}, attribute);
|
|
2449
2458
|
}
|
|
2450
2459
|
/**
|
|
2451
2460
|
* Get the primary attribute name
|
package/dist/index.d.ts
CHANGED
|
@@ -603,6 +603,10 @@ declare class BaseValidator<D extends GenericObject = GenericObject> {
|
|
|
603
603
|
* Determine if the attribute fails the nullable check.
|
|
604
604
|
*/
|
|
605
605
|
private isNotNullIfMarkedAsNullable;
|
|
606
|
+
/**
|
|
607
|
+
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
608
|
+
*/
|
|
609
|
+
private getAttributeValue;
|
|
606
610
|
/**
|
|
607
611
|
* Get the primary attribute name
|
|
608
612
|
*
|
package/dist/index.js
CHANGED
|
@@ -2325,7 +2325,7 @@ var BaseValidator = class BaseValidator {
|
|
|
2325
2325
|
[rule, parameters] = validationRuleParser.parse(rule);
|
|
2326
2326
|
const keys = this.getExplicitKeys(attribute);
|
|
2327
2327
|
if (keys.length > 0 && parameters.length > 0) parameters = this.replaceAsterisksInParameters(parameters, keys);
|
|
2328
|
-
const value =
|
|
2328
|
+
const value = this.getAttributeValue(attribute);
|
|
2329
2329
|
const validatable = this.isValidatable(attribute, value, rule);
|
|
2330
2330
|
if (rule instanceof IRuleContract) return validatable ? this.validateUsingCustomRule(attribute, value, rule) : void 0;
|
|
2331
2331
|
const method = `validate${buildValidationMethodName(rule)}`;
|
|
@@ -2393,14 +2393,14 @@ var BaseValidator = class BaseValidator {
|
|
|
2393
2393
|
* Determine if the attribute is validatable.
|
|
2394
2394
|
*/
|
|
2395
2395
|
isValidatable(attribute, value, rule) {
|
|
2396
|
-
return this.presentOrRuleIsImplicit(attribute, value, rule) && this.passesOptionalCheck(attribute) && this.isNotNullIfMarkedAsNullable(attribute, rule);
|
|
2396
|
+
return this.presentOrRuleIsImplicit(attribute, value, rule) && this.passesOptionalCheck(attribute) && this.isNotNullIfMarkedAsNullable(attribute, value, rule);
|
|
2397
2397
|
}
|
|
2398
2398
|
/**
|
|
2399
2399
|
* Determine if the field is present, or the rule implies required.
|
|
2400
2400
|
*/
|
|
2401
2401
|
presentOrRuleIsImplicit(attribute, value, rule) {
|
|
2402
2402
|
if (typeof value === "string" && value.trim() === "") return isImplicitRule(rule);
|
|
2403
|
-
return typeof
|
|
2403
|
+
return typeof value !== "undefined" || isImplicitRule(rule);
|
|
2404
2404
|
}
|
|
2405
2405
|
/**
|
|
2406
2406
|
* Determine if the attribute passes any optional check.
|
|
@@ -2408,14 +2408,23 @@ var BaseValidator = class BaseValidator {
|
|
|
2408
2408
|
passesOptionalCheck(attribute) {
|
|
2409
2409
|
if (!validationRuleParser.hasRule(attribute, ["sometimes"], this.rules)) return true;
|
|
2410
2410
|
const data = validationData.initializeAndGatherData(attribute, this.data);
|
|
2411
|
-
|
|
2411
|
+
const requestFiles = validationData.initializeAndGatherData(attribute, this.getContext().requestFiles ?? {});
|
|
2412
|
+
return Object.prototype.hasOwnProperty.call(data, attribute) || Object.prototype.hasOwnProperty.call(this.data, attribute) || Object.prototype.hasOwnProperty.call(requestFiles, attribute) || Object.prototype.hasOwnProperty.call(this.getContext().requestFiles ?? {}, attribute);
|
|
2412
2413
|
}
|
|
2413
2414
|
/**
|
|
2414
2415
|
* Determine if the attribute fails the nullable check.
|
|
2415
2416
|
*/
|
|
2416
|
-
isNotNullIfMarkedAsNullable(attribute, rule) {
|
|
2417
|
+
isNotNullIfMarkedAsNullable(attribute, value, rule) {
|
|
2417
2418
|
if (isImplicitRule(rule) || !validationRuleParser.hasRule(attribute, ["nullable"], this.rules)) return true;
|
|
2418
|
-
return
|
|
2419
|
+
return value !== null;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Resolve an attribute value from validator data first, then request-scoped file context.
|
|
2423
|
+
*/
|
|
2424
|
+
getAttributeValue(attribute) {
|
|
2425
|
+
const dataValue = deepFind(this.data, attribute);
|
|
2426
|
+
if (typeof dataValue !== "undefined") return dataValue;
|
|
2427
|
+
return deepFind(this.getContext().requestFiles ?? {}, attribute);
|
|
2419
2428
|
}
|
|
2420
2429
|
/**
|
|
2421
2430
|
* Get the primary attribute name
|