import { CoreSetup , Plugin } from 'opensearch-dashboards/server' ; import { schema } from '@osd/config-schema' ; import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server' ; export interface IndexPatternsTestStartDeps { data : DataPluginStart ; } export class IndexPatternsTestPlugin implements Plugin < IndexPatternsTestPluginSetup , IndexPatternsTestPluginStart , { } , IndexPatternsTestStartDeps > { public setup ( core ) { const router = core . http . createRouter ( ) ; router . get ( { path : '/api/index-patterns-plugin/get-all' , validate : false } , async ( context , req , res ) => { const [ , { data } ] = await core . getStartServices ( ) ; const service = await data . indexPatterns . indexPatternsServiceFactory ( req ) ; const ids = await service . getIds ( ) ; return res . ok ( { body : ids } ) ; } ) ; router . get ( { path : '/api/index-patterns-plugin/get/{id}' , validate : { params : schema . object ( { id : schema . string ( ) , } ) , } , } , async ( context , req , res ) => { const id = ( req . params as Record < string , string > ) . id ; const [ , { data } ] = await core . getStartServices ( ) ; const service = await data . indexPatterns . indexPatternsServiceFactory ( req ) ; const ip = await service . get ( id ) ; return res . ok ( { body : ip . toSpec ( ) } ) ; } ) ; router . get ( { path : '/api/index-patterns-plugin/update/{id}' , validate : { params : schema . object ( { id : schema . string ( ) , } ) , } , } , async ( context , req , res ) => { const [ , { data } ] = await core . getStartServices ( ) ; const id = ( req . params as Record < string , string > ) . id ; const service = await data . indexPatterns . indexPatternsServiceFactory ( req ) ; const ip = await service . get ( id ) ; await service . updateSavedObject ( ip ) ; return res . ok ( ) ; } ) ; router . get ( { path : '/api/index-patterns-plugin/delete/{id}' , validate : { params : schema . object ( { id : schema . string ( ) , } ) , } , } , async ( context , req , res ) => { const [ , { data } ] = await core . getStartServices ( ) ; const id = ( req . params as Record < string , string > ) . id ; const service = await data . indexPatterns . indexPatternsServiceFactory ( req ) ; await service . delete ( id ) ; return res . ok ( ) ; } ) ; } public start ( ) { } public stop ( ) { } } export type IndexPatternsTestPluginSetup = ReturnType < IndexPatternsTestPlugin [ 'setup' ] > ; export type IndexPatternsTestPluginStart = ReturnType < IndexPatternsTestPlugin [ 'start' ] > ;