diff --git a/Makefile b/Makefile index bf8e49c..5c61bc8 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,13 @@ CFILES = \ libvfs.c \ $(CFILES_EXTRA) +JSFILES = \ + src/libauthorizer.js \ + src/libfunction.js \ + src/libmodule.js \ + src/libprogress.js \ + src/libvfs.js + vpath %.c src vpath %.c deps vpath %.c deps/$(SQLITE_VERSION) @@ -56,7 +63,7 @@ EMFLAGS_COMMON = \ EMFLAGS_DEBUG = \ -s ASSERTIONS=1 \ - -g -Oz \ + -g -Oz -Oz \ $(EMFLAGS_COMMON) EMFLAGS_DIST = \ diff --git a/README.md b/README.md index 1be7a5d..2517d84 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Here are the build steps: * `git clone git@github.com:rhashimoto/wa-sqlite.git` * `cd wa-sqlite` * `yarn install` -* `make` (or `yarn prepack`) +* `make` The default build produces ES6 modules + WASM, [synchronous and asynchronous](https://github.com/rhashimoto/wa-sqlite/issues/7) (using Asyncify) in `dist/`. diff --git a/dist/wa-sqlite-async.mjs b/dist/wa-sqlite-async.mjs index d96592b..002a9d6 100644 --- a/dist/wa-sqlite-async.mjs +++ b/dist/wa-sqlite-async.mjs @@ -34,7 +34,7 @@ function pb(a){for(var b;;){if(a===a.parent)return a=a.Jf.ng,b?"/"!==a[a.length- function eb(a,b){var c=P(a.mode)?(c=sb(a,"x"))?c:a.Af.Sf?0:2:54;if(c)throw new N(c);for(c=Q[qb(a.id,b)];c;c=c.Qf){var e=c.name;if(c.parent.id===a.id&&e===b)return c}return a.Af.Sf(a,b)}function cb(a,b,c,e){a=new nb(a,b,c,e);b=qb(a.parent.id,a.name);a.Qf=Q[b];return Q[b]=a}function P(a){return 16384===(a&61440)}function tb(a){var b=["r","w","rw"][a&3];a&512&&(b+="w");return b} function sb(a,b){if(lb)return 0;if(!b.includes("r")||a.mode&292){if(b.includes("w")&&!(a.mode&146)||b.includes("x")&&!(a.mode&73))return 2}else return 2;return 0}function ub(a,b){try{return eb(a,b),20}catch(c){}return sb(a,"wx")}function vb(a,b,c){try{var e=eb(a,b)}catch(f){return f.Df}if(a=sb(a,"wx"))return a;if(c){if(!P(e.mode))return 54;if(e===e.parent||"/"===pb(e))return 10}else if(P(e.mode))return 31;return 0}function S(a){a=jb[a];if(!a)throw new N(8);return a} function wb(a,b=-1){a=Object.assign(new mb,a);if(-1==b)a:{for(b=0;4096>=b;b++)if(!jb[b])break a;throw new N(33);}a.Lf=b;return jb[b]=a}function xb(a,b=-1){a=wb(a,b);a.Bf?.Kg?.(a);return a}var bb={open(a){a.Bf=ib[a.node.Uf].Bf;a.Bf.open?.(a)},Of(){throw new N(70);}};function Xa(a,b){ib[a]={Bf:b}} -function yb(a,b){var c="/"===b;if(c&&hb)throw new N(10);if(!c&&b){var e=R(b,{kg:!1});b=e.path;e=e.node;if(e.Pf)throw new N(10);if(!P(e.mode))throw new N(54);}b={type:a,Qg:{},ng:b,zg:[]};a=a.Jf(b);a.Jf=b;b.root=a;c?hb=a:e&&(e.Pf=b,e.Jf&&e.Jf.zg.push(b))}function zb(a,b,c){var e=R(a,{parent:!0}).node;a=Oa(a);if(!a||"."===a||".."===a)throw new N(28);var f=ub(e,a);if(f)throw new N(f);if(!e.Af.Yf)throw new N(63);return e.Af.Yf(e,a,b,c)}function T(a,b){return zb(a,(void 0!==b?b:511)&1023|16384,0)} +function yb(a,b){var c="/"===b;if(c&&hb)throw new N(10);if(!c&&b){var e=R(b,{kg:!1});b=e.path;e=e.node;if(e.Pf)throw new N(10);if(!P(e.mode))throw new N(54);}b={type:a,Pg:{},ng:b,zg:[]};a=a.Jf(b);a.Jf=b;b.root=a;c?hb=a:e&&(e.Pf=b,e.Jf&&e.Jf.zg.push(b))}function zb(a,b,c){var e=R(a,{parent:!0}).node;a=Oa(a);if(!a||"."===a||".."===a)throw new N(28);var f=ub(e,a);if(f)throw new N(f);if(!e.Af.Yf)throw new N(63);return e.Af.Yf(e,a,b,c)}function T(a,b){return zb(a,(void 0!==b?b:511)&1023|16384,0)} function Ab(a,b,c){"undefined"==typeof c&&(c=b,b=438);zb(a,b|8192,c)}function Bb(a,b){if(!Ra(a))throw new N(44);var c=R(b,{parent:!0}).node;if(!c)throw new N(44);b=Oa(b);var e=ub(c,b);if(e)throw new N(e);if(!c.Af.bg)throw new N(63);c.Af.bg(c,b,a)}function Cb(a){var b=R(a,{parent:!0}).node;a=Oa(a);var c=eb(b,a),e=vb(b,a,!0);if(e)throw new N(e);if(!b.Af.ag)throw new N(63);if(c.Pf)throw new N(10);b.Af.ag(b,a);rb(c)} function ob(a){a=R(a).node;if(!a)throw new N(44);if(!a.Af.Vf)throw new N(28);return Ra(pb(a.parent),a.Af.Vf(a))}function Db(a,b){a=R(a,{Nf:!b}).node;if(!a)throw new N(44);if(!a.Af.If)throw new N(63);return a.Af.If(a)}function Eb(a){return Db(a,!0)}function Fb(a,b){a="string"==typeof a?R(a,{Nf:!0}).node:a;if(!a.Af.Ff)throw new N(63);a.Af.Ff(a,{mode:b&4095|a.mode&-4096,timestamp:Date.now()})} function Gb(a,b){if(0>b)throw new N(28);a="string"==typeof a?R(a,{Nf:!0}).node:a;if(!a.Af.Ff)throw new N(63);if(P(a.mode))throw new N(31);if(32768!==(a.mode&61440))throw new N(28);var c=sb(a,"w");if(c)throw new N(c);a.Af.Ff(a,{size:b,timestamp:Date.now()})} @@ -48,7 +48,7 @@ function Ob(a,b,c){a=a(b);z[c>>2]=a.vg;z[c+4>>2]=a.mode;B[c+8>>2]=a.Bg;z[c+12>>2 var Rb=(a,b)=>b+2097152>>>0<4194305-!!a?(a>>>0)+4294967296*b:NaN,Sb=[0,31,60,91,121,152,182,213,244,274,305,335],Tb=[0,31,59,90,120,151,181,212,243,273,304,334],Ub={},Wb=()=>{if(!Vb){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:da||"./this.program"},b;for(b in Ub)void 0===Ub[b]?delete a[b]:a[b]=Ub[b];var c=[];for(b in a)c.push(`${b}=${a[b]}`);Vb=c}return Vb}, Vb;function Xb(){}function Yb(){}function Zb(){}function $b(){}function ac(){}function bc(){}function cc(){}function dc(){}function ec(){}function fc(){}function gc(){}function hc(){}function ic(){}function jc(){}function kc(){}function lc(){}function mc(){}function nc(){}function oc(){}function pc(){}function qc(){}function rc(){}function sc(){}function tc(){}function uc(){}function vc(){}function wc(){}function xc(){}function yc(){}function zc(){}function Ac(){}function Bc(){}function Cc(){} function Dc(){}function Ec(){}function Fc(){}function Gc(){}function Hc(){}function Ic(){}var Jc=0,Kc=a=>{na=a;Ja||0{a instanceof Ha||"unwind"==a||ea(1,a)},Mc=a=>{try{a()}catch(b){C(b)}},Nc=a=>{if(!u)try{if(a(),!(Ja||0{Pc.push(c);try{return e(...f)}finally{u||(Pc.pop(),W&&1===Y&&0===Pc.length&&(Y=0,Mc(Qc),"undefined"!=typeof Fibers&&Fibers.Rg()))}}:e;return b}var Y=0,W=null,Rc=0,Pc=[],Sc={},Tc={},Uc=0,Vc=null,Wc=[];function Xc(){return new Promise((a,b)=>{Vc={resolve:a,reject:b}})} +function Oc(){var a=V,b={};for(let [c,e]of Object.entries(a))b[c]="function"==typeof e?(...f)=>{Pc.push(c);try{return e(...f)}finally{u||(Pc.pop(),W&&1===Y&&0===Pc.length&&(Y=0,Mc(Qc),"undefined"!=typeof Fibers&&Fibers.Qg()))}}:e;return b}var Y=0,W=null,Rc=0,Pc=[],Sc={},Tc={},Uc=0,Vc=null,Wc=[];function Xc(){return new Promise((a,b)=>{Vc={resolve:a,reject:b}})} function Yc(){var a=Zc(16396),b=a+12;B[a>>2]=b;B[a+4>>2]=b+16384;b=Pc[0];var c=Sc[b];void 0===c&&(c=Uc++,Sc[b]=c,Tc[c]=b);z[a+8>>2]=c;return a} function $c(a){if(!u){if(0===Y){var b=!1,c=!1;a((e=0)=>{if(!u&&(Rc=e,b=!0,c)){Y=2;Mc(()=>ad(W));"undefined"!=typeof Browser&&Browser.eg.xg&&Browser.eg.resume();e=!1;try{var f=(0,V[Tc[z[W+8>>2]]])()}catch(n){f=n,e=!0}var h=!1;if(!W){var k=Vc;k&&(Vc=null,(e?k.reject:k.resolve)(f),h=!0)}if(e&&!h)throw f;}});c=!0;b||(Y=1,W=Yc(),"undefined"!=typeof Browser&&Browser.eg.xg&&Browser.eg.pause(),Mc(()=>bd(W)))}else 2===Y?(Y=0,Mc(cd),dd(W),W=null,Wc.forEach(Nc)):C(`invalid state: ${Y}`);return Rc}} function ed(a){return $c(b=>{a().then(b)})} @@ -68,10 +68,10 @@ t.estimatedCost,"double");I(m+p[10],t.estimatedRows,"i32");I(m+p[11],t.idxFlags, 1:0};lc=function(l,m,p,q,t){const y=f.get(l);p=p?p?J(w,p):"":null;t=new Uint32Array(w.buffer,t,q);return y.module.xFilter(l,m,p,t)};mc=function(l){return f.get(l).module.xNext(l)};ec=function(l,m,p){return f.get(l).module.xColumn(l,m,p)};qc=function(l,m){return f.get(l).module.xRowid(l,a("BigInt64",m))};tc=function(l,m,p,q){const t=e.get(l);p=new Uint32Array(w.buffer,p,m);return t.module.xUpdate(l,p,a("BigInt64",q))};bc=function(l){return e.get(l).module.xBegin(l)};sc=function(l){return e.get(l).module.xSync(l)}; fc=function(l){return e.get(l).module.xCommit(l)};pc=function(l){return e.get(l).module.xRollback(l)};oc=function(l,m){const p=e.get(l);m=m?J(w,m):"";return p.module.xRename(l,m)}})(); (function(){function a(h,k){const n=`get${h}`,l=`set${h}`;return new Proxy(new DataView(w.buffer,k,"Int32"===h?4:8),{get(m,p){if(p===n)return function(q,t){if(!t)throw Error("must be little endian");return m[p](q,t)};if(p===l)return function(q,t,y){if(!y)throw Error("must be little endian");return m[p](q,t,y)};if("string"===typeof p&&p.match(/^(get)|(set)/))throw Error("invalid type");return m[p]}})}const b="object"===typeof fd;b&&(d.handleAsync=ed);const c=new Map,e=new Map;d.registerVFS=function(h, -k){if(Z("sqlite3_vfs_find","number",["string"],[h.name]))throw Error(`VFS '${h.name}' already registered`);b&&(h.handleAsync=ed);var n=h.Pg??64;const l=d._malloc(4);k=Z("register_vfs","number",["string","number","number","number"],[h.name,n,k?1:0,l]);k||(n=H(l,"*"),c.set(n,h));d._free(l);return k};const f=b?new Set:null;wc=function(h){const k=e.get(h);b?f.add(h):e.delete(h);return k.xClose(h)};Dc=function(h,k,n,l,m){return e.get(h).xRead(h,w.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))};Ic=function(h, -k,n,l,m){return e.get(h).xWrite(h,w.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))};Gc=function(h,k,n){return e.get(h).xTruncate(h,4294967296*n+k+(0>k?2**32:0))};Fc=function(h,k){return e.get(h).xSync(h,k)};Ac=function(h,k){const n=e.get(h);k=a("BigInt64",k);return n.xFileSize(h,k)};Bc=function(h,k){return e.get(h).xLock(h,k)};Hc=function(h,k){return e.get(h).xUnlock(h,k)};vc=function(h,k){const n=e.get(h);k=a("Int32",k);return n.xCheckReservedLock(h,k)};zc=function(h,k,n){const l=e.get(h);n=new DataView(w.buffer, -n);return l.xFileControl(h,k,n)};Ec=function(h){return e.get(h).xSectorSize(h)};yc=function(h){return e.get(h).xDeviceCharacteristics(h)};Cc=function(h,k,n,l,m){h=c.get(h);e.set(n,h);if(b){f.delete(n);for(var p of f)e.delete(p)}p=null;if(l&64){p=1;const q=[];for(;p;){const t=w[k++];if(t)q.push(t);else switch(w[k]||(p=null),p){case 1:q.push(63);p=2;break;case 2:q.push(61);p=3;break;case 3:q.push(38),p=2}}p=(new TextDecoder).decode(new Uint8Array(q))}else k&&(p=k?J(w,k):"");m=a("Int32",m);return h.xOpen(p, -n,l,m)};xc=function(h,k,n){return c.get(h).xDelete(k?J(w,k):"",n)};uc=function(h,k,n,l){h=c.get(h);l=a("Int32",l);return h.xAccess(k?J(w,k):"",n,l)}})(); +k){if(Z("sqlite3_vfs_find","number",["string"],[h.name]))throw Error(`VFS '${h.name}' already registered`);b&&(h.handleAsync=ed);var n=h.mxPathName??64;const l=d._malloc(4);k=Z("register_vfs","number",["string","number","number","number"],[h.name,n,k?1:0,l]);k||(n=H(l,"*"),c.set(n,h));d._free(l);return k};const f=b?new Set:null;wc=function(h){const k=e.get(h);b?f.add(h):e.delete(h);return k.xClose(h)};Dc=function(h,k,n,l,m){return e.get(h).xRead(h,w.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))}; +Ic=function(h,k,n,l,m){return e.get(h).xWrite(h,w.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))};Gc=function(h,k,n){return e.get(h).xTruncate(h,4294967296*n+k+(0>k?2**32:0))};Fc=function(h,k){return e.get(h).xSync(h,k)};Ac=function(h,k){const n=e.get(h);k=a("BigInt64",k);return n.xFileSize(h,k)};Bc=function(h,k){return e.get(h).xLock(h,k)};Hc=function(h,k){return e.get(h).xUnlock(h,k)};vc=function(h,k){const n=e.get(h);k=a("Int32",k);return n.xCheckReservedLock(h,k)};zc=function(h,k,n){const l=e.get(h); +n=new DataView(w.buffer,n);return l.xFileControl(h,k,n)};Ec=function(h){return e.get(h).xSectorSize(h)};yc=function(h){return e.get(h).xDeviceCharacteristics(h)};Cc=function(h,k,n,l,m){h=c.get(h);e.set(n,h);if(b){f.delete(n);for(var p of f)e.delete(p)}p=null;if(l&64){p=1;const q=[];for(;p;){const t=w[k++];if(t)q.push(t);else switch(w[k]||(p=null),p){case 1:q.push(63);p=2;break;case 2:q.push(61);p=3;break;case 3:q.push(38),p=2}}p=(new TextDecoder).decode(new Uint8Array(q))}else k&&(p=k?J(w,k):""); +m=a("Int32",m);return h.xOpen(p,n,l,m)};xc=function(h,k,n){return c.get(h).xDelete(k?J(w,k):"",n)};uc=function(h,k,n,l){h=c.get(h);l=a("Int32",l);return h.xAccess(k?J(w,k):"",n,l)}})(); var od={a:(a,b,c,e)=>{C(`Assertion failed: ${a?J(w,a):""}, at: `+[b?b?J(w,b):"":"unknown filename",c,e?e?J(w,e):"":"unknown function"])},N:function(a,b){try{return a=a?J(w,a):"",Fb(a,b),0}catch(c){if("undefined"==typeof U||"ErrnoError"!==c.name)throw c;return-c.Df}},Q:function(a,b,c){try{b=b?J(w,b):"";b=Nb(a,b);if(c&-8)return-28;var e=R(b,{Nf:!0}).node;if(!e)return-44;a="";c&4&&(a+="r");c&2&&(a+="w");c&1&&(a+="x");return a&&sb(e,a)?-2:0}catch(f){if("undefined"==typeof U||"ErrnoError"!==f.name)throw f; return-f.Df}},O:function(a,b){try{var c=S(a);Fb(c.node,b);return 0}catch(e){if("undefined"==typeof U||"ErrnoError"!==e.name)throw e;return-e.Df}},M:function(a){try{var b=S(a).node;var c="string"==typeof b?R(b,{Nf:!0}).node:b;if(!c.Af.Ff)throw new N(63);c.Af.Ff(c,{timestamp:Date.now()});return 0}catch(e){if("undefined"==typeof U||"ErrnoError"!==e.name)throw e;return-e.Df}},b:function(a,b,c){Pb=c;try{var e=S(a);switch(b){case 0:var f=Qb();if(0>f)break;for(;jb[f];)f++;return xb(e,f).Lf;case 1:case 2:return 0; case 3:return e.flags;case 4:return f=Qb(),e.flags|=f,0;case 12:return f=Qb(),x[f+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(h){if("undefined"==typeof U||"ErrnoError"!==h.name)throw h;return-h.Df}},L:function(a,b){try{var c=S(a);return Ob(Db,c.path,b)}catch(e){if("undefined"==typeof U||"ErrnoError"!==e.name)throw e;return-e.Df}},n:function(a,b,c){b=Rb(b,c);try{if(isNaN(b))return 61;var e=S(a);if(0===(e.flags&2097155))throw new N(28);Gb(e.node,b);return 0}catch(f){if("undefined"==typeof U|| diff --git a/dist/wa-sqlite.mjs b/dist/wa-sqlite.mjs index e00050e..92c3129 100644 --- a/dist/wa-sqlite.mjs +++ b/dist/wa-sqlite.mjs @@ -34,7 +34,7 @@ function mb(a){for(var b;;){if(a===a.parent)return a=a.Gf.jg,b?"/"!==a[a.length- function R(a,b){var c=Q(a.mode)?(c=pb(a,"x"))?c:a.wf.Pf?0:2:54;if(c)throw new O(c);for(c=S[nb(a.id,b)];c;c=c.Nf){var e=c.name;if(c.parent.id===a.id&&e===b)return c}return a.wf.Pf(a,b)}function ab(a,b,c,e){a=new kb(a,b,c,e);b=nb(a.parent.id,a.name);a.Nf=S[b];return S[b]=a}function Q(a){return 16384===(a&61440)}function qb(a){var b=["r","w","rw"][a&3];a&512&&(b+="w");return b} function pb(a,b){if(ib)return 0;if(!b.includes("r")||a.mode&292){if(b.includes("w")&&!(a.mode&146)||b.includes("x")&&!(a.mode&73))return 2}else return 2;return 0}function rb(a,b){try{return R(a,b),20}catch(c){}return pb(a,"wx")}function sb(a,b,c){try{var e=R(a,b)}catch(f){return f.zf}if(a=pb(a,"wx"))return a;if(c){if(!Q(e.mode))return 54;if(e===e.parent||"/"===mb(e))return 10}else if(Q(e.mode))return 31;return 0}function U(a){a=gb[a];if(!a)throw new O(8);return a} function tb(a,b=-1){a=Object.assign(new jb,a);if(-1==b)a:{for(b=0;4096>=b;b++)if(!gb[b])break a;throw new O(33);}a.Hf=b;return gb[b]=a}function ub(a,b=-1){a=tb(a,b);a.xf?.Eg?.(a);return a}var $a={open(a){a.xf=fb[a.node.Rf].xf;a.xf.open?.(a)},Kf(){throw new O(70);}};function Va(a,b){fb[a]={xf:b}} -function vb(a,b){var c="/"===b;if(c&&eb)throw new O(10);if(!c&&b){var e=T(b,{fg:!1});b=e.path;e=e.node;if(e.Mf)throw new O(10);if(!Q(e.mode))throw new O(54);}b={type:a,Kg:{},jg:b,ug:[]};a=a.Gf(b);a.Gf=b;b.root=a;c?eb=a:e&&(e.Mf=b,e.Gf&&e.Gf.ug.push(b))}function wb(a,b,c){var e=T(a,{parent:!0}).node;a=Ma(a);if(!a||"."===a||".."===a)throw new O(28);var f=rb(e,a);if(f)throw new O(f);if(!e.wf.Tf)throw new O(63);return e.wf.Tf(e,a,b,c)}function W(a,b){return wb(a,(void 0!==b?b:511)&1023|16384,0)} +function vb(a,b){var c="/"===b;if(c&&eb)throw new O(10);if(!c&&b){var e=T(b,{fg:!1});b=e.path;e=e.node;if(e.Mf)throw new O(10);if(!Q(e.mode))throw new O(54);}b={type:a,Jg:{},jg:b,ug:[]};a=a.Gf(b);a.Gf=b;b.root=a;c?eb=a:e&&(e.Mf=b,e.Gf&&e.Gf.ug.push(b))}function wb(a,b,c){var e=T(a,{parent:!0}).node;a=Ma(a);if(!a||"."===a||".."===a)throw new O(28);var f=rb(e,a);if(f)throw new O(f);if(!e.wf.Tf)throw new O(63);return e.wf.Tf(e,a,b,c)}function W(a,b){return wb(a,(void 0!==b?b:511)&1023|16384,0)} function xb(a,b,c){"undefined"==typeof c&&(c=b,b=438);wb(a,b|8192,c)}function yb(a,b){if(!Pa(a))throw new O(44);var c=T(b,{parent:!0}).node;if(!c)throw new O(44);b=Ma(b);var e=rb(c,b);if(e)throw new O(e);if(!c.wf.Xf)throw new O(63);c.wf.Xf(c,b,a)}function zb(a){var b=T(a,{parent:!0}).node;a=Ma(a);var c=R(b,a),e=sb(b,a,!0);if(e)throw new O(e);if(!b.wf.Wf)throw new O(63);if(c.Mf)throw new O(10);b.wf.Wf(b,a);ob(c)} function lb(a){a=T(a).node;if(!a)throw new O(44);if(!a.wf.Sf)throw new O(28);return Pa(mb(a.parent),a.wf.Sf(a))}function Ab(a,b){a=T(a,{Jf:!b}).node;if(!a)throw new O(44);if(!a.wf.Ef)throw new O(63);return a.wf.Ef(a)}function Bb(a){return Ab(a,!0)}function Cb(a,b){a="string"==typeof a?T(a,{Jf:!0}).node:a;if(!a.wf.Bf)throw new O(63);a.wf.Bf(a,{mode:b&4095|a.mode&-4096,timestamp:Date.now()})} function Db(a,b){if(0>b)throw new O(28);a="string"==typeof a?T(a,{Jf:!0}).node:a;if(!a.wf.Bf)throw new O(63);if(Q(a.mode))throw new O(31);if(32768!==(a.mode&61440))throw new O(28);var c=pb(a,"w");if(c)throw new O(c);a.wf.Bf(a,{size:b,timestamp:Date.now()})} @@ -64,10 +64,10 @@ t.estimatedCost,"double");J(m+p[10],t.estimatedRows,"i32");J(m+p[11],t.idxFlags, 1:0};ic=function(l,m,p,q,t){const y=f.get(l);p=p?p?K(v,p):"":null;t=new Uint32Array(v.buffer,t,q);return y.module.xFilter(l,m,p,t)};jc=function(l){return f.get(l).module.xNext(l)};bc=function(l,m,p){return f.get(l).module.xColumn(l,m,p)};nc=function(l,m){return f.get(l).module.xRowid(l,a("BigInt64",m))};qc=function(l,m,p,q){const t=e.get(l);p=new Uint32Array(v.buffer,p,m);return t.module.xUpdate(l,p,a("BigInt64",q))};Zb=function(l){return e.get(l).module.xBegin(l)};pc=function(l){return e.get(l).module.xSync(l)}; cc=function(l){return e.get(l).module.xCommit(l)};mc=function(l){return e.get(l).module.xRollback(l)};lc=function(l,m){const p=e.get(l);m=m?K(v,m):"";return p.module.xRename(l,m)}})(); (function(){function a(h,k){const n=`get${h}`,l=`set${h}`;return new Proxy(new DataView(v.buffer,k,"Int32"===h?4:8),{get(m,p){if(p===n)return function(q,t){if(!t)throw Error("must be little endian");return m[p](q,t)};if(p===l)return function(q,t,y){if(!y)throw Error("must be little endian");return m[p](q,t,y)};if("string"===typeof p&&p.match(/^(get)|(set)/))throw Error("invalid type");return m[p]}})}const b="object"===typeof Asyncify;b&&(d.handleAsync=Asyncify.hg);const c=new Map,e=new Map;d.registerVFS= -function(h,k){if(Y("sqlite3_vfs_find","number",["string"],[h.name]))throw Error(`VFS '${h.name}' already registered`);b&&(h.handleAsync=Asyncify.hg);var n=h.Jg??64;const l=d._malloc(4);k=Y("register_vfs","number",["string","number","number","number"],[h.name,n,k?1:0,l]);k||(n=I(l,"*"),c.set(n,h));d._free(l);return k};const f=b?new Set:null;tc=function(h){const k=e.get(h);b?f.add(h):e.delete(h);return k.xClose(h)};Ac=function(h,k,n,l,m){return e.get(h).xRead(h,v.subarray(k,k+n),4294967296*m+l+(0>l? -2**32:0))};Fc=function(h,k,n,l,m){return e.get(h).xWrite(h,v.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))};Dc=function(h,k,n){return e.get(h).xTruncate(h,4294967296*n+k+(0>k?2**32:0))};Cc=function(h,k){return e.get(h).xSync(h,k)};xc=function(h,k){const n=e.get(h);k=a("BigInt64",k);return n.xFileSize(h,k)};yc=function(h,k){return e.get(h).xLock(h,k)};Ec=function(h,k){return e.get(h).xUnlock(h,k)};sc=function(h,k){const n=e.get(h);k=a("Int32",k);return n.xCheckReservedLock(h,k)};wc=function(h,k,n){const l= -e.get(h);n=new DataView(v.buffer,n);return l.xFileControl(h,k,n)};Bc=function(h){return e.get(h).xSectorSize(h)};vc=function(h){return e.get(h).xDeviceCharacteristics(h)};zc=function(h,k,n,l,m){h=c.get(h);e.set(n,h);if(b){f.delete(n);for(var p of f)e.delete(p)}p=null;if(l&64){p=1;const q=[];for(;p;){const t=v[k++];if(t)q.push(t);else switch(v[k]||(p=null),p){case 1:q.push(63);p=2;break;case 2:q.push(61);p=3;break;case 3:q.push(38),p=2}}p=(new TextDecoder).decode(new Uint8Array(q))}else k&&(p=k?K(v, -k):"");m=a("Int32",m);return h.xOpen(p,n,l,m)};uc=function(h,k,n){return c.get(h).xDelete(k?K(v,k):"",n)};rc=function(h,k,n,l){h=c.get(h);l=a("Int32",l);return h.xAccess(k?K(v,k):"",n,l)}})(); +function(h,k){if(Y("sqlite3_vfs_find","number",["string"],[h.name]))throw Error(`VFS '${h.name}' already registered`);b&&(h.handleAsync=Asyncify.hg);var n=h.mxPathName??64;const l=d._malloc(4);k=Y("register_vfs","number",["string","number","number","number"],[h.name,n,k?1:0,l]);k||(n=I(l,"*"),c.set(n,h));d._free(l);return k};const f=b?new Set:null;tc=function(h){const k=e.get(h);b?f.add(h):e.delete(h);return k.xClose(h)};Ac=function(h,k,n,l,m){return e.get(h).xRead(h,v.subarray(k,k+n),4294967296* +m+l+(0>l?2**32:0))};Fc=function(h,k,n,l,m){return e.get(h).xWrite(h,v.subarray(k,k+n),4294967296*m+l+(0>l?2**32:0))};Dc=function(h,k,n){return e.get(h).xTruncate(h,4294967296*n+k+(0>k?2**32:0))};Cc=function(h,k){return e.get(h).xSync(h,k)};xc=function(h,k){const n=e.get(h);k=a("BigInt64",k);return n.xFileSize(h,k)};yc=function(h,k){return e.get(h).xLock(h,k)};Ec=function(h,k){return e.get(h).xUnlock(h,k)};sc=function(h,k){const n=e.get(h);k=a("Int32",k);return n.xCheckReservedLock(h,k)};wc=function(h, +k,n){const l=e.get(h);n=new DataView(v.buffer,n);return l.xFileControl(h,k,n)};Bc=function(h){return e.get(h).xSectorSize(h)};vc=function(h){return e.get(h).xDeviceCharacteristics(h)};zc=function(h,k,n,l,m){h=c.get(h);e.set(n,h);if(b){f.delete(n);for(var p of f)e.delete(p)}p=null;if(l&64){p=1;const q=[];for(;p;){const t=v[k++];if(t)q.push(t);else switch(v[k]||(p=null),p){case 1:q.push(63);p=2;break;case 2:q.push(61);p=3;break;case 3:q.push(38),p=2}}p=(new TextDecoder).decode(new Uint8Array(q))}else k&& +(p=k?K(v,k):"");m=a("Int32",m);return h.xOpen(p,n,l,m)};uc=function(h,k,n){return c.get(h).xDelete(k?K(v,k):"",n)};rc=function(h,k,n,l){h=c.get(h);l=a("Int32",l);return h.xAccess(k?K(v,k):"",n,l)}})(); var Nc={a:(a,b,c,e)=>{C(`Assertion failed: ${a?K(v,a):""}, at: `+[b?b?K(v,b):"":"unknown filename",c,e?e?K(v,e):"":"unknown function"])},N:function(a,b){try{return a=a?K(v,a):"",Cb(a,b),0}catch(c){if("undefined"==typeof X||"ErrnoError"!==c.name)throw c;return-c.zf}},Q:function(a,b,c){try{b=b?K(v,b):"";b=Kb(a,b);if(c&-8)return-28;var e=T(b,{Jf:!0}).node;if(!e)return-44;a="";c&4&&(a+="r");c&2&&(a+="w");c&1&&(a+="x");return a&&pb(e,a)?-2:0}catch(f){if("undefined"==typeof X||"ErrnoError"!==f.name)throw f; return-f.zf}},O:function(a,b){try{var c=U(a);Cb(c.node,b);return 0}catch(e){if("undefined"==typeof X||"ErrnoError"!==e.name)throw e;return-e.zf}},M:function(a){try{var b=U(a).node;var c="string"==typeof b?T(b,{Jf:!0}).node:b;if(!c.wf.Bf)throw new O(63);c.wf.Bf(c,{timestamp:Date.now()});return 0}catch(e){if("undefined"==typeof X||"ErrnoError"!==e.name)throw e;return-e.zf}},b:function(a,b,c){Mb=c;try{var e=U(a);switch(b){case 0:var f=Nb();if(0>f)break;for(;gb[f];)f++;return ub(e,f).Hf;case 1:case 2:return 0; case 3:return e.flags;case 4:return f=Nb(),e.flags|=f,0;case 12:return f=Nb(),w[f+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(h){if("undefined"==typeof X||"ErrnoError"!==h.name)throw h;return-h.zf}},L:function(a,b){try{var c=U(a);return Lb(Ab,c.path,b)}catch(e){if("undefined"==typeof X||"ErrnoError"!==e.name)throw e;return-e.zf}},n:function(a,b,c){b=Ob(b,c);try{if(isNaN(b))return 61;var e=U(a);if(0===(e.flags&2097155))throw new O(28);Db(e.node,b);return 0}catch(f){if("undefined"==typeof X|| diff --git a/src/exported_functions.json b/src/exported_functions.json index 14e800a..8889bbf 100644 --- a/src/exported_functions.json +++ b/src/exported_functions.json @@ -11,8 +11,17 @@ "_sqlite3_backup_pagecount", "_sqlite3_backup_remaining", "_sqlite3_backup_step", + "_sqlite3_aggregate_context", + "_sqlite3_auto_extension", + "_sqlite3_autovacuum_pages", + "_sqlite3_backup_finish", + "_sqlite3_backup_init", + "_sqlite3_backup_pagecount", + "_sqlite3_backup_remaining", + "_sqlite3_backup_step", "_sqlite3_bind_blob", "_sqlite3_bind_blob64", + "_sqlite3_bind_blob64", "_sqlite3_bind_double", "_sqlite3_bind_int", "_sqlite3_bind_int64", @@ -21,6 +30,9 @@ "_sqlite3_bind_parameter_index", "_sqlite3_bind_parameter_name", "_sqlite3_bind_pointer", + "_sqlite3_bind_parameter_index", + "_sqlite3_bind_parameter_name", + "_sqlite3_bind_pointer", "_sqlite3_bind_text", "_sqlite3_bind_text16", "_sqlite3_bind_text64", @@ -36,24 +48,45 @@ "_sqlite3_busy_handler", "_sqlite3_busy_timeout", "_sqlite3_cancel_auto_extension", + "_sqlite3_bind_text16", + "_sqlite3_bind_text64", + "_sqlite3_bind_value", + "_sqlite3_bind_zeroblob", + "_sqlite3_bind_zeroblob64", + "_sqlite3_blob_bytes", + "_sqlite3_blob_close", + "_sqlite3_blob_open", + "_sqlite3_blob_read", + "_sqlite3_blob_reopen", + "_sqlite3_blob_write", + "_sqlite3_busy_handler", + "_sqlite3_busy_timeout", + "_sqlite3_cancel_auto_extension", "_sqlite3_changes", "_sqlite3_changes64", + "_sqlite3_changes64", "_sqlite3_clear_bindings", "_sqlite3_close", "_sqlite3_close_v2", "_sqlite3_collation_needed", "_sqlite3_collation_needed16", + "_sqlite3_close_v2", + "_sqlite3_collation_needed", + "_sqlite3_collation_needed16", "_sqlite3_column_blob", "_sqlite3_column_bytes", "_sqlite3_column_bytes16", + "_sqlite3_column_bytes16", "_sqlite3_column_count", "_sqlite3_column_double", "_sqlite3_column_int", "_sqlite3_column_int64", "_sqlite3_column_name", "_sqlite3_column_name16", + "_sqlite3_column_name16", "_sqlite3_column_text", "_sqlite3_column_text16", + "_sqlite3_column_text16", "_sqlite3_column_type", "_sqlite3_column_value", "_sqlite3_commit_hook", @@ -73,6 +106,24 @@ "_sqlite3_create_module", "_sqlite3_create_module_v2", "_sqlite3_create_window_function", + "_sqlite3_column_value", + "_sqlite3_commit_hook", + "_sqlite3_compileoption_get", + "_sqlite3_compileoption_used", + "_sqlite3_complete", + "_sqlite3_complete16", + "_sqlite3_config", + "_sqlite3_context_db_handle", + "_sqlite3_create_collation", + "_sqlite3_create_collation16", + "_sqlite3_create_collation_v2", + "_sqlite3_create_filename", + "_sqlite3_create_function", + "_sqlite3_create_function16", + "_sqlite3_create_function_v2", + "_sqlite3_create_module", + "_sqlite3_create_module_v2", + "_sqlite3_create_window_function", "_sqlite3_data_count", "_sqlite3_database_file_object", "_sqlite3_db_cacheflush", @@ -84,14 +135,30 @@ "_sqlite3_db_readonly", "_sqlite3_db_release_memory", "_sqlite3_db_status", + "_sqlite3_database_file_object", + "_sqlite3_db_cacheflush", + "_sqlite3_db_config", + "_sqlite3_db_filename", + "_sqlite3_db_handle", + "_sqlite3_db_mutex", + "_sqlite3_db_name", + "_sqlite3_db_readonly", + "_sqlite3_db_release_memory", + "_sqlite3_db_status", "_sqlite3_declare_vtab", "_sqlite3_deserialize", "_sqlite3_drop_modules", "_sqlite3_errcode", + "_sqlite3_deserialize", + "_sqlite3_drop_modules", + "_sqlite3_errcode", "_sqlite3_errmsg", "_sqlite3_errmsg16", "_sqlite3_error_offset", "_sqlite3_errstr", + "_sqlite3_errmsg16", + "_sqlite3_error_offset", + "_sqlite3_errstr", "_sqlite3_exec", "_sqlite3_expanded_sql", "_sqlite3_extended_errcode", @@ -100,10 +167,19 @@ "_sqlite3_filename_database", "_sqlite3_filename_journal", "_sqlite3_filename_wal", + "_sqlite3_expanded_sql", + "_sqlite3_extended_errcode", + "_sqlite3_extended_result_codes", + "_sqlite3_file_control", + "_sqlite3_filename_database", + "_sqlite3_filename_journal", + "_sqlite3_filename_wal", "_sqlite3_finalize", "_sqlite3_free", "_sqlite3_free_filename", "_sqlite3_free_table", + "_sqlite3_free_filename", + "_sqlite3_free_table", "_sqlite3_get_autocommit", "_sqlite3_get_auxdata", "_sqlite3_get_clientdata", @@ -116,10 +192,22 @@ "_sqlite3_keyword_count", "_sqlite3_keyword_name", "_sqlite3_last_insert_rowid", + "_sqlite3_get_auxdata", + "_sqlite3_get_clientdata", + "_sqlite3_get_table", + "_sqlite3_hard_heap_limit64", + "_sqlite3_initialize", + "_sqlite3_interrupt", + "_sqlite3_is_interrupted", + "_sqlite3_keyword_check", + "_sqlite3_keyword_count", + "_sqlite3_keyword_name", + "_sqlite3_last_insert_rowid", "_sqlite3_libversion", "_sqlite3_libversion_number", "_sqlite3_limit", "_sqlite3_log", + "_sqlite3_log", "_sqlite3_malloc", "_sqlite3_malloc64", "_sqlite3_memory_highwater", @@ -129,6 +217,14 @@ "_sqlite3_next_stmt", "_sqlite3_open", "_sqlite3_open16", + "_sqlite3_malloc64", + "_sqlite3_memory_highwater", + "_sqlite3_memory_used", + "_sqlite3_mprintf", + "_sqlite3_msize", + "_sqlite3_next_stmt", + "_sqlite3_open", + "_sqlite3_open16", "_sqlite3_open_v2", "_sqlite3_os_end", "_sqlite3_os_init", @@ -137,6 +233,13 @@ "_sqlite3_prepare16", "_sqlite3_prepare16_v2", "_sqlite3_prepare16_v3", + "_sqlite3_os_end", + "_sqlite3_os_init", + "_sqlite3_overload_function", + "_sqlite3_prepare", + "_sqlite3_prepare16", + "_sqlite3_prepare16_v2", + "_sqlite3_prepare16_v3", "_sqlite3_prepare_v2", "_sqlite3_prepare_v3", "_sqlite3_progress_handler", @@ -144,21 +247,34 @@ "_sqlite3_realloc", "_sqlite3_realloc64", "_sqlite3_release_memory", + "_sqlite3_prepare_v3", + "_sqlite3_progress_handler", + "_sqlite3_randomness", + "_sqlite3_realloc", + "_sqlite3_realloc64", + "_sqlite3_release_memory", "_sqlite3_reset", "_sqlite3_reset_auto_extension", "_sqlite3_result_blob", "_sqlite3_result_blob64", + "_sqlite3_result_blob64", "_sqlite3_result_double", "_sqlite3_result_error", "_sqlite3_result_error16", "_sqlite3_result_error_code", "_sqlite3_result_error_nomem", "_sqlite3_result_error_toobig", + "_sqlite3_result_error16", + "_sqlite3_result_error_code", + "_sqlite3_result_error_nomem", + "_sqlite3_result_error_toobig", "_sqlite3_result_int", "_sqlite3_result_int64", "_sqlite3_result_null", "_sqlite3_result_pointer", "_sqlite3_result_subtype", + "_sqlite3_result_pointer", + "_sqlite3_result_subtype", "_sqlite3_result_text", "_sqlite3_result_text16", "_sqlite3_result_text16be", @@ -216,24 +332,92 @@ "_sqlite3_uri_key", "_sqlite3_uri_parameter", "_sqlite3_user_data", + "_sqlite3_result_text16", + "_sqlite3_result_text16be", + "_sqlite3_result_text16le", + "_sqlite3_result_text64", + "_sqlite3_result_value", + "_sqlite3_result_zeroblob", + "_sqlite3_result_zeroblob64", + "_sqlite3_rollback_hook", + "_sqlite3_serialize", + "_sqlite3_set_authorizer", + "_sqlite3_set_auxdata", + "_sqlite3_set_clientdata", + "_sqlite3_set_last_insert_rowid", + "_sqlite3_shutdown", + "_sqlite3_sleep", + "_sqlite3_snprintf", + "_sqlite3_soft_heap_limit64", + "_sqlite3_sourceid", + "_sqlite3_sql", + "_sqlite3_status", + "_sqlite3_status64", + "_sqlite3_step", + "_sqlite3_stmt_busy", + "_sqlite3_stmt_explain", + "_sqlite3_stmt_isexplain", + "_sqlite3_stmt_readonly", + "_sqlite3_stmt_status", + "_sqlite3_str_append", + "_sqlite3_str_appendall", + "_sqlite3_str_appendchar", + "_sqlite3_str_appendf", + "_sqlite3_str_errcode", + "_sqlite3_str_finish", + "_sqlite3_str_length", + "_sqlite3_str_new", + "_sqlite3_str_reset", + "_sqlite3_str_value", + "_sqlite3_str_vappendf", + "_sqlite3_strglob", + "_sqlite3_stricmp", + "_sqlite3_strlike", + "_sqlite3_strnicmp", + "_sqlite3_system_errno", + "_sqlite3_table_column_metadata", + "_sqlite3_test_control", + "_sqlite3_threadsafe", + "_sqlite3_total_changes", + "_sqlite3_total_changes64", + "_sqlite3_trace_v2", + "_sqlite3_txn_state", + "_sqlite3_update_hook", + "_sqlite3_uri_boolean", + "_sqlite3_uri_int64", + "_sqlite3_uri_key", + "_sqlite3_uri_parameter", + "_sqlite3_user_data", "_sqlite3_value_blob", "_sqlite3_value_bytes", "_sqlite3_value_bytes16", + "_sqlite3_value_bytes16", "_sqlite3_value_double", "_sqlite3_value_dup", "_sqlite3_value_encoding", "_sqlite3_value_free", "_sqlite3_value_frombind", + "_sqlite3_value_dup", + "_sqlite3_value_encoding", + "_sqlite3_value_free", + "_sqlite3_value_frombind", "_sqlite3_value_int", "_sqlite3_value_int64", "_sqlite3_value_nochange", "_sqlite3_value_numeric_type", "_sqlite3_value_pointer", "_sqlite3_value_subtype", + "_sqlite3_value_nochange", + "_sqlite3_value_numeric_type", + "_sqlite3_value_pointer", + "_sqlite3_value_subtype", "_sqlite3_value_text", "_sqlite3_value_text16", "_sqlite3_value_text16be", "_sqlite3_value_text16le", + "_sqlite3_value_text16", + "_sqlite3_value_text16be", + "_sqlite3_value_text16le", "_sqlite3_value_type", "_sqlite3_version", "_sqlite3_vfs_find", diff --git a/src/libvfs.c b/src/libvfs.c index 0542193..a180fa2 100644 --- a/src/libvfs.c +++ b/src/libvfs.c @@ -6,71 +6,75 @@ // sqlite3_io_methods javascript handlers // 64-bit integer parameters are passed by pointer. -extern int vfsClose(sqlite3_file* file); -extern int vfsRead(sqlite3_file* file, void* pData, int iAmt, sqlite3_int64 iOffset); -extern int vfsWrite(sqlite3_file* file, const void* pData, int iAmt, sqlite3_int64 iOffset); -extern int vfsTruncate(sqlite3_file* file, sqlite3_int64 size); -extern int vfsSync(sqlite3_file* file, int flags); -extern int vfsFileSize(sqlite3_file* file, sqlite3_int64* pSize); -extern int vfsLock(sqlite3_file* file, int flags); -extern int vfsUnlock(sqlite3_file* file, int flags); -extern int vfsCheckReservedLock(sqlite3_file* file, int* pResOut); -extern int vfsFileControl(sqlite3_file* file, int flags, void* pOut); -extern int vfsSectorSize(sqlite3_file* file); -extern int vfsDeviceCharacteristics(sqlite3_file* file); +extern int vfsClose(sqlite3_file *file); +extern int vfsRead(sqlite3_file *file, void *pData, int iAmt, sqlite3_int64 iOffset); +extern int vfsWrite(sqlite3_file *file, const void *pData, int iAmt, sqlite3_int64 iOffset); +extern int vfsTruncate(sqlite3_file *file, sqlite3_int64 size); +extern int vfsSync(sqlite3_file *file, int flags); +extern int vfsFileSize(sqlite3_file *file, sqlite3_int64 *pSize); +extern int vfsLock(sqlite3_file *file, int flags); +extern int vfsUnlock(sqlite3_file *file, int flags); +extern int vfsCheckReservedLock(sqlite3_file *file, int *pResOut); +extern int vfsFileControl(sqlite3_file *file, int flags, void *pOut); +extern int vfsSectorSize(sqlite3_file *file); +extern int vfsDeviceCharacteristics(sqlite3_file *file); -extern int vfsOpen(sqlite3_vfs* vfs, const char *zName, sqlite3_file* file, int flags, int *pOutFlags); -extern int vfsDelete(sqlite3_vfs* vfs, const char *zName, int syncDir); -extern int vfsAccess(sqlite3_vfs* vfs, const char *zName, int flags, int *pResOut); +extern int vfsOpen(sqlite3_vfs *vfs, const char *zName, sqlite3_file *file, int flags, int *pOutFlags); +extern int vfsDelete(sqlite3_vfs *vfs, const char *zName, int syncDir); +extern int vfsAccess(sqlite3_vfs *vfs, const char *zName, int flags, int *pResOut); // This is undefined in the WASM linker step if not specified extern int __rust_no_alloc_shim_is_unstable = 0; extern int sqlite3_powersync_init(sqlite3 *db, char **pzErrMsg, - const sqlite3_api_routines *pApi); + const sqlite3_api_routines *pApi); -static int xOpen(sqlite3_vfs* vfs, const char* zName, sqlite3_file* file, int flags, int* pOutFlags) { +static int xOpen(sqlite3_vfs *vfs, const char *zName, sqlite3_file *file, int flags, int *pOutFlags) +{ static sqlite3_io_methods io_methods = { - 1, - vfsClose, - vfsRead, - vfsWrite, - vfsTruncate, - vfsSync, - vfsFileSize, - vfsLock, - vfsUnlock, - vfsCheckReservedLock, - vfsFileControl, - vfsSectorSize, - vfsDeviceCharacteristics - }; + 1, + vfsClose, + vfsRead, + vfsWrite, + vfsTruncate, + vfsSync, + vfsFileSize, + vfsLock, + vfsUnlock, + vfsCheckReservedLock, + vfsFileControl, + vfsSectorSize, + vfsDeviceCharacteristics}; file->pMethods = &io_methods; return vfsOpen(vfs, zName, file, flags, pOutFlags); } -static int xFullPathname(sqlite3_vfs* vfs, const char* zName, int nOut, char* zOut) { +static int xFullPathname(sqlite3_vfs *vfs, const char *zName, int nOut, char *zOut) +{ strncpy(zOut, zName, nOut); return SQLITE_OK; } -static int xCurrentTime(sqlite3_vfs* vfs, double* pJulianDay) { +static int xCurrentTime(sqlite3_vfs *vfs, double *pJulianDay) +{ // UNIX epoch 1/1/1970 is Julian day 2440587.5 - static const sqlite3_int64 unixEpoch = 24405875*(sqlite3_int64)8640000; + static const sqlite3_int64 unixEpoch = 24405875 * (sqlite3_int64)8640000; struct timeval sNow; gettimeofday(&sNow, 0); - sqlite3_int64 julianMillis = unixEpoch + 1000*(sqlite3_int64)sNow.tv_sec + sNow.tv_usec/1000; + sqlite3_int64 julianMillis = unixEpoch + 1000 * (sqlite3_int64)sNow.tv_sec + sNow.tv_usec / 1000; *pJulianDay = julianMillis / 86400000.0; return SQLITE_OK; } const int EMSCRIPTEN_KEEPALIVE register_vfs( - const char* zName, - int mxPathName, - int makeDefault, - sqlite3_vfs** ppVFS) { - sqlite3_vfs* vfs = *ppVFS = (sqlite3_vfs*)sqlite3_malloc(sizeof(sqlite3_vfs)); - if (!vfs) { + const char *zName, + int mxPathName, + int makeDefault, + sqlite3_vfs **ppVFS) +{ + sqlite3_vfs *vfs = *ppVFS = (sqlite3_vfs *)sqlite3_malloc(sizeof(sqlite3_vfs)); + if (!vfs) + { return SQLITE_NOMEM; } @@ -85,9 +89,9 @@ const int EMSCRIPTEN_KEEPALIVE register_vfs( vfs->xAccess = vfsAccess; vfs->xFullPathname = xFullPathname; vfs->xCurrentTime = xCurrentTime; - + // Get remaining functionality from the default VFS. - sqlite3_vfs* defer = sqlite3_vfs_find(0); + sqlite3_vfs *defer = sqlite3_vfs_find(0); #define COPY_FIELD(NAME) vfs->NAME = defer->NAME COPY_FIELD(xDlOpen); COPY_FIELD(xDlError); @@ -99,22 +103,26 @@ const int EMSCRIPTEN_KEEPALIVE register_vfs( #undef COPY_FIELD const int result = sqlite3_vfs_register(vfs, makeDefault); - if (result != SQLITE_OK) { + if (result != SQLITE_OK) + { *ppVFS = 0; sqlite3_free(vfs); } return result; } -void* EMSCRIPTEN_KEEPALIVE getSqliteFree() { +void *EMSCRIPTEN_KEEPALIVE getSqliteFree() +{ return sqlite3_free; } -int main() { +int main() +{ sqlite3_initialize(); return 0; } -int setup_powersync() { - return sqlite3_auto_extension((void (*)(void)) &sqlite3_powersync_init); +int setup_powersync() +{ + return sqlite3_auto_extension((void (*)(void)) & sqlite3_powersync_init); } \ No newline at end of file diff --git a/src/libvfs.js b/src/libvfs.js index e6064f6..997b70a 100644 --- a/src/libvfs.js +++ b/src/libvfs.js @@ -22,7 +22,7 @@ const vfs_methods = { vfs['handleAsync'] = Asyncify.handleAsync; } - const mxPathName = vfs.mxPathName ?? 64; + const mxPathName = vfs['mxPathName'] ?? 64; const out = Module['_malloc'](4); const result = ccall('register_vfs', 'number', ['string', 'number', 'number', 'number'], [vfs.name, mxPathName, makeDefault ? 1 : 0, out]);