Skip to content

Commit b31619a

Browse files
Merge branch 'main' into eui-60.0.0
2 parents ed28df2 + 3f1f450 commit b31619a

File tree

65 files changed

+958
-1494
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+958
-1494
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@
918918
"chai": "3.5.0",
919919
"chance": "1.0.18",
920920
"chokidar": "^3.4.3",
921-
"chromedriver": "^102.0.0",
921+
"chromedriver": "^103.0.0",
922922
"clean-webpack-plugin": "^3.0.0",
923923
"cmd-shim": "^2.1.0",
924924
"compression-webpack-plugin": "^4.0.0",
@@ -1046,7 +1046,7 @@
10461046
"resolve": "^1.22.0",
10471047
"rxjs-marbles": "^5.0.6",
10481048
"sass-loader": "^10.2.0",
1049-
"selenium-webdriver": "^4.2.0",
1049+
"selenium-webdriver": "^4.3.0",
10501050
"shelljs": "^0.8.4",
10511051
"simple-git": "1.116.0",
10521052
"sinon": "^7.4.2",

packages/kbn-es-query/grammar/grammar.peggy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
const buildFunctionNode = nodeTypes.function.buildNodeWithArgumentNodes;
1313
const buildLiteralNode = nodeTypes.literal.buildNode;
1414
const buildWildcardNode = nodeTypes.wildcard.buildNode;
15-
const { wildcardSymbol } = nodeTypes.wildcard;
15+
const { KQL_WILDCARD_SYMBOL } = nodeTypes.wildcard;
1616
}
1717

