rozetko
2 years ago
16 changed files with 132 additions and 138 deletions
@ -0,0 +1,45 @@
|
||||
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, |
||||
); |
||||
} |
||||
} |
Loading…
Reference in new issue