1717 * under the License.
1818 */
1919
20- import { PluginInitializerContext , CoreSetup , CoreStart , Plugin } from '../../../core/public' ;
21- import { ExpressionExecutor } from './types' ;
20+ import { PluginInitializerContext , CoreSetup , CoreStart , Plugin } from 'src/core/public' ;
2221import {
23- ExpressionRendererRegistry ,
24- FunctionsRegistry ,
25- serializeProvider ,
26- TypesRegistry ,
2722 ExpressionsService ,
2823 ExpressionsServiceSetup ,
2924 ExpressionsServiceStart ,
3025 ExecutionContext ,
3126} from '../common' ;
32- import { BfetchPublicSetup , BfetchPublicStart } from '../../bfetch/public' ;
33- import {
34- setCoreStart ,
35- setInterpreter ,
36- setRenderersRegistry ,
37- setNotifications ,
38- setExpressionsService ,
39- } from './services' ;
27+ import { setRenderersRegistry , setNotifications , setExpressionsService } from './services' ;
4028import { ReactExpressionRenderer } from './react_expression_renderer' ;
4129import { ExpressionLoader , loader } from './loader' ;
4230import { render , ExpressionRenderHandler } from './render' ;
4331
44- export interface ExpressionsSetupDeps {
45- bfetch : BfetchPublicSetup ;
46- }
47-
48- export interface ExpressionsStartDeps {
49- bfetch : BfetchPublicStart ;
50- }
51-
52- export interface ExpressionsSetup extends ExpressionsServiceSetup {
53- /**
54- * @todo Get rid of these `__LEGACY` APIs.
55- *
56- * `__LEGACY` APIs are used by Canvas. It should be possible to stop
57- * using all of them (except `loadLegacyServerFunctionWrappers`) and use
58- * Kibana Platform plugin contracts instead.
59- */
60- __LEGACY : {
61- /**
62- * Use `registerType` and `getTypes` instead.
63- */
64- types : TypesRegistry ;
65-
66- /**
67- * Use `registerFunction` and `getFunctions` instead.
68- */
69- functions : FunctionsRegistry ;
70-
71- /**
72- * Use `registerRenderer` and `getRenderers`, and `getRenderer` instead.
73- */
74- renderers : ExpressionRendererRegistry ;
75-
76- /**
77- * Use `run` function instead.
78- */
79- getExecutor : ( ) => ExpressionExecutor ;
80-
81- /**
82- * This function is used by Canvas to load server-side function and create
83- * browser-side "wrapper" for each one. This function can be removed once
84- * we enable expressions on server-side: https://github.com/elastic/kibana/issues/46906
85- */
86- loadLegacyServerFunctionWrappers : ( ) => Promise < void > ;
87- } ;
88- }
32+ export type ExpressionsSetup = ExpressionsServiceSetup ;
8933
9034export interface ExpressionsStart extends ExpressionsServiceStart {
9135 ExpressionLoader : typeof ExpressionLoader ;
@@ -95,9 +39,7 @@ export interface ExpressionsStart extends ExpressionsServiceStart {
9539 render : typeof render ;
9640}
9741
98- export class ExpressionsPublicPlugin
99- implements
100- Plugin < ExpressionsSetup , ExpressionsStart , ExpressionsSetupDeps , ExpressionsStartDeps > {
42+ export class ExpressionsPublicPlugin implements Plugin < ExpressionsSetup , ExpressionsStart > {
10143 private readonly expressions : ExpressionsService = new ExpressionsService ( ) ;
10244
10345 constructor ( initializerContext : PluginInitializerContext ) { }
@@ -116,68 +58,21 @@ export class ExpressionsPublicPlugin
11658 } ) ;
11759 }
11860
119- public setup ( core : CoreSetup , { bfetch } : ExpressionsSetupDeps ) : ExpressionsSetup {
61+ public setup ( core : CoreSetup ) : ExpressionsSetup {
12062 this . configureExecutor ( core ) ;
12163
12264 const { expressions } = this ;
123- const { executor , renderers } = expressions ;
65+ const { renderers } = expressions ;
12466
12567 setRenderersRegistry ( renderers ) ;
126- setExpressionsService ( this . expressions ) ;
68+ setExpressionsService ( expressions ) ;
12769
128- const expressionsSetup = expressions . setup ( ) ;
129-
130- // This is legacy. Should go away when we get rid of __LEGACY.
131- const getExecutor = ( ) : ExpressionExecutor => {
132- return { interpreter : { interpretAst : expressionsSetup . run } } ;
133- } ;
134-
135- setInterpreter ( getExecutor ( ) . interpreter ) ;
136-
137- let cached : Promise < void > | null = null ;
138- const loadLegacyServerFunctionWrappers = async ( ) => {
139- if ( ! cached ) {
140- cached = ( async ( ) => {
141- const serverFunctionList = await core . http . get ( `/api/interpreter/fns` ) ;
142- const batchedFunction = bfetch . batchedFunction ( { url : `/api/interpreter/fns` } ) ;
143- const { serialize } = serializeProvider ( executor . getTypes ( ) ) ;
144-
145- // For every sever-side function, register a client-side
146- // function that matches its definition, but which simply
147- // calls the server-side function endpoint.
148- Object . keys ( serverFunctionList ) . forEach ( ( functionName ) => {
149- if ( expressionsSetup . getFunction ( functionName ) ) {
150- return ;
151- }
152- const fn = ( ) => ( {
153- ...serverFunctionList [ functionName ] ,
154- fn : ( input : any , args : any ) => {
155- return batchedFunction ( { functionName, args, context : serialize ( input ) } ) ;
156- } ,
157- } ) ;
158- expressionsSetup . registerFunction ( fn ) ;
159- } ) ;
160- } ) ( ) ;
161- }
162- return cached ;
163- } ;
164-
165- const setup : ExpressionsSetup = {
166- ...expressionsSetup ,
167- __LEGACY : {
168- types : executor . types ,
169- functions : executor . functions ,
170- renderers,
171- getExecutor,
172- loadLegacyServerFunctionWrappers,
173- } ,
174- } ;
70+ const setup = expressions . setup ( ) ;
17571
17672 return Object . freeze ( setup ) ;
17773 }
17874
179- public start ( core : CoreStart , { bfetch } : ExpressionsStartDeps ) : ExpressionsStart {
180- setCoreStart ( core ) ;
75+ public start ( core : CoreStart ) : ExpressionsStart {
18176 setNotifications ( core . notifications ) ;
18277
18378 const { expressions } = this ;
0 commit comments