Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS of esKuery\node_types #56857

Merged
merged 4 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Code review
  • Loading branch information
Liza K committed Feb 6, 2020
commit 0b78487fee617a0843f8cc70b1d378b1eeccb12e
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