import { omit } from 'lodash' ; import { SavedObjectsClient , SimpleSavedObject } from 'src/core/public' ; import { SavedObjectsClientCommon , SavedObjectsClientCommonFindArgs , SavedObject , } from '../../common/index_patterns' ; type SOClient = Pick < SavedObjectsClient , 'find' | 'get' | 'update' | 'create' | 'delete' > ; const simpleSavedObjectToSavedObject = < T > ( simpleSavedObject ) : SavedObject < T > => ( { version : simpleSavedObject . _version , ... omit ( simpleSavedObject , '_version' ) , } as any ) ; export class SavedObjectsClientPublicToCommon implements SavedObjectsClientCommon { private savedObjectClient : SOClient ; constructor ( savedObjectClient ) { this . savedObjectClient = savedObjectClient ; } async find < T = unknown > ( options ) { const response = ( await this . savedObjectClient . find < T > ( options ) ) . savedObjects ; return response . map < SavedObject < T > > ( simpleSavedObjectToSavedObject ) ; } async get < T = unknown > ( type , id ) { const response = await this . savedObjectClient . get < T > ( type , id ) ; return simpleSavedObjectToSavedObject < T > ( response ) ; } async update < T = unknown > ( type , id , attributes , options ) { const response = await this . savedObjectClient . update ( type , id , attributes , options ) ; return simpleSavedObjectToSavedObject < T > ( response ) ; } async create ( type , attributes , options ) { const response = await this . savedObjectClient . create ( type , attributes , options ) ; return simpleSavedObjectToSavedObject ( response ) ; } delete ( type , id ) { return this . savedObjectClient . delete ( type , id ) ; } }