Skip to content

Commit

Permalink
[Expressions] Finish connecting debug mode on expressions (#78874) (#…
Browse files Browse the repository at this point in the history
…80862)

* [Expressions] Finish connecting debug mode on expressions

* Fix bad merge

* Commit API docs
  • Loading branch information
Wylie Conlon authored Oct 16, 2020
1 parent dc3fbd5 commit 549ab5a
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export declare class Executor<Context extends Record<string, unknown> = Record<s
| [inject(ast, references)](./kibana-plugin-plugins-expressions-public.executor.inject.md) | | |
| [registerFunction(functionDefinition)](./kibana-plugin-plugins-expressions-public.executor.registerfunction.md) | | |
| [registerType(typeDefinition)](./kibana-plugin-plugins-expressions-public.executor.registertype.md) | | |
| [run(ast, input, context)](./kibana-plugin-plugins-expressions-public.executor.run.md) | | Execute expression and return result. |
| [run(ast, input, context, options)](./kibana-plugin-plugins-expressions-public.executor.run.md) | | Execute expression and return result. |
| [telemetry(ast, telemetryData)](./kibana-plugin-plugins-expressions-public.executor.telemetry.md) | | |
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Execute expression and return result.
<b>Signature:</b>

```typescript
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext): Promise<Output>;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions): Promise<Output>;
```
## Parameters
Expand All @@ -19,6 +19,7 @@ run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string,
| ast | <code>string &#124; ExpressionAstExpression</code> | |
| input | <code>Input</code> | |
| context | <code>ExtraContext</code> | |
| options | <code>ExpressionExecOptions</code> | |
<b>Returns:</b>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Starts expression execution and immediately returns `ExecutionContract` instance
<b>Signature:</b>

```typescript
execute: <Input = unknown, Output = unknown, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext) => ExecutionContract<ExtraContext, Input, Output>;
execute: <Input = unknown, Output = unknown, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) => ExecutionContract<ExtraContext, Input, Output>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export interface ExpressionsServiceStart

| Property | Type | Description |
| --- | --- | --- |
| [execute](./kibana-plugin-plugins-expressions-public.expressionsservicestart.execute.md) | <code>&lt;Input = unknown, Output = unknown, ExtraContext extends Record&lt;string, unknown&gt; = Record&lt;string, unknown&gt;&gt;(ast: string &#124; ExpressionAstExpression, input: Input, context?: ExtraContext) =&gt; ExecutionContract&lt;ExtraContext, Input, Output&gt;</code> | Starts expression execution and immediately returns <code>ExecutionContract</code> instance that tracks the progress of the execution and can be used to interact with the execution. |
| [execute](./kibana-plugin-plugins-expressions-public.expressionsservicestart.execute.md) | <code>&lt;Input = unknown, Output = unknown, ExtraContext extends Record&lt;string, unknown&gt; = Record&lt;string, unknown&gt;&gt;(ast: string &#124; ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) =&gt; ExecutionContract&lt;ExtraContext, Input, Output&gt;</code> | Starts expression execution and immediately returns <code>ExecutionContract</code> instance that tracks the progress of the execution and can be used to interact with the execution. |
| [fork](./kibana-plugin-plugins-expressions-public.expressionsservicestart.fork.md) | <code>() =&gt; ExpressionsService</code> | Create a new instance of <code>ExpressionsService</code>. The new instance inherits all state of the original <code>ExpressionsService</code>, including all expression types, expression functions and context. Also, all new types and functions registered in the original services AFTER the forking event will be available in the forked instance. However, all new types and functions registered in the forked instances will NOT be available to the original service. |
| [getFunction](./kibana-plugin-plugins-expressions-public.expressionsservicestart.getfunction.md) | <code>(name: string) =&gt; ReturnType&lt;Executor['getFunction']&gt;</code> | Get a registered <code>ExpressionFunction</code> by its name, which was registered using the <code>registerFunction</code> method. The returned <code>ExpressionFunction</code> instance is an internal representation of the function in Expressions service - do not mutate that object. |
| [getRenderer](./kibana-plugin-plugins-expressions-public.expressionsservicestart.getrenderer.md) | <code>(name: string) =&gt; ReturnType&lt;ExpressionRendererRegistry['get']&gt;</code> | Get a registered <code>ExpressionRenderer</code> by its name, which was registered using the <code>registerRenderer</code> method. The returned <code>ExpressionRenderer</code> instance is an internal representation of the renderer in Expressions service - do not mutate that object. |
| [getType](./kibana-plugin-plugins-expressions-public.expressionsservicestart.gettype.md) | <code>(name: string) =&gt; ReturnType&lt;Executor['getType']&gt;</code> | Get a registered <code>ExpressionType</code> by its name, which was registered using the <code>registerType</code> method. The returned <code>ExpressionType</code> instance is an internal representation of the type in Expressions service - do not mutate that object. |
| [run](./kibana-plugin-plugins-expressions-public.expressionsservicestart.run.md) | <code>&lt;Input, Output, ExtraContext extends Record&lt;string, unknown&gt; = Record&lt;string, unknown&gt;&gt;(ast: string &#124; ExpressionAstExpression, input: Input, context?: ExtraContext) =&gt; Promise&lt;Output&gt;</code> | Executes expression string or a parsed expression AST and immediately returns the result.<!-- -->Below example will execute <code>sleep 100 &#124; clog</code> expression with <code>123</code> initial input to the first function.
| [run](./kibana-plugin-plugins-expressions-public.expressionsservicestart.run.md) | <code>&lt;Input, Output, ExtraContext extends Record&lt;string, unknown&gt; = Record&lt;string, unknown&gt;&gt;(ast: string &#124; ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) =&gt; Promise&lt;Output&gt;</code> | Executes expression string or a parsed expression AST and immediately returns the result.<!-- -->Below example will execute <code>sleep 100 &#124; clog</code> expression with <code>123</code> initial input to the first function.
```ts
expressions.run('sleep 100 | clog', 123);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ expressions.run('...', null, { elasticsearchClient });
<b>Signature:</b>

