import { CoreSetup , CoreStart , Plugin , OpenSearchDashboardsRequest , Logger , } from 'opensearch-dashboards/server' ; import { registerRoutes } from './routes' ; import { indexPatternSavedObjectType } from '../saved_objects' ; import { capabilitiesProvider } from './capabilities_provider' ; import { IndexPatternsService as IndexPatternsCommonService } from '../../common/index_patterns' ; import { FieldFormatsStart } from '../field_formats' ; import { UiSettingsServerToCommon } from './ui_settings_wrapper' ; import { IndexPatternsApiServer } from './index_patterns_api_client' ; import { SavedObjectsClientServerToCommon } from './saved_objects_client_wrapper' ; export interface IndexPatternsServiceStart { indexPatternsServiceFactory : ( opensearchDashboardsRequest : OpenSearchDashboardsRequest ) => Promise < IndexPatternsCommonService > ; } export interface IndexPatternsServiceStartDeps { fieldFormats : FieldFormatsStart ; logger : Logger ; } export class IndexPatternsService implements Plugin < void , IndexPatternsServiceStart > { public setup ( core ) { core . savedObjects . registerType ( indexPatternSavedObjectType ) ; core . capabilities . registerProvider ( capabilitiesProvider ) ; registerRoutes ( core . http ) ; } public start ( core , { fieldFormats , logger } ) { const { uiSettings , savedObjects } = core ; return { indexPatternsServiceFactory : async ( opensearchDashboardsRequest ) => { const savedObjectsClient = savedObjects . getScopedClient ( opensearchDashboardsRequest ) ; const uiSettingsClient = uiSettings . asScopedToClient ( savedObjectsClient ) ; const formats = await fieldFormats . fieldFormatServiceFactory ( uiSettingsClient ) ; return new IndexPatternsCommonService ( { uiSettings : new UiSettingsServerToCommon ( uiSettingsClient ) , savedObjectsClient : new SavedObjectsClientServerToCommon ( savedObjectsClient ) , apiClient : new IndexPatternsApiServer ( ) , fieldFormats : formats , onError : ( error ) => { logger . error ( error ) ; } , onNotification : ( { title , text } ) => { logger . warn ( `${ title } : ${ text }` ) ; } , onUnsupportedTimePattern : ( { index , title } ) => { logger . warn ( `Currently querying all indices matching ${ index }. ${ title } should be migrated to a wildcard-based index pattern.` ) ; } , } ) ; } , } ; } }