"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[2001],{"./public/app/plugins/datasource/mixed/module.ts":(e,s,r)=>{r.r(s),r.d(s,{Datasource:()=>m,MixedDatasource:()=>m});var t=r("./node_modules/lodash/lodash.js"),a=r("./node_modules/rxjs/dist/esm5/internal/observable/of.js"),o=r("./node_modules/rxjs/dist/esm5/internal/observable/from.js"),n=r("./node_modules/rxjs/dist/esm5/internal/observable/forkJoin.js"),d=r("./node_modules/rxjs/dist/esm5/internal/operators/mergeMap.js"),i=r("./node_modules/rxjs/dist/esm5/internal/operators/map.js"),u=r("./node_modules/rxjs/dist/esm5/internal/operators/catchError.js"),l=r("./node_modules/rxjs/dist/esm5/internal/operators/mergeAll.js"),c=r("./packages/grafana-data/src/index.ts"),p=r("./packages/grafana-runtime/src/index.ts");class m extends c.DataSourceApi{constructor(e){super(e)}query(e){const s=e.targets.filter((e=>"-- Mixed --"!==e.datasource));if(!s.length)return(0,a.of)({data:[]});const r=(0,t.groupBy)(s,"datasource"),o=[];for(const s in r){const t=r[s],a=t[0].datasource;o.push({datasource:(0,p.getDataSourceSrv)().get(a,e.scopedVars),targets:t})}return this.batchQueries(o,e)}batchQueries(e,s){const r=e.filter(this.isQueryable).map(((e,r)=>(0,o.Dp)(e.datasource).pipe((0,d.z)((n=>{const d=(0,t.cloneDeep)(s);return d.requestId=`mixed-${r}-${d.requestId||""}`,d.targets=e.targets,(0,o.Dp)(n.query(d)).pipe((0,i.U)((e=>Object.assign({},e,{data:e.data||[],state:c.LoadingState.Loading,key:`mixed-${r}-${e.key||""}`}))),(0,u.K)((e=>((e=(0,p.toDataQueryError)(e)).message=`${n.name}: ${e.message}`,(0,a.of)({data:[],state:c.LoadingState.Error,error:e,key:`mixed-${r}-${d.requestId||""}`})))))})))));return(0,n.D)(r).pipe((0,i.U)(this.finalizeResponses),(0,l.J)())}testDatasource(){return Promise.resolve({})}isQueryable(e){return e&&Array.isArray(e.targets)&&e.targets.length>0}finalizeResponses(e){const{length:s}=e;if(0===s)return e;const r=e.find((e=>e.state===c.LoadingState.Error));return r?e.push(r):e[s-1].state=c.LoadingState.Done,e}}}}]);
//# sourceMappingURL=mixedPlugin.8128b05ac04b15cbf98d.js.map