import { ExceptionListSchema , FoundExceptionListSchema , NamespaceType , } from '@kbn/securitysolution-io-ts-list-types' ; import { getSavedObjectTypes } from '@kbn/securitysolution-list-utils' ; import { SavedObjectsClientContract } from 'kibana/server' ; import { findExceptionList } from '../../find_exception_list' ; import { CHUNK_PARSED_OBJECT_SIZE } from '../../import_exception_list_and_items' ; export interface ExceptionListQueryInfo { listId : string ; namespaceType : NamespaceType ; } param objects { array } param savedObjectsClient { object } returns { string } export const getListFilter = ( { objects , namespaceType , } ) : string => { return `${ getSavedObjectTypes ( { namespaceType : [ namespaceType ] , } ) [ 0 ] }.attributes.list_id:(${ objects . map ( ( list ) => list . listId ) . join ( ' OR ' ) })` ; } ; param agnosticListItems { array } param nonAgnosticListItems { array } param savedObjectsClient { object } returns { object } export const findAllListTypes = async ( agnosticListItems , nonAgnosticListItems , savedObjectsClient ) : Promise < FoundExceptionListSchema | null > => { const agnosticFilter = getListFilter ( { namespaceType : 'agnostic' , objects : agnosticListItems , } ) ; const nonAgnosticFilter = getListFilter ( { namespaceType : 'single' , objects : nonAgnosticListItems , } ) ; if ( ! agnosticListItems . length && ! nonAgnosticListItems . length ) { return null ; } else if ( agnosticListItems . length && ! nonAgnosticListItems . length ) { return findExceptionList ( { filter : agnosticFilter , namespaceType : [ 'agnostic' ] , page : undefined , perPage : CHUNK_PARSED_OBJECT_SIZE , savedObjectsClient , sortField : undefined , sortOrder : undefined , } ) ; } else if ( ! agnosticListItems . length && nonAgnosticListItems . length ) { return findExceptionList ( { filter : nonAgnosticFilter , namespaceType : [ 'single' ] , page : undefined , perPage : CHUNK_PARSED_OBJECT_SIZE , savedObjectsClient , sortField : undefined , sortOrder : undefined , } ) ; } else { return findExceptionList ( { filter : `${ agnosticFilter } OR ${ nonAgnosticFilter }` , namespaceType : [ 'single' , 'agnostic' ] , page : undefined , perPage : CHUNK_PARSED_OBJECT_SIZE , savedObjectsClient , sortField : undefined , sortOrder : undefined , } ) ; } } ; param agnosticListItems { array } param nonAgnosticListItems { array } param savedObjectsClient { object } returns { object } export const getAllListTypes = async ( agnosticListItems , nonAgnosticListItems , savedObjectsClient ) : Promise < Record < string , ExceptionListSchema > > => { const foundListsResponse = await findAllListTypes ( agnosticListItems , nonAgnosticListItems , savedObjectsClient ) ; if ( foundListsResponse == null ) { return { } ; } return foundListsResponse . data . reduce ( ( acc , list ) => ( { ... acc , [ list . list_id ] : list , } ) , { } ) ; } ;