Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@electric-sql/pglite

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@electric-sql/pglite - npm Package Compare versions

Comparing version 0.2.4 to 0.2.5

14

dist/index.d.ts

@@ -21,3 +21,3 @@ import { F as Filesystem, P as PostgresMod, D as DumpTarCompressionOptions, a as FilesystemBase, b as FS } from './types-CQTnnKLt.js';

* Use memory:// to use in-memory filesystem
* @param options Optional options
* @param options PGlite options
*/

@@ -34,9 +34,17 @@ constructor(dataDir?: string, options?: PGliteOptions);

* of Typescript, the extensions are not available on the instance interface)
* @param options PGlite options including the data directory
* @returns A promise that resolves to the PGlite instance when it's ready.
*/
static create<O extends PGliteOptions>(options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
/**
* Create a new PGlite instance with extensions on the Typescript interface
* (The main constructor does enable extensions, however due to the limitations
* of Typescript, the extensions are not available on the instance interface)
* @param dataDir The directory to store the database files
* Prefix with idb:// to use indexeddb filesystem in the browser
* Use memory:// to use in-memory filesystem
* @param options Optional options
* @param options PGlite options
* @returns A promise that resolves to the PGlite instance when it's ready.
*/
static create<O extends PGliteOptions>(options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
static create<O extends PGliteOptions>(dataDir?: string, options?: O): Promise<PGlite & PGliteInterfaceExtensions<O['extensions']>>;
/**

@@ -43,0 +51,0 @@ * The Postgres Emscripten Module

@@ -1,2 +0,2 @@

import{b as Ss,d as kt,e as xs,f as Ps,g as at,h as qe,i as Ut,j as Lt}from"./chunk-SJVDOE3S.js";import{d as ot}from"./chunk-TAZBUB4Z.js";import{a as Nt,b as qt,c as vs,d as Rs}from"./chunk-3BCYDNSE.js";import{b as Ne,c as Ts,d as f,e as S,f as P,g as p,i as b}from"./chunk-Y3AVQXKT.js";b();b();b();var ri=new Error("timeout while waiting for mutex to become available"),ii=new Error("mutex already locked"),Ds=new Error("request for lock canceled"),Is=function(t,e,s,r){function i(a){return a instanceof s?a:new s(function(l){l(a)})}return new(s||(s=Promise))(function(a,l){function o(d){try{c(r.next(d))}catch(A){l(A)}}function y(d){try{c(r.throw(d))}catch(A){l(A)}}function c(d){d.done?a(d.value):i(d.value).then(o,y)}c((r=r.apply(t,e||[])).next())})},lt=class{constructor(e,s=Ds){this._value=e,this._cancelError=s,this._weightedQueues=[],this._weightedWaiters=[]}acquire(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,r)=>{this._weightedQueues[e-1]||(this._weightedQueues[e-1]=[]),this._weightedQueues[e-1].push({resolve:s,reject:r}),this._dispatch()})}runExclusive(e,s=1){return Is(this,void 0,void 0,function*(){let[r,i]=yield this.acquire(s);try{return yield e(r)}finally{i()}})}waitForUnlock(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),this._weightedWaiters[e-1].push(s),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(s=>s.reject(this._cancelError))),this._weightedQueues=[]}_dispatch(){var e;for(let s=this._value;s>0;s--){let r=(e=this._weightedQueues[s-1])===null||e===void 0?void 0:e.shift();if(!r)continue;let i=this._value,a=s;this._value-=s,s=this._value+1,r.resolve([i,this._newReleaser(a)])}this._drainUnlockWaiters()}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){for(let e=this._value;e>0;e--)this._weightedWaiters[e-1]&&(this._weightedWaiters[e-1].forEach(s=>s()),this._weightedWaiters[e-1]=[])}},Ms=function(t,e,s,r){function i(a){return a instanceof s?a:new s(function(l){l(a)})}return new(s||(s=Promise))(function(a,l){function o(d){try{c(r.next(d))}catch(A){l(A)}}function y(d){try{c(r.throw(d))}catch(A){l(A)}}function c(d){d.done?a(d.value):i(d.value).then(o,y)}c((r=r.apply(t,e||[])).next())})},$=class{constructor(e){this._semaphore=new lt(1,e)}acquire(){return Ms(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()}};b();import _s from"./postgres.js";var Gt=_s;var Xt={};Ne(Xt,{parseResults:()=>Ye});b();var Wt={};Ne(Wt,{AuthenticationCleartextPassword:()=>ge,AuthenticationMD5Password:()=>we,AuthenticationOk:()=>me,AuthenticationSASL:()=>be,AuthenticationSASLContinue:()=>Ee,AuthenticationSASLFinal:()=>Ae,BackendKeyDataMessage:()=>Re,CommandCompleteMessage:()=>k,CopyDataMessage:()=>Te,CopyResponse:()=>Se,DataRowMessage:()=>z,DatabaseError:()=>q,Field:()=>xe,NoticeMessage:()=>K,NotificationResponseMessage:()=>H,ParameterDescriptionMessage:()=>Pe,ParameterStatusMessage:()=>ve,ReadyForQueryMessage:()=>De,RowDescriptionMessage:()=>G,bindComplete:()=>ce,closeComplete:()=>ue,copyDone:()=>ye,emptyQuery:()=>pe,noData:()=>he,parseComplete:()=>le,portalSuspended:()=>fe,replicationStart:()=>de});b();b();var Os=Object.defineProperty,zt=t=>{throw TypeError(t)},Cs=(t,e)=>{for(var s in e)Os(t,s,{get:e[s],enumerable:!0})},ct=(t,e,s)=>e.has(t)||zt("Cannot "+s),n=(t,e,s)=>(ct(t,e,"read from private field"),s?s.call(t):e.get(t)),v=(t,e,s)=>e.has(t)?zt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),g=(t,e,s,r)=>(ct(t,e,"write to private field"),r?r.call(t,s):e.set(t,s),s),m=(t,e,s)=>(ct(t,e,"access private method"),s),ut=(t,e,s,r)=>({set _(i){g(t,e,i,s)},get _(){return n(t,e,r)}}),ht={};Cs(ht,{AuthenticationCleartextPassword:()=>ge,AuthenticationMD5Password:()=>we,AuthenticationOk:()=>me,AuthenticationSASL:()=>be,AuthenticationSASLContinue:()=>Ee,AuthenticationSASLFinal:()=>Ae,BackendKeyDataMessage:()=>Re,CommandCompleteMessage:()=>k,CopyDataMessage:()=>Te,CopyResponse:()=>Se,DataRowMessage:()=>z,DatabaseError:()=>q,Field:()=>xe,NoticeMessage:()=>K,NotificationResponseMessage:()=>H,ParameterDescriptionMessage:()=>Pe,ParameterStatusMessage:()=>ve,ReadyForQueryMessage:()=>De,RowDescriptionMessage:()=>G,bindComplete:()=>ce,closeComplete:()=>ue,copyDone:()=>ye,emptyQuery:()=>pe,noData:()=>he,parseComplete:()=>le,portalSuspended:()=>fe,replicationStart:()=>de});var le={name:"parseComplete",length:5},ce={name:"bindComplete",length:5},ue={name:"closeComplete",length:5},he={name:"noData",length:5},fe={name:"portalSuspended",length:5},de={name:"replicationStart",length:4},pe={name:"emptyQuery",length:4},ye={name:"copyDone",length:4},me=class{constructor(t){this.length=t,this.name="authenticationOk"}},ge=class{constructor(t){this.length=t,this.name="authenticationCleartextPassword"}},we=class{constructor(t,e){this.length=t,this.salt=e,this.name="authenticationMD5Password"}},be=class{constructor(t,e){this.length=t,this.mechanisms=e,this.name="authenticationSASL"}},Ee=class{constructor(t,e){this.length=t,this.data=e,this.name="authenticationSASLContinue"}},Ae=class{constructor(t,e){this.length=t,this.data=e,this.name="authenticationSASLFinal"}},q=class extends Error{constructor(t,e,s){super(t),this.length=e,this.name=s}},Te=class{constructor(t,e){this.length=t,this.chunk=e,this.name="copyData"}},Se=class{constructor(t,e,s,r){this.length=t,this.name=e,this.binary=s,this.columnTypes=new Array(r)}},xe=class{constructor(t,e,s,r,i,a,l){this.name=t,this.tableID=e,this.columnID=s,this.dataTypeID=r,this.dataTypeSize=i,this.dataTypeModifier=a,this.format=l}},G=class{constructor(t,e){this.length=t,this.fieldCount=e,this.name="rowDescription",this.fields=new Array(this.fieldCount)}},Pe=class{constructor(t,e){this.length=t,this.parameterCount=e,this.name="parameterDescription",this.dataTypeIDs=new Array(this.parameterCount)}},ve=class{constructor(t,e,s){this.length=t,this.parameterName=e,this.parameterValue=s,this.name="parameterStatus"}},Re=class{constructor(t,e,s){this.length=t,this.processID=e,this.secretKey=s,this.name="backendKeyData"}},H=class{constructor(t,e,s,r){this.length=t,this.processId=e,this.channel=s,this.payload=r,this.name="notification"}},De=class{constructor(t,e){this.length=t,this.status=e,this.name="readyForQuery"}},k=class{constructor(t,e){this.length=t,this.text=e,this.name="commandComplete"}},z=class{constructor(t,e){this.length=t,this.fields=e,this.name="dataRow",this.fieldCount=e.length}},K=class{constructor(t,e){this.length=t,this.message=e,this.name="notice"}};var Yt={};Ne(Yt,{ABSTIME:()=>js,ACLITEM:()=>er,BIT:()=>nr,BOOL:()=>ft,BPCHAR:()=>tr,BYTEA:()=>We,CHAR:()=>Qt,CID:()=>Ns,CIDR:()=>Vs,CIRCLE:()=>Ks,DATE:()=>wt,FLOAT4:()=>mt,FLOAT8:()=>je,GTSVECTOR:()=>Ar,INET:()=>Zs,INT2:()=>dt,INT4:()=>pt,INT8:()=>Ie,INTERVAL:()=>rr,JSON:()=>Ve,JSONB:()=>At,MACADDR:()=>Js,MACADDR8:()=>Ys,MONEY:()=>Xs,NUMERIC:()=>or,OID:()=>yt,PATH:()=>Ws,PG_DEPENDENCIES:()=>wr,PG_LSN:()=>mr,PG_NDISTINCT:()=>gr,PG_NODE_TREE:()=>Gs,POLYGON:()=>Qs,REFCURSOR:()=>lr,REGCLASS:()=>fr,REGCONFIG:()=>Tr,REGDICTIONARY:()=>Sr,REGNAMESPACE:()=>xr,REGOPER:()=>ur,REGOPERATOR:()=>hr,REGPROC:()=>ks,REGPROCEDURE:()=>cr,REGROLE:()=>Pr,REGTYPE:()=>dr,RELTIME:()=>$s,SMGR:()=>zs,TEXT:()=>Qe,TID:()=>Us,TIME:()=>sr,TIMESTAMP:()=>bt,TIMESTAMPTZ:()=>Et,TIMETZ:()=>ir,TINTERVAL:()=>Hs,TSQUERY:()=>Er,TSVECTOR:()=>br,TXID_SNAPSHOT:()=>yr,UUID:()=>pr,VARBIT:()=>ar,VARCHAR:()=>gt,XID:()=>Ls,XML:()=>qs,arrayTypes:()=>Ge,parseArray:()=>Kt,parseType:()=>Ke,parsers:()=>Vt,serializeType:()=>He,serializerFor:()=>$t,serializerInstanceof:()=>jt,serializers:()=>ze,types:()=>Tt});b();var Fs=globalThis.JSON.parse,Bs=globalThis.JSON.stringify,ft=16,We=17,Qt=18,Ie=20,dt=21,pt=23,ks=24,Qe=25,yt=26,Us=27,Ls=28,Ns=29,Ve=114,qs=142,Gs=194,zs=210,Ws=602,Qs=604,Vs=650,mt=700,je=701,js=702,$s=703,Hs=704,Ks=718,Ys=774,Xs=790,Js=829,Zs=869,er=1033,tr=1042,gt=1043,wt=1082,sr=1083,bt=1114,Et=1184,rr=1186,ir=1266,nr=1560,ar=1562,or=1700,lr=1790,cr=2202,ur=2203,hr=2204,fr=2205,dr=2206,pr=2950,yr=2970,mr=3220,gr=3361,wr=3402,br=3614,Er=3615,Ar=3642,Tr=3734,Sr=3769,At=3802,xr=4089,Pr=4096,Ge={1001:We,1002:Qt,1016:Ie,1005:dt,1007:pt,1009:Qe,1028:yt,199:Ve,1021:mt,1022:je,1015:gt,3807:At,1182:wt,1115:bt,1116:Et},Tt={string:{to:0,from:[Qe,gt],serialize:t=>t,parse:t=>t,forceTo:Qe},number:{to:0,from:[dt,pt,yt,mt,je],serialize:t=>t.toString(),parse:t=>+t,forceTo:t=>Number.isInteger(t)?Ie:je},bigint:{to:Ie,from:[Ie],js:[BigInt],serialize:t=>t.toString(),parse:t=>{let e=BigInt(t);return e<Number.MIN_SAFE_INTEGER||e>Number.MAX_SAFE_INTEGER?e:Number(e)}},json:{to:Ve,from:[Ve,At],serialize:t=>Bs(t),parse:t=>Fs(t)},boolean:{to:ft,from:[ft],serialize:t=>t===!0?"t":"f",parse:t=>t==="t"},date:{to:1184,from:[wt,bt,Et],js:[Date],serialize:t=>(t instanceof Date?t:new Date(t)).toISOString(),parse:t=>new Date(t)},bytea:{to:We,from:[We],js:[Uint8Array],serialize:t=>"\\x"+Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join(""),parse:t=>{let e=t.slice(2);return Uint8Array.from({length:e.length/2},(s,r)=>parseInt(e.substring(r*2,(r+1)*2),16))}},array:{to:0,from:Object.keys(Ge).map(t=>+t),serialize:t=>Ht(t),parse:(t,e)=>{let s;return e&&e in Ge&&(s=Vt[Ge[e]]),Kt(t,s)}}},$e=Rr(Tt),Vt=$e.parsers,ze=$e.serializers,jt=$e.serializerInstanceof;function $t(t){if(Array.isArray(t))return ze.array;let e=ze[typeof t];if(e)return e;for(let[s,r]of jt)if(t instanceof s)return r;return ze.json}function He(t,e=!1){return t==null?[null,0]:$t(t)(t,e)}function vr(t){return'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function Ht(t){let e="{";for(let s=0;s<t.length;s++)if(s>0&&(e=e+","),t[s]===null||typeof t[s]>"u")e=e+"NULL";else if(Array.isArray(t[s]))e=e+Ht(t[s]);else if(ArrayBuffer.isView(t[s])||t[s]instanceof ArrayBuffer){let r=ArrayBuffer.isView(t[s])?new Uint8Array(t[s].buffer,t[s].byteOffset,t[s].byteLength):new Uint8Array(t[s]);e+="\\"+Tt.bytea.serialize(r)}else e+=vr(He(t[s])[0]);return e=e+"}",e}function Kt(t,e){let s=0,r=null,i="",a=!1,l=0,o;function y(c){let d=[];for(;s<c.length;s++){if(r=c[s],a)r==="\\"?i+=c[++s]:r==='"'?(d.push(e?e(i):i),i="",a=c[s+1]==='"',l=s+2):i+=r;else if(r==='"')a=!0;else if(r==="{")l=++s,d.push(y(c));else if(r==="}"){a=!1,l<s&&d.push(e?e(c.slice(l,s)):c.slice(l,s)),l=s+1;break}else r===","&&o!=="}"&&o!=='"'&&(d.push(e?e(c.slice(l,s)):c.slice(l,s)),l=s+1);o=r}return l<s&&d.push(e?e(c.slice(l,s+1)):c.slice(l,s+1)),d}return y(t)[0]}function Ke(t,e,s){if(t===null)return null;let r=s?.[e]??$e.parsers[e];return r?r(t,e):t}function Rr(t){return Object.keys(t).reduce(({parsers:e,serializers:s,serializerInstanceof:r},i)=>{let{to:a,from:l,serialize:o,parse:y=null,forceTo:c}=t[i],d=(A,L=!1)=>[o(A),L&&c?typeof c=="function"?c(A):c:a];return s[a]=d,s[i]=d,t[i].js&&t[i].js.forEach(A=>r.push([A,d])),y&&(Array.isArray(l)?l.forEach(A=>e[A]=y):e[l]=y,e[i]=y),{parsers:e,serializers:s,serializerInstanceof:r}},{parsers:{},serializers:{},serializerInstanceof:[]})}function Ye(t,e,s){let r=[],i={rows:[],fields:[]},a=0,l=t.filter(o=>o instanceof G||o instanceof z||o instanceof k);return l.forEach((o,y)=>{o instanceof G?i.fields=o.fields.map(c=>({name:c.name,dataTypeID:c.dataTypeID})):o instanceof z&&i?e?.rowMode==="array"?i.rows.push(o.fields.map((c,d)=>Ke(c,i.fields[d].dataTypeID,e?.parsers))):i.rows.push(Object.fromEntries(o.fields.map((c,d)=>[i.fields[d].name,Ke(c,i.fields[d].dataTypeID,e?.parsers)]))):o instanceof k&&(a+=Dr(o),y===l.length-1?r.push({...i,affectedRows:a,...s?{blob:s}:{}}):r.push(i),i={rows:[],fields:[]})}),r.length===0&&r.push({rows:[],fields:[]}),r}function Dr(t){let e=t.text.split(" ");switch(e[0]){case"INSERT":return parseInt(e[2],10);case"UPDATE":case"DELETE":return parseInt(e[1],10);default:return 0}}b();var Jt=Ts(Ss(),1);async function St(t){if(Nt){let e=await import("fs"),s=await import("zlib"),{Writable:r}=await import("stream"),{pipeline:i}=await import("stream/promises");if(!e.existsSync(t))throw new Error(`Extension bundle not found: ${t}`);let a=s.createGunzip(),l=[];return await i(e.createReadStream(t),a,new r({write(o,y,c){l.push(o),c()}})),new Blob(l)}else{let e=await fetch(t.toString());if(!e.ok||!e.body)return null;if(e.headers.get("Content-Encoding")==="gzip")return e.blob();{let s=new DecompressionStream("gzip");return new Response(e.body.pipeThrough(s)).blob()}}}async function Zt(t,e){for(let s in t.pg_extensions){let r;try{r=await t.pg_extensions[s]}catch(i){console.error("Failed to fetch extension:",s,i);continue}if(r){let i=new Uint8Array(await r.arrayBuffer());Ir(t,s,i,e)}else console.error("Could not get binary data for extension:",s)}}function Ir(t,e,s,r){Jt.default.untar(s).forEach(a=>{if(!a.name.startsWith(".")){let l=t.WASM_PREFIX+"/"+a.name;if(a.name.endsWith(".so")){let o=(...c)=>{r("pgfs:ext OK",l,c)},y=(...c)=>{r("pgfs:ext FAIL",l,c)};t.FS.createPreloadedFile(Mr(l),a.name.split("/").pop().slice(0,-3),a.data,!0,!0,o,y,!1)}else t.FS.writeFile(l,a.data)}})}function Mr(t){let e=t.lastIndexOf("/");return e>0?t.slice(0,e):t}var bs={};Ne(bs,{Parser:()=>st,messages:()=>ht,serialize:()=>U});b();function Ze(t){let e=t.length;for(let s=t.length-1;s>=0;s--){let r=t.charCodeAt(s);r>127&&r<=2047?e++:r>2047&&r<=65535&&(e+=2),r>=56320&&r<=57343&&s--}return e}var R,T,_e,vt,Me,_,Je,se,ms,et=class{constructor(t=256){this.size=t,v(this,_),v(this,R),v(this,T,5),v(this,_e,!1),v(this,vt,new TextEncoder),v(this,Me,0),g(this,R,m(this,_,Je).call(this,t))}addInt32(t){return m(this,_,se).call(this,4),n(this,R).setInt32(n(this,T),t,n(this,_e)),g(this,T,n(this,T)+4),this}addInt16(t){return m(this,_,se).call(this,2),n(this,R).setInt16(n(this,T),t,n(this,_e)),g(this,T,n(this,T)+2),this}addCString(t){return t&&this.addString(t),m(this,_,se).call(this,1),n(this,R).setUint8(n(this,T),0),ut(this,T)._++,this}addString(t=""){let e=Ze(t);return m(this,_,se).call(this,e),n(this,vt).encodeInto(t,new Uint8Array(n(this,R).buffer,n(this,T))),g(this,T,n(this,T)+e),this}add(t){return m(this,_,se).call(this,t.byteLength),new Uint8Array(n(this,R).buffer).set(new Uint8Array(t),n(this,T)),g(this,T,n(this,T)+t.byteLength),this}flush(t){let e=m(this,_,ms).call(this,t);return g(this,T,5),g(this,R,m(this,_,Je).call(this,this.size)),new Uint8Array(e)}};R=new WeakMap,T=new WeakMap,_e=new WeakMap,vt=new WeakMap,Me=new WeakMap,_=new WeakSet,Je=function(t){return new DataView(new ArrayBuffer(t))},se=function(t){if(n(this,R).byteLength-n(this,T)<t){let e=n(this,R).buffer,s=e.byteLength+(e.byteLength>>1)+t;g(this,R,m(this,_,Je).call(this,s)),new Uint8Array(n(this,R).buffer).set(new Uint8Array(e))}},ms=function(t){if(t){n(this,R).setUint8(n(this,Me),t);let e=n(this,T)-(n(this,Me)+1);n(this,R).setInt32(n(this,Me)+1,e,n(this,_e))}return n(this,R).buffer.slice(t?0:5,n(this,T))};var w=new et,_r=t=>{w.addInt16(3).addInt16(0);for(let r of Object.keys(t))w.addCString(r).addCString(t[r]);w.addCString("client_encoding").addCString("UTF8");let e=w.addCString("").flush(),s=e.byteLength+4;return new et().addInt32(s).add(e).flush()},Or=()=>{let t=new DataView(new ArrayBuffer(8));return t.setInt32(0,8,!1),t.setInt32(4,80877103,!1),new Uint8Array(t.buffer)},Cr=t=>w.addCString(t).flush(112),Fr=(t,e)=>(w.addCString(t).addInt32(Ze(e)).addString(e),w.flush(112)),Br=t=>w.addString(t).flush(112),kr=t=>w.addCString(t).flush(81),Ur=[],Lr=t=>{let e=t.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 s=w.addCString(e).addCString(t.text).addInt16(t.types?.length??0);return t.types?.forEach(r=>s.addInt32(r)),w.flush(80)},re=new et,Nr=(t,e)=>{for(let s=0;s<t.length;s++){let r=e?e(t[s],s):t[s];if(r===null)w.addInt16(0),re.addInt32(-1);else if(r instanceof ArrayBuffer||ArrayBuffer.isView(r)){let i=ArrayBuffer.isView(r)?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r;w.addInt16(1),re.addInt32(i.byteLength),re.add(i)}else w.addInt16(0),re.addInt32(Ze(r)),re.addString(r)}},qr=(t={})=>{let e=t.portal??"",s=t.statement??"",r=t.binary??!1,i=t.values??Ur,a=i.length;return w.addCString(e).addCString(s),w.addInt16(a),Nr(i,t.valueMapper),w.addInt16(a),w.add(re.flush()),w.addInt16(r?1:0),w.flush(66)},Gr=new Uint8Array([69,0,0,0,9,0,0,0,0,0]),zr=t=>{if(!t||!t.portal&&!t.rows)return Gr;let e=t.portal??"",s=t.rows??0,r=Ze(e),i=4+r+1+4,a=new DataView(new ArrayBuffer(1+i));return a.setUint8(0,69),a.setInt32(1,i,!1),new TextEncoder().encodeInto(e,new Uint8Array(a.buffer,5)),a.setUint8(r+5,0),a.setUint32(a.byteLength-4,s,!1),new Uint8Array(a.buffer)},Wr=(t,e)=>{let s=new DataView(new ArrayBuffer(16));return s.setInt32(0,16,!1),s.setInt16(4,1234,!1),s.setInt16(6,5678,!1),s.setInt32(8,t,!1),s.setInt32(12,e,!1),new Uint8Array(s.buffer)},Mt=(t,e)=>{let s=new et;return s.addCString(e),s.flush(t)},Qr=w.addCString("P").flush(68),Vr=w.addCString("S").flush(68),jr=t=>t.name?Mt(68,`${t.type}${t.name??""}`):t.type==="P"?Qr:Vr,$r=t=>{let e=`${t.type}${t.name??""}`;return Mt(67,e)},Hr=t=>w.add(t).flush(100),Kr=t=>Mt(102,t),tt=t=>new Uint8Array([t,0,0,0,4]),Yr=tt(72),Xr=tt(83),Jr=tt(88),Zr=tt(99),U={startup:_r,password:Cr,requestSsl:Or,sendSASLInitialResponseMessage:Fr,sendSCRAMClientFinalMessage:Br,query:kr,parse:Lr,bind:qr,execute:zr,describe:jr,close:$r,flush:()=>Yr,sync:()=>Xr,end:()=>Jr,copyData:Hr,copyDone:()=>Zr,copyFail:Kr,cancel:Wr},es={text:0,binary:1},ei=new ArrayBuffer(0),W,x,Rt,Dt,Xe,ti=class{constructor(t=0){v(this,W,new DataView(ei)),v(this,x),v(this,Rt,"utf-8"),v(this,Dt,new TextDecoder(n(this,Rt))),v(this,Xe,!1),g(this,x,t)}setBuffer(t,e){g(this,x,t),g(this,W,new DataView(e))}int16(){let t=n(this,W).getInt16(n(this,x),n(this,Xe));return g(this,x,n(this,x)+2),t}byte(){let t=n(this,W).getUint8(n(this,x));return ut(this,x)._++,t}int32(){let t=n(this,W).getInt32(n(this,x),n(this,Xe));return g(this,x,n(this,x)+4),t}string(t){return n(this,Dt).decode(this.bytes(t))}cstring(){let t=n(this,x),e=t;for(;n(this,W).getUint8(e++)!==0;);let s=this.string(e-t-1);return g(this,x,e),s}bytes(t){let e=n(this,W).buffer.slice(n(this,x),n(this,x)+t);return g(this,x,n(this,x)+t),new Uint8Array(e)}};W=new WeakMap,x=new WeakMap,Rt=new WeakMap,Dt=new WeakMap,Xe=new WeakMap;var It=1,si=4,ts=It+si,ss=new ArrayBuffer(0),D,I,M,h,E,gs,ws,rs,is,ns,as,os,xt,ls,cs,us,hs,fs,ds,ps,ys,Pt,st=class{constructor(){v(this,E),v(this,D,new DataView(ss)),v(this,I,0),v(this,M,0),v(this,h,new ti)}parse(t,e){m(this,E,gs).call(this,ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t);let s=n(this,M)+n(this,I),r=n(this,M);for(;r+ts<=s;){let i=n(this,D).getUint8(r),a=n(this,D).getUint32(r+It,!1),l=It+a;if(l+r<=s){let o=m(this,E,ws).call(this,r+ts,i,a,n(this,D).buffer);e(o),r+=l}else break}r===s?(g(this,D,new DataView(ss)),g(this,I,0),g(this,M,0)):(g(this,I,s-r),g(this,M,r))}};D=new WeakMap,I=new WeakMap,M=new WeakMap,h=new WeakMap,E=new WeakSet,gs=function(t){if(n(this,I)>0){let e=n(this,I)+t.byteLength;if(e+n(this,M)>n(this,D).byteLength){let s;if(e<=n(this,D).byteLength&&n(this,M)>=n(this,I))s=n(this,D).buffer;else{let r=n(this,D).byteLength*2;for(;e>=r;)r*=2;s=new ArrayBuffer(r)}new Uint8Array(s).set(new Uint8Array(n(this,D).buffer,n(this,M),n(this,I))),g(this,D,new DataView(s)),g(this,M,0)}new Uint8Array(n(this,D).buffer).set(new Uint8Array(t),n(this,M)+n(this,I)),g(this,I,e)}else g(this,D,new DataView(t)),g(this,M,0),g(this,I,t.byteLength)},ws=function(t,e,s,r){switch(e){case 50:return ce;case 49:return le;case 51:return ue;case 110:return he;case 115:return fe;case 99:return ye;case 87:return de;case 73:return pe;case 68:return m(this,E,fs).call(this,t,s,r);case 67:return m(this,E,is).call(this,t,s,r);case 90:return m(this,E,rs).call(this,t,s,r);case 65:return m(this,E,ls).call(this,t,s,r);case 82:return m(this,E,ys).call(this,t,s,r);case 83:return m(this,E,ds).call(this,t,s,r);case 75:return m(this,E,ps).call(this,t,s,r);case 69:return m(this,E,Pt).call(this,t,s,r,"error");case 78:return m(this,E,Pt).call(this,t,s,r,"notice");case 84:return m(this,E,cs).call(this,t,s,r);case 116:return m(this,E,hs).call(this,t,s,r);case 71:return m(this,E,as).call(this,t,s,r);case 72:return m(this,E,os).call(this,t,s,r);case 100:return m(this,E,ns).call(this,t,s,r);default:return new q("received invalid response: "+e.toString(16),s,"error")}},rs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).string(1);return new De(e,r)},is=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).cstring();return new k(e,r)},ns=function(t,e,s){let r=s.slice(t,t+(e-4));return new Te(e,new Uint8Array(r))},as=function(t,e,s){return m(this,E,xt).call(this,t,e,s,"copyInResponse")},os=function(t,e,s){return m(this,E,xt).call(this,t,e,s,"copyOutResponse")},xt=function(t,e,s,r){n(this,h).setBuffer(t,s);let i=n(this,h).byte()!==0,a=n(this,h).int16(),l=new Se(e,r,i,a);for(let o=0;o<a;o++)l.columnTypes[o]=n(this,h).int16();return l},ls=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32(),i=n(this,h).cstring(),a=n(this,h).cstring();return new H(e,r,i,a)},cs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new G(e,r);for(let a=0;a<r;a++)i.fields[a]=m(this,E,us).call(this);return i},us=function(){let t=n(this,h).cstring(),e=n(this,h).int32(),s=n(this,h).int16(),r=n(this,h).int32(),i=n(this,h).int16(),a=n(this,h).int32(),l=n(this,h).int16()===0?es.text:es.binary;return new xe(t,e,s,r,i,a,l)},hs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new Pe(e,r);for(let a=0;a<r;a++)i.dataTypeIDs[a]=n(this,h).int32();return i},fs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new Array(r);for(let a=0;a<r;a++){let l=n(this,h).int32();i[a]=l===-1?null:n(this,h).string(l)}return new z(e,i)},ds=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).cstring(),i=n(this,h).cstring();return new ve(e,r,i)},ps=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32(),i=n(this,h).int32();return new Re(e,r,i)},ys=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32();switch(r){case 0:return new me(e);case 3:return new ge(e);case 5:return new we(e,n(this,h).bytes(4));case 10:{let i=[];for(;;){let a=n(this,h).cstring();if(a.length===0)return new be(e,i);i.push(a)}}case 11:return new Ee(e,n(this,h).string(e-8));case 12:return new Ae(e,n(this,h).string(e-8));default:throw new Error("Unknown authenticationOk message type "+r)}},Pt=function(t,e,s,r){n(this,h).setBuffer(t,s);let i={},a=n(this,h).string(1);for(;a!=="\0";)i[a]=n(this,h).cstring(),a=n(this,h).string(1);let l=i.M,o=r==="notice"?new K(e,l):new q(l,e,r);return o.severity=i.S,o.code=i.C,o.detail=i.D,o.hint=i.H,o.position=i.P,o.internalPosition=i.p,o.internalQuery=i.q,o.where=i.W,o.schema=i.s,o.table=i.t,o.column=i.c,o.dataType=i.d,o.constraint=i.n,o.file=i.F,o.line=i.L,o.routine=i.R,o};var ie,X,J,Z,ne,Fe,ae,it,oe,Be,ke,Ue,ee,O,C,te,u,As,rt,Q,_t,Ot,Oe,V,Ce,Y,Ct=class Ct{constructor(e={},s={}){S(this,u);S(this,ie,!1);S(this,X,!1);S(this,J,!1);S(this,Z,!1);S(this,ne,!1);S(this,Fe,new $);S(this,ae,new $);S(this,it,new $);S(this,oe,!1);this.debug=0;S(this,Be);S(this,ke,[]);S(this,Ue,new st);S(this,ee);S(this,O);S(this,C,new Map);S(this,te,new Set);typeof e=="string"?s={dataDir:e,...s}:s=e,this.dataDir=s.dataDir,s?.debug!==void 0&&(this.debug=s.debug),s?.relaxedDurability!==void 0&&P(this,ne,s.relaxedDurability),P(this,Be,s.extensions??{}),this.waitReady=p(this,u,As).call(this,s??{})}static async create(e){let s=new Ct(e);return await s.waitReady,s}get Module(){return this.mod}get ready(){return f(this,ie)&&!f(this,X)&&!f(this,J)}get closed(){return f(this,J)}async close(){await p(this,u,Oe).call(this),P(this,X,!0);for(let e of f(this,ke))await e();try{await this.execProtocol(U.end())}catch(e){let s=e;if(!(s.name==="ExitStatus"&&s.status===0))throw e}await this.fs.close(this.mod.FS),P(this,J,!0),P(this,X,!1)}async[Symbol.asyncDispose](){await this.close()}async query(e,s,r){return await p(this,u,Oe).call(this),await f(this,ae).runExclusive(async()=>await p(this,u,rt).call(this,e,s,r))}async sql(e,...s){let{query:r,params:i}=ot(e,...s);return await this.query(r,i)}async exec(e,s){return await p(this,u,Oe).call(this),await f(this,ae).runExclusive(async()=>await p(this,u,Q).call(this,e,s))}async transaction(e){return await p(this,u,Oe).call(this),await f(this,ae).runExclusive(async()=>{await p(this,u,Q).call(this,"BEGIN");let s=!1,r=()=>{if(s)throw new Error("Transaction is closed")};try{let a=await e({query:async(l,o,y)=>(r(),await p(this,u,rt).call(this,l,o,y)),sql:async(l,...o)=>{let{query:y,params:c}=ot(l,...o);return await p(this,u,rt).call(this,y,c)},exec:async(l,o)=>(r(),await p(this,u,Q).call(this,l,o)),rollback:async()=>{r(),await p(this,u,Q).call(this,"ROLLBACK"),s=!0},get closed(){return s}});return s||(s=!0,await p(this,u,Q).call(this,"COMMIT")),a}catch(i){throw s||await p(this,u,Q).call(this,"ROLLBACK"),i}})}async execProtocolRaw(e,{syncToFs:s=!0}={}){let r=e.length,i=this.mod;i._interactive_write(r),i.HEAPU8.set(e,1),i._interactive_one();let a=r+2,l=a+i._interactive_read(),o=i.HEAPU8.subarray(a,l);return s&&await p(this,u,Ce).call(this),o}async execProtocol(e,{syncToFs:s=!0,onNotice:r}={}){let i=await this.execProtocolRaw(e,{syncToFs:s}),a=[];return f(this,Ue).parse(i,l=>{if(l instanceof q)throw P(this,Ue,new st),l;if(l instanceof K)this.debug>0&&console.warn(l),r&&r(l);else if(l instanceof k)switch(l.text){case"BEGIN":P(this,Z,!0);break;case"COMMIT":case"ROLLBACK":P(this,Z,!1);break}else if(l instanceof H){let o=f(this,C).get(l.channel);o&&o.forEach(y=>{queueMicrotask(()=>y(l.payload))}),f(this,te).forEach(y=>{queueMicrotask(()=>y(l.channel,l.payload))})}a.push([l,i])}),a}async listen(e,s){return f(this,C).has(e)||f(this,C).set(e,new Set),f(this,C).get(e).add(s),await this.exec(`LISTEN ${e}`),async()=>{await this.unlisten(e,s)}}async unlisten(e,s){s?(f(this,C).get(e)?.delete(s),f(this,C).get(e)?.size===0&&(await this.exec(`UNLISTEN ${e}`),f(this,C).delete(e))):(await this.exec(`UNLISTEN ${e}`),f(this,C).delete(e))}onNotification(e){return f(this,te).add(e),()=>{f(this,te).delete(e)}}offNotification(e){f(this,te).delete(e)}async dumpDataDir(e){let s=this.dataDir?.split("/").pop()??"pgdata";return this.fs.dumpTar(this.mod.FS,s,e)}};ie=new WeakMap,X=new WeakMap,J=new WeakMap,Z=new WeakMap,ne=new WeakMap,Fe=new WeakMap,ae=new WeakMap,it=new WeakMap,oe=new WeakMap,Be=new WeakMap,ke=new WeakMap,Ue=new WeakMap,ee=new WeakMap,O=new WeakMap,C=new WeakMap,te=new WeakMap,u=new WeakSet,As=async function(e){if(e.fs)this.fs=e.fs;else{let{dataDir:o,fsType:y}=Ut(e.dataDir);this.fs=await Lt(o,y)}let s={},r=[],i=[`PGDATA=${qe}`,`PREFIX=${at}`,`PGUSER=${e.username??"postgres"}`,`PGDATABASE=${e.database??"template1"}`,"MODE=REACT","REPL=N",...this.debug?["-d",this.debug.toString()]:[]],a={WASM_PREFIX:at,arguments:i,INITIAL_MEMORY:e.initialMemory,noExitRuntime:!0,...this.debug>0?{print:console.info,printErr:console.error}:{print:()=>{},printErr:()=>{}},locateFile:await qt(),preRun:[o=>{let y=o.FS.makedev(64,0),c={open:d=>{},close:d=>{},read:(d,A,L,j,N)=>{let Ft=f(this,ee);if(!Ft)throw new Error("No /dev/blob File or Blob provided to read from");let nt=new Uint8Array(Ft);if(N>=nt.length)return 0;let Bt=Math.min(nt.length-N,j);for(let Le=0;Le<Bt;Le++)A[L+Le]=nt[N+Le];return Bt},write:(d,A,L,j,N)=>(f(this,O)??P(this,O,[]),f(this,O).push(A.slice(L,L+j)),j),llseek:(d,A,L)=>{let j=f(this,ee);if(!j)throw new Error("No /dev/blob File or Blob provided to llseek");let N=A;if(L===1?N+=d.position:L===2&&(N=new Uint8Array(j).length),N<0)throw new o.FS.ErrnoError(28);return N}};o.FS.registerDevice(y,c),o.FS.mkdev("/dev/blob",y)}]};a=await this.fs.emscriptenOpts(a);for(let[o,y]of Object.entries(f(this,Be)))if(y instanceof URL)s[o]=St(y);else{let c=await y.setup(this,a);if(c.emscriptenOpts&&(a=c.emscriptenOpts),c.namespaceObj){let d=this;d[o]=c.namespaceObj}c.bundlePath&&(s[o]=St(c.bundlePath)),c.init&&r.push(c.init),c.close&&f(this,ke).push(c.close)}if(a.pg_extensions=s,this.mod=await Gt(a),await this.fs.initialSyncFs(this.mod.FS),e.loadDataDir){if(this.mod.FS.analyzePath(qe+"/PG_VERSION").exists)throw new Error("Database already exists, cannot load from tarball");p(this,u,Y).call(this,"pglite: loading data from tarball"),await kt(this.mod.FS,e.loadDataDir)}this.mod.FS.analyzePath(qe+"/PG_VERSION").exists?p(this,u,Y).call(this,"pglite: found DB, resuming"):p(this,u,Y).call(this,"pglite: no db"),await Zt(this.mod,(...o)=>p(this,u,Y).call(this,...o));let l=this.mod._pg_initdb();if(!l)throw new Error("INITDB failed to return value");if(l&1)throw new Error("INITDB failed");if(l&2){let o=e.username??"postgres",y=e.database??"template1";if(l&4){if(!(l&12))throw new Error("Invalid db/user combination")}else if(y!=="template1"&&o!=="postgres")throw new Error("INITDB created a new datadir, but an alternative db/user was requested")}await p(this,u,Ce).call(this),await p(this,u,Q).call(this,"SET search_path TO public;"),P(this,ie,!0);for(let o of r)await o()},rt=async function(e,s,r){return await f(this,Fe).runExclusive(async()=>{p(this,u,Y).call(this,"runQuery",e,s,r),await p(this,u,_t).call(this,r?.blob);let i=s?.map(o=>He(o,r?.setAllTypes))||[],a;try{a=[...await p(this,u,V).call(this,U.parse({text:e,types:i.map(([,o])=>o)}),r),...await p(this,u,V).call(this,U.bind({values:i.map(([o])=>o)}),r),...await p(this,u,V).call(this,U.describe({type:"P"}),r),...await p(this,u,V).call(this,U.execute({}),r)]}finally{await p(this,u,V).call(this,U.sync(),r)}p(this,u,Ot).call(this),f(this,Z)||await p(this,u,Ce).call(this);let l;return f(this,O)&&(l=new Blob(f(this,O)),P(this,O,void 0)),Ye(a.map(([o])=>o),r,l)[0]})},Q=async function(e,s){return await f(this,Fe).runExclusive(async()=>{p(this,u,Y).call(this,"runExec",e,s),await p(this,u,_t).call(this,s?.blob);let r;try{r=await p(this,u,V).call(this,U.query(e),s)}finally{await p(this,u,V).call(this,U.sync(),s)}p(this,u,Ot).call(this),f(this,Z)||await p(this,u,Ce).call(this);let i;return f(this,O)&&(i=new Blob(f(this,O)),P(this,O,void 0)),Ye(r.map(([a])=>a),s,i)})},_t=async function(e){P(this,ee,e?await e.arrayBuffer():void 0)},Ot=function(){P(this,ee,void 0)},Oe=async function(){if(f(this,X))throw new Error("PGlite is closing");if(f(this,J))throw new Error("PGlite is closed");f(this,ie)||await this.waitReady},V=async function(e,s={}){return await this.execProtocol(e,{...s,syncToFs:!1})},Ce=async function(){if(f(this,oe))return;P(this,oe,!0);let e=async()=>{await f(this,it).runExclusive(async()=>{P(this,oe,!1),await this.fs.syncToFs(this.mod.FS,f(this,ne))})};f(this,ne)?e():await e()},Y=function(...e){this.debug>0&&console.log(...e)};var Es=Ct;b();export{xs as IdbFs,Ps as MemoryFS,$ as Mutex,Es as PGlite,Rs as formatQuery,Wt as messages,Xt as parse,bs as protocol,Yt as types,vs as uuid};
import{b as xs,d as kt,e as Ss,f as Ps,g as at,h as Ge,i as Ut,j as Lt}from"./chunk-SJVDOE3S.js";import{d as ot}from"./chunk-TAZBUB4Z.js";import{a as Nt,b as Gt,c as vs,d as Rs}from"./chunk-3BCYDNSE.js";import{b as Ne,c as Ts,d as f,e as x,f as P,g as p,i as b}from"./chunk-Y3AVQXKT.js";b();b();b();var ri=new Error("timeout while waiting for mutex to become available"),ii=new Error("mutex already locked"),Ds=new Error("request for lock canceled"),Is=function(t,e,s,r){function i(a){return a instanceof s?a:new s(function(l){l(a)})}return new(s||(s=Promise))(function(a,l){function o(d){try{c(r.next(d))}catch(A){l(A)}}function y(d){try{c(r.throw(d))}catch(A){l(A)}}function c(d){d.done?a(d.value):i(d.value).then(o,y)}c((r=r.apply(t,e||[])).next())})},lt=class{constructor(e,s=Ds){this._value=e,this._cancelError=s,this._weightedQueues=[],this._weightedWaiters=[]}acquire(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((s,r)=>{this._weightedQueues[e-1]||(this._weightedQueues[e-1]=[]),this._weightedQueues[e-1].push({resolve:s,reject:r}),this._dispatch()})}runExclusive(e,s=1){return Is(this,void 0,void 0,function*(){let[r,i]=yield this.acquire(s);try{return yield e(r)}finally{i()}})}waitForUnlock(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise(s=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),this._weightedWaiters[e-1].push(s),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(s=>s.reject(this._cancelError))),this._weightedQueues=[]}_dispatch(){var e;for(let s=this._value;s>0;s--){let r=(e=this._weightedQueues[s-1])===null||e===void 0?void 0:e.shift();if(!r)continue;let i=this._value,a=s;this._value-=s,s=this._value+1,r.resolve([i,this._newReleaser(a)])}this._drainUnlockWaiters()}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){for(let e=this._value;e>0;e--)this._weightedWaiters[e-1]&&(this._weightedWaiters[e-1].forEach(s=>s()),this._weightedWaiters[e-1]=[])}},Ms=function(t,e,s,r){function i(a){return a instanceof s?a:new s(function(l){l(a)})}return new(s||(s=Promise))(function(a,l){function o(d){try{c(r.next(d))}catch(A){l(A)}}function y(d){try{c(r.throw(d))}catch(A){l(A)}}function c(d){d.done?a(d.value):i(d.value).then(o,y)}c((r=r.apply(t,e||[])).next())})},$=class{constructor(e){this._semaphore=new lt(1,e)}acquire(){return Ms(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()}};b();import Os from"./postgres.js";var qt=Os;var Xt={};Ne(Xt,{parseResults:()=>Ye});b();var Wt={};Ne(Wt,{AuthenticationCleartextPassword:()=>ge,AuthenticationMD5Password:()=>we,AuthenticationOk:()=>me,AuthenticationSASL:()=>be,AuthenticationSASLContinue:()=>Ee,AuthenticationSASLFinal:()=>Ae,BackendKeyDataMessage:()=>Re,CommandCompleteMessage:()=>k,CopyDataMessage:()=>Te,CopyResponse:()=>xe,DataRowMessage:()=>z,DatabaseError:()=>G,Field:()=>Se,NoticeMessage:()=>K,NotificationResponseMessage:()=>H,ParameterDescriptionMessage:()=>Pe,ParameterStatusMessage:()=>ve,ReadyForQueryMessage:()=>De,RowDescriptionMessage:()=>q,bindComplete:()=>ce,closeComplete:()=>ue,copyDone:()=>ye,emptyQuery:()=>pe,noData:()=>he,parseComplete:()=>le,portalSuspended:()=>fe,replicationStart:()=>de});b();b();var _s=Object.defineProperty,zt=t=>{throw TypeError(t)},Cs=(t,e)=>{for(var s in e)_s(t,s,{get:e[s],enumerable:!0})},ct=(t,e,s)=>e.has(t)||zt("Cannot "+s),n=(t,e,s)=>(ct(t,e,"read from private field"),s?s.call(t):e.get(t)),v=(t,e,s)=>e.has(t)?zt("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),g=(t,e,s,r)=>(ct(t,e,"write to private field"),r?r.call(t,s):e.set(t,s),s),m=(t,e,s)=>(ct(t,e,"access private method"),s),ut=(t,e,s,r)=>({set _(i){g(t,e,i,s)},get _(){return n(t,e,r)}}),ht={};Cs(ht,{AuthenticationCleartextPassword:()=>ge,AuthenticationMD5Password:()=>we,AuthenticationOk:()=>me,AuthenticationSASL:()=>be,AuthenticationSASLContinue:()=>Ee,AuthenticationSASLFinal:()=>Ae,BackendKeyDataMessage:()=>Re,CommandCompleteMessage:()=>k,CopyDataMessage:()=>Te,CopyResponse:()=>xe,DataRowMessage:()=>z,DatabaseError:()=>G,Field:()=>Se,NoticeMessage:()=>K,NotificationResponseMessage:()=>H,ParameterDescriptionMessage:()=>Pe,ParameterStatusMessage:()=>ve,ReadyForQueryMessage:()=>De,RowDescriptionMessage:()=>q,bindComplete:()=>ce,closeComplete:()=>ue,copyDone:()=>ye,emptyQuery:()=>pe,noData:()=>he,parseComplete:()=>le,portalSuspended:()=>fe,replicationStart:()=>de});var le={name:"parseComplete",length:5},ce={name:"bindComplete",length:5},ue={name:"closeComplete",length:5},he={name:"noData",length:5},fe={name:"portalSuspended",length:5},de={name:"replicationStart",length:4},pe={name:"emptyQuery",length:4},ye={name:"copyDone",length:4},me=class{constructor(t){this.length=t,this.name="authenticationOk"}},ge=class{constructor(t){this.length=t,this.name="authenticationCleartextPassword"}},we=class{constructor(t,e){this.length=t,this.salt=e,this.name="authenticationMD5Password"}},be=class{constructor(t,e){this.length=t,this.mechanisms=e,this.name="authenticationSASL"}},Ee=class{constructor(t,e){this.length=t,this.data=e,this.name="authenticationSASLContinue"}},Ae=class{constructor(t,e){this.length=t,this.data=e,this.name="authenticationSASLFinal"}},G=class extends Error{constructor(t,e,s){super(t),this.length=e,this.name=s}},Te=class{constructor(t,e){this.length=t,this.chunk=e,this.name="copyData"}},xe=class{constructor(t,e,s,r){this.length=t,this.name=e,this.binary=s,this.columnTypes=new Array(r)}},Se=class{constructor(t,e,s,r,i,a,l){this.name=t,this.tableID=e,this.columnID=s,this.dataTypeID=r,this.dataTypeSize=i,this.dataTypeModifier=a,this.format=l}},q=class{constructor(t,e){this.length=t,this.fieldCount=e,this.name="rowDescription",this.fields=new Array(this.fieldCount)}},Pe=class{constructor(t,e){this.length=t,this.parameterCount=e,this.name="parameterDescription",this.dataTypeIDs=new Array(this.parameterCount)}},ve=class{constructor(t,e,s){this.length=t,this.parameterName=e,this.parameterValue=s,this.name="parameterStatus"}},Re=class{constructor(t,e,s){this.length=t,this.processID=e,this.secretKey=s,this.name="backendKeyData"}},H=class{constructor(t,e,s,r){this.length=t,this.processId=e,this.channel=s,this.payload=r,this.name="notification"}},De=class{constructor(t,e){this.length=t,this.status=e,this.name="readyForQuery"}},k=class{constructor(t,e){this.length=t,this.text=e,this.name="commandComplete"}},z=class{constructor(t,e){this.length=t,this.fields=e,this.name="dataRow",this.fieldCount=e.length}},K=class{constructor(t,e){this.length=t,this.message=e,this.name="notice"}};var Yt={};Ne(Yt,{ABSTIME:()=>js,ACLITEM:()=>er,BIT:()=>nr,BOOL:()=>ft,BPCHAR:()=>tr,BYTEA:()=>We,CHAR:()=>Qt,CID:()=>Ns,CIDR:()=>Vs,CIRCLE:()=>Ks,DATE:()=>wt,FLOAT4:()=>mt,FLOAT8:()=>je,GTSVECTOR:()=>Ar,INET:()=>Zs,INT2:()=>dt,INT4:()=>pt,INT8:()=>Ie,INTERVAL:()=>rr,JSON:()=>Ve,JSONB:()=>At,MACADDR:()=>Js,MACADDR8:()=>Ys,MONEY:()=>Xs,NUMERIC:()=>or,OID:()=>yt,PATH:()=>Ws,PG_DEPENDENCIES:()=>wr,PG_LSN:()=>mr,PG_NDISTINCT:()=>gr,PG_NODE_TREE:()=>qs,POLYGON:()=>Qs,REFCURSOR:()=>lr,REGCLASS:()=>fr,REGCONFIG:()=>Tr,REGDICTIONARY:()=>xr,REGNAMESPACE:()=>Sr,REGOPER:()=>ur,REGOPERATOR:()=>hr,REGPROC:()=>ks,REGPROCEDURE:()=>cr,REGROLE:()=>Pr,REGTYPE:()=>dr,RELTIME:()=>$s,SMGR:()=>zs,TEXT:()=>Qe,TID:()=>Us,TIME:()=>sr,TIMESTAMP:()=>bt,TIMESTAMPTZ:()=>Et,TIMETZ:()=>ir,TINTERVAL:()=>Hs,TSQUERY:()=>Er,TSVECTOR:()=>br,TXID_SNAPSHOT:()=>yr,UUID:()=>pr,VARBIT:()=>ar,VARCHAR:()=>gt,XID:()=>Ls,XML:()=>Gs,arrayTypes:()=>qe,parseArray:()=>Kt,parseType:()=>Ke,parsers:()=>Vt,serializeType:()=>He,serializerFor:()=>$t,serializerInstanceof:()=>jt,serializers:()=>ze,types:()=>Tt});b();var Fs=globalThis.JSON.parse,Bs=globalThis.JSON.stringify,ft=16,We=17,Qt=18,Ie=20,dt=21,pt=23,ks=24,Qe=25,yt=26,Us=27,Ls=28,Ns=29,Ve=114,Gs=142,qs=194,zs=210,Ws=602,Qs=604,Vs=650,mt=700,je=701,js=702,$s=703,Hs=704,Ks=718,Ys=774,Xs=790,Js=829,Zs=869,er=1033,tr=1042,gt=1043,wt=1082,sr=1083,bt=1114,Et=1184,rr=1186,ir=1266,nr=1560,ar=1562,or=1700,lr=1790,cr=2202,ur=2203,hr=2204,fr=2205,dr=2206,pr=2950,yr=2970,mr=3220,gr=3361,wr=3402,br=3614,Er=3615,Ar=3642,Tr=3734,xr=3769,At=3802,Sr=4089,Pr=4096,qe={1001:We,1002:Qt,1016:Ie,1005:dt,1007:pt,1009:Qe,1028:yt,199:Ve,1021:mt,1022:je,1015:gt,3807:At,1182:wt,1115:bt,1116:Et},Tt={string:{to:0,from:[Qe,gt],serialize:t=>t,parse:t=>t,forceTo:Qe},number:{to:0,from:[dt,pt,yt,mt,je],serialize:t=>t.toString(),parse:t=>+t,forceTo:t=>Number.isInteger(t)?Ie:je},bigint:{to:Ie,from:[Ie],js:[BigInt],serialize:t=>t.toString(),parse:t=>{let e=BigInt(t);return e<Number.MIN_SAFE_INTEGER||e>Number.MAX_SAFE_INTEGER?e:Number(e)}},json:{to:Ve,from:[Ve,At],serialize:t=>Bs(t),parse:t=>Fs(t)},boolean:{to:ft,from:[ft],serialize:t=>t===!0?"t":"f",parse:t=>t==="t"},date:{to:1184,from:[wt,bt,Et],js:[Date],serialize:t=>(t instanceof Date?t:new Date(t)).toISOString(),parse:t=>new Date(t)},bytea:{to:We,from:[We],js:[Uint8Array],serialize:t=>"\\x"+Array.from(t).map(e=>e.toString(16).padStart(2,"0")).join(""),parse:t=>{let e=t.slice(2);return Uint8Array.from({length:e.length/2},(s,r)=>parseInt(e.substring(r*2,(r+1)*2),16))}},array:{to:0,from:Object.keys(qe).map(t=>+t),serialize:t=>Ht(t),parse:(t,e)=>{let s;return e&&e in qe&&(s=Vt[qe[e]]),Kt(t,s)}}},$e=Rr(Tt),Vt=$e.parsers,ze=$e.serializers,jt=$e.serializerInstanceof;function $t(t){if(Array.isArray(t))return ze.array;let e=ze[typeof t];if(e)return e;for(let[s,r]of jt)if(t instanceof s)return r;return ze.json}function He(t,e=!1){return t==null?[null,0]:$t(t)(t,e)}function vr(t){return'"'+t.replace(/\\/g,"\\\\").replace(/"/g,'\\"')+'"'}function Ht(t){let e="{";for(let s=0;s<t.length;s++)if(s>0&&(e=e+","),t[s]===null||typeof t[s]>"u")e=e+"NULL";else if(Array.isArray(t[s]))e=e+Ht(t[s]);else if(ArrayBuffer.isView(t[s])||t[s]instanceof ArrayBuffer){let r=ArrayBuffer.isView(t[s])?new Uint8Array(t[s].buffer,t[s].byteOffset,t[s].byteLength):new Uint8Array(t[s]);e+="\\"+Tt.bytea.serialize(r)}else e+=vr(He(t[s])[0]);return e=e+"}",e}function Kt(t,e){let s=0,r=null,i="",a=!1,l=0,o;function y(c){let d=[];for(;s<c.length;s++){if(r=c[s],a)r==="\\"?i+=c[++s]:r==='"'?(d.push(e?e(i):i),i="",a=c[s+1]==='"',l=s+2):i+=r;else if(r==='"')a=!0;else if(r==="{")l=++s,d.push(y(c));else if(r==="}"){a=!1,l<s&&d.push(e?e(c.slice(l,s)):c.slice(l,s)),l=s+1;break}else r===","&&o!=="}"&&o!=='"'&&(d.push(e?e(c.slice(l,s)):c.slice(l,s)),l=s+1);o=r}return l<s&&d.push(e?e(c.slice(l,s+1)):c.slice(l,s+1)),d}return y(t)[0]}function Ke(t,e,s){if(t===null)return null;let r=s?.[e]??$e.parsers[e];return r?r(t,e):t}function Rr(t){return Object.keys(t).reduce(({parsers:e,serializers:s,serializerInstanceof:r},i)=>{let{to:a,from:l,serialize:o,parse:y=null,forceTo:c}=t[i],d=(A,L=!1)=>[o(A),L&&c?typeof c=="function"?c(A):c:a];return s[a]=d,s[i]=d,t[i].js&&t[i].js.forEach(A=>r.push([A,d])),y&&(Array.isArray(l)?l.forEach(A=>e[A]=y):e[l]=y,e[i]=y),{parsers:e,serializers:s,serializerInstanceof:r}},{parsers:{},serializers:{},serializerInstanceof:[]})}function Ye(t,e,s){let r=[],i={rows:[],fields:[]},a=0,l=t.filter(o=>o instanceof q||o instanceof z||o instanceof k);return l.forEach((o,y)=>{o instanceof q?i.fields=o.fields.map(c=>({name:c.name,dataTypeID:c.dataTypeID})):o instanceof z&&i?e?.rowMode==="array"?i.rows.push(o.fields.map((c,d)=>Ke(c,i.fields[d].dataTypeID,e?.parsers))):i.rows.push(Object.fromEntries(o.fields.map((c,d)=>[i.fields[d].name,Ke(c,i.fields[d].dataTypeID,e?.parsers)]))):o instanceof k&&(a+=Dr(o),y===l.length-1?r.push({...i,affectedRows:a,...s?{blob:s}:{}}):r.push(i),i={rows:[],fields:[]})}),r.length===0&&r.push({rows:[],fields:[]}),r}function Dr(t){let e=t.text.split(" ");switch(e[0]){case"INSERT":return parseInt(e[2],10);case"UPDATE":case"DELETE":return parseInt(e[1],10);default:return 0}}b();var Jt=Ts(xs(),1);async function xt(t){if(Nt){let e=await import("fs"),s=await import("zlib"),{Writable:r}=await import("stream"),{pipeline:i}=await import("stream/promises");if(!e.existsSync(t))throw new Error(`Extension bundle not found: ${t}`);let a=s.createGunzip(),l=[];return await i(e.createReadStream(t),a,new r({write(o,y,c){l.push(o),c()}})),new Blob(l)}else{let e=await fetch(t.toString());if(!e.ok||!e.body)return null;if(e.headers.get("Content-Encoding")==="gzip")return e.blob();{let s=new DecompressionStream("gzip");return new Response(e.body.pipeThrough(s)).blob()}}}async function Zt(t,e){for(let s in t.pg_extensions){let r;try{r=await t.pg_extensions[s]}catch(i){console.error("Failed to fetch extension:",s,i);continue}if(r){let i=new Uint8Array(await r.arrayBuffer());Ir(t,s,i,e)}else console.error("Could not get binary data for extension:",s)}}function Ir(t,e,s,r){Jt.default.untar(s).forEach(a=>{if(!a.name.startsWith(".")){let l=t.WASM_PREFIX+"/"+a.name;if(a.name.endsWith(".so")){let o=(...c)=>{r("pgfs:ext OK",l,c)},y=(...c)=>{r("pgfs:ext FAIL",l,c)};t.FS.createPreloadedFile(Mr(l),a.name.split("/").pop().slice(0,-3),a.data,!0,!0,o,y,!1)}else t.FS.writeFile(l,a.data)}})}function Mr(t){let e=t.lastIndexOf("/");return e>0?t.slice(0,e):t}var bs={};Ne(bs,{Parser:()=>st,messages:()=>ht,serialize:()=>U});b();function Ze(t){let e=t.length;for(let s=t.length-1;s>=0;s--){let r=t.charCodeAt(s);r>127&&r<=2047?e++:r>2047&&r<=65535&&(e+=2),r>=56320&&r<=57343&&s--}return e}var R,T,Oe,vt,Me,O,Je,se,ms,et=class{constructor(t=256){this.size=t,v(this,O),v(this,R),v(this,T,5),v(this,Oe,!1),v(this,vt,new TextEncoder),v(this,Me,0),g(this,R,m(this,O,Je).call(this,t))}addInt32(t){return m(this,O,se).call(this,4),n(this,R).setInt32(n(this,T),t,n(this,Oe)),g(this,T,n(this,T)+4),this}addInt16(t){return m(this,O,se).call(this,2),n(this,R).setInt16(n(this,T),t,n(this,Oe)),g(this,T,n(this,T)+2),this}addCString(t){return t&&this.addString(t),m(this,O,se).call(this,1),n(this,R).setUint8(n(this,T),0),ut(this,T)._++,this}addString(t=""){let e=Ze(t);return m(this,O,se).call(this,e),n(this,vt).encodeInto(t,new Uint8Array(n(this,R).buffer,n(this,T))),g(this,T,n(this,T)+e),this}add(t){return m(this,O,se).call(this,t.byteLength),new Uint8Array(n(this,R).buffer).set(new Uint8Array(t),n(this,T)),g(this,T,n(this,T)+t.byteLength),this}flush(t){let e=m(this,O,ms).call(this,t);return g(this,T,5),g(this,R,m(this,O,Je).call(this,this.size)),new Uint8Array(e)}};R=new WeakMap,T=new WeakMap,Oe=new WeakMap,vt=new WeakMap,Me=new WeakMap,O=new WeakSet,Je=function(t){return new DataView(new ArrayBuffer(t))},se=function(t){if(n(this,R).byteLength-n(this,T)<t){let e=n(this,R).buffer,s=e.byteLength+(e.byteLength>>1)+t;g(this,R,m(this,O,Je).call(this,s)),new Uint8Array(n(this,R).buffer).set(new Uint8Array(e))}},ms=function(t){if(t){n(this,R).setUint8(n(this,Me),t);let e=n(this,T)-(n(this,Me)+1);n(this,R).setInt32(n(this,Me)+1,e,n(this,Oe))}return n(this,R).buffer.slice(t?0:5,n(this,T))};var w=new et,Or=t=>{w.addInt16(3).addInt16(0);for(let r of Object.keys(t))w.addCString(r).addCString(t[r]);w.addCString("client_encoding").addCString("UTF8");let e=w.addCString("").flush(),s=e.byteLength+4;return new et().addInt32(s).add(e).flush()},_r=()=>{let t=new DataView(new ArrayBuffer(8));return t.setInt32(0,8,!1),t.setInt32(4,80877103,!1),new Uint8Array(t.buffer)},Cr=t=>w.addCString(t).flush(112),Fr=(t,e)=>(w.addCString(t).addInt32(Ze(e)).addString(e),w.flush(112)),Br=t=>w.addString(t).flush(112),kr=t=>w.addCString(t).flush(81),Ur=[],Lr=t=>{let e=t.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 s=w.addCString(e).addCString(t.text).addInt16(t.types?.length??0);return t.types?.forEach(r=>s.addInt32(r)),w.flush(80)},re=new et,Nr=(t,e)=>{for(let s=0;s<t.length;s++){let r=e?e(t[s],s):t[s];if(r===null)w.addInt16(0),re.addInt32(-1);else if(r instanceof ArrayBuffer||ArrayBuffer.isView(r)){let i=ArrayBuffer.isView(r)?r.buffer.slice(r.byteOffset,r.byteOffset+r.byteLength):r;w.addInt16(1),re.addInt32(i.byteLength),re.add(i)}else w.addInt16(0),re.addInt32(Ze(r)),re.addString(r)}},Gr=(t={})=>{let e=t.portal??"",s=t.statement??"",r=t.binary??!1,i=t.values??Ur,a=i.length;return w.addCString(e).addCString(s),w.addInt16(a),Nr(i,t.valueMapper),w.addInt16(a),w.add(re.flush()),w.addInt16(r?1:0),w.flush(66)},qr=new Uint8Array([69,0,0,0,9,0,0,0,0,0]),zr=t=>{if(!t||!t.portal&&!t.rows)return qr;let e=t.portal??"",s=t.rows??0,r=Ze(e),i=4+r+1+4,a=new DataView(new ArrayBuffer(1+i));return a.setUint8(0,69),a.setInt32(1,i,!1),new TextEncoder().encodeInto(e,new Uint8Array(a.buffer,5)),a.setUint8(r+5,0),a.setUint32(a.byteLength-4,s,!1),new Uint8Array(a.buffer)},Wr=(t,e)=>{let s=new DataView(new ArrayBuffer(16));return s.setInt32(0,16,!1),s.setInt16(4,1234,!1),s.setInt16(6,5678,!1),s.setInt32(8,t,!1),s.setInt32(12,e,!1),new Uint8Array(s.buffer)},Mt=(t,e)=>{let s=new et;return s.addCString(e),s.flush(t)},Qr=w.addCString("P").flush(68),Vr=w.addCString("S").flush(68),jr=t=>t.name?Mt(68,`${t.type}${t.name??""}`):t.type==="P"?Qr:Vr,$r=t=>{let e=`${t.type}${t.name??""}`;return Mt(67,e)},Hr=t=>w.add(t).flush(100),Kr=t=>Mt(102,t),tt=t=>new Uint8Array([t,0,0,0,4]),Yr=tt(72),Xr=tt(83),Jr=tt(88),Zr=tt(99),U={startup:Or,password:Cr,requestSsl:_r,sendSASLInitialResponseMessage:Fr,sendSCRAMClientFinalMessage:Br,query:kr,parse:Lr,bind:Gr,execute:zr,describe:jr,close:$r,flush:()=>Yr,sync:()=>Xr,end:()=>Jr,copyData:Hr,copyDone:()=>Zr,copyFail:Kr,cancel:Wr},es={text:0,binary:1},ei=new ArrayBuffer(0),W,S,Rt,Dt,Xe,ti=class{constructor(t=0){v(this,W,new DataView(ei)),v(this,S),v(this,Rt,"utf-8"),v(this,Dt,new TextDecoder(n(this,Rt))),v(this,Xe,!1),g(this,S,t)}setBuffer(t,e){g(this,S,t),g(this,W,new DataView(e))}int16(){let t=n(this,W).getInt16(n(this,S),n(this,Xe));return g(this,S,n(this,S)+2),t}byte(){let t=n(this,W).getUint8(n(this,S));return ut(this,S)._++,t}int32(){let t=n(this,W).getInt32(n(this,S),n(this,Xe));return g(this,S,n(this,S)+4),t}string(t){return n(this,Dt).decode(this.bytes(t))}cstring(){let t=n(this,S),e=t;for(;n(this,W).getUint8(e++)!==0;);let s=this.string(e-t-1);return g(this,S,e),s}bytes(t){let e=n(this,W).buffer.slice(n(this,S),n(this,S)+t);return g(this,S,n(this,S)+t),new Uint8Array(e)}};W=new WeakMap,S=new WeakMap,Rt=new WeakMap,Dt=new WeakMap,Xe=new WeakMap;var It=1,si=4,ts=It+si,ss=new ArrayBuffer(0),D,I,M,h,E,gs,ws,rs,is,ns,as,os,St,ls,cs,us,hs,fs,ds,ps,ys,Pt,st=class{constructor(){v(this,E),v(this,D,new DataView(ss)),v(this,I,0),v(this,M,0),v(this,h,new ti)}parse(t,e){m(this,E,gs).call(this,ArrayBuffer.isView(t)?t.buffer.slice(t.byteOffset,t.byteOffset+t.byteLength):t);let s=n(this,M)+n(this,I),r=n(this,M);for(;r+ts<=s;){let i=n(this,D).getUint8(r),a=n(this,D).getUint32(r+It,!1),l=It+a;if(l+r<=s){let o=m(this,E,ws).call(this,r+ts,i,a,n(this,D).buffer);e(o),r+=l}else break}r===s?(g(this,D,new DataView(ss)),g(this,I,0),g(this,M,0)):(g(this,I,s-r),g(this,M,r))}};D=new WeakMap,I=new WeakMap,M=new WeakMap,h=new WeakMap,E=new WeakSet,gs=function(t){if(n(this,I)>0){let e=n(this,I)+t.byteLength;if(e+n(this,M)>n(this,D).byteLength){let s;if(e<=n(this,D).byteLength&&n(this,M)>=n(this,I))s=n(this,D).buffer;else{let r=n(this,D).byteLength*2;for(;e>=r;)r*=2;s=new ArrayBuffer(r)}new Uint8Array(s).set(new Uint8Array(n(this,D).buffer,n(this,M),n(this,I))),g(this,D,new DataView(s)),g(this,M,0)}new Uint8Array(n(this,D).buffer).set(new Uint8Array(t),n(this,M)+n(this,I)),g(this,I,e)}else g(this,D,new DataView(t)),g(this,M,0),g(this,I,t.byteLength)},ws=function(t,e,s,r){switch(e){case 50:return ce;case 49:return le;case 51:return ue;case 110:return he;case 115:return fe;case 99:return ye;case 87:return de;case 73:return pe;case 68:return m(this,E,fs).call(this,t,s,r);case 67:return m(this,E,is).call(this,t,s,r);case 90:return m(this,E,rs).call(this,t,s,r);case 65:return m(this,E,ls).call(this,t,s,r);case 82:return m(this,E,ys).call(this,t,s,r);case 83:return m(this,E,ds).call(this,t,s,r);case 75:return m(this,E,ps).call(this,t,s,r);case 69:return m(this,E,Pt).call(this,t,s,r,"error");case 78:return m(this,E,Pt).call(this,t,s,r,"notice");case 84:return m(this,E,cs).call(this,t,s,r);case 116:return m(this,E,hs).call(this,t,s,r);case 71:return m(this,E,as).call(this,t,s,r);case 72:return m(this,E,os).call(this,t,s,r);case 100:return m(this,E,ns).call(this,t,s,r);default:return new G("received invalid response: "+e.toString(16),s,"error")}},rs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).string(1);return new De(e,r)},is=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).cstring();return new k(e,r)},ns=function(t,e,s){let r=s.slice(t,t+(e-4));return new Te(e,new Uint8Array(r))},as=function(t,e,s){return m(this,E,St).call(this,t,e,s,"copyInResponse")},os=function(t,e,s){return m(this,E,St).call(this,t,e,s,"copyOutResponse")},St=function(t,e,s,r){n(this,h).setBuffer(t,s);let i=n(this,h).byte()!==0,a=n(this,h).int16(),l=new xe(e,r,i,a);for(let o=0;o<a;o++)l.columnTypes[o]=n(this,h).int16();return l},ls=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32(),i=n(this,h).cstring(),a=n(this,h).cstring();return new H(e,r,i,a)},cs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new q(e,r);for(let a=0;a<r;a++)i.fields[a]=m(this,E,us).call(this);return i},us=function(){let t=n(this,h).cstring(),e=n(this,h).int32(),s=n(this,h).int16(),r=n(this,h).int32(),i=n(this,h).int16(),a=n(this,h).int32(),l=n(this,h).int16()===0?es.text:es.binary;return new Se(t,e,s,r,i,a,l)},hs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new Pe(e,r);for(let a=0;a<r;a++)i.dataTypeIDs[a]=n(this,h).int32();return i},fs=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int16(),i=new Array(r);for(let a=0;a<r;a++){let l=n(this,h).int32();i[a]=l===-1?null:n(this,h).string(l)}return new z(e,i)},ds=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).cstring(),i=n(this,h).cstring();return new ve(e,r,i)},ps=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32(),i=n(this,h).int32();return new Re(e,r,i)},ys=function(t,e,s){n(this,h).setBuffer(t,s);let r=n(this,h).int32();switch(r){case 0:return new me(e);case 3:return new ge(e);case 5:return new we(e,n(this,h).bytes(4));case 10:{let i=[];for(;;){let a=n(this,h).cstring();if(a.length===0)return new be(e,i);i.push(a)}}case 11:return new Ee(e,n(this,h).string(e-8));case 12:return new Ae(e,n(this,h).string(e-8));default:throw new Error("Unknown authenticationOk message type "+r)}},Pt=function(t,e,s,r){n(this,h).setBuffer(t,s);let i={},a=n(this,h).string(1);for(;a!=="\0";)i[a]=n(this,h).cstring(),a=n(this,h).string(1);let l=i.M,o=r==="notice"?new K(e,l):new G(l,e,r);return o.severity=i.S,o.code=i.C,o.detail=i.D,o.hint=i.H,o.position=i.P,o.internalPosition=i.p,o.internalQuery=i.q,o.where=i.W,o.schema=i.s,o.table=i.t,o.column=i.c,o.dataType=i.d,o.constraint=i.n,o.file=i.F,o.line=i.L,o.routine=i.R,o};var ie,X,J,Z,ne,Fe,ae,it,oe,Be,ke,Ue,ee,_,C,te,u,As,rt,Q,Ot,_t,_e,V,Ce,Y,Ct=class Ct{constructor(e={},s={}){x(this,u);x(this,ie,!1);x(this,X,!1);x(this,J,!1);x(this,Z,!1);x(this,ne,!1);x(this,Fe,new $);x(this,ae,new $);x(this,it,new $);x(this,oe,!1);this.debug=0;x(this,Be);x(this,ke,[]);x(this,Ue,new st);x(this,ee);x(this,_);x(this,C,new Map);x(this,te,new Set);typeof e=="string"?s={dataDir:e,...s}:s=e,this.dataDir=s.dataDir,s?.debug!==void 0&&(this.debug=s.debug),s?.relaxedDurability!==void 0&&P(this,ne,s.relaxedDurability),P(this,Be,s.extensions??{}),this.waitReady=p(this,u,As).call(this,s??{})}static async create(e,s){let r=typeof e=="string"?{dataDir:e,...s??{}}:e??{},i=new Ct(r);return await i.waitReady,i}get Module(){return this.mod}get ready(){return f(this,ie)&&!f(this,X)&&!f(this,J)}get closed(){return f(this,J)}async close(){await p(this,u,_e).call(this),P(this,X,!0);for(let e of f(this,ke))await e();try{await this.execProtocol(U.end())}catch(e){let s=e;if(!(s.name==="ExitStatus"&&s.status===0))throw e}await this.fs.close(this.mod.FS),P(this,J,!0),P(this,X,!1)}async[Symbol.asyncDispose](){await this.close()}async query(e,s,r){return await p(this,u,_e).call(this),await f(this,ae).runExclusive(async()=>await p(this,u,rt).call(this,e,s,r))}async sql(e,...s){let{query:r,params:i}=ot(e,...s);return await this.query(r,i)}async exec(e,s){return await p(this,u,_e).call(this),await f(this,ae).runExclusive(async()=>await p(this,u,Q).call(this,e,s))}async transaction(e){return await p(this,u,_e).call(this),await f(this,ae).runExclusive(async()=>{await p(this,u,Q).call(this,"BEGIN");let s=!1,r=()=>{if(s)throw new Error("Transaction is closed")};try{let a=await e({query:async(l,o,y)=>(r(),await p(this,u,rt).call(this,l,o,y)),sql:async(l,...o)=>{let{query:y,params:c}=ot(l,...o);return await p(this,u,rt).call(this,y,c)},exec:async(l,o)=>(r(),await p(this,u,Q).call(this,l,o)),rollback:async()=>{r(),await p(this,u,Q).call(this,"ROLLBACK"),s=!0},get closed(){return s}});return s||(s=!0,await p(this,u,Q).call(this,"COMMIT")),a}catch(i){throw s||await p(this,u,Q).call(this,"ROLLBACK"),i}})}async execProtocolRaw(e,{syncToFs:s=!0}={}){let r=e.length,i=this.mod;i._interactive_write(r),i.HEAPU8.set(e,1),i._interactive_one();let a=r+2,l=a+i._interactive_read(),o=i.HEAPU8.subarray(a,l);return s&&await p(this,u,Ce).call(this),o}async execProtocol(e,{syncToFs:s=!0,onNotice:r}={}){let i=await this.execProtocolRaw(e,{syncToFs:s}),a=[];return f(this,Ue).parse(i,l=>{if(l instanceof G)throw P(this,Ue,new st),l;if(l instanceof K)this.debug>0&&console.warn(l),r&&r(l);else if(l instanceof k)switch(l.text){case"BEGIN":P(this,Z,!0);break;case"COMMIT":case"ROLLBACK":P(this,Z,!1);break}else if(l instanceof H){let o=f(this,C).get(l.channel);o&&o.forEach(y=>{queueMicrotask(()=>y(l.payload))}),f(this,te).forEach(y=>{queueMicrotask(()=>y(l.channel,l.payload))})}a.push([l,i])}),a}async listen(e,s){return f(this,C).has(e)||f(this,C).set(e,new Set),f(this,C).get(e).add(s),await this.exec(`LISTEN ${e}`),async()=>{await this.unlisten(e,s)}}async unlisten(e,s){s?(f(this,C).get(e)?.delete(s),f(this,C).get(e)?.size===0&&(await this.exec(`UNLISTEN ${e}`),f(this,C).delete(e))):(await this.exec(`UNLISTEN ${e}`),f(this,C).delete(e))}onNotification(e){return f(this,te).add(e),()=>{f(this,te).delete(e)}}offNotification(e){f(this,te).delete(e)}async dumpDataDir(e){let s=this.dataDir?.split("/").pop()??"pgdata";return this.fs.dumpTar(this.mod.FS,s,e)}};ie=new WeakMap,X=new WeakMap,J=new WeakMap,Z=new WeakMap,ne=new WeakMap,Fe=new WeakMap,ae=new WeakMap,it=new WeakMap,oe=new WeakMap,Be=new WeakMap,ke=new WeakMap,Ue=new WeakMap,ee=new WeakMap,_=new WeakMap,C=new WeakMap,te=new WeakMap,u=new WeakSet,As=async function(e){if(e.fs)this.fs=e.fs;else{let{dataDir:o,fsType:y}=Ut(e.dataDir);this.fs=await Lt(o,y)}let s={},r=[],i=[`PGDATA=${Ge}`,`PREFIX=${at}`,`PGUSER=${e.username??"postgres"}`,`PGDATABASE=${e.database??"template1"}`,"MODE=REACT","REPL=N",...this.debug?["-d",this.debug.toString()]:[]],a={WASM_PREFIX:at,arguments:i,INITIAL_MEMORY:e.initialMemory,noExitRuntime:!0,...this.debug>0?{print:console.info,printErr:console.error}:{print:()=>{},printErr:()=>{}},locateFile:await Gt(),preRun:[o=>{let y=o.FS.makedev(64,0),c={open:d=>{},close:d=>{},read:(d,A,L,j,N)=>{let Ft=f(this,ee);if(!Ft)throw new Error("No /dev/blob File or Blob provided to read from");let nt=new Uint8Array(Ft);if(N>=nt.length)return 0;let Bt=Math.min(nt.length-N,j);for(let Le=0;Le<Bt;Le++)A[L+Le]=nt[N+Le];return Bt},write:(d,A,L,j,N)=>(f(this,_)??P(this,_,[]),f(this,_).push(A.slice(L,L+j)),j),llseek:(d,A,L)=>{let j=f(this,ee);if(!j)throw new Error("No /dev/blob File or Blob provided to llseek");let N=A;if(L===1?N+=d.position:L===2&&(N=new Uint8Array(j).length),N<0)throw new o.FS.ErrnoError(28);return N}};o.FS.registerDevice(y,c),o.FS.mkdev("/dev/blob",y)}]};a=await this.fs.emscriptenOpts(a);for(let[o,y]of Object.entries(f(this,Be)))if(y instanceof URL)s[o]=xt(y);else{let c=await y.setup(this,a);if(c.emscriptenOpts&&(a=c.emscriptenOpts),c.namespaceObj){let d=this;d[o]=c.namespaceObj}c.bundlePath&&(s[o]=xt(c.bundlePath)),c.init&&r.push(c.init),c.close&&f(this,ke).push(c.close)}if(a.pg_extensions=s,this.mod=await qt(a),await this.fs.initialSyncFs(this.mod.FS),e.loadDataDir){if(this.mod.FS.analyzePath(Ge+"/PG_VERSION").exists)throw new Error("Database already exists, cannot load from tarball");p(this,u,Y).call(this,"pglite: loading data from tarball"),await kt(this.mod.FS,e.loadDataDir)}this.mod.FS.analyzePath(Ge+"/PG_VERSION").exists?p(this,u,Y).call(this,"pglite: found DB, resuming"):p(this,u,Y).call(this,"pglite: no db"),await Zt(this.mod,(...o)=>p(this,u,Y).call(this,...o));let l=this.mod._pg_initdb();if(!l)throw new Error("INITDB failed to return value");if(l&1)throw new Error("INITDB failed");if(l&2){let o=e.username??"postgres",y=e.database??"template1";if(l&4){if(!(l&12))throw new Error("Invalid db/user combination")}else if(y!=="template1"&&o!=="postgres")throw new Error("INITDB created a new datadir, but an alternative db/user was requested")}await p(this,u,Ce).call(this),await p(this,u,Q).call(this,"SET search_path TO public;"),P(this,ie,!0);for(let o of r)await o()},rt=async function(e,s,r){return await f(this,Fe).runExclusive(async()=>{p(this,u,Y).call(this,"runQuery",e,s,r),await p(this,u,Ot).call(this,r?.blob);let i=s?.map(o=>He(o,r?.setAllTypes))||[],a;try{a=[...await p(this,u,V).call(this,U.parse({text:e,types:i.map(([,o])=>o)}),r),...await p(this,u,V).call(this,U.bind({values:i.map(([o])=>o)}),r),...await p(this,u,V).call(this,U.describe({type:"P"}),r),...await p(this,u,V).call(this,U.execute({}),r)]}finally{await p(this,u,V).call(this,U.sync(),r)}p(this,u,_t).call(this),f(this,Z)||await p(this,u,Ce).call(this);let l;return f(this,_)&&(l=new Blob(f(this,_)),P(this,_,void 0)),Ye(a.map(([o])=>o),r,l)[0]})},Q=async function(e,s){return await f(this,Fe).runExclusive(async()=>{p(this,u,Y).call(this,"runExec",e,s),await p(this,u,Ot).call(this,s?.blob);let r;try{r=await p(this,u,V).call(this,U.query(e),s)}finally{await p(this,u,V).call(this,U.sync(),s)}p(this,u,_t).call(this),f(this,Z)||await p(this,u,Ce).call(this);let i;return f(this,_)&&(i=new Blob(f(this,_)),P(this,_,void 0)),Ye(r.map(([a])=>a),s,i)})},Ot=async function(e){P(this,ee,e?await e.arrayBuffer():void 0)},_t=function(){P(this,ee,void 0)},_e=async function(){if(f(this,X))throw new Error("PGlite is closing");if(f(this,J))throw new Error("PGlite is closed");f(this,ie)||await this.waitReady},V=async function(e,s={}){return await this.execProtocol(e,{...s,syncToFs:!1})},Ce=async function(){if(f(this,oe))return;P(this,oe,!0);let e=async()=>{await f(this,it).runExclusive(async()=>{P(this,oe,!1),await this.fs.syncToFs(this.mod.FS,f(this,ne))})};f(this,ne)?e():await e()},Y=function(...e){this.debug>0&&console.log(...e)};var Es=Ct;b();export{Ss as IdbFs,Ps as MemoryFS,$ as Mutex,Es as PGlite,Rs as formatQuery,Wt as messages,Xt as parse,bs as protocol,Yt as types,vs as uuid};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import{c as N}from"../chunk-3BCYDNSE.js";import{d as s,e as l,f as p,g as h,i as j}from"../chunk-Y3AVQXKT.js";j();var L,T,A,b,O,w,R,E,m,C,I,G,M,k,q,f,W,D,B,o,F,$,g,z,U=class U{constructor(e,t){l(this,o);l(this,L);l(this,T,0);l(this,A,!1);l(this,b,!1);l(this,O,!1);l(this,w,new EventTarget);l(this,R);l(this,E,!1);l(this,m);l(this,C);l(this,I);l(this,G);l(this,M);l(this,k);l(this,q);l(this,f,new Map);l(this,W,new Set);l(this,D);l(this,B,[]);p(this,m,e),p(this,R,N()),p(this,D,t?.extensions??{}),p(this,I,new Promise(r=>{s(this,m).addEventListener("message",a=>{if(a.data.type==="here")r();else throw new Error("Invalid message")},{once:!0})})),p(this,G,new Promise(r=>{let a=i=>{i.data.type==="ready"&&(p(this,C,i.data.id),s(this,m).removeEventListener("message",a),r())};s(this,m).addEventListener("message",a)})),p(this,L,h(this,o,F).call(this,t))}static async create(e,t){let r=new U(e,t);return await s(r,L),r}get waitReady(){return new Promise(e=>{s(this,L).then(()=>{s(this,E)?e():e(new Promise(t=>{s(this,w).addEventListener("connected",()=>{t()})}))})})}get debug(){return s(this,T)}get ready(){return s(this,A)}get closed(){return s(this,b)}get isLeader(){return s(this,O)}async close(){var e;s(this,b)||(p(this,b,!0),s(this,M)?.close(),s(this,k)?.close(),(e=s(this,q))==null||e.call(this),s(this,m).terminate())}async[Symbol.asyncDispose](){await this.close()}async query(e,t,r){return await this.waitReady,await h(this,o,g).call(this,"query",e,t,r)}async sql(e,...t){return await this.waitReady,await h(this,o,g).call(this,"sql",e,e.raw,t)}async exec(e,t){return await this.waitReady,await h(this,o,g).call(this,"exec",e,t)}async transaction(e){await this.waitReady;let t=await h(this,o,g).call(this,"transactionStart"),r;try{r=await e({query:async(a,i,y)=>await h(this,o,g).call(this,"transactionQuery",t,a,i,y),exec:async(a,i)=>await h(this,o,g).call(this,"transactionExec",t,a,i),rollback:async()=>{await h(this,o,g).call(this,"transactionRollback",t)},closed:!1})}catch(a){throw await h(this,o,g).call(this,"transactionRollback",t),a}return await h(this,o,g).call(this,"transactionCommit",t),r}async execProtocolRaw(e){return await this.waitReady,await h(this,o,g).call(this,"execProtocolRaw",e)}async execProtocol(e){return await this.waitReady,await h(this,o,g).call(this,"execProtocol",e)}async listen(e,t){return await this.waitReady,s(this,f).has(e)||s(this,f).set(e,new Set),s(this,f).get(e)?.add(t),await this.exec(`LISTEN ${e}`),async()=>{await this.unlisten(e,t)}}async unlisten(e,t){await this.waitReady,t?s(this,f).get(e)?.delete(t):s(this,f).delete(e),s(this,f).get(e)?.size===0&&await this.exec(`UNLISTEN ${e}`)}onNotification(e){return s(this,W).add(e),()=>{s(this,W).delete(e)}}offNotification(e){s(this,W).delete(e)}async dumpDataDir(){return await h(this,o,g).call(this,"dumpDataDir")}onLeaderChange(e){return s(this,w).addEventListener("leader-change",e),()=>{s(this,w).removeEventListener("leader-change",e)}}offLeaderChange(e){s(this,w).removeEventListener("leader-change",e)}};L=new WeakMap,T=new WeakMap,A=new WeakMap,b=new WeakMap,O=new WeakMap,w=new WeakMap,R=new WeakMap,E=new WeakMap,m=new WeakMap,C=new WeakMap,I=new WeakMap,G=new WeakMap,M=new WeakMap,k=new WeakMap,q=new WeakMap,f=new WeakMap,W=new WeakMap,D=new WeakMap,B=new WeakMap,o=new WeakSet,F=async function(e={}){for(let[n,v]of Object.entries(s(this,D))){if(v instanceof URL)throw new Error("URL extensions are not supported on the client side of a worker");{let d=await v.setup(this,{},!0);if(d.emscriptenOpts&&console.warn(`PGlite extension ${n} returned emscriptenOpts, these are not supported on the client side of a worker`),d.namespaceObj){let u=this;u[n]=d.namespaceObj}d.bundlePath&&console.warn(`PGlite extension ${n} returned bundlePath, this is not supported on the client side of a worker`),d.init&&await d.init(),d.close&&s(this,B).push(d.close)}}await s(this,I);let{extensions:t,...r}=e;s(this,m).postMessage({type:"init",options:r}),await s(this,G);let a=`pglite-tab-close:${s(this,R)}`;p(this,q,await H(a));let i=`pglite-broadcast:${s(this,C)}`;p(this,M,new BroadcastChannel(i));let y=`pglite-tab:${s(this,R)}`;p(this,k,new BroadcastChannel(y)),s(this,M).addEventListener("message",async n=>{n.data.type==="leader-here"?(p(this,E,!1),s(this,w).dispatchEvent(new Event("leader-change")),h(this,o,$).call(this)):n.data.type==="notify"&&h(this,o,z).call(this,n.data.channel,n.data.payload)}),s(this,k).addEventListener("message",async n=>{n.data.type==="connected"&&(p(this,E,!0),s(this,w).dispatchEvent(new Event("connected")),p(this,T,await h(this,o,g).call(this,"getDebugLevel")),p(this,A,!0))}),s(this,m).addEventListener("message",async n=>{n.data.type==="leader-now"&&(p(this,O,!0),s(this,w).dispatchEvent(new Event("leader-change")))}),h(this,o,$).call(this)},$=async function(){s(this,E)||(s(this,M).postMessage({type:"tab-here",id:s(this,R)}),setTimeout(()=>h(this,o,$).call(this),16))},g=async function(e,...t){let r=N(),a={type:"rpc-call",callId:r,method:e,args:t};return s(this,k).postMessage(a),await new Promise((i,y)=>{let n=u=>{if(u.data.callId!==r)return;d();let P=u.data;if(P.type==="rpc-return")i(P.result);else if(P.type==="rpc-error"){let x=new Error(P.error.message);Object.assign(x,P.error),y(x)}else y(new Error("Invalid message"))},v=()=>{d(),y(new S)},d=()=>{s(this,k).removeEventListener("message",n),s(this,w).removeEventListener("leader-change",v)};s(this,w).addEventListener("leader-change",v),s(this,k).addEventListener("message",n)})},z=function(e,t){let r=s(this,f).get(e);if(r)for(let a of r)queueMicrotask(()=>a(t));for(let a of s(this,W))queueMicrotask(()=>a(e,t))};var Q=U;async function _({init:c}){postMessage({type:"here"});let e=await new Promise(d=>{addEventListener("message",u=>{u.data.type==="init"&&d(u.data.options)},{once:!0})}),t=e.id??`${import.meta.url}:${e.dataDir??""}`;postMessage({type:"ready",id:t});let r=`pglite-election-lock:${t}`,a=`pglite-broadcast:${t}`,i=new BroadcastChannel(a),y=new Set;await H(r);let n=c(e);i.onmessage=async d=>{let u=d.data;switch(u.type){case"tab-here":J(u.id,await n,y);break}},i.postMessage({type:"leader-here",id:t}),postMessage({type:"leader-now"}),(await n).onNotification((d,u)=>{i.postMessage({type:"notify",channel:d,payload:u})})}function J(c,e,t){if(t.has(c))return;t.add(c);let r=`pglite-tab:${c}`,a=`pglite-tab-close:${c}`,i=new BroadcastChannel(r);navigator.locks.request(a,()=>new Promise(n=>{i.close(),t.delete(c),n()}));let y=K(e);i.addEventListener("message",async n=>{let v=n.data;switch(v.type){case"rpc-call":{let{callId:d,method:u,args:P}=v;try{let x=await y[u](...P);i.postMessage({type:"rpc-return",callId:d,result:x})}catch(x){console.error(x),i.postMessage({type:"rpc-error",callId:d,error:{message:x.message}})}break}}}),i.postMessage({type:"connected"})}function K(c){let e=new Map;return{async getDebugLevel(){return c.debug},async close(){await c.close()},async query(t,r,a){return await c.query(t,r,a)},async sql(t,r,a){let i=t;return i.raw=r,await c.sql(i,...a)},async exec(t,r){return await c.exec(t,r)},async transactionStart(){let t=N(),{promise:r,resolve:a}=V();return e.set(t,r),c.transaction(i=>new Promise((y,n)=>{a({tx:i,resolve:y,reject:n})})),t},async transactionCommit(t){if(!e.has(t))throw new Error("No transaction");(await e.get(t)).resolve(),e.delete(t)},async transactionQuery(t,r,a,i){if(!e.has(t))throw new Error("No transaction");return await(await e.get(t)).tx.query(r,a,i)},async transactionExec(t,r,a){if(!e.has(t))throw new Error("No transaction");return(await e.get(t)).tx.exec(r,a)},async transactionRollback(t){if(!e.has(t))throw new Error("No transaction");let r=await e.get(t);await r.tx.rollback(),r.reject(new Error("Transaction rolled back")),e.delete(t)},async execProtocol(t){return await c.execProtocol(t)},async execProtocolRaw(t){return await c.execProtocolRaw(t)},async dumpDataDir(){return await c.dumpDataDir()}}}var S=class extends Error{constructor(){super("Leader changed, pending operation in indeterminate state")}};async function H(c){let e;return await new Promise(t=>{navigator.locks.request(c,()=>new Promise(r=>{e=r,t()}))}),e}function V(){let c,e;return{promise:new Promise((r,a)=>{c=r,e=a}),resolve:c,reject:e}}export{S as LeaderChangedError,Q as PGliteWorker,_ as worker};
import{c as N}from"../chunk-3BCYDNSE.js";import{d as s,e as l,f as y,g as h,i as j}from"../chunk-Y3AVQXKT.js";j();var L,b,A,T,O,w,R,E,m,C,I,q,M,k,G,f,W,D,$,o,F,S,g,z,U=class U{constructor(e,t){l(this,o);l(this,L);l(this,b,0);l(this,A,!1);l(this,T,!1);l(this,O,!1);l(this,w,new EventTarget);l(this,R);l(this,E,!1);l(this,m);l(this,C);l(this,I);l(this,q);l(this,M);l(this,k);l(this,G);l(this,f,new Map);l(this,W,new Set);l(this,D);l(this,$,[]);y(this,m,e),y(this,R,N()),y(this,D,t?.extensions??{}),y(this,I,new Promise(r=>{s(this,m).addEventListener("message",a=>{if(a.data.type==="here")r();else throw new Error("Invalid message")},{once:!0})})),y(this,q,new Promise(r=>{let a=n=>{n.data.type==="ready"&&(y(this,C,n.data.id),s(this,m).removeEventListener("message",a),r())};s(this,m).addEventListener("message",a)})),y(this,L,h(this,o,F).call(this,t))}static async create(e,t){let r=new U(e,t);return await s(r,L),r}get waitReady(){return new Promise(e=>{s(this,L).then(()=>{s(this,E)?e():e(new Promise(t=>{s(this,w).addEventListener("connected",()=>{t()})}))})})}get debug(){return s(this,b)}get ready(){return s(this,A)}get closed(){return s(this,T)}get isLeader(){return s(this,O)}async close(){var e;s(this,T)||(y(this,T,!0),s(this,M)?.close(),s(this,k)?.close(),(e=s(this,G))==null||e.call(this),s(this,m).terminate())}async[Symbol.asyncDispose](){await this.close()}async query(e,t,r){return await this.waitReady,await h(this,o,g).call(this,"query",e,t,r)}async sql(e,...t){return await this.waitReady,await h(this,o,g).call(this,"sql",e,e.raw,t)}async exec(e,t){return await this.waitReady,await h(this,o,g).call(this,"exec",e,t)}async transaction(e){await this.waitReady;let t=await h(this,o,g).call(this,"transactionStart"),r;try{r=await e({query:async(a,n,p)=>await h(this,o,g).call(this,"transactionQuery",t,a,n,p),sql:async(a,...n)=>h(this,o,g).call(this,"transactionSql",t,a,a.raw,n),exec:async(a,n)=>await h(this,o,g).call(this,"transactionExec",t,a,n),rollback:async()=>{await h(this,o,g).call(this,"transactionRollback",t)},closed:!1})}catch(a){throw await h(this,o,g).call(this,"transactionRollback",t),a}return await h(this,o,g).call(this,"transactionCommit",t),r}async execProtocolRaw(e){return await this.waitReady,await h(this,o,g).call(this,"execProtocolRaw",e)}async execProtocol(e){return await this.waitReady,await h(this,o,g).call(this,"execProtocol",e)}async listen(e,t){return await this.waitReady,s(this,f).has(e)||s(this,f).set(e,new Set),s(this,f).get(e)?.add(t),await this.exec(`LISTEN ${e}`),async()=>{await this.unlisten(e,t)}}async unlisten(e,t){await this.waitReady,t?s(this,f).get(e)?.delete(t):s(this,f).delete(e),s(this,f).get(e)?.size===0&&await this.exec(`UNLISTEN ${e}`)}onNotification(e){return s(this,W).add(e),()=>{s(this,W).delete(e)}}offNotification(e){s(this,W).delete(e)}async dumpDataDir(){return await h(this,o,g).call(this,"dumpDataDir")}onLeaderChange(e){return s(this,w).addEventListener("leader-change",e),()=>{s(this,w).removeEventListener("leader-change",e)}}offLeaderChange(e){s(this,w).removeEventListener("leader-change",e)}};L=new WeakMap,b=new WeakMap,A=new WeakMap,T=new WeakMap,O=new WeakMap,w=new WeakMap,R=new WeakMap,E=new WeakMap,m=new WeakMap,C=new WeakMap,I=new WeakMap,q=new WeakMap,M=new WeakMap,k=new WeakMap,G=new WeakMap,f=new WeakMap,W=new WeakMap,D=new WeakMap,$=new WeakMap,o=new WeakSet,F=async function(e={}){for(let[i,v]of Object.entries(s(this,D))){if(v instanceof URL)throw new Error("URL extensions are not supported on the client side of a worker");{let d=await v.setup(this,{},!0);if(d.emscriptenOpts&&console.warn(`PGlite extension ${i} returned emscriptenOpts, these are not supported on the client side of a worker`),d.namespaceObj){let u=this;u[i]=d.namespaceObj}d.bundlePath&&console.warn(`PGlite extension ${i} returned bundlePath, this is not supported on the client side of a worker`),d.init&&await d.init(),d.close&&s(this,$).push(d.close)}}await s(this,I);let{extensions:t,...r}=e;s(this,m).postMessage({type:"init",options:r}),await s(this,q);let a=`pglite-tab-close:${s(this,R)}`;y(this,G,await H(a));let n=`pglite-broadcast:${s(this,C)}`;y(this,M,new BroadcastChannel(n));let p=`pglite-tab:${s(this,R)}`;y(this,k,new BroadcastChannel(p)),s(this,M).addEventListener("message",async i=>{i.data.type==="leader-here"?(y(this,E,!1),s(this,w).dispatchEvent(new Event("leader-change")),h(this,o,S).call(this)):i.data.type==="notify"&&h(this,o,z).call(this,i.data.channel,i.data.payload)}),s(this,k).addEventListener("message",async i=>{i.data.type==="connected"&&(y(this,E,!0),s(this,w).dispatchEvent(new Event("connected")),y(this,b,await h(this,o,g).call(this,"getDebugLevel")),y(this,A,!0))}),s(this,m).addEventListener("message",async i=>{i.data.type==="leader-now"&&(y(this,O,!0),s(this,w).dispatchEvent(new Event("leader-change")))}),h(this,o,S).call(this)},S=async function(){s(this,E)||(s(this,M).postMessage({type:"tab-here",id:s(this,R)}),setTimeout(()=>h(this,o,S).call(this),16))},g=async function(e,...t){let r=N(),a={type:"rpc-call",callId:r,method:e,args:t};return s(this,k).postMessage(a),await new Promise((n,p)=>{let i=u=>{if(u.data.callId!==r)return;d();let x=u.data;if(x.type==="rpc-return")n(x.result);else if(x.type==="rpc-error"){let P=new Error(x.error.message);Object.assign(P,x.error),p(P)}else p(new Error("Invalid message"))},v=()=>{d(),p(new B)},d=()=>{s(this,k).removeEventListener("message",i),s(this,w).removeEventListener("leader-change",v)};s(this,w).addEventListener("leader-change",v),s(this,k).addEventListener("message",i)})},z=function(e,t){let r=s(this,f).get(e);if(r)for(let a of r)queueMicrotask(()=>a(t));for(let a of s(this,W))queueMicrotask(()=>a(e,t))};var Q=U;async function _({init:c}){postMessage({type:"here"});let e=await new Promise(d=>{addEventListener("message",u=>{u.data.type==="init"&&d(u.data.options)},{once:!0})}),t=e.id??`${import.meta.url}:${e.dataDir??""}`;postMessage({type:"ready",id:t});let r=`pglite-election-lock:${t}`,a=`pglite-broadcast:${t}`,n=new BroadcastChannel(a),p=new Set;await H(r);let i=c(e);n.onmessage=async d=>{let u=d.data;switch(u.type){case"tab-here":J(u.id,await i,p);break}},n.postMessage({type:"leader-here",id:t}),postMessage({type:"leader-now"}),(await i).onNotification((d,u)=>{n.postMessage({type:"notify",channel:d,payload:u})})}function J(c,e,t){if(t.has(c))return;t.add(c);let r=`pglite-tab:${c}`,a=`pglite-tab-close:${c}`,n=new BroadcastChannel(r);navigator.locks.request(a,()=>new Promise(i=>{n.close(),t.delete(c),i()}));let p=K(e);n.addEventListener("message",async i=>{let v=i.data;switch(v.type){case"rpc-call":{let{callId:d,method:u,args:x}=v;try{let P=await p[u](...x);n.postMessage({type:"rpc-return",callId:d,result:P})}catch(P){console.error(P),n.postMessage({type:"rpc-error",callId:d,error:{message:P.message}})}break}}}),n.postMessage({type:"connected"})}function K(c){let e=new Map;return{async getDebugLevel(){return c.debug},async close(){await c.close()},async query(t,r,a){return await c.query(t,r,a)},async sql(t,r,a){let n=t;return n.raw=r,await c.sql(n,...a)},async exec(t,r){return await c.exec(t,r)},async transactionStart(){let t=N(),{promise:r,resolve:a}=V();return e.set(t,r),c.transaction(n=>new Promise((p,i)=>{a({tx:n,resolve:p,reject:i})})),t},async transactionCommit(t){if(!e.has(t))throw new Error("No transaction");(await e.get(t)).resolve(),e.delete(t)},async transactionQuery(t,r,a,n){if(!e.has(t))throw new Error("No transaction");return await(await e.get(t)).tx.query(r,a,n)},async transactionSql(t,r,a,n){if(!e.has(t))throw new Error("No transaction");let p=r;return p.raw=a,await(await e.get(t)).tx.sql(p,...n)},async transactionExec(t,r,a){if(!e.has(t))throw new Error("No transaction");return(await e.get(t)).tx.exec(r,a)},async transactionRollback(t){if(!e.has(t))throw new Error("No transaction");let r=await e.get(t);await r.tx.rollback(),r.reject(new Error("Transaction rolled back")),e.delete(t)},async execProtocol(t){return await c.execProtocol(t)},async execProtocolRaw(t){return await c.execProtocolRaw(t)},async dumpDataDir(){return await c.dumpDataDir()}}}var B=class extends Error{constructor(){super("Leader changed, pending operation in indeterminate state")}};async function H(c){let e;return await new Promise(t=>{navigator.locks.request(c,()=>new Promise(r=>{e=r,t()}))}),e}function V(){let c,e;return{promise:new Promise((r,a)=>{c=r,e=a}),resolve:c,reject:e}}export{B as LeaderChangedError,Q as PGliteWorker,_ as worker};
//# sourceMappingURL=index.js.map
{
"name": "@electric-sql/pglite",
"version": "0.2.4",
"version": "0.2.5",
"private": false,

@@ -18,2 +18,3 @@ "publishConfig": {

"author": "Electric DB Limited",
"homepage": "https://pglite.dev",
"license": "Apache-2.0",

@@ -111,3 +112,3 @@ "main": "dist/index.js",

"build:js": "tsup && tsx scripts/bundle-wasm.ts",
"build": "pnpm build:js || pnpm build:js || pnpm build:js",
"build": "pnpm build:js",
"dev": "concurrently \"tsup --watch\" \"sleep 1 && tsx scripts/bundle-wasm.ts\" \"pnpm dev-server\"",

@@ -114,0 +115,0 @@ "dev-server": "pnpm http-server ../",

<p align="center">
<a href="https://electric-sql.com" target="_blank">
<a href="https://pglite.dev" target="_blank">
<picture>
<source media="(prefers-color-scheme: dark)"
srcset="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-light-trans.svg"
srcset="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo.svg"
/>
<source media="(prefers-color-scheme: light)"
srcset="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-black.svg"
srcset="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>
<img alt="ElectricSQL logo"
src="https://raw.githubusercontent.com/electric-sql/meta/main/identity/ElectricSQL-logo-black.svg"
src="https://raw.githubusercontent.com/electric-sql/pglite/main/docs/public/img/brand/logo-light.svg"
/>

@@ -18,3 +18,3 @@ </picture>

<p align="center">
PGlite - the WASM build of Postgres from <a href="https://electric-sql.com" target="_blank">ElectricSQL</a>.<br>
<a href="https://pglite.dev">PGlite</a> - the WASM build of Postgres from <a href="https://electric-sql.com" target="_blank">ElectricSQL</a>.<br>
Build reactive, realtime, local-first apps directly on Postgres.

@@ -114,2 +114,22 @@ <p>

## How to contribute
You will need [pnpm](https://pnpm.io/) installed, and a recent version of Node.js (v20 and above).
You will also need the Postgres WASM build files, which you download from a comment under the most recently merged PR, labeled as _interim build files_, and place them under `packages/pglite/release`. These are necessary to build PGlite and the dependent workspace projects. We plan to enable a local build in the future to streamline this step.
Once the requirements are met, you can install dependencies and build the workspace projects:
```bash
pnpm install
pnpm build
```
This will build all packages in the correct order based on their dependency relationships. You can now develop any individual package using the `build` and `test` scripts, as well as the `stylecheck` and `typecheck` scripts to ensure style and type validity.
When ready to open a PR, run the following command at the root of the repository:
```bash
pnpm changeset
```
And follow the instructions to create an appropriate changeset. Please ensure any contributions that touch code are accompanied by a changeset.
## Acknowledgments

@@ -116,0 +136,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc