Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into ingest-suppor…
Browse files Browse the repository at this point in the history
…t-mappings-settings
  • Loading branch information
jonathan-buttner committed Jul 6, 2020
2 parents d6d9ed2 + 89dcdbb commit fd973f1
Show file tree
Hide file tree
Showing 37 changed files with 630 additions and 890 deletions.
29 changes: 27 additions & 2 deletions src/plugins/expressions/common/execution/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import { keys, last, mapValues, reduce, zipObject } from 'lodash';
import { Executor } from '../executor';
import { Executor, ExpressionExecOptions } from '../executor';
import { createExecutionContainer, ExecutionContainer } from './container';
import { createError } from '../util';
import { Defer, now } from '../../../kibana_utils/common';
Expand All @@ -31,6 +31,7 @@ import {
parse,
formatExpression,
parseExpression,
ExpressionAstNode,
} from '../ast';
import { ExecutionContext, DefaultInspectorAdapters } from './types';
import { getType, ExpressionValue } from '../expression_types';
Expand Down Expand Up @@ -382,7 +383,7 @@ export class Execution<
const resolveArgFns = mapValues(argAstsWithDefaults, (asts, argName) => {
return asts.map((item: ExpressionAstExpression) => {
return async (subInput = input) => {
const output = await this.params.executor.interpret(item, subInput, {
const output = await this.interpret(item, subInput, {
debug: this.params.debug,
});
if (isExpressionValueError(output)) throw output.error;
Expand Down Expand Up @@ -415,4 +416,28 @@ export class Execution<
// function which would be treated as a promise
return { resolvedArgs };
}

public async interpret<T>(
ast: ExpressionAstNode,
input: T,
options?: ExpressionExecOptions
): Promise<unknown> {
switch (getType(ast)) {
case 'expression':
const execution = this.params.executor.createExecution(
ast as ExpressionAstExpression,
this.context,
options
);
execution.start(input);
return await execution.result;
case 'string':
case 'number':
case 'null':
case 'boolean':
return ast;
default:
throw new Error(`Unknown AST object: ${JSON.stringify(ast)}`);
}
}
}
31 changes: 1 addition & 30 deletions src/plugins/expressions/common/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import { Execution, ExecutionParams } from '../execution/execution';
import { IRegistry } from '../types';
import { ExpressionType } from '../expression_types/expression_type';
import { AnyExpressionTypeDefinition } from '../expression_types/types';
import { getType } from '../expression_types';
import { ExpressionAstExpression, ExpressionAstNode } from '../ast';
import { ExpressionAstExpression } from '../ast';
import { typeSpecs } from '../expression_types/specs';
import { functionSpecs } from '../expression_functions/specs';

Expand Down Expand Up @@ -154,34 +153,6 @@ export class Executor<Context extends Record<string, unknown> = Record<string, u
return this.state.selectors.getContext();
}

public async interpret<T>(
ast: ExpressionAstNode,
input: T,
options?: ExpressionExecOptions
): Promise<unknown> {
switch (getType(ast)) {
case 'expression':
return await this.interpretExpression(ast as ExpressionAstExpression, input, options);
case 'string':
case 'number':
case 'null':
case 'boolean':
return ast;
default:
throw new Error(`Unknown AST object: ${JSON.stringify(ast)}`);
}
}

public async interpretExpression<T>(
ast: string | ExpressionAstExpression,
input: T,
options?: ExpressionExecOptions
): Promise<unknown> {
const execution = this.createExecution(ast, undefined, options);
execution.start(input);
return await execution.result;
}

/**
* Execute expression and return result.
*
Expand Down

This file was deleted.

Loading

0 comments on commit fd973f1

Please sign in to comment.