mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
Clean up literal type (#133844)
This commit is contained in:
parent
98cc8ac02e
commit
a3a3e5a8a7
11 changed files with 28 additions and 66 deletions
|
@ -43,7 +43,6 @@ export type {
|
|||
KueryNode,
|
||||
KueryParseOptions,
|
||||
KueryQueryOptions,
|
||||
NodeTypes,
|
||||
} from './kuery';
|
||||
|
||||
export {
|
||||
|
|
|
@ -8,13 +8,12 @@
|
|||
|
||||
import * as literal from '../../node_types/literal';
|
||||
import * as wildcard from '../../node_types/wildcard';
|
||||
import { KueryNode, DataViewBase } from '../../..';
|
||||
import { LiteralTypeBuildNode } from '../../node_types/types';
|
||||
import { DataViewBase, KueryNode } from '../../..';
|
||||
|
||||
export function getFields(node: KueryNode, indexPattern?: DataViewBase) {
|
||||
if (!indexPattern) return [];
|
||||
if (node.type === 'literal') {
|
||||
const fieldName = literal.toElasticsearchQuery(node as LiteralTypeBuildNode);
|
||||
if (literal.isNode(node)) {
|
||||
const fieldName = literal.toElasticsearchQuery(node);
|
||||
const field = indexPattern.fields.find((fld) => fld.name === fieldName);
|
||||
if (!field) {
|
||||
return [];
|
||||
|
|
|
@ -24,5 +24,5 @@ export { KQLSyntaxError } from './kuery_syntax_error';
|
|||
export { nodeTypes, nodeBuilder } from './node_types';
|
||||
export { fromKueryExpression } from './ast';
|
||||
export { escapeKuery } from './utils';
|
||||
export type { FunctionTypeBuildNode, NodeTypes } from './node_types';
|
||||
export type { FunctionTypeBuildNode } from './node_types';
|
||||
export type { DslQuery, KueryNode, KueryQueryOptions, KueryParseOptions } from './types';
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
import * as functionType from './function';
|
||||
import * as literal from './literal';
|
||||
import * as wildcard from './wildcard';
|
||||
import { FunctionTypeBuildNode, NodeTypes } from './types';
|
||||
import { FunctionTypeBuildNode } from './types';
|
||||
|
||||
export type { FunctionTypeBuildNode, NodeTypes };
|
||||
export type { FunctionTypeBuildNode };
|
||||
export { nodeBuilder } from './node_builder';
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const nodeTypes: NodeTypes = {
|
||||
export const nodeTypes = {
|
||||
// This requires better typing of the different typings and their return types.
|
||||
// @ts-ignore
|
||||
function: functionType,
|
||||
|
|
|
@ -6,15 +6,28 @@
|
|||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import { LiteralTypeBuildNode } from './types';
|
||||
import type { KueryNode } from '../types';
|
||||
|
||||
export function buildNode(value: LiteralTypeBuildNode['value']): LiteralTypeBuildNode {
|
||||
export const KQL_NODE_TYPE_LITERAL = 'literal';
|
||||
|
||||
export type KqlLiteralType = null | boolean | number | string;
|
||||
|
||||
export interface KqlLiteralNode extends KueryNode {
|
||||
type: typeof KQL_NODE_TYPE_LITERAL;
|
||||
value: KqlLiteralType;
|
||||
}
|
||||
|
||||
export function isNode(node: KueryNode): node is KqlLiteralNode {
|
||||
return node.type === KQL_NODE_TYPE_LITERAL;
|
||||
}
|
||||
|
||||
export function buildNode(value: KqlLiteralType): KqlLiteralNode {
|
||||
return {
|
||||
type: 'literal',
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
export function toElasticsearchQuery(node: LiteralTypeBuildNode): LiteralTypeBuildNode['value'] {
|
||||
export function toElasticsearchQuery(node: KqlLiteralNode) {
|
||||
return node.value;
|
||||
}
|
||||
|
|
|
@ -10,23 +10,8 @@
|
|||
* WARNING: these typings are incomplete
|
||||
*/
|
||||
|
||||
import { JsonValue } from '@kbn/utility-types';
|
||||
import { KueryNode, KueryQueryOptions } from '..';
|
||||
import { DataViewBase } from '../..';
|
||||
|
||||
export type FunctionName = 'is' | 'and' | 'or' | 'not' | 'range' | 'exists' | 'nested';
|
||||
|
||||
interface FunctionType {
|
||||
buildNode: (functionName: FunctionName, ...args: any[]) => FunctionTypeBuildNode;
|
||||
buildNodeWithArgumentNodes: (functionName: FunctionName, args: any[]) => FunctionTypeBuildNode;
|
||||
toElasticsearchQuery: (
|
||||
node: any,
|
||||
indexPattern?: DataViewBase,
|
||||
config?: KueryQueryOptions,
|
||||
context?: Record<string, any>
|
||||
) => JsonValue;
|
||||
}
|
||||
|
||||
export interface FunctionTypeBuildNode {
|
||||
type: 'function';
|
||||
function: FunctionName;
|
||||
|
@ -34,32 +19,7 @@ export interface FunctionTypeBuildNode {
|
|||
arguments: any[];
|
||||
}
|
||||
|
||||
interface LiteralType {
|
||||
buildNode: (value: null | boolean | number | string) => LiteralTypeBuildNode;
|
||||
toElasticsearchQuery: (node: any) => null | boolean | number | string;
|
||||
}
|
||||
|
||||
export interface LiteralTypeBuildNode {
|
||||
type: 'literal';
|
||||
value: null | boolean | number | string;
|
||||
}
|
||||
|
||||
interface WildcardType {
|
||||
wildcardSymbol: string;
|
||||
buildNode: (value: string) => WildcardTypeBuildNode | KueryNode;
|
||||
test: (node: any, string: string) => boolean;
|
||||
toElasticsearchQuery: (node: any) => string;
|
||||
toQueryStringQuery: (node: any) => string;
|
||||
hasLeadingWildcard: (node: any) => boolean;
|
||||
}
|
||||
|
||||
export interface WildcardTypeBuildNode {
|
||||
type: 'wildcard';
|
||||
value: string;
|
||||
}
|
||||
|
||||
export interface NodeTypes {
|
||||
function: FunctionType;
|
||||
literal: LiteralType;
|
||||
wildcard: WildcardType;
|
||||
}
|
||||
|
|
|
@ -8,11 +8,14 @@
|
|||
|
||||
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
|
||||
import { SerializableRecord } from '@kbn/utility-types';
|
||||
import { NodeTypes } from './node_types';
|
||||
import { KQL_NODE_TYPE_LITERAL } from './node_types/literal';
|
||||
|
||||
/** @public */
|
||||
export type KqlNodeType = typeof KQL_NODE_TYPE_LITERAL | 'function' | 'wildcard';
|
||||
|
||||
/** @public */
|
||||
export interface KueryNode {
|
||||
type: keyof NodeTypes;
|
||||
type: KqlNodeType;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ import {
|
|||
disableFilter as oldDisableFilter,
|
||||
fromKueryExpression as oldFromKueryExpression,
|
||||
toElasticsearchQuery as oldToElasticsearchQuery,
|
||||
nodeTypes as oldNodeTypes,
|
||||
buildEsQuery as oldBuildEsQuery,
|
||||
buildQueryFromFilters as oldBuildQueryFromFilters,
|
||||
luceneStringToDsl as oldLuceneStringToDsl,
|
||||
|
@ -81,11 +80,6 @@ const fromKueryExpression = oldFromKueryExpression;
|
|||
* @removeBy 8.1
|
||||
*/
|
||||
const toElasticsearchQuery = oldToElasticsearchQuery;
|
||||
/**
|
||||
* @deprecated Import from the "@kbn/es-query" package directly instead.
|
||||
* @removeBy 8.1
|
||||
*/
|
||||
const nodeTypes = oldNodeTypes;
|
||||
/**
|
||||
* @deprecated Import from the "@kbn/es-query" package directly instead.
|
||||
* @removeBy 8.1
|
||||
|
@ -367,7 +361,6 @@ export {
|
|||
disableFilter,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
nodeTypes,
|
||||
buildEsQuery,
|
||||
buildQueryFromFilters,
|
||||
luceneStringToDsl,
|
||||
|
|
|
@ -46,7 +46,6 @@ export {
|
|||
getEsQueryConfig,
|
||||
luceneStringToDsl,
|
||||
nodeBuilder,
|
||||
nodeTypes,
|
||||
onlyDisabledFiltersChanged,
|
||||
pinFilter,
|
||||
toElasticsearchQuery,
|
||||
|
|
|
@ -30,7 +30,6 @@ import {
|
|||
disableFilter,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
nodeTypes,
|
||||
buildEsQuery,
|
||||
buildQueryFromFilters,
|
||||
luceneStringToDsl,
|
||||
|
@ -122,7 +121,6 @@ export { isFilters };
|
|||
* @removeBy 8.1
|
||||
*/
|
||||
export const esKuery = {
|
||||
nodeTypes,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
};
|
||||
|
|
|
@ -16,7 +16,6 @@ import {
|
|||
buildPhrasesFilter,
|
||||
buildRangeFilter,
|
||||
isFilterDisabled,
|
||||
nodeTypes,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
buildEsQuery,
|
||||
|
@ -51,7 +50,6 @@ import { getEsQueryConfig } from '../common';
|
|||
* @removeBy 8.1
|
||||
*/
|
||||
export const esKuery = {
|
||||
nodeTypes,
|
||||
fromKueryExpression,
|
||||
toElasticsearchQuery,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue