UNPKG

@sjsf/ajv8-validator

Version:

The ajv-8 based validator for svelte-jsonschema-form

19 lines (18 loc) 1.42 kB
import { type Config, type FailureValidationResult, type FormValue, type Schema, type UiSchemaRoot } from "@sjsf/form"; import { type AsyncValidateFunction, type ErrorObject, type ValidateFunction } from "ajv"; import type { CompiledValidateFunction } from "./internals.js"; export interface ErrorsTransformerOptions { uiSchema?: UiSchemaRoot; schema?: Schema; } export declare function createFormErrorsTransformer({ uiSchema, schema, }: ErrorsTransformerOptions): (errors: ErrorObject[], data: FormValue) => FailureValidationResult; export declare function createFieldErrorsTransformer(config: Config): (errors: ErrorObject[]) => string[]; export type TransformInput<T> = (data: FormValue) => T; export type TransformErrors<R> = (errors: ErrorObject[], data: FormValue) => R; export declare function validateAndTransformErrors<T, R>(validate: ValidateFunction | CompiledValidateFunction, data: FormValue, transformData: TransformInput<T>, transformErrors: TransformErrors<R>): T | R; export declare function validateAndTransformErrorsAsync<T, R>(validate: AsyncValidateFunction, data: FormValue, transformInput: TransformInput<T>, transformErrors: TransformErrors<R>): Promise<T | R>; export type Localize = TransformErrors<ErrorObject[]>; export interface LocalizeOptions { localize?: Localize; } export declare function withLocalize<R>(transform: TransformErrors<R>, localize?: Localize): TransformErrors<R>;