(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[5813],{75813:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>f});var s=a(68584),r=a(46377),n=a(66885),u=a(6434),o=a(2401),i=a.n(o);class f extends r.BaseFeatureDataAdapter{constructor(e,t,a){super(e,t,a),this.endpoint=(0,s.readConfObject)(e,"endpoint").uri,this.queryTemplate=(0,s.readConfObject)(e,"queryTemplate"),this.additionalQueryParams=(0,s.readConfObject)(e,"additionalQueryParams"),this.refNamesQueryTemplate=(0,s.readConfObject)(e,"refNamesQueryTemplate"),this.configRefNames=(0,s.readConfObject)(e,"refNames")}async getRefNames(e){if(this.refNames)return this.refNames;if(this.refNamesQueryTemplate){const t=encodeURIComponent(this.refNamesQueryTemplate),a=await this.querySparql(t,e);this.refNames=this.resultsToRefNames(a)}else this.refNames=this.configRefNames;return this.refNames}getFeatures(e,t={}){return(0,n.ObservableCreate)((async a=>{const s=encodeURIComponent(i()(this.queryTemplate,e)),{refName:r}=e,n=await this.querySparql(s,t),u=this.resultsToFeatures(n,r);for(const e of u)a.next(e);a.complete()}),t.stopToken)}async querySparql(e,t){let a="";this.additionalQueryParams.length&&(a=`&${this.additionalQueryParams.join("&")}`);const s=`${this.endpoint}?query=${e}${a}`;return(await fetch(s,{headers:{accept:"application/json,application/sparql-results+json"}})).json()}resultsToRefNames(e){const t=e.results.bindings||[];if(!e.head.vars.includes("refName"))throw new Error('"refName" not found in refNamesQueryTemplate response');return t.map((e=>e.refName.value))}resultsToFeatures(e,t){const a=e.results.bindings||[],s=e.head.vars;["start","end","uniqueId"].forEach((e=>{s.includes(e)||console.error(`Required field ${e} missing from feature data`)}));const r={};a.forEach((e=>{const a=[{}];s.forEach((t=>{if(t in e){const{value:s}=e[t];let r=0;for(;t.startsWith("sub_");)t=t.slice(4),r+=1;for(;r>a.length-1;)a.push({});a[r][t]=s}})),a.forEach(((e,s)=>{const{uniqueId:n,start:u,end:o,strand:i}=e;s<a.length-1&&(a[s+1].parentUniqueId=n),r[n]={data:{...e,uniqueId:n,refName:t,start:Number.parseInt(u,10),end:Number.parseInt(o,10),strand:Number.parseInt(i,10)||0}}}))}));for(const[e,t]of Object.entries(r)){const a=t.data.parentUniqueId;if(t.data.parentUniqueId=void 0,a){const s=r[a];if(s)s.data.subfeatures||(s.data.subfeatures=[]),s.data.subfeatures.push({...t.data,uniqueId:e}),delete r[e];else{const s=Object.values(r).map((e=>e.data.subfeatures)).filter((e=>!!e)).flat();let n=!1;for(const u of s){if(u.uniqueId===a){u.subfeatures||(u.subfeatures=[]),u.subfeatures.push({...t.data,uniqueId:e}),delete r[e],n=!0;break}u.subfeatures&&s.push(...u.subfeatures)}n||console.error(`Could not find parentID ${a}`)}}}return Object.keys(r).map((e=>new u.A({...r[e].data,uniqueId:e,subfeatures:r[e].data.subfeatures})))}async hasDataForRefName(e,t={}){const a=await this.getRefNames(t);return!(a.length&&!a.includes(e))}freeResources(){}}},2401:e=>{var t=/\{([0-9a-zA-Z_]+)\}/g;e.exports=function(e){var a;if(2===arguments.length&&"object"==typeof arguments[1])a=arguments[1];else{a=new Array(arguments.length-1);for(var s=1;s<arguments.length;++s)a[s-1]=arguments[s]}return a&&a.hasOwnProperty||(a={}),e.replace(t,(function(t,s,r){var n;return"{"===e[r-1]&&"}"===e[r+t.length]?s:null==(n=a.hasOwnProperty(s)?a[s]:null)?"":n}))}}}]);
//# sourceMappingURL=5813.627f33ab.chunk.js.map