import { JsonSchema, JsonSchemaAnyBuilder } from '@naturalcycles/js-lib'; import Ajv from 'ajv'; import { AjvValidationError } from './ajvValidationError'; export interface AjvValidationOptions { objectName?: string; objectId?: string; /** * @default to cfg.logErrors, which defaults to true */ logErrors?: boolean; /** * Used to separate multiple validation errors. * * @default cfg.separator || '\n' */ separator?: string; } export interface AjvSchemaCfg { /** * Pass Ajv instance, otherwise Ajv will be created with * AjvSchema default (not the same as Ajv defaults) parameters */ ajv: Ajv; /** * Dependent schemas to pass to Ajv instance constructor. * Simpler than instantiating and passing ajv instance yourself. */ schemas?: any[]; objectName?: string; /** * Used to separate multiple validation errors. * * @default '\n' */ separator: string; /** * @default true */ logErrors: boolean; } /** * On creation - compiles ajv validation function. * Provides convenient methods, error reporting, etc. * * @experimental */ export declare class AjvSchema { constructor(schema: JsonSchema | JsonSchemaAnyBuilder, cfg?: Partial); /** * Create AjvSchema directly from a filePath of json schema. * Convenient method that just does fs.readFileSync for you. */ static readJsonSync(filePath: string, cfg?: Partial): AjvSchema; readonly cfg: AjvSchemaCfg; private readonly validateFunction; validate(obj: T, opt?: AjvValidationOptions): void; getValidationError(obj: T, opt?: AjvValidationOptions): AjvValidationError | undefined; isValid(obj: T): boolean; }