import { assignIn } from 'lodash' ; import { IMetricAggConfig } from '../metric_agg_type' ; param { AggConfig } agg param { object } props return { Constructor } export const getResponseAggConfigClass = ( agg , props ) => { if ( agg . $$_ResponseAggConfigClass ) { return agg . $$_ResponseAggConfigClass ; } else { return ( agg . $$_ResponseAggConfigClass = create ( agg , props ) ) ; } } ; export interface IResponseAggConfig extends IMetricAggConfig { key : string | number ; parentId : IMetricAggConfig [ 'id' ] ; } export const create = ( parentAgg , props ) => { param { string | number } key function ResponseAggConfig ( this , key ) { const parentId = parentAgg . id ; let id ; const subId = String ( key ) ; if ( subId . indexOf ( '.' ) > - 1 ) { id = parentId + "['" + subId . replace ( /'/g , "\\'" ) + "']" ; } else { id = parentId + '.' + subId ; } this . id = id ; this . key = key ; this . parentId = parentId ; } ResponseAggConfig . prototype = Object . create ( parentAgg ) ; ResponseAggConfig . prototype . constructor = ResponseAggConfig ; assignIn ( ResponseAggConfig . prototype , props ) ; return ResponseAggConfig ; } ;