import rison from 'rison-node' ; import { Workspace } from '../types' ; function escapeQuotes ( str ) { return str . replace ( /"/g , '\\"' ) ; } export function asKQL ( workspace , joinBy ) { const nodes = workspace . returnUnpackedGroupeds ( workspace . getSelectedOrAllNodes ( ) ) ; const clauses = nodes . map ( ( node ) => `"${ escapeQuotes ( node . data . field ) }" : "${ escapeQuotes ( node . data . term ) }"` ) ; const expression = clauses . join ( ` ${ joinBy } ` ) ; return encodeURIComponent ( rison . encode ( expression ) ) ; }