1818
start
@@ -189,7 +189,7 @@ Value "value"
189189
/ value:UnquotedLiteral {
190190
if (value.type === 'cursor') return value;
191191

192-
if (!allowLeadingWildcards && value.type === 'wildcard' && nodeTypes.wildcard.hasLeadingWildcard(value)) {
192+
if (!allowLeadingWildcards && nodeTypes.wildcard.isNode(value) && nodeTypes.wildcard.hasLeadingWildcard(value)) {
193193
error('Leading wildcards are disabled. See query:allowLeadingWildcards in Advanced Settings.');
194194
}
195195

@@ -248,7 +248,7 @@ UnquotedLiteral
248248
if (sequence === 'null') return buildLiteralNode(null);
249249
if (sequence === 'true') return buildLiteralNode(true);
250250
if (sequence === 'false') return buildLiteralNode(false);
251-
if (chars.includes(wildcardSymbol)) return buildWildcardNode(sequence);
251+
if (chars.includes(KQL_WILDCARD_SYMBOL)) return buildWildcardNode(sequence);
252252
return buildLiteralNode(sequence);
253253
}
254254

@@ -261,7 +261,7 @@ UnquotedCharacter
261261
/ !SpecialCharacter !Keyword !Cursor char:. { return char; }
262262

263263
Wildcard
264-
= '*' { return wildcardSymbol; }
264+
= '*' { return KQL_WILDCARD_SYMBOL; }
265265

266266
OptionalSpace
267267
= &{ return parseCursor; } prefix:Space* cursor:Cursor suffix:Space* {

packages/kbn-es-query/src/kuery/ast/ast.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { JsonObject } from '@kbn/utility-types';
1010
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
1111
import { nodeTypes } from '../node_types';
1212
import { KQLSyntaxError } from '../kuery_syntax_error';
13-
import { KueryNode, KueryParseOptions, KueryQueryOptions } from '../types';
13+
import type { KqlContext, KueryNode, KueryParseOptions, KueryQueryOptions } from '../types';
1414

1515
import { parse as parseKuery } from '../grammar';
1616
import { DataViewBase } from '../..';
@@ -68,7 +68,7 @@ export const toElasticsearchQuery = (
6868
node: KueryNode,
6969
indexPattern?: DataViewBase,
7070
config: KueryQueryOptions = {},
71-
context?: Record<string, any>
71+
context?: KqlContext
7272
): JsonObject => {
7373
if (!node || !node.type || !nodeTypes[node.type]) {
7474
return toElasticsearchQuery(nodeTypes.function.buildNode('and', []), indexPattern);

packages/kbn-es-query/src/kuery/functions/and.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
*/
88

99
import * as ast from '../ast';
10-
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
10+
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
11+
import type { KqlContext } from '../types';
1112

1213
export function buildNodeParams(children: KueryNode[]) {
1314
return {
@@ -19,7 +20,7 @@ export function toElasticsearchQuery(
1920
node: KueryNode,
2021
indexPattern?: DataViewBase,
2122
config: KueryQueryOptions = {},
22-
context: Record<string, any> = {}
23+
context: KqlContext = {}
2324
) {
2425
const { filtersInMustClause } = config;
2526
const children = node.arguments || [];

packages/kbn-es-query/src/kuery/functions/exists.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import { nodeTypes } from '../node_types';
1010
import { fields } from '../../filters/stubs';
1111
import { DataViewBase } from '../..';
12+
import { KQL_NODE_TYPE_LITERAL } from '../node_types/literal';
1213

1314
jest.mock('../grammar');
1415

@@ -39,7 +40,7 @@ describe('kuery functions', () => {
3940
arguments: [arg],
4041
} = exists.buildNodeParams('response');
4142

42-
expect(arg).toHaveProperty('type', 'literal');
43+
expect(arg).toHaveProperty('type', KQL_NODE_TYPE_LITERAL);
4344
expect(arg).toHaveProperty('value', 'response');
4445
});
4546
});

packages/kbn-es-query/src/kuery/functions/exists.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
*/
88

99
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
10-
import { DataViewFieldBase, DataViewBase, KueryNode, KueryQueryOptions } from '../..';
10+
import type { DataViewFieldBase, DataViewBase, KueryNode, KueryQueryOptions } from '../..';
1111
import * as literal from '../node_types/literal';
12+
import type { KqlContext } from '../types';
1213

1314
export function buildNodeParams(fieldName: string) {
1415
return {
@@ -20,7 +21,7 @@ export function toElasticsearchQuery(
2021
node: KueryNode,
2122
indexPattern?: DataViewBase,
2223
config: KueryQueryOptions = {},
23-
context: Record<string, any> = {}
24+
context: KqlContext = {}
2425
): estypes.QueryDslQueryContainer {
2526
const {
2627
arguments: [fieldNameArg],

packages/kbn-es-query/src/kuery/functions/is.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { fields } from '../../filters/stubs';
1212
import * as is from './is';
1313
import { DataViewBase } from '../..';
1414
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
15+
import { KQL_NODE_TYPE_WILDCARD } from '../node_types/wildcard';
16+
import { KQL_NODE_TYPE_LITERAL } from '../node_types/literal';
1517

1618
jest.mock('../grammar');
1719

@@ -32,9 +34,9 @@ describe('kuery functions', () => {
3234
arguments: [fieldName, value],
3335
} = is.buildNodeParams('response', 200);
3436

35-
expect(fieldName).toHaveProperty('type', 'literal');
37+
expect(fieldName).toHaveProperty('type', KQL_NODE_TYPE_LITERAL);
3638
expect(fieldName).toHaveProperty('value', 'response');
37-
expect(value).toHaveProperty('type', 'literal');
39+
expect(value).toHaveProperty('type', KQL_NODE_TYPE_LITERAL);
3840
expect(value).toHaveProperty('value', 200);
3941
});
4042

@@ -43,8 +45,8 @@ describe('kuery functions', () => {
4345
arguments: [fieldName, value],
4446
} = is.buildNodeParams('machine*', 'win*');
4547

46-
expect(fieldName).toHaveProperty('type', 'wildcard');
47-
expect(value).toHaveProperty('type', 'wildcard');
48+
expect(fieldName).toHaveProperty('type', KQL_NODE_TYPE_WILDCARD);
49+
expect(value).toHaveProperty('type', KQL_NODE_TYPE_WILDCARD);
4850
});
4951

5052
test('should default to a non-phrase query', () => {

packages/kbn-es-query/src/kuery/functions/is.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { getPhraseScript } from '../../filters';
1212
import { getFields } from './utils/get_fields';
1313
import { getTimeZoneFromSettings, getDataViewFieldSubtypeNested } from '../../utils';
1414
import { getFullFieldNameNode } from './utils/get_full_field_name_node';
15-
import { DataViewBase, KueryNode, DataViewFieldBase, KueryQueryOptions } from '../..';
15+
import type { DataViewBase, KueryNode, DataViewFieldBase, KueryQueryOptions } from '../..';
16+
import type { KqlContext } from '../types';
1617

1718
import * as ast from '../ast';
18-
1919
import * as literal from '../node_types/literal';
2020
import * as wildcard from '../node_types/wildcard';
2121

@@ -42,15 +42,14 @@ export function toElasticsearchQuery(
4242
node: KueryNode,
4343
indexPattern?: DataViewBase,
4444
config: KueryQueryOptions = {},
45-
context: Record<string, any> = {}
45+
context: KqlContext = {}
4646
): estypes.QueryDslQueryContainer {
4747
const {
4848
arguments: [fieldNameArg, valueArg, isPhraseArg],
4949
} = node;
5050

51-
const isExistsQuery = valueArg.type === 'wildcard' && valueArg.value === wildcard.wildcardSymbol;
52-
const isAllFieldsQuery =
53-
fieldNameArg.type === 'wildcard' && fieldNameArg.value === wildcard.wildcardSymbol;
51+
const isExistsQuery = wildcard.isNode(valueArg) && wildcard.isLoneWildcard(valueArg);
52+
const isAllFieldsQuery = wildcard.isNode(fieldNameArg) && wildcard.isLoneWildcard(fieldNameArg);
5453
const isMatchAllQuery = isExistsQuery && isAllFieldsQuery;
5554

5655
if (isMatchAllQuery) {
@@ -65,7 +64,7 @@ export function toElasticsearchQuery(
6564
const value = !isUndefined(valueArg) ? ast.toElasticsearchQuery(valueArg) : valueArg;
6665
const type = isPhraseArg.value ? 'phrase' : 'best_fields';
6766
if (fullFieldNameArg.value === null) {
68-
if (valueArg.type === 'wildcard') {
67+
if (wildcard.isNode(valueArg)) {
6968
return {
7069
query_string: {
7170
query: wildcard.toQueryStringQuery(valueArg),
@@ -106,7 +105,7 @@ export function toElasticsearchQuery(
106105
// Wildcards can easily include nested and non-nested fields. There isn't a good way to let
107106
// users handle this themselves so we automatically add nested queries in this scenario.
108107
const subTypeNested = getDataViewFieldSubtypeNested(field);
109-
if (!(fullFieldNameArg.type === 'wildcard') || !subTypeNested?.nested || context?.nested) {
108+
if (!wildcard.isNode(fullFieldNameArg) || !subTypeNested?.nested || context?.nested) {
110109
return query;
111110
} else {
112111
return {
@@ -143,7 +142,7 @@ export function toElasticsearchQuery(
143142
},
144143
}),
145144
];
146-
} else if (valueArg.type === 'wildcard') {
145+
} else if (wildcard.isNode(valueArg)) {
147146
return [
148147
...accumulator,
149148
wrapWithNestedQuery({

packages/kbn-es-query/src/kuery/functions/nested.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
1010
import * as ast from '../ast';
1111
import * as literal from '../node_types/literal';
12-
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
12+
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
13+
import type { KqlContext } from '../types';
1314

1415
export function buildNodeParams(path: any, child: any) {
1516
const pathNode =
@@ -23,7 +24,7 @@ export function toElasticsearchQuery(
2324
node: KueryNode,
2425
indexPattern?: DataViewBase,
2526
config: KueryQueryOptions = {},
26-
context: Record<string, any> = {}
27+
context: KqlContext = {}
2728
): estypes.QueryDslQueryContainer {
2829
const [path, child] = node.arguments;
2930
const stringPath = ast.toElasticsearchQuery(path) as unknown as string;

packages/kbn-es-query/src/kuery/functions/not.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
1010
import * as ast from '../ast';
11-
import { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
11+
import type { DataViewBase, KueryNode, KueryQueryOptions } from '../..';
12+
import type { KqlContext } from '../types';
1213

1314
export function buildNodeParams(child: KueryNode) {
1415
return {
@@ -20,7 +21,7 @@ export function toElasticsearchQuery(
2021
node: KueryNode,
2122
indexPattern?: DataViewBase,
2223
config: KueryQueryOptions = {},
23-
context: Record<string, any> = {}
24+
context: KqlContext = {}
2425
): estypes.QueryDslQueryContainer {
2526
const [argument] = node.arguments;
2627

0 commit comments

Comments
 (0)