import { identity } from 'lodash' ; import { CoreSetup , Plugin } from '../../../../src/core/server' ; import { EmbeddableSetup } from '../../../../src/plugins/embeddable/server' ; import { dynamicActionEnhancement } from './dynamic_action_enhancement' ; import { ActionFactoryRegistry , SerializedEvent , ActionFactoryDefinition } from './types' ; export interface SetupContract { registerActionFactory : ( definition : ActionFactoryDefinition ) => void ; } export type StartContract = void ; interface SetupDependencies { embeddable : EmbeddableSetup ; } export class AdvancedUiActionsServerPlugin implements Plugin < SetupContract , StartContract , SetupDependencies > { protected readonly actionFactories : ActionFactoryRegistry = new Map ( ) ; constructor ( ) { } public setup ( core , { embeddable } ) { const getActionFactory = ( actionFactoryId ) => this . actionFactories . get ( actionFactoryId ) ; embeddable . registerEnhancement ( dynamicActionEnhancement ( getActionFactory ) ) ; return { registerActionFactory : this . registerActionFactory , } ; } public start ( ) { } public stop ( ) { } /**
     * Register an action factory. Action factories are used to configure and
     * serialize/deserialize dynamic actions.
     */ public readonly registerActionFactory = ( definition ) => { if ( this . actionFactories . has ( definition . id ) ) { throw new Error ( `ActionFactory [actionFactory.id = ${ definition . id }] already registered.` ) ; } this . actionFactories . set ( definition . id , { id : definition . id , telemetry : definition . telemetry || ( ( state , stats ) => stats ) , inject : definition . inject || identity , extract : definition . extract || ( ( state ) => { return { state , references : [ ] } ; } ) , migrations : definition . migrations || { } , } ) ; } ; }