Hi, I'd love to give this a try in my existing Django application. As I'm using JSON features, I tried the full integration (pattern 2) but I'm getting an error when starting the pglite server.
This is running the current version (0.4.1) inside docker. I realize it's maybe not a lot to go on - is there additional information I might provide?
/tmp/py-pglite-ma5kpab0/node_modules/@electric-sql/pglite/dist/index.cjs:1
"use strict";var Is=Object.create;var st=Object.defineProperty;var Fs=Object.getOwnPropertyDescriptor;var Ps=Object.getOwnPropertyNames;var As=Object.getPrototypeOf,ks=Object.prototype.hasOwnProperty;var na=e=>{throw TypeError(e)};var Ts=(e,t,r)=>t in e?st(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var ot=(e,t)=>()=>(e&&(t=e(e=0)),t);var Be=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ie=(e,t)=>{for(var r in t)st(e,r,{get:t[r],enumerable:!0})},ia=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ps(t))!ks.call(e,s)&&s!==r&&st(e,s,{get:()=>t[s],enumerable:!(a=Fs(t,s))||a.enumerable});return e};var K=(e,t,r)=>(r=e!=null?Is(As(e)):{},ia(t||!e||!e.__esModule?st(r,"default",{value:e,enumerable:!0}):r,e)),Us=e=>ia(st({},"__esModule",{value:!0}),e);var ne=(e,t,r)=>Ts(e,typeof t!="symbol"?t+"":t,r),ur=(e,t,r)=>t.has(e)||na("Cannot "+r);var p=(e,t,r)=>(ur(e,t,"read from private field"),r?r.call(e):t.get(e)),E=(e,t,r)=>t.has(e)?na("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),S=(e,t,r,a)=>(ur(e,t,"write to private field"),a?a.call(e,r):t.set(e,r),r),h=(e,t,r)=>(ur(e,t,"access private method"),r);var Fe=(e,t,r,a)=>({set _(s){S(e,t,s,r)},get _(){return p(e,t,a)}});var Rs,C,M=ot(()=>{"use strict";Rs=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,C=Rs()});var Ct=Be((Wi,Q)=>{"use strict";M();var Oa=9007199254740991,La=function(e){return e}();function _n(e){return e===La}function Ba(e){return typeof e=="string"||Object.prototype.toString.call(e)=="[object String]"}function mn(e){return Object.prototype.toString.call(e)=="[object Date]"}function tr(e){return e!==null&&typeof e=="object"}function rr(e){return typeof e=="function"}function pn(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=Oa}function dn(e){return Object.prototype.toString.call(e)=="[object Array]"}function Ga(e){return tr(e)&&!rr(e)&&pn(e.length)}function Hr(e){return Object.prototype.toString.call(e)=="[object ArrayBuffer]"}function un(e,t){return Array.prototype.map.call(e,t)}function cn(e,t){var r=La;return rr(t)&&Array.prototype.every.call(e,function(a,s,o){var n=t(a,s,o);return n&&(r=a),!n}),r}function gn(e){return Object.assign.apply(null,arguments)}function Ha(e){var t,r,a;if(Ba(e)){for(r=e.length,a=new Uint8Array(r),t=0;t<r;t++)a[t]=e.charCodeAt(t)&255;return a}return Hr(e)?new Uint8Array(e):tr(e)&&Hr(e.buffer)?new Uint8Array(e.buffer):Ga(e)?new Uint8Array(e):tr(e)&&rr(e.toString)?Ha(e.toString()):new Uint8Array}Q.exports.MAX_SAFE_INTEGER=Oa;Q.exports.isUndefined=_n;Q.exports.isString=Ba;Q.exports.isObject=tr;Q.exports.isDateTime=mn;Q.exports.isFunction=rr;Q.exports.isArray=dn;Q.exports.isArrayLike=Ga;Q.exports.isArrayBuffer=Hr;Q.exports.map=un;Q.exports.find=cn;Q.exports.extend=gn;Q.exports.toUint8Array=Ha});var It=Be((Ki,Xa)=>{"use strict";M();var Xr="\0";Xa.exports={NULL_CHAR:Xr,TMAGIC:"ustar"+Xr+"00",OLDGNU_MAGIC:"ustar "+Xr,REGTYPE:0,LNKTYPE:1,SYMTYPE:2,CHRTYPE:3,BLKTYPE:4,DIRTYPE:5,FIFOTYPE:6,CONTTYPE:7,TSUID:parseInt("4000",8),TSGID:parseInt("2000",8),TSVTX:parseInt("1000",8),TUREAD:parseInt("0400",8),TUWRITE:parseInt("0200",8),TUEXEC:parseInt("0100",8),TGREAD:parseInt("0040",8),TGWRITE:parseInt("0020",8),TGEXEC:parseInt("0010",8),TOREAD:parseInt("0004",8),TOWRITE:parseInt("0002",8),TOEXEC:parseInt("0001",8),TPERMALL:parseInt("0777",8),TPERMMASK:parseInt("0777",8)}});var Vr=Be((Ji,$)=>{"use strict";M();var ja=Ct(),L=It(),fn=512,jr=L.TPERMALL,Wa=0,Va=0,Wr=[["name",100,0,function(e,t){return Ft(e[t[0]],t[1])},function(e,t,r){return De(e.slice(t,t+r[1]))}],["mode",8,100,function(e,t){var r=e[t[0]]||jr;return r=r&L.TPERMMASK,Ve(r,t[1],jr)},function(e,t,r){var a=fe(e.slice(t,t+r[1]));return a&=L.TPERMMASK,a}],["uid",8,108,function(e,t){return Ve(e[t[0]],t[1],Wa)},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["gid",8,116,function(e,t){return Ve(e[t[0]],t[1],Va)},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["size",12,124,function(e,t){return Ve(e.data.length,t[1])},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["modifyTime",12,136,function(e,t){return ar(e[t[0]],t[1])},function(e,t,r){return sr(e.slice(t,t+r[1]))}],["checksum",8,148,function(e,t){return" "},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["type",1,156,function(e,t){return""+(parseInt(e[t[0]],10)||0)%8},function(e,t,r){return(parseInt(String.fromCharCode(e[t]),10)||0)%8}],["linkName",100,157,function(e,t){return""},function(e,t,r){return De(e.slice(t,t+r[1]))}],["ustar",8,257,function(e,t){return L.TMAGIC},function(e,t,r){return hn(De(e.slice(t,t+r[1]),!0))},function(e,t){return e[t[0]]==L.TMAGIC||e[t[0]]==L.OLDGNU_MAGIC}],["owner",32,265,function(e,t){return Ft(e[t[0]],t[1])},function(e,t,r){return De(e.slice(t,t+r[1]))}],["group",32,297,function(e,t){return Ft(e[t[0]],t[1])},function(e,t,r){return De(e.slice(t,t+r[1]))}],["majorNumber",8,329,function(e,t){return""},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["minorNumber",8,337,function(e,t){return""},function(e,t,r){return fe(e.slice(t,t+r[1]))}],["prefix",131,345,function(e,t){return Ft(e[t[0]],t[1])},function(e,t,r){return De(e.slice(t,t+r[1]))}],["accessTime",12,476,function(e,t){return ar(e[t[0]],t[1])},function(e,t,r){return sr(e.slice(t,t+r[1]))}],["createTime",12,488,function(e,t){return ar(e[t[0]],t[1])},function(e,t,r){return sr(e.slice(t,t+r[1]))}]],Ka=function(e){var t=e[e.length-1];return t[2]+t[1]}(Wr);function hn(e){if(e.length==8){var t=e.split("");if(t[5]==L.NULL_CHAR)return(t[6]==" "||t[6]==L.NULL_CHAR)&&(t[6]="0"),(t[7]==" "||t[7]==L.NULL_CHAR)&&(t[7]="0"),t=t.join(""),t==L.TMAGIC?t:e;if(t[7]==L.NULL_CHAR)return t[5]==L.NULL_CHAR&&(t[5]=" "),t[6]==L.NULL_CHAR&&(t[6]=" "),t==L.OLDGNU_MAGIC?t:e}return e}function Ft(e,t){return t-=1,ja.isUndefined(e)&&(e=""),e=(""+e).substr(0,t),e+L.NULL_CHAR}function Ve(e,t,r){for(r=parseInt(r)||0,t-=1,e=(parseInt(e)||r).toString(8).substr(-t,t);e.length<t;)e="0"+e;return e+L.NULL_CHAR}function ar(e,t){if(ja.isDateTime(e))e=Math.floor(1*e/1e3);else if(e=parseInt(e,10),isFinite(e)){if(e<=0)return""}else e=Math.floor(1*new Date/1e3);return Ve(e,t,0)}function De(e,t){var r=String.fromCharCode.apply(null,e);if(t)return r;var a=r.indexOf(L.NULL_CHAR);return a>=0?r.substr(0,a):r}function fe(e){var t=String.fromCharCode.apply(null,e);return parseInt(t.replace(/^0+$/g,""),8)||0}function sr(e){return e.length==0||e[0]==0?null:new Date(1e3*fe(e))}function xn(e,t,r){var a=parseInt(t,10)||0,s=Math.min(a+Ka,e.length),o=0,n=0,l=0;r&&Wr.every(function(u){return u[0]=="checksum"?(n=a+u[2],l=n+u[1],!1):!0});for(var _=32,m=a;m<s;m++){var d=m>=n&&m<l?_:e[m];o=(o+d)%262144}return o}$.exports.recordSize=fn;$.exports.defaultFileMode=jr;$.exports.defaultUid=Wa;$.exports.defaultGid=Va;$.exports.posixHeader=Wr;$.exports.effectiveHeaderSize=Ka;$.exports.calculateChecksum=xn;$.exports.formatTarString=Ft;$.exports.formatTarNumber=Ve;$.exports.formatTarDateTime=ar;$.exports.parseTarString=De;$.exports.parseTarNumber=fe;$.exports.parseTarDateTime=sr});var $a=Be(($i,Qa)=>{"use strict";M();var Mn=It(),or=Ct(),Se=Vr();function Ya(e){return Se.recordSize}function Ja(e){return Math.ceil(e.data.length/Se.recordSize)*Se.recordSize}function Sn(e){var t=0;return e.forEach(function(r){t+=Ya(r)+Ja(r)}),t+=Se.recordSize*2,new Uint8Array(t)}function En(e,t,r){r=parseInt(r)||0;var a=r;Se.posixHeader.forEach(function(_){for(var m=_[3](t,_),d=m.length,u=0;u<d;u+=1)e[a+u]=m.charCodeAt(u)&255;a+=_[1]});var s=or.find(Se.posixHeader,function(_){return _[0]=="checksum"});if(s){var o=Se.calculateChecksum(e,r,!0),n=Se.formatTarNumber(o,s[1]-2)+Mn.NULL_CHAR+" ";a=r+s[2];for(var l=0;l<n.length;l+=1)e[a]=n.charCodeAt(l)&255,a++}return r+Ya(t)}function vn(e,t,r){return r=parseInt(r,10)||0,e.set(t.data,r),r+Ja(t)}function yn(e){e=or.map(e,function(a){return or.extend({},a,{data:or.toUint8Array(a.data)})});var t=Sn(e),r=0;return e.forEach(function(a){r=En(t,a,r),r=vn(t,a,r)}),t}Qa.exports.tar=yn});var es=Be((el,Za)=>{"use strict";M();var wn=It(),Yr=Ct(),_e=Vr(),bn={extractData:!0,checkHeader:!0,checkChecksum:!0,checkFileSize:!0},Cn={size:!0,checksum:!0,ustar:!0},Kr={unexpectedEndOfFile:"Unexpected end of file.",fileCorrupted:"File is corrupted.",checksumCheckFailed:"Checksum check failed."};function In(e){return _e.recordSize}function Fn(e){return Math.ceil(e/_e.recordSize)*_e.recordSize}function Pn(e,t){for(var r=t,a=Math.min(e.length,t+_e.recordSize*2),s=r;s<a;s++)if(e[s]!=0)return!1;return!0}function An(e,t,r){if(e.length-t<_e.recordSize){if(r.checkFileSize)throw new Error(Kr.unexpectedEndOfFile);return null}t=parseInt(t)||0;var a={},s=t;if(_e.posixHeader.forEach(function(l){a[l[0]]=l[4](e,s,l),s+=l[1]}),a.type!=0&&(a.size=0),r.checkHeader&&_e.posixHeader.forEach(function(l){if(Yr.isFunction(l[5])&&!l[5](a,l)){var _=new Error(Kr.fileCorrupted);throw _.data={offset:t+l[2],field:l[0]},_}}),r.checkChecksum){var o=_e.calculateChecksum(e,t,!0);if(o!=a.checksum){var n=new Error(Kr.checksumCheckFailed);throw n.data={offset:t,header:a,checksum:o},n}}return a}function kn(e,t,r,a){return a.extractData?r.size<=0?new Uint8Array:e.slice(t,t+r.size):null}function Tn(e,t){var r={};return _e.posixHeader.forEach(function(a){var s=a[0];Cn[s]||(r[s]=e[s])}),r.isOldGNUFormat=e.ustar==wn.OLDGNU_MAGIC,t&&(r.data=t),r}function Un(e,t){t=Yr.extend({},bn,t);for(var r=[],a=0,s=e.length;s-a>=_e.recordSize;){e=Yr.toUint8Array(e);var o=An(e,a,t);if(!o)break;a+=In(o);var n=kn(e,a,o,t);if(r.push(Tn(o,n)),a+=Fn(o.size),Pn(e,a))break}return r}Za.exports.untar=Un});var Jr=Be((rl,ts)=>{"use strict";M();var Rn=Ct(),Dn=It(),qn=$a(),Nn=es();Rn.extend(ts.exports,qn,Nn,Dn)});async function Zr(e,t,r="pgdata",a="auto"){let s=Gn(e,t),[o,n]=await Hn(s,a),l=r+(n?".tar.gz":".tar"),_=n?"application/x-gzip":"application/x-tar";return typeof File<"u"?new File([o],l,{type:_}):new Blob([o],{type:_})}async function ps(e,t,r){let a=new Uint8Array(await t.arrayBuffer()),s=typeof File<"u"&&t instanceof File?t.name:void 0;(Ln.includes(t.type)||s?.endsWith(".tgz")||s?.endsWith(".tar.gz"))&&(a=await _s(a));let n;try{n=(0,ie.untar)(a)}catch(l){if(l instanceof Error&&l.message.includes("File is corrupted"))a=await _s(a),n=(0,ie.untar)(a);else throw l}for(let l of n){let _=r+l.name,m=_.split("/").slice(0,-1);for(let d=1;d<=m.length;d++){let u=m.slice(0,d).join("/");e.analyzePath(u).exists||e.mkdir(u)}l.type===ie.REGTYPE?(e.writeFile(_,l.data),e.utime(_,ms(l.modifyTime),ms(l.modifyTime))):l.type===ie.DIRTYPE&&e.mkdir(_)}}function Bn(e,t){let r=[],a=s=>{e.readdir(s).forEach(n=>{if(n==="."||n==="..")return;let l=s+"/"+n,_=e.stat(l),m=e.isFile(_.mode)?e.readFile(l,{encoding:"binary"}):new Uint8Array(0);r.push({name:l.substring(t.length),mode:_.mode,size:_.size,type:e.isFile(_.mode)?ie.REGTYPE:ie.DIRTYPE,modifyTime:_.mtime,data:m}),e.isDir(_.mode)&&a(l)})};return a(t),r}function Gn(e,t){let r=Bn(e,t);return(0,ie.tar)(r)}async function Hn(e,t="auto"){if(t==="none")return[e,!1];if(typeof CompressionStream<"u")return[await Xn(e),!0];if(typeof process<"u"&&process.versions&&process.versions.node)return[await jn(e),!0];if(t==="auto")return[e,!1];throw new Error("Compression not supported in this environment")}async function Xn(e){let t=new CompressionStream("gzip"),r=t.writable.getWriter(),a=t.readable.getReader();r.write(e),r.close();let s=[];for(;;){let{value:l,done:_}=await a.read();if(_)break;l&&s.push(l)}let o=new Uint8Array(s.reduce((l,_)=>l+_.length,0)),n=0;return s.forEach(l=>{o.set(l,n),n+=l.length}),o}async function jn(e){let{promisify:t}=await import("util"),{gzip:r}=await import("zlib");return await t(r)(e)}async function _s(e){if(typeof CompressionStream<"u")return await Wn(e);if(typeof process<"u"&&process.versions&&process.versions.node)return await Vn(e);throw new Error("Unsupported environment for decompression")}async function Wn(e){let t=new DecompressionStream("gzip"),r=t.writable.getWriter(),a=t.readable.getReader();r.write(e),r.close();let s=[];for(;;){let{value:l,done:_}=await a.read();if(_)break;l&&s.push(l)}let o=new Uint8Array(s.reduce((l,_)=>l+_.length,0)),n=0;return s.forEach(l=>{o.set(l,n),n+=l.length}),o}async function Vn(e){let{promisify:t}=await import("util"),{gunzip:r}=await import("zlib");return await t(r)(e)}function ms(e){return e?typeof e=="number"?e:Math.floor(e.getTime()/1e3):Math.floor(Date.now()/1e3)}var ie,Ln,ea=ot(()=>{"use strict";M();ie=K(Jr(),1);Ln=["application/x-gtar","application/x-tar+gzip","application/x-gzip","application/gzip"]});var Ut,X,Ee,kt,Tt,Kn,Ye=ot(()=>{"use strict";M();ea();Ut="/tmp/pglite",X=Ut+"/base",Ee=class{constructor(t){this.dataDir=t}async init(t,r){return this.pg=t,{emscriptenOpts:r}}async syncToFs(t){}async initialSyncFs(){}async closeFs(){}async dumpTar(t,r){return Zr(this.pg.Module.FS,X,t,r)}},kt=class{constructor(t,{debug:r=!1}={}){this.dataDir=t,this.debug=r}async syncToFs(t){}async initialSyncFs(){}async closeFs(){}async dumpTar(t,r){return Zr(this.pg.Module.FS,X,t,r)}async init(t,r){return this.pg=t,{emscriptenOpts:{...r,preRun:[...r.preRun||[],s=>{let o=Kn(s,this);s.FS.mkdir(X),s.FS.mount(o,{},X)}]}}}},Tt={EBADF:8,EBADFD:127,EEXIST:20,EINVAL:28,EISDIR:31,ENODEV:43,ENOENT:44,ENOTDIR:54,ENOTEMPTY:55},Kn=(e,t)=>{let r=e.FS,a=t.debug?console.log:null,s={tryFSOperation(o){try{return o()}catch(n){throw n.code?n.code==="UNKNOWN"?new r.ErrnoError(Tt.EINVAL):new r.ErrnoError(n.code):n}},mount(o){return s.createNode(null,"/",16895,0)},syncfs(o,n,l){},createNode(o,n,l,_){if(!r.isDir(l)&&!r.isFile(l))throw new r.ErrnoError(28);let m=r.createNode(o,n,l);return m.node_ops=s.node_ops,m.stream_ops=s.stream_ops,m},getMode:function(o){return a?.("getMode",o),s.tryFSOperation(()=>t.lstat(o).mode)},realPath:function(o){let n=[];for(;o.parent!==o;)n.push(o.name),o=o.parent;return n.push(o.mount.opts.root),n.reverse(),n.join("/")},node_ops:{getattr(o){a?.("getattr",s.realPath(o));let n=s.realPath(o);return s.tryFSOperation(()=>{let l=t.lstat(n);return{...l,dev:0,ino:o.id,nlink:1,rdev:o.rdev,atime:new Date(l.atime),mtime:new Date(l.mtime),ctime:new Date(l.ctime)}})},setattr(o,n){a?.("setattr",s.realPath(o),n);let l=s.realPath(o);s.tryFSOperation(()=>{n.mode!==void 0&&t.chmod(l,n.mode),n.size!==void 0&&t.truncate(l,n.size),n.timestamp!==void 0&&t.utimes(l,n.timestamp,n.timestamp),n.size!==void 0&&t.truncate(l,n.size)})},lookup(o,n){a?.("lookup",s.realPath(o),n);let l=[s.realPath(o),n].join("/"),_=s.getMode(l);return s.createNode(o,n,_)},mknod(o,n,l,_){a?.("mknod",s.realPath(o),n,l,_);let m=s.createNode(o,n,l,_),d=s.realPath(m);return s.tryFSOperation(()=>(r.isDir(m.mode)?t.mkdir(d,{mode:l}):t.writeFile(d,"",{mode:l}),m))},rename(o,n,l){a?.("rename",s.realPath(o),s.realPath(n),l);let _=s.realPath(o),m=[s.realPath(n),l].join("/");s.tryFSOperation(()=>{t.rename(_,m)}),o.name=l},unlink(o,n){a?.("unlink",s.realPath(o),n);let l=[s.realPath(o),n].join("/");try{t.unlink(l)}catch{}},rmdir(o,n){a?.("rmdir",s.realPath(o),n);let l=[s.realPath(o),n].join("/");return s.tryFSOperation(()=>{t.rmdir(l)})},readdir(o){a?.("readdir",s.realPath(o));let n=s.realPath(o);return s.tryFSOperation(()=>t.readdir(n))},symlink(o,n,l){throw a?.("symlink",s.realPath(o),n,l),new r.ErrnoError(63)},readlink(o){throw a?.("readlink",s.realPath(o)),new r.ErrnoError(63)}},stream_ops:{open(o){a?.("open stream",s.realPath(o.node));let n=s.realPath(o.node);return s.tryFSOperation(()=>{r.isFile(o.node.mode)&&(o.shared.refcount=1,o.nfd=t.open(n))})},close(o){return a?.("close stream",s.realPath(o.node)),s.tryFSOperation(()=>{r.isFile(o.node.mode)&&o.nfd&&--o.shared.refcount===0&&t.close(o.nfd)})},dup(o){a?.("dup stream",s.realPath(o.node)),o.shared.refcount++},read(o,n,l,_,m){return a?.("read stream",s.realPath(o.node),l,_,m),_===0?0:s.tryFSOperation(()=>t.read(o.nfd,n,l,_,m))},write(o,n,l,_,m){return a?.("write stream",s.realPath(o.node),l,_,m),s.tryFSOperation(()=>t.write(o.nfd,n.buffer,l,_,m))},llseek(o,n,l){a?.("llseek stream",s.realPath(o.node),n,l);let _=n;if(l===1?_+=o.position:l===2&&r.isFile(o.node.mode)&&s.tryFSOperation(()=>{let m=t.fstat(o.nfd);_+=m.size}),_<0)throw new r.ErrnoError(28);return _},mmap(o,n,l,_,m){if(a?.("mmap stream",s.realPath(o.node),n,l,_,m),!r.isFile(o.node.mode))throw new r.ErrnoError(Tt.ENODEV);let d=e.mmapAlloc(n);return s.stream_ops.read(o,e.HEAP8,d,n,l),{ptr:d,allocated:!0}},msync(o,n,l,_,m){return a?.("msync stream",s.realPath(o.node),l,_,m),s.stream_ops.write(o,n,0,_,l),0}}};return s}});var ds={};Ie(ds,{NodeFS:()=>ta});var nr,ir,ta,us=ot(()=>{"use strict";M();nr=K(require("fs"),1),ir=K(require("path"),1);Ye();ta=class extends Ee{constructor(t){super(t),this.rootDir=ir.resolve(t),nr.existsSync(ir.join(this.rootDir))||nr.mkdirSync(this.rootDir)}async init(t,r){return this.pg=t,{emscriptenOpts:{...r,preRun:[...r.preRun||[],s=>{let o=s.FS.filesystems.NODEFS;s.FS.mkdir(X),s.FS.mount(o,{root:this.rootDir},X)}]}}}async closeFs(){this.pg.Module.FS.quit()}}});var hs={};Ie(hs,{OpfsAhpFS:()=>aa});var Yn,Jn,ra,Dt,Ze,ve,qt,B,he,W,Nt,ye,we,pe,v,cs,qe,$e,me,j,Rt,gs,sa,aa,q,xs=ot(()=>{"use strict";M();Ye();Yn="state.txt",Jn="data",ra={DIR:16384,FILE:32768},aa=class extends kt{constructor(r,{initialPoolSize:a=1e3,maintainedPoolSize:s=100,debug:o=!1}={}){super(r,{debug:o});E(this,v);E(this,Dt);E(this,Ze);E(this,ve);E(this,qt);E(this,B);E(this,he,new Map);E(this,W,new Map);E(this,Nt,0);E(this,ye,new Map);E(this,we,new Map);this.lastCheckpoint=0;this.checkpointInterval=1e3*60;this.poolCounter=0;E(this,pe,new Set);this.initialPoolSize=a,this.maintainedPoolSize=s}async init(r,a){return await h(this,v,cs).call(this),super.init(r,a)}async syncToFs(r=!1){await this.maybeCheckpointState(),await this.maintainPool(),r||this.flush()}async closeFs(){for(let r of p(this,W).values())r.close();p(this,B).flush(),p(this,B).close(),this.pg.Module.FS.quit()}async maintainPool(r){r=r||this.maintainedPoolSize;let a=r-this.state.pool.length,s=[];for(let o=0;o<a;o++)s.push(new Promise(async n=>{++this.poolCounter;let l=`${(Date.now()-1704063600).toString(16).padStart(8,"0")}-${this.poolCounter.toString(16).padStart(8,"0")}`,_=await p(this,ve).getFileHandle(l,{create:!0}),m=await _.createSyncAccessHandle();p(this,he).set(l,_),p(this,W).set(l,m),h(this,v,$e).call(this,{opp:"createPoolFile",args:[l]}),this.state.pool.push(l),n()}));for(let o=0;o>a;o--)s.push(new Promise(async n=>{let l=this.state.pool.pop();h(this,v,$e).call(this,{opp:"deletePoolFile",args:[l]});let _=p(this,he).get(l);p(this,W).get(l)?.close(),await p(this,ve).removeEntry(_.name),p(this,he).delete(l),p(this,W).delete(l),n()}));await Promise.all(s)}_createPoolFileState(r){this.state.pool.push(r)}_deletePoolFileState(r){let a=this.state.pool.indexOf(r);a>-1&&this.state.pool.splice(a,1)}async maybeCheckpointState(){Date.now()-this.lastCheckpoint>this.checkpointInterval&&await this.checkpointState()}async checkpointState(){let r=new TextEncoder().encode(JSON.stringify(this.state));p(this,B).truncate(0),p(this,B).write(r,{at:0}),p(this,B).flush(),this.lastCheckpoint=Date.now()}flush(){for(let r of p(this,pe))try{r.flush()}catch{}p(this,pe).clear()}chmod(r,a){h(this,v,qe).call(this,{opp:"chmod",args:[r,a]},()=>{this._chmodState(r,a)})}_chmodState(r,a){let s=h(this,v,j).call(this,r);s.mode=a}close(r){let a=h(this,v,Rt).call(this,r);p(this,ye).delete(r),p(this,we).delete(a)}fstat(r){let a=h(this,v,Rt).call(this,r);return this.lstat(a)}lstat(r){let a=h(this,v,j).call(this,r),s=a.type==="file"?p(this,W).get(a.backingFilename).getSize():0,o=4096;return{dev:0,ino:0,mode:a.mode,nlink:1,uid:0,gid:0,rdev:0,size:s,blksize:o,blocks:Math.ceil(s/o),atime:a.lastModified,mtime:a.lastModified,ctime:a.lastModified}}mkdir(r,a){h(this,v,qe).call(this,{opp:"mkdir",args:[r,a]},()=>{this._mkdirState(r,a)})}_mkdirState(r,a){let s=h(this,v,me).call(this,r),o=s.pop(),n=[],l=this.state.root;for(let m of s){if(n.push(r),!Object.prototype.hasOwnProperty.call(l.children,m))if(a?.recursive)this.mkdir(n.join("/"));else throw new q("ENOENT","No such file or directory");if(l.children[m].type!=="directory")throw new q("ENOTDIR","Not a directory");l=l.children[m]}if(Object.prototype.hasOwnProperty.call(l.children,o))throw new q("EEXIST","File exists");let _={type:"directory",lastModified:Date.now(),mode:a?.mode||ra.DIR,children:{}};l.children[o]=_}open(r,a,s){if(h(this,v,j).call(this,r).type!=="file")throw new q("EISDIR","Is a directory");let n=h(this,v,gs).call(this);return p(this,ye).set(n,r),p(this,we).set(r,n),n}readdir(r){let a=h(this,v,j).call(this,r);if(a.type!=="directory")throw new q("ENOTDIR","Not a directory");return Object.keys(a.children)}read(r,a,s,o,n){let l=h(this,v,Rt).call(this,r),_=h(this,v,j).call(this,l);if(_.type!=="file")throw new q("EISDIR","Is a directory");return p(this,W).get(_.backingFilename).read(new Uint8Array(a.buffer,s,o),{at:n})}rename(r,a){h(this,v,qe).call(this,{opp:"rename",args:[r,a]},()=>{this._renameState(r,a,!0)})}_renameState(r,a,s=!1){let o=h(this,v,me).call(this,r),n=o.pop(),l=h(this,v,j).call(this,o.join("/"));if(!Object.prototype.hasOwnProperty.call(l.children,n))throw new q("ENOENT","No such file or directory");let _=h(this,v,me).call(this,a),m=_.pop(),d=h(this,v,j).call(this,_.join("/"));if(s&&Object.prototype.hasOwnProperty.call(d.children,m)){let u=d.children[m];p(this,W).get(u.backingFilename).truncate(0),this.state.pool.push(u.backingFilename)}d.children[m]=l.children[n],delete l.children[n]}rmdir(r){h(this,v,qe).call(this,{opp:"rmdir",args:[r]},()=>{this._rmdirState(r)})}_rmdirState(r){let a=h(this,v,me).call(this,r),s=a.pop(),o=h(this,v,j).call(this,a.join("/"));if(!Object.prototype.hasOwnProperty.call(o.children,s))throw new q("ENOENT","No such file or directory");let n=o.children[s];if(n.type!=="directory")throw new q("ENOTDIR","Not a directory");if(Object.keys(n.children).length>0)throw new q("ENOTEMPTY","Directory not empty");delete o.children[s]}truncate(r,a=0){let s=h(this,v,j).call(this,r);if(s.type!=="file")throw new q("EISDIR","Is a directory");let o=p(this,W).get(s.backingFilename);if(!o)throw new q("ENOENT","No such file or directory");o.truncate(a),p(this,pe).add(o)}unlink(r){h(this,v,qe).call(this,{opp:"unlink",args:[r]},()=>{this._unlinkState(r,!0)})}_unlinkState(r,a=!1){let s=h(this,v,me).call(this,r),o=s.pop(),n=h(this,v,j).call(this,s.join("/"));if(!Object.prototype.hasOwnProperty.call(n.children,o))throw new q("ENOENT","No such file or directory");let l=n.children[o];if(l.type!=="file")throw new q("EISDIR","Is a directory");if(delete n.children[o],a){let _=p(this,W).get(l.backingFilename);_?.truncate(0),p(this,pe).add(_),p(this,we).has(r)&&(p(this,ye).delete(p(this,we).get(r)),p(this,we).delete(r))}this.state.pool.push(l.backingFilename)}utimes(r,a,s){h(this,v,qe).call(this,{opp:"utimes",args:[r,a,s]},()=>{this._utimesState(r,a,s)})}_utimesState(r,a,s){let o=h(this,v,j).call(this,r);o.lastModified=s}writeFile(r,a,s){let o=h(this,v,me).call(this,r),n=o.pop(),l=h(this,v,j).call(this,o.join("/"));if(Object.prototype.hasOwnProperty.call(l.children,n)){let d=l.children[n];d.lastModified=Date.now(),h(this,v,$e).call(this,{opp:"setLastModified",args:[r,d.lastModified]})}else{if(this.state.pool.length===0)throw new Error("No more file handles available in the pool");let d={type:"file",lastModified:Date.now(),mode:s?.mode||ra.FILE,backingFilename:this.state.pool.pop()};l.children[n]=d,h(this,v,$e).call(this,{opp:"createFileNode",args:[r,d]})}let _=l.children[n],m=p(this,W).get(_.backingFilename);a.length>0&&(m.write(typeof a=="string"?new TextEncoder().encode(a):new Uint8Array(a),{at:0}),r.startsWith("/pg_wal")&&p(this,pe).add(m))}_createFileNodeState(r,a){let s=h(this,v,me).call(this,r),o=s.pop(),n=h(this,v,j).call(this,s.join("/"));n.children[o]=a;let l=this.state.pool.indexOf(a.backingFilename);return l>-1&&this.state.pool.splice(l,1),a}_setLastModifiedState(r,a){let s=h(this,v,j).call(this,r);s.lastModified=a}write(r,a,s,o,n){let l=h(this,v,Rt).call(this,r),_=h(this,v,j).call(this,l);if(_.type!=="file")throw new q("EISDIR","Is a directory");let m=p(this,W).get(_.backingFilename);if(!m)throw new q("EBADF","Bad file descriptor");let d=m.write(new Uint8Array(a,s,o),{at:n});return l.startsWith("/pg_wal")&&p(this,pe).add(m),d}};Dt=new WeakMap,Ze=new WeakMap,ve=new WeakMap,qt=new WeakMap,B=new WeakMap,he=new WeakMap,W=new WeakMap,Nt=new WeakMap,ye=new WeakMap,we=new WeakMap,pe=new WeakMap,v=new WeakSet,cs=async function(){S(this,Dt,await navigator.storage.getDirectory()),S(this,Ze,await h(this,v,sa).call(this,this.dataDir,{create:!0})),S(this,ve,await h(this,v,sa).call(this,Jn,{from:p(this,Ze),create:!0})),S(this,qt,await p(this,Ze).getFileHandle(Yn,{create:!0})),S(this,B,await p(this,qt).createSyncAccessHandle());let r=new ArrayBuffer(p(this,B).getSize());p(this,B).read(r,{at:0});let a,s=new TextDecoder().decode(r).split(`
SyntaxError: Unexpected token '.'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/tmp/py-pglite-ma5kpab0/pglite_manager.js:1:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
Hi, I'd love to give this a try in my existing Django application. As I'm using JSON features, I tried the full integration (pattern 2) but I'm getting an error when starting the pglite server.
This is running the current version (0.4.1) inside docker. I realize it's maybe not a lot to go on - is there additional information I might provide?
Full error output:
Python exception raised here.