import { CoreSetup , CoreStart , Plugin , PluginInitializerContext } from 'src/core/server' ; import { LicensingPluginStart } from '../../licensing/server' ; import { LicenseChecker , ILicenseChecker } from '../common/license_checker' ; import { SearchService , SearchServiceStart } from './services' ; import { registerRoutes } from './routes' ; import { GlobalSearchPluginSetup , GlobalSearchPluginStart , GlobalSearchRequestHandlerContext , } from './types' ; import { GlobalSearchConfigType } from './config' ; export interface GlobalSearchPluginSetupDeps { } export interface GlobalSearchPluginStartDeps { licensing : LicensingPluginStart ; } export class GlobalSearchPlugin implements Plugin < GlobalSearchPluginSetup , GlobalSearchPluginStart , GlobalSearchPluginSetupDeps , GlobalSearchPluginStartDeps > { private readonly config : GlobalSearchConfigType ; private readonly searchService = new SearchService ( ) ; private searchServiceStart ? : SearchServiceStart ; private licenseChecker ? : ILicenseChecker ; constructor ( context ) { this . config = context . config . get < GlobalSearchConfigType > ( ) ; } public setup ( core ) { const { registerResultProvider } = this . searchService . setup ( { basePath : core . http . basePath , config : this . config , } ) ; registerRoutes ( core . http . createRouter ( ) ) ; core . http . registerRouteHandlerContext < GlobalSearchRequestHandlerContext , 'globalSearch' > ( 'globalSearch' , ( _ , req ) => { return { find : ( term , options ) => this . searchServiceStart ! . find ( term , options , req ) , getSearchableTypes : ( ) => this . searchServiceStart ! . getSearchableTypes ( req ) , } ; } ) ; return { registerResultProvider , } ; } public start ( core , { licensing } ) { this . licenseChecker = new LicenseChecker ( licensing . license$ ) ; this . searchServiceStart = this . searchService . start ( { core , licenseChecker : this . licenseChecker , } ) ; return { find : this . searchServiceStart . find , getSearchableTypes : this . searchServiceStart . getSearchableTypes , } ; } public stop ( ) { if ( this . licenseChecker ) { this . licenseChecker . clean ( ) ; } } }