import { flow } from 'fp-ts/lib/function' ; import { addIdToItem , removeIdFromItem } from '@kbn/securitysolution-utils' ; import type { CreateExceptionListItemSchema , EntriesArray , Entry , ExceptionListItemSchema , UpdateExceptionListItemSchema , } from '@kbn/securitysolution-io-ts-list-types' ; param exceptionItem returns export const transformOutput = ( exceptionItem ) : UpdateExceptionListItemSchema | ExceptionListItemSchema => flow ( removeIdFromExceptionItemsEntries ) ( exceptionItem ) ; export const transformNewItemOutput = ( exceptionItem ) : CreateExceptionListItemSchema => flow ( removeIdFromExceptionItemsEntries ) ( exceptionItem ) ; param exceptionItem returns export const transformInput = ( exceptionItem ) : ExceptionListItemSchema => flow ( addIdToExceptionItemEntries ) ( exceptionItem ) ; param exceptionItem returns export const addIdToExceptionItemEntries = ( exceptionItem ) : ExceptionListItemSchema => { const entries = exceptionItem . entries . map ( ( entry ) => { if ( entry . type === 'nested' ) { return addIdToItem ( { ... entry , entries : entry . entries . map ( ( nestedEntry ) => addIdToItem ( nestedEntry ) ) , } ) ; } else { return addIdToItem ( entry ) ; } } ) ; return { ... exceptionItem , entries } ; } ; param exceptionItem returns export const removeIdFromExceptionItemsEntries = < T extends { entries : EntriesArray ; } > ( exceptionItem ) : T => { const { entries } = exceptionItem ; const entriesNoId = entries . map ( ( entry ) => { if ( entry . type === 'nested' ) { return removeIdFromItem ( { ... entry , entries : entry . entries . map ( ( nestedEntry ) => removeIdFromItem ( nestedEntry ) ) , } ) ; } else { return removeIdFromItem < Entry > ( entry ) ; } } ) ; return { ... exceptionItem , entries : entriesNoId } ; } ;