@warlock.js/seal 4.0.31 → 4.0.39
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/index.js +2 -1
- package/cjs/index.js.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/package.json +36 -48
- package/cjs/config.d.ts +0 -48
- package/cjs/config.d.ts.map +0 -1
- package/cjs/config.js +0 -42
- package/cjs/config.js.map +0 -1
- package/cjs/factory/index.d.ts +0 -3
- package/cjs/factory/index.d.ts.map +0 -1
- package/cjs/factory/validate.d.ts +0 -8
- package/cjs/factory/validate.d.ts.map +0 -1
- package/cjs/factory/validate.js +0 -21
- package/cjs/factory/validate.js.map +0 -1
- package/cjs/factory/validators.d.ts +0 -36
- package/cjs/factory/validators.d.ts.map +0 -1
- package/cjs/factory/validators.js +0 -39
- package/cjs/factory/validators.js.map +0 -1
- package/cjs/helpers/date-helpers.d.ts +0 -16
- package/cjs/helpers/date-helpers.d.ts.map +0 -1
- package/cjs/helpers/date-helpers.js +0 -20
- package/cjs/helpers/date-helpers.js.map +0 -1
- package/cjs/helpers/get-field-value.d.ts +0 -37
- package/cjs/helpers/get-field-value.d.ts.map +0 -1
- package/cjs/helpers/get-field-value.js +0 -40
- package/cjs/helpers/get-field-value.js.map +0 -1
- package/cjs/helpers/index.d.ts +0 -5
- package/cjs/helpers/index.d.ts.map +0 -1
- package/cjs/helpers/path-helpers.d.ts +0 -5
- package/cjs/helpers/path-helpers.d.ts.map +0 -1
- package/cjs/helpers/path-helpers.js +0 -8
- package/cjs/helpers/path-helpers.js.map +0 -1
- package/cjs/helpers/validation-helpers.d.ts +0 -4
- package/cjs/helpers/validation-helpers.d.ts.map +0 -1
- package/cjs/helpers/validation-helpers.js +0 -48
- package/cjs/helpers/validation-helpers.js.map +0 -1
- package/cjs/index.d.ts +0 -29
- package/cjs/index.d.ts.map +0 -1
- package/cjs/mutators/array-mutators.d.ts +0 -12
- package/cjs/mutators/array-mutators.d.ts.map +0 -1
- package/cjs/mutators/array-mutators.js +0 -37
- package/cjs/mutators/array-mutators.js.map +0 -1
- package/cjs/mutators/date-mutators.d.ts +0 -39
- package/cjs/mutators/date-mutators.d.ts.map +0 -1
- package/cjs/mutators/date-mutators.js +0 -120
- package/cjs/mutators/date-mutators.js.map +0 -1
- package/cjs/mutators/index.d.ts +0 -7
- package/cjs/mutators/index.d.ts.map +0 -1
- package/cjs/mutators/number-mutators.d.ts +0 -9
- package/cjs/mutators/number-mutators.d.ts.map +0 -1
- package/cjs/mutators/number-mutators.js +0 -23
- package/cjs/mutators/number-mutators.js.map +0 -1
- package/cjs/mutators/object-mutators.d.ts +0 -8
- package/cjs/mutators/object-mutators.d.ts.map +0 -1
- package/cjs/mutators/object-mutators.js +0 -50
- package/cjs/mutators/object-mutators.js.map +0 -1
- package/cjs/mutators/scalar-mutators.d.ts +0 -3
- package/cjs/mutators/scalar-mutators.d.ts.map +0 -1
- package/cjs/mutators/scalar-mutators.js +0 -6
- package/cjs/mutators/scalar-mutators.js.map +0 -1
- package/cjs/mutators/string-mutators.d.ts +0 -72
- package/cjs/mutators/string-mutators.d.ts.map +0 -1
- package/cjs/mutators/string-mutators.js +0 -193
- package/cjs/mutators/string-mutators.js.map +0 -1
- package/cjs/plugins/index.d.ts +0 -7
- package/cjs/plugins/index.d.ts.map +0 -1
- package/cjs/plugins/plugin-system.d.ts +0 -71
- package/cjs/plugins/plugin-system.d.ts.map +0 -1
- package/cjs/plugins/plugin-system.js +0 -68
- package/cjs/plugins/plugin-system.js.map +0 -1
- package/cjs/rules/array/array-rules.d.ts +0 -12
- package/cjs/rules/array/array-rules.d.ts.map +0 -1
- package/cjs/rules/array/array-rules.js +0 -44
- package/cjs/rules/array/array-rules.js.map +0 -1
- package/cjs/rules/array/index.d.ts +0 -2
- package/cjs/rules/array/index.d.ts.map +0 -1
- package/cjs/rules/color/color-rules.d.ts +0 -30
- package/cjs/rules/color/color-rules.d.ts.map +0 -1
- package/cjs/rules/color/color-rules.js +0 -120
- package/cjs/rules/color/color-rules.js.map +0 -1
- package/cjs/rules/color/index.d.ts +0 -2
- package/cjs/rules/color/index.d.ts.map +0 -1
- package/cjs/rules/common/enum.d.ts +0 -26
- package/cjs/rules/common/enum.d.ts.map +0 -1
- package/cjs/rules/common/enum.js +0 -55
- package/cjs/rules/common/enum.js.map +0 -1
- package/cjs/rules/common/equals-field-rules.d.ts +0 -18
- package/cjs/rules/common/equals-field-rules.d.ts.map +0 -1
- package/cjs/rules/common/equals-field-rules.js +0 -38
- package/cjs/rules/common/equals-field-rules.js.map +0 -1
- package/cjs/rules/common/index.d.ts +0 -5
- package/cjs/rules/common/index.d.ts.map +0 -1
- package/cjs/rules/common/type-rules.d.ts +0 -34
- package/cjs/rules/common/type-rules.d.ts.map +0 -1
- package/cjs/rules/common/type-rules.js +0 -104
- package/cjs/rules/common/type-rules.js.map +0 -1
- package/cjs/rules/common/unknown-key.d.ts +0 -9
- package/cjs/rules/common/unknown-key.d.ts.map +0 -1
- package/cjs/rules/common/unknown-key.js +0 -20
- package/cjs/rules/common/unknown-key.js.map +0 -1
- package/cjs/rules/conditional/forbidden-if-rules.d.ts +0 -54
- package/cjs/rules/conditional/forbidden-if-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/forbidden-if-rules.js +0 -112
- package/cjs/rules/conditional/forbidden-if-rules.js.map +0 -1
- package/cjs/rules/conditional/index.d.ts +0 -10
- package/cjs/rules/conditional/index.d.ts.map +0 -1
- package/cjs/rules/conditional/present-if-rules.d.ts +0 -45
- package/cjs/rules/conditional/present-if-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/present-if-rules.js +0 -98
- package/cjs/rules/conditional/present-if-rules.js.map +0 -1
- package/cjs/rules/conditional/present-unless-rules.d.ts +0 -11
- package/cjs/rules/conditional/present-unless-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/present-unless-rules.js +0 -20
- package/cjs/rules/conditional/present-unless-rules.js.map +0 -1
- package/cjs/rules/conditional/present-with-rules.d.ts +0 -26
- package/cjs/rules/conditional/present-with-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/present-with-rules.js +0 -63
- package/cjs/rules/conditional/present-with-rules.js.map +0 -1
- package/cjs/rules/conditional/present-without-rules.d.ts +0 -26
- package/cjs/rules/conditional/present-without-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/present-without-rules.js +0 -63
- package/cjs/rules/conditional/present-without-rules.js.map +0 -1
- package/cjs/rules/conditional/required-if-rules.d.ts +0 -45
- package/cjs/rules/conditional/required-if-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/required-if-rules.js +0 -98
- package/cjs/rules/conditional/required-if-rules.js.map +0 -1
- package/cjs/rules/conditional/required-unless-rules.d.ts +0 -11
- package/cjs/rules/conditional/required-unless-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/required-unless-rules.js +0 -20
- package/cjs/rules/conditional/required-unless-rules.js.map +0 -1
- package/cjs/rules/conditional/required-with-rules.d.ts +0 -26
- package/cjs/rules/conditional/required-with-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/required-with-rules.js +0 -63
- package/cjs/rules/conditional/required-with-rules.js.map +0 -1
- package/cjs/rules/conditional/required-without-rules.d.ts +0 -26
- package/cjs/rules/conditional/required-without-rules.d.ts.map +0 -1
- package/cjs/rules/conditional/required-without-rules.js +0 -63
- package/cjs/rules/conditional/required-without-rules.js.map +0 -1
- package/cjs/rules/core/equal.d.ts +0 -8
- package/cjs/rules/core/equal.d.ts.map +0 -1
- package/cjs/rules/core/equal.js +0 -13
- package/cjs/rules/core/equal.js.map +0 -1
- package/cjs/rules/core/forbidden.d.ts +0 -6
- package/cjs/rules/core/forbidden.d.ts.map +0 -1
- package/cjs/rules/core/forbidden.js +0 -13
- package/cjs/rules/core/forbidden.js.map +0 -1
- package/cjs/rules/core/index.d.ts +0 -6
- package/cjs/rules/core/index.d.ts.map +0 -1
- package/cjs/rules/core/required.d.ts +0 -11
- package/cjs/rules/core/required.d.ts.map +0 -1
- package/cjs/rules/core/required.js +0 -31
- package/cjs/rules/core/required.js.map +0 -1
- package/cjs/rules/core/union.d.ts +0 -9
- package/cjs/rules/core/union.d.ts.map +0 -1
- package/cjs/rules/core/union.js +0 -40
- package/cjs/rules/core/union.js.map +0 -1
- package/cjs/rules/core/when.d.ts +0 -6
- package/cjs/rules/core/when.d.ts.map +0 -1
- package/cjs/rules/core/when.js +0 -40
- package/cjs/rules/core/when.js.map +0 -1
- package/cjs/rules/date/date-comparison-rules.d.ts +0 -25
- package/cjs/rules/date/date-comparison-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-comparison-rules.js +0 -78
- package/cjs/rules/date/date-comparison-rules.js.map +0 -1
- package/cjs/rules/date/date-day-rules.d.ts +0 -21
- package/cjs/rules/date/date-day-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-day-rules.js +0 -65
- package/cjs/rules/date/date-day-rules.js.map +0 -1
- package/cjs/rules/date/date-field-comparison-rules.d.ts +0 -28
- package/cjs/rules/date/date-field-comparison-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-field-comparison-rules.js +0 -90
- package/cjs/rules/date/date-field-comparison-rules.js.map +0 -1
- package/cjs/rules/date/date-period-rules.d.ts +0 -108
- package/cjs/rules/date/date-period-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-period-rules.js +0 -566
- package/cjs/rules/date/date-period-rules.js.map +0 -1
- package/cjs/rules/date/date-relative-rules.d.ts +0 -20
- package/cjs/rules/date/date-relative-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-relative-rules.js +0 -57
- package/cjs/rules/date/date-relative-rules.js.map +0 -1
- package/cjs/rules/date/date-special-rules.d.ts +0 -20
- package/cjs/rules/date/date-special-rules.d.ts.map +0 -1
- package/cjs/rules/date/date-special-rules.js +0 -72
- package/cjs/rules/date/date-special-rules.js.map +0 -1
- package/cjs/rules/date/date.d.ts +0 -93
- package/cjs/rules/date/date.d.ts.map +0 -1
- package/cjs/rules/date/date.js +0 -279
- package/cjs/rules/date/date.js.map +0 -1
- package/cjs/rules/date/index.d.ts +0 -8
- package/cjs/rules/date/index.d.ts.map +0 -1
- package/cjs/rules/file/dimensions.d.ts +0 -26
- package/cjs/rules/file/dimensions.d.ts.map +0 -1
- package/cjs/rules/file/dimensions.js +0 -56
- package/cjs/rules/file/dimensions.js.map +0 -1
- package/cjs/rules/file/file-size.d.ts +0 -14
- package/cjs/rules/file/file-size.d.ts.map +0 -1
- package/cjs/rules/file/file-size.js +0 -26
- package/cjs/rules/file/file-size.js.map +0 -1
- package/cjs/rules/file/index.d.ts +0 -11
- package/cjs/rules/file/index.d.ts.map +0 -1
- package/cjs/rules/index.d.ts +0 -19
- package/cjs/rules/index.d.ts.map +0 -1
- package/cjs/rules/length/index.d.ts +0 -2
- package/cjs/rules/length/index.d.ts.map +0 -1
- package/cjs/rules/length/length-rules.d.ts +0 -49
- package/cjs/rules/length/length-rules.d.ts.map +0 -1
- package/cjs/rules/length/length-rules.js +0 -116
- package/cjs/rules/length/length-rules.js.map +0 -1
- package/cjs/rules/number/index.d.ts +0 -2
- package/cjs/rules/number/index.d.ts.map +0 -1
- package/cjs/rules/number/number-rules.d.ts +0 -65
- package/cjs/rules/number/number-rules.d.ts.map +0 -1
- package/cjs/rules/number/number-rules.js +0 -234
- package/cjs/rules/number/number-rules.js.map +0 -1
- package/cjs/rules/scalar/accepted-rule.d.ts +0 -39
- package/cjs/rules/scalar/accepted-rule.d.ts.map +0 -1
- package/cjs/rules/scalar/accepted-rule.js +0 -110
- package/cjs/rules/scalar/accepted-rule.js.map +0 -1
- package/cjs/rules/scalar/declined-rule.d.ts +0 -39
- package/cjs/rules/scalar/declined-rule.d.ts.map +0 -1
- package/cjs/rules/scalar/declined-rule.js +0 -110
- package/cjs/rules/scalar/declined-rule.js.map +0 -1
- package/cjs/rules/scalar/index.d.ts +0 -3
- package/cjs/rules/scalar/index.d.ts.map +0 -1
- package/cjs/rules/string/alpha.d.ts +0 -14
- package/cjs/rules/string/alpha.d.ts.map +0 -1
- package/cjs/rules/string/alpha.js +0 -39
- package/cjs/rules/string/alpha.js.map +0 -1
- package/cjs/rules/string/credit-card.d.ts +0 -6
- package/cjs/rules/string/credit-card.d.ts.map +0 -1
- package/cjs/rules/string/credit-card.js +0 -31
- package/cjs/rules/string/credit-card.js.map +0 -1
- package/cjs/rules/string/email.d.ts +0 -6
- package/cjs/rules/string/email.d.ts.map +0 -1
- package/cjs/rules/string/email.js +0 -13
- package/cjs/rules/string/email.js.map +0 -1
- package/cjs/rules/string/index.d.ts +0 -17
- package/cjs/rules/string/index.d.ts.map +0 -1
- package/cjs/rules/string/ip.d.ts +0 -14
- package/cjs/rules/string/ip.d.ts.map +0 -1
- package/cjs/rules/string/ip.js +0 -39
- package/cjs/rules/string/ip.js.map +0 -1
- package/cjs/rules/string/matches.d.ts +0 -8
- package/cjs/rules/string/matches.d.ts.map +0 -1
- package/cjs/rules/string/matches.js +0 -14
- package/cjs/rules/string/matches.js.map +0 -1
- package/cjs/rules/string/pattern.d.ts +0 -8
- package/cjs/rules/string/pattern.d.ts.map +0 -1
- package/cjs/rules/string/pattern.js +0 -13
- package/cjs/rules/string/pattern.js.map +0 -1
- package/cjs/rules/string/string-comparison.d.ts +0 -26
- package/cjs/rules/string/string-comparison.d.ts.map +0 -1
- package/cjs/rules/string/string-comparison.js +0 -52
- package/cjs/rules/string/string-comparison.js.map +0 -1
- package/cjs/rules/string/strong-password-rule.d.ts +0 -14
- package/cjs/rules/string/strong-password-rule.d.ts.map +0 -1
- package/cjs/rules/string/strong-password-rule.js +0 -38
- package/cjs/rules/string/strong-password-rule.js.map +0 -1
- package/cjs/rules/string/url.d.ts +0 -6
- package/cjs/rules/string/url.d.ts.map +0 -1
- package/cjs/rules/string/url.js +0 -16
- package/cjs/rules/string/url.js.map +0 -1
- package/cjs/rules/string/without-whitespace.d.ts +0 -6
- package/cjs/rules/string/without-whitespace.d.ts.map +0 -1
- package/cjs/rules/string/without-whitespace.js +0 -13
- package/cjs/rules/string/without-whitespace.js.map +0 -1
- package/cjs/types/conditional-types.d.ts +0 -15
- package/cjs/types/conditional-types.d.ts.map +0 -1
- package/cjs/types/context-types.d.ts +0 -44
- package/cjs/types/context-types.d.ts.map +0 -1
- package/cjs/types/data-transformer-types.d.ts +0 -25
- package/cjs/types/data-transformer-types.d.ts.map +0 -1
- package/cjs/types/date-types.d.ts +0 -9
- package/cjs/types/date-types.d.ts.map +0 -1
- package/cjs/types/date-types.js +0 -12
- package/cjs/types/date-types.js.map +0 -1
- package/cjs/types/index.d.ts +0 -10
- package/cjs/types/index.d.ts.map +0 -1
- package/cjs/types/inference-types.d.ts +0 -29
- package/cjs/types/inference-types.d.ts.map +0 -1
- package/cjs/types/mutator-types.d.ts +0 -27
- package/cjs/types/mutator-types.d.ts.map +0 -1
- package/cjs/types/result-types.d.ts +0 -19
- package/cjs/types/result-types.d.ts.map +0 -1
- package/cjs/types/rule-types.d.ts +0 -54
- package/cjs/types/rule-types.d.ts.map +0 -1
- package/cjs/types/schema-types.d.ts +0 -6
- package/cjs/types/schema-types.d.ts.map +0 -1
- package/cjs/validators/any-validator.d.ts +0 -7
- package/cjs/validators/any-validator.d.ts.map +0 -1
- package/cjs/validators/any-validator.js +0 -5
- package/cjs/validators/any-validator.js.map +0 -1
- package/cjs/validators/array-validator.d.ts +0 -59
- package/cjs/validators/array-validator.d.ts.map +0 -1
- package/cjs/validators/array-validator.js +0 -134
- package/cjs/validators/array-validator.js.map +0 -1
- package/cjs/validators/base-validator.d.ts +0 -609
- package/cjs/validators/base-validator.d.ts.map +0 -1
- package/cjs/validators/base-validator.js +0 -1154
- package/cjs/validators/base-validator.js.map +0 -1
- package/cjs/validators/boolean-validator.d.ts +0 -47
- package/cjs/validators/boolean-validator.d.ts.map +0 -1
- package/cjs/validators/boolean-validator.js +0 -54
- package/cjs/validators/boolean-validator.js.map +0 -1
- package/cjs/validators/date-validator.d.ts +0 -307
- package/cjs/validators/date-validator.d.ts.map +0 -1
- package/cjs/validators/date-validator.js +0 -645
- package/cjs/validators/date-validator.js.map +0 -1
- package/cjs/validators/float-validator.d.ts +0 -8
- package/cjs/validators/float-validator.d.ts.map +0 -1
- package/cjs/validators/float-validator.js +0 -9
- package/cjs/validators/float-validator.js.map +0 -1
- package/cjs/validators/index.d.ts +0 -24
- package/cjs/validators/index.d.ts.map +0 -1
- package/cjs/validators/int-validator.d.ts +0 -8
- package/cjs/validators/int-validator.d.ts.map +0 -1
- package/cjs/validators/int-validator.js +0 -9
- package/cjs/validators/int-validator.js.map +0 -1
- package/cjs/validators/number-validator.d.ts +0 -113
- package/cjs/validators/number-validator.d.ts.map +0 -1
- package/cjs/validators/number-validator.js +0 -192
- package/cjs/validators/number-validator.js.map +0 -1
- package/cjs/validators/numeric-validator.d.ts +0 -15
- package/cjs/validators/numeric-validator.d.ts.map +0 -1
- package/cjs/validators/numeric-validator.js +0 -18
- package/cjs/validators/numeric-validator.js.map +0 -1
- package/cjs/validators/object-validator.d.ts +0 -178
- package/cjs/validators/object-validator.d.ts.map +0 -1
- package/cjs/validators/object-validator.js +0 -356
- package/cjs/validators/object-validator.js.map +0 -1
- package/cjs/validators/record-validator.d.ts +0 -33
- package/cjs/validators/record-validator.d.ts.map +0 -1
- package/cjs/validators/record-validator.js +0 -70
- package/cjs/validators/record-validator.js.map +0 -1
- package/cjs/validators/scalar-validator.d.ts +0 -82
- package/cjs/validators/scalar-validator.d.ts.map +0 -1
- package/cjs/validators/scalar-validator.js +0 -160
- package/cjs/validators/scalar-validator.js.map +0 -1
- package/cjs/validators/string-validator.d.ts +0 -191
- package/cjs/validators/string-validator.d.ts.map +0 -1
- package/cjs/validators/string-validator.js +0 -410
- package/cjs/validators/string-validator.js.map +0 -1
- package/cjs/validators/tuple-validator.d.ts +0 -34
- package/cjs/validators/tuple-validator.d.ts.map +0 -1
- package/cjs/validators/tuple-validator.js +0 -79
- package/cjs/validators/tuple-validator.js.map +0 -1
- package/cjs/validators/union-validator.d.ts +0 -42
- package/cjs/validators/union-validator.d.ts.map +0 -1
- package/cjs/validators/union-validator.js +0 -44
- package/cjs/validators/union-validator.js.map +0 -1
- package/esm/config.d.ts +0 -48
- package/esm/config.d.ts.map +0 -1
- package/esm/config.js +0 -42
- package/esm/config.js.map +0 -1
- package/esm/factory/index.d.ts +0 -3
- package/esm/factory/index.d.ts.map +0 -1
- package/esm/factory/validate.d.ts +0 -8
- package/esm/factory/validate.d.ts.map +0 -1
- package/esm/factory/validate.js +0 -21
- package/esm/factory/validate.js.map +0 -1
- package/esm/factory/validators.d.ts +0 -36
- package/esm/factory/validators.d.ts.map +0 -1
- package/esm/factory/validators.js +0 -39
- package/esm/factory/validators.js.map +0 -1
- package/esm/helpers/date-helpers.d.ts +0 -16
- package/esm/helpers/date-helpers.d.ts.map +0 -1
- package/esm/helpers/date-helpers.js +0 -20
- package/esm/helpers/date-helpers.js.map +0 -1
- package/esm/helpers/get-field-value.d.ts +0 -37
- package/esm/helpers/get-field-value.d.ts.map +0 -1
- package/esm/helpers/get-field-value.js +0 -40
- package/esm/helpers/get-field-value.js.map +0 -1
- package/esm/helpers/index.d.ts +0 -5
- package/esm/helpers/index.d.ts.map +0 -1
- package/esm/helpers/path-helpers.d.ts +0 -5
- package/esm/helpers/path-helpers.d.ts.map +0 -1
- package/esm/helpers/path-helpers.js +0 -8
- package/esm/helpers/path-helpers.js.map +0 -1
- package/esm/helpers/validation-helpers.d.ts +0 -4
- package/esm/helpers/validation-helpers.d.ts.map +0 -1
- package/esm/helpers/validation-helpers.js +0 -48
- package/esm/helpers/validation-helpers.js.map +0 -1
- package/esm/index.d.ts +0 -29
- package/esm/index.d.ts.map +0 -1
- package/esm/mutators/array-mutators.d.ts +0 -12
- package/esm/mutators/array-mutators.d.ts.map +0 -1
- package/esm/mutators/array-mutators.js +0 -37
- package/esm/mutators/array-mutators.js.map +0 -1
- package/esm/mutators/date-mutators.d.ts +0 -39
- package/esm/mutators/date-mutators.d.ts.map +0 -1
- package/esm/mutators/date-mutators.js +0 -120
- package/esm/mutators/date-mutators.js.map +0 -1
- package/esm/mutators/index.d.ts +0 -7
- package/esm/mutators/index.d.ts.map +0 -1
- package/esm/mutators/number-mutators.d.ts +0 -9
- package/esm/mutators/number-mutators.d.ts.map +0 -1
- package/esm/mutators/number-mutators.js +0 -23
- package/esm/mutators/number-mutators.js.map +0 -1
- package/esm/mutators/object-mutators.d.ts +0 -8
- package/esm/mutators/object-mutators.d.ts.map +0 -1
- package/esm/mutators/object-mutators.js +0 -50
- package/esm/mutators/object-mutators.js.map +0 -1
- package/esm/mutators/scalar-mutators.d.ts +0 -3
- package/esm/mutators/scalar-mutators.d.ts.map +0 -1
- package/esm/mutators/scalar-mutators.js +0 -6
- package/esm/mutators/scalar-mutators.js.map +0 -1
- package/esm/mutators/string-mutators.d.ts +0 -72
- package/esm/mutators/string-mutators.d.ts.map +0 -1
- package/esm/mutators/string-mutators.js +0 -193
- package/esm/mutators/string-mutators.js.map +0 -1
- package/esm/plugins/index.d.ts +0 -7
- package/esm/plugins/index.d.ts.map +0 -1
- package/esm/plugins/plugin-system.d.ts +0 -71
- package/esm/plugins/plugin-system.d.ts.map +0 -1
- package/esm/plugins/plugin-system.js +0 -68
- package/esm/plugins/plugin-system.js.map +0 -1
- package/esm/rules/array/array-rules.d.ts +0 -12
- package/esm/rules/array/array-rules.d.ts.map +0 -1
- package/esm/rules/array/array-rules.js +0 -44
- package/esm/rules/array/array-rules.js.map +0 -1
- package/esm/rules/array/index.d.ts +0 -2
- package/esm/rules/array/index.d.ts.map +0 -1
- package/esm/rules/color/color-rules.d.ts +0 -30
- package/esm/rules/color/color-rules.d.ts.map +0 -1
- package/esm/rules/color/color-rules.js +0 -120
- package/esm/rules/color/color-rules.js.map +0 -1
- package/esm/rules/color/index.d.ts +0 -2
- package/esm/rules/color/index.d.ts.map +0 -1
- package/esm/rules/common/enum.d.ts +0 -26
- package/esm/rules/common/enum.d.ts.map +0 -1
- package/esm/rules/common/enum.js +0 -55
- package/esm/rules/common/enum.js.map +0 -1
- package/esm/rules/common/equals-field-rules.d.ts +0 -18
- package/esm/rules/common/equals-field-rules.d.ts.map +0 -1
- package/esm/rules/common/equals-field-rules.js +0 -38
- package/esm/rules/common/equals-field-rules.js.map +0 -1
- package/esm/rules/common/index.d.ts +0 -5
- package/esm/rules/common/index.d.ts.map +0 -1
- package/esm/rules/common/type-rules.d.ts +0 -34
- package/esm/rules/common/type-rules.d.ts.map +0 -1
- package/esm/rules/common/type-rules.js +0 -104
- package/esm/rules/common/type-rules.js.map +0 -1
- package/esm/rules/common/unknown-key.d.ts +0 -9
- package/esm/rules/common/unknown-key.d.ts.map +0 -1
- package/esm/rules/common/unknown-key.js +0 -20
- package/esm/rules/common/unknown-key.js.map +0 -1
- package/esm/rules/conditional/forbidden-if-rules.d.ts +0 -54
- package/esm/rules/conditional/forbidden-if-rules.d.ts.map +0 -1
- package/esm/rules/conditional/forbidden-if-rules.js +0 -112
- package/esm/rules/conditional/forbidden-if-rules.js.map +0 -1
- package/esm/rules/conditional/index.d.ts +0 -10
- package/esm/rules/conditional/index.d.ts.map +0 -1
- package/esm/rules/conditional/present-if-rules.d.ts +0 -45
- package/esm/rules/conditional/present-if-rules.d.ts.map +0 -1
- package/esm/rules/conditional/present-if-rules.js +0 -98
- package/esm/rules/conditional/present-if-rules.js.map +0 -1
- package/esm/rules/conditional/present-unless-rules.d.ts +0 -11
- package/esm/rules/conditional/present-unless-rules.d.ts.map +0 -1
- package/esm/rules/conditional/present-unless-rules.js +0 -20
- package/esm/rules/conditional/present-unless-rules.js.map +0 -1
- package/esm/rules/conditional/present-with-rules.d.ts +0 -26
- package/esm/rules/conditional/present-with-rules.d.ts.map +0 -1
- package/esm/rules/conditional/present-with-rules.js +0 -63
- package/esm/rules/conditional/present-with-rules.js.map +0 -1
- package/esm/rules/conditional/present-without-rules.d.ts +0 -26
- package/esm/rules/conditional/present-without-rules.d.ts.map +0 -1
- package/esm/rules/conditional/present-without-rules.js +0 -63
- package/esm/rules/conditional/present-without-rules.js.map +0 -1
- package/esm/rules/conditional/required-if-rules.d.ts +0 -45
- package/esm/rules/conditional/required-if-rules.d.ts.map +0 -1
- package/esm/rules/conditional/required-if-rules.js +0 -98
- package/esm/rules/conditional/required-if-rules.js.map +0 -1
- package/esm/rules/conditional/required-unless-rules.d.ts +0 -11
- package/esm/rules/conditional/required-unless-rules.d.ts.map +0 -1
- package/esm/rules/conditional/required-unless-rules.js +0 -20
- package/esm/rules/conditional/required-unless-rules.js.map +0 -1
- package/esm/rules/conditional/required-with-rules.d.ts +0 -26
- package/esm/rules/conditional/required-with-rules.d.ts.map +0 -1
- package/esm/rules/conditional/required-with-rules.js +0 -63
- package/esm/rules/conditional/required-with-rules.js.map +0 -1
- package/esm/rules/conditional/required-without-rules.d.ts +0 -26
- package/esm/rules/conditional/required-without-rules.d.ts.map +0 -1
- package/esm/rules/conditional/required-without-rules.js +0 -63
- package/esm/rules/conditional/required-without-rules.js.map +0 -1
- package/esm/rules/core/equal.d.ts +0 -8
- package/esm/rules/core/equal.d.ts.map +0 -1
- package/esm/rules/core/equal.js +0 -13
- package/esm/rules/core/equal.js.map +0 -1
- package/esm/rules/core/forbidden.d.ts +0 -6
- package/esm/rules/core/forbidden.d.ts.map +0 -1
- package/esm/rules/core/forbidden.js +0 -13
- package/esm/rules/core/forbidden.js.map +0 -1
- package/esm/rules/core/index.d.ts +0 -6
- package/esm/rules/core/index.d.ts.map +0 -1
- package/esm/rules/core/required.d.ts +0 -11
- package/esm/rules/core/required.d.ts.map +0 -1
- package/esm/rules/core/required.js +0 -31
- package/esm/rules/core/required.js.map +0 -1
- package/esm/rules/core/union.d.ts +0 -9
- package/esm/rules/core/union.d.ts.map +0 -1
- package/esm/rules/core/union.js +0 -40
- package/esm/rules/core/union.js.map +0 -1
- package/esm/rules/core/when.d.ts +0 -6
- package/esm/rules/core/when.d.ts.map +0 -1
- package/esm/rules/core/when.js +0 -40
- package/esm/rules/core/when.js.map +0 -1
- package/esm/rules/date/date-comparison-rules.d.ts +0 -25
- package/esm/rules/date/date-comparison-rules.d.ts.map +0 -1
- package/esm/rules/date/date-comparison-rules.js +0 -78
- package/esm/rules/date/date-comparison-rules.js.map +0 -1
- package/esm/rules/date/date-day-rules.d.ts +0 -21
- package/esm/rules/date/date-day-rules.d.ts.map +0 -1
- package/esm/rules/date/date-day-rules.js +0 -65
- package/esm/rules/date/date-day-rules.js.map +0 -1
- package/esm/rules/date/date-field-comparison-rules.d.ts +0 -28
- package/esm/rules/date/date-field-comparison-rules.d.ts.map +0 -1
- package/esm/rules/date/date-field-comparison-rules.js +0 -90
- package/esm/rules/date/date-field-comparison-rules.js.map +0 -1
- package/esm/rules/date/date-period-rules.d.ts +0 -108
- package/esm/rules/date/date-period-rules.d.ts.map +0 -1
- package/esm/rules/date/date-period-rules.js +0 -566
- package/esm/rules/date/date-period-rules.js.map +0 -1
- package/esm/rules/date/date-relative-rules.d.ts +0 -20
- package/esm/rules/date/date-relative-rules.d.ts.map +0 -1
- package/esm/rules/date/date-relative-rules.js +0 -57
- package/esm/rules/date/date-relative-rules.js.map +0 -1
- package/esm/rules/date/date-special-rules.d.ts +0 -20
- package/esm/rules/date/date-special-rules.d.ts.map +0 -1
- package/esm/rules/date/date-special-rules.js +0 -72
- package/esm/rules/date/date-special-rules.js.map +0 -1
- package/esm/rules/date/date.d.ts +0 -93
- package/esm/rules/date/date.d.ts.map +0 -1
- package/esm/rules/date/date.js +0 -279
- package/esm/rules/date/date.js.map +0 -1
- package/esm/rules/date/index.d.ts +0 -8
- package/esm/rules/date/index.d.ts.map +0 -1
- package/esm/rules/file/dimensions.d.ts +0 -26
- package/esm/rules/file/dimensions.d.ts.map +0 -1
- package/esm/rules/file/dimensions.js +0 -56
- package/esm/rules/file/dimensions.js.map +0 -1
- package/esm/rules/file/file-size.d.ts +0 -14
- package/esm/rules/file/file-size.d.ts.map +0 -1
- package/esm/rules/file/file-size.js +0 -26
- package/esm/rules/file/file-size.js.map +0 -1
- package/esm/rules/file/index.d.ts +0 -11
- package/esm/rules/file/index.d.ts.map +0 -1
- package/esm/rules/index.d.ts +0 -19
- package/esm/rules/index.d.ts.map +0 -1
- package/esm/rules/length/index.d.ts +0 -2
- package/esm/rules/length/index.d.ts.map +0 -1
- package/esm/rules/length/length-rules.d.ts +0 -49
- package/esm/rules/length/length-rules.d.ts.map +0 -1
- package/esm/rules/length/length-rules.js +0 -116
- package/esm/rules/length/length-rules.js.map +0 -1
- package/esm/rules/number/index.d.ts +0 -2
- package/esm/rules/number/index.d.ts.map +0 -1
- package/esm/rules/number/number-rules.d.ts +0 -65
- package/esm/rules/number/number-rules.d.ts.map +0 -1
- package/esm/rules/number/number-rules.js +0 -234
- package/esm/rules/number/number-rules.js.map +0 -1
- package/esm/rules/scalar/accepted-rule.d.ts +0 -39
- package/esm/rules/scalar/accepted-rule.d.ts.map +0 -1
- package/esm/rules/scalar/accepted-rule.js +0 -110
- package/esm/rules/scalar/accepted-rule.js.map +0 -1
- package/esm/rules/scalar/declined-rule.d.ts +0 -39
- package/esm/rules/scalar/declined-rule.d.ts.map +0 -1
- package/esm/rules/scalar/declined-rule.js +0 -110
- package/esm/rules/scalar/declined-rule.js.map +0 -1
- package/esm/rules/scalar/index.d.ts +0 -3
- package/esm/rules/scalar/index.d.ts.map +0 -1
- package/esm/rules/string/alpha.d.ts +0 -14
- package/esm/rules/string/alpha.d.ts.map +0 -1
- package/esm/rules/string/alpha.js +0 -39
- package/esm/rules/string/alpha.js.map +0 -1
- package/esm/rules/string/credit-card.d.ts +0 -6
- package/esm/rules/string/credit-card.d.ts.map +0 -1
- package/esm/rules/string/credit-card.js +0 -31
- package/esm/rules/string/credit-card.js.map +0 -1
- package/esm/rules/string/email.d.ts +0 -6
- package/esm/rules/string/email.d.ts.map +0 -1
- package/esm/rules/string/email.js +0 -13
- package/esm/rules/string/email.js.map +0 -1
- package/esm/rules/string/index.d.ts +0 -17
- package/esm/rules/string/index.d.ts.map +0 -1
- package/esm/rules/string/ip.d.ts +0 -14
- package/esm/rules/string/ip.d.ts.map +0 -1
- package/esm/rules/string/ip.js +0 -39
- package/esm/rules/string/ip.js.map +0 -1
- package/esm/rules/string/matches.d.ts +0 -8
- package/esm/rules/string/matches.d.ts.map +0 -1
- package/esm/rules/string/matches.js +0 -14
- package/esm/rules/string/matches.js.map +0 -1
- package/esm/rules/string/pattern.d.ts +0 -8
- package/esm/rules/string/pattern.d.ts.map +0 -1
- package/esm/rules/string/pattern.js +0 -13
- package/esm/rules/string/pattern.js.map +0 -1
- package/esm/rules/string/string-comparison.d.ts +0 -26
- package/esm/rules/string/string-comparison.d.ts.map +0 -1
- package/esm/rules/string/string-comparison.js +0 -52
- package/esm/rules/string/string-comparison.js.map +0 -1
- package/esm/rules/string/strong-password-rule.d.ts +0 -14
- package/esm/rules/string/strong-password-rule.d.ts.map +0 -1
- package/esm/rules/string/strong-password-rule.js +0 -38
- package/esm/rules/string/strong-password-rule.js.map +0 -1
- package/esm/rules/string/url.d.ts +0 -6
- package/esm/rules/string/url.d.ts.map +0 -1
- package/esm/rules/string/url.js +0 -16
- package/esm/rules/string/url.js.map +0 -1
- package/esm/rules/string/without-whitespace.d.ts +0 -6
- package/esm/rules/string/without-whitespace.d.ts.map +0 -1
- package/esm/rules/string/without-whitespace.js +0 -13
- package/esm/rules/string/without-whitespace.js.map +0 -1
- package/esm/types/conditional-types.d.ts +0 -15
- package/esm/types/conditional-types.d.ts.map +0 -1
- package/esm/types/context-types.d.ts +0 -44
- package/esm/types/context-types.d.ts.map +0 -1
- package/esm/types/data-transformer-types.d.ts +0 -25
- package/esm/types/data-transformer-types.d.ts.map +0 -1
- package/esm/types/date-types.d.ts +0 -9
- package/esm/types/date-types.d.ts.map +0 -1
- package/esm/types/date-types.js +0 -12
- package/esm/types/date-types.js.map +0 -1
- package/esm/types/index.d.ts +0 -10
- package/esm/types/index.d.ts.map +0 -1
- package/esm/types/inference-types.d.ts +0 -29
- package/esm/types/inference-types.d.ts.map +0 -1
- package/esm/types/mutator-types.d.ts +0 -27
- package/esm/types/mutator-types.d.ts.map +0 -1
- package/esm/types/result-types.d.ts +0 -19
- package/esm/types/result-types.d.ts.map +0 -1
- package/esm/types/rule-types.d.ts +0 -54
- package/esm/types/rule-types.d.ts.map +0 -1
- package/esm/types/schema-types.d.ts +0 -6
- package/esm/types/schema-types.d.ts.map +0 -1
- package/esm/validators/any-validator.d.ts +0 -7
- package/esm/validators/any-validator.d.ts.map +0 -1
- package/esm/validators/any-validator.js +0 -5
- package/esm/validators/any-validator.js.map +0 -1
- package/esm/validators/array-validator.d.ts +0 -59
- package/esm/validators/array-validator.d.ts.map +0 -1
- package/esm/validators/array-validator.js +0 -134
- package/esm/validators/array-validator.js.map +0 -1
- package/esm/validators/base-validator.d.ts +0 -609
- package/esm/validators/base-validator.d.ts.map +0 -1
- package/esm/validators/base-validator.js +0 -1154
- package/esm/validators/base-validator.js.map +0 -1
- package/esm/validators/boolean-validator.d.ts +0 -47
- package/esm/validators/boolean-validator.d.ts.map +0 -1
- package/esm/validators/boolean-validator.js +0 -54
- package/esm/validators/boolean-validator.js.map +0 -1
- package/esm/validators/date-validator.d.ts +0 -307
- package/esm/validators/date-validator.d.ts.map +0 -1
- package/esm/validators/date-validator.js +0 -645
- package/esm/validators/date-validator.js.map +0 -1
- package/esm/validators/float-validator.d.ts +0 -8
- package/esm/validators/float-validator.d.ts.map +0 -1
- package/esm/validators/float-validator.js +0 -9
- package/esm/validators/float-validator.js.map +0 -1
- package/esm/validators/index.d.ts +0 -24
- package/esm/validators/index.d.ts.map +0 -1
- package/esm/validators/int-validator.d.ts +0 -8
- package/esm/validators/int-validator.d.ts.map +0 -1
- package/esm/validators/int-validator.js +0 -9
- package/esm/validators/int-validator.js.map +0 -1
- package/esm/validators/number-validator.d.ts +0 -113
- package/esm/validators/number-validator.d.ts.map +0 -1
- package/esm/validators/number-validator.js +0 -192
- package/esm/validators/number-validator.js.map +0 -1
- package/esm/validators/numeric-validator.d.ts +0 -15
- package/esm/validators/numeric-validator.d.ts.map +0 -1
- package/esm/validators/numeric-validator.js +0 -18
- package/esm/validators/numeric-validator.js.map +0 -1
- package/esm/validators/object-validator.d.ts +0 -178
- package/esm/validators/object-validator.d.ts.map +0 -1
- package/esm/validators/object-validator.js +0 -356
- package/esm/validators/object-validator.js.map +0 -1
- package/esm/validators/record-validator.d.ts +0 -33
- package/esm/validators/record-validator.d.ts.map +0 -1
- package/esm/validators/record-validator.js +0 -70
- package/esm/validators/record-validator.js.map +0 -1
- package/esm/validators/scalar-validator.d.ts +0 -82
- package/esm/validators/scalar-validator.d.ts.map +0 -1
- package/esm/validators/scalar-validator.js +0 -160
- package/esm/validators/scalar-validator.js.map +0 -1
- package/esm/validators/string-validator.d.ts +0 -191
- package/esm/validators/string-validator.d.ts.map +0 -1
- package/esm/validators/string-validator.js +0 -410
- package/esm/validators/string-validator.js.map +0 -1
- package/esm/validators/tuple-validator.d.ts +0 -34
- package/esm/validators/tuple-validator.d.ts.map +0 -1
- package/esm/validators/tuple-validator.js +0 -79
- package/esm/validators/tuple-validator.js.map +0 -1
- package/esm/validators/union-validator.d.ts +0 -42
- package/esm/validators/union-validator.d.ts.map +0 -1
- package/esm/validators/union-validator.js +0 -44
- package/esm/validators/union-validator.js.map +0 -1
|
@@ -1,1154 +0,0 @@
|
|
|
1
|
-
'use strict';var reinforcements=require('@mongez/reinforcements'),supportiveIs=require('@mongez/supportive-is'),validationHelpers=require('../helpers/validation-helpers.js'),equal=require('../rules/core/equal.js'),forbidden=require('../rules/core/forbidden.js'),required=require('../rules/core/required.js'),when=require('../rules/core/when.js');require('net');var requiredIfRules=require('../rules/conditional/required-if-rules.js'),requiredUnlessRules=require('../rules/conditional/required-unless-rules.js'),requiredWithRules=require('../rules/conditional/required-with-rules.js'),requiredWithoutRules=require('../rules/conditional/required-without-rules.js'),presentIfRules=require('../rules/conditional/present-if-rules.js'),presentUnlessRules=require('../rules/conditional/present-unless-rules.js'),presentWithRules=require('../rules/conditional/present-with-rules.js'),presentWithoutRules=require('../rules/conditional/present-without-rules.js'),forbiddenIfRules=require('../rules/conditional/forbidden-if-rules.js'),equalsFieldRules=require('../rules/common/equals-field-rules.js');/**
|
|
2
|
-
* Base validator class - foundation for all validators
|
|
3
|
-
*/
|
|
4
|
-
class BaseValidator {
|
|
5
|
-
rules = [];
|
|
6
|
-
mutators = [];
|
|
7
|
-
defaultValue;
|
|
8
|
-
description;
|
|
9
|
-
shouldOmit = false;
|
|
10
|
-
isNullable = false;
|
|
11
|
-
/**
|
|
12
|
-
* Pipeline to transform the mutated/original data before returning it
|
|
13
|
-
*/
|
|
14
|
-
dataTransformers = [];
|
|
15
|
-
/**
|
|
16
|
-
* Attributes text to be replaced on translations
|
|
17
|
-
* If the value is an object, it will be used as the attributes list for the rule
|
|
18
|
-
* If the value is a string, it will be used as the attributes list for the rule
|
|
19
|
-
*/
|
|
20
|
-
attributesText = {};
|
|
21
|
-
/**
|
|
22
|
-
* Attributed that will be always using the attribute translator
|
|
23
|
-
*/
|
|
24
|
-
translatedAttributes = {};
|
|
25
|
-
/**
|
|
26
|
-
* Get the default value
|
|
27
|
-
*/
|
|
28
|
-
getDefaultValue() {
|
|
29
|
-
return this.defaultValue;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Determine if value accepts null value
|
|
33
|
-
*/
|
|
34
|
-
nullable() {
|
|
35
|
-
this.isNullable = true;
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Explicitly disallow null values after calling nullable
|
|
40
|
-
*/
|
|
41
|
-
notNullable() {
|
|
42
|
-
this.isNullable = false;
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Add transformer with optional options
|
|
47
|
-
*
|
|
48
|
-
* @param transform - The transformer callback function
|
|
49
|
-
* @param options - Optional options to pass to the transformer
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```ts
|
|
53
|
-
* // Without options
|
|
54
|
-
* v.date().addTransformer(data => data.toISOString())
|
|
55
|
-
*
|
|
56
|
-
* // With options
|
|
57
|
-
* v.date().addTransformer(
|
|
58
|
-
* (data, { options }) => dayjs(data).format(options.format),
|
|
59
|
-
* { format: 'YYYY-MM-DD' }
|
|
60
|
-
* )
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
addTransformer(transform, options = {}) {
|
|
64
|
-
this.dataTransformers.push({
|
|
65
|
-
transform,
|
|
66
|
-
options,
|
|
67
|
-
});
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Transform the output value - simple one-time transformation
|
|
72
|
-
*
|
|
73
|
-
* @param callback - Simple callback receiving data and context
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```ts
|
|
77
|
-
* // Simple transformation
|
|
78
|
-
* v.string().outputAs(data => data.toUpperCase())
|
|
79
|
-
*
|
|
80
|
-
* // With context
|
|
81
|
-
* v.string().outputAs((data, context) => {
|
|
82
|
-
* console.log(`Transforming ${context.path}`);
|
|
83
|
-
* return data.toLowerCase();
|
|
84
|
-
* })
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
outputAs(callback) {
|
|
88
|
-
this.addTransformer((data, { context }) => callback(data, context));
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Transform output to JSON string
|
|
93
|
-
*
|
|
94
|
-
* Works with any validator type (string, number, date, object, array, etc.)
|
|
95
|
-
*
|
|
96
|
-
* @param indent - Optional indentation for pretty printing (default: 0 for compact)
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* ```ts
|
|
100
|
-
* // Compact JSON
|
|
101
|
-
* v.object({ name: v.string() }).toJSON()
|
|
102
|
-
* // Output: '{"name":"John"}'
|
|
103
|
-
*
|
|
104
|
-
* // Pretty-printed JSON
|
|
105
|
-
* v.array(v.object({...})).toJSON(2)
|
|
106
|
-
* // Output:
|
|
107
|
-
* // [
|
|
108
|
-
* // {
|
|
109
|
-
* // "name": "John"
|
|
110
|
-
* // }
|
|
111
|
-
* // ]
|
|
112
|
-
*
|
|
113
|
-
* // Works with any type
|
|
114
|
-
* v.string().toJSON() // '"hello"'
|
|
115
|
-
* v.number().toJSON() // '42'
|
|
116
|
-
* v.date().toJSON() // '"2024-10-26T00:00:00.000Z"'
|
|
117
|
-
* ```
|
|
118
|
-
*
|
|
119
|
-
* @category Transformer
|
|
120
|
-
*/
|
|
121
|
-
toJSON(indent) {
|
|
122
|
-
this.addTransformer((data, { options }) => JSON.stringify(data, null, options.indent), { indent: indent ?? 0 });
|
|
123
|
-
return this;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Start data transformation pipeline
|
|
127
|
-
* Context is passed at runtime, not stored
|
|
128
|
-
*/
|
|
129
|
-
async startTransformationPipeline(data, context) {
|
|
130
|
-
for (const transformer of this.dataTransformers) {
|
|
131
|
-
data = await transformer.transform(data, {
|
|
132
|
-
options: transformer.options,
|
|
133
|
-
context,
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
return data;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Set attributes text to be replaced on translations
|
|
140
|
-
* If the value is an object, it will be used as the attributes list for the rule
|
|
141
|
-
* If the value is a string, it will be used as the attributes list for the rule
|
|
142
|
-
*
|
|
143
|
-
* @example
|
|
144
|
-
* v.string().attributes({
|
|
145
|
-
* name: "Name",
|
|
146
|
-
* email: "Email",
|
|
147
|
-
* });
|
|
148
|
-
* // Example 2: Add custom attributes for matches
|
|
149
|
-
* v.string().matches("confirmPassword").attributes({
|
|
150
|
-
* matches: {
|
|
151
|
-
* confirmPassword: "Confirm Password",
|
|
152
|
-
* },
|
|
153
|
-
* });
|
|
154
|
-
*/
|
|
155
|
-
attributes(attributes) {
|
|
156
|
-
for (const key in attributes) {
|
|
157
|
-
this.attributesText[key] = attributes[key];
|
|
158
|
-
}
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Define a lazy getter property for each attribute in the given object and use the config attribute translator
|
|
163
|
-
*/
|
|
164
|
-
transAttributes(attributes) {
|
|
165
|
-
for (const key in attributes) {
|
|
166
|
-
this.translatedAttributes[key] = attributes[key];
|
|
167
|
-
}
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Add description to the validator
|
|
172
|
-
*/
|
|
173
|
-
describe(description) {
|
|
174
|
-
this.description = description;
|
|
175
|
-
return this;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Check if this validator can handle the given value's type
|
|
179
|
-
* Override this in specific validators to enable type-based routing in union validators
|
|
180
|
-
*
|
|
181
|
-
* Default: returns true (validator will attempt to validate any type)
|
|
182
|
-
*
|
|
183
|
-
* @param value - The value to check
|
|
184
|
-
* @returns True if this validator can handle this type
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```ts
|
|
188
|
-
* // StringValidator
|
|
189
|
-
* public matchesType(value: any): boolean {
|
|
190
|
-
* return typeof value === 'string';
|
|
191
|
-
* }
|
|
192
|
-
*
|
|
193
|
-
* // Custom FileValidator
|
|
194
|
-
* public matchesType(value: any): boolean {
|
|
195
|
-
* return value instanceof UploadedFile;
|
|
196
|
-
* }
|
|
197
|
-
* ```
|
|
198
|
-
*/
|
|
199
|
-
matchesType(_value) {
|
|
200
|
-
return true; // Default: permissive, attempt to validate any type
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Create a copy of this validator with the same configuration
|
|
204
|
-
* Copies all rules, mutators, transformers, default values, and settings
|
|
205
|
-
*
|
|
206
|
-
* @returns A new validator instance with copied configuration
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* ```ts
|
|
210
|
-
* // Create reusable validator templates
|
|
211
|
-
* const baseString = v.string().required().trim().min(3);
|
|
212
|
-
* const emailField = baseString.clone().email();
|
|
213
|
-
* const usernameField = baseString.clone().alphanumeric().max(20);
|
|
214
|
-
*
|
|
215
|
-
* // Works with all validators
|
|
216
|
-
* const positiveInt = v.int().positive().required();
|
|
217
|
-
* const ageField = positiveInt.clone().min(18).max(120);
|
|
218
|
-
* ```
|
|
219
|
-
*/
|
|
220
|
-
clone() {
|
|
221
|
-
// Create a new instance using Object.create to preserve the prototype chain
|
|
222
|
-
const Constructor = this.constructor;
|
|
223
|
-
const cloned = Object.create(Constructor.prototype);
|
|
224
|
-
// Copy all BaseValidator properties
|
|
225
|
-
cloned.rules = [...this.rules];
|
|
226
|
-
cloned.mutators = [...this.mutators];
|
|
227
|
-
cloned.dataTransformers = [...this.dataTransformers];
|
|
228
|
-
cloned.defaultValue = this.defaultValue;
|
|
229
|
-
cloned.shouldOmit = this.shouldOmit;
|
|
230
|
-
cloned.description = this.description;
|
|
231
|
-
cloned.attributesText = { ...this.attributesText };
|
|
232
|
-
cloned.isNullable = this.isNullable;
|
|
233
|
-
return cloned;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* @deprecated This method is no longer needed and does nothing.
|
|
237
|
-
* Empty values are now automatically skipped for validation rules by default.
|
|
238
|
-
* Only presence validators (required, present, etc.) will check empty values.
|
|
239
|
-
* You can safely remove this call from your code.
|
|
240
|
-
*/
|
|
241
|
-
ignoreEmptyValue(_ignoreEmptyValue = true) {
|
|
242
|
-
// No-op for backward compatibility
|
|
243
|
-
return this;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Omit this field from the validated data output
|
|
247
|
-
*
|
|
248
|
-
* Field will still be validated but not included in the final result.
|
|
249
|
-
* Useful for confirmation fields, captcha, terms acceptance, etc.
|
|
250
|
-
*
|
|
251
|
-
* @example
|
|
252
|
-
* ```ts
|
|
253
|
-
* v.object({
|
|
254
|
-
* password: v.string().required(),
|
|
255
|
-
* confirmPassword: v.string().required().sameAs("password").omit(),
|
|
256
|
-
* acceptTerms: v.boolean().required().omit(),
|
|
257
|
-
* });
|
|
258
|
-
* // Output: { password: "..." }
|
|
259
|
-
* // confirmPassword and acceptTerms validated but omitted
|
|
260
|
-
* ```
|
|
261
|
-
*/
|
|
262
|
-
omit() {
|
|
263
|
-
this.shouldOmit = true;
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* @alias omit
|
|
268
|
-
*/
|
|
269
|
-
exclude() {
|
|
270
|
-
return this.omit();
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Check if this field should be omitted from the output
|
|
274
|
-
*/
|
|
275
|
-
isOmitted() {
|
|
276
|
-
return this.shouldOmit;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Value must be equal to the given value
|
|
280
|
-
*/
|
|
281
|
-
equal(value, errorMessage) {
|
|
282
|
-
const rule = this.addRule(equal.equalRule, errorMessage);
|
|
283
|
-
rule.context.options.value = value;
|
|
284
|
-
return this;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* Value must be the same as another field's value
|
|
288
|
-
*/
|
|
289
|
-
sameAs(field, errorMessage) {
|
|
290
|
-
const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
|
|
291
|
-
rule.context.options.field = field;
|
|
292
|
-
rule.context.options.scope = "global";
|
|
293
|
-
return this;
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Value must be the same as another sibling field's value
|
|
297
|
-
*/
|
|
298
|
-
sameAsSibling(field, errorMessage) {
|
|
299
|
-
const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
|
|
300
|
-
rule.context.options.field = field;
|
|
301
|
-
rule.context.options.scope = "sibling";
|
|
302
|
-
return this;
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Value must be different from another field's value
|
|
306
|
-
*/
|
|
307
|
-
differentFrom(field, errorMessage) {
|
|
308
|
-
const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
|
|
309
|
-
rule.context.options.field = field;
|
|
310
|
-
rule.context.options.scope = "global";
|
|
311
|
-
return this;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Value must be different from another sibling field's value
|
|
315
|
-
*/
|
|
316
|
-
differentFromSibling(field, errorMessage) {
|
|
317
|
-
const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
|
|
318
|
-
rule.context.options.field = field;
|
|
319
|
-
rule.context.options.scope = "sibling";
|
|
320
|
-
return this;
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Add rule to the validator
|
|
324
|
-
*/
|
|
325
|
-
addRule(rule, errorMessage) {
|
|
326
|
-
const newRule = {
|
|
327
|
-
...reinforcements.clone(rule),
|
|
328
|
-
context: {
|
|
329
|
-
errorMessage,
|
|
330
|
-
options: {},
|
|
331
|
-
attributesList: this.attributesText,
|
|
332
|
-
translatedAttributes: this.translatedAttributes,
|
|
333
|
-
},
|
|
334
|
-
};
|
|
335
|
-
if (errorMessage) {
|
|
336
|
-
newRule.errorMessage = errorMessage;
|
|
337
|
-
}
|
|
338
|
-
if (rule.sortOrder === undefined) {
|
|
339
|
-
newRule.sortOrder = this.rules.length + 1;
|
|
340
|
-
}
|
|
341
|
-
this.rules.push(newRule);
|
|
342
|
-
return newRule;
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Use a custom or pre-built validation rule
|
|
346
|
-
*
|
|
347
|
-
* @param rule - The validation rule to apply
|
|
348
|
-
* @param options - Rule options including errorMessage and any rule-specific options
|
|
349
|
-
*
|
|
350
|
-
* @example
|
|
351
|
-
* ```ts
|
|
352
|
-
* import { hexColorRule } from "@warlock.js/seal-plugins/colors";
|
|
353
|
-
*
|
|
354
|
-
* v.string().useRule(hexColorRule, { errorMessage: "Invalid color" });
|
|
355
|
-
* ```
|
|
356
|
-
*
|
|
357
|
-
* @example
|
|
358
|
-
* ```ts
|
|
359
|
-
* // With rule options
|
|
360
|
-
* v.string().useRule(myCustomRule, {
|
|
361
|
-
* customOption: true,
|
|
362
|
-
* errorMessage: "Custom validation failed"
|
|
363
|
-
* });
|
|
364
|
-
* ```
|
|
365
|
-
*/
|
|
366
|
-
useRule(rule, options) {
|
|
367
|
-
const { errorMessage, ...ruleOptions } = options || {};
|
|
368
|
-
const ruleInstance = this.addRule(rule, errorMessage);
|
|
369
|
-
// Assign rule-specific options
|
|
370
|
-
if (Object.keys(ruleOptions).length > 0) {
|
|
371
|
-
Object.assign(ruleInstance.context.options, ruleOptions);
|
|
372
|
-
}
|
|
373
|
-
return this;
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Define custom rule
|
|
377
|
-
*/
|
|
378
|
-
refine(callback) {
|
|
379
|
-
this.addRule({
|
|
380
|
-
name: "custom",
|
|
381
|
-
async validate(value, context) {
|
|
382
|
-
const result = await callback(value, context);
|
|
383
|
-
if (result) {
|
|
384
|
-
this.context.errorMessage = result;
|
|
385
|
-
return validationHelpers.invalidRule(this, context);
|
|
386
|
-
}
|
|
387
|
-
return validationHelpers.VALID_RULE;
|
|
388
|
-
},
|
|
389
|
-
});
|
|
390
|
-
return this;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Add mutator to the validator
|
|
394
|
-
*/
|
|
395
|
-
addMutator(mutator, options = {}) {
|
|
396
|
-
this.mutators.push({
|
|
397
|
-
mutate: mutator,
|
|
398
|
-
context: {
|
|
399
|
-
options,
|
|
400
|
-
ctx: {},
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
return this;
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Set default value for the field
|
|
407
|
-
*/
|
|
408
|
-
default(value) {
|
|
409
|
-
this.defaultValue = value;
|
|
410
|
-
return this;
|
|
411
|
-
}
|
|
412
|
-
// ==================== UNCONDITIONAL STATES ====================
|
|
413
|
-
/**
|
|
414
|
-
* This value must be present and has a value
|
|
415
|
-
*/
|
|
416
|
-
required(errorMessage) {
|
|
417
|
-
this.addRule(required.requiredRule, errorMessage);
|
|
418
|
-
return this;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Value must be present but not necessarily has a value
|
|
422
|
-
*/
|
|
423
|
-
present(errorMessage) {
|
|
424
|
-
this.addRule(required.presentRule, errorMessage);
|
|
425
|
-
return this;
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Mark the field as optional, so pass it if it has no value or has a value
|
|
429
|
-
* Because this is the default behavior, this method is just syntactic sugar
|
|
430
|
-
*/
|
|
431
|
-
optional() {
|
|
432
|
-
return this;
|
|
433
|
-
}
|
|
434
|
-
// ==================== REQUIRED: BASED ON FIELD PRESENCE ====================
|
|
435
|
-
/**
|
|
436
|
-
* Value is required if another field exists
|
|
437
|
-
*/
|
|
438
|
-
requiredWith(field, errorMessage) {
|
|
439
|
-
const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
|
|
440
|
-
rule.context.options.field = field;
|
|
441
|
-
rule.context.options.scope = "global";
|
|
442
|
-
return this;
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Value is required if another sibling field exists
|
|
446
|
-
*/
|
|
447
|
-
requiredWithSibling(field, errorMessage) {
|
|
448
|
-
const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
|
|
449
|
-
rule.context.options.field = field;
|
|
450
|
-
rule.context.options.scope = "sibling";
|
|
451
|
-
return this;
|
|
452
|
-
}
|
|
453
|
-
/**
|
|
454
|
-
* Value is required if another field is missing
|
|
455
|
-
*/
|
|
456
|
-
requiredWithout(field, errorMessage) {
|
|
457
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
|
|
458
|
-
rule.context.options.field = field;
|
|
459
|
-
rule.context.options.scope = "global";
|
|
460
|
-
return this;
|
|
461
|
-
}
|
|
462
|
-
/**
|
|
463
|
-
* Value is required if another sibling field is missing
|
|
464
|
-
*/
|
|
465
|
-
requiredWithoutSibling(field, errorMessage) {
|
|
466
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
|
|
467
|
-
rule.context.options.field = field;
|
|
468
|
-
rule.context.options.scope = "sibling";
|
|
469
|
-
return this;
|
|
470
|
-
}
|
|
471
|
-
// ==================== REQUIRED: BASED ON FIELD VALUE ====================
|
|
472
|
-
/**
|
|
473
|
-
* Value is required if another field equals a specific value
|
|
474
|
-
*/
|
|
475
|
-
requiredIf(field, value, errorMessage) {
|
|
476
|
-
const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
|
|
477
|
-
rule.context.options.field = field;
|
|
478
|
-
rule.context.options.value = value;
|
|
479
|
-
rule.context.options.scope = "global";
|
|
480
|
-
return this;
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Value is required if another sibling field equals a specific value
|
|
484
|
-
*/
|
|
485
|
-
requiredIfSibling(field, value, errorMessage) {
|
|
486
|
-
const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
|
|
487
|
-
rule.context.options.field = field;
|
|
488
|
-
rule.context.options.value = value;
|
|
489
|
-
rule.context.options.scope = "sibling";
|
|
490
|
-
return this;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Value is required unless another field equals a specific value
|
|
494
|
-
*/
|
|
495
|
-
requiredUnless(field, value, errorMessage) {
|
|
496
|
-
const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
|
|
497
|
-
rule.context.options.field = field;
|
|
498
|
-
rule.context.options.value = value;
|
|
499
|
-
rule.context.options.scope = "global";
|
|
500
|
-
return this;
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Value is required unless another sibling field equals a specific value
|
|
504
|
-
*/
|
|
505
|
-
requiredUnlessSibling(field, value, errorMessage) {
|
|
506
|
-
const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
|
|
507
|
-
rule.context.options.field = field;
|
|
508
|
-
rule.context.options.value = value;
|
|
509
|
-
rule.context.options.scope = "sibling";
|
|
510
|
-
return this;
|
|
511
|
-
}
|
|
512
|
-
// ==================== REQUIRED: BASED ON FIELD EMPTY STATE ====================
|
|
513
|
-
/**
|
|
514
|
-
* Value is required if another field is empty
|
|
515
|
-
*/
|
|
516
|
-
requiredIfEmpty(field, errorMessage) {
|
|
517
|
-
const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
|
|
518
|
-
rule.context.options.field = field;
|
|
519
|
-
rule.context.options.scope = "global";
|
|
520
|
-
return this;
|
|
521
|
-
}
|
|
522
|
-
/**
|
|
523
|
-
* Value is required if another sibling field is empty
|
|
524
|
-
*/
|
|
525
|
-
requiredIfEmptySibling(field, errorMessage) {
|
|
526
|
-
const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
|
|
527
|
-
rule.context.options.field = field;
|
|
528
|
-
rule.context.options.scope = "sibling";
|
|
529
|
-
return this;
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Value is required if another field is not empty
|
|
533
|
-
*/
|
|
534
|
-
requiredIfNotEmpty(field, errorMessage) {
|
|
535
|
-
const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
|
|
536
|
-
rule.context.options.field = field;
|
|
537
|
-
rule.context.options.scope = "global";
|
|
538
|
-
return this;
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Value is required if another sibling field is not empty
|
|
542
|
-
*/
|
|
543
|
-
requiredIfNotEmptySibling(field, errorMessage) {
|
|
544
|
-
const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
|
|
545
|
-
rule.context.options.field = field;
|
|
546
|
-
rule.context.options.scope = "sibling";
|
|
547
|
-
return this;
|
|
548
|
-
}
|
|
549
|
-
/**
|
|
550
|
-
* Value is required if another field's value is in the given array
|
|
551
|
-
*/
|
|
552
|
-
requiredIfIn(field, values, errorMessage) {
|
|
553
|
-
const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
|
|
554
|
-
rule.context.options.field = field;
|
|
555
|
-
rule.context.options.values = values;
|
|
556
|
-
rule.context.options.scope = "global";
|
|
557
|
-
return this;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Value is required if another sibling field's value is in the given array
|
|
561
|
-
*/
|
|
562
|
-
requiredIfInSibling(field, values, errorMessage) {
|
|
563
|
-
const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
|
|
564
|
-
rule.context.options.field = field;
|
|
565
|
-
rule.context.options.values = values;
|
|
566
|
-
rule.context.options.scope = "sibling";
|
|
567
|
-
return this;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Value is required if another field's value is NOT in the given array
|
|
571
|
-
*/
|
|
572
|
-
requiredIfNotIn(field, values, errorMessage) {
|
|
573
|
-
const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
|
|
574
|
-
rule.context.options.field = field;
|
|
575
|
-
rule.context.options.values = values;
|
|
576
|
-
rule.context.options.scope = "global";
|
|
577
|
-
return this;
|
|
578
|
-
}
|
|
579
|
-
/**
|
|
580
|
-
* Value is required if another sibling field's value is NOT in the given array
|
|
581
|
-
*/
|
|
582
|
-
requiredIfNotInSibling(field, values, errorMessage) {
|
|
583
|
-
const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
|
|
584
|
-
rule.context.options.field = field;
|
|
585
|
-
rule.context.options.values = values;
|
|
586
|
-
rule.context.options.scope = "sibling";
|
|
587
|
-
return this;
|
|
588
|
-
}
|
|
589
|
-
// ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ALL) ====================
|
|
590
|
-
/**
|
|
591
|
-
* Value is required if all specified fields exist
|
|
592
|
-
*/
|
|
593
|
-
requiredWithAll(fields, errorMessage) {
|
|
594
|
-
const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
|
|
595
|
-
rule.context.options.fields = fields;
|
|
596
|
-
rule.context.options.scope = "global";
|
|
597
|
-
return this;
|
|
598
|
-
}
|
|
599
|
-
/**
|
|
600
|
-
* Value is required if all specified sibling fields exist
|
|
601
|
-
*/
|
|
602
|
-
requiredWithAllSiblings(fields, errorMessage) {
|
|
603
|
-
const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
|
|
604
|
-
rule.context.options.fields = fields;
|
|
605
|
-
rule.context.options.scope = "sibling";
|
|
606
|
-
return this;
|
|
607
|
-
}
|
|
608
|
-
/**
|
|
609
|
-
* Value is required if all specified fields are missing
|
|
610
|
-
*/
|
|
611
|
-
requiredWithoutAll(fields, errorMessage) {
|
|
612
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
|
|
613
|
-
rule.context.options.fields = fields;
|
|
614
|
-
rule.context.options.scope = "global";
|
|
615
|
-
return this;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Value is required if all specified sibling fields are missing
|
|
619
|
-
*/
|
|
620
|
-
requiredWithoutAllSiblings(fields, errorMessage) {
|
|
621
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
|
|
622
|
-
rule.context.options.fields = fields;
|
|
623
|
-
rule.context.options.scope = "sibling";
|
|
624
|
-
return this;
|
|
625
|
-
}
|
|
626
|
-
// ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ANY) ====================
|
|
627
|
-
/**
|
|
628
|
-
* Value is required if any of the specified fields exists
|
|
629
|
-
*/
|
|
630
|
-
requiredWithAny(fields, errorMessage) {
|
|
631
|
-
const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
|
|
632
|
-
rule.context.options.fields = fields;
|
|
633
|
-
rule.context.options.scope = "global";
|
|
634
|
-
return this;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Value is required if any of the specified sibling fields exists
|
|
638
|
-
*/
|
|
639
|
-
requiredWithAnySiblings(fields, errorMessage) {
|
|
640
|
-
const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
|
|
641
|
-
rule.context.options.fields = fields;
|
|
642
|
-
rule.context.options.scope = "sibling";
|
|
643
|
-
return this;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Value is required if any of the specified fields is missing
|
|
647
|
-
*/
|
|
648
|
-
requiredWithoutAny(fields, errorMessage) {
|
|
649
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
|
|
650
|
-
rule.context.options.fields = fields;
|
|
651
|
-
rule.context.options.scope = "global";
|
|
652
|
-
return this;
|
|
653
|
-
}
|
|
654
|
-
/**
|
|
655
|
-
* Value is required if any of the specified sibling fields is missing
|
|
656
|
-
*/
|
|
657
|
-
requiredWithoutAnySiblings(fields, errorMessage) {
|
|
658
|
-
const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
|
|
659
|
-
rule.context.options.fields = fields;
|
|
660
|
-
rule.context.options.scope = "sibling";
|
|
661
|
-
return this;
|
|
662
|
-
}
|
|
663
|
-
// ==================== PRESENT: BASED ON FIELD PRESENCE ====================
|
|
664
|
-
/**
|
|
665
|
-
* Field must be present if another field exists
|
|
666
|
-
*/
|
|
667
|
-
presentWith(field, errorMessage) {
|
|
668
|
-
const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
|
|
669
|
-
rule.context.options.field = field;
|
|
670
|
-
rule.context.options.scope = "global";
|
|
671
|
-
return this;
|
|
672
|
-
}
|
|
673
|
-
/**
|
|
674
|
-
* Field must be present if another sibling field exists
|
|
675
|
-
*/
|
|
676
|
-
presentWithSibling(field, errorMessage) {
|
|
677
|
-
const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
|
|
678
|
-
rule.context.options.field = field;
|
|
679
|
-
rule.context.options.scope = "sibling";
|
|
680
|
-
return this;
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Field must be present if another field is missing
|
|
684
|
-
*/
|
|
685
|
-
presentWithout(field, errorMessage) {
|
|
686
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
|
|
687
|
-
rule.context.options.field = field;
|
|
688
|
-
rule.context.options.scope = "global";
|
|
689
|
-
return this;
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Field must be present if another sibling field is missing
|
|
693
|
-
*/
|
|
694
|
-
presentWithoutSibling(field, errorMessage) {
|
|
695
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
|
|
696
|
-
rule.context.options.field = field;
|
|
697
|
-
rule.context.options.scope = "sibling";
|
|
698
|
-
return this;
|
|
699
|
-
}
|
|
700
|
-
// ==================== PRESENT: BASED ON FIELD VALUE ====================
|
|
701
|
-
/**
|
|
702
|
-
* Field must be present if another field equals a specific value
|
|
703
|
-
*/
|
|
704
|
-
presentIf(field, value, errorMessage) {
|
|
705
|
-
const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
|
|
706
|
-
rule.context.options.field = field;
|
|
707
|
-
rule.context.options.value = value;
|
|
708
|
-
rule.context.options.scope = "global";
|
|
709
|
-
return this;
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Field must be present if another sibling field equals a specific value
|
|
713
|
-
*/
|
|
714
|
-
presentIfSibling(field, value, errorMessage) {
|
|
715
|
-
const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
|
|
716
|
-
rule.context.options.field = field;
|
|
717
|
-
rule.context.options.value = value;
|
|
718
|
-
rule.context.options.scope = "sibling";
|
|
719
|
-
return this;
|
|
720
|
-
}
|
|
721
|
-
/**
|
|
722
|
-
* Field must be present unless another field equals a specific value
|
|
723
|
-
*/
|
|
724
|
-
presentUnless(field, value, errorMessage) {
|
|
725
|
-
const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
|
|
726
|
-
rule.context.options.field = field;
|
|
727
|
-
rule.context.options.value = value;
|
|
728
|
-
rule.context.options.scope = "global";
|
|
729
|
-
return this;
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* Field must be present unless another sibling field equals a specific value
|
|
733
|
-
*/
|
|
734
|
-
presentUnlessSibling(field, value, errorMessage) {
|
|
735
|
-
const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
|
|
736
|
-
rule.context.options.field = field;
|
|
737
|
-
rule.context.options.value = value;
|
|
738
|
-
rule.context.options.scope = "sibling";
|
|
739
|
-
return this;
|
|
740
|
-
}
|
|
741
|
-
// ==================== PRESENT: BASED ON FIELD EMPTY STATE ====================
|
|
742
|
-
/**
|
|
743
|
-
* Field must be present if another field is empty
|
|
744
|
-
*/
|
|
745
|
-
presentIfEmpty(field, errorMessage) {
|
|
746
|
-
const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
|
|
747
|
-
rule.context.options.field = field;
|
|
748
|
-
rule.context.options.scope = "global";
|
|
749
|
-
return this;
|
|
750
|
-
}
|
|
751
|
-
/**
|
|
752
|
-
* Field must be present if another sibling field is empty
|
|
753
|
-
*/
|
|
754
|
-
presentIfEmptySibling(field, errorMessage) {
|
|
755
|
-
const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
|
|
756
|
-
rule.context.options.field = field;
|
|
757
|
-
rule.context.options.scope = "sibling";
|
|
758
|
-
return this;
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Field must be present if another field is not empty
|
|
762
|
-
*/
|
|
763
|
-
presentIfNotEmpty(field, errorMessage) {
|
|
764
|
-
const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
|
|
765
|
-
rule.context.options.field = field;
|
|
766
|
-
rule.context.options.scope = "global";
|
|
767
|
-
return this;
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Field must be present if another sibling field is not empty
|
|
771
|
-
*/
|
|
772
|
-
presentIfNotEmptySibling(field, errorMessage) {
|
|
773
|
-
const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
|
|
774
|
-
rule.context.options.field = field;
|
|
775
|
-
rule.context.options.scope = "sibling";
|
|
776
|
-
return this;
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Field must be present if another field's value is in the given array
|
|
780
|
-
*/
|
|
781
|
-
presentIfIn(field, values, errorMessage) {
|
|
782
|
-
const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
|
|
783
|
-
rule.context.options.field = field;
|
|
784
|
-
rule.context.options.values = values;
|
|
785
|
-
rule.context.options.scope = "global";
|
|
786
|
-
return this;
|
|
787
|
-
}
|
|
788
|
-
/**
|
|
789
|
-
* Field must be present if another sibling field's value is in the given array
|
|
790
|
-
*/
|
|
791
|
-
presentIfInSibling(field, values, errorMessage) {
|
|
792
|
-
const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
|
|
793
|
-
rule.context.options.field = field;
|
|
794
|
-
rule.context.options.values = values;
|
|
795
|
-
rule.context.options.scope = "sibling";
|
|
796
|
-
return this;
|
|
797
|
-
}
|
|
798
|
-
/**
|
|
799
|
-
* Field must be present if another field's value is NOT in the given array
|
|
800
|
-
*/
|
|
801
|
-
presentIfNotIn(field, values, errorMessage) {
|
|
802
|
-
const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
|
|
803
|
-
rule.context.options.field = field;
|
|
804
|
-
rule.context.options.values = values;
|
|
805
|
-
rule.context.options.scope = "global";
|
|
806
|
-
return this;
|
|
807
|
-
}
|
|
808
|
-
/**
|
|
809
|
-
* Field must be present if another sibling field's value is NOT in the given array
|
|
810
|
-
*/
|
|
811
|
-
presentIfNotInSibling(field, values, errorMessage) {
|
|
812
|
-
const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
|
|
813
|
-
rule.context.options.field = field;
|
|
814
|
-
rule.context.options.values = values;
|
|
815
|
-
rule.context.options.scope = "sibling";
|
|
816
|
-
return this;
|
|
817
|
-
}
|
|
818
|
-
// ==================== PRESENT: BASED ON MULTIPLE FIELDS (ALL) ====================
|
|
819
|
-
/**
|
|
820
|
-
* Field must be present if all specified fields exist
|
|
821
|
-
*/
|
|
822
|
-
presentWithAll(fields, errorMessage) {
|
|
823
|
-
const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
|
|
824
|
-
rule.context.options.fields = fields;
|
|
825
|
-
rule.context.options.scope = "global";
|
|
826
|
-
return this;
|
|
827
|
-
}
|
|
828
|
-
/**
|
|
829
|
-
* Field must be present if all specified sibling fields exist
|
|
830
|
-
*/
|
|
831
|
-
presentWithAllSiblings(fields, errorMessage) {
|
|
832
|
-
const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
|
|
833
|
-
rule.context.options.fields = fields;
|
|
834
|
-
rule.context.options.scope = "sibling";
|
|
835
|
-
return this;
|
|
836
|
-
}
|
|
837
|
-
/**
|
|
838
|
-
* Field must be present if all specified fields are missing
|
|
839
|
-
*/
|
|
840
|
-
presentWithoutAll(fields, errorMessage) {
|
|
841
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
|
|
842
|
-
rule.context.options.fields = fields;
|
|
843
|
-
rule.context.options.scope = "global";
|
|
844
|
-
return this;
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Field must be present if all specified sibling fields are missing
|
|
848
|
-
*/
|
|
849
|
-
presentWithoutAllSiblings(fields, errorMessage) {
|
|
850
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
|
|
851
|
-
rule.context.options.fields = fields;
|
|
852
|
-
rule.context.options.scope = "sibling";
|
|
853
|
-
return this;
|
|
854
|
-
}
|
|
855
|
-
// ==================== PRESENT: BASED ON MULTIPLE FIELDS (ANY) ====================
|
|
856
|
-
/**
|
|
857
|
-
* Field must be present if any of the specified fields exists
|
|
858
|
-
*/
|
|
859
|
-
presentWithAny(fields, errorMessage) {
|
|
860
|
-
const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
|
|
861
|
-
rule.context.options.fields = fields;
|
|
862
|
-
rule.context.options.scope = "global";
|
|
863
|
-
return this;
|
|
864
|
-
}
|
|
865
|
-
/**
|
|
866
|
-
* Field must be present if any of the specified sibling fields exists
|
|
867
|
-
*/
|
|
868
|
-
presentWithAnySiblings(fields, errorMessage) {
|
|
869
|
-
const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
|
|
870
|
-
rule.context.options.fields = fields;
|
|
871
|
-
rule.context.options.scope = "sibling";
|
|
872
|
-
return this;
|
|
873
|
-
}
|
|
874
|
-
/**
|
|
875
|
-
* Field must be present if any of the specified fields is missing
|
|
876
|
-
*/
|
|
877
|
-
presentWithoutAny(fields, errorMessage) {
|
|
878
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
|
|
879
|
-
rule.context.options.fields = fields;
|
|
880
|
-
rule.context.options.scope = "global";
|
|
881
|
-
return this;
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Field must be present if any of the specified sibling fields is missing
|
|
885
|
-
*/
|
|
886
|
-
presentWithoutAnySiblings(fields, errorMessage) {
|
|
887
|
-
const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
|
|
888
|
-
rule.context.options.fields = fields;
|
|
889
|
-
rule.context.options.scope = "sibling";
|
|
890
|
-
return this;
|
|
891
|
-
}
|
|
892
|
-
/**
|
|
893
|
-
* Mutate the data
|
|
894
|
-
*/
|
|
895
|
-
async mutate(data, context) {
|
|
896
|
-
let mutatedData = data;
|
|
897
|
-
for (const mutator of this.mutators) {
|
|
898
|
-
mutator.context.ctx = context;
|
|
899
|
-
mutatedData = await mutator.mutate(mutatedData, mutator.context);
|
|
900
|
-
}
|
|
901
|
-
return mutatedData;
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Value is forbidden to be present
|
|
905
|
-
*/
|
|
906
|
-
forbidden(errorMessage) {
|
|
907
|
-
this.addRule(forbidden.forbiddenRule, errorMessage);
|
|
908
|
-
return this;
|
|
909
|
-
}
|
|
910
|
-
/**
|
|
911
|
-
* Value is forbidden if another field equals a specific value (global scope)
|
|
912
|
-
*/
|
|
913
|
-
forbiddenIf(field, value, errorMessage) {
|
|
914
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfRule, errorMessage);
|
|
915
|
-
rule.context.options.field = field;
|
|
916
|
-
rule.context.options.value = value;
|
|
917
|
-
rule.context.options.scope = "global";
|
|
918
|
-
return this;
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Value is forbidden if another field equals a specific value (sibling scope)
|
|
922
|
-
*/
|
|
923
|
-
forbiddenIfSibling(field, value, errorMessage) {
|
|
924
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfRule, errorMessage);
|
|
925
|
-
rule.context.options.field = field;
|
|
926
|
-
rule.context.options.value = value;
|
|
927
|
-
rule.context.options.scope = "sibling";
|
|
928
|
-
return this;
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Value is forbidden if another field does NOT equal a specific value (global scope)
|
|
932
|
-
*/
|
|
933
|
-
forbiddenIfNot(field, value, errorMessage) {
|
|
934
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotRule, errorMessage);
|
|
935
|
-
rule.context.options.field = field;
|
|
936
|
-
rule.context.options.value = value;
|
|
937
|
-
rule.context.options.scope = "global";
|
|
938
|
-
return this;
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* Value is forbidden if another field does NOT equal a specific value (sibling scope)
|
|
942
|
-
*/
|
|
943
|
-
forbiddenIfNotSibling(field, value, errorMessage) {
|
|
944
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotRule, errorMessage);
|
|
945
|
-
rule.context.options.field = field;
|
|
946
|
-
rule.context.options.value = value;
|
|
947
|
-
rule.context.options.scope = "sibling";
|
|
948
|
-
return this;
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* Value is forbidden if another field is empty (global scope)
|
|
952
|
-
*/
|
|
953
|
-
forbiddenIfEmpty(field, errorMessage) {
|
|
954
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfEmptyRule, errorMessage);
|
|
955
|
-
rule.context.options.field = field;
|
|
956
|
-
rule.context.options.scope = "global";
|
|
957
|
-
return this;
|
|
958
|
-
}
|
|
959
|
-
/**
|
|
960
|
-
* Value is forbidden if another field is empty (sibling scope)
|
|
961
|
-
*/
|
|
962
|
-
forbiddenIfEmptySibling(field, errorMessage) {
|
|
963
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfEmptyRule, errorMessage);
|
|
964
|
-
rule.context.options.field = field;
|
|
965
|
-
rule.context.options.scope = "sibling";
|
|
966
|
-
return this;
|
|
967
|
-
}
|
|
968
|
-
/**
|
|
969
|
-
* Value is forbidden if another field is not empty (global scope)
|
|
970
|
-
*/
|
|
971
|
-
forbiddenIfNotEmpty(field, errorMessage) {
|
|
972
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotEmptyRule, errorMessage);
|
|
973
|
-
rule.context.options.field = field;
|
|
974
|
-
rule.context.options.scope = "global";
|
|
975
|
-
return this;
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Value is forbidden if another field is not empty (sibling scope)
|
|
979
|
-
*/
|
|
980
|
-
forbiddenIfNotEmptySibling(field, errorMessage) {
|
|
981
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotEmptyRule, errorMessage);
|
|
982
|
-
rule.context.options.field = field;
|
|
983
|
-
rule.context.options.scope = "sibling";
|
|
984
|
-
return this;
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Value is forbidden if another field's value is in the given array (global scope)
|
|
988
|
-
*/
|
|
989
|
-
forbiddenIfIn(field, values, errorMessage) {
|
|
990
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfInRule, errorMessage);
|
|
991
|
-
rule.context.options.field = field;
|
|
992
|
-
rule.context.options.values = values;
|
|
993
|
-
rule.context.options.scope = "global";
|
|
994
|
-
return this;
|
|
995
|
-
}
|
|
996
|
-
/**
|
|
997
|
-
* Value is forbidden if another field's value is in the given array (sibling scope)
|
|
998
|
-
*/
|
|
999
|
-
forbiddenIfInSibling(field, values, errorMessage) {
|
|
1000
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfInRule, errorMessage);
|
|
1001
|
-
rule.context.options.field = field;
|
|
1002
|
-
rule.context.options.values = values;
|
|
1003
|
-
rule.context.options.scope = "sibling";
|
|
1004
|
-
return this;
|
|
1005
|
-
}
|
|
1006
|
-
/**
|
|
1007
|
-
* Value is forbidden if another field's value is NOT in the given array (global scope)
|
|
1008
|
-
*/
|
|
1009
|
-
forbiddenIfNotIn(field, values, errorMessage) {
|
|
1010
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotInRule, errorMessage);
|
|
1011
|
-
rule.context.options.field = field;
|
|
1012
|
-
rule.context.options.values = values;
|
|
1013
|
-
rule.context.options.scope = "global";
|
|
1014
|
-
return this;
|
|
1015
|
-
}
|
|
1016
|
-
/**
|
|
1017
|
-
* Value is forbidden if another field's value is NOT in the given array (sibling scope)
|
|
1018
|
-
*/
|
|
1019
|
-
forbiddenIfNotInSibling(field, values, errorMessage) {
|
|
1020
|
-
const rule = this.addRule(forbiddenIfRules.forbiddenIfNotInRule, errorMessage);
|
|
1021
|
-
rule.context.options.field = field;
|
|
1022
|
-
rule.context.options.values = values;
|
|
1023
|
-
rule.context.options.scope = "sibling";
|
|
1024
|
-
return this;
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* Apply different validation rules based on another field's value (global scope)
|
|
1028
|
-
*
|
|
1029
|
-
* Use this when you need to apply completely different validators
|
|
1030
|
-
* based on another field's value (not just required/optional).
|
|
1031
|
-
*
|
|
1032
|
-
* @param field - Field name to check (can be nested with dot notation)
|
|
1033
|
-
* @param options - Validation options per field value
|
|
1034
|
-
*
|
|
1035
|
-
* @example
|
|
1036
|
-
* ```ts
|
|
1037
|
-
* // Different allowed values based on user type
|
|
1038
|
-
* v.object({
|
|
1039
|
-
* userType: v.string().in(['admin', 'user']),
|
|
1040
|
-
* role: v.string().when('userType', {
|
|
1041
|
-
* is: {
|
|
1042
|
-
* admin: v.string().in(['super', 'moderator']),
|
|
1043
|
-
* user: v.string().in(['member', 'guest'])
|
|
1044
|
-
* },
|
|
1045
|
-
* otherwise: v.string().optional()
|
|
1046
|
-
* })
|
|
1047
|
-
* })
|
|
1048
|
-
*
|
|
1049
|
-
* // Different validation rules based on type
|
|
1050
|
-
* v.object({
|
|
1051
|
-
* contactType: v.string().in(['email', 'phone']),
|
|
1052
|
-
* contact: v.string().when('contactType', {
|
|
1053
|
-
* is: {
|
|
1054
|
-
* email: v.string().email(),
|
|
1055
|
-
* phone: v.string().pattern(/^\d{10}$/)
|
|
1056
|
-
* }
|
|
1057
|
-
* })
|
|
1058
|
-
* })
|
|
1059
|
-
* ```
|
|
1060
|
-
* @category Conditional Validation
|
|
1061
|
-
*/
|
|
1062
|
-
when(field, options) {
|
|
1063
|
-
const rule = this.addRule(when.whenRule);
|
|
1064
|
-
rule.context.options.field = field;
|
|
1065
|
-
rule.context.options.is = options.is;
|
|
1066
|
-
rule.context.options.otherwise = options.otherwise;
|
|
1067
|
-
rule.context.options.scope = "global";
|
|
1068
|
-
return this;
|
|
1069
|
-
}
|
|
1070
|
-
/**
|
|
1071
|
-
* Apply different validation rules based on sibling field's value
|
|
1072
|
-
*
|
|
1073
|
-
* Use this for nested objects where you need to check a field
|
|
1074
|
-
* within the same parent object.
|
|
1075
|
-
*
|
|
1076
|
-
* @param siblingField - Sibling field name to check
|
|
1077
|
-
* @param options - Validation options per field value
|
|
1078
|
-
*
|
|
1079
|
-
* @example
|
|
1080
|
-
* ```ts
|
|
1081
|
-
* // Array of users with role-based permissions
|
|
1082
|
-
* v.array(v.object({
|
|
1083
|
-
* userType: v.string().in(['admin', 'user']),
|
|
1084
|
-
* permissions: v.string().whenSibling('userType', {
|
|
1085
|
-
* is: {
|
|
1086
|
-
* admin: v.string().in(['read', 'write', 'delete']),
|
|
1087
|
-
* user: v.string().in(['read'])
|
|
1088
|
-
* }
|
|
1089
|
-
* })
|
|
1090
|
-
* }))
|
|
1091
|
-
* ```
|
|
1092
|
-
* @category Conditional Validation
|
|
1093
|
-
*/
|
|
1094
|
-
whenSibling(siblingField, options) {
|
|
1095
|
-
const rule = this.addRule(when.whenRule);
|
|
1096
|
-
rule.context.options.field = siblingField;
|
|
1097
|
-
rule.context.options.is = options.is;
|
|
1098
|
-
rule.context.options.otherwise = options.otherwise;
|
|
1099
|
-
rule.context.options.scope = "sibling";
|
|
1100
|
-
return this;
|
|
1101
|
-
}
|
|
1102
|
-
/**
|
|
1103
|
-
* Set the label for the validator that will be matching the :input attribute
|
|
1104
|
-
*/
|
|
1105
|
-
label(label) {
|
|
1106
|
-
this.attributesText.input = label;
|
|
1107
|
-
return this;
|
|
1108
|
-
}
|
|
1109
|
-
/**
|
|
1110
|
-
* Validate the data
|
|
1111
|
-
*/
|
|
1112
|
-
async validate(data, context) {
|
|
1113
|
-
if (data === null && this.isNullable) {
|
|
1114
|
-
return { isValid: true, errors: [], data: null };
|
|
1115
|
-
}
|
|
1116
|
-
const valueForMutation = data ?? this.defaultValue;
|
|
1117
|
-
const mutatedData = await this.mutate(valueForMutation, context);
|
|
1118
|
-
const valueForRules = valueForMutation;
|
|
1119
|
-
const errors = [];
|
|
1120
|
-
let isValid = true;
|
|
1121
|
-
const isFirstErrorOnly = context.configurations?.firstErrorOnly ?? true;
|
|
1122
|
-
for (const rule of this.rules) {
|
|
1123
|
-
if ((rule.requiresValue ?? true) && supportiveIs.isEmpty(valueForRules))
|
|
1124
|
-
continue;
|
|
1125
|
-
this.setRuleAttributesList(rule);
|
|
1126
|
-
const result = await rule.validate(mutatedData, context);
|
|
1127
|
-
if (result.isValid === false) {
|
|
1128
|
-
isValid = false;
|
|
1129
|
-
errors.push({
|
|
1130
|
-
type: rule.name,
|
|
1131
|
-
error: result.error,
|
|
1132
|
-
input: result.path ?? context.path,
|
|
1133
|
-
});
|
|
1134
|
-
if (isFirstErrorOnly) {
|
|
1135
|
-
break;
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
return {
|
|
1140
|
-
isValid,
|
|
1141
|
-
errors,
|
|
1142
|
-
data: await this.startTransformationPipeline(mutatedData, context),
|
|
1143
|
-
};
|
|
1144
|
-
}
|
|
1145
|
-
/**
|
|
1146
|
-
* Set rule attributes list
|
|
1147
|
-
*/
|
|
1148
|
-
setRuleAttributesList(rule) {
|
|
1149
|
-
rule.context.attributesList =
|
|
1150
|
-
typeof this.attributesText[rule.name] === "object"
|
|
1151
|
-
? this.attributesText[rule.name]
|
|
1152
|
-
: this.attributesText;
|
|
1153
|
-
}
|
|
1154
|
-
}exports.BaseValidator=BaseValidator;//# sourceMappingURL=base-validator.js.map
|