{
  "version": 3,
  "sources": ["../../../src/field-types/utils/get-is-valid.ts"],
  "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { Field, NormalizedRules } from '../../types';\nimport type { FieldType } from '../../types/private';\n\nfunction supportsNumericRangeConstraint( type?: string ) {\n\treturn type === 'integer' || type === 'number';\n}\n\nfunction supportsDateRangeConstraint( type?: string ) {\n\treturn type === 'date' || type === 'datetime';\n}\n\nfunction normalizeRangeRule< Item >(\n\tvalue: number | string | undefined,\n\tfieldType: FieldType< Item >,\n\tkey: 'min' | 'max'\n): NormalizedRules< Item >[ 'min' ] {\n\tconst validator = fieldType.validate[ key ];\n\tif (\n\t\tvalidator &&\n\t\t( ( typeof value === 'number' &&\n\t\t\tsupportsNumericRangeConstraint( fieldType.type ) ) ||\n\t\t\t( typeof value === 'string' &&\n\t\t\t\tsupportsDateRangeConstraint( fieldType.type ) ) )\n\t) {\n\t\treturn { constraint: value, validate: validator } as NonNullable<\n\t\t\tNormalizedRules< Item >[ typeof key ]\n\t\t>;\n\t}\n\treturn undefined;\n}\n\nexport default function getIsValid< Item >(\n\tfield: Field< Item >,\n\tfieldType: FieldType< Item >\n): NormalizedRules< Item > {\n\tconst rules = field.isValid;\n\tlet required;\n\tif (\n\t\trules?.required === true &&\n\t\tfieldType.validate.required !== undefined\n\t) {\n\t\trequired = {\n\t\t\tconstraint: true,\n\t\t\tvalidate: fieldType.validate.required,\n\t\t};\n\t}\n\n\tlet elements;\n\tif (\n\t\t( rules?.elements === true ||\n\t\t\t// elements is enabled unless the field opts-out\n\t\t\t( rules?.elements === undefined &&\n\t\t\t\t( !! field.elements || !! field.getElements ) ) ) &&\n\t\tfieldType.validate.elements !== undefined\n\t) {\n\t\telements = {\n\t\t\tconstraint: true,\n\t\t\tvalidate: fieldType.validate.elements,\n\t\t};\n\t}\n\n\tconst min = normalizeRangeRule( rules?.min, fieldType, 'min' );\n\tconst max = normalizeRangeRule( rules?.max, fieldType, 'max' );\n\n\tconst minLengthValue = rules?.minLength;\n\tlet minLength;\n\tif (\n\t\ttypeof minLengthValue === 'number' &&\n\t\tfieldType.validate.minLength !== undefined\n\t) {\n\t\tminLength = {\n\t\t\tconstraint: minLengthValue,\n\t\t\tvalidate: fieldType.validate.minLength,\n\t\t};\n\t}\n\n\tconst maxLengthValue = rules?.maxLength;\n\tlet maxLength;\n\tif (\n\t\ttypeof maxLengthValue === 'number' &&\n\t\tfieldType.validate.maxLength !== undefined\n\t) {\n\t\tmaxLength = {\n\t\t\tconstraint: maxLengthValue,\n\t\t\tvalidate: fieldType.validate.maxLength,\n\t\t};\n\t}\n\n\tconst patternValue = rules?.pattern;\n\tlet pattern;\n\tif (\n\t\tpatternValue !== undefined &&\n\t\tfieldType.validate.pattern !== undefined\n\t) {\n\t\tpattern = {\n\t\t\tconstraint: patternValue,\n\t\t\tvalidate: fieldType.validate.pattern,\n\t\t};\n\t}\n\n\tconst custom = rules?.custom ?? fieldType.validate.custom;\n\n\treturn {\n\t\trequired,\n\t\telements,\n\t\tmin,\n\t\tmax,\n\t\tminLength,\n\t\tmaxLength,\n\t\tpattern,\n\t\tcustom,\n\t};\n}\n"],
  "mappings": ";AAMA,SAAS,+BAAgC,MAAgB;AACxD,SAAO,SAAS,aAAa,SAAS;AACvC;AAEA,SAAS,4BAA6B,MAAgB;AACrD,SAAO,SAAS,UAAU,SAAS;AACpC;AAEA,SAAS,mBACR,OACA,WACA,KACmC;AACnC,QAAM,YAAY,UAAU,SAAU,GAAI;AAC1C,MACC,cACI,OAAO,UAAU,YACpB,+BAAgC,UAAU,IAAK,KAC7C,OAAO,UAAU,YAClB,4BAA6B,UAAU,IAAK,IAC7C;AACD,WAAO,EAAE,YAAY,OAAO,UAAU,UAAU;AAAA,EAGjD;AACA,SAAO;AACR;AAEe,SAAR,WACN,OACA,WAC0B;AAC1B,QAAM,QAAQ,MAAM;AACpB,MAAI;AACJ,MACC,OAAO,aAAa,QACpB,UAAU,SAAS,aAAa,QAC/B;AACD,eAAW;AAAA,MACV,YAA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