UNPKG

forestdb

Version:

An uncomplicated real-time database with encrypted HTTP and WebSocket server-client communication, fast caching, state management, a cross-runtime file system manager, and more, working seamlessly on both frontend and backend.

7 lines 218 kB
var xr=Object.defineProperty;var z=(l,o)=>xr(l,"name",{value:o,configurable:!0});var Pt=32,mr=z(l=>/^[a-zA-Z0-9]+$/.test(l.pkey),"isKeyValidFunc"),wt=z(l=>{let o=new Uint8Array(l.data),t="";for(let c=0;c<o.length;c++){let e=o[c].toString(16).padStart(2,"0");t+=e}return t},"bufferToHexFunc"),Ge=z(l=>{let o=l.data,t=o.length,c=new Uint8Array(t/2);for(let e=0;e<t;e+=2)c[e/2]=parseInt(o.substr(e,2),16);return c},"hexToBufferFunc"),xt=z(l=>{let o=l.data,t=o.length,c=0,e=Math.ceil(t/8);c=e<5?5:e;let n=[];for(let a=0;a<t;a+=c)n.push(o.slice(a,a+c));return String(n.length)+String(n.length>1?n.join("-"):n[0])},"cipherStringToChunksFunc"),br=z(l=>{let o=l.data,t=l.key,c=l.iv,e=l.authTag,n=l.ignoreKey,s=o.split("").reverse().join(""),a=xt({data:s}),i="";if(!n){let r=t.split("").reverse().join("");i=xt({data:r})}let f=c.split("").reverse().join(""),d=xt({data:f}),b=e.split("").reverse().join(""),E=xt({data:b});return(n?[d,E,a]:[d,E,a,i]).join("-")},"L2_cipherMixerFunc"),vr=z(l=>{let o=l.data,t=o.split("-"),c=l.ignoreKey,e=parseInt(o[0]),s=t.splice(0,e).join("").slice(1).split("").reverse().join("");o=t.join("-"),t=o.split("-");let a=parseInt(o[0]),f=t.splice(0,a).join("").slice(1).split("").reverse().join("");o=t.join("-"),t=o.split("-");let d=parseInt(o[0]),E=t.splice(0,d).join("").slice(1).split("").reverse().join("");o=t.join("-"),t=o.split("-");let p="";if(!c){let h=parseInt(o[0]);p=t.splice(0,h).join("").slice(1).split("").reverse().join("")}return{data:E,key:p,iv:s,authTag:f}},"L2_cipherDemixerFunc"),Yr=z(async l=>{let o=l.data,t=new TextEncoder().encode(o),c=await crypto.subtle.digest("SHA-256",t);return Array.from(new Uint8Array(c)).map(s=>s.toString(16).padStart(2,"0")).join("")},"web_createHashFunc"),Dr=z(async()=>await crypto.subtle.generateKey({name:"AES-GCM",length:128},!0,["encrypt","decrypt"]),"web_generateKeyFunc"),Or=z(async l=>{try{if(typeof l.data!="string")throw new Error("Data to encrypt is not a string");let o=l.data,t=l.privateKey??void 0;if(t!==void 0&&typeof t!="string")throw new Error(`Invalid key "${t}"`);if(typeof t=="string"){if(t.length!==Pt)throw new Error(`Invalid key length "${t.length}" - The valid key length is "${Pt}"`);if(!mr({pkey:t}))throw new Error}let c=new TextEncoder,e=t!==void 0?Ge({data:t}):void 0,n=e!==void 0?await crypto.subtle.importKey("raw",e,{name:"AES-GCM"},!0,["encrypt","decrypt"]):await Dr(),s=crypto.getRandomValues(new Uint8Array(12)),a=128,i=c.encode(o),f=await crypto.subtle.encrypt({name:"AES-GCM",iv:s,tagLength:a},n,i),d=16,b=new Uint8Array(f),E=b.length-d,p=b.slice(E),h=await crypto.subtle.exportKey("raw",n),r=f.slice(0,E),I=wt({data:r}),T=wt({data:h}),v=wt({data:s}),u=wt({data:p});return{status:"success",log:"",data:br({data:I,key:T,iv:v,authTag:u,ignoreKey:e!==void 0})}}catch(o){return{status:"error",log:o.message,data:o.message}}},"web_cipherFunc"),Sr=z(async l=>{try{if(typeof l.data!="string")throw new Error("Data to decrypt is not a string");let o=l.privateKey??void 0;if(o!==void 0&&typeof o!="string")throw new Error(`Invalid key "${o}"`);let t=vr({data:l.data,ignoreKey:o!==void 0}),c=t.data,e=o!==void 0?o:t.key,n=t.iv,s=t.authTag,a=Ge({data:c+s}),i=Ge({data:e}),f=Ge({data:n}),d=await crypto.subtle.importKey("raw",i,"AES-GCM",!0,["decrypt"]),b=await crypto.subtle.decrypt({name:"AES-GCM",iv:f,tagLength:128},d,a);return{status:"success",log:"",data:new TextDecoder().decode(b)}}catch(o){return{status:"error",log:o,data:o}}},"web_decipherFunc"),$r="aes-128-gcm",Mr=z(async l=>{let t=l.api.createHash("sha256");return t.update(l.data),t.digest("hex")},"crypto_createHashFunc"),Nr=z(l=>{try{if(typeof l.data!="string")throw new Error("Data to encrypt is not a string");let o=l.privateKey||void 0;if(o!==void 0&&typeof o!="string")throw new Error(`Invalid key "${o}"`);if(typeof o=="string"){if(o.length!==Pt)throw new Error(`Invalid key length "${o.length}" - The valid key length is "${Pt}"`);if(!mr({pkey:o}))throw new Error}let t=l.data,c=l.api,e=o!==void 0?Ge({data:o}):c.randomBytes(16),n=c.randomBytes(12),s=c.createCipheriv($r,e,n),a=s.update(t,"utf8","hex");a+=s.final("hex");let i=s.getAuthTag().toString("hex"),f=wt({data:e}),d=wt({data:n});return{status:"success",data:br({data:a,key:f,iv:d,authTag:i,ignoreKey:o!==void 0})}}catch(o){return{status:"error",data:o.message}}},"crypto_cipherFunc"),Pr=z(l=>{try{if(typeof l.data!="string")throw new Error("Data to decrypt is not a string");let o=l.privateKey;if(o!==void 0&&typeof o!="string")throw new Error(`Invalid key "${o}"`);let t=vr({data:l.data,ignoreKey:o!==void 0}),c=l.api,e=t.data,n=Ge(o!==void 0?{data:o}:{data:t.key}),s=Ge({data:t.iv}),a=Ge({data:t.authTag}),i=c.createSecretKey(n),f=c.createDecipheriv($r,i,s);f.setAuthTag(a);let d=f.update(e,"hex","utf8");return d+=f.final("utf8"),{status:"success",data:o!==void 0?d:JSON.parse(d)}}catch(o){return{status:"error",data:o.message}}},"crypto_decipherFunc"),Br=!1,Rr=["string","number","boolean","object","undefined"],Lr=["_$$type","_$$isMutation","_$$isCondition","_$$default"],ke={current:["YYYY_MM_DD","MM_DD_YYYY","DD_MM_YYYY"]},ot={json:{headers:{"Content-type":"application/json","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":"Content-Type"}},file:{headers:{"Content-type":"multipart/form-data","Access-Control-Allow-Origin":"*","Access-Control-Allow-Methods":"POST","Access-Control-Allow-Headers":"Content-Type"}}},or=32,Bt=100,ar=200,xn=1*1024*1024,Yn=1*1024*1024,Rt=35,Kt=300,zr=2e3,_t="forest",Lt="butterfly",Jr="0.0.0.0",Kr=3e4,kr="static",Ur=256,Er=["Deno","Node","Bun"],jr=["Browser","React_native"],Hr="./forest",Ie={initialization_failed:"initialization_failed",max_tree_name_length_exceeded:"max_tree_name_length_exceeded",not_branch_specified:"not_branch_specified",empty_json_data:"empty_json_data",transaction_failed:"transaction_failed",feed_update_failed:"feed_update_failed",request_failed:"request_failed",phantom_tree:"phantom_tree",phantom_branch:"phantom_branch",phantom_feed:"phantom_feed",corrupted_chain:"corrupted_chain",corrupted_condition:"corrupted_condition",invalid_path:"invalid_path",invalid_tree_name:"invalid_tree_name",invalid_tree_name_length:"invalid_tree_name_length",invalid_tree_options:"invalid_tree_options",invalid_argument:"invalid_argument",invalid_chain:"invalid_chain",invalid_date:"invalid_date",invalid_mutation:"invalid_mutation",invalid_mutation_path:"invalid_mutation_path",invalid_json_path:"invalid_json_path",invalid_condition:"invalid_condition",invalid_condition_operator:"invalid_condition_operator",invalid_condition_path:"invalid_condition_path",invalid_condition_value:"invalid_condition_value",invalid_value_type:"invalid_value_type",invalid_target_value_type:"invalid_target_value_type",unmatched_type:"unmatched_type",unmatched_condition:"unmatched_condition",unmatched_condition_type:"unmatched_condition_type",tree_not_found:"tree_not_found",no_tree_found:"no_tree_found",branch_not_found:"branch_not_found",feed_not_found:"feed_not_found",incorrect_data_type:"incorrect_data_type",incorrect_branch_name:"incorrect_branch_name",nested_mutation_found:"nested_mutation_found",nested_condition_found:"nested_condition_found"},At={config:{mainKey:"id",dateFormat:["YYYY_MM_DD","MM_DD_YYYY"]}},Z={current:void 0},te={current:void 0},ft={current:Hr},ut={current:void 0},sr={current:void 0},Ze={current:{rate:2*1024*1024,ms:60}},Me={current:void 0},Xt={enable:!1},Ut={enable:!1},tr={value:void 0},zt={},_e={},et={},Te={},Qe={},gt={},It={},bt={},Et={},nt={},rr={},Je={},Ve={},kt={},St={},Ht={hasInit:!1,isLoadingSchema:!1,runtime:void 0,wstate:{status:"close",log:"WebSocket is off"}},me={},le={},oe={},mt={set:{},update:{},delete:{}},Ye={},Le={id:{},family:{}},Pe={},je={},ze={},at={},er={},ce={id:"",oldSessionId:"",runtime:void 0,runtimeType:"client",fsEnable:!1,cryptoEnable:!1},Be={},Ke=z((...l)=>{Br&&console.log(...l)},"logFunc"),He=z((...l)=>{console.log(...l)},"plog"),Ue=z(l=>{let o=l?.noTmp??!0,t="0aW9zXe8CrVt1By5NuA46iZ3oEpRmTlYkUjIhOgPfMdQsSqDwFxGcHvJbKnL",c=l?.length!==void 0?l.length:t.length,e=String(new Date().getTime()),n="";for(let s=0;s<c;s++)n+=t.charAt(Math.floor(Math.random()*36));return n=o?n:n+e,n},"generateIdFunc"),We=z(l=>l.acceptSpecial?/^[a-zA-Z0-9_-]+$/.test(l.value):/^[a-zA-Z0-9]+$/.test(l.value),"isAlphanumericFunc"),de=z(l=>l.operation<0?0:l.operation,"keepPositiveFunc"),Ee=z(l=>new Promise(o=>setTimeout(o,l?.ms||.5)),"delayFunc"),Ae=z(l=>{let o=l.object,t=typeof o;return t!=="object"?"undefined":t===null?"null":Array.isArray(o)?"array":"json"},"getObjectTypeFunc"),ae=z(l=>{let o=l.treeName,t=l.status,c=l.type,e=l.value,n=l.transactionId,s=l.joinId,a=l.skipCommit||!1,i=new Date().toISOString(),f=`[${t}][${c}][${i}][GTID -> '${n}'][JID -> '${s??null}'] :: [${e}]; `;return a||(typeof kt[o]!="string"&&(kt[o]=""),kt[o]=kt[o]+f,typeof St[o]!="object"&&(St[o]={}),St[o][n]=n),f},"setLogFunc"),Wr=z(l=>{let o=l.input,t=l.maxDepth||Rt,c=z(e=>{let n=typeof e.value=="object"?e.value:void 0,s=e.currentDepth;if(s>t)return!0;if(n&&(typeof n=="object"||Array.isArray(n))){for(let a in n)if(c({value:n[a],currentDepth:s+1}))return!0}return!1},"recurse");return c({value:o,currentDepth:1})},"checkMaxNestedObjFunc"),_r=z(l=>{let o=l.check,t=l.obj;if(typeof t=="object"&&t!==null){let c=t,e=!1;if((o==="all"&&(tt({obj:c})||st({obj:c}))||o==="mutation"&&tt({obj:c})||o==="condition"&&st({obj:c}))&&(e=!0),e)return!0;{let n=Object.keys(c);for(let s=0;s<n.length;s++){let a=n[s],i=c[a];if(typeof i=="object"&&_r({check:o,obj:i}))return!0}return!1}}else return!1},"hasMutationOrConditionFunc"),N=z((l,o)=>{let t=typeof l=="object"&&l!==null?l:{};return Object.prototype.hasOwnProperty.call(t,o)},"hasPropertyFunc"),G=z(l=>{try{let o=typeof l.obj=="object"&&l.obj!==null,t=l.obj,c=l.useLoop??!1,e={};if(o){if(!c)e=structuredClone(t);else{e=[];for(let n=0;n<t.length;n++){let s=structuredClone(t[n]);e.push(s)}}return e}return Array.isArray(l.obj)?[]:{}}catch(o){return He("Clonning failed !"),{status:"error",log:o.message,data:void 0}}},"cloneObjFunc"),tt=z(l=>!!(typeof l.obj=="object"&&!Array.isArray(l.obj)&&l.obj!==null&&N(l.obj,"_$$isMutation")),"isMutationFunc"),st=z(l=>!!(typeof l.obj=="object"&&!Array.isArray(l.obj)&&l.obj!==null&&N(l.obj,"_$$isCondition")),"isConditionFunc"),$e=z(l=>isFinite(Number(l.value)),"isNumericFunc"),ct=z(l=>l.arr.flat(),"mergeNestedArrayFunc"),lt=z(l=>{let o=l.arr,t=l.maxLevel||2;if(!Array.isArray(o))return-1;let c=1;for(let e of o)if(Array.isArray(e)){let n=lt({arr:e,maxLevel:t});if(n===-1||(c=Math.max(c,n+1),c>t))return-1}return c},"getArrayDepthFunc"),q=z(l=>{let o=l.keepSpaces??!1,t=l.value.normalize("NFD").replace(/[\u0300-\u036f]/g,""),c=l.lowerCase?t.toLocaleLowerCase():t;return l.keepSpaces&&c.replaceAll(" ",""),c},"removeAccentFunc"),qr={1:31,2:28,3:31,4:30,5:31,6:30,7:31,8:31,9:30,10:31,11:30,12:31},Vr=z(l=>{let o=l.month,t=l.year;return o===2&&t%4===0&&(t%100!==0||t%400===0)?29:qr[o]},"getDaysInMonthFunc"),xe=z(l=>(l.value.match(/\b\w+\b/g)||[]).length,"getWordCountFunc"),vt=z(l=>{let o=Array.isArray(l.path)?l.path.join("."):l.path,t=l.value,c=o.split(".").reverse(),e=c.length,n=Array(e).fill(void 0).map(()=>({}));for(let s=0;s<e;s++){let a=c[s];s===0?n[s][a]=t:n[s][a]=n[s-1]}return n[e-1]},"buildJsonFromPathFunc"),Se=z(l=>{let o=Array.isArray(l.path)?l.path.join("."):l.path,t=l.firstKey||void 0,c=l.sourceObj||void 0,e=l.asJson??!1,n="";try{let s=o.split("."),a="short",f=G({obj:s}).join(".");a=f[0]==="#"?"long":"short";let d={},b=[];if(a==="short"){let r=Ae({object:c});if(c===void 0||r!=="json")throw n=n+"Invalid source",new Error;t!==void 0&&s[0]!==t&&(s=[t,...s]),d=G({obj:c}),b=s}else{let r=s[0].replace("#","");if(!N(Te,r))throw n=n+`The feed "${r}" doesn't exists`,new Error(n);d=G({obj:Te[r]}),b=f.replace("#","").split(".")}let E=s.length,p={current:void 0},h=!1;for(let r=0;r<E&&!h;r++){let I=s[r],T=p.current!==void 0,v=$e({value:p.current}),u=r===E-2,Y=r===E-1;if(!v&&!N(T?p.current:d,I))throw n=n+`The path "${o}" doesn't exists`,new Error(n);p.current!==void 0&&(N(p.current,I)||(p.current[I]={})),p.current=T?p.current[I]:d[I]}return e&&(p.current=vt({path:b,value:p.current})),{status:"success",log:n,data:p.current}}catch(s){return{status:"error",log:s.message,data:void 0}}},"resolvePathFunc"),Wt=z(l=>(l.value.match(/\d+/g)||[]).map(Number),"extractNumberFunc"),Ar=z(l=>{let o=l.value.matchAll(/\d+/g),t=[];return o.forEach(c=>{t.push({index:c.index,value:c[0]})}),t},"extractNumberIndexFunc"),pe=z((l,o)=>{let t=l;if(o!==void 0){let s=l.point,a=o.point;t=s>=a?l:o}let c=[],e="";return t.hasDate&&(c.push("YYYY","MM","DD"),e=e+"YYYY-MM-DD"),t.hasTime&&(c.push("HH","mm"),e=e+"THH:mm"),t.hasSec&&(c.push("ss"),e=e+":ss"),t.hasMilli&&(c.push("sss"),e=e+".sss"),t.hasUTCHour?(c.push("+HH"),e=e+"++HH"):e=e+"Z",t.hasUTCMin&&(c.push("+mm"),e=e+":+mm"),{proto:c,fullDate:e}},"buildDateTemplateFunc"),Qr=z(l=>{let o=l.value,t=l.format,c=l.template||void 0,e=l.extractModel||!1,n=!!(c!==void 0||e),s="",a={hasDate:!1,hasTime:!1,hasSec:!1,hasMilli:!1,hasUTCHour:!1,hasUTCMin:!1,point:0};try{if(!n&&typeof o=="number"){let Y=String(o).length;return Y===10?o*1e3:Y===13?o:Y>13&&Y<=16?Math.floor(o/10**(Y-13)):-1}n&&typeof o=="number"&&(o=new Date(o).toISOString());let i=n?o:String(o.replaceAll(" ","")),f=Wt({value:i});if(f.length<3||f.length===4)throw s=s+`invalid date "${i}"`,new Error(s);let d=f.splice(0,3),b=[t==="DD_MM_YYYY"||t==="MM_DD_YYYY"?d[2]:t==="YYYY_MM_DD"?d[0]:-1,t==="DD_MM_YYYY"?d[1]:t==="MM_DD_YYYY"?d[0]:t==="YYYY_MM_DD"?d[1]:-1,t==="DD_MM_YYYY"?d[0]:t==="MM_DD_YYYY"?d[1]:t==="YYYY_MM_DD"?d[2]:-1],E=[];if(i.includes(":")){let Y=i.lastIndexOf("+")||i.lastIndexOf("Z")||i.lastIndexOf("z")||-1,R=i.match(/:/g)||[];if(R.length>3||R.length<1)throw s=s+`invalid date "${i}"`,new Error(s);let B=i.indexOf(":")-2,F=Y!==-1?i.slice(B,Y):i.slice(B),H=Wt({value:F}),S=H.length;if(S===0)throw s=s+`invalid date "${i}"`,new Error(s);E=[H[0],S===1?0:H[1]],H[2]!==void 0&&E.push(S<=2?0:H[2]),H[3]!==void 0&&E.push(S===3?0:H[3])}let p=[];if(i.includes("+")){let Y=i.lastIndexOf("+"),R=i.slice(Y),B=Wt({value:R}),F=B.length;if(F===0)throw s=s+`invalid date "${i}"`,new Error(s);p=[B[0]],B[1]!==void 0&&E.push(F===1?0:B[1])}f=[...b,...E,...p];let h=c?.proto||["YYYY","MM","DD","HH","mm","ss","sss","+HH","+mm"],r=c?.fullDate||"YYYY-MM-DDTHH:mm:ss.sss++HH:+mm";for(let Y=0;Y<h.length;Y++){let R=h[Y],B=f[Y]??-1,F=B===-1?f[Y]:B;switch(R){case"YYYY":{if(String(B).length<4||B===-1)throw s=s+`invalid year "${F}"`,new Error(s);r=r.replace("YYYY",String(B)),a.hasDate=!0}break;case"MM":{if(B<1||B>12||B===-1)throw s=s+`invalid month "${F}"`,new Error(s);r=r.replace("MM",String(B).padStart(2,"0"))}break;case"DD":{let H=Vr({month:f[1],year:f[0]});if(B<1||B>H||B===-1)throw s=s+`invalid date "${F}", the range should be from 1 to "${H}"`,new Error(s);r=r.replace("DD",String(B).padStart(2,"0"))}break;case"HH":{if((B<0||B>23)&&B!==-1)throw s=s+`invalid hour "${F}"`,new Error(s);let H=B!==-1;r=r.replace("HH",H?String(B).padStart(2,"0"):"00"),a.hasTime=!!H}break;case"mm":{if((B<0||B>59)&&B!==-1)throw s=s+`invalid minute "${F}"`,new Error(s);r=r.replace("mm",B===-1?"00":String(B).padStart(2,"0"))}break;case"ss":{if((B<0||B>59)&&B!==-1)throw s=s+`invalid seconds "${F}"`,new Error(s);let H=B!==-1;r=r.replace("ss",H?String(B).padStart(2,"0"):"00"),a.hasSec=!!H}break;case"sss":{if((B<0||B>999)&&B!==-1)throw s=s+`invalid seconds "${F}"`,new Error(s);let H=B!==-1;r=r.replace("sss",H?String(B).padStart(3,"0"):"000"),a.hasMilli=!!H}break;case"+HH":{let H=B!==-1;if(!H){r=r.replace("++HH:+mm","Z");break}if(B<0||B>23)throw s=s+`invalid UTC hour "${F}"`,new Error(s);r=r.replace("+HH",String(B).padStart(2,"0")),a.hasUTCHour=!!H}break;case"+mm":{if((B<0||B>59)&&B!==-1)throw s=s+`invalid seconds "${F}"`,new Error(s);let H=B!==-1;r=r.replace("+mm",H?String(B).padStart(2,"0"):"00"),a.hasUTCMin=!!H}break;default:throw s=s+`unknown date parameter "${R}"`,new Error(s)}}let T=Object.values(a).filter(Y=>Y===!0);a.point=T.length;let v=new Date(r),u=isNaN(v.getTime())?-1:v.getTime();return e?{tmp:u,model:a}:u}catch(i){return Ke('err "tmpExtractorFunc" fail ::',i.message),-1}},"tmpExtractorFunc"),J=z(l=>{let o=l.value,t=l.dateFormat!==void 0?G({obj:l.dateFormat}):G({obj:ke.current}),c=-1;for(let e=0;e<t.length;e++){let n=t[e],s=Qr({value:o,format:n,template:l.template,extractModel:l.extractModel});if(c=s,s!==-1)break}return c},"extractTimestampFunc"),ir=z(l=>{let o=l.value,t=l.format,c="",e;try{for(let s=0;s<o.length;s++){let a=o[s];if(Array.isArray(a)){let i=a;for(let f=0;f<a.length;f++){let d=i[f];e=d;let b=J({value:d,dateFormat:t});if(b===-1)throw c=c+`The date "${d}" doesn't respect provided date format "[${ke.current}]"`,new Error(c);i[f]=b}o[s]=i.sort((f,d)=>f-d)}else e=a,o[s]=J({value:a,dateFormat:t})}return ct({arr:o}).includes(-1)?{status:"error",log:c,data:e}:{status:"success",log:c,data:o}}catch{return{status:"error",log:c,data:e}}},"transformIntoTimestampFunc"),Fe=z(l=>{let o=l.target,t=l.data,c=Ae({object:o}),e=Ae({object:t});if(c!=="json"||e!=="json")return t;for(let n in t)if(N(t,n)){let s=Ae({object:o[n]}),a=Ae({object:t[n]});n in o&&s==="json"&&a==="json"?o[n]=Fe({target:o[n],data:t[n]}):o[n]=t[n]}return o},"mergeObjFunc"),Zr=z(l=>{let o=Array.isArray(l.path)?l.path.join("."):l.path,t=l.target,c=l.firstkey,e=o.split("."),n={status:"success",log:"",data:void 0};try{c!==void 0&&e[0]!==c&&(e=[c,...e]);let s=e.length,a={};for(let i=0;i<s;i++){let f=e[i],d=i===0?t:a;if(!N(d,f))throw n.status="error",new Error(`Path "${f}" not found`);if(a=d[f],i===s-2){let b=e[i+1];delete a[b];break}}n.data=t}catch(s){n.log=s.message}return n},"deleteJsonFieldFunc"),Gr=z(l=>{try{let o=l.url;if(o.includes("://")){let e=new URL(o);return{protocol:e.protocol.replace(":",""),hostname:e.hostname,port:e.port||void 0}}let[t,c]=o.split(":");return{protocol:void 0,hostname:t,port:c||void 0}}catch{return}},"parseUrlFunc"),qe=z(l=>{let o={status:"success",log:"",data:void 0},t={};try{let c=l.data;for(let e in c){let n=c[e],s=l.ktab?[...l.ktab]:[];if(Ae({object:n})==="json"){s.push(e);let i=qe({data:n,ktab:s});Fe({target:t,data:i.data})}else{s.push(e);let i=s.join(".");t[i]=c[e]}}o.data=t}catch(c){o.status="error",o.log=c.message}return o},"topLevelJsonFunc"),nr=z(l=>{let o={status:"success",log:"",data:void 0};try{let t=l.obj,e=l.clone??!1?G({obj:t}):t,n=Object.keys(e);for(let s=0;s<n.length;s++){let a=n[s];if(e[a]===void 0){delete e[a];continue}let i=e[a];typeof i=="object"&&i!==null&&nr({obj:i,clone:!1,recursive:!0})}}catch(t){o.status="error",o.log=t.message}return o},"removeUndefinedValuesFunc"),ht=z(l=>{let o=l.oldPath.replace(/[\\/]/g,"/"),t=o.lastIndexOf("/");return t===-1?l.newName:o.slice(0,t+1)+l.newName},"getNewPathFunc"),Xr=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=Me.current==="Node";if(typeof l!="string")throw new Error("The value to hash is not a string");if(t&&ut.current===void 0)throw new Error("Unable to find crypto's API");let c=t?await Mr({data:l,api:ut.current}):await Yr({data:l});o.data=c}catch(t){o.status="error",o.log=t.message}return o},"createHashFunc"),Tt=z(async l=>{let o={status:"success",log:"",data:void 0};try{if(ce.cryptoEnable){let t=tr.value||void 0,c=ut.current!==void 0&&ce.runtime==="Node"?Nr({data:l.data,api:ut.current,privateKey:t}):await Or({data:l.data,privateKey:t});if(c.status!=="success")throw new Error("Encryption failed");o.data=c.data}return o}catch(t){o.status="error",o.log=t.message,o.data=l.data}return o},"encryptFunc"),Ct=z(async l=>{let o={status:"success",log:"",data:void 0},t=l.data||void 0;try{if(t===void 0)throw new Error("Invalid data");if(ce.cryptoEnable){let c=tr.value||void 0,e=ut.current!==void 0?Pr({data:l.data,api:ut.current,privateKey:c}):await Sr({data:l.data,privateKey:c});if(e.status!=="success")throw new Error("Decryption failed");o.data=e.data}return o}catch(c){o.status="error",o.log=c.message,o.data=l.data}return o},"decryptFunc"),Xe=z(async l=>{let o=l.api,t=JSON.stringify(l.msg),c={status:"success",log:"",data:void 0},e={value:t},n="";try{if(ce.cryptoEnable){let s=await Tt({data:e.value});if(s.status!=="success")throw new Error(s.log);e.value=s.data}n=JSON.stringify(e)}catch(s){c.status="error",c.log=`[WebSocket] :: ${s.message}`}return o.send(n),c},"ws_sendFunc"),Ir=z(async l=>{let o=l.data,t={status:"success",log:"",data:void 0};try{let c=Object.keys(Pe);if(c.length===0)throw new Error("Not server found to commit client session");let e=[];for(let a=0;a<c.length;a++){let i=c[a],f=Pe[i],d=f.id,b=f.api,E=await Xe({api:b,msg:{id:ce.id,object:"commit_session",data:o,target:"single",targetId:d,oldSessionId:ce.oldSessionId}});if(E.status!=="success"){e.push(d),Ke("session failed to commit ::",E.log);continue}}let n=e.length,s=c.length;if(n>0){if(n<s)t.log=`Failed to commit session to following server(s) "[${e}"]`;else if(n===s)throw new Error("Failed to commit session")}}catch(c){t.status="error",t.log=c.message}return t},"ws_commitClientSessionFunc"),en=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.targetType,c=l.filter,e=t==="client"?je:Pe,n=Object.keys(e),s=[],a=0;if(n.length>0)for(let i=0;i<n.length;i++){a>0&&a%Ze.current.rate===0&&await Ee({ms:Ze.current.ms});let f=n[i],d=e[f],b=d.session;if(b===void 0||Object.keys(b).length===0)continue;let E=jt({feed:b,condition:c});if(E.status!=="success")throw new Error(E.log);E.data&&s.push(d.id),a++}o.data=s}catch(t){o.status="error",o.log=t.message}return o},"ws_filterFunc"),pt=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l,c=t.targetId,e=c==="*",n=t.targetFilter!==void 0&&Object.keys(t.targetFilter).length>0,s=1e3,a={type:t.type,source:t.source,func:t.method,xorder:t.execOrder};switch(t.targetType){case"client":if(e){let i=[];if(Object.keys(je).length===0&&await Ee({ms:s*5}),n){let d=await en({targetType:"client",filter:t.targetFilter||{}});if(d.status!=="success")throw new Error(d.log);i=d.data}else i=Object.keys(je);if(i.length===0)throw new Error(n?"No client matches the filter - Broadcast cancelled":"No clients found - Broadcast cancelled");let f=0;for(let d=0;d<i.length;d++){f>0&&f%Ze.current.rate===0&&await Ee({ms:Ze.current.ms});let b=i[d],E=je[b].api;if(E===void 0){o.log=o.log+`Unable to send message to client with id "${b}" - It API may be broken `,f++;continue}try{await Xe({api:E,msg:{id:ce.id,object:"trigger_method",data:a}})}catch(p){o.log=o.log+`Unable to send message to client with id "${b}" - ${p.message} `,f++;continue}f++}}else{let i=N(je,t.targetId);if(i||(await Ee({ms:s*5}),i=N(je,c)),!i)throw new Error(`Can't found a client with id "${t.targetId}"`);let f=t.targetId,d=je[f].id,b=je[f].api;if(b===void 0)throw new Error(`Invalid API for client "${f}"`);let E,p;if(t.callback!==void 0){if(typeof t.callback!="function")throw new Error("Invalid callback");let h=t.callbackId||Ue({length:8});if(N(at,h))throw new Error(`The id "${h}" is already used by another callback`);at[h]=t.callback,E=h,p=ce.id}await Xe({api:b,msg:{id:ce.id,object:"trigger_method",data:a,callbackId:E,callbackOwnerId:p}})}break;case"server":if(e){let i=Object.keys(Pe);if(i.length===0&&(await Ee({ms:s}),i=Object.keys(Pe)),i.length===0)throw new Error("No server found - Broadcast cancelled");let f=0;for(let d=0;d<i.length;d++){f>0&&f%Ze.current.rate&&await Ee({ms:Ze.current.ms});let b=i[d],E=Pe[b].api,p=Pe[b].id;if(E===void 0){o.log=o.log+`Unable to send message to server with id "${b}" - It API may be broken `,f++;continue}try{await Xe({api:E,msg:{id:ce.id,object:"trigger_method",data:a,targetId:p,sessionFilter:t.targetFilter||{}}})}catch(h){o.log=o.log+`Unable to send message to server with id "${b}" - ${h.message} `,f++;continue}f++}}else{let i=N(Pe,c);if(i||(await Ee({ms:s}),i=N(Pe,c)),!i)throw new Error(`Can't found a server with id "${c}"`);let f=c,d=Pe[f].id,b=Pe[f].api;if(b===void 0)throw new Error(`Invalid API for server "${f}"`);let E,p;if(t.callback!==void 0){if(typeof t.callback!="function")throw new Error("Invalid callback");let h=t.callbackId||Ue({length:8});if(N(at,h))throw new Error(`The id "${h}" is already used by another callback`);at[h]=t.callback,E=h,p=ce.id}await Xe({api:b,msg:{id:ce.id,object:"trigger_method",data:a,callbackId:E,callbackOwnerId:p}})}break;default:}}catch(t){o.status="error",o.log=`[WebSocket] :: ${o.log+` `+t.message}`}return o},"ws_sendtriggerMethodFunc"),Fr=z(l=>{let o={status:"success",log:"",data:void 0};try{Tr(l.config)}catch(t){o.status="error",o.data=`[WebSocket] :: ${t.message}`}return o},"ws_restartConnectionToServerFunc"),tn=z(()=>{let l={status:"success",log:"",data:void 0};try{if(Object.keys(ze).length===0)return l.log="No server found",l;let o=ze;for(let t in o){let c=o[t];if(c.isActive||c.retryCount!==0)continue;let e=Fr({config:c.config});if(e.status!=="success"){let n=e.log.replaceAll("[WebSocket] :: ","");throw new Error(n)}}}catch(o){l.status="error",l.log=`[WebSocket] :: ${o.message}`}return l},"ws_restartDeadConnectionsFunc"),Ne=z(async l=>{try{let o=l.event,t=l.type||ce.runtimeType,c=l.serverId||void 0,e=l.data||void 0,n=l.api||void 0,s=l.config||void 0;switch(o){case"open":if(t==="client"){if(c===void 0){He("[WebSocket] :: Unable to find server ID");return}N(ze,c)?(ze[c].retryCount=0,ze[c].isActive=!0):ze[c]={config:s,retryCount:0,isActive:!0},sr.current=n;let a=await Xe({api:sr.current,msg:{id:ce.id,oldSessionId:ce.oldSessionId,object:"client_handshake"}})}break;case"message":{let a=String(e),f=JSON.parse(a).value,d=f;if(ce.cryptoEnable){let b=await Ct({data:f});if(b.status!=="success")throw Ke("dec failed ::",b.log),new Error("[WebSocket] :: Message descryption failed");d=typeof b.data=="string"?JSON.parse(b.data):b.data}if(typeof d=="string"&&(d=JSON.parse(d)),t==="client"){let b=d.id,E=d.object,p=d.callbackOwnerId,h=c||b;switch(E){case"server_handshake":{let r=N(Pe,h);Pe[h]={id:h,api:n,store:{},session:{}},await Ir({data:Be}),He(`[WebSocket] :: Successfully connected to server "${h}"`)}break;case"trigger_method":{let r=d.data,I=d.callbackId,T=await dt({type:r.type,source:r.source,func:r.func,xorder:r.xorder});if(I!==void 0){let v=Pe[h].api;await Xe({api:v,msg:{id:ce.id,oldSessionId:ce.oldSessionId,object:"trigger_back",data:T,callbackId:I,callbackOwnerId:p}})}}break;case"trigger_back":{let r=d.data,I=d.callbackId;if(I!==void 0){let T=at[I];if(typeof T!="function")return;try{await T({id:I,response:r})}catch{}delete at[I]}}break;default:}}else{let b=d.id,E=d.oldSessionId,p=d.object,h=d.data,r=d.callbackOwnerId,I=N(je,b);switch(p){case"client_handshake":je[b]={id:b,api:n,store:{},session:{}},await Xe({api:n,msg:{id:ce.id,oldSessionId:ce.oldSessionId,object:"server_handshake"}}),tn();break;case"commit_session":I||((E===""?!1:N(je,E))?(je[b]=je[E],je[b].id=b,delete je[E]):je[b]={id:b,api:n,store:{},session:{}}),Fe({target:je[b].session,data:h});break;case"commit_store":I||((E===""?!1:N(je,E))?(je[b]=je[E],delete je[E]):je[b]={id:b,api:n,store:{},session:{}}),Fe({target:je[b].store,data:h});break;case"trigger_method":{let T=d.sessionFilter;if(T!==void 0&&Object.keys(T).length>0){let R=G({obj:Be}),B=jt({feed:R,condition:T});if(B.status!=="success"||!B.data)return}let v=d.data,u=d.callbackId,Y=await dt({type:v.type,source:v.source,func:v.func,xorder:v.xorder});if(u!==void 0){let R=je[b].api;await Xe({api:R,msg:{id:ce.id,oldSessionId:ce.oldSessionId,object:"trigger_back",data:Y,callbackId:u,callbackOwnerId:r}})}}break;case"trigger_back":{let T=d.data,v=d.callbackId;if(v!==void 0){let u=at[v];if(typeof u!="function")return;try{await u({id:v,response:T})}catch{}delete at[v]}}break;default:}}}break;case"close":if(t==="client"){if(c===void 0||s===void 0){He("[WebSocket] :: Server ID or config not found, impossible to establish a connection");return}N(ze,c)||(ze[c]={config:s,retryCount:0,isActive:!1});let a=s.serverId,i=ze[a].retryCount;i<Kt?Ee({ms:zr}).then(()=>{i===0&&He(`[WebSocket] :: Connection to server "${a}" via "${s.host}" failed - Please wait while forest retry the process...`),ze[a].retryCount+=1,Fr({config:s}).status!=="success"&&(ze[a].retryCount=Kt)}):(He(`[WebSocket] :: Unfortunally, connection to server "${a}" failed after "${Kt}" attempts - Please check that the server is serving on the right port`),ze[a].retryCount=0,ze[a].isActive=!1)}break;case"error":break;default:}}catch(o){Ke("[WebSocket] ::",o.message)}},"processWebsocketFunc"),Tr=z(l=>{let o={status:"success",log:"",data:void 0};try{let t=l,c=l.rt||void 0,e=l.ws||void 0,n=l.type||void 0,s=l.serverId||void 0,a=l.host||void 0,i=l.wsPort||void 0,f=ce;if(f.runtimeType===void 0&&f.runtime!==void 0&&(ce.runtimeType=Er.includes(f.runtime)?"server":jr.includes(f.runtime)?"client":void 0),n==="client"){let d=new e(a);d.onopen=async()=>{await Ne({event:"open",type:n,serverId:s,api:d,config:t})},d.onmessage=async b=>{await Ne({event:"message",type:n,serverId:s,api:d,data:b.data})},d.onclose=async()=>{await Ne({event:"close",type:n,serverId:s,api:d,config:t})},d.onerror=async b=>{await Ne({event:"error",type:n,serverId:s,api:d,data:b,config:t})}}else if(n==="server")switch(c){case"Deno":e.serve({port:i},async d=>{if(d.headers.get("upgrade")==="websocket"){let{socket:b,response:E}=Deno.upgradeWebSocket(d);return b.onopen=async()=>{await Ne({event:"open",type:n,serverId:s,api:b})},b.onmessage=async p=>{await Ne({event:"message",type:n,serverId:s,api:b,data:p.data})},b.onclose=async()=>{await Ne({event:"close",type:n,serverId:s,api:b,config:t})},b.onerror=async p=>{await Ne({event:"error",type:n,serverId:s,api:b,data:p,config:t})},E}return new Response("Invalid request",{status:400})});break;case"Node":new e({port:i}).on("connection",(b,E)=>{b.on("open",async()=>{await Ne({event:"open",type:n,serverId:s,api:b})}),b.on("message",async p=>{await Ne({event:"message",type:n,serverId:s,api:b,data:p})}),b.on("close",async()=>{await Ne({event:"close",type:n,serverId:s,api:b,config:t})}),b.on("error",async p=>{await Ne({event:"error",type:n,serverId:s,api:b,data:p,config:t})})});break;case"Bun":e.serve({port:i,websocket:{async open(d){await Ne({event:"open",type:n,serverId:s,api:d})},async message(d,b){await Ne({event:"message",type:n,serverId:s,data:b,api:d})},async close(d,b,E){await Ne({event:"close",type:n,serverId:s,data:{code:b,reason:E},api:d,config:t})},async error(d,b){await Ne({event:"error",type:n,serverId:s,data:b,api:d,config:t})}},fetch(d,b){if(!b.upgrade(d))return new Response("Forest socket is ready...")}});break;default:}}catch(t){o.status="error",o.log=`[WebSocket] :: ${t.message}`}return o},"setupWebsocketFunc"),rn=z(l=>{let o={status:"success",log:"",data:void 0};try{if(l.length===0)throw new Error("Empty websocket config list");for(let t=0;t<l.length;t++){let c=l[t],e=Tr({rt:c.runtime,ws:c.api,type:c.type,serverId:c.serverId,host:c.host,wsPort:c.port});if(e.status!=="success")throw new Error(e.log)}}catch(t){o.status="error",o.log=`[WebSocket] :: ${t.message}`}return o},"bulkWebsocketConfigFunc"),nn=z(async(l,o)=>{let t={status:"success",log:"",data:void 0},c=o;try{let e=l.method.toLowerCase(),n=l.headers,a=(await l.json()).value,i=new URL(l.url).pathname.replace("/",""),f=ce.httpConfig?.as_server?.endpoint;if(e!=="post"){t.status="error",t.log="Not a POST request";let d=JSON.stringify(t);return new c(d,ot.json)}if(![f,Lt].includes(i))return t.status="error",t.log=`Unknow route "${i}"`,new c(JSON.stringify(t),ot.json);if(i===f){let d=a;if(ce.cryptoEnable){let T=await Ct({data:a});if(T.status!=="success")throw new Error("Descryption failed");d=typeof T.data=="string"?JSON.parse(T.data):T.data,typeof d=="string"&&(d=JSON.parse(d))}else if(d=typeof d=="string"&&d.includes("{")?JSON.parse(d):d,typeof d=="string")throw new Error("Descryption failed");let b=d.type,E=d.source,p=d.method,h=d.xorder;t=await dt({type:b,source:E,func:p,xorder:h});let I=JSON.stringify(t);if(ce.cryptoEnable){let T=await Tt({data:I});if(T.status!=="success")throw new Error(T.log);I=T.data}return new c(I,ot.json)}else i===Lt&&Ke("h ::",n.get("content-type"))}catch(e){t.status="error",t.log=e.message;let n=JSON.stringify(t);return new c(n,ot.json)}},"httpDenoRequestProcessorFunc"),on=z(async(l,o)=>{let t={status:"success",log:"",data:void 0},c=o;try{let e=l.body,n=l.headers,s=e.value,a=s;if(ce.cryptoEnable){let h=await Ct({data:s});if(h.status!=="success")throw new Error("Descryption failed");a=typeof h.data=="string"?JSON.parse(h.data):h.data,typeof a=="string"&&(a=JSON.parse(a))}else if(a=typeof a=="string"&&a.includes("{")?JSON.parse(a):a,typeof a=="string")throw new Error("Descryption failed");let i=a.type,f=a.source,d=a.method,b=a.xorder;t=await dt({type:i,source:f,func:d,xorder:b});let p=JSON.stringify(t);if(ce.cryptoEnable){let h=await Tt({data:p});if(h.status!=="success")throw new Error(h.log);p=h.data}c.json(p)}catch(e){let n=e.message;return c.json({status:"error",log:n,data:void 0})}},"httpNodeRequestProcessorFunc"),an=z(async(l,o)=>{let t={status:"success",log:"",data:void 0},c=o;try{let e=l.method.toLowerCase(),n=l.headers,a=(await l.json()).value,i=new URL(l.url).pathname.replace("/",""),f=ce.httpConfig?.as_server?.endpoint;if(e!=="post"){t.status="error",t.log="Not a POST request";let d=JSON.stringify(t);return new c(d,ot.json)}if(![f,Lt].includes(i))return t.status="error",t.log=`Unknow route "${i}"`,new c(JSON.stringify(t),ot.json);if(i===f){let d=a;if(ce.cryptoEnable){let T=await Ct({data:a});if(T.status!=="success")throw new Error("Descryption failed");d=typeof T.data=="string"?JSON.parse(T.data):T.data,typeof d=="string"&&(d=JSON.parse(d))}else if(d=typeof d=="string"&&d.includes("{")?JSON.parse(d):d,typeof d=="string")throw new Error("Descryption failed");let b=d.type,E=d.source,p=d.method,h=d.xorder;t=await dt({type:b,source:E,func:p,xorder:h});let I=JSON.stringify(t);if(ce.cryptoEnable){let T=await Tt({data:I});if(T.status!=="success")throw new Error(T.log);I=T.data}return new c(I,ot.json)}else i===Lt&&Ke("h ::",n.get("content-type"))}catch(e){t.status="error",t.log=e.message;let n=JSON.stringify(t);return new c(n,ot.json)}},"httpBunRequestProcessorFunc"),cr=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.serverId,c=l.execOrder,e=l.method,n=l.type,s=l.source,a={value:""};if(!N(er,t))throw new Error(`Server "${t}" not found - Check http plugin config`);let f=er[t],d=f.api,b=f.endpoint||_t,E={xorder:c,method:e,type:n,source:s};if(a.value=JSON.stringify(E),ce.cryptoEnable){let h=await Tt({data:a.value});if(h.status!=="success")throw new Error(h.log);a.value=h.data}return await d.post(`/${b}`,a,{}).then(async h=>{let r=h.data,I=typeof r=="string"&&r.includes("{")?JSON.parse(r):r;if(ce.cryptoEnable){let T=await Ct({data:r});if(T.status!=="success")throw new Error("Descryption failed");I=typeof T.data=="string"?JSON.parse(T.data):T.data,typeof I=="string"&&(I=JSON.parse(I))}return o=I,o}).catch(h=>(o.status="error",o.log=h.message,o))}catch(t){o.status="error",o.log=t.message}return o},"sendHTTPrequestFunc"),sn=z(l=>{let o={status:"success",log:"",data:void 0};try{let t=l,c=ce;if(c.runtimeType===void 0&&c.runtime!==void 0&&(ce.runtimeType=Er.includes(c.runtime)?"server":jr.includes(c.runtime)?"client":void 0),t.type==="client"&&t.serverId!==void 0){let e=t.api,n=e.create({baseURL:t.url,timeout:t.timeout}),s=e.create({baseURL:t.url,timeout:t.timeout,headers:{"Content-Type":"multipart/form-data"}});er[t.serverId]={id:t.serverId,api:n,upload_api:s,endpoint:t.endpoint||_t}}else if(t.type==="server")switch(Fe({target:ce,data:{httpConfig:{as_server:{api:{},abortController:void 0,port:t.port,timeout:t.timeout,endpoint:t.endpoint,requestSize:t.requestSize,staticFiles:t.staticFiles}}}}),t.runtime){case"Deno":{let e=t.api,n=e.api,s=e.response;n.serve({port:t.port,hostname:t.host,onListen:z(()=>{let a=ce.httpConfig;a.as_server.api={deno:{app:n,response:s}},He("Forest server is running...")},"onListen"),onError:z(a=>{He("Internal Server Error ::",a)},"onError")},async a=>await nn(a,s))}break;case"Node":{let e=t.api,n=e.express,s=e.cors,a=e.bodyParser,i=e.compression,f=e.helmet,d=n();t.staticFiles!==void 0&&d.use(`/${t.staticFiles.routeName||kr}`,n.static(t.staticFiles.path,{maxAge:"1d"})),f!==void 0&&d.use(f()),i!==void 0&&d.use(i()),d.use(a.json({limit:t.requestSize})),d.use(a.urlencoded({extended:!0,limit:t.requestSize})),d.use(s()),d.use(n.json({limit:t.requestSize})),d.post(`/${t.endpoint||_t}`,on),d.use((b,E,p,h)=>{He("Internal Server Error ::",b),p.status(500).json({error:"Internal Server Error"})}),d.listen(t.port,t.host,()=>{let b=ce.httpConfig;b.as_server.api={node:{app:d,...e}},He("Forest server is running...")})}break;case"Bun":{let e=t.api,n=e.api,s=e.response;n.serve({port:t.port,hostname:t.host,maxRequestBodySize:t.requestSize,async fetch(a){return await an(a,s)}}),He("Forest server is running...")}break;default:}}catch(t){o.status="error",o.log=t.message}return o},"setupHTTPserverClientFunc"),cn=z(l=>{let o={status:"success",log:"",data:void 0};try{if(l.length===0)throw new Error("Empty http config list");for(let t=0;t<l.length;t++){let c=l[t],e=sn({runtime:c.runtime,type:c.type,api:c.api,endpoint:c.endpoint,serverId:c.serverId,host:c.host,port:c.port,url:c.url,timeout:c.timeout,requestSize:c.requestSize,staticFiles:c.staticFiles});if(e.status!=="success")throw new Error(e.log)}}catch(t){o.status="error",o.log=t.message}return o},"bulkHTTPconfigFunc"),lr=z(async l=>{let o={status:"success",log:"",data:void 0};try{if(Me.current===void 0)throw new Error('"runtime" is undefined');let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.files!==void 0?Array.isArray(s.files)?s.files:[s.files]:[];if(await Z.current.mkdir(a,{recursive:!0}),i.length>0)for(let f=0;f<i.length;f++){let d=i[f],b=d.name,E=d.content||"",p=new TextEncoder().encode(E);await Z.current.writeFile(`${a}/${b}`,p,{append:!0})}}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.files!==void 0?Array.isArray(s.files)?s.files:[s.files]:[];if(await te.current.mkdir(a,{recursive:!0}),i.length>0)for(let f=0;f<i.length;f++){let d=i[f],b=d.name,E=d.content||"";await te.current.writeFile(`${a}/${b}`,E,{encoding:"utf8",flag:"a"})}}}break;case"Bun":{if(Z.current===void 0)throw new Error('Fs API for "Bun" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.files!==void 0?Array.isArray(s.files)?s.files:[s.files]:[];if(await te.current.mkdir(a,"").catch(f=>{}),i.length>0)for(let f=0;f<i.length;f++){let d=i[f],b=d.name,E=d.content||"";await Z.current.write(`${a}/${b}`,E,{append:!0})}}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}else if(t==="file"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content,f=new TextEncoder().encode(i);await Z.current.writeFile(a,f,{append:!0})}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content;await te.current.writeFile(a,i,{encoding:"utf8",flag:"a"})}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs API for "Bun" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content;await te.current.writeFile(a,i,{encoding:"utf8",flag:"a"})}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}}catch(t){o.status="error",o.log=`[FS] :: ${o.log+t.message}`}return o},"fs_createFunc"),ln=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="file"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content,f=s.overwrite||!1,d=new TextEncoder().encode(i);await Z.current.writeFile(a,d,{append:!f})}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content,f=s.overwrite||!1;await te.current.writeFile(a,i,{encoding:"utf8",flag:f?"w":"a"})}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs API for "Bun" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content,f=s.overwrite||!1;await te.current.writeFile(a,i,{encoding:"utf8",flag:f?"w":"a"})}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.content,f=s.overwrite||!1}}break;default:}}}catch(t){o.status="error",o.log=t.message}return o},"fs_writeFunc"),ur=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e={},n=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=a.target||"all";e[i]={files:[],folders:[]};for await(let b of Z.current.readDir(f)){let E=b.name;b.isFile&&["files","all"].includes(d)?e[i].files.push(E):b.isDirectory&&["folders","all"].includes(d)&&e[i].folders.push(E)}}o.data=e}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=a.target||"all";e[i]={files:[],folders:[]},(await te.current.readdir(f,{withFileTypes:!0})).forEach(E=>{let p=E.name;E.isFile()&&["files","all"].includes(d)?e[i].files.push(p):E.isDirectory()&&["folders","all"].includes(d)&&e[i].folders.push(p)})}o.data=e}break;case"Bun":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=a.target||"all";e[i]={files:[],folders:[]},(await te.current.readdir(f,{withFileTypes:!0})).forEach(E=>{let p=E.name;E.isFile()&&["files","all"].includes(d)?e[i].files.push(p):E.isDirectory()&&["folders","all"].includes(d)&&e[i].folders.push(p)})}o.data=e}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(n.length>0)for(let s=0;s<n.length;s++);o.data=e}break;default:}}else if(t==="file"){let e={},n=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=await Z.current.readTextFile(f);e[i]=d}o.data=e}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=await te.current.readFile(f,"utf8");e[i]=d}o.data=e}break;case"Bun":{if(Z.current===void 0)throw new Error('Fs API for "Bun" not found');if(n.length>0)for(let s=0;s<n.length;s++){let a=n[s],i=a.id,f=a.path,d=Z.current.file(f);if(await d.exists()){let b=await d.text();e[i]=b}else e[i]=void 0}o.data=e}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "Node" not found');if(n.length>0)for(let s=0;s<n.length;s++);o.data=e}break;default:}}}catch(t){o.status="error",o.log=`[FS] :: ${t.message}`}return o},"fs_readFunc"),dr=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];(await Z.current.stat(s)).isDirectory&&await Z.current.remove(s,{recursive:!0})}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];await te.current.rm(s,{recursive:!0,force:!0,maxRetries:3,retryDelay:200})}}break;case"Bun":{if(Z.current===void 0)throw new Error('Fs API for "Bun" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];await Z.current.$`rm -rf ${s}`.quiet()}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n]}}break;default:}}else if(t==="file"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];(await Z.current.stat(s)).isFile&&await Z.current.remove(s)}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];await te.current.rm(s,{force:!0,maxRetries:3,retryDelay:200})}}break;case"Bun":{if(Z.current===void 0)throw new Error('Fs API for "Bun" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n];await Z.current.$`rm ${s}`.quiet()}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}}catch(t){o.status="error",o.log=`[FS] :: ${t.message}`}return o},"fs_deleteFunc"),fr=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName;if(!(await Z.current.stat(a)).isDirectory)continue;let d=ht({oldPath:a,newName:i});await Z.current.rename(a,d)}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName,f=ht({oldPath:a,newName:i});await te.current.rename(a,f)}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName,f=ht({oldPath:a,newName:i});await te.current.rename(a,f)}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}else if(t==="file"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName;if(!(await Z.current.stat(a)).isFile)continue;let d=ht({oldPath:a,newName:i});await Z.current.rename(a,d)}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName,f=ht({oldPath:a,newName:i});await te.current.rename(a,f)}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.path,i=s.newName,f=ht({oldPath:a,newName:i});await te.current.rename(a,f)}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}}catch(t){o.status="error",o.log=`[FS] :: ${t.message}`}return o},"fs_renameFunc"),hr=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;(await Z.current.stat(a)).isDirectory&&await Z.current.rename(a,i)}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;await te.current.rename(a,i)}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;await te.current.rename(a,i)}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs API for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}else if(t==="file"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;(await Z.current.stat(a)).isFile&&await Z.current.rename(a,i)}}break;case"Node":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;await te.current.rename(a,i)}}break;case"Bun":{if(te.current===void 0)throw new Error('Fs package for "Node" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to;await te.current.rename(a,i)}}break;case"React_native":{if(Z.current===void 0)throw new Error('Fs package for "React_native" not found');if(e.length>0)for(let n=0;n<e.length;n++);}break;default:}}}catch(t){o.status="error",o.log=`[FS] :: ${t.message}`}return o},"fs_moveFunc"),Jt=z(async l=>{let o={status:"success",log:"",data:void 0};try{let t=l.type,c=l.data!==void 0?l.data:[];if(t==="folder"){let e=Array.isArray(c)?c:[c];switch(Me.current){case"Deno":{if(Z.current===void 0)throw new Error('Fs API for "Deno" not found');if(e.length>0)for(let n=0;n<e.length;n++){let s=e[n],a=s.from,i=s.to,f=await Z.current.stat(a);if(!f.isDirectory)throw new Error(`The direction "${f}" doesn't exists`);await Z.current.mkdir(i,{recursive:!0});for await(let d of Z.current.readDir(a)){let b=`${a}/${d.name}`,E=`${i}/${d.name}`;d.isDirectory?await Jt({type:"folder",data:{from:b,to:E}