|
| 1 | +import type { Options, Ajv, ValidateFunction, AsyncValidateFunction } from "ajv"; |
| 2 | +import type { UiSchemaRoot, Schema, Config } from '@sjsf/form' |
| 3 | +import type { AsyncValidator, Validator } from '@sjsf/ajv8-validator' |
| 4 | + |
| 5 | +interface AbstractValidatorOptions { |
| 6 | + ajv: Ajv; |
| 7 | + /** |
| 8 | + * Necessary for correct inference of the field title |
| 9 | + * @default {} |
| 10 | + */ |
| 11 | + uiSchema?: UiSchemaRoot; |
| 12 | + /** @default DEFAULT_ID_PREFIX */ |
| 13 | + idPrefix?: string; |
| 14 | + /** @default DEFAULT_ID_SEPARATOR */ |
| 15 | + idSeparator?: string; |
| 16 | + /** @default DEFAULT_PSEUDO_ID_SEPARATOR */ |
| 17 | + idPseudoSeparator?: string; |
| 18 | +} |
| 19 | + |
| 20 | +interface ValidatorOptions extends AbstractValidatorOptions { |
| 21 | + /** @default makeSchemaCompiler(ajv, false) */ |
| 22 | + compileSchema?: (schema: Schema, rootSchema: Schema) => ValidateFunction; |
| 23 | + /** @default makeFieldSchemaCompiler(ajv, false) */ |
| 24 | + compileFieldSchema?: (config: Config) => ValidateFunction; |
| 25 | +} |
| 26 | + |
| 27 | +type FactoryOptions<O> = Omit<O, "ajv"> & { |
| 28 | + /** @default DEFAULT_AJV_CONFIG */ |
| 29 | + ajvOptions?: Options; |
| 30 | + /** @default addFormComponents(new Ajv(ajvOptions)) */ |
| 31 | + ajv?: Ajv; |
| 32 | +}; |
| 33 | + |
| 34 | +function createValidator2(options?: FactoryOptions<ValidatorOptions>): Validator |
| 35 | + |
| 36 | +interface AsyncValidatorOptions extends AbstractValidatorOptions { |
| 37 | + /** @default makeSchemaCompiler(ajv, false) */ |
| 38 | + compileSchema?: (schema: Schema, rootSchema: Schema) => ValidateFunction; |
| 39 | + /** @default makeSchemaCompiler(ajv, true) */ |
| 40 | + compileAsyncSchema?: ( |
| 41 | + schema: Schema, |
| 42 | + rootSchema: Schema |
| 43 | + ) => AsyncValidateFunction; |
| 44 | + /** @default makeFieldSchemaCompiler(ajv, true) */ |
| 45 | + compileAsyncFieldSchema?: (config: Config) => AsyncValidateFunction; |
| 46 | +} |
| 47 | + |
| 48 | +function createAsyncValidator(options?: FactoryOptions<AsyncValidatorOptions>): AsyncValidator |
0 commit comments