@electric-sql/pglite
Version:
PGlite is a WASM Postgres build packaged into a TypeScript client library that enables you to run Postgres in the browser, Node.js and Bun, with no need to install any other dependencies. It is only 3.7mb gzipped.
2 lines • 14.3 kB
JavaScript
;var mr=Object.create;var v=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var fr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var hr=(e,r)=>()=>(e&&(r=e(e=0)),r);var A=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Sr=(e,r)=>{for(var t in r)v(e,t,{get:r[t],enumerable:!0})},W=(e,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of fr(r))!gr.call(e,i)&&i!==t&&v(e,i,{get:()=>r[i],enumerable:!(a=lr(r,i))||a.enumerable});return e};var D=(e,r,t)=>(t=e!=null?mr(yr(e)):{},W(r||!e||!e.__esModule?v(t,"default",{value:e,enumerable:!0}):t,e)),Fr=e=>W(v({},"__esModule",{value:!0}),e);var p=hr(()=>{"use strict"});var P=A((ie,m)=>{"use strict";p();var X=9007199254740991,K=function(e){return e}();function br(e){return e===K}function V(e){return typeof e=="string"||Object.prototype.toString.call(e)=="[object String]"}function Tr(e){return Object.prototype.toString.call(e)=="[object Date]"}function N(e){return e!==null&&typeof e=="object"}function k(e){return typeof e=="function"}function Ar(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=X}function Er(e){return Object.prototype.toString.call(e)=="[object Array]"}function $(e){return N(e)&&!k(e)&&Ar(e.length)}function M(e){return Object.prototype.toString.call(e)=="[object ArrayBuffer]"}function Pr(e,r){return Array.prototype.map.call(e,r)}function wr(e,r){var t=K;return k(r)&&Array.prototype.every.call(e,function(a,i,n){var o=r(a,i,n);return o&&(t=a),!o}),t}function xr(e){return Object.assign.apply(null,arguments)}function Z(e){var r,t,a;if(V(e)){for(t=e.length,a=new Uint8Array(t),r=0;r<t;r++)a[r]=e.charCodeAt(r)&255;return a}return M(e)?new Uint8Array(e):N(e)&&M(e.buffer)?new Uint8Array(e.buffer):$(e)?new Uint8Array(e):N(e)&&k(e.toString)?Z(e.toString()):new Uint8Array}m.exports.MAX_SAFE_INTEGER=X;m.exports.isUndefined=br;m.exports.isString=V;m.exports.isObject=N;m.exports.isDateTime=Tr;m.exports.isFunction=k;m.exports.isArray=Er;m.exports.isArrayLike=$;m.exports.isArrayBuffer=M;m.exports.map=Pr;m.exports.find=wr;m.exports.extend=xr;m.exports.toUint8Array=Z});var w=A((ae,J)=>{"use strict";p();var I="\0";J.exports={NULL_CHAR:I,TMAGIC:"ustar"+I+"00",OLDGNU_MAGIC:"ustar "+I,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 L=A((ue,l)=>{"use strict";p();var Q=P(),d=w(),Ur=512,_=d.TPERMALL,rr=0,er=0,R=[["name",100,0,function(e,r){return x(e[r[0]],r[1])},function(e,r,t){return b(e.slice(r,r+t[1]))}],["mode",8,100,function(e,r){var t=e[r[0]]||_;return t=t&d.TPERMMASK,E(t,r[1],_)},function(e,r,t){var a=g(e.slice(r,r+t[1]));return a&=d.TPERMMASK,a}],["uid",8,108,function(e,r){return E(e[r[0]],r[1],rr)},function(e,r,t){return g(e.slice(r,r+t[1]))}],["gid",8,116,function(e,r){return E(e[r[0]],r[1],er)},function(e,r,t){return g(e.slice(r,r+t[1]))}],["size",12,124,function(e,r){return E(e.data.length,r[1])},function(e,r,t){return g(e.slice(r,r+t[1]))}],["modifyTime",12,136,function(e,r){return z(e[r[0]],r[1])},function(e,r,t){return O(e.slice(r,r+t[1]))}],["checksum",8,148,function(e,r){return" "},function(e,r,t){return g(e.slice(r,r+t[1]))}],["type",1,156,function(e,r){return""+(parseInt(e[r[0]],10)||0)%8},function(e,r,t){return(parseInt(String.fromCharCode(e[r]),10)||0)%8}],["linkName",100,157,function(e,r){return""},function(e,r,t){return b(e.slice(r,r+t[1]))}],["ustar",8,257,function(e,r){return d.TMAGIC},function(e,r,t){return vr(b(e.slice(r,r+t[1]),!0))},function(e,r){return e[r[0]]==d.TMAGIC||e[r[0]]==d.OLDGNU_MAGIC}],["owner",32,265,function(e,r){return x(e[r[0]],r[1])},function(e,r,t){return b(e.slice(r,r+t[1]))}],["group",32,297,function(e,r){return x(e[r[0]],r[1])},function(e,r,t){return b(e.slice(r,r+t[1]))}],["majorNumber",8,329,function(e,r){return""},function(e,r,t){return g(e.slice(r,r+t[1]))}],["minorNumber",8,337,function(e,r){return""},function(e,r,t){return g(e.slice(r,r+t[1]))}],["prefix",131,345,function(e,r){return x(e[r[0]],r[1])},function(e,r,t){return b(e.slice(r,r+t[1]))}],["accessTime",12,476,function(e,r){return z(e[r[0]],r[1])},function(e,r,t){return O(e.slice(r,r+t[1]))}],["createTime",12,488,function(e,r){return z(e[r[0]],r[1])},function(e,r,t){return O(e.slice(r,r+t[1]))}]],tr=function(e){var r=e[e.length-1];return r[2]+r[1]}(R);function vr(e){if(e.length==8){var r=e.split("");if(r[5]==d.NULL_CHAR)return(r[6]==" "||r[6]==d.NULL_CHAR)&&(r[6]="0"),(r[7]==" "||r[7]==d.NULL_CHAR)&&(r[7]="0"),r=r.join(""),r==d.TMAGIC?r:e;if(r[7]==d.NULL_CHAR)return r[5]==d.NULL_CHAR&&(r[5]=" "),r[6]==d.NULL_CHAR&&(r[6]=" "),r==d.OLDGNU_MAGIC?r:e}return e}function x(e,r){return r-=1,Q.isUndefined(e)&&(e=""),e=(""+e).substr(0,r),e+d.NULL_CHAR}function E(e,r,t){for(t=parseInt(t)||0,r-=1,e=(parseInt(e)||t).toString(8).substr(-r,r);e.length<r;)e="0"+e;return e+d.NULL_CHAR}function z(e,r){if(Q.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 E(e,r,0)}function b(e,r){var t=String.fromCharCode.apply(null,e);if(r)return t;var a=t.indexOf(d.NULL_CHAR);return a>=0?t.substr(0,a):t}function g(e){var r=String.fromCharCode.apply(null,e);return parseInt(r.replace(/^0+$/g,""),8)||0}function O(e){return e.length==0||e[0]==0?null:new Date(1e3*g(e))}function Nr(e,r,t){var a=parseInt(r,10)||0,i=Math.min(a+tr,e.length),n=0,o=0,s=0;t&&R.every(function(h){return h[0]=="checksum"?(o=a+h[2],s=o+h[1],!1):!0});for(var u=32,c=a;c<i;c++){var f=c>=o&&c<s?u:e[c];n=(n+f)%262144}return n}l.exports.recordSize=Ur;l.exports.defaultFileMode=_;l.exports.defaultUid=rr;l.exports.defaultGid=er;l.exports.posixHeader=R;l.exports.effectiveHeaderSize=tr;l.exports.calculateChecksum=Nr;l.exports.formatTarString=x;l.exports.formatTarNumber=E;l.exports.formatTarDateTime=z;l.exports.parseTarString=b;l.exports.parseTarNumber=g;l.exports.parseTarDateTime=O});var ar=A((pe,or)=>{"use strict";p();var kr=w(),C=P(),S=L();function nr(e){return S.recordSize}function ir(e){return Math.ceil(e.data.length/S.recordSize)*S.recordSize}function zr(e){var r=0;return e.forEach(function(t){r+=nr(t)+ir(t)}),r+=S.recordSize*2,new Uint8Array(r)}function Or(e,r,t){t=parseInt(t)||0;var a=t;S.posixHeader.forEach(function(u){for(var c=u[3](r,u),f=c.length,h=0;h<f;h+=1)e[a+h]=c.charCodeAt(h)&255;a+=u[1]});var i=C.find(S.posixHeader,function(u){return u[0]=="checksum"});if(i){var n=S.calculateChecksum(e,t,!0),o=S.formatTarNumber(n,i[1]-2)+kr.NULL_CHAR+" ";a=t+i[2];for(var s=0;s<o.length;s+=1)e[a]=o.charCodeAt(s)&255,a++}return t+nr(r)}function Cr(e,r,t){return t=parseInt(t,10)||0,e.set(r.data,t),t+ir(r)}function Dr(e){e=C.map(e,function(a){return C.extend({},a,{data:C.toUint8Array(a.data)})});var r=zr(e),t=0;return e.forEach(function(a){t=Or(r,a,t),t=Cr(r,a,t)}),r}or.exports.tar=Dr});var ur=A((me,sr)=>{"use strict";p();var Mr=w(),H=P(),y=L(),Ir={extractData:!0,checkHeader:!0,checkChecksum:!0,checkFileSize:!0},_r={size:!0,checksum:!0,ustar:!0},G={unexpectedEndOfFile:"Unexpected end of file.",fileCorrupted:"File is corrupted.",checksumCheckFailed:"Checksum check failed."};function Rr(e){return y.recordSize}function Lr(e){return Math.ceil(e/y.recordSize)*y.recordSize}function Gr(e,r){for(var t=r,a=Math.min(e.length,r+y.recordSize*2),i=t;i<a;i++)if(e[i]!=0)return!1;return!0}function Hr(e,r,t){if(e.length-r<y.recordSize){if(t.checkFileSize)throw new Error(G.unexpectedEndOfFile);return null}r=parseInt(r)||0;var a={},i=r;if(y.posixHeader.forEach(function(s){a[s[0]]=s[4](e,i,s),i+=s[1]}),a.type!=0&&(a.size=0),t.checkHeader&&y.posixHeader.forEach(function(s){if(H.isFunction(s[5])&&!s[5](a,s)){var u=new Error(G.fileCorrupted);throw u.data={offset:r+s[2],field:s[0]},u}}),t.checkChecksum){var n=y.calculateChecksum(e,r,!0);if(n!=a.checksum){var o=new Error(G.checksumCheckFailed);throw o.data={offset:r,header:a,checksum:n},o}}return a}function jr(e,r,t,a){return a.extractData?t.size<=0?new Uint8Array:e.slice(r,r+t.size):null}function Br(e,r){var t={};return y.posixHeader.forEach(function(a){var i=a[0];_r[i]||(t[i]=e[i])}),t.isOldGNUFormat=e.ustar==Mr.OLDGNU_MAGIC,r&&(t.data=r),t}function qr(e,r){r=H.extend({},Ir,r);for(var t=[],a=0,i=e.length;i-a>=y.recordSize;){e=H.toUint8Array(e);var n=Hr(e,a,r);if(!n)break;a+=Rr(n);var o=jr(e,a,n,r);if(t.push(Br(n,o)),a+=Lr(n.size),Gr(e,a))break}return t}sr.exports.untar=qr});var pr=A((fe,cr)=>{"use strict";p();var Yr=P(),Wr=w(),Xr=ar(),Kr=ur();Yr.extend(cr.exports,Xr,Kr,Wr)});var ee={};Sr(ee,{BaseFilesystem:()=>q,ERRNO_CODES:()=>Y,EmscriptenBuiltinFilesystem:()=>B,PGDATA:()=>U,WASM_PREFIX:()=>dr});module.exports=Fr(ee);p();p();var T=D(pr(),1);async function j(e,r,t="pgdata",a="auto"){let i=$r(e,r),[n,o]=await Zr(i,a),s=t+(o?".tar.gz":".tar"),u=o?"application/x-gzip":"application/x-tar";return typeof File<"u"?new File([n],s,{type:u}):new Blob([n],{type:u})}function Vr(e,r){let t=[],a=i=>{e.readdir(i).forEach(o=>{if(o==="."||o==="..")return;let s=i+"/"+o,u=e.stat(s),c=e.isFile(u.mode)?e.readFile(s,{encoding:"binary"}):new Uint8Array(0);t.push({name:s.substring(r.length),mode:u.mode,size:u.size,type:e.isFile(u.mode)?T.REGTYPE:T.DIRTYPE,modifyTime:u.mtime,data:c}),e.isDir(u.mode)&&a(s)})};return a(r),t}function $r(e,r){let t=Vr(e,r);return(0,T.tar)(t)}async function Zr(e,r="auto"){if(r==="none")return[e,!1];if(typeof CompressionStream<"u")return[await Jr(e),!0];if(typeof process<"u"&&process.versions&&process.versions.node)return[await Qr(e),!0];if(r==="auto")return[e,!1];throw new Error("Compression not supported in this environment")}async function Jr(e){let r=new CompressionStream("gzip"),t=r.writable.getWriter(),a=r.readable.getReader();t.write(e),t.close();let i=[];for(;;){let{value:s,done:u}=await a.read();if(u)break;s&&i.push(s)}let n=new Uint8Array(i.reduce((s,u)=>s+u.length,0)),o=0;return i.forEach(s=>{n.set(s,o),o+=s.length}),n}async function Qr(e){let{promisify:r}=await import("util"),{gzip:t}=await import("zlib");return await r(t)(e)}var dr="/tmp/pglite",U=dr+"/base",B=class{constructor(r){this.dataDir=r}async init(r,t){return this.pg=r,{emscriptenOpts:t}}async syncToFs(r){}async initialSyncFs(){}async closeFs(){}async dumpTar(r,t){return j(this.pg.Module.FS,U,r,t)}},q=class{constructor(r,{debug:t=!1}={}){this.dataDir=r,this.debug=t}async syncToFs(r){}async initialSyncFs(){}async closeFs(){}async dumpTar(r,t){return j(this.pg.Module.FS,U,r,t)}async init(r,t){return this.pg=r,{emscriptenOpts:{...t,preRun:[...t.preRun||[],i=>{let n=re(i,this);i.FS.mkdir(U),i.FS.mount(n,{},U)}]}}}},Y={EBADF:8,EBADFD:127,EEXIST:20,EINVAL:28,EISDIR:31,ENODEV:43,ENOENT:44,ENOTDIR:54,ENOTEMPTY:55},re=(e,r)=>{let t=e.FS,a=r.debug?console.log:null,i={tryFSOperation(n){try{return n()}catch(o){throw o.code?o.code==="UNKNOWN"?new t.ErrnoError(Y.EINVAL):new t.ErrnoError(o.code):o}},mount(n){return i.createNode(null,"/",16895,0)},syncfs(n,o,s){},createNode(n,o,s,u){if(!t.isDir(s)&&!t.isFile(s))throw new t.ErrnoError(28);let c=t.createNode(n,o,s);return c.node_ops=i.node_ops,c.stream_ops=i.stream_ops,c},getMode:function(n){return a?.("getMode",n),i.tryFSOperation(()=>r.lstat(n).mode)},realPath:function(n){let o=[];for(;n.parent!==n;)o.push(n.name),n=n.parent;return o.push(n.mount.opts.root),o.reverse(),o.join("/")},node_ops:{getattr(n){a?.("getattr",i.realPath(n));let o=i.realPath(n);return i.tryFSOperation(()=>{let s=r.lstat(o);return{...s,dev:0,ino:n.id,nlink:1,rdev:n.rdev,atime:new Date(s.atime),mtime:new Date(s.mtime),ctime:new Date(s.ctime)}})},setattr(n,o){a?.("setattr",i.realPath(n),o);let s=i.realPath(n);i.tryFSOperation(()=>{o.mode!==void 0&&r.chmod(s,o.mode),o.size!==void 0&&r.truncate(s,o.size),o.timestamp!==void 0&&r.utimes(s,o.timestamp,o.timestamp),o.size!==void 0&&r.truncate(s,o.size)})},lookup(n,o){a?.("lookup",i.realPath(n),o);let s=[i.realPath(n),o].join("/"),u=i.getMode(s);return i.createNode(n,o,u)},mknod(n,o,s,u){a?.("mknod",i.realPath(n),o,s,u);let c=i.createNode(n,o,s,u),f=i.realPath(c);return i.tryFSOperation(()=>(t.isDir(c.mode)?r.mkdir(f,{mode:s}):r.writeFile(f,"",{mode:s}),c))},rename(n,o,s){a?.("rename",i.realPath(n),i.realPath(o),s);let u=i.realPath(n),c=[i.realPath(o),s].join("/");i.tryFSOperation(()=>{r.rename(u,c)}),n.name=s},unlink(n,o){a?.("unlink",i.realPath(n),o);let s=[i.realPath(n),o].join("/");try{r.unlink(s)}catch{}},rmdir(n,o){a?.("rmdir",i.realPath(n),o);let s=[i.realPath(n),o].join("/");return i.tryFSOperation(()=>{r.rmdir(s)})},readdir(n){a?.("readdir",i.realPath(n));let o=i.realPath(n);return i.tryFSOperation(()=>r.readdir(o))},symlink(n,o,s){throw a?.("symlink",i.realPath(n),o,s),new t.ErrnoError(63)},readlink(n){throw a?.("readlink",i.realPath(n)),new t.ErrnoError(63)}},stream_ops:{open(n){a?.("open stream",i.realPath(n.node));let o=i.realPath(n.node);return i.tryFSOperation(()=>{t.isFile(n.node.mode)&&(n.shared.refcount=1,n.nfd=r.open(o))})},close(n){return a?.("close stream",i.realPath(n.node)),i.tryFSOperation(()=>{t.isFile(n.node.mode)&&n.nfd&&--n.shared.refcount===0&&r.close(n.nfd)})},dup(n){a?.("dup stream",i.realPath(n.node)),n.shared.refcount++},read(n,o,s,u,c){return a?.("read stream",i.realPath(n.node),s,u,c),u===0?0:i.tryFSOperation(()=>r.read(n.nfd,o,s,u,c))},write(n,o,s,u,c){return a?.("write stream",i.realPath(n.node),s,u,c),i.tryFSOperation(()=>r.write(n.nfd,o.buffer,s,u,c))},llseek(n,o,s){a?.("llseek stream",i.realPath(n.node),o,s);let u=o;if(s===1?u+=n.position:s===2&&t.isFile(n.node.mode)&&i.tryFSOperation(()=>{let c=r.fstat(n.nfd);u+=c.size}),u<0)throw new t.ErrnoError(28);return u},mmap(n,o,s,u,c){if(a?.("mmap stream",i.realPath(n.node),o,s,u,c),!t.isFile(n.node.mode))throw new t.ErrnoError(Y.ENODEV);let f=e.mmapAlloc(o);return i.stream_ops.read(n,e.HEAP8,f,o,s),{ptr:f,allocated:!0}},msync(n,o,s,u,c){return a?.("msync stream",i.realPath(n.node),s,u,c),i.stream_ops.write(n,o,0,u,s),0}}};return i};0&&(module.exports={BaseFilesystem,ERRNO_CODES,EmscriptenBuiltinFilesystem,PGDATA,WASM_PREFIX});
//# sourceMappingURL=base.cjs.map