dns-worker 1.0.24 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +158 -109
  2. package/dist/serverfull.mjs +5319 -911
  3. package/migrations/0052_add_e2ee_to_logs.sql +6 -0
  4. package/migrations/0053_add_e2ee_key_tables.sql +31 -0
  5. package/migrations/0054_drop_hourly_rollups.sql +12 -0
  6. package/migrations/0055_add_is_active_to_user_log_keys.sql +2 -0
  7. package/migrations/0056_add_kem_keys_and_encrypt_version.sql +21 -0
  8. package/migrations/0057_add_idx_logs_kem_key_id.sql +2 -0
  9. package/package.json +8 -5
  10. package/static/_headers +8 -0
  11. package/static/assets/AccountView-CdfTI-rw.js +4 -0
  12. package/static/assets/AnalyticsView-DE25Td6t.js +2 -0
  13. package/static/assets/AuthView-DeKX1gG-.js +2 -0
  14. package/static/assets/DestinationMap-CRCdjD4S.js +1 -0
  15. package/static/assets/FilteringView-9SF7vAn0.js +1 -0
  16. package/static/assets/LogsView-DGXuCkRb.js +5 -0
  17. package/static/assets/QRCodeCanvas-9YjBSnzo.js +2 -0
  18. package/static/assets/RulesView-C8mXn9m8.js +1 -0
  19. package/static/assets/SettingsView-yiZeyh7q.js +1 -0
  20. package/static/assets/SetupView-r5GQKPN4.js +1 -0
  21. package/static/assets/{SwipeableDrawer-CzMJdF3W.js → SwipeableDrawer-DuXKmSrw.js} +1 -1
  22. package/static/assets/{TrendChart-Dl9UU7gA.js → TrendChart-BbPOeC8w.js} +3 -3
  23. package/static/assets/browser-BqNNtPRD.js +1 -0
  24. package/static/assets/date-dnUzoLoj.js +1 -0
  25. package/static/assets/de-DE-Bvn6LW48.js +10 -0
  26. package/static/assets/es-ES-BHMlKDw4.js +10 -0
  27. package/static/assets/fr-FR-DEgfea4H.js +10 -0
  28. package/static/assets/index-Ct0QwtUk.js +14 -0
  29. package/static/assets/index-D53KGRYV.css +2 -0
  30. package/static/assets/ja-JP-C1UasoOt.js +10 -0
  31. package/static/assets/ko-KR-DRVmuXAK.js +10 -0
  32. package/static/assets/ru-RU-BrUQ8HMM.js +10 -0
  33. package/static/assets/services-unF2tLc7.js +1 -0
  34. package/static/assets/sqlite.worker-C50yoTbX.js +186 -0
  35. package/static/assets/sqlite3-Con_VOcu.wasm +0 -0
  36. package/static/assets/sqlite3-opfs-async-proxy-Ck-yCayi.js +881 -0
  37. package/static/assets/sqlite3-opfs-async-proxy.js +881 -0
  38. package/static/assets/sqlite3-worker1-DZ2OAEkd.js +44 -0
  39. package/static/assets/vendor-react-GZisTXSQ.js +11 -0
  40. package/static/assets/{vendor-ui-core-CCxBtqRD.js → vendor-ui-core-BjAOArGo.js} +1 -1
  41. package/static/assets/vendor-utils-C-1rF3VB.js +9 -0
  42. package/static/assets/vi-VN-_fj_hwx9.js +10 -0
  43. package/static/assets/zh-CN-DRUEP9Sg.js +10 -0
  44. package/static/assets/zh-TW-v7FvDwjG.js +10 -0
  45. package/static/index.html +5 -5
  46. package/static/sqlite3-opfs-async-proxy.js +881 -0
  47. package/static/sw.js +1 -1
  48. package/static/assets/AccountView-yBM8r7xk.js +0 -4
  49. package/static/assets/AnalyticsView-CW9l8krm.js +0 -2
  50. package/static/assets/AuthView-BpLHhuif.js +0 -2
  51. package/static/assets/DestinationMap-DUZnyLyb.js +0 -1
  52. package/static/assets/FilteringView-BvOw_liH.js +0 -1
  53. package/static/assets/LogsView-CYxZaJPW.js +0 -5
  54. package/static/assets/QRCodeCanvas-vzXe_hzQ.js +0 -2
  55. package/static/assets/RulesView-CbToiqT1.js +0 -1
  56. package/static/assets/SettingsView-mSkxdlrh.js +0 -1
  57. package/static/assets/SetupView-Dzbc8NmG.js +0 -1
  58. package/static/assets/browser-BskSZoIg.js +0 -1
  59. package/static/assets/date-WF-_cJDs.js +0 -1
  60. package/static/assets/de-DE-CXKS_pep.js +0 -10
  61. package/static/assets/es-ES-B2e3ea35.js +0 -10
  62. package/static/assets/fr-FR-1qQHEpoW.js +0 -10
  63. package/static/assets/index-DLmOvLdX.js +0 -16
  64. package/static/assets/index-DdQuGqR5.css +0 -2
  65. package/static/assets/ja-JP-CCVeJXwX.js +0 -10
  66. package/static/assets/ko-KR-bQ1okpC2.js +0 -10
  67. package/static/assets/ru-RU-DeRsms_o.js +0 -10
  68. package/static/assets/services-C-uSOjyn.js +0 -1
  69. package/static/assets/vendor-react-DifRgRH3.js +0 -11
  70. package/static/assets/vendor-utils-D17P9mkD.js +0 -9
  71. package/static/assets/vi-VN-BcXfqmzH.js +0 -10
  72. package/static/assets/zh-CN-D8YK7j27.js +0 -12
  73. package/static/assets/zh-TW-C2_-uaZk.js +0 -12
