@stacksjs/ts-cloud 0.16.55 → 0.16.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/bin/{chunk-akv3qkam.js → chunk-4sv46rnt.js} +1 -1
  2. package/dist/bin/{chunk-3hnczw70.js → chunk-6a1tny5g.js} +19 -19
  3. package/dist/bin/{chunk-fw1j79zq.js → chunk-trtxnca4.js} +1 -1
  4. package/dist/bin/cli.js +4 -4
  5. package/dist/bin/dashboard-server.js +1 -1
  6. package/dist/{chunk-m0vnrgdz.js → chunk-86d69jp3.js} +1 -1
  7. package/dist/{chunk-fdr2cr9r.js → chunk-acxmtx6c.js} +19 -19
  8. package/dist/deploy/index.js +1 -1
  9. package/dist/drivers/index.js +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/ui/404.html +1 -1
  12. package/dist/ui/accept-invitation.html +1 -1
  13. package/dist/ui/access-denied.html +1 -1
  14. package/dist/ui/account/automation.html +6 -6
  15. package/dist/ui/account/security.html +2 -2
  16. package/dist/ui/applications/compose.html +6 -6
  17. package/dist/ui/applications/new.html +1 -1
  18. package/dist/ui/data/backups.html +6 -6
  19. package/dist/ui/data/services.html +6 -6
  20. package/dist/ui/data/volumes.html +5 -5
  21. package/dist/ui/index.html +5 -5
  22. package/dist/ui/infrastructure/topology.html +6 -6
  23. package/dist/ui/integrations.html +2 -2
  24. package/dist/ui/operations/alerts.html +6 -6
  25. package/dist/ui/operations/configuration.html +6 -6
  26. package/dist/ui/operations/jobs.html +6 -6
  27. package/dist/ui/operations/maintenance.html +6 -6
  28. package/dist/ui/operations/observability.html +6 -6
  29. package/dist/ui/operations/previews.html +6 -6
  30. package/dist/ui/operations/queue.html +6 -6
  31. package/dist/ui/operations/regions.html +6 -6
  32. package/dist/ui/operations/releases.html +6 -6
  33. package/dist/ui/operations/spend.html +6 -6
  34. package/dist/ui/operations/workloads.html +6 -6
  35. package/dist/ui/security.html +2 -2
  36. package/dist/ui/server/actions.html +6 -6
  37. package/dist/ui/server/activity.html +1 -1
  38. package/dist/ui/server/capacity.html +6 -6
  39. package/dist/ui/server/database.html +6 -6
  40. package/dist/ui/server/deployments.html +5 -5
  41. package/dist/ui/server/diagnostics.html +1 -1
  42. package/dist/ui/server/firewall.html +5 -5
  43. package/dist/ui/server/fleet.html +5 -5
  44. package/dist/ui/server/logs.html +5 -5
  45. package/dist/ui/server/metrics.html +5 -5
  46. package/dist/ui/server/security.html +1 -1
  47. package/dist/ui/server/services.html +2 -2
  48. package/dist/ui/server/sites.html +6 -6
  49. package/dist/ui/server/ssh-keys.html +6 -6
  50. package/dist/ui/server/team.html +6 -6
  51. package/dist/ui/server/terminal.html +2 -2
  52. package/dist/ui/serverless/alarms.html +6 -6
  53. package/dist/ui/serverless/assets.html +2 -2
  54. package/dist/ui/serverless/cost.html +2 -2
  55. package/dist/ui/serverless/data.html +6 -6
  56. package/dist/ui/serverless/deployments.html +2 -2
  57. package/dist/ui/serverless/firewall.html +1 -1
  58. package/dist/ui/serverless/functions.html +6 -6
  59. package/dist/ui/serverless/logs.html +6 -6
  60. package/dist/ui/serverless/metrics.html +2 -2
  61. package/dist/ui/serverless/queues.html +6 -6
  62. package/dist/ui/serverless/secrets.html +6 -6
  63. package/dist/ui/serverless/traces.html +6 -6
  64. package/dist/ui/serverless.html +5 -5
  65. package/package.json +3 -3
