import{b as Tr,d as Ut,e as Fr,f as Rr,g as He,h as Pe,i as _t,j as Ot}from"./chunk-T24MUNUQ.js";import{a as Nt,b as Lt,c as Sr,d as Pr}from"./chunk-OUZ4AEES.js";import{a as Ve,b as Se,c as Ct,d,e as x,f as B,g as y,i as m}from"./chunk-ZYB3MGPW.js";var Qt=Ve(Me=>{"use strict";m();Me.byteLength=Or;Me.toByteArray=Lr;Me.fromByteArray=Gr;var _=[],S=[],_r=typeof Uint8Array<"u"?Uint8Array:Array,it="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(W=0,Gt=it.length;W0)throw new Error("Invalid string. Length must be a multiple of 4");var t=r.indexOf("=");t===-1&&(t=e);var n=t===e?0:4-t%4;return[t,n]}function Or(r){var e=$t(r),t=e[0],n=e[1];return(t+n)*3/4-n}function Nr(r,e,t){return(e+t)*3/4-t}function Lr(r){var e,t=$t(r),n=t[0],i=t[1],s=new _r(Nr(r,n,i)),o=0,a=i>0?n-4:n,c;for(c=0;c>16&255,s[o++]=e>>8&255,s[o++]=e&255;return i===2&&(e=S[r.charCodeAt(c)]<<2|S[r.charCodeAt(c+1)]>>4,s[o++]=e&255),i===1&&(e=S[r.charCodeAt(c)]<<10|S[r.charCodeAt(c+1)]<<4|S[r.charCodeAt(c+2)]>>2,s[o++]=e>>8&255,s[o++]=e&255),s}function kr(r){return _[r>>18&63]+_[r>>12&63]+_[r>>6&63]+_[r&63]}function vr(r,e,t){for(var n,i=[],s=e;sa?a:o+s));return n===1?(e=r[t-1],i.push(_[e>>2]+_[e<<4&63]+"==")):n===2&&(e=(r[t-2]<<8)+r[t-1],i.push(_[e>>10]+_[e>>4&63]+_[e<<2&63]+"=")),i.join("")}});var zt=Ve(st=>{"use strict";m();st.read=function(r,e,t,n,i){var s,o,a=i*8-n-1,c=(1<>1,l=-7,p=t?i-1:0,T=t?-1:1,w=r[e+p];for(p+=T,s=w&(1<<-l)-1,w>>=-l,l+=a;l>0;s=s*256+r[e+p],p+=T,l-=8);for(o=s&(1<<-l)-1,s>>=-l,l+=n;l>0;o=o*256+r[e+p],p+=T,l-=8);if(s===0)s=1-f;else{if(s===c)return o?NaN:(w?-1:1)*(1/0);o=o+Math.pow(2,n),s=s-f}return(w?-1:1)*o*Math.pow(2,s-n)};st.write=function(r,e,t,n,i,s){var o,a,c,f=s*8-i-1,l=(1<>1,T=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=n?0:s-1,R=n?1:-1,Fe=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,o=l):(o=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-o))<1&&(o--,c*=2),o+p>=1?e+=T/c:e+=T*Math.pow(2,1-p),e*c>=2&&(o++,c/=2),o+p>=l?(a=0,o=l):o+p>=1?(a=(e*c-1)*Math.pow(2,i),o=o+p):(a=e*Math.pow(2,p-1)*Math.pow(2,i),o=0));i>=8;r[t+w]=a&255,w+=R,a/=256,i-=8);for(o=o<0;r[t+w]=o&255,w+=R,o/=256,f-=8);r[t+w-R]|=Fe*128}});var or=Ve(ne=>{"use strict";m();var ot=Qt(),te=zt(),qt=typeof Symbol=="function"&&typeof Symbol.for=="function"?Symbol.for("nodejs.util.inspect.custom"):null;ne.Buffer=u;ne.SlowBuffer=jr;ne.INSPECT_MAX_BYTES=50;var De=2147483647;ne.kMaxLength=De;u.TYPED_ARRAY_SUPPORT=$r();!u.TYPED_ARRAY_SUPPORT&&typeof console<"u"&&typeof console.error=="function"&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function $r(){try{let r=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(r,e),r.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}});Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function N(r){if(r>De)throw new RangeError('The value "'+r+'" is invalid for option "size"');let e=new Uint8Array(r);return Object.setPrototypeOf(e,u.prototype),e}function u(r,e,t){if(typeof r=="number"){if(typeof e=="string")throw new TypeError('The "string" argument must be of type string. Received type number');return ft(r)}return Ht(r,e,t)}u.poolSize=8192;function Ht(r,e,t){if(typeof r=="string")return zr(r,e);if(ArrayBuffer.isView(r))return qr(r);if(r==null)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r);if(O(r,ArrayBuffer)||r&&O(r.buffer,ArrayBuffer)||typeof SharedArrayBuffer<"u"&&(O(r,SharedArrayBuffer)||r&&O(r.buffer,SharedArrayBuffer)))return ut(r,e,t);if(typeof r=="number")throw new TypeError('The "value" argument must not be of type number. Received type number');let n=r.valueOf&&r.valueOf();if(n!=null&&n!==r)return u.from(n,e,t);let i=Wr(r);if(i)return i;if(typeof Symbol<"u"&&Symbol.toPrimitive!=null&&typeof r[Symbol.toPrimitive]=="function")return u.from(r[Symbol.toPrimitive]("string"),e,t);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof r)}u.from=function(r,e,t){return Ht(r,e,t)};Object.setPrototypeOf(u.prototype,Uint8Array.prototype);Object.setPrototypeOf(u,Uint8Array);function Yt(r){if(typeof r!="number")throw new TypeError('"size" argument must be of type number');if(r<0)throw new RangeError('The value "'+r+'" is invalid for option "size"')}function Qr(r,e,t){return Yt(r),r<=0?N(r):e!==void 0?typeof t=="string"?N(r).fill(e,t):N(r).fill(e):N(r)}u.alloc=function(r,e,t){return Qr(r,e,t)};function ft(r){return Yt(r),N(r<0?0:lt(r)|0)}u.allocUnsafe=function(r){return ft(r)};u.allocUnsafeSlow=function(r){return ft(r)};function zr(r,e){if((typeof e!="string"||e==="")&&(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);let t=Kt(r,e)|0,n=N(t),i=n.write(r,e);return i!==t&&(n=n.slice(0,i)),n}function at(r){let e=r.length<0?0:lt(r.length)|0,t=N(e);for(let n=0;n=De)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+De.toString(16)+" bytes");return r|0}function jr(r){return+r!=r&&(r=0),u.alloc(+r)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype};u.compare=function(e,t){if(O(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),O(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(e)||!u.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;let n=e.length,i=t.length;for(let s=0,o=Math.min(n,i);si.length?(u.isBuffer(o)||(o=u.from(o)),o.copy(i,s)):Uint8Array.prototype.set.call(i,o,s);else if(u.isBuffer(o))o.copy(i,s);else throw new TypeError('"list" argument must be an Array of Buffers');s+=o.length}return i};function Kt(r,e){if(u.isBuffer(r))return r.length;if(ArrayBuffer.isView(r)||O(r,ArrayBuffer))return r.byteLength;if(typeof r!="string")throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof r);let t=r.length,n=arguments.length>2&&arguments[2]===!0;if(!n&&t===0)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return t;case"utf8":case"utf-8":return ct(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return t*2;case"hex":return t>>>1;case"base64":return sr(r).length;default:if(i)return n?-1:ct(r).length;e=(""+e).toLowerCase(),i=!0}}u.byteLength=Kt;function Vr(r,e,t){let n=!1;if((e===void 0||e<0)&&(e=0),e>this.length||((t===void 0||t>this.length)&&(t=this.length),t<=0)||(t>>>=0,e>>>=0,t<=e))return"";for(r||(r="utf8");;)switch(r){case"hex":return nn(this,e,t);case"utf8":case"utf-8":return Jt(this,e,t);case"ascii":return tn(this,e,t);case"latin1":case"binary":return rn(this,e,t);case"base64":return Zr(this,e,t);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return sn(this,e,t);default:if(n)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),n=!0}}u.prototype._isBuffer=!0;function j(r,e,t){let n=r[e];r[e]=r[t],r[t]=n}u.prototype.swap16=function(){let e=this.length;if(e%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let t=0;tt&&(e+=" ... "),""};qt&&(u.prototype[qt]=u.prototype.inspect);u.prototype.compare=function(e,t,n,i,s){if(O(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),i===void 0&&(i=0),s===void 0&&(s=this.length),t<0||n>e.length||i<0||s>this.length)throw new RangeError("out of range index");if(i>=s&&t>=n)return 0;if(i>=s)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,i>>>=0,s>>>=0,this===e)return 0;let o=s-i,a=n-t,c=Math.min(o,a),f=this.slice(i,s),l=e.slice(t,n);for(let p=0;p2147483647?t=2147483647:t<-2147483648&&(t=-2147483648),t=+t,ht(t)&&(t=i?0:r.length-1),t<0&&(t=r.length+t),t>=r.length){if(i)return-1;t=r.length-1}else if(t<0)if(i)t=0;else return-1;if(typeof e=="string"&&(e=u.from(e,n)),u.isBuffer(e))return e.length===0?-1:Wt(r,e,t,n,i);if(typeof e=="number")return e=e&255,typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(r,e,t):Uint8Array.prototype.lastIndexOf.call(r,e,t):Wt(r,[e],t,n,i);throw new TypeError("val must be string, number or Buffer")}function Wt(r,e,t,n,i){let s=1,o=r.length,a=e.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(r.length<2||e.length<2)return-1;s=2,o/=2,a/=2,t/=2}function c(l,p){return s===1?l[p]:l.readUInt16BE(p*s)}let f;if(i){let l=-1;for(f=t;fo&&(t=o-a),f=t;f>=0;f--){let l=!0;for(let p=0;pi&&(n=i)):n=i;let s=e.length;n>s/2&&(n=s/2);let o;for(o=0;o>>0,isFinite(n)?(n=n>>>0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");let s=this.length-t;if((n===void 0||n>s)&&(n=s),e.length>0&&(n<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");let o=!1;for(;;)switch(i){case"hex":return Hr(this,e,t,n);case"utf8":case"utf-8":return Yr(this,e,t,n);case"ascii":case"latin1":case"binary":return Kr(this,e,t,n);case"base64":return Xr(this,e,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Jr(this,e,t,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}};u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Zr(r,e,t){return e===0&&t===r.length?ot.fromByteArray(r):ot.fromByteArray(r.slice(e,t))}function Jt(r,e,t){t=Math.min(r.length,t);let n=[],i=e;for(;i239?4:s>223?3:s>191?2:1;if(i+a<=t){let c,f,l,p;switch(a){case 1:s<128&&(o=s);break;case 2:c=r[i+1],(c&192)===128&&(p=(s&31)<<6|c&63,p>127&&(o=p));break;case 3:c=r[i+1],f=r[i+2],(c&192)===128&&(f&192)===128&&(p=(s&15)<<12|(c&63)<<6|f&63,p>2047&&(p<55296||p>57343)&&(o=p));break;case 4:c=r[i+1],f=r[i+2],l=r[i+3],(c&192)===128&&(f&192)===128&&(l&192)===128&&(p=(s&15)<<18|(c&63)<<12|(f&63)<<6|l&63,p>65535&&p<1114112&&(o=p))}}o===null?(o=65533,a=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),i+=a}return en(n)}var jt=4096;function en(r){let e=r.length;if(e<=jt)return String.fromCharCode.apply(String,r);let t="",n=0;for(;nn)&&(t=n);let i="";for(let s=e;sn&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),tt)throw new RangeError("Trying to access beyond buffer length")}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,t,n){e=e>>>0,t=t>>>0,n||E(e,t,this.length);let i=this[e],s=1,o=0;for(;++o>>0,t=t>>>0,n||E(e,t,this.length);let i=this[e+--t],s=1;for(;t>0&&(s*=256);)i+=this[e+--t]*s;return i};u.prototype.readUint8=u.prototype.readUInt8=function(e,t){return e=e>>>0,t||E(e,1,this.length),this[e]};u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,t){return e=e>>>0,t||E(e,2,this.length),this[e]|this[e+1]<<8};u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,t){return e=e>>>0,t||E(e,2,this.length),this[e]<<8|this[e+1]};u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,t){return e=e>>>0,t||E(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216};u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,t){return e=e>>>0,t||E(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])};u.prototype.readBigUInt64LE=v(function(e){e=e>>>0,re(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&be(e,this.length-8);let i=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,s=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(i)+(BigInt(s)<>>0,re(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&be(e,this.length-8);let i=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],s=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(i)<>>0,t=t>>>0,n||E(e,t,this.length);let i=this[e],s=1,o=0;for(;++o=s&&(i-=Math.pow(2,8*t)),i};u.prototype.readIntBE=function(e,t,n){e=e>>>0,t=t>>>0,n||E(e,t,this.length);let i=t,s=1,o=this[e+--i];for(;i>0&&(s*=256);)o+=this[e+--i]*s;return s*=128,o>=s&&(o-=Math.pow(2,8*t)),o};u.prototype.readInt8=function(e,t){return e=e>>>0,t||E(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]};u.prototype.readInt16LE=function(e,t){e=e>>>0,t||E(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n};u.prototype.readInt16BE=function(e,t){e=e>>>0,t||E(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n};u.prototype.readInt32LE=function(e,t){return e=e>>>0,t||E(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24};u.prototype.readInt32BE=function(e,t){return e=e>>>0,t||E(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]};u.prototype.readBigInt64LE=v(function(e){e=e>>>0,re(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&be(e,this.length-8);let i=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(i)<>>0,re(e,"offset");let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&be(e,this.length-8);let i=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(i)<>>0,t||E(e,4,this.length),te.read(this,e,!0,23,4)};u.prototype.readFloatBE=function(e,t){return e=e>>>0,t||E(e,4,this.length),te.read(this,e,!1,23,4)};u.prototype.readDoubleLE=function(e,t){return e=e>>>0,t||E(e,8,this.length),te.read(this,e,!0,52,8)};u.prototype.readDoubleBE=function(e,t){return e=e>>>0,t||E(e,8,this.length),te.read(this,e,!1,52,8)};function F(r,e,t,n,i,s){if(!u.isBuffer(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||er.length)throw new RangeError("Index out of range")}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;F(this,e,t,n,a,0)}let s=1,o=0;for(this[t]=e&255;++o>>0,n=n>>>0,!i){let a=Math.pow(2,8*n)-1;F(this,e,t,n,a,0)}let s=n-1,o=1;for(this[t+s]=e&255;--s>=0&&(o*=256);)this[t+s]=e/o&255;return t+n};u.prototype.writeUint8=u.prototype.writeUInt8=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,1,255,0),this[t]=e&255,t+1};u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2};u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2};u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4};u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function Zt(r,e,t,n,i){ir(e,n,i,r,t,7);let s=Number(e&BigInt(4294967295));r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s,s=s>>8,r[t++]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,o=o>>8,r[t++]=o,t}function er(r,e,t,n,i){ir(e,n,i,r,t,7);let s=Number(e&BigInt(4294967295));r[t+7]=s,s=s>>8,r[t+6]=s,s=s>>8,r[t+5]=s,s=s>>8,r[t+4]=s;let o=Number(e>>BigInt(32)&BigInt(4294967295));return r[t+3]=o,o=o>>8,r[t+2]=o,o=o>>8,r[t+1]=o,o=o>>8,r[t]=o,t+8}u.prototype.writeBigUInt64LE=v(function(e,t=0){return Zt(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeBigUInt64BE=v(function(e,t=0){return er(this,e,t,BigInt(0),BigInt("0xffffffffffffffff"))});u.prototype.writeIntLE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);F(this,e,t,n,c-1,-c)}let s=0,o=1,a=0;for(this[t]=e&255;++s>0)-a&255;return t+n};u.prototype.writeIntBE=function(e,t,n,i){if(e=+e,t=t>>>0,!i){let c=Math.pow(2,8*n-1);F(this,e,t,n,c-1,-c)}let s=n-1,o=1,a=0;for(this[t+s]=e&255;--s>=0&&(o*=256);)e<0&&a===0&&this[t+s+1]!==0&&(a=1),this[t+s]=(e/o>>0)-a&255;return t+n};u.prototype.writeInt8=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1};u.prototype.writeInt16LE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2};u.prototype.writeInt16BE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2};u.prototype.writeInt32LE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4};u.prototype.writeInt32BE=function(e,t,n){return e=+e,t=t>>>0,n||F(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};u.prototype.writeBigInt64LE=v(function(e,t=0){return Zt(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});u.prototype.writeBigInt64BE=v(function(e,t=0){return er(this,e,t,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))});function tr(r,e,t,n,i,s){if(t+n>r.length)throw new RangeError("Index out of range");if(t<0)throw new RangeError("Index out of range")}function rr(r,e,t,n,i){return e=+e,t=t>>>0,i||tr(r,e,t,4,34028234663852886e22,-34028234663852886e22),te.write(r,e,t,n,23,4),t+4}u.prototype.writeFloatLE=function(e,t,n){return rr(this,e,t,!0,n)};u.prototype.writeFloatBE=function(e,t,n){return rr(this,e,t,!1,n)};function nr(r,e,t,n,i){return e=+e,t=t>>>0,i||tr(r,e,t,8,17976931348623157e292,-17976931348623157e292),te.write(r,e,t,n,52,8),t+8}u.prototype.writeDoubleLE=function(e,t,n){return nr(this,e,t,!0,n)};u.prototype.writeDoubleBE=function(e,t,n){return nr(this,e,t,!1,n)};u.prototype.copy=function(e,t,n,i){if(!u.isBuffer(e))throw new TypeError("argument should be a Buffer");if(n||(n=0),!i&&i!==0&&(i=this.length),t>=e.length&&(t=e.length),t||(t=0),i>0&&i=this.length)throw new RangeError("Index out of range");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),e.length-t>>0,n=n===void 0?this.length:n>>>0,e||(e=0);let s;if(typeof e=="number")for(s=t;s2**32?i=Vt(String(t)):typeof t=="bigint"&&(i=String(t),(t>BigInt(2)**BigInt(32)||t<-(BigInt(2)**BigInt(32)))&&(i=Vt(i)),i+="n"),n+=` It must be ${e}. Received ${i}`,n},RangeError);function Vt(r){let e="",t=r.length,n=r[0]==="-"?1:0;for(;t>=n+4;t-=3)e=`_${r.slice(t-3,t)}${e}`;return`${r.slice(0,t)}${e}`}function on(r,e,t){re(e,"offset"),(r[e]===void 0||r[e+t]===void 0)&&be(e,r.length-(t+1))}function ir(r,e,t,n,i,s){if(r>t||r3?e===0||e===BigInt(0)?a=`>= 0${o} and < 2${o} ** ${(s+1)*8}${o}`:a=`>= -(2${o} ** ${(s+1)*8-1}${o}) and < 2 ** ${(s+1)*8-1}${o}`:a=`>= ${e}${o} and <= ${t}${o}`,new ee.ERR_OUT_OF_RANGE("value",a,r)}on(n,i,s)}function re(r,e){if(typeof r!="number")throw new ee.ERR_INVALID_ARG_TYPE(e,"number",r)}function be(r,e,t){throw Math.floor(r)!==r?(re(r,t),new ee.ERR_OUT_OF_RANGE(t||"offset","an integer",r)):e<0?new ee.ERR_BUFFER_OUT_OF_BOUNDS:new ee.ERR_OUT_OF_RANGE(t||"offset",`>= ${t?1:0} and <= ${e}`,r)}var an=/[^+/0-9A-Za-z-_]/g;function un(r){if(r=r.split("=")[0],r=r.trim().replace(an,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function ct(r,e){e=e||1/0;let t,n=r.length,i=null,s=[];for(let o=0;o55295&&t<57344){if(!i){if(t>56319){(e-=3)>-1&&s.push(239,191,189);continue}else if(o+1===n){(e-=3)>-1&&s.push(239,191,189);continue}i=t;continue}if(t<56320){(e-=3)>-1&&s.push(239,191,189),i=t;continue}t=(i-55296<<10|t-56320)+65536}else i&&(e-=3)>-1&&s.push(239,191,189);if(i=null,t<128){if((e-=1)<0)break;s.push(t)}else if(t<2048){if((e-=2)<0)break;s.push(t>>6|192,t&63|128)}else if(t<65536){if((e-=3)<0)break;s.push(t>>12|224,t>>6&63|128,t&63|128)}else if(t<1114112){if((e-=4)<0)break;s.push(t>>18|240,t>>12&63|128,t>>6&63|128,t&63|128)}else throw new Error("Invalid code point")}return s}function cn(r){let e=[];for(let t=0;t>8,i=t%256,s.push(i),s.push(n);return s}function sr(r){return ot.toByteArray(un(r))}function Ce(r,e,t,n){let i;for(i=0;i=e.length||i>=r.length);++i)e[i+t]=r[i];return i}function O(r,e){return r instanceof e||r!=null&&r.constructor!=null&&r.constructor.name!=null&&r.constructor.name===e.name}function ht(r){return r!==r}var ln=function(){let r="0123456789abcdef",e=new Array(256);for(let t=0;t<16;++t){let n=t*16;for(let i=0;i<16;++i)e[n+i]=r[t]+r[i]}return e}();function v(r){return typeof BigInt>"u"?pn:r}function pn(){throw new Error("BigInt not supported")}});m();m();m();var Oi=new Error("timeout while waiting for mutex to become available"),Ni=new Error("mutex already locked"),Mr=new Error("request for lock canceled"),Dr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(o){o(s)})}return new(t||(t=Promise))(function(s,o){function a(l){try{f(n.next(l))}catch(p){o(p)}}function c(l){try{f(n.throw(l))}catch(p){o(p)}}function f(l){l.done?s(l.value):i(l.value).then(a,c)}f((n=n.apply(r,e||[])).next())})},Ye=class{constructor(e,t=Mr){this._value=e,this._cancelError=t,this._weightedQueues=[],this._weightedWaiters=[]}acquire(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((t,n)=>{this._weightedQueues[e-1]||(this._weightedQueues[e-1]=[]),this._weightedQueues[e-1].push({resolve:t,reject:n}),this._dispatch()})}runExclusive(e,t=1){return Dr(this,void 0,void 0,function*(){let[n,i]=yield this.acquire(t);try{return yield e(n)}finally{i()}})}waitForUnlock(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise(t=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),this._weightedWaiters[e-1].push(t),this._dispatch()})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatch()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatch()}cancel(){this._weightedQueues.forEach(e=>e.forEach(t=>t.reject(this._cancelError))),this._weightedQueues=[]}_dispatch(){var e;for(let t=this._value;t>0;t--){let n=(e=this._weightedQueues[t-1])===null||e===void 0?void 0:e.shift();if(!n)continue;let i=this._value,s=t;this._value-=t,t=this._value+1,n.resolve([i,this._newReleaser(s)])}this._drainUnlockWaiters()}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){for(let e=this._value;e>0;e--)this._weightedWaiters[e-1]&&(this._weightedWaiters[e-1].forEach(t=>t()),this._weightedWaiters[e-1]=[])}},Cr=function(r,e,t,n){function i(s){return s instanceof t?s:new t(function(o){o(s)})}return new(t||(t=Promise))(function(s,o){function a(l){try{f(n.next(l))}catch(p){o(p)}}function c(l){try{f(n.throw(l))}catch(p){o(p)}}function f(l){l.done?s(l.value):i(l.value).then(a,c)}f((n=n.apply(r,e||[])).next())})},Q=class{constructor(e){this._semaphore=new Ye(1,e)}acquire(){return Cr(this,void 0,void 0,function*(){let[,e]=yield this._semaphore.acquire();return e})}runExclusive(e){return this._semaphore.runExclusive(()=>e())}isLocked(){return this._semaphore.isLocked()}waitForUnlock(){return this._semaphore.waitForUnlock()}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}};m();import Ur from"./postgres.js";var kt=Ur;var mr={};Se(mr,{parseResults:()=>Qe});m();var vt={};Se(vt,{AuthenticationMD5Password:()=>ye,BackendKeyDataMessage:()=>me,CommandCompleteMessage:()=>U,CopyDataMessage:()=>fe,CopyResponse:()=>le,DataRowMessage:()=>k,DatabaseError:()=>C,Field:()=>pe,NoticeMessage:()=>q,NotificationResponseMessage:()=>z,ParameterDescriptionMessage:()=>he,ParameterStatusMessage:()=>de,ReadyForQueryMessage:()=>ge,RowDescriptionMessage:()=>L,bindComplete:()=>Xe,closeComplete:()=>Je,copyDone:()=>nt,emptyQuery:()=>rt,noData:()=>Ze,parseComplete:()=>Ke,portalSuspended:()=>et,replicationStart:()=>tt});m();var Ke={name:"parseComplete",length:5},Xe={name:"bindComplete",length:5},Je={name:"closeComplete",length:5},Ze={name:"noData",length:5},et={name:"portalSuspended",length:5},tt={name:"replicationStart",length:4},rt={name:"emptyQuery",length:4},nt={name:"copyDone",length:4},C=class extends Error{constructor(t,n,i){super(t);this.length=n;this.name=i}},fe=class{constructor(e,t){this.length=e;this.chunk=t;this.name="copyData"}},le=class{constructor(e,t,n,i){this.length=e;this.name=t;this.binary=n;this.columnTypes=new Array(i)}},pe=class{constructor(e,t,n,i,s,o,a){this.name=e;this.tableID=t;this.columnID=n;this.dataTypeID=i;this.dataTypeSize=s;this.dataTypeModifier=o;this.format=a}},L=class{constructor(e,t){this.length=e;this.fieldCount=t;this.name="rowDescription";this.fields=new Array(this.fieldCount)}},he=class{constructor(e,t){this.length=e;this.parameterCount=t;this.name="parameterDescription";this.dataTypeIDs=new Array(this.parameterCount)}},de=class{constructor(e,t,n){this.length=e;this.parameterName=t;this.parameterValue=n;this.name="parameterStatus"}},ye=class{constructor(e,t){this.length=e;this.salt=t;this.name="authenticationMD5Password"}},me=class{constructor(e,t,n){this.length=e;this.processID=t;this.secretKey=n;this.name="backendKeyData"}},z=class{constructor(e,t,n,i){this.length=e;this.processId=t;this.channel=n;this.payload=i;this.name="notification"}},ge=class{constructor(e,t){this.length=e;this.status=t;this.name="readyForQuery"}},U=class{constructor(e,t){this.length=e;this.text=t;this.name="commandComplete"}},k=class{constructor(e,t){this.length=e;this.fields=t;this.name="dataRow";this.fieldCount=t.length}},q=class{constructor(e,t){this.length=e;this.message=t;this.name="notice"}};var yr={};Se(yr,{ABSTIME:()=>Tn,ACLITEM:()=>Un,BIT:()=>kn,BOOL:()=>dt,BPCHAR:()=>_n,BYTEA:()=>Oe,CHAR:()=>ur,CID:()=>bn,CIDR:()=>An,CIRCLE:()=>Sn,DATE:()=>xt,FLOAT4:()=>bt,FLOAT8:()=>ke,GTSVECTOR:()=>ei,INET:()=>Cn,INT2:()=>yt,INT4:()=>mt,INT8:()=>we,INTERVAL:()=>Nn,JSON:()=>Le,JSONB:()=>It,MACADDR:()=>Dn,MACADDR8:()=>Pn,MONEY:()=>Mn,NUMERIC:()=>Gn,OID:()=>gt,PATH:()=>Bn,PG_DEPENDENCIES:()=>Xn,PG_LSN:()=>Yn,PG_NDISTINCT:()=>Kn,PG_NODE_TREE:()=>xn,POLYGON:()=>In,REFCURSOR:()=>$n,REGCLASS:()=>Wn,REGCONFIG:()=>ti,REGDICTIONARY:()=>ri,REGNAMESPACE:()=>ni,REGOPER:()=>zn,REGOPERATOR:()=>qn,REGPROC:()=>yn,REGPROCEDURE:()=>Qn,REGROLE:()=>ii,REGTYPE:()=>jn,RELTIME:()=>Fn,SMGR:()=>En,TEXT:()=>Ne,TID:()=>mn,TIME:()=>On,TIMESTAMP:()=>Et,TIMESTAMPTZ:()=>Bt,TIMETZ:()=>Ln,TINTERVAL:()=>Rn,TSQUERY:()=>Zn,TSVECTOR:()=>Jn,TXID_SNAPSHOT:()=>Hn,UUID:()=>Vn,VARBIT:()=>vn,VARCHAR:()=>wt,XID:()=>gn,XML:()=>wn,arrayTypes:()=>Ue,parseArray:()=>dr,parseType:()=>$e,parsers:()=>fr,serializeType:()=>Ge,serializerFor:()=>pr,serializerInstanceof:()=>lr,serializers:()=>_e,types:()=>cr});m();m();var ar=Ct(or(),1),g;globalThis.Buffer?g=globalThis.Buffer:g=ar.Buffer;var hn=globalThis.JSON.parse,dn=globalThis.JSON.stringify,dt=16,Oe=17,ur=18,we=20,yt=21,mt=23,yn=24,Ne=25,gt=26,mn=27,gn=28,bn=29,Le=114,wn=142,xn=194,En=210,Bn=602,In=604,An=650,bt=700,ke=701,Tn=702,Fn=703,Rn=704,Sn=718,Pn=774,Mn=790,Dn=829,Cn=869,Un=1033,_n=1042,wt=1043,xt=1082,On=1083,Et=1114,Bt=1184,Nn=1186,Ln=1266,kn=1560,vn=1562,Gn=1700,$n=1790,Qn=2202,zn=2203,qn=2204,Wn=2205,jn=2206,Vn=2950,Hn=2970,Yn=3220,Kn=3361,Xn=3402,Jn=3614,Zn=3615,ei=3642,ti=3734,ri=3769,It=3802,ni=4089,ii=4096,Ue={1001:Oe,1002:ur,1016:we,1005:yt,1007:mt,1009:Ne,1028:gt,199:Le,1021:bt,1022:ke,1015:wt,3807:It,1182:xt,1115:Et,1116:Bt},cr={string:{to:0,from:[Ne,wt],serialize:r=>r,parse:r=>r,forceTo:Ne},number:{to:0,from:[yt,mt,gt,bt,ke],serialize:r=>r.toString(),parse:r=>+r,forceTo:r=>Number.isInteger(r)?we:ke},bigint:{to:we,from:[we],js:[BigInt],serialize:r=>r.toString(),parse:r=>{let e=BigInt(r);return eNumber.MAX_SAFE_INTEGER?e:Number(e)}},json:{to:Le,from:[Le,It],serialize:r=>dn(r),parse:r=>hn(r)},boolean:{to:dt,from:[dt],serialize:r=>r===!0?"t":"f",parse:r=>r==="t"},date:{to:1184,from:[xt,Et,Bt],js:[Date],serialize:r=>(r instanceof Date?r:new Date(r)).toISOString(),parse:r=>new Date(r)},bytea:{to:Oe,from:[Oe],js:[Uint8Array,g],serialize:r=>"\\x"+g.from(r).toString("hex"),parse:r=>new Uint8Array(g.from(r.slice(2),"hex"))},array:{to:0,from:Object.keys(Ue).map(r=>+r),serialize:r=>hr(r),parse:(r,e)=>{let t;return e&&e in Ue&&(t=fr[Ue[e]]),dr(r,t)}}},ve=oi(cr),fr=ve.parsers,_e=ve.serializers,lr=ve.serializerInstanceof;function pr(r){if(Array.isArray(r))return _e.array;let e=_e[typeof r];if(e)return e;for(let[t,n]of lr)if(r instanceof t)return n;return _e.json}function Ge(r,e=!1){return r==null?[null,0]:pr(r)(r,e)}function si(r){return'"'+r.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function hr(r){let e="{";for(let t=0;t0&&(e=e+","),r[t]===null||typeof r[t]>"u")e=e+"NULL";else if(Array.isArray(r[t]))e=e+hr(r[t]);else if(ArrayBuffer.isView(r[t])){let n=r[t];if(!(n instanceof g)){let i=g.from(n.buffer,n.byteOffset,n.byteLength);i.length===n.byteLength?n=i:n=i.slice(n.byteOffset,n.byteOffset+n.byteLength)}e+="\\\\x"+n.toString("hex")}else e+=si(Ge(r[t])[0]);return e=e+"}",e}function dr(r,e){let t=0,n=null,i="",s=!1,o=0,a;function c(f){let l=[];for(;t{let{to:s,from:o,serialize:a,parse:c=null,forceTo:f}=r[i],l=(p,T=!1)=>[a(p),T&&f?typeof f=="function"?f(p):f:s];return t[s]=l,t[i]=l,r[i].js&&r[i].js.forEach(p=>n.push([p,l])),c&&(Array.isArray(o)?o.forEach(p=>e[p]=c):e[o]=c,e[i]=c),{parsers:e,serializers:t,serializerInstanceof:n}},{parsers:{},serializers:{},serializerInstanceof:[]})}function Qe(r,e,t){let n=[],i={rows:[],fields:[]},s=0,o=r.filter(a=>a instanceof L||a instanceof k||a instanceof U);return o.forEach((a,c)=>{a instanceof L?i.fields=a.fields.map(f=>({name:f.name,dataTypeID:f.dataTypeID})):a instanceof k&&i?e?.rowMode==="array"?i.rows.push(a.fields.map((f,l)=>$e(f,i.fields[l].dataTypeID,e?.parsers))):i.rows.push(Object.fromEntries(a.fields.map((f,l)=>[i.fields[l].name,$e(f,i.fields[l].dataTypeID,e?.parsers)]))):a instanceof U&&(s+=ai(a),c===o.length-1?n.push({...i,affectedRows:s,...t?{blob:t}:{}}):n.push(i),i={rows:[],fields:[]})}),n.length===0&&n.push({rows:[],fields:[]}),n}function ai(r){let e=r.text.split(" ");switch(e[0]){case"INSERT":return parseInt(e[2],10);case"UPDATE":case"DELETE":return parseInt(e[1],10);default:return 0}}m();var gr=Ct(Tr(),1);async function At(r){if(Nt){let e=await import("fs"),t=await import("zlib"),{Writable:n}=await import("stream"),{pipeline:i}=await import("stream/promises");if(!e.existsSync(r))throw new Error(`Extension bundle not found: ${r}`);let s=t.createGunzip(),o=[];return await i(e.createReadStream(r),s,new n({write(a,c,f){o.push(a),f()}})),new Blob(o)}else{let e=await fetch(r.toString());if(!e.ok||!e.body)return null;if(e.headers.get("Content-Encoding")==="gzip")return e.blob();{let t=new DecompressionStream("gzip");return new Response(e.body.pipeThrough(t)).blob()}}}async function br(r,e){for(let t in r.pg_extensions){let n;try{n=await r.pg_extensions[t]}catch(i){console.error("Failed to fetch extension:",t,i);continue}if(n){let i=new Uint8Array(await n.arrayBuffer());ui(r,t,i,e)}else console.error("Could not get binary data for extension:",t)}}function ui(r,e,t,n){gr.default.untar(t).forEach(s=>{if(!s.name.startsWith(".")){let o=r.WASM_PREFIX+"/"+s.name;if(s.name.endsWith(".so")){let a=(...f)=>{n("pgfs:ext OK",o,f)},c=(...f)=>{n("pgfs:ext FAIL",o,f)};r.FS.createPreloadedFile(ci(o),s.name.split("/").pop().slice(0,-3),s.data,!0,!0,a,c,!1)}else r.FS.writeFile(o,s.data)}})}function ci(r){let e=r.lastIndexOf("/");return e>0?r.slice(0,e):r}var Br={};Se(Br,{DatabaseError:()=>C,parse:()=>_i,serialize:()=>P});m();m();m();var ie=class{constructor(e=256){this.size=e;this.offset=5;this.headerPosition=0;this.buffer=g.allocUnsafe(e)}ensure(e){var t=this.buffer.length-this.offset;if(t>1)+e;this.buffer=g.allocUnsafe(i),n.copy(this.buffer)}}addInt32(e){return this.ensure(4),this.buffer[this.offset++]=e>>>24&255,this.buffer[this.offset++]=e>>>16&255,this.buffer[this.offset++]=e>>>8&255,this.buffer[this.offset++]=e>>>0&255,this}addInt16(e){return this.ensure(2),this.buffer[this.offset++]=e>>>8&255,this.buffer[this.offset++]=e>>>0&255,this}addCString(e){if(!e)this.ensure(1);else{var t=g.byteLength(e);this.ensure(t+1),this.buffer.write(e,this.offset,"utf-8"),this.offset+=t}return this.buffer[this.offset++]=0,this}addString(e=""){var t=g.byteLength(e);return this.ensure(t),this.buffer.write(e,this.offset),this.offset+=t,this}add(e){return this.ensure(e.length),e.copy(this.buffer,this.offset),this.offset+=e.length,this}join(e){if(e){this.buffer[this.headerPosition]=e;let t=this.offset-(this.headerPosition+1);this.buffer.writeInt32BE(t,this.headerPosition+1)}return this.buffer.slice(e?0:5,this.offset)}flush(e){var t=this.join(e);return this.offset=5,this.headerPosition=0,this.buffer=g.allocUnsafe(this.size),t}};var b=new ie,fi=r=>{b.addInt16(3).addInt16(0);for(let n of Object.keys(r))b.addCString(n).addCString(r[n]);b.addCString("client_encoding").addCString("UTF8");var e=b.addCString("").flush(),t=e.length+4;return new ie().addInt32(t).add(e).flush()},li=()=>{let r=g.allocUnsafe(8);return r.writeInt32BE(8,0),r.writeInt32BE(80877103,4),r},pi=r=>b.addCString(r).flush(112),hi=function(r,e){return b.addCString(r).addInt32(g.byteLength(e)).addString(e),b.flush(112)},di=function(r){return b.addString(r).flush(112)},yi=r=>b.addCString(r).flush(81),wr=[],mi=r=>{let e=r.name||"";e.length>63&&(console.error("Warning! Postgres only supports 63 characters for query names."),console.error("You supplied %s (%s)",e,e.length),console.error("This can cause conflicts and silent errors executing queries"));let t=r.types||wr;for(var n=t.length,i=b.addCString(e).addCString(r.text).addInt16(n),s=0;s{let e=r.portal||"",t=r.statement||"",n=r.binary||!1,i=r.values||wr,s=i.length;return b.addCString(e).addCString(t),b.addInt16(s),gi(i,r.valueMapper),b.addInt16(s),b.add(se.flush()),b.addInt16(n?1:0),b.flush(66)},wi=g.from([69,0,0,0,9,0,0,0,0,0]),xi=r=>{if(!r||!r.portal&&!r.rows)return wi;let e=r.portal||"",t=r.rows||0,n=g.byteLength(e),i=4+n+1+4,s=g.allocUnsafe(1+i);return s[0]=69,s.writeInt32BE(i,1),s.write(e,5,"utf-8"),s[n+5]=0,s.writeUInt32BE(t,s.length-4),s},Ei=(r,e)=>{let t=g.allocUnsafe(16);return t.writeInt32BE(16,0),t.writeInt16BE(1234,4),t.writeInt16BE(5678,6),t.writeInt32BE(r,8),t.writeInt32BE(e,12),t},Tt=(r,e)=>{let n=4+g.byteLength(e)+1,i=g.allocUnsafe(1+n);return i[0]=r,i.writeInt32BE(n,1),i.write(e,5,"utf-8"),i[n]=0,i},Bi=b.addCString("P").flush(68),Ii=b.addCString("S").flush(68),Ai=r=>r.name?Tt(68,`${r.type}${r.name||""}`):r.type==="P"?Bi:Ii,Ti=r=>{let e=`${r.type}${r.name||""}`;return Tt(67,e)},Fi=r=>b.add(r).flush(100),Ri=r=>Tt(102,r),ze=r=>g.from([r,0,0,0,4]),Si=ze(72),Pi=ze(83),Mi=ze(88),Di=ze(99),P={startup:fi,password:pi,requestSsl:li,sendSASLInitialResponseMessage:hi,sendSCRAMClientFinalMessage:di,query:yi,parse:mi,bind:bi,execute:xi,describe:Ai,close:Ti,flush:()=>Si,sync:()=>Pi,end:()=>Mi,copyData:Fi,copyDone:()=>Di,copyFail:Ri,cancel:Ei};m();m();var Ci=g.allocUnsafe(0),qe=class{constructor(e=0){this.offset=e;this.buffer=Ci;this.encoding="utf-8"}setBuffer(e,t){this.offset=e,this.buffer=t}int16(){let e=this.buffer.readInt16BE(this.offset);return this.offset+=2,e}byte(){let e=this.buffer[this.offset];return this.offset++,e}int32(){let e=this.buffer.readInt32BE(this.offset);return this.offset+=4,e}string(e){let t=this.buffer.toString(this.encoding,this.offset,this.offset+e);return this.offset+=e,t}cstring(){let e=this.offset,t=e;for(;this.buffer[t++]!==0;);return this.offset=t,this.buffer.toString(this.encoding,e,t-1)}bytes(e){let t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}};var Ft=1,Ui=4,xr=Ft+Ui,Er=g.allocUnsafe(0);var V=class{constructor(e){this.buffer=Er;this.bufferLength=0;this.bufferOffset=0;this.reader=new qe;if(e?.mode==="binary")throw new Error("Binary mode not supported yet");this.mode=e?.mode||"text"}parse(e,t){this.mergeBuffer(e);let n=this.bufferOffset+this.bufferLength,i=this.bufferOffset;for(;i+xr<=n;){let s=this.buffer[i],o=this.buffer.readUInt32BE(i+Ft),a=Ft+o;if(a+i<=n){let c=this.handlePacket(i+xr,s,o,this.buffer);t(c),i+=a}else break}i===n?(this.buffer=Er,this.bufferLength=0,this.bufferOffset=0):(this.bufferLength=n-i,this.bufferOffset=i)}mergeBuffer(e){if(this.bufferLength>0){let t=this.bufferLength+e.byteLength;if(t+this.bufferOffset>this.buffer.byteLength){let i;if(t<=this.buffer.byteLength&&this.bufferOffset>=this.bufferLength)i=this.buffer;else{let s=this.buffer.byteLength*2;for(;t>=s;)s*=2;i=g.allocUnsafe(s)}this.buffer.copy(i,0,this.bufferOffset,this.bufferOffset+this.bufferLength),this.buffer=i,this.bufferOffset=0}e.copy(this.buffer,this.bufferOffset+this.bufferLength),this.bufferLength=t}else this.buffer=e,this.bufferOffset=0,this.bufferLength=e.byteLength}handlePacket(e,t,n,i){switch(t){case 50:return Xe;case 49:return Ke;case 51:return Je;case 110:return Ze;case 115:return et;case 99:return nt;case 87:return tt;case 73:return rt;case 68:return this.parseDataRowMessage(e,n,i);case 67:return this.parseCommandCompleteMessage(e,n,i);case 90:return this.parseReadyForQueryMessage(e,n,i);case 65:return this.parseNotificationMessage(e,n,i);case 82:return this.parseAuthenticationResponse(e,n,i);case 83:return this.parseParameterStatusMessage(e,n,i);case 75:return this.parseBackendKeyData(e,n,i);case 69:return this.parseErrorMessage(e,n,i,"error");case 78:return this.parseErrorMessage(e,n,i,"notice");case 84:return this.parseRowDescriptionMessage(e,n,i);case 116:return this.parseParameterDescriptionMessage(e,n,i);case 71:return this.parseCopyInMessage(e,n,i);case 72:return this.parseCopyOutMessage(e,n,i);case 100:return this.parseCopyData(e,n,i);default:return new C("received invalid response: "+t.toString(16),n,"error")}}parseReadyForQueryMessage(e,t,n){this.reader.setBuffer(e,n);let i=this.reader.string(1);return new ge(t,i)}parseCommandCompleteMessage(e,t,n){this.reader.setBuffer(e,n);let i=this.reader.cstring();return new U(t,i)}parseCopyData(e,t,n){let i=n.slice(e,e+(t-4));return new fe(t,i)}parseCopyInMessage(e,t,n){return this.parseCopyMessage(e,t,n,"copyInResponse")}parseCopyOutMessage(e,t,n){return this.parseCopyMessage(e,t,n,"copyOutResponse")}parseCopyMessage(e,t,n,i){this.reader.setBuffer(e,n);let s=this.reader.byte()!==0,o=this.reader.int16(),a=new le(t,i,s,o);for(let c=0;ct.parse(n,e)),new Promise(n=>r.on("end",()=>n()))}var oe,Y,K,X,ae,Be,ue,We,ce,Ie,Ae,Te,J,M,D,Z,h,Ar,Rt,G,St,Pt,xe,$,Ee,H,Mt=class Mt{constructor(e={},t={}){x(this,h);x(this,oe,!1);x(this,Y,!1);x(this,K,!1);x(this,X,!1);x(this,ae,!1);x(this,Be,new Q);x(this,ue,new Q);x(this,We,new Q);x(this,ce,!1);this.debug=0;x(this,Ie);x(this,Ae,[]);x(this,Te,new V);x(this,J);x(this,M);x(this,D,new Map);x(this,Z,new Set);typeof e=="string"?t={dataDir:e,...t}:t=e,this.dataDir=t.dataDir,t?.debug!==void 0&&(this.debug=t.debug),t?.relaxedDurability!==void 0&&B(this,ae,t.relaxedDurability),B(this,Ie,t.extensions??{}),this.waitReady=y(this,h,Ar).call(this,t??{})}static async create(e){let t=new Mt(e);return await t.waitReady,t}get Module(){return this.mod}get ready(){return d(this,oe)&&!d(this,Y)&&!d(this,K)}get closed(){return d(this,K)}async close(){await y(this,h,xe).call(this),B(this,Y,!0);for(let e of d(this,Ae))await e();try{await this.execProtocol(P.end())}catch(e){let t=e;if(!(t.name==="ExitStatus"&&t.status===0))throw e}await this.fs.close(this.mod.FS),B(this,K,!0),B(this,Y,!1)}async[Symbol.asyncDispose](){await this.close()}async query(e,t,n){return await y(this,h,xe).call(this),await d(this,ue).runExclusive(async()=>await y(this,h,Rt).call(this,e,t,n))}async exec(e,t){return await y(this,h,xe).call(this),await d(this,ue).runExclusive(async()=>await y(this,h,G).call(this,e,t))}async transaction(e){return await y(this,h,xe).call(this),await d(this,ue).runExclusive(async()=>{await y(this,h,G).call(this,"BEGIN");let t=!1,n=()=>{if(t)throw new Error("Transaction is closed")};try{let s=await e({query:async(o,a,c)=>(n(),await y(this,h,Rt).call(this,o,a,c)),exec:async(o,a)=>(n(),await y(this,h,G).call(this,o,a)),rollback:async()=>{n(),await y(this,h,G).call(this,"ROLLBACK"),t=!0},get closed(){return t}});return t||(t=!0,await y(this,h,G).call(this,"COMMIT")),s}catch(i){throw t||await y(this,h,G).call(this,"ROLLBACK"),i}})}async execProtocolRaw(e,{syncToFs:t=!0}={}){let n=e.length,i=this.mod;i._interactive_write(n),i.HEAPU8.set(e,1),i._interactive_one();let s=n+2,o=s+i._interactive_read(),a=i.HEAPU8.subarray(s,o);return t&&await y(this,h,Ee).call(this),a}async execProtocol(e,{syncToFs:t=!0,onNotice:n}={}){let i=await this.execProtocolRaw(e,{syncToFs:t}),s=[];return d(this,Te).parse(g.from(i),o=>{if(o instanceof C)throw B(this,Te,new V),o;if(o instanceof q)this.debug>0&&console.warn(o),n&&n(o);else if(o instanceof U)switch(o.text){case"BEGIN":B(this,X,!0);break;case"COMMIT":case"ROLLBACK":B(this,X,!1);break}else if(o instanceof z){let a=d(this,D).get(o.channel);a&&a.forEach(c=>{queueMicrotask(()=>c(o.payload))}),d(this,Z).forEach(c=>{queueMicrotask(()=>c(o.channel,o.payload))})}s.push([o,i])}),s}async listen(e,t){return d(this,D).has(e)||d(this,D).set(e,new Set),d(this,D).get(e).add(t),await this.exec(`LISTEN ${e}`),async()=>{await this.unlisten(e,t)}}async unlisten(e,t){t?(d(this,D).get(e)?.delete(t),d(this,D).get(e)?.size===0&&(await this.exec(`UNLISTEN ${e}`),d(this,D).delete(e))):(await this.exec(`UNLISTEN ${e}`),d(this,D).delete(e))}onNotification(e){return d(this,Z).add(e),()=>{d(this,Z).delete(e)}}offNotification(e){d(this,Z).delete(e)}async dumpDataDir(){let e=this.dataDir?.split("/").pop()??"pgdata";return this.fs.dumpTar(this.mod.FS,e)}};oe=new WeakMap,Y=new WeakMap,K=new WeakMap,X=new WeakMap,ae=new WeakMap,Be=new WeakMap,ue=new WeakMap,We=new WeakMap,ce=new WeakMap,Ie=new WeakMap,Ae=new WeakMap,Te=new WeakMap,J=new WeakMap,M=new WeakMap,D=new WeakMap,Z=new WeakMap,h=new WeakSet,Ar=async function(e){if(e.fs)this.fs=e.fs;else{let{dataDir:a,fsType:c}=_t(e.dataDir);this.fs=await Ot(a,c)}let t={},n=[],i=[`PGDATA=${Pe}`,`PREFIX=${He}`,`PGUSER=${e.username??"postgres"}`,`PGDATABASE=${e.database??"template1"}`,"MODE=REACT","REPL=N",...this.debug?["-d",this.debug.toString()]:[]],s={WASM_PREFIX:He,arguments:i,INITIAL_MEMORY:e.initialMemory,noExitRuntime:!0,...this.debug>0?{print:console.info,printErr:console.error}:{print:()=>{},printErr:()=>{}},locateFile:await Lt(),preRun:[a=>{let c=a.FS.makedev(64,0),f={open:l=>{},close:l=>{},read:(l,p,T,w,R)=>{let Fe=d(this,J);if(!Fe)throw new Error("No /dev/blob File or Blob provided to read from");let je=new Uint8Array(Fe);if(R>=je.length)return 0;let Dt=Math.min(je.length-R,w);for(let Re=0;Re(d(this,M)??B(this,M,[]),d(this,M).push(p.slice(T,T+w)),w),llseek:(l,p,T)=>{let w=d(this,J);if(!w)throw new Error("No /dev/blob File or Blob provided to llseek");let R=p;if(T===1?R+=l.position:T===2&&(R=new Uint8Array(w).length),R<0)throw new a.FS.ErrnoError(28);return R}};a.FS.registerDevice(c,f),a.FS.mkdev("/dev/blob",c)}]};s=await this.fs.emscriptenOpts(s);for(let[a,c]of Object.entries(d(this,Ie)))if(c instanceof URL)t[a]=At(c);else{let f=await c.setup(this,s);if(f.emscriptenOpts&&(s=f.emscriptenOpts),f.namespaceObj){let l=this;l[a]=f.namespaceObj}f.bundlePath&&(t[a]=At(f.bundlePath)),f.init&&n.push(f.init),f.close&&d(this,Ae).push(f.close)}if(s.pg_extensions=t,this.mod=await kt(s),await this.fs.initialSyncFs(this.mod.FS),e.loadDataDir){if(this.mod.FS.analyzePath(Pe+"/PG_VERSION").exists)throw new Error("Database already exists, cannot load from tarball");y(this,h,H).call(this,"pglite: loading data from tarball"),await Ut(this.mod.FS,e.loadDataDir)}this.mod.FS.analyzePath(Pe+"/PG_VERSION").exists?y(this,h,H).call(this,"pglite: found DB, resuming"):y(this,h,H).call(this,"pglite: no db"),await br(this.mod,(...a)=>y(this,h,H).call(this,...a));let o=this.mod._pg_initdb();if(!o)throw new Error("INITDB failed to return value");if(o&1)throw new Error("INITDB failed");if(o&2){let a=e.username??"postgres",c=e.database??"template1";if(o&4){if(!(o&12))throw new Error("Invalid db/user combination")}else if(c!=="template1"&&a!=="postgres")throw new Error("INITDB created a new datadir, but an alternative db/user was requested")}await y(this,h,Ee).call(this),await y(this,h,G).call(this,"SET search_path TO public;"),B(this,oe,!0);for(let a of n)await a()},Rt=async function(e,t,n){return await d(this,Be).runExclusive(async()=>{y(this,h,H).call(this,"runQuery",e,t,n),await y(this,h,St).call(this,n?.blob);let i=t?.map(a=>Ge(a,n?.setAllTypes))||[],s;try{s=[...await y(this,h,$).call(this,P.parse({text:e,types:i.map(([,a])=>a)}),n),...await y(this,h,$).call(this,P.bind({values:i.map(([a])=>a)}),n),...await y(this,h,$).call(this,P.describe({type:"P"}),n),...await y(this,h,$).call(this,P.execute({}),n)]}finally{await y(this,h,$).call(this,P.sync(),n)}y(this,h,Pt).call(this),d(this,X)||await y(this,h,Ee).call(this);let o;return d(this,M)&&(o=new Blob(d(this,M)),B(this,M,void 0)),Qe(s.map(([a])=>a),n,o)[0]})},G=async function(e,t){return await d(this,Be).runExclusive(async()=>{y(this,h,H).call(this,"runExec",e,t),await y(this,h,St).call(this,t?.blob);let n;try{n=await y(this,h,$).call(this,P.query(e),t)}finally{await y(this,h,$).call(this,P.sync(),t)}y(this,h,Pt).call(this),d(this,X)||await y(this,h,Ee).call(this);let i;return d(this,M)&&(i=new Blob(d(this,M)),B(this,M,void 0)),Qe(n.map(([s])=>s),t,i)})},St=async function(e){B(this,J,e?await e.arrayBuffer():void 0)},Pt=function(){B(this,J,void 0)},xe=async function(){if(d(this,Y))throw new Error("PGlite is closing");if(d(this,K))throw new Error("PGlite is closed");d(this,oe)||await this.waitReady},$=async function(e,t={}){return await this.execProtocol(e,{...t,syncToFs:!1})},Ee=async function(){if(d(this,ce))return;B(this,ce,!0);let e=async()=>{await d(this,We).runExclusive(async()=>{B(this,ce,!1),await this.fs.syncToFs(this.mod.FS,d(this,ae))})};d(this,ae)?e():await e()},H=function(...e){this.debug>0&&console.log(...e)};var Ir=Mt;m();export{Fr as IdbFs,Rr as MemoryFS,Q as Mutex,Ir as PGlite,Pr as formatQuery,vt as messages,mr as parse,Br as protocol,yr as types,Sr as uuid}; /*! Bundled license information: ieee754/index.js: (*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh *) buffer/index.js: (*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh * @license MIT *) */ //# sourceMappingURL=index.js.map