UNPKG

@sjsf/ajv8-validator

Version:

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

44 lines (43 loc) 2.61 kB
import { Ajv, type AsyncValidateFunction, type Options, type ValidateFunction } from "ajv"; import type { AsyncFieldValueValidator, AsyncFormValueValidator, Config, Schema, FieldValueValidator, FormValueValidator, Validator } from "@sjsf/form"; import { type ValidatorsCache } from "./schema-compilers.js"; import { type ErrorsTransformerOptions } from "./errors.js"; export interface ValidatorOptions { compileSchema: (schema: Schema, rootSchema: Schema) => ValidateFunction; } export declare function createValidator({ compileSchema, }: ValidatorOptions): Validator; export interface FormValueValidatorOptions extends ValidatorOptions, ErrorsTransformerOptions { } export declare function createFormValueValidator<T>(options: FormValueValidatorOptions): FormValueValidator<T>; export interface FieldValueValidatorOptions { compileFieldSchema: (config: Config) => ValidateFunction; } export declare function createFieldValueValidator({ compileFieldSchema, }: FieldValueValidatorOptions): FieldValueValidator; export interface AsyncFormValueValidatorOptions extends ErrorsTransformerOptions { compileAsyncSchema: (schema: Schema, rootSchema: Schema) => AsyncValidateFunction; } export declare function createAsyncFormValueValidator<T>(options: AsyncFormValueValidatorOptions): AsyncFormValueValidator<T>; export interface AsyncFieldValueValidatorOptions { compileAsyncFieldSchema: (config: Config) => AsyncValidateFunction; } export declare function createAsyncFieldValueValidator({ compileAsyncFieldSchema, }: AsyncFieldValueValidatorOptions): AsyncFieldValueValidator; export interface FormValidatorOptions extends ValidatorOptions, FormValueValidatorOptions, FieldValueValidatorOptions { } export declare function createFormValidator<T>({ ajvOptions, ajvPlugins, ajv, validatorsCache, compileSchema, compileFieldSchema, ...rest }?: Partial<FormValidatorOptions> & { /** * @default `DEFAULT_AJV_CONFIG` */ ajvOptions?: Options; /** * @default `addFormComponents` */ ajvPlugins?: (ajv: Ajv) => Ajv; ajv?: Ajv; validatorsCache?: ValidatorsCache; }): Validator & FormValueValidator<T> & FieldValueValidator; export interface AsyncFormValidatorOptions extends ValidatorOptions, AsyncFormValueValidatorOptions, AsyncFieldValueValidatorOptions { } export declare function createAsyncFormValidator<T>({ ajv, validatorsCache, compileSchema, compileAsyncSchema, compileAsyncFieldSchema, ...rest }: Partial<AsyncFormValidatorOptions> & { ajv: Ajv; validatorsCache?: ValidatorsCache; }): Validator & AsyncFormValueValidator<T> & AsyncFieldValueValidator;