diff --git a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md index 8ecdd5640dbe2..b5d5c5cfee5ad 100644 --- a/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md +++ b/docs/development/plugins/data/public/kibana-plugin-plugins-data-public.esfilters.md @@ -20,18 +20,18 @@ esFilters: { FILTERS: typeof import("@kbn/es-query").FILTERS; FilterStateStore: typeof FilterStateStore; buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("@kbn/es-query").Filter; - buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: any[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; + buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: string[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter; - buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: any, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; + buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: string | number | boolean, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; buildRangeFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: import("@kbn/es-query").RangeFilterParams, indexPattern: import("@kbn/es-query").IndexPatternBase, formattedValue?: string | undefined) => import("@kbn/es-query").RangeFilter; - isPhraseFilter: (filter: any) => filter is import("@kbn/es-query").PhraseFilter; - isExistsFilter: (filter: any) => filter is import("@kbn/es-query").ExistsFilter; - isPhrasesFilter: (filter: any) => filter is import("@kbn/es-query").PhrasesFilter; - isRangeFilter: (filter: any) => filter is import("@kbn/es-query").RangeFilter; - isMatchAllFilter: (filter: any) => filter is import("@kbn/es-query").MatchAllFilter; - isMissingFilter: (filter: any) => filter is import("@kbn/es-query").MissingFilter; - isQueryStringFilter: (filter: any) => filter is import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; + isPhraseFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").PhraseFilter; + isExistsFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").ExistsFilter; + isPhrasesFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").PhrasesFilter; + isRangeFilter: (filter?: import("@kbn/es-query").ExistsFilter | import("@kbn/es-query").GeoPolygonFilter | import("@kbn/es-query").PhrasesFilter | import("@kbn/es-query").PhraseFilter | import("@kbn/es-query").MatchAllFilter | import("@kbn/es-query").MissingFilter | import("@kbn/es-query").RangeFilter | import("@kbn/es-query").GeoBoundingBoxFilter | undefined) => filter is import("@kbn/es-query").RangeFilter; + isMatchAllFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").MatchAllFilter; + isMissingFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").MissingFilter; + isQueryStringFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; isFilterPinned: (filter: import("@kbn/es-query").Filter) => boolean | undefined; toggleFilterNegated: (filter: import("@kbn/es-query").Filter) => { meta: { @@ -46,7 +46,9 @@ esFilters: { params?: any; value?: string | undefined; }; - $state?: import("@kbn/es-query").FilterState | undefined; + $state?: { + store: FilterStateStore; + } | undefined; query?: any; }; disableFilter: (filter: import("@kbn/es-query").Filter) => import("@kbn/es-query").Filter; diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.castestokbnfieldtypename.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.castestokbnfieldtypename.md index b930893f3a61e..a3f92491e8983 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.castestokbnfieldtypename.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.castestokbnfieldtypename.md @@ -6,11 +6,7 @@ > Warning: This API is now obsolete. > -<<<<<<< HEAD -> import from "@kbn/field-types" instead -======= > Import from the "@kbn/field-types" package directly instead. 8.1 ->>>>>>> af3a976e177... [FieldFormats] Break from `data` plugin (#107173) > Signature: diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.esfilters.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.esfilters.md index b807fe7d66369..b37d0555194fc 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.esfilters.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.esfilters.md @@ -13,8 +13,8 @@ esFilters: { buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("@kbn/es-query").Filter; buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter; buildFilter: typeof import("@kbn/es-query").buildFilter; - buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: any, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; - buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: any[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; + buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: string | number | boolean, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; + buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: string[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; buildRangeFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: import("@kbn/es-query").RangeFilterParams, indexPattern: import("@kbn/es-query").IndexPatternBase, formattedValue?: string | undefined) => import("@kbn/es-query").RangeFilter; isFilterDisabled: (filter: import("@kbn/es-query").Filter) => boolean; } diff --git a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md index a6b04999755a4..0363aa1ce6442 100644 --- a/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md +++ b/docs/development/plugins/data/server/kibana-plugin-plugins-data-server.md @@ -23,8 +23,6 @@ | Enumeration | Description | | --- | --- | | [BUCKET\_TYPES](./kibana-plugin-plugins-data-server.bucket_types.md) | | -| [ES\_FIELD\_TYPES](./kibana-plugin-plugins-data-server.es_field_types.md) | \* | -| [KBN\_FIELD\_TYPES](./kibana-plugin-plugins-data-server.kbn_field_types.md) | \* | | [METRIC\_TYPES](./kibana-plugin-plugins-data-server.metric_types.md) | | ## Functions @@ -74,7 +72,7 @@ | [AggGroupLabels](./kibana-plugin-plugins-data-server.agggrouplabels.md) | | | [AggGroupNames](./kibana-plugin-plugins-data-server.agggroupnames.md) | | | [buildQueryFromFilters](./kibana-plugin-plugins-data-server.buildqueryfromfilters.md) | | -| [castEsToKbnFieldTypeName](./kibana-plugin-plugins-data-server.castestokbnfieldtypename.md) | Get the KbnFieldType name for an esType string | +| [castEsToKbnFieldTypeName](./kibana-plugin-plugins-data-server.castestokbnfieldtypename.md) | | | [config](./kibana-plugin-plugins-data-server.config.md) | | | [ES\_SEARCH\_STRATEGY](./kibana-plugin-plugins-data-server.es_search_strategy.md) | | | [esFilters](./kibana-plugin-plugins-data-server.esfilters.md) | | diff --git a/packages/kbn-es-query/src/es_query/build_es_query.ts b/packages/kbn-es-query/src/es_query/build_es_query.ts index e8a494ec1b8e4..955af1e4c185f 100644 --- a/packages/kbn-es-query/src/es_query/build_es_query.ts +++ b/packages/kbn-es-query/src/es_query/build_es_query.ts @@ -13,6 +13,10 @@ import { buildQueryFromLucene } from './from_lucene'; import { Filter, Query } from '../filters'; import { IndexPatternBase } from './types'; +/** + * Configurations to be used while constructing an ES query. + * @public + */ export interface EsQueryConfig { allowLeadingWildcards: boolean; queryStringOptions: Record; @@ -33,6 +37,8 @@ function removeMatchAll(filters: T[]) { * @param config - an objects with query:allowLeadingWildcards and query:queryString:options UI * settings in form of { allowLeadingWildcards, queryStringOptions } * config contains dateformat:tz + * + * @public */ export function buildEsQuery( indexPattern: IndexPatternBase | undefined, @@ -47,7 +53,7 @@ export function buildEsQuery( queries = Array.isArray(queries) ? queries : [queries]; filters = Array.isArray(filters) ? filters : [filters]; - const validQueries = queries.filter((query) => has(query, 'query')); + const validQueries = queries.filter((query: any) => has(query, 'query')); const queriesByLanguage = groupBy(validQueries, 'language'); const kueryQuery = buildQueryFromKuery( indexPattern, diff --git a/packages/kbn-es-query/src/es_query/decorate_query.ts b/packages/kbn-es-query/src/es_query/decorate_query.ts index 594e046a979de..b6623b9b1946c 100644 --- a/packages/kbn-es-query/src/es_query/decorate_query.ts +++ b/packages/kbn-es-query/src/es_query/decorate_query.ts @@ -16,6 +16,8 @@ import { DslQuery, isEsQueryString } from './es_query_dsl'; * @param queryStringOptions query:queryString:options from UI settings * @param dateFormatTZ dateFormat:tz from UI settings * @returns {object} + * + * @public */ export function decorateQuery( diff --git a/packages/kbn-es-query/src/es_query/es_query_dsl.ts b/packages/kbn-es-query/src/es_query/es_query_dsl.ts index 30f7693ee2a94..6cff8b0ff47c7 100644 --- a/packages/kbn-es-query/src/es_query/es_query_dsl.ts +++ b/packages/kbn-es-query/src/es_query/es_query_dsl.ts @@ -43,6 +43,9 @@ export interface DslTermQuery { term: Record; } +/** + * @public + */ export type DslQuery = | DslRangeQuery | DslMatchQuery @@ -50,5 +53,6 @@ export type DslQuery = | DslMatchAllQuery | DslTermQuery; +/** @internal */ export const isEsQueryString = (query: any): query is DslQueryStringQuery => has(query, 'query_string.query'); diff --git a/packages/kbn-es-query/src/es_query/filter_matches_index.ts b/packages/kbn-es-query/src/es_query/filter_matches_index.ts index 7df719533486a..541298ee0e19b 100644 --- a/packages/kbn-es-query/src/es_query/filter_matches_index.ts +++ b/packages/kbn-es-query/src/es_query/filter_matches_index.ts @@ -13,6 +13,8 @@ import { IndexPatternBase } from '..'; * TODO: We should base this on something better than `filter.meta.key`. We should probably modify * this to check if `filter.meta.index` matches `indexPattern.id` instead, but that's a breaking * change. + * + * @internal */ export function filterMatchesIndex(filter: Filter, indexPattern?: IndexPatternBase | null) { if (!filter.meta?.key || !indexPattern) { diff --git a/packages/kbn-es-query/src/es_query/from_filters.ts b/packages/kbn-es-query/src/es_query/from_filters.ts index 7b3c58d45a569..94def4008a2bc 100644 --- a/packages/kbn-es-query/src/es_query/from_filters.ts +++ b/packages/kbn-es-query/src/es_query/from_filters.ts @@ -43,6 +43,14 @@ const translateToQuery = (filter: Filter) => { return filter; }; +/** + * @param filters + * @param indexPattern + * @param ignoreFilterIfFieldNotInIndex by default filters that use fields that can't be found in the specified index pattern are not applied. Set this to true if you want to apply them any way. + * @returns An EQL query + * + * @public + */ export const buildQueryFromFilters = ( filters: Filter[] = [], indexPattern: IndexPatternBase | undefined, diff --git a/packages/kbn-es-query/src/es_query/from_kuery.ts b/packages/kbn-es-query/src/es_query/from_kuery.ts index efe8b26a81412..87382585181f8 100644 --- a/packages/kbn-es-query/src/es_query/from_kuery.ts +++ b/packages/kbn-es-query/src/es_query/from_kuery.ts @@ -10,6 +10,7 @@ import { Query } from '../filters'; import { fromKueryExpression, toElasticsearchQuery, nodeTypes, KueryNode } from '../kuery'; import { IndexPatternBase } from './types'; +/** @internal */ export function buildQueryFromKuery( indexPattern: IndexPatternBase | undefined, queries: Query[] = [], diff --git a/packages/kbn-es-query/src/es_query/from_lucene.ts b/packages/kbn-es-query/src/es_query/from_lucene.ts index cba789513c983..ef4becd1d1584 100644 --- a/packages/kbn-es-query/src/es_query/from_lucene.ts +++ b/packages/kbn-es-query/src/es_query/from_lucene.ts @@ -10,6 +10,7 @@ import { Query } from '..'; import { decorateQuery } from './decorate_query'; import { luceneStringToDsl } from './lucene_string_to_dsl'; +/** @internal */ export function buildQueryFromLucene( queries: Query[], queryStringOptions: Record, diff --git a/packages/kbn-es-query/src/es_query/handle_nested_filter.ts b/packages/kbn-es-query/src/es_query/handle_nested_filter.ts index 60e92769503fb..74c758c1c54bf 100644 --- a/packages/kbn-es-query/src/es_query/handle_nested_filter.ts +++ b/packages/kbn-es-query/src/es_query/handle_nested_filter.ts @@ -9,6 +9,7 @@ import { getFilterField, cleanFilter, Filter } from '../filters'; import { IndexPatternBase } from './types'; +/** @internal */ export const handleNestedFilter = (filter: Filter, indexPattern?: IndexPatternBase) => { if (!indexPattern) return filter; diff --git a/packages/kbn-es-query/src/es_query/lucene_string_to_dsl.ts b/packages/kbn-es-query/src/es_query/lucene_string_to_dsl.ts index 97160bd645797..2e4eb5ab7f7c4 100644 --- a/packages/kbn-es-query/src/es_query/lucene_string_to_dsl.ts +++ b/packages/kbn-es-query/src/es_query/lucene_string_to_dsl.ts @@ -9,6 +9,13 @@ import { isString } from 'lodash'; import { DslQuery } from './es_query_dsl'; +/** + * + * @param query + * @returns + * + * @public + */ export function luceneStringToDsl(query: string | any): DslQuery { if (isString(query)) { if (query.trim() === '') { diff --git a/packages/kbn-es-query/src/es_query/migrate_filter.ts b/packages/kbn-es-query/src/es_query/migrate_filter.ts index 9bd78b092fc18..5edab3e042f5c 100644 --- a/packages/kbn-es-query/src/es_query/migrate_filter.ts +++ b/packages/kbn-es-query/src/es_query/migrate_filter.ts @@ -11,6 +11,7 @@ import { getConvertedValueForField } from '../filters'; import { Filter } from '../filters'; import { IndexPatternBase } from './types'; +/** @internal */ export interface DeprecatedMatchPhraseFilter extends Filter { query: { match: { @@ -28,6 +29,7 @@ function isDeprecatedMatchPhraseFilter(filter: any): filter is DeprecatedMatchPh return Boolean(fieldName && get(filter, ['query', 'match', fieldName, 'type']) === 'phrase'); } +/** @internal */ export function migrateFilter(filter: Filter, indexPattern?: IndexPatternBase) { if (isDeprecatedMatchPhraseFilter(filter)) { const fieldName = Object.keys(filter.query.match)[0]; diff --git a/packages/kbn-es-query/src/es_query/types.ts b/packages/kbn-es-query/src/es_query/types.ts index ca6a542779053..d68d9e4a4da22 100644 --- a/packages/kbn-es-query/src/es_query/types.ts +++ b/packages/kbn-es-query/src/es_query/types.ts @@ -8,10 +8,19 @@ import type { estypes } from '@elastic/elasticsearch'; +/** + * A field's sub type + * @public + */ export interface IFieldSubType { multi?: { parent: string }; nested?: { path: string }; } + +/** + * A base interface for an index pattern field + * @public + */ export interface IndexPatternFieldBase { name: string; /** @@ -31,6 +40,10 @@ export interface IndexPatternFieldBase { scripted?: boolean; } +/** + * A base interface for an index pattern + * @public + */ export interface IndexPatternBase { fields: IndexPatternFieldBase[]; id?: string; diff --git a/packages/kbn-es-query/src/filters/build_filters/build_empty_filter.ts b/packages/kbn-es-query/src/filters/build_filters/build_empty_filter.ts index a7945da5829a9..09b58bb15147f 100644 --- a/packages/kbn-es-query/src/filters/build_filters/build_empty_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/build_empty_filter.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { Filter, FilterMeta, FilterState, FilterStateStore } from './types'; +import { Filter, FilterMeta, FilterStateStore } from './types'; export const buildEmptyFilter = (isPinned: boolean, index?: string): Filter => { const meta: FilterMeta = { @@ -15,7 +15,7 @@ export const buildEmptyFilter = (isPinned: boolean, index?: string): Filter => { alias: null, index, }; - const $state: FilterState = { + const $state: Filter['$state'] = { store: isPinned ? FilterStateStore.GLOBAL_STATE : FilterStateStore.APP_STATE, }; diff --git a/packages/kbn-es-query/src/filters/build_filters/build_filters.ts b/packages/kbn-es-query/src/filters/build_filters/build_filters.ts index 9beee96fd2ee2..eba7a6a26c545 100644 --- a/packages/kbn-es-query/src/filters/build_filters/build_filters.ts +++ b/packages/kbn-es-query/src/filters/build_filters/build_filters.ts @@ -14,8 +14,22 @@ import { buildRangeFilter } from './range_filter'; import { buildExistsFilter } from './exists_filter'; import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query'; -import { FilterMeta, FilterStateStore } from './types'; +import { FilterStateStore } from './types'; +/** + * + * @param indexPattern + * @param field + * @param type + * @param negate whether the filter is negated (NOT filter) + * @param disabled whether the filter is disabled andwon't be applied to searches + * @param params + * @param alias a display name for the filter + * @param store whether the filter applies to the current application or should be applied to global context + * @returns + * + * @public + */ export function buildFilter( indexPattern: IndexPatternBase, field: IndexPatternFieldBase, @@ -36,26 +50,6 @@ export function buildFilter( return filter; } -export function buildCustomFilter( - indexPatternString: string, - queryDsl: any, - disabled: boolean, - negate: boolean, - alias: string | null, - store: FilterStateStore -): Filter { - const meta: FilterMeta = { - index: indexPatternString, - type: FILTERS.CUSTOM, - disabled, - negate, - alias, - }; - const filter: Filter = { ...queryDsl, meta }; - filter.$state = { store }; - return filter; -} - function buildBaseFilter( indexPattern: IndexPatternBase, field: IndexPatternFieldBase, diff --git a/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts b/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts index 0dc1fc86d25a1..60a128d58fee3 100644 --- a/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/custom_filter.ts @@ -6,8 +6,41 @@ * Side Public License, v 1. */ -import type { Filter } from './types'; +import { Filter, FilterMeta, FILTERS, FilterStateStore } from './types'; +/** @public */ export type CustomFilter = Filter & { query: any; }; + +/** + * + * @param indexPatternString + * @param queryDsl + * @param disabled + * @param negate + * @param alias + * @param store + * @returns + * + * @public + */ +export function buildCustomFilter( + indexPatternString: string, + queryDsl: any, + disabled: boolean, + negate: boolean, + alias: string | null, + store: FilterStateStore +): Filter { + const meta: FilterMeta = { + index: indexPatternString, + type: FILTERS.CUSTOM, + disabled, + negate, + alias, + }; + const filter: Filter = { ...queryDsl, meta }; + filter.$state = { store }; + return filter; +} diff --git a/packages/kbn-es-query/src/filters/build_filters/exists_filter.ts b/packages/kbn-es-query/src/filters/build_filters/exists_filter.ts index fdb4ab548fdc5..3a8935d057f4a 100644 --- a/packages/kbn-es-query/src/filters/build_filters/exists_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/exists_filter.ts @@ -6,26 +6,42 @@ * Side Public License, v 1. */ +import { has } from 'lodash'; import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query'; -import type { Filter, FilterMeta } from './types'; - -export type ExistsFilterMeta = FilterMeta; - -export interface FilterExistsProperty { - field: any; -} +import type { FieldFilter, Filter, FilterMeta } from './types'; +/** @public */ export type ExistsFilter = Filter & { - meta: ExistsFilterMeta; - exists?: FilterExistsProperty; + meta: FilterMeta; + exists?: { + field: string; + }; }; -export const isExistsFilter = (filter: any): filter is ExistsFilter => filter && filter.exists; +/** + * @param filter + * @returns `true` if a filter is an `ExistsFilter` + * + * @public + */ +export const isExistsFilter = (filter: FieldFilter): filter is ExistsFilter => + has(filter, 'exists'); +/** + * @internal + */ export const getExistsFilterField = (filter: ExistsFilter) => { return filter.exists && filter.exists.field; }; +/** + * Builds an `ExistsFilter` + * @param field field to validate the existence of + * @param indexPattern index pattern to look for the field in + * @returns An `ExistsFilter` + * + * @public + */ export const buildExistsFilter = (field: IndexPatternFieldBase, indexPattern: IndexPatternBase) => { return { meta: { diff --git a/packages/kbn-es-query/src/filters/build_filters/geo_bounding_box_filter.ts b/packages/kbn-es-query/src/filters/build_filters/geo_bounding_box_filter.ts index 323c7108ea3e5..9066b695c17fc 100644 --- a/packages/kbn-es-query/src/filters/build_filters/geo_bounding_box_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/geo_bounding_box_filter.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { Filter, FilterMeta, LatLon } from './types'; +import { has } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta, LatLon } from './types'; export type GeoBoundingBoxFilterMeta = FilterMeta & { params: { @@ -20,9 +21,18 @@ export type GeoBoundingBoxFilter = Filter & { geo_bounding_box: any; }; -export const isGeoBoundingBoxFilter = (filter: any): filter is GeoBoundingBoxFilter => - filter && filter.geo_bounding_box; +/** + * @param filter + * @returns `true` if a filter is an `GeoBoundingBoxFilter` + * + * @public + */ +export const isGeoBoundingBoxFilter = (filter: FieldFilter): filter is GeoBoundingBoxFilter => + has(filter, 'geo_bounding_box'); +/** + * @internal + */ export const getGeoBoundingBoxFilterField = (filter: GeoBoundingBoxFilter) => { return ( filter.geo_bounding_box && diff --git a/packages/kbn-es-query/src/filters/build_filters/geo_polygon_filter.ts b/packages/kbn-es-query/src/filters/build_filters/geo_polygon_filter.ts index d25f2a87dcd8c..edeccdcf28b26 100644 --- a/packages/kbn-es-query/src/filters/build_filters/geo_polygon_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/geo_polygon_filter.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { Filter, FilterMeta, LatLon } from './types'; +import { has } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta, LatLon } from './types'; export type GeoPolygonFilterMeta = FilterMeta & { params: { @@ -19,9 +20,18 @@ export type GeoPolygonFilter = Filter & { geo_polygon: any; }; -export const isGeoPolygonFilter = (filter: any): filter is GeoPolygonFilter => - filter && filter.geo_polygon; +/** + * @param filter + * @returns `true` if a filter is an `GeoPolygonFilter` + * + * @public + */ +export const isGeoPolygonFilter = (filter: FieldFilter): filter is GeoPolygonFilter => + has(filter, 'geo_polygon'); +/** + * @internal + */ export const getGeoPolygonFilterField = (filter: GeoPolygonFilter) => { return ( filter.geo_polygon && Object.keys(filter.geo_polygon).find((key) => key !== 'ignore_unmapped') diff --git a/packages/kbn-es-query/src/filters/build_filters/get_filter_field.ts b/packages/kbn-es-query/src/filters/build_filters/get_filter_field.ts index a949c0f7cd5b1..4ebed12e1237e 100644 --- a/packages/kbn-es-query/src/filters/build_filters/get_filter_field.ts +++ b/packages/kbn-es-query/src/filters/build_filters/get_filter_field.ts @@ -15,6 +15,7 @@ import { getPhraseFilterField, isPhraseFilter } from './phrase_filter'; import { getRangeFilterField, isRangeFilter } from './range_filter'; import type { Filter } from './types'; +/** @internal */ export const getFilterField = (filter: Filter) => { if (isExistsFilter(filter)) { return getExistsFilterField(filter); diff --git a/packages/kbn-es-query/src/filters/build_filters/get_filter_params.ts b/packages/kbn-es-query/src/filters/build_filters/get_filter_params.ts index 65a586db39789..46585acd9efc0 100644 --- a/packages/kbn-es-query/src/filters/build_filters/get_filter_params.ts +++ b/packages/kbn-es-query/src/filters/build_filters/get_filter_params.ts @@ -11,6 +11,9 @@ import type { PhraseFilter } from './phrase_filter'; import type { RangeFilter } from './range_filter'; import { Filter, FILTERS } from './types'; +/** + * @internal used only by the filter bar to create filter pills. + */ export function getFilterParams(filter: Filter) { switch (filter.meta.type) { case FILTERS.PHRASE: diff --git a/packages/kbn-es-query/src/filters/build_filters/match_all_filter.ts b/packages/kbn-es-query/src/filters/build_filters/match_all_filter.ts index 1a3fae4181379..b1b134313b746 100644 --- a/packages/kbn-es-query/src/filters/build_filters/match_all_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/match_all_filter.ts @@ -6,10 +6,11 @@ * Side Public License, v 1. */ -import type { Filter, FilterMeta } from './types'; +import { has } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta } from './types'; export interface MatchAllFilterMeta extends FilterMeta { - field: any; + field: string; formattedValue: string; } @@ -18,5 +19,11 @@ export type MatchAllFilter = Filter & { match_all: any; }; -export const isMatchAllFilter = (filter: any): filter is MatchAllFilter => - filter && filter.match_all; +/** + * @param filter + * @returns `true` if a filter is an `MatchAllFilter` + * + * @public + */ +export const isMatchAllFilter = (filter: FieldFilter): filter is MatchAllFilter => + has(filter, 'match_all'); diff --git a/packages/kbn-es-query/src/filters/build_filters/missing_filter.ts b/packages/kbn-es-query/src/filters/build_filters/missing_filter.ts index e52b7753c13a4..8f0364a565d79 100644 --- a/packages/kbn-es-query/src/filters/build_filters/missing_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/missing_filter.ts @@ -6,17 +6,30 @@ * Side Public License, v 1. */ -import type { Filter, FilterMeta } from './types'; +import { has } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta } from './types'; export type MissingFilterMeta = FilterMeta; export type MissingFilter = Filter & { meta: MissingFilterMeta; - missing: any; + missing: { + field: string; + }; }; -export const isMissingFilter = (filter: any): filter is MissingFilter => filter && filter.missing; +/** + * @param filter + * @returns `true` if a filter is an `MissingFilter` + * + * @public + */ +export const isMissingFilter = (filter: FieldFilter): filter is MissingFilter => + has(filter, 'missing'); +/** + * @internal + */ export const getMissingFilterField = (filter: MissingFilter) => { return filter.missing && filter.missing.field; }; diff --git a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts index bc60043d0887e..7b60548f912ba 100644 --- a/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/phrase_filter.ts @@ -6,33 +6,39 @@ * Side Public License, v 1. */ import type { estypes } from '@elastic/elasticsearch'; -import { get, isPlainObject } from 'lodash'; -import type { Filter, FilterMeta } from './types'; +import { has, isPlainObject } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta } from './types'; import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query'; import { getConvertedValueForField } from './get_converted_value_for_field'; +type PhraseFilterValue = string | number | boolean; + export type PhraseFilterMeta = FilterMeta & { params?: { - query: string; // The unformatted value + query: PhraseFilterValue; // The unformatted value }; - field?: any; - index?: any; + field?: string; + index?: string; }; export type PhraseFilter = Filter & { meta: PhraseFilterMeta; script?: { script: { - source?: any; + source?: string; lang?: estypes.ScriptLanguage; - params: any; + params: { [key: string]: PhraseFilterValue }; }; }; }; -type PhraseFilterValue = string | number | boolean; - -export const isPhraseFilter = (filter: any): filter is PhraseFilter => { +/** + * @param filter + * @returns `true` if a filter is a `PhraseFilter` + * + * @public + */ +export const isPhraseFilter = (filter: FieldFilter): filter is PhraseFilter => { const isMatchPhraseQuery = filter && filter.query && filter.query.match_phrase; const isDeprecatedMatchPhraseQuery = @@ -44,23 +50,42 @@ export const isPhraseFilter = (filter: any): filter is PhraseFilter => { return Boolean(isMatchPhraseQuery || isDeprecatedMatchPhraseQuery); }; -export const isScriptedPhraseFilter = (filter: any): filter is PhraseFilter => - Boolean(get(filter, 'script.script.params.value')); +/** + * @param filter + * @returns `true` if a filter is a scripted `PhrasesFilter` + * + * @public + */ +export const isScriptedPhraseFilter = (filter: FieldFilter): filter is PhraseFilter => + has(filter, 'script.script.params.value'); +/** @internal */ export const getPhraseFilterField = (filter: PhraseFilter) => { const queryConfig = filter.query.match_phrase || filter.query.match; return Object.keys(queryConfig)[0]; }; +/** + * @internal + */ export const getPhraseFilterValue = (filter: PhraseFilter): PhraseFilterValue => { const queryConfig = filter.query.match_phrase || filter.query.match; const queryValue = Object.values(queryConfig)[0] as any; return isPlainObject(queryValue) ? queryValue.query : queryValue; }; +/** + * Creates a filter where the given field matches a given value + * @param field + * @param params + * @param indexPattern + * @returns `PhraseFilter` + * + * @public + */ export const buildPhraseFilter = ( field: IndexPatternFieldBase, - value: any, + value: PhraseFilterValue, indexPattern: IndexPatternBase ): PhraseFilter => { const convertedValue = getConvertedValueForField(field, value); @@ -82,7 +107,8 @@ export const buildPhraseFilter = ( } }; -export const getPhraseScript = (field: IndexPatternFieldBase, value: string) => { +/** @internal */ +export const getPhraseScript = (field: IndexPatternFieldBase, value: PhraseFilterValue) => { const convertedValue = getConvertedValueForField(field, value); const script = buildInlineScriptForPhraseFilter(field); diff --git a/packages/kbn-es-query/src/filters/build_filters/phrases_filter.ts b/packages/kbn-es-query/src/filters/build_filters/phrases_filter.ts index 6f8c3815a5c63..526d3802337ea 100644 --- a/packages/kbn-es-query/src/filters/build_filters/phrases_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/phrases_filter.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { Filter, FilterMeta, FILTERS } from './types'; +import { FieldFilter, Filter, FilterMeta, FILTERS } from './types'; import { getPhraseScript } from './phrase_filter'; import type { IndexPatternFieldBase, IndexPatternBase } from '../../es_query'; @@ -19,20 +19,35 @@ export type PhrasesFilter = Filter & { meta: PhrasesFilterMeta; }; -export const isPhrasesFilter = (filter: any): filter is PhrasesFilter => +/** + * @param filter + * @returns `true` if a filter is a `PhrasesFilter` + * + * @public + */ +export const isPhrasesFilter = (filter: FieldFilter): filter is PhrasesFilter => filter?.meta?.type === FILTERS.PHRASES; +/** @internal */ export const getPhrasesFilterField = (filter: PhrasesFilter) => { // Phrases is a newer filter type that has always been created via a constructor that ensures // `meta.key` is set to the field name return filter.meta.key; }; -// Creates a filter where the given field matches one or more of the given values -// params should be an array of values +/** + * Creates a filter where the given field matches one or more of the given values + * params should be an array of values + * @param field + * @param params + * @param indexPattern + * @returns + * + * @public + */ export const buildPhrasesFilter = ( field: IndexPatternFieldBase, - params: any[], + params: string[], indexPattern: IndexPatternBase ) => { const index = indexPattern.id; @@ -41,11 +56,11 @@ export const buildPhrasesFilter = ( let should; if (field.scripted) { - should = params.map((v: any) => ({ + should = params.map((v) => ({ script: getPhraseScript(field, v), })); } else { - should = params.map((v: any) => ({ + should = params.map((v) => ({ match_phrase: { [field.name]: v, }, diff --git a/packages/kbn-es-query/src/filters/build_filters/query_string_filter.ts b/packages/kbn-es-query/src/filters/build_filters/query_string_filter.ts index 4fa084f181827..c083775b8db44 100644 --- a/packages/kbn-es-query/src/filters/build_filters/query_string_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/query_string_filter.ts @@ -6,7 +6,8 @@ * Side Public License, v 1. */ -import type { Filter, FilterMeta } from './types'; +import { has } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta } from './types'; export type QueryStringFilterMeta = FilterMeta; @@ -19,10 +20,24 @@ export type QueryStringFilter = Filter & { }; }; -export const isQueryStringFilter = (filter: any): filter is QueryStringFilter => - filter && filter.query && filter.query.query_string; +/** + * @param filter + * @returns `true` if a filter is a `QueryStringFilter` + * + * @public + */ +export const isQueryStringFilter = (filter: FieldFilter): filter is QueryStringFilter => + has(filter, 'query.query_string'); -// Creates a filter corresponding to a raw Elasticsearch query DSL object +/** + * Creates a filter corresponding to a raw Elasticsearch query DSL object + * @param query + * @param index + * @param alias + * @returns `QueryStringFilter` + * + * @public + */ export const buildQueryFilter = (query: QueryStringFilter['query'], index: string, alias: string) => ({ query, diff --git a/packages/kbn-es-query/src/filters/build_filters/range_filter.ts b/packages/kbn-es-query/src/filters/build_filters/range_filter.ts index 6ed560ccc831e..ae26c6ae48db8 100644 --- a/packages/kbn-es-query/src/filters/build_filters/range_filter.ts +++ b/packages/kbn-es-query/src/filters/build_filters/range_filter.ts @@ -6,8 +6,8 @@ * Side Public License, v 1. */ import type { estypes } from '@elastic/elasticsearch'; -import { map, reduce, mapValues, get, keys, pickBy } from 'lodash'; -import type { Filter, FilterMeta } from './types'; +import { map, reduce, mapValues, has, get, keys, pickBy } from 'lodash'; +import type { FieldFilter, Filter, FilterMeta } from './types'; import type { IndexPatternBase, IndexPatternFieldBase } from '../../es_query'; const OPERANDS_IN_RANGE = 2; @@ -32,6 +32,10 @@ const dateComparators = { lt: 'boolean lt(Supplier s, def v) {return s.get().toInstant().isBefore(Instant.parse(v))}', }; +/** + * An interface for all possible range filter params + * @public + */ export interface RangeFilterParams { from?: number | string; to?: number | string; @@ -49,7 +53,7 @@ const hasRangeKeys = (params: RangeFilterParams) => export type RangeFilterMeta = FilterMeta & { params: RangeFilterParams; - field?: any; + field?: string; formattedValue?: string; }; @@ -57,6 +61,9 @@ export interface EsRangeFilter { range: { [key: string]: RangeFilterParams }; } +/** + * @public + */ export type RangeFilter = Filter & EsRangeFilter & { meta: RangeFilterMeta; @@ -64,20 +71,36 @@ export type RangeFilter = Filter & script: { params: any; lang: estypes.ScriptLanguage; - source: any; + source: string; }; }; match_all?: any; }; -export const isRangeFilter = (filter: any): filter is RangeFilter => filter && filter.range; - -export const isScriptedRangeFilter = (filter: any): filter is RangeFilter => { +/** + * @param filter + * @returns `true` if a filter is an `RangeFilter` + * + * @public + */ +export const isRangeFilter = (filter?: FieldFilter): filter is RangeFilter => has(filter, 'range'); + +/** + * + * @param filter + * @returns `true` if a filter is a scripted `RangeFilter` + * + * @public + */ +export const isScriptedRangeFilter = (filter: FieldFilter): filter is RangeFilter => { const params: RangeFilterParams = get(filter, 'script.script.params', {}); return hasRangeKeys(params); }; +/** + * @internal + */ export const getRangeFilterField = (filter: RangeFilter) => { return filter.range && Object.keys(filter.range)[0]; }; @@ -85,8 +108,18 @@ export const getRangeFilterField = (filter: RangeFilter) => { const formatValue = (params: any[]) => map(params, (val: any, key: string) => get(operators, key) + val).join(' '); -// Creates a filter where the value for the given field is in the given range -// params should be an object containing `lt`, `lte`, `gt`, and/or `gte` +/** + * Creates a filter where the value for the given field is in the given range + * params should be an object containing `lt`, `lte`, `gt`, and/or `gte` + * + * @param field + * @param params + * @param indexPattern + * @param formattedValue + * @returns + * + * @public + */ export const buildRangeFilter = ( field: IndexPatternFieldBase, params: RangeFilterParams, @@ -134,6 +167,9 @@ export const buildRangeFilter = ( return filter as RangeFilter; }; +/** + * @internal + */ export const getRangeScript = (field: IndexPatternFieldBase, params: RangeFilterParams) => { const knownParams = mapValues( pickBy(params, (val, key: any) => key in operators), diff --git a/packages/kbn-es-query/src/filters/build_filters/types.ts b/packages/kbn-es-query/src/filters/build_filters/types.ts index 13e4a941b9166..4bf53303c1544 100644 --- a/packages/kbn-es-query/src/filters/build_filters/types.ts +++ b/packages/kbn-es-query/src/filters/build_filters/types.ts @@ -15,7 +15,10 @@ import { RangeFilter } from './range_filter'; import { MatchAllFilter } from './match_all_filter'; import { MissingFilter } from './missing_filter'; -// Any filter associated with a field (used in the filter bar/editor) +/** + * A common type for filters supported by this package + * @public + **/ export type FieldFilter = | ExistsFilter | GeoBoundingBoxFilter @@ -26,6 +29,16 @@ export type FieldFilter = | MatchAllFilter | MissingFilter; +/** + * A common type for filters supported by this package + * @public + **/ +export type FilterParams = any; + +/** + * An enum of all types of filters supported by this package + * @public + */ export enum FILTERS { CUSTOM = 'custom', PHRASES = 'phrases', @@ -41,16 +54,15 @@ export enum FILTERS { SPATIAL_FILTER = 'spatial_filter', } +/** + * An enum to denote whether a filter is specific to an application's context or whether it should be applied globally. + * @public + */ export enum FilterStateStore { APP_STATE = 'appState', GLOBAL_STATE = 'globalState', } -// eslint-disable-next-line -export type FilterState = { - store: FilterStateStore; -}; - // eslint-disable-next-line export type FilterMeta = { alias: string | null; @@ -69,7 +81,9 @@ export type FilterMeta = { // eslint-disable-next-line export type Filter = { - $state?: FilterState; + $state?: { + store: FilterStateStore; + }; meta: FilterMeta; query?: any; // TODO: can we use the Query type her? }; @@ -80,6 +94,10 @@ export type Query = { language: string; }; +/** + * An interface for a latitude-longitude pair + * @public + */ export interface LatLon { lat: number; lon: number; diff --git a/packages/kbn-es-query/src/filters/helpers/compare_filters.ts b/packages/kbn-es-query/src/filters/helpers/compare_filters.ts index 1ca9143247eea..ffc7461bc6cdd 100644 --- a/packages/kbn-es-query/src/filters/helpers/compare_filters.ts +++ b/packages/kbn-es-query/src/filters/helpers/compare_filters.ts @@ -9,6 +9,7 @@ import { defaults, isEqual, omit, map } from 'lodash'; import type { FilterMeta, Filter } from '../build_filters'; +/** @public */ export interface FilterCompareOptions { index?: boolean; disabled?: boolean; @@ -19,6 +20,7 @@ export interface FilterCompareOptions { /** * Include disabled, negate and store when comparing filters + * @public */ export const COMPARE_ALL_OPTIONS: FilterCompareOptions = { index: true, @@ -60,6 +62,8 @@ const mapFilterArray = ( * @param {FilterCompareOptions} comparatorOptions Parameters to use for comparison * * @returns {bool} Filters are the same + * + * @public */ export const compareFilters = ( first: Filter | Filter[], diff --git a/packages/kbn-es-query/src/filters/helpers/dedup_filters.ts b/packages/kbn-es-query/src/filters/helpers/dedup_filters.ts index 564354d012371..f43ef31837ae2 100644 --- a/packages/kbn-es-query/src/filters/helpers/dedup_filters.ts +++ b/packages/kbn-es-query/src/filters/helpers/dedup_filters.ts @@ -18,6 +18,8 @@ import { compareFilters, FilterCompareOptions } from './compare_filters'; * @param {object} comparatorOptions - Parameters to use for comparison * * @returns {object} An array of filters that were not in existing + * + * @internal */ export const dedupFilters = ( existingFilters: Filter[], diff --git a/packages/kbn-es-query/src/filters/helpers/meta_filter.ts b/packages/kbn-es-query/src/filters/helpers/meta_filter.ts index 91f5186570195..61b89d45d1962 100644 --- a/packages/kbn-es-query/src/filters/helpers/meta_filter.ts +++ b/packages/kbn-es-query/src/filters/helpers/meta_filter.ts @@ -9,10 +9,32 @@ import { omit, get } from 'lodash'; import { Filter, FilterStateStore } from '../build_filters'; +/** + * + * @param filter + * @returns `true` if the filter should be applied to global scope + * + * @public + */ export const isFilterPinned = (filter: Filter) => { return filter.$state && filter.$state.store === FilterStateStore.GLOBAL_STATE; }; +/** + * @param filter + * @returns `true` if the filter is disabled + * + * @public + */ +export const isFilterDisabled = (filter: Filter): boolean => get(filter, 'meta.disabled', false); + +/** + * + * @param filter + * @returns A copy of the filter with a toggled disabled state + * + * @public + */ export const toggleFilterDisabled = (filter: Filter) => { const disabled = !filter.meta.disabled; const meta = { ...filter.meta, disabled }; @@ -20,6 +42,13 @@ export const toggleFilterDisabled = (filter: Filter) => { return { ...filter, meta }; }; +/** + * + * @param filter + * @returns A copy of the filter with a toggled negated state + * + * @public + */ export const toggleFilterNegated = (filter: Filter) => { const negate = !filter.meta.negate; const meta = { ...filter.meta, negate }; @@ -27,6 +56,13 @@ export const toggleFilterNegated = (filter: Filter) => { return { ...filter, meta }; }; +/** + * + * @param filter + * @returns A copy of the filter with a toggled pinned state (toggles store from app to global and vice versa) + * + * @public + */ export const toggleFilterPinned = (filter: Filter) => { const store = isFilterPinned(filter) ? FilterStateStore.APP_STATE : FilterStateStore.GLOBAL_STATE; const $state = { ...filter.$state, store }; @@ -34,18 +70,48 @@ export const toggleFilterPinned = (filter: Filter) => { return { ...filter, $state }; }; +/** + * @param filter + * @returns An enabled copy of the filter + * + * @public + */ export const enableFilter = (filter: Filter) => !filter.meta.disabled ? filter : toggleFilterDisabled(filter); +/** + * @param filter + * @returns A disabled copy of the filter + * + * @public + */ export const disableFilter = (filter: Filter) => filter.meta.disabled ? filter : toggleFilterDisabled(filter); +/** + * @param filter + * @returns A pinned (global) copy of the filter + * + * @public + */ export const pinFilter = (filter: Filter) => isFilterPinned(filter) ? filter : toggleFilterPinned(filter); +/** + * @param filter + * @returns An unpinned (app scoped) copy of the filter + * + * @public + */ export const unpinFilter = (filter: Filter) => !isFilterPinned(filter) ? filter : toggleFilterPinned(filter); +/** + * @param {unknown} filter + * @returns `true` if the given object is a filter + * + * @public + */ export const isFilter = (x: unknown): x is Filter => !!x && typeof x === 'object' && @@ -53,6 +119,12 @@ export const isFilter = (x: unknown): x is Filter => typeof (x as Filter).meta === 'object' && typeof (x as Filter).meta.disabled === 'boolean'; +/** + * @param {unknown} filters + * @returns `true` if the given object is an array of filters + * + * @public + */ export const isFilters = (x: unknown): x is Filter[] => Array.isArray(x) && !x.find((y) => !isFilter(y)); @@ -60,7 +132,7 @@ export const isFilters = (x: unknown): x is Filter[] => * Clean out any invalid attributes from the filters * @param {object} filter The filter to clean * @returns {object} + * + * @public */ export const cleanFilter = (filter: Filter): Filter => omit(filter, ['meta', '$state']) as Filter; - -export const isFilterDisabled = (filter: Filter): boolean => get(filter, 'meta.disabled', false); diff --git a/packages/kbn-es-query/src/filters/helpers/only_disabled.ts b/packages/kbn-es-query/src/filters/helpers/only_disabled.ts index d090c411934f7..d605d8b0be628 100644 --- a/packages/kbn-es-query/src/filters/helpers/only_disabled.ts +++ b/packages/kbn-es-query/src/filters/helpers/only_disabled.ts @@ -14,8 +14,9 @@ const isEnabled = (f: Filter) => f && f.meta && !f.meta.disabled; /** * Checks to see if only disabled filters have been changed - * * @returns {bool} Only disabled filters + * + * @public */ export const onlyDisabledFiltersChanged = (newFilters?: Filter[], oldFilters?: Filter[]) => { // If it's the same - compare only enabled filters diff --git a/packages/kbn-es-query/src/filters/helpers/uniq_filters.ts b/packages/kbn-es-query/src/filters/helpers/uniq_filters.ts index e502cd5dbba5d..1e388ed7a8c96 100644 --- a/packages/kbn-es-query/src/filters/helpers/uniq_filters.ts +++ b/packages/kbn-es-query/src/filters/helpers/uniq_filters.ts @@ -15,8 +15,8 @@ import { dedupFilters } from './dedup_filters'; * * @param {array} filters The filters to remove duplicates from * @param {object} comparatorOptions - Parameters to use for comparison - * @returns {object} The original filters array with duplicates removed + * @public */ export const uniqFilters = (filters: Filter[], comparatorOptions: any = {}) => { let results: Filter[] = []; diff --git a/packages/kbn-es-query/src/filters/index.ts b/packages/kbn-es-query/src/filters/index.ts index 57139dc5110a4..61ee6ce6f0da6 100644 --- a/packages/kbn-es-query/src/filters/index.ts +++ b/packages/kbn-es-query/src/filters/index.ts @@ -59,7 +59,6 @@ export { export { Query, Filter, - FilterState, LatLon, FieldFilter, FilterMeta, diff --git a/packages/kbn-es-query/src/kuery/kuery_syntax_error.ts b/packages/kbn-es-query/src/kuery/kuery_syntax_error.ts index aa4440579eb49..e7ea0b5c2dd34 100644 --- a/packages/kbn-es-query/src/kuery/kuery_syntax_error.ts +++ b/packages/kbn-es-query/src/kuery/kuery_syntax_error.ts @@ -52,6 +52,10 @@ interface KQLSyntaxErrorExpected { type: string; } +/** + * A type of error indicating KQL syntax errors + * @public + */ export class KQLSyntaxError extends Error { shortMessage: string; diff --git a/packages/kbn-es-query/src/kuery/node_types/index.ts b/packages/kbn-es-query/src/kuery/node_types/index.ts index dc284bd64273b..a9298f27d28be 100644 --- a/packages/kbn-es-query/src/kuery/node_types/index.ts +++ b/packages/kbn-es-query/src/kuery/node_types/index.ts @@ -15,6 +15,9 @@ import { NodeTypes } from './types'; export { NodeTypes }; export { nodeBuilder } from './node_builder'; +/** + * @public + */ export const nodeTypes: NodeTypes = { // This requires better typing of the different typings and their return types. // @ts-ignore diff --git a/packages/kbn-es-query/src/kuery/types.ts b/packages/kbn-es-query/src/kuery/types.ts index fe1496ead7ab6..f188eab61c546 100644 --- a/packages/kbn-es-query/src/kuery/types.ts +++ b/packages/kbn-es-query/src/kuery/types.ts @@ -8,13 +8,19 @@ import { NodeTypes } from './node_types'; +/** @public */ export interface KueryNode { type: keyof NodeTypes; [key: string]: any; } +/** + * TODO: Replace with real type + * @public + */ export type DslQuery = any; +/** @internal */ export interface KueryParseOptions { helpers: { [key: string]: any; diff --git a/packages/kbn-es-query/src/utils.ts b/packages/kbn-es-query/src/utils.ts index 5e8d60a4b66fe..48d17e75e346c 100644 --- a/packages/kbn-es-query/src/utils.ts +++ b/packages/kbn-es-query/src/utils.ts @@ -8,6 +8,7 @@ import moment from 'moment-timezone'; +/** @internal */ export function getTimeZoneFromSettings(dateFormatTZ: string) { const detectedTimezone = moment.tz.guess(); diff --git a/src/core/public/fatal_errors/fatal_errors_service.tsx b/src/core/public/fatal_errors/fatal_errors_service.tsx index 52ec32b1d2d3d..975c0160d83b2 100644 --- a/src/core/public/fatal_errors/fatal_errors_service.tsx +++ b/src/core/public/fatal_errors/fatal_errors_service.tsx @@ -51,7 +51,7 @@ export interface FatalErrorsSetup { */ export type FatalErrorsStart = FatalErrorsSetup; -/** @interal */ +/** @internal */ export class FatalErrorsService { private readonly errorInfo$ = new Rx.ReplaySubject(); private fatalErrors?: FatalErrorsSetup; diff --git a/src/plugins/data/public/index.ts b/src/plugins/data/public/index.ts index 873608d401e1c..803b93cc7acf5 100644 --- a/src/plugins/data/public/index.ts +++ b/src/plugins/data/public/index.ts @@ -6,19 +6,15 @@ * Side Public License, v 1. */ -/* - * esQuery and esKuery: - */ - import { PluginInitializerContext } from '../../../core/public'; import { ConfigSchema } from '../config'; +export * from './deprecated'; + /* * Filters: */ -export * from './deprecated'; - export { getEsQueryConfig } from '../common'; export { FilterLabel, FilterItem } from './ui'; export { getDisplayValueFromFilter, generateFilters, extractTimeRange } from './query'; diff --git a/src/plugins/data/public/public.api.md b/src/plugins/data/public/public.api.md index 6178edff3687b..c7e556c6da554 100644 --- a/src/plugins/data/public/public.api.md +++ b/src/plugins/data/public/public.api.md @@ -743,18 +743,18 @@ export const esFilters: { FILTERS: typeof import("@kbn/es-query").FILTERS; FilterStateStore: typeof FilterStateStore; buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("@kbn/es-query").Filter; - buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: any[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; + buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: string[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter; - buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: any, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; + buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: string | number | boolean, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; buildQueryFilter: (query: any, index: string, alias: string) => import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; buildRangeFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: import("@kbn/es-query").RangeFilterParams, indexPattern: import("@kbn/es-query").IndexPatternBase, formattedValue?: string | undefined) => import("@kbn/es-query").RangeFilter; - isPhraseFilter: (filter: any) => filter is import("@kbn/es-query").PhraseFilter; - isExistsFilter: (filter: any) => filter is import("@kbn/es-query").ExistsFilter; - isPhrasesFilter: (filter: any) => filter is import("@kbn/es-query").PhrasesFilter; - isRangeFilter: (filter: any) => filter is import("@kbn/es-query").RangeFilter; - isMatchAllFilter: (filter: any) => filter is import("@kbn/es-query").MatchAllFilter; - isMissingFilter: (filter: any) => filter is import("@kbn/es-query").MissingFilter; - isQueryStringFilter: (filter: any) => filter is import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; + isPhraseFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").PhraseFilter; + isExistsFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").ExistsFilter; + isPhrasesFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").PhrasesFilter; + isRangeFilter: (filter?: import("@kbn/es-query").ExistsFilter | import("@kbn/es-query").GeoPolygonFilter | import("@kbn/es-query").PhrasesFilter | import("@kbn/es-query").PhraseFilter | import("@kbn/es-query").MatchAllFilter | import("@kbn/es-query").MissingFilter | import("@kbn/es-query").RangeFilter | import("@kbn/es-query").GeoBoundingBoxFilter | undefined) => filter is import("@kbn/es-query").RangeFilter; + isMatchAllFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").MatchAllFilter; + isMissingFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query").MissingFilter; + isQueryStringFilter: (filter: import("@kbn/es-query").FieldFilter) => filter is import("@kbn/es-query/target_types/filters/build_filters").QueryStringFilter; isFilterPinned: (filter: import("@kbn/es-query").Filter) => boolean | undefined; toggleFilterNegated: (filter: import("@kbn/es-query").Filter) => { meta: { @@ -769,7 +769,9 @@ export const esFilters: { params?: any; value?: string | undefined; }; - $state?: import("@kbn/es-query").FilterState | undefined; + $state?: { + store: FilterStateStore; + } | undefined; query?: any; }; disableFilter: (filter: import("@kbn/es-query").Filter) => import("@kbn/es-query").Filter; diff --git a/src/plugins/data/server/server.api.md b/src/plugins/data/server/server.api.md index ec5e0a7d08186..555177c6cf5ad 100644 --- a/src/plugins/data/server/server.api.md +++ b/src/plugins/data/server/server.api.md @@ -393,8 +393,8 @@ export const esFilters: { buildEmptyFilter: (isPinned: boolean, index?: string | undefined) => import("@kbn/es-query").Filter; buildExistsFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").ExistsFilter; buildFilter: typeof import("@kbn/es-query").buildFilter; - buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: any, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; - buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: any[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; + buildPhraseFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, value: string | number | boolean, indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhraseFilter; + buildPhrasesFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: string[], indexPattern: import("@kbn/es-query").IndexPatternBase) => import("@kbn/es-query").PhrasesFilter; buildRangeFilter: (field: import("@kbn/es-query").IndexPatternFieldBase, params: import("@kbn/es-query").RangeFilterParams, indexPattern: import("@kbn/es-query").IndexPatternBase, formattedValue?: string | undefined) => import("@kbn/es-query").RangeFilter; isFilterDisabled: (filter: import("@kbn/es-query").Filter) => boolean; }; diff --git a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts index 9b637ab4bab99..3e85c5db28a6c 100644 --- a/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts +++ b/x-pack/plugins/maps/public/classes/tooltips/es_tooltip_property.ts @@ -87,7 +87,7 @@ export class ESTooltipProperty implements ITooltipProperty { existsFilter.meta.negate = true; return [existsFilter]; } else { - return [esFilters.buildPhraseFilter(indexPatternField, value, this._indexPattern)]; + return [esFilters.buildPhraseFilter(indexPatternField, value as string, this._indexPattern)]; } } } diff --git a/x-pack/plugins/observability/public/components/shared/filter_value_label/filter_value_label.tsx b/x-pack/plugins/observability/public/components/shared/filter_value_label/filter_value_label.tsx index 82392b5c23bf9..9e7b96b02206f 100644 --- a/x-pack/plugins/observability/public/components/shared/filter_value_label/filter_value_label.tsx +++ b/x-pack/plugins/observability/public/components/shared/filter_value_label/filter_value_label.tsx @@ -28,7 +28,7 @@ export function buildFilterLabel({ const filter = value instanceof Array && value.length > 1 ? esFilters.buildPhrasesFilter(indexField, value, indexPattern) - : esFilters.buildPhraseFilter(indexField, value, indexPattern); + : esFilters.buildPhraseFilter(indexField, value as string, indexPattern); filter.meta.type = value instanceof Array && value.length > 1 ? 'phrases' : 'phrase';