@stacksjs/ts-cloud 0.16.63 → 0.16.64
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.
- package/dist/bin/{chunk-45es9r0p.js → chunk-75kt8tzd.js} +69 -69
- package/dist/bin/{chunk-jkv2c5t7.js → chunk-sd64xmjq.js} +1 -1
- package/dist/bin/{chunk-vk3y548h.js → chunk-sjz4kxgt.js} +1 -1
- package/dist/bin/cli.js +4 -4
- package/dist/bin/dashboard-server.js +1 -1
- package/dist/{chunk-5zve44t6.js → chunk-6k5demvz.js} +1 -1
- package/dist/{chunk-c9vpysxv.js → chunk-v3qf7v5z.js} +69 -69
- package/dist/deploy/index.js +1 -1
- package/dist/drivers/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/ui/404.html +1 -1
- package/dist/ui/accept-invitation.html +1 -1
- package/dist/ui/access-denied.html +1 -1
- package/dist/ui/account/automation.html +6 -6
- package/dist/ui/account/security.html +2 -2
- package/dist/ui/applications/compose.html +6 -6
- package/dist/ui/applications/new.html +2 -2
- package/dist/ui/data/backups.html +6 -6
- package/dist/ui/data/services.html +5 -5
- package/dist/ui/data/volumes.html +6 -6
- package/dist/ui/index.html +6 -6
- package/dist/ui/infrastructure/topology.html +5 -5
- package/dist/ui/integrations.html +1 -1
- package/dist/ui/operations/alerts.html +6 -6
- package/dist/ui/operations/configuration.html +6 -6
- package/dist/ui/operations/jobs.html +5 -5
- package/dist/ui/operations/maintenance.html +6 -6
- package/dist/ui/operations/observability.html +6 -6
- package/dist/ui/operations/previews.html +6 -6
- package/dist/ui/operations/queue.html +6 -6
- package/dist/ui/operations/regions.html +6 -6
- package/dist/ui/operations/releases.html +6 -6
- package/dist/ui/operations/spend.html +6 -6
- package/dist/ui/operations/workloads.html +6 -6
- package/dist/ui/security.html +1 -1
- package/dist/ui/server/actions.html +6 -6
- package/dist/ui/server/activity.html +1 -1
- package/dist/ui/server/capacity.html +6 -6
- package/dist/ui/server/database.html +6 -6
- package/dist/ui/server/deployments.html +5 -5
- package/dist/ui/server/diagnostics.html +1 -1
- package/dist/ui/server/firewall.html +5 -5
- package/dist/ui/server/fleet.html +6 -6
- package/dist/ui/server/logs.html +6 -6
- package/dist/ui/server/metrics.html +5 -5
- package/dist/ui/server/security.html +2 -2
- package/dist/ui/server/services.html +2 -2
- package/dist/ui/server/sites.html +6 -6
- package/dist/ui/server/ssh-keys.html +6 -6
- package/dist/ui/server/team.html +6 -6
- package/dist/ui/server/terminal.html +2 -2
- package/dist/ui/serverless/alarms.html +6 -6
- package/dist/ui/serverless/assets.html +2 -2
- package/dist/ui/serverless/cost.html +2 -2
- package/dist/ui/serverless/data.html +6 -6
- package/dist/ui/serverless/deployments.html +2 -2
- package/dist/ui/serverless/firewall.html +1 -1
- package/dist/ui/serverless/functions.html +6 -6
- package/dist/ui/serverless/logs.html +6 -6
- package/dist/ui/serverless/metrics.html +2 -2
- package/dist/ui/serverless/queues.html +6 -6
- package/dist/ui/serverless/secrets.html +6 -6
- package/dist/ui/serverless/traces.html +6 -6
- package/dist/ui/serverless.html +5 -5
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{nl,Q,l,sl,K,g,be,m,dr,cl,Xi,Go,gl,fl,hl,$l,pn,ns,hr,Ml,Fl,ql,jl}from"./chunk-r9ydamw0.js";import{Ie,rr,x,nr,s,Li,yo,Wr,Td,wd,ae,c,bo,We,Jr,Rd,Eo,Dd,Xr,vo,ir,Yr,Fi,ar,Gi,Vi,Je,cr,Wd,Jd,ji,zi,Rt,$o,i,Ki,Fo,Uo}from"./chunk-2phe49y7.js";import{n}from"./chunk-et77ydjb.js";import{Re}from"./chunk-rs8v7c67.js";import{o}from"./chunk-betvtvy7.js";import{Te,Er,$s,dt,re,pe,T,we,wr,me,ut,Dr}from"./chunk-f512g4fq.js";import{ne}from"./chunk-7mw4x3ay.js";import{p,mt,Zs,Xt,Or,_g,Yt,Lg,$g,Qc,qe,yt,pi,F,er,Hr}from"./chunk-c9vpysxv.js";import{U,d}from"./chunk-8jqv6wh7.js";import{Ln}from"./chunk-r41cawtf.js";import{$n,Ig,Bs,L,P,xs,bg}from"./chunk-sqtzajrx.js";import{I}from"./chunk-pjdp30dn.js";import{He}from"./chunk-n0xw26th.js";import{Be}from"./chunk-bydj8p3h.js";import{A}from"./chunk-tt3pn05f.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 No}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 jo}from"os";import{dirname as Jm,resolve as qr}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 Bf,mkdirSync as DT,readdirSync as OT,writeFileSync as $T}from"fs";import{homedir as Al}from"os";import{dirname as BT,resolve as Ur}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 Mf,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 _l,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 Bo,unlink as Dc,writeFile as Tl}from"fs/promises";import{join as Mo}from"path";import _r from"process";import{pipeline as Lw}from"stream/promises";import{createGzip as rf}from"zlib";import Lo from"process";import di from"process";import{Buffer as ai}from"buffer";import{createCipheriv as Fw,createDecipheriv as zw,randomBytes as xl}from"crypto";import{closeSync as Dl,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 zo,unlink as Nc,writeFile as Ol}from"fs/promises";import{isAbsolute as Hw,join as qo,resolve as Kw}from"path";import At from"process";import{pipeline as Jw}from"stream/promises";import{createGzip as df}from"zlib";import Vo from"process";import li from"process";import jc from"process";import{existsSync as Bc}from"fs";import{resolve as Nl}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 Ll}from"crypto";import{closeSync as zl,createReadStream as pf,createWriteStream as nk,existsSync as Mc,fsyncSync as gf,openSync as mf,writeFileSync as ik}from"fs";import{access as ok,constants as ff,mkdir as sk,readdir as Lc,rename as hf,stat as Wo,unlink as Fc,writeFile as Ul}from"fs/promises";import{isAbsolute as ak,join as Ho,resolve as ck}from"path";import Ct from"process";import{pipeline as dk}from"stream/promises";import{createGzip as yf}from"zlib";import Ko from"process";import ui from"process";import Uc from"process";import{existsSync as qc}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),f=a??this.options.ttl,h=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:f,hits:0,size:h}),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,f=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:f},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 f=await t(),h=performance.now()-a;return this.recordMetric({operation:e,duration:h,timestamp:u,...r}),f}catch(f){let h=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:h,timestamp:u,...r}),f}}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,f)=>u+f,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 Gc=new Df,sp=new Of;var $f=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];function Nf(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 f of u){if(!f)continue;if(a.push(f,`.${f}.config`,`${f}.config`,`.${f}`),t)a.push(`${t}.${f}.config`,`.${t}.${f}.config`)}return Array.from(new Set(a.filter(Boolean)))}function kw(e){return Nf(e).flatMap((r)=>$f.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),Lf={};gk(Lf,{withErrorRecovery:()=>Hf,tryLoadConfig:()=>Bk,loadConfigWithResult:()=>Nk,loadConfig:()=>Ph,isRetryableError:()=>_k,isConfigNotFoundError:()=>Pk,isBunfigError:()=>Qf,globalPerformanceMonitor:()=>Qs,globalCache:()=>Jo,getEnvOrDefault:()=>Tk,generateConfigTypes:()=>Mk,defaultGeneratedDir:()=>jh,defaultConfigDir:()=>Nh,deepMergeWithArrayStrategy:()=>up,deepMerge:()=>wh,createLibraryConfig:()=>Lk,config:()=>jk,bunfigPlugin:()=>Fk,applyEnvVarsToConfig:()=>Hs,TypeGenerationError:()=>rp,SchemaValidationError:()=>Gs,PluginError:()=>ip,PerformanceMonitor:()=>cp,FileSystemError:()=>tp,ErrorFactory:()=>Pi,EnvVarError:()=>sd,EnvProcessor:()=>ud,ConfigValidator:()=>pp,ConfigValidationError:()=>tu,ConfigNotFoundError:()=>od,ConfigMergeError:()=>ep,ConfigLoader:()=>gp,ConfigLoadError:()=>Js,ConfigFileLoader:()=>pd,ConfigCache:()=>ap,CacheUtils:()=>Th,BunfigError:()=>cn,BrowserConfigError:()=>np,ArrayMergeStrategies:()=>Oh});class ap{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),f=a??this.options.ttl,h=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:f,hits:0,size:h}),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,f=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:f},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 cp{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let f=await t(),h=performance.now()-a;return this.recordMetric({operation:e,duration:h,timestamp:u,...r}),f}catch(f){let h=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:h,timestamp:u,...r}),f}}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,f)=>u+f,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 dp(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&Wt(t[0])&&"id"in t[0]&&t[0].id===3&&Wt(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(Wt(t)&&Wt(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(Wt(e)&&"arr"in e&&Array.isArray(e.arr)&&Wt(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&Wt(t[0])&&Wt(e[0])){let a=[...t];for(let u of e)if(Wt(u)&&"name"in u){if(!a.find((h)=>Wt(h)&&("name"in h)&&h.name===u.name))a.push(u)}else if(Wt(u)&&"path"in u){if(!a.find((h)=>Wt(h)&&("path"in h)&&h.path===u.path))a.push(u)}else if(!a.some((f)=>td(f,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(!Wt(t)||!Wt(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(Wt(u)&&Wt(r[a]))r[a]=dp(r[a],u);else if(Array.isArray(u)&&Array.isArray(r[a]))if(u.length>0&&r[a].length>0&&Wt(u[0])&&Wt(r[a][0])){let f=[...u];for(let h of r[a])if(Wt(h)&&"name"in h){if(!f.find((S)=>Wt(S)&&("name"in S)&&S.name===h.name))f.push(h)}else if(Wt(h)&&"path"in h){if(!f.find((S)=>Wt(S)&&("path"in S)&&S.path===h.path))f.push(h)}else if(!f.some((b)=>td(b,h)))f.push(h);r[a]=f}else if(u.every((f)=>typeof f==="string")&&r[a].every((f)=>typeof f==="string")){let f=[...u];for(let h of r[a])if(!f.includes(h))f.push(h);r[a]=f}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(Wt(e)&&Wt(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 Wt(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function vk(e,t){if(!Mf(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 dp(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"],f=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let h of f)for(let b of u){let S=Xc(a,`${h}${b}`),y=await vk(S,r);if(y!==null)return y}try{let h=Xc(a,"package.json");if(Mf(h)){let S=(await import(h))[e];if(S&&typeof S==="object"&&!Array.isArray(S))try{return dp(r,S)}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:Wc,cwd:Zc.cwd(),endpoint:"",headers:{}});return{...Wc,...e}}catch{return Wc}}function Qt(){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 Ff{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:Lo.pid,hostname:t(),environment:Lo.env.NODE_ENV||"development",platform:Lo.platform,version:Lo.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:Lo.env.NODE_ENV||Lo.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 Ff,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??_r.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(),f=this.generateKey();this.currentKeyId=u,this.keys.set(u,f),this.encryptionKeys.set(u,{key:f,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...Hc,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...Hc};return{...Hc,...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,f=0,h=3,b=1000;while(f<h)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 S=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Ci.from(e);try{if(!_l(this.currentLogFile))await Tl(this.currentLogFile,"",{mode:420});if(u=Xm(this.currentLogFile,"a",420),jw(u,S,{flag:"a"}),Zm(u),u!==void 0)Pl(u),u=void 0;if((await Bo(this.currentLogFile)).size===0){if(await Tl(this.currentLogFile,S,{flag:"w",mode:420}),(await Bo(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(y){let k=y;if(k.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(k.code)){if(f<h-1){let R=typeof k.message==="string"?k.message:"Unknown error";console.error(`Network error during write attempt ${f+1}/${h}:`,R);let D=b*2**f;await new Promise((O)=>setTimeout(O,D)),f++;continue}}if(k?.code&&["ENOSPC","EDQUOT"].includes(k.code))throw Error(`Disk quota exceeded or no space left on device: ${k.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",k),k}finally{if(u!==void 0)try{Pl(u)}catch(y){console.error("Debug: [writeToFile] Error closing file descriptor:",y)}}}catch(S){if(f===h-1){let k=S,R=typeof k.message==="string"?k.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",R),S}f++;let y=b*2**(f-1);await new Promise((k)=>setTimeout(k,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 Mo(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 Mo(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Mo(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(Qt())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],[,S])=>S.createdAt.getTime()-b.createdAt.getTime()),f=typeof t.maxKeys==="number"?t.maxKeys:1,h=Math.max(1,f);if(u.length>h)for(let[b]of u.slice(h))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()]),f=a.getAuthTag();return{encrypted:Ci.concat([r,u,f]),iv:r}}async compressData(e){return new Promise((t,r)=>{let a=rf(),u=[];a.on("data",(f)=>u.push(f)),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(Qt())return;let e=await Bo(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),f=u.filter((S)=>S.startsWith(this.name)&&/\.log\.\d+$/.test(S)).sort((S,y)=>{let k=Number.parseInt(S.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(y.match(/\.log\.(\d+)$/)?.[1]||"0")-k}),h=f.length>0?Number.parseInt(f[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,b=`${r}.${h}`;if(await Bo(r).catch(()=>null))try{if(await tf(r,b),t.compress)try{let S=`${b}.gz`;await this.compressLogFile(b,S),await Dc(b)}catch(S){console.error("Error compressing rotated file:",S)}if(f.length===0&&!u.some((S)=>S.endsWith(".log.1")))try{let S=`${r}.1`;await Tl(S,"")}catch(S){console.error("Error creating backup file:",S)}}catch(S){console.error(`Error during rotation: ${S instanceof Error?S.message:String(S)}`)}}else{let u=new Date().toISOString().replace(/[:.]/g,"-"),f=r.replace(/\.log$/,`-${u}.log`);if(await Bo(r).catch(()=>null))await tf(r,f)}if(this.currentLogFile=a,t.maxFiles){let f=(await xc(this.config.logDirectory)).filter((h)=>h.startsWith(this.name)).sort((h,b)=>b.localeCompare(h));for(let h of f.slice(t.maxFiles))await Dc(Mo(this.config.logDirectory,h))}}}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()})),_l(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(!Qt()&&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(Mo(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?jt.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:r="",tag:a="",message:u,level:f,showTimestamp:h=!0}=e,b=(O)=>O.replace(this.ANSI_PATTERN,"");if(!this.fancy){let O=[];if(h)O.push(t);if(f==="warning")O.push("WARN");else if(f==="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 S=_r.stdout.columns||120,y="";if(f==="warning"||f==="error")y=`${r} ${u}`;else if(f==="info"||f==="success")y=`${r} ${a} ${u}`;else y=`${r} ${a} ${jt.cyan(u)}`;if(!h)return y.trim();let k=b(y).trim().length,R=b(t).length,D=Math.max(1,S-2-k-R);return`${y.trim()}${" ".repeat(D)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(f,h)=>{let b=Number.parseInt(h,10);return b<t[0].length?String(t[0][b]):f});let r=/%([sdijfo%])/g,a=0,u=e.replace(r,(f,h)=>{if(h==="%")return"%";if(a>=t.length)return f;let b=t[a++];switch(h){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 f}});if(a<t.length)u+=` ${t.slice(a).map((f)=>typeof f==="object"?JSON.stringify(f,null,2):String(f)).join(" ")}`;return u}async log(e,t,...r){let a=new Date,u=this.formatConsoleTimestamp(a),f=this.formatFileTimestamp(a),h,b;if(t instanceof Error)h=t.message,b=t.stack;else h=this.formatMessage(t,r);if(this.fancy&&!Qt()){let y=xh[e],k=this.options.showTags!==!1&&this.name?jt.gray(this.formatTag(this.name)):"",R;switch(e){case"debug":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:jt.gray(h),level:e}),console.error(R);break;case"info":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.error(R);break;case"success":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:jt.green(h),level:e}),console.error(R);break;case"warning":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.warn(R);break;case"error":if(R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.error(R),b){let D=b.split(`
|
|
1
|
+
import{nl,Q,l,sl,K,g,be,m,dr,cl,Xi,Go,gl,fl,hl,$l,pn,ns,hr,Ml,Fl,ql,jl}from"./chunk-r9ydamw0.js";import{Ie,rr,x,nr,s,Li,yo,Wr,Td,wd,ae,c,bo,We,Jr,Rd,Eo,Dd,Xr,vo,ir,Yr,Fi,ar,Gi,Vi,Je,cr,Wd,Jd,ji,zi,Rt,$o,i,Ki,Fo,Uo}from"./chunk-2phe49y7.js";import{n}from"./chunk-et77ydjb.js";import{Re}from"./chunk-rs8v7c67.js";import{o}from"./chunk-betvtvy7.js";import{Te,Er,$s,dt,re,pe,T,we,wr,me,ut,Dr}from"./chunk-f512g4fq.js";import{ne}from"./chunk-7mw4x3ay.js";import{p,mt,Zs,Xt,Or,_g,Yt,Lg,$g,Qc,qe,yt,pi,F,er,Hr}from"./chunk-v3qf7v5z.js";import{U,d}from"./chunk-8jqv6wh7.js";import{Ln}from"./chunk-r41cawtf.js";import{$n,Ig,Bs,L,P,xs,bg}from"./chunk-sqtzajrx.js";import{I}from"./chunk-pjdp30dn.js";import{He}from"./chunk-n0xw26th.js";import{Be}from"./chunk-bydj8p3h.js";import{A}from"./chunk-tt3pn05f.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 No}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 jo}from"os";import{dirname as Jm,resolve as qr}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 Bf,mkdirSync as DT,readdirSync as OT,writeFileSync as $T}from"fs";import{homedir as Al}from"os";import{dirname as BT,resolve as Ur}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 Mf,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 _l,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 Bo,unlink as Dc,writeFile as Tl}from"fs/promises";import{join as Mo}from"path";import _r from"process";import{pipeline as Lw}from"stream/promises";import{createGzip as rf}from"zlib";import Lo from"process";import di from"process";import{Buffer as ai}from"buffer";import{createCipheriv as Fw,createDecipheriv as zw,randomBytes as xl}from"crypto";import{closeSync as Dl,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 zo,unlink as Nc,writeFile as Ol}from"fs/promises";import{isAbsolute as Hw,join as qo,resolve as Kw}from"path";import At from"process";import{pipeline as Jw}from"stream/promises";import{createGzip as df}from"zlib";import Vo from"process";import li from"process";import jc from"process";import{existsSync as Bc}from"fs";import{resolve as Nl}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 Ll}from"crypto";import{closeSync as zl,createReadStream as pf,createWriteStream as nk,existsSync as Mc,fsyncSync as gf,openSync as mf,writeFileSync as ik}from"fs";import{access as ok,constants as ff,mkdir as sk,readdir as Lc,rename as hf,stat as Wo,unlink as Fc,writeFile as Ul}from"fs/promises";import{isAbsolute as ak,join as Ho,resolve as ck}from"path";import Ct from"process";import{pipeline as dk}from"stream/promises";import{createGzip as yf}from"zlib";import Ko from"process";import ui from"process";import Uc from"process";import{existsSync as qc}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),f=a??this.options.ttl,h=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:f,hits:0,size:h}),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,f=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:f},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 f=await t(),h=performance.now()-a;return this.recordMetric({operation:e,duration:h,timestamp:u,...r}),f}catch(f){let h=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:h,timestamp:u,...r}),f}}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,f)=>u+f,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 Gc=new Df,sp=new Of;var $f=[".ts",".js",".mjs",".cjs",".json",".mts",".cts"];function Nf(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 f of u){if(!f)continue;if(a.push(f,`.${f}.config`,`${f}.config`,`.${f}`),t)a.push(`${t}.${f}.config`,`.${t}.${f}.config`)}return Array.from(new Set(a.filter(Boolean)))}function kw(e){return Nf(e).flatMap((r)=>$f.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),Lf={};gk(Lf,{withErrorRecovery:()=>Hf,tryLoadConfig:()=>Bk,loadConfigWithResult:()=>Nk,loadConfig:()=>Ph,isRetryableError:()=>_k,isConfigNotFoundError:()=>Pk,isBunfigError:()=>Qf,globalPerformanceMonitor:()=>Qs,globalCache:()=>Jo,getEnvOrDefault:()=>Tk,generateConfigTypes:()=>Mk,defaultGeneratedDir:()=>jh,defaultConfigDir:()=>Nh,deepMergeWithArrayStrategy:()=>up,deepMerge:()=>wh,createLibraryConfig:()=>Lk,config:()=>jk,bunfigPlugin:()=>Fk,applyEnvVarsToConfig:()=>Hs,TypeGenerationError:()=>rp,SchemaValidationError:()=>Gs,PluginError:()=>ip,PerformanceMonitor:()=>cp,FileSystemError:()=>tp,ErrorFactory:()=>Pi,EnvVarError:()=>sd,EnvProcessor:()=>ud,ConfigValidator:()=>pp,ConfigValidationError:()=>tu,ConfigNotFoundError:()=>od,ConfigMergeError:()=>ep,ConfigLoader:()=>gp,ConfigLoadError:()=>Js,ConfigFileLoader:()=>pd,ConfigCache:()=>ap,CacheUtils:()=>Th,BunfigError:()=>cn,BrowserConfigError:()=>np,ArrayMergeStrategies:()=>Oh});class ap{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),f=a??this.options.ttl,h=this.estimateSize(t);this.cache.set(u,{value:t,timestamp:new Date,ttl:f,hits:0,size:h}),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,f=u?u.mtime:new Date;this.set(e,{value:t,fileTimestamp:f},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 cp{metrics=[];maxMetrics=1000;async track(e,t,r={}){let a=performance.now(),u=new Date;try{let f=await t(),h=performance.now()-a;return this.recordMetric({operation:e,duration:h,timestamp:u,...r}),f}catch(f){let h=performance.now()-a;throw this.recordMetric({operation:`${e}:error`,duration:h,timestamp:u,...r}),f}}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,f)=>u+f,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 dp(e,t){if(Array.isArray(t)&&Array.isArray(e)&&t.length===2&&e.length===2&&Wt(t[0])&&"id"in t[0]&&t[0].id===3&&Wt(t[1])&&"id"in t[1]&&t[1].id===4)return t;if(Wt(t)&&Wt(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(Wt(e)&&"arr"in e&&Array.isArray(e.arr)&&Wt(t)&&"arr"in t&&Array.isArray(t.arr))return t;if(t.length>0&&e.length>0&&Wt(t[0])&&Wt(e[0])){let a=[...t];for(let u of e)if(Wt(u)&&"name"in u){if(!a.find((h)=>Wt(h)&&("name"in h)&&h.name===u.name))a.push(u)}else if(Wt(u)&&"path"in u){if(!a.find((h)=>Wt(h)&&("path"in h)&&h.path===u.path))a.push(u)}else if(!a.some((f)=>td(f,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(!Wt(t)||!Wt(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(Wt(u)&&Wt(r[a]))r[a]=dp(r[a],u);else if(Array.isArray(u)&&Array.isArray(r[a]))if(u.length>0&&r[a].length>0&&Wt(u[0])&&Wt(r[a][0])){let f=[...u];for(let h of r[a])if(Wt(h)&&"name"in h){if(!f.find((S)=>Wt(S)&&("name"in S)&&S.name===h.name))f.push(h)}else if(Wt(h)&&"path"in h){if(!f.find((S)=>Wt(S)&&("path"in S)&&S.path===h.path))f.push(h)}else if(!f.some((b)=>td(b,h)))f.push(h);r[a]=f}else if(u.every((f)=>typeof f==="string")&&r[a].every((f)=>typeof f==="string")){let f=[...u];for(let h of r[a])if(!f.includes(h))f.push(h);r[a]=f}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(Wt(e)&&Wt(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 Wt(e){return Boolean(e&&typeof e==="object"&&!Array.isArray(e))}async function vk(e,t){if(!Mf(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 dp(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"],f=[`${e}.config`,`.${e}.config`,e,`.${e}`];for(let h of f)for(let b of u){let S=Xc(a,`${h}${b}`),y=await vk(S,r);if(y!==null)return y}try{let h=Xc(a,"package.json");if(Mf(h)){let S=(await import(h))[e];if(S&&typeof S==="object"&&!Array.isArray(S))try{return dp(r,S)}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:Wc,cwd:Zc.cwd(),endpoint:"",headers:{}});return{...Wc,...e}}catch{return Wc}}function Qt(){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 Ff{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:Lo.pid,hostname:t(),environment:Lo.env.NODE_ENV||"development",platform:Lo.platform,version:Lo.version}}return{userAgent:navigator.userAgent,hostname:window.location.hostname||"browser",environment:Lo.env.NODE_ENV||Lo.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 Ff,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??_r.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(),f=this.generateKey();this.currentKeyId=u,this.keys.set(u,f),this.encryptionKeys.set(u,{key:f,createdAt:new Date}),this.setupKeyRotation()}}initializeFingersCrossedConfig(e){if(!e.fingersCrossedEnabled&&e.fingersCrossed)return{...Hc,...e.fingersCrossed};if(!e.fingersCrossedEnabled)return null;if(!e.fingersCrossed)return{...Hc};return{...Hc,...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,f=0,h=3,b=1000;while(f<h)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 S=this.validateEncryptionConfig()?(await this.encrypt(e)).encrypted:Ci.from(e);try{if(!_l(this.currentLogFile))await Tl(this.currentLogFile,"",{mode:420});if(u=Xm(this.currentLogFile,"a",420),jw(u,S,{flag:"a"}),Zm(u),u!==void 0)Pl(u),u=void 0;if((await Bo(this.currentLogFile)).size===0){if(await Tl(this.currentLogFile,S,{flag:"w",mode:420}),(await Bo(this.currentLogFile)).size===0)throw Error("File exists but is empty after retry write")}return}catch(y){let k=y;if(k.code&&["ENETDOWN","ENETUNREACH","ENOTFOUND","ETIMEDOUT"].includes(k.code)){if(f<h-1){let R=typeof k.message==="string"?k.message:"Unknown error";console.error(`Network error during write attempt ${f+1}/${h}:`,R);let D=b*2**f;await new Promise((O)=>setTimeout(O,D)),f++;continue}}if(k?.code&&["ENOSPC","EDQUOT"].includes(k.code))throw Error(`Disk quota exceeded or no space left on device: ${k.message}`);throw console.error("Debug: [writeToFile] Error writing to file:",k),k}finally{if(u!==void 0)try{Pl(u)}catch(y){console.error("Debug: [writeToFile] Error closing file descriptor:",y)}}}catch(S){if(f===h-1){let k=S,R=typeof k.message==="string"?k.message:"Unknown error";throw console.error("Debug: [writeToFile] Max retries reached. Final error:",R),S}f++;let y=b*2**(f-1);await new Promise((k)=>setTimeout(k,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 Mo(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 Mo(this.config.logDirectory,`${this.name}.log`);let e=new Date().toISOString().split("T")[0];return Mo(this.config.logDirectory,`${this.name}-${e}.log`)}setupRotation(){if(Qt())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],[,S])=>S.createdAt.getTime()-b.createdAt.getTime()),f=typeof t.maxKeys==="number"?t.maxKeys:1,h=Math.max(1,f);if(u.length>h)for(let[b]of u.slice(h))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()]),f=a.getAuthTag();return{encrypted:Ci.concat([r,u,f]),iv:r}}async compressData(e){return new Promise((t,r)=>{let a=rf(),u=[];a.on("data",(f)=>u.push(f)),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(Qt())return;let e=await Bo(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),f=u.filter((S)=>S.startsWith(this.name)&&/\.log\.\d+$/.test(S)).sort((S,y)=>{let k=Number.parseInt(S.match(/\.log\.(\d+)$/)?.[1]||"0");return Number.parseInt(y.match(/\.log\.(\d+)$/)?.[1]||"0")-k}),h=f.length>0?Number.parseInt(f[0].match(/\.log\.(\d+)$/)?.[1]||"0")+1:1,b=`${r}.${h}`;if(await Bo(r).catch(()=>null))try{if(await tf(r,b),t.compress)try{let S=`${b}.gz`;await this.compressLogFile(b,S),await Dc(b)}catch(S){console.error("Error compressing rotated file:",S)}if(f.length===0&&!u.some((S)=>S.endsWith(".log.1")))try{let S=`${r}.1`;await Tl(S,"")}catch(S){console.error("Error creating backup file:",S)}}catch(S){console.error(`Error during rotation: ${S instanceof Error?S.message:String(S)}`)}}else{let u=new Date().toISOString().replace(/[:.]/g,"-"),f=r.replace(/\.log$/,`-${u}.log`);if(await Bo(r).catch(()=>null))await tf(r,f)}if(this.currentLogFile=a,t.maxFiles){let f=(await xc(this.config.logDirectory)).filter((h)=>h.startsWith(this.name)).sort((h,b)=>b.localeCompare(h));for(let h of f.slice(t.maxFiles))await Dc(Mo(this.config.logDirectory,h))}}}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()})),_l(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(!Qt()&&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(Mo(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?jt.gray(e.toLocaleTimeString()):e.toLocaleTimeString()}formatConsoleMessage(e){let{timestamp:t,icon:r="",tag:a="",message:u,level:f,showTimestamp:h=!0}=e,b=(O)=>O.replace(this.ANSI_PATTERN,"");if(!this.fancy){let O=[];if(h)O.push(t);if(f==="warning")O.push("WARN");else if(f==="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 S=_r.stdout.columns||120,y="";if(f==="warning"||f==="error")y=`${r} ${u}`;else if(f==="info"||f==="success")y=`${r} ${a} ${u}`;else y=`${r} ${a} ${jt.cyan(u)}`;if(!h)return y.trim();let k=b(y).trim().length,R=b(t).length,D=Math.max(1,S-2-k-R);return`${y.trim()}${" ".repeat(D)}${t}`}formatMessage(e,t){if(t.length===1&&Array.isArray(t[0]))return e.replace(/\{(\d+)\}/g,(f,h)=>{let b=Number.parseInt(h,10);return b<t[0].length?String(t[0][b]):f});let r=/%([sdijfo%])/g,a=0,u=e.replace(r,(f,h)=>{if(h==="%")return"%";if(a>=t.length)return f;let b=t[a++];switch(h){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 f}});if(a<t.length)u+=` ${t.slice(a).map((f)=>typeof f==="object"?JSON.stringify(f,null,2):String(f)).join(" ")}`;return u}async log(e,t,...r){let a=new Date,u=this.formatConsoleTimestamp(a),f=this.formatFileTimestamp(a),h,b;if(t instanceof Error)h=t.message,b=t.stack;else h=this.formatMessage(t,r);if(this.fancy&&!Qt()){let y=xh[e],k=this.options.showTags!==!1&&this.name?jt.gray(this.formatTag(this.name)):"",R;switch(e){case"debug":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:jt.gray(h),level:e}),console.error(R);break;case"info":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.error(R);break;case"success":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:jt.green(h),level:e}),console.error(R);break;case"warning":R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.warn(R);break;case"error":if(R=this.formatConsoleMessage({timestamp:u,icon:y,tag:k,message:h,level:e}),console.error(R),b){let D=b.split(`
|
|
2
2
|
`);for(let O of D)if(O.trim()&&!O.includes(h))console.error(this.formatConsoleMessage({timestamp:u,message:jt.gray(` ${O}`),level:e,showTimestamp:!1}))}break}}else if(!Qt()){if(console.error(`${f} ${this.environment}.${e.toUpperCase()}: ${h}`),b)console.error(b)}if(!this.shouldLog(e))return;let S=`${f} ${this.environment}.${e.toUpperCase()}: ${h}
|
|
3
3
|
`;if(b)S+=`${b}
|
|
4
4
|
`;S=S.replace(this.ANSI_PATTERN,""),await this.writeToFile(S)}time(e){let t=performance.now();if(this.fancy&&!Qt()){let r=this.options.showTags!==!1&&this.name?jt.gray(this.formatTag(this.name)):"",a=this.formatConsoleTimestamp(new Date);console.error(this.formatConsoleMessage({timestamp:a,icon:jt.blue("◐"),tag:r,message:`${jt.cyan(e)}...`}))}return async(r)=>{if(!this.enabled)return;let a=performance.now(),u=Math.round(a-t),f=`${e} completed in ${u}ms`,h=new Date,b=this.formatConsoleTimestamp(h),y=`${this.formatFileTimestamp(h)} ${this.environment}.INFO: ${f}`;if(r)y+=` ${JSON.stringify(r)}`;if(y+=`
|