Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into split-types-from-code-on-kbn-test-subj-selector
Browse files Browse the repository at this point in the history
kibanamachine authored Dec 22, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents a363bef + e5761ca commit 9747c5b
Showing 158 changed files with 3,121 additions and 7,010 deletions.
Original file line number Diff line number Diff line change
@@ -213,6 +213,7 @@ readonly links: {
};
readonly securitySolution: {
readonly trustedApps: string;
readonly eventFilters: string;
};
readonly query: {
readonly eql: string;

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -601,6 +601,7 @@
"@types/kbn__server-http-tools": "link:bazel-bin/packages/kbn-server-http-tools/npm_module_types",
"@types/kbn__server-route-repository": "link:bazel-bin/packages/kbn-server-route-repository/npm_module_types",
"@types/kbn__std": "link:bazel-bin/packages/kbn-std/npm_module_types",
"@types/kbn__telemetry-tools": "link:bazel-bin/packages/kbn-telemetry-tools/npm_module_types",
"@types/license-checker": "15.0.0",
"@types/listr": "^0.14.0",
"@types/loader-utils": "^1.1.3",
1 change: 1 addition & 0 deletions packages/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ filegroup(
"//packages/kbn-server-http-tools:build_types",
"//packages/kbn-server-route-repository:build_types",
"//packages/kbn-std:build_types",
"//packages/kbn-telemetry-tools:build_types",
],
)

4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/build_es_query.ts
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ import { buildQueryFromKuery } from './from_kuery';
import { buildQueryFromFilters } from './from_filters';
import { buildQueryFromLucene } from './from_lucene';
import { Filter, Query } from '../filters';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';
import { KueryQueryOptions } from '../kuery';

