import { Datasource, DatasourceConnector } from '../metrics/metric'; import { connectorFactory } from '../metrics/metrics_factory'; export class QueryConfig { datasource: Datasource; // TODO: Target type (depends on datasource type) targets: any[]; private _datasourceConnector?: DatasourceConnector; constructor(datasource: Datasource, targets: any[]) { if(datasource === undefined) { throw new Error('datasource is undefined'); } if(targets === undefined) { throw new Error('targets is undefined'); } this.datasource = datasource; this.targets = targets; } get datasourceConnector(): DatasourceConnector { if(this._datasourceConnector === undefined) { this._datasourceConnector = connectorFactory(this); } return this._datasourceConnector; } public toObject() { return { datasource: this.datasource, targets: this.targets, }; } static fromObject(obj: any): QueryConfig { if(obj === undefined) { throw new Error('obj is undefined'); } return new QueryConfig( obj.datasource, obj.targets, ); } }