const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./Na41S91A.js","./BzhixHsn.js","./entry.Ce8jAJ2M.css"])))=>i.map(i=>d[i]);
import{_ as w}from"./BzhixHsn.js";import{c as p,t as d,a as f,f as b}from"./CJJwG8jL.js";async function h(n,a="gzip"){let e;if(typeof Buffer<"u"){const i=Buffer.from(n,"base64");e=Uint8Array.from(i)}else if(typeof atob<"u")e=Uint8Array.from(atob(n),i=>i.charCodeAt(0));else throw new TypeError("No base64 decoding method available");const o=new Response(new Blob([e])).body?.pipeThrough(new DecompressionStream(a)),c=await new Response(o).text();return JSON.parse(c)}function l(n,a){const e=g(n),t={...a};for(const o in t)e[o]==="json"&&t[o]&&t[o]!=="undefined"&&(t[o]=JSON.parse(t[o])),e[o]==="boolean"&&t[o]!=="undefined"&&(t[o]=!!t[o]);for(const o in t)t[o]==="NULL"&&(t[o]=void 0);return t}function g(n){const a=n.match(/FROM\s+(\w+)/);return a?p[y(a[1])]?.fields||{}:{}}function y(n){return n.replace(/^_content_/,"")}let r;const u=new Map,s=new Map;function x(n){async function a(e){const t=String(e);return r||(s.has("_")||s.set("_",S()),r=await s.get("_"),s.delete("_")),u.has(t)||(s.has(t)||s.set(t,_(e)),await s.get(t),u.set(t,"loaded"),s.delete(t)),r}return{all:async(e,t)=>(await a(n),r.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).map(o=>l(e,o))),first:async(e,t)=>(await a(n),l(e,r.exec({sql:e,bind:t,rowMode:"object",returnValue:"resultRows"}).shift())),exec:async(e,t)=>{await a(n),await r.exec({sql:e,bind:t})}}}async function S(){if(!r){const n=await w(()=>import("./Na41S91A.js"),__vite__mapDeps([0,1,2]),import.meta.url).then(e=>e.default);globalThis.sqlite3ApiConfig={silent:!0,debug:(...e)=>console.debug(...e),warn:(...e)=>{String(e[0]).includes("OPFS sqlite3_vfs")||console.warn(...e)},error:(...e)=>console.error(...e),log:(...e)=>console.log(...e)};const a=await n();r=new a.oo1.DB}return r}async function _(n){if(window.sessionStorage.getItem("previewToken"))return r;let a=null;const e=`checksum_${n}`,t=`collection_${n}`;let o="matched";try{r.exec({sql:`SELECT * FROM ${d.info} where id = '${e}'`,rowMode:"object",returnValue:"resultRows"}).shift()?.version!==f[String(n)]&&(o="mismatch")}catch{o="missing"}if(o!=="matched"){if(window.localStorage.getItem(`content_${e}`)===f[String(n)]&&(a=window.localStorage.getItem(`content_${t}`)),!a){a=await b(void 0,String(n));try{window.localStorage.setItem(`content_${e}`,f[String(n)]),window.localStorage.setItem(`content_${t}`,a)}catch(i){console.error("Database integrity check failed, rebuilding database",i)}}const c=await h(a);await r.exec({sql:`DROP TABLE IF EXISTS ${d[String(n)]}`}),o==="mismatch"&&await r.exec({sql:`DELETE FROM ${d.info} WHERE id = '${e}'`});for(const i of c)try{await r.exec(i)}catch(m){console.error("Error executing command",m)}}return r}export{x as loadDatabaseAdapter};
