@warlock.js/seal 5.30.0 → 5.32.0
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/CHANGELOG.md +46 -7
- package/README.md +57 -9
- package/cjs/index.cjs +41 -29
- package/cjs/index.cjs.map +1 -1
- package/cjs/{object--LXRt5RF.cjs → object-BoVGJ68E.cjs} +43 -24
- package/cjs/object-BoVGJ68E.cjs.map +1 -0
- package/cjs/object.cjs +2 -2
- package/cjs/{required-methods-DYsRO9aZ.cjs → required-methods-BJlnLnwa.cjs} +343 -258
- package/cjs/required-methods-BJlnLnwa.cjs.map +1 -0
- package/cjs/{string-DsqnKoSB.cjs → string-CM8x0u2w.cjs} +46 -44
- package/cjs/string-CM8x0u2w.cjs.map +1 -0
- package/cjs/string.cjs +2 -2
- package/esm/config.d.mts +7 -8
- package/esm/config.d.mts.map +1 -1
- package/esm/config.mjs.map +1 -1
- package/esm/factory/index.d.mts +2 -1
- package/esm/factory/index.mjs +1 -1
- package/esm/factory/validate.d.mts +3 -6
- package/esm/factory/validate.d.mts.map +1 -1
- package/esm/factory/validators.d.mts +16 -13
- package/esm/factory/validators.d.mts.map +1 -1
- package/esm/factory/validators.mjs +7 -1
- package/esm/factory/validators.mjs.map +1 -1
- package/esm/helpers/date-helpers.d.mts +1 -2
- package/esm/helpers/date-helpers.d.mts.map +1 -1
- package/esm/helpers/file.utils.d.mts +2 -4
- package/esm/helpers/file.utils.d.mts.map +1 -1
- package/esm/helpers/get-field-value.d.mts +2 -3
- package/esm/helpers/get-field-value.d.mts.map +1 -1
- package/esm/helpers/get-field-value.mjs +2 -1
- package/esm/helpers/get-field-value.mjs.map +1 -1
- package/esm/helpers/index.d.mts +6 -0
- package/esm/helpers/index.mjs +1 -1
- package/esm/helpers/path-helpers.d.mts +1 -2
- package/esm/helpers/path-helpers.d.mts.map +1 -1
- package/esm/helpers/validation-helpers.d.mts +4 -10
- package/esm/helpers/validation-helpers.d.mts.map +1 -1
- package/esm/index.d.mts +7 -0
- package/esm/mutators/array-mutators.d.mts +6 -7
- package/esm/mutators/array-mutators.d.mts.map +1 -1
- package/esm/mutators/boolean-mutators.d.mts +3 -4
- package/esm/mutators/boolean-mutators.d.mts.map +1 -1
- package/esm/mutators/date-mutators.d.mts +18 -19
- package/esm/mutators/date-mutators.d.mts.map +1 -1
- package/esm/mutators/index.d.mts +8 -0
- package/esm/mutators/index.mjs +1 -1
- package/esm/mutators/number-mutators.d.mts +10 -11
- package/esm/mutators/number-mutators.d.mts.map +1 -1
- package/esm/mutators/object-mutators.d.mts +4 -5
- package/esm/mutators/object-mutators.d.mts.map +1 -1
- package/esm/mutators/object-mutators.mjs +5 -4
- package/esm/mutators/object-mutators.mjs.map +1 -1
- package/esm/mutators/scalar-mutators.d.mts +2 -3
- package/esm/mutators/scalar-mutators.d.mts.map +1 -1
- package/esm/mutators/string-mutators.d.mts +37 -38
- package/esm/mutators/string-mutators.d.mts.map +1 -1
- package/esm/mutators/string-mutators.mjs +5 -3
- package/esm/mutators/string-mutators.mjs.map +1 -1
- package/esm/object.d.mts +3 -5
- package/esm/object.d.mts.map +1 -1
- package/esm/object.mjs.map +1 -1
- package/esm/plugins/plugin-system.d.mts +11 -9
- package/esm/plugins/plugin-system.d.mts.map +1 -1
- package/esm/rules/array/array-rules.d.mts +3 -4
- package/esm/rules/array/array-rules.d.mts.map +1 -1
- package/esm/rules/array/index.d.mts +2 -0
- package/esm/rules/array/index.mjs +1 -1
- package/esm/rules/color/color-rules.d.mts +8 -9
- package/esm/rules/color/color-rules.d.mts.map +1 -1
- package/esm/rules/color/index.d.mts +2 -0
- package/esm/rules/color/index.mjs +1 -1
- package/esm/rules/common/enum.d.mts +5 -6
- package/esm/rules/common/enum.d.mts.map +1 -1
- package/esm/rules/common/equals-field-rules.d.mts +3 -4
- package/esm/rules/common/equals-field-rules.d.mts.map +1 -1
- package/esm/rules/common/index.d.mts +7 -0
- package/esm/rules/common/index.mjs +1 -1
- package/esm/rules/common/instanceof.d.mts +2 -3
- package/esm/rules/common/instanceof.d.mts.map +1 -1
- package/esm/rules/common/literal.d.mts +2 -3
- package/esm/rules/common/literal.d.mts.map +1 -1
- package/esm/rules/common/literal.mjs.map +1 -1
- package/esm/rules/common/type-rules.d.mts +10 -11
- package/esm/rules/common/type-rules.d.mts.map +1 -1
- package/esm/rules/common/unknown-key.d.mts +2 -3
- package/esm/rules/common/unknown-key.d.mts.map +1 -1
- package/esm/rules/conditional/forbidden-if-rules.d.mts +7 -8
- package/esm/rules/conditional/forbidden-if-rules.d.mts.map +1 -1
- package/esm/rules/conditional/index.d.mts +11 -0
- package/esm/rules/conditional/index.mjs +1 -1
- package/esm/rules/conditional/present-if-rules.d.mts +6 -7
- package/esm/rules/conditional/present-if-rules.d.mts.map +1 -1
- package/esm/rules/conditional/present-unless-rules.d.mts +2 -3
- package/esm/rules/conditional/present-unless-rules.d.mts.map +1 -1
- package/esm/rules/conditional/present-with-rules.d.mts +4 -5
- package/esm/rules/conditional/present-with-rules.d.mts.map +1 -1
- package/esm/rules/conditional/present-without-rules.d.mts +4 -5
- package/esm/rules/conditional/present-without-rules.d.mts.map +1 -1
- package/esm/rules/conditional/required-if-rules.d.mts +10 -11
- package/esm/rules/conditional/required-if-rules.d.mts.map +1 -1
- package/esm/rules/conditional/required-unless-rules.d.mts +2 -3
- package/esm/rules/conditional/required-unless-rules.d.mts.map +1 -1
- package/esm/rules/conditional/required-when-rule.d.mts +2 -3
- package/esm/rules/conditional/required-when-rule.d.mts.map +1 -1
- package/esm/rules/conditional/required-with-rules.d.mts +4 -5
- package/esm/rules/conditional/required-with-rules.d.mts.map +1 -1
- package/esm/rules/conditional/required-without-rules.d.mts +4 -5
- package/esm/rules/conditional/required-without-rules.d.mts.map +1 -1
- package/esm/rules/core/equal.d.mts +2 -3
- package/esm/rules/core/equal.d.mts.map +1 -1
- package/esm/rules/core/forbidden.d.mts +2 -3
- package/esm/rules/core/forbidden.d.mts.map +1 -1
- package/esm/rules/core/index.d.mts +6 -0
- package/esm/rules/core/index.mjs +1 -1
- package/esm/rules/core/required.d.mts +3 -4
- package/esm/rules/core/required.d.mts.map +1 -1
- package/esm/rules/core/union.d.mts +10 -4
- package/esm/rules/core/union.d.mts.map +1 -1
- package/esm/rules/core/union.mjs +56 -10
- package/esm/rules/core/union.mjs.map +1 -1
- package/esm/rules/core/when.d.mts +2 -3
- package/esm/rules/core/when.d.mts.map +1 -1
- package/esm/rules/core/when.mjs.map +1 -1
- package/esm/rules/date/date-comparison-rules.d.mts +6 -7
- package/esm/rules/date/date-comparison-rules.d.mts.map +1 -1
- package/esm/rules/date/date-day-rules.d.mts +5 -6
- package/esm/rules/date/date-day-rules.d.mts.map +1 -1
- package/esm/rules/date/date-field-comparison-rules.d.mts +4 -5
- package/esm/rules/date/date-field-comparison-rules.d.mts.map +1 -1
- package/esm/rules/date/date-field-comparison-rules.mjs +6 -3
- package/esm/rules/date/date-field-comparison-rules.mjs.map +1 -1
- package/esm/rules/date/date-period-rules.d.mts +16 -16
- package/esm/rules/date/date-period-rules.d.mts.map +1 -1
- package/esm/rules/date/date-period-rules.mjs +24 -12
- package/esm/rules/date/date-period-rules.mjs.map +1 -1
- package/esm/rules/date/date-relative-rules.d.mts +4 -5
- package/esm/rules/date/date-relative-rules.d.mts.map +1 -1
- package/esm/rules/date/date-relative-rules.mjs +3 -3
- package/esm/rules/date/date-relative-rules.mjs.map +1 -1
- package/esm/rules/date/date-special-rules.d.mts +4 -5
- package/esm/rules/date/date-special-rules.d.mts.map +1 -1
- package/esm/rules/date/date.d.mts +16 -17
- package/esm/rules/date/date.d.mts.map +1 -1
- package/esm/rules/date/date.mjs +4 -2
- package/esm/rules/date/date.mjs.map +1 -1
- package/esm/rules/date/index.d.mts +8 -0
- package/esm/rules/date/index.mjs +1 -1
- package/esm/rules/file/dimensions.d.mts +5 -6
- package/esm/rules/file/dimensions.d.mts.map +1 -1
- package/esm/rules/file/file-size.d.mts +3 -4
- package/esm/rules/file/file-size.d.mts.map +1 -1
- package/esm/rules/file/index.d.mts +3 -0
- package/esm/rules/file/index.mjs +1 -1
- package/esm/rules/index.d.mts +56 -0
- package/esm/rules/index.mjs +1 -1
- package/esm/rules/length/index.d.mts +2 -0
- package/esm/rules/length/index.mjs +1 -1
- package/esm/rules/length/length-rules.d.mts +8 -9
- package/esm/rules/length/length-rules.d.mts.map +1 -1
- package/esm/rules/number/index.d.mts +2 -0
- package/esm/rules/number/index.mjs +1 -1
- package/esm/rules/number/number-rules.d.mts +11 -12
- package/esm/rules/number/number-rules.d.mts.map +1 -1
- package/esm/rules/number/number-rules.mjs +12 -6
- package/esm/rules/number/number-rules.mjs.map +1 -1
- package/esm/rules/scalar/index.mjs +1 -1
- package/esm/rules/string/alpha.d.mts +4 -5
- package/esm/rules/string/alpha.d.mts.map +1 -1
- package/esm/rules/string/credit-card.d.mts +2 -3
- package/esm/rules/string/credit-card.d.mts.map +1 -1
- package/esm/rules/string/email.d.mts +2 -3
- package/esm/rules/string/email.d.mts.map +1 -1
- package/esm/rules/string/id-formats.d.mts +6 -7
- package/esm/rules/string/id-formats.d.mts.map +1 -1
- package/esm/rules/string/index.d.mts +12 -0
- package/esm/rules/string/index.mjs +1 -1
- package/esm/rules/string/ip.d.mts +7 -8
- package/esm/rules/string/ip.d.mts.map +1 -1
- package/esm/rules/string/matches.d.mts +2 -3
- package/esm/rules/string/matches.d.mts.map +1 -1
- package/esm/rules/string/pattern.d.mts +2 -3
- package/esm/rules/string/pattern.d.mts.map +1 -1
- package/esm/rules/string/string-comparison.d.mts +5 -6
- package/esm/rules/string/string-comparison.d.mts.map +1 -1
- package/esm/rules/string/strong-password-rule.d.mts +2 -3
- package/esm/rules/string/strong-password-rule.d.mts.map +1 -1
- package/esm/rules/string/url.d.mts +2 -3
- package/esm/rules/string/url.d.mts.map +1 -1
- package/esm/rules/string/without-whitespace.d.mts +2 -3
- package/esm/rules/string/without-whitespace.d.mts.map +1 -1
- package/esm/standard-schema/index.d.mts +4 -0
- package/esm/standard-schema/json-schema.d.mts +5 -7
- package/esm/standard-schema/json-schema.d.mts.map +1 -1
- package/esm/standard-schema/json-schema.mjs.map +1 -1
- package/esm/standard-schema/map-result.d.mts +2 -3
- package/esm/standard-schema/map-result.d.mts.map +1 -1
- package/esm/standard-schema/map-result.mjs.map +1 -1
- package/esm/standard-schema/types.d.mts +4 -5
- package/esm/standard-schema/types.d.mts.map +1 -1
- package/esm/string.d.mts +2 -3
- package/esm/string.d.mts.map +1 -1
- package/esm/types/conditional-types.d.mts +8 -6
- package/esm/types/conditional-types.d.mts.map +1 -1
- package/esm/types/context-types.d.mts +24 -15
- package/esm/types/context-types.d.mts.map +1 -1
- package/esm/types/data-transformer-types.d.mts +3 -5
- package/esm/types/data-transformer-types.d.mts.map +1 -1
- package/esm/types/date-types.d.mts +2 -3
- package/esm/types/date-types.d.mts.map +1 -1
- package/esm/types/file.types.d.mts +1 -2
- package/esm/types/file.types.d.mts.map +1 -1
- package/esm/types/index.d.mts +11 -0
- package/esm/types/inference-types.d.mts +15 -14
- package/esm/types/inference-types.d.mts.map +1 -1
- package/esm/types/mutator-types.d.mts +9 -7
- package/esm/types/mutator-types.d.mts.map +1 -1
- package/esm/types/result-types.d.mts +12 -7
- package/esm/types/result-types.d.mts.map +1 -1
- package/esm/types/rule-types.d.mts +33 -15
- package/esm/types/rule-types.d.mts.map +1 -1
- package/esm/types/schema-types.d.mts +1 -3
- package/esm/types/schema-types.d.mts.map +1 -1
- package/esm/validators/any-validator.d.mts +1 -3
- package/esm/validators/any-validator.d.mts.map +1 -1
- package/esm/validators/array-validator.d.mts +2 -3
- package/esm/validators/array-validator.d.mts.map +1 -1
- package/esm/validators/array-validator.mjs +3 -3
- package/esm/validators/array-validator.mjs.map +1 -1
- package/esm/validators/base-validator.d.mts +10 -11
- package/esm/validators/base-validator.d.mts.map +1 -1
- package/esm/validators/base-validator.mjs +52 -21
- package/esm/validators/base-validator.mjs.map +1 -1
- package/esm/validators/boolean-validator.d.mts +1 -3
- package/esm/validators/boolean-validator.d.mts.map +1 -1
- package/esm/validators/computed-validator.d.mts +3 -4
- package/esm/validators/computed-validator.d.mts.map +1 -1
- package/esm/validators/computed-validator.mjs +4 -4
- package/esm/validators/computed-validator.mjs.map +1 -1
- package/esm/validators/date-validator.d.mts +2 -3
- package/esm/validators/date-validator.d.mts.map +1 -1
- package/esm/validators/discriminated-union-validator.d.mts +3 -3
- package/esm/validators/discriminated-union-validator.d.mts.map +1 -1
- package/esm/validators/discriminated-union-validator.mjs +1 -1
- package/esm/validators/discriminated-union-validator.mjs.map +1 -1
- package/esm/validators/float-validator.d.mts +1 -3
- package/esm/validators/float-validator.d.mts.map +1 -1
- package/esm/validators/index.d.mts +2 -1
- package/esm/validators/index.mjs +1 -1
- package/esm/validators/instanceof-validator.d.mts +1 -3
- package/esm/validators/instanceof-validator.d.mts.map +1 -1
- package/esm/validators/int-validator.d.mts +1 -3
- package/esm/validators/int-validator.d.mts.map +1 -1
- package/esm/validators/lazy-validator.d.mts +2 -3
- package/esm/validators/lazy-validator.d.mts.map +1 -1
- package/esm/validators/lazy-validator.mjs +1 -1
- package/esm/validators/lazy-validator.mjs.map +1 -1
- package/esm/validators/literal-validator.d.mts +1 -3
- package/esm/validators/literal-validator.d.mts.map +1 -1
- package/esm/validators/managed-validator.d.mts +3 -4
- package/esm/validators/managed-validator.d.mts.map +1 -1
- package/esm/validators/methods/equality-conditional-methods.d.mts +3 -4
- package/esm/validators/methods/equality-conditional-methods.d.mts.map +1 -1
- package/esm/validators/methods/forbidden-methods.d.mts +2 -3
- package/esm/validators/methods/forbidden-methods.d.mts.map +1 -1
- package/esm/validators/methods/present-methods.d.mts +2 -3
- package/esm/validators/methods/present-methods.d.mts.map +1 -1
- package/esm/validators/methods/required-methods.d.mts +3 -4
- package/esm/validators/methods/required-methods.d.mts.map +1 -1
- package/esm/validators/number-validator.d.mts +1 -3
- package/esm/validators/number-validator.d.mts.map +1 -1
- package/esm/validators/number-validator.mjs +12 -8
- package/esm/validators/number-validator.mjs.map +1 -1
- package/esm/validators/numeric-validator.d.mts +1 -3
- package/esm/validators/numeric-validator.d.mts.map +1 -1
- package/esm/validators/object-validator.d.mts +2 -3
- package/esm/validators/object-validator.d.mts.map +1 -1
- package/esm/validators/object-validator.mjs +9 -7
- package/esm/validators/object-validator.mjs.map +1 -1
- package/esm/validators/primitive-validator.d.mts +1 -3
- package/esm/validators/primitive-validator.d.mts.map +1 -1
- package/esm/validators/record-validator.d.mts +2 -3
- package/esm/validators/record-validator.d.mts.map +1 -1
- package/esm/validators/record-validator.mjs +3 -3
- package/esm/validators/record-validator.mjs.map +1 -1
- package/esm/validators/scalar-validator.d.mts +1 -3
- package/esm/validators/scalar-validator.d.mts.map +1 -1
- package/esm/validators/scalar-validator.mjs.map +1 -1
- package/esm/validators/string-validator.d.mts +1 -3
- package/esm/validators/string-validator.d.mts.map +1 -1
- package/esm/validators/tuple-validator.d.mts +2 -3
- package/esm/validators/tuple-validator.d.mts.map +1 -1
- package/esm/validators/tuple-validator.mjs +3 -3
- package/esm/validators/tuple-validator.mjs.map +1 -1
- package/esm/validators/union-validator.d.mts +4 -4
- package/esm/validators/union-validator.d.mts.map +1 -1
- package/esm/validators/union-validator.mjs +3 -1
- package/esm/validators/union-validator.mjs.map +1 -1
- package/llms-full.txt +656 -527
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/skills/bridge-standard-schema/SKILL.md +60 -36
- package/skills/compose-seal-modifiers/SKILL.md +89 -53
- package/skills/define-structural-shape/SKILL.md +41 -27
- package/skills/define-structural-shape/array-methods.md +27 -27
- package/skills/define-structural-shape/object-methods.md +38 -30
- package/skills/extend-seal-with-plugins/SKILL.md +39 -5
- package/skills/generate-json-schema/SKILL.md +13 -13
- package/skills/handle-seal-errors/SKILL.md +23 -23
- package/skills/index.md +4 -1
- package/skills/overview/SKILL.md +10 -2
- package/skills/pick-seal-primitive/SKILL.md +45 -45
- package/skills/pick-seal-primitive/date-methods.md +96 -96
- package/skills/pick-seal-primitive/number-methods.md +55 -55
- package/skills/pick-seal-primitive/string-methods.md +107 -102
- package/skills/seal-basics/SKILL.md +14 -14
- package/cjs/object--LXRt5RF.cjs.map +0 -1
- package/cjs/required-methods-DYsRO9aZ.cjs.map +0 -1
- package/cjs/string-DsqnKoSB.cjs.map +0 -1
package/esm/rules/core/union.mjs
CHANGED
|
@@ -2,8 +2,37 @@ import { VALID_RULE, invalidRule } from "../../helpers/validation-helpers.mjs";
|
|
|
2
2
|
import "../../helpers/index.mjs";
|
|
3
3
|
|
|
4
4
|
//#region ../../packages/seal/src/rules/core/union.ts
|
|
5
|
+
const describeFailure = (index, errors) => ({
|
|
6
|
+
index,
|
|
7
|
+
errors,
|
|
8
|
+
literalMismatches: errors.filter((error) => error.type === "literal").length,
|
|
9
|
+
depth: Math.max(0, ...errors.map((error) => error.input ? error.input.split(".").length : 0))
|
|
10
|
+
});
|
|
5
11
|
/**
|
|
6
|
-
*
|
|
12
|
+
* Whether `candidate` is closer to the value than `best`:
|
|
13
|
+
*
|
|
14
|
+
* 1. Fewest mismatched literals. A literal that does not match (`kind: "owner"`
|
|
15
|
+
* given `"member"`) says the value is a different member, while any other
|
|
16
|
+
* error says it is this member with a bad field.
|
|
17
|
+
* 2. Fewest errors.
|
|
18
|
+
* 3. Deepest error: the member matched more of the value's structure.
|
|
19
|
+
* 4. Declaration order (an earlier member wins a tie).
|
|
20
|
+
*/
|
|
21
|
+
const isCloser = (candidate, best) => {
|
|
22
|
+
if (candidate.literalMismatches !== best.literalMismatches) return candidate.literalMismatches < best.literalMismatches;
|
|
23
|
+
if (candidate.errors.length !== best.errors.length) return candidate.errors.length < best.errors.length;
|
|
24
|
+
if (candidate.depth !== best.depth) return candidate.depth > best.depth;
|
|
25
|
+
return candidate.index < best.index;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Union rule - value must match at least one of the provided validators.
|
|
29
|
+
*
|
|
30
|
+
* Every member whose type matches the value is tried, in order, until one
|
|
31
|
+
* passes. When none passes, the errors of the closest failed member (see
|
|
32
|
+
* `isCloser`) are reported at their own paths with the `union` type: its
|
|
33
|
+
* first error under `firstErrorOnly` (the default), all of them otherwise.
|
|
34
|
+
* A custom union error message replaces them with a single error, as does the
|
|
35
|
+
* default message when no member matches the value's type.
|
|
7
36
|
*/
|
|
8
37
|
const unionRule = {
|
|
9
38
|
name: "union",
|
|
@@ -13,17 +42,34 @@ const unionRule = {
|
|
|
13
42
|
if (value === void 0) return VALID_RULE;
|
|
14
43
|
const validators = this.context.options.validators;
|
|
15
44
|
const firstErrorOnly = context.configurations?.firstErrorOnly ?? true;
|
|
16
|
-
|
|
17
|
-
for (const validator of validators) {
|
|
45
|
+
let closest;
|
|
46
|
+
for (const [index, validator] of validators.entries()) {
|
|
18
47
|
if (!validator.matchesType(value)) continue;
|
|
19
|
-
const result = await validator.validate(value, context);
|
|
20
|
-
if (result.isValid) return
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
48
|
+
const result = await validator.validate(value, { ...context });
|
|
49
|
+
if (result.isValid) return {
|
|
50
|
+
isValid: true,
|
|
51
|
+
data: result.data
|
|
52
|
+
};
|
|
53
|
+
const failure = describeFailure(index, result.errors?.length ? result.errors : [{
|
|
54
|
+
type: "union",
|
|
55
|
+
error: "Validation failed",
|
|
56
|
+
input: context.path
|
|
57
|
+
}]);
|
|
58
|
+
if (!closest || isCloser(failure, closest)) closest = failure;
|
|
24
59
|
}
|
|
25
|
-
|
|
26
|
-
|
|
60
|
+
const failed = invalidRule(this, context);
|
|
61
|
+
if (!closest || this.context.errorMessage) return failed;
|
|
62
|
+
const errors = (firstErrorOnly ? closest.errors.slice(0, 1) : closest.errors).map((error) => ({
|
|
63
|
+
error: error.error,
|
|
64
|
+
path: error.input
|
|
65
|
+
}));
|
|
66
|
+
const first = errors[0];
|
|
67
|
+
return first ? {
|
|
68
|
+
...failed,
|
|
69
|
+
error: first.error,
|
|
70
|
+
path: first.path,
|
|
71
|
+
errors
|
|
72
|
+
} : failed;
|
|
27
73
|
}
|
|
28
74
|
};
|
|
29
75
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"union.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/union.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule } from \"../../types\";\nimport type { BaseValidator } from \"../../validators/base-validator\";\n\n/**\n * Union rule - value must match at least one of the provided validators\n */\nexport const unionRule: SchemaRule<{ validators: BaseValidator[] }> = {\n name: \"union\",\n // Runs on \"empty\" values too: `v.union([v.literal(\"\"), v.int()]).present()`\n // must still ask its members about `\"\"` instead of accepting it unchecked.\n requiresValue: false,\n defaultErrorMessage: \"Value must match one of the allowed types\",\n async validate(value: any, context) {\n // Absence is the required/present rule's question, as for `literalRule`;\n // answering it here would defeat `.optional()`.\n if (value === undefined) {\n return VALID_RULE;\n }\n\n const validators = this.context.options.validators;\n const firstErrorOnly = context.configurations?.firstErrorOnly ?? true;\n
|
|
1
|
+
{"version":3,"file":"union.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/union.ts"],"sourcesContent":["import { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule, ValidationResult } from \"../../types\";\nimport type { BaseValidator } from \"../../validators/base-validator\";\n\ntype MemberFailure = {\n /** Declaration order of the member, the last tie-breaker. */\n index: number;\n errors: ValidationResult[\"errors\"];\n /** Mismatched literals: each says the value is a different member. */\n literalMismatches: number;\n /** Segments in the deepest error path (`a.b.c` → 3). */\n depth: number;\n};\n\nconst describeFailure = (index: number, errors: ValidationResult[\"errors\"]): MemberFailure => ({\n index,\n errors,\n literalMismatches: errors.filter((error) => error.type === \"literal\").length,\n depth: Math.max(0, ...errors.map((error) => (error.input ? error.input.split(\".\").length : 0))),\n});\n\n/**\n * Whether `candidate` is closer to the value than `best`:\n *\n * 1. Fewest mismatched literals. A literal that does not match (`kind: \"owner\"`\n * given `\"member\"`) says the value is a different member, while any other\n * error says it is this member with a bad field.\n * 2. Fewest errors.\n * 3. Deepest error: the member matched more of the value's structure.\n * 4. Declaration order (an earlier member wins a tie).\n */\nconst isCloser = (candidate: MemberFailure, best: MemberFailure): boolean => {\n if (candidate.literalMismatches !== best.literalMismatches) {\n return candidate.literalMismatches < best.literalMismatches;\n }\n\n if (candidate.errors.length !== best.errors.length) {\n return candidate.errors.length < best.errors.length;\n }\n\n if (candidate.depth !== best.depth) {\n return candidate.depth > best.depth;\n }\n\n return candidate.index < best.index;\n};\n\n/**\n * Union rule - value must match at least one of the provided validators.\n *\n * Every member whose type matches the value is tried, in order, until one\n * passes. When none passes, the errors of the closest failed member (see\n * `isCloser`) are reported at their own paths with the `union` type: its\n * first error under `firstErrorOnly` (the default), all of them otherwise.\n * A custom union error message replaces them with a single error, as does the\n * default message when no member matches the value's type.\n */\nexport const unionRule: SchemaRule<{ validators: BaseValidator[] }> = {\n name: \"union\",\n // Runs on \"empty\" values too: `v.union([v.literal(\"\"), v.int()]).present()`\n // must still ask its members about `\"\"` instead of accepting it unchecked.\n requiresValue: false,\n defaultErrorMessage: \"Value must match one of the allowed types\",\n async validate(value: any, context) {\n // Absence is the required/present rule's question, as for `literalRule`;\n // answering it here would defeat `.optional()`.\n if (value === undefined) {\n return VALID_RULE;\n }\n\n const validators = this.context.options.validators;\n const firstErrorOnly = context.configurations?.firstErrorOnly ?? true;\n let closest: MemberFailure | undefined;\n\n // `firstErrorOnly` limits the errors reported, never the members tried:\n // several object members all match a plain object, and a later one may\n // be the member the value belongs to.\n for (const [index, validator] of validators.entries()) {\n // A member that cannot hold this type of value cannot pass.\n if (!validator.matchesType(value)) {\n continue;\n }\n\n // Each member gets its own context: a member must not see what an\n // earlier member wrote into it (an object member sets `schema`).\n const result = await validator.validate(value, { ...context });\n\n if (result.isValid) {\n // Preserve defaults, computed fields and transformations from the branch.\n return { isValid: true, data: result.data };\n }\n\n const failure = describeFailure(\n index,\n result.errors?.length\n ? result.errors\n : [{ type: \"union\", error: \"Validation failed\", input: context.path }],\n );\n\n if (!closest || isCloser(failure, closest)) {\n closest = failure;\n }\n }\n\n const failed = invalidRule(this, context);\n\n // No member matched the type, or the union has its own message.\n if (!closest || this.context.errorMessage) {\n return failed;\n }\n\n const reported = firstErrorOnly ? closest.errors.slice(0, 1) : closest.errors;\n const errors = reported.map((error) => ({ error: error.error, path: error.input }));\n const first = errors[0];\n\n return first ? { ...failed, error: first.error, path: first.path, errors } : failed;\n },\n};\n"],"mappings":";;;;AAcA,MAAM,mBAAmB,OAAe,YAAuD;CAC7F;CACA;CACA,mBAAmB,OAAO,QAAQ,UAAU,MAAM,SAAS,SAAS,CAAC,CAAC;CACtE,OAAO,KAAK,IAAI,GAAG,GAAG,OAAO,KAAK,UAAW,MAAM,QAAQ,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,CAAE,CAAC;AAChG;;;;;;;;;;;AAYA,MAAM,YAAY,WAA0B,SAAiC;CAC3E,IAAI,UAAU,sBAAsB,KAAK,mBACvC,OAAO,UAAU,oBAAoB,KAAK;CAG5C,IAAI,UAAU,OAAO,WAAW,KAAK,OAAO,QAC1C,OAAO,UAAU,OAAO,SAAS,KAAK,OAAO;CAG/C,IAAI,UAAU,UAAU,KAAK,OAC3B,OAAO,UAAU,QAAQ,KAAK;CAGhC,OAAO,UAAU,QAAQ,KAAK;AAChC;;;;;;;;;;;AAYA,MAAa,YAAyD;CACpE,MAAM;CAGN,eAAe;CACf,qBAAqB;CACrB,MAAM,SAAS,OAAY,SAAS;EAGlC,IAAI,UAAU,QACZ,OAAO;EAGT,MAAM,aAAa,KAAK,QAAQ,QAAQ;EACxC,MAAM,iBAAiB,QAAQ,gBAAgB,kBAAkB;EACjE,IAAI;EAKJ,KAAK,MAAM,CAAC,OAAO,cAAc,WAAW,QAAQ,GAAG;GAErD,IAAI,CAAC,UAAU,YAAY,KAAK,GAC9B;GAKF,MAAM,SAAS,MAAM,UAAU,SAAS,OAAO,EAAE,GAAG,QAAQ,CAAC;GAE7D,IAAI,OAAO,SAET,OAAO;IAAE,SAAS;IAAM,MAAM,OAAO;GAAK;GAG5C,MAAM,UAAU,gBACd,OACA,OAAO,QAAQ,SACX,OAAO,SACP,CAAC;IAAE,MAAM;IAAS,OAAO;IAAqB,OAAO,QAAQ;GAAK,CAAC,CACzE;GAEA,IAAI,CAAC,WAAW,SAAS,SAAS,OAAO,GACvC,UAAU;EAEd;EAEA,MAAM,SAAS,YAAY,MAAM,OAAO;EAGxC,IAAI,CAAC,WAAW,KAAK,QAAQ,cAC3B,OAAO;EAIT,MAAM,UADW,iBAAiB,QAAQ,OAAO,MAAM,GAAG,CAAC,IAAI,QAAQ,OAChD,CAAC,KAAK,WAAW;GAAE,OAAO,MAAM;GAAO,MAAM,MAAM;EAAM,EAAE;EAClF,MAAM,QAAQ,OAAO;EAErB,OAAO,QAAQ;GAAE,GAAG;GAAQ,OAAO,MAAM;GAAO,MAAM,MAAM;GAAM;EAAO,IAAI;CAC/E;AACF"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { SchemaRule } from "../../types/rule-types.mjs";
|
|
2
2
|
import { WhenRuleOptions } from "../../types/conditional-types.mjs";
|
|
3
|
-
|
|
3
|
+
import "../../types/index.mjs";
|
|
4
4
|
//#region ../../packages/seal/src/rules/core/when.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* When rule - conditional validation based on another field value
|
|
7
7
|
*/
|
|
8
|
-
declare const whenRule: SchemaRule<WhenRuleOptions>;
|
|
8
|
+
export declare const whenRule: SchemaRule<WhenRuleOptions>;
|
|
9
9
|
//#endregion
|
|
10
|
-
export { whenRule };
|
|
11
10
|
//# sourceMappingURL=when.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"when.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"mappings":";;;;;;;qBAOa,UAAU,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"when.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule, WhenRuleOptions } from \"../../types\";\n\n/**\n * When rule - conditional validation based on another field value\n */\nexport const whenRule: SchemaRule<WhenRuleOptions> = {\n name: \"when\",\n description: \"Apply conditional validation based on another field value\",\n async validate(value: any, context) {\n const fieldToCheck = this.context.options.field;\n const conditions = this.context.options.is;\n const otherwise = this.context.options.otherwise;\n const scope = this.context.options.scope || \"global\";\n\n const fieldValue =\n scope === \"global\"
|
|
1
|
+
{"version":3,"file":"when.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/core/when.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport type { SchemaRule, WhenRuleOptions } from \"../../types\";\n\n/**\n * When rule - conditional validation based on another field value\n */\nexport const whenRule: SchemaRule<WhenRuleOptions> = {\n name: \"when\",\n description: \"Apply conditional validation based on another field value\",\n async validate(value: any, context) {\n const fieldToCheck = this.context.options.field;\n const conditions = this.context.options.is;\n const otherwise = this.context.options.otherwise;\n const scope = this.context.options.scope || \"global\";\n\n const fieldValue =\n scope === \"global\" ? get(context.allValues, fieldToCheck) : get(context.parent, fieldToCheck);\n\n // Convert field value to string for key lookup\n // This handles boolean, number, and string field values\n const fieldValueKey = String(fieldValue);\n\n if (conditions[fieldValueKey]) {\n const result = await conditions[fieldValueKey].validate(value, context);\n if (result.isValid) {\n return VALID_RULE;\n }\n\n // Safe error access\n this.context.errorMessage = result.errors?.[0]?.error || \"Validation failed\";\n return invalidRule(this, context);\n }\n\n if (otherwise) {\n const result = await otherwise.validate(value, context);\n\n if (result.isValid) {\n return VALID_RULE;\n }\n\n // Safe error access\n this.context.errorMessage = result.errors?.[0]?.error || \"Validation failed\";\n return invalidRule(this, context);\n }\n\n return VALID_RULE;\n },\n};\n"],"mappings":";;;;;;;;AAOA,MAAa,WAAwC;CACnD,MAAM;CACN,aAAa;CACb,MAAM,SAAS,OAAY,SAAS;EAClC,MAAM,eAAe,KAAK,QAAQ,QAAQ;EAC1C,MAAM,aAAa,KAAK,QAAQ,QAAQ;EACxC,MAAM,YAAY,KAAK,QAAQ,QAAQ;EAGvC,MAAM,cAFQ,KAAK,QAAQ,QAAQ,SAAS,cAGhC,WAAW,IAAI,QAAQ,WAAW,YAAY,IAAI,IAAI,QAAQ,QAAQ,YAAY;EAI9F,MAAM,gBAAgB,OAAO,UAAU;EAEvC,IAAI,WAAW,gBAAgB;GAC7B,MAAM,SAAS,MAAM,WAAW,cAAc,CAAC,SAAS,OAAO,OAAO;GACtE,IAAI,OAAO,SACT,OAAO;GAIT,KAAK,QAAQ,eAAe,OAAO,SAAS,EAAE,EAAE,SAAS;GACzD,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,IAAI,WAAW;GACb,MAAM,SAAS,MAAM,UAAU,SAAS,OAAO,OAAO;GAEtD,IAAI,OAAO,SACT,OAAO;GAIT,KAAK,QAAQ,eAAe,OAAO,SAAS,EAAE,EAAE,SAAS;GACzD,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,OAAO;CACT;AACF"}
|
|
@@ -1,29 +1,28 @@
|
|
|
1
1
|
import { SchemaRule } from "../../types/rule-types.mjs";
|
|
2
|
-
|
|
2
|
+
import "../../types/index.mjs";
|
|
3
3
|
//#region ../../packages/seal/src/rules/date/date-comparison-rules.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Between dates rule - date must be between start and end dates
|
|
6
6
|
*/
|
|
7
|
-
declare const betweenDatesRule: SchemaRule<{
|
|
7
|
+
export declare const betweenDatesRule: SchemaRule<{
|
|
8
8
|
startDate: Date;
|
|
9
9
|
endDate: Date;
|
|
10
10
|
}>;
|
|
11
11
|
/**
|
|
12
12
|
* Today rule - date must be exactly today
|
|
13
13
|
*/
|
|
14
|
-
declare const todayRule: SchemaRule;
|
|
14
|
+
export declare const todayRule: SchemaRule;
|
|
15
15
|
/**
|
|
16
16
|
* Past rule - date must be in the past
|
|
17
17
|
*/
|
|
18
|
-
declare const pastRule: SchemaRule;
|
|
18
|
+
export declare const pastRule: SchemaRule;
|
|
19
19
|
/**
|
|
20
20
|
* Future rule - date must be in the future
|
|
21
21
|
*/
|
|
22
|
-
declare const futureRule: SchemaRule;
|
|
22
|
+
export declare const futureRule: SchemaRule;
|
|
23
23
|
/**
|
|
24
24
|
* After today rule - date must be after today (not including today)
|
|
25
25
|
*/
|
|
26
|
-
declare const afterTodayRule: SchemaRule;
|
|
26
|
+
export declare const afterTodayRule: SchemaRule;
|
|
27
27
|
//#endregion
|
|
28
|
-
export { afterTodayRule, betweenDatesRule, futureRule, pastRule, todayRule };
|
|
29
28
|
//# sourceMappingURL=date-comparison-rules.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-comparison-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-comparison-rules.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"date-comparison-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-comparison-rules.ts"],"mappings":";;;;;;qBAMa,kBAAkB;EAC7B,WAAW;EACX,SAAS;;;;;qBAqBE,WAAW;;;;qBAmBX,UAAU;;;;qBAiBV,YAAY;;;;qBAiBZ,gBAAgB"}
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { SchemaRule } from "../../types/rule-types.mjs";
|
|
2
2
|
import { WeekDay } from "../../types/date-types.mjs";
|
|
3
|
-
|
|
3
|
+
import "../../types/index.mjs";
|
|
4
4
|
//#region ../../packages/seal/src/rules/date/date-day-rules.d.ts
|
|
5
5
|
/**
|
|
6
6
|
* Weekend rule - date must be Saturday or Sunday
|
|
7
7
|
*/
|
|
8
|
-
declare const weekendRule: SchemaRule;
|
|
8
|
+
export declare const weekendRule: SchemaRule;
|
|
9
9
|
/**
|
|
10
10
|
* Weekday rule - date must be Monday through Friday
|
|
11
11
|
*/
|
|
12
|
-
declare const weekdayRule: SchemaRule;
|
|
12
|
+
export declare const weekdayRule: SchemaRule;
|
|
13
13
|
/**
|
|
14
14
|
* Weekdays rule - date must be one of specified weekdays
|
|
15
15
|
*/
|
|
16
|
-
declare const weekdaysRule: SchemaRule<{
|
|
16
|
+
export declare const weekdaysRule: SchemaRule<{
|
|
17
17
|
days: WeekDay[];
|
|
18
18
|
}>;
|
|
19
19
|
/**
|
|
20
20
|
* Business day rule - date must be Monday-Friday (no weekends)
|
|
21
21
|
*/
|
|
22
|
-
declare const businessDayRule: SchemaRule;
|
|
22
|
+
export declare const businessDayRule: SchemaRule;
|
|
23
23
|
//#endregion
|
|
24
|
-
export { businessDayRule, weekdayRule, weekdaysRule, weekendRule };
|
|
25
24
|
//# sourceMappingURL=date-day-rules.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-day-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-day-rules.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"date-day-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-day-rules.ts"],"mappings":";;;;;;;qBAQa,aAAa;;;;qBAkBb,aAAa;;;;qBAmBb,cAAc;EAAa,MAAM;;;;;qBAyBjC,iBAAiB"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SchemaRule } from "../../types/rule-types.mjs";
|
|
2
|
-
|
|
2
|
+
import "../../types/index.mjs";
|
|
3
3
|
//#region ../../packages/seal/src/rules/date/date-field-comparison-rules.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Before field rule - date must be < given date or field
|
|
6
6
|
* Smart detection: date value or field name
|
|
7
7
|
* Supports both global and sibling scope
|
|
8
8
|
*/
|
|
9
|
-
declare const beforeFieldRule: SchemaRule<{
|
|
9
|
+
export declare const beforeFieldRule: SchemaRule<{
|
|
10
10
|
dateOrField: Date | string | number;
|
|
11
11
|
scope?: "global" | "sibling";
|
|
12
12
|
}>;
|
|
@@ -15,7 +15,7 @@ declare const beforeFieldRule: SchemaRule<{
|
|
|
15
15
|
* Smart detection: date value or field name
|
|
16
16
|
* Supports both global and sibling scope
|
|
17
17
|
*/
|
|
18
|
-
declare const afterFieldRule: SchemaRule<{
|
|
18
|
+
export declare const afterFieldRule: SchemaRule<{
|
|
19
19
|
dateOrField: Date | string | number;
|
|
20
20
|
scope?: "global" | "sibling";
|
|
21
21
|
}>;
|
|
@@ -23,10 +23,9 @@ declare const afterFieldRule: SchemaRule<{
|
|
|
23
23
|
* Same as field rule - date must be the same as another field's date
|
|
24
24
|
* Supports both global and sibling scope
|
|
25
25
|
*/
|
|
26
|
-
declare const sameAsFieldDateRule: SchemaRule<{
|
|
26
|
+
export declare const sameAsFieldDateRule: SchemaRule<{
|
|
27
27
|
field: string;
|
|
28
28
|
scope?: "global" | "sibling";
|
|
29
29
|
}>;
|
|
30
30
|
//#endregion
|
|
31
|
-
export { afterFieldRule, beforeFieldRule, sameAsFieldDateRule };
|
|
32
31
|
//# sourceMappingURL=date-field-comparison-rules.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field-comparison-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-field-comparison-rules.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"date-field-comparison-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-field-comparison-rules.ts"],"mappings":";;;;;;;;qBAUa,iBAAiB;EAC5B,aAAa;EACb;;;;;;;qBAsCW,gBAAgB;EAC3B,aAAa;EACb;;;;;;qBAwCW,qBAAqB;EAChC;EACA"}
|
|
@@ -18,7 +18,8 @@ const beforeFieldRule = {
|
|
|
18
18
|
let compareDate;
|
|
19
19
|
if (isDateValue(dateOrField)) compareDate = new Date(dateOrField);
|
|
20
20
|
else {
|
|
21
|
-
const
|
|
21
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
22
|
+
const fieldValue = get(source, dateOrField);
|
|
22
23
|
if (fieldValue === void 0) return VALID_RULE;
|
|
23
24
|
compareDate = new Date(fieldValue);
|
|
24
25
|
}
|
|
@@ -42,7 +43,8 @@ const afterFieldRule = {
|
|
|
42
43
|
compareDate = new Date(dateOrField);
|
|
43
44
|
this.context.translationParams.dateOrField = compareDate.toISOString();
|
|
44
45
|
} else {
|
|
45
|
-
const
|
|
46
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
47
|
+
const fieldValue = get(source, dateOrField);
|
|
46
48
|
if (fieldValue === void 0) return VALID_RULE;
|
|
47
49
|
compareDate = new Date(fieldValue);
|
|
48
50
|
this.context.translatableParams.dateOrField = fieldValue;
|
|
@@ -61,7 +63,8 @@ const sameAsFieldDateRule = {
|
|
|
61
63
|
defaultErrorMessage: "The :input must be the same as :field",
|
|
62
64
|
async validate(value, context) {
|
|
63
65
|
const { field, scope = "global" } = this.context.options;
|
|
64
|
-
const
|
|
66
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
67
|
+
const fieldValue = get(source, field);
|
|
65
68
|
if (fieldValue === void 0 || value === void 0) {
|
|
66
69
|
this.context.translatableParams.field = fieldValue;
|
|
67
70
|
return invalidRule(this, context);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-field-comparison-rules.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-field-comparison-rules.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport { isDateValue } from \"../../helpers/date-helpers\";\nimport type { SchemaRule } from \"../../types\";\n\n/**\n * Before field rule - date must be < given date or field\n * Smart detection: date value or field name\n * Supports both global and sibling scope\n */\nexport const beforeFieldRule: SchemaRule<{\n dateOrField: Date | string | number;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"beforeField\",\n description: \"The date must be before the given date or field\",\n defaultErrorMessage: \"The :input must be before :dateOrField\",\n async validate(value: Date, context) {\n const { dateOrField, scope = \"global\" } = this.context.options;\n let compareDate: Date;\n\n if (isDateValue(dateOrField)) {\n // Value comparison\n compareDate = new Date(dateOrField);\n } else {\n // Field comparison\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, dateOrField as string);\n\n if (fieldValue === undefined) {\n return VALID_RULE;\n }\n\n compareDate = new Date(fieldValue);\n }\n\n const inputDate = new Date(value);\n\n if (inputDate < compareDate) {\n return VALID_RULE;\n }\n return invalidRule(this, context);\n },\n};\n\n/**\n * After field rule - date must be > given date or field\n * Smart detection: date value or field name\n * Supports both global and sibling scope\n */\nexport const afterFieldRule: SchemaRule<{\n dateOrField: Date | string | number;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"afterField\",\n description: \"The date must be after the given date or field\",\n defaultErrorMessage: \"The :input must be after :dateOrField\",\n async validate(value: Date, context) {\n const { dateOrField, scope = \"global\" } = this.context.options;\n let compareDate: Date;\n\n if (isDateValue(dateOrField)) {\n // Value comparison\n compareDate = new Date(dateOrField);\n this.context.translationParams.dateOrField = compareDate.toISOString();\n } else {\n // Field comparison\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, dateOrField as string);\n\n if (fieldValue === undefined) {\n return VALID_RULE;\n }\n\n compareDate = new Date(fieldValue);\n this.context.translatableParams.dateOrField = fieldValue;\n }\n\n const inputDate = new Date(value);\n\n if (inputDate > compareDate) {\n return VALID_RULE;\n }\n\n return invalidRule(this, context);\n },\n};\n\n/**\n * Same as field rule - date must be the same as another field's date\n * Supports both global and sibling scope\n */\nexport const sameAsFieldDateRule: SchemaRule<{\n field: string;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"sameAsFieldDate\",\n description: \"The date must be the same as another field's date\",\n defaultErrorMessage: \"The :input must be the same as :field\",\n async validate(value: Date, context) {\n const { field, scope = \"global\" } = this.context.options;\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, field);\n\n // Both fields must exist to be considered \"the same\"\n if (fieldValue === undefined || value === undefined) {\n this.context.translatableParams.field = fieldValue;\n return invalidRule(this, context);\n }\n\n const inputDate = new Date(value);\n inputDate.setHours(0, 0, 0, 0);\n const compareDate = new Date(fieldValue);\n compareDate.setHours(0, 0, 0, 0);\n\n if (inputDate.getTime() === compareDate.getTime()) {\n return VALID_RULE;\n }\n\n this.context.translatableParams.field = fieldValue;\n return invalidRule(this, context);\n },\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,kBAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;
|
|
1
|
+
{"version":3,"file":"date-field-comparison-rules.mjs","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-field-comparison-rules.ts"],"sourcesContent":["import { get } from \"@mongez/reinforcements\";\nimport { invalidRule, VALID_RULE } from \"../../helpers\";\nimport { isDateValue } from \"../../helpers/date-helpers\";\nimport type { SchemaRule } from \"../../types\";\n\n/**\n * Before field rule - date must be < given date or field\n * Smart detection: date value or field name\n * Supports both global and sibling scope\n */\nexport const beforeFieldRule: SchemaRule<{\n dateOrField: Date | string | number;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"beforeField\",\n description: \"The date must be before the given date or field\",\n defaultErrorMessage: \"The :input must be before :dateOrField\",\n async validate(value: Date, context) {\n const { dateOrField, scope = \"global\" } = this.context.options;\n let compareDate: Date;\n\n if (isDateValue(dateOrField)) {\n // Value comparison\n compareDate = new Date(dateOrField);\n } else {\n // Field comparison\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, dateOrField as string);\n\n if (fieldValue === undefined) {\n return VALID_RULE;\n }\n\n compareDate = new Date(fieldValue);\n }\n\n const inputDate = new Date(value);\n\n if (inputDate < compareDate) {\n return VALID_RULE;\n }\n return invalidRule(this, context);\n },\n};\n\n/**\n * After field rule - date must be > given date or field\n * Smart detection: date value or field name\n * Supports both global and sibling scope\n */\nexport const afterFieldRule: SchemaRule<{\n dateOrField: Date | string | number;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"afterField\",\n description: \"The date must be after the given date or field\",\n defaultErrorMessage: \"The :input must be after :dateOrField\",\n async validate(value: Date, context) {\n const { dateOrField, scope = \"global\" } = this.context.options;\n let compareDate: Date;\n\n if (isDateValue(dateOrField)) {\n // Value comparison\n compareDate = new Date(dateOrField);\n this.context.translationParams.dateOrField = compareDate.toISOString();\n } else {\n // Field comparison\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, dateOrField as string);\n\n if (fieldValue === undefined) {\n return VALID_RULE;\n }\n\n compareDate = new Date(fieldValue);\n this.context.translatableParams.dateOrField = fieldValue;\n }\n\n const inputDate = new Date(value);\n\n if (inputDate > compareDate) {\n return VALID_RULE;\n }\n\n return invalidRule(this, context);\n },\n};\n\n/**\n * Same as field rule - date must be the same as another field's date\n * Supports both global and sibling scope\n */\nexport const sameAsFieldDateRule: SchemaRule<{\n field: string;\n scope?: \"global\" | \"sibling\";\n}> = {\n name: \"sameAsFieldDate\",\n description: \"The date must be the same as another field's date\",\n defaultErrorMessage: \"The :input must be the same as :field\",\n async validate(value: Date, context) {\n const { field, scope = \"global\" } = this.context.options;\n const source = scope === \"sibling\" ? context.parent : context.allValues;\n const fieldValue = get(source, field);\n\n // Both fields must exist to be considered \"the same\"\n if (fieldValue === undefined || value === undefined) {\n this.context.translatableParams.field = fieldValue;\n return invalidRule(this, context);\n }\n\n const inputDate = new Date(value);\n inputDate.setHours(0, 0, 0, 0);\n const compareDate = new Date(fieldValue);\n compareDate.setHours(0, 0, 0, 0);\n\n if (inputDate.getTime() === compareDate.getTime()) {\n return VALID_RULE;\n }\n\n this.context.translatableParams.field = fieldValue;\n return invalidRule(this, context);\n },\n};\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,kBAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAEzB,cAAc,IAAI,KAAK,WAAW;OAC7B;GAEL,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;GAC9D,MAAM,aAAa,IAAI,QAAQ,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;EACnC;EAIA,IAAI,IAFkB,KAAK,KAEf,IAAI,aACd,OAAO;EAET,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;;AAOA,MAAa,iBAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,aAAa,QAAQ,aAAa,KAAK,QAAQ;EACvD,IAAI;EAEJ,IAAI,YAAY,WAAW,GAAG;GAE5B,cAAc,IAAI,KAAK,WAAW;GAClC,KAAK,QAAQ,kBAAkB,cAAc,YAAY,YAAY;EACvE,OAAO;GAEL,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;GAC9D,MAAM,aAAa,IAAI,QAAQ,WAAqB;GAEpD,IAAI,eAAe,QACjB,OAAO;GAGT,cAAc,IAAI,KAAK,UAAU;GACjC,KAAK,QAAQ,mBAAmB,cAAc;EAChD;EAIA,IAAI,IAFkB,KAAK,KAEf,IAAI,aACd,OAAO;EAGT,OAAO,YAAY,MAAM,OAAO;CAClC;AACF;;;;;AAMA,MAAa,sBAGR;CACH,MAAM;CACN,aAAa;CACb,qBAAqB;CACrB,MAAM,SAAS,OAAa,SAAS;EACnC,MAAM,EAAE,OAAO,QAAQ,aAAa,KAAK,QAAQ;EACjD,MAAM,SAAS,UAAU,YAAY,QAAQ,SAAS,QAAQ;EAC9D,MAAM,aAAa,IAAI,QAAQ,KAAK;EAGpC,IAAI,eAAe,UAAa,UAAU,QAAW;GACnD,KAAK,QAAQ,mBAAmB,QAAQ;GACxC,OAAO,YAAY,MAAM,OAAO;EAClC;EAEA,MAAM,YAAY,IAAI,KAAK,KAAK;EAChC,UAAU,SAAS,GAAG,GAAG,GAAG,CAAC;EAC7B,MAAM,cAAc,IAAI,KAAK,UAAU;EACvC,YAAY,SAAS,GAAG,GAAG,GAAG,CAAC;EAE/B,IAAI,UAAU,QAAQ,MAAM,YAAY,QAAQ,GAC9C,OAAO;EAGT,KAAK,QAAQ,mBAAmB,QAAQ;EACxC,OAAO,YAAY,MAAM,OAAO;CAClC;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaRule } from "../../types/rule-types.mjs";
|
|
2
|
-
|
|
2
|
+
import "../../types/index.mjs";
|
|
3
3
|
//#region ../../packages/seal/src/rules/date/date-period-rules.d.ts
|
|
4
4
|
declare const MONTHS: {
|
|
5
5
|
1: string;
|
|
@@ -15,24 +15,24 @@ declare const MONTHS: {
|
|
|
15
15
|
11: string;
|
|
16
16
|
12: string;
|
|
17
17
|
};
|
|
18
|
-
type Month = keyof typeof MONTHS;
|
|
18
|
+
export type Month = keyof typeof MONTHS;
|
|
19
19
|
/**
|
|
20
20
|
* Month rule - date must be in specific month (1-12)
|
|
21
21
|
*/
|
|
22
|
-
declare const monthRule: SchemaRule<{
|
|
22
|
+
export declare const monthRule: SchemaRule<{
|
|
23
23
|
month: Month;
|
|
24
24
|
}>;
|
|
25
25
|
/**
|
|
26
26
|
* Year rule - date must be in specific year
|
|
27
27
|
*/
|
|
28
|
-
declare const yearRule: SchemaRule<{
|
|
28
|
+
export declare const yearRule: SchemaRule<{
|
|
29
29
|
year: number;
|
|
30
30
|
}>;
|
|
31
31
|
/**
|
|
32
32
|
* Between years rule - date must be between start and end years
|
|
33
33
|
* Supports field names with sibling scope
|
|
34
34
|
*/
|
|
35
|
-
declare const betweenYearsRule: SchemaRule<{
|
|
35
|
+
export declare const betweenYearsRule: SchemaRule<{
|
|
36
36
|
startYear: number | string;
|
|
37
37
|
endYear: number | string;
|
|
38
38
|
scope?: "global" | "sibling";
|
|
@@ -41,7 +41,7 @@ declare const betweenYearsRule: SchemaRule<{
|
|
|
41
41
|
* Between months rule - date must be between start and end months (1-12)
|
|
42
42
|
* Supports field names with sibling scope
|
|
43
43
|
*/
|
|
44
|
-
declare const betweenMonthsRule: SchemaRule<{
|
|
44
|
+
export declare const betweenMonthsRule: SchemaRule<{
|
|
45
45
|
startMonth: Month | string;
|
|
46
46
|
endMonth: Month | string;
|
|
47
47
|
scope?: "global" | "sibling";
|
|
@@ -50,7 +50,7 @@ declare const betweenMonthsRule: SchemaRule<{
|
|
|
50
50
|
* Between days rule - date must be between start and end days (1-31)
|
|
51
51
|
* Supports field names with sibling scope
|
|
52
52
|
*/
|
|
53
|
-
declare const betweenDaysRule: SchemaRule<{
|
|
53
|
+
export declare const betweenDaysRule: SchemaRule<{
|
|
54
54
|
startDay: number | string;
|
|
55
55
|
endDay: number | string;
|
|
56
56
|
scope?: "global" | "sibling";
|
|
@@ -58,13 +58,13 @@ declare const betweenDaysRule: SchemaRule<{
|
|
|
58
58
|
/**
|
|
59
59
|
* Quarter rule - date must be in specific quarter (1-4)
|
|
60
60
|
*/
|
|
61
|
-
declare const quarterRule: SchemaRule<{
|
|
61
|
+
export declare const quarterRule: SchemaRule<{
|
|
62
62
|
quarter: 1 | 2 | 3 | 4;
|
|
63
63
|
}>;
|
|
64
64
|
/**
|
|
65
65
|
* Between times rule - time must be between start and end times (HH:MM format)
|
|
66
66
|
*/
|
|
67
|
-
declare const betweenTimesRule: SchemaRule<{
|
|
67
|
+
export declare const betweenTimesRule: SchemaRule<{
|
|
68
68
|
startTime: string;
|
|
69
69
|
endTime: string;
|
|
70
70
|
}>;
|
|
@@ -73,7 +73,7 @@ declare const betweenTimesRule: SchemaRule<{
|
|
|
73
73
|
* Smart detection: number or field name
|
|
74
74
|
* Supports both global and sibling scope
|
|
75
75
|
*/
|
|
76
|
-
declare const minYearRule: SchemaRule<{
|
|
76
|
+
export declare const minYearRule: SchemaRule<{
|
|
77
77
|
yearOrField: number | string;
|
|
78
78
|
scope?: "global" | "sibling";
|
|
79
79
|
}>;
|
|
@@ -82,7 +82,7 @@ declare const minYearRule: SchemaRule<{
|
|
|
82
82
|
* Smart detection: number or field name
|
|
83
83
|
* Supports both global and sibling scope
|
|
84
84
|
*/
|
|
85
|
-
declare const maxYearRule: SchemaRule<{
|
|
85
|
+
export declare const maxYearRule: SchemaRule<{
|
|
86
86
|
yearOrField: number | string;
|
|
87
87
|
scope?: "global" | "sibling";
|
|
88
88
|
}>;
|
|
@@ -91,7 +91,7 @@ declare const maxYearRule: SchemaRule<{
|
|
|
91
91
|
* Smart detection: number or field name
|
|
92
92
|
* Supports both global and sibling scope
|
|
93
93
|
*/
|
|
94
|
-
declare const minMonthRule: SchemaRule<{
|
|
94
|
+
export declare const minMonthRule: SchemaRule<{
|
|
95
95
|
monthOrField: number | string;
|
|
96
96
|
scope?: "global" | "sibling";
|
|
97
97
|
}>;
|
|
@@ -100,7 +100,7 @@ declare const minMonthRule: SchemaRule<{
|
|
|
100
100
|
* Smart detection: number or field name
|
|
101
101
|
* Supports both global and sibling scope
|
|
102
102
|
*/
|
|
103
|
-
declare const maxMonthRule: SchemaRule<{
|
|
103
|
+
export declare const maxMonthRule: SchemaRule<{
|
|
104
104
|
monthOrField: Month | string;
|
|
105
105
|
scope?: "global" | "sibling";
|
|
106
106
|
}>;
|
|
@@ -109,7 +109,7 @@ declare const maxMonthRule: SchemaRule<{
|
|
|
109
109
|
* Smart detection: number or field name
|
|
110
110
|
* Supports both global and sibling scope
|
|
111
111
|
*/
|
|
112
|
-
declare const minDayRule: SchemaRule<{
|
|
112
|
+
export declare const minDayRule: SchemaRule<{
|
|
113
113
|
dayOrField: number | string;
|
|
114
114
|
scope?: "global" | "sibling";
|
|
115
115
|
}>;
|
|
@@ -118,10 +118,10 @@ declare const minDayRule: SchemaRule<{
|
|
|
118
118
|
* Smart detection: number or field name
|
|
119
119
|
* Supports both global and sibling scope
|
|
120
120
|
*/
|
|
121
|
-
declare const maxDayRule: SchemaRule<{
|
|
121
|
+
export declare const maxDayRule: SchemaRule<{
|
|
122
122
|
dayOrField: number | string;
|
|
123
123
|
scope?: "global" | "sibling";
|
|
124
124
|
}>;
|
|
125
125
|
//#endregion
|
|
126
|
-
export {
|
|
126
|
+
export {};
|
|
127
127
|
//# sourceMappingURL=date-period-rules.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date-period-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-period-rules.ts"],"mappings":";;;cAIM
|
|
1
|
+
{"version":3,"file":"date-period-rules.d.mts","names":[],"sources":["../../../../../../../../../packages/seal/src/rules/date/date-period-rules.ts"],"mappings":";;;cAIM;EACJ;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,qBAAqB;;;;qBAKpB,WAAW;EAAa,OAAO;;;;;qBAoB/B,UAAU;EAAa;;;;;;qBAoBvB,kBAAkB;EAC7B;EACA;EACA;;;;;;qBA2EW,mBAAmB;EAC9B,YAAY;EACZ,UAAU;EACV;;;;;;qBA+EW,iBAAiB;EAC5B;EACA;EACA;;;;;qBA0EW,aAAa;EAAa;;;;;qBAoB1B,kBAAkB;EAC7B;EACA;;;;;;;qBAyCW,aAAa;EACxB;EACA;;;;;;;qBAsDW,aAAa;EACxB;EACA;;;;;;;qBAsDW,cAAc;EACzB;EACA;;;;;;;qBAqDW,cAAc;EACzB,cAAc;EACd;;;;;;;qBAsDW,YAAY;EACvB;EACA;;;;;;;qBAqDW,YAAY;EACvB;EACA"}
|
|
@@ -54,7 +54,8 @@ const betweenYearsRule = {
|
|
|
54
54
|
let compareStartYear;
|
|
55
55
|
if (typeof startYear === "number") compareStartYear = startYear;
|
|
56
56
|
else {
|
|
57
|
-
const
|
|
57
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
58
|
+
const fieldValue = get(source, startYear);
|
|
58
59
|
if (fieldValue === void 0) return VALID_RULE;
|
|
59
60
|
if (fieldValue instanceof Date) compareStartYear = fieldValue.getFullYear();
|
|
60
61
|
else if (typeof fieldValue === "number") compareStartYear = fieldValue;
|
|
@@ -67,7 +68,8 @@ const betweenYearsRule = {
|
|
|
67
68
|
let compareEndYear;
|
|
68
69
|
if (typeof endYear === "number") compareEndYear = endYear;
|
|
69
70
|
else {
|
|
70
|
-
const
|
|
71
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
72
|
+
const fieldValue = get(source, endYear);
|
|
71
73
|
if (fieldValue === void 0) return VALID_RULE;
|
|
72
74
|
if (fieldValue instanceof Date) compareEndYear = fieldValue.getFullYear();
|
|
73
75
|
else if (typeof fieldValue === "number") compareEndYear = fieldValue;
|
|
@@ -98,7 +100,8 @@ const betweenMonthsRule = {
|
|
|
98
100
|
compareStartMonth = startMonth;
|
|
99
101
|
this.context.translatableParams.startMonth = MONTHS[compareStartMonth];
|
|
100
102
|
} else {
|
|
101
|
-
const
|
|
103
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
104
|
+
const fieldValue = get(source, startMonth);
|
|
102
105
|
if (fieldValue === void 0) return VALID_RULE;
|
|
103
106
|
this.context.translatableParams.startMonth = startMonth;
|
|
104
107
|
if (fieldValue instanceof Date) compareStartMonth = fieldValue.getMonth() + 1;
|
|
@@ -114,7 +117,8 @@ const betweenMonthsRule = {
|
|
|
114
117
|
compareEndMonth = endMonth;
|
|
115
118
|
this.context.translatableParams.endMonth = MONTHS[compareEndMonth];
|
|
116
119
|
} else {
|
|
117
|
-
const
|
|
120
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
121
|
+
const fieldValue = get(source, endMonth);
|
|
118
122
|
if (fieldValue === void 0) return VALID_RULE;
|
|
119
123
|
this.context.translatableParams.endMonth = endMonth;
|
|
120
124
|
if (fieldValue instanceof Date) compareEndMonth = fieldValue.getMonth() + 1;
|
|
@@ -142,7 +146,8 @@ const betweenDaysRule = {
|
|
|
142
146
|
let compareStartDay;
|
|
143
147
|
if (typeof startDay === "number") compareStartDay = startDay;
|
|
144
148
|
else {
|
|
145
|
-
const
|
|
149
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
150
|
+
const fieldValue = get(source, startDay);
|
|
146
151
|
if (fieldValue === void 0) return VALID_RULE;
|
|
147
152
|
if (fieldValue instanceof Date) compareStartDay = fieldValue.getDate();
|
|
148
153
|
else if (typeof fieldValue === "number") compareStartDay = fieldValue;
|
|
@@ -155,7 +160,8 @@ const betweenDaysRule = {
|
|
|
155
160
|
let compareEndDay;
|
|
156
161
|
if (typeof endDay === "number") compareEndDay = endDay;
|
|
157
162
|
else {
|
|
158
|
-
const
|
|
163
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
164
|
+
const fieldValue = get(source, endDay);
|
|
159
165
|
if (fieldValue === void 0) return VALID_RULE;
|
|
160
166
|
if (fieldValue instanceof Date) compareEndDay = fieldValue.getDate();
|
|
161
167
|
else if (typeof fieldValue === "number") compareEndDay = fieldValue;
|
|
@@ -224,7 +230,8 @@ const minYearRule = {
|
|
|
224
230
|
compareYear = yearOrField;
|
|
225
231
|
this.context.translationParams.yearOrField = yearOrField;
|
|
226
232
|
} else {
|
|
227
|
-
const
|
|
233
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
234
|
+
const fieldValue = get(source, yearOrField);
|
|
228
235
|
if (fieldValue === void 0) return VALID_RULE;
|
|
229
236
|
this.context.translatableParams.yearOrField = yearOrField;
|
|
230
237
|
if (fieldValue instanceof Date) compareYear = fieldValue.getFullYear();
|
|
@@ -255,7 +262,8 @@ const maxYearRule = {
|
|
|
255
262
|
compareYear = yearOrField;
|
|
256
263
|
this.context.translationParams.yearOrField = compareYear;
|
|
257
264
|
} else {
|
|
258
|
-
const
|
|
265
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
266
|
+
const fieldValue = get(source, yearOrField);
|
|
259
267
|
if (fieldValue === void 0) return VALID_RULE;
|
|
260
268
|
this.context.translatableParams.yearOrField = yearOrField;
|
|
261
269
|
if (fieldValue instanceof Date) compareYear = fieldValue.getFullYear();
|
|
@@ -286,7 +294,8 @@ const minMonthRule = {
|
|
|
286
294
|
compareMonth = monthOrField;
|
|
287
295
|
this.context.translationParams.monthOrField = compareMonth;
|
|
288
296
|
} else {
|
|
289
|
-
const
|
|
297
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
298
|
+
const fieldValue = get(source, monthOrField);
|
|
290
299
|
if (fieldValue === void 0) return VALID_RULE;
|
|
291
300
|
this.context.translatableParams.monthOrField = monthOrField;
|
|
292
301
|
if (fieldValue instanceof Date) compareMonth = fieldValue.getMonth() + 1;
|
|
@@ -317,7 +326,8 @@ const maxMonthRule = {
|
|
|
317
326
|
compareMonth = monthOrField;
|
|
318
327
|
this.context.translatableParams.monthOrField = MONTHS[monthOrField];
|
|
319
328
|
} else {
|
|
320
|
-
const
|
|
329
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
330
|
+
const fieldValue = get(source, monthOrField);
|
|
321
331
|
if (fieldValue === void 0) return VALID_RULE;
|
|
322
332
|
this.context.translatableParams.monthOrField = monthOrField;
|
|
323
333
|
if (fieldValue instanceof Date) compareMonth = fieldValue.getMonth() + 1;
|
|
@@ -348,7 +358,8 @@ const minDayRule = {
|
|
|
348
358
|
compareDay = dayOrField;
|
|
349
359
|
this.context.translationParams.dayOrField = dayOrField;
|
|
350
360
|
} else {
|
|
351
|
-
const
|
|
361
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
362
|
+
const fieldValue = get(source, dayOrField);
|
|
352
363
|
if (fieldValue === void 0) return VALID_RULE;
|
|
353
364
|
this.context.translatableParams.dayOrField = dayOrField;
|
|
354
365
|
if (fieldValue instanceof Date) compareDay = fieldValue.getDate();
|
|
@@ -379,7 +390,8 @@ const maxDayRule = {
|
|
|
379
390
|
compareDay = dayOrField;
|
|
380
391
|
this.context.translationParams.dayOrField = dayOrField;
|
|
381
392
|
} else {
|
|
382
|
-
const
|
|
393
|
+
const source = scope === "sibling" ? context.parent : context.allValues;
|
|
394
|
+
const fieldValue = get(source, dayOrField);
|
|
383
395
|
if (fieldValue === void 0) return VALID_RULE;
|
|
384
396
|
this.context.translatableParams.dayOrField = dayOrField;
|
|
385
397
|
if (fieldValue instanceof Date) compareDay = fieldValue.getDate();
|