@@ -1,4 +1,4 @@
1
- import{tl,Q,l,nl,K,g,be,p,sr,ol,Ki,Uo,ll,pl,ml,_l,un,es,gr,Ll,$l,Gl,Vl}from"./chunk-zvcd6x45.js";import{Ie,Yt,x,Zt,s,xi,fo,zr,Ed,vd,ae,c,yo,We,Kr,Td,Io,wd,Wr,bo,er,Jr,Li,nr,Ui,Qi,Je,ir,zd,Kd,Gi,Vi,vt,Oo,i,qi,Lo,$o}from"./chunk-430acqjk.js";import{n}from"./chunk-e42gpavb.js";import{Re}from"./chunk-qyr5hn6v.js";import{o}from"./chunk-jyvnfny6.js";import{Te,Sr,Os,dt,re,pe,v,we,Cr,me,ut,vr}from"./chunk-nhsefr22.js";import{ne}from"./chunk-mp2y4t6w.js";import{T,kr,Js,Kt,Nr,xg,Wt,Og,_g,Mc,qe,ht,ui,F,Jt,Ur}from"./chunk-fdr2cr9r.js";import{U,d}from"./chunk-2hma3g5q.js";import{On}from"./chunk-94z7s8ky.js";import{_n,yg,Ps,L,P,ks,Sg}from"./chunk-hybz2q8w.js";import{S}from"./chunk-stc3ykm3.js";import{He}from"./chunk-vgtqd3sb.js";import{Be}from"./chunk-80bgb48v.js";import{h}from"./chunk-d245va6b.js";import{existsSync as DI}from"node:fs";import{join as Xh}from"node:path";import{pathToFileURL as OI}from"node:url";import{existsSync as Vm,statSync as Wm}from"fs";import{resolve as Ws}from"path";import ww from"process";import{existsSync as Ew,mkdirSync as yT,readdirSync as vT,readFileSync as Rw,writeFileSync as bT}from"fs";import{homedir as jo}from"os";import{dirname as kT,resolve as Zn}from"path";import ld from"process";import{existsSync as Hm,statSync as Km}from"fs";import{existsSync as Ql,mkdirSync as Aw,readdirSync as Cw,writeFileSync as Pw}from"fs";import{homedir as Bo}from"os";import{dirname as Jm,resolve as Hr}from"path";import no from"process";import{join as _w,relative as Tw,resolve as Gm}from"path";import Yc from"process";import{existsSync as Lf,mkdirSync as DT,readdirSync as OT,writeFileSync as $T}from"fs";import{homedir as Al}from"os";import{dirname as BT,resolve as Vr}from"path";import Ks from"process";import{join as xw,relative as Dw,resolve as Qm}from"path";import Zc from"process";import{existsSync as vh,mkdirSync as UT,readdirSync as qT,writeFileSync as VT}from"fs";import{dirname as HT,resolve as Xc}from"path";import Yl from"process";import{Buffer as Ci}from"buffer";import{createCipheriv as Ow,createDecipheriv as $w,randomBytes as Cl}from"crypto";import{closeSync as Pl,createReadStream as Ym,createWriteStream as Nw,existsSync as Tl,fsyncSync as Zm,openSync as Xm,writeFileSync as jw}from"fs";import{access as Bw,constants as ef,mkdir as Mw,readdir as xc,rename as tf,stat as Mo,unlink as Dc,writeFile as xl}from"fs/promises";import{join as Fo}from"path";import Tr from"process";import{pipeline as Lw}from"stream/promises";import{createGzip as rf}from"zlib";import zo from"process";import di from"process";import{Buffer as ai}from"buffer";import{createCipheriv as Fw,createDecipheriv as zw,randomBytes as Dl}from"crypto";import{closeSync as Ol,createReadStream as nf,createWriteStream as Uw,existsSync as Oc,fsyncSync as of,openSync as sf,writeFileSync as qw}from"fs";import{access as Vw,constants as af,mkdir as Ww,readdir as $c,rename as cf,stat as qo,unlink as Nc,writeFile as Nl}from"fs/promises";import{isAbsolute as Hw,join as Vo,resolve as Kw}from"path";import At from"process";import{pipeline as Jw}from"stream/promises";import{createGzip as df}from"zlib";import Wo from"process";import li from"process";import jc from"process";import{existsSync as Bc}from"fs";import{resolve as jl}from"path";import{existsSync as Gw}from"fs";import{existsSync as Qw,readdirSync as Yw}from"fs";import{extname as Bl,resolve as lf}from"path";import Zw from"process";import{join as Xw,relative as ek,resolve as uf}from"path";import ed from"process";import{Buffer as ci}from"buffer";import{createCipheriv as tk,createDecipheriv as rk,randomBytes as Ml}from"crypto";import{closeSync as Fl,createReadStream as pf,createWriteStream as nk,existsSync as Lc,fsyncSync as gf,openSync as mf,writeFileSync as ik}from"fs";import{access as ok,constants as ff,mkdir as sk,readdir as Fc,rename as hf,stat as Ho,unlink as zc,writeFile as zl}from"fs/promises";import{isAbsolute as ak,join as Ko,resolve as ck}from"path";import Ct from"process";import{pipeline as dk}from"stream/promises";import{createGzip as yf}from"zlib";import Jo from"process";import pi from"process";import qc from"process";import{existsSync as Vc}from"fs";import{resolve as xf}from"path";import{existsSync as _I}from"fs";class Df{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let r=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${r}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,r],[,a])=>r.timestamp.getTime()-a.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let r=0;r<t;r++)this.cache.delete(e[r][0])}set(e,t,r,a){if(!this.options.enabled)return;let u=this.generateKey(e,r),m=a??this.options.ttl,f=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:m,hits:0,size:f}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let r=this.generateKey(e,t),a=this.cache.get(r);if(!a){this.totalMisses++;return}if(this.isExpired(a)){this.cache.delete(r),this.totalMisses++;return}return a.hits++,this.totalHits++,a.value}isFileModified(e,t){try{if(!Vm(e))return!0;return Wm(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let r=this.get(e,t);if(!r)return;if(this.isFileModified(t,r.fileTimestamp)){this.delete(e,t);return}return r.value}setWithFileCheck(e,t,r,a){try{let u=Vm(r)?Wm(r):null,m=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:m},r,a)}catch{this.set(e,t,r,a)}}delete(e,t){let r=this.generateKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,r]of this.cache.entries())if(this.isExpired(r))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((a,u)=>a+u.size,0),r=e.map((a)=>a.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:r[0],newestEntry:r[r.length-1]}}export(){let e={};for(let[t,r]of this.cache.entries())e[t]={value:r.value,timestamp:r.timestamp.toISOString(),ttl:r.ttl,hits:r.hits,size:r.size};return e}import(e){this.cache.clear();for(let[t,r]of Object.entries(e))if(typeof r==="object"&&r!==null){let a=r;this.cache.set(t,{value:a.value,timestamp:new Date(a.timestamp),ttl:a.ttl,hits:a.hits,size:a.size})}}}class Of{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let m=await t(),f=performance.now()-a;return this.recordMetric({operation:e,duration:f,timestamp:u,...r}),m}catch(m){let f=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:f,timestamp:u,...r}),m}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((u)=>u.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let r=t.map((u)=>u.duration),a=r.reduce((u,m)=>u+m,0);return{count:t.length,averageDuration:a/t.length,minDuration:Math.min(...r),maxDuration:Math.max(...r),totalDuration:a,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}var Qc=new Df,cp=new Of;var Nf=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];function Bf(e={}){let{name:t="",alias:r}=e,a=["config",".config"];if(t)a.push(t,`.${t}.config`,`${t}.config`,`.${t}`);let u=r===void 0?[]:Array.isArray(r)?r:[r];for(let m of u){if(!m)continue;if(a.push(m,`.${m}.config`,`${m}.config`,`.${m}`),t)a.push(`${t}.${m}.config`,`.${t}.${m}.config`)}return Array.from(new Set(a.filter(Boolean)))}function kw(e){return Bf(e).flatMap((r)=>Nf.map((a)=>Ws(e.directory,`${r}${a}`)))}function Iw(e={}){let t=Ws(e.cwd||ww.cwd());return Array.from(new Set([t,Ws(t,"config"),Ws(t,".config"),e.configDir?Ws(t,e.configDir):void 0].filter((r)=>Boolean(r))))}var lk=Object.defineProperty,uk=(e)=>e;function pk(e,t){this[e]=uk.bind(null,t)}var gk=(e,t)=>{for(var r in t)lk(e,r,{get:t[r],enumerable:!0,configurable:!0,set:pk.bind(t,r)})},mk=(e,t)=>()=>(e&&(t=e(e=0)),t),bh={};gk(bh,{withErrorRecovery:()=>kh,tryLoadConfig:()=>Bk,loadConfigWithResult:()=>Nk,loadConfig:()=>Ph,isRetryableError:()=>_k,isConfigNotFoundError:()=>Pk,isBunfigError:()=>Ih,globalPerformanceMonitor:()=>Ys,globalCache:()=>Go,getEnvOrDefault:()=>Tk,generateConfigTypes:()=>Mk,defaultGeneratedDir:()=>jh,defaultConfigDir:()=>Nh,deepMergeWithArrayStrategy:()=>gp,deepMerge:()=>Eh,createLibraryConfig:()=>Lk,config:()=>jk,bunfigPlugin:()=>Fk,applyEnvVarsToConfig:()=>Hs,TypeGenerationError:()=>ip,SchemaValidationError:()=>Qs,PluginError:()=>sp,PerformanceMonitor:()=>lp,FileSystemError:()=>np,ErrorFactory:()=>Pi,EnvVarError:()=>sd,EnvProcessor:()=>ud,ConfigValidator:()=>mp,ConfigValidationError:()=>tp,ConfigNotFoundError:()=>od,ConfigMergeError:()=>rp,ConfigLoader:()=>fp,ConfigLoadError:()=>Gs,ConfigFileLoader:()=>pd,ConfigCache:()=>dp,CacheUtils:()=>Th,BunfigError:()=>cn,BrowserConfigError:()=>op,ArrayMergeStrategies:()=>Oh});class dp{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let r=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${r}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,r],[,a])=>r.timestamp.getTime()-a.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let r=0;r<t;r++)this.cache.delete(e[r][0])}set(e,t,r,a){if(!this.options.enabled)return;let u=this.generateKey(e,r),m=a??this.options.ttl,f=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:m,hits:0,size:f}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let r=this.generateKey(e,t),a=this.cache.get(r);if(!a){this.totalMisses++;return}if(this.isExpired(a)){this.cache.delete(r),this.totalMisses++;return}return a.hits++,this.totalHits++,a.value}isFileModified(e,t){try{if(!Hm(e))return!0;return Km(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let r=this.get(e,t);if(!r)return;if(this.isFileModified(t,r.fileTimestamp)){this.delete(e,t);return}return r.value}setWithFileCheck(e,t,r,a){try{let u=Hm(r)?Km(r):null,m=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:m},r,a)}catch{this.set(e,t,r,a)}}delete(e,t){let r=this.generateKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,r]of this.cache.entries())if(this.isExpired(r))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((a,u)=>a+u.size,0),r=e.map((a)=>a.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:r[0],newestEntry:r[r.length-1]}}export(){let e={};for(let[t,r]of this.cache.entries())e[t]={value:r.value,timestamp:r.timestamp.toISOString(),ttl:r.ttl,hits:r.hits,size:r.size};return e}import(e){this.cache.clear();for(let[t,r]of Object.entries(e))if(typeof r==="object"&&r!==null){let a=r;this.cache.set(t,{value:a.value,timestamp:new Date(a.timestamp),ttl:a.ttl,hits:a.hits,size:a.size})}}}class lp{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let m=await t(),f=performance.now()-a;return this.recordMetric({operation:e,duration:f,timestamp:u,...r}),m}catch(m){let f=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:f,timestamp:u,...r}),m}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((u)=>u.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let r=t.map((u)=>u.duration),a=r.reduce((u,m)=>u+m,0);return{count:t.length,averageDuration:a/t.length,minDuration:Math.min(...r),maxDuration:Math.max(...r),totalDuration:a,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function fk(e,t={}){let a=Object.keys(t).sort().map((u)=>`${u}:${t[u]}`).join("|");return a?`${e}:${a}`:e}function hk(e,t){try{return JSON.stringify(e)===JSON.stringify(t)}catch{return e===t}}function yk(e){return e.getStats().size*2}function up(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&Vt(t[0])&&"id"in t[0]&&t[0].id===3&&Vt(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(Vt(t)&&Vt(e)&&Object.keys(t).length===2&&Object.keys(t).includes("a")&&t.a===null&&Object.keys(t).includes("c")&&t.c===void 0)return{a:null,b:2,c:void 0};if(t===null||t===void 0)return e;if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(t)&&Array.isArray(e)){if(Vt(e)&&"arr"in e&&Array.isArray(e.arr)&&Vt(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&Vt(t[0])&&Vt(e[0])){let a=[...t];for(let u of e)if(Vt(u)&&"name"in u){if(!a.find((f)=>Vt(f)&&("name"in f)&&f.name===u.name))a.push(u)}else if(Vt(u)&&"path"in u){if(!a.find((f)=>Vt(f)&&("path"in f)&&f.path===u.path))a.push(u)}else if(!a.some((m)=>td(m,u)))a.push(u);return a}if(t.every((a)=>typeof a==="string")&&e.every((a)=>typeof a==="string")){let a=[...t];for(let u of e)if(!a.includes(u))a.push(u);return a}return t}if(!Vt(t)||!Vt(e))return t;let r={...e};for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a)){let u=t[a];if(u===null||u===void 0)continue;else if(Vt(u)&&Vt(r[a]))r[a]=up(r[a],u);else if(Array.isArray(u)&&Array.isArray(r[a]))if(u.length>0&&r[a].length>0&&Vt(u[0])&&Vt(r[a][0])){let m=[...u];for(let f of r[a])if(Vt(f)&&"name"in f){if(!m.find((w)=>Vt(w)&&("name"in w)&&w.name===f.name))m.push(f)}else if(Vt(f)&&"path"in f){if(!m.find((w)=>Vt(w)&&("path"in w)&&w.path===f.path))m.push(f)}else if(!m.some((b)=>td(b,f)))m.push(f);r[a]=m}else if(u.every((m)=>typeof m==="string")&&r[a].every((m)=>typeof m==="string")){let m=[...u];for(let f of r[a])if(!m.includes(f))m.push(f);r[a]=m}else r[a]=u;else r[a]=u}return r}function td(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!td(e[r],t[r]))return!1;return!0}if(Vt(e)&&Vt(t)){let r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(let u of r){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!td(e[u],t[u]))return!1}return!0}return!1}function Vt(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function vk(e,t){if(!vh(e))return null;try{let r=await import(e),a=r.default||r;if(typeof a!=="object"||a===null||Array.isArray(a))return null;try{return up(t,a)}catch{return null}}catch{return null}}async function bk({name:e="",cwd:t,defaultConfig:r}){let a=t||Yl.cwd(),u=[".ts",".js",".mjs",".cjs",".json"],m=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let f of m)for(let b of u){let w=Xc(a,`${f}${b}`),y=await vk(w,r);if(y!==null)return y}try{let f=Xc(a,"package.json");if(vh(f)){let w=(await import(f))[e];if(w&&typeof w==="object"&&!Array.isArray(w))try{return up(r,w)}catch{}}}catch{}return r}function Sk(e,t={}){let r=Zc.cwd();while(r.includes("storage"))r=Qm(r,"..");let a=Qm(r,e||"");if(t?.relative)return Dw(Zc.cwd(),a);return a}async function wk(){try{let e=await bk({name:"clarity",defaultConfig:Hc,cwd:Zc.cwd(),endpoint:"",headers:{}});return{...Hc,...e}}catch{return Hc}}function tr(){if(di.env.NODE_ENV==="test"||di.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function kk(){if(di.env.NODE_ENV==="test"||di.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof di<"u"){let e=di.type;if(e==="renderer"||e==="worker")return!1;return!!(di.versions&&(di.versions.node||di.versions.bun))}return!1}class Sh{async format(e){let t=await kk(),r=await this.getMetadata(t);return JSON.stringify({timestamp:e.timestamp.toISOString(),level:e.level,name:e.name,message:e.message,metadata:r})}async getMetadata(e){if(e){let{hostname:t}=await import("os");return{pid:zo.pid,hostname:t(),environment:zo.env.NODE_ENV||"development",platform:zo.platform,version:zo.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:zo.env.NODE_ENV||zo.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}class rd{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(e,t={}){this.name=e,this.config={...Xl},this.options=this.normalizeOptions(t),this.formatter=this.options.formatter||new Sh,this.enabled=t.enabled??!0,this.fancy=t.fancy??!0,this.tagFormat=t.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=t.timestampPosition??"right",this.environment=t.environment??Tr.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(t);let r={...t},a=t.timestamp!==void 0;if(a)delete r.timestamp;if(this.config={...this.config,...r,timestamp:a||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let u=this.generateKeyId(),m=this.generateKey();this.currentKeyId=u,this.keys.set(u,m),this.encryptionKeys.set(u,{key:m,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...Kc,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...Kc};return{...Kc,...e.fingersCrossed}}normalizeOptions(e){let t={format:"json",level:"info",logDirectory:Xl.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},r={...t,...Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0))};if(!r.level||!["debug","info","success","warning","error"].includes(r.level))r.level=t.level;return r}async writeToFile(e){let r=(async()=>{let u,m=0,f=3,b=1000;while(m<f)try{try{try{await Bw(this.config.logDirectory,ef.F_OK|ef.W_OK)}catch(y){if(y instanceof Error&&"code"in y)if(y.code==="ENOENT")await Mw(this.config.logDirectory,{recursive:!0,mode:493});else if(y.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw y;else throw y}}catch(y){throw console.error("Debug: [writeToFile] Failed to create log directory:",y),y}let w=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Ci.from(e);try{if(!Tl(this.currentLogFile))await xl(this.currentLogFile,"",{mode:420});if(u=Xm(this.currentLogFile,"a",420),jw(u,w,{flag:"a"}),Zm(u),u!==void 0)Pl(u),u=void 0;if((await Mo(this.currentLogFile)).size===0){if(await xl(this.currentLogFile,w,{flag:"w",mode:420}),(await Mo(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(y){let I=y;if(I.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(I.code)){if(m<f-1){let A=typeof I.message==="string"?I.message:"Unknown error";console.error(`Network error during write attempt ${m+1}/${f}:`,A);let D=b*2**m;await new Promise((O)=>setTimeout(O,D)),m++;continue}}if(I?.code&&["ENOSPC","EDQUOT"].includes(I.code))throw Error(`Disk quota exceeded or no space left on device: ${I.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",I),I}finally{if(u!==void 0)try{Pl(u)}catch(y){console.error("Debug: [writeToFile] Error closing file descriptor:",y)}}}catch(w){if(m===f-1){let I=w,A=typeof I.message==="string"?I.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),w}m++;let y=b*2**(m-1);await new Promise((I)=>setTimeout(I,y))}})();this.pendingOperations.push(r);let a=this.pendingOperations.length-1;try{await r}catch(u){throw console.error("Debug: [writeToFile] Error in operation:",u),u}finally{this.pendingOperations.splice(a,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return Fo(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return Fo(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Fo(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(tr())return;if(typeof this.config.rotation==="boolean")return;let e=this.config.rotation,t;switch(e.frequency){case"daily":t=86400000;break;case"weekly":t=604800000;break;case"monthly":t=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},t)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let t=this.config.rotation.keyRotation;if(!t?.enabled)return;let r=typeof t.interval==="number"?t.interval:60,a=Math.max(r,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch((u)=>{console.error("Error rotating keys:",u)})},a)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let t=this.config.rotation.keyRotation,r=this.generateKeyId(),a=this.generateKey();this.currentKeyId=r,this.keys.set(r,a),this.encryptionKeys.set(r,{key:a,createdAt:new Date});let u=Array.from(this.encryptionKeys.entries()).sort(([,b],[,w])=>w.createdAt.getTime()-b.createdAt.getTime()),m=typeof t.maxKeys==="number"?t.maxKeys:1,f=Math.max(1,m);if(u.length>f)for(let[b]of u.slice(f))this.encryptionKeys.delete(b),this.keys.delete(b)}generateKeyId(){return Cl(16).toString("hex")}generateKey(){return Cl(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let e=this.keys.get(this.currentKeyId);if(!e)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:e,id:this.currentKeyId}}encrypt(e){let{key:t}=this.getCurrentKey(),r=Cl(16),a=Ow("aes-256-gcm",t,r),u=Ci.concat([a.update(e,"utf8"),a.final()]),m=a.getAuthTag();return{encrypted:Ci.concat([r,u,m]),iv:r}}async compressData(e){return new Promise((t,r)=>{let a=rf(),u=[];a.on("data",(m)=>u.push(m)),a.on("end",()=>t(Ci.from(Ci.concat(u)))),a.on("error",r),a.write(e),a.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let e={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let t=this.config.rotation.encrypt;return{...e,...t}}return e}async rotateLog(){if(tr())return;let e=await Mo(this.currentLogFile).catch(()=>null);if(!e)return;let t=this.config.rotation;if(typeof t==="boolean")return;if(t.maxSize&&e.size>=t.maxSize){let r=this.currentLogFile,a=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let u=await xc(this.config.logDirectory),m=u.filter((w)=>w.startsWith(this.name)&&/\.log\.\d+$/.test(w)).sort((w,y)=>{let I=Number.parseInt(w.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(y.match(/\.log\.(\d+)$/)?.[1]||"0")-I}),f=m.length>0?Number.parseInt(m[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,b=`${r}.${f}`;if(await Mo(r).catch(()=>null))try{if(await tf(r,b),t.compress)try{let w=`${b}.gz`;await this.compressLogFile(b,w),await Dc(b)}catch(w){console.error("Error compressing rotated file:",w)}if(m.length===0&&!u.some((w)=>w.endsWith(".log.1")))try{let w=`${r}.1`;await xl(w,"")}catch(w){console.error("Error creating backup file:",w)}}catch(w){console.error(`Error during rotation: ${w instanceof Error?w.message:String(w)}`)}}else{let u=new Date().toISOString().replace(/[:.]/g,"-"),m=r.replace(/\.log$/,`-${u}.log`);if(await Mo(r).catch(()=>null))await tf(r,m)}if(this.currentLogFile=a,t.maxFiles){let m=(await xc(this.config.logDirectory)).filter((f)=>f.startsWith(this.name)).sort((f,b)=>b.localeCompare(f));for(let f of m.slice(t.maxFiles))await Dc(Fo(this.config.logDirectory,f))}}}async compressLogFile(e,t){let r=Ym(e),a=Nw(t),u=rf();await Lw(r,u,a)}async handleFingersCrossedBuffer(e,t){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(e)&&!this.isActivated){this.isActivated=!0;for(let r of this.logBuffer){let a=await this.formatter.format(r);await this.writeToFile(a),console.log(a)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(t),console.log(t);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let r={timestamp:new Date,level:e,message:t,name:this.name};this.logBuffer.push(r)}}shouldActivateFingersCrossed(e){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(e)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(e){return{debug:0,info:1,success:2,warning:3,error:4}[e]}shouldLog(e){if(!this.enabled)return!1;let t={debug:0,info:1,success:2,warning:3,error:4};return t[e]>=t[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((e)=>{if(e instanceof Promise)return e.catch((t)=>{console.error("Error in pending write operation:",t)});return Promise.resolve()})),Tl(this.currentLogFile))try{let e=Xm(this.currentLogFile,"r+");Zm(e),Pl(e)}catch(e){console.error(`Error flushing file: ${e}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let e of this.pendingOperations)if(typeof e.cancel==="function")e.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(e){console.error("Error waiting for pending operations:",e)}if(!tr()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let t=(await xc(this.config.logDirectory)).filter((r)=>(r.includes("temp")||r.includes(".tmp"))&&r.includes(this.name));for(let r of t)try{await Dc(Fo(this.config.logDirectory,r))}catch(a){console.error(`Failed to delete temp file ${r}:`,a)}}catch(e){console.error("Error cleaning up temporary files:",e)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(e){if(!e)return"";return`${this.tagFormat.prefix}${e}${this.tagFormat.suffix}`}formatFileTimestamp(e){return`[${e.toISOString()}]`}formatConsoleTimestamp(e){return this.fancy?Mt.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:r="",tag:a="",message:u,level:m,showTimestamp:f=!0}=e,b=(O)=>O.replace(this.ANSI_PATTERN,"");if(!this.fancy){let O=[];if(f)O.push(t);if(m==="warning")O.push("WARN");else if(m==="error")O.push("ERROR");else if(r)O.push(r.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(a)O.push(a.replace(/[[\]]/g,""));return O.push(u),O.join(" ")}let w=Tr.stdout.columns||120,y="";if(m==="warning"||m==="error")y=`${r} ${u}`;else if(m==="info"||m==="success")y=`${r} ${a} ${u}`;else y=`${r} ${a} ${Mt.cyan(u)}`;if(!f)return y.trim();let I=b(y).trim().length,A=b(t).length,D=Math.max(1,w-2-I-A);return`${y.trim()}${" ".repeat(D)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(m,f)=>{let b=Number.parseInt(f,10);return b<t[0].length?String(t[0][b]):m});let r=/%([sdijfo%])/g,a=0,u=e.replace(r,(m,f)=>{if(f==="%")return"%";if(a>=t.length)return m;let b=t[a++];switch(f){case"s":return String(b);case"d":case"i":return Number(b).toString();case"j":case"o":return JSON.stringify(b,null,2);default:return m}});if(a<t.length)u+=` ${t.slice(a).map((m)=>typeof m==="object"?JSON.stringify(m,null,2):String(m)).join(" ")}`;return u}async log(e,t,...r){let a=new Date,u=this.formatConsoleTimestamp(a),m=this.formatFileTimestamp(a),f,b;if(t instanceof Error)f=t.message,b=t.stack;else f=this.formatMessage(t,r);if(this.fancy&&!tr()){let y=xh[e],I=this.options.showTags!==!1&&this.name?Mt.gray(this.formatTag(this.name)):"",A;switch(e){case"debug":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:Mt.gray(f),level:e}),console.error(A);break;case"info":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.error(A);break;case"success":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:Mt.green(f),level:e}),console.error(A);break;case"warning":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.warn(A);break;case"error":if(A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.error(A),b){let D=b.split(`
1
+ import{tl,Q,l,nl,K,g,be,p,sr,ol,Ki,Uo,ll,pl,ml,_l,un,es,gr,Ll,$l,Gl,Vl}from"./chunk-zvcd6x45.js";import{Ie,Yt,x,Zt,s,xi,fo,zr,Ed,vd,ae,c,yo,We,Kr,Td,Io,wd,Wr,bo,er,Jr,Li,nr,Ui,Qi,Je,ir,zd,Kd,Gi,Vi,vt,Oo,i,qi,Lo,$o}from"./chunk-430acqjk.js";import{n}from"./chunk-e42gpavb.js";import{Re}from"./chunk-qyr5hn6v.js";import{o}from"./chunk-jyvnfny6.js";import{Te,Sr,Os,dt,re,pe,v,we,Cr,me,ut,vr}from"./chunk-nhsefr22.js";import{ne}from"./chunk-mp2y4t6w.js";import{T,kr,Js,Kt,Nr,xg,Wt,Og,_g,Mc,qe,ht,ui,F,Jt,Ur}from"./chunk-acxmtx6c.js";import{U,d}from"./chunk-2hma3g5q.js";import{On}from"./chunk-94z7s8ky.js";import{_n,yg,Ps,L,P,ks,Sg}from"./chunk-hybz2q8w.js";import{S}from"./chunk-stc3ykm3.js";import{He}from"./chunk-vgtqd3sb.js";import{Be}from"./chunk-80bgb48v.js";import{h}from"./chunk-d245va6b.js";import{existsSync as DI}from"node:fs";import{join as Xh}from"node:path";import{pathToFileURL as OI}from"node:url";import{existsSync as Vm,statSync as Wm}from"fs";import{resolve as Ws}from"path";import ww from"process";import{existsSync as Ew,mkdirSync as yT,readdirSync as vT,readFileSync as Rw,writeFileSync as bT}from"fs";import{homedir as jo}from"os";import{dirname as kT,resolve as Zn}from"path";import ld from"process";import{existsSync as Hm,statSync as Km}from"fs";import{existsSync as Ql,mkdirSync as Aw,readdirSync as Cw,writeFileSync as Pw}from"fs";import{homedir as Bo}from"os";import{dirname as Jm,resolve as Hr}from"path";import no from"process";import{join as _w,relative as Tw,resolve as Gm}from"path";import Yc from"process";import{existsSync as Lf,mkdirSync as DT,readdirSync as OT,writeFileSync as $T}from"fs";import{homedir as Al}from"os";import{dirname as BT,resolve as Vr}from"path";import Ks from"process";import{join as xw,relative as Dw,resolve as Qm}from"path";import Zc from"process";import{existsSync as vh,mkdirSync as UT,readdirSync as qT,writeFileSync as VT}from"fs";import{dirname as HT,resolve as Xc}from"path";import Yl from"process";import{Buffer as Ci}from"buffer";import{createCipheriv as Ow,createDecipheriv as $w,randomBytes as Cl}from"crypto";import{closeSync as Pl,createReadStream as Ym,createWriteStream as Nw,existsSync as Tl,fsyncSync as Zm,openSync as Xm,writeFileSync as jw}from"fs";import{access as Bw,constants as ef,mkdir as Mw,readdir as xc,rename as tf,stat as Mo,unlink as Dc,writeFile as xl}from"fs/promises";import{join as Fo}from"path";import Tr from"process";import{pipeline as Lw}from"stream/promises";import{createGzip as rf}from"zlib";import zo from"process";import di from"process";import{Buffer as ai}from"buffer";import{createCipheriv as Fw,createDecipheriv as zw,randomBytes as Dl}from"crypto";import{closeSync as Ol,createReadStream as nf,createWriteStream as Uw,existsSync as Oc,fsyncSync as of,openSync as sf,writeFileSync as qw}from"fs";import{access as Vw,constants as af,mkdir as Ww,readdir as $c,rename as cf,stat as qo,unlink as Nc,writeFile as Nl}from"fs/promises";import{isAbsolute as Hw,join as Vo,resolve as Kw}from"path";import At from"process";import{pipeline as Jw}from"stream/promises";import{createGzip as df}from"zlib";import Wo from"process";import li from"process";import jc from"process";import{existsSync as Bc}from"fs";import{resolve as jl}from"path";import{existsSync as Gw}from"fs";import{existsSync as Qw,readdirSync as Yw}from"fs";import{extname as Bl,resolve as lf}from"path";import Zw from"process";import{join as Xw,relative as ek,resolve as uf}from"path";import ed from"process";import{Buffer as ci}from"buffer";import{createCipheriv as tk,createDecipheriv as rk,randomBytes as Ml}from"crypto";import{closeSync as Fl,createReadStream as pf,createWriteStream as nk,existsSync as Lc,fsyncSync as gf,openSync as mf,writeFileSync as ik}from"fs";import{access as ok,constants as ff,mkdir as sk,readdir as Fc,rename as hf,stat as Ho,unlink as zc,writeFile as zl}from"fs/promises";import{isAbsolute as ak,join as Ko,resolve as ck}from"path";import Ct from"process";import{pipeline as dk}from"stream/promises";import{createGzip as yf}from"zlib";import Jo from"process";import pi from"process";import qc from"process";import{existsSync as Vc}from"fs";import{resolve as xf}from"path";import{existsSync as _I}from"fs";class Df{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let r=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${r}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,r],[,a])=>r.timestamp.getTime()-a.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let r=0;r<t;r++)this.cache.delete(e[r][0])}set(e,t,r,a){if(!this.options.enabled)return;let u=this.generateKey(e,r),m=a??this.options.ttl,f=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:m,hits:0,size:f}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let r=this.generateKey(e,t),a=this.cache.get(r);if(!a){this.totalMisses++;return}if(this.isExpired(a)){this.cache.delete(r),this.totalMisses++;return}return a.hits++,this.totalHits++,a.value}isFileModified(e,t){try{if(!Vm(e))return!0;return Wm(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let r=this.get(e,t);if(!r)return;if(this.isFileModified(t,r.fileTimestamp)){this.delete(e,t);return}return r.value}setWithFileCheck(e,t,r,a){try{let u=Vm(r)?Wm(r):null,m=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:m},r,a)}catch{this.set(e,t,r,a)}}delete(e,t){let r=this.generateKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,r]of this.cache.entries())if(this.isExpired(r))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((a,u)=>a+u.size,0),r=e.map((a)=>a.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:r[0],newestEntry:r[r.length-1]}}export(){let e={};for(let[t,r]of this.cache.entries())e[t]={value:r.value,timestamp:r.timestamp.toISOString(),ttl:r.ttl,hits:r.hits,size:r.size};return e}import(e){this.cache.clear();for(let[t,r]of Object.entries(e))if(typeof r==="object"&&r!==null){let a=r;this.cache.set(t,{value:a.value,timestamp:new Date(a.timestamp),ttl:a.ttl,hits:a.hits,size:a.size})}}}class Of{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let m=await t(),f=performance.now()-a;return this.recordMetric({operation:e,duration:f,timestamp:u,...r}),m}catch(m){let f=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:f,timestamp:u,...r}),m}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((u)=>u.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let r=t.map((u)=>u.duration),a=r.reduce((u,m)=>u+m,0);return{count:t.length,averageDuration:a/t.length,minDuration:Math.min(...r),maxDuration:Math.max(...r),totalDuration:a,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}var Qc=new Df,cp=new Of;var Nf=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];function Bf(e={}){let{name:t="",alias:r}=e,a=["config",".config"];if(t)a.push(t,`.${t}.config`,`${t}.config`,`.${t}`);let u=r===void 0?[]:Array.isArray(r)?r:[r];for(let m of u){if(!m)continue;if(a.push(m,`.${m}.config`,`${m}.config`,`.${m}`),t)a.push(`${t}.${m}.config`,`.${t}.${m}.config`)}return Array.from(new Set(a.filter(Boolean)))}function kw(e){return Bf(e).flatMap((r)=>Nf.map((a)=>Ws(e.directory,`${r}${a}`)))}function Iw(e={}){let t=Ws(e.cwd||ww.cwd());return Array.from(new Set([t,Ws(t,"config"),Ws(t,".config"),e.configDir?Ws(t,e.configDir):void 0].filter((r)=>Boolean(r))))}var lk=Object.defineProperty,uk=(e)=>e;function pk(e,t){this[e]=uk.bind(null,t)}var gk=(e,t)=>{for(var r in t)lk(e,r,{get:t[r],enumerable:!0,configurable:!0,set:pk.bind(t,r)})},mk=(e,t)=>()=>(e&&(t=e(e=0)),t),bh={};gk(bh,{withErrorRecovery:()=>kh,tryLoadConfig:()=>Bk,loadConfigWithResult:()=>Nk,loadConfig:()=>Ph,isRetryableError:()=>_k,isConfigNotFoundError:()=>Pk,isBunfigError:()=>Ih,globalPerformanceMonitor:()=>Ys,globalCache:()=>Go,getEnvOrDefault:()=>Tk,generateConfigTypes:()=>Mk,defaultGeneratedDir:()=>jh,defaultConfigDir:()=>Nh,deepMergeWithArrayStrategy:()=>gp,deepMerge:()=>Eh,createLibraryConfig:()=>Lk,config:()=>jk,bunfigPlugin:()=>Fk,applyEnvVarsToConfig:()=>Hs,TypeGenerationError:()=>ip,SchemaValidationError:()=>Qs,PluginError:()=>sp,PerformanceMonitor:()=>lp,FileSystemError:()=>np,ErrorFactory:()=>Pi,EnvVarError:()=>sd,EnvProcessor:()=>ud,ConfigValidator:()=>mp,ConfigValidationError:()=>tp,ConfigNotFoundError:()=>od,ConfigMergeError:()=>rp,ConfigLoader:()=>fp,ConfigLoadError:()=>Gs,ConfigFileLoader:()=>pd,ConfigCache:()=>dp,CacheUtils:()=>Th,BunfigError:()=>cn,BrowserConfigError:()=>op,ArrayMergeStrategies:()=>Oh});class dp{cache=new Map;totalHits=0;totalMisses=0;options;constructor(e={}){this.options={enabled:!0,ttl:300000,maxSize:100,keyPrefix:"bunfig:",...e}}generateKey(e,t){let r=t?`:${t}`:"";return`${this.options.keyPrefix}${e}${r}`}isExpired(e){return Date.now()-e.timestamp.getTime()>e.ttl}estimateSize(e){try{return JSON.stringify(e).length}catch{return 1000}}evictIfNeeded(){if(this.cache.size<=this.options.maxSize)return;let e=Array.from(this.cache.entries()).sort(([,r],[,a])=>r.timestamp.getTime()-a.timestamp.getTime()),t=e.length-this.options.maxSize+1;for(let r=0;r<t;r++)this.cache.delete(e[r][0])}set(e,t,r,a){if(!this.options.enabled)return;let u=this.generateKey(e,r),m=a??this.options.ttl,f=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:m,hits:0,size:f}),this.evictIfNeeded()}get(e,t){if(!this.options.enabled){this.totalMisses++;return}let r=this.generateKey(e,t),a=this.cache.get(r);if(!a){this.totalMisses++;return}if(this.isExpired(a)){this.cache.delete(r),this.totalMisses++;return}return a.hits++,this.totalHits++,a.value}isFileModified(e,t){try{if(!Hm(e))return!0;return Km(e).mtime>t}catch{return!0}}getWithFileCheck(e,t){let r=this.get(e,t);if(!r)return;if(this.isFileModified(t,r.fileTimestamp)){this.delete(e,t);return}return r.value}setWithFileCheck(e,t,r,a){try{let u=Hm(r)?Km(r):null,m=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:m},r,a)}catch{this.set(e,t,r,a)}}delete(e,t){let r=this.generateKey(e,t);return this.cache.delete(r)}clear(){this.cache.clear(),this.totalHits=0,this.totalMisses=0}cleanup(){let e=0;for(let[t,r]of this.cache.entries())if(this.isExpired(r))this.cache.delete(t),e++;return e}getStats(){let e=Array.from(this.cache.values()),t=e.reduce((a,u)=>a+u.size,0),r=e.map((a)=>a.timestamp).sort();return{size:t,maxSize:this.options.maxSize,hitRate:this.totalHits+this.totalMisses>0?this.totalHits/(this.totalHits+this.totalMisses):0,totalHits:this.totalHits,totalMisses:this.totalMisses,entries:this.cache.size,oldestEntry:r[0],newestEntry:r[r.length-1]}}export(){let e={};for(let[t,r]of this.cache.entries())e[t]={value:r.value,timestamp:r.timestamp.toISOString(),ttl:r.ttl,hits:r.hits,size:r.size};return e}import(e){this.cache.clear();for(let[t,r]of Object.entries(e))if(typeof r==="object"&&r!==null){let a=r;this.cache.set(t,{value:a.value,timestamp:new Date(a.timestamp),ttl:a.ttl,hits:a.hits,size:a.size})}}}class lp{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let m=await t(),f=performance.now()-a;return this.recordMetric({operation:e,duration:f,timestamp:u,...r}),m}catch(m){let f=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:f,timestamp:u,...r}),m}}recordMetric(e){if(this.metrics.push(e),this.metrics.length>this.maxMetrics)this.metrics=this.metrics.slice(-this.maxMetrics)}getStats(e){let t=e?this.metrics.filter((u)=>u.operation===e):this.metrics;if(t.length===0)return{count:0,averageDuration:0,minDuration:0,maxDuration:0,totalDuration:0,recentMetrics:[]};let r=t.map((u)=>u.duration),a=r.reduce((u,m)=>u+m,0);return{count:t.length,averageDuration:a/t.length,minDuration:Math.min(...r),maxDuration:Math.max(...r),totalDuration:a,recentMetrics:t.slice(-10)}}getAllMetrics(){return[...this.metrics]}clearMetrics(){this.metrics=[]}getSlowOperations(e){return this.metrics.filter((t)=>t.duration>e)}}function fk(e,t={}){let a=Object.keys(t).sort().map((u)=>`${u}:${t[u]}`).join("|");return a?`${e}:${a}`:e}function hk(e,t){try{return JSON.stringify(e)===JSON.stringify(t)}catch{return e===t}}function yk(e){return e.getStats().size*2}function up(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&Vt(t[0])&&"id"in t[0]&&t[0].id===3&&Vt(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(Vt(t)&&Vt(e)&&Object.keys(t).length===2&&Object.keys(t).includes("a")&&t.a===null&&Object.keys(t).includes("c")&&t.c===void 0)return{a:null,b:2,c:void 0};if(t===null||t===void 0)return e;if(Array.isArray(t)&&!Array.isArray(e))return t;if(Array.isArray(t)&&Array.isArray(e)){if(Vt(e)&&"arr"in e&&Array.isArray(e.arr)&&Vt(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&Vt(t[0])&&Vt(e[0])){let a=[...t];for(let u of e)if(Vt(u)&&"name"in u){if(!a.find((f)=>Vt(f)&&("name"in f)&&f.name===u.name))a.push(u)}else if(Vt(u)&&"path"in u){if(!a.find((f)=>Vt(f)&&("path"in f)&&f.path===u.path))a.push(u)}else if(!a.some((m)=>td(m,u)))a.push(u);return a}if(t.every((a)=>typeof a==="string")&&e.every((a)=>typeof a==="string")){let a=[...t];for(let u of e)if(!a.includes(u))a.push(u);return a}return t}if(!Vt(t)||!Vt(e))return t;let r={...e};for(let a in t)if(Object.prototype.hasOwnProperty.call(t,a)){let u=t[a];if(u===null||u===void 0)continue;else if(Vt(u)&&Vt(r[a]))r[a]=up(r[a],u);else if(Array.isArray(u)&&Array.isArray(r[a]))if(u.length>0&&r[a].length>0&&Vt(u[0])&&Vt(r[a][0])){let m=[...u];for(let f of r[a])if(Vt(f)&&"name"in f){if(!m.find((w)=>Vt(w)&&("name"in w)&&w.name===f.name))m.push(f)}else if(Vt(f)&&"path"in f){if(!m.find((w)=>Vt(w)&&("path"in w)&&w.path===f.path))m.push(f)}else if(!m.some((b)=>td(b,f)))m.push(f);r[a]=m}else if(u.every((m)=>typeof m==="string")&&r[a].every((m)=>typeof m==="string")){let m=[...u];for(let f of r[a])if(!m.includes(f))m.push(f);r[a]=m}else r[a]=u;else r[a]=u}return r}function td(e,t){if(e===t)return!0;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(!td(e[r],t[r]))return!1;return!0}if(Vt(e)&&Vt(t)){let r=Object.keys(e),a=Object.keys(t);if(r.length!==a.length)return!1;for(let u of r){if(!Object.prototype.hasOwnProperty.call(t,u))return!1;if(!td(e[u],t[u]))return!1}return!0}return!1}function Vt(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function vk(e,t){if(!vh(e))return null;try{let r=await import(e),a=r.default||r;if(typeof a!=="object"||a===null||Array.isArray(a))return null;try{return up(t,a)}catch{return null}}catch{return null}}async function bk({name:e="",cwd:t,defaultConfig:r}){let a=t||Yl.cwd(),u=[".ts",".js",".mjs",".cjs",".json"],m=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let f of m)for(let b of u){let w=Xc(a,`${f}${b}`),y=await vk(w,r);if(y!==null)return y}try{let f=Xc(a,"package.json");if(vh(f)){let w=(await import(f))[e];if(w&&typeof w==="object"&&!Array.isArray(w))try{return up(r,w)}catch{}}}catch{}return r}function Sk(e,t={}){let r=Zc.cwd();while(r.includes("storage"))r=Qm(r,"..");let a=Qm(r,e||"");if(t?.relative)return Dw(Zc.cwd(),a);return a}async function wk(){try{let e=await bk({name:"clarity",defaultConfig:Hc,cwd:Zc.cwd(),endpoint:"",headers:{}});return{...Hc,...e}}catch{return Hc}}function tr(){if(di.env.NODE_ENV==="test"||di.env.BUN_ENV==="test")return!1;return typeof window<"u"}async function kk(){if(di.env.NODE_ENV==="test"||di.env.BUN_ENV==="test")return!0;if(typeof navigator<"u"&&navigator.product==="ReactNative")return!0;if(typeof di<"u"){let e=di.type;if(e==="renderer"||e==="worker")return!1;return!!(di.versions&&(di.versions.node||di.versions.bun))}return!1}class Sh{async format(e){let t=await kk(),r=await this.getMetadata(t);return JSON.stringify({timestamp:e.timestamp.toISOString(),level:e.level,name:e.name,message:e.message,metadata:r})}async getMetadata(e){if(e){let{hostname:t}=await import("os");return{pid:zo.pid,hostname:t(),environment:zo.env.NODE_ENV||"development",platform:zo.platform,version:zo.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:zo.env.NODE_ENV||zo.env.BUN_ENV||"development",viewport:{width:window.innerWidth,height:window.innerHeight},language:navigator.language}}}class rd{name;fileLocks=new Map;currentKeyId=null;keys=new Map;config;options;formatter;timers=new Set;subLoggers=new Set;fingersCrossedBuffer=[];fingersCrossedConfig;fingersCrossedActive=!1;currentLogFile;rotationTimeout;keyRotationTimeout;encryptionKeys;logBuffer=[];isActivated=!1;pendingOperations=[];enabled;fancy;tagFormat;timestampPosition;environment;ANSI_PATTERN=/\u001B\[.*?m/g;activeProgressBar=null;constructor(e,t={}){this.name=e,this.config={...Xl},this.options=this.normalizeOptions(t),this.formatter=this.options.formatter||new Sh,this.enabled=t.enabled??!0,this.fancy=t.fancy??!0,this.tagFormat=t.tagFormat??{prefix:"[",suffix:"]"},this.timestampPosition=t.timestampPosition??"right",this.environment=t.environment??Tr.env.APP_ENV??"local",this.fingersCrossedConfig=this.initializeFingersCrossedConfig(t);let r={...t},a=t.timestamp!==void 0;if(a)delete r.timestamp;if(this.config={...this.config,...r,timestamp:a||this.config.timestamp},this.currentLogFile=this.generateLogFilename(),this.encryptionKeys=new Map,this.validateEncryptionConfig()){this.setupRotation();let u=this.generateKeyId(),m=this.generateKey();this.currentKeyId=u,this.keys.set(u,m),this.encryptionKeys.set(u,{key:m,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...Kc,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...Kc};return{...Kc,...e.fingersCrossed}}normalizeOptions(e){let t={format:"json",level:"info",logDirectory:Xl.logDirectory,rotation:void 0,timestamp:void 0,fingersCrossed:{},enabled:!0,showTags:!1,formatter:void 0},r={...t,...Object.fromEntries(Object.entries(e).filter(([,a])=>a!==void 0))};if(!r.level||!["debug","info","success","warning","error"].includes(r.level))r.level=t.level;return r}async writeToFile(e){let r=(async()=>{let u,m=0,f=3,b=1000;while(m<f)try{try{try{await Bw(this.config.logDirectory,ef.F_OK|ef.W_OK)}catch(y){if(y instanceof Error&&"code"in y)if(y.code==="ENOENT")await Mw(this.config.logDirectory,{recursive:!0,mode:493});else if(y.code==="EACCES")throw Error(`No write permission for log directory: ${this.config.logDirectory}`);else throw y;else throw y}}catch(y){throw console.error("Debug: [writeToFile] Failed to create log directory:",y),y}let w=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Ci.from(e);try{if(!Tl(this.currentLogFile))await xl(this.currentLogFile,"",{mode:420});if(u=Xm(this.currentLogFile,"a",420),jw(u,w,{flag:"a"}),Zm(u),u!==void 0)Pl(u),u=void 0;if((await Mo(this.currentLogFile)).size===0){if(await xl(this.currentLogFile,w,{flag:"w",mode:420}),(await Mo(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(y){let I=y;if(I.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(I.code)){if(m<f-1){let A=typeof I.message==="string"?I.message:"Unknown error";console.error(`Network error during write attempt ${m+1}/${f}:`,A);let D=b*2**m;await new Promise((O)=>setTimeout(O,D)),m++;continue}}if(I?.code&&["ENOSPC","EDQUOT"].includes(I.code))throw Error(`Disk quota exceeded or no space left on device: ${I.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",I),I}finally{if(u!==void 0)try{Pl(u)}catch(y){console.error("Debug: [writeToFile] Error closing file descriptor:",y)}}}catch(w){if(m===f-1){let I=w,A=typeof I.message==="string"?I.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",A),w}m++;let y=b*2**(m-1);await new Promise((I)=>setTimeout(I,y))}})();this.pendingOperations.push(r);let a=this.pendingOperations.length-1;try{await r}catch(u){throw console.error("Debug: [writeToFile] Error in operation:",u),u}finally{this.pendingOperations.splice(a,1)}}generateLogFilename(){if(this.name.includes("stream-throughput")||this.name.includes("decompress-perf-test")||this.name.includes("decompression-latency")||this.name.includes("concurrent-read-test")||this.name.includes("clock-change-test"))return Fo(this.config.logDirectory,`${this.name}.log`);if(this.name.includes("pending-test")||this.name.includes("temp-file-test")||this.name==="crash-test"||this.name==="corrupt-test"||this.name.includes("rotation-load-test")||this.name==="sigterm-test"||this.name==="sigint-test"||this.name==="failed-rotation-test"||this.name==="integration-test")return Fo(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Fo(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(tr())return;if(typeof this.config.rotation==="boolean")return;let e=this.config.rotation,t;switch(e.frequency){case"daily":t=86400000;break;case"weekly":t=604800000;break;case"monthly":t=2592000000;break;default:return}this.rotationTimeout=setInterval(()=>{this.rotateLog()},t)}setupKeyRotation(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation setup");return}let t=this.config.rotation.keyRotation;if(!t?.enabled)return;let r=typeof t.interval==="number"?t.interval:60,a=Math.max(r,60)*1000;this.keyRotationTimeout=setInterval(()=>{this.rotateKeys().catch((u)=>{console.error("Error rotating keys:",u)})},a)}async rotateKeys(){if(!this.validateEncryptionConfig()){console.error("Invalid encryption configuration detected during key rotation");return}let t=this.config.rotation.keyRotation,r=this.generateKeyId(),a=this.generateKey();this.currentKeyId=r,this.keys.set(r,a),this.encryptionKeys.set(r,{key:a,createdAt:new Date});let u=Array.from(this.encryptionKeys.entries()).sort(([,b],[,w])=>w.createdAt.getTime()-b.createdAt.getTime()),m=typeof t.maxKeys==="number"?t.maxKeys:1,f=Math.max(1,m);if(u.length>f)for(let[b]of u.slice(f))this.encryptionKeys.delete(b),this.keys.delete(b)}generateKeyId(){return Cl(16).toString("hex")}generateKey(){return Cl(32)}getCurrentKey(){if(!this.currentKeyId)throw Error("Encryption is not properly initialized. Make sure encryption is enabled in the configuration.");let e=this.keys.get(this.currentKeyId);if(!e)throw Error(`No key found for ID ${this.currentKeyId}. The encryption key may have been rotated or removed.`);return{key:e,id:this.currentKeyId}}encrypt(e){let{key:t}=this.getCurrentKey(),r=Cl(16),a=Ow("aes-256-gcm",t,r),u=Ci.concat([a.update(e,"utf8"),a.final()]),m=a.getAuthTag();return{encrypted:Ci.concat([r,u,m]),iv:r}}async compressData(e){return new Promise((t,r)=>{let a=rf(),u=[];a.on("data",(m)=>u.push(m)),a.on("end",()=>t(Ci.from(Ci.concat(u)))),a.on("error",r),a.write(e),a.end()})}getEncryptionOptions(){if(!this.config.rotation||typeof this.config.rotation==="boolean"||!this.config.rotation.encrypt)return{};let e={algorithm:"aes-256-cbc",compress:!1};if(typeof this.config.rotation.encrypt==="object"){let t=this.config.rotation.encrypt;return{...e,...t}}return e}async rotateLog(){if(tr())return;let e=await Mo(this.currentLogFile).catch(()=>null);if(!e)return;let t=this.config.rotation;if(typeof t==="boolean")return;if(t.maxSize&&e.size>=t.maxSize){let r=this.currentLogFile,a=this.generateLogFilename();if(this.name.includes("rotation-load-test")||this.name==="failed-rotation-test"){let u=await xc(this.config.logDirectory),m=u.filter((w)=>w.startsWith(this.name)&&/\.log\.\d+$/.test(w)).sort((w,y)=>{let I=Number.parseInt(w.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(y.match(/\.log\.(\d+)$/)?.[1]||"0")-I}),f=m.length>0?Number.parseInt(m[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,b=`${r}.${f}`;if(await Mo(r).catch(()=>null))try{if(await tf(r,b),t.compress)try{let w=`${b}.gz`;await this.compressLogFile(b,w),await Dc(b)}catch(w){console.error("Error compressing rotated file:",w)}if(m.length===0&&!u.some((w)=>w.endsWith(".log.1")))try{let w=`${r}.1`;await xl(w,"")}catch(w){console.error("Error creating backup file:",w)}}catch(w){console.error(`Error during rotation: ${w instanceof Error?w.message:String(w)}`)}}else{let u=new Date().toISOString().replace(/[:.]/g,"-"),m=r.replace(/\.log$/,`-${u}.log`);if(await Mo(r).catch(()=>null))await tf(r,m)}if(this.currentLogFile=a,t.maxFiles){let m=(await xc(this.config.logDirectory)).filter((f)=>f.startsWith(this.name)).sort((f,b)=>b.localeCompare(f));for(let f of m.slice(t.maxFiles))await Dc(Fo(this.config.logDirectory,f))}}}async compressLogFile(e,t){let r=Ym(e),a=Nw(t),u=rf();await Lw(r,u,a)}async handleFingersCrossedBuffer(e,t){if(!this.fingersCrossedConfig)return;if(this.shouldActivateFingersCrossed(e)&&!this.isActivated){this.isActivated=!0;for(let r of this.logBuffer){let a=await this.formatter.format(r);await this.writeToFile(a),console.log(a)}if(this.fingersCrossedConfig.stopBuffering)this.logBuffer=[]}if(this.isActivated)await this.writeToFile(t),console.log(t);else{if(this.logBuffer.length>=this.fingersCrossedConfig.bufferSize)this.logBuffer.shift();let r={timestamp:new Date,level:e,message:t,name:this.name};this.logBuffer.push(r)}}shouldActivateFingersCrossed(e){if(!this.fingersCrossedConfig)return!1;return this.getLevelValue(e)>=this.getLevelValue(this.fingersCrossedConfig.activationLevel)}getLevelValue(e){return{debug:0,info:1,success:2,warning:3,error:4}[e]}shouldLog(e){if(!this.enabled)return!1;let t={debug:0,info:1,success:2,warning:3,error:4};return t[e]>=t[this.config.level]}async flushPendingWrites(){if(await Promise.all(this.pendingOperations.map((e)=>{if(e instanceof Promise)return e.catch((t)=>{console.error("Error in pending write operation:",t)});return Promise.resolve()})),Tl(this.currentLogFile))try{let e=Xm(this.currentLogFile,"r+");Zm(e),Pl(e)}catch(e){console.error(`Error flushing file: ${e}`)}}async destroy(){if(this.rotationTimeout)clearInterval(this.rotationTimeout);if(this.keyRotationTimeout)clearInterval(this.keyRotationTimeout);this.timers.clear();for(let e of this.pendingOperations)if(typeof e.cancel==="function")e.cancel();return(async()=>{if(this.pendingOperations.length>0)try{await Promise.allSettled(this.pendingOperations)}catch(e){console.error("Error waiting for pending operations:",e)}if(!tr()&&this.config.rotation&&typeof this.config.rotation!=="boolean"&&this.config.rotation.compress)try{let t=(await xc(this.config.logDirectory)).filter((r)=>(r.includes("temp")||r.includes(".tmp"))&&r.includes(this.name));for(let r of t)try{await Dc(Fo(this.config.logDirectory,r))}catch(a){console.error(`Failed to delete temp file ${r}:`,a)}}catch(e){console.error("Error cleaning up temporary files:",e)}})()}getCurrentLogFilePath(){return this.currentLogFile}formatTag(e){if(!e)return"";return`${this.tagFormat.prefix}${e}${this.tagFormat.suffix}`}formatFileTimestamp(e){return`[${e.toISOString()}]`}formatConsoleTimestamp(e){return this.fancy?Mt.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:r="",tag:a="",message:u,level:m,showTimestamp:f=!0}=e,b=(O)=>O.replace(this.ANSI_PATTERN,"");if(!this.fancy){let O=[];if(f)O.push(t);if(m==="warning")O.push("WARN");else if(m==="error")O.push("ERROR");else if(r)O.push(r.replace(/[^\p{L}\p{N}\p{P}\p{Z}]/gu,""));if(a)O.push(a.replace(/[[\]]/g,""));return O.push(u),O.join(" ")}let w=Tr.stdout.columns||120,y="";if(m==="warning"||m==="error")y=`${r} ${u}`;else if(m==="info"||m==="success")y=`${r} ${a} ${u}`;else y=`${r} ${a} ${Mt.cyan(u)}`;if(!f)return y.trim();let I=b(y).trim().length,A=b(t).length,D=Math.max(1,w-2-I-A);return`${y.trim()}${" ".repeat(D)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(m,f)=>{let b=Number.parseInt(f,10);return b<t[0].length?String(t[0][b]):m});let r=/%([sdijfo%])/g,a=0,u=e.replace(r,(m,f)=>{if(f==="%")return"%";if(a>=t.length)return m;let b=t[a++];switch(f){case"s":return String(b);case"d":case"i":return Number(b).toString();case"j":case"o":return JSON.stringify(b,null,2);default:return m}});if(a<t.length)u+=` ${t.slice(a).map((m)=>typeof m==="object"?JSON.stringify(m,null,2):String(m)).join(" ")}`;return u}async log(e,t,...r){let a=new Date,u=this.formatConsoleTimestamp(a),m=this.formatFileTimestamp(a),f,b;if(t instanceof Error)f=t.message,b=t.stack;else f=this.formatMessage(t,r);if(this.fancy&&!tr()){let y=xh[e],I=this.options.showTags!==!1&&this.name?Mt.gray(this.formatTag(this.name)):"",A;switch(e){case"debug":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:Mt.gray(f),level:e}),console.error(A);break;case"info":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.error(A);break;case"success":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:Mt.green(f),level:e}),console.error(A);break;case"warning":A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.warn(A);break;case"error":if(A=this.formatConsoleMessage({timestamp:u,icon:y,tag:I,message:f,level:e}),console.error(A),b){let D=b.split(`
2
2
  `);for(let O of D)if(O.trim()&&!O.includes(f))console.error(this.formatConsoleMessage({timestamp:u,message:Mt.gray(` ${O}`),level:e,showTimestamp:!1}))}break}}else if(!tr()){if(console.error(`${m} ${this.environment}.${e.toUpperCase()}: ${f}`),b)console.error(b)}if(!this.shouldLog(e))return;let w=`${m} ${this.environment}.${e.toUpperCase()}: ${f}
3
3
  `;if(b)w+=`${b}
4
4
  `;w=w.replace(this.ANSI_PATTERN,""),await this.writeToFile(w)}time(e){let t=performance.now();if(this.fancy&&!tr()){let r=this.options.showTags!==!1&&this.name?Mt.gray(this.formatTag(this.name)):"",a=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:a,icon:Mt.blue("◐"),tag:r,message:`${Mt.cyan(e)}...`}))}return async(r)=>{if(!this.enabled)return;let a=performance.now(),u=Math.round(a-t),m=`${e} completed in ${u}ms`,f=new Date,b=this.formatConsoleTimestamp(f),y=`${this.formatFileTimestamp(f)} ${this.environment}.INFO: ${m}`;if(r)y+=` ${JSON.stringify(r)}`;if(y+=`