9 lines
22 KiB
JavaScript
9 lines
22 KiB
JavaScript
|
|
"use strict";var pe=Object.defineProperty;var qe=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var $e=Object.prototype.hasOwnProperty;var Me=e=>{throw TypeError(e)};var je=(e,r)=>{for(var t in r)pe(e,t,{get:r[t],enumerable:!0})},He=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ze(r))!$e.call(e,i)&&i!==t&&pe(e,i,{get:()=>r[i],enumerable:!(n=qe(r,i))||n.enumerable});return e};var Ye=e=>He(pe({},"__esModule",{value:!0}),e);var de=(e,r,t)=>r.has(e)||Me("Cannot "+t);var a=(e,r,t)=>(de(e,r,"read from private field"),t?t.call(e):r.get(e)),p=(e,r,t)=>r.has(e)?Me("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(e):r.set(e,t),d=(e,r,t,n)=>(de(e,r,"write to private field"),n?n.call(e,t):r.set(e,t),t),c=(e,r,t)=>(de(e,r,"access private method"),t);var ye=(e,r,t,n)=>({set _(i){d(e,r,i,t)},get _(){return a(e,r,n)}});var zt={};je(zt,{LeaderChangedError:()=>le,PGliteWorker:()=>Ee,worker:()=>Qt});module.exports=Ye(zt);var Ke=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,x=Ke();var ke={part:"part",container:"container"};function te(e,r,...t){let n=e.length-1,i=t.length-1;if(i!==-1){if(i===0){e[n]=e[n]+t[0]+r;return}e[n]=e[n]+t[0],e.push(...t.slice(1,i)),e.push(t[i]+r)}}function Je(e,...r){let t=[e[0]];t.raw=[e.raw[0]];let n=[];for(let i=0;i<r.length;i++){let s=r[i],o=i+1;if(s?._templateType===ke.part){te(t,e[o],s.str),te(t.raw,e.raw[o],s.str);continue}if(s?._templateType===ke.container){te(t,e[o],...s.strings),te(t.raw,e.raw[o],...s.strings.raw),n.push(...s.values);continue}t.push(e[o]),t.raw.push(e.raw[o]),n.push(s)}return{_templateType:"container",strings:t,values:n}}function me(e,...r){let{strings:t,values:n}=Je(e,...r);return{query:[t[0],...n.flatMap((i,s)=>[`$${s+1}`,t[s+1]])].join(""),params:n}}var Xe=globalThis.JSON.parse,Ze=globalThis.JSON.stringify,Ie=16,Le=17;var Ce=20,et=21,tt=23;var he=25,rt=26;var ve=114;var nt=700,st=701;var at=1042,it=1043,ot=1082;var ct=1114,Oe=1184;var lt=3802;var ut={string:{to:he,from:[he,it,at],serialize:e=>{if(typeof e=="string")return e;if(typeof e=="number")return e.toString();throw new Error("Invalid input for string type")},parse:e=>e},number:{to:0,from:[et,tt,rt,nt,st],serialize:e=>e.toString(),parse:e=>+e},bigint:{to:Ce,from:[Ce],serialize:e=>e.toString(),parse:e=>{let r=BigInt(e);return r<Number.MIN_SAFE_INTEGER||r>Number.MAX_SAFE_INTEGER?r:Number(r)}},json:{to:ve,from:[ve,lt],serialize:e=>typeof e=="string"?e:Ze(e),parse:e=>Xe(e)},boolean:{to:Ie,from:[Ie],serialize:e=>{if(typeof e!="boolean")throw new Error("Invalid input for boolean type");return e?"t":"f"},parse:e=>e==="t"},date:{to:Oe,from:[ot,ct,Oe],serialize:e=>{if(typeof e=="string")return e;if(typeof e=="number")return new Date(e).toISOString();if(e instanceof Date)return e.toISOString();throw new Error("Invalid input for date type")},parse:e=>new Date(e)},bytea:{to:Le,from:[Le],serialize:e=>{if(!(e instanceof Uint8Array))throw new Error("Invalid input for bytea type");return"\\x"+Array.from(e).map(r=>r.toString(16).padStart(2,"0")).join("")},parse:e=>{let r=e.slice(2);return Uint8Array.from({length:r.length/2},(t,n)=>parseInt(r.substring(n*2,(n+1)*2),16))}}},ge=pt(ut),Ue=ge.parsers,Ne=ge.serializers;function be(e,r,t){if(e===null)return null;let n=t?.[r]??ge.parsers[r];return n?n(e,r):e}function pt(e){return Object.keys(e).reduce(({parsers:r,serializers:t},n)=>{let{to:i,from:s,serialize:o,parse:u}=e[n];return t[i]=o,t[n]=o,r[n]=u,Array.isArray(s)?s.forEach(l=>{r[l]=u,t[l]=o}):(r[s]=u,t[s]=o),{parsers:r,serializers:t}},{parsers:{},serializers:{}})}var dt=/\\/g,yt=/"/g;function mt(e){return e.replace(dt,"\\\\").replace(yt,'\\"')}function we(e,r,t){if(Array.isArray(e)===!1)return e;if(!e.length)return"{}";let n=e[0],i=t===1020?";":",";return Array.isArray(n)?`{${e.map(s=>we(s,r,t)).join(i)}}`:`{${e.map(s=>(s===void 0&&(s=null),s===null?"null":'"'+mt(r?r(s):s.toString())+'"')).join(i)}}`}var fe={i:0,char:null,str:"",quoted:!1,last:0,p:null};function _e(e,r,t)
|
||
|
|
SELECT b.oid, b.typarray
|
||
|
|
FROM pg_catalog.pg_type a
|
||
|
|
LEFT JOIN pg_catalog.pg_type b ON b.oid = a.typelem
|
||
|
|
WHERE a.typcategory = 'A'
|
||
|
|
GROUP BY b.oid, b.typarray
|
||
|
|
ORDER BY b.oid
|
||
|
|
`);for(let n of t.rows)this.serializers[n.typarray]=i=>we(i,this.serializers[n.oid],n.typarray),this.parsers[n.typarray]=i=>_e(i,this.parsers[n.oid],n.typarray)}async refreshArrayTypes(){await this._initArrayTypes({force:!0})}async query(r,t,n){return await this._checkReady(),await this._runExclusiveTransaction(async()=>await c(this,f,ie).call(this,r,t,n))}async sql(r,...t){let{query:n,params:i}=me(r,...t);return await this.query(n,i)}async exec(r,t){return await this._checkReady(),await this._runExclusiveTransaction(async()=>await c(this,f,v).call(this,r,t))}async describeQuery(r,t){let n=[];try{await c(this,f,B).call(this,A.parse({text:r,types:t?.paramTypes}),t),n=await c(this,f,B).call(this,A.describe({type:"S"}),t)}catch(l){throw l instanceof C?ae({e:l,options:t,params:void 0,query:r}):l}finally{n.push(...await c(this,f,B).call(this,A.sync(),t))}let i=n.find(l=>l.name==="parameterDescription"),s=n.find(l=>l.name==="rowDescription"),o=i?.dataTypeIDs.map(l=>({dataTypeID:l,serializer:this.serializers[l]}))??[],u=s?.fields.map(l=>({name:l.name,dataTypeID:l.dataTypeID,parser:this.parsers[l.dataTypeID]}))??[];return{queryParams:o,resultFields:u}}async transaction(r){return await this._checkReady(),await this._runExclusiveTransaction(async()=>{await c(this,f,v).call(this,"BEGIN"),d(this,I,!0);let t=!1,n=()=>{if(t)throw new Error("Transaction is closed")},i={query:async(s,o,u)=>(n(),await c(this,f,ie).call(this,s,o,u)),sql:async(s,...o)=>{let{query:u,params:l}=me(s,...o);return await c(this,f,ie).call(this,u,l)},exec:async(s,o)=>(n(),await c(this,f,v).call(this,s,o)),rollback:async()=>{n(),await c(this,f,v).call(this,"ROLLBACK"),t=!0},listen:async(s,o)=>(n(),await this.listen(s,o,i)),get closed(){return t}};try{let s=await r(i);return t||(t=!0,await c(this,f,v).call(this,"COMMIT")),d(this,I,!1),s}catch(s){throw t||await c(this,f,v).call(this,"ROLLBACK"),d(this,I,!1),s}})}async runExclusive(r){return await this._runExclusiveQuery(r)}};$=new WeakMap,I=new WeakMap,f=new WeakSet,B=async function(r,t={}){return await this.execProtocolStream(r,{...t,syncToFs:!1})},ie=async function(r,t=[],n){return await this._runExclusiveQuery(async()=>{c(this,f,Ae).call(this,"runQuery",r,t,n),await this._handleBlob(n?.blob);let i=[];try{let o=await c(this,f,B).call(this,A.parse({text:r,types:n?.paramTypes}),n),u=Pe(await c(this,f,B).call(this,A.describe({type:"S"}),n)),l=t.map((m,y)=>{let P=u[y];if(m==null)return null;let E=n?.serializers?.[P]??this.serializers[P];return E?E(m):m.toString()});i=[...o,...await c(this,f,B).call(this,A.bind({values:l}),n),...await c(this,f,B).call(this,A.describe({type:"P"}),n),...await c(this,f,B).call(this,A.execute({}),n)]}catch(o){throw o instanceof C?ae({e:o,options:n,params:t,query:r}):o}finally{i.push(...await c(this,f,B).call(this,A.sync(),n))}await this._cleanupBlob(),a(this,I)||await this.syncToFs();let s=await this._getWrittenBlob();return xe(i,this.parsers,n,s)[0]})},v=async function(r,t){return await this._runExclusiveQuery(async()=>{c(this,f,Ae).call(this,"runExec",r,t),await this._handleBlob(t?.blob);let n=[];try{n=await c(this,f,B).call(this,A.query(r),t)}catch(s){throw s instanceof C?ae({e:s,options:t,params:void 0,query:r}):s}finally{n.push(...await c(this,f,B).call(this,A.sync(),t))}this._cleanupBlob(),a(this,I)||await this.syncToFs();let i=await this._getWrittenBlob();return xe(n,this.parsers,t,i)})},Ae=function(...r){this.debug>0&&console.log(...r)};var Dn=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string";var Re=()=>{if(globalThis.crypto?.randomUUID)return globalThis.crypto.randomUUID();let e=new Uint8Array(16);if(globalThis.crypto?.getRandomValues)globalThis.crypto.getRandomValues(e);else for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256);e[6]=e[6]&15|64,e[8]=e[8]&63|128;let r=[];return e.forEach(t=>{r.push(t.toString(16).padStart(2,"0"))}),r.slice(0,4).join("")+"-"+r.slice(4,6).join("")+"-"+r.slice(6,8).join("")+"-"+r.slice(8,10).join("")+"-"+r.slice(10).join("")};function Fe(e){let r;return e.startsWith('"')&&e.endsWith('"')?r
|
||
|
|
//# sourceMappingURL=index.cjs.map
|