UNPKG

@rjsf/validator-ajv8

Version:
44 lines (43 loc) 3.5 kB
import type { CustomValidator, ErrorTransformer, FormContextType, RJSFSchema, RJSFValidationError, StrictRJSFSchema, UiSchema, ValidatorType } from '@rjsf/utils'; import type { ErrorObject } from 'ajv'; import type { SuppressDuplicateFilteringType } from './types.js'; export interface RawValidationErrorsType<Result = any> { errors?: Result[]; validationError?: Error; } /** Filters duplicate errors from `anyOf`/`oneOf` schema paths according to the `suppressDuplicateFiltering` flag. * * @param errorList - The list of `RJSFValidationError`s to filter * @param [suppressDuplicateFiltering='none'] - Controls which duplicate filtering is suppressed: * - `'none'` (default): filters duplicates for both `anyOf` and `oneOf` * - `'all'`: returns `errorList` unmodified * - `'anyOf'`: suppresses filtering for `anyOf` errors; `oneOf` duplicates are still filtered * - `'oneOf'`: suppresses filtering for `oneOf` errors; `anyOf` duplicates are still filtered */ export declare function filterDuplicateErrors(errorList: RJSFValidationError[], suppressDuplicateFiltering?: SuppressDuplicateFilteringType): RJSFValidationError[]; /** Transforming the error output from ajv to format used by @rjsf/utils. * At some point, components should be updated to support ajv. * * @param errors - The list of AJV errors to convert to `RJSFValidationErrors` * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate` * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors` */ export declare function transformRJSFValidationErrors<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(errors?: ErrorObject[], uiSchema?: UiSchema<T, S, F>, suppressDuplicateFiltering?: SuppressDuplicateFilteringType): RJSFValidationError[]; /** This function processes the `formData` with an optional user contributed `customValidate` function, which receives * the form data and a `errorHandler` function that will be used to add custom validation errors for each field. Also * supports a `transformErrors` function that will take the raw AJV validation errors, prior to custom validation and * transform them in what ever way it chooses. * * @param validator - The `ValidatorType` implementation used for the `getDefaultFormState()` call * @param rawErrors - The list of raw `ErrorObject`s to process * @param formData - The form data to validate * @param schema - The schema against which to validate the form data * @param [customValidate] - An optional function that is used to perform custom validation * @param [transformErrors] - An optional function that is used to transform errors after AJV validation * @param [uiSchema] - An optional uiSchema that is passed to `transformErrors` and `customValidate` * @param [suppressDuplicateFiltering] - Controls which duplicate filtering is suppressed; see `filterDuplicateErrors` */ export default function processRawValidationErrors<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, rawErrors: RawValidationErrorsType<ErrorObject>, formData: T | undefined, schema: S, customValidate?: CustomValidator<T, S, F>, transformErrors?: ErrorTransformer<T, S, F>, uiSchema?: UiSchema<T, S, F>, suppressDuplicateFiltering?: SuppressDuplicateFilteringType): { errors: RJSFValidationError[]; errorSchema: import("@rjsf/utils").ErrorSchema<T>; };