import { AggConfig , IAggConfig , AggConfigSerialized } from '../agg_config' ; import { BaseParamType } from './base' ; export class AggParamType < TAggConfig extends IAggConfig = IAggConfig > extends BaseParamType < TAggConfig > { makeAgg : ( agg : TAggConfig , state ? : AggConfigSerialized ) => TAggConfig ; allowedAggs : string [ ] = [ ] ; constructor ( config ) { super ( config ) ; if ( config . allowedAggs ) { this . allowedAggs = config . allowedAggs ; } if ( ! config . write ) { this . write = ( aggConfig , output ) => { if ( aggConfig . params [ this . name ] && aggConfig . params [ this . name ] . length ) { output . params [ this . name ] = aggConfig . params [ this . name ] ; } } ; } if ( ! config . serialize ) { this . serialize = ( agg ) => { return agg . serialize ( ) ; } ; } if ( ! config . deserialize ) { this . deserialize = ( state , agg ? ) : TAggConfig => { if ( ! agg ) { throw new Error ( 'aggConfig was not provided to AggParamType deserialize function' ) ; } return this . makeAgg ( agg , state ) ; } ; } if ( ! config . toExpressionAst ) { this . toExpressionAst = ( agg ) => { if ( ! agg || ! agg . toExpressionAst ) { throw new Error ( 'aggConfig was not provided to AggParamType toExpressionAst function' ) ; } return agg . toExpressionAst ( ) ; } ; } this . makeAgg = config . makeAgg ; this . valueType = AggConfig ; } }