"use strict";var d=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var R=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of u(e))!h.call(r,s)&&s!==t&&d(r,s,{get:()=>e[s],enumerable:!(n=y(e,s))||n.enumerable});return r};var f=r=>R(d({},"__esModule",{value:!0}),r);var g={};module.exports=f(g);var l=require("node:fs"),c=require("node:sqlite"),a=require("worker_threads");var i=class{constructor(){this.nextId=1;this.handlers=new Map}createHandler(){let e=this.nextId++,t,n,s=new Promise((p,o)=>{t=p,n=o});return this.handlers.set(e,{resolve:t,reject:n}),{id:e,result:s}}handleResponse(e){let t=this.handlers.get(e.id);t&&(this.handlers.delete(e.id),e.err?t.reject(e.err):t.resolve(e.res))}handleError(e){for(let t of this.handlers.values())t.reject(e);this.handlers.clear()}clear(){this.handlers.clear()}};var w=new i;a.parentPort.on("message",r=>{if("fn"in r)try{let e=x(r.fn,r.args);a.parentPort.postMessage({id:r.id,res:e})}catch(e){a.parentPort.postMessage({id:r.id,err:e})}else w.handleResponse(r)});function x(r,e){if(r==="queryTodos")return k(e[0]);throw new Error(`Unknown function: ${r}`)}function k(r){if(!(0,l.existsSync)(r))return[];let e;try{return e=new c.DatabaseSync(r,{open:!0}),e.exec("PRAGMA busy_timeout = 2000"),e.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name='todos'").all().length===0?[]:e.prepare("SELECT id, title, description, status FROM todos ORDER BY created_at ASC").all().map(o=>({id:String(o.id??""),title:String(o.title??""),description:String(o.description??""),status:String(o.status??"pending")}))}finally{e?.close()}}
