import _ , { defaults } from 'lodash' ; import { AggGroupNames , AggParam } from '../../../data/public' ; import type { ISchemas , Schema } from './types' ; private export class Schemas implements ISchemas { all : Schema [ ] = [ ] ; [ AggGroupNames . Buckets ] : Schema [ ] = [ ] ; [ AggGroupNames . Metrics ] : Schema [ ] = [ ] ; constructor ( schemas ) { _ ( schemas || [ ] ) . chain ( ) . map ( ( schema ) => { if ( ! schema . name ) throw new Error ( 'all schema must have a unique name' ) ; if ( schema . name === 'split' ) { schema . params = [ { name : 'row' , default : true , } , ] as AggParam [ ] ; } defaults ( schema , { min : 0 , max : Infinity , group : AggGroupNames . Buckets , title : schema . name , aggFilter : '*' , params : [ ] , } ) ; return schema as Schema ; } ) . tap ( ( fullSchemas ) => { this . all = fullSchemas ; } ) . groupBy ( 'group' ) . forOwn ( ( group , groupName ) => { this [ groupName ] = group ; } ) . commit ( ) ; } }