import { Datasource, DatasourceConnector, QueryType } from '../connectors'; import { connectorFactory } from '../connectors/connector_factory'; import { QueryService } from '../services/query_service/base'; import { queryServiceFactory } from '../services/query_service/query_service_factory'; export class QueryConfig { queryType: QueryType; datasource: Datasource; // TODO: Target type (depends on datasource type) targets: any[]; private _datasourceConnector?: DatasourceConnector; private _queryService?: QueryService; constructor(queryType: QueryType, datasource: Datasource, targets: any[]) { if(queryType === undefined) { throw new Error('queryType is undefined'); } if(datasource === undefined) { throw new Error('datasource is undefined'); } if(targets === undefined) { throw new Error('targets is undefined'); } this.queryType = queryType; this.datasource = datasource; this.targets = targets; } get datasourceConnector(): DatasourceConnector { if(this._datasourceConnector === undefined) { this._datasourceConnector = connectorFactory(this); } return this._datasourceConnector; } get queryService(): QueryService { if(this._queryService === undefined) { this._queryService = queryServiceFactory(this); } return this._queryService; } public toObject() { return { queryType: this.queryType, datasource: this.datasource, targets: this.targets, }; } static fromObject(obj: any): QueryConfig { if(obj === undefined) { throw new Error('obj is undefined'); } return new QueryConfig( obj.queryType, obj.datasource, obj.targets, ); } }