validatorFor(event) {
        // Extract the schemaUri for this event.
        const eventSchemaUri = this.extractSchemaUri(event);
        this.log.debug(`getting validator for event schema ${eventSchemaUri}`);

        // If this eventSchemaUri has been seen before, return the already compiled
        // and cached AJV validator.
        const validator = this.ajv.getSchema(eventSchemaUri);
        if (validator) {
            return P.resolve(validator);
        } else {
            // Else load the event's schema from its schema uri and compile it.
            return this.loadSchema(eventSchemaUri)
            // Wrap Event schema loading errors in EventSchemaLoadError
            .catch((error) => {
                throw new EventSchemaLoadError(
                    `Failed loading schema at ${eventSchemaUri}`,
                    { error, event_schema_uri: eventSchemaUri }
                );
            })
            .then((schema) => {
                return this.ajv.compileAsync(schema).then((validatorForEvent) => {
                    // Also cache this schema at uri if uri is different than schema.$id
                    // and this schema uri hasn't yet been added to the AJV cache
                    if (_.isUndefined(this.ajv.getSchema(eventSchemaUri))) {
                        this.log.debug(
                            `Additionally caching schema with $id ` +
                            `'${validatorForEvent.schema.$id}' by event schema URI ` +
                            `${eventSchemaUri}`
                        );
                        this.ajv.addSchema(validatorForEvent.schema, eventSchemaUri);
                    }
                    return validatorForEvent;
                });
            });
        }
    }
/**
     * Returns a promise of a validate function for the event.
     * If the event's schema URI or $id has been seen before, it should
     * be loaded from the AJV cache and not recompiled.
     * @param {Object} event
     * @return {Promise<function(Object) => Object}}
     */
Returns a promise of a validate function for the event.
If the event's schema URI or $id has been seen before, it should
be loaded from the AJV cache and not recompiled.
@param {Object} event
@return {Promise Object}}
Returns a promise of a validate function for the event . If the event ' s schema URI or $id has been seen before it should be loaded from the AJV cache and not recompiled . @param { Object } event @return { Promise Object }}
validatorFor(event) {
        const eventSchemaUri = this.extractSchemaUri(event);
        this.log.debug(`getting validator for event schema ${eventSchemaUri}`);
        const validator = this.ajv.getSchema(eventSchemaUri);
        if (validator) {
            return P.resolve(validator);
        } else {
            return this.loadSchema(eventSchemaUri)
            .catch((error) => {
                throw new EventSchemaLoadError(
                    `Failed loading schema at ${eventSchemaUri}`,
                    { error, event_schema_uri: eventSchemaUri }
                );
            })
            .then((schema) => {
                return this.ajv.compileAsync(schema).then((validatorForEvent) => {
                    if (_.isUndefined(this.ajv.getSchema(eventSchemaUri))) {
                        this.log.debug(
                            `Additionally caching schema with $id ` +
                            `'${validatorForEvent.schema.$id}' by event schema URI ` +
                            `${eventSchemaUri}`
                        );
                        this.ajv.addSchema(validatorForEvent.schema, eventSchemaUri);
                    }
                    return validatorForEvent;
                });
            });
        }
    }
validatorFor ( event ) { const eventSchemaUri = this . extractSchemaUri ( event ) ; this . log . debug ( ` ${ eventSchemaUri } ` ) ; const validator = this . ajv . getSchema ( eventSchemaUri ) ; if ( validator ) { return P . resolve ( validator ) ; } else { return this . loadSchema ( eventSchemaUri ) . catch ( ( error ) => { throw new EventSchemaLoadError ( ` ${ eventSchemaUri } ` , { error , event_schema_uri : eventSchemaUri } ) ; } ) . then ( ( schema ) => { return this . ajv . compileAsync ( schema ) . then ( ( validatorForEvent ) => { if ( _ . isUndefined ( this . ajv . getSchema ( eventSchemaUri ) ) ) { this . log . debug ( ` ` + ` ${ validatorForEvent . schema . $id } ` + ` ${ eventSchemaUri } ` ) ; this . ajv . addSchema ( validatorForEvent . schema , eventSchemaUri ) ; } return validatorForEvent ; } ) ; } ) ; } }
Returns a promise of a validate function for the event.
Returns a promise of a validate function for the event .
// Extract the schemaUri for this event. // If this eventSchemaUri has been seen before, return the already compiled // and cached AJV validator. // Else load the event's schema from its schema uri and compile it. // Wrap Event schema loading errors in EventSchemaLoadError // Also cache this schema at uri if uri is different than schema.$id // and this schema uri hasn't yet been added to the AJV cache