import { createSavedObjectSanitizedDocSchema } from './schema' ; import { SavedObjectsValidationMap } from './types' ; import { SavedObjectSanitizedDoc } from '../serialization' ; import { Logger } from '../../logging' ; /**
 * Helper class that takes a  SavedObjectsValidationMap and runs validations for a
 * given type based on the provided Kibana version.
 *
 *  internal export class SavedObjectsTypeValidator { private readonly log : Logger ; private readonly type : string ; private readonly validationMap : SavedObjectsValidationMap ; constructor ( { logger , type , validationMap , } ) { this . log = logger ; this . type = type ; this . validationMap = typeof validationMap === 'function' ? validationMap ( ) : validationMap ; } public validate ( objectVersion , data ) { const validationRule = this . validationMap [ objectVersion ] ; if ( ! validationRule ) { return ; } try { const validationSchema = createSavedObjectSanitizedDocSchema ( validationRule ) ; validationSchema . validate ( data ) ; } catch ( e ) { this . log . warn ( `Error validating object of type [${ this . type }] against version [${ objectVersion }]` ) ; throw e ; } } }