import { MetricName } from '.' ; import MetricQueries , { MetricQuery } from './metricQueries' ; export class MetricQueryBuilder { private queryObj : MetricQuery ; private queries : MetricQueries ; constructor ( queries , query ? ) { this . queries = queries ; this . queryObj = query || { metric : '' , filters : [ ] , groupBy : [ ] , orderBy : [ ] } ; } public metric ( metric ) { return this . extendQuery_ ( { metric } ) ; } public between ( start , end ) { return this . extendQuery_ ( { start , end } ) ; } public interval ( interval ) { return this . extendQuery_ ( { interval } ) ; } public filter ( name , operator , value ) { return this . extendQuery_ ( { filters : [ ... this . queryObj . filters , { name , operator , value } ] } ) ; } public groupBy ( dimension ) { return this . extendQuery_ ( { groupBy : [ ... this . queryObj . groupBy , dimension ] } ) ; } public orderBy ( name , order ) { return this . extendQuery_ ( { orderBy : [ ... this . queryObj . orderBy , { name , order } ] } ) ; } public percentile_ ( percentile ) { return this . extendQuery_ ( { percentile } ) ; } public licenseKey ( licenseKey ) { return this . extendQuery_ ( { licenseKey } ) ; } public limit ( limit ) { return this . extendQuery_ ( { limit } ) ; } public offset ( offset ) { return this . extendQuery_ ( { offset } ) ; } public async ( async ) { return this . extendQuery_ ( { async } ) ; } public jobId ( jobId ) { return this . extendQuery_ ( { jobId } ) ; } public cursor ( cursor ) { return this . extendQuery_ ( { cursor } ) ; } public extendQuery_ ( extensions ) { return new MetricQueryBuilder ( this . queries , { ... this . queryObj , ... extensions } ) ; } public query ( ) { return this . queries . metric ( this . queryObj ) ; } public queryObject ( ) { return this . queryObj ; } }