import{parentPort as p}from"node:worker_threads";import{performance as l}from"node:perf_hooks";import f from"better-sqlite3";import{W as d,i as c}from"./AsyncSqlite-8sGv3lfc.mjs";import{s as u}from"./setup-jOmJhQLK.mjs";import"os";import"./sentry-common-ai21LIAw.mjs";import"./_commonjsHelpers-CLLqo0NO.mjs";import"./index-7t_wvw7g.mjs";import"worker_threads";import"./constants-DED7MIJj.mjs";import"path";import"url";import"fs";import"./package-uaSG8XjZ.mjs";import"./machine-id-D3_purtu.mjs";import"perf_hooks";import"child_process";import"./index-Cl8VihPn.mjs";import"timers/promises";import"./logger-D_9t6p_W.mjs";import"async_hooks";import"./dev-fp014L8f.mjs";import"node:module";import"node:path";import"node:url";import"./sentry-buffer-BNqrS-8_.mjs";import"module";import"crypto";import"vm";import"./util-4MLVQf5_.mjs";import"./register-proxy-C4V2Z2tW.mjs";import"./index-66F80Yco.mjs";import"domain";import"http";import"https";import"./index-HJDsW6S6.mjs";import"net";import"tls";import"./inject-globals-v3dPEknE.mjs";import"./got-BLig4ziO.mjs";import"events";import"util";import"stream";import"dns";import"buffer";import"zlib";import"http2";import"./got-fetch-D7dM7Qr-.mjs";import"./system-stats-DIGFNPck.mjs";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"4.2.860"}}catch{}})();try{(function(){var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},r=new e.Error().stack;r&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[r]="31244b6f-7af3-4fd1-9170-ce93b49097fb",e._sentryDebugIdIdentifier="sentry-dbid-31244b6f-7af3-4fd1-9170-ce93b49097fb")})()}catch{}await u(d.SQLITE_WORKER,{injectGlobals:!1,registerSystemStatsReporting:!1});class b{constructor(){this.statementMap=new Map}prepareSQL(r){const i=this.statementMap.get(r);if(i)return i;const t=this.db.prepare(r);return this.statementMap.set(r,t),t}runBatchOp({method:r,sql:i,params:t}){const o=this.prepareSQL(i);if(r.includes("_")){const[s,n]=r.split("_");return o[s]()[n](...t)}return o[r](...t)}processMessage({sql:r,methodName:i,args:t}){switch(i){case"init":if(this.db)throw Error("db already initialized");return this.filePath=t[0],this.db=f(this.filePath,{...t[1]}),Sentry.setTag("sql_file_path",this.filePath),!0;case"exec":return this.db.exec(r),!0;case"close":return c&&logger.log("closing db",this.filePath),this.db.close(),!0;case"batch":{if(!this.db)throw Error("db not initialized");const o=t[0];return this.db.transaction(n=>n.map(m=>this.runBatchOp(m)))(o)}}if(!this.db)throw Error("db not initialized");try{c&&logger.silently.debug(`[sqlite-worker] ${r}`);const o=this.prepareSQL(r);if(i.includes("_")){const[s,n]=i.split("_");return o[s]()[n](...t)}return o[i](...t)}finally{}}}const a=new b;p.on("message",e=>{switch(e){case"cleanup":a.db?.close(),p?.postMessage({cleanup:!0});return;case"powermonitor-on-resume":return}const{reqID:r}=e,i=l.now();try{const t=a.processMessage(e);p.postMessage({reqID:r,result:t,workerExecMs:l.now()-i})}catch(t){const o=l.now()-i;Sentry.captureException(t),logger.error("sqlite-worker error",a.filePath,t,c?e:null);const s=t?.name==="SqliteError"&&(t?.message==="file is not a database"||t?.message==="database disk image is malformed");p.postMessage({reqID:r,errorMessage:s?"$TextsDbCorrupted$"+a.filePath:t.message,workerExecMs:o})}});
//# sourceMappingURL=sqlite-worker-B_vOOgAE.mjs.map
