"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("lodash");class o{static replaceURLVariables(e,n){try{const t=e.match(/\${(.*?)}/g);if(t)for(let a=0;a<t.length;a++){const r=t[a].substring(2,t[a].length-1),i=o.extractVariableName(r),s=n.find(l=>l.name===i);if(!s)continue;const c=o.getNestedValue(s._value,r.substring(i.length));e=e.replaceAll(t[a],c)}return e}catch{return e}}static replaceObjectVariables(e,n){try{let t=JSON.stringify(e);const a=t.match(/\$g{(.*?)}/g);if(a){for(let r=0;r<a.length;r++){const i=a[r].substring(3,a[r].length-1),s=this.extractVariableName(i),c=n.find(u=>u.name===s);if(!c)continue;const l=this.getNestedValue(c._value,i.substring(s.length));t=t.replaceAll(a[r],l)}return JSON.parse(t)}return e}catch{return e}}static replaceStringVariables(e,n){try{const t=e.match(/\$g{(.*?)}/g);if(t)for(let a=0;a<t.length;a++){const r=t[a].substring(3,t[a].length-1),i=this.extractVariableName(r),s=n.find(l=>l.name===i);if(!s)continue;const c=this.getNestedValue(s._value,r.substring(i.length));e=e.replaceAll(t[a],c)}return e}catch{return e}}static replaceEnvVariables(e,n){try{let t="";if(!e.includes("http")&&n){const a=n.filter(r=>r.selected);a&&g.isArray(a)&&a.length>0&&(t=a[0].envBaseUrl||"")}return t}catch{return""}}static noneData(e){return{id:e,finalKeyData:[],finalUserData:{id:e,data:[]},filteredData:[],rawData:[],noMappingData:[]}}static getEnvironments(){let e=sessionStorage.getItem("currentApiEnvironments");return e&&(e=JSON.parse(e)),e}static setEnvironments(e){sessionStorage.setItem("currentApiEnvironments",JSON.stringify(e))}static getVariableData(){let e=sessionStorage.getItem("currentVariableData");return e&&(e=JSON.parse(e)),e}static setVariableData(e){sessionStorage.setItem("currentVariableData",JSON.stringify(e))}static hasValidWebSocket(e,n,t){const a=e.get(n);if(!a)return!1;for(const r of a)if(r.getId()===t&&r.isConnected())return!0;return!1}static cleanupPreviousWebSockets(e,n,t){const a=e.get(t);a&&(a.forEach(r=>{n.includes(r.getId())||(r.disconnect(),a.delete(r))}),a.size===0&&e.delete(t))}static getNestedValue(e,n){try{return new Function("obj",`return obj${n}`)(e)}catch{return}}static extractVariableName(e){const n=e.match(/^([\u4e00-\u9fa5a-zA-Z0-9_][\u4e00-\u9fa5a-zA-Z0-9_]*)/);return n?n[1]:""}}exports.DataSourceUtils=o;