@@ -0,0 +1,186 @@
1
+ /* @preserve
2
+ **
3
+ ** LICENSE for the sqlite3 WebAssembly/JavaScript APIs.
4
+ **
5
+ ** This bundle (typically released as sqlite3.js or sqlite3.mjs)
6
+ ** is an amalgamation of JavaScript source code from two projects:
7
+ **
8
+ ** 1) https://emscripten.org: the Emscripten "glue code" is covered by
9
+ ** the terms of the MIT license and University of Illinois/NCSA
10
+ ** Open Source License, as described at:
11
+ **
12
+ ** https://emscripten.org/docs/introducing_emscripten/emscripten_license.html
13
+ **
14
+ ** 2) https://sqlite.org: all code and documentation labeled as being
15
+ ** from this source are released under the same terms as the sqlite3
16
+ ** C library:
17
+ **
18
+ ** 2022-10-16
19
+ **
20
+ ** The author disclaims copyright to this source code. In place of a
21
+ ** legal notice, here is a blessing:
22
+ **
23
+ ** * May you do good and not evil.
24
+ ** * May you find forgiveness for yourself and forgive others.
25
+ ** * May you share freely, never taking more than you give.
26
+ */
27
+ /* @preserve
28
+ ** This code was built from sqlite3 version...
29
+ **
30
+ ** SQLITE_VERSION "3.53.4"
31
+ ** SQLITE_VERSION_NUMBER 3053004
32
+ ** SQLITE_SOURCE_ID "2026-07-24 19:02:57 bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bcc"
33
+ **
34
+ ** Emscripten SDK: 5.0.5
35
+ */
36
+ async function e(e={}){var t,n=e,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope;globalThis.process?.versions?.node&&globalThis.process?.type;var a=`./this.program`,o=import.meta.url,s=``;function c(e){return n.locateFile?n.locateFile(e,s):s+e}var l,u;if(r||i){try{s=new URL(`.`,o).href}catch{}i&&(u=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),l=async e=>{var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var d=console.log.bind(console),f=console.error.bind(console),p,m=!1,h,g,_=!1;function y(){var e=U.buffer;I=new Int8Array(e),N=new Int16Array(e),V=new Uint8Array(e),R=new Uint16Array(e),P=new Int32Array(e),z=new Uint32Array(e),L=new Float32Array(e),te=new Float64Array(e),F=new BigInt64Array(e),B=new BigUint64Array(e)}function b(){if(n.wasmMemory)U=n.wasmMemory;else{var e=n.INITIAL_MEMORY||8388608;U=new WebAssembly.Memory({initial:e/65536,maximum:32768})}y()}function x(){if(n.preRun)for(typeof n.preRun==`function`&&(n.preRun=[n.preRun]);n.preRun.length;)ae(n.preRun.shift());ne(ie)}function S(){_=!0,!n.noFSInit&&!Z.initialized&&Z.init(),q.init(),Ft.__wasm_call_ctors(),Z.ignorePermissions=!1}function C(){if(n.postRun)for(typeof n.postRun==`function`&&(n.postRun=[n.postRun]);n.postRun.length;)H(n.postRun.shift());ne(re)}function w(e){n.onAbort?.(e),e=`Aborted(${e})`,f(e),m=!0,e+=`. Build with -sASSERTIONS for more info.`;var t=new WebAssembly.RuntimeError(e);throw g?.(t),t}var T;function E(){return n.locateFile?c(`sqlite3.wasm`):new URL(`/assets/sqlite3-Con_VOcu.wasm`,``+import.meta.url).href}function D(e){if(e==T&&p)return new Uint8Array(p);if(u)return u(e);throw`both async and sync fetching of the wasm failed`}async function O(e){if(!p)try{var t=await l(e);return new Uint8Array(t)}catch{}return D(e)}async function A(e,t){try{var n=await O(e);return await WebAssembly.instantiate(n,t)}catch(e){f(`failed to asynchronously prepare wasm: ${e}`),w(e)}}async function j(e,t,n){if(!e)try{var r=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(r,n)}catch(e){f(`wasm streaming compile failed: ${e}`),f(`falling back to ArrayBuffer instantiation`)}return A(t,n)}function ee(){return{env:Nt,wasi_snapshot_preview1:Nt}}async function M(){function e(e,t){return Ft=e.exports,Mt(Ft),Ft}function t(t){return e(t.instance)}var r=ee();return n.instantiateWasm?new Promise((t,i)=>{n.instantiateWasm(r,(n,r)=>{t(e(n,r))})}):(T??=E(),t(await j(p,T,r)))}var N,P,F,I,L,te,R,z,B,V,ne=e=>{for(;e.length>0;)e.shift()(n)},re=[],H=e=>re.push(e),ie=[],ae=e=>ie.push(e),U,W={isAbs:e=>e.charAt(0)===`/`,splitPath:e=>/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1),normalizeArray:(e,t)=>{for(var n=0,r=e.length-1;r>=0;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},normalize:e=>{var t=W.isAbs(e),n=e.slice(-1)===`/`;return e=W.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),!e&&!t&&(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},dirname:e=>{var t=W.splitPath(e),n=t[0],r=t[1];return!n&&!r?`.`:(r&&=r.slice(0,-1),n+r)},basename:e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],join:(...e)=>W.normalize(e.join(`/`)),join2:(e,t)=>W.normalize(e+`/`+t)},oe=()=>e=>(crypto.getRandomValues(e),0),se=e=>(se=oe())(e),G={resolve:(...e)=>{for(var t=``,n=!1,r=e.length-1;r>=-1&&!n;r--){var i=r>=0?e[r]:Z.cwd();if(typeof i!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!i)return``;t=i+`/`+t,n=W.isAbs(i)}return t=W.normalizeArray(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},relative:(e,t)=>{e=G.resolve(e).slice(1),t=G.resolve(t).slice(1);function n(e){for(var t=0;t<e.length&&e[t]===``;t++);for(var n=e.length-1;n>=0&&e[n]===``;n--);return t>n?[]:e.slice(t,n-t+1)}for(var r=n(e.split(`/`)),i=n(t.split(`/`)),a=Math.min(r.length,i.length),o=a,s=0;s<a;s++)if(r[s]!==i[s]){o=s;break}for(var c=[],s=o;s<r.length;s++)c.push(`..`);return c=c.concat(i.slice(o)),c.join(`/`)}},ce=new TextDecoder,le=(e,t,n,r)=>{var i=t+n;if(r)return i;for(;e[t]&&!(t>=i);)++t;return t},K=(e,t=0,n,r)=>{var i=le(e,t,n,r);return ce.decode(e.buffer?e.subarray(t,i):new Uint8Array(e.slice(t,i)))},ue=[],de=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);r<=127?t++:r<=2047?t+=2:r>=55296&&r<=57343?(t+=4,++n):t+=3}return t},fe=(e,t,n,r)=>{if(!(r>0))return 0;for(var i=n,a=n+r-1,o=0;o<e.length;++o){var s=e.codePointAt(o);if(s<=127){if(n>=a)break;t[n++]=s}else if(s<=2047){if(n+1>=a)break;t[n++]=192|s>>6,t[n++]=128|s&63}else if(s<=65535){if(n+2>=a)break;t[n++]=224|s>>12,t[n++]=128|s>>6&63,t[n++]=128|s&63}else{if(n+3>=a)break;t[n++]=240|s>>18,t[n++]=128|s>>12&63,t[n++]=128|s>>6&63,t[n++]=128|s&63,o++}}return t[n]=0,n-i},pe=(e,t,n)=>{var r=n>0?n:de(e)+1,i=Array(r),a=fe(e,i,0,i.length);return t&&(i.length=a),i},me=()=>{if(!ue.length){var e=null;if(globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
37
+ `)),!e)return null;ue=pe(e,!0)}return ue.shift()},q={ttys:[],init(){},shutdown(){},register(e,t){q.ttys[e]={input:[],output:[],ops:t},Z.registerDevice(e,q.stream_ops)},stream_ops:{open(e){var t=q.ttys[e.node.rdev];if(!t)throw new Z.ErrnoError(43);e.tty=t,e.seekable=!1},close(e){e.tty.ops.fsync(e.tty)},fsync(e){e.tty.ops.fsync(e.tty)},read(e,t,n,r,i){if(!e.tty||!e.tty.ops.get_char)throw new Z.ErrnoError(60);for(var a=0,o=0;o<r;o++){var s;try{s=e.tty.ops.get_char(e.tty)}catch{throw new Z.ErrnoError(29)}if(s===void 0&&a===0)throw new Z.ErrnoError(6);if(s==null)break;a++,t[n+o]=s}return a&&(e.node.atime=Date.now()),a},write(e,t,n,r,i){if(!e.tty||!e.tty.ops.put_char)throw new Z.ErrnoError(60);try{for(var a=0;a<r;a++)e.tty.ops.put_char(e.tty,t[n+a])}catch{throw new Z.ErrnoError(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),a}},default_tty_ops:{get_char(e){return me()},put_char(e,t){t===null||t===10?(d(K(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(d(K(e.output)),e.output=[])},ioctl_tcgets(e){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(e,t,n){return 0},ioctl_tiocgwinsz(e){return[24,80]}},default_tty1_ops:{put_char(e,t){t===null||t===10?(f(K(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(f(K(e.output)),e.output=[])}}},he=(e,t)=>V.fill(0,e,e+t),ge=(e,t)=>Math.ceil(e/t)*t,_e=e=>{e=ge(e,65536);var t=jt(65536,e);return t&&he(t,e),t},J={ops_table:null,mount(e){return J.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if(Z.isBlkdev(n)||Z.isFIFO(n))throw new Z.ErrnoError(63);J.ops_table||={dir:{node:{getattr:J.node_ops.getattr,setattr:J.node_ops.setattr,lookup:J.node_ops.lookup,mknod:J.node_ops.mknod,rename:J.node_ops.rename,unlink:J.node_ops.unlink,rmdir:J.node_ops.rmdir,readdir:J.node_ops.readdir,symlink:J.node_ops.symlink},stream:{llseek:J.stream_ops.llseek}},file:{node:{getattr:J.node_ops.getattr,setattr:J.node_ops.setattr},stream:{llseek:J.stream_ops.llseek,read:J.stream_ops.read,write:J.stream_ops.write,mmap:J.stream_ops.mmap,msync:J.stream_ops.msync}},link:{node:{getattr:J.node_ops.getattr,setattr:J.node_ops.setattr,readlink:J.node_ops.readlink},stream:{}},chrdev:{node:{getattr:J.node_ops.getattr,setattr:J.node_ops.setattr},stream:Z.chrdev_stream_ops}};var i=Z.createNode(e,t,n,r);return Z.isDir(i.mode)?(i.node_ops=J.ops_table.dir.node,i.stream_ops=J.ops_table.dir.stream,i.contents={}):Z.isFile(i.mode)?(i.node_ops=J.ops_table.file.node,i.stream_ops=J.ops_table.file.stream,i.usedBytes=0,i.contents=J.emptyFileContents??=new Uint8Array):Z.isLink(i.mode)?(i.node_ops=J.ops_table.link.node,i.stream_ops=J.ops_table.link.stream):Z.isChrdev(i.mode)&&(i.node_ops=J.ops_table.chrdev.node,i.stream_ops=J.ops_table.chrdev.stream),i.atime=i.mtime=i.ctime=Date.now(),e&&(e.contents[t]=i,e.atime=e.mtime=e.ctime=i.atime),i},getFileDataAsTypedArray(e){return e.contents.subarray(0,e.usedBytes)},expandFileStorage(e,t){var n=e.contents.length;if(!(n>=t)){t=Math.max(t,n*(n<1048576?2:1.125)>>>0),n&&(t=Math.max(t,256));var r=J.getFileDataAsTypedArray(e);e.contents=new Uint8Array(t),e.contents.set(r)}},resizeFileStorage(e,t){if(e.usedBytes!=t){var n=e.contents;e.contents=new Uint8Array(t),e.contents.set(n.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}},node_ops:{getattr(e){var t={};return t.dev=Z.isChrdev(e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,Z.isDir(e.mode)?t.size=4096:Z.isFile(e.mode)?t.size=e.usedBytes:Z.isLink(e.mode)?t.size=e.link.length:t.size=0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){for(let n of[`mode`,`atime`,`mtime`,`ctime`])t[n]!=null&&(e[n]=t[n]);t.size!==void 0&&J.resizeFileStorage(e,t.size)},lookup(e,t){throw J.doesNotExistError||(J.doesNotExistError=new Z.ErrnoError(44),J.doesNotExistError.stack=`<generic error, no stack>`),J.doesNotExistError},mknod(e,t,n,r){return J.createNode(e,t,n,r)},rename(e,t,n){var r;try{r=Z.lookupNode(t,n)}catch{}if(r){if(Z.isDir(e.mode))for(var i in r.contents)throw new Z.ErrnoError(55);Z.hashRemoveNode(r)}delete e.parent.contents[e.name],t.contents[n]=e,e.name=n,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.contents[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){for(var n in Z.lookupNode(e,t).contents)throw new Z.ErrnoError(55);delete e.contents[t],e.ctime=e.mtime=Date.now()},readdir(e){return[`.`,`..`,...Object.keys(e.contents)]},symlink(e,t,n){var r=J.createNode(e,t,41471,0);return r.link=n,r},readlink(e){if(!Z.isLink(e.mode))throw new Z.ErrnoError(28);return e.link}},stream_ops:{read(e,t,n,r,i){var a=e.node.contents;if(i>=e.node.usedBytes)return 0;var o=Math.min(e.node.usedBytes-i,r);return t.set(a.subarray(i,i+o),n),o},write(e,t,n,r,i,a){if(t.buffer===I.buffer&&(a=!1),!r)return 0;var o=e.node;return o.mtime=o.ctime=Date.now(),a?(o.contents=t.subarray(n,n+r),o.usedBytes=r):o.usedBytes===0&&i===0?(o.contents=t.slice(n,n+r),o.usedBytes=r):(J.expandFileStorage(o,i+r),o.contents.set(t.subarray(n,n+r),i),o.usedBytes=Math.max(o.usedBytes,i+r)),r},llseek(e,t,n){var r=t;if(n===1?r+=e.position:n===2&&Z.isFile(e.node.mode)&&(r+=e.node.usedBytes),r<0)throw new Z.ErrnoError(28);return r},mmap(e,t,n,r,i){if(!Z.isFile(e.node.mode))throw new Z.ErrnoError(43);var a,o,s=e.node.contents;if(!(i&2)&&s.buffer===I.buffer)o=!1,a=s.byteOffset;else{if(o=!0,a=_e(t),!a)throw new Z.ErrnoError(48);s&&((n>0||n+t<s.length)&&(s=s.subarray?s.subarray(n,n+t):Array.prototype.slice.call(s,n,n+t)),I.set(s,a))}return{ptr:a,allocated:o}},msync(e,t,n,r,i){return J.stream_ops.write(e,t,0,r,n,!1),0}}},ve=e=>{if(typeof e!=`string`)return e;var t={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[e];if(t===void 0)throw Error(`Unknown file open mode: ${e}`);return t},ye=e=>(typeof e==`string`&&(e=pe(e,!0)),e.subarray||(e=new Uint8Array(e)),e),be=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},xe=async e=>{var t=await l(e);return new Uint8Array(t)},Se=(...e)=>Z.createDataFile(...e),Y=e=>e,X=0,Ce=null,we=e=>{if(X--,n.monitorRunDependencies?.(X),X==0&&Ce){var t=Ce;Ce=null,t()}},Te=e=>{X++,n.monitorRunDependencies?.(X)},Ee=[],De=async(e,t)=>{typeof Browser<`u`&&Browser.init();for(var n of Ee)if(n.canHandle(t))return n.handle(e,t);return e},Oe=async(e,t,n,r,i,a,o,s)=>{var c=t?G.resolve(W.join2(e,t)):e,l=Y(`cp ${c}`);Te(l);try{var u=n;typeof n==`string`&&(u=await xe(n)),u=await De(u,c),s?.(),a||Se(e,t,u,r,i,o)}finally{we(l)}},ke=(e,t,n,r,i,a,o,s,c,l)=>{Oe(e,t,n,r,i,s,c,l).then(a).catch(o)},Z={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:`/`,initialized:!1,ignorePermissions:!0,filesystems:null,syncFSRequests:0,ErrnoError:class{name=`ErrnoError`;constructor(e){this.errno=e}},FSStream:class{shared={};get object(){return this.node}set object(e){this.node=e}get isRead(){return(this.flags&2097155)!=1}get isWrite(){return(this.flags&2097155)!=0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(e){this.shared.flags=e}get position(){return this.shared.position}set position(e){this.shared.position=e}},FSNode:class{node_ops={};stream_ops={};readMode=365;writeMode=146;mounted=null;constructor(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.id=Z.nextInode++,this.name=t,this.mode=n,this.rdev=r,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(e){e?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(e){e?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return Z.isDir(this.mode)}get isDevice(){return Z.isChrdev(this.mode)}},lookupPath(e,t={}){if(!e)throw new Z.ErrnoError(44);t.follow_mount??=!0,W.isAbs(e)||(e=Z.cwd()+`/`+e);linkloop:for(var n=0;n<40;n++){for(var r=e.split(`/`).filter(e=>!!e),i=Z.root,a=`/`,o=0;o<r.length;o++){var s=o===r.length-1;if(s&&t.parent)break;if(r[o]!==`.`){if(r[o]===`..`){if(a=W.dirname(a),Z.isRoot(i)){e=a+`/`+r.slice(o+1).join(`/`),n--;continue linkloop}else i=i.parent;continue}a=W.join2(a,r[o]);try{i=Z.lookupNode(i,r[o])}catch(e){if(e?.errno===44&&s&&t.noent_okay)return{path:a};throw e}if(Z.isMountpoint(i)&&(!s||t.follow_mount)&&(i=i.mounted.root),Z.isLink(i.mode)&&(!s||t.follow)){if(!i.node_ops.readlink)throw new Z.ErrnoError(52);var c=i.node_ops.readlink(i);W.isAbs(c)||(c=W.dirname(a)+`/`+c),e=c+`/`+r.slice(o+1).join(`/`);continue linkloop}}}return{path:a,node:i}}throw new Z.ErrnoError(32)},getPath(e){for(var t;;){if(Z.isRoot(e)){var n=e.mount.mountpoint;return t?n[n.length-1]===`/`?n+t:`${n}/${t}`:n}t=t?`${e.name}/${t}`:e.name,e=e.parent}},hashName(e,t){for(var n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r)|0;return(e+n>>>0)%Z.nameTable.length},hashAddNode(e){var t=Z.hashName(e.parent.id,e.name);e.name_next=Z.nameTable[t],Z.nameTable[t]=e},hashRemoveNode(e){var t=Z.hashName(e.parent.id,e.name);if(Z.nameTable[t]===e)Z.nameTable[t]=e.name_next;else for(var n=Z.nameTable[t];n;){if(n.name_next===e){n.name_next=e.name_next;break}n=n.name_next}},lookupNode(e,t){var n=Z.mayLookup(e);if(n)throw new Z.ErrnoError(n);for(var r=Z.hashName(e.id,t),i=Z.nameTable[r];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===t)return i}return Z.lookup(e,t)},createNode(e,t,n,r){var i=new Z.FSNode(e,t,n,r);return Z.hashAddNode(i),i},destroyNode(e){Z.hashRemoveNode(e)},isRoot(e){return e===e.parent},isMountpoint(e){return!!e.mounted},isFile(e){return(e&61440)==32768},isDir(e){return(e&61440)==16384},isLink(e){return(e&61440)==40960},isChrdev(e){return(e&61440)==8192},isBlkdev(e){return(e&61440)==24576},isFIFO(e){return(e&61440)==4096},isSocket(e){return(e&49152)==49152},flagsToPermissionString(e){var t=[`r`,`w`,`rw`][e&3];return e&512&&(t+=`w`),t},nodePermissions(e,t){return Z.ignorePermissions?0:t.includes(`r`)&&!(e.mode&292)||t.includes(`w`)&&!(e.mode&146)||t.includes(`x`)&&!(e.mode&73)?2:0},mayLookup(e){return Z.isDir(e.mode)?Z.nodePermissions(e,`x`)||(e.node_ops.lookup?0:2):54},mayCreate(e,t){if(!Z.isDir(e.mode))return 54;try{return Z.lookupNode(e,t),20}catch{}return Z.nodePermissions(e,`wx`)},mayDelete(e,t,n){var r;try{r=Z.lookupNode(e,t)}catch(e){return e.errno}var i=Z.nodePermissions(e,`wx`);if(i)return i;if(n){if(!Z.isDir(r.mode))return 54;if(Z.isRoot(r)||Z.getPath(r)===Z.cwd())return 10}else if(Z.isDir(r.mode))return 31;return 0},mayOpen(e,t){if(!e)return 44;if(Z.isLink(e.mode))return 32;var n=Z.flagsToPermissionString(t);return Z.isDir(e.mode)&&(n!==`r`||t&576)?31:Z.nodePermissions(e,n)},checkOpExists(e,t){if(!e)throw new Z.ErrnoError(t);return e},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=Z.MAX_OPEN_FDS;e++)if(!Z.streams[e])return e;throw new Z.ErrnoError(33)},getStreamChecked(e){var t=Z.getStream(e);if(!t)throw new Z.ErrnoError(8);return t},getStream:e=>Z.streams[e],createStream(e,t=-1){return e=Object.assign(new Z.FSStream,e),t==-1&&(t=Z.nextfd()),e.fd=t,Z.streams[t]=e,e},closeStream(e){Z.streams[e]=null},dupStream(e,t=-1){var n=Z.createStream(e,t);return n.stream_ops?.dup?.(n),n},doSetAttr(e,t,n){var r=e?.stream_ops.setattr,i=r?e:t;r??=t.node_ops.setattr,Z.checkOpExists(r,63),r(i,n)},chrdev_stream_ops:{open(e){e.stream_ops=Z.getDevice(e.node.rdev).stream_ops,e.stream_ops.open?.(e)},llseek(){throw new Z.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,t)=>e<<8|t,registerDevice(e,t){Z.devices[e]={stream_ops:t}},getDevice:e=>Z.devices[e],getMounts(e){for(var t=[],n=[e];n.length;){var r=n.pop();t.push(r),n.push(...r.mounts)}return t},syncfs(e,t){typeof e==`function`&&(t=e,e=!1),Z.syncFSRequests++,Z.syncFSRequests>1&&f(`warning: ${Z.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var n=Z.getMounts(Z.root.mount),r=0;function i(e){return Z.syncFSRequests--,t(e)}function a(e){if(e)return a.errored?void 0:(a.errored=!0,i(e));++r>=n.length&&i(null)}for(var o of n)o.type.syncfs?o.type.syncfs(o,e,a):a(null)},mount(e,t,n){var r=n===`/`,i=!n,a;if(r&&Z.root)throw new Z.ErrnoError(10);if(!r&&!i){var o=Z.lookupPath(n,{follow_mount:!1});if(n=o.path,a=o.node,Z.isMountpoint(a))throw new Z.ErrnoError(10);if(!Z.isDir(a.mode))throw new Z.ErrnoError(54)}var s={type:e,opts:t,mountpoint:n,mounts:[]},c=e.mount(s);return c.mount=s,s.root=c,r?Z.root=c:a&&(a.mounted=s,a.mount&&a.mount.mounts.push(s)),c},unmount(e){var t=Z.lookupPath(e,{follow_mount:!1});if(!Z.isMountpoint(t.node))throw new Z.ErrnoError(28);var n=t.node,r=n.mounted,i=Z.getMounts(r);for(var[a,o]of Object.entries(Z.nameTable))for(;o;){var s=o.name_next;i.includes(o.mount)&&Z.destroyNode(o),o=s}n.mounted=null;var c=n.mount.mounts.indexOf(r);n.mount.mounts.splice(c,1)},lookup(e,t){return e.node_ops.lookup(e,t)},mknod(e,t,n){var r=Z.lookupPath(e,{parent:!0}).node,i=W.basename(e);if(!i)throw new Z.ErrnoError(28);if(i===`.`||i===`..`)throw new Z.ErrnoError(20);var a=Z.mayCreate(r,i);if(a)throw new Z.ErrnoError(a);if(!r.node_ops.mknod)throw new Z.ErrnoError(63);return r.node_ops.mknod(r,i,t,n)},statfs(e){return Z.statfsNode(Z.lookupPath(e,{follow:!0}).node)},statfsStream(e){return Z.statfsNode(e.node)},statfsNode(e){var t={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:Z.nextInode,ffree:Z.nextInode-1,fsid:42,flags:2,namelen:255};return e.node_ops.statfs&&Object.assign(t,e.node_ops.statfs(e.mount.opts.root)),t},create(e,t=438){return t&=4095,t|=32768,Z.mknod(e,t,0)},mkdir(e,t=511){return t&=1023,t|=16384,Z.mknod(e,t,0)},mkdirTree(e,t){var n=e.split(`/`),r=``;for(var i of n)if(i){(r||W.isAbs(e))&&(r+=`/`),r+=i;try{Z.mkdir(r,t)}catch(e){if(e.errno!=20)throw e}}},mkdev(e,t,n){return n===void 0&&(n=t,t=438),t|=8192,Z.mknod(e,t,n)},symlink(e,t){if(!G.resolve(e))throw new Z.ErrnoError(44);var n=Z.lookupPath(t,{parent:!0}).node;if(!n)throw new Z.ErrnoError(44);var r=W.basename(t),i=Z.mayCreate(n,r);if(i)throw new Z.ErrnoError(i);if(!n.node_ops.symlink)throw new Z.ErrnoError(63);return n.node_ops.symlink(n,r,e)},rename(e,t){var n=W.dirname(e),r=W.dirname(t),i=W.basename(e),a=W.basename(t),o=Z.lookupPath(e,{parent:!0}),s=o.node,c;if(o=Z.lookupPath(t,{parent:!0}),c=o.node,!s||!c)throw new Z.ErrnoError(44);if(s.mount!==c.mount)throw new Z.ErrnoError(75);var l=Z.lookupNode(s,i),u=G.relative(e,r);if(u.charAt(0)!==`.`)throw new Z.ErrnoError(28);if(u=G.relative(t,n),u.charAt(0)!==`.`)throw new Z.ErrnoError(55);var d;try{d=Z.lookupNode(c,a)}catch{}if(l!==d){var f=Z.isDir(l.mode),p=Z.mayDelete(s,i,f);if(p||(p=d?Z.mayDelete(c,a,f):Z.mayCreate(c,a),p))throw new Z.ErrnoError(p);if(!s.node_ops.rename)throw new Z.ErrnoError(63);if(Z.isMountpoint(l)||d&&Z.isMountpoint(d))throw new Z.ErrnoError(10);if(c!==s&&(p=Z.nodePermissions(s,`w`),p))throw new Z.ErrnoError(p);Z.hashRemoveNode(l);try{s.node_ops.rename(l,c,a),l.parent=c}catch(e){throw e}finally{Z.hashAddNode(l)}}},rmdir(e){var t=Z.lookupPath(e,{parent:!0}).node,n=W.basename(e),r=Z.lookupNode(t,n),i=Z.mayDelete(t,n,!0);if(i)throw new Z.ErrnoError(i);if(!t.node_ops.rmdir)throw new Z.ErrnoError(63);if(Z.isMountpoint(r))throw new Z.ErrnoError(10);t.node_ops.rmdir(t,n),Z.destroyNode(r)},readdir(e){var t=Z.lookupPath(e,{follow:!0}).node;return Z.checkOpExists(t.node_ops.readdir,54)(t)},unlink(e){var t=Z.lookupPath(e,{parent:!0}).node;if(!t)throw new Z.ErrnoError(44);var n=W.basename(e),r=Z.lookupNode(t,n),i=Z.mayDelete(t,n,!1);if(i)throw new Z.ErrnoError(i);if(!t.node_ops.unlink)throw new Z.ErrnoError(63);if(Z.isMountpoint(r))throw new Z.ErrnoError(10);t.node_ops.unlink(t,n),Z.destroyNode(r)},readlink(e){var t=Z.lookupPath(e).node;if(!t)throw new Z.ErrnoError(44);if(!t.node_ops.readlink)throw new Z.ErrnoError(28);return t.node_ops.readlink(t)},stat(e,t){var n=Z.lookupPath(e,{follow:!t}).node;return Z.checkOpExists(n.node_ops.getattr,63)(n)},fstat(e){var t=Z.getStreamChecked(e),n=t.node,r=t.stream_ops.getattr,i=r?t:n;return r??=n.node_ops.getattr,Z.checkOpExists(r,63),r(i)},lstat(e){return Z.stat(e,!0)},doChmod(e,t,n,r){Z.doSetAttr(e,t,{mode:n&4095|t.mode&-4096,ctime:Date.now(),dontFollow:r})},chmod(e,t,n){var r=typeof e==`string`?Z.lookupPath(e,{follow:!n}).node:e;Z.doChmod(null,r,t,n)},lchmod(e,t){Z.chmod(e,t,!0)},fchmod(e,t){var n=Z.getStreamChecked(e);Z.doChmod(n,n.node,t,!1)},doChown(e,t,n){Z.doSetAttr(e,t,{timestamp:Date.now(),dontFollow:n})},chown(e,t,n,r){var i=typeof e==`string`?Z.lookupPath(e,{follow:!r}).node:e;Z.doChown(null,i,r)},lchown(e,t,n){Z.chown(e,t,n,!0)},fchown(e,t,n){var r=Z.getStreamChecked(e);Z.doChown(r,r.node,!1)},doTruncate(e,t,n){if(Z.isDir(t.mode))throw new Z.ErrnoError(31);if(!Z.isFile(t.mode))throw new Z.ErrnoError(28);var r=Z.nodePermissions(t,`w`);if(r)throw new Z.ErrnoError(r);Z.doSetAttr(e,t,{size:n,timestamp:Date.now()})},truncate(e,t){if(t<0)throw new Z.ErrnoError(28);var n=typeof e==`string`?Z.lookupPath(e,{follow:!0}).node:e;Z.doTruncate(null,n,t)},ftruncate(e,t){var n=Z.getStreamChecked(e);if(t<0||!(n.flags&2097155))throw new Z.ErrnoError(28);Z.doTruncate(n,n.node,t)},utime(e,t,n){var r=Z.lookupPath(e,{follow:!0}).node;Z.checkOpExists(r.node_ops.setattr,63)(r,{atime:t,mtime:n})},open(e,t,n=438){if(e===``)throw new Z.ErrnoError(44);t=ve(t),n=t&64?n&4095|32768:0;var r,i;if(typeof e==`object`)r=e;else{i=e.endsWith(`/`);var a=Z.lookupPath(e,{follow:!(t&131072),noent_okay:!0});r=a.node,e=a.path}var o=!1;if(t&64)if(r){if(t&128)throw new Z.ErrnoError(20)}else if(i)throw new Z.ErrnoError(31);else r=Z.mknod(e,n|511,0),o=!0;if(!r)throw new Z.ErrnoError(44);if(Z.isChrdev(r.mode)&&(t&=-513),t&65536&&!Z.isDir(r.mode))throw new Z.ErrnoError(54);if(!o){var s=Z.mayOpen(r,t);if(s)throw new Z.ErrnoError(s)}t&512&&!o&&Z.truncate(r,0),t&=-131713;var c=Z.createStream({node:r,path:Z.getPath(r),flags:t,seekable:!0,position:0,stream_ops:r.stream_ops,ungotten:[],error:!1});return c.stream_ops.open&&c.stream_ops.open(c),o&&Z.chmod(r,n&511),c},close(e){if(Z.isClosed(e))throw new Z.ErrnoError(8);e.getdents&&=null;try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{Z.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,t,n){if(Z.isClosed(e))throw new Z.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new Z.ErrnoError(70);if(n!=0&&n!=1&&n!=2)throw new Z.ErrnoError(28);return e.position=e.stream_ops.llseek(e,t,n),e.ungotten=[],e.position},read(e,t,n,r,i){if(r<0||i<0)throw new Z.ErrnoError(28);if(Z.isClosed(e)||(e.flags&2097155)==1)throw new Z.ErrnoError(8);if(Z.isDir(e.node.mode))throw new Z.ErrnoError(31);if(!e.stream_ops.read)throw new Z.ErrnoError(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new Z.ErrnoError(70);var o=e.stream_ops.read(e,t,n,r,i);return a||(e.position+=o),o},write(e,t,n,r,i,a){if(r<0||i<0)throw new Z.ErrnoError(28);if(Z.isClosed(e)||!(e.flags&2097155))throw new Z.ErrnoError(8);if(Z.isDir(e.node.mode))throw new Z.ErrnoError(31);if(!e.stream_ops.write)throw new Z.ErrnoError(28);e.seekable&&e.flags&1024&&Z.llseek(e,0,2);var o=i!==void 0;if(!o)i=e.position;else if(!e.seekable)throw new Z.ErrnoError(70);var s=e.stream_ops.write(e,t,n,r,i,a);return o||(e.position+=s),s},mmap(e,t,n,r,i){if(r&2&&!(i&2)&&(e.flags&2097155)!=2||(e.flags&2097155)==1)throw new Z.ErrnoError(2);if(!e.stream_ops.mmap)throw new Z.ErrnoError(43);if(!t)throw new Z.ErrnoError(28);return e.stream_ops.mmap(e,t,n,r,i)},msync(e,t,n,r,i){return e.stream_ops.msync?e.stream_ops.msync(e,t,n,r,i):0},ioctl(e,t,n){if(!e.stream_ops.ioctl)throw new Z.ErrnoError(59);return e.stream_ops.ioctl(e,t,n)},readFile(e,t={}){t.flags=t.flags||0,t.encoding=t.encoding||`binary`,t.encoding!==`utf8`&&t.encoding!==`binary`&&w(`Invalid encoding type "${t.encoding}"`);var n=Z.open(e,t.flags),r=Z.stat(e).size,i=new Uint8Array(r);return Z.read(n,i,0,r,0),t.encoding===`utf8`&&(i=K(i)),Z.close(n),i},writeFile(e,t,n={}){n.flags=n.flags||577;var r=Z.open(e,n.flags,n.mode);t=ye(t),Z.write(r,t,0,t.byteLength,void 0,n.canOwn),Z.close(r)},cwd:()=>Z.currentPath,chdir(e){var t=Z.lookupPath(e,{follow:!0});if(t.node===null)throw new Z.ErrnoError(44);if(!Z.isDir(t.node.mode))throw new Z.ErrnoError(54);var n=Z.nodePermissions(t.node,`x`);if(n)throw new Z.ErrnoError(n);Z.currentPath=t.path},createDefaultDirectories(){Z.mkdir(`/tmp`),Z.mkdir(`/home`),Z.mkdir(`/home/web_user`)},createDefaultDevices(){Z.mkdir(`/dev`),Z.registerDevice(Z.makedev(1,3),{read:()=>0,write:(e,t,n,r,i)=>r,llseek:()=>0}),Z.mkdev(`/dev/null`,Z.makedev(1,3)),q.register(Z.makedev(5,0),q.default_tty_ops),q.register(Z.makedev(6,0),q.default_tty1_ops),Z.mkdev(`/dev/tty`,Z.makedev(5,0)),Z.mkdev(`/dev/tty1`,Z.makedev(6,0));var e=new Uint8Array(1024),t=0,n=()=>(t===0&&(se(e),t=e.byteLength),e[--t]);Z.createDevice(`/dev`,`random`,n),Z.createDevice(`/dev`,`urandom`,n),Z.mkdir(`/dev/shm`),Z.mkdir(`/dev/shm/tmp`)},createSpecialDirectories(){Z.mkdir(`/proc`);var e=Z.mkdir(`/proc/self`);Z.mkdir(`/proc/self/fd`),Z.mount({mount(){var t=Z.createNode(e,`fd`,16895,73);return t.stream_ops={llseek:J.stream_ops.llseek},t.node_ops={lookup(e,t){var n=+t,r=Z.getStreamChecked(n),i={parent:null,mount:{mountpoint:`fake`},node_ops:{readlink:()=>r.path},id:n+1};return i.parent=i,i},readdir(){return Array.from(Z.streams.entries()).filter(([e,t])=>t).map(([e,t])=>e.toString())}},t}},{},`/proc/self/fd`)},createStandardStreams(e,t,n){e?Z.createDevice(`/dev`,`stdin`,e):Z.symlink(`/dev/tty`,`/dev/stdin`),t?Z.createDevice(`/dev`,`stdout`,null,t):Z.symlink(`/dev/tty`,`/dev/stdout`),n?Z.createDevice(`/dev`,`stderr`,null,n):Z.symlink(`/dev/tty1`,`/dev/stderr`),Z.open(`/dev/stdin`,0),Z.open(`/dev/stdout`,1),Z.open(`/dev/stderr`,1)},staticInit(){Z.nameTable=Array(4096),Z.mount(J,{},`/`),Z.createDefaultDirectories(),Z.createDefaultDevices(),Z.createSpecialDirectories(),Z.filesystems={MEMFS:J}},init(e,t,r){Z.initialized=!0,e??=n.stdin,t??=n.stdout,r??=n.stderr,Z.createStandardStreams(e,t,r)},quit(){Z.initialized=!1;for(var e of Z.streams)e&&Z.close(e)},findObject(e,t){var n=Z.analyzePath(e,t);return n.exists?n.object:null},analyzePath(e,t){try{var n=Z.lookupPath(e,{follow:!t});e=n.path}catch{}var r={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var n=Z.lookupPath(e,{parent:!0});r.parentExists=!0,r.parentPath=n.path,r.parentObject=n.node,r.name=W.basename(e),n=Z.lookupPath(e,{follow:!t}),r.exists=!0,r.path=n.path,r.object=n.node,r.name=n.node.name,r.isRoot=n.path===`/`}catch(e){r.error=e.errno}return r},createPath(e,t,n,r){e=typeof e==`string`?e:Z.getPath(e);for(var i=t.split(`/`).reverse();i.length;){var a=i.pop();if(a){var o=W.join2(e,a);try{Z.mkdir(o)}catch(e){if(e.errno!=20)throw e}e=o}}return o},createFile(e,t,n,r,i){var a=W.join2(typeof e==`string`?e:Z.getPath(e),t),o=be(r,i);return Z.create(a,o)},createDataFile(e,t,n,r,i,a){var o=t;e&&(e=typeof e==`string`?e:Z.getPath(e),o=t?W.join2(e,t):e);var s=be(r,i),c=Z.create(o,s);if(n){n=ye(n),Z.chmod(c,s|146);var l=Z.open(c,577);Z.write(l,n,0,n.length,0,a),Z.close(l),Z.chmod(c,s)}},createDevice(e,t,n,r){var i=W.join2(typeof e==`string`?e:Z.getPath(e),t),a=be(!!n,!!r);Z.createDevice.major??=64;var o=Z.makedev(Z.createDevice.major++,0);return Z.registerDevice(o,{open(e){e.seekable=!1},close(e){r?.buffer?.length&&r(10)},read(e,t,r,i,a){for(var o=0,s=0;s<i;s++){var c;try{c=n()}catch{throw new Z.ErrnoError(29)}if(c===void 0&&o===0)throw new Z.ErrnoError(6);if(c==null)break;o++,t[r+s]=c}return o&&(e.node.atime=Date.now()),o},write(e,t,n,i,a){for(var o=0;o<i;o++)try{r(t[n+o])}catch{throw new Z.ErrnoError(29)}return i&&(e.node.mtime=e.node.ctime=Date.now()),o}}),Z.mkdev(i,a,o)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(globalThis.XMLHttpRequest)w(`Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.`);else try{e.contents=u(e.url)}catch{throw new Z.ErrnoError(29)}},createLazyFile(e,t,n,r,a){class o{lengthKnown=!1;chunks=[];get(e){if(!(e>this.length-1||e<0)){var t=e%this.chunkSize,n=e/this.chunkSize|0;return this.getter(n)[t]}}setDataGetter(e){this.getter=e}cacheLength(){var e=new XMLHttpRequest;e.open(`HEAD`,n,!1),e.send(null),e.status>=200&&e.status<300||e.status===304||w(`Couldn't load `+n+`. Status: `+e.status);var t=Number(e.getResponseHeader(`Content-length`)),r,i=(r=e.getResponseHeader(`Accept-Ranges`))&&r===`bytes`,a=(r=e.getResponseHeader(`Content-Encoding`))&&r===`gzip`,o=1048576;i||(o=t);var s=(e,r)=>{e>r&&w(`invalid range (`+e+`, `+r+`) or no bytes requested!`),r>t-1&&w(`only `+t+` bytes available! programmer error!`);var i=new XMLHttpRequest;return i.open(`GET`,n,!1),t!==o&&i.setRequestHeader(`Range`,`bytes=`+e+`-`+r),i.responseType=`arraybuffer`,i.overrideMimeType&&i.overrideMimeType(`text/plain; charset=x-user-defined`),i.send(null),i.status>=200&&i.status<300||i.status===304||w(`Couldn't load `+n+`. Status: `+i.status),i.response===void 0?pe(i.responseText||``,!0):new Uint8Array(i.response||[])},c=this;c.setDataGetter(e=>{var n=e*o,r=(e+1)*o-1;return r=Math.min(r,t-1),c.chunks[e]===void 0&&(c.chunks[e]=s(n,r)),c.chunks[e]===void 0&&w(`doXHR failed!`),c.chunks[e]}),(a||!t)&&(o=t=1,t=this.getter(0).length,o=t,d(`LazyFiles on gzip forces download of the whole file when length is accessed`)),this._length=t,this._chunkSize=o,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(globalThis.XMLHttpRequest){i||w(`Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc`);var s={isDevice:!1,contents:new o}}else var s={isDevice:!1,url:n};var c=Z.createFile(e,t,s,r,a);s.contents?c.contents=s.contents:s.url&&(c.contents=null,c.url=s.url),Object.defineProperties(c,{usedBytes:{get:function(){return this.contents.length}}});var l={};for(let[e,t]of Object.entries(c.stream_ops))l[e]=(...e)=>(Z.forceLoadFile(c),t(...e));function u(e,t,n,r,i){var a=e.node.contents;if(i>=a.length)return 0;var o=Math.min(a.length-i,r);if(a.slice)for(var s=0;s<o;s++)t[n+s]=a[i+s];else for(var s=0;s<o;s++)t[n+s]=a.get(i+s);return o}return l.read=(e,t,n,r,i)=>(Z.forceLoadFile(c),u(e,t,n,r,i)),l.mmap=(e,t,n,r,i)=>{Z.forceLoadFile(c);var a=_e(t);if(!a)throw new Z.ErrnoError(48);return u(e,I,a,t,n),{ptr:a,allocated:!0}},c.stream_ops=l,c}},Ae=(e,t,n)=>{if(!e)return``;var r=le(V,e,t,n);return ce.decode(V.subarray(e,r))},Q={calculateAt(e,t,n){if(W.isAbs(t))return t;var r=e===-100?Z.cwd():Q.getStreamFromFD(e).path;if(t.length==0){if(!n)throw new Z.ErrnoError(44);return r}return r+`/`+t},writeStat(e,t){z[e>>2]=t.dev,z[e+4>>2]=t.mode,z[e+8>>2]=t.nlink,z[e+12>>2]=t.uid,z[e+16>>2]=t.gid,z[e+20>>2]=t.rdev,F[e+24>>3]=BigInt(t.size),P[e+32>>2]=4096,P[e+36>>2]=t.blocks;var n=t.atime.getTime(),r=t.mtime.getTime(),i=t.ctime.getTime();return F[e+40>>3]=BigInt(Math.floor(n/1e3)),z[e+48>>2]=n%1e3*1e3*1e3,F[e+56>>3]=BigInt(Math.floor(r/1e3)),z[e+64>>2]=r%1e3*1e3*1e3,F[e+72>>3]=BigInt(Math.floor(i/1e3)),z[e+80>>2]=i%1e3*1e3*1e3,F[e+88>>3]=BigInt(t.ino),0},writeStatFs(e,t){z[e+4>>2]=t.bsize,z[e+60>>2]=t.bsize,F[e+8>>3]=BigInt(t.blocks),F[e+16>>3]=BigInt(t.bfree),F[e+24>>3]=BigInt(t.bavail),F[e+32>>3]=BigInt(t.files),F[e+40>>3]=BigInt(t.ffree),z[e+48>>2]=t.fsid,z[e+64>>2]=t.flags,z[e+56>>2]=t.namelen},doMsync(e,t,n,r,i){if(!Z.isFile(t.node.mode))throw new Z.ErrnoError(43);if(r&2)return 0;var a=V.slice(e,e+n);Z.msync(t,a,i,n,r)},getStreamFromFD(e){return Z.getStreamChecked(e)},varargs:void 0,getStr(e){return Ae(e)}};function je(e,t){try{return e=Q.getStr(e),Z.chmod(e,t),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Me(e,t,n,r){try{if(t=Q.getStr(t),t=Q.calculateAt(e,t),n&-8)return-28;var i=Z.lookupPath(t,{follow:!0}).node;if(!i)return-44;var a=``;return n&4&&(a+=`r`),n&2&&(a+=`w`),n&1&&(a+=`x`),a&&Z.nodePermissions(i,a)?-2:0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ne(e,t){try{return Z.fchmod(e,t),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Pe(e,t,n){try{return Z.fchown(e,t,n),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var Fe=()=>{var e=P[Q.varargs>>2];return Q.varargs+=4,e},Ie=Fe;function Le(e,t,n){Q.varargs=n;try{var r=Q.getStreamFromFD(e);switch(t){case 0:var i=Fe();if(i<0)return-28;for(;Z.streams[i];)i++;return Z.dupStream(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:var i=Fe();return r.flags|=i,0;case 12:var i=Ie(),a=0;return N[i+a>>1]=2,0;case 13:case 14:return 0}return-28}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Re(e,t){try{return Q.writeStat(t,Z.fstat(e))}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var ze=9007199254740992,Be=-9007199254740992,Ve=e=>e<Be||e>ze?NaN:Number(e);function He(e,t){t=Ve(t);try{return isNaN(t)?-61:(Z.ftruncate(e,t),0)}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var $=(e,t,n)=>fe(e,V,t,n);function Ue(e,t){try{if(t===0)return-28;var n=Z.cwd(),r=de(n)+1;return t<r?-68:($(n,e,t),r)}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function We(e,t,n){Q.varargs=n;try{var r=Q.getStreamFromFD(e);switch(t){case 21509:return r.tty?0:-59;case 21505:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcgets){var i=r.tty.ops.ioctl_tcgets(r),a=Ie();P[a>>2]=i.c_iflag||0,P[a+4>>2]=i.c_oflag||0,P[a+8>>2]=i.c_cflag||0,P[a+12>>2]=i.c_lflag||0;for(var o=0;o<32;o++)I[a+o+17]=i.c_cc[o]||0;return 0}return 0;case 21510:case 21511:case 21512:return r.tty?0:-59;case 21506:case 21507:case 21508:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcsets){for(var a=Ie(),s=P[a>>2],c=P[a+4>>2],l=P[a+8>>2],u=P[a+12>>2],d=[],o=0;o<32;o++)d.push(I[a+o+17]);return r.tty.ops.ioctl_tcsets(r.tty,t,{c_iflag:s,c_oflag:c,c_cflag:l,c_lflag:u,c_cc:d})}return 0;case 21519:if(!r.tty)return-59;var a=Ie();return P[a>>2]=0,0;case 21520:return r.tty?-28:-59;case 21537:case 21531:var a=Ie();return Z.ioctl(r,t,a);case 21523:if(!r.tty)return-59;if(r.tty.ops.ioctl_tiocgwinsz){var f=r.tty.ops.ioctl_tiocgwinsz(r.tty),a=Ie();N[a>>1]=f[0],N[a+2>>1]=f[1]}return 0;case 21524:return r.tty?0:-59;case 21515:return r.tty?0:-59;default:return-28}}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ge(e,t){try{return e=Q.getStr(e),Q.writeStat(t,Z.lstat(e))}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ke(e,t,n){try{return t=Q.getStr(t),t=Q.calculateAt(e,t),Z.mkdir(t,n,0),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function qe(e,t,n,r){try{t=Q.getStr(t);var i=r&256,a=r&4096;return r&=-6401,t=Q.calculateAt(e,t,a),Q.writeStat(n,i?Z.lstat(t):Z.stat(t))}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Je(e,t,n,r){Q.varargs=r;try{t=Q.getStr(t),t=Q.calculateAt(e,t);var i=r?Fe():0;return Z.open(t,n,i).fd}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ye(e,t,n,r){try{if(t=Q.getStr(t),t=Q.calculateAt(e,t),r<=0)return-28;var i=Z.readlink(t),a=Math.min(r,de(i)),o=I[n+a];return $(i,n,r+1),I[n+a]=o,a}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Xe(e){try{return e=Q.getStr(e),Z.rmdir(e),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ze(e,t){try{return e=Q.getStr(e),Q.writeStat(t,Z.stat(e))}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Qe(e,t,n){try{if(t=Q.getStr(t),t=Q.calculateAt(e,t),!n)Z.unlink(t);else if(n===512)Z.rmdir(t);else return-28;return 0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var $e=e=>z[e>>2]+P[e+4>>2]*4294967296;function et(e,t,n,r){try{t=Q.getStr(t),t=Q.calculateAt(e,t,!0);var i=Date.now(),a,o;if(!n)a=i,o=i;else{var s=$e(n),c=P[n+8>>2];a=c==1073741823?i:c==1073741822?null:s*1e3+c/1e6,n+=16,s=$e(n),c=P[n+8>>2],o=c==1073741823?i:c==1073741822?null:s*1e3+c/1e6}return(o??a)!==null&&Z.utime(t,a,o),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var tt=e=>e%4==0&&(e%100!=0||e%400==0),nt=[0,31,60,91,121,152,182,213,244,274,305,335],rt=[0,31,59,90,120,151,181,212,243,273,304,334],it=e=>(tt(e.getFullYear())?nt:rt)[e.getMonth()]+e.getDate()-1;function at(e,t){e=Ve(e);var n=new Date(e*1e3);P[t>>2]=n.getSeconds(),P[t+4>>2]=n.getMinutes(),P[t+8>>2]=n.getHours(),P[t+12>>2]=n.getDate(),P[t+16>>2]=n.getMonth(),P[t+20>>2]=n.getFullYear()-1900,P[t+24>>2]=n.getDay();var r=it(n)|0;P[t+28>>2]=r,P[t+36>>2]=-(n.getTimezoneOffset()*60);var i=new Date(n.getFullYear(),0,1),a=new Date(n.getFullYear(),6,1).getTimezoneOffset(),o=i.getTimezoneOffset(),s=(a!=o&&n.getTimezoneOffset()==Math.min(o,a))|0;P[t+32>>2]=s}function ot(e,t,n,r,i,a,o){i=Ve(i);try{var s=Q.getStreamFromFD(r),c=Z.mmap(s,e,i,t,n),l=c.ptr;return P[a>>2]=c.allocated,z[o>>2]=l,0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function st(e,t,n,r,i,a){a=Ve(a);try{var o=Q.getStreamFromFD(i);n&2&&Q.doMsync(e,o,t,r,a)}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var ct=(e,t,n,r)=>{var i=new Date().getFullYear(),a=new Date(i,0,1),o=new Date(i,6,1),s=a.getTimezoneOffset(),c=o.getTimezoneOffset(),l=Math.max(s,c);z[e>>2]=l*60,P[t>>2]=Number(s!=c);var u=e=>{var t=e>=0?`-`:`+`,n=Math.abs(e);return`UTC${t}${String(Math.floor(n/60)).padStart(2,`0`)}${String(n%60).padStart(2,`0`)}`},d=u(s),f=u(c);c<s?($(d,n,17),$(f,r,17)):($(d,r,17),$(f,n,17))},lt=()=>performance.now(),ut=()=>Date.now(),dt=1,ft=e=>e>=0&&e<=3;function pt(e,t,n){if(t=Ve(t),!ft(e))return 28;var r;if(e===0)r=ut();else if(dt)r=lt();else return 52;var i=Math.round(r*1e3*1e3);return F[n>>3]=BigInt(i),0}var mt=()=>2147483648,ht=()=>mt(),gt=e=>{var t=(e-U.buffer.byteLength+65535)/65536|0;try{return U.grow(t),y(),1}catch{}},_t=e=>{var t=V.length;e>>>=0;var n=mt();if(e>n)return!1;for(var r=1;r<=4;r*=2){var i=t*(1+.2/r);if(i=Math.min(i,e+100663296),gt(Math.min(n,ge(Math.max(e,i),65536))))return!0}return!1},vt={},yt=()=>a||`./this.program`,bt=()=>{if(!bt.strings){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(globalThis.navigator?.language??`C`).replace(`-`,`_`)+`.UTF-8`,_:yt()};for(var t in vt)vt[t]===void 0?delete e[t]:e[t]=vt[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);bt.strings=n}return bt.strings},xt=(e,t)=>{var n=0,r=0;for(var i of bt()){var a=t+n;z[e+r>>2]=a,n+=$(i,a,1/0)+1,r+=4}return 0},St=(e,t)=>{var n=bt();z[e>>2]=n.length;var r=0;for(var i of n)r+=de(i)+1;return z[t>>2]=r,0};function Ct(e){try{var t=Q.getStreamFromFD(e);return Z.close(t),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}function wt(e,t){try{var n=0,r=0,i=0,a=Q.getStreamFromFD(e),o=a.tty?2:Z.isDir(a.mode)?3:Z.isLink(a.mode)?7:4;return I[t]=o,N[t+2>>1]=i,F[t+8>>3]=BigInt(n),F[t+16>>3]=BigInt(r),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var Tt=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=z[t>>2],s=z[t+4>>2];t+=8;var c=Z.read(e,I,o,s,r);if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i};function Et(e,t,n,r){try{var i=Tt(Q.getStreamFromFD(e),t,n);return z[r>>2]=i,0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}function Dt(e,t,n,r){t=Ve(t);try{if(isNaN(t))return 61;var i=Q.getStreamFromFD(e);return Z.llseek(i,t,n),F[r>>3]=BigInt(i.position),i.getdents&&t===0&&n===0&&(i.getdents=null),0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}function Ot(e){try{var t=Q.getStreamFromFD(e);return t.stream_ops?.fsync?.(t)}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var kt=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=z[t>>2],s=z[t+4>>2];t+=8;var c=Z.write(e,I,o,s,r);if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i};function At(e,t,n,r){try{var i=kt(Q.getStreamFromFD(e),t,n);return z[r>>2]=i,0}catch(e){if(Z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}if(Z.createPreloadedFile=ke,Z.preloadFile=Oe,Z.staticInit(),b(),n.noExitRuntime&&n.noExitRuntime,n.preloadPlugins&&(Ee=n.preloadPlugins),n.print&&(d=n.print),n.printErr&&(f=n.printErr),n.wasmBinary&&(p=n.wasmBinary),n.arguments&&n.arguments,n.thisProgram&&(a=n.thisProgram),n.preInit)for(typeof n.preInit==`function`&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.shift()();n.wasmMemory=U;var jt;function Mt(e){n._sqlite3_status64=e.sqlite3_status64,n._sqlite3_status=e.sqlite3_status,n._sqlite3_db_status64=e.sqlite3_db_status64,n._sqlite3_msize=e.sqlite3_msize,n._sqlite3_db_status=e.sqlite3_db_status,n._sqlite3_vfs_find=e.sqlite3_vfs_find,n._sqlite3_initialize=e.sqlite3_initialize,n._sqlite3_malloc=e.sqlite3_malloc,n._sqlite3_free=e.sqlite3_free,n._sqlite3_vfs_register=e.sqlite3_vfs_register,n._sqlite3_vfs_unregister=e.sqlite3_vfs_unregister,n._sqlite3_malloc64=e.sqlite3_malloc64,n._sqlite3_realloc=e.sqlite3_realloc,n._sqlite3_realloc64=e.sqlite3_realloc64,n._sqlite3_value_text=e.sqlite3_value_text,n._sqlite3_randomness=e.sqlite3_randomness,n._sqlite3_stricmp=e.sqlite3_stricmp,n._sqlite3_strnicmp=e.sqlite3_strnicmp,n._sqlite3_uri_parameter=e.sqlite3_uri_parameter,n._sqlite3_uri_boolean=e.sqlite3_uri_boolean,n._sqlite3_serialize=e.sqlite3_serialize,n._sqlite3_prepare_v2=e.sqlite3_prepare_v2,n._sqlite3_step=e.sqlite3_step,n._sqlite3_column_int64=e.sqlite3_column_int64,n._sqlite3_reset=e.sqlite3_reset,n._sqlite3_exec=e.sqlite3_exec,n._sqlite3_column_int=e.sqlite3_column_int,n._sqlite3_finalize=e.sqlite3_finalize,n._sqlite3_file_control=e.sqlite3_file_control,n._sqlite3_column_name=e.sqlite3_column_name,n._sqlite3_column_text=e.sqlite3_column_text,n._sqlite3_column_type=e.sqlite3_column_type,n._sqlite3_errmsg=e.sqlite3_errmsg,n._sqlite3_deserialize=e.sqlite3_deserialize,n._sqlite3_clear_bindings=e.sqlite3_clear_bindings,n._sqlite3_value_blob=e.sqlite3_value_blob,n._sqlite3_value_bytes=e.sqlite3_value_bytes,n._sqlite3_value_double=e.sqlite3_value_double,n._sqlite3_value_int=e.sqlite3_value_int,n._sqlite3_value_int64=e.sqlite3_value_int64,n._sqlite3_value_subtype=e.sqlite3_value_subtype,n._sqlite3_value_pointer=e.sqlite3_value_pointer,n._sqlite3_value_type=e.sqlite3_value_type,n._sqlite3_value_nochange=e.sqlite3_value_nochange,n._sqlite3_value_frombind=e.sqlite3_value_frombind,n._sqlite3_value_dup=e.sqlite3_value_dup,n._sqlite3_value_free=e.sqlite3_value_free,n._sqlite3_result_blob=e.sqlite3_result_blob,n._sqlite3_result_error_toobig=e.sqlite3_result_error_toobig,n._sqlite3_result_error_nomem=e.sqlite3_result_error_nomem,n._sqlite3_result_double=e.sqlite3_result_double,n._sqlite3_result_error=e.sqlite3_result_error,n._sqlite3_result_int=e.sqlite3_result_int,n._sqlite3_result_int64=e.sqlite3_result_int64,n._sqlite3_result_null=e.sqlite3_result_null,n._sqlite3_result_pointer=e.sqlite3_result_pointer,n._sqlite3_result_subtype=e.sqlite3_result_subtype,n._sqlite3_result_text=e.sqlite3_result_text,n._sqlite3_result_zeroblob=e.sqlite3_result_zeroblob,n._sqlite3_result_zeroblob64=e.sqlite3_result_zeroblob64,n._sqlite3_result_error_code=e.sqlite3_result_error_code,n._sqlite3_user_data=e.sqlite3_user_data,n._sqlite3_context_db_handle=e.sqlite3_context_db_handle,n._sqlite3_vtab_nochange=e.sqlite3_vtab_nochange,n._sqlite3_vtab_in_first=e.sqlite3_vtab_in_first,n._sqlite3_vtab_in_next=e.sqlite3_vtab_in_next,n._sqlite3_aggregate_context=e.sqlite3_aggregate_context,n._sqlite3_get_auxdata=e.sqlite3_get_auxdata,n._sqlite3_set_auxdata=e.sqlite3_set_auxdata,n._sqlite3_column_count=e.sqlite3_column_count,n._sqlite3_data_count=e.sqlite3_data_count,n._sqlite3_column_blob=e.sqlite3_column_blob,n._sqlite3_column_bytes=e.sqlite3_column_bytes,n._sqlite3_column_double=e.sqlite3_column_double,n._sqlite3_column_value=e.sqlite3_column_value,n._sqlite3_column_decltype=e.sqlite3_column_decltype,n._sqlite3_column_database_name=e.sqlite3_column_database_name,n._sqlite3_column_table_name=e.sqlite3_column_table_name,n._sqlite3_column_origin_name=e.sqlite3_column_origin_name,n._sqlite3_bind_blob=e.sqlite3_bind_blob,n._sqlite3_bind_double=e.sqlite3_bind_double,n._sqlite3_bind_int=e.sqlite3_bind_int,n._sqlite3_bind_int64=e.sqlite3_bind_int64,n._sqlite3_bind_null=e.sqlite3_bind_null,n._sqlite3_bind_pointer=e.sqlite3_bind_pointer,n._sqlite3_bind_text=e.sqlite3_bind_text,n._sqlite3_bind_zeroblob=e.sqlite3_bind_zeroblob,n._sqlite3_bind_parameter_count=e.sqlite3_bind_parameter_count,n._sqlite3_bind_parameter_name=e.sqlite3_bind_parameter_name,n._sqlite3_bind_parameter_index=e.sqlite3_bind_parameter_index,n._sqlite3_db_handle=e.sqlite3_db_handle,n._sqlite3_stmt_readonly=e.sqlite3_stmt_readonly,n._sqlite3_stmt_isexplain=e.sqlite3_stmt_isexplain,n._sqlite3_stmt_explain=e.sqlite3_stmt_explain,n._sqlite3_stmt_busy=e.sqlite3_stmt_busy,n._sqlite3_next_stmt=e.sqlite3_next_stmt,n._sqlite3_stmt_status=e.sqlite3_stmt_status,n._sqlite3_sql=e.sqlite3_sql,n._sqlite3_expanded_sql=e.sqlite3_expanded_sql,n._sqlite3_preupdate_old=e.sqlite3_preupdate_old,n._sqlite3_preupdate_count=e.sqlite3_preupdate_count,n._sqlite3_preupdate_depth=e.sqlite3_preupdate_depth,n._sqlite3_preupdate_blobwrite=e.sqlite3_preupdate_blobwrite,n._sqlite3_preupdate_new=e.sqlite3_preupdate_new,n._sqlite3_value_numeric_type=e.sqlite3_value_numeric_type,n._sqlite3_set_authorizer=e.sqlite3_set_authorizer,n._sqlite3_strglob=e.sqlite3_strglob,n._sqlite3_strlike=e.sqlite3_strlike,n._sqlite3_auto_extension=e.sqlite3_auto_extension,n._sqlite3_cancel_auto_extension=e.sqlite3_cancel_auto_extension,n._sqlite3_reset_auto_extension=e.sqlite3_reset_auto_extension,n._sqlite3_prepare_v3=e.sqlite3_prepare_v3,n._sqlite3_create_module=e.sqlite3_create_module,n._sqlite3_create_module_v2=e.sqlite3_create_module_v2,n._sqlite3_drop_modules=e.sqlite3_drop_modules,n._sqlite3_declare_vtab=e.sqlite3_declare_vtab,n._sqlite3_vtab_on_conflict=e.sqlite3_vtab_on_conflict,n._sqlite3_vtab_collation=e.sqlite3_vtab_collation,n._sqlite3_vtab_in=e.sqlite3_vtab_in,n._sqlite3_vtab_rhs_value=e.sqlite3_vtab_rhs_value,n._sqlite3_vtab_distinct=e.sqlite3_vtab_distinct,n._sqlite3_keyword_name=e.sqlite3_keyword_name,n._sqlite3_keyword_count=e.sqlite3_keyword_count,n._sqlite3_keyword_check=e.sqlite3_keyword_check,n._sqlite3_complete=e.sqlite3_complete,n._sqlite3_libversion=e.sqlite3_libversion,n._sqlite3_libversion_number=e.sqlite3_libversion_number,n._sqlite3_shutdown=e.sqlite3_shutdown,n._sqlite3_last_insert_rowid=e.sqlite3_last_insert_rowid,n._sqlite3_set_last_insert_rowid=e.sqlite3_set_last_insert_rowid,n._sqlite3_changes64=e.sqlite3_changes64,n._sqlite3_changes=e.sqlite3_changes,n._sqlite3_total_changes64=e.sqlite3_total_changes64,n._sqlite3_total_changes=e.sqlite3_total_changes,n._sqlite3_txn_state=e.sqlite3_txn_state,n._sqlite3_close_v2=e.sqlite3_close_v2,n._sqlite3_busy_handler=e.sqlite3_busy_handler,n._sqlite3_progress_handler=e.sqlite3_progress_handler,n._sqlite3_busy_timeout=e.sqlite3_busy_timeout,n._sqlite3_interrupt=e.sqlite3_interrupt,n._sqlite3_is_interrupted=e.sqlite3_is_interrupted,n._sqlite3_create_function=e.sqlite3_create_function,n._sqlite3_create_function_v2=e.sqlite3_create_function_v2,n._sqlite3_create_window_function=e.sqlite3_create_window_function,n._sqlite3_overload_function=e.sqlite3_overload_function,n._sqlite3_trace_v2=e.sqlite3_trace_v2,n._sqlite3_commit_hook=e.sqlite3_commit_hook,n._sqlite3_update_hook=e.sqlite3_update_hook,n._sqlite3_rollback_hook=e.sqlite3_rollback_hook,n._sqlite3_preupdate_hook=e.sqlite3_preupdate_hook,n._sqlite3_set_errmsg=e.sqlite3_set_errmsg,n._sqlite3_error_offset=e.sqlite3_error_offset,n._sqlite3_errcode=e.sqlite3_errcode,n._sqlite3_extended_errcode=e.sqlite3_extended_errcode,n._sqlite3_errstr=e.sqlite3_errstr,n._sqlite3_limit=e.sqlite3_limit,n._sqlite3_open=e.sqlite3_open,n._sqlite3_open_v2=e.sqlite3_open_v2,n._sqlite3_create_collation=e.sqlite3_create_collation,n._sqlite3_create_collation_v2=e.sqlite3_create_collation_v2,n._sqlite3_collation_needed=e.sqlite3_collation_needed,n._sqlite3_get_autocommit=e.sqlite3_get_autocommit,n._sqlite3_table_column_metadata=e.sqlite3_table_column_metadata,n._sqlite3_extended_result_codes=e.sqlite3_extended_result_codes,n._sqlite3_uri_key=e.sqlite3_uri_key,n._sqlite3_uri_int64=e.sqlite3_uri_int64,n._sqlite3_db_name=e.sqlite3_db_name,n._sqlite3_db_filename=e.sqlite3_db_filename,n._sqlite3_db_readonly=e.sqlite3_db_readonly,n._sqlite3_compileoption_used=e.sqlite3_compileoption_used,n._sqlite3_compileoption_get=e.sqlite3_compileoption_get,n._sqlite3session_diff=e.sqlite3session_diff,n._sqlite3session_attach=e.sqlite3session_attach,n._sqlite3session_create=e.sqlite3session_create,n._sqlite3session_delete=e.sqlite3session_delete,n._sqlite3session_table_filter=e.sqlite3session_table_filter,n._sqlite3session_changeset=e.sqlite3session_changeset,n._sqlite3session_changeset_strm=e.sqlite3session_changeset_strm,n._sqlite3session_patchset_strm=e.sqlite3session_patchset_strm,n._sqlite3session_patchset=e.sqlite3session_patchset,n._sqlite3session_enable=e.sqlite3session_enable,n._sqlite3session_indirect=e.sqlite3session_indirect,n._sqlite3session_isempty=e.sqlite3session_isempty,n._sqlite3session_memory_used=e.sqlite3session_memory_used,n._sqlite3session_object_config=e.sqlite3session_object_config,n._sqlite3session_changeset_size=e.sqlite3session_changeset_size,n._sqlite3changeset_start=e.sqlite3changeset_start,n._sqlite3changeset_start_v2=e.sqlite3changeset_start_v2,n._sqlite3changeset_start_strm=e.sqlite3changeset_start_strm,n._sqlite3changeset_start_v2_strm=e.sqlite3changeset_start_v2_strm,n._sqlite3changeset_next=e.sqlite3changeset_next,n._sqlite3changeset_op=e.sqlite3changeset_op,n._sqlite3changeset_pk=e.sqlite3changeset_pk,n._sqlite3changeset_old=e.sqlite3changeset_old,n._sqlite3changeset_new=e.sqlite3changeset_new,n._sqlite3changeset_conflict=e.sqlite3changeset_conflict,n._sqlite3changeset_fk_conflicts=e.sqlite3changeset_fk_conflicts,n._sqlite3changeset_finalize=e.sqlite3changeset_finalize,n._sqlite3changeset_invert=e.sqlite3changeset_invert,n._sqlite3changeset_invert_strm=e.sqlite3changeset_invert_strm,n._sqlite3changeset_apply_v2=e.sqlite3changeset_apply_v2,n._sqlite3changeset_apply_v3=e.sqlite3changeset_apply_v3,n._sqlite3changeset_apply=e.sqlite3changeset_apply,n._sqlite3changeset_apply_v3_strm=e.sqlite3changeset_apply_v3_strm,n._sqlite3changeset_apply_v2_strm=e.sqlite3changeset_apply_v2_strm,n._sqlite3changeset_apply_strm=e.sqlite3changeset_apply_strm,n._sqlite3changegroup_new=e.sqlite3changegroup_new,n._sqlite3changegroup_add=e.sqlite3changegroup_add,n._sqlite3changegroup_output=e.sqlite3changegroup_output,n._sqlite3changegroup_add_strm=e.sqlite3changegroup_add_strm,n._sqlite3changegroup_output_strm=e.sqlite3changegroup_output_strm,n._sqlite3changegroup_delete=e.sqlite3changegroup_delete,n._sqlite3changeset_concat=e.sqlite3changeset_concat,n._sqlite3changeset_concat_strm=e.sqlite3changeset_concat_strm,n._sqlite3session_config=e.sqlite3session_config,n._sqlite3_sourceid=e.sqlite3_sourceid,n._sqlite3__wasm_pstack_ptr=e.sqlite3__wasm_pstack_ptr,n._sqlite3__wasm_pstack_restore=e.sqlite3__wasm_pstack_restore,n._sqlite3__wasm_pstack_alloc=e.sqlite3__wasm_pstack_alloc,n._sqlite3__wasm_pstack_remaining=e.sqlite3__wasm_pstack_remaining,n._sqlite3__wasm_pstack_quota=e.sqlite3__wasm_pstack_quota,n._sqlite3__wasm_test_struct=e.sqlite3__wasm_test_struct,n._sqlite3__wasm_enum_json=e.sqlite3__wasm_enum_json,n._sqlite3__wasm_vfs_unlink=e.sqlite3__wasm_vfs_unlink,n._sqlite3__wasm_db_vfs=e.sqlite3__wasm_db_vfs,n._sqlite3__wasm_db_reset=e.sqlite3__wasm_db_reset,n._sqlite3__wasm_db_export_chunked=e.sqlite3__wasm_db_export_chunked,n._sqlite3__wasm_db_serialize=e.sqlite3__wasm_db_serialize,n._sqlite3__wasm_vfs_create_file=e.sqlite3__wasm_vfs_create_file,n._sqlite3__wasm_posix_create_file=e.sqlite3__wasm_posix_create_file,n._sqlite3__wasm_kvvfsMakeKey=e.sqlite3__wasm_kvvfsMakeKey,n._sqlite3__wasm_kvvfs_methods=e.sqlite3__wasm_kvvfs_methods,n._sqlite3__wasm_vtab_config=e.sqlite3__wasm_vtab_config,n._sqlite3__wasm_db_config_ip=e.sqlite3__wasm_db_config_ip,n._sqlite3__wasm_db_config_pii=e.sqlite3__wasm_db_config_pii,n._sqlite3__wasm_db_config_s=e.sqlite3__wasm_db_config_s,n._sqlite3__wasm_config_i=e.sqlite3__wasm_config_i,n._sqlite3__wasm_config_ii=e.sqlite3__wasm_config_ii,n._sqlite3__wasm_config_j=e.sqlite3__wasm_config_j,n._sqlite3__wasm_qfmt_token=e.sqlite3__wasm_qfmt_token,n._sqlite3__wasm_kvvfs_decode=e.sqlite3__wasm_kvvfs_decode,n._sqlite3__wasm_kvvfs_encode=e.sqlite3__wasm_kvvfs_encode,n._sqlite3__wasm_init_wasmfs=e.sqlite3__wasm_init_wasmfs,n._sqlite3__wasm_test_intptr=e.sqlite3__wasm_test_intptr,n._sqlite3__wasm_test_voidptr=e.sqlite3__wasm_test_voidptr,n._sqlite3__wasm_test_int64_max=e.sqlite3__wasm_test_int64_max,n._sqlite3__wasm_test_int64_min=e.sqlite3__wasm_test_int64_min,n._sqlite3__wasm_test_int64_times2=e.sqlite3__wasm_test_int64_times2,n._sqlite3__wasm_test_int64_minmax=e.sqlite3__wasm_test_int64_minmax,n._sqlite3__wasm_test_int64ptr=e.sqlite3__wasm_test_int64ptr,n._sqlite3__wasm_test_stack_overflow=e.sqlite3__wasm_test_stack_overflow,n._sqlite3__wasm_test_str_hello=e.sqlite3__wasm_test_str_hello,n._sqlite3__wasm_SQLTester_strglob=e.sqlite3__wasm_SQLTester_strglob,n._malloc=e.malloc,n._free=e.free,n._realloc=e.realloc,jt=e.emscripten_builtin_memalign,e._emscripten_stack_restore,e._emscripten_stack_alloc,e.emscripten_stack_get_current,e.__indirect_function_table}var Nt={__syscall_chmod:je,__syscall_faccessat:Me,__syscall_fchmod:Ne,__syscall_fchown32:Pe,__syscall_fcntl64:Le,__syscall_fstat64:Re,__syscall_ftruncate64:He,__syscall_getcwd:Ue,__syscall_ioctl:We,__syscall_lstat64:Ge,__syscall_mkdirat:Ke,__syscall_newfstatat:qe,__syscall_openat:Je,__syscall_readlinkat:Ye,__syscall_rmdir:Xe,__syscall_stat64:Ze,__syscall_unlinkat:Qe,__syscall_utimensat:et,_localtime_js:at,_mmap_js:ot,_munmap_js:st,_tzset_js:ct,clock_time_get:pt,emscripten_date_now:ut,emscripten_get_heap_max:ht,emscripten_get_now:lt,emscripten_resize_heap:_t,environ_get:xt,environ_sizes_get:St,fd_close:Ct,fd_fdstat_get:wt,fd_read:Et,fd_seek:Dt,fd_sync:Ot,fd_write:At,memory:U};function Pt(){if(X>0){Ce=Pt;return}if(x(),X>0){Ce=Pt;return}function e(){n.calledRun=!0,!m&&(S(),h?.(n),n.onRuntimeInitialized?.(),C())}n.setStatus?(n.setStatus(`Running...`),setTimeout(()=>{setTimeout(()=>n.setStatus(``),1),e()},1)):e()}var Ft=await M();return Pt(),n.runSQLite3PostLoadInit=async function(e,t,n){delete t.runSQLite3PostLoadInit,globalThis.sqlite3ApiBootstrap=async function r(i=globalThis.sqlite3ApiConfig||r.defaultConfig){if(r.sqlite3)return(r.sqlite3.config||console).warn(`sqlite3ApiBootstrap() called multiple times.`,`Config and external initializers are ignored on calls after the first.`),r.sqlite3;let a=(...e)=>Object.assign(Object.create(null),...e),o=a({exports:void 0,memory:void 0,bigIntEnabled:!!globalThis.BigInt64Array,debug:console.debug.bind(console),warn:console.warn.bind(console),error:console.error.bind(console),log:console.log.bind(console),wasmfsOpfsDir:`/opfs`,useStdAlloc:!1},i);Object.assign(o,{allocExportName:o.useStdAlloc?`malloc`:`sqlite3_malloc`,deallocExportName:o.useStdAlloc?`free`:`sqlite3_free`,reallocExportName:o.useStdAlloc?`realloc`:`sqlite3_realloc`}),[`exports`,`memory`,`functionTable`,`wasmfsOpfsDir`].forEach(e=>{typeof o[e]==`function`&&(o[e]=o[e]())});let s=a(),c=a(),l=e=>s.sqlite3_js_rc_str&&s.sqlite3_js_rc_str(e)||`Unknown result code #`+e,u=e=>typeof e==`number`&&e===(e|0)&&e<=2147483647&&e>=-2147483648;class d extends Error{constructor(...e){let t;if(e.length)if(u(e[0]))if(t=e[0],e.length===1)super(l(e[0]));else{let n=l(t);typeof e[1]==`object`?super(n,e[1]):(e[0]=n+`:`,super(e.join(` `)))}else e.length===2&&typeof e[1]==`object`?super(...e):super(e.join(` `));this.resultCode=t||s.SQLITE_ERROR,this.name=`SQLite3Error`}}d.toss=(...e)=>{throw new d(...e)};let f=d.toss;o.wasmfsOpfsDir&&!/^\/[^/]+$/.test(o.wasmfsOpfsDir)&&f(`config.wasmfsOpfsDir must be falsy or in the form '/dir-name'.`);let p=function e(t){return e._max||(e._max=BigInt(`0x7fffffffffffffff`),e._min=~e._max),t>=e._min&&t<=e._max},m=e=>e>=-2147483647n-1n&&e<=2147483647n,h=function e(t){return e._min||(e._min=-(2**53-1),e._max=2**53-1),t>=e._min&&t<=e._max},g=e=>e&&e.constructor&&u(e.constructor.BYTES_PER_ELEMENT)?e:!1,_=e=>e&&(e instanceof Uint8Array||e instanceof Int8Array||e instanceof ArrayBuffer),y=e=>e&&(e instanceof Uint8Array||e instanceof Int8Array||e instanceof ArrayBuffer),b=e=>_(e)||f(`Value is not of a supported TypedArray type.`),x=function(e){return y(e)?c.typedArrayToString(e instanceof ArrayBuffer?new Uint8Array(e):e,0,e.length):Array.isArray(e)?e.join(``):(c.isPtr(e)&&(e=c.cstrToJs(e)),e)};class S extends Error{constructor(...e){e.length===2&&typeof e[1]==`object`?super(...e):e.length?super(e.join(` `)):super(`Allocation failed.`),this.resultCode=s.SQLITE_NOMEM,this.name=`WasmAllocError`}}S.toss=(...e)=>{throw new S(...e)},Object.assign(s,{sqlite3_bind_blob:void 0,sqlite3_bind_text:void 0,sqlite3_create_function_v2:(e,t,n,r,i,a,o,s,c)=>{},sqlite3_create_function:(e,t,n,r,i,a,o,s)=>{},sqlite3_create_window_function:(e,t,n,r,i,a,o,s,c,l)=>{},sqlite3_prepare_v3:(e,t,n,r,i,a)=>{},sqlite3_prepare_v2:(e,t,n,r,i)=>{},sqlite3_exec:(e,t,n,r,i)=>{},sqlite3_randomness:(e,t)=>{}});let C={affirmBindableTypedArray:b,flexibleString:x,bigIntFits32:m,bigIntFits64:p,bigIntFitsDouble:h,isBindableTypedArray:_,isInt32:u,isSQLableTypedArray:y,isTypedArray:g,isUIThread:()=>globalThis.window===globalThis&&!!globalThis.document,toss:function(...e){throw Error(e.join(` `))},toss3:f,typedArrayPart:c.typedArrayPart,nu:a,assert:function(e,t){e||C.toss(`Assertion failed:`,t)},affirmDbHeader:function(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e)),15>e.byteLength&&f(`Input does not contain an SQLite3 database header.`);for(let t=0;t<15;++t)`SQLite format 3`.charCodeAt(t)!==e[t]&&f(`Input does not contain an SQLite3 database header.`)},affirmIsDb:function(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e));let t=e.byteLength;(t<512||t%512!=0)&&f(`Byte array size`,t,`is invalid for an SQLite3 db.`),C.affirmDbHeader(e)}};Object.assign(c,{exports:o.exports||f(`Missing API config.exports (WASM module exports).`),memory:o.memory||o.exports.memory||f(`API config object requires a WebAssembly.Memory object`,`in either config.exports.memory (exported)`,`or config.memory (imported).`),pointerSize:typeof o.exports.sqlite3_libversion()==`number`?4:8,bigIntEnabled:!!o.bigIntEnabled,functionTable:o.functionTable,alloc:void 0,realloc:void 0,dealloc:void 0}),c.allocFromTypedArray=function(e){e instanceof ArrayBuffer&&(e=new Uint8Array(e)),b(e);let t=c.alloc(e.byteLength||1);return c.heapForSize(e.constructor).set(e.byteLength?e:[0],Number(t)),t};{let e=o.allocExportName,t=o.deallocExportName,n=o.reallocExportName;for(let r of[e,t,n])c.exports[r]instanceof Function||f(`Missing required exports[`,r,`] function.`);c.alloc=function e(t){return e.impl(t)||S.toss(`Failed to allocate`,t,` bytes.`)},c.alloc.impl=c.exports[e],c.realloc=function e(t,n){let r=e.impl(c.ptr.coerce(t),n);return n?r||S.toss(`Failed to reallocate`,n,` bytes.`):c.ptr.null},c.realloc.impl=c.exports[n],c.dealloc=function e(t){e.impl(c.ptr.coerce(t))},c.dealloc.impl=c.exports[t]}c.compileOptionUsed=function e(t){if(arguments.length){if(Array.isArray(t)){let e=a();return t.forEach(t=>{e[t]=s.sqlite3_compileoption_used(t)}),e}else if(typeof t==`object`)return Object.keys(t).forEach(e=>{t[e]=s.sqlite3_compileoption_used(e)}),t}else{if(e._result)return e._result;e._opt||=(e._rx=/^([^=]+)=(.+)/,e._rxInt=/^-?\d+$/,function(t,n){let r=e._rx.exec(t);n[0]=r?r[1]:t,n[1]=r?e._rxInt.test(r[2])?+r[2]:r[2]:!0});let t=a(),n=[0,0],r=0,i;for(;i=s.sqlite3_compileoption_get(r++);)e._opt(i,n),t[n[0]]=n[1];return e._result=t}return typeof t==`string`?!!s.sqlite3_compileoption_used(t):!1},c.pstack=a({restore:c.exports.sqlite3__wasm_pstack_restore,alloc:function(e){return typeof e==`string`&&!(e=c.sizeofIR(e))&&S.toss(`Invalid value for pstack.alloc(`,arguments[0],`)`),c.exports.sqlite3__wasm_pstack_alloc(e)||S.toss(`Could not allocate`,e,`bytes from the pstack.`)},allocChunks:function(e,t){typeof t==`string`&&!(t=c.sizeofIR(t))&&S.toss(`Invalid size value for allocChunks(`,arguments[1],`)`);let n=c.pstack.alloc(e*t),r=[n],i=1,a=t;for(;i<e;++i,a+=t)r.push(c.ptr.add(n,a));return r},allocPtr:(e=1,t=!0)=>e===1?c.pstack.alloc(t?8:c.ptr.size):c.pstack.allocChunks(e,t?8:c.ptr.size),call:function(e){let t=c.pstack.pointer;try{return e(w)}finally{c.pstack.restore(t)}}}),Object.defineProperties(c.pstack,{pointer:{configurable:!1,iterable:!0,writeable:!1,get:c.exports.sqlite3__wasm_pstack_ptr},quota:{configurable:!1,iterable:!0,writeable:!1,get:c.exports.sqlite3__wasm_pstack_quota},remaining:{configurable:!1,iterable:!0,writeable:!1,get:c.exports.sqlite3__wasm_pstack_remaining}}),s.sqlite3_randomness=(...e)=>{if(e.length===1&&C.isTypedArray(e[0])&&e[0].BYTES_PER_ELEMENT===1){let t=e[0];if(t.byteLength===0)return c.exports.sqlite3_randomness(0,c.ptr.null),t;let n=c.pstack.pointer;try{let e=t.byteLength,n=0,r=c.exports.sqlite3_randomness,i=c.heap8u(),a=e<512?e:512,o=c.pstack.alloc(a);do{let s=e>a?a:e;r(s,o),t.set(c.typedArrayPart(i,o,c.ptr.add(o,s)),n),e-=s,n+=s}while(e>0)}catch(e){o.error(`Highly unexpected (and ignored!) exception in sqlite3_randomness():`,e)}finally{c.pstack.restore(n)}return t}c.exports.sqlite3_randomness(...e)},s.sqlite3_wasmfs_opfs_dir=function(){if(this.dir!==void 0)return this.dir;let e=o.wasmfsOpfsDir;if(!e||!globalThis.FileSystemHandle||!globalThis.FileSystemDirectoryHandle||!globalThis.FileSystemFileHandle||!c.exports.sqlite3__wasm_init_wasmfs)return this.dir=``;try{return e&&c.xCallWrapped(`sqlite3__wasm_init_wasmfs`,`i32`,[`string`],e)===0?this.dir=e:this.dir=``}catch{return this.dir=``}}.bind(a()),s.sqlite3_wasmfs_filename_is_persistent=function(e){let t=s.sqlite3_wasmfs_opfs_dir();return t&&e?e.startsWith(t+`/`):!1},s.sqlite3_js_db_uses_vfs=function(e,t,n=0){try{let r=s.sqlite3_vfs_find(t);return r?e?r===s.sqlite3_js_db_vfs(e,n)?r:!1:r===s.sqlite3_vfs_find(0)?r:!1:!1}catch{return!1}},s.sqlite3_js_vfs_list=function(){let e=[],t=s.sqlite3_vfs_find(c.ptr.null);for(;t;){let n=new s.sqlite3_vfs(t);e.push(c.cstrToJs(n.$zName)),t=n.$pNext,n.dispose()}return e},s.sqlite3_js_db_export=function(e,t=0){e=c.xWrap.testConvertArg(`sqlite3*`,e),e||f(`Invalid sqlite3* argument.`),c.bigIntEnabled||f(`BigInt support is not enabled.`);let n=c.scopedAllocPush(),r;try{let n=c.scopedAlloc(8+c.ptr.size),i=c.ptr.add(n,8),a=t?c.isPtr(t)?t:c.scopedAllocCString(``+t):c.ptr.null,o=c.exports.sqlite3__wasm_db_serialize(e,a,i,n,0);o&&f(`Database serialization failed with code`,w.capi.sqlite3_js_rc_str(o)),r=c.peekPtr(i);let s=c.peek(n,`i64`);return o=s?c.heap8u().slice(Number(r),Number(r)+Number(s)):new Uint8Array,o}finally{r&&c.exports.sqlite3_free(r),c.scopedAllocPop(n)}},s.sqlite3_js_db_vfs=(e,t=c.ptr.null)=>C.sqlite3__wasm_db_vfs(e,t),s.sqlite3_js_aggregate_context=(e,t)=>s.sqlite3_aggregate_context(e,t)||(t?S.toss(`Cannot allocate`,t,`bytes for sqlite3_aggregate_context()`):0),s.sqlite3_js_posix_create_file=function(e,t,n){let r;t&&c.isPtr(t)?r=t:t instanceof ArrayBuffer||t instanceof Uint8Array?(r=c.allocFromTypedArray(t),(arguments.length<3||!C.isInt32(n)||n<0)&&(n=t.byteLength)):d.toss(`Invalid 2nd argument for sqlite3_js_posix_create_file().`);try{(!C.isInt32(n)||n<0)&&d.toss(`Invalid 3rd argument for sqlite3_js_posix_create_file().`);let t=C.sqlite3__wasm_posix_create_file(e,r,n);t&&d.toss(`Creation of file failed with sqlite3 result code`,s.sqlite3_js_rc_str(t))}finally{r&&r!==t&&c.dealloc(r)}},s.sqlite3_js_vfs_create_file=function(e,t,n,r){o.warn(`sqlite3_js_vfs_create_file() is deprecated and`,`should be avoided because it can lead to C-level crashes.`,`See its documentation for alternatives.`);let i;n?c.isPtr(n)?i=n:(n instanceof ArrayBuffer&&(n=new Uint8Array(n)),n instanceof Uint8Array?(i=c.allocFromTypedArray(n),(arguments.length<4||!C.isInt32(r)||r<0)&&(r=n.byteLength)):d.toss(`Invalid 3rd argument type for sqlite3_js_vfs_create_file().`)):i=0,(!C.isInt32(r)||r<0)&&(i&&i!==n&&c.dealloc(i),d.toss(`Invalid 4th argument for sqlite3_js_vfs_create_file().`));try{let n=C.sqlite3__wasm_vfs_create_file(e,t,i,r);n&&d.toss(`Creation of file failed with sqlite3 result code`,s.sqlite3_js_rc_str(n))}finally{i&&i!==n&&c.dealloc(i)}},s.sqlite3_js_sql_to_string=e=>{if(typeof e==`string`)return e;let t=x(v);return t===v?void 0:t},s.sqlite3_db_config=function(e,t,...n){switch(t){case s.SQLITE_DBCONFIG_ENABLE_FKEY:case s.SQLITE_DBCONFIG_ENABLE_TRIGGER:case s.SQLITE_DBCONFIG_ENABLE_FTS3_TOKENIZER:case s.SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION:case s.SQLITE_DBCONFIG_NO_CKPT_ON_CLOSE:case s.SQLITE_DBCONFIG_ENABLE_QPSG:case s.SQLITE_DBCONFIG_TRIGGER_EQP:case s.SQLITE_DBCONFIG_RESET_DATABASE:case s.SQLITE_DBCONFIG_DEFENSIVE:case s.SQLITE_DBCONFIG_WRITABLE_SCHEMA:case s.SQLITE_DBCONFIG_LEGACY_ALTER_TABLE:case s.SQLITE_DBCONFIG_DQS_DML:case s.SQLITE_DBCONFIG_DQS_DDL:case s.SQLITE_DBCONFIG_ENABLE_VIEW:case s.SQLITE_DBCONFIG_LEGACY_FILE_FORMAT:case s.SQLITE_DBCONFIG_TRUSTED_SCHEMA:case s.SQLITE_DBCONFIG_STMT_SCANSTATUS:case s.SQLITE_DBCONFIG_REVERSE_SCANORDER:case s.SQLITE_DBCONFIG_ENABLE_ATTACH_CREATE:case s.SQLITE_DBCONFIG_ENABLE_ATTACH_WRITE:case s.SQLITE_DBCONFIG_ENABLE_COMMENTS:case s.SQLITE_DBCONFIG_FP_DIGITS:return this.ip||=c.xWrap(`sqlite3__wasm_db_config_ip`,`int`,[`sqlite3*`,`int`,`int`,`*`]),this.ip(e,t,n[0],n[1]||0);case s.SQLITE_DBCONFIG_LOOKASIDE:return this.pii||=c.xWrap(`sqlite3__wasm_db_config_pii`,`int`,[`sqlite3*`,`int`,`*`,`int`,`int`]),this.pii(e,t,n[0],n[1],n[2]);case s.SQLITE_DBCONFIG_MAINDBNAME:return this.s||=c.xWrap(`sqlite3__wasm_db_config_s`,`int`,[`sqlite3*`,`int`,`string:static`]),this.s(e,t,n[0]);default:return s.SQLITE_MISUSE}}.bind(a()),s.sqlite3_value_to_js=function(e,t=!0){let n,r=s.sqlite3_value_type(e);switch(r){case s.SQLITE_INTEGER:c.bigIntEnabled?(n=s.sqlite3_value_int64(e),C.bigIntFitsDouble(n)&&(n=Number(n))):n=s.sqlite3_value_double(e);break;case s.SQLITE_FLOAT:n=s.sqlite3_value_double(e);break;case s.SQLITE_TEXT:n=s.sqlite3_value_text(e);break;case s.SQLITE_BLOB:{let t=s.sqlite3_value_bytes(e),r=s.sqlite3_value_blob(e);t&&!r&&w.WasmAllocError.toss(`Cannot allocate memory for blob argument of`,t,`byte(s)`),n=t?c.heap8u().slice(Number(r),Number(r)+Number(t)):null;break}case s.SQLITE_NULL:n=null;break;default:t&&f(s.SQLITE_MISMATCH,`Unhandled sqlite3_value_type():`,r),n=void 0}return n},s.sqlite3_values_to_js=function(e,t,n=!0){let r,i=[];for(r=0;r<e;++r)i.push(s.sqlite3_value_to_js(c.peekPtr(c.ptr.add(t,c.ptr.size*r)),n));return i},s.sqlite3_result_error_js=function(e,t){t instanceof S?s.sqlite3_result_error_nomem(e):s.sqlite3_result_error(e,``+t,-1)},s.sqlite3_result_js=function(e,t){if(t instanceof Error){s.sqlite3_result_error_js(e,t);return}try{switch(typeof t){case`undefined`:break;case`boolean`:s.sqlite3_result_int(e,t?1:0);break;case`bigint`:C.bigIntFits32(t)?s.sqlite3_result_int(e,Number(t)):C.bigIntFitsDouble(t)?s.sqlite3_result_double(e,Number(t)):c.bigIntEnabled?C.bigIntFits64(t)?s.sqlite3_result_int64(e,t):f(`BigInt value`,t.toString(),`is too BigInt for int64.`):f(`BigInt value`,t.toString(),`is too BigInt.`);break;case`number`:{let n;n=C.isInt32(t)?s.sqlite3_result_int:c.bigIntEnabled&&Number.isInteger(t)&&C.bigIntFits64(BigInt(t))?s.sqlite3_result_int64:s.sqlite3_result_double,n(e,t);break}case`string`:{let[n,r]=c.allocCString(t,!0);s.sqlite3_result_text(e,n,r,s.SQLITE_WASM_DEALLOC);break}case`object`:if(t===null){s.sqlite3_result_null(e);break}else if(C.isBindableTypedArray(t)){let n=c.allocFromTypedArray(t);s.sqlite3_result_blob(e,n,t.byteLength,s.SQLITE_WASM_DEALLOC);break}default:f(`Don't not how to handle this UDF result value:`,typeof t,t)}}catch(t){s.sqlite3_result_error_js(e,t)}},s.sqlite3_column_js=function(e,t,n=!0){let r=s.sqlite3_column_value(e,t);return r===0?void 0:s.sqlite3_value_to_js(r,n)};{let e=function(e,t,n){n=s[n],this.ptr?c.pokePtr(this.ptr,0):this.ptr=c.allocPtr();let r=n(e,t,this.ptr);if(r)return d.toss(r,arguments[2]+`() failed with code `+r);let i=c.peekPtr(this.ptr);return i?s.sqlite3_value_to_js(i,!0):void 0}.bind(a());s.sqlite3_preupdate_new_js=(t,n)=>e(t,n,`sqlite3_preupdate_new`),s.sqlite3_preupdate_old_js=(t,n)=>e(t,n,`sqlite3_preupdate_old`),s.sqlite3changeset_new_js=(t,n)=>e(t,n,`sqlite3changeset_new`),s.sqlite3changeset_old_js=(t,n)=>e(t,n,`sqlite3changeset_old`)}s.sqlite3_js_retry_busy=function(e,t,n){for(let r=1;r<=e;++r)try{n&&r>1&&n(r);let i=t();if(s.SQLITE_BUSY===i){if(r===e)throw new d(i,[`sqlite3_js_retry_busy() max retry attempts (`,e,`) reached.`].join(``));continue}return i}catch(t){if(r<e&&t instanceof d&&t.resultCode===s.SQLITE_BUSY)continue;throw t}};let w={WasmAllocError:S,SQLite3Error:d,capi:s,util:C,wasm:c,config:o,version:a(),client:void 0,asyncPostInit:async function e(){if(e.isReady instanceof Promise)return e.isReady;let t=this.initializersAsync;delete this.initializersAsync;let n=async()=>(w.__isUnderTest||(delete w.util,delete w.StructBinder,delete w.opfs),w),r=e=>{throw o.error(`an async sqlite3 initializer failed:`,e),e};if(!t||!t.length)return e.isReady=n().catch(r);t=t.map(e=>e instanceof Function?async t=>e(w):e),t.push(n);let i=Promise.resolve(w);for(;t.length;)i=i.then(t.shift());return e.isReady=i.catch(r)}.bind(r),scriptInfo:void 0};n!==void 0&&(w.__isUnderTest=!!n);try{r.initializers.forEach(e=>{e(w)})}catch(e){throw console.error(`sqlite3 bootstrap initializer threw:`,e),e}if(delete r.initializers,r.sqlite3=w,e!==void 0&&(e.debugModule(`sqlite3ApiBootstrap() complete`,w),w.scriptInfo=e),w.__isUnderTest){t!==void 0&&(w.config.emscripten=t);let e=w.scriptInfo?.instantiateWasm;e&&(w.wasm.module=e.module,w.wasm.instance=e.instance,w.wasm.imports=e.imports)}return delete globalThis.sqlite3ApiConfig,delete globalThis.sqlite3ApiBootstrap,delete r.defaultConfig,w.asyncPostInit().then(t=>(e!==void 0&&e.debugModule(`sqlite3.asyncPostInit() complete`,t),delete t.asyncPostInit,delete t.scriptInfo,delete t.emscripten,t))},globalThis.sqlite3ApiBootstrap.initializers=[],globalThis.sqlite3ApiBootstrap.initializersAsync=[],globalThis.sqlite3ApiBootstrap.defaultConfig=Object.create(null),globalThis.sqlite3ApiBootstrap.sqlite3=void 0,globalThis.sqlite3ApiBootstrap.initializers.push(function(e){e.version={libVersion:`3.53.4`,libVersionNumber:3053004,sourceId:`2026-07-24 19:02:57 bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bcc`,downloadVersion:3530400,scm:{"sha3-256":`bf7c7f30031888f4e796e429ab3978879485813aaca6f641c7b33e4e09459bcc`,branch:`branch-3.53`,tags:`release version-3.53.4`,datetime:`2026-07-24T19:02:57.525Z`}}}),globalThis.WhWasmUtilInstaller=function(e){e.bigIntEnabled===void 0&&(e.bigIntEnabled=!!globalThis.BigInt64Array);let t=(...e)=>{throw Error(e.join(` `))};if(!e.pointerSize&&!e.pointerIR&&e.alloc&&e.dealloc){let t=e.alloc(1);e.pointerSize=typeof t==`bigint`?8:4,e.dealloc(t)}e.pointerSize&&!e.pointerIR&&(e.pointerIR=e.pointerSize===4?`i32`:`i64`);let n=e.pointerIR??=`i32`,r=e.pointerSize??=n===`i32`?4:n===`i64`?8:0;delete e.pointerSize,delete e.pointerIR,n!==`i32`&&n!==`i64`?t(`Invalid pointerIR:`,n):r!==8&&r!==4&&t(`Invalid pointerSize:`,r);let i=e.bigIntEnabled?e=>BigInt(e||0):e=>t(`BigInt support is disabled in this build.`),a=r===4?e=>Number(e||0):i,o=a(0),s=function(...e){let t=a(0);for(let n of e)t+=a(n);return t};{let i=Object.create(null);Object.defineProperty(e,`ptr`,{enumerable:!0,get:()=>i,set:()=>t(`The ptr property is read-only.`)}),(function e(n,r){return Object.defineProperty(i,n,{enumerable:!0,get:()=>r,set:()=>t(`ptr[`+n+`] is read-only.`)}),e})(`null`,o)(`size`,r)(`ir`,n)(`coerce`,a)(`add`,s)(`addn`,n===4?s:(...e)=>Number(s(...e)))}e.exports||Object.defineProperty(e,`exports`,{enumerable:!0,configurable:!0,get:()=>e.instance?.exports});let c=Object.create(null);c.heapSize=0,c.memory=null,c.freeFuncIndexes=[],c.scopedAlloc=[],c.scopedAlloc.pushPtr=e=>(c.scopedAlloc[c.scopedAlloc.length-1].push(e),e),c.utf8Decoder=new TextDecoder,c.utf8Encoder=new TextEncoder(`utf-8`),e.sizeofIR=e=>{switch(e){case`i8`:return 1;case`i16`:return 2;case`i32`:case`f32`:case`float`:return 4;case`i64`:case`f64`:case`double`:return 8;case`*`:return r;default:return(``+e).endsWith(`*`)?r:void 0}};let l=function(){if(!c.memory)c.memory=e.memory instanceof WebAssembly.Memory?e.memory:e.exports.memory;else if(c.heapSize===c.memory.buffer.byteLength)return c;let n=c.memory.buffer;return c.HEAP8=new Int8Array(n),c.HEAP8U=new Uint8Array(n),c.HEAP16=new Int16Array(n),c.HEAP16U=new Uint16Array(n),c.HEAP32=new Int32Array(n),c.HEAP32U=new Uint32Array(n),c.HEAP32F=new Float32Array(n),c.HEAP64F=new Float64Array(n),e.bigIntEnabled&&(typeof BigInt64Array<`u`?(c.HEAP64=new BigInt64Array(n),c.HEAP64U=new BigUint64Array(n)):t(`BigInt support is enabled, but the BigInt64Array type is missing.`)),c.heapSize=n.byteLength,c};e.heap8=()=>l().HEAP8,e.heap8u=()=>l().HEAP8U,e.heap16=()=>l().HEAP16,e.heap16u=()=>l().HEAP16U,e.heap32=()=>l().HEAP32,e.heap32u=()=>l().HEAP32U,e.heapForSize=function(n,r=!0){let i=c.memory&&c.heapSize===c.memory.buffer.byteLength?c:l();switch(n){case Int8Array:return i.HEAP8;case Uint8Array:return i.HEAP8U;case Int16Array:return i.HEAP16;case Uint16Array:return i.HEAP16U;case Int32Array:return i.HEAP32;case Uint32Array:return i.HEAP32U;case 8:return r?i.HEAP8U:i.HEAP8;case 16:return r?i.HEAP16U:i.HEAP16;case 32:return r?i.HEAP32U:i.HEAP32;case 64:if(i.HEAP64)return r?i.HEAP64U:i.HEAP64;break;default:if(e.bigIntEnabled){if(n===globalThis.BigUint64Array)return i.HEAP64U;if(n===globalThis.BigInt64Array)return i.HEAP64;break}}t(`Invalid heapForSize() size: expecting 8, 16, 32,`,`or (if BigInt is enabled) 64.`)};let u=e.functionTable;delete e.functionTable,e.functionTable=u?()=>u:()=>e.exports.__indirect_function_table,e.functionEntry=function(t){let n=e.functionTable();return t<n.length?n.get(a(t)):void 0},e.jsFuncToWasm=function e(r,i){if(e._||={sigTypes:Object.assign(Object.create(null),{i:`i32`,p:n,P:n,s:n,j:`i64`,f:`f32`,d:`f64`}),typeCodes:Object.assign(Object.create(null),{f64:124,f32:125,i64:126,i32:127}),uleb128Encode:(e,t,n)=>{n<128?e[t](n):e[t](n%128|128,n>>7)},rxJSig:/^(\w)\((\w*)\)$/,sigParams:t=>{let n=e._.rxJSig.exec(t);return n?n[2]:t.substr(1)},letterType:n=>e._.sigTypes[n]||t(`Invalid signature letter:`,n),pushSigType:(t,n)=>t.push(e._.typeCodes[e._.letterType(n)])},typeof r==`string`){let e=i;i=r,r=e}let a=e._,o=a.sigParams(i),s=[1,96];a.uleb128Encode(s,`push`,o.length);for(let e of o)a.pushSigType(s,e);return i[0]===`v`?s.push(0):(s.push(1),a.pushSigType(s,i[0])),a.uleb128Encode(s,`unshift`,s.length),s.unshift(0,97,115,109,1,0,0,0,1),s.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array(s)),{e:{f:r}}).exports.f};let d=function(n,r,i){if(i&&!c.scopedAlloc.length&&t(`No scopedAllocPush() scope is active.`),typeof n==`string`){let e=r;r=n,n=e}(typeof r!=`string`||!(n instanceof Function))&&t(`Invalid arguments: expecting (function,signature) or (signature,function).`);let o=e.functionTable(),s=a(o.length),l;for(;(l=c.freeFuncIndexes.pop())&&o.get(l);)l=null;l||(l=a(s),o.grow(a(1)));try{return o.set(l,n),i&&c.scopedAlloc.pushPtr(l),l}catch(e){if(!(e instanceof TypeError))throw l===s&&c.freeFuncIndexes.push(s),e}try{let t=e.jsFuncToWasm(n,r);o.set(l,t),i&&c.scopedAlloc.pushPtr(l)}catch(e){throw l===s&&c.freeFuncIndexes.push(s),e}return l};e.installFunction=(e,t)=>d(e,t,!1),e.scopedInstallFunction=(e,t)=>d(e,t,!0),e.uninstallFunction=function(t){if(!t&&o!==t)return;let n=e.functionTable();c.freeFuncIndexes.push(t);let r=n.get(t);return n.set(t,null),r},e.peek=function(e,r=`i8`){r.endsWith(`*`)&&(r=n);let a=c.memory&&c.heapSize===c.memory.buffer.byteLength?c:l(),o=Array.isArray(e)?[]:void 0,s;do{switch(o&&(e=arguments[0].shift()),r){case`i1`:case`i8`:s=a.HEAP8[Number(e)>>0];break;case`i16`:s=a.HEAP16[Number(e)>>1];break;case`i32`:s=a.HEAP32[Number(e)>>2];break;case`float`:case`f32`:s=a.HEAP32F[Number(e)>>2];break;case`double`:case`f64`:s=Number(a.HEAP64F[Number(e)>>3]);break;case`i64`:if(a.HEAP64){s=i(a.HEAP64[Number(e)>>3]);break}default:t(`Invalid type for peek():`,r)}o&&o.push(s)}while(o&&arguments[0].length);return o||s},e.poke=function(e,r,a=`i8`){a.endsWith(`*`)&&(a=n);let o=c.memory&&c.heapSize===c.memory.buffer.byteLength?c:l();for(let n of Array.isArray(e)?e:[e])switch(a){case`i1`:case`i8`:o.HEAP8[Number(n)>>0]=r;continue;case`i16`:o.HEAP16[Number(n)>>1]=r;continue;case`i32`:o.HEAP32[Number(n)>>2]=r;continue;case`float`:case`f32`:o.HEAP32F[Number(n)>>2]=r;continue;case`double`:case`f64`:o.HEAP64F[Number(n)>>3]=r;continue;case`i64`:if(o.HEAP64){o.HEAP64[Number(n)>>3]=i(r);continue}default:t(`Invalid type for poke(): `+a)}return this},e.peekPtr=(...t)=>e.peek(t.length===1?t[0]:t,n),e.pokePtr=(t,r=0)=>e.poke(t,r,n),e.peek8=(...t)=>e.peek(t.length===1?t[0]:t,`i8`),e.poke8=(t,n)=>e.poke(t,n,`i8`),e.peek16=(...t)=>e.peek(t.length===1?t[0]:t,`i16`),e.poke16=(t,n)=>e.poke(t,n,`i16`),e.peek32=(...t)=>e.peek(t.length===1?t[0]:t,`i32`),e.poke32=(t,n)=>e.poke(t,n,`i32`),e.peek64=(...t)=>e.peek(t.length===1?t[0]:t,`i64`),e.poke64=(t,n)=>e.poke(t,n,`i64`),e.peek32f=(...t)=>e.peek(t.length===1?t[0]:t,`f32`),e.poke32f=(t,n)=>e.poke(t,n,`f32`),e.peek64f=(...t)=>e.peek(t.length===1?t[0]:t,`f64`),e.poke64f=(t,n)=>e.poke(t,n,`f64`),e.getMemValue=e.peek,e.getPtrValue=e.peekPtr,e.setMemValue=e.poke,e.setPtrValue=e.pokePtr,e.isPtr32=e=>typeof e==`number`&&e>=0&&e===(e|0),e.isPtr64=t=>typeof t==`bigint`?t>=0:e.isPtr32(t),e.isPtr=r===4?e.isPtr32:e.isPtr64,e.cstrlen=function(t){if(!t||!e.isPtr(t))return null;t=Number(t);let n=l().HEAP8U,r=t;for(;n[r]!==0;++r);return r-t};let f=typeof SharedArrayBuffer>`u`?function(){}:SharedArrayBuffer,p=e=>e.buffer instanceof f;e.isSharedTypedArray=p;let m=(e,t,n)=>(r===8&&(typeof t==`bigint`&&(t=Number(t)),typeof n==`bigint`&&(n=Number(n))),p(e)?e.slice(t,n):e.subarray(t,n));e.typedArrayPart=m;let h=(e,t,n)=>c.utf8Decoder.decode(m(e,t,n));e.typedArrayToString=h,e.cstrToJs=function(t){let n=e.cstrlen(t);return n?h(l().HEAP8U,Number(t),Number(t)+n):n===null?n:``},e.jstrlen=function(e){if(typeof e!=`string`)return null;let t=e.length,n=0;for(let r=0;r<t;++r){let t=e.charCodeAt(r);t>=55296&&t<=57343&&(t=65536+((t&1023)<<10)|e.charCodeAt(++r)&1023),t<=127?++n:t<=2047?n+=2:t<=65535?n+=3:n+=4}return n},e.jstrcpy=function(e,n,r=0,i=-1,a=!0){if((!n||!(n instanceof Int8Array)&&!(n instanceof Uint8Array))&&t(`jstrcpy() target must be an Int8Array or Uint8Array.`),i=Number(i),r=Number(r),i<0&&(i=n.length-r),!(i>0)||!(r>=0))return 0;let o=0,s=e.length,c=r,l=r+i-(a?1:0);for(;o<s&&r<l;++o){let t=e.charCodeAt(o);if(t>=55296&&t<=57343&&(t=65536+((t&1023)<<10)|e.charCodeAt(++o)&1023),t<=127){if(r>=l)break;n[r++]=t}else if(t<=2047){if(r+1>=l)break;n[r++]=192|t>>6,n[r++]=128|t&63}else if(t<=65535){if(r+2>=l)break;n[r++]=224|t>>12,n[r++]=128|t>>6&63,n[r++]=128|t&63}else{if(r+3>=l)break;n[r++]=240|t>>18,n[r++]=128|t>>12&63,n[r++]=128|t>>6&63,n[r++]=128|t&63}}return a&&(n[r++]=0),r-c},e.cstrncpy=function(n,r,i){if((!n||!r)&&t(`cstrncpy() does not accept NULL strings.`),i<0)i=e.cstrlen(strPtr)+1;else if(!(i>0))return 0;let a=e.heap8u(),o=0,s,c=Number(n),l=Number(r);for(;o<i&&(s=a[l+o]);++o)a[c+o]=s;return o<i&&(a[c+ o++]=0),o},e.jstrToUintArray=(e,t=!1)=>c.utf8Encoder.encode(t?e+`\0`:e);let g=(e,n)=>{(!(e.alloc instanceof Function)||!(e.dealloc instanceof Function))&&t(`Object is missing alloc() and/or dealloc() function(s)`,`required by`,n+`().`)},_=function(t,n,r,i){if(g(e,i),typeof t!=`string`)return null;let a=c.utf8Encoder.encode(t),u=r(a.length+1),d=u;try{let e=l().HEAP8U;return e.set(a,Number(u)),e[s(u,a.length)]=0,d=o,n?[u,a.length]:u}finally{d&&e.dealloc(d)}};e.allocCString=(t,n=!1)=>_(t,n,e.alloc,`allocCString()`),e.scopedAllocPush=function(){g(e,`scopedAllocPush`);let t=[];return c.scopedAlloc.push(t),t},e.scopedAllocPop=function(n){g(e,`scopedAllocPop`);let r=arguments.length?c.scopedAlloc.indexOf(n):c.scopedAlloc.length-1;r<0&&t(`Invalid state object for scopedAllocPop().`),arguments.length===0&&(n=c.scopedAlloc[r]),c.scopedAlloc.splice(r,1);for(let t;t=n.pop();)e.functionEntry(t)?e.uninstallFunction(t):e.dealloc(t)},e.scopedAlloc=function(n){c.scopedAlloc.length||t(`No scopedAllocPush() scope is active.`);let r=a(e.alloc(n));return c.scopedAlloc.pushPtr(r)},Object.defineProperty(e.scopedAlloc,`level`,{configurable:!1,enumerable:!1,get:()=>c.scopedAlloc.length,set:()=>t(`The 'active' property is read-only.`)}),e.scopedAllocCString=(t,n=!1)=>_(t,n,e.scopedAlloc,`scopedAllocCString()`);let y=function(t,n){let r=e[t?`scopedAlloc`:`alloc`]((n.length+1)*e.ptr.size),i=0;return n.forEach(n=>{e.pokePtr(s(r,e.ptr.size*i++),e[t?`scopedAllocCString`:`allocCString`](``+n))}),e.pokePtr(s(r,e.ptr.size*i),0),r};e.scopedAllocMainArgv=e=>y(!0,e),e.allocMainArgv=e=>y(!1,e),e.cArgvToJs=(t,n)=>{let r=[];for(let i=0;i<t;++i){let t=e.peekPtr(s(n,e.ptr.size*i));r.push(t?e.cstrToJs(t):null)}return r},e.scopedAllocCall=function(t){e.scopedAllocPush();try{return t()}finally{e.scopedAllocPop()}};let b=function(t,i,a){g(e,a);let o=i?`i64`:n,c=e[a](t*(i?8:r));if(e.poke(c,0,o),t===1)return c;let l=[c];for(let n=1;n<t;++n)c=s(c,i?8:r),l[n]=c,e.poke(c,0,o);return l};e.allocPtr=(e=1,t=!0)=>b(e,t,`alloc`),e.scopedAllocPtr=(e=1,t=!0)=>b(e,t,`scopedAlloc`),e.xGet=function(n){return e.exports[n]||t(`Cannot find exported symbol:`,n)};let x=(e,n)=>t(e+`() requires`,n,`argument(s).`);e.xCall=function(n,...r){let i=n instanceof Function?n:e.xGet(n);return i instanceof Function||t(`Exported symbol`,n,`is not a function.`),i.length!==r.length&&x(i===n?i.name:n,i.length),arguments.length===2&&Array.isArray(arguments[1])?i.apply(null,arguments[1]):i.apply(null,r)},c.xWrap=Object.create(null),c.xWrap.convert=Object.create(null),c.xWrap.convert.arg=new Map,c.xWrap.convert.result=new Map;let S=c.xWrap.convert.arg,C=c.xWrap.convert.result,w=a;S.set(`i64`,i).set(`i32`,e=>e|0).set(`i16`,e=>(e|0)&65535).set(`i8`,e=>(e|0)&255).set(`f32`,e=>Number(e).valueOf()).set(`float`,S.get(`f32`)).set(`f64`,S.get(`f32`)).set(`double`,S.get(`f64`)).set(`int`,S.get(`i32`)).set(`null`,e=>e).set(null,S.get(`null`)).set(`**`,w).set(`*`,w),C.set(`*`,w).set(`pointer`,w).set(`number`,e=>Number(e)).set(`void`,e=>void 0).set(void 0,C.get(`void`)).set(`null`,e=>e).set(null,C.get(`null`));for(let e of[`i8`,`i16`,`i32`,`i64`,`int`,`f32`,`float`,`f64`,`double`])S.set(e+`*`,w),C.set(e+`*`,w),C.set(e,S.get(e)||t(`Maintenance required: missing arg converter for`,e));let T=t=>typeof t==`string`?e.scopedAllocCString(t):a(t);S.set(`string`,T).set(`utf8`,T),C.set(`string`,t=>e.cstrToJs(t)).set(`utf8`,C.get(`string`)).set(`string:dealloc`,t=>{try{return t?e.cstrToJs(t):null}finally{e.dealloc(t)}}).set(`utf8:dealloc`,C.get(`string:dealloc`)).set(`json`,t=>JSON.parse(e.cstrToJs(t))).set(`json:dealloc`,t=>{try{return t?JSON.parse(e.cstrToJs(t)):null}finally{e.dealloc(t)}});let E=class{constructor(e){this.name=e.name||`unnamed adapter`}convertArg(e,n,r){t(`AbstractArgAdapter must be subclassed.`)}};S.FuncPtrAdapter=class n extends E{constructor(e){super(e),S.FuncPtrAdapter.warnOnUse&&console.warn(`xArg.FuncPtrAdapter is an internal-only API`,`and is not intended to be invoked from`,`client-level code. Invoked with:`,e),this.name=e.name||`unnamed`,this.signature=e.signature,e.contextKey instanceof Function&&(this.contextKey=e.contextKey,e.bindScope||=`context`),this.bindScope=e.bindScope||t(`FuncPtrAdapter options requires a bindScope (explicit or implied).`),n.bindScopes.indexOf(e.bindScope)<0&&t(`Invalid options.bindScope (`+e.bindMod+`) for FuncPtrAdapter. Expecting one of: (`+n.bindScopes.join(`, `)+`)`),this.isTransient=this.bindScope===`transient`,this.isContext=this.bindScope===`context`,this.isPermanent=this.bindScope===`permanent`,this.singleton=this.bindScope===`singleton`?[]:void 0,this.callProxy=e.callProxy instanceof Function?e.callProxy:void 0}contextKey(e,t){return this}contextMap(e){let t=this.__cmap||=new Map,n=t.get(e);return n===void 0&&t.set(e,n=[]),n}convertArg(t,r,i){let a=this.singleton;if(!a&&this.isContext&&(a=this.contextMap(this.contextKey(r,i))),a&&a.length===2&&a[0]===t)return a[1];if(t instanceof Function){this.callProxy&&(t=this.callProxy(t));let e=d(t,this.signature,this.isTransient);if(n.debugFuncInstall&&n.debugOut(`FuncPtrAdapter installed`,this,this.contextKey(r,i),`@`+e,t),a){if(a[1]){n.debugFuncInstall&&n.debugOut(`FuncPtrAdapter uninstalling`,this,this.contextKey(r,i),`@`+a[1],t);try{c.scopedAlloc.pushPtr(a[1])}catch{}}a[0]=arguments[0]||o,a[1]=e}return e}else if(e.isPtr(t)||t==null){if(a&&a[1]&&a[1]!==t){n.debugFuncInstall&&n.debugOut(`FuncPtrAdapter uninstalling`,this,this.contextKey(r,i),`@`+a[1],t);try{c.scopedAlloc.pushPtr(a[1])}catch{}a[0]=a[1]=t||o}return t||o}else throw TypeError(`Invalid FuncPtrAdapter argument type. Expecting a function pointer or a `+(this.name?this.name+` `:``)+`function matching signature `+this.signature+`.`)}},S.FuncPtrAdapter.warnOnUse=!1,S.FuncPtrAdapter.debugFuncInstall=!1,S.FuncPtrAdapter.debugOut=console.debug.bind(console),S.FuncPtrAdapter.bindScopes=[`transient`,`context`,`singleton`,`permanent`];let D=e=>S.get(e)||t(`Argument adapter not found:`,e),O=e=>C.get(e)||t(`Result adapter not found:`,e);c.xWrap.convertArg=(e,...t)=>D(e)(...t),c.xWrap.convertArgNoCheck=(e,...t)=>S.get(e)(...t),c.xWrap.convertResult=(e,t)=>e===null?t:e?O(e)(t):void 0,c.xWrap.convertResultNoCheck=(e,t)=>e===null?t:e?C.get(e)(t):void 0,e.xWrap=function n(r,i,...a){arguments.length===3&&Array.isArray(arguments[2])&&(a=arguments[2]),e.isPtr(r)&&(r=e.functionEntry(r)||t(`Function pointer not found in WASM function table.`));let o=r instanceof Function,s=o?r:e.xGet(r);if(o&&(r=s.name||`unnamed function`),a.length!==s.length&&x(r,s.length),s.length===0&&(i===null||i===`null`))return s;O(i);for(let e of a)e instanceof E?S.set(e,(...t)=>e.convertArg(...t)):D(e);let l=c.xWrap;return s.length===0?(...e)=>e.length?x(r,s.length):l.convertResult(i,s.call(null)):function(...t){t.length!==s.length&&x(r,s.length);let o=e.scopedAllocPush();try{let e=0;for(n.debug&&console.debug(`xWrap() preparing: resultType `,i,`xf`,s,`argTypes`,a,`args`,t);e<t.length;++e)t[e]=l.convertArgNoCheck(a[e],t[e],t,e);return n.debug&&console.debug(`xWrap() calling: resultType `,i,`xf`,s,`argTypes`,a,`args`,t),l.convertResultNoCheck(i,s.apply(null,t))}finally{e.scopedAllocPop(o)}}};let A=function(e,n,r,i,a,o){if(typeof r==`string`){if(n===1)return o.get(r);if(n===2){if(i)i instanceof Function||t(a,`requires a function argument.`);else return o.delete(r),e;return o.set(r,i),e}}t(`Invalid arguments to`,a)};return e.xWrap.resultAdapter=function e(t,n){return A(e,arguments.length,t,n,`resultAdapter()`,C)},e.xWrap.argAdapter=function e(t,n){return A(e,arguments.length,t,n,`argAdapter()`,S)},e.xWrap.FuncPtrAdapter=S.FuncPtrAdapter,e.xCallWrapped=function(t,n,r,...i){return Array.isArray(arguments[3])&&(i=arguments[3]),e.xWrap(t,n,r||[]).apply(null,i||[])},e.xWrap.testConvertArg=c.xWrap.convertArg,e.xWrap.testConvertResult=c.xWrap.convertResult,e},globalThis.WhWasmUtilInstaller.yawl=function(e){let t=()=>fetch(e.uri,{credentials:`same-origin`}),n=this,r=function(t){if(e.wasmUtilTarget){let r=(...e)=>{throw Error(e.join(` `))},i=e.wasmUtilTarget;if(i.module=t.module,i.instance=t.instance,i.instance.exports.memory||(i.memory=e?.imports?.env?.memory||r(`Missing 'memory' object!`)),!i.alloc&&t.instance.exports.malloc){let e=t.instance.exports;i.alloc=function(t){return e.malloc(t)||r(`Allocation of`,t,`bytes failed.`)},i.dealloc=function(t){t&&e.free(t)}}n(i)}return t.config=e,e.onload&&e.onload(t),t};return WebAssembly.instantiateStreaming?()=>WebAssembly.instantiateStreaming(t(),e.imports||{}).then(r):()=>t().then(e=>e.arrayBuffer()).then(t=>WebAssembly.instantiate(t,e.imports||{})).then(r)}.bind(globalThis.WhWasmUtilInstaller),globalThis.Jaccwabyt=function e(t){let n=(...e)=>{throw Error(e.join(` `))};{let e=t.heap;e instanceof WebAssembly.Memory?e=function(){return new Uint8Array(this.buffer)}.bind(e):e instanceof Function||n(`config.heap must be WebAssembly.Memory instance or`,`a function which returns one.`),t.heap=e}[`alloc`,`dealloc`].forEach(function(e){t[e]instanceof Function||n(`Config option '`+e+`' must be a function.`)});let r=e,i=t.heap,a=t.alloc,o=t.dealloc;t.realloc;let s=t.log||console.debug.bind(console),c=t.memberPrefix||``,l=t.memberSuffix||``,u=globalThis.BigInt,d=globalThis.BigInt64Array,f=t.bigIntEnabled??!!d,p,m=t.pointerSize||t.ptrSize||(typeof(p=a(1))==`bigint`?8:4),h=t.pointerIR||t.ptrIR||(m===4?`i32`:`i64`);p&&=(o(p),void 0),m!==4&&m!==8&&n(`Invalid pointer size:`,m),h!==`i32`&&h!==`i64`&&n(`Invalid pointer representation:`,h);let g=f&&u?e=>u(e||0):e=>n(`BigInt support is disabled in this build.`),_=h==`i32`?Number:g,y=_(0),b=function(...e){let t=y;for(let n=0;n<e.length;++n)t+=_(e[n]);return t},x=function(...e){return b(this.pointer,...e)};r.debugFlags||=(r.__makeDebugFlags=function(e=null){e&&e.__flags&&(e=e.__flags);let t=function e(t){return arguments.length===0?e.__flags:(t<0?(delete e.__flags.getter,delete e.__flags.setter,delete e.__flags.alloc,delete e.__flags.dealloc):(e.__flags.getter=(1&t)!=0,e.__flags.setter=(2&t)!=0,e.__flags.alloc=(4&t)!=0,e.__flags.dealloc=(8&t)!=0),e._flags)};return Object.defineProperty(t,`__flags`,{iterable:!1,writable:!1,value:Object.create(e)}),e||t(0),t},r.__makeDebugFlags());let S=e=>e[1]===`(`,C=e=>e===`p`||e===`P`||e===`s`,w=e=>e===`P`,T=e=>e?S(e)?`p`:e[0]:void 0,E=function(e){switch(T(e)){case`c`:case`C`:return`i8`;case`i`:return`i32`;case`p`:case`P`:case`s`:return h;case`j`:return`i64`;case`f`:return`float`;case`d`:return`double`}n(`Unhandled signature IR:`,e)},D=function(e){switch(T(e)){case`c`:case`C`:return 1;case`i`:return 4;case`p`:case`P`:case`s`:return m;case`j`:return 8;case`f`:return 4;case`d`:return 8}n(`Unhandled signature sizeof:`,e)},O=d?()=>!0:()=>n(`BigInt64Array is not available.`),A=function(e){switch(T(e)){case`p`:case`P`:case`s`:switch(m){case 4:return`getInt32`;case 8:return O()&&`getBigInt64`}break;case`i`:return`getInt32`;case`c`:return`getInt8`;case`C`:return`getUint8`;case`j`:return O()&&`getBigInt64`;case`f`:return`getFloat32`;case`d`:return`getFloat64`}n(`Unhandled DataView getter for signature:`,e)},j=function(e){switch(T(e)){case`p`:case`P`:case`s`:switch(m){case 4:return`setInt32`;case 8:return O()&&`setBigInt64`}break;case`i`:return`setInt32`;case`c`:return`setInt8`;case`C`:return`setUint8`;case`j`:return O()&&`setBigInt64`;case`f`:return`setFloat32`;case`d`:return`setFloat64`}n(`Unhandled DataView setter for signature:`,e)},ee=function(e){switch(T(e)){case`i`:case`f`:case`c`:case`C`:case`d`:return Number;case`j`:return g;case`p`:case`P`:case`s`:switch(m){case 4:return Number;case 8:return g}}n(`Unhandled DataView set wrapper for signature:`,e)},M=(e,t)=>e+`::`+t,N=function(e,t){return()=>n(M(e,t),`is read-only.`)},P=function e(t,n=!0){let r=e.map.get(t);return!r&&n&&e.map.set(t,r=e.create(t)),r};P.map=new WeakMap,P.create=e=>Object.assign(Object.create(null),{o:e,p:void 0,ownsPointer:!1,zod:!1,xb:0});let F=e=>P.map.delete(e),I=e=>typeof e==`number`&&e===(e|0)&&e>=0,L=m===4?I:e=>typeof e==`bigint`&&e>=0||I(e),te=e=>L(e)&&e>0,R=function(e,t,n){let r=P(t,!1);if(r){if(F(t),!n&&!(n=r.p)){console.warn(`Cannot(?) happen: __freeStruct() found no instanceInfo`);return}if(Array.isArray(t.ondispose)){let r;for(;r=t.ondispose.pop();)try{r instanceof Function?r.call(t):r instanceof J?r.dispose():L(r)&&o(r)}catch(t){console.warn(`ondispose() for`,e.structName,`@`,n,`threw. NOT propagating it.`,t)}}else if(t.ondispose instanceof Function)try{t.ondispose()}catch(t){console.warn(`ondispose() for`,e.structName,`@`,n,`threw. NOT propagating it.`,t)}delete t.ondispose,e.debugFlags.__flags.dealloc&&s(`debug.dealloc:`,r.ownsPointer?``:`EXTERNAL`,e.structName,`instance:`,e.structInfo.sizeof,`bytes @`+n),r.ownsPointer&&((r.zod||e.structInfo.zeroOnDispose)&&i().fill(0,Number(n),Number(n)+e.structInfo.sizeof+r.xb),o(n))}},z=()=>({configurable:!1,writable:!1,iterable:!1}),B=e=>({...z(),value:e}),V=function(e,t,r){let o,c=t=>{te(t)||n(`Invalid pointer value`,arguments[0],`for`,e.structName,`constructor.`)};arguments.length>=3?r&&typeof r==`object`?(o=r,r=o?.wrap):(c(r),o={wrap:r}):o={};let l=!r,u=0,d=!1;if(r)c(r),d=!!o?.takeOwnership;else{let t=o?.extraBytes??0;(t<0||t!==(t|0))&&n(`Invalid extraBytes value:`,o?.extraBytes),u=e.structInfo.sizeof+t,r=a(u)||n(`Allocation of`,e.structName,`structure failed.`),d=!0}try{o?.debugFlags&&t.debugFlags(o.debugFlags),e.debugFlags.__flags.alloc&&s(`debug.alloc:`,l?``:`EXTERNAL`,e.structName,`instance:`,e.structInfo.sizeof,`bytes @`+r),l&&i().fill(0,Number(r),Number(r)+u);let n=P(t);n.p=r,n.ownsPointer=d,n.xb=u?u-e.structInfo.sizeof:0,n.zod=!!o?.zeroOnDispose,o?.ondispose&&o.ondispose!==r&&t.addOnDispose(o.ondispose)}catch(n){throw R(e,t,r),n}},ne=function e(t){return e.rxSig1??=/^[ipPsjfdcC]$/,e.rxSig2??=/^[vipPsjfdcC]\([ipPsjfdcC]*\)$/,e.rxSig1.test(t)||e.rxSig2.test(t)},re=function(e){let t=this.get(e);return t||(t=[Object.create(null),Object.create(null),Object.create(null)],this.set(e,t)),t}.bind(new WeakMap),H=function(e,t,n,r){let i=re(e)[t];return arguments.length===3?i[n]:r?i[n]=r:delete i[n]},ie=function(e,...t){return H(this,0,e,...t)},ae=function(e,t){ne(t)&&n(e,`(`,t,`) collides with a data type signature.`)},U=function(e,...t){return ae(`Setter adaptor`,e),H(this,1,e,...t)},W=function(e,...t){return ae(`Struct adaptor`,e),H(this,2,e,...t)},oe=function(e,t){let r=typeof t==`string`?H(e,2,t):t;return typeof r!=`object`&&n(`Invalid struct mapping object. Arg =`,t,JSON.stringify(r)),r},se=B(e=>c+e+l),G=function(e,t,r=!0){let i=e.members[t];if(!i&&(c||l)){for(let n of Object.values(e.members))if(n.key===t){i=n;break}!i&&r&&n(M(e.name||e.structName,t),`is not a mapped struct member.`)}return i},ce=function e(t,n,r=!1){e._||=e=>e.replace(/[^vipPsjrdcC]/g,``).replace(/[pPscC]/g,`i`);let i=G(t.structInfo,n,!0);return r?e._(i.signature):i.signature},le=B(function(){let e=[];for(let t of Object.keys(this.structInfo.members))e.push(this.memberKey(t));return e}),K=new TextDecoder(`utf-8`),ue=new TextEncoder,de=typeof SharedArrayBuffer>`u`?function(){}:SharedArrayBuffer,fe=function(e,t,n){return m===8&&(t=Number(t),n=Number(n)),K.decode(e.buffer instanceof de?e.slice(t,n):e.subarray(t,n))},pe=function(e,t,n=!1){let r=G(e.structInfo,t,n);return r&&r.signature.length===1&&r.signature[0]===`s`?r:!1},me=function(e){e.signature!==`s`&&n(`Invalid member type signature for C-string value:`,JSON.stringify(e))},q=function(e,t){let n=G(e.structInfo,t,!0);me(n);let r=e[n.key];if(!r)return null;let a=r,o=i();for(;o[a]!==0;++a);return r===a?``:fe(o,r,a)},he=function(e,...t){e.ondispose?Array.isArray(e.ondispose)||(e.ondispose=[e.ondispose]):e.ondispose=[],e.ondispose.push(...t)},ge=function(e){let t=ue.encode(e),r=a(t.length+1);r||n(`Allocation error while duplicating string:`,e);let o=i();return o.set(t,Number(r)),o[b(r,t.length)]=0,r},_e=function(e,t,n){let r=G(e.structInfo,t,!0);me(r);let i=ge(n);return e[r.key]=i,he(e,i),e},J=function(e,t){arguments[2]!==B&&n(`Do not call the StructType constructor`,`from client-level code.`),Object.defineProperties(this,{structName:B(e),structInfo:B(t)})};J.prototype=Object.create(null,{dispose:B(function(){R(this.constructor,this)}),lookupMember:B(function(e,t=!0){return G(this.structInfo,e,t)}),memberToJsString:B(function(e){return q(this,e)}),memberIsString:B(function(e,t=!0){return pe(this,e,t)}),memberKey:se,memberKeys:le,memberSignature:B(function(e,t=!1){return ce(this,e,t)}),memoryDump:B(function(){let e=this.pointer;return e?new Uint8Array(i().slice(Number(e),Number(e)+this.structInfo.sizeof)):null}),extraBytes:{configurable:!1,enumerable:!1,get:function(){return P(this,!1)?.xb??0}},zeroOnDispose:{configurable:!1,enumerable:!1,get:function(){return P(this,!1)?.zod??!!this.structInfo.zeroOnDispose}},pointer:{configurable:!1,enumerable:!1,get:function(){return P(this,!1)?.p},set:()=>n(`Cannot assign the 'pointer' property of a struct.`)},setMemberCString:B(function(e,t){return _e(this,e,t)})}),Object.assign(J.prototype,{addOnDispose:function(...e){return he(this,...e),this}}),Object.defineProperties(J,{allocCString:B(ge),isA:B(e=>e instanceof J),hasExternalPointer:B(e=>{let t=P(e,!1);return!!(t?.p&&!t?.ownsPointer)}),memberKey:se});let ve=function(e){return e.get||(e.adaptGet?Y.adaptGet(e.adaptGet):void 0)},ye=function(e){return e.set||(e.adaptSet?Y.adaptSet(e.adaptSet):void 0)},be=function e(t,r,i){let a=e.innerStructs??=new Map,o=t.memberKey(r);i.signature!==void 0&&n(`'signature' cannot be used on an embedded struct (`,t.structName,`.`,o,`).`),ye(i)&&n(`'set' and 'adaptSet' are not permitted for nested struct members.`),i.structName??=t.structName+`::`+r,i.key=o,i.name=r,i.constructor=this.call(this,i.structName,i);let c=ve(i),l=Object.assign(Object.create(null),{configurable:!1,enumerable:!1,set:N(t.structName,o),get:function(){let e=this.debugFlags.__flags,t=this.pointer,n=t+`.`+o,r=a.get(n);return e.getter&&s(`debug.getter: k =`,n),r||(r=new i.constructor(b(t,i.offset)),a.set(n,r),this.addOnDispose(()=>r.dispose()),r.addOnDispose(()=>a.delete(n))),c&&(r=c.apply(this,[r,o])),e.getter&&s(`debug.getter: result =`,r),r}});Object.defineProperty(t.prototype,o,l)},xe=function e(t,r,a){if(a=oe(this,a),a.members)return be.call(this,t,r,a);if(!e.cache){e.cache={getters:{},setters:{},sw:{}};let t=[`i`,`c`,`C`,`p`,`P`,`s`,`f`,`d`,`v()`];f&&t.push(`j`),t.forEach(function(t){e.cache.getters[t]=A(t),e.cache.setters[t]=j(t),e.cache.sw[t]=ee(t)}),e.sigCheck=function(e,t,r,i){Object.prototype.hasOwnProperty.call(e,r)&&n(e.structName,`already has a property named`,r+`.`),ne(i)||n(`Malformed signature for`,M(e.structName,t)+`:`,i)}}let o=t.memberKey(r);e.sigCheck(t.prototype,r,o,a.signature),a.key=o,a.name=r;let c=T(a.signature),l=M(t.structName,o),u=t.debugFlags.__flags,d=ve(a),p=Object.create(null);if(p.configurable=!1,p.enumerable=!1,p.get=function(){u.getter&&s(`debug.getter:`,e.cache.getters[c],`for`,E(c),l,`@`,this.pointer,`+`,a.offset,`sz`,a.sizeof);let t=new DataView(i().buffer,Number(this.pointer)+a.offset,a.sizeof)[e.cache.getters[c]](0,!0);return d&&(t=d.apply(this,[o,t])),u.getter&&s(`debug.getter:`,l,`result =`,t),t},a.readOnly)p.set=N(t.prototype.structName,o);else{let t=ye(a);p.set=function(r){u.setter&&s(`debug.setter:`,e.cache.setters[c],`for`,E(c),l,`@`,this.pointer,`+`,a.offset,`sz`,a.sizeof,r),this.pointer||n(`Cannot set native property on a disposed`,this.structName,`instance.`),t&&(r=t.apply(this,[o,r])),r==null?r=y:C(a.signature)&&!L(r)&&(w(a.signature)&&r instanceof J?(r=r.pointer||y,u.setter&&s(`debug.setter:`,l,`resolved to`,r)):n(`Invalid value for pointer-type`,l+`.`)),new DataView(i().buffer,Number(this.pointer)+a.offset,a.sizeof)[e.cache.setters[c]](0,e.cache.sw[c](r),!0)}}Object.defineProperty(t.prototype,o,p)},Se=function e(t,i,a=Object.create(null)){let o=function e(r){this instanceof e||n(`The`,t,`constructor may only be called via 'new'.`),V(e,this,...arguments)},s=this,c=e=>typeof e==`string`&&ne(e)?{signature:e}:oe(s,e);arguments.length===1?(i=c(t),t=i.structName||i.name):arguments.length===2?(i=c(i),i.name??=t):i=c(i),t??=i.structName,t??=a.structName,t||n(`One of 'name' or 'structName' are required.`),i.adapt&&(Object.keys(i.adapt.struct||{}).forEach(t=>{W.call(e,t,i.adapt.struct[t])}),Object.keys(i.adapt.set||{}).forEach(t=>{U.call(e,t,i.adapt.set[t])}),Object.keys(i.adapt.get||{}).forEach(t=>{ie.call(e,t,i.adapt.get[t])})),!i.members&&!i.sizeof&&(i.sizeof=D(i.signature));let l=B(r.__makeDebugFlags(Y.debugFlags));Object.defineProperties(o,{debugFlags:l,isA:B(e=>e instanceof o),memberKey:se,memberKeys:le,structInfo:B(i),structName:B(t),ptrAdd:B(b)}),o.prototype=new J(t,i,B),Object.defineProperties(o.prototype,{debugFlags:l,constructor:B(o),ptrAdd:B(x)});let u=!1,d=0,f=!!i.autoCalcSizeOffset;return f||i.sizeof||n(t,`description is missing its sizeof property.`),i.offset??=0,Object.keys(i.members||{}).forEach(e=>{let r=c(i.members[e]);!r.members&&!r.sizeof&&(r.sizeof=D(r.signature),r.sizeof||n(M(t,e),`is missing a sizeof property.`,r)),r.offset===void 0&&(f?r.offset=d:n(M(t,e),`is missing its offset.`,JSON.stringify(r))),i.members[e]=r,(!u||u.offset<r.offset)&&(u=r);let a=!!r.autoCalc;f&&(r.autoCalcSizeOffset=!0),xe.call(s,o,e,r),a?r.autoCalcSizeOffset=!0:delete r.autoCalcSizeOffset,d+=r.sizeof}),u||n(`No member property descriptions found.`),i.sizeof||=d,i.sizeof===1?i.signature===`c`||i.signature===`C`||n(`Unexpected sizeof==1 member`,M(t,k),`with signature`,i.signature):(i.sizeof%4!=0&&(console.warn(`Invalid struct member description`,i),n(t,`sizeof is not aligned. sizeof=`+i.sizeof)),i.offset%4!=0&&(console.warn(`Invalid struct member description`,i),n(t,`offset is not aligned. offset=`+i.offset))),i.sizeof<d&&(console.warn(`Suspect struct description:`,i,`offset =`,d),n(`Mismatch in the calculated vs. the provided sizeof/offset info.`,`Expected sizeof`,d,`but got`,i.sizeof,`for`,i)),delete i.autoCalcSizeOffset,o},Y=function e(t,n){return arguments.length==1?Se.call(e,t):Se.call(e,t,n)};return Y.StructType=J,Y.config=t,Y.allocCString=ge,Y.adaptGet=ie,Y.adaptSet=U,Y.adaptStruct=W,Y.ptrAdd=b,Y.debugFlags||=r.__makeDebugFlags(r.debugFlags),Y},globalThis.sqlite3ApiBootstrap.initializers.push(function(e){let t=(...e)=>{throw Error(e.join(` `))},n=e.capi,r=e.wasm,i=e.util;globalThis.WhWasmUtilInstaller(r),delete globalThis.WhWasmUtilInstaller;let a={core:[[`sqlite3_aggregate_context`,`void*`,`sqlite3_context*`,`int`],[`sqlite3_bind_double`,`int`,`sqlite3_stmt*`,`int`,`f64`],[`sqlite3_bind_int`,`int`,`sqlite3_stmt*`,`int`,`int`],[`sqlite3_bind_null`,void 0,`sqlite3_stmt*`,`int`],[`sqlite3_bind_parameter_count`,`int`,`sqlite3_stmt*`],[`sqlite3_bind_parameter_index`,`int`,`sqlite3_stmt*`,`string`],[`sqlite3_bind_parameter_name`,`string`,`sqlite3_stmt*`,`int`],[`sqlite3_bind_pointer`,`int`,`sqlite3_stmt*`,`int`,`*`,`string:static`,`*`],[`sqlite3_bind_zeroblob`,`int`,`sqlite3_stmt*`,`int`,`int`],[`sqlite3_busy_handler`,`int`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({signature:`i(pi)`,contextKey:(e,t)=>e[0]}),`*`]],[`sqlite3_busy_timeout`,`int`,`sqlite3*`,`int`],[`sqlite3_changes`,`int`,`sqlite3*`],[`sqlite3_clear_bindings`,`int`,`sqlite3_stmt*`],[`sqlite3_collation_needed`,`int`,`sqlite3*`,`*`,`*`],[`sqlite3_column_blob`,`*`,`sqlite3_stmt*`,`int`],[`sqlite3_column_bytes`,`int`,`sqlite3_stmt*`,`int`],[`sqlite3_column_count`,`int`,`sqlite3_stmt*`],[`sqlite3_column_decltype`,`string`,`sqlite3_stmt*`,`int`],[`sqlite3_column_double`,`f64`,`sqlite3_stmt*`,`int`],[`sqlite3_column_int`,`int`,`sqlite3_stmt*`,`int`],[`sqlite3_column_name`,`string`,`sqlite3_stmt*`,`int`],[`sqlite3_column_type`,`int`,`sqlite3_stmt*`,`int`],[`sqlite3_column_value`,`sqlite3_value*`,`sqlite3_stmt*`,`int`],[`sqlite3_commit_hook`,`void*`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_commit_hook`,signature:`i(p)`,contextKey:e=>e[0]}),`*`]],[`sqlite3_compileoption_get`,`string`,`int`],[`sqlite3_compileoption_used`,`int`,`string`],[`sqlite3_complete`,`int`,`string:flexible`],[`sqlite3_context_db_handle`,`sqlite3*`,`sqlite3_context*`],[`sqlite3_data_count`,`int`,`sqlite3_stmt*`],[`sqlite3_db_filename`,`string`,`sqlite3*`,`string`],[`sqlite3_db_handle`,`sqlite3*`,`sqlite3_stmt*`],[`sqlite3_db_name`,`string`,`sqlite3*`,`int`],[`sqlite3_db_readonly`,`int`,`sqlite3*`,`string`],[`sqlite3_db_status`,`int`,`sqlite3*`,`int`,`*`,`*`,`int`],[`sqlite3_errcode`,`int`,`sqlite3*`],[`sqlite3_errmsg`,`string`,`sqlite3*`],[`sqlite3_error_offset`,`int`,`sqlite3*`],[`sqlite3_errstr`,`string`,`int`],[`sqlite3_exec`,`int`,[`sqlite3*`,`string:flexible`,new r.xWrap.FuncPtrAdapter({signature:`i(pipp)`,bindScope:`transient`,callProxy:e=>{let t;return(i,a,o,s)=>{try{let n=r.cArgvToJs(a,o);return t||=r.cArgvToJs(a,s),e(n,t)|0}catch(e){return e.resultCode||n.SQLITE_ERROR}}}}),`*`,`**`]],[`sqlite3_expanded_sql`,`string`,`sqlite3_stmt*`],[`sqlite3_extended_errcode`,`int`,`sqlite3*`],[`sqlite3_extended_result_codes`,`int`,`sqlite3*`,`int`],[`sqlite3_file_control`,`int`,`sqlite3*`,`string`,`int`,`*`],[`sqlite3_finalize`,`int`,`sqlite3_stmt*`],[`sqlite3_free`,void 0,`*`],[`sqlite3_get_autocommit`,`int`,`sqlite3*`],[`sqlite3_get_auxdata`,`*`,`sqlite3_context*`,`int`],[`sqlite3_initialize`,void 0],[`sqlite3_interrupt`,void 0,`sqlite3*`],[`sqlite3_is_interrupted`,`int`,`sqlite3*`],[`sqlite3_keyword_count`,`int`],[`sqlite3_keyword_name`,`int`,[`int`,`**`,`*`]],[`sqlite3_keyword_check`,`int`,[`string`,`int`]],[`sqlite3_libversion`,`string`],[`sqlite3_libversion_number`,`int`],[`sqlite3_limit`,`int`,[`sqlite3*`,`int`,`int`]],[`sqlite3_malloc`,`*`,`int`],[`sqlite3_next_stmt`,`sqlite3_stmt*`,[`sqlite3*`,`sqlite3_stmt*`]],[`sqlite3_open`,`int`,`string`,`*`],[`sqlite3_open_v2`,`int`,`string`,`*`,`int`,`string`],[`sqlite3_realloc`,`*`,`*`,`int`],[`sqlite3_reset`,`int`,`sqlite3_stmt*`],[`sqlite3_result_blob`,void 0,`sqlite3_context*`,`*`,`int`,`*`],[`sqlite3_result_double`,void 0,`sqlite3_context*`,`f64`],[`sqlite3_result_error`,void 0,`sqlite3_context*`,`string`,`int`],[`sqlite3_result_error_code`,void 0,`sqlite3_context*`,`int`],[`sqlite3_result_error_nomem`,void 0,`sqlite3_context*`],[`sqlite3_result_error_toobig`,void 0,`sqlite3_context*`],[`sqlite3_result_int`,void 0,`sqlite3_context*`,`int`],[`sqlite3_result_null`,void 0,`sqlite3_context*`],[`sqlite3_result_pointer`,void 0,`sqlite3_context*`,`*`,`string:static`,`*`],[`sqlite3_result_subtype`,void 0,`sqlite3_value*`,`int`],[`sqlite3_result_text`,void 0,`sqlite3_context*`,`string`,`int`,`*`],[`sqlite3_result_zeroblob`,void 0,`sqlite3_context*`,`int`],[`sqlite3_rollback_hook`,`void*`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_rollback_hook`,signature:`v(p)`,contextKey:e=>e[0]}),`*`]],[`sqlite3_set_auxdata`,void 0,[`sqlite3_context*`,`int`,`*`,`*`]],[`sqlite3_set_errmsg`,`int`,`sqlite3*`,`int`,`string`],[`sqlite3_shutdown`,void 0],[`sqlite3_sourceid`,`string`],[`sqlite3_sql`,`string`,`sqlite3_stmt*`],[`sqlite3_status`,`int`,`int`,`*`,`*`,`int`],[`sqlite3_step`,`int`,`sqlite3_stmt*`],[`sqlite3_stmt_busy`,`int`,`sqlite3_stmt*`],[`sqlite3_stmt_readonly`,`int`,`sqlite3_stmt*`],[`sqlite3_stmt_status`,`int`,`sqlite3_stmt*`,`int`,`int`],[`sqlite3_strglob`,`int`,`string`,`string`],[`sqlite3_stricmp`,`int`,`string`,`string`],[`sqlite3_strlike`,`int`,`string`,`string`,`int`],[`sqlite3_strnicmp`,`int`,`string`,`string`,`int`],[`sqlite3_table_column_metadata`,`int`,`sqlite3*`,`string`,`string`,`string`,`**`,`**`,`*`,`*`,`*`],[`sqlite3_total_changes`,`int`,`sqlite3*`],[`sqlite3_trace_v2`,`int`,[`sqlite3*`,`int`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_trace_v2::callback`,signature:`i(ippp)`,contextKey:(e,t)=>e[0]}),`*`]],[`sqlite3_txn_state`,`int`,[`sqlite3*`,`string`]],[`sqlite3_uri_boolean`,`int`,`sqlite3_filename`,`string`,`int`],[`sqlite3_uri_key`,`string`,`sqlite3_filename`,`int`],[`sqlite3_uri_parameter`,`string`,`sqlite3_filename`,`string`],[`sqlite3_user_data`,`void*`,`sqlite3_context*`],[`sqlite3_value_blob`,`*`,`sqlite3_value*`],[`sqlite3_value_bytes`,`int`,`sqlite3_value*`],[`sqlite3_value_double`,`f64`,`sqlite3_value*`],[`sqlite3_value_dup`,`sqlite3_value*`,`sqlite3_value*`],[`sqlite3_value_free`,void 0,`sqlite3_value*`],[`sqlite3_value_frombind`,`int`,`sqlite3_value*`],[`sqlite3_value_int`,`int`,`sqlite3_value*`],[`sqlite3_value_nochange`,`int`,`sqlite3_value*`],[`sqlite3_value_numeric_type`,`int`,`sqlite3_value*`],[`sqlite3_value_pointer`,`*`,`sqlite3_value*`,`string:static`],[`sqlite3_value_subtype`,`int`,`sqlite3_value*`],[`sqlite3_value_type`,`int`,`sqlite3_value*`],[`sqlite3_vfs_find`,`*`,`string`],[`sqlite3_vfs_register`,`int`,`sqlite3_vfs*`,`int`],[`sqlite3_vfs_unregister`,`int`,`sqlite3_vfs*`]],int64:[[`sqlite3_bind_int64`,`int`,[`sqlite3_stmt*`,`int`,`i64`]],[`sqlite3_changes64`,`i64`,[`sqlite3*`]],[`sqlite3_column_int64`,`i64`,[`sqlite3_stmt*`,`int`]],[`sqlite3_deserialize`,`int`,`sqlite3*`,`string`,`*`,`i64`,`i64`,`int`],[`sqlite3_last_insert_rowid`,`i64`,[`sqlite3*`]],[`sqlite3_malloc64`,`*`,`i64`],[`sqlite3_msize`,`i64`,`*`],[`sqlite3_overload_function`,`int`,[`sqlite3*`,`string`,`int`]],[`sqlite3_realloc64`,`*`,`*`,`i64`],[`sqlite3_result_int64`,void 0,`*`,`i64`],[`sqlite3_result_zeroblob64`,`int`,`*`,`i64`],[`sqlite3_serialize`,`*`,`sqlite3*`,`string`,`*`,`int`],[`sqlite3_set_last_insert_rowid`,void 0,[`sqlite3*`,`i64`]],[`sqlite3_status64`,`int`,`int`,`*`,`*`,`int`],[`sqlite3_db_status64`,`int`,`sqlite3*`,`int`,`*`,`*`,`int`],[`sqlite3_total_changes64`,`i64`,[`sqlite3*`]],[`sqlite3_update_hook`,`*`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_update_hook::callback`,signature:`v(pippj)`,contextKey:e=>e[0],callProxy:e=>(t,n,i,a,o)=>{e(t,n,r.cstrToJs(i),r.cstrToJs(a),o)}}),`*`]],[`sqlite3_uri_int64`,`i64`,[`sqlite3_filename`,`string`,`i64`]],[`sqlite3_value_int64`,`i64`,`sqlite3_value*`]],wasmInternal:[[`sqlite3__wasm_db_reset`,`int`,`sqlite3*`],[`sqlite3__wasm_db_vfs`,`sqlite3_vfs*`,`sqlite3*`,`string`],[`sqlite3__wasm_vfs_create_file`,`int`,`sqlite3_vfs*`,`string`,`*`,`int`],[`sqlite3__wasm_posix_create_file`,`int`,`string`,`*`,`int`],[`sqlite3__wasm_vfs_unlink`,`int`,`sqlite3_vfs*`,`string`],[`sqlite3__wasm_qfmt_token`,`string:dealloc`,`string`,`int`]]};if(r.exports.sqlite3_progress_handler&&a.core.push([`sqlite3_progress_handler`,void 0,[`sqlite3*`,`int`,new r.xWrap.FuncPtrAdapter({name:`xProgressHandler`,signature:`i(p)`,bindScope:`context`,contextKey:(e,t)=>e[0]}),`*`]]),r.exports.sqlite3_stmt_explain&&a.core.push([`sqlite3_stmt_explain`,`int`,`sqlite3_stmt*`,`int`],[`sqlite3_stmt_isexplain`,`int`,`sqlite3_stmt*`]),r.exports.sqlite3_set_authorizer&&a.core.push([`sqlite3_set_authorizer`,`int`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_set_authorizer::xAuth`,signature:`i(pissss)`,contextKey:(e,t)=>e[0],callProxy:e=>(t,i,a,o,s,c)=>{try{return a&&=r.cstrToJs(a),o&&=r.cstrToJs(o),s&&=r.cstrToJs(s),c&&=r.cstrToJs(c),e(t,i,a,o,s,c)|0}catch(e){return e.resultCode||n.SQLITE_ERROR}}}),`*`]]),r.exports.sqlite3_column_origin_name&&a.core.push([`sqlite3_column_database_name`,`string`,`sqlite3_stmt*`,`int`],[`sqlite3_column_origin_name`,`string`,`sqlite3_stmt*`,`int`],[`sqlite3_column_table_name`,`string`,`sqlite3_stmt*`,`int`]),r.bigIntEnabled&&r.exports.sqlite3_declare_vtab&&a.int64.push([`sqlite3_create_module`,`int`,[`sqlite3*`,`string`,`sqlite3_module*`,`*`]],[`sqlite3_create_module_v2`,`int`,[`sqlite3*`,`string`,`sqlite3_module*`,`*`,`*`]],[`sqlite3_declare_vtab`,`int`,[`sqlite3*`,`string:flexible`]],[`sqlite3_drop_modules`,`int`,[`sqlite3*`,`**`]],[`sqlite3_vtab_collation`,`string`,`sqlite3_index_info*`,`int`],[`sqlite3_vtab_distinct`,`int`,`sqlite3_index_info*`],[`sqlite3_vtab_in`,`int`,`sqlite3_index_info*`,`int`,`int`],[`sqlite3_vtab_in_first`,`int`,`sqlite3_value*`,`**`],[`sqlite3_vtab_in_next`,`int`,`sqlite3_value*`,`**`],[`sqlite3_vtab_nochange`,`int`,`sqlite3_context*`],[`sqlite3_vtab_on_conflict`,`int`,`sqlite3*`],[`sqlite3_vtab_rhs_value`,`int`,`sqlite3_index_info*`,`int`,`**`]),r.bigIntEnabled&&r.exports.sqlite3_preupdate_hook&&a.int64.push([`sqlite3_preupdate_blobwrite`,`int`,`sqlite3*`],[`sqlite3_preupdate_count`,`int`,`sqlite3*`],[`sqlite3_preupdate_depth`,`int`,`sqlite3*`],[`sqlite3_preupdate_hook`,`*`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`sqlite3_preupdate_hook`,signature:`v(ppippjj)`,contextKey:e=>e[0],callProxy:e=>(t,n,i,a,o,s,c)=>{e(t,n,i,r.cstrToJs(a),r.cstrToJs(o),s,c)}}),`*`]],[`sqlite3_preupdate_new`,`int`,[`sqlite3*`,`int`,`**`]],[`sqlite3_preupdate_old`,`int`,[`sqlite3*`,`int`,`**`]]),r.bigIntEnabled&&r.exports.sqlite3changegroup_add&&r.exports.sqlite3session_create&&r.exports.sqlite3_preupdate_hook){let e={signature:`i(ps)`,callProxy:e=>(t,i)=>{try{return e(t,r.cstrToJs(i))|0}catch(e){return e.resultCode||n.SQLITE_ERROR}}};a.int64.push([`sqlite3changegroup_add`,`int`,[`sqlite3_changegroup*`,`int`,`void*`]],[`sqlite3changegroup_add_strm`,`int`,[`sqlite3_changegroup*`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`]],[`sqlite3changegroup_delete`,void 0,[`sqlite3_changegroup*`]],[`sqlite3changegroup_new`,`int`,[`**`]],[`sqlite3changegroup_output`,`int`,[`sqlite3_changegroup*`,`int*`,`**`]],[`sqlite3changegroup_output_strm`,`int`,[`sqlite3_changegroup*`,new r.xWrap.FuncPtrAdapter({name:`xOutput`,signature:`i(ppi)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_apply`,`int`,[`sqlite3*`,`int`,`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,bindScope:`transient`,...e}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_apply_strm`,`int`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,bindScope:`transient`,...e}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_apply_v2`,`int`,[`sqlite3*`,`int`,`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,bindScope:`transient`,...e}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`,`**`,`int*`,`int`]],[`sqlite3changeset_apply_v2_strm`,`int`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,bindScope:`transient`,...e}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`,`**`,`int*`,`int`]],[`sqlite3changeset_apply_v3`,`int`,[`sqlite3*`,`int`,`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,signature:`i(pp)`,bindScope:`transient`}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`,`**`,`int*`,`int`]],[`sqlite3changeset_apply_v3_strm`,`int`,[`sqlite3*`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,signature:`i(pp)`,bindScope:`transient`}),new r.xWrap.FuncPtrAdapter({name:`xConflict`,signature:`i(pip)`,bindScope:`transient`}),`void*`,`**`,`int*`,`int`]],[`sqlite3changeset_concat`,`int`,[`int`,`void*`,`int`,`void*`,`int*`,`**`]],[`sqlite3changeset_concat_strm`,`int`,[new r.xWrap.FuncPtrAdapter({name:`xInputA`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xInputB`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xOutput`,signature:`i(ppi)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_conflict`,`int`,[`sqlite3_changeset_iter*`,`int`,`**`]],[`sqlite3changeset_finalize`,`int`,[`sqlite3_changeset_iter*`]],[`sqlite3changeset_fk_conflicts`,`int`,[`sqlite3_changeset_iter*`,`int*`]],[`sqlite3changeset_invert`,`int`,[`int`,`void*`,`int*`,`**`]],[`sqlite3changeset_invert_strm`,`int`,[new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,new r.xWrap.FuncPtrAdapter({name:`xOutput`,signature:`i(ppi)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_new`,`int`,[`sqlite3_changeset_iter*`,`int`,`**`]],[`sqlite3changeset_next`,`int`,[`sqlite3_changeset_iter*`]],[`sqlite3changeset_old`,`int`,[`sqlite3_changeset_iter*`,`int`,`**`]],[`sqlite3changeset_op`,`int`,[`sqlite3_changeset_iter*`,`**`,`int*`,`int*`,`int*`]],[`sqlite3changeset_pk`,`int`,[`sqlite3_changeset_iter*`,`**`,`int*`]],[`sqlite3changeset_start`,`int`,[`**`,`int`,`*`]],[`sqlite3changeset_start_strm`,`int`,[`**`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`]],[`sqlite3changeset_start_v2`,`int`,[`**`,`int`,`*`,`int`]],[`sqlite3changeset_start_v2_strm`,`int`,[`**`,new r.xWrap.FuncPtrAdapter({name:`xInput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`,`int`]],[`sqlite3session_attach`,`int`,[`sqlite3_session*`,`string`]],[`sqlite3session_changeset`,`int`,[`sqlite3_session*`,`int*`,`**`]],[`sqlite3session_changeset_size`,`i64`,[`sqlite3_session*`]],[`sqlite3session_changeset_strm`,`int`,[`sqlite3_session*`,new r.xWrap.FuncPtrAdapter({name:`xOutput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`]],[`sqlite3session_config`,`int`,[`int`,`void*`]],[`sqlite3session_create`,`int`,[`sqlite3*`,`string`,`**`]],[`sqlite3session_diff`,`int`,[`sqlite3_session*`,`string`,`string`,`**`]],[`sqlite3session_enable`,`int`,[`sqlite3_session*`,`int`]],[`sqlite3session_indirect`,`int`,[`sqlite3_session*`,`int`]],[`sqlite3session_isempty`,`int`,[`sqlite3_session*`]],[`sqlite3session_memory_used`,`i64`,[`sqlite3_session*`]],[`sqlite3session_object_config`,`int`,[`sqlite3_session*`,`int`,`void*`]],[`sqlite3session_patchset`,`int`,[`sqlite3_session*`,`*`,`**`]],[`sqlite3session_patchset_strm`,`int`,[`sqlite3_session*`,new r.xWrap.FuncPtrAdapter({name:`xOutput`,signature:`i(ppp)`,bindScope:`transient`}),`void*`]],[`sqlite3session_table_filter`,void 0,[`sqlite3_session*`,new r.xWrap.FuncPtrAdapter({name:`xFilter`,...e,contextKey:(e,t)=>e[0]}),`*`]])}e.StructBinder=globalThis.Jaccwabyt({heap:r.heap8u,alloc:r.alloc,dealloc:r.dealloc,bigIntEnabled:r.bigIntEnabled,pointerIR:r.ptr.ir,memberPrefix:`$`}),delete globalThis.Jaccwabyt;{let o=r.xWrap.argAdapter(`string`);r.xWrap.argAdapter(`string:flexible`,e=>o(i.flexibleString(e))),r.xWrap.argAdapter(`string:static`,function(e){return r.isPtr(e)?e:(e=``+e,this[e]||(this[e]=r.allocCString(e)))}.bind(Object.create(null)));let s=r.xWrap.argAdapter(`*`),c=function(){};r.xWrap.argAdapter(`sqlite3_filename`,s)(`sqlite3_context*`,s)(`sqlite3_value*`,s)(`void*`,s)(`sqlite3_changegroup*`,s)(`sqlite3_changeset_iter*`,s)(`sqlite3_session*`,s)(`sqlite3_stmt*`,t=>s(t instanceof(e?.oo1?.Stmt||c)?t.pointer:t))(`sqlite3*`,t=>s(t instanceof(e?.oo1?.DB||c)?t.pointer:t))(`sqlite3_vfs*`,t=>typeof t==`string`?n.sqlite3_vfs_find(t)||e.SQLite3Error.toss(n.SQLITE_NOTFOUND,`Unknown sqlite3_vfs name:`,t):s(t instanceof(n.sqlite3_vfs||c)?t.pointer:t)),r.exports.sqlite3_declare_vtab&&r.xWrap.argAdapter(`sqlite3_index_info*`,e=>s(e instanceof(n.sqlite3_index_info||c)?e.pointer:e))(`sqlite3_module*`,e=>s(e instanceof(n.sqlite3_module||c)?e.pointer:e));let l=r.xWrap.resultAdapter(`*`);r.xWrap.resultAdapter(`sqlite3*`,l)(`sqlite3_context*`,l)(`sqlite3_stmt*`,l)(`sqlite3_value*`,l)(`sqlite3_vfs*`,l)(`void*`,l);for(let e of a.core)n[e[0]]=r.xWrap.apply(null,e);for(let e of a.wasmInternal)i[e[0]]=r.xWrap.apply(null,e);for(let e of a.int64)n[e[0]]=r.bigIntEnabled?r.xWrap.apply(null,e):()=>t(e[0]+`() is unavailable due to lack`,`of BigInt support in this build.`);delete a.core,delete a.int64,delete a.wasmInternal,i.sqlite3__wasm_db_error=function(t,r,i){return t?(r instanceof e.WasmAllocError?(r=n.SQLITE_NOMEM,i=0):r instanceof Error&&(i||=``+r,r=r.resultCode||n.SQLITE_ERROR),n.sqlite3_set_errmsg(t,r,i)||r):n.SQLITE_MISUSE}}{let i=r.xCall(`sqlite3__wasm_enum_json`);i||t(`Maintenance required: increase sqlite3__wasm_enum_json()'s`,`static buffer size!`),r.ctype=JSON.parse(r.cstrToJs(i));let a=[`access`,`authorizer`,`blobFinalizers`,`changeset`,`config`,`dataTypes`,`dbConfig`,`dbStatus`,`encodings`,`fcntl`,`flock`,`ioCap`,`limits`,`openFlags`,`prepareFlags`,`resultCodes`,`sqlite3Status`,`stmtStatus`,`syncFlags`,`trace`,`txnState`,`udfFlags`,`version`];r.bigIntEnabled&&a.push(`serialize`,`session`,`vtab`);for(let e of a)for(let t of Object.entries(r.ctype[e]))n[t[0]]=t[1];r.functionEntry(n.SQLITE_WASM_DEALLOC)||t(`Internal error: cannot resolve exported function`,`entry SQLITE_WASM_DEALLOC (==`+n.SQLITE_WASM_DEALLOC+`).`);let o=Object.create(null);for(let e of Object.entries(r.ctype.resultCodes))o[e[1]]=e[0];n.sqlite3_js_rc_str=e=>o[e];let s=Object.assign(Object.create(null),{WasmTestStruct:!0,sqlite3_index_info:!r.bigIntEnabled,sqlite3_index_constraint:!r.bigIntEnabled,sqlite3_index_orderby:!r.bigIntEnabled,sqlite3_index_constraint_usage:!r.bigIntEnabled});for(let t of r.ctype.structs)s[t.name]||(n[t.name]=e.StructBinder(t));if(n.sqlite3_index_info){for(let e of[`sqlite3_index_constraint`,`sqlite3_index_orderby`,`sqlite3_index_constraint_usage`])n.sqlite3_index_info[e]=n[e],delete n[e];n.sqlite3_vtab_config=r.xWrap(`sqlite3__wasm_vtab_config`,`int`,[`sqlite3*`,`int`,`int`])}}let o=(e,t,r)=>i.sqlite3__wasm_db_error(e,n.SQLITE_MISUSE,t+`() requires `+r+` argument`+(r===1?``:`s`)+`.`),s=e=>i.sqlite3__wasm_db_error(e,n.SQLITE_FORMAT,`SQLITE_UTF8 is the only supported encoding.`),c=e=>r.xWrap.argAdapter(`sqlite3*`)(e),l=e=>r.isPtr(e)?r.cstrToJs(e):e,u=function(e,t){e=c(e);let n=this.dbMap.get(e);if(t)!n&&t>0&&this.dbMap.set(e,n=Object.create(null));else return this.dbMap.delete(e),n;return n}.bind(Object.assign(Object.create(null),{dbMap:new Map}));u.addCollation=function(e,t){let n=u(e,1);n.collation||=new Set,n.collation.add(l(t).toLowerCase())},u._addUDF=function(e,t,n,r){t=l(t).toLowerCase();let i=r.get(t);i||r.set(t,i=new Set),i.add(n<0?-1:n)},u.addFunction=function(e,t,n){let r=u(e,1);r.udf||=new Map,this._addUDF(e,t,n,r.udf)},r.exports.sqlite3_create_window_function&&(u.addWindowFunc=function(e,t,n){let r=u(e,1);r.wudf||=new Map,this._addUDF(e,t,n,r.wudf)}),u.cleanup=function(t){t=c(t);for(let i of[[`sqlite3_busy_handler`,3],[`sqlite3_commit_hook`,3],[`sqlite3_preupdate_hook`,3],[`sqlite3_progress_handler`,4],[`sqlite3_rollback_hook`,3],[`sqlite3_set_authorizer`,3],[`sqlite3_trace_v2`,4],[`sqlite3_update_hook`,3]]){let[a,o]=i;if(!r.exports[a])continue;let s=[t];s.length=o;try{n[a](...s)}catch(t){e.config.warn(`close-time call of`,a+`(`,s,`) threw:`,t)}}let i=u(t,0);if(!i)return;if(i.collation){for(let e of i.collation)try{n.sqlite3_create_collation_v2(t,e,n.SQLITE_UTF8,0,0,0)}catch{}delete i.collation}let a=0;for(;a<2;++a){let e=a?i.wudf:i.udf;if(!e)continue;let r=a?n.sqlite3_create_window_function:n.sqlite3_create_function_v2;for(let i of e){let e=i[0],o=i[1],s=[t,e,0,n.SQLITE_UTF8,0,0,0,0,0];a&&s.push(0);for(let e of o)try{s[2]=e,r.apply(null,s)}catch{}o.clear()}e.clear()}delete i.udf,delete i.wudf};{let e=r.xWrap(`sqlite3_close_v2`,`int`,`sqlite3*`);n.sqlite3_close_v2=function(t){if(arguments.length!==1)return o(t,`sqlite3_close_v2`,1);if(t)try{u.cleanup(t)}catch{}return e(t)}}if(n.sqlite3session_create){let e=r.xWrap(`sqlite3session_delete`,void 0,[`sqlite3_session*`]);n.sqlite3session_delete=function(t){if(arguments.length!==1)return o(pDb,`sqlite3session_delete`,1);t&&n.sqlite3session_table_filter(t,0,0),e(t)}}{let e=(e,t)=>`argv[`+t+`]:`+e[0]+`:`+r.cstrToJs(e[1]).toLowerCase(),t=r.xWrap(`sqlite3_create_collation_v2`,`int`,[`sqlite3*`,`string`,`int`,`*`,new r.xWrap.FuncPtrAdapter({name:`xCompare`,signature:`i(pipip)`,contextKey:e}),new r.xWrap.FuncPtrAdapter({name:`xDestroy`,signature:`v(p)`,contextKey:e})]);n.sqlite3_create_collation_v2=function(e,r,a,c,l,d){if(arguments.length!==6)return o(e,`sqlite3_create_collation_v2`,6);if(!(a&15))a|=n.SQLITE_UTF8;else if(n.SQLITE_UTF8!==(a&15))return s(e);try{let n=t(e,r,a,c,l,d);return n===0&&l instanceof Function&&u.addCollation(e,r),n}catch(t){return i.sqlite3__wasm_db_error(e,t)}},n.sqlite3_create_collation=(e,t,r,i,a)=>arguments.length===5?n.sqlite3_create_collation_v2(e,t,r,i,a,0):o(e,`sqlite3_create_collation`,5)}{let e=function(e,t){return e[0]+`:`+(e[2]<0?-1:e[2])+`:`+t+`:`+r.cstrToJs(e[1]).toLowerCase()},t=Object.assign(Object.create(null),{xInverseAndStep:{signature:`v(pip)`,contextKey:e,callProxy:e=>(t,r,i)=>{try{e(t,...n.sqlite3_values_to_js(r,i))}catch(e){n.sqlite3_result_error_js(t,e)}}},xFinalAndValue:{signature:`v(p)`,contextKey:e,callProxy:e=>t=>{try{n.sqlite3_result_js(t,e(t))}catch(e){n.sqlite3_result_error_js(t,e)}}},xFunc:{signature:`v(pip)`,contextKey:e,callProxy:e=>(t,r,i)=>{try{n.sqlite3_result_js(t,e(t,...n.sqlite3_values_to_js(r,i)))}catch(e){n.sqlite3_result_error_js(t,e)}}},xDestroy:{signature:`v(p)`,contextKey:e,callProxy:e=>t=>{try{e(t)}catch(e){console.error(`UDF xDestroy method threw:`,e)}}}}),a=r.xWrap(`sqlite3_create_function_v2`,`int`,[`sqlite3*`,`string`,`int`,`int`,`*`,new r.xWrap.FuncPtrAdapter({name:`xFunc`,...t.xFunc}),new r.xWrap.FuncPtrAdapter({name:`xStep`,...t.xInverseAndStep}),new r.xWrap.FuncPtrAdapter({name:`xFinal`,...t.xFinalAndValue}),new r.xWrap.FuncPtrAdapter({name:`xDestroy`,...t.xDestroy})]),c=r.exports.sqlite3_create_window_function?r.xWrap(`sqlite3_create_window_function`,`int`,[`sqlite3*`,`string`,`int`,`int`,`*`,new r.xWrap.FuncPtrAdapter({name:`xStep`,...t.xInverseAndStep}),new r.xWrap.FuncPtrAdapter({name:`xFinal`,...t.xFinalAndValue}),new r.xWrap.FuncPtrAdapter({name:`xValue`,...t.xFinalAndValue}),new r.xWrap.FuncPtrAdapter({name:`xInverse`,...t.xInverseAndStep}),new r.xWrap.FuncPtrAdapter({name:`xDestroy`,...t.xDestroy})]):void 0;n.sqlite3_create_function_v2=function e(t,r,c,l,d,f,p,m,h){if(e.length!==arguments.length)return o(t,`sqlite3_create_function_v2`,e.length);if(!(l&15))l|=n.SQLITE_UTF8;else if(n.SQLITE_UTF8!==(l&15))return s(t);try{let e=a(t,r,c,l,d,f,p,m,h);return e===0&&(f instanceof Function||p instanceof Function||m instanceof Function||h instanceof Function)&&u.addFunction(t,r,c),e}catch(e){return console.error(`sqlite3_create_function_v2() setup threw:`,e),i.sqlite3__wasm_db_error(t,e,`Creation of UDF threw: `+e)}},n.sqlite3_create_function=function e(t,r,i,a,s,c,l,u){return e.length===arguments.length?n.sqlite3_create_function_v2(t,r,i,a,s,c,l,u,0):o(t,`sqlite3_create_function`,e.length)},c?n.sqlite3_create_window_function=function e(t,r,a,l,d,f,p,m,h,g){if(e.length!==arguments.length)return o(t,`sqlite3_create_window_function`,e.length);if(!(l&15))l|=n.SQLITE_UTF8;else if(n.SQLITE_UTF8!==(l&15))return s(t);try{let e=c(t,r,a,l,d,f,p,m,h,g);return e===0&&(f instanceof Function||p instanceof Function||m instanceof Function||h instanceof Function||g instanceof Function)&&u.addWindowFunc(t,r,a),e}catch(e){return console.error(`sqlite3_create_window_function() setup threw:`,e),i.sqlite3__wasm_db_error(t,e,`Creation of UDF threw: `+e)}}:delete n.sqlite3_create_window_function,n.sqlite3_create_function_v2.udfSetResult=n.sqlite3_create_function.udfSetResult=n.sqlite3_result_js,n.sqlite3_create_window_function&&(n.sqlite3_create_window_function.udfSetResult=n.sqlite3_result_js),n.sqlite3_create_function_v2.udfConvertArgs=n.sqlite3_create_function.udfConvertArgs=n.sqlite3_values_to_js,n.sqlite3_create_window_function&&(n.sqlite3_create_window_function.udfConvertArgs=n.sqlite3_values_to_js),n.sqlite3_create_function_v2.udfSetError=n.sqlite3_create_function.udfSetError=n.sqlite3_result_error_js,n.sqlite3_create_window_function&&(n.sqlite3_create_window_function.udfSetError=n.sqlite3_result_error_js)}{let e=(e,t)=>(typeof e==`string`?t=-1:i.isSQLableTypedArray(e)?(t=e.byteLength,e=r.typedArrayToString(e instanceof ArrayBuffer?new Uint8Array(e):e)):Array.isArray(e)&&(e=e.join(``),t=-1),[e,t]),t={basic:r.xWrap(`sqlite3_prepare_v3`,`int`,[`sqlite3*`,`string`,`int`,`int`,`**`,`**`]),full:r.xWrap(`sqlite3_prepare_v3`,`int`,[`sqlite3*`,`*`,`int`,`int`,`**`,`**`])};n.sqlite3_prepare_v3=function a(s,c,l,u,d,f){if(a.length!==arguments.length)return o(s,`sqlite3_prepare_v3`,a.length);let[p,m]=e(c,Number(l));switch(typeof p){case`string`:return t.basic(s,p,m,u,d,null);case typeof r.ptr.null:return t.full(s,r.ptr.coerce(p),m,u,d,f);default:return i.sqlite3__wasm_db_error(s,n.SQLITE_MISUSE,`Invalid SQL argument type for sqlite3_prepare_v2/v3(). typeof=`+typeof p)}},n.sqlite3_prepare_v2=function e(t,r,i,a,s){return e.length===arguments.length?n.sqlite3_prepare_v3(t,r,i,0,a,s):o(t,`sqlite3_prepare_v2`,e.length)}}{let e=r.xWrap(`sqlite3_bind_text`,`int`,[`sqlite3_stmt*`,`int`,`string`,`int`,`*`]),t=r.xWrap(`sqlite3_bind_blob`,`int`,[`sqlite3_stmt*`,`int`,`*`,`int`,`*`]);n.sqlite3_bind_text=function t(a,s,c,l,u){if(t.length!==arguments.length)return o(n.sqlite3_db_handle(a),`sqlite3_bind_text`,t.length);if(r.isPtr(c)||c===null)return e(a,s,c,l,u);c instanceof ArrayBuffer?c=new Uint8Array(c):Array.isArray(pMem)&&(c=pMem.join(``));let d,f;try{if(i.isSQLableTypedArray(c))d=r.allocFromTypedArray(c),f=c.byteLength;else if(typeof c==`string`)[d,f]=r.allocCString(c);else return i.sqlite3__wasm_db_error(n.sqlite3_db_handle(a),n.SQLITE_MISUSE,`Invalid 3rd argument type for sqlite3_bind_text().`);return e(a,s,d,f,n.SQLITE_WASM_DEALLOC)}catch(e){return r.dealloc(d),i.sqlite3__wasm_db_error(n.sqlite3_db_handle(a),e)}},n.sqlite3_bind_blob=function e(a,s,c,l,u){if(e.length!==arguments.length)return o(n.sqlite3_db_handle(a),`sqlite3_bind_blob`,e.length);if(r.isPtr(c)||c===null)return t(a,s,c,l,u);c instanceof ArrayBuffer?c=new Uint8Array(c):Array.isArray(c)&&(c=c.join(``));let d,f;try{if(i.isBindableTypedArray(c))d=r.allocFromTypedArray(c),f=l>=0?l:c.byteLength;else if(typeof c==`string`)[d,f]=r.allocCString(c);else return i.sqlite3__wasm_db_error(n.sqlite3_db_handle(a),n.SQLITE_MISUSE,`Invalid 3rd argument type for sqlite3_bind_blob().`);return t(a,s,d,f,n.SQLITE_WASM_DEALLOC)}catch(e){return r.dealloc(d),i.sqlite3__wasm_db_error(n.sqlite3_db_handle(a),e)}}}if(!n.sqlite3_column_text){let e=r.xWrap.argAdapter(`sqlite3_stmt*`),t=r.xWrap.argAdapter(`int`),i=r.xWrap.argAdapter(`sqlite3_value*`),a=(e,t)=>r.typedArrayToString(r.heap8u(),Number(e),Number(e)+t);n.sqlite3_column_text=function(n,i){let o=e(n),s=t(i),c=r.exports.sqlite3_column_text(o,s);return c?a(c,r.exports.sqlite3_column_bytes(o,s)):null},n.sqlite3_value_text=function(e){let t=i(e),n=r.exports.sqlite3_value_text(t);return n?a(n,r.exports.sqlite3_value_bytes(t)):null}}n.sqlite3_config=function(e,...t){if(arguments.length<2)return n.SQLITE_MISUSE;switch(e){case n.SQLITE_CONFIG_COVERING_INDEX_SCAN:case n.SQLITE_CONFIG_MEMSTATUS:case n.SQLITE_CONFIG_SMALL_MALLOC:case n.SQLITE_CONFIG_SORTERREF_SIZE:case n.SQLITE_CONFIG_STMTJRNL_SPILL:case n.SQLITE_CONFIG_URI:return r.exports.sqlite3__wasm_config_i(e,t[0]);case n.SQLITE_CONFIG_LOOKASIDE:return r.exports.sqlite3__wasm_config_ii(e,t[0],t[1]);case n.SQLITE_CONFIG_MEMDB_MAXSIZE:return r.exports.sqlite3__wasm_config_j(e,t[0]);case n.SQLITE_CONFIG_GETMALLOC:case n.SQLITE_CONFIG_GETMUTEX:case n.SQLITE_CONFIG_GETPCACHE2:case n.SQLITE_CONFIG_GETPCACHE:case n.SQLITE_CONFIG_HEAP:case n.SQLITE_CONFIG_LOG:case n.SQLITE_CONFIG_MALLOC:case n.SQLITE_CONFIG_MMAP_SIZE:case n.SQLITE_CONFIG_MULTITHREAD:case n.SQLITE_CONFIG_MUTEX:case n.SQLITE_CONFIG_PAGECACHE:case n.SQLITE_CONFIG_PCACHE2:case n.SQLITE_CONFIG_PCACHE:case n.SQLITE_CONFIG_PCACHE_HDRSZ:case n.SQLITE_CONFIG_PMASZ:case n.SQLITE_CONFIG_SERIALIZED:case n.SQLITE_CONFIG_SINGLETHREAD:case n.SQLITE_CONFIG_SQLLOG:case n.SQLITE_CONFIG_WIN32_HEAPSIZE:default:return n.SQLITE_NOTFOUND}};{let e=new Set;n.sqlite3_auto_extension=function(t){if(t instanceof Function)t=r.installFunction(`i(ppp)`,t);else if(arguments.length!==1||!r.isPtr(t))return n.SQLITE_MISUSE;let i=r.exports.sqlite3_auto_extension(t);return t!==arguments[0]&&(i===0?e.add(t):r.uninstallFunction(t)),i},n.sqlite3_cancel_auto_extension=function(e){return!e||arguments.length!==1||!r.isPtr(e)?0:r.exports.sqlite3_cancel_auto_extension(e)},n.sqlite3_reset_auto_extension=function(){r.exports.sqlite3_reset_auto_extension();for(let t of e)r.uninstallFunction(t);e.clear()}}r.xWrap.FuncPtrAdapter.warnOnUse=!0;let d=e.StructBinder,f=function e(n,i,a,o=e.installMethodArgcCheck){if(n instanceof d.StructType?!(a instanceof Function)&&!r.isPtr(a)&&t(`Usage error: expecting a Function or WASM pointer to one.`):t(`Usage error: target object is-not-a StructType.`),arguments.length===1)return(t,r)=>e(n,t,r,o);e.argcProxy||(e.argcProxy=function(e,n,r,i){return function(...a){return r.length!==arguments.length&&t(`Argument mismatch for`,e.structInfo.name+`::`+n+`: Native signature is:`,i),r.apply(this,a)}},e.removeFuncList=function(){this.ondispose.__removeFuncList&&(this.ondispose.__removeFuncList.forEach((e,t)=>{if(r.isPtr(e))try{r.uninstallFunction(e)}catch{}}),delete this.ondispose.__removeFuncList)});let s=n.memberSignature(i);s.length<2&&t(`Member`,i,`does not have a function pointer signature:`,s);let c=n.memberKey(i),l=o&&!r.isPtr(a)?e.argcProxy(n,c,a,s):a;if(r.isPtr(l))l&&!r.functionEntry(l)&&t(`Pointer`,l,`is not a WASM function table entry.`),n[c]=l;else{let t=r.installFunction(l,s);n[c]=t,(!n.ondispose||!n.ondispose.__removeFuncList)&&(n.addOnDispose(`ondispose.__removeFuncList handler`,e.removeFuncList),n.ondispose.__removeFuncList=[]),n.ondispose.__removeFuncList.push(c,t)}return(t,r)=>e(n,t,r,o)};f.installMethodArgcCheck=!1;let p=function(e,t,n=f.installMethodArgcCheck){let r=new Map;for(let i of Object.keys(t)){let a=t[i],o=r.get(a);if(o){let t=e.memberKey(i);e[t]=e[e.memberKey(o)]}else f(e,i,a,n),r.set(a,i)}return e};d.StructType.prototype.installMethod=function(e,t,n=f.installMethodArgcCheck){return arguments.length<3&&e&&typeof e==`object`?p(this,...arguments):f(this,...arguments)},d.StructType.prototype.installMethods=function(e,t=f.installMethodArgcCheck){return p(this,e,t)}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){let t=(...t)=>{throw new e.SQLite3Error(...t)},n=e.capi,r=e.wasm,i=e.util;e.__isUnderTest?console.debug.bind(console):e.config.debug,e.__isUnderTest?console.warn.bind(console):e.config.warn,e.__isUnderTest?console.error.bind(console):e.config.error;let a=new WeakMap,o=new Set,s=new WeakMap,c=(e,t,n)=>{let r=Object.getOwnPropertyDescriptor(e,t);return r?r.value:n},l=function(e,r){return r&&(e instanceof p&&(e=e.pointer),t(r,`sqlite3 result code`,r+`:`,e?n.sqlite3_errmsg(e):n.sqlite3_errstr(r))),arguments[0]},u=r.installFunction(`i(ippp)`,function(e,t,i,a){n.SQLITE_TRACE_STMT===e&&console.log(`SQL TRACE #`+ ++this.counter,`via sqlite3@`+t+`[`+n.sqlite3_db_filename(t,null)+`]`,r.cstrToJs(a))}.bind({counter:0})),d=Object.create(null),f=function i(...c){let f=i.normalizeArgs(...c),p;if(p=f[`sqlite3*`])f[`sqlite3*:takeOwnership`]||o.add(this),this.filename=n.sqlite3_db_filename(p,`main`);else{let i=f.filename,a=f.vfs,o=f.flags;(typeof i!=`string`&&!r.isPtr(i)||typeof o!=`string`||a&&typeof a!=`string`&&!r.isPtr(a))&&(e.config.error(`Invalid DB ctor args`,f,arguments),t(`Invalid arguments for DB constructor:`,arguments,`opts:`,f));let s=0;o.indexOf(`c`)>=0&&(s|=n.SQLITE_OPEN_CREATE|n.SQLITE_OPEN_READWRITE),o.indexOf(`w`)>=0&&(s|=n.SQLITE_OPEN_READWRITE),s===0&&(s|=n.SQLITE_OPEN_READONLY),s|=n.SQLITE_OPEN_EXRESCODE;let c=r.pstack.pointer;try{let e=r.pstack.allocPtr(),t=n.sqlite3_open_v2(i,e,s,a||r.ptr.null);p=r.peekPtr(e),l(p,t),n.sqlite3_extended_result_codes(p,1),o.indexOf(`t`)>=0&&n.sqlite3_trace_v2(p,n.SQLITE_TRACE_STMT,u,p)}catch(e){throw p&&n.sqlite3_close_v2(p),e}finally{r.pstack.restore(c)}this.filename=r.isPtr(i)?r.cstrToJs(i):i}if(a.set(this,p),s.set(this,Object.create(null)),!f[`sqlite3*`])try{let r=d[n.sqlite3_js_db_vfs(p)||t(`Internal error: cannot get VFS for new db handle.`)];r&&(r instanceof Function?r(this,e):l(p,n.sqlite3_exec(p,r,0,0,0)))}catch(e){throw this.close(),e}};f.setVfsPostOpenCallback=function(e,n){n instanceof Function||t(`dbCtorHelper.setVfsPostOpenCallback() should not be used with a non-function argument.`,arguments),d[e]=n},f.normalizeArgs=function(e=`:memory:`,t=`c`,n=null){let r={};return arguments.length===1&&arguments[0]&&typeof arguments[0]==`object`?(Object.assign(r,arguments[0]),r.flags===void 0&&(r.flags=`c`),r.vfs===void 0&&(r.vfs=null),r.filename===void 0&&(r.filename=`:memory:`)):(r.filename=e,r.flags=t,r.vfs=n),r};let p=function(...e){f.apply(this,e)};p.dbCtorHelper=f;let m={null:1,number:2,string:3,boolean:4,blob:5};r.bigIntEnabled&&(m.bigint=m.number);let h=function(){m!==arguments[2]&&t(n.SQLITE_MISUSE,`Do not call the Stmt constructor directly. Use DB.prepare().`),this.db=arguments[0],a.set(this,arguments[1]),arguments.length>3&&!arguments[3]&&o.add(this)},g=function(e){return e.pointer||t(`DB has been closed.`),e},_=function(e,n){return(n!==(n|0)||n<0||n>=e.columnCount)&&t(`Column index`,n,`is out of range.`),e},y=function(e,r){let a=Object.create(null);switch(a.opt=Object.create(null),r.length){case 1:typeof r[0]==`string`||i.isSQLableTypedArray(r[0])||Array.isArray(r[0])?a.sql=r[0]:r[0]&&typeof r[0]==`object`&&(a.opt=r[0],a.sql=a.opt.sql);break;case 2:a.sql=r[0],a.opt=r[1];break;default:t(`Invalid argument count for exec().`)}a.sql=i.flexibleString(a.sql),typeof a.sql!=`string`&&t(`Missing SQL argument or unsupported SQL value type.`);let o=a.opt;switch(o.returnValue){case`resultRows`:o.resultRows||=[],a.returnVal=()=>o.resultRows;break;case`saveSql`:o.saveSql||=[],a.returnVal=()=>o.saveSql;break;case void 0:case`this`:a.returnVal=()=>e;break;default:t(`Invalid returnValue value:`,o.returnValue)}if(!o.callback&&!o.returnValue&&o.rowMode!==void 0&&(o.resultRows||=[],a.returnVal=()=>o.resultRows),o.callback||o.resultRows)switch(o.rowMode===void 0?`array`:o.rowMode){case`object`:a.cbArg=(e,t)=>{t.columnNames||=e.getColumnNames([]);let n=e.get([]),r=Object.create(null);for(let e in t.columnNames)r[t.columnNames[e]]=n[e];return r};break;case`array`:a.cbArg=e=>e.get([]);break;case`stmt`:Array.isArray(o.resultRows)&&t(`exec(): invalid rowMode for a resultRows array: must`,`be one of 'array', 'object',`,`a result column number, or column name reference.`),a.cbArg=e=>e;break;default:if(i.isInt32(o.rowMode)){a.cbArg=e=>e.get(o.rowMode);break}else if(typeof o.rowMode==`string`&&o.rowMode.length>1&&o.rowMode[0]===`$`){let e=o.rowMode.substr(1);a.cbArg=r=>{let i=r.get(Object.create(null))[e];return i===void 0?t(n.SQLITE_NOTFOUND,`exec(): unknown result column:`,e):i};break}t(`Invalid rowMode:`,o.rowMode)}return a},b=(e,t,n,...r)=>{let i=e.prepare(t);try{let e=i.bind(n).step()?i.get(...r):void 0;return i.reset(),e}finally{i.finalize()}},x=(e,t,n,r)=>e.exec({sql:t,bind:n,rowMode:r,returnValue:`resultRows`});p.checkRc=(e,t)=>l(e,t),p.prototype={isOpen:function(){return!!this.pointer},affirmOpen:function(){return g(this)},close:function(){let e=this.pointer;if(e){if(this.onclose&&this.onclose.before instanceof Function)try{this.onclose.before(this)}catch{}if(Object.keys(s.get(this)).forEach((e,t)=>{if(t&&t.pointer)try{t.finalize()}catch{}}),a.delete(this),s.delete(this),o.delete(this)||n.sqlite3_close_v2(e),this.onclose&&this.onclose.after instanceof Function)try{this.onclose.after(this)}catch{}delete this.filename}},changes:function(e=!1,t=!1){let r=g(this).pointer;return e?t?n.sqlite3_total_changes64(r):n.sqlite3_total_changes(r):t?n.sqlite3_changes64(r):n.sqlite3_changes(r)},dbFilename:function(e=`main`){return n.sqlite3_db_filename(g(this).pointer,e)},dbName:function(e=0){return n.sqlite3_db_name(g(this).pointer,e)},dbVfsName:function(e=0){let t,i=n.sqlite3_js_db_vfs(g(this).pointer,e);if(i){let e=new n.sqlite3_vfs(i);try{t=r.cstrToJs(e.$zName)}finally{e.dispose()}}return t},prepare:function(e){g(this);let i=r.pstack.pointer,a,o;try{a=r.pstack.alloc(8),p.checkRc(this,n.sqlite3_prepare_v2(this.pointer,e,-1,a,null)),o=r.peekPtr(a)}finally{r.pstack.restore(i)}o||t(`Cannot prepare empty SQL.`);let c=new h(this,o,m);return s.get(this)[o]=c,c},exec:function(){g(this);let e=y(this,arguments);if(!e.sql)return t(`exec() requires an SQL string.`);let a=e.opt,o=a.callback,s=Array.isArray(a.resultRows)?a.resultRows:void 0,c,l=a.bind,u=!!(e.cbArg||a.columnNames||s),d=r.scopedAllocPush(),f=Array.isArray(a.saveSql)?a.saveSql:void 0;try{let t=i.isSQLableTypedArray(e.sql),d=t?e.sql.byteLength:r.jstrlen(e.sql),g=r.scopedAlloc(2*r.ptr.size+(d+1)),_=r.ptr.add(g,r.ptr.size),y=r.ptr.add(_,r.ptr.size),b=r.ptr.add(y,d);for(t?r.heap8().set(e.sql,y):r.jstrcpy(e.sql,r.heap8(),y,d,!1),r.poke8(r.ptr.add(y,d),0);y&&r.peek8(y);){r.pokePtr([g,_],0),p.checkRc(this,n.sqlite3_prepare_v3(this.pointer,y,d,0,g,_));let t=r.peekPtr(g);if(y=r.peekPtr(_),d=Number(r.ptr.add(b,-y)),t){if(f&&f.push(n.sqlite3_sql(t).trim()),c=new h(this,t,m),l&&c.parameterCount&&(c.bind(l),l=null),u&&c.columnCount){let t=Array.isArray(a.columnNames)?0:1;if(u=!1,e.cbArg||s){let n=Object.create(null);for(;c.step();E.delete(c)){t++===0&&c.getColumnNames(n.columnNames=a.columnNames||[]),E.add(c);let r=e.cbArg(c,n);if(s&&s.push(r),o&&!1===o.call(a,r,c))break}E.delete(c)}t===0&&c.getColumnNames(a.columnNames)}else c.step();c.reset().finalize(),c=null}}}finally{c&&(E.delete(c),c.finalize()),r.scopedAllocPop(d)}return e.returnVal()},createFunction:function(e,i,a){let o=e=>e instanceof Function;switch(arguments.length){case 1:a=e,e=a.name,i=a.xFunc||0;break;case 2:o(i)||(a=i,i=a.xFunc||0)}a||={},typeof e!=`string`&&t(`Invalid arguments: missing function name.`);let s=a.xStep||0,l=a.xFinal||0,u=a.xValue||0,d=a.xInverse||0,f;o(i)?(f=!1,(o(s)||o(l))&&t(`Ambiguous arguments: scalar or aggregate?`),s=l=null):o(s)?(o(l)||t(`Missing xFinal() callback for aggregate or window UDF.`),i=null):o(l)?t(`Missing xStep() callback for aggregate or window UDF.`):t(`Missing function-type properties.`),!1===f?(o(u)||o(d))&&t(`xValue and xInverse are not permitted for non-window UDFs.`):o(u)?(o(d)||t(`xInverse must be provided if xValue is.`),f=!0):o(d)&&t(`xValue must be provided if xInverse is.`);let m=a.pApp;m!=null&&!r.isPtr(m)&&t(`Invalid value for pApp property. Must be a legal WASM pointer value.`);let h=a.xDestroy||0;h&&!o(h)&&t(`xDestroy property must be a function.`);let g=0;c(a,`deterministic`)&&(g|=n.SQLITE_DETERMINISTIC),c(a,`directOnly`)&&(g|=n.SQLITE_DIRECTONLY),c(a,`innocuous`)&&(g|=n.SQLITE_INNOCUOUS),e=e.toLowerCase();let _=i||s,y=c(a,`arity`),b=typeof y==`number`?y:_.length?_.length-1:0,x;return x=f?n.sqlite3_create_window_function(this.pointer,e,b,n.SQLITE_UTF8|g,m||0,s,l,u,d,h):n.sqlite3_create_function_v2(this.pointer,e,b,n.SQLITE_UTF8|g,m||0,i,s,l,h),p.checkRc(this,x),this},selectValue:function(e,t,n){return b(this,e,t,0,n)},selectValues:function(e,t,n){let r=this.prepare(e),i=[];try{for(r.bind(t);r.step();)i.push(r.get(0,n));r.reset()}finally{r.finalize()}return i},selectArray:function(e,t){return b(this,e,t,[])},selectObject:function(e,t){return b(this,e,t,{})},selectArrays:function(e,t){return x(this,e,t,`array`)},selectObjects:function(e,t){return x(this,e,t,`object`)},openStatementCount:function(){return this.pointer?Object.keys(s.get(this)).length:0},transaction:function(e){let r=`BEGIN`;arguments.length>1&&(/[^a-zA-Z]/.test(arguments[0])&&t(n.SQLITE_MISUSE,`Invalid argument for BEGIN qualifier.`),r+=` `+arguments[0],e=arguments[1]),g(this).exec(r);try{let t=e(this);return this.exec(`COMMIT`),t}catch(e){throw this.exec(`ROLLBACK`),e}},savepoint:function(e){g(this).exec(`SAVEPOINT oo1`);try{let t=e(this);return this.exec(`RELEASE oo1`),t}catch(e){throw this.exec(`ROLLBACK to SAVEPOINT oo1; RELEASE SAVEPOINT oo1`),e}},checkRc:function(e){return l(this,e)}},p.wrapHandle=function(t,i=!1){if(!t||!r.isPtr(t))throw new e.SQLite3Error(n.SQLITE_MISUSE,`Argument must be a WASM sqlite3 pointer`);return new p({"sqlite3*":t,"sqlite3*:takeOwnership":!!i})};let S=function(e){return e.pointer||t(`Stmt has been closed.`),e},C=function(e){let t=m[e==null?`null`:typeof e];switch(t){case m.boolean:case m.null:case m.number:case m.string:return t;case m.bigint:return r.bigIntEnabled?t:void 0;default:return i.isBindableTypedArray(e)?m.blob:void 0}},w=function(e){return C(e)||t(`Unsupported bind() argument type:`,typeof e)},T=function(e,r){let a=typeof r==`number`?r:n.sqlite3_bind_parameter_index(e.pointer,r);return a===0||!i.isInt32(a)?t(`Invalid bind() parameter name: `+r):(a<1||a>e.parameterCount)&&t(`Bind index`,r,`is out of range.`),a},E=new Set,D=new Set,O=function(e,n){return E.has(e)&&t(`Operation is illegal when statement is locked:`,n),e},A=function a(o,s,c,l){O(S(o),`bind()`),a._||=(a._tooBigInt=e=>t(`BigInt value is too big to store without precision loss:`,e),{string:function(e,t,i,a){let[o,s]=r.allocCString(i,!0);return(a?n.sqlite3_bind_blob:n.sqlite3_bind_text)(e.pointer,t,o,s,n.SQLITE_WASM_DEALLOC)}}),w(l),s=T(o,s);let u=0;switch(l==null?m.null:c){case m.null:u=n.sqlite3_bind_null(o.pointer,s);break;case m.string:u=a._.string(o,s,l,!1);break;case m.number:{let e;i.isInt32(l)?e=n.sqlite3_bind_int:typeof l==`bigint`?i.bigIntFits64(l)?r.bigIntEnabled?e=n.sqlite3_bind_int64:i.bigIntFitsDouble(l)?(l=Number(l),e=n.sqlite3_bind_double):a._tooBigInt(l):a._tooBigInt(l):(l=Number(l),e=r.bigIntEnabled&&Number.isInteger(l)?n.sqlite3_bind_int64:n.sqlite3_bind_double),u=e(o.pointer,s,l);break}case m.boolean:u=n.sqlite3_bind_int(o.pointer,s,l?1:0);break;case m.blob:{if(typeof l==`string`){u=a._.string(o,s,l,!0);break}else l instanceof ArrayBuffer?l=new Uint8Array(l):i.isBindableTypedArray(l)||t(`Binding a value as a blob requires`,`that it be a string, Uint8Array, Int8Array, or ArrayBuffer.`);let e=r.alloc(l.byteLength||1);r.heap8().set(l.byteLength?l:[0],Number(e)),u=n.sqlite3_bind_blob(o.pointer,s,e,l.byteLength,n.SQLITE_WASM_DEALLOC);break}default:e.config.warn(`Unsupported bind() argument type:`,l),t(`Unsupported bind() argument type: `+typeof l)}return u&&p.checkRc(o.db.pointer,u),o};h.prototype={finalize:function(){let e=this.pointer;if(e){O(this,`finalize()`);let t=o.delete(this)?0:n.sqlite3_finalize(e);return delete s.get(this.db)[e],a.delete(this),E.delete(this),D.delete(this),delete this.parameterCount,delete this.db,t}},clearBindings:function(){return O(S(this),`clearBindings()`),n.sqlite3_clear_bindings(this.pointer),D.delete(this),this},reset:function(e){O(this,`reset()`),e&&this.clearBindings();let t=n.sqlite3_reset(S(this).pointer);return D.delete(this),l(this.db,t),this},bind:function(){S(this);let e,n;switch(arguments.length){case 1:e=1,n=arguments[0];break;case 2:e=arguments[0],n=arguments[1];break;default:t(`Invalid bind() arguments.`)}return n===void 0?this:(this.parameterCount||t(`This statement has no bindable parameters.`),D.delete(this),n===null?A(this,e,m.null,n):Array.isArray(n)?(arguments.length!==1&&t(`When binding an array, an index argument is not permitted.`),n.forEach((e,t)=>A(this,t+1,w(e),e)),this):(n instanceof ArrayBuffer&&(n=new Uint8Array(n)),typeof n==`object`&&!i.isBindableTypedArray(n)?(arguments.length!==1&&t(`When binding an object, an index argument is not permitted.`),Object.keys(n).forEach(e=>A(this,e,w(n[e]),n[e])),this):A(this,e,w(n),n)))},bindAsBlob:function(e,n){S(this),arguments.length===1&&(n=e,e=1);let r=w(n);return m.string!==r&&m.blob!==r&&m.null!==r&&t(`Invalid value type for bindAsBlob()`),A(this,e,m.blob,n)},step:function(){O(this,`step()`);let t=n.sqlite3_step(S(this).pointer);switch(t){case n.SQLITE_DONE:return D.delete(this),!1;case n.SQLITE_ROW:return D.add(this),!0;default:D.delete(this),e.config.warn(`sqlite3_step() rc=`,t,n.sqlite3_js_rc_str(t),`SQL =`,n.sqlite3_sql(this.pointer)),p.checkRc(this.db.pointer,t)}},stepReset:function(){return this.step(),this.reset()},stepFinalize:function(){try{let e=this.step();return this.reset(),e}finally{try{this.finalize()}catch{}}},get:function(e,a){if(D.has(S(this))||t(`Stmt.step() has not (recently) returned true.`),Array.isArray(e)){let t=0,n=this.columnCount;for(;t<n;)e[t]=this.get(t++);return e}else if(e&&typeof e==`object`){let t=0,r=this.columnCount;for(;t<r;)e[n.sqlite3_column_name(this.pointer,t)]=this.get(t++);return e}switch(_(this,e),a===void 0?n.sqlite3_column_type(this.pointer,e):a){case n.SQLITE_NULL:return null;case n.SQLITE_INTEGER:if(r.bigIntEnabled){let t=n.sqlite3_column_int64(this.pointer,e);return t>=-(2**53-1)&&t<=2**53-1?Number(t).valueOf():t}else{let r=n.sqlite3_column_double(this.pointer,e);return(r>2**53-1||r<-(2**53-1))&&t(`Integer is out of range for JS integer range: `+r),i.isInt32(r)?r|0:r}case n.SQLITE_FLOAT:return n.sqlite3_column_double(this.pointer,e);case n.SQLITE_TEXT:return n.sqlite3_column_text(this.pointer,e);case n.SQLITE_BLOB:{let t=n.sqlite3_column_bytes(this.pointer,e),i=n.sqlite3_column_blob(this.pointer,e),a=new Uint8Array(t);return t&&(a.set(r.heap8u().slice(Number(i),Number(i)+t),0),this.db._blobXfer instanceof Array&&this.db._blobXfer.push(a.buffer)),a}default:t(`Don't know how to translate`,`type of result column #`+e+`.`)}t(`Not reached.`)},getInt:function(e){return this.get(e,n.SQLITE_INTEGER)},getFloat:function(e){return this.get(e,n.SQLITE_FLOAT)},getString:function(e){return this.get(e,n.SQLITE_TEXT)},getBlob:function(e){return this.get(e,n.SQLITE_BLOB)},getJSON:function(e){let t=this.get(e,n.SQLITE_STRING);return t===null?t:JSON.parse(t)},getColumnName:function(e){return n.sqlite3_column_name(_(S(this),e).pointer,e)},getColumnNames:function(e=[]){_(S(this),0);let t=this.columnCount;for(let r=0;r<t;++r)e.push(n.sqlite3_column_name(this.pointer,r));return e},getParamIndex:function(e){return S(this).parameterCount?n.sqlite3_bind_parameter_index(this.pointer,e):void 0},getParamName:function(e){return S(this).parameterCount?n.sqlite3_bind_parameter_name(this.pointer,e):void 0},isBusy:function(){return n.sqlite3_stmt_busy(S(this))!==0},isReadOnly:function(){return n.sqlite3_stmt_readonly(S(this))!==0}};{let e={enumerable:!0,get:function(){return a.get(this)},set:()=>t(`The pointer property is read-only.`)};Object.defineProperty(h.prototype,`pointer`,e),Object.defineProperty(p.prototype,`pointer`,e)}Object.defineProperty(h.prototype,`columnCount`,{enumerable:!1,get:function(){return n.sqlite3_column_count(this.pointer)},set:()=>t(`The columnCount property is read-only.`)}),Object.defineProperty(h.prototype,`parameterCount`,{enumerable:!1,get:function(){return n.sqlite3_bind_parameter_count(this.pointer)},set:()=>t(`The parameterCount property is read-only.`)}),h.wrapHandle=function(t,n,i=!1){if(!(t instanceof p)||!t.pointer)throw new e.SQLite3Error(e.SQLITE_MISUSE,`First argument must be an opened sqlite3.oo1.DB instance`);if(!n||!r.isPtr(n))throw new e.SQLite3Error(e.SQLITE_MISUSE,`Second argument must be a WASM sqlite3_stmt pointer`);return new h(t,n,m,!!i)},e.oo1={DB:p,Stmt:h}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){let t=e.util;e.initWorker1API=function(){let e=(...e)=>{throw Error(e.join(` `))};globalThis.WorkerGlobalScope instanceof Function||e(`initWorker1API() must be run from a Worker thread.`);let n=this.sqlite3||e(`Missing this.sqlite3 object.`),r=n.oo1.DB,i=function(e){let t=a.idMap.get(e);return t||(t=`db#`+ ++a.idSeq+`:`+Math.floor(Math.random()*1e8)+`:`+Math.floor(Math.random()*1e8),a.idMap.set(e,t),t)},a={dbList:[],idSeq:0,idMap:new WeakMap,xfer:[],open:function(e){let t=new r(e);return this.dbs[i(t)]=t,this.dbList.indexOf(t)<0&&this.dbList.push(t),t},close:function(e,n){if(e){delete this.dbs[i(e)];let r=e.filename,a=t.sqlite3__wasm_db_vfs(e.pointer,0);e.close();let o=this.dbList.indexOf(e);o>=0&&this.dbList.splice(o,1),n&&r&&a&&t.sqlite3__wasm_vfs_unlink(a,r)}},post:function(e,t){t&&t.length?(globalThis.postMessage(e,Array.from(t)),t.length=0):globalThis.postMessage(e)},dbs:Object.create(null),getDb:function(t,n=!0){return this.dbs[t]||(n?e(`Unknown (or closed) DB ID:`,t):void 0)}},o=function(t=a.dbList[0]){return t&&t.pointer?t:e(`DB is not opened.`)},s=function(e,t=!0){let n=a.getDb(e.dbId,!1)||a.dbList[0];return t?o(n):n},c=function(){return a.dbList[0]&&i(a.dbList[0])},l={open:function(t){let r=Object.create(null),o=t.args||Object.create(null);o.simulateError&&e(`Throwing because of simulateError flag.`);let s=Object.create(null);r.vfs=o.vfs,r.filename=o.filename||``;let c=a.open(r);return s.filename=c.filename,s.persistent=!!n.capi.sqlite3_js_db_uses_vfs(c.pointer,`opfs`),s.dbId=i(c),s.vfs=c.dbVfsName(),s},close:function(e){let t=s(e,!1),n={filename:t&&t.filename};if(t){let n=e.args&&typeof e.args==`object`?!!e.args.unlink:!1;a.close(t,n)}return n},exec:function(t){let r=typeof t.args==`string`?{sql:t.args}:t.args||Object.create(null);r.rowMode===`stmt`?e(`Invalid rowMode for 'exec': stmt mode`,`does not work in the Worker API.`):r.sql||e(`'exec' requires input SQL.`);let i=s(t);(r.callback||Array.isArray(r.resultRows))&&(i._blobXfer=a.xfer);let o=r.callback,c=0,l=!!r.columnNames;typeof o==`string`&&(l||(r.columnNames=[]),r.callback=function(e,t){a.post({type:o,columnNames:r.columnNames,rowNumber:++c,row:e},a.xfer)});try{let e=r.countChanges?i.changes(!0,r.countChanges===64):void 0;i.exec(r),e!==void 0&&(r.changeCount=i.changes(!0,r.countChanges===64)-e);let t=r.lastInsertRowId?n.capi.sqlite3_last_insert_rowid(i):void 0;t!==void 0&&(r.lastInsertRowId=t),r.callback instanceof Function&&(r.callback=o,a.post({type:o,columnNames:r.columnNames,rowNumber:null,row:void 0}))}finally{delete i._blobXfer,r.callback&&=o}return r},"config-get":function(){let e=Object.create(null),t=n.config;return[`bigIntEnabled`].forEach(function(n){Object.getOwnPropertyDescriptor(t,n)&&(e[n]=t[n])}),e.version=n.version,e.vfsList=n.capi.sqlite3_js_vfs_list(),e},export:function(e){let t=s(e),r={byteArray:n.capi.sqlite3_js_db_export(t.pointer),filename:t.filename,mimetype:`application/x-sqlite3`};return a.xfer.push(r.byteArray.buffer),r},toss:function(t){e(`Testing worker exception`)}};globalThis.onmessage=async function(t){t=t.data;let n,r=t.dbId,i=t.type,o=performance.now();try{l.hasOwnProperty(i)&&l[i]instanceof Function?n=await l[i](t):e(`Unknown db worker message type:`,t.type)}catch(e){i=`error`,n={operation:t.type,message:e.message,errorClass:e.name,input:t},e.stack&&(n.stack=typeof e.stack==`string`?e.stack.split(/\n\s*/):e.stack)}r||=n.dbId||c(),a.post({type:i,dbId:r,messageId:t.messageId,workerReceivedTime:o,workerRespondTime:performance.now(),departureTime:t.departureTime,result:n},a.xfer)},globalThis.postMessage({type:`sqlite3-api`,result:`worker1-ready`})}.bind({sqlite3:e})}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){let t=e.wasm,n=e.capi,r=e.util.toss3,i=Object.create(null);e.vfs=i,n.sqlite3_vfs.prototype.registerVfs=function(t=!1){this instanceof e.capi.sqlite3_vfs||r(`Expecting a sqlite3_vfs-type argument.`);let i=n.sqlite3_vfs_register(this,t?1:0);return i&&r(`sqlite3_vfs_register(`,this,`) failed with rc`,i),this.pointer!==n.sqlite3_vfs_find(this.$zName)&&r(`BUG: sqlite3_vfs_find(vfs.$zName) failed for just-installed VFS`,this),this},i.installVfs=function(e){let n=0,i=[`io`,`vfs`];for(let r of i){let i=e[r];i&&(++n,i.struct.installMethods(i.methods,!!i.applyArgcCheck),r===`vfs`&&(!i.struct.$zName&&typeof i.name==`string`&&i.struct.addOnDispose(i.struct.$zName=t.allocCString(i.name)),i.struct.registerVfs(!!i.asDefault)))}return n||r(`Misuse: installVfs() options object requires at least`,`one of:`,i),this}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(!e.wasm.exports.sqlite3_declare_vtab)return;let t=e.wasm,n=e.capi,r=e.util.toss3,i=Object.create(null);e.vtab=i;let a=n.sqlite3_index_info;a.prototype.nthConstraint=function(e,n=!1){if(e<0||e>=this.$nConstraint)return!1;let r=t.ptr.add(this.$aConstraint,a.sqlite3_index_constraint.structInfo.sizeof*e);return n?r:new a.sqlite3_index_constraint(r)},a.prototype.nthConstraintUsage=function(e,n=!1){if(e<0||e>=this.$nConstraint)return!1;let r=t.ptr.add(this.$aConstraintUsage,a.sqlite3_index_constraint_usage.structInfo.sizeof*e);return n?r:new a.sqlite3_index_constraint_usage(r)},a.prototype.nthOrderBy=function(e,n=!1){if(e<0||e>=this.$nOrderBy)return!1;let r=t.ptr.add(this.$aOrderBy,a.sqlite3_index_orderby.structInfo.sizeof*e);return n?r:new a.sqlite3_index_orderby(r)};let o=function(n,r){return function(i,a=!1){if(arguments.length===0&&(i=new r),i instanceof r)return this.set(i.pointer,i),i;t.isPtr(i)||e.SQLite3Error.toss(`Invalid argument to`,n+`()`);let o=this.get(i);return a&&this.delete(i),o}.bind(new Map)},s=function(e,n){let r=o(e,n);return Object.assign(Object.create(null),{StructType:n,create:e=>{let n=r();return t.pokePtr(e,n.pointer),n},get:e=>r(e),unget:e=>r(e,!0),dispose:e=>r(e,!0)?.dispose?.()})};i.xVtab=s(`xVtab`,n.sqlite3_vtab),i.xCursor=s(`xCursor`,n.sqlite3_vtab_cursor),i.xIndexInfo=e=>new n.sqlite3_index_info(e),i.xError=function t(r,i,a){if(t.errorReporter instanceof Function)try{t.errorReporter(`sqlite3_module::`+r+`(): `+i.message)}catch{}let o;return i instanceof e.WasmAllocError?o=n.SQLITE_NOMEM:arguments.length>2?o=a:i instanceof e.SQLite3Error&&(o=i.resultCode),o||n.SQLITE_ERROR},i.xError.errorReporter=e.config.error.bind(e.config),i.xRowid=(e,n)=>t.poke(e,n,`i64`),i.setupModule=function(a){let o=!1,s=this instanceof n.sqlite3_module?this:a.struct||(o=new n.sqlite3_module);try{let n=a.methods||r(`Missing 'methods' object.`);for(let e of Object.entries({xConnect:`xCreate`,xDisconnect:`xDestroy`})){let t=e[0],r=e[1];!0===n[t]?n[t]=n[r]:!0===n[r]&&(n[r]=n[t])}if(a.catchExceptions){let r=function(n,r){return[`xConnect`,`xCreate`].indexOf(n)>=0?function(a,o,s,c,l,u){try{return r(...arguments)||0}catch(r){return r instanceof e.WasmAllocError||(t.dealloc(t.peekPtr(u)),t.pokePtr(u,t.allocCString(r.message))),i.xError(n,r)}}:function(...e){try{return r(...e)||0}catch(e){return i.xError(n,e)}}},a=[`xCreate`,`xConnect`,`xBestIndex`,`xDisconnect`,`xDestroy`,`xOpen`,`xClose`,`xFilter`,`xNext`,`xEof`,`xColumn`,`xRowid`,`xUpdate`,`xBegin`,`xSync`,`xCommit`,`xRollback`,`xFindFunction`,`xRename`,`xSavepoint`,`xRelease`,`xRollbackTo`,`xShadowName`],o=Object.create(null);for(let e of a){let t=n[e];if(t instanceof Function)e===`xConnect`&&n.xCreate===t?o[e]=n.xCreate:e===`xCreate`&&n.xConnect===t?o[e]=n.xConnect:o[e]=r(e,t);else continue}s.installMethods(o,!1)}else s.installMethods(n,!!a.applyArgcCheck);if(s.$iVersion===0){let e;e=typeof a.iVersion==`number`?a.iVersion:s.$xIntegrity?4:s.$xShadowName?3:s.$xSavePoint||s.$xRelease||s.$xRollbackTo?2:1,s.$iVersion=e}}catch(e){throw o&&o.dispose(),e}return s},n.sqlite3_module.prototype.setupModule=function(e){return i.setupModule.call(this,e)}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(e.config.disable?.vfs?.kvvfs)return;let t=e.capi,n=t.sqlite3_kvvfs_methods,r=t.KVVfsFile,i=e.capi.sqlite3_vfs_find(`kvvfs`);if(delete t.sqlite3_kvvfs_methods,delete t.KVVfsFile,!i)return;let a=e.util,o=e.wasm,s=a.toss3,c=new n(o.exports.sqlite3__wasm_kvvfs_methods());a.assert(32<=c.$nKeySize,`unexpected kvvfsMethods.$nKeySize: `+c.$nKeySize);let l=Object.assign(Object.create(null),{rxJournalSuffix:/-journal$/,zKeyJrnl:o.allocCString(`jrnl`),zKeySz:o.allocCString(`sz`),keySize:c.$nKeySize,buffer:Object.assign(Object.create(null),{n:c.$nBufferSize,pool:Object.create(null)})});l.memBuffer=(e=0)=>l.buffer.pool[e]??=o.alloc(l.buffer.n),l.memBufferFree=e=>{let t=l.buffer.pool[e];t&&(o.dealloc(t),delete l.buffer.pool[e])};let u=e.__isUnderTest?(...t)=>e.config.debug?.(`kvvfs:`,...t):()=>{},d=(...t)=>e.config.warn?.(`kvvfs:`,...t),f=(...t)=>e.config.error?.(`kvvfs:`,...t);class p{#e=Object.create(null);#t=null;#n=0;constructor(){this.clear()}#r(){return this.#t??=Object.keys(this.#e)}key(e){return e<0||e>=this.#n?null:this.#r()[e]}getItem(e){return this.#e[e]??null}setItem(e,t){e in this.#e||(++this.#n,this.#t=null),this.#e[e]=``+t}removeItem(e){e in this.#e&&(delete this.#e[e],--this.#n,this.#t=null)}clear(){this.#e=Object.create(null),this.#t=null,this.#n=0}get length(){return this.#n}}let m=e=>e===`local`||e===`session`,h=e=>m(e)?`kvvfs-`+e+`-`:``,g=function(e,n=!1){if(m(e))return;let r=new Blob([e]).size;r||s(t.SQLITE_MISUSE,`Empty name is not permitted.`);let i=l.keySize-1;l.rxJournalSuffix.test(e)?n||s(t.SQLITE_MISUSE,`Storage names may not have a '-journal' suffix.`):[`-wal`,`-shm`].filter(t=>e.endsWith(t)).length?s(t.SQLITE_MISUSE,`Storage names may not have a -wal or -shm suffix.`):i-=8,r>i&&s(t.SQLITE_RANGE,`Storage name is too long. Limit =`,i);let a=0;for(;a<r;++a){let n=e.codePointAt(a);n<32&&s(t.SQLITE_RANGE,`Illegal character (`+n+`d) in storage name:`,e)}},_=(e,t=void 0)=>Object.assign(Object.create(null),{jzClass:e,refc:1,deleteAtRefc0:!1,storage:t||new p,keyPrefix:h(e),files:[],listeners:void 0}),y=e.kvvfs=Object.create(null);e.__isUnderTest&&(y.log=Object.assign(Object.create(null),{xOpen:!1,xClose:!1,xWrite:!1,xRead:!1,xSync:!1,xAccess:!1,xFileControl:!1,xRcrdRead:!1,xRcrdWrite:!1,xRcrdDelete:!1}));let b=function(t){let n=l.rxJournalSuffix.test(t.jzClass)?t.jzClass.replace(l.rxJournalSuffix,``):t.jzClass+`-journal`;y?.log?.xClose&&u(`cleaning up storage handles [`,t.jzClass,n,`]`,t),delete l.storagePool[t.jzClass],delete l.storagePool[n],e.__isUnderTest||(delete t.storage,delete t.refc)},x=e=>l.storagePool[e.jzClass]=l.storagePool[e.jzClass+`-journal`]=e;l.storagePool=Object.assign(Object.create(null),{".":_(`.`)}),globalThis.Storage&&(globalThis.localStorage instanceof globalThis.Storage&&(l.storagePool.local=_(`local`,globalThis.localStorage)),globalThis.sessionStorage instanceof globalThis.Storage&&(l.storagePool.session=_(`session`,globalThis.sessionStorage))),l.builtinStorageNames=Object.keys(l.storagePool);let S=e=>l.builtinStorageNames.indexOf(e)>-1;for(let e of Object.keys(l.storagePool)){let t=l.storagePool[e];l.storagePool[e+`-journal`]=t}l.setError=(e=void 0,n=t.SQLITE_ERROR)=>e?(l.lastError=e,e.resultCode|0||n):(delete l.lastError,0),l.popError=()=>{let e=l.lastError;return delete l.lastError,e};let C=e=>{d(`kvvfs.listener handler threw:`,e)},w=o.exports.sqlite3__wasm_kvvfs_decode,T=o.exports.sqlite3__wasm_kvvfs_encode,E=async function(e,t,...n){try{t.keyPrefix&&n[0]&&(n[0]=n[0].replace(t.keyPrefix,``));let r,i,a,s;for(let c of t.listeners){let u=Object.create(null);u.storageName=t.jzClass,u.type=e,c.decodePages;let f=c.events[e];if(f){if(!c.includeJournal&&n[0]===`jrnl`)continue;if(e===`write`&&c.decodePages&&+n[0]>0){if(u.data=[n[0]],s?.[n[0]]){u.data[1]=s[n[0]];continue}r??=new TextEncoder(`utf-8`),i??=l.memBuffer(10),a??=l.memBuffer(11);let e=r.encode(n[1]),t=o.heap8u();t.set(e,Number(i)),t[o.ptr.addn(i,e.length)]=0;let c=w(i,a,l.buffer.n);if(c>0)s??=Object.create(null),s[n[0]]=u.data[1]=t.slice(Number(a),o.ptr.addn(a,c));else continue}else u.data=n.length?n.length===1?n[0]:n:void 0;try{f(u)?.catch?.(C)}catch(n){d(`notifyListeners [`,t.jzClass,`]`,e,n)}}}}catch(e){C(e)}},D=e=>typeof e==`string`?l.storagePool[e]:l.storagePool[o.cstrToJs(e)],O=o.exports.sqlite3__wasm_kvvfsMakeKey,A=(e,t,n)=>t&&e.keyPrefix?O(t,n):n,j=(e,t,n)=>o.cstrToJs(A(e,t,n)),ee=e=>+e.storage.getItem(e.keyPrefix+`sz`),M=new Map,N={vfs:Object.create(null),ioDb:Object.create(null),ioJrnl:Object.create(null)},P=new t.sqlite3_vfs(c.$pVfs),F=new t.sqlite3_io_methods(c.$pIoDb),I=new t.sqlite3_io_methods(c.$pIoJrnl),L=Object.create(null),te=Object.assign(Object.create(null),{pFileHandles:M,cache:l,storageForZClass:D,KVVfsStorage:p,disablePageSizeChange:!0});y.log&&(y.internal=te);let R={recordHandler:{xRcrdRead:(e,n,r,i)=>{try{let a=o.cstrToJs(e),c=D(a);if(!c)return-1;let u=j(c,e,n);y?.log?.xRcrdRead&&d(`xRcrdRead`,a,u,i,c);let f=c.storage.getItem(u);if(f===null)return-1;let p=f.length;if(i<=0)return p;if(i===1)return o.poke(r,0),p;i+1<p&&s(t.SQLITE_RANGE,`xRcrdRead()`,a,u,`input buffer is too small: need`,p,`but have`,i);let m=l.memBuffer(0),h=o.heap8(),g=0;for(;g<p;++g)h[o.ptr.add(m,g)]=f.codePointAt(g)&255;return h.copyWithin(Number(r),Number(m),o.ptr.addn(m,g)),h[o.ptr.add(r,p)]=0,i}catch(e){return f(`kvrecordRead()`,e),l.setError(e),-2}},xRcrdWrite:(e,n,r)=>{try{let t=D(e),i=j(t,e,n),a=o.cstrToJs(r);return y?.log?.xRcrdWrite&&d(`xRcrdWrite`,i,t),t.storage.setItem(i,a),t.listeners&&E(`write`,t,i,a),0}catch(e){return f(`kvrecordWrite()`,e),l.setError(e,t.SQLITE_IOERR)}},xRcrdDelete:(e,n)=>{try{let t=D(e),r=j(t,e,n);return y?.log?.xRcrdDelete&&d(`xRcrdDelete`,r,t),t.storage.removeItem(r),t.listeners&&E(`delete`,t,r),0}catch(e){return f(`kvrecordDelete()`,e),l.setError(e,t.SQLITE_IOERR)}}},vfs:{xOpen:function(e,n,i,c,f){l.popError();let p;try{n||=(p=o.allocCString(``+i+`.`+(Math.random()*1e5|0)),p);let d=o.cstrToJs(n);y?.log?.xOpen&&u(`xOpen`,d,`flags =`,c),g(d,!0),c&(t.SQLITE_OPEN_MAIN_DB|t.SQLITE_OPEN_TEMP_DB|t.SQLITE_OPEN_TRANSIENT_DB)&&l.rxJournalSuffix.test(d)&&s(t.SQLITE_ERROR,`DB files may not have a '-journal' suffix.`);let m=D(d);!m&&!(c&t.SQLITE_OPEN_CREATE)&&s(t.SQLITE_ERROR,`Storage not found:`,d);let h=N.vfs.xOpen(e,n,i,c,f);if(h)return h;let b=!!(t.SQLITE_OPEN_DELETEONCLOSE&c);o.isPtr(arguments[1])&&t.sqlite3_uri_boolean(n,`delete-on-close`,0)&&(b=!0);let S=new r(i);if(a.assert(S.$zClass,`Missing f.$zClass`),S.addOnDispose(p),p=void 0,m)++m.refc,m.files.push(S),o.poke32(f,c);else{o.poke32(f,c|t.SQLITE_OPEN_CREATE),a.assert(!S.$isJournal,`Opening a journal before its db? `+d);let e=d.replace(l.rxJournalSuffix,``);m=_(e),x(m),m.files.push(S),m.deleteAtRefc0=b,y?.log?.xOpen&&u(`xOpen installed storage handle [`,e,e+`-journal`,`]`,m)}return M.set(i,{store:m,file:S,jzClass:d}),m.listeners&&E(`open`,m,m.files.length),0}catch(e){return d(`xOpen:`,e),l.setError(e)}finally{p&&o.dealloc(p)}},xDelete:function(e,t,n){l.popError();try{let e=o.cstrToJs(t);return l.rxJournalSuffix.test(e)&&L.xRcrdDelete(t,l.zKeyJrnl),0}catch(e){return d(`xDelete`,e),l.setError(e)}},xAccess:function(e,t,n,r){l.popError();try{let e=D(t),i=e?.jzClass||o.cstrToJs(t);if(y?.log?.xAccess&&u(`xAccess`,i,`flags =`,n,`*pResOut =`,o.peek32(r),`store =`,e),!e)try{g(i)}catch{return o.poke32(r,0),0}if(e){let t=e.keyPrefix+(l.rxJournalSuffix.test(i)?`jrnl`:`1`),n=e.storage.getItem(t)?0:1;o.poke32(r,n)}else o.poke32(r,0);return 0}catch(e){return f(`xAccess`,e),l.setError(e)}},xRandomness:function(e,t,n){let r=o.heap8u(),i=0,a=Number(n);for(;i<t;++i)r[a+i]=Math.random()*255e3&255;return t},xGetLastError:function(e,n,r){let i=l.popError();if(u(`xGetLastError`,i),i){let e=o.scopedAllocPush();try{let[e,a]=o.scopedAllocCString(i.message,!0);return o.cstrncpy(r,e,n),a>n&&o.poke8(o.ptr.add(r,n,-1),0),u(`set xGetLastError`,i.message),i.resultCode|0||t.SQLITE_IOERR}catch{return t.SQLITE_NOMEM}finally{o.scopedAllocPop(e)}}return 0}},ioDb:{xClose:function(e){l.popError();try{let t=M.get(e);if(y?.log?.xClose&&u(`xClose`,e,t),t){M.delete(e);let n=t.store;n.files=n.files.filter(e=>e!==t.file),--n.refc<=0&&n.deleteAtRefc0&&b(n),N.ioDb.xClose(e),t.file.dispose(),n.listeners&&E(`close`,n,n.files.length)}return 0}catch(e){return f(`xClose`,e),l.setError(e)}},xFileControl:function(e,n,r){l.popError();try{let i=M.get(e);if(a.assert(i,`Missing KVVfsFile handle`),y?.log?.xFileControl&&u(`xFileControl`,i,`op =`,n),n===t.SQLITE_FCNTL_PRAGMA&&te.disablePageSizeChange){let e=o.peekPtr(o.ptr.add(r,o.ptr.size));if(o.cstrToJs(e)===`page_size`){y?.log?.xFileControl&&u(`xFileControl pragma`,o.cstrToJs(e));let t=o.peekPtr(o.ptr.add(r,2*o.ptr.size));if(t)return y?.log?.xFileControl&&d(`xFileControl pragma`,i,`NOT setting page size to`,o.cstrToJs(t)),i.file.$szPage=-1,0;if(i.file.$szPage>0)return y?.log?.xFileControl&&d(`xFileControl`,i,`getting page size`,i.file.$szPage),o.pokePtr(r,o.allocCString(``+i.file.$szPage)),0}}let s=N.ioDb.xFileControl(e,n,r);return s==0&&t.SQLITE_FCNTL_SYNC===n&&i.store.listeners&&E(`sync`,i.store,!1),s}catch(e){return f(`xFileControl`,e),l.setError(e)}},xSync:function(e,t){l.popError();try{let n=M.get(e);y?.log?.xSync&&u(`xSync`,n),a.assert(n,`Missing KVVfsFile handle`);let r=N.ioDb.xSync(e,t);return r==0&&n.store.listeners&&E(`sync`,n.store,!0),r}catch(e){return f(`xSync`,e),l.setError(e)}}},ioJrnl:{xClose:!0}};try{a.assert(l.buffer.n>132096,`Heap buffer is not large enough`);for(let e of Object.entries(R.recordHandler)){let t=e[0],n=e[1];L[t]=n,c[c.memberKey(t)]=o.installFunction(c.memberSignature(t),n)}for(let e of Object.entries(R.vfs)){let t=e[0],n=e[1],r=P.memberKey(t),i=P.structInfo.members[t]||a.toss(`Missing pVfs.structInfo[`,t,`]`);N.vfs[t]=o.functionEntry(P[r]),P[r]=o.installFunction(i.signature,n)}for(let e of Object.entries(R.ioDb)){let t=e[0],n=e[1],r=F.memberKey(t);N.ioDb[t]=o.functionEntry(F[r])||a.toss(`Missing native pIoDb[`,r,`]`),F[r]=o.installFunction(F.memberSignature(t),n)}for(let e of Object.entries(R.ioJrnl)){let t=e[0],n=e[1],r=I.memberKey(t);N.ioJrnl[t]=o.functionEntry(I[r])||a.toss(`Missing native pIoJrnl[`,r,`]`),!0===n?I[r]=F[r]||a.toss(`Missing copied pIoDb[`,r,`]`):I[r]=o.installFunction(I.memberSignature(t),n)}}finally{c.dispose(),P.dispose(),F.dispose(),I.dispose()}let z=function e(n){if(n===``)return e(`local`)+e(`session`);let r=D(n);if(!r)return 0;r.files.length&&(globalThis.localStorage===r.storage||globalThis.sessionStorage===r.storage||s(t.SQLITE_ACCESS,`Cannot clear in-use database storage.`));let i=r.storage,a=[],o,c=i.length;for(o=0;o<c;++o){let e=i.key(o);(!r.keyPrefix||e.startsWith(r.keyPrefix))&&a.push(e)}return a.forEach(e=>i.removeItem(e)),a.length},B=function e(t){if(t===``)return e(`local`)+e(`session`);let n=D(t);if(!n)return 0;let r=n.storage,i,a=0;for(i=0;i<r.length;++i){let e=r.key(i);(!n.keyPrefix||e.startsWith(n.keyPrefix))&&(a+=e.length,a+=r.getItem(e).length)}return a*2},V=function(...e){let n;e.length===1&&typeof e[0]==`object`?n=e[0]:e.length&&(n=Object.assign(Object.create(null),{name:e[0]}));let r=n?D(n.name):null;r||s(t.SQLITE_NOTFOUND,`There is no kvvfs storage named`,n?.name);let i=r.storage,c=Object.assign(Object.create(null),{name:r.jzClass,timestamp:Date.now(),pages:[]}),u=Object.create(null),d=r.keyPrefix,f=d?/^kvvfs-[^-]+-(\w+)/:void 0,p=0,m=i.length;for(;p<m;++p){let e=i.key(p);if(!d||e.startsWith(d)){let r=(d?f.exec(e):void 0)?.[1]??e;switch(r){case`jrnl`:n.includeJournal&&(c.journal=i.getItem(e));break;case`sz`:c.size=+i.getItem(e);break;default:if(r=+r,(!a.isInt32(r)||r<=0)&&s(t.SQLITE_RANGE,`Malformed kvvfs key: `+e),n.decodePages){let t=i.getItem(e),n=t.length,a=l.memBuffer(0),s=l.memBuffer(1),c=o.heap8u(),d=0;for(;d<n;++d)c[o.ptr.add(a,d)]=t.codePointAt(d)&255;c[o.ptr.add(a,d)]=0;let f=w(a,s,l.buffer.n);u[r]=c.slice(Number(s),o.ptr.addn(s,f))}else u[r]=i.getItem(e)}}}return n.decodePages&&l.memBufferFree(1),Object.keys(u).map(e=>+e).sort().forEach(e=>c.pages.push(u[e])),c},ne=function(e,n=!1){!e?.timestamp||!e.name||e.size===void 0||!Array.isArray(e.pages)?s(t.SQLITE_MISUSE,`Malformed export object.`):(!e.size||e.size!==(e.size|0)||e.size>=2147483647)&&s(t.SQLITE_RANGE,`Invalid db size: `+e.size),g(e.name);let r=D(e.name),i=!r;r?(n?!r.files||!r.jzClass?s(t.SQLITE_ERROR,`Internal storage object`,e.name,`seems to be malformed.`):r.files.length&&s(t.SQLITE_IOERR_ACCESS,`Cannot import db storage while it is in use.`):s(t.SQLITE_ACCESS,`Storage '`+e.name+`' already exists and`,`overwrite was not specified.`),z(e.name)):r=_(e.name);let c=h(e.name),u;try{let t=r.storage;t.setItem(c+`sz`,e.size),e.journal&&t.setItem(c+`jrnl`,e.journal),e.pages[0]instanceof Uint8Array?e.pages.forEach((e,n)=>{let r=e.length;u??=l.memBuffer(1);let i=l.memBuffer(0),s=o.heap8u();s.set(e,Number(i)),s[o.ptr.addn(i,r)]=0;let d=T(i,r,u);a.assert(d<l.buffer.n,`Impossibly long output - possibly smashed the heap`),a.assert(o.peek8(o.ptr.add(u,d))===0,`Expecting NUL-terminated encoded output`);let f=o.cstrToJs(u);t.setItem(c+(n+1),f)}):e.pages[0]&&e.pages.forEach((e,n)=>t.setItem(c+(n+1),e)),i&&x(r)}catch{if(!i)try{z(e.name)}catch{}}finally{u&&l.memBufferFree(1)}return this},re=function(e){let t=D(e);if(t){++t.refc;return}g(e),x(_(e))},H=function(e){let t=D(e);return!t||m(t.jzClass)||S(t.jzClass)||l.rxJournalSuffix.test(e)?!1:t.refc>t.files.length||t.files.length===0?(--t.refc<=0&&b(t),!0):!1},ie=function(e){(!e||typeof e!=`object`)&&s(t.SQLITE_MISUSE,`Expecting a listener object.`);let n=D(e.storage);n||(e.storage&&e.reserve?(re(e.storage),n=D(e.storage),a.assert(n,`Unexpectedly cannot fetch reserved storage `+e.storage)):s(t.SQLITE_NOTFOUND,`No such storage:`,e.storage)),e.events&&(n.listeners??=[]).push(e)},ae=function(e){let t=D(e?.storage);if(t?.listeners&&e.events){let n=t.listeners.length;t.listeners=t.listeners.filter(t=>t!==e);let r=n>t.listeners.length;return t.listeners.length||(t.listeners=void 0),r}return!1};if(e.kvvfs.reserve=re,e.kvvfs.import=ne,e.kvvfs.export=V,e.kvvfs.unlink=H,e.kvvfs.listen=ie,e.kvvfs.unlisten=ae,e.kvvfs.exists=e=>!!D(e),e.kvvfs.estimateSize=B,e.kvvfs.clear=z,globalThis.Storage&&(t.sqlite3_js_kvvfs_size=(e=``)=>B(e),t.sqlite3_js_kvvfs_clear=(e=``)=>z(e)),e.oo1?.DB){let t=e.oo1.DB;e.oo1.JsStorageDb=function(n=e.oo1.JsStorageDb.defaultStorageName){let r=t.dbCtorHelper.normalizeArgs(...arguments);switch(r.vfs=`kvvfs`,r.filename){case`:sessionStorage:`:r.filename=`session`;break;case`:localStorage:`:r.filename=`local`}let i=/(file:(\/\/)?)([^?]+)/.exec(r.filename);g(i?i[3]:r.filename),t.dbCtorHelper.call(this,r)},e.oo1.JsStorageDb.defaultStorageName=l.storagePool.session?`session`:`.`;let n=e.oo1.JsStorageDb;n.prototype=Object.create(t.prototype),n.clearStorage=z,n.prototype.clearStorage=function(){return n.clearStorage(this.affirmOpen().dbFilename(),!0)},n.storageSize=B,n.prototype.storageSize=function(){return n.storageSize(this.affirmOpen().dbFilename(),!0)}}if(e.__isUnderTest&&e.vtab){let n=Object.assign(Object.create(null),{rowid:{type:`INTEGER`},name:{type:`TEXT`},nRef:{type:`INTEGER`},nOpen:{type:`INTEGER`},isTransient:{type:`INTEGER`},dbSize:{type:`INTEGER`}});Object.keys(n).forEach((e,t)=>n[e].colId=t);let r=e.vtab,i=Object.assign(Object.create(null),{row:function(){return l.storagePool[this.names[this.rowid]]}});Object.assign(Object.create(i),{rowid:0,names:Object.keys(l.storagePool).filter(e=>!l.rxJournalSuffix.test(e))});let s=function(e,n){let a=e instanceof t.sqlite3_vtab_cursor?e:r.xCursor.get(e);return(n||!a.vTabState)&&(a.vTabState=Object.assign(Object.create(i),{rowid:0,names:Object.keys(l.storagePool).filter(e=>!l.rxJournalSuffix.test(e))})),a.vTabState},c=function i(){return i.mod??=new e.capi.sqlite3_module().setupModule({catchExceptions:!0,methods:{xConnect:function(e,i,s,c,l,u){try{let i=[];Object.keys(n).forEach(e=>{i.push(e+` `+n[e].type)});let s=t.sqlite3_declare_vtab(e,`CREATE TABLE ignored(`+i.join(`,`)+`)`);if(s===0){let e=r.xVtab.create(l);a.assert(e===r.xVtab.get(o.peekPtr(l)),`output pointer check failed`)}return s}catch(e){return r.xError(`xConnect`,e,t.SQLITE_ERROR)}},xCreate:o.ptr.null,xDisconnect:function(e){return r.xVtab.dispose(e),0},xOpen:function(e,t){return r.xCursor.create(t),0},xClose:function(e){let t=r.xCursor.unget(e);return delete t.vTabState,t.dispose(),0},xNext:function(e){let t=r.xCursor.get(e);return++s(t).rowid,0},xColumn:function(e,r,i){let o=s(e),c=o.row();switch(a.assert(c,`Unexpected xColumn call`),i){case n.rowid.colId:t.sqlite3_result_int(r,o.rowid);break;case n.name.colId:t.sqlite3_result_text(r,c.jzClass,-1,t.SQLITE_TRANSIENT);break;case n.nRef.colId:t.sqlite3_result_int(r,c.refc);break;case n.nOpen.colId:t.sqlite3_result_int(r,c.files.length);break;case n.isTransient.colId:t.sqlite3_result_int(r,!!c.deleteAtRefc0);break;case n.dbSize.colId:t.sqlite3_result_int(r,ee(c));break;default:return t.sqlite3_result_error(r,`Invalid column id: `+i),t.SQLITE_RANGE}return 0},xRowid:function(e,t){let n=s(e);return r.xRowid(t,n.rowid),0},xEof:function(e){let t=s(e);return``+!t.row(),!t.row()},xFilter:function(e,t,n,r,i){return s(e,!0),0},xBestIndex:function(e,n){let r=new t.sqlite3_index_info(n);return r.$estimatedRows=l.storagePool.size,r.$estimatedCost=1,r.dispose(),0}}})};e.kvvfs.create_module=function(e,n=`sqlite_kvvfs`){return t.sqlite3_create_module(e,n,c(),o.ptr.null)}}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(e.config.disable?.vfs?.opfs&&e.config.disable.vfs[`opfs-vfs`])return;let t=e.util.toss;e.capi;let n=e.util;e.wasm;let r=e.opfs=Object.create(null);r.thisThreadHasOPFS=()=>globalThis.FileSystemHandle&&globalThis.FileSystemDirectoryHandle&&globalThis.FileSystemFileHandle&&globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle&&navigator?.storage?.getDirectory,r.getRootDir=async function e(){return e.promise??=navigator.storage.getDirectory().then(e=>(r.rootDirectory=e,e)).catch(t=>{throw delete e.promise,t})},r.getResolvedPath=function(e,t){let n=new URL(e,`file://irrelevant`).pathname;return t?n.split(`/`).filter(e=>!!e):n},r.getDirForFilename=async function(e,t=!1){let n=r.getResolvedPath(e,!0),i=n.pop(),a=await r.getRootDir();for(let e of n)e&&(a=await a.getDirectoryHandle(e,{create:!!t}));return[a,i]},r.mkdir=async function(e){try{return await r.getDirForFilename(e+`/filepart`,!0),!0}catch{return!1}},r.entryExists=async function(e){try{let[t,n]=await r.getDirForFilename(e);return await t.getFileHandle(n),!0}catch{return!1}},r.randomFilename=function e(t=16){e._chars||(e._chars=`abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012346789`,e._n=e._chars.length);let n=[],r=0;for(;r<t;++r){let t=Math.random()*(e._n*64)%e._n|0;n[r]=e._chars[t]}return n.join(``)},r.treeList=async function(){let e=async function e(t,n){n.name=t.name,n.dirs=[],n.files=[];for await(let r of t.values())if(r.kind===`directory`){let t=Object.create(null);n.dirs.push(t),await e(r,t)}else n.files.push(r.name)},t=Object.create(null);return await e(await r.getRootDir(),t),t},r.rmfr=async function(){let e=await r.getRootDir(),t={recurse:!0};for await(let n of e.values())e.removeEntry(n.name,t)},r.unlink=async function(e,t=!1,n=!1){try{let[n,i]=await r.getDirForFilename(e,!1);return await n.removeEntry(i,{recursive:t}),!0}catch(e){if(n)throw Error(`unlink(`,arguments[0],`) failed: `+e.message,{cause:e});return!1}},r.traverse=async function(e){let t={recursive:!0,directory:await r.getRootDir()};typeof e==`function`&&(e={callback:e}),e=Object.assign(t,e||{}),(async function t(n,r){for await(let i of n.values())if(!1===e.callback(i,n,r))return!1;else if(e.recursive&&i.kind===`directory`&&!1===await t(i,r+1))break})(e.directory,0)};let i=async function(e,i){let[a,o]=await r.getDirForFilename(e,!0),s=await(await a.getFileHandle(o,{create:!0})).createSyncAccessHandle(),c=0,l,u=!1;try{for(s.truncate(0);(l=await i())!==void 0;)l instanceof ArrayBuffer&&(l=new Uint8Array(l)),!u&&c===0&&l.byteLength>=15&&(n.affirmDbHeader(l),u=!0),s.write(l,{at:c}),c+=l.byteLength;if((c<512||c%512!=0)&&t(`Input size`,c,`is not correct for an SQLite database.`),!u){let e=new Uint8Array(20);s.read(e,{at:0}),n.affirmDbHeader(e)}return s.write(new Uint8Array([1,1]),{at:18}),c}catch(e){throw await s.close(),s=void 0,await a.removeEntry(o).catch(()=>{}),e}finally{s&&await s.close()}};r.importDb=async function(e,a){if(a instanceof Function)return i(e,a);a instanceof ArrayBuffer&&(a=new Uint8Array(a)),n.affirmIsDb(a);let o=a.byteLength,[s,c]=await r.getDirForFilename(e,!0),l,u=0;try{return l=await(await s.getFileHandle(c,{create:!0})).createSyncAccessHandle(),l.truncate(0),u=l.write(a,{at:0}),u!=o&&t(`Expected to write `+o+` bytes but wrote `+u+`.`),l.write(new Uint8Array([1,1]),{at:18}),u}catch(e){throw l&&=(await l.close(),void 0),await s.removeEntry(c).catch(()=>{}),e}finally{l&&await l.close()}},r.vfsInstallationFeatureCheck=function(e){!globalThis.SharedArrayBuffer||!globalThis.Atomics?t(`Cannot install OPFS: Missing SharedArrayBuffer and/or Atomics.`,`The server must emit the COOP/COEP response headers to enable those.`,`See https://sqlite.org/wasm/doc/trunk/persistence.md#coop-coep`):typeof WorkerGlobalScope>`u`?t(`The OPFS sqlite3_vfs cannot run in the main thread`,`because it requires Atomics.wait().`):!globalThis.FileSystemHandle||!globalThis.FileSystemDirectoryHandle||!globalThis.FileSystemFileHandle?.prototype?.createSyncAccessHandle||!navigator?.storage?.getDirectory?t(`Missing required OPFS APIs.`):e===`opfs-wl`&&!globalThis.Atomics.waitAsync&&t(`The`,e,`VFS requires Atomics.waitAsync(), which is not available.`)},r.initOptions=function(t,i){let a=new URL(globalThis.location.href).searchParams;if(!a.has(t+`-disable`)){try{r.vfsInstallationFeatureCheck(t)}catch{return}return i=n.nu(i),i.vfsName=t,i.verbose??=a.has(`opfs-verbose`)?+a.get(`opfs-verbose`):1,i.sanityChecks??=a.has(`opfs-sanity-check`),r.proxyUri||(r.proxyUri=`sqlite3-opfs-async-proxy.js`,e.scriptInfo?.sqlite3Dir&&(r.proxyUri=e.scriptInfo.sqlite3Dir+r.proxyUri)),i.proxyUri??=r.proxyUri,typeof i.proxyUri==`function`&&(i.proxyUri=i.proxyUri()),r.options=i}},r.createVfsState=function(){let i=n.nu(),a=r.options;i.verbose=a.verbose;let o=[e.config.error,e.config.warn,e.config.log],s=a.vfsName||t(`Maintenance required: missing VFS name`),c=(e,...t)=>{i.verbose>e&&o[e](s+`:`,...t)},l=(...e)=>c(2,...e),u=(...e)=>c(1,...e),d=(...e)=>c(0,...e),f=e.capi,p=e.wasm,m=i.vfs=new f.sqlite3_vfs,h=m.ioMethods=new f.sqlite3_io_methods;h.$iVersion=1,m.$iVersion=2,m.$szOsFile=f.sqlite3_file.structInfo.sizeof,m.$mxPathname=1024,m.$zName=p.allocCString(s),m.addOnDispose(`$zName`,m.$zName,h),m.metrics=n.nu({counters:n.nu(),dump:function(){let t,n=0,r=0,a=0;for(t in i.opIds){let e=g[t];n+=e.count,r+=e.time,a+=e.wait,e.avgTime=e.count&&e.time?e.time/e.count:0,e.avgWait=e.count&&e.wait?e.wait/e.count:0}e.config.log(globalThis.location.href,`metrics for`,globalThis.location.href,`:`,g,`
38
+ Total of`,n,`op(s) for`,r,`ms (incl. `+a+` ms of waiting on the async side)`),e.config.log(`Serialization metrics:`,m.metrics.counters.s11n),m.worker?.postMessage?.({type:`opfs-async-metrics`})},reset:function(){let e,t=e=>e.count=e.time=e.wait=0,n=m.metrics.counters;for(e in i.opIds)t(n[e]=Object.create(null));let r=n.s11n=Object.create(null);r=r.serialize=Object.create(null),r.count=r.time=0,r=n.s11n.deserialize=Object.create(null),r.count=r.time=0}}),i.asyncIdleWaitTime=150,i.asyncS11nExceptions=1,i.fileBufferSize=65536,i.sabS11nOffset=i.fileBufferSize,i.sabS11nSize=m.$mxPathname*2,i.sabIO=new SharedArrayBuffer(i.fileBufferSize+i.sabS11nSize),i.opIds=Object.create(null);{let e=0;i.opIds.whichOp=e++,i.opIds.rc=e++,i.opIds.xAccess=e++,i.opIds.xClose=e++,i.opIds.xDelete=e++,i.opIds.xDeleteNoWait=e++,i.opIds.xFileSize=e++,i.opIds.xLock=e++,i.opIds.xOpen=e++,i.opIds.xRead=e++,i.opIds.xSleep=e++,i.opIds.xSync=e++,i.opIds.xTruncate=e++,i.opIds.xUnlock=e++,i.opIds.xWrite=e++,i.opIds.mkdir=e++,i.opIds[`opfs-async-metrics`]=e++,i.opIds[`opfs-async-shutdown`]=e++,i.opIds.retry=e++,i.sabOP=new SharedArrayBuffer(e*4)}i.sq3Codes=Object.create(null);for(let e of`SQLITE_ACCESS_EXISTS.SQLITE_ACCESS_READWRITE.SQLITE_BUSY.SQLITE_CANTOPEN.SQLITE_ERROR.SQLITE_IOERR.SQLITE_IOERR_ACCESS.SQLITE_IOERR_CLOSE.SQLITE_IOERR_DELETE.SQLITE_IOERR_FSYNC.SQLITE_IOERR_LOCK.SQLITE_IOERR_READ.SQLITE_IOERR_SHORT_READ.SQLITE_IOERR_TRUNCATE.SQLITE_IOERR_UNLOCK.SQLITE_IOERR_WRITE.SQLITE_LOCK_EXCLUSIVE.SQLITE_LOCK_NONE.SQLITE_LOCK_PENDING.SQLITE_LOCK_RESERVED.SQLITE_LOCK_SHARED.SQLITE_LOCKED.SQLITE_MISUSE.SQLITE_NOTFOUND.SQLITE_OPEN_CREATE.SQLITE_OPEN_DELETEONCLOSE.SQLITE_OPEN_MAIN_DB.SQLITE_OPEN_READONLY.SQLITE_LOCK_NONE.SQLITE_LOCK_SHARED.SQLITE_LOCK_RESERVED.SQLITE_LOCK_PENDING.SQLITE_LOCK_EXCLUSIVE`.split(`.`))i.sq3Codes[e]=f[e]??t(`Maintenance required: not found:`,e);i.opfsFlags=Object.assign(Object.create(null),{OPFS_UNLOCK_ASAP:1,OPFS_UNLINK_BEFORE_OPEN:2,defaultUnlockAsap:!1}),m.metrics.reset();let g=m.metrics.counters,_=m.opRun=(e,...n)=>{let r=i.opIds[e]||t(m.vfsName+`: Invalid op ID:`,e);i.s11n.serialize(...n),Atomics.store(i.sabOPView,i.opIds.rc,-1),Atomics.store(i.sabOPView,i.opIds.whichOp,r),Atomics.notify(i.sabOPView,i.opIds.whichOp);let a=performance.now();for(;Atomics.wait(i.sabOPView,i.opIds.rc,-1)!==`not-equal`;);let o=Atomics.load(i.sabOPView,i.opIds.rc);if(g[e].wait+=performance.now()-a,o&&i.asyncS11nExceptions){let t=i.s11n.deserialize();t&&d(e+`() async error:`,...t)}return o},y=Object.create(null);y.op=void 0,y.start=void 0;let b=m.mTimeStart=e=>{y.start=performance.now(),y.op=e,++g[e].count},x=m.mTimeEnd=()=>g[y.op].time+=performance.now()-y.start,S=m.__openFiles=Object.create(null);m.ioSyncWrappers=n.nu({xCheckReservedLock:function(e,t){return p.poke(t,0,`i32`),0},xClose:function(e){b(`xClose`);let t=0,n=S[e];return n&&(delete S[e],t=_(`xClose`,e),n.sq3File&&n.sq3File.dispose()),x(),t},xDeviceCharacteristics:function(e){return f.SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN},xFileControl:function(e,t,n){return f.SQLITE_NOTFOUND},xFileSize:function(e,t){b(`xFileSize`);let n=_(`xFileSize`,e);if(n==0)try{let e=i.s11n.deserialize()[0];p.poke(t,e,`i64`)}catch(e){d(`Unexpected error reading xFileSize() result:`,e),n=i.sq3Codes.SQLITE_IOERR}return x(),n},xRead:function(e,t,n,r){b(`xRead`);let i=S[e],a;try{a=_(`xRead`,e,n,Number(r)),(a===0||f.SQLITE_IOERR_SHORT_READ===a)&&p.heap8u().set(i.sabView.subarray(0,n),Number(t))}catch(e){d(`xRead(`,arguments,`) failed:`,e,i),a=f.SQLITE_IOERR_READ}return x(),a},xSync:function(e,t){b(`xSync`);let n=_(`xSync`,e,t);return x(),n},xTruncate:function(e,t){b(`xTruncate`);let n=_(`xTruncate`,e,Number(t));return x(),n},xWrite:function(e,t,n,r){b(`xWrite`);let i=S[e],a;try{i.sabView.set(p.heap8u().subarray(Number(t),Number(t)+n)),a=_(`xWrite`,e,n,Number(r))}catch(e){d(`xWrite(`,arguments,`) failed:`,e,i),a=f.SQLITE_IOERR_WRITE}return x(),a}}),m.vfsSyncWrappers={xAccess:function(e,t,n,r){b(`xAccess`);let i=_(`xAccess`,p.cstrToJs(t));return p.poke(r,i?0:1,`i32`),x(),0},xCurrentTime:function(e,t){return p.poke(t,2440587.5+new Date().getTime()/864e5,`double`),0},xCurrentTimeInt64:function(e,t){return p.poke(t,0xbfc83e532200+new Date().getTime(),`i64`),0},xDelete:function(e,t,n){b(`xDelete`);let r=_(`xDelete`,p.cstrToJs(t),n,!1);return x(),r},xFullPathname:function(e,t,n,r){return p.cstrncpy(r,t,n)<n?0:f.SQLITE_CANTOPEN},xGetLastError:function(t,n,r){return e.config.warn(`OPFS xGetLastError() has nothing sensible to return.`),0},xOpen:function(t,a,o,s,c){b(`xOpen`);let l=0,u,d;if(!a)u=r.randomFilename(),a=d=p.allocCString(u);else if(p.isPtr(a))f.sqlite3_uri_boolean(a,`opfs-unlock-asap`,0)&&(l|=i.opfsFlags.OPFS_UNLOCK_ASAP),f.sqlite3_uri_boolean(a,`delete-before-open`,0)&&(l|=i.opfsFlags.OPFS_UNLINK_BEFORE_OPEN),u=p.cstrToJs(a);else return e.config.error(`Impossible zName value in xOpen?`,a),f.SQLITE_CANTOPEN;let m=n.nu({fid:o,filename:u,sab:new SharedArrayBuffer(i.fileBufferSize),flags:s,readOnly:!(f.SQLITE_OPEN_CREATE&s)&&!!(s&f.SQLITE_OPEN_READONLY)}),g=_(`xOpen`,o,u,s,l);return g?d&&p.dealloc(d):(m.readOnly&&p.poke(c,f.SQLITE_OPEN_READONLY,`i32`),S[o]=m,m.sabView=i.sabFileBufView,m.sq3File=new f.sqlite3_file(o),d&&m.sq3File.addOnDispose(d),m.sq3File.$pMethods=h.pointer,m.lockType=f.SQLITE_LOCK_NONE),x(),g}};let C=f.sqlite3_vfs_find(null);if(C){let e=new f.sqlite3_vfs(C);m.$xRandomness=e.$xRandomness,m.$xSleep=e.$xSleep,e.dispose()}return m.$xRandomness||(m.vfsSyncWrappers.xRandomness=function(e,t,n){let r=p.heap8u(),i=0,a=Number(n);for(;i<t;++i)r[a+i]=Math.random()*255e3&255;return i}),m.$xSleep||(m.vfsSyncWrappers.xSleep=function(e,t){return b(`xSleep`),Atomics.wait(i.sabOPView,i.opIds.xSleep,0,t),x(),0}),m.initS11n=function(){if(i.s11n)return i.s11n;let e=new TextDecoder,n=new TextEncoder(`utf-8`),r=new Uint8Array(i.sabIO,i.sabS11nOffset,i.sabS11nSize),a=new DataView(i.sabIO,i.sabS11nOffset,i.sabS11nSize);i.s11n=Object.create(null);let o=Object.create(null);o.number={id:1,size:8,getter:`getFloat64`,setter:`setFloat64`},o.bigint={id:2,size:8,getter:`getBigInt64`,setter:`setBigInt64`},o.boolean={id:3,size:4,getter:`getInt32`,setter:`setInt32`},o.string={id:4};let s=e=>o[typeof e]||t(`Maintenance required: this value type cannot be serialized.`,e),c=e=>{switch(e){case o.number.id:return o.number;case o.bigint.id:return o.bigint;case o.boolean.id:return o.boolean;case o.string.id:return o.string;default:t(`Invalid type ID:`,e)}};return i.s11n.deserialize=function(t=!1){performance.now();let n=r[0],o=n?[]:null;if(n){let t=[],s=1,l,u,d;for(l=0;l<n;++l,++s)t.push(c(r[s]));for(l=0;l<n;++l){let n=t[l];n.getter?(d=a[n.getter](s,i.littleEndian),s+=n.size):(u=a.getInt32(s,i.littleEndian),s+=4,d=e.decode(r.slice(s,s+u)),s+=u),o.push(d)}}return t&&(r[0]=0),o},i.s11n.serialize=function(...e){if(performance.now(),e.length){let t=[],o=0,c=1;for(r[0]=e.length&255;o<e.length;++o,++c)t.push(s(e[o])),r[c]=t[o].id;for(o=0;o<e.length;++o){let s=t[o];if(s.setter)a[s.setter](c,e[o],i.littleEndian),c+=s.size;else{let t=n.encode(e[o]);a.setInt32(c,t.byteLength,i.littleEndian),c+=4,r.set(t,c),c+=t.byteLength}}}else r[0]=0},i.s11n},m.bindVfs=function(a,o){return Object.assign(m.ioSyncWrappers,a),new Promise(function(a,c){let h,g=e=>(h=!0,m.dispose(),c(e)),_=()=>{try{o(e,m)}catch(e){return g(e)}return h=!1,a(e)},y=r.options,b=m.worker=(()=>{let e=new URL(`/assets/sqlite3-opfs-async-proxy-Ck-yCayi.js`,``+import.meta.url);return e.searchParams.set(`vfs`,s),new Worker(e.toString())})(),x=setTimeout(()=>{h===void 0&&g(Error(`Timeout while waiting for OPFS async proxy worker.`))},4e3);b._originalOnError=b.onerror,b.onerror=function(e){d(`Error initializing OPFS asyncer:`,e),g(Error(`Loading OPFS async Worker failed for unknown reasons.`))},m.opRun;let S=function(){let e=p.scopedAllocPush(),n=new f.sqlite3_file;try{let e=n.pointer,r=f.SQLITE_OPEN_CREATE|f.SQLITE_OPEN_READWRITE|f.SQLITE_OPEN_MAIN_DB,a=p.scopedAlloc(8),o=`/sanity/check/file`+randomFilename(8),s=p.scopedAllocCString(o),c;if(i.s11n.serialize(`This is ä string.`),c=i.s11n.deserialize(),l(`deserialize() says:`,c),c[0]!==`This is ä string.`&&t(`String d13n error.`),m.vfsSyncWrappers.xAccess(m.pointer,s,0,a),c=p.peek(a,`i32`),l(`xAccess(`,o,`) exists ?=`,c),c=m.vfsSyncWrappers.xOpen(m.pointer,s,e,r,a),l(`open rc =`,c,`state.sabOPView[xOpen] =`,i.sabOPView[i.opIds.xOpen]),c!==0){d(`open failed with code`,c);return}m.vfsSyncWrappers.xAccess(m.pointer,s,0,a),c=p.peek(a,`i32`),c||t(`xAccess() failed to detect file.`),c=m.ioSyncWrappers.xSync(n.pointer,0),c&&t(`sync failed w/ rc`,c),c=m.ioSyncWrappers.xTruncate(n.pointer,1024),c&&t(`truncate failed w/ rc`,c),p.poke(a,0,`i64`),c=m.ioSyncWrappers.xFileSize(n.pointer,a),c&&t(`xFileSize failed w/ rc`,c),l(`xFileSize says:`,p.peek(a,`i64`)),c=m.ioSyncWrappers.xWrite(n.pointer,s,10,1),c&&t(`xWrite() failed!`);let h=p.scopedAlloc(16);c=m.ioSyncWrappers.xRead(n.pointer,h,6,2),p.poke(h+6,0);let g=p.cstrToJs(h);l(`xRead() got:`,g),g!==`sanity`&&t(`Unexpected xRead() value.`),m.vfsSyncWrappers.xSleep&&(l(`xSleep()ing before close()ing...`),m.vfsSyncWrappers.xSleep(m.pointer,2e3),l(`waking up from xSleep()`)),c=m.ioSyncWrappers.xClose(e),l(`xClose rc =`,c,`sabOPView =`,i.sabOPView),l(`Deleting file:`,o),m.vfsSyncWrappers.xDelete(m.pointer,s,4660),m.vfsSyncWrappers.xAccess(m.pointer,s,0,a),c=p.peek(a,`i32`),c&&t(`Expecting 0 from xAccess(`,o,`) after xDelete().`),u(`End of OPFS sanity checks.`)}finally{n.dispose(),p.scopedAllocPop(e)}};b.onmessage=function({data:t}){switch(t.type){case`opfs-unavailable`:g(Error(t.payload.join(` `)));break;case`opfs-async-loaded`:delete i.vfs,b.postMessage({type:`opfs-async-init`,args:n.nu(i)});break;case`opfs-async-inited`:if(!0===h)break;clearTimeout(x),x=null;try{e.vfs.installVfs({io:{struct:m.ioMethods,methods:m.ioSyncWrappers},vfs:{struct:m,methods:m.vfsSyncWrappers}}),i.sabOPView=new Int32Array(i.sabOP),i.sabFileBufView=new Uint8Array(i.sabIO,0,i.fileBufferSize),i.sabS11nView=new Uint8Array(i.sabIO,i.sabS11nOffset,i.sabS11nSize),m.initS11n(),delete m.initS11n,y.sanityChecks&&(u(`Running sanity checks because of opfs-sanity-check URL arg...`),S()),r.thisThreadHasOPFS()?r.getRootDir().then(e=>{b.onerror=b._originalOnError,delete b._originalOnError,l(`End of OPFS sqlite3_vfs setup.`,m),_()}).catch(g):_()}catch(e){d(e),g(e)}break;case`debug`:u(`debug message from worker:`,t);break;default:{let e=`Unexpected message from the OPFS async worker: `+JSON.stringify(t);d(e),g(Error(e));break}}}})},i}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(!e.opfs||e.config.disable?.vfs?.opfs)return;let t=e.util,n=e.opfs||e.util.toss(`Missing sqlite3.opfs`),r=async function(r){if(r=n.initOptions(`opfs`,r),!r)return e;let i=e.capi,a=n.createVfsState().vfs,o=a.metrics.counters,s=a.mTimeStart,c=a.mTimeEnd,l=a.opRun,u=a.__openFiles;return a.bindVfs(t.nu({xLock:function(e,t){s(`xLock`),++o.xLock.count;let n=u[e],r=0;return n.lockType?n.lockType=t:(r=l(`xLock`,e,t),r===0&&(n.lockType=t)),c(),r},xUnlock:function(e,t){s(`xUnlock`),++o.xUnlock.count;let n=u[e],r=0;return i.SQLITE_LOCK_NONE===t&&n.lockType&&(r=l(`xUnlock`,e,t)),r===0&&(n.lockType=t),c(),r}}),function(e,t){if(e.oo1){let r=function(...n){let r=e.oo1.DB.dbCtorHelper.normalizeArgs(...n);r.vfs=t.$zName,e.oo1.DB.dbCtorHelper.call(this,r)};r.prototype=Object.create(e.oo1.DB.prototype),e.oo1.OpfsDb=r,r.importDb=n.importDb,e.oo1.DB.dbCtorHelper.setVfsPostOpenCallback(a.pointer,function(e,t){t.capi.sqlite3_busy_timeout(e,1e4)})}})};globalThis.sqlite3ApiBootstrap.initializersAsync.push(async e=>r().catch(t=>{e.config.warn(`Ignoring inability to install 'opfs' sqlite3_vfs:`,t)}))}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(e.config.disable?.vfs?.[`opfs-sahpool`])return;let t=e.util.toss,n=e.util.toss3,r=Object.create(null),i=e.capi,a=e.util,o=e.wasm,s=4096,c=s,l=i.SQLITE_OPEN_MAIN_DB|i.SQLITE_OPEN_MAIN_JOURNAL|i.SQLITE_OPEN_SUPER_JOURNAL|i.SQLITE_OPEN_WAL,u=i.SQLITE_OPEN_MEMORY,d=`.opaque`,f=()=>Math.random().toString(36).slice(2),p=new TextDecoder,m=new TextEncoder,h=Object.assign(Object.create(null),{name:`opfs-sahpool`,directory:void 0,initialCapacity:6,clearOnInit:!1,verbosity:2,forceReinitIfPreviouslyFailed:!1}),g=[e.config.error,e.config.warn,e.config.log];e.config.log;let _=e.config.warn;e.config.error;let y=new Map,b=e=>y.get(e),x=(e,t)=>{t?y.set(e,t):y.delete(e)},S=new Map,C=e=>S.get(e),w=(e,t)=>{t?S.set(e,t):S.delete(e)},T={xCheckReservedLock:function(e,t){let n=C(e);return n.log(`xCheckReservedLock`),n.storeErr(),o.poke32(t,1),0},xClose:function(e){let t=C(e);t.storeErr();let n=t.getOFileForS3File(e);if(n)try{t.log(`xClose ${n.path}`),t.mapS3FileToOFile(e,!1),n.sah.flush(),n.flags&i.SQLITE_OPEN_DELETEONCLOSE&&t.deletePath(n.path)}catch(e){return t.storeErr(e,i.SQLITE_IOERR)}return 0},xDeviceCharacteristics:function(e){return i.SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN},xFileControl:function(e,t,n){return i.SQLITE_NOTFOUND},xFileSize:function(e,t){let n=C(e);n.log(`xFileSize`);let r=n.getOFileForS3File(e).sah.getSize()-c;return o.poke64(t,BigInt(r)),0},xLock:function(e,t){let n=C(e);n.log(`xLock ${t}`),n.storeErr();let r=n.getOFileForS3File(e);return r.lockType=t,0},xRead:function(e,t,n,r){let a=C(e);a.storeErr();let s=a.getOFileForS3File(e);a.log(`xRead ${s.path} ${n} @ ${r}`);try{let e=s.sah.read(o.heap8u().subarray(Number(t),Number(t)+n),{at:c+Number(r)});return e<n?(o.heap8u().fill(0,Number(t)+e,Number(t)+n),i.SQLITE_IOERR_SHORT_READ):0}catch(e){return a.storeErr(e,i.SQLITE_IOERR)}},xSectorSize:function(e){return s},xSync:function(e,t){let n=C(e);n.log(`xSync ${t}`),n.storeErr();let r=n.getOFileForS3File(e);try{return r.sah.flush(),0}catch(e){return n.storeErr(e,i.SQLITE_IOERR)}},xTruncate:function(e,t){let n=C(e);n.log(`xTruncate ${t}`),n.storeErr();let r=n.getOFileForS3File(e);try{return r.sah.truncate(c+Number(t)),0}catch(e){return n.storeErr(e,i.SQLITE_IOERR)}},xUnlock:function(e,t){let n=C(e);n.log(`xUnlock`);let r=n.getOFileForS3File(e);return r.lockType=t,0},xWrite:function(e,n,r,a){let s=C(e);s.storeErr();let l=s.getOFileForS3File(e);s.log(`xWrite ${l.path} ${r} ${a}`);try{return r===l.sah.write(o.heap8u().subarray(Number(n),Number(n)+r),{at:c+Number(a)})?0:t(`Unknown write() failure.`)}catch(e){return s.storeErr(e,i.SQLITE_IOERR)}}},E=new i.sqlite3_io_methods;E.$iVersion=1,e.vfs.installVfs({io:{struct:E,methods:T}});let D={xAccess:function(e,t,n,r){let i=b(e);i.storeErr();try{let e=i.getPath(t);o.poke32(r,i.hasFilename(e)?1:0)}catch{o.poke32(r,0)}return 0},xCurrentTime:function(e,t){return o.poke(t,2440587.5+new Date().getTime()/864e5,`double`),0},xCurrentTimeInt64:function(e,t){return o.poke(t,0xbfc83e532200+new Date().getTime(),`i64`),0},xDelete:function(e,t,n){let r=b(e);r.log(`xDelete ${o.cstrToJs(t)}`),r.storeErr();try{return r.deletePath(r.getPath(t)),0}catch(e){return r.storeErr(e),i.SQLITE_IOERR_DELETE}},xFullPathname:function(e,t,n,r){return o.cstrncpy(r,t,n)<n?0:i.SQLITE_CANTOPEN},xGetLastError:function(e,t,n){let r=b(e),a=r.popErr();if(r.log(`xGetLastError ${t} e =`,a),a){let e=o.scopedAllocPush();try{let[e,r]=o.scopedAllocCString(a.message,!0);o.cstrncpy(n,e,t),r>t&&o.poke8(o.ptr.add(n,t,-1),0)}catch{return i.SQLITE_NOMEM}finally{o.scopedAllocPop(e)}}return a?a.sqlite3Rc||i.SQLITE_IOERR:0},xOpen:function(e,n,r,a,s){let c=b(e);try{a&=~u,c.log(`xOpen ${o.cstrToJs(n)} ${a}`);let e=n&&o.peek8(n)?c.getPath(n):f(),l=c.getSAHForPath(e);!l&&a&i.SQLITE_OPEN_CREATE&&(c.getFileCount()<c.getCapacity()?(l=c.nextAvailableSAH(),c.setAssociatedPath(l,e,a)):t(`SAH pool is full. Cannot create file`,e)),l||t(`file not found:`,e);let d={path:e,flags:a,sah:l};c.mapS3FileToOFile(r,d),d.lockType=i.SQLITE_LOCK_NONE;let p=new i.sqlite3_file(r);return p.$pMethods=E.pointer,p.dispose(),o.poke32(s,a),0}catch(e){return c.storeErr(e),i.SQLITE_CANTOPEN}}},O=function(t){e.capi.sqlite3_vfs_find(t)&&n(`VFS name is already registered:`,t);let r=new i.sqlite3_vfs,a=i.sqlite3_vfs_find(null),s=a?new i.sqlite3_vfs(a):null;return r.$iVersion=2,r.$szOsFile=i.sqlite3_file.structInfo.sizeof,r.$mxPathname=512,r.addOnDispose(r.$zName=o.allocCString(t),()=>x(r.pointer,0)),s&&(r.$xRandomness=s.$xRandomness,r.$xSleep=s.$xSleep,s.dispose()),!r.$xRandomness&&!D.xRandomness&&(D.xRandomness=function(e,t,n){let r=o.heap8u(),i=0,a=Number(n);for(;i<t;++i)r[a+i]=Math.random()*255e3&255;return i}),!r.$xSleep&&!D.xSleep&&(D.xSleep=(e,t)=>0),e.vfs.installVfs({vfs:{struct:r,methods:D}}),r};class A{vfsDir;#e;#t;#n;#r=new Map;#i=new Map;#a=new Set;#o=new Map;#s=new Uint8Array(516);#c;#l;#u;constructor(e=Object.create(null)){this.#u=e.verbosity??h.verbosity,this.vfsName=e.name||h.name,this.#l=O(this.vfsName),x(this.#l.pointer,this),this.vfsDir=e.directory||`.`+this.vfsName,this.#c=new DataView(this.#s.buffer,this.#s.byteOffset),this.isReady=this.reset(!!(e.clearOnInit??h.clearOnInit)).then(()=>{if(this.$error)throw this.$error;return this.getCapacity()?Promise.resolve(void 0):this.addCapacity(e.initialCapacity||h.initialCapacity)})}#d(e,...t){this.#u>e&&g[e](this.vfsName+`:`,...t)}log(...e){this.#d(2,...e)}warn(...e){this.#d(1,...e)}error(...e){this.#d(0,...e)}getVfs(){return this.#l}getCapacity(){return this.#r.size}getFileCount(){return this.#i.size}getFileNames(){let e=[];for(let t of this.#i.keys())e.push(t);return e}async addCapacity(e){for(let t=0;t<e;++t){let e=f(),t=await(await this.#t.getFileHandle(e,{create:!0})).createSyncAccessHandle();this.#r.set(t,e),this.setAssociatedPath(t,``,0)}return this.getCapacity()}async reduceCapacity(e){let t=0;for(let n of Array.from(this.#a)){if(t===e||this.getFileCount()===this.getCapacity())break;let r=this.#r.get(n);n.close(),await this.#t.removeEntry(r),this.#r.delete(n),this.#a.delete(n),++t}return t}releaseAccessHandles(){for(let e of this.#r.keys())e.close();this.#r.clear(),this.#i.clear(),this.#a.clear()}async acquireAccessHandles(e=!1){let t=[];for await(let[e,n]of this.#t)n.kind===`file`&&t.push([e,n]);return Promise.all(t.map(async([t,n])=>{try{let r=await n.createSyncAccessHandle();if(this.#r.set(r,t),e)r.truncate(c),this.setAssociatedPath(r,``,0);else{let e=this.getAssociatedPath(r);e?this.#i.set(e,r):this.#a.add(r)}}catch(e){throw this.storeErr(e),this.releaseAccessHandles(),e}}))}getAssociatedPath(e){e.read(this.#s,{at:0});let t=this.#c.getUint32(512);if(this.#s[0]&&(t&i.SQLITE_OPEN_DELETEONCLOSE||(t&l)===0))return _(`Removing file with unexpected flags ${t.toString(16)}`,this.#s),this.setAssociatedPath(e,``,0),``;let n=new Uint32Array(8/4);e.read(n,{at:516});let r=this.computeDigest(this.#s,t);if(n.every((e,t)=>e===r[t])){let t=this.#s.findIndex(e=>e===0);return t===0&&e.truncate(c),t?p.decode(this.#s.subarray(0,t)):``}else return _(`Disassociating file with bad digest.`),this.setAssociatedPath(e,``,0),``}setAssociatedPath(e,n,r){let i=m.encodeInto(n,this.#s);512<=i.written+1&&t(`Path too long:`,n),n&&r&&(r|=u),this.#s.fill(0,i.written,512),this.#c.setUint32(512,r);let a=this.computeDigest(this.#s,r);e.write(this.#s,{at:0}),e.write(a,{at:516}),e.flush(),n?(this.#i.set(n,e),this.#a.delete(e)):(e.truncate(c),this.#a.add(e))}computeDigest(e,t){if(t&u){let t=3735928559,n=1103547991;for(let r of e)t=Math.imul(t^r,2654435761),n=Math.imul(n^r,104729);return new Uint32Array([t>>>0,n>>>0])}else return new Uint32Array([0,0])}async reset(e){await this.isReady;let t=await navigator.storage.getDirectory(),n;for(let e of this.vfsDir.split(`/`))e&&(n=t,t=await t.getDirectoryHandle(e,{create:!0}));return this.#e=t,this.#n=n,this.#t=await this.#e.getDirectoryHandle(d,{create:!0}),this.releaseAccessHandles(),this.acquireAccessHandles(e)}getPath(e){return o.isPtr(e)&&(e=o.cstrToJs(e)),(e instanceof URL?e:new URL(e,`file://localhost/`)).pathname}deletePath(e){let t=this.#i.get(e);return t&&(this.#i.delete(e),this.setAssociatedPath(t,``,0)),!!t}storeErr(e,t){return e&&(e.sqlite3Rc=t||i.SQLITE_IOERR,this.error(e)),this.$error=e,t}popErr(){let e=this.$error;return this.$error=void 0,e}nextAvailableSAH(){let[e]=this.#a.keys();return e}getOFileForS3File(e){return this.#o.get(e)}mapS3FileToOFile(e,t){t?(this.#o.set(e,t),w(e,this)):(this.#o.delete(e),w(e,!1))}hasFilename(e){return this.#i.has(e)}getSAHForPath(e){return this.#i.get(e)}async removeVfs(){if(!this.#l.pointer||!this.#t)return!1;i.sqlite3_vfs_unregister(this.#l.pointer),this.#l.dispose(),delete r[this.vfsName];try{this.releaseAccessHandles(),await this.#e.removeEntry(d,{recursive:!0}),this.#t=void 0,await this.#n.removeEntry(this.#e.name,{recursive:!0}),this.#e=this.#n=void 0}catch(t){e.config.error(this.vfsName,`removeVfs() failed with no recovery strategy:`,t)}return!0}pauseVfs(){return this.#o.size>0&&e.SQLite3Error.toss(i.SQLITE_MISUSE,`Cannot pause VFS`,this.vfsName,`because it has opened files.`),this.#r.size>0&&(i.sqlite3_vfs_unregister(this.vfsName),this.releaseAccessHandles()),this}isPaused(){return this.#r.size===0}async unpauseVfs(){return this.#r.size===0?this.acquireAccessHandles(!1).then(()=>i.sqlite3_vfs_register(this.#l,0),this):this}
39
+ //! Documented elsewhere in this file.
40
+ exportFile(e){let n=this.#i.get(e)||t(`File not found:`,e),r=n.getSize()-c,i=new Uint8Array(r>0?r:0);if(r>0){let e=n.read(i,{at:c});e!=r&&t(`Expected to read `+r+` bytes but read `+e+`.`)}return i}
41
+ //! Impl for importDb() when its 2nd arg is a function.
42
+ async importDbChunked(e,n){let r=this.#i.get(e)||this.nextAvailableSAH()||t(`No available handles to import to.`);r.truncate(0);let o=0,s,l=!1;try{for(;(s=await n())!==void 0;)s instanceof ArrayBuffer&&(s=new Uint8Array(s)),!l&&o===0&&s.byteLength>=15&&(a.affirmDbHeader(s),l=!0),r.write(s,{at:c+o}),o+=s.byteLength;if((o<512||o%512!=0)&&t(`Input size`,o,`is not correct for an SQLite database.`),!l){let e=new Uint8Array(20);r.read(e,{at:0}),a.affirmDbHeader(e)}r.write(new Uint8Array([1,1]),{at:4114})}catch(e){throw this.setAssociatedPath(r,``,0),e}return this.setAssociatedPath(r,e,i.SQLITE_OPEN_MAIN_DB),o}
43
+ //! Documented elsewhere in this file.
44
+ importDb(e,n){if(n instanceof ArrayBuffer)n=new Uint8Array(n);else if(n instanceof Function)return this.importDbChunked(e,n);let r=this.#i.get(e)||this.nextAvailableSAH()||t(`No available handles to import to.`),a=n.byteLength;(a<512||a%512!=0)&&t(`Byte array size is invalid for an SQLite db.`);for(let e=0;e<15;++e)`SQLite format 3`.charCodeAt(e)!==n[e]&&t(`Input does not contain an SQLite database header.`);let o=r.write(n,{at:c});return o==a?(r.write(new Uint8Array([1,1]),{at:4114}),this.setAssociatedPath(r,e,i.SQLITE_OPEN_MAIN_DB)):(this.setAssociatedPath(r,``,0),t(`Expected to write `+a+` bytes but wrote `+o+`.`)),o}}class j{#e;constructor(e){this.#e=e,this.vfsName=e.vfsName}async addCapacity(e){return this.#e.addCapacity(e)}async reduceCapacity(e){return this.#e.reduceCapacity(e)}getCapacity(){return this.#e.getCapacity(this.#e)}getFileCount(){return this.#e.getFileCount()}getFileNames(){return this.#e.getFileNames()}async reserveMinimumCapacity(e){let t=this.#e.getCapacity();return t<e?this.#e.addCapacity(e-t):t}exportFile(e){return this.#e.exportFile(e)}importDb(e,t){return this.#e.importDb(e,t)}async wipeFiles(){return this.#e.reset(!0)}unlink(e){return this.#e.deletePath(e)}async removeVfs(){return this.#e.removeVfs()}pauseVfs(){return this.#e.pauseVfs(),this}async unpauseVfs(){return this.#e.unpauseVfs().then(()=>this)}isPaused(){return this.#e.isPaused()}}let ee=async()=>{let e=await navigator.storage.getDirectory(),n=`.opfs-sahpool-sync-check-`+f(),r=(await(await e.getFileHandle(n,{create:!0})).createSyncAccessHandle()).close();return await r,await e.removeEntry(n),r?.then&&t(`The local OPFS API is too old for opfs-sahpool:`,`it has an async FileSystemSyncAccessHandle.close() method.`),!0};e.installOpfsSAHPoolVfs=async function(t=Object.create(null)){t=Object.assign(Object.create(null),h,t||{});let n=t.name;if(t.$testThrowPhase1)throw t.$testThrowPhase1;if(r[n])try{return await r[n]}catch(e){if(t.forceReinitIfPreviouslyFailed)delete r[n];else throw e}return!globalThis.FileSystemHandle||!globalThis.FileSystemDirectoryHandle||!globalThis.FileSystemFileHandle||!globalThis.FileSystemFileHandle.prototype.createSyncAccessHandle||!navigator?.storage?.getDirectory?r[n]=Promise.reject(Error(`Missing required OPFS APIs.`)):r[n]=ee().then(async function(){if(t.$testThrowPhase2)throw t.$testThrowPhase2;let n=new A(t);return n.isReady.then(async()=>{let t=new j(n);if(e.oo1){let r=e.oo1,i=n.getVfs(),a=function(...e){let t=r.DB.dbCtorHelper.normalizeArgs(...e);t.vfs=i.$zName,r.DB.dbCtorHelper.call(this,t)};a.prototype=Object.create(r.DB.prototype),t.OpfsSAHPoolDb=a}return n.log(`VFS initialized.`),t}).catch(async e=>{throw await n.removeVfs().catch(()=>{}),e})}).catch(e=>r[n]=Promise.reject(e))}}),globalThis.sqlite3ApiBootstrap.initializers.push(function(e){if(!e.opfs||e.config.disable?.vfs?.[`opfs-wl`])return;let t=e.util;e.util.toss;let n=e.opfs,r=`opfs-wl`,i=async function(i){if(i=n.initOptions(r,i),!i)return e;e.capi;let a=n.createVfsState().vfs;a.metrics.counters;let o=a.mTimeStart,s=a.mTimeEnd,c=a.opRun,l=a.__openFiles;return a.bindVfs(t.nu({xLock:function(e,t){o(`xLock`);let n=l[e],r=c(`xLock`,e,t);return r||(n.lockType=t),s(),r},xUnlock:function(e,t){o(`xUnlock`);let n=l[e],r=c(`xUnlock`,e,t);return r||(n.lockType=t),s(),r}}),function(e,t){if(e.oo1){let r=function(...n){let r=e.oo1.DB.dbCtorHelper.normalizeArgs(...n);r.vfs=t.$zName,e.oo1.DB.dbCtorHelper.call(this,r)};r.prototype=Object.create(e.oo1.DB.prototype),e.oo1.OpfsWlDb=r,r.importDb=n.importDb}})};globalThis.sqlite3ApiBootstrap.initializersAsync.push(async e=>i().catch(t=>{e.config.warn(`Ignoring inability to install the`,r,`sqlite3_vfs:`,t)}))});try{let n=Object.assign(Object.create(null),{memory:U===void 0?t.wasmMemory:U,exports:Ft===void 0?Object.prototype.hasOwnProperty.call(t,`wasmExports`)?t.wasmExports:t.asm:Ft},globalThis.sqlite3ApiBootstrap.defaultConfig,globalThis.sqlite3ApiConfig||{});e.debugModule(`Bootstrapping lib config`,n);let r=globalThis.sqlite3ApiBootstrap(n);return delete globalThis.sqlite3ApiBootstrap,r}catch(e){throw console.error(`sqlite3ApiBootstrap() error:`,e),e}},t=_?n:new Promise((e,t)=>{h=e,g=t}),t}e=(function(){let t=e;if(!t)throw Error(`Expecting sqlite3InitModule to be defined by the Emscripten build.`);let n=globalThis.sqlite3InitModuleState=Object.assign(Object.create(null),{moduleScript:globalThis?.document?.currentScript,isWorker:typeof WorkerGlobalScope<`u`,location:globalThis.location,urlParams:globalThis?.location?.href?new URL(globalThis.location.href).searchParams:new URLSearchParams,wasmFilename:`sqlite3.wasm`});if(n.debugModule=n.urlParams.has(`sqlite3.debugModule`)?(...e)=>console.warn(`sqlite3.debugModule:`,...e):()=>{},n.urlParams.has(`sqlite3.dir`))n.sqlite3Dir=n.urlParams.get(`sqlite3.dir`)+`/`;else if(n.moduleScript){let e=n.moduleScript.src.split(`/`);e.pop(),n.sqlite3Dir=e.join(`/`)+`/`}let r=globalThis.sqlite3InitModule=function e(...r){return n.emscriptenLocateFile=r[0]?.locateFile,n.emscriptenInstantiateWasm=r[0]?.instantiateWasm,t(...r).then(t=>{n.debugModule(`sqlite3InitModule() sIMS =`,n),n.debugModule(`sqlite3InitModule() EmscriptenModule =`,t);let r=t.runSQLite3PostLoadInit(n,t,!!e.__isUnderTest);return n.debugModule(`sqlite3InitModule() sqlite3 =`,r),r}).catch(e=>{throw console.error(`Exception loading sqlite3 module:`,e),e})};if(r.ready=t.ready,n.moduleScript){let e=n.moduleScript.src.split(`/`);e.pop(),n.scriptDir=e.join(`/`)+`/`}return n.debugModule(`extern-post-js.c-pp.js sqlite3InitModuleState =`,n),r})();var t=e;globalThis.sqlite3Worker1Promiser=function e(t=e.defaultConfig){if(arguments.length===1&&typeof arguments[0]==`function`){let n=t;t=Object.assign(Object.create(null),e.defaultConfig),t.onready=n}else t=Object.assign(Object.create(null),e.defaultConfig,t);let n=Object.create(null),r=function(){},i=t.onerror||r,a=t.debug||r,o=t.generateMessageId?void 0:Object.create(null),s=t.generateMessageId||function(e){return e.type+`#`+(o[e.type]=(o[e.type]||0)+1)},c=(...e)=>{throw Error(e.join(` `))};t.worker||=e.defaultConfig.worker,typeof t.worker==`function`&&(t.worker=t.worker());let l,u;return t.worker.onmessage=function(e){e=e.data,a(`worker1.onmessage`,e);let r=n[e.messageId];if(!r){if(e&&e.type===`sqlite3-api`&&e.result===`worker1-ready`){t.onready&&t.onready(u);return}if(r=n[e.type],r&&r.onrow){r.onrow(e);return}t.onunhandled?t.onunhandled(arguments[0]):i(`sqlite3Worker1Promiser() unhandled worker message:`,e);return}switch(delete n[e.messageId],e.type){case`error`:r.reject(e);return;case`open`:l||=e.dbId;break;case`close`:e.dbId===l&&(l=void 0)}try{r.resolve(e)}catch(e){r.reject(e)}},u=function(){let e;arguments.length===1?e=arguments[0]:arguments.length===2?(e=Object.create(null),e.type=arguments[0],e.args=arguments[1],e.dbId=e.args.dbId):c(`Invalid arguments for sqlite3Worker1Promiser()-created factory.`),!e.dbId&&e.type!==`open`&&(e.dbId=l),e.messageId=s(e),e.departureTime=performance.now();let r=Object.create(null);r.message=e;let i;e.type===`exec`&&e.args&&(typeof e.args.callback==`function`?(i=e.messageId+`:row`,r.onrow=e.args.callback,e.args.callback=i,n[i]=r):typeof e.args.callback==`string`&&c(`exec callback may not be a string when using the Promise interface.`));let o=new Promise(function(i,o){r.resolve=i,r.reject=o,n[e.messageId]=r,a(`Posting`,e.type,`message to Worker dbId=`+(l||`default`)+`:`,e),t.worker.postMessage(e)});return i&&(o=o.finally(()=>delete n[i])),o}},globalThis.sqlite3Worker1Promiser.defaultConfig={worker:function(){return new Worker(new URL(`/assets/sqlite3-worker1-DZ2OAEkd.js`,``+import.meta.url),{type:`module`})},onerror:(...e)=>console.error(`sqlite3Worker1Promiser():`,...e)},globalThis.sqlite3Worker1Promiser.v2=function e(t=e.defaultConfig){let n;typeof t==`function`?(n=t,t={}):typeof t?.onready==`function`&&(n=t.onready,delete t.onready);let r=Object.create(null);t=Object.assign(t||Object.create(null),{onready:async function(e){try{n&&await n(e),r.resolve(e)}catch(e){r.reject(e)}}});let i=new Promise(function(e,t){r.resolve=e,r.reject=t});try{this.original(t)}catch(e){r.reject(e)}return i}.bind({original:sqlite3Worker1Promiser}),globalThis.sqlite3Worker1Promiser.v2.defaultConfig=globalThis.sqlite3Worker1Promiser.defaultConfig,sqlite3Worker1Promiser.v2,delete globalThis.sqlite3Worker1Promiser;const n=t;let r=null,i=!1,a=null;function o(){if(!r)throw Error(`Database not initialized. Ensure initDatabase() is awaited.`);return r}function s(){return i}async function c(){return r?i:a||(a=(async()=>{try{let e=await n();if(e.oo1?.OpfsDb)try{r=new e.oo1.OpfsDb(`/obex_local_logs.sqlite3`,`c`),i=!0,console.log(`[SQLite Worker] Successfully opened OPFS persistent database via OpfsDb`)}catch(e){console.warn(`[SQLite Worker] OpfsDb initialization failed, trying OpfsSAHPool:`,e),r=null}if(!r&&typeof e.installOpfsSAHPoolVfs==`function`)try{r=new(await(e.installOpfsSAHPoolVfs({name:`obex-sahpool`,clearOnInit:!1,initialCapacity:10}))).OpfsSAHPoolDb(`/obex_local_logs.sqlite3`),i=!0,console.log(`[SQLite Worker] Successfully opened OPFS persistent database via OpfsSAHPool`)}catch(e){console.warn(`[SQLite Worker] OpfsSAHPool initialization failed:`,e),r=null}if(!r&&e.oo1?.DB&&(console.warn(`[SQLite Worker] OPFS persistence unavailable (incognito/restricted mode), falling back to in-memory SQLite`),r=new e.oo1.DB(`/obex_local_logs_mem.sqlite3`,`c`),i=!1),!r)throw Error(`Failed to instantiate any SQLite storage driver (OpfsDb, OpfsSAHPool, or In-Memory).`);r.exec(`
45
+ PRAGMA synchronous = NORMAL;
46
+
47
+ CREATE TABLE IF NOT EXISTS local_logs (
48
+ profile_id TEXT NOT NULL,
49
+ timestamp INTEGER NOT NULL,
50
+ id INTEGER NOT NULL,
51
+ domain TEXT NOT NULL,
52
+ record_type TEXT NOT NULL,
53
+ action TEXT NOT NULL,
54
+ reason TEXT,
55
+ client_ip TEXT NOT NULL,
56
+ geo_country TEXT,
57
+ answer TEXT,
58
+ dest_geoip TEXT,
59
+ ecs TEXT,
60
+ upstream TEXT,
61
+ latency INTEGER,
62
+ access_point_id TEXT,
63
+ access_point_name TEXT,
64
+ dest_country_code TEXT,
65
+ dest_country TEXT,
66
+ dest_isp TEXT,
67
+ encrypt_version INTEGER DEFAULT 0,
68
+ kem_key_id TEXT,
69
+ kem_ct TEXT,
70
+ encrypted_payload TEXT,
71
+ PRIMARY KEY (profile_id, timestamp, id)
72
+ );
73
+
74
+ CREATE INDEX IF NOT EXISTS idx_local_logs_time ON local_logs (profile_id, timestamp DESC);
75
+ CREATE INDEX IF NOT EXISTS idx_local_logs_domain ON local_logs (profile_id, domain);
76
+ CREATE INDEX IF NOT EXISTS idx_local_logs_action ON local_logs (profile_id, action);
77
+ CREATE INDEX IF NOT EXISTS idx_local_logs_client ON local_logs (profile_id, client_ip);
78
+
79
+ CREATE TABLE IF NOT EXISTS sync_watermarks (
80
+ profile_id TEXT PRIMARY KEY,
81
+ latest_timestamp INTEGER NOT NULL,
82
+ earliest_timestamp INTEGER NOT NULL,
83
+ last_synced_at INTEGER NOT NULL,
84
+ total_synced_count INTEGER DEFAULT 0
85
+ );
86
+
87
+ CREATE TABLE IF NOT EXISTS local_settings (
88
+ key TEXT PRIMARY KEY,
89
+ value TEXT NOT NULL
90
+ );
91
+ `);try{r.exec(`ALTER TABLE local_logs ADD COLUMN access_point_name TEXT;`)}catch{}try{r.exec(`ALTER TABLE local_logs ADD COLUMN encrypt_version INTEGER DEFAULT 0;`)}catch{}try{r.exec(`ALTER TABLE local_logs ADD COLUMN kem_key_id TEXT;`)}catch{}try{r.exec(`ALTER TABLE local_logs ADD COLUMN kem_ct TEXT;`)}catch{}try{r.exec(`UPDATE local_logs SET encrypt_version = 1 WHERE is_encrypted = 1;`)}catch{}try{let e=r.selectObject(`SELECT count(*) as count FROM local_logs WHERE client_ip = '' OR client_ip IS NULL;`);e&&Number(e.count)>0&&(console.log(`[SQLite Worker] Cleaning ${e.count} stale logs with empty client_ip for clean resync`),r.exec(`DELETE FROM local_logs WHERE client_ip = '' OR client_ip IS NULL; DELETE FROM sync_watermarks;`))}catch(e){console.warn(`[SQLite Worker] Clean stale logs check skipped:`,e)}return i}catch(e){throw console.error(`[SQLite Worker] Fatal initialization error:`,e),e}})(),a)}function l(e){let t=o(),{profileId:n,logs:r}=e;if(!r||r.length===0)return{inserted:0};let i=0,a=1/0,s=-1/0;t.exec(`BEGIN TRANSACTION;`);try{let e=t.prepare(`
92
+ INSERT OR REPLACE INTO local_logs (
93
+ profile_id, timestamp, id, domain, record_type, action, reason,
94
+ client_ip, geo_country, answer, dest_geoip, ecs, upstream, latency,
95
+ access_point_id, access_point_name, dest_country_code, dest_country, dest_isp,
96
+ encrypt_version, kem_key_id, kem_ct, encrypted_payload
97
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
98
+ `);try{for(let t of r)t.timestamp<a&&(a=t.timestamp),t.timestamp>s&&(s=t.timestamp),e.bind([n,t.timestamp,t.id!==void 0&&t.id!==null?t.id:t.timestamp*1e3+Math.floor(Math.random()*1e3),t.domain||``,t.record_type||`A`,t.action||`PASS`,t.reason||null,t.client_ip||``,t.geo_country||null,t.answer||null,t.dest_geoip||null,t.ecs||null,t.upstream||null,t.latency===void 0?null:t.latency,t.access_point_id||null,t.access_point_name||null,t.dest_country_code||null,t.dest_country||null,t.dest_isp||null,t.encrypt_version??0,t.kem_key_id||null,t.kem_ct||null,t.encrypted_payload||null]),e.step(),e.reset(),i++}finally{e.finalize()}let o=Math.floor(Date.now()/1e3),c=t.selectObject(`SELECT latest_timestamp, earliest_timestamp, total_synced_count FROM sync_watermarks WHERE profile_id = ?;`,[n]);if(c&&c.latest_timestamp!==void 0&&c.earliest_timestamp!==void 0){let e=Math.max(Number(c.latest_timestamp),s),r=Math.min(Number(c.earliest_timestamp),a),l=Number(c.total_synced_count||0)+i;t.exec({sql:`
99
+ UPDATE sync_watermarks
100
+ SET latest_timestamp = ?, earliest_timestamp = ?, last_synced_at = ?, total_synced_count = ?
101
+ WHERE profile_id = ?;
102
+ `,bind:[e,r,o,l,n]})}else t.exec({sql:`
103
+ INSERT INTO sync_watermarks (profile_id, latest_timestamp, earliest_timestamp, last_synced_at, total_synced_count)
104
+ VALUES (?, ?, ?, ?, ?);
105
+ `,bind:[n,s,a,o,i]});return t.exec(`COMMIT;`),{inserted:i}}catch(e){throw t.exec(`ROLLBACK;`),e}}function u(e){return o().selectObject(`SELECT latest_timestamp, earliest_timestamp, last_synced_at, total_synced_count FROM sync_watermarks WHERE profile_id = ?;`,[e.profileId])||null}function d(e){let t=o(),{profileId:n,logs:r}=e;if(!r||r.length===0)return{updated:0};t.exec(`BEGIN TRANSACTION;`);try{let e=t.prepare(`
106
+ UPDATE local_logs SET
107
+ domain = ?, client_ip = ?, geo_country = ?, answer = ?,
108
+ dest_geoip = ?, dest_country_code = ?, dest_country = ?, dest_isp = ?,
109
+ ecs = ?, upstream = ?, reason = ?, encrypt_version = 0, encrypted_payload = NULL
110
+ WHERE profile_id = ? AND timestamp = ? AND id = ?;
111
+ `);try{for(let t of r)e.bind([t.domain||``,t.client_ip||``,t.geo_country||null,t.answer||null,t.dest_geoip||null,t.dest_country_code||null,t.dest_country||null,t.dest_isp||null,t.ecs||null,t.upstream||null,t.reason||null,n,t.timestamp,t.id]),e.step(),e.reset()}finally{e.finalize()}return t.exec(`COMMIT;`),{updated:r.length}}catch(e){throw t.exec(`ROLLBACK;`),e}}function f(e){let t=o(),n=e.limit||500,r=[],i=t.prepare(`
112
+ SELECT * FROM local_logs
113
+ WHERE profile_id = ? AND (encrypt_version > 0 OR (is_encrypted = 1 AND encrypt_version IS NULL))
114
+ LIMIT ?;
115
+ `);try{for(i.bind([e.profileId,n]);i.step();)r.push(i.get({}))}finally{i.finalize()}return{rows:r}}function p(e){let t=o(),{profileId:n,search:r,action:i,accessPointId:a,destCountry:s,isp:c,since:l,until:u,before:d,limit:f,offset:p=0}=e,m=[`profile_id = ?`],h=[n];if(l!==void 0&&(m.push(`timestamp >= ?`),h.push(l)),u!==void 0&&(m.push(`timestamp <= ?`),h.push(u)),d!==void 0&&(m.push(`timestamp < ?`),h.push(d)),i&&i!==`ALL`&&(m.push(`action = ?`),h.push(i)),a&&(m.push(`access_point_id = ?`),h.push(a)),s&&(m.push(`dest_country = ?`),h.push(s)),c&&(m.push(`dest_isp = ?`),h.push(c)),r&&r.trim()){m.push(`(domain LIKE ? OR client_ip LIKE ? OR reason LIKE ?)`);let e=`%${r.trim()}%`;h.push(e,e,e)}let g=m.join(` AND `),_=t.selectObject(`SELECT count(*) as total FROM local_logs WHERE ${g};`,h),y=_?.total?Number(_.total):0,b={total:0,pass:0,block:0,redirect:0},x=t.prepare(`SELECT action, count(*) as count FROM local_logs WHERE ${g} GROUP BY action;`);try{for(x.bind(h);x.step();){let e=x.get({}),t=Number(e.count)||0;b.total+=t,e.action===`PASS`?b.pass=t:e.action===`BLOCK`?b.block=t:e.action===`REDIRECT`&&(b.redirect=t)}}finally{x.finalize()}let S=[...h,f,p],C=[],w=t.prepare(`
116
+ SELECT * FROM local_logs
117
+ WHERE ${g}
118
+ ORDER BY timestamp DESC, id DESC
119
+ LIMIT ? OFFSET ?;
120
+ `);try{for(w.bind(S);w.step();)C.push(w.get({}))}finally{w.finalize()}return{rows:C,total:y,stats:b}}function m(e){let t=o(),{profileId:n,since:r,until:i,bucketSec:a,accessPointId:s}=e,c=`profile_id = ? AND timestamp BETWEEN ? AND ?`,l=[n,r,i];s&&(c+=` AND access_point_id = ?`,l.push(s));let u=[],d=t.prepare(`
121
+ SELECT action, count(*) as count
122
+ FROM local_logs
123
+ WHERE ${c}
124
+ GROUP BY action;
125
+ `);try{for(d.bind(l);d.step();)u.push(d.get({}))}finally{d.finalize()}let f=[],p=t.prepare(`
126
+ SELECT (timestamp / ?) * ? as timestamp, action, count(*) as count
127
+ FROM local_logs
128
+ WHERE ${c}
129
+ GROUP BY timestamp, action
130
+ ORDER BY timestamp ASC;
131
+ `);try{for(p.bind([a,a,...l]);p.step();)f.push(p.get({}))}finally{p.finalize()}let m=[],h=t.prepare(`
132
+ SELECT domain, count(*) as count
133
+ FROM local_logs
134
+ WHERE ${c} AND action IN ('PASS', 'REDIRECT')
135
+ GROUP BY domain
136
+ ORDER BY count DESC
137
+ LIMIT 10;
138
+ `);try{for(h.bind(l);h.step();)m.push(h.get({}))}finally{h.finalize()}let g=[],_=t.prepare(`
139
+ SELECT domain, count(*) as count
140
+ FROM local_logs
141
+ WHERE ${c} AND action = 'BLOCK'
142
+ GROUP BY domain
143
+ ORDER BY count DESC
144
+ LIMIT 10;
145
+ `);try{for(_.bind(l);_.step();)g.push(_.get({}))}finally{_.finalize()}let y=[],b=t.prepare(`
146
+ SELECT client_ip, COALESCE(geo_country, 'Unknown') as geo_country, count(*) as count
147
+ FROM local_logs
148
+ WHERE ${c} AND client_ip IS NOT NULL AND client_ip != ''
149
+ GROUP BY client_ip
150
+ ORDER BY count DESC
151
+ LIMIT 10;
152
+ `);try{for(b.bind(l);b.step();)y.push(b.get({}))}finally{b.finalize()}let x=[],S=t.prepare(`
153
+ SELECT
154
+ COALESCE(dest_country_code, json_extract(dest_geoip, '$.country_code')) as country_code,
155
+ COALESCE(dest_country, json_extract(dest_geoip, '$.country'), 'Unknown') as country,
156
+ count(*) as count
157
+ FROM local_logs
158
+ WHERE ${c}
159
+ AND (
160
+ (dest_country_code IS NOT NULL AND dest_country_code != '')
161
+ OR
162
+ (dest_geoip IS NOT NULL AND json_extract(dest_geoip, '$.country_code') IS NOT NULL AND json_extract(dest_geoip, '$.country_code') != '')
163
+ )
164
+ GROUP BY country_code, country
165
+ ORDER BY count DESC
166
+ LIMIT 15;
167
+ `);try{for(S.bind(l);S.step();)x.push(S.get({}))}finally{S.finalize()}return{summary:u,trend:f,top_allowed:m,top_blocked:g,clients:y,destinations:x}}function h(e){let t=o(),{profileId:n,countryCode:r,since:i,until:a,accessPointId:s,limit:c=250}=e,l=`profile_id = ? AND timestamp BETWEEN ? AND ?`,u=[n,i,a];s&&(l+=` AND access_point_id = ?`,u.push(s)),r&&(l+=` AND (
168
+ UPPER(COALESCE(dest_country_code, json_extract(dest_geoip, '$.country_code'))) = ?
169
+ )`,u.push(r.toUpperCase())),l+=` AND (
170
+ (dest_isp IS NOT NULL AND dest_isp != '')
171
+ OR
172
+ (dest_geoip IS NOT NULL AND json_extract(dest_geoip, '$.isp') IS NOT NULL AND json_extract(dest_geoip, '$.isp') != '')
173
+ )`;let d=[],f=t.prepare(`
174
+ SELECT
175
+ COALESCE(dest_isp, json_extract(dest_geoip, '$.isp'), 'Unknown') as name,
176
+ count(*) as count
177
+ FROM local_logs
178
+ WHERE ${l}
179
+ GROUP BY name
180
+ ORDER BY count DESC
181
+ LIMIT ?;
182
+ `);try{for(f.bind([...u,c]);f.step();){let e=f.get({});e&&e.name&&d.push(e)}}finally{f.finalize()}return d}function g(e){let t=o(),{retentionDays:n}=e;if(!n||n<=0)return{deleted:0};let r=Math.floor(Date.now()/1e3)-n*86400,i=t.selectObject(`SELECT count(*) as count FROM local_logs;`),a=i?.count?Number(i.count):0;t.exec({sql:`DELETE FROM local_logs WHERE timestamp < ?;`,bind:[r]});let s=t.selectObject(`SELECT count(*) as count FROM local_logs;`),c=a-(s?.count?Number(s.count):0);if(c>1e3)try{t.exec(`VACUUM;`)}catch(e){console.warn(`[SQLite Worker] VACUUM skipped:`,e)}return{deleted:c}}function _(){let e=o(),t=e.selectObject(`SELECT count(*) as count FROM local_logs;`),n=t?.count?Number(t.count):0,r=[],i=e.prepare(`
183
+ SELECT profile_id, count(*) as count, min(timestamp) as earliest, max(timestamp) as latest
184
+ FROM local_logs
185
+ GROUP BY profile_id;
186
+ `);try{for(;i.step();){let e=i.get({});r.push({profile_id:String(e.profile_id),count:Number(e.count)||0,earliest:Number(e.earliest)||0,latest:Number(e.latest)||0})}}finally{i.finalize()}return{totalRows:n,isOpfs:s(),profileStats:r}}function y(e){let t=o();return t.exec({sql:`DELETE FROM local_logs WHERE profile_id = ?;`,bind:[e.profileId]}),t.exec({sql:`DELETE FROM sync_watermarks WHERE profile_id = ?;`,bind:[e.profileId]}),{success:!0}}self.onmessage=async e=>{let{id:t,type:n,payload:r}=e.data;try{let e=null;switch(n){case`INIT`:e={ready:!0,isOpfs:await c()};break;case`SYNC_BATCH`:e=l(r);break;case`UPDATE_LOGS_BATCH`:e=d(r);break;case`GET_ENCRYPTED_LOGS`:e=f(r);break;case`GET_WATERMARK`:e=u(r);break;case`QUERY_LOGS`:e=p(r);break;case`QUERY_ANALYTICS`:e=m(r);break;case`QUERY_ISPS`:e=h(r);break;case`CLEANUP`:e=g(r);break;case`GET_STORAGE_INFO`:e=_();break;case`CLEAR_PROFILE`:e=y(r);break;default:throw Error(`Unknown worker message type: ${n}`)}self.postMessage({id:t,success:!0,data:e})}catch(e){let r=e instanceof Error?e.message:String(e);console.error(`[SQLite Worker] Error executing %s:`,n,e),self.postMessage({id:t,success:!1,error:r})}},self.onerror=e=>{console.error(`[SQLite Worker] Uncaught worker runtime error:`,e)},self.onunhandledrejection=e=>{console.error(`[SQLite Worker] Unhandled promise rejection in worker:`,e.reason)};