```typescript
run: <Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext) => Promise<Output>;
run: <Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) => Promise<Output>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-expressions-public](./kibana-plugin-plugins-expressions-public.md) &gt; [IExpressionLoaderParams](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.md) &gt; [debug](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.debug.md)

## IExpressionLoaderParams.debug property

<b>Signature:</b>

```typescript
debug?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface IExpressionLoaderParams
| [context](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.context.md) | <code>ExpressionValue</code> | |
| [customFunctions](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.customfunctions.md) | <code>[]</code> | |
| [customRenderers](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.customrenderers.md) | <code>[]</code> | |
| [debug](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.debug.md) | <code>boolean</code> | |
| [disableCaching](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.disablecaching.md) | <code>boolean</code> | |
| [inspectorAdapters](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.inspectoradapters.md) | <code>Adapters</code> | |
| [onRenderError](./kibana-plugin-plugins-expressions-public.iexpressionloaderparams.onrendererror.md) | <code>RenderErrorHandlerFnType</code> | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export declare class Executor<Context extends Record<string, unknown> = Record<s
| [inject(ast, references)](./kibana-plugin-plugins-expressions-server.executor.inject.md) | | |
| [registerFunction(functionDefinition)](./kibana-plugin-plugins-expressions-server.executor.registerfunction.md) | | |
| [registerType(typeDefinition)](./kibana-plugin-plugins-expressions-server.executor.registertype.md) | | |
| [run(ast, input, context)](./kibana-plugin-plugins-expressions-server.executor.run.md) | | Execute expression and return result. |
| [run(ast, input, context, options)](./kibana-plugin-plugins-expressions-server.executor.run.md) | | Execute expression and return result. |
| [telemetry(ast, telemetryData)](./kibana-plugin-plugins-expressions-server.executor.telemetry.md) | | |
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Execute expression and return result.
<b>Signature:</b>