/**
@@ -42,7 +42,7 @@ function removeMatchAll<T>(filters: T[]) {
* @public
*/
export function buildEsQuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queries: Query | Query[],
filters: Filter | Filter[],
config: EsQueryConfig = {
14 changes: 7 additions & 7 deletions packages/kbn-es-query/src/es_query/filter_matches_index.test.ts
Original file line number Diff line number Diff line change
@@ -8,12 +8,12 @@

import { Filter } from '../filters';
import { filterMatchesIndex } from './filter_matches_index';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';

describe('filterMatchesIndex', () => {
it('should return true if the filter has no meta', () => {
const filter = {} as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
@@ -26,35 +26,35 @@ describe('filterMatchesIndex', () => {

it('should return true if the filter key matches a field name', () => {
const filter = { meta: { index: 'foo', key: 'bar' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});

it('should return true if custom filter for the same index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bara' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bara' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});

it('should return false if custom filter for a different index is passed', () => {
const filter = { meta: { index: 'foo', key: 'bar', type: 'custom' } } as Filter;
const indexPattern = { id: 'food', fields: [{ name: 'bara' }] } as IndexPatternBase;
const indexPattern = { id: 'food', fields: [{ name: 'bara' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});

it('should return false if the filter key does not match a field name', () => {
const filter = { meta: { index: 'foo', key: 'baz' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(false);
});

it('should return true if the filter has meta without a key', () => {
const filter = { meta: { index: 'foo' } } as Filter;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as IndexPatternBase;
const indexPattern = { id: 'foo', fields: [{ name: 'bar' }] } as DataViewBase;

expect(filterMatchesIndex(filter, indexPattern)).toBe(true);
});
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/filter_matches_index.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
*/

import { Filter } from '../filters';
import { IndexPatternBase } from '..';
import { DataViewBase } from '..';

/*
* TODO: We should base this on something better than `filter.meta.key`. We should probably modify
@@ -16,7 +16,7 @@ import { IndexPatternBase } from '..';
*
* @internal
*/
export function filterMatchesIndex(filter: Filter, indexPattern?: IndexPatternBase | null) {
export function filterMatchesIndex(filter: Filter, indexPattern?: DataViewBase | null) {
if (!filter.meta?.key || !indexPattern) {
return true;
}
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/from_filters.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { migrateFilter } from './migrate_filter';
import { filterMatchesIndex } from './filter_matches_index';
import { Filter, cleanFilter, isFilterDisabled } from '../filters';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';
import { handleNestedFilter } from './handle_nested_filter';

/**
@@ -48,7 +48,7 @@ const translateToQuery = (filter: Partial<Filter>): estypes.QueryDslQueryContain
*/
export const buildQueryFromFilters = (
filters: Filter[] = [],
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
ignoreFilterIfFieldNotInIndex: boolean = false
): BoolQuery => {
filters = filters.filter((filter) => filter && !isFilterDisabled(filter));
6 changes: 3 additions & 3 deletions packages/kbn-es-query/src/es_query/from_kuery.ts
Original file line number Diff line number Diff line change
@@ -9,11 +9,11 @@
import { SerializableRecord } from '@kbn/utility-types';
import { Query } from '../filters';
import { fromKueryExpression, toElasticsearchQuery, nodeTypes, KueryNode } from '../kuery';
import { BoolQuery, IndexPatternBase } from './types';
import { BoolQuery, DataViewBase } from './types';

/** @internal */
export function buildQueryFromKuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queries: Query[] = [],
allowLeadingWildcards: boolean = false,
dateFormatTZ?: string,
@@ -27,7 +27,7 @@ export function buildQueryFromKuery(
}

function buildQuery(
indexPattern: IndexPatternBase | undefined,
indexPattern: DataViewBase | undefined,
queryASTs: KueryNode[],
config: SerializableRecord = {}
): BoolQuery {
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/handle_nested_filter.ts
Original file line number Diff line number Diff line change
@@ -7,11 +7,11 @@
*/

import { getFilterField, cleanFilter, Filter } from '../filters';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';
import { getDataViewFieldSubtypeNested } from '../utils';

/** @internal */
export const handleNestedFilter = (filter: Filter, indexPattern?: IndexPatternBase) => {
export const handleNestedFilter = (filter: Filter, indexPattern?: DataViewBase) => {
if (!indexPattern) return filter;

const fieldName = getFilterField(filter);
2 changes: 0 additions & 2 deletions packages/kbn-es-query/src/es_query/index.ts
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@ export { buildQueryFromFilters } from './from_filters';
export { luceneStringToDsl } from './lucene_string_to_dsl';
export { decorateQuery } from './decorate_query';
export type {
IndexPatternBase,
IndexPatternFieldBase,
IFieldSubType,
BoolQuery,
DataViewBase,
4 changes: 2 additions & 2 deletions packages/kbn-es-query/src/es_query/migrate_filter.ts
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import { get, omit } from 'lodash';
import { getConvertedValueForField } from '../filters';
import { Filter } from '../filters';
import { IndexPatternBase } from './types';
import { DataViewBase } from './types';

/** @internal */
export interface DeprecatedMatchPhraseFilter extends Filter {
@@ -32,7 +32,7 @@ function isDeprecatedMatchPhraseFilter(filter: Filter): filter is DeprecatedMatc
}

/** @internal */
export function migrateFilter(filter: Filter, indexPattern?: IndexPatternBase) {
export function migrateFilter(filter: Filter, indexPattern?: DataViewBase) {
if (isDeprecatedMatchPhraseFilter(filter)) {
// @ts-ignore
const match = filter.match || filter.query.match;
10 changes: 0 additions & 10 deletions packages/kbn-es-query/src/es_query/types.ts
Original file line number Diff line number Diff line change
@@ -53,11 +53,6 @@ export interface DataViewFieldBase {
scripted?: boolean;
}

/**
* @deprecated Use DataViewField instead. All index pattern interfaces were renamed.
*/
export type IndexPatternFieldBase = DataViewFieldBase;

/**
* A base interface for an index pattern
* @public
@@ -68,11 +63,6 @@ export interface DataViewBase {
title: string;
}

/**
* @deprecated Use DataViewBase instead. All index pattern interfaces were renamed.
*/
export type IndexPatternBase = DataViewBase;

export interface BoolQuery {
must: estypes.QueryDslQueryContainer[];
must_not: estypes.QueryDslQueryContainer[];
10 changes: 5 additions & 5 deletions packages/kbn-es-query/src/filters/build_filters/build_filters.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import { buildPhrasesFilter } from './phrases_filter';
import { buildRangeFilter, RangeFilterParams } from './range_filter';
import { buildExistsFilter } from './exists_filter';

import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import { FilterStateStore } from './types';

/**
@@ -32,8 +32,8 @@ import { FilterStateStore } from './types';
* @public
*/
export function buildFilter(
indexPattern: IndexPatternBase,
field: IndexPatternFieldBase,
indexPattern: DataViewBase,
field: DataViewFieldBase,
type: FILTERS,
negate: boolean,
disabled: boolean,
@@ -52,8 +52,8 @@ export function buildFilter(
}

function buildBaseFilter(
indexPattern: IndexPatternBase,
field: IndexPatternFieldBase,
indexPattern: DataViewBase,
field: DataViewFieldBase,
type: FILTERS,
params: Serializable
): Filter {
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
*/

import { has } from 'lodash';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import type { Filter, FilterMeta } from './types';

/** @public */
@@ -44,7 +44,7 @@ export const getExistsFilterField = (filter: ExistsFilter) => {
*
* @public
*/
export const buildExistsFilter = (field: IndexPatternFieldBase, indexPattern: IndexPatternBase) => {
export const buildExistsFilter = (field: DataViewFieldBase, indexPattern: DataViewBase) => {
return {
meta: {
index: indexPattern.id,
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { IndexPatternFieldBase } from '../../es_query';
import { DataViewFieldBase } from '../../es_query';

/**
* @internal
@@ -18,7 +18,7 @@ import { IndexPatternFieldBase } from '../../es_query';
* https://github.com/elastic/elasticsearch/pull/22201
**/
export const getConvertedValueForField = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
value: string | boolean | number
) => {
if (typeof value !== 'boolean' && field.type === 'boolean') {
10 changes: 5 additions & 5 deletions packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { get, has, isPlainObject } from 'lodash';
import type { Filter, FilterMeta } from './types';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';
import { getConvertedValueForField } from './get_converted_value_for_field';

export type PhraseFilterValue = string | number | boolean;
@@ -93,9 +93,9 @@ export const getPhraseFilterValue = (
* @public
*/
export const buildPhraseFilter = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
value: PhraseFilterValue,
indexPattern: IndexPatternBase
indexPattern: DataViewBase
): PhraseFilter | ScriptedPhraseFilter => {
const convertedValue = getConvertedValueForField(field, value);

@@ -117,7 +117,7 @@ export const buildPhraseFilter = (
};

/** @internal */
export const getPhraseScript = (field: IndexPatternFieldBase, value: PhraseFilterValue) => {
export const getPhraseScript = (field: DataViewFieldBase, value: PhraseFilterValue) => {
const convertedValue = getConvertedValueForField(field, value);
const script = buildInlineScriptForPhraseFilter(field);

@@ -141,7 +141,7 @@ export const getPhraseScript = (field: IndexPatternFieldBase, value: PhraseFilte
* @param {object} scriptedField A Field object representing a scripted field
* @returns {string} The inline script string
*/
export const buildInlineScriptForPhraseFilter = (scriptedField: IndexPatternFieldBase) => {
export const buildInlineScriptForPhraseFilter = (scriptedField: DataViewFieldBase) => {
// We must wrap painless scripts in a lambda in case they're more than a simple expression
if (scriptedField.lang === 'painless') {
return (
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { Filter, FilterMeta, FILTERS } from './types';
import { getPhraseScript, PhraseFilterValue } from './phrase_filter';
import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query';
import type { DataViewFieldBase, DataViewBase } from '../../es_query';

export type PhrasesFilterMeta = FilterMeta & {
params: PhraseFilterValue[]; // The unformatted values
@@ -48,9 +48,9 @@ export const getPhrasesFilterField = (filter: PhrasesFilter) => {
* @public
*/
export const buildPhrasesFilter = (
field: IndexPatternFieldBase,
field: DataViewFieldBase,
params: PhraseFilterValue[],
indexPattern: IndexPatternBase
indexPattern: DataViewBase
) => {
const index = indexPattern.id;
const type = FILTERS.PHRASES;
Loading

0 comments on commit 9747c5b

Please sign in to comment.