import { schema } from '@kbn/config-schema' ; import { pluck } from 'rxjs/operators' ; import { CoreSetup , Plugin , HttpResponsePayload } from '../../../../../src/core/server' ; import { PluginStart as DataPluginStart } from '../../../../../src/plugins/data/server' ; import { ExpressionsServerStart } from '../../../../../src/plugins/expressions/server' ; export interface TestStartDeps { data : DataPluginStart ; expressions : ExpressionsServerStart ; } export class TestPlugin implements Plugin < TestPluginSetup , TestPluginStart , { } , TestStartDeps > { public setup ( core ) { const router = core . http . createRouter ( ) ; router . post ( { path : '/api/interpreter_functional/run_expression' , validate : { body : schema . object ( { input : schema . maybe ( schema . nullable ( schema . object ( { } , { unknowns : 'allow' } ) ) ) , expression : schema . string ( ) , } ) , } , } , async ( context , req , res ) => { const [ , { expressions } ] = await core . getStartServices ( ) ; const output = await expressions . run < unknown , HttpResponsePayload > ( req . body . expression , req . body . input , { kibanaRequest : req , } ) . pipe ( pluck ( 'result' ) ) . toPromise ( ) ; return res . ok ( { body : output } ) ; } ) ; } public start ( ) { } public stop ( ) { } } export type TestPluginSetup = ReturnType < TestPlugin [ 'setup' ] > ; export type TestPluginStart = ReturnType < TestPlugin [ 'start' ] > ;