```typescript
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext): Promise<Output>;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions): Promise<Output>;
```
## Parameters
Expand All @@ -19,6 +19,7 @@ run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string,
| ast | <code>string &#124; ExpressionAstExpression</code> | |
| input | <code>Input</code> | |
| context | <code>ExtraContext</code> | |
| options | <code>ExpressionExecOptions</code> | |
<b>Returns:</b>
Expand Down
9 changes: 7 additions & 2 deletions src/plugins/expressions/common/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,13 @@ export class Executor<Context extends Record<string, unknown> = Record<string, u
Input,
Output,
ExtraContext extends Record<string, unknown> = Record<string, unknown>
>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext) {
const execution = this.createExecution(ast, context);
>(
ast: string | ExpressionAstExpression,
input: Input,
context?: ExtraContext,
options?: ExpressionExecOptions
) {
const execution = this.createExecution(ast, context, options);
execution.start(input);
return (await execution.result) as Output;
}
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/expressions/common/service/expressions_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/

import { Executor } from '../executor';
import { Executor, ExpressionExecOptions } from '../executor';
import { AnyExpressionRenderDefinition, ExpressionRendererRegistry } from '../expression_renderers';
import { ExpressionAstExpression } from '../ast';
import { ExecutionContract } from '../execution/execution_contract';
Expand Down Expand Up @@ -101,7 +101,8 @@ export interface ExpressionsServiceStart {
run: <Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(
ast: string | ExpressionAstExpression,
input: Input,
context?: ExtraContext
context?: ExtraContext,
options?: ExpressionExecOptions
) => Promise<Output>;

/**
Expand All @@ -117,7 +118,8 @@ export interface ExpressionsServiceStart {
ast: string | ExpressionAstExpression,
// This any is for legacy reasons.
input: Input,
context?: ExtraContext
context?: ExtraContext,
options?: ExpressionExecOptions
) => ExecutionContract<ExtraContext, Input, Output>;

/**
Expand Down Expand Up @@ -212,8 +214,8 @@ export class ExpressionsService implements PersistableState<ExpressionAstExpress
definition: AnyExpressionRenderDefinition | (() => AnyExpressionRenderDefinition)
): void => this.renderers.register(definition);

public readonly run: ExpressionsServiceStart['run'] = (ast, input, context) =>
this.executor.run(ast, input, context);
public readonly run: ExpressionsServiceStart['run'] = (ast, input, context, options) =>
this.executor.run(ast, input, context, options);

public readonly getFunction: ExpressionsServiceStart['getFunction'] = (name) =>
this.executor.getFunction(name);
Expand Down Expand Up @@ -244,8 +246,8 @@ export class ExpressionsService implements PersistableState<ExpressionAstExpress
*/
public readonly getTypes = (): ReturnType<Executor['getTypes']> => this.executor.getTypes();

public readonly execute: ExpressionsServiceStart['execute'] = ((ast, input, context) => {
const execution = this.executor.createExecution(ast, context);
public readonly execute: ExpressionsServiceStart['execute'] = ((ast, input, context, options) => {
const execution = this.executor.createExecution(ast, context, options);
execution.start(input);
return execution.contract;
}) as ExpressionsServiceStart['execute'];
Expand Down
18 changes: 13 additions & 5 deletions src/plugins/expressions/public/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,18 @@ export class ExpressionLoader {
this.execution.cancel();
}
this.setParams(params);
this.execution = getExpressionsService().execute(expression, params.context, {
search: params.searchContext,
variables: params.variables || {},
inspectorAdapters: params.inspectorAdapters,
});
this.execution = getExpressionsService().execute(
expression,
params.context,
{
search: params.searchContext,
variables: params.variables || {},
inspectorAdapters: params.inspectorAdapters,
},
{
debug: params.debug,
}
);

const prevDataHandler = this.execution;
const data = await prevDataHandler.getData();
Expand Down Expand Up @@ -181,6 +188,7 @@ export class ExpressionLoader {
if (params.variables && this.params) {
this.params.variables = params.variables;
}
this.params.debug = Boolean(params.debug);

this.params.inspectorAdapters = (params.inspectorAdapters ||
this.execution?.inspect()) as Adapters;
Expand Down
8 changes: 5 additions & 3 deletions src/plugins/expressions/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class Executor<Context extends Record<string, unknown> = Record<string, u
registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void;
// (undocumented)
registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext): Promise<Output>;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions): Promise<Output>;
// (undocumented)
readonly state: ExecutorContainer<Context>;
// (undocumented)
Expand Down Expand Up @@ -609,12 +609,12 @@ export type ExpressionsServiceSetup = Pick<ExpressionsService, 'getFunction' | '
//
// @public
export interface ExpressionsServiceStart {
execute: <Input = unknown, Output = unknown, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext) => ExecutionContract<ExtraContext, Input, Output>;
execute: <Input = unknown, Output = unknown, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) => ExecutionContract<ExtraContext, Input, Output>;
fork: () => ExpressionsService;
getFunction: (name: string) => ReturnType<Executor['getFunction']>;
getRenderer: (name: string) => ReturnType<ExpressionRendererRegistry['get']>;
getType: (name: string) => ReturnType<Executor['getType']>;
run: <Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext) => Promise<Output>;
run: <Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions) => Promise<Output>;
}

// Warning: (ae-missing-release-tag) "ExpressionsSetup" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
Expand Down Expand Up @@ -878,6 +878,8 @@ export interface IExpressionLoaderParams {
// (undocumented)
customRenderers?: [];
// (undocumented)
debug?: boolean;
// (undocumented)
disableCaching?: boolean;
// (undocumented)
inspectorAdapters?: Adapters;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/expressions/public/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface IExpressionLoaderParams {
searchContext?: ExecutionContextSearch;
context?: ExpressionValue;
variables?: Record<string, any>;
// Enables debug tracking on each expression in the AST
debug?: boolean;
disableCaching?: boolean;
customFunctions?: [];
customRenderers?: [];
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/server/server.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class Executor<Context extends Record<string, unknown> = Record<string, u
registerFunction(functionDefinition: AnyExpressionFunctionDefinition | (() => AnyExpressionFunctionDefinition)): void;
// (undocumented)
registerType(typeDefinition: AnyExpressionTypeDefinition | (() => AnyExpressionTypeDefinition)): void;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext): Promise<Output>;
run<Input, Output, ExtraContext extends Record<string, unknown> = Record<string, unknown>>(ast: string | ExpressionAstExpression, input: Input, context?: ExtraContext, options?: ExpressionExecOptions): Promise<Output>;
// (undocumented)
readonly state: ExecutorContainer<Context>;
// (undocumented)
Expand Down

0 comments on commit 549ab5a

Please sign in to comment.