import { map , shareReplay } from 'rxjs/operators' ; import { combineLatest , Observable } from 'rxjs' ; import { PathConfigType , config as pathConfig } from '@kbn/utils' ; import { pick , deepFreeze } from '@kbn/std' ; import { IConfigService } from '@kbn/config' ; import { SharedGlobalConfig , SharedGlobalConfigKeys } from './types' ; import { ElasticsearchConfigType , config as elasticsearchConfig , } from '../elasticsearch/elasticsearch_config' ; import { SavedObjectsConfigType , savedObjectsConfig } from '../saved_objects/saved_objects_config' ; const createGlobalConfig = ( { elasticsearch , path , savedObjects , } ) : SharedGlobalConfig => { return deepFreeze ( { elasticsearch : pick ( elasticsearch , SharedGlobalConfigKeys . elasticsearch ) , path : pick ( path , SharedGlobalConfigKeys . path ) , savedObjects : pick ( savedObjects , SharedGlobalConfigKeys . savedObjects ) , } ) ; } ; export const getGlobalConfig = ( configService ) : SharedGlobalConfig => { return createGlobalConfig ( { elasticsearch : configService . atPathSync < ElasticsearchConfigType > ( elasticsearchConfig . path ) , path : configService . atPathSync < PathConfigType > ( pathConfig . path ) , savedObjects : configService . atPathSync < SavedObjectsConfigType > ( savedObjectsConfig . path ) , } ) ; } ; export const getGlobalConfig$ = ( configService ) : Observable < SharedGlobalConfig > => { return combineLatest ( [ configService . atPath < ElasticsearchConfigType > ( elasticsearchConfig . path ) , configService . atPath < PathConfigType > ( pathConfig . path ) , configService . atPath < SavedObjectsConfigType > ( savedObjectsConfig . path ) , ] ) . pipe ( map ( ( [ elasticsearch , path , savedObjects ] ) => createGlobalConfig ( { elasticsearch , path , savedObjects , } ) , shareReplay ( 1 ) ) ) ; } ;