@@ -22,8 +22,41 @@ import { ExpressionRendererRegistry } from '../expression_renderers';
2222import { ExpressionAstExpression } from '../ast' ;
2323import { ExecutionContract } from '../execution/execution_contract' ;
2424
25- export type ExpressionsServiceSetup = ReturnType < ExpressionsService [ 'setup' ] > ;
26- export type ExpressionsServiceStart = ReturnType < ExpressionsService [ 'start' ] > ;
25+ /**
26+ * The public contract that `ExpressionsService` provides to other plugins
27+ * in Kibana Platform in *setup* life-cycle.
28+ */
29+ export type ExpressionsServiceSetup = Pick <
30+ ExpressionsService ,
31+ | 'getFunction'
32+ | 'getFunctions'
33+ | 'getRenderer'
34+ | 'getRenderers'
35+ | 'getType'
36+ | 'getTypes'
37+ | 'registerFunction'
38+ | 'registerRenderer'
39+ | 'registerType'
40+ | 'run'
41+ | 'fork'
42+ > ;
43+
44+ /**
45+ * The public contract that `ExpressionsService` provides to other plugins
46+ * in Kibana Platform in *start* life-cycle.
47+ */
48+ export type ExpressionsServiceStart = Pick <
49+ ExpressionsService ,
50+ | 'getFunction'
51+ | 'getFunctions'
52+ | 'getRenderer'
53+ | 'getRenderers'
54+ | 'getType'
55+ | 'getTypes'
56+ | 'run'
57+ | 'execute'
58+ | 'fork'
59+ > ;
2760
2861export interface ExpressionServiceParams {
2962 executor ?: Executor ;
@@ -97,6 +130,14 @@ export class ExpressionsService {
97130 ...args : Parameters < Executor [ 'registerFunction' ] >
98131 ) : ReturnType < Executor [ 'registerFunction' ] > => this . executor . registerFunction ( ...args ) ;
99132
133+ public readonly registerType = (
134+ ...args : Parameters < Executor [ 'registerType' ] >
135+ ) : ReturnType < Executor [ 'registerType' ] > => this . executor . registerType ( ...args ) ;
136+
137+ public readonly registerRenderer = (
138+ ...args : Parameters < ExpressionRendererRegistry [ 'register' ] >
139+ ) : ReturnType < ExpressionRendererRegistry [ 'register' ] > => this . renderers . register ( ...args ) ;
140+
100141 /**
101142 * Executes expression string or a parsed expression AST and immediately
102143 * returns the result.
@@ -132,21 +173,51 @@ export class ExpressionsService {
132173 ) : Promise < Output > => this . executor . run < Input , Output , ExtraContext > ( ast , input , context ) ;
133174
134175 /**
135- * Create a new instance of `ExpressionsService`. The new instance inherits
136- * all state of the original `ExpressionsService`, including all expression
137- * types, expression functions and context. Also, all new types and functions
138- * registered in the original services AFTER the forking event will be
139- * available in the forked instance. However, all new types and functions
140- * registered in the forked instances will NOT be available to the original
141- * service.
176+ * Get a registered `ExpressionFunction` by its name, which was registered
177+ * using the `registerFunction` method. The returned `ExpressionFunction`
178+ * instance is an internal representation of the function in Expressions
179+ * service - do not mutate that object.
142180 */
143- public readonly fork = ( ) : ExpressionsService => {
144- const executor = this . executor . fork ( ) ;
145- const renderers = this . renderers ;
146- const fork = new ExpressionsService ( { executor, renderers } ) ;
181+ public readonly getFunction = ( name : string ) : ReturnType < Executor [ 'getFunction' ] > =>
182+ this . executor . getFunction ( name ) ;
147183
148- return fork ;
149- } ;
184+ /**
185+ * Returns POJO map of all registered expression functions, where keys are
186+ * names of the functions and values are `ExpressionFunction` instances.
187+ */
188+ public readonly getFunctions = ( ) : ReturnType < Executor [ 'getFunctions' ] > =>
189+ this . executor . getFunctions ( ) ;
190+
191+ /**
192+ * Get a registered `ExpressionRenderer` by its name, which was registered
193+ * using the `registerRenderer` method. The returned `ExpressionRenderer`
194+ * instance is an internal representation of the renderer in Expressions
195+ * service - do not mutate that object.
196+ */
197+ public readonly getRenderer = ( name : string ) : ReturnType < ExpressionRendererRegistry [ 'get' ] > =>
198+ this . renderers . get ( name ) ;
199+
200+ /**
201+ * Returns POJO map of all registered expression renderers, where keys are
202+ * names of the renderers and values are `ExpressionRenderer` instances.
203+ */
204+ public readonly getRenderers = ( ) : ReturnType < ExpressionRendererRegistry [ 'toJS' ] > =>
205+ this . renderers . toJS ( ) ;
206+
207+ /**
208+ * Get a registered `ExpressionType` by its name, which was registered
209+ * using the `registerType` method. The returned `ExpressionType`
210+ * instance is an internal representation of the type in Expressions
211+ * service - do not mutate that object.
212+ */
213+ public readonly getType = ( name : string ) : ReturnType < Executor [ 'getType' ] > =>
214+ this . executor . getType ( name ) ;
215+
216+ /**
217+ * Returns POJO map of all registered expression types, where keys are
218+ * names of the types and values are `ExpressionType` instances.
219+ */
220+ public readonly getTypes = ( ) : ReturnType < Executor [ 'getTypes' ] > => this . executor . getTypes ( ) ;
150221
151222 /**
152223 * Starts expression execution and immediately returns `ExecutionContract`
@@ -168,53 +239,37 @@ export class ExpressionsService {
168239 return execution . contract ;
169240 } ;
170241
171- public setup ( ) {
172- const { executor, renderers, registerFunction, run, fork } = this ;
173-
174- const getFunction = executor . getFunction . bind ( executor ) ;
175- const getFunctions = executor . getFunctions . bind ( executor ) ;
176- const getRenderer = renderers . get . bind ( renderers ) ;
177- const getRenderers = renderers . toJS . bind ( renderers ) ;
178- const getType = executor . getType . bind ( executor ) ;
179- const getTypes = executor . getTypes . bind ( executor ) ;
180- const registerRenderer = renderers . register . bind ( renderers ) ;
181- const registerType = executor . registerType . bind ( executor ) ;
182-
183- return {
184- fork,
185- getFunction,
186- getFunctions,
187- getRenderer,
188- getRenderers,
189- getType,
190- getTypes,
191- registerFunction,
192- registerRenderer,
193- registerType,
194- run,
195- } ;
242+ /**
243+ * Create a new instance of `ExpressionsService`. The new instance inherits
244+ * all state of the original `ExpressionsService`, including all expression
245+ * types, expression functions and context. Also, all new types and functions
246+ * registered in the original services AFTER the forking event will be
247+ * available in the forked instance. However, all new types and functions
248+ * registered in the forked instances will NOT be available to the original
249+ * service.
250+ */
251+ public readonly fork = ( ) : ExpressionsService => {
252+ const executor = this . executor . fork ( ) ;
253+ const renderers = this . renderers ;
254+ const fork = new ExpressionsService ( { executor, renderers } ) ;
255+
256+ return fork ;
257+ } ;
258+
259+ /**
260+ * Returns Kibana Platform *setup* life-cycle contract. Useful to return the
261+ * same contract on server-side and browser-side.
262+ */
263+ public setup ( ) : ExpressionsServiceSetup {
264+ return this ;
196265 }
197266
198- public start ( ) {
199- const { execute, executor, renderers, run } = this ;
200-
201- const getFunction = executor . getFunction . bind ( executor ) ;
202- const getFunctions = executor . getFunctions . bind ( executor ) ;
203- const getRenderer = renderers . get . bind ( renderers ) ;
204- const getRenderers = renderers . toJS . bind ( renderers ) ;
205- const getType = executor . getType . bind ( executor ) ;
206- const getTypes = executor . getTypes . bind ( executor ) ;
207-
208- return {
209- execute,
210- getFunction,
211- getFunctions,
212- getRenderer,
213- getRenderers,
214- getType,
215- getTypes,
216- run,
217- } ;
267+ /**
268+ * Returns Kibana Platform *start* life-cycle contract. Useful to return the
269+ * same contract on server-side and browser-side.
270+ */
271+ public start ( ) : ExpressionsServiceStart {
272+ return this ;
218273 }
219274
220275 public stop ( ) { }
0 commit comments