Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Liza K committed Feb 6, 2020
1 parent 0f55c77 commit 0b78487
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function buildNode(functionName: FunctionName, ...args: any[]) {
// Mainly only useful in the grammar where we'll already have real argument nodes in hand
export function buildNodeWithArgumentNodes(
functionName: FunctionName,
...args: any[]
args: any[]
): FunctionTypeBuildNode {
if (_.isUndefined(functions[functionName])) {
throw new Error(`Unknown function "${functionName}"`);
Expand Down
6 changes: 2 additions & 4 deletions src/plugins/data/common/es_query/kuery/node_types/literal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@

import { LiteralTypeBuildNode } from './types';

type LiteralNodeValue = null | boolean | number | string;

export function buildNode(value: LiteralNodeValue): LiteralTypeBuildNode {
export function buildNode(value: LiteralTypeBuildNode['value']): LiteralTypeBuildNode {
return {
type: 'literal',
value,
};
}

export function toElasticsearchQuery(node: LiteralTypeBuildNode): LiteralNodeValue {
export function toElasticsearchQuery(node: LiteralTypeBuildNode): LiteralTypeBuildNode['value'] {
return node.value;
}
6 changes: 3 additions & 3 deletions src/plugins/data/common/es_query/kuery/node_types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/

import { IIndexPattern } from '../../../index_patterns';
import { JsonValue } from '..';
import { JsonValue, KueryNode } from '..';

export type FunctionName =
| 'is'
Expand All @@ -37,7 +37,7 @@ export type FunctionName =

interface FunctionType {
buildNode: (functionName: FunctionName, ...args: any[]) => FunctionTypeBuildNode;
buildNodeWithArgumentNodes: (functionName: FunctionName, ...args: any[]) => FunctionTypeBuildNode;
buildNodeWithArgumentNodes: (functionName: FunctionName, args: any[]) => FunctionTypeBuildNode;
toElasticsearchQuery: (
node: any,
indexPattern?: IIndexPattern,
Expand Down Expand Up @@ -75,7 +75,7 @@ export interface NamedArgTypeBuildNode {
}

interface WildcardType {
buildNode: (value: string) => WildcardTypeBuildNode;
buildNode: (value: string) => WildcardTypeBuildNode | KueryNode;
test: (node: any, string: string) => boolean;
toElasticsearchQuery: (node: any) => string;
toQueryStringQuery: (node: any) => string;
Expand Down
5 changes: 3 additions & 2 deletions src/plugins/data/common/es_query/kuery/node_types/wildcard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import { fromLiteralExpression } from '../ast/ast';
import { WildcardTypeBuildNode } from './types';
import { KueryNode } from '..';

export const wildcardSymbol = '@kuery-wildcard@';

Expand All @@ -32,9 +33,9 @@ function escapeQueryString(str: string) {
return str.replace(/[+-=&|><!(){}[\]^"~*?:\\/]/g, '\\$&'); // $& means the whole matched string
}

export function buildNode(value: string): WildcardTypeBuildNode {
export function buildNode(value: string): WildcardTypeBuildNode | KueryNode {
if (!value.includes(wildcardSymbol)) {
return (fromLiteralExpression(value) as unknown) as WildcardTypeBuildNode;
return fromLiteralExpression(value);
}

return {
Expand Down

0 comments on commit 0b78487

Please sign in to comment.