import { AggParamType } from './param_types/agg' ; import { FieldParamType } from './param_types/field' ; import { OptionedParamType } from './param_types/optioned' ; import { StringParamType } from './param_types/string' ; import { JsonParamType } from './param_types/json' ; import { BaseParamType } from './param_types/base' ; import { AggConfig } from './agg_config' ; import { IAggConfigs } from './agg_configs' ; const paramTypeMap = { field : FieldParamType , optioned : OptionedParamType , string : StringParamType , json : JsonParamType , agg : AggParamType , _default : BaseParamType , } as Record < string , any > ; export type AggParam = BaseParamType ; export interface AggParamOption { val : string ; display : string ; enabled ? ( agg ) : boolean ; } export const initParams = < TAggParam extends AggParamType = AggParamType > ( params ) : TAggParam [ ] => params . map ( ( config ) => { const Class = paramTypeMap [ config . type ] || paramTypeMap . _default ; return new Class ( config ) ; } ) as TAggParam [ ] ; method param { AggConfig } aggConfig param { object } locals return { object } export const writeParams = < TAggConfig extends AggConfig = AggConfig , TAggParam extends AggParamType < TAggConfig > = AggParamType < TAggConfig > > ( params = [ ] , aggConfig , aggs ? , locals ? ) => { const output = { params : { } as Record < string , any > , } ; locals = locals || { } ; params . forEach ( ( param ) => { if ( param . write ) { param . write ( aggConfig , output , aggs , locals ) ; } else { if ( param && param . name ) { output . params [ param . name ] = aggConfig . params [ param . name ] ; } } } ) ; return output ; } ;