import t from"@arcgis/core/request";import{getCache as e}from"./_requestCache.js";export class DefaultArcGISRequestHelper{ttl;batchLayerRequests;constructor(t){const e={ttl:1e4,batchLayerRequests:!0,...t};this.ttl=e.ttl,this.batchLayerRequests=e.batchLayerRequests}createSocket(t){return new WebSocket(t)}request(t,s){const{ttl:a}={ttl:this.ttl,...s};if(!e().has(t)){const r=this._doRequest(t,s);setTimeout((()=>{e().delete(t)}),a),e().set(t,r)}return e().get(t)}async _doRequest(s,a){const{batchLayerRequests:r,ttl:c,...i}={ttl:this.ttl,batchLayerRequests:this.batchLayerRequests,...a};try{const c=s.match(/\/MapServer\/(\d+)$/i);if(c&&2===c.length){const t=`${s.slice(0,s.length-c[1].length)}layers`;if(r||e().has(t)){const e=await this.request(t,a);if(e?.data){const t=parseInt(c[1]);if(e.data.layers){const s=e.data.layers.find((e=>e.id===t));if(s)return{data:s}}if(e.data.tables){const s=e.data.tables.find((e=>e.id===t));if(s)return{data:s}}}}}return await t(s,i)}catch(t){throw e().delete(s),t}}}