Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sqlite-worker

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sqlite-worker - npm Package Compare versions

Comparing version 0.7.1 to 0.8.0

31

cjs/init.js

@@ -43,16 +43,14 @@ 'use strict';

const db = new Database(result || options.database || new Uint8Array(0));
const save = () => {
queue = queue.then(() => new Promise((resolve, onerror) => {
const uint8array = db.export();
assign(store('readwrite').put(uint8array, keyPath).transaction, {
oncomplete() {
resolve();
if (options.update)
options.update(uint8array);
},
onabort: onerror,
onerror
});
}));
};
const save = () => (queue = queue.then(() => new Promise((resolve, onerror) => {
const uint8array = db.export();
assign(store('readwrite').put(uint8array, keyPath).transaction, {
oncomplete() {
resolve();
if (options.update)
options.update(uint8array);
},
onabort: onerror,
onerror
});
})));
if (!result)

@@ -95,2 +93,7 @@ save();

all, get, raw, transaction,
create_function: (name, func) => db.create_function(name, func),
close: () => {
clearTimeout(t);
return save().then(() => db.close());
},
query(template) {

@@ -97,0 +100,0 @@ if (/\b(?:INSERT|DELETE|UPDATE)\b/i.test(template[0])) {

@@ -60,2 +60,7 @@ 'use strict';

},
close: () => post('close'),
create_function: (name, func) => post(
'create_function',
[name, func.toString()]
),
all: query('all'),

@@ -62,0 +67,0 @@ get: query('get'),

@@ -15,2 +15,24 @@ 'use strict';

}
else if (action === 'close') {
db.then(module => module.close().then(
() => {
postMessage({id});
},
({message: error}) => {
postMessage({id, error});
}
));
}
else if (action === 'create_function') {
db.then(module => {
try {
const [name, func] = options;
const result = module[action](name, Function('return ' + func)());
postMessage({id, result});
}
catch({message: error}) {
postMessage({id, error});
}
});
}
// action === `all` || `get` || `query`

