@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 • 10.9 kB
JavaScript
var dr=Object.create;var v=Object.defineProperty;var lr=Object.getOwnPropertyDescriptor;var fr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var hr=(r,e)=>()=>(r&&(e=r(r=0)),e);var P=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),Sr=(r,e)=>{for(var t in e)v(r,t,{get:e[t],enumerable:!0})},W=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of fr(e))!gr.call(r,i)&&i!==t&&v(r,i,{get:()=>e[i],enumerable:!(n=lr(e,i))||n.enumerable});return r};var A=(r,e,t)=>(t=r!=null?dr(yr(r)):{},W(e||!r||!r.__esModule?v(t,"default",{value:r,enumerable:!0}):t,r)),Fr=r=>W(v({},"__esModule",{value:!0}),r);var c=hr(()=>{"use strict"});var E=P((ie,m)=>{"use strict";c();var X=9007199254740991,K=function(r){return r}();function br(r){return r===K}function V(r){return typeof r=="string"||Object.prototype.toString.call(r)=="[object String]"}function Pr(r){return Object.prototype.toString.call(r)=="[object Date]"}function U(r){return r!==null&&typeof r=="object"}function N(r){return typeof r=="function"}function Tr(r){return typeof r=="number"&&r>-1&&r%1==0&&r<=X}function Ar(r){return Object.prototype.toString.call(r)=="[object Array]"}function $(r){return U(r)&&!N(r)&&Tr(r.length)}function _(r){return Object.prototype.toString.call(r)=="[object ArrayBuffer]"}function Er(r,e){return Array.prototype.map.call(r,e)}function wr(r,e){var t=K;return N(e)&&Array.prototype.every.call(r,function(n,i,a){var s=e(n,i,a);return s&&(t=n),!s}),t}function xr(r){return Object.assign.apply(null,arguments)}function Z(r){var e,t,n;if(V(r)){for(t=r.length,n=new Uint8Array(t),e=0;e<t;e++)n[e]=r.charCodeAt(e)&255;return n}return _(r)?new Uint8Array(r):U(r)&&_(r.buffer)?new Uint8Array(r.buffer):$(r)?new Uint8Array(r):U(r)&&N(r.toString)?Z(r.toString()):new Uint8Array}m.exports.MAX_SAFE_INTEGER=X;m.exports.isUndefined=br;m.exports.isString=V;m.exports.isObject=U;m.exports.isDateTime=Pr;m.exports.isFunction=N;m.exports.isArray=Ar;m.exports.isArrayLike=$;m.exports.isArrayBuffer=_;m.exports.map=Er;m.exports.find=wr;m.exports.extend=xr;m.exports.toUint8Array=Z});var w=P((ae,J)=>{"use strict";c();var L="\0";J.exports={NULL_CHAR:L,TMAGIC:"ustar"+L+"00",OLDGNU_MAGIC:"ustar "+L,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 j=P((ue,d)=>{"use strict";c();var Q=E(),p=w(),vr=512,G=p.TPERMALL,rr=0,er=0,H=[["name",100,0,function(r,e){return x(r[e[0]],e[1])},function(r,e,t){return F(r.slice(e,e+t[1]))}],["mode",8,100,function(r,e){var t=r[e[0]]||G;return t=t&p.TPERMMASK,T(t,e[1],G)},function(r,e,t){var n=y(r.slice(e,e+t[1]));return n&=p.TPERMMASK,n}],["uid",8,108,function(r,e){return T(r[e[0]],e[1],rr)},function(r,e,t){return y(r.slice(e,e+t[1]))}],["gid",8,116,function(r,e){return T(r[e[0]],e[1],er)},function(r,e,t){return y(r.slice(e,e+t[1]))}],["size",12,124,function(r,e){return T(r.data.length,e[1])},function(r,e,t){return y(r.slice(e,e+t[1]))}],["modifyTime",12,136,function(r,e){return D(r[e[0]],e[1])},function(r,e,t){return k(r.slice(e,e+t[1]))}],["checksum",8,148,function(r,e){return" "},function(r,e,t){return y(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 F(r.slice(e,e+t[1]))}],["ustar",8,257,function(r,e){return p.TMAGIC},function(r,e,t){return Ur(F(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 x(r[e[0]],e[1])},function(r,e,t){return F(r.slice(e,e+t[1]))}],["group",32,297,function(r,e){return x(r[e[0]],e[1])},function(r,e,t){return F(r.slice(e,e+t[1]))}],["majorNumber",8,329,function(r,e){return""},function(r,e,t){return y(r.slice(e,e+t[1]))}],["minorNumber",8,337,function(r,e){return""},function(r,e,t){return y(r.slice(e,e+t[1]))}],["prefix",131,345,function(r,e){return x(r[e[0]],e[1])},function(r,e,t){return F(r.slice(e,e+t[1]))}],["accessTime",12,476,function(r,e){return D(r[e[0]],e[1])},function(r,e,t){return k(r.slice(e,e+t[1]))}],["createTime",12,488,function(r,e){return D(r[e[0]],e[1])},function(r,e,t){return k(r.slice(e,e+t[1]))}]],tr=function(r){var e=r[r.length-1];return e[2]+e[1]}(H);function Ur(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 x(r,e){return e-=1,Q.isUndefined(r)&&(r=""),r=(""+r).substr(0,e),r+p.NULL_CHAR}function T(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 D(r,e){if(Q.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 T(r,e,0)}function F(r,e){var t=String.fromCharCode.apply(null,r);if(e)return t;var n=t.indexOf(p.NULL_CHAR);return n>=0?t.substr(0,n):t}function y(r){var e=String.fromCharCode.apply(null,r);return parseInt(e.replace(/^0+$/g,""),8)||0}function k(r){return r.length==0||r[0]==0?null:new Date(1e3*y(r))}function Nr(r,e,t){var n=parseInt(e,10)||0,i=Math.min(n+tr,r.length),a=0,s=0,o=0;t&&H.every(function(g){return g[0]=="checksum"?(s=n+g[2],o=s+g[1],!1):!0});for(var u=32,l=n;l<i;l++){var R=l>=s&&l<o?u:r[l];a=(a+R)%262144}return a}d.exports.recordSize=vr;d.exports.defaultFileMode=G;d.exports.defaultUid=rr;d.exports.defaultGid=er;d.exports.posixHeader=H;d.exports.effectiveHeaderSize=tr;d.exports.calculateChecksum=Nr;d.exports.formatTarString=x;d.exports.formatTarNumber=T;d.exports.formatTarDateTime=D;d.exports.parseTarString=F;d.exports.parseTarNumber=y;d.exports.parseTarDateTime=k});var ar=P((pe,or)=>{"use strict";c();var Dr=w(),M=E(),S=j();function nr(r){return S.recordSize}function ir(r){return Math.ceil(r.data.length/S.recordSize)*S.recordSize}function kr(r){var e=0;return r.forEach(function(t){e+=nr(t)+ir(t)}),e+=S.recordSize*2,new Uint8Array(e)}function Mr(r,e,t){t=parseInt(t)||0;var n=t;S.posixHeader.forEach(function(u){for(var l=u[3](e,u),R=l.length,g=0;g<R;g+=1)r[n+g]=l.charCodeAt(g)&255;n+=u[1]});var i=M.find(S.posixHeader,function(u){return u[0]=="checksum"});if(i){var a=S.calculateChecksum(r,t,!0),s=S.formatTarNumber(a,i[1]-2)+Dr.NULL_CHAR+" ";n=t+i[2];for(var o=0;o<s.length;o+=1)r[n]=s.charCodeAt(o)&255,n++}return t+nr(e)}function Or(r,e,t){return t=parseInt(t,10)||0,r.set(e.data,t),t+ir(e)}function zr(r){r=M.map(r,function(n){return M.extend({},n,{data:M.toUint8Array(n.data)})});var e=kr(r),t=0;return r.forEach(function(n){t=Mr(e,n,t),t=Or(e,n,t)}),e}or.exports.tar=zr});var ur=P((de,sr)=>{"use strict";c();var Cr=w(),q=E(),f=j(),Ir={extractData:!0,checkHeader:!0,checkChecksum:!0,checkFileSize:!0},Rr={size:!0,checksum:!0,ustar:!0},B={unexpectedEndOfFile:"Unexpected end of file.",fileCorrupted:"File is corrupted.",checksumCheckFailed:"Checksum check failed."};function _r(r){return f.recordSize}function Lr(r){return Math.ceil(r/f.recordSize)*f.recordSize}function Gr(r,e){for(var t=e,n=Math.min(r.length,e+f.recordSize*2),i=t;i<n;i++)if(r[i]!=0)return!1;return!0}function Hr(r,e,t){if(r.length-e<f.recordSize){if(t.checkFileSize)throw new Error(B.unexpectedEndOfFile);return null}e=parseInt(e)||0;var n={},i=e;if(f.posixHeader.forEach(function(o){n[o[0]]=o[4](r,i,o),i+=o[1]}),n.type!=0&&(n.size=0),t.checkHeader&&f.posixHeader.forEach(function(o){if(q.isFunction(o[5])&&!o[5](n,o)){var u=new Error(B.fileCorrupted);throw u.data={offset:e+o[2],field:o[0]},u}}),t.checkChecksum){var a=f.calculateChecksum(r,e,!0);if(a!=n.checksum){var s=new Error(B.checksumCheckFailed);throw s.data={offset:e,header:n,checksum:a},s}}return n}function jr(r,e,t,n){return n.extractData?t.size<=0?new Uint8Array:r.slice(e,e+t.size):null}function Br(r,e){var t={};return f.posixHeader.forEach(function(n){var i=n[0];Rr[i]||(t[i]=r[i])}),t.isOldGNUFormat=r.ustar==Cr.OLDGNU_MAGIC,e&&(t.data=e),t}function qr(r,e){e=q.extend({},Ir,e);for(var t=[],n=0,i=r.length;i-n>=f.recordSize;){r=q.toUint8Array(r);var a=Hr(r,n,e);if(!a)break;n+=_r(a);var s=jr(r,n,a,e);if(t.push(Br(a,s)),n+=Lr(a.size),Gr(r,n))break}return t}sr.exports.untar=qr});var pr=P((fe,cr)=>{"use strict";c();var Yr=E(),Wr=w(),Xr=ar(),Kr=ur();Yr.extend(cr.exports,Xr,Kr,Wr)});var ee={};Sr(ee,{NodeFS:()=>Y});module.exports=Fr(ee);c();var C=A(require("fs"),1),I=A(require("path"),1);c();c();var b=A(pr(),1);async function mr(r,e,t="pgdata",n="auto"){let i=$r(r,e),[a,s]=await Zr(i,n),o=t+(s?".tar.gz":".tar"),u=s?"application/x-gzip":"application/x-tar";return typeof File<"u"?new File([a],o,{type:u}):new Blob([a],{type:u})}function Vr(r,e){let t=[],n=i=>{r.readdir(i).forEach(s=>{if(s==="."||s==="..")return;let o=i+"/"+s,u=r.stat(o),l=r.isFile(u.mode)?r.readFile(o,{encoding:"binary"}):new Uint8Array(0);t.push({name:o.substring(e.length),mode:u.mode,size:u.size,type:r.isFile(u.mode)?b.REGTYPE:b.DIRTYPE,modifyTime:u.mtime,data:l}),r.isDir(u.mode)&&n(o)})};return n(e),t}function $r(r,e){let t=Vr(r,e);return(0,b.tar)(t)}async function Zr(r,e="auto"){if(e==="none")return[r,!1];if(typeof CompressionStream<"u")return[await Jr(r),!0];if(typeof process<"u"&&process.versions&&process.versions.node)return[await Qr(r),!0];if(e==="auto")return[r,!1];throw new Error("Compression not supported in this environment")}async function Jr(r){let e=new CompressionStream("gzip"),t=e.writable.getWriter(),n=e.readable.getReader();t.write(r),t.close();let i=[];for(;;){let{value:o,done:u}=await n.read();if(u)break;o&&i.push(o)}let a=new Uint8Array(i.reduce((o,u)=>o+u.length,0)),s=0;return i.forEach(o=>{a.set(o,s),s+=o.length}),a}async function Qr(r){let{promisify:e}=await import("util"),{gzip:t}=await import("zlib");return await e(t)(r)}var re="/tmp/pglite",z=re+"/base",O=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 mr(this.pg.Module.FS,z,e,t)}};var Y=class extends O{constructor(e){super(e),this.rootDir=I.resolve(e),C.existsSync(I.join(this.rootDir))||C.mkdirSync(this.rootDir)}async init(e,t){return this.pg=e,{emscriptenOpts:{...t,preRun:[...t.preRun||[],i=>{let a=i.FS.filesystems.NODEFS;i.FS.mkdir(z),i.FS.mount(a,{root:this.rootDir},z)}]}}}async closeFs(){this.pg.Module.FS.quit()}};0&&(module.exports={NodeFS});
//# sourceMappingURL=nodefs.cjs.map
;