import { SavedObject } from '../../../../core/types/saved_objects' ; import { BaseVisType } from './base_vis_type' ; export type VisualizationStage = 'experimental' | 'beta' | 'production' ; export interface VisualizationListItem { editUrl : string ; editApp ? : string ; error ? : string ; icon : string ; id : string ; stage : VisualizationStage ; savedObjectType : string ; title : string ; description ? : string ; getSupportedTriggers ? : ( ) => string [ ] ; typeTitle : string ; image ? : string ; type ? : BaseVisType | string ; } export interface VisualizationsAppExtension { docTypes : string [ ] ; searchFields ? : string [ ] ; toListItem : ( savedObject : SavedObject ) => VisualizationListItem ; } export interface VisTypeAlias { aliasPath : string ; aliasApp : string ; name : string ; title : string ; icon : string ; promotion ? : boolean ; description : string ; note ? : string ; getSupportedTriggers ? : ( ) => string [ ] ; stage : VisualizationStage ; appExtensions ? : { visualizations : VisualizationsAppExtension ; [ appName ] : unknown ; } ; } let registry = [ ] ; const discardOnRegister = [ ] ; interface VisTypeAliasRegistry { get : ( ) => VisTypeAlias [ ] ; add : ( newVisTypeAlias : VisTypeAlias ) => void ; remove : ( visTypeAliasName : string ) => void ; } export const visTypeAliasRegistry = { get : ( ) => [ ... registry ] , add : ( newVisTypeAlias ) => { if ( registry . find ( ( visTypeAlias ) => visTypeAlias . name === newVisTypeAlias . name ) ) { throw new Error ( `${ newVisTypeAlias . name } already registered` ) ; } const isToBeDiscarded = discardOnRegister . some ( ( aliasName ) => aliasName === newVisTypeAlias . name ) ; if ( ! isToBeDiscarded ) { registry . push ( newVisTypeAlias ) ; } } , remove : ( visTypeAliasName ) => { const isAliasPresent = registry . find ( ( visTypeAlias ) => visTypeAlias . name === visTypeAliasName ) ; if ( ! isAliasPresent ) { discardOnRegister . push ( visTypeAliasName ) ; } else { registry = registry . filter ( ( visTypeAlias ) => visTypeAlias . name !== visTypeAliasName ) ; } } , } ;