@@ -17,0 +39,0 @@ else {

@@ -1,1 +0,1 @@

function e(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];return t}const{isArray:t}=Array;class r extends String{}const{defineProperty:n}=Object,o=(e,n)=>(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,...n)=>{const o=[e[0]],s=[o];for(let c=0;c<n.length;c++)n[c]instanceof r?o[o.length-1]+=n[c]+e[c+1]:(t(n[c])?(o.push(...n[c].slice(1).map((e=>","))),s.push(...n[c])):s.push(n[c]),o.push(e[c+1]));return s})(o,...s);e[n](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 n(((...t)=>{e=e.then((()=>s(...t)))}),"commit",{value:()=>e=e.then((()=>s(["COMMIT"])))})},all:o(t,"all"),get:o(t,"get"),raw:(t,...n)=>{return o=e(t,...n),new r(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,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,t(e)};if(self.exports={},self.module={exports:exports},a)importScripts(e),n();else{const{head:t}=document;c(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),n()},onerror:r,src:e})}})),u=(e,t=1)=>new Promise(((r,n)=>{c(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),c(t,{oncomplete(){r(e)}})},onsuccess({target:{result:e}}){r(e)},onerror:n})})),p=(e={})=>new Promise(((t,r)=>{const n=e.dist||l;i(n+"/sql-wasm.js").then((({default:o})=>{Promise.all([u(e.name||"sqlite-worker"),o({locateFile:e=>n+"/"+e})]).then((([n,{Database:o}])=>{const a=e=>n.transaction(["sqlite"],e).objectStore("sqlite");c(a("readonly").get("buffer"),{onsuccess(){let r=Promise.resolve();const{result:n}=this,l=new o(n||e.database||new Uint8Array(0)),i=()=>{r=r.then((()=>new Promise(((t,r)=>{const n=l.export();c(a("readwrite").put(n,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(n)},onabort:r,onerror:r})}))))};n||i();const{all:u,get:p,query:m,raw:f,transaction:h}=s({all(e,t,r){try{const n=l.exec(e,t),o=[];n.forEach(d,o),r(null,o)}catch(e){r(e)}},get(e,t,r){try{const n=l.exec(e+" LIMIT 1",t),o=[];n.forEach(d,o),r(null,o.shift()||null)}catch(e){r(e)}},run(e,t,r){try{r(null,l.run(e,t))}catch(e){r(e)}}});let g=0;t({all:u,get:p,raw:f,transaction:h,query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(g),g=setTimeout(i,e.timeout||250)),m.apply(this,arguments)}})},onerror:r})}),r)}))}));function d({columns:e,values:t}){for(let{length:r}=t,n=0;n<r;n++){const r=t[n],o={};for(let{length:t}=e,n=0;n<t;n++)o[e[n]]=r[n];this.push(o)}}const m=new WeakMap,f=(e,t)=>{const r=[e[0]],n=[];for(let o=0,s=0,c=0,{length:a}=t;s<a;s++)t[s]instanceof h?r[o]+=t[s].v+e[s+1]:(n[c++]=s,r[++o]=e[s+1]);return{t:r,v:n}};function h(e){this.v=e}const{defineProperty:g}=Object,w=new Map,b=(t,...r)=>new h(e(t,...r));let y=0;function v(e={}){const{credentials:t}=e,r=e.dist||l,n=e.worker||r+"/worker.js",o=e=>(t,...r)=>{const[n,...o]=((e,...t)=>{const{t:r,v:n}=f(e,t),o=m.get(e)||m.set(e,{}).get(e);return(o[r]||(o[r]=[r])).concat(n.map((e=>t[e])))})(t,...r);return s(e,{template:n,values:o})},s=(e,t)=>new Promise(((r,n)=>{const o=y++;w.set(o,{resolve:r,reject:n}),a.postMessage({id:o,action:e,options:t})})),a=c(new Worker(/^(?:\.|\/)/.test(n)?n:(e=>URL.createObjectURL(new Blob([`importScripts('${e}')`],{type:"text/javascript"})))(n),{credentials:t}),{onmessage({data:{id:e,result:t,error:r}}){const{resolve:n,reject:o}=w.get(e);w.delete(e),r?o(r):n(t)}}),i=o("query");return s("init",c({dist:r,library:r+"/init.js"},e)).then((()=>({transaction(){let e=i(["BEGIN TRANSACTION"]);return g(((...t)=>{e=e.then((()=>i(...t)))}),"commit",{value:()=>e=e.then((()=>i(["COMMIT"])))})},all:o("all"),get:o("get"),query:i,raw:b})))}export{v as SQLiteWorker,p as init};
function e(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];return t}const{isArray:t}=Array;class r extends String{}const{defineProperty:n}=Object,o=(e,n)=>(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,...n)=>{const o=[e[0]],s=[o];for(let c=0;c<n.length;c++)n[c]instanceof r?o[o.length-1]+=n[c]+e[c+1]:(t(n[c])?(o.push(...n[c].slice(1).map((e=>","))),s.push(...n[c])):s.push(n[c]),o.push(e[c+1]));return s})(o,...s);e[n](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 n(((...t)=>{e=e.then((()=>s(...t)))}),"commit",{value:()=>e=e.then((()=>s(["COMMIT"])))})},all:o(t,"all"),get:o(t,"get"),raw:(t,...n)=>{return o=e(t,...n),new r(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,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,t(e)};if(self.exports={},self.module={exports:exports},a)importScripts(e),n();else{const{head:t}=document;c(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),n()},onerror:r,src:e})}})),u=(e,t=1)=>new Promise(((r,n)=>{c(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),c(t,{oncomplete(){r(e)}})},onsuccess({target:{result:e}}){r(e)},onerror:n})})),p=(e={})=>new Promise(((t,r)=>{const n=e.dist||l;i(n+"/sql-wasm.js").then((({default:o})=>{Promise.all([u(e.name||"sqlite-worker"),o({locateFile:e=>n+"/"+e})]).then((([n,{Database:o}])=>{const a=e=>n.transaction(["sqlite"],e).objectStore("sqlite");c(a("readonly").get("buffer"),{onsuccess(){let r=Promise.resolve();const{result:n}=this,l=new o(n||e.database||new Uint8Array(0)),i=()=>r=r.then((()=>new Promise(((t,r)=>{const n=l.export();c(a("readwrite").put(n,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(n)},onabort:r,onerror:r})}))));n||i();const{all:u,get:p,query:f,raw:m,transaction:h}=s({all(e,t,r){try{const n=l.exec(e,t),o=[];n.forEach(d,o),r(null,o)}catch(e){r(e)}},get(e,t,r){try{const n=l.exec(e+" LIMIT 1",t),o=[];n.forEach(d,o),r(null,o.shift()||null)}catch(e){r(e)}},run(e,t,r){try{r(null,l.run(e,t))}catch(e){r(e)}}});let g=0;t({all:u,get:p,raw:m,transaction:h,create_function:(e,t)=>l.create_function(e,t),close:()=>(clearTimeout(g),i().then((()=>l.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(g),g=setTimeout(i,e.timeout||250)),f.apply(this,arguments)}})},onerror:r})}),r)}))}));function d({columns:e,values:t}){for(let{length:r}=t,n=0;n<r;n++){const r=t[n],o={};for(let{length:t}=e,n=0;n<t;n++)o[e[n]]=r[n];this.push(o)}}const f=new WeakMap,m=(e,t)=>{const r=[e[0]],n=[];for(let o=0,s=0,c=0,{length:a}=t;s<a;s++)t[s]instanceof h?r[o]+=t[s].v+e[s+1]:(n[c++]=s,r[++o]=e[s+1]);return{t:r,v:n}};function h(e){this.v=e}const{defineProperty:g}=Object,w=new Map,b=(t,...r)=>new h(e(t,...r));let y=0;function v(e={}){const{credentials:t}=e,r=e.dist||l,n=e.worker||r+"/worker.js",o=e=>(t,...r)=>{const[n,...o]=((e,...t)=>{const{t:r,v:n}=m(e,t),o=f.get(e)||f.set(e,{}).get(e);return(o[r]||(o[r]=[r])).concat(n.map((e=>t[e])))})(t,...r);return s(e,{template:n,values:o})},s=(e,t)=>new Promise(((r,n)=>{const o=y++;w.set(o,{resolve:r,reject:n}),a.postMessage({id:o,action:e,options:t})})),a=c(new Worker(/^(?:\.|\/)/.test(n)?n:(e=>URL.createObjectURL(new Blob([`importScripts('${e}')`],{type:"text/javascript"})))(n),{credentials:t}),{onmessage({data:{id:e,result:t,error:r}}){const{resolve:n,reject:o}=w.get(e);w.delete(e),r?o(r):n(t)}}),i=o("query");return s("init",c({dist:r,library:r+"/init.js"},e)).then((()=>({transaction(){let e=i(["BEGIN TRANSACTION"]);return g(((...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{v as SQLiteWorker,p as init};

@@ -1,1 +0,1 @@

const{isArray:e}=Array;class t extends String{}const{defineProperty:r}=Object,n=(r,n)=>(o,...s)=>new Promise(((l,c)=>{if(o.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",c(e)}else{const[a,...i]=((r,...n)=>{const o=[r[0]],s=[o];for(let l=0;l<n.length;l++)n[l]instanceof t?o[o.length-1]+=n[l]+r[l+1]:(e(n[l])?(o.push(...n[l].slice(1).map((e=>","))),s.push(...n[l])):s.push(n[l]),o.push(r[l+1]));return s})(o,...s);r[n](a.join("?"),i,((e,t)=>{e?c(e):l(t)}))}}));function o(e){const o=n(e,"run");return{transaction(){let e=o(["BEGIN TRANSACTION"]);return r(((...t)=>{e=e.then((()=>o(...t)))}),"commit",{value:()=>e=e.then((()=>o(["COMMIT"])))})},all:n(e,"all"),get:n(e,"get"),raw:(e,...r)=>{return n=function(e){for(var t=e[0],r=1,n=arguments.length;r<n;r++)t+=arguments[r]+e[r];return t}(e,...r),new t(n);var n},close:()=>e.close(),query:o}}const{assign:s}=Object,l="function"==typeof importScripts,c=e=>new Promise(((t,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,t(e)};if(self.exports={},self.module={exports:exports},l)importScripts(e),n();else{const{head:t}=document;s(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),n()},onerror:r,src:e})}})),a=(e,t=1)=>new Promise(((r,n)=>{s(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),s(t,{oncomplete(){r(e)}})},onsuccess({target:{result:e}}){r(e)},onerror:n})}));function i({columns:e,values:t}){for(let{length:r}=t,n=0;n<r;n++){const r=t[n],o={};for(let{length:t}=e,n=0;n<t;n++)o[e[n]]=r[n];this.push(o)}}exports.init=(e={})=>new Promise(((t,r)=>{const n=e.dist||".";c(n+"/sql-wasm.js").then((({default:l})=>{Promise.all([a(e.name||"sqlite-worker"),l({locateFile:e=>n+"/"+e})]).then((([n,{Database:l}])=>{const c=e=>n.transaction(["sqlite"],e).objectStore("sqlite");s(c("readonly").get("buffer"),{onsuccess(){let r=Promise.resolve();const{result:n}=this,a=new l(n||e.database||new Uint8Array(0)),u=()=>{r=r.then((()=>new Promise(((t,r)=>{const n=a.export();s(c("readwrite").put(n,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(n)},onabort:r,onerror:r})}))))};n||u();const{all:p,get:d,query:f,raw:h,transaction:m}=o({all(e,t,r){try{const n=a.exec(e,t),o=[];n.forEach(i,o),r(null,o)}catch(e){r(e)}},get(e,t,r){try{const n=a.exec(e+" LIMIT 1",t),o=[];n.forEach(i,o),r(null,o.shift()||null)}catch(e){r(e)}},run(e,t,r){try{r(null,a.run(e,t))}catch(e){r(e)}}});let g=0;t({all:p,get:d,raw:h,transaction:m,query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(g),g=setTimeout(u,e.timeout||250)),f.apply(this,arguments)}})},onerror:r})}),r)}))}));
const{isArray:e}=Array;class t extends String{}const{defineProperty:n}=Object,r=(n,r)=>(o,...s)=>new Promise(((c,l)=>{if(o.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",l(e)}else{const[a,...i]=((n,...r)=>{const o=[n[0]],s=[o];for(let c=0;c<r.length;c++)r[c]instanceof t?o[o.length-1]+=r[c]+n[c+1]:(e(r[c])?(o.push(...r[c].slice(1).map((e=>","))),s.push(...r[c])):s.push(r[c]),o.push(n[c+1]));return s})(o,...s);n[r](a.join("?"),i,((e,t)=>{e?l(e):c(t)}))}}));function o(e){const o=r(e,"run");return{transaction(){let e=o(["BEGIN TRANSACTION"]);return n(((...t)=>{e=e.then((()=>o(...t)))}),"commit",{value:()=>e=e.then((()=>o(["COMMIT"])))})},all:r(e,"all"),get:r(e,"get"),raw:(e,...n)=>{return r=function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(e,...n),new t(r);var r},close:()=>e.close(),query:o}}const{assign:s}=Object,c="function"==typeof importScripts,l=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},c)importScripts(e),r();else{const{head:t}=document;s(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),r()},onerror:n,src:e})}})),a=(e,t=1)=>new Promise(((n,r)=>{s(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),s(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})}));function i({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)}}exports.init=(e={})=>new Promise(((t,n)=>{const r=e.dist||".";l(r+"/sql-wasm.js").then((({default:c})=>{Promise.all([a(e.name||"sqlite-worker"),c({locateFile:e=>r+"/"+e})]).then((([r,{Database:c}])=>{const l=e=>r.transaction(["sqlite"],e).objectStore("sqlite");s(l("readonly").get("buffer"),{onsuccess(){let n=Promise.resolve();const{result:r}=this,a=new c(r||e.database||new Uint8Array(0)),u=()=>n=n.then((()=>new Promise(((t,n)=>{const r=a.export();s(l("readwrite").put(r,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))));r||u();const{all:f,get:p,query:d,raw:h,transaction:m}=o({all(e,t,n){try{const r=a.exec(e,t),o=[];r.forEach(i,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=a.exec(e+" LIMIT 1",t),o=[];r.forEach(i,o),n(null,o.shift()||null)}catch(e){n(e)}},run(e,t,n){try{n(null,a.run(e,t))}catch(e){n(e)}}});let g=0;t({all:f,get:p,raw:h,transaction:m,create_function:(e,t)=>a.create_function(e,t),close:()=>(clearTimeout(g),u().then((()=>a.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(g),g=setTimeout(u,e.timeout||250)),d.apply(this,arguments)}})},onerror:n})}),n)}))}));

@@ -1,1 +0,1 @@

self.sqliteWorker=function(e){"use strict";const t=["name","type","notnull","dflt_value","pk"],{keys:n}=Object,r=(e,t,r)=>new Promise(((i,u)=>{const m=o(t),h=n(r);e.all(`PRAGMA table_info('${m}')`,((t,n)=>{const{length:p}=n,f=h.map(c,r),d=`tmp_${m}_backup`,E=`CREATE TABLE IF NOT EXISTS '${p?d:m}' (${s(f)})`;p?e.run(E,(t=>{t?u(t):e.all(`PRAGMA table_info('${d}')`,((t,r)=>{if(n.length!==r.length||n.some(a,r)){const t=n.filter(l,r).map((e=>`'${o(e.name)}'`)),c=t.map((e=>`'${m}'.${e}`));e.run(`INSERT INTO '${d}' (${s(t)})\n SELECT ${s(c)} FROM '${m}'`,(t=>{t?e.run(`DROP TABLE IF EXISTS '${d}'`,(()=>u(t))):e.run(`DROP TABLE IF EXISTS '${m}'`,(()=>{e.run(`ALTER TABLE '${d}' RENAME TO '${m}'`,i)}))}))}else e.run(`DROP TABLE IF EXISTS '${d}'`,i)}))})):e.run(E,(e=>{e?u(e):i()}))}))})),o=e=>e.replace(/'/g,"''"),s=e=>e.join(", ");function l(e){return-1<this.findIndex((({name:t})=>t===e.name))}function c(e){return`'${o(e)}' ${this[e]}`}function a(e,n){const r=this[n];return t.some((t=>e[t]!==r[t]))}const i=(e,t)=>e(t).then((e=>t.tables?((e,t)=>new Promise(((o,s)=>{const l=[];for(const o of n(t))l.push(r(e,o,t[o]));Promise.all(l).then(o,s)})))((({all:e,query:t})=>({all(t,n){e([t]).then((e=>n(null,e)),n)},run(e,n){t([e]).then((()=>n()),n)}}))(e),t.tables).then((()=>e)):e));const{isArray:u}=Array;class m extends String{}const{defineProperty:h}=Object,p=(e,t)=>(n,...r)=>new Promise(((o,s)=>{if(n.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",s(e)}else{const[l,...c]=((e,...t)=>{const n=[e[0]],r=[n];for(let o=0;o<t.length;o++)t[o]instanceof m?n[n.length-1]+=t[o]+e[o+1]:(u(t[o])?(n.push(...t[o].slice(1).map((e=>","))),r.push(...t[o])):r.push(t[o]),n.push(e[o+1]));return r})(n,...r);e[t](l.join("?"),c,((e,t)=>{e?s(e):o(t)}))}}));function f(e){const t=p(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return h(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:p(e,"all"),get:p(e,"get"),raw:(e,...t)=>{return n=function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(e,...t),new m(n);var n},close:()=>e.close(),query:t}}const{assign:d}=Object,E="function"==typeof importScripts,T=t=>new Promise(((n,r)=>{const o=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,n(e)};if(self.exports={},self.module={exports:e},E)importScripts(t),o();else{const{head:e}=document;d(e.appendChild(document.createElement("script")),{onload(){e.removeChild(this),o()},onerror:r,src:t})}})),S="sqlite",g="buffer",I=(e,t=1)=>new Promise(((n,r)=>{d(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains(S)||e.createObjectStore(S).createIndex(g,g,{unique:!0}),d(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})})),$=(e={})=>new Promise(((t,n)=>{const r=e.dist||".";T(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([I(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const s=e=>r.transaction([S],e).objectStore(S);d(s("readonly").get(g),{onsuccess(){let n=Promise.resolve();const{result:r}=this,l=new o(r||e.database||new Uint8Array(0)),c=()=>{n=n.then((()=>new Promise(((t,n)=>{const r=l.export();d(s("readwrite").put(r,g).transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))))};r||c();const{all:a,get:i,query:u,raw:m,transaction:h}=f({all(e,t,n){try{const r=l.exec(e,t),o=[];r.forEach(A,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=l.exec(e+" LIMIT 1",t),o=[];r.forEach(A,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 p=0;t({all:a,get:i,raw:m,transaction:h,query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(p),p=setTimeout(c,e.timeout||250)),u.apply(this,arguments)}})},onerror:n})}),n)}))}));function A({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)}}return(e={})=>i($,e)}({});
self.sqliteWorker=function(e){"use strict";const t=["name","type","notnull","dflt_value","pk"],{keys:n}=Object,r=(e,t,r)=>new Promise(((i,u)=>{const m=o(t),h=n(r);e.all(`PRAGMA table_info('${m}')`,((t,n)=>{const{length:f}=n,p=h.map(c,r),d=`tmp_${m}_backup`,E=`CREATE TABLE IF NOT EXISTS '${f?d:m}' (${s(p)})`;f?e.run(E,(t=>{t?u(t):e.all(`PRAGMA table_info('${d}')`,((t,r)=>{if(n.length!==r.length||n.some(a,r)){const t=n.filter(l,r).map((e=>`'${o(e.name)}'`)),c=t.map((e=>`'${m}'.${e}`));e.run(`INSERT INTO '${d}' (${s(t)})\n SELECT ${s(c)} FROM '${m}'`,(t=>{t?e.run(`DROP TABLE IF EXISTS '${d}'`,(()=>u(t))):e.run(`DROP TABLE IF EXISTS '${m}'`,(()=>{e.run(`ALTER TABLE '${d}' RENAME TO '${m}'`,i)}))}))}else e.run(`DROP TABLE IF EXISTS '${d}'`,i)}))})):e.run(E,(e=>{e?u(e):i()}))}))})),o=e=>e.replace(/'/g,"''"),s=e=>e.join(", ");function l(e){return-1<this.findIndex((({name:t})=>t===e.name))}function c(e){return`'${o(e)}' ${this[e]}`}function a(e,n){const r=this[n];return t.some((t=>e[t]!==r[t]))}const i=(e,t)=>e(t).then((e=>t.tables?((e,t)=>new Promise(((o,s)=>{const l=[];for(const o of n(t))l.push(r(e,o,t[o]));Promise.all(l).then(o,s)})))((({all:e,query:t})=>({all(t,n){e([t]).then((e=>n(null,e)),n)},run(e,n){t([e]).then((()=>n()),n)}}))(e),t.tables).then((()=>e)):e));const{isArray:u}=Array;class m extends String{}const{defineProperty:h}=Object,f=(e,t)=>(n,...r)=>new Promise(((o,s)=>{if(n.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",s(e)}else{const[l,...c]=((e,...t)=>{const n=[e[0]],r=[n];for(let o=0;o<t.length;o++)t[o]instanceof m?n[n.length-1]+=t[o]+e[o+1]:(u(t[o])?(n.push(...t[o].slice(1).map((e=>","))),r.push(...t[o])):r.push(t[o]),n.push(e[o+1]));return r})(n,...r);e[t](l.join("?"),c,((e,t)=>{e?s(e):o(t)}))}}));function p(e){const t=f(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return h(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:f(e,"all"),get:f(e,"get"),raw:(e,...t)=>{return n=function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(e,...t),new m(n);var n},close:()=>e.close(),query:t}}const{assign:d}=Object,E="function"==typeof importScripts,T=t=>new Promise(((n,r)=>{const o=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,n(e)};if(self.exports={},self.module={exports:e},E)importScripts(t),o();else{const{head:e}=document;d(e.appendChild(document.createElement("script")),{onload(){e.removeChild(this),o()},onerror:r,src:t})}})),S="sqlite",g="buffer",I=(e,t=1)=>new Promise(((n,r)=>{d(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains(S)||e.createObjectStore(S).createIndex(g,g,{unique:!0}),d(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})})),$=(e={})=>new Promise(((t,n)=>{const r=e.dist||".";T(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([I(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const s=e=>r.transaction([S],e).objectStore(S);d(s("readonly").get(g),{onsuccess(){let n=Promise.resolve();const{result:r}=this,l=new o(r||e.database||new Uint8Array(0)),c=()=>n=n.then((()=>new Promise(((t,n)=>{const r=l.export();d(s("readwrite").put(r,g).transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))));r||c();const{all:a,get:i,query:u,raw:m,transaction:h}=p({all(e,t,n){try{const r=l.exec(e,t),o=[];r.forEach(A,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=l.exec(e+" LIMIT 1",t),o=[];r.forEach(A,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 f=0;t({all:a,get:i,raw:m,transaction:h,create_function:(e,t)=>l.create_function(e,t),close:()=>(clearTimeout(f),c().then((()=>l.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(f),f=setTimeout(c,e.timeout||250)),u.apply(this,arguments)}})},onerror:n})}),n)}))}));function A({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)}}return(e={})=>i($,e)}({});

@@ -1,1 +0,1 @@

self.sqliteWorker=function(e){"use strict";const{isArray:t}=Array;class n extends String{}const{defineProperty:r}=Object,o=(e,r)=>(o,...s)=>new Promise(((c,l)=>{if(o.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",l(e)}else{const[a,...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](a.join("?"),i,((e,t)=>{e?l(e):c(t)}))}}));function s(e){const t=o(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return r(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:o(e,"all"),get:o(e,"get"),raw:(e,...t)=>{return r=function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(e,...t),new n(r);var r},close:()=>e.close(),query:t}}const{assign:c}=Object,l="function"==typeof importScripts,a=t=>new Promise(((n,r)=>{const o=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,n(e)};if(self.exports={},self.module={exports:e},l)importScripts(t),o();else{const{head:e}=document;c(e.appendChild(document.createElement("script")),{onload(){e.removeChild(this),o()},onerror:r,src:t})}})),i="sqlite",u="buffer",d=(e,t=1)=>new Promise(((n,r)=>{c(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains(i)||e.createObjectStore(i).createIndex(u,u,{unique:!0}),c(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})}));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)}}return(e={})=>new Promise(((t,n)=>{const r=e.dist||".";a(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([d(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const l=e=>r.transaction([i],e).objectStore(i);c(l("readonly").get(u),{onsuccess(){let n=Promise.resolve();const{result:r}=this,a=new o(r||e.database||new Uint8Array(0)),i=()=>{n=n.then((()=>new Promise(((t,n)=>{const r=a.export();c(l("readwrite").put(r,u).transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))))};r||i();const{all:d,get:m,query:p,raw:f,transaction:g}=s({all(e,t,n){try{const r=a.exec(e,t),o=[];r.forEach(h,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=a.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,a.run(e,t))}catch(e){n(e)}}});let w=0;t({all:d,get:m,raw:f,transaction:g,query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(w),w=setTimeout(i,e.timeout||250)),p.apply(this,arguments)}})},onerror:n})}),n)}))}))}({});
self.sqliteWorker=function(e){"use strict";const{isArray:t}=Array;class n extends String{}const{defineProperty:r}=Object,o=(e,r)=>(o,...s)=>new Promise(((c,l)=>{if(o.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",l(e)}else{const[a,...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](a.join("?"),i,((e,t)=>{e?l(e):c(t)}))}}));function s(e){const t=o(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return r(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:o(e,"all"),get:o(e,"get"),raw:(e,...t)=>{return r=function(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}(e,...t),new n(r);var r},close:()=>e.close(),query:t}}const{assign:c}=Object,l="function"==typeof importScripts,a=t=>new Promise(((n,r)=>{const o=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,n(e)};if(self.exports={},self.module={exports:e},l)importScripts(t),o();else{const{head:e}=document;c(e.appendChild(document.createElement("script")),{onload(){e.removeChild(this),o()},onerror:r,src:t})}})),i="sqlite",u="buffer",d=(e,t=1)=>new Promise(((n,r)=>{c(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains(i)||e.createObjectStore(i).createIndex(u,u,{unique:!0}),c(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})}));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)}}return(e={})=>new Promise(((t,n)=>{const r=e.dist||".";a(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([d(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const l=e=>r.transaction([i],e).objectStore(i);c(l("readonly").get(u),{onsuccess(){let n=Promise.resolve();const{result:r}=this,a=new o(r||e.database||new Uint8Array(0)),i=()=>n=n.then((()=>new Promise(((t,n)=>{const r=a.export();c(l("readwrite").put(r,u).transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))));r||i();const{all:d,get:m,query:p,raw:f,transaction:g}=s({all(e,t,n){try{const r=a.exec(e,t),o=[];r.forEach(h,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=a.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,a.run(e,t))}catch(e){n(e)}}});let w=0;t({all:d,get:m,raw:f,transaction:g,create_function:(e,t)=>a.create_function(e,t),close:()=>(clearTimeout(w),i().then((()=>a.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(w),w=setTimeout(i,e.timeout||250)),p.apply(this,arguments)}})},onerror:n})}),n)}))}))}({});

@@ -1,1 +0,1 @@

const e=["name","type","notnull","dflt_value","pk"],{keys:t}=Object,n=(e,n,c)=>new Promise(((i,u)=>{const p=r(n),m=t(c);e.all(`PRAGMA table_info('${p}')`,((t,n)=>{const{length:f}=n,h=m.map(l,c),d=`tmp_${p}_backup`,E=`CREATE TABLE IF NOT EXISTS '${f?d:p}' (${o(h)})`;f?e.run(E,(t=>{t?u(t):e.all(`PRAGMA table_info('${d}')`,((t,l)=>{if(n.length!==l.length||n.some(a,l)){const t=n.filter(s,l).map((e=>`'${r(e.name)}'`)),a=t.map((e=>`'${p}'.${e}`));e.run(`INSERT INTO '${d}' (${o(t)})\n SELECT ${o(a)} FROM '${p}'`,(t=>{t?e.run(`DROP TABLE IF EXISTS '${d}'`,(()=>u(t))):e.run(`DROP TABLE IF EXISTS '${p}'`,(()=>{e.run(`ALTER TABLE '${d}' RENAME TO '${p}'`,i)}))}))}else e.run(`DROP TABLE IF EXISTS '${d}'`,i)}))})):e.run(E,(e=>{e?u(e):i()}))}))})),r=e=>e.replace(/'/g,"''"),o=e=>e.join(", ");function s(e){return-1<this.findIndex((({name:t})=>t===e.name))}function l(e){return`'${r(e)}' ${this[e]}`}function a(t,n){const r=this[n];return e.some((e=>t[e]!==r[e]))}const c=(e,r)=>e(r).then((e=>r.tables?((e,r)=>new Promise(((o,s)=>{const l=[];for(const o of t(r))l.push(n(e,o,r[o]));Promise.all(l).then(o,s)})))((({all:e,query:t})=>({all(t,n){e([t]).then((e=>n(null,e)),n)},run(e,n){t([e]).then((()=>n()),n)}}))(e),r.tables).then((()=>e)):e));function i(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}const{isArray:u}=Array;class p extends String{}const{defineProperty:m}=Object,f=(e,t)=>(n,...r)=>new Promise(((o,s)=>{if(n.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",s(e)}else{const[l,...a]=((e,...t)=>{const n=[e[0]],r=[n];for(let o=0;o<t.length;o++)t[o]instanceof p?n[n.length-1]+=t[o]+e[o+1]:(u(t[o])?(n.push(...t[o].slice(1).map((e=>","))),r.push(...t[o])):r.push(t[o]),n.push(e[o+1]));return r})(n,...r);e[t](l.join("?"),a,((e,t)=>{e?s(e):o(t)}))}}));function h(e){const t=f(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return m(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:f(e,"all"),get:f(e,"get"),raw:(e,...t)=>{return n=i(e,...t),new p(n);var n},close:()=>e.close(),query:t}}const{assign:d}=Object,E="function"==typeof importScripts,T=E?".":import.meta.url.replace(/\/[^/]*$/,""),g=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},E)importScripts(e),r();else{const{head:t}=document;d(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),r()},onerror:n,src:e})}})),w=(e,t=1)=>new Promise(((n,r)=>{d(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),d(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})})),b=(e={})=>new Promise(((t,n)=>{const r=e.dist||T;g(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([w(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const s=e=>r.transaction(["sqlite"],e).objectStore("sqlite");d(s("readonly").get("buffer"),{onsuccess(){let n=Promise.resolve();const{result:r}=this,l=new o(r||e.database||new Uint8Array(0)),a=()=>{n=n.then((()=>new Promise(((t,n)=>{const r=l.export();d(s("readwrite").put(r,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))))};r||a();const{all:c,get:i,query:u,raw:p,transaction:m}=h({all(e,t,n){try{const r=l.exec(e,t),o=[];r.forEach(I,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=l.exec(e+" LIMIT 1",t),o=[];r.forEach(I,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 f=0;t({all:c,get:i,raw:p,transaction:m,query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(f),f=setTimeout(a,e.timeout||250)),u.apply(this,arguments)}})},onerror:n})}),n)}))}));function I({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 S=(e={})=>c(b,e),y=new WeakMap,R=(e,t)=>{const n=[e[0]],r=[];for(let o=0,s=0,l=0,{length:a}=t;s<a;s++)t[s]instanceof $?n[o]+=t[s].v+e[s+1]:(r[l++]=s,n[++o]=e[s+1]);return{t:n,v:r}};function $(e){this.v=e}const{defineProperty:A}=Object,O=new Map,P=(e,...t)=>new $(i(e,...t));let j=0;function v(e={}){const{credentials:t}=e,n=e.dist||T,r=e.worker||n+"/worker.js",o=e=>(t,...n)=>{const[r,...o]=((e,...t)=>{const{t:n,v:r}=R(e,t),o=y.get(e)||y.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++;O.set(o,{resolve:n,reject:r}),l.postMessage({id:o,action:e,options:t})})),l=d(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}=O.get(e);O.delete(e),n?o(n):r(t)}}),a=o("query");return s("init",d({dist:n,library:n+"/init.js"},e)).then((()=>({transaction(){let e=a(["BEGIN TRANSACTION"]);return A(((...t)=>{e=e.then((()=>a(...t)))}),"commit",{value:()=>e=e.then((()=>a(["COMMIT"])))})},all:o("all"),get:o("get"),query:a,raw:P})))}function x(e={}){return c(v,e)}export{x as SQLiteWorker,S as init};
const e=["name","type","notnull","dflt_value","pk"],{keys:t}=Object,n=(e,n,a)=>new Promise(((i,u)=>{const p=r(n),m=t(a);e.all(`PRAGMA table_info('${p}')`,((t,n)=>{const{length:f}=n,h=m.map(c,a),d=`tmp_${p}_backup`,E=`CREATE TABLE IF NOT EXISTS '${f?d:p}' (${o(h)})`;f?e.run(E,(t=>{t?u(t):e.all(`PRAGMA table_info('${d}')`,((t,c)=>{if(n.length!==c.length||n.some(l,c)){const t=n.filter(s,c).map((e=>`'${r(e.name)}'`)),l=t.map((e=>`'${p}'.${e}`));e.run(`INSERT INTO '${d}' (${o(t)})\n SELECT ${o(l)} FROM '${p}'`,(t=>{t?e.run(`DROP TABLE IF EXISTS '${d}'`,(()=>u(t))):e.run(`DROP TABLE IF EXISTS '${p}'`,(()=>{e.run(`ALTER TABLE '${d}' RENAME TO '${p}'`,i)}))}))}else e.run(`DROP TABLE IF EXISTS '${d}'`,i)}))})):e.run(E,(e=>{e?u(e):i()}))}))})),r=e=>e.replace(/'/g,"''"),o=e=>e.join(", ");function s(e){return-1<this.findIndex((({name:t})=>t===e.name))}function c(e){return`'${r(e)}' ${this[e]}`}function l(t,n){const r=this[n];return e.some((e=>t[e]!==r[e]))}const a=(e,r)=>e(r).then((e=>r.tables?((e,r)=>new Promise(((o,s)=>{const c=[];for(const o of t(r))c.push(n(e,o,r[o]));Promise.all(c).then(o,s)})))((({all:e,query:t})=>({all(t,n){e([t]).then((e=>n(null,e)),n)},run(e,n){t([e]).then((()=>n()),n)}}))(e),r.tables).then((()=>e)):e));function i(e){for(var t=e[0],n=1,r=arguments.length;n<r;n++)t+=arguments[n]+e[n];return t}const{isArray:u}=Array;class p extends String{}const{defineProperty:m}=Object,f=(e,t)=>(n,...r)=>new Promise(((o,s)=>{if(n.some((e=>e.includes("?")))){const e=new Error("SQLITE_ERROR: SQL injection hazard");e.code="SQLITE_ERROR",s(e)}else{const[c,...l]=((e,...t)=>{const n=[e[0]],r=[n];for(let o=0;o<t.length;o++)t[o]instanceof p?n[n.length-1]+=t[o]+e[o+1]:(u(t[o])?(n.push(...t[o].slice(1).map((e=>","))),r.push(...t[o])):r.push(t[o]),n.push(e[o+1]));return r})(n,...r);e[t](c.join("?"),l,((e,t)=>{e?s(e):o(t)}))}}));function h(e){const t=f(e,"run");return{transaction(){let e=t(["BEGIN TRANSACTION"]);return m(((...n)=>{e=e.then((()=>t(...n)))}),"commit",{value:()=>e=e.then((()=>t(["COMMIT"])))})},all:f(e,"all"),get:f(e,"get"),raw:(e,...t)=>{return n=i(e,...t),new p(n);var n},close:()=>e.close(),query:t}}const{assign:d}=Object,E="function"==typeof importScripts,T=E?".":import.meta.url.replace(/\/[^/]*$/,""),g=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},E)importScripts(e),r();else{const{head:t}=document;d(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),r()},onerror:n,src:e})}})),w=(e,t=1)=>new Promise(((n,r)=>{d(indexedDB.open(e,t),{onupgradeneeded({target:{result:e,transaction:t}}){e.objectStoreNames.contains("sqlite")||e.createObjectStore("sqlite").createIndex("buffer","buffer",{unique:!0}),d(t,{oncomplete(){n(e)}})},onsuccess({target:{result:e}}){n(e)},onerror:r})})),b=(e={})=>new Promise(((t,n)=>{const r=e.dist||T;g(r+"/sql-wasm.js").then((({default:o})=>{Promise.all([w(e.name||"sqlite-worker"),o({locateFile:e=>r+"/"+e})]).then((([r,{Database:o}])=>{const s=e=>r.transaction(["sqlite"],e).objectStore("sqlite");d(s("readonly").get("buffer"),{onsuccess(){let n=Promise.resolve();const{result:r}=this,c=new o(r||e.database||new Uint8Array(0)),l=()=>n=n.then((()=>new Promise(((t,n)=>{const r=c.export();d(s("readwrite").put(r,"buffer").transaction,{oncomplete(){t(),e.update&&e.update(r)},onabort:n,onerror:n})}))));r||l();const{all:a,get:i,query:u,raw:p,transaction:m}=h({all(e,t,n){try{const r=c.exec(e,t),o=[];r.forEach(S,o),n(null,o)}catch(e){n(e)}},get(e,t,n){try{const r=c.exec(e+" LIMIT 1",t),o=[];r.forEach(S,o),n(null,o.shift()||null)}catch(e){n(e)}},run(e,t,n){try{n(null,c.run(e,t))}catch(e){n(e)}}});let f=0;t({all:a,get:i,raw:p,transaction:m,create_function:(e,t)=>c.create_function(e,t),close:()=>(clearTimeout(f),l().then((()=>c.close()))),query(t){return/\b(?:INSERT|DELETE|UPDATE)\b/i.test(t[0])&&(clearTimeout(f),f=setTimeout(l,e.timeout||250)),u.apply(this,arguments)}})},onerror:n})}),n)}))}));function S({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 I=(e={})=>a(b,e),y=new WeakMap,R=(e,t)=>{const n=[e[0]],r=[];for(let o=0,s=0,c=0,{length:l}=t;s<l;s++)t[s]instanceof $?n[o]+=t[s].v+e[s+1]:(r[c++]=s,n[++o]=e[s+1]);return{t:n,v:r}};function $(e){this.v=e}const{defineProperty:A}=Object,O=new Map,P=(e,...t)=>new $(i(e,...t));let j=0;function v(e={}){const{credentials:t}=e,n=e.dist||T,r=e.worker||n+"/worker.js",o=e=>(t,...n)=>{const[r,...o]=((e,...t)=>{const{t:n,v:r}=R(e,t),o=y.get(e)||y.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++;O.set(o,{resolve:n,reject:r}),c.postMessage({id:o,action:e,options:t})})),c=d(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}=O.get(e);O.delete(e),n?o(n):r(t)}}),l=o("query");return s("init",d({dist:n,library:n+"/init.js"},e)).then((()=>({transaction(){let e=l(["BEGIN TRANSACTION"]);return A(((...t)=>{e=e.then((()=>l(...t)))}),"commit",{value:()=>e=e.then((()=>l(["COMMIT"])))})},close:()=>s("close"),create_function:(e,t)=>s("create_function",[e,t.toString()]),all:o("all"),get:o("get"),query:l,raw:P})))}function x(e={}){return a(v,e)}export{x as SQLiteWorker,I as init};

@@ -1,1 +0,1 @@

!function(){"use strict";const{assign:e}=Object,t="function"==typeof importScripts;t||(document.currentScript&&document.currentScript.src||new URL("tmp.js",document.baseURI).href).replace(/\/[^/]*$/,"");const s=s=>new Promise(((o,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,o(e)};if(self.exports={},self.module={exports:exports},t)importScripts(s),n();else{const{head:t}=document;e(t.appendChild(document.createElement("script")),{onload(){t.removeChild(this),n()},onerror:r,src:s})}}));let o=null;addEventListener("message",(({data:{id:e,action:t,options:r}})=>{if("init"===t)o||(o=s(r.library).then((({init:e})=>e(r)))),o.then((()=>postMessage({id:e,result:"OK"})),(({message:t})=>postMessage({id:e,error:t})));else{const{template:s,values:n}=r;o.then((o=>{o[t](s,...n).then((t=>{postMessage({id:e,result:t})}),(({message:t})=>{postMessage({id:e,error:t})}))}))}}))}();
!function(){"use strict";const{assign:e}=Object,s="function"==typeof importScripts;s||(document.currentScript&&document.currentScript.src||new URL("tmp.js",document.baseURI).href).replace(/\/[^/]*$/,"");const t=t=>new Promise(((o,r)=>{const n=()=>{const e=self.module.exports;delete self.exports,self.module=void 0,o(e)};if(self.exports={},self.module={exports:exports},s)importScripts(t),n();else{const{head:s}=document;e(s.appendChild(document.createElement("script")),{onload(){s.removeChild(this),n()},onerror:r,src:t})}}));let o=null;addEventListener("message",(({data:{id:e,action:s,options:r}})=>{if("init"===s)o||(o=t(r.library).then((({init:e})=>e(r)))),o.then((()=>postMessage({id:e,result:"OK"})),(({message:s})=>postMessage({id:e,error:s})));else if("close"===s)o.then((s=>s.close().then((()=>{postMessage({id:e})}),(({message:s})=>{postMessage({id:e,error:s})}))));else if("create_function"===s)o.then((t=>{try{const[o,n]=r,i=t[s](o,Function("return "+n)());postMessage({id:e,result:i})}catch({message:s}){postMessage({id:e,error:s})}}));else{const{template:t,values:n}=r;o.then((o=>{o[s](t,...n).then((s=>{postMessage({id:e,result:s})}),(({message:s})=>{postMessage({id:e,error:s})}))}))}}))}();

@@ -42,16 +42,14 @@ import SQLiteTag from 'sqlite-tag';

const db = new Database(result || options.database || new Uint8Array(0));
const save = () => {
queue = queue.then(() => new Promise((resolve, onerror) => {
const uint8array = db.export();
assign(store('readwrite').put(uint8array, keyPath).transaction, {
oncomplete() {
resolve();
if (options.update)
options.update(uint8array);
},
onabort: onerror,
onerror
});
}));
};
const save = () => (queue = queue.then(() => new Promise((resolve, onerror) => {
const uint8array = db.export();
assign(store('readwrite').put(uint8array, keyPath).transaction, {
oncomplete() {
resolve();
if (options.update)
options.update(uint8array);
},
onabort: onerror,
onerror
});
})));
if (!result)

@@ -94,2 +92,7 @@ save();

all, get, raw, transaction,
create_function: (name, func) => db.create_function(name, func),
close: () => {
clearTimeout(t);
return save().then(() => db.close());
},
query(template) {

@@ -96,0 +99,0 @@ if (/\b(?:INSERT|DELETE|UPDATE)\b/i.test(template[0])) {

@@ -59,2 +59,7 @@ import plain from 'plain-tag';

},
close: () => post('close'),
create_function: (name, func) => post(
'create_function',
[name, func.toString()]
),
all: query('all'),

@@ -61,0 +66,0 @@ get: query('get'),

@@ -14,2 +14,24 @@ import {load} from './utils.js';

}
else if (action === 'close') {
db.then(module => module.close().then(
() => {
postMessage({id});
},
({message: error}) => {
postMessage({id, error});
}
));
}
else if (action === 'create_function') {
db.then(module => {
try {
const [name, func] = options;
const result = module[action](name, Function('return ' + func)());
postMessage({id, result});
}
catch({message: error}) {
postMessage({id, error});
}
});
}
// action === `all` || `get` || `query`

@@ -16,0 +38,0 @@ else {

{
"name": "sqlite-worker",
"version": "0.7.1",
"version": "0.8.0",
"description": "A simple, and persistent, SQLite database for Web and Workers",

@@ -27,3 +27,3 @@ "main": "./cjs/index.js",

"devDependencies": {
"@babel/core": "^7.17.5",
"@babel/core": "^7.17.8",
"@babel/preset-env": "^7.16.11",

@@ -30,0 +30,0 @@ "@rollup/plugin-babel": "^5.3.1",

@@ -155,2 +155,4 @@ # sqlite-worker

* **transaction**: a function that returns a template literal tag to perform any statement until `tag.commit()` is awaited and executed.
* **close**: a function to force save and close the db at any time.
* **create_function**: a function to register custom SQLite functions. **Please note** when used as *Worker* it requires a **pure function** (no outer scope access) and **Function** evaluation. No limitations when used directly through init.

@@ -157,0 +159,0 @@ All tags, except the `raw` helper, are *asynchronous*, so that it's possible to *await* their result.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc