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