import { set } from '@elastic/safer-lodash-set' ; import { get , has } from 'lodash' ; import { SavedObject as SavedObjectType } from '../../server' ; import { SavedObjectsClientContract } from './saved_objects_client' ; /**
 * This class is a very simple wrapper for SavedObjects loaded from the server
 * with the  SavedObjectsClient .
 *
 * It provides basic functionality for creating/saving/deleting saved objects,
 * but doesn't include any type-specific implementations.
 *
 *  public export class SimpleSavedObject < T = unknown > { public attributes : T ; public _version ? : SavedObjectType < T > [ 'version' ] ; public id : SavedObjectType < T > [ 'id' ] ; public type : SavedObjectType < T > [ 'type' ] ; public migrationVersion : SavedObjectType < T > [ 'migrationVersion' ] ; public coreMigrationVersion : SavedObjectType < T > [ 'coreMigrationVersion' ] ; public error : SavedObjectType < T > [ 'error' ] ; public references : SavedObjectType < T > [ 'references' ] ; /**
     * Space(s) that this saved object exists in. This attribute is not used for "global" saved object types which are registered with
     * `namespaceType: 'agnostic'`.
     */ public namespaces : SavedObjectType < T > [ 'namespaces' ] ; constructor ( private client , { id , type , version , attributes , error , references , migrationVersion , coreMigrationVersion , namespaces , } ) { this . id = id ; this . type = type ; this . attributes = attributes || ( { } as T ) ; this . references = references || [ ] ; this . _version = version ; this . migrationVersion = migrationVersion ; this . coreMigrationVersion = coreMigrationVersion ; this . namespaces = namespaces ; if ( error ) { this . error = error ; } } public get ( key ) { return get ( this . attributes , key ) ; } public set ( key , value ) { return set ( this . attributes as any , key , value ) ; } public has ( key ) { return has ( this . attributes , key ) ; } public save ( ) { if ( this . id ) { return this . client . update ( this . type , this . id , this . attributes , { references : this . references , } ) ; } else { return this . client . create ( this . type , this . attributes , { migrationVersion : this . migrationVersion , coreMigrationVersion : this . coreMigrationVersion , references : this . references , } ) ; } } public delete ( ) { return this . client . delete ( this . type , this . id ) ; } }