import { BoolQuery , EsQueryConfig , Query , buildEsQuery } from '@kbn/es-query' ; import { escapeQuotes } from './escape_query' ; export interface GetQueryFilterOptions { filter : string ; } export interface GetQueryFilterWithListIdOptions { filter : string ; listId : string ; } export interface GetQueryFilterReturn { bool : BoolQuery ; } export const getQueryFilter = ( { filter } ) : GetQueryFilterReturn => { const kqlQuery = { language : 'kuery' , query : filter , } ; const config = { allowLeadingWildcards : true , dateFormatTZ : 'Zulu' , ignoreFilterIfFieldNotInIndex : false , queryStringOptions : { analyze_wildcard : true } , } ; return buildEsQuery ( undefined , kqlQuery , [ ] , config ) ; } ; export const getQueryFilterWithListId = ( { filter , listId , } ) : GetQueryFilterReturn => { const escapedListId = escapeQuotes ( listId ) ; const filterWithListId = filter . trim ( ) !== '' ? `list_id: "${ escapedListId }" AND (${ filter })` : `list_id: "${ escapedListId }"` ; return getQueryFilter ( { filter : filterWithListId } ) ; } ;