import { cloneDeep , get , omit , has , flow , forOwn } from 'lodash' ; import type { SavedObjectMigrationFn } from 'kibana/server' ; import { DEFAULT_QUERY_LANGUAGE , INDEX_PATTERN_SAVED_OBJECT_TYPE } from '../../../data/common' ; import { commonAddSupportOfDualIndexSelectionModeInTSVB , commonHideTSVBLastValueIndicator , commonRemoveDefaultIndexPatternAndTimeFieldFromTSVBModel , commonMigrateVislibPie , commonAddEmptyValueColorRule , commonMigrateTagCloud , commonAddDropLastBucketIntoTSVBModel , commonAddDropLastBucketIntoTSVBModel714Above , commonRemoveMarkdownLessFromTSVB , } from './visualization_common_migrations' ; const migrateIndexPattern = ( doc ) => { const searchSourceJSON = get ( doc , 'attributes.kibanaSavedObjectMeta.searchSourceJSON' ) ; if ( typeof searchSourceJSON !== 'string' ) { return doc ; } let searchSource ; try { searchSource = JSON . parse ( searchSourceJSON ) ; } catch ( e ) { return doc ; } if ( searchSource . index && Array . isArray ( doc . references ) ) { searchSource . indexRefName = 'kibanaSavedObjectMeta.searchSourceJSON.index' ; doc . references . push ( { name : searchSource . indexRefName , type : INDEX_PATTERN_SAVED_OBJECT_TYPE , id : searchSource . index , } ) ; delete searchSource . index ; } if ( searchSource . filter ) { searchSource . filter . forEach ( ( filterRow , i ) => { if ( ! filterRow . meta || ! filterRow . meta . index || ! Array . isArray ( doc . references ) ) { return ; } filterRow . meta . indexRefName = `kibanaSavedObjectMeta.searchSourceJSON.filter[${ i }].meta.index` ; doc . references . push ( { name : filterRow . meta . indexRefName , type : INDEX_PATTERN_SAVED_OBJECT_TYPE , id : filterRow . meta . index , } ) ; delete filterRow . meta . index ; } ) ; } doc . attributes . kibanaSavedObjectMeta . searchSourceJSON = JSON . stringify ( searchSource ) ; return doc ; } ; const migratePercentileRankAggregation = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . type === 'metrics' ) { const series = get ( visState , 'params.series' ) || [ ] ; series . forEach ( ( part ) => { ( part . metrics || [ ] ) . forEach ( ( metric ) => { if ( metric . type === 'percentile_rank' && has ( metric , 'value' ) ) { metric . values = [ metric . value ] ; delete metric . value ; } } ) ; } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const migrateFilterRatioQuery = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . type === 'metrics' ) { const series = get ( visState , 'params.series' ) || [ ] ; series . forEach ( ( part ) => { ( part . metrics || [ ] ) . forEach ( ( metric ) => { if ( metric . type === 'filter_ratio' ) { if ( typeof metric . numerator === 'string' ) { metric . numerator = { query : metric . numerator , language : 'lucene' } ; } if ( typeof metric . denominator === 'string' ) { metric . denominator = { query : metric . denominator , language : 'lucene' } ; } } } ) ; } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const migrateOperatorKeyTypo = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . type === 'metrics' ) { const gaugeColorRules = get ( visState , 'params.gauge_color_rules' ) || [ ] ; gaugeColorRules . forEach ( ( colorRule ) => { if ( colorRule . opperator ) { delete colorRule . opperator ; } } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; see https const migrateSplitByChartRow = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . aggs && visState . params ) { let row ; visState . aggs . forEach ( ( agg ) => { if ( agg . type === 'terms' && agg . schema === 'split' && 'row' in agg . params ) { row = agg . params . row ; delete agg . params . row ; } } ) ; if ( row !== undefined ) { visState . params . row = row ; } return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const migrateDateHistogramAggregation = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . aggs ) { visState . aggs . forEach ( ( agg ) => { if ( agg . type === 'date_histogram' && agg . params ) { if ( agg . params . interval === 'custom' ) { agg . params . interval = agg . params . customInterval ; } delete agg . params . customInterval ; } if ( get ( agg , 'params.customBucket.type' , null ) === 'date_histogram' && agg . params . customBucket . params ) { if ( agg . params . customBucket . params . interval === 'custom' ) { agg . params . customBucket . params . interval = agg . params . customBucket . params . customInterval ; } delete agg . params . customBucket . params . customInterval ; } } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const migrateSchema = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } function replaceSchema ( agg ) { forOwn ( agg , ( value , key ) => { if ( typeof value === 'object' ) { if ( key === 'schema' ) { agg [ key ] = value . name ; } else { replaceSchema ( value ) ; } } } ) ; } if ( visState && visState . aggs ) { for ( const agg of visState . aggs ) { if ( typeof agg === 'object' ) { replaceSchema ( agg ) ; } } return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const removeDateHistogramTimeZones = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { let visState ; try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . aggs ) { visState . aggs . forEach ( ( agg ) => { if ( agg . type === 'date_histogram' && agg . params ) { delete agg . params . time_zone ; } if ( get ( agg , 'params.customBucket.type' , null ) === 'date_histogram' && agg . params . customBucket . params ) { delete agg . params . customBucket . params . time_zone ; } } ) ; doc . attributes . visState = JSON . stringify ( visState ) ; } } return doc ; } ; const migrateGaugeVerticalSplitToAlignment = ( doc , logger ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { try { const visState = JSON . parse ( visStateJSON ) ; if ( visState && visState . type === 'gauge' && ! visState . params . gauge . alignment ) { visState . params . gauge . alignment = visState . params . gauge . verticalSplit ? 'vertical' : 'horizontal' ; delete visState . params . gauge . verticalSplit ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } catch ( e ) { logger . log . warn ( `Exception @ migrateGaugeVerticalSplitToAlignment! ${ e }` ) ; logger . log . warn ( `Exception @ migrateGaugeVerticalSplitToAlignment! Payload: ${ visStateJSON }` ) ; } } return doc ; } ; const transformFilterStringToQueryObject = ( doc , logger ) => { const newDoc = cloneDeep ( doc ) ; const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { let visState ; try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState ) { const visType = get ( visState , 'params.type' ) ; const tsvbTypes = [ 'metric' , 'markdown' , 'top_n' , 'gauge' , 'table' , 'timeseries' ] ; if ( tsvbTypes . indexOf ( visType ) === - 1 ) { return doc ; } const params = get ( visState , 'params' ) ; if ( params . filter && typeof params . filter === 'string' ) { const paramsFilterObject = { query : params . filter , language : 'lucene' , } ; params . filter = paramsFilterObject ; } const annotations = get ( visState , 'params.annotations' ) || [ ] ; annotations . forEach ( ( item ) => { if ( ! item . query_string ) { return ; } if ( typeof item . query_string === 'string' ) { const itemQueryStringObject = { query : item . query_string , language : 'lucene' , } ; item . query_string = itemQueryStringObject ; } } ) ; const series = get ( visState , 'params.series' ) || [ ] ; series . forEach ( ( item ) => { if ( ! item . filter ) { return ; } if ( typeof item . filter === 'string' ) { const itemfilterObject = { query : item . filter , language : 'lucene' , } ; item . filter = itemfilterObject ; } if ( item . split_filters ) { const splitFilters = get ( item , 'split_filters' ) || [ ] ; splitFilters . forEach ( ( filter ) => { if ( ! filter . filter ) { return ; } if ( typeof filter . filter === 'string' ) { const filterfilterObject = { query : filter . filter , language : 'lucene' , } ; filter . filter = filterfilterObject ; } } ) ; } } ) ; newDoc . attributes . visState = JSON . stringify ( visState ) ; } } return newDoc ; } ; const transformSplitFiltersStringToQueryObject = ( doc ) => { const newDoc = cloneDeep ( doc ) ; const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { let visState ; try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState ) { const visType = get ( visState , 'params.type' ) ; const tsvbTypes = [ 'metric' , 'markdown' , 'top_n' , 'gauge' , 'table' , 'timeseries' ] ; if ( tsvbTypes . indexOf ( visType ) === - 1 ) { return doc ; } const series = get ( visState , 'params.series' ) || [ ] ; series . forEach ( ( item ) => { if ( item . split_filters ) { const splitFilters = get ( item , 'split_filters' ) || [ ] ; if ( splitFilters . length > 0 ) { splitFilters . forEach ( ( filter ) => { if ( typeof filter . filter === 'string' ) { const filterfilterObject = { query : filter . filter , language : 'lucene' , } ; filter . filter = filterfilterObject ; } } ) ; } } } ) ; newDoc . attributes . visState = JSON . stringify ( visState ) ; } } return newDoc ; } ; const migrateFiltersAggQuery = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { try { const visState = JSON . parse ( visStateJSON ) ; if ( visState && visState . aggs ) { visState . aggs . forEach ( ( agg ) => { if ( agg . type !== 'filters' ) return ; agg . params . filters . forEach ( ( filter ) => { if ( filter . input . language ) return filter ; filter . input . language = 'lucene' ; } ) ; } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } catch ( e ) { } } return doc ; } ; const replaceMovAvgToMovFn = ( doc , logger ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; if ( visState && visState . type === 'metrics' ) { const series = get ( visState , 'params.series' , [ ] ) ; series . forEach ( ( part ) => { if ( part . metrics && Array . isArray ( part . metrics ) ) { part . metrics . forEach ( ( metric ) => { if ( metric . type === 'moving_average' ) { metric . model_type = metric . model ; metric . alpha = get ( metric , 'settings.alpha' , 0.3 ) ; metric . beta = get ( metric , 'settings.beta' , 0.1 ) ; metric . gamma = get ( metric , 'settings.gamma' , 0.3 ) ; metric . period = get ( metric , 'settings.period' , 1 ) ; metric . multiplicative = get ( metric , 'settings.type' ) === 'mult' ; delete metric . minimize ; delete metric . model ; delete metric . settings ; delete metric . predict ; } } ) ; } } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } catch ( e ) { logger . log . warn ( `Exception @ replaceMovAvgToMovFn! ${ e }` ) ; logger . log . warn ( `Exception @ replaceMovAvgToMovFn! Payload: ${ visStateJSON }` ) ; } } return doc ; } ; const migrateFiltersAggQueryStringQueries = ( doc , logger ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { try { const visState = JSON . parse ( visStateJSON ) ; if ( visState && visState . aggs ) { visState . aggs . forEach ( ( agg ) => { if ( agg . type !== 'filters' ) return doc ; agg . params . filters . forEach ( ( filter ) => { if ( filter . input . query . query_string ) { filter . input . query = filter . input . query . query_string . query ; } } ) ; } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } catch ( e ) { } } return doc ; } ; const addDocReferences = ( doc ) => ( { ... doc , references : doc . references || [ ] , } ) ; const migrateSavedSearch = ( doc ) => { const savedSearchId = get ( doc , 'attributes.savedSearchId' ) ; if ( savedSearchId && doc . references ) { doc . references . push ( { type : 'search' , name : 'search_0' , id : savedSearchId , } ) ; doc . attributes . savedSearchRefName = 'search_0' ; } delete doc . attributes . savedSearchId ; return doc ; } ; const migrateControls = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; if ( visStateJSON ) { let visState ; try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState ) { const controls = get ( visState , 'params.controls' ) || [ ] ; controls . forEach ( ( control , i ) => { if ( ! control . indexPattern || ! doc . references ) { return ; } control . indexPatternRefName = `control_${ i }_index_pattern` ; doc . references . push ( { name : control . indexPatternRefName , type : INDEX_PATTERN_SAVED_OBJECT_TYPE , id : control . indexPattern , } ) ; delete control . indexPattern ; } ) ; doc . attributes . visState = JSON . stringify ( visState ) ; } } return doc ; } ; const migrateTableSplits = ( doc ) => { try { const visState = JSON . parse ( doc . attributes . visState ) ; if ( get ( visState , 'type' ) !== 'table' ) { return doc ; } let splitCount = 0 ; visState . aggs = visState . aggs . map ( ( agg ) => { if ( agg . schema !== 'split' ) { return agg ; } splitCount ++ ; if ( splitCount === 1 ) { return agg ; } agg . schema = 'bucket' ; agg . params = omit ( agg . params , [ 'row' ] ) ; return agg ; } ) ; if ( splitCount <= 1 ) { return doc ; } const newDoc = cloneDeep ( doc ) ; newDoc . attributes . visState = JSON . stringify ( visState ) ; return newDoc ; } catch ( e ) { throw new Error ( `Failure attempting to migrate saved object '${ doc . attributes . title }' - ${ e }` ) ; } } ; link link const migrateMatchAllQuery = ( doc ) => { const searchSourceJSON = get ( doc , 'attributes.kibanaSavedObjectMeta.searchSourceJSON' ) ; if ( searchSourceJSON ) { let searchSource ; try { searchSource = JSON . parse ( searchSourceJSON ) ; } catch ( e ) { return doc ; } if ( searchSource . query ?. match_all ) { return { ... doc , attributes : { ... doc . attributes , kibanaSavedObjectMeta : { searchSourceJSON : JSON . stringify ( { ... searchSource , query : { query : '' , language : DEFAULT_QUERY_LANGUAGE , } , } ) , } , } , } ; } } return doc ; } ; const migrateTsvbDefaultColorPalettes = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . type === 'metrics' ) { const series = get ( visState , 'params.series' ) || [ ] ; series . forEach ( ( part ) => { if ( ! part . split_color_mode ) { part . split_color_mode = 'gradient' ; } } ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( visState ) , } , } ; } } return doc ; } ; const removeTSVBSearchSource = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; const searchSourceJSON = get ( doc , 'attributes.kibanaSavedObjectMeta.searchSourceJSON' ) ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && visState . type === 'metrics' && searchSourceJSON !== '{}' ) { return { ... doc , attributes : { ... doc . attributes , kibanaSavedObjectMeta : { ... get ( doc , 'attributes.kibanaSavedObjectMeta' ) , searchSourceJSON : '{}' , } , } , } ; } } return doc ; } ; const addSupportOfDualIndexSelectionModeInTSVB = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { return doc ; } const newVisState = commonAddSupportOfDualIndexSelectionModeInTSVB ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } return doc ; } ; const enableDataTableVisToolbar = ( doc ) => { let visState ; try { visState = JSON . parse ( doc . attributes . visState ) ; } catch ( e ) { } if ( visState ?. type === 'table' ) { return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( { ... visState , params : { ... visState . params , showToolbar : true , } , } ) , } , } ; } return doc ; } ; /**
 * Decorate axes with default label filter value
 */ const decorateAxes = < T extends { labels : { filter ? : boolean ; } ; } > ( axes , fallback ) : T [ ] => axes . map ( ( axis ) => ( { ... axis , labels : { ... axis . labels , filter : axis . labels . filter ?? fallback , } , } ) ) ; /**
 * Defaults circlesRadius to 1 if it is not configured
 */ const addCirclesRadius = < T extends { circlesRadius : number ; } > ( axes ) : T [ ] => axes . map ( ( axis ) => { const hasCircleRadiusAttribute = Number . isFinite ( axis ?. circlesRadius ) ; return { ... axis , ... ( ! hasCircleRadiusAttribute && { circlesRadius : 1 , } ) , } ; } ) ; const CHART_TYPE_AREA = 'area' ; const CHART_TYPE_LINE = 'line' ; const CHART_TYPE_HISTOGRAM = 'histogram' ; /**
 * Migrate vislib bar, line and area charts to use new vis_type_xy plugin
 */ const migrateVislibAreaLineBarTypes = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } if ( visState && [ CHART_TYPE_AREA , CHART_TYPE_LINE , CHART_TYPE_HISTOGRAM ] . includes ( visState ?. params ?. type ) ) { const isHorizontalBar = visState . type === 'horizontal_bar' ; const isLineOrArea = visState ?. params ?. type === CHART_TYPE_AREA || visState ?. params ?. type === CHART_TYPE_LINE ; const hasPalette = visState ?. params ?. palette ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( { ... visState , params : { ... visState . params , ... ( ! hasPalette && { palette : { type : 'palette' , name : 'kibana_palette' , } , } ) , categoryAxes : visState . params . categoryAxes && decorateAxes ( visState . params . categoryAxes , ! isHorizontalBar ) , valueAxes : visState . params . valueAxes && decorateAxes ( visState . params . valueAxes , isHorizontalBar ) , seriesParams : visState . params . seriesParams && addCirclesRadius ( visState . params . seriesParams ) , isVislibVis : true , detailedTooltip : true , ... ( isLineOrArea && { fittingFunction : 'linear' , } ) , } , } ) , } , } ; } } return doc ; } ; /**
 * [TSVB] Hide Last value indicator by default for all TSVB types except timeseries
 */ const hideTSVBLastValueIndicator = ( doc ) => { try { const visState = JSON . parse ( doc . attributes . visState ) ; const newVisState = commonHideTSVBLastValueIndicator ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } catch ( e ) { } return doc ; } ; const addDropLastBucketIntoTSVBModel = ( doc ) => { try { const visState = JSON . parse ( doc . attributes . visState ) ; const newVisState = commonAddDropLastBucketIntoTSVBModel ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } catch ( e ) { } return doc ; } ; const addDropLastBucketIntoTSVBModel714Above = ( doc ) => { try { const visState = JSON . parse ( doc . attributes . visState ) ; const newVisState = commonAddDropLastBucketIntoTSVBModel714Above ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } catch ( e ) { } return doc ; } ; const removeDefaultIndexPatternAndTimeFieldFromTSVBModel = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { return doc ; } } const newVisState = commonRemoveDefaultIndexPatternAndTimeFieldFromTSVBModel ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } ; const addEmptyValueColorRule = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } const newVisState = commonAddEmptyValueColorRule ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } return doc ; } ; const migrateVislibPie = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } const newVisState = commonMigrateVislibPie ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } return doc ; } ; const migrateTagCloud = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } const newVisState = commonMigrateTagCloud ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } return doc ; } ; export const replaceIndexPatternReference = ( doc ) => ( { ... doc , references : Array . isArray ( doc . references ) ? doc . references . map ( ( reference ) => { if ( reference . type === 'index_pattern' ) { reference . type = INDEX_PATTERN_SAVED_OBJECT_TYPE ; } return reference ; } ) : doc . references , } ) ; export const removeMarkdownLessFromTSVB = ( doc ) => { const visStateJSON = get ( doc , 'attributes.visState' ) ; let visState ; if ( visStateJSON ) { try { visState = JSON . parse ( visStateJSON ) ; } catch ( e ) { } const newVisState = commonRemoveMarkdownLessFromTSVB ( visState ) ; return { ... doc , attributes : { ... doc . attributes , visState : JSON . stringify ( newVisState ) , } , } ; } return doc ; } ; export const visualizationSavedObjectTypeMigrations = { /**
     * We need to have this migration twice, once with a version prior to 7.0.0 once with a version
     * after it. The reason for that is, that this migration has been introduced once 7.0.0 was already
     * released. Thus a user who already had 7.0.0 installed already got the 7.0.0 migrations below running,
     * so we need a version higher than that. But this fix was backported to the 6.7 release, meaning if we
     * would only have the 7.0.1 migration in here a user on the 6.7 release will migrate their saved objects
     * to the 7.0.1 state, and thus when updating their Kibana to 7.0, will never run the 7.0.0 migrations introduced
     * in that version. So we apply this twice, once with 6.7.2 and once with 7.0.1 while the backport to 6.7
     * only contained the 6.7.2 migration and not the 7.0.1 migration.
     */ '6.7.2' : flow ( migrateMatchAllQuery , removeDateHistogramTimeZones ) , '7.0.0' : flow ( addDocReferences , migrateIndexPattern , migrateSavedSearch , migrateControls , migrateTableSplits ) , '7.0.1' : flow ( removeDateHistogramTimeZones ) , '7.2.0' : flow ( migratePercentileRankAggregation , migrateDateHistogramAggregation ) , '7.3.0' : flow ( migrateGaugeVerticalSplitToAlignment , transformFilterStringToQueryObject , migrateFiltersAggQuery , replaceMovAvgToMovFn ) , '7.3.1' : flow ( migrateFiltersAggQueryStringQueries ) , '7.4.2' : flow ( transformSplitFiltersStringToQueryObject ) , '7.7.0' : flow ( migrateOperatorKeyTypo , migrateSplitByChartRow ) , '7.8.0' : flow ( migrateTsvbDefaultColorPalettes ) , '7.9.3' : flow ( migrateMatchAllQuery ) , '7.10.0' : flow ( migrateFilterRatioQuery , removeTSVBSearchSource ) , '7.11.0' : flow ( enableDataTableVisToolbar ) , '7.12.0' : flow ( migrateVislibAreaLineBarTypes , migrateSchema ) , '7.13.0' : flow ( addSupportOfDualIndexSelectionModeInTSVB , hideTSVBLastValueIndicator , removeDefaultIndexPatternAndTimeFieldFromTSVBModel ) , '7.13.1' : flow ( addSupportOfDualIndexSelectionModeInTSVB , hideTSVBLastValueIndicator , removeDefaultIndexPatternAndTimeFieldFromTSVBModel ) , '7.14.0' : flow ( addEmptyValueColorRule , migrateVislibPie , migrateTagCloud , replaceIndexPatternReference , addDropLastBucketIntoTSVBModel ) , '7.17.0' : flow ( addDropLastBucketIntoTSVBModel714Above ) , '8.0.0' : flow ( removeMarkdownLessFromTSVB ) , } ;