-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.js
More file actions
1 lines (1 loc) · 4.07 KB
/
Copy pathindex.js
File metadata and controls
1 lines (1 loc) · 4.07 KB
1
function e(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}const{isArray:t}=Array;class n extends String{}const{defineProperty:r}=Object,o=(e,r)=>(o,...s)=>new Promise(((c,a)=>{if(o.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",a(e)}else{const[l,...i]=((e,...r)=>{const o=[e[0]],s=[o];for(let c=0;c<r.length;c++)r[c]instanceof n?o[o.length-1]+=r[c]+e[c+1]:(t(r[c])?(o.push(...r[c].slice(1).map((e=>","))),s.push(...r[c])):s.push(r[c]),o.push(e[c+1]));return s})(o,...s);e[r](l.join("?"),i,((e,t)=>{e?a(e):c(t)}))}}));function s(t){const s=o(t,"run");return{transaction(){let e=s(["BEGIN TRANSACTION"]);return r(((...t)=>{e=e.then((()=>s(...t)))}),"commit",{value:()=>e=e.then((()=>s(["COMMIT"])))})},all:o(t,"all"),get:o(t,"get"),raw:(t,...r)=>{return o=e(t,...r),new n(o);var o},close:()=>t.close(),query:s}}const{assign:c}=Object,a="function"==typeof importScripts,l=a?".":import.meta.url.replace(/\/[^/]*$/,""),i=e=>new Promise(((t,n)=>{const r=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,t(e)};if(self.exports={},self.module={exports:exports},a)importScripts(e),r();else{const{head:t}=document;c(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),r()},onerror:n,src:e})}})),u="sqlite",p="buffer",d=(e,t=1)=>new Promise(((n,r)=>{c(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains(u)||e.createObjectStore(u).createIndex(p,p,{unique:!0}),c(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})})),m=(e={})=>new Promise(((t,n)=>{const r=e.dist||l;i(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([d(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const a=e=>r.transaction([u],e).objectStore(u);c(a("readonly").get(p),{onsuccess(){let n=Promise.resolve();const{result:r}=this,l=new o(r||e.database||new Uint8Array(0)),i=()=>n=n.then((()=>new Promise(((t,n)=>{const r=l.export();c(a("readwrite").put(r,p).transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))));r||i();const{all:u,get:d,query:m,raw:f,transaction:g}=s({all(e,t,n){try{const r=l.exec(e,t),o=[];r.forEach(h,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=l.exec(e+" LIMIT 1",t),o=[];r.forEach(h,o),n(null,o.shift()||null)}catch(e){n(e)}},run(e,t,n){try{n(null,l.run(e,t))}catch(e){n(e)}}});let w=0;t({all:u,get:d,raw:f,transaction:g,create_function:(e,t)=>l.create_function(e,t),close:()=>(clearTimeout(w),i().then((()=>l.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(w),w=setTimeout(i,e.timeout||250)),m.apply(this,arguments)}})},onerror:n})}),n)}))}));function h({columns:e,values:t}){for(let{length:n}=t,r=0;r<n;r++){const n=t[r],o={};for(let{length:t}=e,r=0;r<t;r++)o[e[r]]=n[r];this.push(o)}}const f=new WeakMap,g=(e,t)=>{const n=[e[0]],r=[];for(let o=0,s=0,c=0,{length:a}=t;s<a;s++)t[s]instanceof w?n[o]+=t[s].v+e[s+1]:(r[c++]=s,n[++o]=e[s+1]);return{t:n,v:r}};function w(e){this.v=e}const{defineProperty:y}=Object,v=new Map,b=(t,...n)=>new w(e(t,...n));let j=0;function E(e={}){const{credentials:t}=e,n=e.dist||l,r=e.worker||n+"/worker.js",o=e=>(t,...n)=>{const[r,...o]=((e,...t)=>{const{t:n,v:r}=g(e,t),o=f.get(e)||f.set(e,{}).get(e);return(o[n]||(o[n]=[n])).concat(r.map((e=>t[e])))})(t,...n);return s(e,{template:r,values:o})},s=(e,t)=>new Promise(((n,r)=>{const o=j++;v.set(o,{resolve:n,reject:r}),a.postMessage({id:o,action:e,options:t})})),a=c(new Worker(/^(?:\.|\/)/.test(r)?r:(e=>URL.createObjectURL(new Blob([`importScripts('${e}')`],{type:"text/javascript"})))(r),{credentials:t}),{onmessage({data:{id:e,result:t,error:n}}){const{resolve:r,reject:o}=v.get(e);v.delete(e),n?o(n):r(t)}}),i=o("query");return s("init",c({dist:n,library:n+"/init.js"},e)).then((()=>({transaction(){let e=i(["BEGIN TRANSACTION"]);return y(((...t)=>{e=e.then((()=>i(...t)))}),"commit",{value:()=>e=e.then((()=>i(["COMMIT"])))})},close:()=>s("close"),create_function:(e,t)=>s("create_function",[e,t.toString()]),all:o("all"),get:o("get"),query:i,raw:b})))}export{E as SQLiteWorker,m as init};