import { MapSavedObjectAttributes } from '../map_saved_object_type' ; import { JoinDescriptor , LayerDescriptor , VectorLayerDescriptor } from '../descriptor_types' ; import { SOURCE_TYPES } from '../constants' ; export function addTypeToTermJoin ( { attributes , } ) { if ( ! attributes || ! attributes . layerListJSON ) { return attributes ; } let layerList = [ ] ; try { layerList = JSON . parse ( attributes . layerListJSON ) ; } catch ( e ) { throw new Error ( 'Unable to parse attribute layerListJSON' ) ; } layerList . forEach ( ( layer ) => { if ( ! ( 'joins' in layer ) ) { return ; } const vectorLayer = layer as VectorLayerDescriptor ; if ( ! vectorLayer . joins ) { return ; } vectorLayer . joins . forEach ( ( join ) => { if ( ! join . right ) { return ; } if ( typeof join . right . type === 'undefined' ) { join . right . type = SOURCE_TYPES . ES_TERM_SOURCE ; } } ) ; } ) ; return { ... attributes , layerListJSON : JSON . stringify ( layerList ) , } ; }