/** * @module json-schema */ /** @pratico/json-schema */ import ajv from 'ajv'; import { EventEmitter, Listener } from './typed-event-emitter'; import { ValidatorConfig } from './models/validator-config'; import { JsonSchema } from './models/draft-06'; import { ValidationResult } from './models/validation-result'; /** * PraticoJsonSchemaValidator allows to setup ajvObject and run the tests through ajv * needs import * as ajv from 'ajv'; * @export * @class PraticoJsonSchemaValidator */ export declare class Validator extends EventEmitter { /** * Allows to set a listener to the onValidated event * * @type {{ * (handler: { (newValue: ValidationResult): any }): Listener; * }} * @memberof Validator */ onValidated: { (handler: { (newValue: ValidationResult): any; }): Listener; }; /** * Allows to set a listener to the onError event * * @type {{ * (handler: { (newValue: Error): any }): Listener; * }} * @memberof Validator */ onError: { (handler: { (newValue: Error): any; }): Listener; }; /** * ajvInstance stores the ajv instance being used to validated * * @private * @type {ajv.Ajv} * @memberof Validator */ private ajvInstance; private executionId; /** * stores the configuration passed to the validator instance through the {@link constructor} * * @type {ValidatorConfig} * @memberof Validator */ private config; /** * Creates an instance of PraticoJsonSchemaValidator. * @param {ValidatorConfig} config * * @memberof {@link Validator} */ constructor(config: ValidatorConfig, ajv: { new (options?: ajv.Options): ajv.Ajv; }); /** * Updates the validator current schema * @param {string} id * @param {any} schema * * @memberof Validator */ updateSchema(id: string, schema: any): void; /** * Adds a schema to the validator * * @param {string} id * @param {*} schema * * @memberof Validator */ addSchema(id: string, schema: JsonSchema): void; /** * Returns a schema, given a $id or $ref * * @param {string} keyRef * @returns {JsonSchema} * * @memberof Validator */ getSchema(keyRef: string): JsonSchema | undefined; /** * Removes a schema from the validator * * @param {string} id * * @memberof Validator */ removeSchema(id: string): void; /** * Validate some data using some schema loaded into ajv * * @param {string} schemaId The id which will be used to validate the data * @param {*} data The data to be validated * @returns {number} the execution id * * @memberof PraticoJsonSchemaValidator */ validate(schemaId: string | JsonSchema, data: any, callback?: { (res: ValidationResult): void; }): number; addFormat(name: string, format: ajv.FormatDefinition | RegExp): void; private loadSchemasKeywordsAndFormats; }