import { cloneDeep } from 'lodash' ; import type { SavedObjectUnsanitizedDoc } from '../saved_objects' ; import type { CoreUsageStats } from './types' ; export const migrateTo7141 = ( doc ) => { try { return resetFields ( doc , [ 'apiCalls.savedObjectsImport.total' , 'apiCalls.savedObjectsImport.namespace.default.total' , 'apiCalls.savedObjectsImport.namespace.default.kibanaRequest.yes' , 'apiCalls.savedObjectsImport.namespace.default.kibanaRequest.no' , 'apiCalls.savedObjectsImport.namespace.custom.total' , 'apiCalls.savedObjectsImport.namespace.custom.kibanaRequest.yes' , 'apiCalls.savedObjectsImport.namespace.custom.kibanaRequest.no' , 'apiCalls.savedObjectsImport.createNewCopiesEnabled.yes' , 'apiCalls.savedObjectsImport.createNewCopiesEnabled.no' , 'apiCalls.savedObjectsImport.overwriteEnabled.yes' , 'apiCalls.savedObjectsImport.overwriteEnabled.no' , ] ) ; } catch ( err ) { } return doc ; } ; function resetFields ( doc , fieldsToReset ) { const newDoc = cloneDeep ( doc ) ; const { attributes = { } } = newDoc ; for ( const field of fieldsToReset ) { attributes [ field ] = 0 ; } return { ... newDoc , attributes } ; }