From 22046d6a97b5a994957a7f81b5374b49def1ca8a Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Fri, 9 Jul 2021 19:01:50 -0400 Subject: [PATCH 1/2] [RFC] Allow 'leasing' of Expression constructs --- .../expressions/common/executor/container.ts | 80 ++++++++++++++++++- .../common/executor/executor.test.ts | 34 ++++++++ .../expressions/common/executor/executor.ts | 60 ++++++++++---- .../expression_renderer_registry.ts | 4 + .../common/service/expressions_services.ts | 54 ++++++++++--- .../canvas/canvas_plugin_src/plugin.ts | 30 +++++-- x-pack/plugins/canvas/public/plugin.tsx | 6 +- x-pack/plugins/canvas/public/plugin_api.ts | 35 +------- 8 files changed, 235 insertions(+), 68 deletions(-) diff --git a/src/plugins/expressions/common/executor/container.ts b/src/plugins/expressions/common/executor/container.ts index 87c45bb2c40bf..60d8a0ce17e9e 100644 --- a/src/plugins/expressions/common/executor/container.ts +++ b/src/plugins/expressions/common/executor/container.ts @@ -27,13 +27,89 @@ export const defaultState: ExecutorState = { export interface ExecutorPureTransitions { addFunction: (state: ExecutorState) => (fn: ExpressionFunction) => ExecutorState; + addFunctions: (state: ExecutorState) => (fns: ExpressionFunction[]) => ExecutorState; + removeFunction: (state: ExecutorState) => (fnName: ExpressionFunction['name']) => ExecutorState; + removeFunctions: ( + state: ExecutorState + ) => (fnNames: Array) => ExecutorState; addType: (state: ExecutorState) => (type: ExpressionType) => ExecutorState; + addTypes: (state: ExecutorState) => (types: ExpressionType[]) => ExecutorState; + removeType: (state: ExecutorState) => (typeName: ExpressionType['name']) => ExecutorState; + removeTypes: (state: ExecutorState) => (typeName: Array) => ExecutorState; extendContext: (state: ExecutorState) => (extraContext: Record) => ExecutorState; } +const addFunctions: ExecutorPureTransitions['addFunctions'] = (state) => (fns) => { + const functions = {} as Record; + + fns.forEach((fn) => { + functions[fn.name] = fn; + }); + + return { + ...state, + functions: { + ...state.functions, + ...functions, + }, + }; +}; + +const removeFunctions: ExecutorPureTransitions['removeFunctions'] = (state) => (names) => { + const functions = {} as Record; + + for (const name in state.functions) { + if (!names.includes(name)) { + functions[name] = state.functions[name]; + } + } + + return { + ...state, + functions, + }; +}; + +const addTypes: ExecutorPureTransitions['addTypes'] = (state) => (typesToAdd) => { + const types = {} as Record; + + typesToAdd.forEach((type) => { + types[type.name] = type; + }); + + return { + ...state, + types: { + ...state.types, + ...types, + }, + }; +}; + +const removeTypes: ExecutorPureTransitions['removeTypes'] = (state) => (typesToRemove) => { + const types = {} as Record; + + for (const name in state.types) { + if (!typesToRemove.includes(name)) { + types[name] = state.types[name]; + } + } + + return { + ...state, + types, + }; +}; + export const pureTransitions: ExecutorPureTransitions = { - addFunction: (state) => (fn) => ({ ...state, functions: { ...state.functions, [fn.name]: fn } }), - addType: (state) => (type) => ({ ...state, types: { ...state.types, [type.name]: type } }), + addFunction: (state) => (fn) => addFunctions(state)([fn]), + addFunctions, + removeFunction: (state) => (fnName) => removeFunctions(state)([fnName]), + removeFunctions, + addType: (state) => (type) => addTypes(state)([type]), + addTypes, + removeType: (state) => (typeName) => removeTypes(state)([typeName]), + removeTypes, extendContext: (state) => (extraContext) => ({ ...state, context: { ...state.context, ...extraContext }, diff --git a/src/plugins/expressions/common/executor/executor.test.ts b/src/plugins/expressions/common/executor/executor.test.ts index 3c24a3c24e01b..096770b45f3a7 100644 --- a/src/plugins/expressions/common/executor/executor.test.ts +++ b/src/plugins/expressions/common/executor/executor.test.ts @@ -44,6 +44,18 @@ describe('Executor', () => { expressionTypes.typeSpecs.map((spec) => spec.name).sort() ); }); + + test('can lease all types', () => { + const executor = new Executor(); + const release = executor.leaseTypes(expressionTypes.typeSpecs); + let types = executor.getTypes(); + expect(Object.keys(types).sort()).toEqual( + expressionTypes.typeSpecs.map((spec) => spec.name).sort() + ); + release(); + types = executor.getTypes(); + expect(Object.keys(types).length).toBe(0); + }); }); describe('function registry', () => { @@ -80,6 +92,28 @@ describe('Executor', () => { expect(Object.keys(functions).sort()).toEqual(functionSpecs.map((spec) => spec.name).sort()); }); + + test('can lease functions', () => { + const executor = new Executor(); + const functionSpecs = [ + expressionFunctions.clog, + expressionFunctions.font, + expressionFunctions.variableSet, + expressionFunctions.variable, + expressionFunctions.theme, + expressionFunctions.cumulativeSum, + expressionFunctions.derivative, + expressionFunctions.movingAverage, + expressionFunctions.mapColumn, + expressionFunctions.math, + ]; + const release = executor.leaseFunctions(functionSpecs); + let functions = executor.getFunctions(); + expect(Object.keys(functions).sort()).toEqual(functionSpecs.map((spec) => spec.name).sort()); + release(); + functions = executor.getFunctions(); + expect(Object.keys(functions).length).toBe(0); + }); }); describe('context', () => { diff --git a/src/plugins/expressions/common/executor/executor.ts b/src/plugins/expressions/common/executor/executor.ts index 7ca5a005991bd..1fba3b28a0ed5 100644 --- a/src/plugins/expressions/common/executor/executor.ts +++ b/src/plugins/expressions/common/executor/executor.ts @@ -77,14 +77,16 @@ export class FunctionsRegistry implements IRegistry { } } +type FunctionDefinition = AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition); +type TypeDefinition = AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition); + export class Executor = Record> implements PersistableStateService { static createWithDefaults = Record>( state?: ExecutorState ): Executor { const executor = new Executor(state); - for (const type of typeSpecs) executor.registerType(type); - + executor.registerTypes(typeSpecs); return executor; } @@ -106,13 +108,27 @@ export class Executor = Record AnyExpressionFunctionDefinition) - ) { - const fn = new ExpressionFunction( - typeof functionDefinition === 'object' ? functionDefinition : functionDefinition() + public registerFunction(functionDefinition: FunctionDefinition) { + this.registerFunctions([functionDefinition]); + } + + public registerFunctions(functionDefinitions: FunctionDefinition[]) { + const fns = functionDefinitions.map( + (fn) => new ExpressionFunction(typeof fn === 'object' ? fn : fn()) ); - this.state.transitions.addFunction(fn); + + this.state.transitions.addFunctions(fns); + } + + public leaseFunctions(functionDefinitions: FunctionDefinition[]) { + const fns = functionDefinitions.map( + (fn) => new ExpressionFunction(typeof fn === 'object' ? fn : fn()) + ); + + this.state.transitions.addFunctions(fns); + const names = fns.map((fn) => fn.name); + + return () => this.state.transitions.removeFunctions(names); } public getFunction(name: string): ExpressionFunction | undefined { @@ -123,13 +139,29 @@ export class Executor = Record AnyExpressionTypeDefinition) - ) { - const type = new ExpressionType( - typeof typeDefinition === 'object' ? typeDefinition : typeDefinition() + public registerType(typeDefinition: TypeDefinition) { + this.registerTypes([typeDefinition]); + } + + public registerTypes(typeDefinitions: TypeDefinition[]) { + const types = typeDefinitions.map( + (typeDefinition) => + new ExpressionType(typeof typeDefinition === 'object' ? typeDefinition : typeDefinition()) ); - this.state.transitions.addType(type); + + this.state.transitions.addTypes(types); + } + + public leaseTypes(typeDefinitions: TypeDefinition[]) { + const types = typeDefinitions.map( + (typeDefinition) => + new ExpressionType(typeof typeDefinition === 'object' ? typeDefinition : typeDefinition()) + ); + + this.state.transitions.addTypes(types); + const names = types.map((type) => type.name); + + return () => this.state.transitions.removeTypes(names); } public getType(name: string): ExpressionType | undefined { diff --git a/src/plugins/expressions/common/expression_renderers/expression_renderer_registry.ts b/src/plugins/expressions/common/expression_renderers/expression_renderer_registry.ts index 8335e31187b41..9ec5f0db93ed0 100644 --- a/src/plugins/expressions/common/expression_renderers/expression_renderer_registry.ts +++ b/src/plugins/expressions/common/expression_renderers/expression_renderer_registry.ts @@ -22,6 +22,10 @@ export class ExpressionRendererRegistry implements IRegistry this.renderers.set(renderer.name, renderer); } + remove(name: string) { + this.renderers.delete(name); + } + public get(id: string): ExpressionRenderer | null { return this.renderers.get(id) || null; } diff --git a/src/plugins/expressions/common/service/expressions_services.ts b/src/plugins/expressions/common/service/expressions_services.ts index ed798db6cc915..f505b316178e6 100644 --- a/src/plugins/expressions/common/service/expressions_services.ts +++ b/src/plugins/expressions/common/service/expressions_services.ts @@ -14,8 +14,7 @@ import { Executor } from '../executor'; import { AnyExpressionRenderDefinition, ExpressionRendererRegistry } from '../expression_renderers'; import { ExpressionAstExpression } from '../ast'; import { ExecutionContract, ExecutionResult } from '../execution'; -import { AnyExpressionTypeDefinition, ExpressionValueError } from '../expression_types'; -import { AnyExpressionFunctionDefinition } from '../expression_functions'; +import { ExpressionValueError } from '../expression_types'; import { SavedObjectReference } from '../../../../core/types'; import { PersistableStateService, SerializableState } from '../../../kibana_utils/common'; import { Adapters } from '../../../inspector/common/adapters'; @@ -43,13 +42,19 @@ export type ExpressionsServiceSetup = Pick< ExpressionsService, | 'getFunction' | 'getFunctions' + | 'leaseFunctions' | 'getRenderer' | 'getRenderers' | 'getType' | 'getTypes' + | 'leaseTypes' | 'registerFunction' + | 'registerFunctions' | 'registerRenderer' + | 'registerRenderers' + | 'leaseRenderers' | 'registerType' + | 'registerTypes' | 'run' | 'fork' >; @@ -231,17 +236,44 @@ export class ExpressionsService implements PersistableStateService AnyExpressionFunctionDefinition) - ): void => this.executor.registerFunction(functionDefinition); + public readonly registerFunction: Executor['registerFunction'] = (functionDefinition) => + this.executor.registerFunction(functionDefinition); - public readonly registerType = ( - typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition) - ): void => this.executor.registerType(typeDefinition); + public readonly registerFunctions: Executor['registerFunctions'] = (functionDefinitions) => + this.executor.registerFunctions(functionDefinitions); - public readonly registerRenderer = ( - definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition) - ): void => this.renderers.register(definition); + public readonly leaseFunctions: Executor['leaseFunctions'] = (fns) => + this.executor.leaseFunctions(fns); + + public readonly registerType: Executor['registerType'] = (typeDefinition) => + this.executor.registerType(typeDefinition); + + public readonly registerTypes: Executor['registerTypes'] = (typeDefinitions) => + this.executor.registerTypes(typeDefinitions); + + public readonly leaseTypes: Executor['leaseTypes'] = (types) => this.executor.leaseTypes(types); + + public readonly registerRenderer: ExpressionRendererRegistry['register'] = (definition): void => + this.renderers.register(definition); + + public readonly registerRenderers = ( + definitions: Array AnyExpressionRenderDefinition)> + ) => { + definitions.forEach(this.registerRenderer); + }; + + public readonly leaseRenderers = ( + definitions: Array AnyExpressionRenderDefinition)> + ) => { + const names = definitions.map((definition) => { + this.renderers.register(definition); + return definition.name; + }); + + return () => { + names.forEach((name) => this.renderers.remove(name)); + }; + }; public readonly run: ExpressionsServiceStart['run'] = (ast, input, params) => this.executor.run(ast, input, params); diff --git a/x-pack/plugins/canvas/canvas_plugin_src/plugin.ts b/x-pack/plugins/canvas/canvas_plugin_src/plugin.ts index a30b3bf9b2121..33d9687624c26 100644 --- a/x-pack/plugins/canvas/canvas_plugin_src/plugin.ts +++ b/x-pack/plugins/canvas/canvas_plugin_src/plugin.ts @@ -7,16 +7,20 @@ import { CoreSetup, CoreStart, Plugin } from 'src/core/public'; import { ChartsPluginStart } from 'src/plugins/charts/public'; +import { ExpressionsSetup } from 'src/plugins/expressions/public'; + import { CanvasSetup } from '../public'; import { EmbeddableStart } from '../../../../src/plugins/embeddable/public'; import { UiActionsStart } from '../../../../src/plugins/ui_actions/public'; import { Start as InspectorStart } from '../../../../src/plugins/inspector/public'; +import { AnyExpressionRenderDefinition } from '../types'; import { functions } from './functions/browser'; import { typeFunctions } from './expression_types'; import { renderFunctions, renderFunctionFactories } from './renderers'; interface SetupDeps { canvas: CanvasSetup; + expressions: ExpressionsSetup; } export interface StartDeps { @@ -32,15 +36,24 @@ export type StartInitializer = (core: CoreStart, plugins: StartDeps) => T; /** @internal */ export class CanvasSrcPlugin implements Plugin { public setup(core: CoreSetup, plugins: SetupDeps) { - plugins.canvas.addFunctions(functions); - plugins.canvas.addTypes(typeFunctions); + const { expressions } = plugins; + const releaseFunctions = expressions.leaseFunctions(functions); + const releaseTypes = expressions.leaseTypes(typeFunctions); + + // There is an issue of the canvas render definition not matching the expression render definition + // due to our handlers needing additional methods. For now, we are going to cast to get to the proper + // type, but we should work with AppArch to figure out how the Handlers can be genericized + const releaseRenderers = expressions.leaseRenderers( + (renderFunctions as unknown) as AnyExpressionRenderDefinition[] + ); - plugins.canvas.addRenderers(renderFunctions); + let releaseFactories = () => {}; core.getStartServices().then(([coreStart, depsStart]) => { - plugins.canvas.addRenderers( - renderFunctionFactories.map((factory: any) => factory(coreStart, depsStart)) + const renderers = renderFunctionFactories.map((factory: any) => + factory(coreStart, depsStart) ); + releaseFactories = expressions.leaseRenderers(renderers); }); plugins.canvas.addDatasourceUIs(async () => { @@ -81,6 +94,13 @@ export class CanvasSrcPlugin implements Plugin const { transformSpecs } = await import('./canvas_addons'); return transformSpecs; }); + + return () => { + releaseFunctions(); + releaseTypes(); + releaseRenderers(); + releaseFactories(); + }; } public start(core: CoreStart, plugins: StartDeps) {} diff --git a/x-pack/plugins/canvas/public/plugin.tsx b/x-pack/plugins/canvas/public/plugin.tsx index 101f64e53b685..1b87ea23d334d 100644 --- a/x-pack/plugins/canvas/public/plugin.tsx +++ b/x-pack/plugins/canvas/public/plugin.tsx @@ -75,7 +75,8 @@ export class CanvasPlugin private appUpdater = new BehaviorSubject(() => ({})); public setup(coreSetup: CoreSetup, setupPlugins: CanvasSetupDeps) { - const { api: canvasApi, registries } = getPluginApi(setupPlugins.expressions); + const { expressions } = setupPlugins; + const { api: canvasApi, registries } = getPluginApi(); // Set the nav link to the last saved url if we have one in storage const lastPath = getSessionStorage().get( @@ -97,7 +98,7 @@ export class CanvasPlugin mount: async (params: AppMountParameters) => { const { CanvasSrcPlugin } = await import('../canvas_plugin_src/plugin'); const srcPlugin = new CanvasSrcPlugin(); - srcPlugin.setup(coreSetup, { canvas: canvasApi }); + const teardown = srcPlugin.setup(coreSetup, { canvas: canvasApi, expressions }); // Get start services const [coreStart, startPlugins] = await coreSetup.getStartServices(); @@ -123,6 +124,7 @@ export class CanvasPlugin return () => { unmount(); + teardown(); teardownCanvas(coreStart); }; }, diff --git a/x-pack/plugins/canvas/public/plugin_api.ts b/x-pack/plugins/canvas/public/plugin_api.ts index 8f39f2d990d0c..7282b145474b3 100644 --- a/x-pack/plugins/canvas/public/plugin_api.ts +++ b/x-pack/plugins/canvas/public/plugin_api.ts @@ -5,30 +5,19 @@ * 2.0. */ -import { - AnyExpressionFunctionDefinition, - AnyExpressionTypeDefinition, - AnyExpressionRenderDefinition, - AnyRendererFactory, -} from '../types'; import { ElementFactory } from '../types'; -import { ExpressionsSetup } from '../../../../src/plugins/expressions/public'; type SpecPromiseFn = () => Promise; type AddToRegistry = (add: T[] | SpecPromiseFn) => void; -type AddSpecsToRegistry = (add: T[]) => void; export interface CanvasApi { addArgumentUIs: AddToRegistry; addDatasourceUIs: AddToRegistry; addElements: AddToRegistry; - addFunctions: AddSpecsToRegistry<() => AnyExpressionFunctionDefinition>; addModelUIs: AddToRegistry; - addRenderers: AddSpecsToRegistry; addTagUIs: AddToRegistry; addTransformUIs: AddToRegistry; addTransitions: AddToRegistry; - addTypes: AddSpecsToRegistry<() => AnyExpressionTypeDefinition>; addViewUIs: AddToRegistry; } @@ -43,9 +32,7 @@ export interface SetupRegistries extends Record { transitions: any[]; } -export function getPluginApi( - expressionsPluginSetup: ExpressionsSetup -): { api: CanvasApi; registries: SetupRegistries } { +export function getPluginApi(): { api: CanvasApi; registries: SetupRegistries } { const registries: SetupRegistries = { elements: [], transformUIs: [], @@ -68,26 +55,6 @@ export function getPluginApi( }; const api: CanvasApi = { - // Functions, types and renderers are registered directly to expression plugin - addFunctions: (fns) => { - fns.forEach((fn) => { - expressionsPluginSetup.registerFunction(fn); - }); - }, - addTypes: (types) => { - types.forEach((type) => { - expressionsPluginSetup.registerType(type as any); - }); - }, - addRenderers: (renderers) => { - renderers.forEach((r) => { - // There is an issue of the canvas render definition not matching the expression render definition - // due to our handlers needing additional methods. For now, we are going to cast to get to the proper - // type, but we should work with AppArch to figure out how the Handlers can be genericized - expressionsPluginSetup.registerRenderer((r as unknown) as AnyExpressionRenderDefinition); - }); - }, - // All these others are local to canvas, and they will only register on start addElements: addToRegistry(registries.elements), addTransformUIs: addToRegistry(registries.transformUIs), From 545b15e6cb0718e8d886aa779293a8298a71f333 Mon Sep 17 00:00:00 2001 From: Clint Andrew Hall Date: Mon, 12 Jul 2021 12:22:56 -0400 Subject: [PATCH 2/2] update docs --- ...ressions-public.executor.leasefunctions.md | 24 ++++++++++++++ ...-expressions-public.executor.leasetypes.md | 24 ++++++++++++++ ...gin-plugins-expressions-public.executor.md | 8 +++-- ...ssions-public.executor.registerfunction.md | 6 ++-- ...sions-public.executor.registerfunctions.md | 24 ++++++++++++++ ...xpressions-public.executor.registertype.md | 6 ++-- ...pressions-public.executor.registertypes.md | 24 ++++++++++++++ ...sions-public.expressionrendererregistry.md | 1 + ...ublic.expressionrendererregistry.remove.md | 22 +++++++++++++ ...ublic.expressionsservice.leasefunctions.md | 13 ++++++++ ...ublic.expressionsservice.leaserenderers.md | 11 +++++++ ...ns-public.expressionsservice.leasetypes.md | 11 +++++++ ...s-expressions-public.expressionsservice.md | 12 +++++-- ...lic.expressionsservice.registerfunction.md | 2 +- ...ic.expressionsservice.registerfunctions.md | 13 ++++++++ ...lic.expressionsservice.registerrenderer.md | 2 +- ...ic.expressionsservice.registerrenderers.md | 11 +++++++ ...-public.expressionsservice.registertype.md | 2 +- ...public.expressionsservice.registertypes.md | 11 +++++++ ...ressions-public.expressionsservicesetup.md | 2 +- ...ressions-server.executor.leasefunctions.md | 24 ++++++++++++++ ...-expressions-server.executor.leasetypes.md | 24 ++++++++++++++ ...gin-plugins-expressions-server.executor.md | 8 +++-- ...ssions-server.executor.registerfunction.md | 6 ++-- ...sions-server.executor.registerfunctions.md | 24 ++++++++++++++ ...xpressions-server.executor.registertype.md | 6 ++-- ...pressions-server.executor.registertypes.md | 24 ++++++++++++++ ...sions-server.expressionrendererregistry.md | 1 + ...erver.expressionrendererregistry.remove.md | 22 +++++++++++++ .../expressions/common/executor/executor.ts | 20 ++++++++++++ .../common/service/expressions_services.ts | 8 +++++ src/plugins/expressions/public/mocks.tsx | 6 ++++ src/plugins/expressions/public/public.api.md | 32 ++++++++++++++----- src/plugins/expressions/server/mocks.ts | 6 ++++ src/plugins/expressions/server/server.api.md | 14 +++++--- 35 files changed, 423 insertions(+), 31 deletions(-) create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasefunctions.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasetypes.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registerfunctions.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertypes.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrendererregistry.remove.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md create mode 100644 docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasefunctions.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasetypes.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registerfunctions.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertypes.md create mode 100644 docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.expressionrendererregistry.remove.md diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasefunctions.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasefunctions.md new file mode 100644 index 0000000000000..cec77b44bdb3a --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasefunctions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [Executor](./kibana-plugin-plugins-expressions-public.executor.md) > [leaseFunctions](./kibana-plugin-plugins-expressions-public.executor.leasefunctions.md) + +## Executor.leaseFunctions() method + +Register a collection of functions meant to be deregegistered by the registering context, when they are no longer to be used, which can be done with the callback returned. + +Signature: + +```typescript +leaseFunctions(functionDefinitions: FunctionDefinition[]): () => ExecutorState>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| functionDefinitions | FunctionDefinition[] | | + +Returns: + +`() => ExecutorState>` + diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasetypes.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasetypes.md new file mode 100644 index 0000000000000..63fb70f37a1d9 --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.leasetypes.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [Executor](./kibana-plugin-plugins-expressions-public.executor.md) > [leaseTypes](./kibana-plugin-plugins-expressions-public.executor.leasetypes.md) + +## Executor.leaseTypes() method + +Register a collection of types meant to be deregegistered by the registering context when they are no longer to be used, which can be done with the callback returned. + +Signature: + +```typescript +leaseTypes(typeDefinitions: TypeDefinition[]): () => ExecutorState>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| typeDefinitions | TypeDefinition[] | | + +Returns: + +`() => ExecutorState>` + diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.md index 6835188c2fb04..bceedc81ca838 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.md @@ -39,9 +39,13 @@ export declare class Executor = RecordSignature: ```typescript -registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void; +registerFunction(functionDefinition: FunctionDefinition): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| functionDefinition | AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition) | | +| functionDefinition | FunctionDefinition | | Returns: diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registerfunctions.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registerfunctions.md new file mode 100644 index 0000000000000..4b64b2702578d --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registerfunctions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [Executor](./kibana-plugin-plugins-expressions-public.executor.md) > [registerFunctions](./kibana-plugin-plugins-expressions-public.executor.registerfunctions.md) + +## Executor.registerFunctions() method + +Register a collection of functions with the executor. + +Signature: + +```typescript +registerFunctions(functionDefinitions: FunctionDefinition[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| functionDefinitions | FunctionDefinition[] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertype.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertype.md index f56e5ffcfb9ee..426b9cdbbd821 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertype.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertype.md @@ -4,17 +4,19 @@ ## Executor.registerType() method +Register a single type with the executor. + Signature: ```typescript -registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void; +registerType(typeDefinition: TypeDefinition): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| typeDefinition | AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition) | | +| typeDefinition | TypeDefinition | | Returns: diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertypes.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertypes.md new file mode 100644 index 0000000000000..5df009c9a6f7d --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.executor.registertypes.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [Executor](./kibana-plugin-plugins-expressions-public.executor.md) > [registerTypes](./kibana-plugin-plugins-expressions-public.executor.registertypes.md) + +## Executor.registerTypes() method + +Register a collection of types with the executor. + +Signature: + +```typescript +registerTypes(typeDefinitions: TypeDefinition[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| typeDefinitions | TypeDefinition[] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrendererregistry.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrendererregistry.md index e53f2a7970723..f0d0253795f08 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrendererregistry.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionrendererregistry.md @@ -16,6 +16,7 @@ export declare class ExpressionRendererRegistry implements IRegistry + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionRendererRegistry](./kibana-plugin-plugins-expressions-public.expressionrendererregistry.md) > [remove](./kibana-plugin-plugins-expressions-public.expressionrendererregistry.remove.md) + +## ExpressionRendererRegistry.remove() method + +Signature: + +```typescript +remove(name: string): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | | + +Returns: + +`void` + diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md new file mode 100644 index 0000000000000..988215abca163 --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [leaseFunctions](./kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md) + +## ExpressionsService.leaseFunctions property + +Register a collection of expression functions that are meant to be deregistered by the registering context, (e.g. a plugin leases on mount and deregisters on unmount). This call returns a simple callback to make registering easier. + +Signature: + +```typescript +readonly leaseFunctions: Executor['leaseFunctions']; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md new file mode 100644 index 0000000000000..0abfaaa1f4ecc --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [leaseRenderers](./kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md) + +## ExpressionsService.leaseRenderers property + +Signature: + +```typescript +readonly leaseRenderers: (definitions: Array AnyExpressionRenderDefinition)>) => () => void; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md new file mode 100644 index 0000000000000..bd165bd7b871f --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [leaseTypes](./kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md) + +## ExpressionsService.leaseTypes property + +Signature: + +```typescript +readonly leaseTypes: Executor['leaseTypes']; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.md index 9afd603bc4869..d5e5c820ad79a 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.md @@ -39,8 +39,11 @@ export declare class ExpressionsService implements PersistableStateServiceExpressionsServiceStart['getType'] | | | [getTypes](./kibana-plugin-plugins-expressions-public.expressionsservice.gettypes.md) | | () => ReturnType<Executor['getTypes']> | Returns POJO map of all registered expression types, where keys are names of the types and values are ExpressionType instances. | | [inject](./kibana-plugin-plugins-expressions-public.expressionsservice.inject.md) | | (state: ExpressionAstExpression, references: SavedObjectReference[]) => ExpressionAstExpression | Injects saved object references into expression AST | +| [leaseFunctions](./kibana-plugin-plugins-expressions-public.expressionsservice.leasefunctions.md) | | Executor['leaseFunctions'] | Register a collection of expression functions that are meant to be deregistered by the registering context, (e.g. a plugin leases on mount and deregisters on unmount). This call returns a simple callback to make registering easier. | +| [leaseRenderers](./kibana-plugin-plugins-expressions-public.expressionsservice.leaserenderers.md) | | (definitions: Array<AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)>) => () => void | | +| [leaseTypes](./kibana-plugin-plugins-expressions-public.expressionsservice.leasetypes.md) | | Executor['leaseTypes'] | | | [migrate](./kibana-plugin-plugins-expressions-public.expressionsservice.migrate.md) | | (state: SerializableState, version: string) => ExpressionAstExpression | Runs the migration (if it exists) for specified version. This will run a single migration step (ie from 7.10.0 to 7.10.1) | -| [registerFunction](./kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md) | | (functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)) => void | Register an expression function, which will be possible to execute as part of the expression pipeline.Below we register a function which simply sleeps for given number of milliseconds to delay the execution and outputs its input as-is. +| [registerFunction](./kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md) | | Executor['registerFunction'] | Register an expression function, which will be possible to execute as part of the expression pipeline.Below we register a function which simply sleeps for given number of milliseconds to delay the execution and outputs its input as-is. ```ts expressions.registerFunction({ name: 'sleep', @@ -60,8 +63,11 @@ expressions.registerFunction({ ``` The actual function is defined in the fn key. The function can be \*async\*. It receives three arguments: (1) input is the output of the previous function or the initial input of the expression if the function is first in chain; (2) args are function arguments as defined in expression string, that can be edited by user (e.g in case of Canvas); (3) context is a shared object passed to all functions that can be used for side-effects. | -| [registerRenderer](./kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md) | | (definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)) => void | | -| [registerType](./kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md) | | (typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)) => void | | +| [registerFunctions](./kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md) | | Executor['registerFunctions'] | Register a collection of expression functions. See registerFunction for details. | +| [registerRenderer](./kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md) | | ExpressionRendererRegistry['register'] | | +| [registerRenderers](./kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md) | | (definitions: Array<AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)>) => void | | +| [registerType](./kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md) | | Executor['registerType'] | | +| [registerTypes](./kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md) | | Executor['registerTypes'] | | | [renderers](./kibana-plugin-plugins-expressions-public.expressionsservice.renderers.md) | | ExpressionRendererRegistry | | | [run](./kibana-plugin-plugins-expressions-public.expressionsservice.run.md) | | ExpressionsServiceStart['run'] | | | [telemetry](./kibana-plugin-plugins-expressions-public.expressionsservice.telemetry.md) | | (state: ExpressionAstExpression, telemetryData?: Record<string, any>) => Record<string, any> | Extracts telemetry from expression AST | diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md index 0653e68bb4837..8c37d24cc6f2b 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunction.md @@ -31,5 +31,5 @@ The actual function is defined in the `fn` key. The function can be \*async\*. I Signature: ```typescript -readonly registerFunction: (functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)) => void; +readonly registerFunction: Executor['registerFunction']; ``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md new file mode 100644 index 0000000000000..87231f29b4892 --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [registerFunctions](./kibana-plugin-plugins-expressions-public.expressionsservice.registerfunctions.md) + +## ExpressionsService.registerFunctions property + +Register a collection of expression functions. See `registerFunction` for details. + +Signature: + +```typescript +readonly registerFunctions: Executor['registerFunctions']; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md index 7aff36e7fd817..60b8c5887b138 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderer.md @@ -7,5 +7,5 @@ Signature: ```typescript -readonly registerRenderer: (definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)) => void; +readonly registerRenderer: ExpressionRendererRegistry['register']; ``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md new file mode 100644 index 0000000000000..0d6880a78c54c --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [registerRenderers](./kibana-plugin-plugins-expressions-public.expressionsservice.registerrenderers.md) + +## ExpressionsService.registerRenderers property + +Signature: + +```typescript +readonly registerRenderers: (definitions: Array AnyExpressionRenderDefinition)>) => void; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md index e6e71e5e7e7e9..7bbfb1256e1ab 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertype.md @@ -7,5 +7,5 @@ Signature: ```typescript -readonly registerType: (typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)) => void; +readonly registerType: Executor['registerType']; ``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md new file mode 100644 index 0000000000000..0d647d811ff71 --- /dev/null +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md @@ -0,0 +1,11 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) > [ExpressionsService](./kibana-plugin-plugins-expressions-public.expressionsservice.md) > [registerTypes](./kibana-plugin-plugins-expressions-public.expressionsservice.registertypes.md) + +## ExpressionsService.registerTypes property + +Signature: + +```typescript +readonly registerTypes: Executor['registerTypes']; +``` diff --git a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservicesetup.md b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservicesetup.md index 4cf3fb9b53978..909fc68edbc1a 100644 --- a/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservicesetup.md +++ b/docs/development/plugins/expressions/public/kibana-plugin-plugins-expressions-public.expressionsservicesetup.md @@ -9,5 +9,5 @@ The public contract that `ExpressionsService` provides to other plugins in Kiban Signature: ```typescript -export declare type ExpressionsServiceSetup = Pick; +export declare type ExpressionsServiceSetup = Pick; ``` diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasefunctions.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasefunctions.md new file mode 100644 index 0000000000000..a50c8cec2bac6 --- /dev/null +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasefunctions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [Executor](./kibana-plugin-plugins-expressions-server.executor.md) > [leaseFunctions](./kibana-plugin-plugins-expressions-server.executor.leasefunctions.md) + +## Executor.leaseFunctions() method + +Register a collection of functions meant to be deregegistered by the registering context, when they are no longer to be used, which can be done with the callback returned. + +Signature: + +```typescript +leaseFunctions(functionDefinitions: FunctionDefinition[]): () => ExecutorState>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| functionDefinitions | FunctionDefinition[] | | + +Returns: + +`() => ExecutorState>` + diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasetypes.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasetypes.md new file mode 100644 index 0000000000000..0a078d61cd766 --- /dev/null +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.leasetypes.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [Executor](./kibana-plugin-plugins-expressions-server.executor.md) > [leaseTypes](./kibana-plugin-plugins-expressions-server.executor.leasetypes.md) + +## Executor.leaseTypes() method + +Register a collection of types meant to be deregegistered by the registering context when they are no longer to be used, which can be done with the callback returned. + +Signature: + +```typescript +leaseTypes(typeDefinitions: TypeDefinition[]): () => ExecutorState>; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| typeDefinitions | TypeDefinition[] | | + +Returns: + +`() => ExecutorState>` + diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.md index 48002a9f986df..dab4558606b88 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.md @@ -39,9 +39,13 @@ export declare class Executor = RecordSignature: ```typescript -registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void; +registerFunction(functionDefinition: FunctionDefinition): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| functionDefinition | AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition) | | +| functionDefinition | FunctionDefinition | | Returns: diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registerfunctions.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registerfunctions.md new file mode 100644 index 0000000000000..d79bbcc30da2f --- /dev/null +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registerfunctions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [Executor](./kibana-plugin-plugins-expressions-server.executor.md) > [registerFunctions](./kibana-plugin-plugins-expressions-server.executor.registerfunctions.md) + +## Executor.registerFunctions() method + +Register a collection of functions with the executor. + +Signature: + +```typescript +registerFunctions(functionDefinitions: FunctionDefinition[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| functionDefinitions | FunctionDefinition[] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertype.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertype.md index 355ff92921f10..7220dc7ad3a4d 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertype.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertype.md @@ -4,17 +4,19 @@ ## Executor.registerType() method +Register a single type with the executor. + Signature: ```typescript -registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void; +registerType(typeDefinition: TypeDefinition): void; ``` ## Parameters | Parameter | Type | Description | | --- | --- | --- | -| typeDefinition | AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition) | | +| typeDefinition | TypeDefinition | | Returns: diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertypes.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertypes.md new file mode 100644 index 0000000000000..7a04b95b32463 --- /dev/null +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.executor.registertypes.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [Executor](./kibana-plugin-plugins-expressions-server.executor.md) > [registerTypes](./kibana-plugin-plugins-expressions-server.executor.registertypes.md) + +## Executor.registerTypes() method + +Register a collection of types with the executor. + +Signature: + +```typescript +registerTypes(typeDefinitions: TypeDefinition[]): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| typeDefinitions | TypeDefinition[] | | + +Returns: + +`void` + diff --git a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.expressionrendererregistry.md b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.expressionrendererregistry.md index d4a34ab140854..c216b8c691d91 100644 --- a/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.expressionrendererregistry.md +++ b/docs/development/plugins/expressions/server/kibana-plugin-plugins-expressions-server.expressionrendererregistry.md @@ -16,6 +16,7 @@ export declare class ExpressionRendererRegistry implements IRegistry + +[Home](./index.md) > [kibana-plugin-plugins-expressions-server](./kibana-plugin-plugins-expressions-server.md) > [ExpressionRendererRegistry](./kibana-plugin-plugins-expressions-server.expressionrendererregistry.md) > [remove](./kibana-plugin-plugins-expressions-server.expressionrendererregistry.remove.md) + +## ExpressionRendererRegistry.remove() method + +Signature: + +```typescript +remove(name: string): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| name | string | | + +Returns: + +`void` + diff --git a/src/plugins/expressions/common/executor/executor.ts b/src/plugins/expressions/common/executor/executor.ts index 1fba3b28a0ed5..5de0061ed7bbe 100644 --- a/src/plugins/expressions/common/executor/executor.ts +++ b/src/plugins/expressions/common/executor/executor.ts @@ -108,10 +108,16 @@ export class Executor = Record new ExpressionFunction(typeof fn === 'object' ? fn : fn()) @@ -120,6 +126,10 @@ export class Executor = Record new ExpressionFunction(typeof fn === 'object' ? fn : fn()) @@ -139,10 +149,16 @@ export class Executor = Record @@ -152,6 +168,10 @@ export class Executor = Record diff --git a/src/plugins/expressions/common/service/expressions_services.ts b/src/plugins/expressions/common/service/expressions_services.ts index f505b316178e6..7a0c7a5919a45 100644 --- a/src/plugins/expressions/common/service/expressions_services.ts +++ b/src/plugins/expressions/common/service/expressions_services.ts @@ -239,9 +239,17 @@ export class ExpressionsService implements PersistableStateService this.executor.registerFunction(functionDefinition); + /** + * Register a collection of expression functions. See `registerFunction` for details. + */ public readonly registerFunctions: Executor['registerFunctions'] = (functionDefinitions) => this.executor.registerFunctions(functionDefinitions); + /** + * Register a collection of expression functions that are meant to be deregistered by the + * registering context, (e.g. a plugin leases on mount and deregisters on unmount). This + * call returns a simple callback to make registering easier. + */ public readonly leaseFunctions: Executor['leaseFunctions'] = (fns) => this.executor.leaseFunctions(fns); diff --git a/src/plugins/expressions/public/mocks.tsx b/src/plugins/expressions/public/mocks.tsx index 84287aefe046b..ed010f8d0071a 100644 --- a/src/plugins/expressions/public/mocks.tsx +++ b/src/plugins/expressions/public/mocks.tsx @@ -27,6 +27,12 @@ const createSetupContract = (): Setup => { registerRenderer: jest.fn(), registerType: jest.fn(), run: jest.fn(), + leaseFunctions: jest.fn(), + leaseRenderers: jest.fn(), + leaseTypes: jest.fn(), + registerFunctions: jest.fn(), + registerRenderers: jest.fn(), + registerTypes: jest.fn(), }; return setupContract; }; diff --git a/src/plugins/expressions/public/public.api.md b/src/plugins/expressions/public/public.api.md index 2d9c6d94cfa6d..54a96deaa854b 100644 --- a/src/plugins/expressions/public/public.api.md +++ b/src/plugins/expressions/public/public.api.md @@ -223,14 +223,18 @@ export class Executor = Record ExecutorState>; + leaseTypes(typeDefinitions: TypeDefinition[]): () => ExecutorState>; // Warning: (ae-forgotten-export) The symbol "SerializableState" needs to be exported by the entry point index.d.ts // // (undocumented) migrate(ast: SerializableState, version: string): ExpressionAstExpression; - // (undocumented) - registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void; - // (undocumented) - registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void; + // Warning: (ae-forgotten-export) The symbol "FunctionDefinition" needs to be exported by the entry point index.d.ts + registerFunction(functionDefinition: FunctionDefinition): void; + registerFunctions(functionDefinitions: FunctionDefinition[]): void; + // Warning: (ae-forgotten-export) The symbol "TypeDefinition" needs to be exported by the entry point index.d.ts + registerType(typeDefinition: TypeDefinition): void; + registerTypes(typeDefinitions: TypeDefinition[]): void; run(ast: string | ExpressionAstExpression, input: Input, params?: ExpressionExecutionParams): Observable>; // (undocumented) readonly state: ExecutorContainer; @@ -515,6 +519,8 @@ export class ExpressionRendererRegistry implements IRegistry // (undocumented) register(definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)): void; // (undocumented) + remove(name: string): void; + // (undocumented) toArray(): ExpressionRenderer[]; // (undocumented) toJS(): Record; @@ -607,12 +613,22 @@ export class ExpressionsService implements PersistableStateService ReturnType; readonly inject: (state: ExpressionAstExpression, references: SavedObjectReference[]) => ExpressionAstExpression; + readonly leaseFunctions: Executor['leaseFunctions']; + // (undocumented) + readonly leaseRenderers: (definitions: Array AnyExpressionRenderDefinition)>) => () => void; + // (undocumented) + readonly leaseTypes: Executor['leaseTypes']; readonly migrate: (state: SerializableState, version: string) => ExpressionAstExpression; - readonly registerFunction: (functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)) => void; + readonly registerFunction: Executor['registerFunction']; + readonly registerFunctions: Executor['registerFunctions']; + // (undocumented) + readonly registerRenderer: ExpressionRendererRegistry['register']; + // (undocumented) + readonly registerRenderers: (definitions: Array AnyExpressionRenderDefinition)>) => void; // (undocumented) - readonly registerRenderer: (definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)) => void; + readonly registerType: Executor['registerType']; // (undocumented) - readonly registerType: (typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)) => void; + readonly registerTypes: Executor['registerTypes']; // (undocumented) readonly renderers: ExpressionRendererRegistry; // (undocumented) @@ -627,7 +643,7 @@ export class ExpressionsService implements PersistableStateService; +export type ExpressionsServiceSetup = Pick; // Warning: (ae-missing-release-tag) "ExpressionsServiceStart" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) // diff --git a/src/plugins/expressions/server/mocks.ts b/src/plugins/expressions/server/mocks.ts index 9bc25d89a04ca..1c93627c7b61b 100644 --- a/src/plugins/expressions/server/mocks.ts +++ b/src/plugins/expressions/server/mocks.ts @@ -26,6 +26,12 @@ const createSetupContract = (): Setup => { registerRenderer: jest.fn(), registerType: jest.fn(), run: jest.fn(), + leaseFunctions: jest.fn(), + leaseRenderers: jest.fn(), + leaseTypes: jest.fn(), + registerFunctions: jest.fn(), + registerRenderers: jest.fn(), + registerTypes: jest.fn(), }; return setupContract; }; diff --git a/src/plugins/expressions/server/server.api.md b/src/plugins/expressions/server/server.api.md index ec16d95ea8a3f..e2c714ad1493f 100644 --- a/src/plugins/expressions/server/server.api.md +++ b/src/plugins/expressions/server/server.api.md @@ -205,14 +205,18 @@ export class Executor = Record ExecutorState>; + leaseTypes(typeDefinitions: TypeDefinition[]): () => ExecutorState>; // Warning: (ae-forgotten-export) The symbol "SerializableState" needs to be exported by the entry point index.d.ts // // (undocumented) migrate(ast: SerializableState, version: string): ExpressionAstExpression; - // (undocumented) - registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void; - // (undocumented) - registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void; + // Warning: (ae-forgotten-export) The symbol "FunctionDefinition" needs to be exported by the entry point index.d.ts + registerFunction(functionDefinition: FunctionDefinition): void; + registerFunctions(functionDefinitions: FunctionDefinition[]): void; + // Warning: (ae-forgotten-export) The symbol "TypeDefinition" needs to be exported by the entry point index.d.ts + registerType(typeDefinition: TypeDefinition): void; + registerTypes(typeDefinitions: TypeDefinition[]): void; run(ast: string | ExpressionAstExpression, input: Input, params?: ExpressionExecutionParams): Observable>; // (undocumented) readonly state: ExecutorContainer; @@ -472,6 +476,8 @@ export class ExpressionRendererRegistry implements IRegistry // (undocumented) register(definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)): void; // (undocumented) + remove(name: string): void; + // (undocumented) toArray(): ExpressionRenderer[]; // (undocumented) toJS(): Record;