@rjsf/validator-ajv8 5.6.2 → 5.7.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"validator-ajv8.esm.js","sources":["../src/createAjvInstance.ts","../src/validator.ts","../src/customizeValidator.ts","../src/index.ts"],"sourcesContent":["import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n ValidationData,\n validationDataMerge,\n ValidatorType,\n withIdRefPrefix,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n * @protected\n */\n protected transformRJSFValidationErrors(\n errors: ErrorObject[] = [],\n uiSchema?: UiSchema<T, S, F>\n ): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: RJSFSchema, formData?: T): { errors?: Result[]; validationError?: Error } {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema['$id']) {\n compiledValidator = this.ajv.getSchema(schema['$id']);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = this.transformRJSFValidationErrors(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(this, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema['$id'] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix['$id']) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);\n }\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import customizeValidator from './customizeValidator';\n\nexport { customizeValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","ajv","_extends","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","AJV8Validator","options","localizer","_proto","prototype","toErrorList","errorSchema","fieldPath","transformRJSFValidationErrors","errors","uiSchema","map","e","instancePath","keyword","params","schemaPath","parentSchema","rest","_objectWithoutPropertiesLoose","_excluded","_rest$message","message","property","replace","stack","trim","missingProperty","currentProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","rawValidation","schema","formData","compilationError","undefined","compiledValidator","getSchema","compile","err","validationError","validateFormData","customValidate","transformErrors","rawErrors","invalidSchemaError","concat","toErrorSchema","$schema","__errors","newFormData","getDefaultFormState","errorHandler","createErrorHandler","userErrorSchema","unwrapErrorHandler","validationDataMerge","isValid","rootSchema","_rootSchema$$id","rootSchemaId","ROOT_SCHEMA_PREFIX","addSchema","schemaWithIdRefPrefix","withIdRefPrefix","result","console","warn","removeSchema","customizeValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOO,IAAMA,UAAU,GAAY;AACjCC,EAAAA,SAAS,EAAE,IAAI;AACfC,EAAAA,mBAAmB,EAAE,CAAC;AACtBC,EAAAA,MAAM,EAAE,KAAK;AACbC,EAAAA,OAAO,EAAE,IAAA;CACD,CAAA;AACH,IAAMC,kBAAkB,GAC7B,4YAA4Y,CAAA;AACvY,IAAMC,qBAAqB,GAAG,2DAA2D,CAAA;AAEhG;;;;;;;;;;;;;;AAcG;AACqB,SA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AAA;AACb,KAAA,SAAS;AACR;AACA;AACA,MAAA,IAAI,CAAC3B,GAAG,CAACwF,YAAY,CAACR,YAAY,CAAC,CAAA;AACpC,KAAA;GACF,CAAA;AAAA,EAAA,OAAAjE,aAAA,CAAA;AAAA,CAAA,EAAA;;ACvPH;;;;;AAKG;AACqB,SAAA0E,kBAAkBA,CAIxCzE,OAAsC,EAAIC,SAAqB,EAAA;AAAA,EAAA,IAA/DD,OAAsC,KAAA,KAAA,CAAA,EAAA;IAAtCA,OAAsC,GAAA,EAAE,CAAA;AAAA,GAAA;AACxC,EAAA,OAAO,IAAID,aAAa,CAAUC,OAAO,EAAEC,SAAS,CAAC,CAAA;AACvD;;ACZA,YAAA,aAAewE,kBAAkB,EAAE;;;;"}
1
+ {"version":3,"file":"validator-ajv8.esm.js","sources":["../src/createAjvInstance.ts","../src/processRawValidationErrors.ts","../src/validator.ts","../src/customizeValidator.ts","../src/precompiledValidator.ts","../src/createPrecompiledValidator.ts","../src/index.ts"],"sourcesContent":["import Ajv, { Options } from 'ajv';\nimport addFormats, { FormatsPluginOptions } from 'ajv-formats';\nimport isObject from 'lodash/isObject';\n\nimport { CustomValidatorOptionsType } from './types';\nimport { ADDITIONAL_PROPERTY_FLAG, RJSF_ADDITONAL_PROPERTIES_FLAG } from '@rjsf/utils';\n\nexport const AJV_CONFIG: Options = {\n allErrors: true,\n multipleOfPrecision: 8,\n strict: false,\n verbose: true,\n} as const;\nexport const COLOR_FORMAT_REGEX =\n /^(#?([0-9A-Fa-f]{3}){1,2}\\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\\(\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*,\\s*\\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\b\\s*\\))|(rgb\\(\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*,\\s*(\\d?\\d%|100%)+\\s*\\)))$/;\nexport const DATA_URL_FORMAT_REGEX = /^data:([a-z]+\\/[a-z0-9-+.]+)?;(?:name=(.*);)?base64,(.*)$/;\n\n/** Creates an Ajv version 8 implementation object with standard support for the 'color` and `data-url` custom formats.\n * If `additionalMetaSchemas` are provided then the Ajv instance is modified to add each of the meta schemas in the\n * list. If `customFormats` are provided then those additional formats are added to the list of supported formats. If\n * `ajvOptionsOverrides` are provided then they are spread on top of the default `AJV_CONFIG` options when constructing\n * the `Ajv` instance. With Ajv v8, the JSON Schema formats are not provided by default, but can be plugged in. By\n * default, all formats from the `ajv-formats` library are added. To disable this capability, set the `ajvFormatOptions`\n * parameter to `false`. Additionally, you can configure the `ajv-formats` by providing a custom set of\n * [format options](https://github.com/ajv-validator/ajv-formats) to the `ajvFormatOptions` parameter.\n *\n * @param [additionalMetaSchemas] - The list of additional meta schemas that the validator can access\n * @param [customFormats] - The set of additional custom formats that the validator will support\n * @param [ajvOptionsOverrides={}] - The set of validator config override options\n * @param [ajvFormatOptions] - The `ajv-format` options to use when adding formats to `ajv`; pass `false` to disable it\n * @param [AjvClass] - The `Ajv` class to use when creating the validator instance\n */\nexport default function createAjvInstance(\n additionalMetaSchemas?: CustomValidatorOptionsType['additionalMetaSchemas'],\n customFormats?: CustomValidatorOptionsType['customFormats'],\n ajvOptionsOverrides: CustomValidatorOptionsType['ajvOptionsOverrides'] = {},\n ajvFormatOptions?: FormatsPluginOptions | false,\n AjvClass: typeof Ajv = Ajv\n) {\n const ajv = new AjvClass({ ...AJV_CONFIG, ...ajvOptionsOverrides });\n if (ajvFormatOptions) {\n addFormats(ajv, ajvFormatOptions);\n } else if (ajvFormatOptions !== false) {\n addFormats(ajv);\n }\n\n // add custom formats\n ajv.addFormat('data-url', DATA_URL_FORMAT_REGEX);\n ajv.addFormat('color', COLOR_FORMAT_REGEX);\n\n // Add RJSF-specific additional properties keywords so Ajv doesn't report errors if strict is enabled.\n ajv.addKeyword(ADDITIONAL_PROPERTY_FLAG);\n ajv.addKeyword(RJSF_ADDITONAL_PROPERTIES_FLAG);\n\n // add more schemas to validate against\n if (Array.isArray(additionalMetaSchemas)) {\n ajv.addMetaSchema(additionalMetaSchemas);\n }\n\n // add more custom formats to validate against\n if (isObject(customFormats)) {\n Object.keys(customFormats).forEach((formatName) => {\n ajv.addFormat(formatName, customFormats[formatName]);\n });\n }\n\n return ajv;\n}\n","import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport {\n createErrorHandler,\n CustomValidator,\n ErrorTransformer,\n FormContextType,\n getDefaultFormState,\n getUiOptions,\n PROPERTIES_KEY,\n RJSFSchema,\n RJSFValidationError,\n StrictRJSFSchema,\n toErrorSchema,\n UiSchema,\n unwrapErrorHandler,\n validationDataMerge,\n ValidatorType,\n} from '@rjsf/utils';\n\nexport type RawValidationErrorsType<Result = any> = { errors?: Result[]; validationError?: Error };\n\n/** Transforming the error output from ajv to format used by @rjsf/utils.\n * At some point, components should be updated to support ajv.\n *\n * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport function transformRJSFValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(errors: ErrorObject[] = [], uiSchema?: UiSchema<T, S, F>): RJSFValidationError[] {\n return errors.map((e: ErrorObject) => {\n const { instancePath, keyword, params, schemaPath, parentSchema, ...rest } = e;\n let { message = '' } = rest;\n let property = instancePath.replace(/\\//g, '.');\n let stack = `${property} ${message}`.trim();\n\n if ('missingProperty' in params) {\n property = property ? `${property}.${params.missingProperty}` : params.missingProperty;\n const currentProperty: string = params.missingProperty;\n const uiSchemaTitle = getUiOptions(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n message = message.replace(currentProperty, uiSchemaTitle);\n } else {\n const parentSchemaTitle = get(parentSchema, [PROPERTIES_KEY, currentProperty, 'title']);\n\n if (parentSchemaTitle) {\n message = message.replace(currentProperty, parentSchemaTitle);\n }\n }\n\n stack = message;\n } else {\n const uiSchemaTitle = getUiOptions<T, S, F>(get(uiSchema, `${property.replace(/^\\./, '')}`)).title;\n\n if (uiSchemaTitle) {\n stack = `'${uiSchemaTitle}' ${message}`.trim();\n } else {\n const parentSchemaTitle = parentSchema?.title;\n\n if (parentSchemaTitle) {\n stack = `'${parentSchemaTitle}' ${message}`.trim();\n }\n }\n }\n\n // put data in expected format\n return {\n name: keyword,\n property,\n message,\n params, // specific to ajv\n stack,\n schemaPath,\n };\n });\n}\n\n/** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call\n * @param rawErrors - The list of raw `ErrorObject`s to process\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\nexport default function processRawValidationErrors<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(\n validator: ValidatorType<T, S, F>,\n rawErrors: RawValidationErrorsType<ErrorObject>,\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n) {\n const { validationError: invalidSchemaError } = rawErrors;\n let errors = transformRJSFValidationErrors<T, S, F>(rawErrors.errors, uiSchema);\n\n if (invalidSchemaError) {\n errors = [...errors, { stack: invalidSchemaError!.message }];\n }\n if (typeof transformErrors === 'function') {\n errors = transformErrors(errors, uiSchema);\n }\n\n let errorSchema = toErrorSchema<T>(errors);\n\n if (invalidSchemaError) {\n errorSchema = {\n ...errorSchema,\n $schema: {\n __errors: [invalidSchemaError!.message],\n },\n };\n }\n\n if (typeof customValidate !== 'function') {\n return { errors, errorSchema };\n }\n\n // Include form data with undefined values, which is required for custom validation.\n const newFormData = getDefaultFormState<T, S, F>(validator, schema, formData, schema, true) as T;\n\n const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);\n const userErrorSchema = unwrapErrorHandler<T>(errorHandler);\n return validationDataMerge<T>({ errors, errorSchema }, userErrorSchema);\n}\n","import Ajv, { ErrorObject, ValidateFunction } from 'ajv';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n ID_KEY,\n RJSFSchema,\n ROOT_SCHEMA_PREFIX,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n withIdRefPrefix,\n} from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport createAjvInstance from './createAjvInstance';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses the AJV 8 validation mechanism.\n */\nexport default class AJV8Validator<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>\n implements ValidatorType<T, S, F>\n{\n /** The AJV instance to use for all validations\n *\n * @private\n */\n private ajv: Ajv;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8Validator` instance using the `options`\n *\n * @param options - The `CustomValidatorOptionsType` options that are used to create the AJV instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n */\n constructor(options: CustomValidatorOptionsType, localizer?: Localizer) {\n const { additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass } = options;\n this.ajv = createAjvInstance(additionalMetaSchemas, customFormats, ajvOptionsOverrides, ajvFormatOptions, AjvClass);\n this.localizer = localizer;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n let compilationError: Error | undefined = undefined;\n let compiledValidator: ValidateFunction | undefined;\n if (schema[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schema[ID_KEY]);\n }\n try {\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schema);\n }\n compiledValidator(formData);\n } catch (err) {\n compilationError = err as Error;\n }\n\n let errors;\n if (compiledValidator) {\n if (typeof this.localizer === 'function') {\n this.localizer(compiledValidator.errors);\n }\n errors = compiledValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n compiledValidator.errors = null;\n }\n\n return {\n errors: errors as unknown as Result[],\n validationError: compilationError,\n };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or\n * false otherwise. If the schema is invalid, then this function will return\n * false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n const rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;\n try {\n // add the rootSchema ROOT_SCHEMA_PREFIX as id.\n // then rewrite the schema ref's to point to the rootSchema\n // this accounts for the case where schema have references to models\n // that lives in the rootSchema but not in the schema in question.\n if (this.ajv.getSchema(rootSchemaId) === undefined) {\n this.ajv.addSchema(rootSchema, rootSchemaId);\n }\n const schemaWithIdRefPrefix = withIdRefPrefix<S>(schema) as S;\n let compiledValidator: ValidateFunction | undefined;\n if (schemaWithIdRefPrefix[ID_KEY]) {\n compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[ID_KEY]);\n }\n if (compiledValidator === undefined) {\n compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);\n }\n const result = compiledValidator(formData);\n return result as boolean;\n } catch (e) {\n console.warn('Error encountered compiling schema:', e);\n return false;\n } finally {\n // TODO: A function should be called if the root schema changes so we don't have to remove and recompile the schema every run.\n // make sure we remove the rootSchema from the global ajv instance\n this.ajv.removeSchema(rootSchemaId);\n }\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { CustomValidatorOptionsType, Localizer } from './types';\nimport AJV8Validator from './validator';\n\n/** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if\n * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV\n * validation.\n *\n * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The custom validator implementation resulting from the set of parameters provided\n */\nexport default function customizeValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(options: CustomValidatorOptionsType = {}, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8Validator<T, S, F>(options, localizer);\n}\n","import { ErrorObject } from 'ajv';\nimport get from 'lodash/get';\nimport isEqual from 'lodash/isEqual';\nimport {\n CustomValidator,\n ErrorSchema,\n ErrorTransformer,\n FormContextType,\n hashForSchema,\n ID_KEY,\n RJSFSchema,\n StrictRJSFSchema,\n toErrorList,\n UiSchema,\n ValidationData,\n ValidatorType,\n} from '@rjsf/utils';\n\nimport { CompiledValidateFunction, Localizer, ValidatorFunctions } from './types';\nimport processRawValidationErrors, { RawValidationErrorsType } from './processRawValidationErrors';\n\n/** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the\n * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.\n */\nexport default class AJV8PrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n> implements ValidatorType<T, S, F>\n{\n /** The root schema object used to construct this validator\n *\n * @private\n */\n readonly rootSchema: S;\n\n /** The `ValidatorFunctions` map used to construct this validator\n *\n * @private\n */\n readonly validateFns: ValidatorFunctions<T>;\n\n /** The main validator function associated with the base schema in the `precompiledValidator`\n *\n * @private\n */\n readonly mainValidator: CompiledValidateFunction<T>;\n\n /** The Localizer function to use for localizing Ajv errors\n *\n * @private\n */\n readonly localizer?: Localizer;\n\n /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`\n *\n * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function\n * @param rootSchema - The root schema that was used with the `compileSchema()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @throws - Error when the base schema of the precompiled validator does not have a matching validator function\n */\n constructor(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer) {\n this.rootSchema = rootSchema;\n this.validateFns = validateFns;\n this.localizer = localizer;\n this.mainValidator = this.getValidator(rootSchema);\n }\n\n /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator\n * functions.\n *\n * @param schema - The schema for which a precompiled validator function is desired\n * @returns - The precompiled validator function associated with this schema\n */\n getValidator(schema: S) {\n const key = get(schema, ID_KEY) || hashForSchema(schema);\n const validator = this.validateFns[key];\n if (!validator) {\n throw new Error(`No precompiled validator function was found for the given schema for \"${key}\"`);\n }\n return validator;\n }\n\n /** Converts an `errorSchema` into a list of `RJSFValidationErrors`\n *\n * @param errorSchema - The `ErrorSchema` instance to convert\n * @param [fieldPath=[]] - The current field path, defaults to [] if not specified\n * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in\n * the next major release.\n */\n toErrorList(errorSchema?: ErrorSchema<T>, fieldPath: string[] = []) {\n return toErrorList(errorSchema, fieldPath);\n }\n\n /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use\n * by the playground. Returns the `errors` from the validation\n *\n * @param schema - The schema against which to validate the form data * @param schema\n * @param formData - The form data to validate\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator\n */\n rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {\n if (!isEqual(schema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled schema differs from the schema provided for validation'\n );\n }\n this.mainValidator(formData);\n\n if (typeof this.localizer === 'function') {\n this.localizer(this.mainValidator.errors);\n }\n const errors = this.mainValidator.errors || undefined;\n\n // Clear errors to prevent persistent errors, see #1104\n this.mainValidator.errors = null;\n\n return { errors: errors as unknown as Result[] };\n }\n\n /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives\n * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also\n * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and\n * transform them in what ever way it chooses.\n *\n * @param formData - The form data to validate\n * @param schema - The schema against which to validate the form data\n * @param [customValidate] - An optional function that is used to perform custom validation\n * @param [transformErrors] - An optional function that is used to transform errors after AJV validation\n * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`\n */\n validateFormData(\n formData: T | undefined,\n schema: S,\n customValidate?: CustomValidator<T, S, F>,\n transformErrors?: ErrorTransformer<T, S, F>,\n uiSchema?: UiSchema<T, S, F>\n ): ValidationData<T> {\n const rawErrors = this.rawValidation<ErrorObject>(schema, formData);\n return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);\n }\n\n /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is\n * invalid, then this function will return false.\n *\n * @param schema - The schema against which to validate the form data\n * @param formData - The form data to validate\n * @param rootSchema - The root schema used to provide $ref resolutions\n * @returns - true if the formData validates against the schema, false otherwise\n * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there\n * isn't a precompiled validator function associated with the schema\n */\n isValid(schema: S, formData: T | undefined, rootSchema: S) {\n if (!isEqual(rootSchema, this.rootSchema)) {\n throw new Error(\n 'The schema associated with the precompiled validator differs from the rootSchema provided for validation'\n );\n }\n const validator = this.getValidator(schema);\n return validator(formData);\n }\n}\n","import { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from '@rjsf/utils';\n\nimport { Localizer, ValidatorFunctions } from './types';\nimport AJV8PrecompiledValidator from './precompiledValidator';\n\n/** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`\n * is provided, it is used to translate the messages generated by the underlying AJV validation.\n *\n * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via\n * the `compileSchemaValidators()` function.\n *\n * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function\n * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function\n * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s\n * @returns - The precompiled validator implementation resulting from the set of parameters provided\n */\nexport default function createPrecompiledValidator<\n T = any,\n S extends StrictRJSFSchema = RJSFSchema,\n F extends FormContextType = any\n>(validateFns: ValidatorFunctions<T>, rootSchema: S, localizer?: Localizer): ValidatorType<T, S, F> {\n return new AJV8PrecompiledValidator<T, S, F>(validateFns, rootSchema, localizer);\n}\n","import customizeValidator from './customizeValidator';\nimport createPrecompiledValidator from './createPrecompiledValidator';\n\nexport { customizeValidator, createPrecompiledValidator };\nexport * from './types';\n\nexport default customizeValidator();\n"],"names":["AJV_CONFIG","allErrors","multipleOfPrecision","strict","verbose","COLOR_FORMAT_REGEX","DATA_URL_FORMAT_REGEX","createAjvInstance","additionalMetaSchemas","customFormats","ajvOptionsOverrides","ajvFormatOptions","AjvClass","Ajv","ajv","_extends","addFormats","addFormat","addKeyword","ADDITIONAL_PROPERTY_FLAG","RJSF_ADDITONAL_PROPERTIES_FLAG","Array","isArray","addMetaSchema","isObject","Object","keys","forEach","formatName","transformRJSFValidationErrors","errors","uiSchema","map","e","instancePath","keyword","params","schemaPath","parentSchema","rest","_objectWithoutPropertiesLoose","_excluded","_rest$message","message","property","replace","stack","trim","missingProperty","currentProperty","uiSchemaTitle","getUiOptions","get","title","parentSchemaTitle","PROPERTIES_KEY","name","processRawValidationErrors","validator","rawErrors","formData","schema","customValidate","transformErrors","invalidSchemaError","validationError","concat","errorSchema","toErrorSchema","$schema","__errors","newFormData","getDefaultFormState","errorHandler","createErrorHandler","userErrorSchema","unwrapErrorHandler","validationDataMerge","AJV8Validator","options","localizer","_proto","prototype","toErrorList","fieldPath","rawValidation","compilationError","undefined","compiledValidator","ID_KEY","getSchema","compile","err","validateFormData","isValid","rootSchema","_rootSchema$ID_KEY","rootSchemaId","ROOT_SCHEMA_PREFIX","addSchema","schemaWithIdRefPrefix","withIdRefPrefix","result","console","warn","removeSchema","customizeValidator","AJV8PrecompiledValidator","validateFns","mainValidator","getValidator","key","hashForSchema","Error","isEqual","createPrecompiledValidator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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,KAAK,CACb,0GAA0G,CAC3G,CAAA;AACF,KAAA;AACD,IAAA,IAAMvD,SAAS,GAAG,IAAI,CAACoD,YAAY,CAACjD,MAAM,CAAC,CAAA;IAC3C,OAAOH,SAAS,CAACE,QAAQ,CAAC,CAAA;GAC3B,CAAA;AAAA,EAAA,OAAA+C,wBAAA,CAAA;AAAA,CAAA,EAAA;;AC3JH;;;;;;;;;;AAUG;AACqB,SAAAQ,0BAA0BA,CAIhDP,WAAkC,EAAEb,UAAa,EAAEf,SAAqB,EAAA;EACxE,OAAO,IAAI2B,wBAAwB,CAAUC,WAAW,EAAEb,UAAU,EAAEf,SAAS,CAAC,CAAA;AAClF;;AChBA,YAAe0B,aAAAA,kBAAkB,EAAE;;;;"}
@@ -1,15 +1,16 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lodash-es/get'), require('@rjsf/utils'), require('ajv'), require('ajv-formats'), require('lodash-es/isObject')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lodash-es/get', '@rjsf/utils', 'ajv', 'ajv-formats', 'lodash-es/isObject'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/validator-ajv8"] = {}, global.get, global.utils, global.Ajv, global.addFormats, global.isObject));
5
- })(this, (function (exports, get, utils, Ajv, addFormats, isObject) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@rjsf/utils'), require('ajv'), require('ajv-formats'), require('lodash-es/isObject'), require('lodash-es/get'), require('lodash-es/isEqual')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@rjsf/utils', 'ajv', 'ajv-formats', 'lodash-es/isObject', 'lodash-es/get', 'lodash-es/isEqual'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@rjsf/validator-ajv8"] = {}, global.utils, global.Ajv, global.addFormats, global.isObject, global.get, global.isEqual));
5
+ })(this, (function (exports, utils, Ajv, addFormats, isObject, get, isEqual) { 'use strict';
6
6
 
7
7
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
8
 
9
- var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
10
9
  var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
11
10
  var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
12
11
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
12
+ var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
13
+ var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
13
14
 
14
15
  function _extends() {
15
16
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -94,6 +95,110 @@
94
95
  }
95
96
 
96
97
  var _excluded = ["instancePath", "keyword", "params", "schemaPath", "parentSchema"];
98
+ /** Transforming the error output from ajv to format used by @rjsf/utils.
99
+ * At some point, components should be updated to support ajv.
100
+ *
101
+ * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
102
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
103
+ */
104
+ function transformRJSFValidationErrors(errors, uiSchema) {
105
+ if (errors === void 0) {
106
+ errors = [];
107
+ }
108
+ return errors.map(function (e) {
109
+ var instancePath = e.instancePath,
110
+ keyword = e.keyword,
111
+ params = e.params,
112
+ schemaPath = e.schemaPath,
113
+ parentSchema = e.parentSchema,
114
+ rest = _objectWithoutPropertiesLoose(e, _excluded);
115
+ var _rest$message = rest.message,
116
+ message = _rest$message === void 0 ? '' : _rest$message;
117
+ var property = instancePath.replace(/\//g, '.');
118
+ var stack = (property + " " + message).trim();
119
+ if ('missingProperty' in params) {
120
+ property = property ? property + "." + params.missingProperty : params.missingProperty;
121
+ var currentProperty = params.missingProperty;
122
+ var uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
123
+ if (uiSchemaTitle) {
124
+ message = message.replace(currentProperty, uiSchemaTitle);
125
+ } else {
126
+ var parentSchemaTitle = get__default["default"](parentSchema, [utils.PROPERTIES_KEY, currentProperty, 'title']);
127
+ if (parentSchemaTitle) {
128
+ message = message.replace(currentProperty, parentSchemaTitle);
129
+ }
130
+ }
131
+ stack = message;
132
+ } else {
133
+ var _uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
134
+ if (_uiSchemaTitle) {
135
+ stack = ("'" + _uiSchemaTitle + "' " + message).trim();
136
+ } else {
137
+ var _parentSchemaTitle = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title;
138
+ if (_parentSchemaTitle) {
139
+ stack = ("'" + _parentSchemaTitle + "' " + message).trim();
140
+ }
141
+ }
142
+ }
143
+ // put data in expected format
144
+ return {
145
+ name: keyword,
146
+ property: property,
147
+ message: message,
148
+ params: params,
149
+ stack: stack,
150
+ schemaPath: schemaPath
151
+ };
152
+ });
153
+ }
154
+ /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
155
+ * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
156
+ * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
157
+ * transform them in what ever way it chooses.
158
+ *
159
+ * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call
160
+ * @param rawErrors - The list of raw `ErrorObject`s to process
161
+ * @param formData - The form data to validate
162
+ * @param schema - The schema against which to validate the form data
163
+ * @param [customValidate] - An optional function that is used to perform custom validation
164
+ * @param [transformErrors] - An optional function that is used to transform errors after AJV validation
165
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
166
+ */
167
+ function processRawValidationErrors(validator, rawErrors, formData, schema, customValidate, transformErrors, uiSchema) {
168
+ var invalidSchemaError = rawErrors.validationError;
169
+ var errors = transformRJSFValidationErrors(rawErrors.errors, uiSchema);
170
+ if (invalidSchemaError) {
171
+ errors = [].concat(errors, [{
172
+ stack: invalidSchemaError.message
173
+ }]);
174
+ }
175
+ if (typeof transformErrors === 'function') {
176
+ errors = transformErrors(errors, uiSchema);
177
+ }
178
+ var errorSchema = utils.toErrorSchema(errors);
179
+ if (invalidSchemaError) {
180
+ errorSchema = _extends({}, errorSchema, {
181
+ $schema: {
182
+ __errors: [invalidSchemaError.message]
183
+ }
184
+ });
185
+ }
186
+ if (typeof customValidate !== 'function') {
187
+ return {
188
+ errors: errors,
189
+ errorSchema: errorSchema
190
+ };
191
+ }
192
+ // Include form data with undefined values, which is required for custom validation.
193
+ var newFormData = utils.getDefaultFormState(validator, schema, formData, schema, true);
194
+ var errorHandler = customValidate(newFormData, utils.createErrorHandler(newFormData), uiSchema);
195
+ var userErrorSchema = utils.unwrapErrorHandler(errorHandler);
196
+ return utils.validationDataMerge({
197
+ errors: errors,
198
+ errorSchema: errorSchema
199
+ }, userErrorSchema);
200
+ }
201
+
97
202
  /** `ValidatorType` implementation that uses the AJV 8 validation mechanism.
98
203
  */
99
204
  var AJV8Validator = /*#__PURE__*/function () {
@@ -135,63 +240,6 @@
135
240
  }
136
241
  return utils.toErrorList(errorSchema, fieldPath);
137
242
  }
138
- /** Transforming the error output from ajv to format used by @rjsf/utils.
139
- * At some point, components should be updated to support ajv.
140
- *
141
- * @param errors - The list of AJV errors to convert to `RJSFValidationErrors`
142
- * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
143
- * @protected
144
- */;
145
- _proto.transformRJSFValidationErrors = function transformRJSFValidationErrors(errors, uiSchema) {
146
- if (errors === void 0) {
147
- errors = [];
148
- }
149
- return errors.map(function (e) {
150
- var instancePath = e.instancePath,
151
- keyword = e.keyword,
152
- params = e.params,
153
- schemaPath = e.schemaPath,
154
- parentSchema = e.parentSchema,
155
- rest = _objectWithoutPropertiesLoose(e, _excluded);
156
- var _rest$message = rest.message,
157
- message = _rest$message === void 0 ? '' : _rest$message;
158
- var property = instancePath.replace(/\//g, '.');
159
- var stack = (property + " " + message).trim();
160
- if ('missingProperty' in params) {
161
- property = property ? property + "." + params.missingProperty : params.missingProperty;
162
- var currentProperty = params.missingProperty;
163
- var uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
164
- if (uiSchemaTitle) {
165
- message = message.replace(currentProperty, uiSchemaTitle);
166
- } else {
167
- var parentSchemaTitle = get__default["default"](parentSchema, [utils.PROPERTIES_KEY, currentProperty, 'title']);
168
- if (parentSchemaTitle) {
169
- message = message.replace(currentProperty, parentSchemaTitle);
170
- }
171
- }
172
- stack = message;
173
- } else {
174
- var _uiSchemaTitle = utils.getUiOptions(get__default["default"](uiSchema, "" + property.replace(/^\./, ''))).title;
175
- if (_uiSchemaTitle) {
176
- stack = ("'" + _uiSchemaTitle + "' " + message).trim();
177
- } else {
178
- var _parentSchemaTitle = parentSchema === null || parentSchema === void 0 ? void 0 : parentSchema.title;
179
- if (_parentSchemaTitle) {
180
- stack = ("'" + _parentSchemaTitle + "' " + message).trim();
181
- }
182
- }
183
- }
184
- // put data in expected format
185
- return {
186
- name: keyword,
187
- property: property,
188
- message: message,
189
- params: params,
190
- stack: stack,
191
- schemaPath: schemaPath
192
- };
193
- });
194
- }
195
243
  /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
196
244
  * by the playground. Returns the `errors` from the validation
197
245
  *
@@ -201,8 +249,8 @@
201
249
  _proto.rawValidation = function rawValidation(schema, formData) {
202
250
  var compilationError = undefined;
203
251
  var compiledValidator;
204
- if (schema['$id']) {
205
- compiledValidator = this.ajv.getSchema(schema['$id']);
252
+ if (schema[utils.ID_KEY]) {
253
+ compiledValidator = this.ajv.getSchema(schema[utils.ID_KEY]);
206
254
  }
207
255
  try {
208
256
  if (compiledValidator === undefined) {
@@ -239,38 +287,7 @@
239
287
  */;
240
288
  _proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
241
289
  var rawErrors = this.rawValidation(schema, formData);
242
- var invalidSchemaError = rawErrors.validationError;
243
- var errors = this.transformRJSFValidationErrors(rawErrors.errors, uiSchema);
244
- if (invalidSchemaError) {
245
- errors = [].concat(errors, [{
246
- stack: invalidSchemaError.message
247
- }]);
248
- }
249
- if (typeof transformErrors === 'function') {
250
- errors = transformErrors(errors, uiSchema);
251
- }
252
- var errorSchema = utils.toErrorSchema(errors);
253
- if (invalidSchemaError) {
254
- errorSchema = _extends({}, errorSchema, {
255
- $schema: {
256
- __errors: [invalidSchemaError.message]
257
- }
258
- });
259
- }
260
- if (typeof customValidate !== 'function') {
261
- return {
262
- errors: errors,
263
- errorSchema: errorSchema
264
- };
265
- }
266
- // Include form data with undefined values, which is required for custom validation.
267
- var newFormData = utils.getDefaultFormState(this, schema, formData, schema, true);
268
- var errorHandler = customValidate(newFormData, utils.createErrorHandler(newFormData), uiSchema);
269
- var userErrorSchema = utils.unwrapErrorHandler(errorHandler);
270
- return utils.validationDataMerge({
271
- errors: errors,
272
- errorSchema: errorSchema
273
- }, userErrorSchema);
290
+ return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);
274
291
  }
275
292
  /** Validates data against a schema, returning true if the data is valid, or
276
293
  * false otherwise. If the schema is invalid, then this function will return
@@ -281,8 +298,8 @@
281
298
  * @param rootSchema - The root schema used to provide $ref resolutions
282
299
  */;
283
300
  _proto.isValid = function isValid(schema, formData, rootSchema) {
284
- var _rootSchema$$id;
285
- var rootSchemaId = (_rootSchema$$id = rootSchema['$id']) != null ? _rootSchema$$id : utils.ROOT_SCHEMA_PREFIX;
301
+ var _rootSchema$ID_KEY;
302
+ var rootSchemaId = (_rootSchema$ID_KEY = rootSchema[utils.ID_KEY]) != null ? _rootSchema$ID_KEY : utils.ROOT_SCHEMA_PREFIX;
286
303
  try {
287
304
  // add the rootSchema ROOT_SCHEMA_PREFIX as id.
288
305
  // then rewrite the schema ref's to point to the rootSchema
@@ -293,8 +310,8 @@
293
310
  }
294
311
  var schemaWithIdRefPrefix = utils.withIdRefPrefix(schema);
295
312
  var compiledValidator;
296
- if (schemaWithIdRefPrefix['$id']) {
297
- compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix['$id']);
313
+ if (schemaWithIdRefPrefix[utils.ID_KEY]) {
314
+ compiledValidator = this.ajv.getSchema(schemaWithIdRefPrefix[utils.ID_KEY]);
298
315
  }
299
316
  if (compiledValidator === undefined) {
300
317
  compiledValidator = this.ajv.compile(schemaWithIdRefPrefix);
@@ -314,10 +331,12 @@
314
331
  }();
315
332
 
316
333
  /** Creates and returns a customized implementation of the `ValidatorType` with the given customization `options` if
317
- * provided.
334
+ * provided. If a `localizer` is provided, it is used to translate the messages generated by the underlying AJV
335
+ * validation.
318
336
  *
319
337
  * @param [options={}] - The `CustomValidatorOptionsType` options that are used to create the `ValidatorType` instance
320
338
  * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
339
+ * @returns - The custom validator implementation resulting from the set of parameters provided
321
340
  */
322
341
  function customizeValidator(options, localizer) {
323
342
  if (options === void 0) {
@@ -326,8 +345,146 @@
326
345
  return new AJV8Validator(options, localizer);
327
346
  }
328
347
 
348
+ /** `ValidatorType` implementation that uses an AJV 8 precompiled validator as created by the
349
+ * `compileSchemaValidators()` function provided by the `@rjsf/validator-ajv8` library.
350
+ */
351
+ var AJV8PrecompiledValidator = /*#__PURE__*/function () {
352
+ /** Constructs an `AJV8PrecompiledValidator` instance using the `validateFns` and `rootSchema`
353
+ *
354
+ * @param validateFns - The map of the validation functions that are generated by the `schemaCompile()` function
355
+ * @param rootSchema - The root schema that was used with the `compileSchema()` function
356
+ * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
357
+ * @throws - Error when the base schema of the precompiled validator does not have a matching validator function
358
+ */
359
+ function AJV8PrecompiledValidator(validateFns, rootSchema, localizer) {
360
+ /** The root schema object used to construct this validator
361
+ *
362
+ * @private
363
+ */
364
+ this.rootSchema = void 0;
365
+ /** The `ValidatorFunctions` map used to construct this validator
366
+ *
367
+ * @private
368
+ */
369
+ this.validateFns = void 0;
370
+ /** The main validator function associated with the base schema in the `precompiledValidator`
371
+ *
372
+ * @private
373
+ */
374
+ this.mainValidator = void 0;
375
+ /** The Localizer function to use for localizing Ajv errors
376
+ *
377
+ * @private
378
+ */
379
+ this.localizer = void 0;
380
+ this.rootSchema = rootSchema;
381
+ this.validateFns = validateFns;
382
+ this.localizer = localizer;
383
+ this.mainValidator = this.getValidator(rootSchema);
384
+ }
385
+ /** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
386
+ * functions.
387
+ *
388
+ * @param schema - The schema for which a precompiled validator function is desired
389
+ * @returns - The precompiled validator function associated with this schema
390
+ */
391
+ var _proto = AJV8PrecompiledValidator.prototype;
392
+ _proto.getValidator = function getValidator(schema) {
393
+ var key = get__default["default"](schema, utils.ID_KEY) || utils.hashForSchema(schema);
394
+ var validator = this.validateFns[key];
395
+ if (!validator) {
396
+ throw new Error("No precompiled validator function was found for the given schema for \"" + key + "\"");
397
+ }
398
+ return validator;
399
+ }
400
+ /** Converts an `errorSchema` into a list of `RJSFValidationErrors`
401
+ *
402
+ * @param errorSchema - The `ErrorSchema` instance to convert
403
+ * @param [fieldPath=[]] - The current field path, defaults to [] if not specified
404
+ * @deprecated - Use the `toErrorList()` function provided by `@rjsf/utils` instead. This function will be removed in
405
+ * the next major release.
406
+ */;
407
+ _proto.toErrorList = function toErrorList(errorSchema, fieldPath) {
408
+ if (fieldPath === void 0) {
409
+ fieldPath = [];
410
+ }
411
+ return utils.toErrorList(errorSchema, fieldPath);
412
+ }
413
+ /** Runs the pure validation of the `schema` and `formData` without any of the RJSF functionality. Provided for use
414
+ * by the playground. Returns the `errors` from the validation
415
+ *
416
+ * @param schema - The schema against which to validate the form data * @param schema
417
+ * @param formData - The form data to validate
418
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator
419
+ */;
420
+ _proto.rawValidation = function rawValidation(schema, formData) {
421
+ if (!isEqual__default["default"](schema, this.rootSchema)) {
422
+ throw new Error('The schema associated with the precompiled schema differs from the schema provided for validation');
423
+ }
424
+ this.mainValidator(formData);
425
+ if (typeof this.localizer === 'function') {
426
+ this.localizer(this.mainValidator.errors);
427
+ }
428
+ var errors = this.mainValidator.errors || undefined;
429
+ // Clear errors to prevent persistent errors, see #1104
430
+ this.mainValidator.errors = null;
431
+ return {
432
+ errors: errors
433
+ };
434
+ }
435
+ /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives
436
+ * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also
437
+ * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and
438
+ * transform them in what ever way it chooses.
439
+ *
440
+ * @param formData - The form data to validate
441
+ * @param schema - The schema against which to validate the form data
442
+ * @param [customValidate] - An optional function that is used to perform custom validation
443
+ * @param [transformErrors] - An optional function that is used to transform errors after AJV validation
444
+ * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate`
445
+ */;
446
+ _proto.validateFormData = function validateFormData(formData, schema, customValidate, transformErrors, uiSchema) {
447
+ var rawErrors = this.rawValidation(schema, formData);
448
+ return processRawValidationErrors(this, rawErrors, formData, schema, customValidate, transformErrors, uiSchema);
449
+ }
450
+ /** Validates data against a schema, returning true if the data is valid, or false otherwise. If the schema is
451
+ * invalid, then this function will return false.
452
+ *
453
+ * @param schema - The schema against which to validate the form data
454
+ * @param formData - The form data to validate
455
+ * @param rootSchema - The root schema used to provide $ref resolutions
456
+ * @returns - true if the formData validates against the schema, false otherwise
457
+ * @throws - Error when the schema provided does not match the base schema of the precompiled validator OR if there
458
+ * isn't a precompiled validator function associated with the schema
459
+ */;
460
+ _proto.isValid = function isValid(schema, formData, rootSchema) {
461
+ if (!isEqual__default["default"](rootSchema, this.rootSchema)) {
462
+ throw new Error('The schema associated with the precompiled validator differs from the rootSchema provided for validation');
463
+ }
464
+ var validator = this.getValidator(schema);
465
+ return validator(formData);
466
+ };
467
+ return AJV8PrecompiledValidator;
468
+ }();
469
+
470
+ /** Creates and returns a `ValidatorType` interface that is implemented with a precompiled validator. If a `localizer`
471
+ * is provided, it is used to translate the messages generated by the underlying AJV validation.
472
+ *
473
+ * NOTE: The `validateFns` parameter is an object obtained by importing from a precompiled validation file created via
474
+ * the `compileSchemaValidators()` function.
475
+ *
476
+ * @param validateFns - The map of the validation functions that are created by the `compileSchemaValidators()` function
477
+ * @param rootSchema - The root schema that was used with the `compileSchemaValidators()` function
478
+ * @param [localizer] - If provided, is used to localize a list of Ajv `ErrorObject`s
479
+ * @returns - The precompiled validator implementation resulting from the set of parameters provided
480
+ */
481
+ function createPrecompiledValidator(validateFns, rootSchema, localizer) {
482
+ return new AJV8PrecompiledValidator(validateFns, rootSchema, localizer);
483
+ }
484
+
329
485
  var index = /*#__PURE__*/customizeValidator();
330
486
 
487
+ exports.createPrecompiledValidator = createPrecompiledValidator;
331
488
  exports.customizeValidator = customizeValidator;
332
489
  exports["default"] = index;
333
490