@prisma/studio-core 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/chunk-BUOKRYKO.js +10 -0
  2. package/dist/chunk-FRW62KTF.js +10 -0
  3. package/dist/chunk-O6LRAFT5.js +10 -0
  4. package/dist/chunk-P5LRZ6C2.js +10 -0
  5. package/dist/data/accelerate/index.cjs +2 -1
  6. package/dist/data/accelerate/index.d.cts +10 -2
  7. package/dist/data/accelerate/index.d.ts +10 -2
  8. package/dist/data/accelerate/index.js +10 -1
  9. package/dist/data/bff/index.cjs +2 -1
  10. package/dist/data/bff/index.d.cts +10 -3
  11. package/dist/data/bff/index.d.ts +10 -3
  12. package/dist/data/bff/index.js +10 -1
  13. package/dist/data/index.cjs +2 -1
  14. package/dist/data/index.d.cts +11 -2
  15. package/dist/data/index.d.ts +11 -2
  16. package/dist/data/index.js +10 -1
  17. package/dist/data/pglite/index.cjs +2 -1
  18. package/dist/data/pglite/index.d.cts +2 -2
  19. package/dist/data/pglite/index.d.ts +2 -2
  20. package/dist/data/pglite/index.js +10 -1
  21. package/dist/data/postgres-core/index.cjs +2 -1
  22. package/dist/data/postgres-core/index.d.cts +80 -20
  23. package/dist/data/postgres-core/index.d.ts +80 -20
  24. package/dist/data/postgres-core/index.js +10 -1
  25. package/dist/metafile-cjs.json +1 -0
  26. package/dist/metafile-esm.json +1 -0
  27. package/dist/{adapter-CKFCHq71.d.cts → query-Q-ZKX_Vr.d.cts} +94 -7
  28. package/dist/{adapter-CKFCHq71.d.ts → query-Q-ZKX_Vr.d.ts} +94 -7
  29. package/dist/ui/index.cjs +258 -1370
  30. package/dist/ui/index.css +1234 -700
  31. package/dist/ui/index.d.cts +69 -3
  32. package/dist/ui/index.d.ts +69 -3
  33. package/dist/ui/index.js +267 -42
  34. package/package.json +36 -32
  35. package/dist/CPIOZS5X-V4BHP4CI.js +0 -1
  36. package/dist/OKF6E45R-XYOIK2NY.js +0 -1
  37. package/dist/chunk-2ZJZX5I7.js +0 -0
  38. package/dist/chunk-5MNS4IJC.js +0 -1332
  39. package/dist/chunk-BMVJYUJW.js +0 -1
  40. package/dist/chunk-N2MLAUEV.js +0 -1
  41. package/dist/chunk-P72NBTYE.js +0 -1
  42. package/dist/chunk-XS52QRY2.js +0 -1
  43. package/dist/index-BDPv5Gnt.d.ts +0 -48
  44. package/dist/index-BNAA6jKD.d.cts +0 -48
@@ -1 +0,0 @@
1
- var g=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var l=(b,a)=>{for(var c in a)g(b,c,{get:a[c],enumerable:!0})},f=(b,a,c,e)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of i(a))!j.call(b,d)&&d!==c&&g(b,d,{get:()=>a[d],enumerable:!(e=h(a,d))||e.enumerable});return b},m=(b,a,c)=>(f(b,a,"default"),c&&f(c,a,"default"));var p={postgres:{encoded:"ZGF0YXNvdXJjZSBkYiB7CiAgICBwcm92aWRlciA9ICJwb3N0Z3JlcyIKICAgIHVybCAgICAgID0gZW52KCJEQVRBQkFTRV9VUkwiKQp9CiAgICAKZ2VuZXJhdG9yIGNsaWVudCB7CiAgICBwcm92aWRlciA9ICJwcmlzbWEtY2xpZW50LWpzIgp9",hash:"54195896aeafa3318ca33f5a8bb44c6b4d89c368cb15288f3bd5ace35a3f9227"}};export{l as a,m as b,p as c};
@@ -1 +0,0 @@
1
- var g={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return De(this.context.count)},getNextContextId(){return De(this.context.count++)}};function De(e){let t=String(e),n=t.length-1;return g.context.id+(n?String.fromCharCode(96+n):"")+t}function U(e){g.context=e}function Rt(){return{...g.context,id:g.getNextContextId(),count:0}}var Je=!1,Vt=(e,t)=>e===t,he=Symbol("solid-proxy"),et=typeof Proxy=="function",tt=Symbol("solid-track"),ye={equals:Vt},je=null,nt=ut,N=1,te=2,rt={owned:null,cleanups:null,context:null,owner:null},Oe={},y=null,f=null,W=null,Q=null,p=null,E=null,C=null,pe=0;function F(e,t){let n=p,r=y,s=e.length===0,i=t===void 0?r:t,o=s?rt:{owned:null,cleanups:null,context:i?i.context:null,owner:i},l=s?e:()=>e(()=>O(()=>D(o)));y=o,p=null;try{return T(l,!0)}finally{p=n,y=r}}function V(e,t){t=t?Object.assign({},ye,t):ye;let n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},r=s=>(typeof s=="function"&&(f&&f.running&&f.sources.has(n)?s=s(n.tValue):s=s(n.value)),ft(n,s));return[at.bind(n),r]}function Ue(e,t,n){let r=ve(e,t,!0,N);W&&f&&f.running?E.push(r):Z(r)}function K(e,t,n){let r=ve(e,t,!1,N);W&&f&&f.running?E.push(r):Z(r)}function st(e,t,n){nt=Ut;let r=ve(e,t,!1,N),s=ne&&ot(ne);s&&(r.suspense=s),(!n||!n.render)&&(r.user=!0),C?C.push(r):Z(r)}function x(e,t,n){n=n?Object.assign({},ye,n):ye;let r=ve(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,W&&f&&f.running?(r.tState=N,E.push(r)):Z(r),at.bind(r)}function Lt(e){return e&&typeof e=="object"&&"then"in e}function Mt(e,t,n){let r,s,i;r=!0,s=e,i={};let o=null,l=Oe,a=null,c=!1,d=!1,u="initialValue"in i,h=typeof r=="function"&&x(r),w=new Set,[v,k]=(i.storage||V)(i.initialValue),[L,_]=V(void 0),[I,P]=V(void 0,{equals:!1}),[R,$]=V(u?"ready":"unresolved");g.context&&(a=g.getNextContextId(),i.ssrLoadFrom==="initial"?l=i.initialValue:g.load&&g.has(a)&&(l=g.load(a)));function B(b,S,A,z){return o===b&&(o=null,z!==void 0&&(u=!0),(b===l||S===l)&&i.onHydrated&&queueMicrotask(()=>i.onHydrated(z,{value:S})),l=Oe,f&&b&&c?(f.promises.delete(b),c=!1,T(()=>{f.running=!0,Be(S,A)},!1)):Be(S,A)),S}function Be(b,S){T(()=>{S===void 0&&k(()=>b),$(S!==void 0?"errored":u?"ready":"unresolved"),_(S);for(let A of w.keys())A.decrement();w.clear()},!1)}function Ae(){let b=ne&&ot(ne),S=v(),A=L();if(A!==void 0&&!o)throw A;return p&&!p.user&&b&&Ue(()=>{I(),o&&(b.resolved&&f&&c?f.promises.add(o):w.has(b)||(b.increment(),w.add(b)))}),S}function Ee(b=!0){if(b!==!1&&d)return;d=!1;let S=h?h():r;if(c=f&&f.running,S==null||S===!1){B(o,O(v));return}f&&o&&f.promises.delete(o);let A=l!==Oe?l:O(()=>s(S,{value:v(),refetching:b}));return Lt(A)?(o=A,"value"in A?(A.status==="success"?B(o,A.value,void 0,S):B(o,void 0,Ce(A.value),S),A):(d=!0,queueMicrotask(()=>d=!1),T(()=>{$(u?"refreshing":"pending"),P()},!1),A.then(z=>B(A,z,void 0,S),z=>B(A,void 0,Ce(z),S)))):(B(o,A,void 0,S),A)}return Object.defineProperties(Ae,{state:{get:()=>R()},error:{get:()=>L()},loading:{get(){let b=R();return b==="pending"||b==="refreshing"}},latest:{get(){if(!u)return Ae();let b=L();if(b&&!o)throw b;return v()}}}),h?Ue(()=>Ee(!1)):Ee(!1),[Ae,{refetch:Ee,mutate:k}]}function tr(e){return T(e,!1)}function O(e){if(!Q&&p===null)return e();let t=p;p=null;try{return Q?Q.untrack(e):e()}finally{p=t}}function nr(e,t,n){let r=Array.isArray(e),s,i=n&&n.defer;return o=>{let l;if(r){l=Array(e.length);for(let c=0;c<e.length;c++)l[c]=e[c]()}else l=e();if(i)return i=!1,o;let a=O(()=>t(l,s,o));return s=l,a}}function $t(e){st(()=>O(e))}function X(e){return y===null||(y.cleanups===null?y.cleanups=[e]:y.cleanups.push(e)),e}function Fe(){return y}function _t(e,t){let n=y,r=p;y=e,p=null;try{return T(t,!0)}catch(s){be(s)}finally{y=n,p=r}}function it(e){if(f&&f.running)return e(),f.done;let t=p,n=y;return Promise.resolve().then(()=>{p=t,y=n;let r;return(W||ne)&&(r=f||(f={sources:new Set,effects:[],promises:new Set,disposed:new Set,queue:new Set,running:!0}),r.done||(r.done=new Promise(s=>r.resolve=s)),r.running=!0),T(e,!1),p=y=null,r?r.done:void 0})}var[Bt,Ke]=V(!1);function rr(){return[Bt,it]}function sr(e,t){let n=Symbol("context");return{id:n,Provider:Ft(n),defaultValue:e}}function ot(e){let t;return y&&y.context&&(t=y.context[e.id])!==void 0?t:e.defaultValue}function lt(e){let t=x(e),n=x(()=>Te(t()));return n.toArray=()=>{let r=n();return Array.isArray(r)?r:r!=null?[r]:[]},n}var ne;function at(){let e=f&&f.running;if(this.sources&&(e?this.tState:this.state))if((e?this.tState:this.state)===N)Z(this);else{let t=E;E=null,T(()=>me(this),!1),E=t}if(p){let t=this.observers?this.observers.length:0;p.sources?(p.sources.push(this),p.sourceSlots.push(t)):(p.sources=[this],p.sourceSlots=[t]),this.observers?(this.observers.push(p),this.observerSlots.push(p.sources.length-1)):(this.observers=[p],this.observerSlots=[p.sources.length-1])}return e&&f.sources.has(this)?this.tValue:this.value}function ft(e,t,n){let r=f&&f.running&&f.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(f){let s=f.running;(s||!n&&f.sources.has(e))&&(f.sources.add(e),e.tValue=t),s||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&T(()=>{for(let s=0;s<e.observers.length;s+=1){let i=e.observers[s],o=f&&f.running;o&&f.disposed.has(i)||((o?!i.tState:!i.state)&&(i.pure?E.push(i):C.push(i),i.observers&&ct(i)),o?i.tState=N:i.state=N)}if(E.length>1e6)throw E=[],new Error},!1)}return t}function Z(e){if(!e.fn)return;D(e);let t=pe;qe(e,f&&f.running&&f.sources.has(e)?e.tValue:e.value,t),f&&!f.running&&f.sources.has(e)&&queueMicrotask(()=>{T(()=>{f&&(f.running=!0),p=y=e,qe(e,e.tValue,t),p=y=null},!1)})}function qe(e,t,n){let r,s=y,i=p;p=y=e;try{r=e.fn(t)}catch(o){return e.pure&&(f&&f.running?(e.tState=N,e.tOwned&&e.tOwned.forEach(D),e.tOwned=void 0):(e.state=N,e.owned&&e.owned.forEach(D),e.owned=null)),e.updatedAt=n+1,be(o)}finally{p=i,y=s}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&"observers"in e?ft(e,r,!0):f&&f.running&&e.pure?(f.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function ve(e,t,n,r=N,s){let i={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:y,context:y?y.context:null,pure:n};if(f&&f.running&&(i.state=0,i.tState=r),y===null||y!==rt&&(f&&f.running&&y.pure?y.tOwned?y.tOwned.push(i):y.tOwned=[i]:y.owned?y.owned.push(i):y.owned=[i]),Q&&i.fn){let[o,l]=V(void 0,{equals:!1}),a=Q.factory(i.fn,l);X(()=>a.dispose());let c=()=>it(l).then(()=>d.dispose()),d=Q.factory(i.fn,c);i.fn=u=>(o(),f&&f.running?d.track(u):a.track(u))}return i}function re(e){let t=f&&f.running;if((t?e.tState:e.state)===0)return;if((t?e.tState:e.state)===te)return me(e);if(e.suspense&&O(e.suspense.inFallback))return e.suspense.effects.push(e);let n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<pe);){if(t&&f.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let s=e,i=n[r+1];for(;(s=s.owner)&&s!==i;)if(f.disposed.has(s))return}if((t?e.tState:e.state)===N)Z(e);else if((t?e.tState:e.state)===te){let s=E;E=null,T(()=>me(e,n[0]),!1),E=s}}}function T(e,t){if(E)return e();let n=!1;t||(E=[]),C?n=!0:C=[],pe++;try{let r=e();return Dt(n),r}catch(r){n||(C=null),E=null,be(r)}}function Dt(e){if(E&&(W&&f&&f.running?jt(E):ut(E),E=null),e)return;let t;if(f){if(!f.promises.size&&!f.queue.size){let r=f.sources,s=f.disposed;C.push.apply(C,f.effects),t=f.resolve;for(let i of C)"tState"in i&&(i.state=i.tState),delete i.tState;f=null,T(()=>{for(let i of s)D(i);for(let i of r){if(i.value=i.tValue,i.owned)for(let o=0,l=i.owned.length;o<l;o++)D(i.owned[o]);i.tOwned&&(i.owned=i.tOwned),delete i.tValue,delete i.tOwned,i.tState=0}Ke(!1)},!1)}else if(f.running){f.running=!1,f.effects.push.apply(f.effects,C),C=null,Ke(!0);return}}let n=C;C=null,n.length&&T(()=>nt(n),!1),t&&t()}function ut(e){for(let t=0;t<e.length;t++)re(e[t])}function jt(e){for(let t=0;t<e.length;t++){let n=e[t],r=f.queue;r.has(n)||(r.add(n),W(()=>{r.delete(n),T(()=>{f.running=!0,re(n)},!1),f&&(f.running=!1)}))}}function Ut(e){let t,n=0;for(t=0;t<e.length;t++){let r=e[t];r.user?e[n++]=r:re(r)}if(g.context){if(g.count){g.effects||(g.effects=[]),g.effects.push(...e.slice(0,n));return}U()}for(g.effects&&(g.done||!g.count)&&(e=[...g.effects,...e],n+=g.effects.length,delete g.effects),t=0;t<n;t++)re(e[t])}function me(e,t){let n=f&&f.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){let s=e.sources[r];if(s.sources){let i=n?s.tState:s.state;i===N?s!==t&&(!s.updatedAt||s.updatedAt<pe)&&re(s):i===te&&me(s,t)}}}function ct(e){let t=f&&f.running;for(let n=0;n<e.observers.length;n+=1){let r=e.observers[n];(t?!r.tState:!r.state)&&(t?r.tState=te:r.state=te,r.pure?E.push(r):C.push(r),r.observers&&ct(r))}}function D(e){let t;if(e.sources)for(;e.sources.length;){let n=e.sources.pop(),r=e.sourceSlots.pop(),s=n.observers;if(s&&s.length){let i=s.pop(),o=n.observerSlots.pop();r<s.length&&(i.sourceSlots[o]=r,s[r]=i,n.observerSlots[r]=o)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)D(e.tOwned[t]);delete e.tOwned}if(f&&f.running&&e.pure)dt(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)D(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}f&&f.running?e.tState=0:e.state=0}function dt(e,t){if(t||(e.tState=0,f.disposed.add(e)),e.owned)for(let n=0;n<e.owned.length;n++)dt(e.owned[n])}function Ce(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function ze(e,t,n){try{for(let r of t)r(e)}catch(r){be(r,n&&n.owner||null)}}function be(e,t=y){let n=je&&t&&t.context&&t.context[je],r=Ce(e);if(!n)throw r;C?C.push({fn(){ze(r,n,t)},state:N}):ze(r,n,t)}function Te(e){if(typeof e=="function"&&!e.length)return Te(e());if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=Te(e[n]);Array.isArray(r)?t.push.apply(t,r):t.push(r)}return t}return e}function Ft(e,t){return function(r){let s;return K(()=>s=O(()=>(y.context={...y.context,[e]:r.value},lt(()=>r.children))),void 0),s}}var Ne=Symbol("fallback");function we(e){for(let t=0;t<e.length;t++)e[t]()}function Kt(e,t,n={}){let r=[],s=[],i=[],o=0,l=t.length>1?[]:null;return X(()=>we(i)),()=>{let a=e()||[],c=a.length,d,u;return a[tt],O(()=>{let w,v,k,L,_,I,P,R,$;if(c===0)o!==0&&(we(i),i=[],r=[],s=[],o=0,l&&(l=[])),n.fallback&&(r=[Ne],s[0]=F(B=>(i[0]=B,n.fallback())),o=1);else if(o===0){for(s=new Array(c),u=0;u<c;u++)r[u]=a[u],s[u]=F(h);o=c}else{for(k=new Array(c),L=new Array(c),l&&(_=new Array(c)),I=0,P=Math.min(o,c);I<P&&r[I]===a[I];I++);for(P=o-1,R=c-1;P>=I&&R>=I&&r[P]===a[R];P--,R--)k[R]=s[P],L[R]=i[P],l&&(_[R]=l[P]);for(w=new Map,v=new Array(R+1),u=R;u>=I;u--)$=a[u],d=w.get($),v[u]=d===void 0?-1:d,w.set($,u);for(d=I;d<=P;d++)$=r[d],u=w.get($),u!==void 0&&u!==-1?(k[u]=s[d],L[u]=i[d],l&&(_[u]=l[d]),u=v[u],w.set($,u)):i[d]();for(u=I;u<c;u++)u in k?(s[u]=k[u],i[u]=L[u],l&&(l[u]=_[u],l[u](u))):s[u]=F(h);s=s.slice(0,o=c),r=a.slice(0)}return s});function h(w){if(i[u]=w,l){let[v,k]=V(u);return l[u]=k,t(a[u],v)}return t(a[u])}}}function qt(e,t,n={}){let r=[],s=[],i=[],o=[],l=0,a;return X(()=>we(i)),()=>{let c=e()||[],d=c.length;return c[tt],O(()=>{if(d===0)return l!==0&&(we(i),i=[],r=[],s=[],l=0,o=[]),n.fallback&&(r=[Ne],s[0]=F(h=>(i[0]=h,n.fallback())),l=1),s;for(r[0]===Ne&&(i[0](),i=[],r=[],s=[],l=0),a=0;a<d;a++)a<r.length&&r[a]!==c[a]?o[a](()=>c[a]):a>=r.length&&(s[a]=F(u));for(;a<r.length;a++)i[a]();return l=o.length=i.length=d,r=c.slice(0),s=s.slice(0,l)});function u(h){i[a]=h;let[w,v]=V(c[a]);return o[a]=v,t(w,a)}}}var zt=!1;function ir(e,t){if(zt&&g.context){let n=g.context;U(Rt());let r=O(()=>e(t||{}));return U(n),r}return O(()=>e(t||{}))}function ae(){return!0}var Ie={get(e,t,n){return t===he?n:e.get(t)},has(e,t){return t===he?!0:e.has(t)},set:ae,deleteProperty:ae,getOwnPropertyDescriptor(e,t){return{configurable:!0,enumerable:!0,get(){return e.get(t)},set:ae,deleteProperty:ae}},ownKeys(e){return e.keys()}};function xe(e){return(e=typeof e=="function"?e():e)?e:{}}function Ht(){for(let e=0,t=this.length;e<t;++e){let n=this[e]();if(n!==void 0)return n}}function or(...e){let t=!1;for(let o=0;o<e.length;o++){let l=e[o];t=t||!!l&&he in l,e[o]=typeof l=="function"?(t=!0,x(l)):l}if(et&&t)return new Proxy({get(o){for(let l=e.length-1;l>=0;l--){let a=xe(e[l])[o];if(a!==void 0)return a}},has(o){for(let l=e.length-1;l>=0;l--)if(o in xe(e[l]))return!0;return!1},keys(){let o=[];for(let l=0;l<e.length;l++)o.push(...Object.keys(xe(e[l])));return[...new Set(o)]}},Ie);let n={},r=Object.create(null);for(let o=e.length-1;o>=0;o--){let l=e[o];if(!l)continue;let a=Object.getOwnPropertyNames(l);for(let c=a.length-1;c>=0;c--){let d=a[c];if(d==="__proto__"||d==="constructor")continue;let u=Object.getOwnPropertyDescriptor(l,d);if(!r[d])r[d]=u.get?{enumerable:!0,configurable:!0,get:Ht.bind(n[d]=[u.get.bind(l)])}:u.value!==void 0?u:void 0;else{let h=n[d];h&&(u.get?h.push(u.get.bind(l)):u.value!==void 0&&h.push(()=>u.value))}}}let s={},i=Object.keys(r);for(let o=i.length-1;o>=0;o--){let l=i[o],a=r[l];a&&a.get?Object.defineProperty(s,l,a):s[l]=a?a.value:void 0}return s}function Gt(e,...t){if(et&&he in e){let s=new Set(t.length>1?t.flat():t[0]),i=t.map(o=>new Proxy({get(l){return o.includes(l)?e[l]:void 0},has(l){return o.includes(l)&&l in e},keys(){return o.filter(l=>l in e)}},Ie));return i.push(new Proxy({get(o){return s.has(o)?void 0:e[o]},has(o){return s.has(o)?!1:o in e},keys(){return Object.keys(e).filter(o=>!s.has(o))}},Ie)),i}let n={},r=t.map(()=>({}));for(let s of Object.getOwnPropertyNames(e)){let i=Object.getOwnPropertyDescriptor(e,s),o=!i.get&&!i.set&&i.enumerable&&i.writable&&i.configurable,l=!1,a=0;for(let c of t)c.includes(s)&&(l=!0,o?r[a][s]=i.value:Object.defineProperty(r[a],s,i)),++a;l||(o?n[s]=i.value:Object.defineProperty(n,s,i))}return[...r,n]}function lr(e){let t,n,r=s=>{let i=g.context;if(i){let[l,a]=V();g.count||(g.count=0),g.count++,(n||(n=e())).then(c=>{!g.done&&U(i),g.count--,a(()=>c.default),U()}),t=l}else if(!t){let[l]=Mt(()=>(n||(n=e())).then(a=>a.default));t=l}let o;return x(()=>(o=t())?O(()=>{if(!i||g.done)return o(s);let l=g.context;U(i);let a=o(s);return U(l),a}):"")};return r.preload=()=>n||((n=e()).then(s=>t=()=>s.default),n),r}var Qt=0;function ar(){return g.context?g.getNextContextId():`cl-${Qt++}`}var gt=e=>`Stale read from <${e}>.`;function fr(e){let t="fallback"in e&&{fallback:()=>e.fallback};return x(Kt(()=>e.each,e.children,t||void 0))}function ur(e){let t="fallback"in e&&{fallback:()=>e.fallback};return x(qt(()=>e.each,e.children,t||void 0))}function cr(e){let t=e.keyed,n=x(()=>e.when,void 0,void 0),r=t?n:x(n,void 0,{equals:(s,i)=>!s==!i});return x(()=>{let s=r();if(s){let i=e.children;return typeof i=="function"&&i.length>0?O(()=>i(t?s:()=>{if(!O(r))throw gt("Show");return n()})):i}return e.fallback},void 0,void 0)}function dr(e){let t=lt(()=>e.children),n=x(()=>{let r=t(),s=Array.isArray(r)?r:[r],i=()=>{};for(let o=0;o<s.length;o++){let l=o,a=s[o],c=i,d=x(()=>c()?void 0:a.when,void 0,void 0),u=a.keyed?d:x(d,void 0,{equals:(h,w)=>!h==!w});i=()=>c()||(u()?[l,d,a]:void 0)}return i});return x(()=>{let r=n()();if(!r)return e.fallback;let[s,i,o]=r,l=o.children;return typeof l=="function"&&l.length>0?O(()=>l(o.keyed?i():()=>{if(O(n)()?.[0]!==s)throw gt("Match");return i()})):l},void 0,void 0)}function gr(e){return e}var hr=void 0,Xt=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected"],Yt=new Set(["className","value","readOnly","formNoValidate","isMap","noModule","playsInline",...Xt]),Wt=new Set(["innerHTML","textContent","innerText","children"]),Zt=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),Jt=Object.assign(Object.create(null),{class:"className",formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1}});function en(e,t){let n=Jt[e];return typeof n=="object"?n[t]?n.$:void 0:n}var tn=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),nn=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),rn={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"};function sn(e,t,n){let r=n.length,s=t.length,i=r,o=0,l=0,a=t[s-1].nextSibling,c=null;for(;o<s||l<i;){if(t[o]===n[l]){o++,l++;continue}for(;t[s-1]===n[i-1];)s--,i--;if(s===o){let d=i<r?l?n[l-1].nextSibling:n[i-l]:a;for(;l<i;)e.insertBefore(n[l++],d)}else if(i===l)for(;o<s;)(!c||!c.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[i-1]&&n[l]===t[s-1]){let d=t[--s].nextSibling;e.insertBefore(n[l++],t[o++].nextSibling),e.insertBefore(n[--i],d),t[s]=n[i]}else{if(!c){c=new Map;let u=l;for(;u<i;)c.set(n[u],u++)}let d=c.get(t[o]);if(d!=null)if(l<d&&d<i){let u=o,h=1,w;for(;++u<s&&u<i&&!((w=c.get(t[u]))==null||w!==d+h);)h++;if(h>d-l){let v=t[o];for(;l<d;)e.insertBefore(n[l++],v)}else e.replaceChild(n[l++],t[o++])}else o++;else t[o++].remove()}}}var J="_$DX_DELEGATE";function yr(e,t,n,r={}){let s;return F(i=>{s=i,t===document?e():Re(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{s(),t.textContent=""}}function mr(e,t,n,r){let s,i=()=>{let l=r?document.createElementNS("http://www.w3.org/1998/Math/MathML","template"):document.createElement("template");return l.innerHTML=e,n?l.content.firstChild.firstChild:r?l.firstChild:l.content.firstChild},o=t?()=>O(()=>document.importNode(s||(s=i()),!0)):()=>(s||(s=i())).cloneNode(!0);return o.cloneNode=o,o}function on(e,t=window.document){let n=t[J]||(t[J]=new Set);for(let r=0,s=e.length;r<s;r++){let i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,ht))}}function wr(e=window.document){if(e[J]){for(let t of e[J].keys())e.removeEventListener(t,ht);delete e[J]}}function Pe(e,t,n){q(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function ln(e,t,n,r){q(e)||(r==null?e.removeAttributeNS(t,n):e.setAttributeNS(t,n,r))}function an(e,t,n){q(e)||(n?e.setAttribute(t,""):e.removeAttribute(t))}function fn(e,t){q(e)||(t==null?e.removeAttribute("class"):e.className=t)}function un(e,t,n,r){if(r)Array.isArray(n)?(e[`$$${t}`]=n[0],e[`$$${t}Data`]=n[1]):e[`$$${t}`]=n;else if(Array.isArray(n)){let s=n[0];e.addEventListener(t,n[0]=i=>s.call(e,n[1],i))}else e.addEventListener(t,n,typeof n!="function"&&n)}function cn(e,t,n={}){let r=Object.keys(t||{}),s=Object.keys(n),i,o;for(i=0,o=s.length;i<o;i++){let l=s[i];!l||l==="undefined"||t[l]||(He(e,l,!1),delete n[l])}for(i=0,o=r.length;i<o;i++){let l=r[i],a=!!t[l];!l||l==="undefined"||n[l]===a||!a||(He(e,l,!0),n[l]=a)}return n}function dn(e,t,n){if(!t)return n?Pe(e,"style"):t;let r=e.style;if(typeof t=="string")return r.cssText=t;typeof n=="string"&&(r.cssText=n=void 0),n||(n={}),t||(t={});let s,i;for(i in n)t[i]==null&&r.removeProperty(i),delete n[i];for(i in t)s=t[i],s!==n[i]&&(r.setProperty(i,s),n[i]=s);return n}function gn(e,t={},n,r){let s={};return r||K(()=>s.children=se(e,t.children,s.children)),K(()=>typeof t.ref=="function"&&hn(t.ref,e)),K(()=>yn(e,t,n,!0,s,!0)),s}function hn(e,t,n){return O(()=>e(t,n))}function Re(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!="function")return se(e,t,r,n);K(s=>se(e,t(),s,n),r)}function yn(e,t,n,r,s={},i=!1){t||(t={});for(let o in s)if(!(o in t)){if(o==="children")continue;s[o]=Ge(e,o,null,s[o],n,i,t)}for(let o in t){if(o==="children")continue;let l=t[o];s[o]=Ge(e,o,l,s[o],n,i,t)}}function mn(e){let t,n;return!q()||!(t=g.registry.get(n=pn()))?e():(g.completed&&g.completed.add(t),g.registry.delete(n),t)}function q(e){return!!g.context&&!g.done&&(!e||e.isConnected)}function wn(e){return e.toLowerCase().replace(/-([a-z])/g,(t,n)=>n.toUpperCase())}function He(e,t,n){let r=t.trim().split(/\s+/);for(let s=0,i=r.length;s<i;s++)e.classList.toggle(r[s],n)}function Ge(e,t,n,r,s,i,o){let l,a,c,d,u;if(t==="style")return dn(e,n,r);if(t==="classList")return cn(e,n,r);if(n===r)return r;if(t==="ref")i||n(e);else if(t.slice(0,3)==="on:"){let h=t.slice(3);r&&e.removeEventListener(h,r,typeof r!="function"&&r),n&&e.addEventListener(h,n,typeof n!="function"&&n)}else if(t.slice(0,10)==="oncapture:"){let h=t.slice(10);r&&e.removeEventListener(h,r,!0),n&&e.addEventListener(h,n,!0)}else if(t.slice(0,2)==="on"){let h=t.slice(2).toLowerCase(),w=tn.has(h);if(!w&&r){let v=Array.isArray(r)?r[0]:r;e.removeEventListener(h,v)}(w||n)&&(un(e,h,n,w),w&&on([h]))}else if(t.slice(0,5)==="attr:")Pe(e,t.slice(5),n);else if(t.slice(0,5)==="bool:")an(e,t.slice(5),n);else if((u=t.slice(0,5)==="prop:")||(c=Wt.has(t))||!s&&((d=en(t,e.tagName))||(a=Yt.has(t)))||(l=e.nodeName.includes("-")||"is"in o)){if(u)t=t.slice(5),a=!0;else if(q(e))return n;t==="class"||t==="className"?fn(e,n):l&&!a&&!c?e[wn(t)]=n:e[d||t]=n}else{let h=s&&t.indexOf(":")>-1&&rn[t.split(":")[0]];h?ln(e,h,t,n):Pe(e,Zt[t]||t,n)}return n}function ht(e){if(g.registry&&g.events&&g.events.find(([a,c])=>c===e))return;let t=e.target,n=`$$${e.type}`,r=e.target,s=e.currentTarget,i=a=>Object.defineProperty(e,"target",{configurable:!0,value:a}),o=()=>{let a=t[n];if(a&&!t.disabled){let c=t[`${n}Data`];if(c!==void 0?a.call(t,c,e):a.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&i(t.host),!0},l=()=>{for(;o()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),g.registry&&!g.done&&(g.done=_$HY.done=!0),e.composedPath){let a=e.composedPath();i(a[0]);for(let c=0;c<a.length-2&&(t=a[c],!!o());c++){if(t._$host){t=t._$host,l();break}if(t.parentNode===s)break}}else l();i(r)}function se(e,t,n,r,s){let i=q(e);if(i){!n&&(n=[...e.childNodes]);let a=[];for(let c=0;c<n.length;c++){let d=n[c];d.nodeType===8&&d.data.slice(0,2)==="!$"?d.remove():a.push(d)}n=a}for(;typeof n=="function";)n=n();if(t===n)return n;let o=typeof t,l=r!==void 0;if(e=l&&n[0]&&n[0].parentNode||e,o==="string"||o==="number"){if(i||o==="number"&&(t=t.toString(),t===n))return n;if(l){let a=n[0];a&&a.nodeType===3?a.data!==t&&(a.data=t):a=document.createTextNode(t),n=H(e,n,r,a)}else n!==""&&typeof n=="string"?n=e.firstChild.data=t:n=e.textContent=t}else if(t==null||o==="boolean"){if(i)return n;n=H(e,n,r)}else{if(o==="function")return K(()=>{let a=t();for(;typeof a=="function";)a=a();n=se(e,a,n,r)}),()=>n;if(Array.isArray(t)){let a=[],c=n&&Array.isArray(n);if(Ve(a,t,n,s))return K(()=>n=se(e,a,n,r,!0)),()=>n;if(i){if(!a.length)return n;if(r===void 0)return n=[...e.childNodes];let d=a[0];if(d.parentNode!==e)return n;let u=[d];for(;(d=d.nextSibling)!==r;)u.push(d);return n=u}if(a.length===0){if(n=H(e,n,r),l)return n}else c?n.length===0?Qe(e,a,r):sn(e,n,a):(n&&H(e),Qe(e,a));n=a}else if(t.nodeType){if(i&&t.parentNode)return n=l?[t]:t;if(Array.isArray(n)){if(l)return n=H(e,n,r,t);H(e,n,null,t)}else n==null||n===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}}return n}function Ve(e,t,n,r){let s=!1;for(let i=0,o=t.length;i<o;i++){let l=t[i],a=n&&n[e.length],c;if(!(l==null||l===!0||l===!1))if((c=typeof l)=="object"&&l.nodeType)e.push(l);else if(Array.isArray(l))s=Ve(e,l,a)||s;else if(c==="function")if(r){for(;typeof l=="function";)l=l();s=Ve(e,Array.isArray(l)?l:[l],Array.isArray(a)?a:[a])||s}else e.push(l),s=!0;else{let d=String(l);a&&a.nodeType===3&&a.data===d?e.push(a):e.push(document.createTextNode(d))}}return s}function Qe(e,t,n=null){for(let r=0,s=t.length;r<s;r++)e.insertBefore(t[r],n)}function H(e,t,n,r){if(n===void 0)return e.textContent="";let s=r||document.createTextNode("");if(t.length){let i=!1;for(let o=t.length-1;o>=0;o--){let l=t[o];if(s!==l){let a=l.parentNode===e;!i&&!o?a?e.replaceChild(s,l):e.insertBefore(s,n):a&&l.remove()}else i=!0}}else e.insertBefore(s,n);return[s]}function pn(){return g.getNextContextId()}var pr=!1,vn="http://www.w3.org/2000/svg";function yt(e,t=!1){return t?document.createElementNS(vn,e):document.createElement(e)}function vr(e){let{useShadow:t}=e,n=document.createTextNode(""),r=()=>e.mount||document.body,s=Fe(),i,o=!!g.context;return st(()=>{o&&(Fe().user=o=!1),i||(i=_t(s,()=>x(()=>e.children)));let l=r();if(l instanceof HTMLHeadElement){let[a,c]=V(!1),d=()=>c(!0);F(u=>Re(l,()=>a()?u():i(),null)),X(d)}else{let a=yt(e.isSVG?"g":"div",e.isSVG),c=t&&a.attachShadow?a.attachShadow({mode:"open"}):a;Object.defineProperty(a,"_$host",{get(){return n.parentNode},configurable:!0}),Re(c,i),l.appendChild(a),e.ref&&e.ref(a),X(()=>l.removeChild(a))}},void 0,{render:!o}),n}function bn(e,t){let n=x(e);return x(()=>{let r=n();switch(typeof r){case"function":return O(()=>r(t));case"string":let s=nn.has(r),i=g.context?mn():yt(r,s);return gn(i,t,s),i}})}function br(e){let[,t]=Gt(e,["component"]);return bn(()=>e.component,t)}var Sn=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},mt=class{constructor(e){this.generateIdentifier=e,this.kv=new Sn}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},An=class extends mt{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function En(e){if("values"in Object)return Object.values(e);let t=[];for(let n in e)e.hasOwnProperty(n)&&t.push(e[n]);return t}function On(e,t){let n=En(e);if("find"in n)return n.find(t);let r=n;for(let s=0;s<r.length;s++){let i=r[s];if(t(i))return i}}function Y(e,t){Object.entries(e).forEach(([n,r])=>t(r,n))}function ge(e,t){return e.indexOf(t)!==-1}function Xe(e,t){for(let n=0;n<e.length;n++){let r=e[n];if(t(r))return r}}var xn=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return On(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},kn=e=>Object.prototype.toString.call(e).slice(8,-1),wt=e=>typeof e>"u",Cn=e=>e===null,ie=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,Le=e=>ie(e)&&Object.keys(e).length===0,j=e=>Array.isArray(e),Tn=e=>typeof e=="string",Nn=e=>typeof e=="number"&&!isNaN(e),In=e=>typeof e=="boolean",Pn=e=>e instanceof RegExp,oe=e=>e instanceof Map,le=e=>e instanceof Set,pt=e=>kn(e)==="Symbol",Rn=e=>e instanceof Date&&!isNaN(e.valueOf()),Vn=e=>e instanceof Error,Ye=e=>typeof e=="number"&&isNaN(e),Ln=e=>In(e)||Cn(e)||wt(e)||Nn(e)||Tn(e)||pt(e),Mn=e=>typeof e=="bigint",$n=e=>e===1/0||e===-1/0,_n=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),Bn=e=>e instanceof URL,vt=e=>e.replace(/\./g,"\\."),ke=e=>e.map(String).map(vt).join("."),ee=e=>{let t=[],n="";for(let s=0;s<e.length;s++){let i=e.charAt(s);if(i==="\\"&&e.charAt(s+1)==="."){n+=".",s++;continue}if(i==="."){t.push(n),n="";continue}n+=i}let r=n;return t.push(r),t};function M(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var bt=[M(wt,"undefined",()=>null,()=>{}),M(Mn,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),M(Rn,"Date",e=>e.toISOString(),e=>new Date(e)),M(Vn,"Error",(e,t)=>{let n={name:e.name,message:e.message};return t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n},(e,t)=>{let n=new Error(e.message);return n.name=e.name,n.stack=e.stack,t.allowedErrorProps.forEach(r=>{n[r]=e[r]}),n}),M(Pn,"regexp",e=>""+e,e=>{let t=e.slice(1,e.lastIndexOf("/")),n=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,n)}),M(le,"set",e=>[...e.values()],e=>new Set(e)),M(oe,"map",e=>[...e.entries()],e=>new Map(e)),M(e=>Ye(e)||$n(e),"number",e=>Ye(e)?"NaN":e>0?"Infinity":"-Infinity",Number),M(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),M(Bn,"URL",e=>e.toString(),e=>new URL(e))];function Se(e,t,n,r){return{isApplicable:e,annotation:t,transform:n,untransform:r}}var St=Se((e,t)=>pt(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,n)=>{let r=n.symbolRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown symbol");return r}),Dn=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),At=Se(_n,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{let n=Dn[t[1]];if(!n)throw new Error("Trying to deserialize unknown typed array");return new n(e)});function Et(e,t){return e?.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var Ot=Se(Et,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{let n=t.classRegistry.getAllowedProps(e.constructor);if(!n)return{...e};let r={};return n.forEach(s=>{r[s]=e[s]}),r},(e,t,n)=>{let r=n.classRegistry.getValue(t[1]);if(!r)throw new Error("Trying to deserialize unknown class - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564");return Object.assign(Object.create(r.prototype),e)}),xt=Se((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,n)=>{let r=n.customTransformerRegistry.findByName(t[1]);if(!r)throw new Error("Trying to deserialize unknown custom value");return r.deserialize(e)}),jn=[Ot,St,xt,At],We=(e,t)=>{let n=Xe(jn,s=>s.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation(e,t)};let r=Xe(bt,s=>s.isApplicable(e,t));if(r)return{value:r.transform(e,t),type:r.annotation}},kt={};bt.forEach(e=>{kt[e.annotation]=e});var Un=(e,t,n)=>{if(j(t))switch(t[0]){case"symbol":return St.untransform(e,t,n);case"class":return Ot.untransform(e,t,n);case"custom":return xt.untransform(e,t,n);case"typed-array":return At.untransform(e,t,n);default:throw new Error("Unknown transformation: "+t)}else{let r=kt[t];if(!r)throw new Error("Unknown transformation: "+t);return r.untransform(e,n)}},G=(e,t)=>{let n=e.keys();for(;t>0;)n.next(),t--;return n.next().value};function Ct(e){if(ge(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(ge(e,"prototype"))throw new Error("prototype is not allowed as a property");if(ge(e,"constructor"))throw new Error("constructor is not allowed as a property")}var Fn=(e,t)=>{Ct(t);for(let n=0;n<t.length;n++){let r=t[n];if(le(e))e=G(e,+r);else if(oe(e)){let s=+r,i=+t[++n]==0?"key":"value",o=G(e,s);switch(i){case"key":e=o;break;case"value":e=e.get(o);break}}else e=e[r]}return e},Me=(e,t,n)=>{if(Ct(t),t.length===0)return n(e);let r=e;for(let i=0;i<t.length-1;i++){let o=t[i];if(j(r)){let l=+o;r=r[l]}else if(ie(r))r=r[o];else if(le(r)){let l=+o;r=G(r,l)}else if(oe(r)){if(i===t.length-2)break;let a=+o,c=+t[++i]==0?"key":"value",d=G(r,a);switch(c){case"key":r=d;break;case"value":r=r.get(d);break}}}let s=t[t.length-1];if(j(r)?r[+s]=n(r[+s]):ie(r)&&(r[s]=n(r[s])),le(r)){let i=G(r,+s),o=n(i);i!==o&&(r.delete(i),r.add(o))}if(oe(r)){let i=+t[t.length-2],o=G(r,i);switch(+s==0?"key":"value"){case"key":{let a=n(o);r.set(a,r.get(o)),a!==o&&r.delete(o);break}case"value":{r.set(o,n(r.get(o)));break}}}return e};function $e(e,t,n=[]){if(!e)return;if(!j(e)){Y(e,(i,o)=>$e(i,t,[...n,...ee(o)]));return}let[r,s]=e;s&&Y(s,(i,o)=>{$e(i,t,[...n,...ee(o)])}),t(r,n)}function Kn(e,t,n){return $e(t,(r,s)=>{e=Me(e,s,i=>Un(i,r,n))}),e}function qn(e,t){function n(r,s){let i=Fn(e,ee(s));r.map(ee).forEach(o=>{e=Me(e,o,()=>i)})}if(j(t)){let[r,s]=t;r.forEach(i=>{e=Me(e,ee(i),()=>e)}),s&&Y(s,n)}else Y(t,n);return e}var zn=(e,t)=>ie(e)||j(e)||oe(e)||le(e)||Et(e,t);function Hn(e,t,n){let r=n.get(e);r?r.push(t):n.set(e,[t])}function Gn(e,t){let n={},r;return e.forEach(s=>{if(s.length<=1)return;t||(s=s.map(l=>l.map(String)).sort((l,a)=>l.length-a.length));let[i,...o]=s;i.length===0?r=o.map(ke):n[ke(i)]=o.map(ke)}),r?Le(n)?[r]:[r,n]:Le(n)?void 0:n}var Tt=(e,t,n,r,s=[],i=[],o=new Map)=>{let l=Ln(e);if(!l){Hn(e,s,t);let w=o.get(e);if(w)return r?{transformedValue:null}:w}if(!zn(e,n)){let w=We(e,n),v=w?{transformedValue:w.value,annotations:[w.type]}:{transformedValue:e};return l||o.set(e,v),v}if(ge(i,e))return{transformedValue:null};let a=We(e,n),c=a?.value??e,d=j(c)?[]:{},u={};Y(c,(w,v)=>{if(v==="__proto__"||v==="constructor"||v==="prototype")throw new Error(`Detected property ${v}. This is a prototype pollution risk, please remove it from your object.`);let k=Tt(w,t,n,r,[...s,v],[...i,e],o);d[v]=k.transformedValue,j(k.annotations)?u[v]=k.annotations:ie(k.annotations)&&Y(k.annotations,(L,_)=>{u[vt(v)+"."+_]=L})});let h=Le(u)?{transformedValue:d,annotations:a?[a.type]:void 0}:{transformedValue:d,annotations:a?[a.type,u]:u};return l||o.set(e,h),h};function Nt(e){return Object.prototype.toString.call(e).slice(8,-1)}function Ze(e){return Nt(e)==="Array"}function Qn(e){if(Nt(e)!=="Object")return!1;let t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function Xn(e,t,n,r,s){let i={}.propertyIsEnumerable.call(r,t)?"enumerable":"nonenumerable";i==="enumerable"&&(e[t]=n),s&&i==="nonenumerable"&&Object.defineProperty(e,t,{value:n,enumerable:!1,writable:!0,configurable:!0})}function _e(e,t={}){if(Ze(e))return e.map(s=>_e(s,t));if(!Qn(e))return e;let n=Object.getOwnPropertyNames(e),r=Object.getOwnPropertySymbols(e);return[...n,...r].reduce((s,i)=>{if(Ze(t.props)&&!t.props.includes(i))return s;let o=e[i],l=_e(o,t);return Xn(s,i,l,e,t.nonenumerable),s},{})}var m=class{constructor({dedupe:e=!1}={}){this.classRegistry=new An,this.symbolRegistry=new mt(t=>t.description??""),this.customTransformerRegistry=new xn,this.allowedErrorProps=[],this.dedupe=e}serialize(e){let t=new Map,n=Tt(e,t,this,this.dedupe),r={json:n.transformedValue};n.annotations&&(r.meta={...r.meta,values:n.annotations});let s=Gn(t,this.dedupe);return s&&(r.meta={...r.meta,referentialEqualities:s}),r}deserialize(e){let{json:t,meta:n}=e,r=_e(t);return n?.values&&(r=Kn(r,n.values,this)),n?.referentialEqualities&&(r=qn(r,n.referentialEqualities)),r}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};m.defaultInstance=new m;m.serialize=m.defaultInstance.serialize.bind(m.defaultInstance);m.deserialize=m.defaultInstance.deserialize.bind(m.defaultInstance);m.stringify=m.defaultInstance.stringify.bind(m.defaultInstance);m.parse=m.defaultInstance.parse.bind(m.defaultInstance);m.registerClass=m.defaultInstance.registerClass.bind(m.defaultInstance);m.registerSymbol=m.defaultInstance.registerSymbol.bind(m.defaultInstance);m.registerCustom=m.defaultInstance.registerCustom.bind(m.defaultInstance);m.allowErrorProps=m.defaultInstance.allowErrorProps.bind(m.defaultInstance);var Yn=m.serialize;m.deserialize;var Sr=m.stringify;m.parse;m.registerClass;m.registerCustom;m.registerSymbol;m.allowErrorProps;function Ar(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function Er(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function Or({queryState:e,observerCount:t,isStale:n}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":n?"yellow":"green":"gray"}function xr({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function kr(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var Cr=(e,t=!1)=>{let{json:n}=Yn(e);return JSON.stringify(n,null,t?2:void 0)},fe=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,Wn=(e,t)=>e.queryHash.localeCompare(t.queryHash),It=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,Zn=(e,t)=>fe(e)===fe(t)?It(e,t):fe(e)>fe(t)?1:-1,Tr={status:Zn,"query hash":Wn,"last updated":It},ue=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,Pt=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,Jn=(e,t)=>ue(e)===ue(t)?Pt(e,t):ue(e)>ue(t)?1:-1,Nr={status:Jn,"last updated":Pt},Ir=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),Pr=()=>{let[e,t]=V("dark");return $t(()=>{let n=window.matchMedia("(prefers-color-scheme: dark)");t(n.matches?"dark":"light");let r=s=>{t(s.matches?"dark":"light")};n.addEventListener("change",r),X(()=>n.removeEventListener("change",r))}),e},ce=(e,t,n)=>{if(t.length===0)return n;if(e instanceof Map){let r=new Map(e);if(t.length===1)return r.set(t[0],n),r;let[s,...i]=t;return r.set(s,ce(r.get(s),i,n)),r}if(e instanceof Set){let r=ce(Array.from(e),t,n);return new Set(r)}if(Array.isArray(e)){let r=[...e];if(t.length===1)return r[t[0]]=n,r;let[s,...i]=t;return r[s]=ce(r[s],i,n),r}if(e instanceof Object){let r={...e};if(t.length===1)return r[t[0]]=n,r;let[s,...i]=t;return r[s]=ce(r[s],i,n),r}return e},de=(e,t)=>{if(e instanceof Map){let n=new Map(e);if(t.length===1)return n.delete(t[0]),n;let[r,...s]=t;return n.set(r,de(n.get(r),s)),n}if(e instanceof Set){let n=de(Array.from(e),t);return new Set(n)}if(Array.isArray(e)){let n=[...e];if(t.length===1)return n.filter((i,o)=>o.toString()!==t[0]);let[r,...s]=t;return n[r]=de(n[r],s),n}if(e instanceof Object){let n={...e};if(t.length===1)return delete n[t[0]],n;let[r,...s]=t;return n[r]=de(n[r],s),n}return e},Rr=(e,t)=>{if(!e||document.querySelector("#_goober")||t?.querySelector("#_goober"))return;let r=document.createElement("style"),s=document.createTextNode("");r.appendChild(s),r.id="_goober",r.setAttribute("nonce",e),t?t.appendChild(r):document.head.appendChild(r)};export{tt as a,F as b,V as c,Ue as d,K as e,st as f,x as g,tr as h,O as i,nr as j,$t as k,X as l,Fe as m,rr as n,sr as o,ot as p,ir as q,or as r,Gt as s,lr as t,ar as u,fr as v,ur as w,cr as x,dr as y,gr as z,hr as A,yr as B,mr as C,on as D,wr as E,Pe as F,fn as G,un as H,gn as I,hn as J,Re as K,pr as L,vr as M,br as N,Yn as O,Sr as P,Ar as Q,Er as R,Or as S,xr as T,kr as U,Cr as V,Tr as W,Nr as X,Ir as Y,Pr as Z,ce as _,de as $,Rr as aa};
@@ -1 +0,0 @@
1
- function U(r){return typeof r>"u"||r===void 0}function W(r){return typeof r=="string"}function Le(r){return typeof r=="number"}function qr(r){return typeof r=="boolean"}function Ir(r){return r===null}function ci(r){return r instanceof Date}function Br(r){return typeof r=="bigint"}function O(r){return typeof r=="function"}function A(r){return typeof r=="object"&&r!==null}function o(r){return Object.freeze(r)}function yr(r){return D(r)?r:[r]}function D(r){return Array.isArray(r)}function L(r){return r}var h=o({is(r){return r.kind==="AlterTableNode"},create(r){return o({kind:"AlterTableNode",table:r})},cloneWithTableProps(r,e){return o({...r,...e})},cloneWithColumnAlteration(r,e){return o({...r,columnAlterations:r.columnAlterations?[...r.columnAlterations,e]:[e]})}});var d=o({is(r){return r.kind==="IdentifierNode"},create(r){return o({kind:"IdentifierNode",name:r})}});var Y=o({is(r){return r.kind==="CreateIndexNode"},create(r){return o({kind:"CreateIndexNode",name:d.create(r)})},cloneWith(r,e){return o({...r,...e})},cloneWithColumns(r,e){return o({...r,columns:[...r.columns||[],...e]})}});var Dr=o({is(r){return r.kind==="CreateSchemaNode"},create(r,e){return o({kind:"CreateSchemaNode",schema:d.create(r),...e})},cloneWith(r,e){return o({...r,...e})}});var Po=["preserve rows","delete rows","drop"],M=o({is(r){return r.kind==="CreateTableNode"},create(r){return o({kind:"CreateTableNode",table:r,columns:o([])})},cloneWithColumn(r,e){return o({...r,columns:o([...r.columns,e])})},cloneWithConstraint(r,e){return o({...r,constraints:r.constraints?o([...r.constraints,e]):o([e])})},cloneWithFrontModifier(r,e){return o({...r,frontModifiers:r.frontModifiers?o([...r.frontModifiers,e]):o([e])})},cloneWithEndModifier(r,e){return o({...r,endModifiers:r.endModifiers?o([...r.endModifiers,e]):o([e])})},cloneWith(r,e){return o({...r,...e})}});var Q=o({is(r){return r.kind==="SchemableIdentifierNode"},create(r){return o({kind:"SchemableIdentifierNode",identifier:d.create(r)})},createWithSchema(r,e){return o({kind:"SchemableIdentifierNode",schema:d.create(r),identifier:d.create(e)})}});var We=o({is(r){return r.kind==="DropIndexNode"},create(r,e){return o({kind:"DropIndexNode",name:Q.create(r),...e})},cloneWith(r,e){return o({...r,...e})}});var wr=o({is(r){return r.kind==="DropSchemaNode"},create(r,e){return o({kind:"DropSchemaNode",schema:d.create(r),...e})},cloneWith(r,e){return o({...r,...e})}});var xr=o({is(r){return r.kind==="DropTableNode"},create(r,e){return o({kind:"DropTableNode",table:r,...e})},cloneWith(r,e){return o({...r,...e})}});var P=o({is(r){return r.kind==="AliasNode"},create(r,e){return o({kind:"AliasNode",node:r,alias:e})}});var J=o({is(r){return r.kind==="TableNode"},create(r){return o({kind:"TableNode",table:Q.create(r)})},createWithSchema(r,e){return o({kind:"TableNode",table:Q.createWithSchema(r,e)})}});function g(r){return A(r)&&O(r.toOperationNode)}function Qr(r){return A(r)&&"expressionType"in r&&g(r)}function vo(r){return A(r)&&"expression"in r&&W(r.alias)&&g(r)}var se=o({is(r){return r.kind==="SelectModifierNode"},create(r,e){return o({kind:"SelectModifierNode",modifier:r,of:e})},createWithExpression(r){return o({kind:"SelectModifierNode",rawModifier:r})}});var z=o({is(r){return r.kind==="AndNode"},create(r,e){return o({kind:"AndNode",left:r,right:e})}});var X=o({is(r){return r.kind==="OrNode"},create(r,e){return o({kind:"OrNode",left:r,right:e})}});var Pr=o({is(r){return r.kind==="OnNode"},create(r){return o({kind:"OnNode",on:r})},cloneWithOperation(r,e,t){return o({...r,on:e==="And"?z.create(r.on,t):X.create(r.on,t)})}});var he=o({is(r){return r.kind==="JoinNode"},create(r,e){return o({kind:"JoinNode",joinType:r,table:e,on:void 0})},createWithOn(r,e,t){return o({kind:"JoinNode",joinType:r,table:e,on:Pr.create(t)})},cloneWithOn(r,e){return o({...r,on:r.on?Pr.cloneWithOperation(r.on,"And",e):Pr.create(e)})}});var ge=o({is(r){return r.kind==="BinaryOperationNode"},create(r,e,t){return o({kind:"BinaryOperationNode",leftOperand:r,operator:e,rightOperand:t})}});var qn=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],In=["+","-","*","/","%","^","&","|","#","<<",">>"],Lo=["->","->>"],Bn=[...qn,...In,"&&","||"],Dn=["exists","not exists"],Qn=["not","-",...Dn],Fo=[...Bn,...Lo,...Qn,"between","between symmetric"],Z=o({is(r){return r.kind==="OperatorNode"},create(r){return o({kind:"OperatorNode",operator:r})}});function Lt(r){return W(r)&&Lo.includes(r)}var m=o({is(r){return r.kind==="ColumnNode"},create(r){return o({kind:"ColumnNode",column:d.create(r)})}});var Fe=o({is(r){return r.kind==="SelectAllNode"},create(){return o({kind:"SelectAllNode"})}});var Me=o({is(r){return r.kind==="ReferenceNode"},create(r,e){return o({kind:"ReferenceNode",table:e,column:r})},createSelectAll(r){return o({kind:"ReferenceNode",table:r,column:Fe.create()})}});var vr=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Ft(this.#e)}};function Lr(r){return A(r)&&g(r)&&W(r.dynamicReference)}var _=o({is(r){return r.kind==="OrderByItemNode"},create(r,e){return o({kind:"OrderByItemNode",orderBy:r,direction:e})},cloneWith(r,e){return o({...r,...e})}});var v=o({is(r){return r.kind==="RawNode"},create(r,e){return o({kind:"RawNode",sqlFragments:o(r),parameters:o(e)})},createWithSql(r){return v.create([r],[])},createWithChild(r){return v.create(["",""],[r])},createWithChildren(r){return v.create(new Array(r.length+1).fill(""),r)}});var Mo={is(r){return r.kind==="CollateNode"},create(r){return o({kind:"CollateNode",collation:d.create(r)})}};var Fr=class r{#e;constructor(e){this.#e=o(e)}desc(){return new r({node:_.cloneWith(this.#e.node,{direction:v.createWithSql("desc")})})}asc(){return new r({node:_.cloneWith(this.#e.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new r({node:_.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new r({node:_.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new r({node:_.cloneWith(this.#e.node,{collation:Mo.create(e)})})}toOperationNode(){return this.#e.node}};var zo=new Set;function ze(r){zo.has(r)||(zo.add(r),console.log(r))}function zt(r){return r==="asc"||r==="desc"}function $(r){if(r.length===2)return[Mt(r[0],r[1])];if(r.length===1){let[e]=r;return Array.isArray(e)?(ze("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(t=>Mt(t))):[Mt(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${r.length}`)}function Mt(r,e){let t=Pn(r);if(_.is(t)){if(e)throw new Error("Cannot specify direction twice!");return t}return Vo(t,e)}function Pn(r){if(le(r))return V(r);if(Lr(r))return r.toOperationNode();let[e,t]=r.split(" ");return t?(ze("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Vo(ee(e),t)):ee(r)}function Vo(r,e){if(typeof e=="string"){if(!zt(e))throw new Error(`Invalid order by direction: ${e}`);return _.create(r,v.createWithSql(e))}if(Qr(e))return ze("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),_.create(r,e.toOperationNode());let t=_.create(r);return e?e(new Fr({node:t})).toOperationNode():t}var Ve=o({is(r){return r.kind==="JSONReferenceNode"},create(r,e){return o({kind:"JSONReferenceNode",reference:r,traversal:e})},cloneWithTraversal(r,e){return o({...r,traversal:e})}});var Mr=o({is(r){return r.kind==="JSONOperatorChainNode"},create(r){return o({kind:"JSONOperatorChainNode",operator:r,values:o([])})},cloneWithValue(r,e){return o({...r,values:o([...r.values,e])})}});var Ce=o({is(r){return r.kind==="JSONPathNode"},create(r){return o({kind:"JSONPathNode",inOperator:r,pathLegs:o([])})},cloneWithLeg(r,e){return o({...r,pathLegs:o([...r.pathLegs,e])})}});function Ft(r){return W(r)?ee(r):r.toOperationNode()}function pe(r){return D(r)?r.map(e=>R(e)):[R(r)]}function R(r){return le(r)?V(r):Ft(r)}function Uo(r,e){let t=ee(r);if(Lt(e))return Ve.create(t,Mr.create(Z.create(e)));let n=e.slice(0,-1);if(Lt(n))return Ve.create(t,Ce.create(Z.create(n)));throw new Error(`Invalid JSON operator: ${e}`)}function ee(r){let e=".";if(!r.includes(e))return Me.create(m.create(r));let t=r.split(e).map(Ut);if(t.length===3)return vn(t);if(t.length===2)return Ln(t);throw new Error(`invalid column reference ${r}`)}function Jo(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map(Ut);return P.create(ee(t),d.create(n))}else return ee(r)}function Vt(r){return m.create(r)}function Ue(r){let e=" ";if(r.includes(e)){let[t,n]=r.split(e).map(Ut);if(!zt(n))throw new Error(`invalid order direction "${n}" next to "${t}"`);return $([t,n])[0]}else return Vt(r)}function vn(r){let[e,t,n]=r;return Me.create(m.create(n),J.createWithSchema(e,t))}function Ln(r){let[e,t]=r;return Me.create(m.create(t),J.create(e))}function Ut(r){return r.trim()}var zr=o({is(r){return r.kind==="PrimitiveValueListNode"},create(r){return o({kind:"PrimitiveValueListNode",values:o([...r])})}});var ae=o({is(r){return r.kind==="ValueListNode"},create(r){return o({kind:"ValueListNode",values:o(r)})}});var b=o({is(r){return r.kind==="ValueNode"},create(r){return o({kind:"ValueNode",value:r})},createImmediate(r){return o({kind:"ValueNode",value:r,immediate:!0})}});function $o(r){return D(r)?Fn(r):w(r)}function w(r){return le(r)?V(r):b.create(r)}function Vr(r){return Le(r)||qr(r)||Ir(r)}function Or(r){if(!Vr(r))throw new Error(`unsafe immediate value ${JSON.stringify(r)}`);return b.createImmediate(r)}function Fn(r){return r.some(le)?ae.create(r.map(e=>w(e))):zr.create(r)}var be=o({is(r){return r.kind==="ParensNode"},create(r){return o({kind:"ParensNode",node:r})}});function N(r){if(r.length===3)return Ur(r[0],r[1],r[2]);if(r.length===1)return w(r[0]);throw new Error(`invalid arguments: ${JSON.stringify(r)}`)}function Ur(r,e,t){return Mn(e)&&Go(t)?ge.create(R(r),Jt(e),b.createImmediate(t)):ge.create(R(r),Jt(e),$o(t))}function T(r,e,t){return ge.create(R(r),Jt(e),R(t))}function $t(r,e){return Je(Object.entries(r).filter(([,t])=>!U(t)).map(([t,n])=>Ur(t,Go(n)?"is":"=",n)),e)}function Je(r,e,t=!0){let n=e==="and"?z.create:X.create;if(r.length===0)return ge.create(b.createImmediate(1),Z.create("="),b.createImmediate(e==="and"?1:0));let s=Ko(r[0]);for(let u=1;u<r.length;++u)s=n(s,Ko(r[u]));return r.length>1&&t?be.create(s):s}function Mn(r){return r==="is"||r==="is not"}function Go(r){return Ir(r)||qr(r)}function Jt(r){if(W(r)&&Fo.includes(r))return Z.create(r);if(g(r))return r.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(r)}`)}function Ko(r){return g(r)?r.toOperationNode():r}var fe=o({is(r){return r.kind==="OrderByNode"},create(r){return o({kind:"OrderByNode",items:o([...r])})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var Kt=o({is(r){return r.kind==="PartitionByNode"},create(r){return o({kind:"PartitionByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var Wr=o({is(r){return r.kind==="OverNode"},create(){return o({kind:"OverNode"})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?fe.cloneWithItems(r.orderBy,e):fe.create(e)})},cloneWithPartitionByItems(r,e){return o({...r,partitionBy:r.partitionBy?Kt.cloneWithItems(r.partitionBy,e):Kt.create(e)})}});var Re=o({is(r){return r.kind==="FromNode"},create(r){return o({kind:"FromNode",froms:o(r)})},cloneWithFroms(r,e){return o({...r,froms:o([...r.froms,...e])})}});var Gt=o({is(r){return r.kind==="GroupByNode"},create(r){return o({kind:"GroupByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var jt=o({is(r){return r.kind==="HavingNode"},create(r){return o({kind:"HavingNode",having:r})},cloneWithOperation(r,e,t){return o({...r,having:e==="And"?z.create(r.having,t):X.create(r.having,t)})}});var C=o({is(r){return r.kind==="InsertQueryNode"},create(r,e,t){return o({kind:"InsertQueryNode",into:r,...e&&{with:e},replace:t})},createWithoutInto(){return o({kind:"InsertQueryNode"})},cloneWith(r,e){return o({...r,...e})}});var Jr=o({is(r){return r.kind==="ListNode"},create(r){return o({kind:"ListNode",items:o(r)})}});var ue=o({is(r){return r.kind==="UpdateQueryNode"},create(r,e){return o({kind:"UpdateQueryNode",table:r.length===1?r[0]:Jr.create(r),...e&&{with:e}})},createWithoutTable(){return o({kind:"UpdateQueryNode"})},cloneWithFromItems(r,e){return o({...r,from:r.from?Re.cloneWithFroms(r.from,e):Re.create(e)})},cloneWithUpdates(r,e){return o({...r,updates:r.updates?o([...r.updates,...e]):e})},cloneWithLimit(r,e){return o({...r,limit:e})}});var Ht=o({is(r){return r.kind==="UsingNode"},create(r){return o({kind:"UsingNode",tables:o(r)})},cloneWithTables(r,e){return o({...r,tables:o([...r.tables,...e])})}});var ke=o({is(r){return r.kind==="DeleteQueryNode"},create(r,e){return o({kind:"DeleteQueryNode",from:Re.create(r),...e&&{with:e}})},cloneWithOrderByItems:(r,e)=>a.cloneWithOrderByItems(r,e),cloneWithoutOrderBy:r=>a.cloneWithoutOrderBy(r),cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithUsing(r,e){return o({...r,using:r.using!==void 0?Ht.cloneWithTables(r.using,e):Ht.create(e)})}});var q=o({is(r){return r.kind==="WhereNode"},create(r){return o({kind:"WhereNode",where:r})},cloneWithOperation(r,e,t){return o({...r,where:e==="And"?z.create(r.where,t):X.create(r.where,t)})}});var Yt=o({is(r){return r.kind==="ReturningNode"},create(r){return o({kind:"ReturningNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var jo=o({is(r){return r.kind==="ExplainNode"},create(r,e){return o({kind:"ExplainNode",format:r,options:e})}});var Ne=o({is(r){return r.kind==="WhenNode"},create(r){return o({kind:"WhenNode",condition:r})},cloneWithResult(r,e){return o({...r,result:e})}});var K=o({is(r){return r.kind==="MergeQueryNode"},create(r,e){return o({kind:"MergeQueryNode",into:r,...e&&{with:e}})},cloneWithUsing(r,e){return o({...r,using:e})},cloneWithWhen(r,e){return o({...r,whens:r.whens?o([...r.whens,e]):o([e])})},cloneWithThen(r,e){return o({...r,whens:r.whens?o([...r.whens.slice(0,-1),Ne.cloneWithResult(r.whens[r.whens.length-1],e)]):void 0})}});var Xt=o({is(r){return r.kind==="OutputNode"},create(r){return o({kind:"OutputNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var a=o({is(r){return f.is(r)||C.is(r)||ue.is(r)||ke.is(r)||K.is(r)},cloneWithEndModifier(r,e){return o({...r,endModifiers:r.endModifiers?o([...r.endModifiers,e]):o([e])})},cloneWithWhere(r,e){return o({...r,where:r.where?q.cloneWithOperation(r.where,"And",e):q.create(e)})},cloneWithJoin(r,e){return o({...r,joins:r.joins?o([...r.joins,e]):o([e])})},cloneWithReturning(r,e){return o({...r,returning:r.returning?Yt.cloneWithSelections(r.returning,e):Yt.create(e)})},cloneWithoutReturning(r){return o({...r,returning:void 0})},cloneWithoutWhere(r){return o({...r,where:void 0})},cloneWithExplain(r,e,t){return o({...r,explain:jo.create(e,t?.toOperationNode())})},cloneWithTop(r,e){return o({...r,top:e})},cloneWithOutput(r,e){return o({...r,output:r.output?Xt.cloneWithSelections(r.output,e):Xt.create(e)})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?fe.cloneWithItems(r.orderBy,e):fe.create(e)})},cloneWithoutOrderBy(r){return o({...r,orderBy:void 0})}});var f=o({is(r){return r.kind==="SelectQueryNode"},create(r){return o({kind:"SelectQueryNode",...r&&{with:r}})},createFrom(r,e){return o({kind:"SelectQueryNode",from:Re.create(r),...e&&{with:e}})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})},cloneWithDistinctOn(r,e){return o({...r,distinctOn:r.distinctOn?o([...r.distinctOn,...e]):o(e)})},cloneWithFrontModifier(r,e){return o({...r,frontModifiers:r.frontModifiers?o([...r.frontModifiers,e]):o([e])})},cloneWithOrderByItems:(r,e)=>a.cloneWithOrderByItems(r,e),cloneWithGroupByItems(r,e){return o({...r,groupBy:r.groupBy?Gt.cloneWithItems(r.groupBy,e):Gt.create(e)})},cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithOffset(r,e){return o({...r,offset:e})},cloneWithFetch(r,e){return o({...r,fetch:e})},cloneWithHaving(r,e){return o({...r,having:r.having?jt.cloneWithOperation(r.having,"And",e):jt.create(e)})},cloneWithSetOperations(r,e){return o({...r,setOperations:r.setOperations?o([...r.setOperations,...e]):o([...e])})},cloneWithoutSelections(r){return o({...r,selections:[]})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithoutOffset(r){return o({...r,offset:void 0})},cloneWithoutOrderBy:r=>a.cloneWithoutOrderBy(r),cloneWithoutGroupBy(r){return o({...r,groupBy:void 0})}});var $r=class r{#e;constructor(e){this.#e=o(e)}on(...e){return new r({...this.#e,joinNode:he.cloneWithOn(this.#e.joinNode,N(e))})}onRef(e,t,n){return new r({...this.#e,joinNode:he.cloneWithOn(this.#e.joinNode,T(e,t,n))})}onTrue(){return new r({...this.#e,joinNode:he.cloneWithOn(this.#e.joinNode,v.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var Ho=o({is(r){return r.kind==="PartitionByItemNode"},create(r){return o({kind:"PartitionByItemNode",partitionBy:r})}});function Yo(r){return pe(r).map(Ho.create)}var Kr=class r{#e;constructor(e){this.#e=o(e)}orderBy(...e){return new r({overNode:Wr.cloneWithOrderByItems(this.#e.overNode,$(e))})}clearOrderBy(){return new r({overNode:a.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new r({overNode:Wr.cloneWithPartitionByItems(this.#e.overNode,Yo(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var $e=o({is(r){return r.kind==="SelectionNode"},create(r){return o({kind:"SelectionNode",selection:r})},createSelectAll(){return o({kind:"SelectionNode",selection:Fe.create()})},createSelectAllFromTable(r){return o({kind:"SelectionNode",selection:Me.createSelectAll(r)})}});function k(r){return O(r)?k(r(re())):D(r)?r.map(e=>Xo(e)):[Xo(r)]}function Xo(r){return W(r)?$e.create(Jo(r)):Lr(r)?$e.create(r.toOperationNode()):$e.create(Gr(r))}function S(r){return r?Array.isArray(r)?r.map(Zo):[Zo(r)]:[$e.createSelectAll()]}function Zo(r){if(W(r))return $e.createSelectAllFromTable(l(r));throw new Error(`invalid value selectAll expression: ${JSON.stringify(r)}`)}var _o=o({is(r){return r.kind==="ValuesNode"},create(r){return o({kind:"ValuesNode",values:o(r)})}});var en=o({is(r){return r.kind==="DefaultInsertValueNode"},create(){return o({kind:"DefaultInsertValueNode"})}});function jr(r){let e=O(r)?r(re()):r,t=D(e)?e:o([e]);return zn(t)}function zn(r){let e=Vn(r);return[o([...e.keys()].map(m.create)),_o.create(r.map(t=>Un(t,e)))]}function Vn(r){let e=new Map;for(let t of r){let n=Object.keys(t);for(let s of n)!e.has(s)&&t[s]!==void 0&&e.set(s,e.size)}return e}function Un(r,e){let t=Object.keys(r),n=Array.from({length:e.size}),s=!1,u=t.length;for(let E of t){let I=e.get(E);if(U(I)){u--;continue}let B=r[E];(U(B)||le(B))&&(s=!0),n[I]=B}if(u<e.size||s){let E=en.create();return ae.create(n.map(I=>U(I)?E:w(I)))}return zr.create(n)}var Zt=o({is(r){return r.kind==="ColumnUpdateNode"},create(r,e){return o({kind:"ColumnUpdateNode",column:r,value:e})}});function rn(...r){return r.length===2?[Zt.create(R(r[0]),w(r[1]))]:gr(r[0])}function gr(r){let e=O(r)?r(re()):r;return Object.entries(e).filter(([t,n])=>n!==void 0).map(([t,n])=>Zt.create(m.create(t),w(n)))}var tn=o({is(r){return r.kind==="OnDuplicateKeyNode"},create(r){return o({kind:"OnDuplicateKeyNode",updates:r})}});var Hr=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}};var j=class extends Error{node;constructor(e){super("no result"),this.node=e}};function de(r){return Object.prototype.hasOwnProperty.call(r,"prototype")}var F=o({is(r){return r.kind==="OnConflictNode"},create(){return o({kind:"OnConflictNode"})},cloneWith(r,e){return o({...r,...e})},cloneWithIndexWhere(r,e){return o({...r,indexWhere:r.indexWhere?q.cloneWithOperation(r.indexWhere,"And",e):q.create(e)})},cloneWithIndexOrWhere(r,e){return o({...r,indexWhere:r.indexWhere?q.cloneWithOperation(r.indexWhere,"Or",e):q.create(e)})},cloneWithUpdateWhere(r,e){return o({...r,updateWhere:r.updateWhere?q.cloneWithOperation(r.updateWhere,"And",e):q.create(e)})},cloneWithUpdateOrWhere(r,e){return o({...r,updateWhere:r.updateWhere?q.cloneWithOperation(r.updateWhere,"Or",e):q.create(e)})},cloneWithoutIndexWhere(r){return o({...r,indexWhere:void 0})},cloneWithoutUpdateWhere(r){return o({...r,updateWhere:void 0})}});var Yr=class r{#e;constructor(e){this.#e=o(e)}column(e){let t=m.create(e);return new r({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,t]):o([t])})})}columns(e){let t=e.map(m.create);return new r({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,...t]):o(t)})})}constraint(e){return new r({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{constraint:d.create(e)})})}expression(e){return new r({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new r({...this.#e,onConflictNode:F.cloneWithIndexWhere(this.#e.onConflictNode,N(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:F.cloneWithIndexWhere(this.#e.onConflictNode,T(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:F.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new _t({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new eo({...this.#e,onConflictNode:F.cloneWith(this.#e.onConflictNode,{updates:gr(e)})})}$call(e){return e(this)}},_t=class{#e;constructor(e){this.#e=o(e)}toOperationNode(){return this.#e.onConflictNode}},eo=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,onConflictNode:F.cloneWithUpdateWhere(this.#e.onConflictNode,N(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:F.cloneWithUpdateWhere(this.#e.onConflictNode,T(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:F.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var on=o({is(r){return r.kind==="TopNode"},create(r,e){return o({kind:"TopNode",expression:r,modifiers:e})}});function te(r,e){if(!Le(r)&&!Br(r))throw new Error(`Invalid top expression: ${r}`);if(!U(e)&&!Jn(e))throw new Error(`Invalid top modifiers: ${e}`);return on.create(r,e)}function Jn(r){return r==="percent"||r==="with ties"||r==="percent with ties"}var qe=o({is(r){return r.kind==="OrActionNode"},create(r){return o({kind:"OrActionNode",action:r})}});var Cr=class r{#e;constructor(e){this.#e=o(e)}values(e){let[t,n]=jr(e);return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{columns:t,values:n})})}columns(e){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{columns:o(e.map(m.create))})})}expression(e){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{values:V(e)})})}defaultValues(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("ignore")})})}orIgnore(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("ignore")})})}orAbort(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("abort")})})}orFail(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("fail")})})}orReplace(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("replace")})})}orRollback(){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{orAction:qe.create("rollback")})})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}onConflict(e){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{onConflict:e(new Yr({onConflictNode:F.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new r({...this.#e,queryNode:C.cloneWith(this.#e.queryNode,{onDuplicateKey:tn.create(gr(e))})})}returning(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,S())})}output(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,S(e))})}clearReturning(){return new r({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:n}=this.#e.executor,s=e.query;return s.returning&&n.supportsReturning||s.output&&n.supportsOutput?t.rows:[new Hr(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let t=await this.executeTakeFirst();if(t===void 0)throw de(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e,this.#e.queryId);for await(let s of n)yield*s.rows}async explain(e,t){return await new r({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var Xr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var Ke=o({is(r){return r.kind==="LimitNode"},create(r){return o({kind:"LimitNode",limit:r})}});var Zr=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,T(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}using(e){return new r({...this.#e,queryNode:ke.cloneWithUsing(this.#e.queryNode,oe(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,Te(e,t))})}returning(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,S(e))})}output(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,S(e))})}clearReturning(){return new r({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:ke.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new r({...this.#e,queryNode:a.cloneWithOrderByItems(this.#e.queryNode,$(e))})}clearOrderBy(){return new r({...this.#e,queryNode:a.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:ke.cloneWithLimit(this.#e.queryNode,Ke.create(w(e)))})}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:n}=this.#e.executor,s=e.query;return s.returning&&n.supportsReturning||s.output&&n.supportsOutput?t.rows:[new Xr(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let t=await this.executeTakeFirst();if(t===void 0)throw de(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e,this.#e.queryId);for await(let s of n)yield*s.rows}async explain(e,t){return await new r({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var _r=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}};var Ge=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,T(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}from(e){return new r({...this.#e,queryNode:ue.cloneWithFromItems(this.#e.queryNode,oe(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,Te(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:a.cloneWithOrderByItems(this.#e.queryNode,$(e))})}clearOrderBy(){return new r({...this.#e,queryNode:a.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:ue.cloneWithLimit(this.#e.queryNode,Ke.create(w(e)))})}set(...e){return new r({...this.#e,queryNode:ue.cloneWithUpdates(this.#e.queryNode,rn(...e))})}returning(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,S(e))})}output(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,S(e))})}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new r({...this.#e,queryNode:a.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:n}=this.#e.executor,s=e.query;return s.returning&&n.supportsReturning||s.output&&n.supportsOutput?t.rows:[new _r(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let t=await this.executeTakeFirst();if(t===void 0)throw de(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e,this.#e.queryId);for await(let s of n)yield*s.rows}async explain(e,t){return await new r({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var ro=o({is(r){return r.kind==="CommonTableExpressionNameNode"},create(r,e){return o({kind:"CommonTableExpressionNameNode",table:J.create(r),columns:e?o(e.map(m.create)):void 0})}});var je=o({is(r){return r.kind==="CommonTableExpressionNode"},create(r,e){return o({kind:"CommonTableExpressionNode",name:r,expression:e})},cloneWith(r,e){return o({...r,...e})}});var et=class r{#e;constructor(e){this.#e=o(e)}materialized(){return new r({...this.#e,node:je.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new r({...this.#e,node:je.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function to(r,e){let t=e(sn()).toOperationNode();return O(r)?r($n(t)).toOperationNode():je.create(nn(r),t)}function $n(r){return e=>new et({node:je.create(nn(e),r)})}function nn(r){if(r.includes("(")){let e=r.split(/[\(\)]/),t=e[0],n=e[1].split(",").map(s=>s.trim());return ro.create(t,n)}else return ro.create(r)}var br=o({is(r){return r.kind==="WithNode"},create(r,e){return o({kind:"WithNode",expressions:o([r]),...e})},cloneWithExpression(r,e){return o({...r,expressions:o([...r.expressions,e])})}});var an=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function un(r){let e="";for(let t=0;t<r;++t)e+=Kn();return e}function Kn(){return an[~~(Math.random()*an.length)]}function x(){return new oo}var oo=class{#e;get queryId(){return this.#e===void 0&&(this.#e=un(8)),this.#e}};var Se=class{nodeStack=[];#e=o({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let n=this.transformNodeImpl(e,t);return this.nodeStack.pop(),o(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&o(e.map(n=>this.transformNode(n,t)))}transformSelectQuery(e,t){return{kind:"SelectQueryNode",from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)}}transformSelection(e,t){return{kind:"SelectionNode",selection:this.transformNode(e.selection,t)}}transformColumn(e,t){return{kind:"ColumnNode",column:this.transformNode(e.column,t)}}transformAlias(e,t){return{kind:"AliasNode",node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)}}transformTable(e,t){return{kind:"TableNode",table:this.transformNode(e.table,t)}}transformFrom(e,t){return{kind:"FromNode",froms:this.transformNodeList(e.froms,t)}}transformReference(e,t){return{kind:"ReferenceNode",column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)}}transformAnd(e,t){return{kind:"AndNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformOr(e,t){return{kind:"OrNode",left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformValueList(e,t){return{kind:"ValueListNode",values:this.transformNodeList(e.values,t)}}transformParens(e,t){return{kind:"ParensNode",node:this.transformNode(e.node,t)}}transformJoin(e,t){return{kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)}}transformRaw(e,t){return{kind:"RawNode",sqlFragments:o([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)}}transformWhere(e,t){return{kind:"WhereNode",where:this.transformNode(e.where,t)}}transformInsertQuery(e,t){return{kind:"InsertQueryNode",into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformValues(e,t){return{kind:"ValuesNode",values:this.transformNodeList(e.values,t)}}transformDeleteQuery(e,t){return{kind:"DeleteQueryNode",from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformReturning(e,t){return{kind:"ReturningNode",selections:this.transformNodeList(e.selections,t)}}transformCreateTable(e,t){return{kind:"CreateTableNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)}}transformColumnDefinition(e,t){return{kind:"ColumnDefinitionNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists}}transformAddColumn(e,t){return{kind:"AddColumnNode",column:this.transformNode(e.column,t)}}transformDropTable(e,t){return{kind:"DropTableNode",table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformOrderBy(e,t){return{kind:"OrderByNode",items:this.transformNodeList(e.items,t)}}transformOrderByItem(e,t){return{kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls}}transformGroupBy(e,t){return{kind:"GroupByNode",items:this.transformNodeList(e.items,t)}}transformGroupByItem(e,t){return{kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,t)}}transformUpdateQuery(e,t){return{kind:"UpdateQueryNode",table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)}}transformColumnUpdate(e,t){return{kind:"ColumnUpdateNode",column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)}}transformLimit(e,t){return{kind:"LimitNode",limit:this.transformNode(e.limit,t)}}transformOffset(e,t){return{kind:"OffsetNode",offset:this.transformNode(e.offset,t)}}transformOnConflict(e,t){return{kind:"OnConflictNode",columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing}}transformOnDuplicateKey(e,t){return{kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,t)}}transformCreateIndex(e,t){return{kind:"CreateIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct}}transformList(e,t){return{kind:"ListNode",items:this.transformNodeList(e.items,t)}}transformDropIndex(e,t){return{kind:"DropIndexNode",name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e,t){return{kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformUniqueConstraint(e,t){return{kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformForeignKeyConstraint(e,t){return{kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformSetOperation(e,t){return{kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all}}transformReferences(e,t){return{kind:"ReferencesNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e,t){return{kind:"CheckConstraintNode",expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)}}transformWith(e,t){return{kind:"WithNode",expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive}}transformCommonTableExpression(e,t){return{kind:"CommonTableExpressionNode",name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)}}transformCommonTableExpressionName(e,t){return{kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)}}transformHaving(e,t){return{kind:"HavingNode",having:this.transformNode(e.having,t)}}transformCreateSchema(e,t){return{kind:"CreateSchemaNode",schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists}}transformDropSchema(e,t){return{kind:"DropSchemaNode",schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e,t){return{kind:"AlterTableNode",table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)}}transformDropColumn(e,t){return{kind:"DropColumnNode",column:this.transformNode(e.column,t)}}transformRenameColumn(e,t){return{kind:"RenameColumnNode",column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)}}transformAlterColumn(e,t){return{kind:"AlterColumnNode",column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull}}transformModifyColumn(e,t){return{kind:"ModifyColumnNode",column:this.transformNode(e.column,t)}}transformAddConstraint(e,t){return{kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,t)}}transformDropConstraint(e,t){return{kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier}}transformRenameConstraint(e,t){return{kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)}}transformCreateView(e,t){return{kind:"CreateViewNode",name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)}}transformRefreshMaterializedView(e,t){return{kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData}}transformDropView(e,t){return{kind:"DropViewNode",name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e,t){return{kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)}}transformDefaultValue(e,t){return{kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,t)}}transformOn(e,t){return{kind:"OnNode",on:this.transformNode(e.on,t)}}transformSelectModifier(e,t){return{kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)}}transformCreateType(e,t){return{kind:"CreateTypeNode",name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)}}transformDropType(e,t){return{kind:"DropTypeNode",name:this.transformNode(e.name,t),ifExists:e.ifExists}}transformExplain(e,t){return{kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,t)}}transformSchemableIdentifier(e,t){return{kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)}}transformAggregateFunction(e,t){return{kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)}}transformOver(e,t){return{kind:"OverNode",orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)}}transformPartitionBy(e,t){return{kind:"PartitionByNode",items:this.transformNodeList(e.items,t)}}transformPartitionByItem(e,t){return{kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,t)}}transformBinaryOperation(e,t){return{kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)}}transformUnaryOperation(e,t){return{kind:"UnaryOperationNode",operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)}}transformUsing(e,t){return{kind:"UsingNode",tables:this.transformNodeList(e.tables,t)}}transformFunction(e,t){return{kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,t)}}transformCase(e,t){return{kind:"CaseNode",value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement}}transformWhen(e,t){return{kind:"WhenNode",condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)}}transformJSONReference(e,t){return{kind:"JSONReferenceNode",reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)}}transformJSONPath(e,t){return{kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)}}transformJSONPathLeg(e,t){return{kind:"JSONPathLegNode",type:e.type,value:e.value}}transformJSONOperatorChain(e,t){return{kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)}}transformTuple(e,t){return{kind:"TupleNode",values:this.transformNodeList(e.values,t)}}transformMergeQuery(e,t){return{kind:"MergeQueryNode",into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)}}transformMatched(e,t){return{kind:"MatchedNode",not:e.not,bySource:e.bySource}}transformAddIndex(e,t){return{kind:"AddIndexNode",name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists}}transformCast(e,t){return{kind:"CastNode",expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)}}transformFetch(e,t){return{kind:"FetchNode",rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier}}transformTop(e,t){return{kind:"TopNode",expression:e.expression,modifiers:e.modifiers}}transformOutput(e,t){return{kind:"OutputNode",selections:this.transformNodeList(e.selections,t)}}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}};var Gn=o({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),jn={json_agg:!0,to_json:!0},rt=class extends Se{#e;#r=new Set;#t=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!this.#o(e))return super.transformNodeImpl(e,t);let n=this.#d(e);for(let c of n)this.#t.add(c);let s=this.#a(e);for(let c of s)this.#r.add(c);let u=super.transformNodeImpl(e,t);for(let c of s)this.#r.delete(c);for(let c of n)this.#t.delete(c);return u}transformSchemableIdentifier(e,t){let n=super.transformSchemableIdentifier(e,t);return n.schema||!this.#r.has(e.identifier.name)?n:{...n,schema:d.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:J.createWithSchema(this.#e,n.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#i(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#i(e,t,"arguments")}}#i(e,t,n){return jn[e.func]?e[n].map(s=>!J.is(s)||s.table.schema?this.transformNode(s,t):{...s,table:this.transformIdentifier(s.table.identifier,t)}):this.transformNodeList(e[n],t)}#o(e){return e.kind in Gn}#a(e){let t=new Set;if("name"in e&&e.name&&Q.is(e.name)&&this.#s(e.name,t),"from"in e&&e.from)for(let n of e.from.froms)this.#n(n,t);if("into"in e&&e.into&&this.#n(e.into,t),"table"in e&&e.table&&this.#n(e.table,t),"joins"in e&&e.joins)for(let n of e.joins)this.#n(n.table,t);return"using"in e&&e.using&&this.#n(e.using,t),t}#d(e){let t=new Set;return"with"in e&&e.with&&this.#u(e.with,t),t}#n(e,t){if(J.is(e))this.#s(e.table,t);else if(P.is(e)&&J.is(e.node))this.#s(e.node.table,t);else if(Jr.is(e))for(let n of e.items)this.#n(n,t)}#s(e,t){let n=e.identifier.name;!this.#r.has(n)&&!this.#t.has(n)&&t.add(n)}#u(e,t){for(let n of e.expressions){let s=n.name.table.table.identifier.name;this.#t.has(s)||t.add(s)}}};var H=class{#e;constructor(e){this.#e=new rt(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var dn=o({is(r){return r.kind==="MatchedNode"},create(r,e=!1){return o({kind:"MatchedNode",not:r,bySource:e})}});function no(r,e,t){return Ne.create(Je([dn.create(!r.isMatched,r.bySource),...e&&e.length>0?[e.length===3&&t?T(e[0],e[1],e[2]):N(e)]:[]],"and",!1))}function He(r){return W(r)?v.create([r],[]):g(r)?r.toOperationNode():r}var kr=class{#e;#r;#t;constructor(){this.#e=new Promise((e,t)=>{this.#t=t,this.#r=e})}get promise(){return this.#e}resolve=e=>{this.#r&&this.#r(e)};reject=e=>{this.#t&&this.#t(e)}};async function tt(r){let e=new kr,t=new kr;return r.provideConnection(async n=>(e.resolve(n),await t.promise)).catch(n=>e.reject(n)),o({connection:await e.promise,release:t.resolve})}var Hn=o([]),Ye=class{#e;constructor(e=Hn){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let n of this.#e){let s=n.transformQuery({node:e,queryId:t});if(s.kind===e.kind)e=s;else throw new Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${e.kind}`,`but it returned a ${s.kind}`].join(" "))}return e}async executeQuery(e,t){return await this.provideConnection(async n=>{let s=await n.executeQuery(e);return"numUpdatedOrDeletedRows"in s&&ze("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#r(s,t)})}async*stream(e,t,n){let{connection:s,release:u}=await tt(this);try{for await(let c of s.streamQuery(e,t))yield await this.#r(c,n)}finally{u()}}async#r(e,t){for(let n of this.#e)e=await n.transformResult({result:e,queryId:t});return e}};var io=class r extends Ye{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new r([...this.plugins,e])}withPlugins(e){return new r([...this.plugins,...e])}withPluginAtFront(e){return new r([e,...this.plugins])}withoutPlugins(){return new r([])}},Xe=new io;var ot=class{numChangedRows;constructor(e){this.numChangedRows=e}};var nt=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}using(...e){return new Ee({...this.#e,queryNode:K.cloneWithUsing(this.#e.queryNode,Te("Using",e))})}returning(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,S(e))})}output(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,S(e))})}},Ee=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,t,n){return this.#r([e,t,n],!0)}#r(e,t){return new it({...this.#e,queryNode:K.cloneWithWhen(this.#e.queryNode,no({isMatched:!0},e,t))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,t,n){return this.#t([e,t,n],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,n){return this.#t([e,t,n],!0,!0)}returning(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,k(e))})}returningAll(e){return new r({...this.#e,queryNode:a.cloneWithReturning(this.#e.queryNode,S(e))})}output(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,k(e))})}outputAll(e){return new r({...this.#e,queryNode:a.cloneWithOutput(this.#e.queryNode,S(e))})}#t(e,t=!1,n=!1){let s={...this.#e,queryNode:K.cloneWithWhen(this.#e.queryNode,no({isMatched:!1,bySource:n},e,t))},u=n?it:so;return new u(s)}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e,this.#e.queryId),{adapter:n}=this.#e.executor,s=e.query;return s.returning&&n.supportsReturning||s.output&&n.supportsOutput?t.rows:[new ot(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let t=await this.executeTakeFirst();if(t===void 0)throw de(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}},it=class{#e;constructor(e){this.#e=o(e)}thenDelete(){return new Ee({...this.#e,queryNode:K.cloneWithThen(this.#e.queryNode,He("delete"))})}thenDoNothing(){return new Ee({...this.#e,queryNode:K.cloneWithThen(this.#e.queryNode,He("do nothing"))})}thenUpdate(e){return new Ee({...this.#e,queryNode:K.cloneWithThen(this.#e.queryNode,He(e(new Ge({queryId:this.#e.queryId,executor:Xe,queryNode:ue.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},so=class{#e;constructor(e){this.#e=o(e)}thenDoNothing(){return new Ee({...this.#e,queryNode:K.cloneWithThen(this.#e.queryNode,He("do nothing"))})}thenInsertValues(e){let[t,n]=jr(e);return new Ee({...this.#e,queryNode:K.cloneWithThen(this.#e.queryNode,He(C.cloneWith(C.createWithoutInto(),{columns:t,values:n})))})}};var Ze=class r{#e;constructor(e){this.#e=o(e)}selectFrom(e){return Tr({queryId:x(),executor:this.#e.executor,queryNode:f.createFrom(oe(e),this.#e.withNode)})}selectNoFrom(e){return Tr({queryId:x(),executor:this.#e.executor,queryNode:f.cloneWithSelections(f.create(this.#e.withNode),k(e))})}insertInto(e){return new Cr({queryId:x(),executor:this.#e.executor,queryNode:C.create(l(e),this.#e.withNode)})}replaceInto(e){return new Cr({queryId:x(),executor:this.#e.executor,queryNode:C.create(l(e),this.#e.withNode,!0)})}deleteFrom(e){return new Zr({queryId:x(),executor:this.#e.executor,queryNode:ke.create(oe(e),this.#e.withNode)})}updateTable(e){return new Ge({queryId:x(),executor:this.#e.executor,queryNode:ue.create(oe(e),this.#e.withNode)})}mergeInto(e){return new nt({queryId:x(),executor:this.#e.executor,queryNode:K.create(ao(e),this.#e.withNode)})}with(e,t){let n=to(e,t);return new r({...this.#e,withNode:this.#e.withNode?br.cloneWithExpression(this.#e.withNode,n):br.create(n)})}withRecursive(e,t){let n=to(e,t);return new r({...this.#e,withNode:this.#e.withNode?br.cloneWithExpression(this.#e.withNode,n):br.create(n,{recursive:!0})})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new H(e))})}};function sn(){return new Ze({executor:Xe})}function cn(r,e){return new $r({joinNode:he.create(r,Ie(e))})}function mn(){return new Kr({overNode:Wr.create()})}function Te(r,e){if(e.length===3)return Xn(r,e[0],e[1],e[2]);if(e.length===2)return Yn(r,e[0],e[1]);if(e.length===1)return Zn(r,e[0]);throw new Error("not implemented")}function Yn(r,e,t){return t(cn(r,e)).toOperationNode()}function Xn(r,e,t,n){return he.createWithOn(r,Ie(e),T(t,"=",n))}function Zn(r,e){return he.create(r,Ie(e))}var hn=o({is(r){return r.kind==="OffsetNode"},create(r){return o({kind:"OffsetNode",offset:r})}});var ln=o({is(r){return r.kind==="GroupByItemNode"},create(r){return o({kind:"GroupByItemNode",groupBy:r})}});function pn(r){return r=O(r)?r(re()):r,pe(r).map(ln.create)}var fn=o({is(r){return r.kind==="SetOperationNode"},create(r,e,t){return o({kind:"SetOperationNode",operator:r,expression:e,all:t})}});function Be(r,e,t){return O(e)&&(e=e(st())),D(e)||(e=[e]),e.map(n=>fn.create(r,V(n),t))}var p=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Sr(this,e)}or(...e){return new uo(X.create(this.#e,N(e)))}and(...e){return new co(z.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},Sr=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return P.create(this.#e.toOperationNode(),g(this.#r)?this.#r.toOperationNode():d.create(this.#r))}},uo=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Sr(this,e)}or(...e){return new r(X.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return be.create(this.#e)}},co=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Sr(this,e)}and(...e){return new r(z.create(this.#e,N(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return be.create(this.#e)}};var Nn={is(r){return r.kind==="FetchNode"},create(r,e){return{kind:"FetchNode",rowCount:b.create(r),modifier:e}}};function yn(r,e){if(!Le(r)&&!Br(r))throw new Error(`Invalid fetch row count: ${r}`);if(!_n(e))throw new Error(`Invalid fetch modifier: ${e}`);return Nn.create(r,e)}function _n(r){return r==="only"||r==="with ties"}var mo=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,N(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:a.cloneWithWhere(this.#e.queryNode,T(e,t,n))})}having(...e){return new r({...this.#e,queryNode:f.cloneWithHaving(this.#e.queryNode,N(e))})}havingRef(e,t,n){return new r({...this.#e,queryNode:f.cloneWithHaving(this.#e.queryNode,T(e,t,n))})}select(e){return new r({...this.#e,queryNode:f.cloneWithSelections(this.#e.queryNode,k(e))})}distinctOn(e){return new r({...this.#e,queryNode:f.cloneWithDistinctOn(this.#e.queryNode,pe(e))})}modifyFront(e){return new r({...this.#e,queryNode:f.cloneWithFrontModifier(this.#e.queryNode,se.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.createWithExpression(e.toOperationNode()))})}distinct(){return new r({...this.#e,queryNode:f.cloneWithFrontModifier(this.#e.queryNode,se.create("Distinct"))})}forUpdate(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("ForUpdate",e?yr(e).map(l):void 0))})}forShare(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("ForShare",e?yr(e).map(l):void 0))})}forKeyShare(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("ForKeyShare",e?yr(e).map(l):void 0))})}forNoKeyUpdate(e){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("ForNoKeyUpdate",e?yr(e).map(l):void 0))})}skipLocked(){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("SkipLocked"))})}noWait(){return new r({...this.#e,queryNode:a.cloneWithEndModifier(this.#e.queryNode,se.create("NoWait"))})}selectAll(e){return new r({...this.#e,queryNode:f.cloneWithSelections(this.#e.queryNode,S(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}crossJoin(...e){return this.#r("CrossJoin",e)}innerJoinLateral(...e){return this.#r("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#r("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#r("LateralCrossJoin",e)}crossApply(...e){return this.#r("CrossApply",e)}outerApply(...e){return this.#r("OuterApply",e)}#r(e,t){return new r({...this.#e,queryNode:a.cloneWithJoin(this.#e.queryNode,Te(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:a.cloneWithOrderByItems(this.#e.queryNode,$(e))})}groupBy(e){return new r({...this.#e,queryNode:f.cloneWithGroupByItems(this.#e.queryNode,pn(e))})}limit(e){return new r({...this.#e,queryNode:f.cloneWithLimit(this.#e.queryNode,Ke.create(w(e)))})}offset(e){return new r({...this.#e,queryNode:f.cloneWithOffset(this.#e.queryNode,hn.create(w(e)))})}fetch(e,t="only"){return new r({...this.#e,queryNode:f.cloneWithFetch(this.#e.queryNode,yn(e,t))})}top(e,t){return new r({...this.#e,queryNode:a.cloneWithTop(this.#e.queryNode,te(e,t))})}union(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("union",e,!1))})}unionAll(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("union",e,!0))})}intersect(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("intersect",e,!1))})}intersectAll(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("intersect",e,!0))})}except(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("except",e,!1))})}exceptAll(e){return new r({...this.#e,queryNode:f.cloneWithSetOperations(this.#e.queryNode,Be("except",e,!0))})}as(e){return new ho(this,e)}clearSelect(){return new r({...this.#e,queryNode:f.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new r({...this.#e,queryNode:a.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:f.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new r({...this.#e,queryNode:f.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new r({...this.#e,queryNode:a.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new r({...this.#e,queryNode:f.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}$asTuple(){return new p(this.toOperationNode())}$asScalar(){return new p(this.toOperationNode())}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e,this.#e.queryId)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=j){let t=await this.executeTakeFirst();if(t===void 0)throw de(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e,this.#e.queryId);for await(let s of n)yield*s.rows}async explain(e,t){return await new r({...this.#e,queryNode:a.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};function Tr(r){return new mo(r)}var ho=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return P.create(this.#e.toOperationNode(),d.create(this.#r))}};var ce=o({is(r){return r.kind==="AggregateFunctionNode"},create(r,e=[]){return o({kind:"AggregateFunctionNode",func:r,aggregated:e})},cloneWithDistinct(r){return o({...r,distinct:!0})},cloneWithOrderBy(r,e,t=!1){let n=t?"withinGroup":"orderBy";return o({...r,[n]:r[n]?fe.cloneWithItems(r[n],e):fe.create(e)})},cloneWithFilter(r,e){return o({...r,filter:r.filter?q.cloneWithOperation(r.filter,"And",e):q.create(e)})},cloneWithOrFilter(r,e){return o({...r,filter:r.filter?q.cloneWithOperation(r.filter,"Or",e):q.create(e)})},cloneWithOver(r,e){return o({...r,over:e})}});var lo=o({is(r){return r.kind==="FunctionNode"},create(r,e){return o({kind:"FunctionNode",func:r,arguments:e})}});var _e=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}as(e){return new po(this,e)}distinct(){return new r({...this.#e,aggregateFunctionNode:ce.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new r({...this.#e,aggregateFunctionNode:a.cloneWithOrderByItems(this.#e.aggregateFunctionNode,$(e))})}clearOrderBy(){return new r({...this.#e,aggregateFunctionNode:a.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new r({...this.#e,aggregateFunctionNode:ce.cloneWithOrderBy(this.#e.aggregateFunctionNode,$(e),!0)})}filterWhere(...e){return new r({...this.#e,aggregateFunctionNode:ce.cloneWithFilter(this.#e.aggregateFunctionNode,N(e))})}filterWhereRef(e,t,n){return new r({...this.#e,aggregateFunctionNode:ce.cloneWithFilter(this.#e.aggregateFunctionNode,T(e,t,n))})}over(e){let t=mn();return new r({...this.#e,aggregateFunctionNode:ce.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}},po=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return P.create(this.#e.toOperationNode(),d.create(this.#r))}};function at(){let r=(t,n)=>new p(lo.create(t,pe(n??[]))),e=(t,n)=>new _e({aggregateFunctionNode:ce.create(t,n?pe(n):void 0)});return Object.assign(r,{agg:e,avg(t){return e("avg",[t])},coalesce(...t){return r("coalesce",t)},count(t){return e("count",[t])},countAll(t){return new _e({aggregateFunctionNode:ce.create("count",S(t))})},max(t){return e("max",[t])},min(t){return e("min",[t])},sum(t){return e("sum",[t])},any(t){return r("any",[t])},jsonAgg(t){return new _e({aggregateFunctionNode:ce.create("json_agg",[W(t)?l(t):t.toOperationNode()])})},toJson(t){return new p(lo.create("to_json",[W(t)?l(t):t.toOperationNode()]))}})}var wn=o({is(r){return r.kind==="UnaryOperationNode"},create(r,e){return o({kind:"UnaryOperationNode",operator:r,operand:e})}});function xn(r,e){return wn.create(Z.create(r),R(e))}var G=o({is(r){return r.kind==="CaseNode"},create(r){return o({kind:"CaseNode",value:r})},cloneWithWhen(r,e){return o({...r,when:o(r.when?[...r.when,e]:[e])})},cloneWithThen(r,e){return o({...r,when:r.when?o([...r.when.slice(0,-1),Ne.cloneWithResult(r.when[r.when.length-1],e)]):void 0})},cloneWith(r,e){return o({...r,...e})}});var er=class{#e;constructor(e){this.#e=o(e)}when(...e){return new ut({...this.#e,node:G.cloneWithWhen(this.#e.node,Ne.create(N(e)))})}},ut=class{#e;constructor(e){this.#e=o(e)}then(e){return new fo({...this.#e,node:G.cloneWithThen(this.#e.node,Vr(e)?Or(e):w(e))})}},fo=class{#e;constructor(e){this.#e=o(e)}when(...e){return new ut({...this.#e,node:G.cloneWithWhen(this.#e.node,Ne.create(N(e)))})}else(e){return new No({...this.#e,node:G.cloneWith(this.#e.node,{else:Vr(e)?Or(e):w(e)})})}end(){return new p(G.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(G.cloneWith(this.#e.node,{isStatement:!0}))}},No=class{#e;constructor(e){this.#e=o(e)}end(){return new p(G.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new p(G.cloneWith(this.#e.node,{isStatement:!0}))}};var yo=o({is(r){return r.kind==="JSONPathLegNode"},create(r,e){return o({kind:"JSONPathLegNode",type:r,value:e})}});var rr=class{#e;constructor(e){this.#e=e}at(e){return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,t){return Ve.is(this.#e)?new dt(Ve.cloneWithTraversal(this.#e,Ce.is(this.#e.traversal)?Ce.cloneWithLeg(this.#e.traversal,yo.create(e,t)):Mr.cloneWithValue(this.#e.traversal,b.createImmediate(t)))):new dt(Ce.cloneWithLeg(this.#e,yo.create(e,t)))}},dt=class r extends rr{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new wo(this,e)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},wo=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return P.create(this.#e.toOperationNode(),g(this.#r)?this.#r.toOperationNode():d.create(this.#r))}};var xo=o({is(r){return r.kind==="TupleNode"},create(r){return o({kind:"TupleNode",values:o(r)})}});var ei=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],ri=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],On=o({is(r){return r.kind==="DataTypeNode"},create(r){return o({kind:"DataTypeNode",dataType:r})}});function Wn(r){return!!(ei.includes(r)||ri.some(e=>e.test(r)))}function ne(r){if(g(r))return r.toOperationNode();if(Wn(r))return On.create(r);throw new Error(`invalid column data type ${JSON.stringify(r)}`)}var gn=o({is(r){return r.kind==="CastNode"},create(r,e){return o({kind:"CastNode",expression:r,dataType:e})}});function st(r=Xe){function e(s,u,c){return new p(Ur(s,u,c))}function t(s,u){return new p(xn(s,u))}let n=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(s){return Tr({queryId:x(),executor:r,queryNode:f.createFrom(oe(s))})},case(s){return new er({node:G.create(U(s)?void 0:R(s))})},ref(s,u){return U(u)?new p(ee(s)):new rr(Uo(s,u))},jsonPath(){return new rr(Ce.create())},table(s){return new p(l(s))},val(s){return new p(w(s))},refTuple(...s){return new p(xo.create(s.map(R)))},tuple(...s){return new p(xo.create(s.map(w)))},lit(s){return new p(Or(s))},unary:t,not(s){return t("not",s)},exists(s){return t("exists",s)},neg(s){return t("-",s)},between(s,u,c){return new p(ge.create(R(s),Z.create("between"),z.create(w(u),w(c))))},betweenSymmetric(s,u,c){return new p(ge.create(R(s),Z.create("between symmetric"),z.create(w(u),w(c))))},and(s){return D(s)?new p(Je(s,"and")):new p($t(s,"and"))},or(s){return D(s)?new p(Je(s,"or")):new p($t(s,"or"))},parens(...s){let u=N(s);return be.is(u)?new p(u):new p(be.create(u))},cast(s,u){return new p(gn.create(R(s),ne(u)))},withSchema(s){return st(r.withPluginAtFront(new H(s)))}});return n.fn=at(),n.eb=n,n}function re(r){return st()}function V(r){if(g(r))return r.toOperationNode();if(O(r))return r(re()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(r)}`)}function Gr(r){if(g(r))return r.toOperationNode();if(O(r))return r(re()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(r)}`)}function le(r){return Qr(r)||vo(r)||O(r)}var ct=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Oo(this.#e,e)}},Oo=class{#e;#r;get table(){return this.#e}get alias(){return this.#r}constructor(e,t){this.#e=e,this.#r=t}toOperationNode(){return P.create(l(this.#e),d.create(this.#r))}};function Cn(r){return A(r)&&g(r)&&W(r.table)&&W(r.alias)}function oe(r){return D(r)?r.map(e=>Ie(e)):[Ie(r)]}function Ie(r){return W(r)?ao(r):Cn(r)?r.toOperationNode():Gr(r)}function ao(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map(bn);return P.create(l(t),d.create(n))}else return l(r)}function l(r){let e=".";if(r.includes(e)){let[t,n]=r.split(e).map(bn);return J.createWithSchema(t,n)}else return J.create(r)}function bn(r){return r.trim()}var Wo=o({is(r){return r.kind==="AddColumnNode"},create(r){return o({kind:"AddColumnNode",column:r})}});var y=o({is(r){return r.kind==="ColumnDefinitionNode"},create(r,e){return o({kind:"ColumnDefinitionNode",column:m.create(r),dataType:e})},cloneWithFrontModifier(r,e){return o({...r,frontModifiers:r.frontModifiers?o([...r.frontModifiers,e]):[e]})},cloneWithEndModifier(r,e){return o({...r,endModifiers:r.endModifiers?o([...r.endModifiers,e]):[e]})},cloneWith(r,e){return o({...r,...e})}});var go=o({is(r){return r.kind==="DropColumnNode"},create(r){return o({kind:"DropColumnNode",column:m.create(r)})}});var Co=o({is(r){return r.kind==="RenameColumnNode"},create(r,e){return o({kind:"RenameColumnNode",column:m.create(r),renameTo:m.create(e)})}});var tr=o({is(r){return r.kind==="CheckConstraintNode"},create(r,e){return o({kind:"CheckConstraintNode",expression:r,name:e?d.create(e):void 0})}});var kn=["no action","restrict","cascade","set null","set default"],or=o({is(r){return r.kind==="ReferencesNode"},create(r,e){return o({kind:"ReferencesNode",table:r,columns:o([...e])})},cloneWithOnDelete(r,e){return o({...r,onDelete:e})},cloneWithOnUpdate(r,e){return o({...r,onUpdate:e})}});function mt(r){return g(r)?r.toOperationNode():b.createImmediate(r)}var Er=o({is(r){return r.kind==="GeneratedNode"},create(r){return o({kind:"GeneratedNode",...r})},createWithExpression(r){return o({kind:"GeneratedNode",always:!0,expression:r})},cloneWith(r,e){return o({...r,...e})}});var Tn=o({is(r){return r.kind==="DefaultValueNode"},create(r){return o({kind:"DefaultValueNode",defaultValue:r})}});function nr(r){if(kn.includes(r))return r;throw new Error(`invalid OnModifyForeignAction ${r}`)}var ye=class r{#e;constructor(e){this.#e=e}autoIncrement(){return new r(y.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new r(y.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new r(y.cloneWith(this.#e,{primaryKey:!0}))}references(e){let t=ee(e);if(!t.table||Fe.is(t.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new r(y.cloneWith(this.#e,{references:or.create(t.table,[t.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new r(y.cloneWith(this.#e,{references:or.cloneWithOnDelete(this.#e.references,nr(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new r(y.cloneWith(this.#e,{references:or.cloneWithOnUpdate(this.#e.references,nr(e))}))}unique(){return new r(y.cloneWith(this.#e,{unique:!0}))}notNull(){return new r(y.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new r(y.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new r(y.cloneWith(this.#e,{defaultTo:Tn.create(mt(e))}))}check(e){return new r(y.cloneWith(this.#e,{check:tr.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new r(y.cloneWith(this.#e,{generated:Er.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new r(y.cloneWith(this.#e,{generated:Er.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new r(y.cloneWith(this.#e,{generated:Er.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new r(y.cloneWith(this.#e,{generated:Er.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new r(y.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new r(y.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new r(y.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new r(y.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};var bo=o({is(r){return r.kind==="ModifyColumnNode"},create(r){return o({kind:"ModifyColumnNode",column:r})}});var ie=o({is(r){return r.kind==="ForeignKeyConstraintNode"},create(r,e,t,n){return o({kind:"ForeignKeyConstraintNode",columns:r,references:or.create(e,t),name:n?d.create(n):void 0})},cloneWith(r,e){return o({...r,...e})}});var ir=class r{#e;constructor(e){this.#e=e}onDelete(e){return new r(ie.cloneWith(this.#e,{onDelete:nr(e)}))}onUpdate(e){return new r(ie.cloneWith(this.#e,{onUpdate:nr(e)}))}deferrable(){return new r(ie.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new r(ie.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new r(ie.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new r(ie.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var sr=o({is(r){return r.kind==="AddConstraintNode"},create(r){return o({kind:"AddConstraintNode",constraint:r})}});var me=o({is(r){return r.kind==="UniqueConstraintNode"},create(r,e,t){return o({kind:"UniqueConstraintNode",columns:o(r.map(m.create)),name:e?d.create(e):void 0,nullsNotDistinct:t})},cloneWith(r,e){return o({...r,...e})}});var ar=o({is(r){return r.kind==="DropConstraintNode"},create(r){return o({kind:"DropConstraintNode",constraintName:d.create(r)})},cloneWith(r,e){return o({...r,...e})}});var ur=o({is(r){return r.kind==="AlterColumnNode"},create(r,e,t){return o({kind:"AlterColumnNode",column:m.create(r),[e]:t})}});var Ar=class{#e;constructor(e){this.#e=e}setDataType(e){return new De(ur.create(this.#e,"dataType",ne(e)))}setDefault(e){return new De(ur.create(this.#e,"setDefault",mt(e)))}dropDefault(){return new De(ur.create(this.#e,"dropDefault",!0))}setNotNull(){return new De(ur.create(this.#e,"setNotNull",!0))}dropNotNull(){return new De(ur.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}},De=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};var we=class{#e;constructor(e){this.#e=o(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var ht=class r{#e;constructor(e){this.#e=o(e)}onDelete(e){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new r({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(h.cloneWithTableProps(this.#e.node,{addConstraint:sr.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Rr=class r{#e;constructor(e){this.#e=o(e)}ifExists(){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{dropConstraint:ar.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{dropConstraint:ar.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{dropConstraint:ar.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var xe=o({is(r){return r.kind==="PrimaryKeyConstraintNode"},create(r,e){return o({kind:"PrimaryKeyConstraintNode",columns:o(r.map(m.create)),name:e?d.create(e):void 0})},cloneWith(r,e){return o({...r,...e})}});var Ae=o({is(r){return r.kind==="AddIndexNode"},create(r){return o({kind:"AddIndexNode",name:d.create(r)})},cloneWith(r,e){return o({...r,...e})},cloneWithColumns(r,e){return o({...r,columns:[...r.columns||[],...e]})}});var lt=class r{#e;constructor(e){this.#e=o(e)}unique(){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.cloneWithColumns(this.#e.node.addIndex,[Ue(e)])})})}columns(e){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.cloneWithColumns(this.#e.node.addIndex,e.map(Ue))})})}expression(e){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new r({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.cloneWith(this.#e.node.addIndex,{using:v.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var dr=class r{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new r(me.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new r(me.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new r(me.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new r(me.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new r(me.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var cr=class r{#e;constructor(e){this.#e=e}deferrable(){return new r(xe.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new r(xe.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new r(xe.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new r(xe.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var mr=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};var Sn=o({is(r){return r.kind==="RenameConstraintNode"},create(r,e){return o({kind:"RenameConstraintNode",oldName:d.create(r),newName:d.create(e)})}});var pt=class{#e;constructor(e){this.#e=o(e)}renameTo(e){return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{renameTo:l(e)})})}setSchema(e){return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{setSchema:d.create(e)})})}alterColumn(e,t){let n=t(new Ar(e));return new Qe({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e){return new Qe({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,go.create(e))})}renameColumn(e,t){return new Qe({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,Co.create(e,t))})}addColumn(e,t,n=L){let s=n(new ye(y.create(e,ne(t))));return new Qe({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,Wo.create(s.toOperationNode()))})}modifyColumn(e,t,n=L){let s=n(new ye(y.create(e,ne(t))));return new Qe({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,bo.create(s.toOperationNode()))})}addUniqueConstraint(e,t,n=L){let s=n(new dr(me.create(t,e)));return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addConstraint:sr.create(s.toOperationNode())})})}addCheckConstraint(e,t,n=L){let s=n(new mr(tr.create(t.toOperationNode(),e)));return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addConstraint:sr.create(s.toOperationNode())})})}addForeignKeyConstraint(e,t,n,s,u=L){let c=u(new ir(ie.create(t.map(m.create),l(n),s.map(m.create),e)));return new ht({...this.#e,constraintBuilder:c})}addPrimaryKeyConstraint(e,t,n=L){let s=n(new cr(xe.create(t,e)));return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addConstraint:sr.create(s.toOperationNode())})})}dropConstraint(e){return new Rr({...this.#e,node:h.cloneWithTableProps(this.#e.node,{dropConstraint:ar.create(e)})})}renameConstraint(e,t){return new Rr({...this.#e,node:h.cloneWithTableProps(this.#e.node,{renameConstraint:Sn.create(e,t)})})}addIndex(e){return new lt({...this.#e,node:h.cloneWithTableProps(this.#e.node,{addIndex:Ae.create(e)})})}dropIndex(e){return new we({...this.#e,node:h.cloneWithTableProps(this.#e.node,{dropIndex:We.create(e)})})}$call(e){return e(this)}},Qe=class r{#e;constructor(e){this.#e=o(e)}alterColumn(e,t){let n=t(new Ar(e));return new r({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e){return new r({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,go.create(e))})}renameColumn(e,t){return new r({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,Co.create(e,t))})}addColumn(e,t,n=L){let s=n(new ye(y.create(e,ne(t))));return new r({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,Wo.create(s.toOperationNode()))})}modifyColumn(e,t,n=L){let s=n(new ye(y.create(e,ne(t))));return new r({...this.#e,node:h.cloneWithColumnAlteration(this.#e.node,bo.create(s.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var hr=class extends Se{transformPrimitiveValueList(e){return ae.create(e.values.map(b.createImmediate))}transformValue(e){return b.createImmediate(e.value)}};var ft=class r{#e;constructor(e){this.#e=o(e)}ifNotExists(){return new r({...this.#e,node:Y.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new r({...this.#e,node:Y.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new r({...this.#e,node:Y.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new r({...this.#e,node:Y.cloneWith(this.#e.node,{table:l(e)})})}column(e){return new r({...this.#e,node:Y.cloneWithColumns(this.#e.node,[Ue(e)])})}columns(e){return new r({...this.#e,node:Y.cloneWithColumns(this.#e.node,e.map(Ue))})}expression(e){return new r({...this.#e,node:Y.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new r({...this.#e,node:Y.cloneWith(this.#e.node,{using:v.createWithSql(e)})})}where(...e){let t=new hr;return new r({...this.#e,node:a.cloneWithWhere(this.#e.node,t.transformNode(N(e),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Nt=class r{#e;constructor(e){this.#e=o(e)}ifNotExists(){return new r({...this.#e,node:Dr.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function En(r){if(Po.includes(r))return r;throw new Error(`invalid OnCommitAction ${r}`)}var yt=class r{#e;constructor(e){this.#e=o(e)}temporary(){return new r({...this.#e,node:M.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new r({...this.#e,node:M.cloneWith(this.#e.node,{onCommit:En(e)})})}ifNotExists(){return new r({...this.#e,node:M.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,n=L){let s=n(new ye(y.create(e,ne(t))));return new r({...this.#e,node:M.cloneWithColumn(this.#e.node,s.toOperationNode())})}addPrimaryKeyConstraint(e,t,n=L){let s=n(new cr(xe.create(t,e)));return new r({...this.#e,node:M.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addUniqueConstraint(e,t,n=L){let s=n(new dr(me.create(t,e)));return new r({...this.#e,node:M.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addCheckConstraint(e,t,n=L){let s=n(new mr(tr.create(t.toOperationNode(),e)));return new r({...this.#e,node:M.cloneWithConstraint(this.#e.node,s.toOperationNode())})}addForeignKeyConstraint(e,t,n,s,u=L){let c=u(new ir(ie.create(t.map(m.create),l(n),s.map(m.create),e)));return new r({...this.#e,node:M.cloneWithConstraint(this.#e.node,c.toOperationNode())})}modifyFront(e){return new r({...this.#e,node:M.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new r({...this.#e,node:M.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new r({...this.#e,node:M.cloneWith(this.#e.node,{selectQuery:V(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var wt=class r{#e;constructor(e){this.#e=o(e)}on(e){return new r({...this.#e,node:We.cloneWith(this.#e.node,{table:l(e)})})}ifExists(){return new r({...this.#e,node:We.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:We.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var xt=class r{#e;constructor(e){this.#e=o(e)}ifExists(){return new r({...this.#e,node:wr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:wr.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Ot=class r{#e;constructor(e){this.#e=o(e)}ifExists(){return new r({...this.#e,node:xr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:xr.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Oe=o({is(r){return r.kind==="CreateViewNode"},create(r){return o({kind:"CreateViewNode",name:Q.create(r)})},cloneWith(r,e){return o({...r,...e})}});var Wt=class{#e=new hr;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}};var gt=class r{#e;constructor(e){this.#e=o(e)}temporary(){return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{columns:e.map(Vt)})})}as(e){let t=e.withPlugin(new Wt).toOperationNode();return new r({...this.#e,node:Oe.cloneWith(this.#e.node,{as:t})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var lr=o({is(r){return r.kind==="DropViewNode"},create(r){return o({kind:"DropViewNode",name:Q.create(r)})},cloneWith(r,e){return o({...r,...e})}});var Ct=class r{#e;constructor(e){this.#e=o(e)}materialized(){return new r({...this.#e,node:lr.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new r({...this.#e,node:lr.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new r({...this.#e,node:lr.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var bt=o({is(r){return r.kind==="CreateTypeNode"},create(r){return o({kind:"CreateTypeNode",name:r})},cloneWithEnum(r,e){return o({...r,enum:ae.create(e.map(b.createImmediate))})}});var kt=class r{#e;constructor(e){this.#e=o(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new r({...this.#e,node:bt.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var Tt=o({is(r){return r.kind==="DropTypeNode"},create(r){return o({kind:"DropTypeNode",name:r})},cloneWith(r,e){return o({...r,...e})}});var St=class r{#e;constructor(e){this.#e=o(e)}ifExists(){return new r({...this.#e,node:Tt.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};function ko(r){let e=".";if(r.includes(e)){let t=r.split(e).map(ti);if(t.length===2)return Q.createWithSchema(t[0],t[1]);throw new Error(`invalid schemable identifier ${r}`)}else return Q.create(r)}function ti(r){return r.trim()}var pr=o({is(r){return r.kind==="RefreshMaterializedViewNode"},create(r){return o({kind:"RefreshMaterializedViewNode",name:Q.create(r)})},cloneWith(r,e){return o({...r,...e})}});var Et=class r{#e;constructor(e){this.#e=o(e)}concurrently(){return new r({...this.#e,node:pr.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new r({...this.#e,node:pr.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new r({...this.#e,node:pr.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile(),this.#e.queryId)}};var At=class r{#e;constructor(e){this.#e=e}createTable(e){return new yt({queryId:x(),executor:this.#e,node:M.create(l(e))})}dropTable(e){return new Ot({queryId:x(),executor:this.#e,node:xr.create(l(e))})}createIndex(e){return new ft({queryId:x(),executor:this.#e,node:Y.create(e)})}dropIndex(e){return new wt({queryId:x(),executor:this.#e,node:We.create(e)})}createSchema(e){return new Nt({queryId:x(),executor:this.#e,node:Dr.create(e)})}dropSchema(e){return new xt({queryId:x(),executor:this.#e,node:wr.create(e)})}alterTable(e){return new pt({queryId:x(),executor:this.#e,node:h.create(l(e))})}createView(e){return new gt({queryId:x(),executor:this.#e,node:Oe.create(e)})}refreshMaterializedView(e){return new Et({queryId:x(),executor:this.#e,node:pr.create(e)})}dropView(e){return new Ct({queryId:x(),executor:this.#e,node:lr.create(e)})}createType(e){return new kt({queryId:x(),executor:this.#e,node:bt.create(ko(e))})}dropType(e){return new St({queryId:x(),executor:this.#e,node:Tt.create(ko(e))})}withPlugin(e){return new r(this.#e.withPlugin(e))}withoutPlugins(){return new r(this.#e.withoutPlugins())}withSchema(e){return new r(this.#e.withPluginAtFront(new H(e)))}};var Rt=class{ref(e){return new vr(e)}table(e){return new ct(e)}};var qt=class{#e;constructor(e){this.#e=e}async provideConnection(e){let t=await this.#e.acquireConnection();try{return await e(t)}finally{await this.#e.releaseConnection(t)}}};var It=class r extends Ye{#e;#r;#t;constructor(e,t,n,s=[]){super(s),this.#e=e,this.#r=t,this.#t=n}get adapter(){return this.#r}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#t.provideConnection(e)}withPlugins(e){return new r(this.#e,this.#r,this.#t,[...this.plugins,...e])}withPlugin(e){return new r(this.#e,this.#r,this.#t,[...this.plugins,e])}withPluginAtFront(e){return new r(this.#e,this.#r,this.#t,[e,...this.plugins])}withConnectionProvider(e){return new r(this.#e,this.#r,e,[...this.plugins])}withoutPlugins(){return new r(this.#e,this.#r,this.#t,[])}};function Bt(){return typeof performance<"u"&&O(performance.now)?performance.now():Date.now()}var Dt=class{#e;#r;#t;#i;#o;#a=new WeakSet;constructor(e,t){this.#i=!1,this.#e=e,this.#r=t}async init(){if(this.#o)throw new Error("driver has already been destroyed");this.#t||(this.#t=this.#e.init().then(()=>{this.#i=!0}).catch(e=>(this.#t=void 0,Promise.reject(e)))),await this.#t}async acquireConnection(){if(this.#o)throw new Error("driver has already been destroyed");this.#i||await this.init();let e=await this.#e.acquireConnection();return this.#a.has(e)||(this.#d()&&this.#n(e),this.#a.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,t){return this.#e.beginTransaction(e,t)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,t,n){if(this.#e.savepoint)return this.#e.savepoint(e,t,n);throw new Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,t,n);throw new Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,t,n);throw new Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){this.#t&&(await this.#t,this.#o||(this.#o=this.#e.destroy().catch(e=>(this.#o=void 0,Promise.reject(e)))),await this.#o)}#d(){return this.#r.isLevelEnabled("query")||this.#r.isLevelEnabled("error")}#n(e){let t=e.executeQuery,n=e.streamQuery,s=this;e.executeQuery=async u=>{let c,E=Bt();try{return await t.call(e,u)}catch(I){throw c=I,await s.#s(I,u,E),I}finally{c||await s.#u(u,E)}},e.streamQuery=async function*(u,c){let E,I=Bt();try{for await(let B of n.call(e,u,c))yield B}catch(B){throw E=B,await s.#s(B,u,I),B}finally{E||await s.#u(u,I,!0)}}}async#s(e,t,n){await this.#r.error(()=>({level:"error",error:e,query:t,queryDurationMillis:this.#c(n)}))}async#u(e,t,n=!1){await this.#r.query(()=>({level:"query",isStream:n,query:e,queryDurationMillis:this.#c(t)}))}#c(e){return Bt()-e}};var oi=()=>{},fr=class{#e;#r;constructor(e){this.#e=e}async provideConnection(e){for(;this.#r;)await this.#r.catch(oi);return this.#r=this.#t(e).finally(()=>{this.#r=void 0}),this.#r}async#t(e){return await e(this.#e)}};var ni=["read only","read write"],ii=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function To(r){if(r.accessMode&&!ni.includes(r.accessMode))throw new Error(`invalid transaction access mode ${r.accessMode}`);if(r.isolationLevel&&!ii.includes(r.isolationLevel))throw new Error(`invalid transaction isolation level ${r.isolationLevel}`)}var UC=o(["query","error"]),Qt=class{#e;#r;constructor(e){O(e)?(this.#r=e,this.#e=o({query:!0,error:!0})):(this.#r=si,this.#e=o({query:e.includes("query"),error:e.includes("error")}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#r(e())}async error(e){this.#e.error&&await this.#r(e())}};function si(r){if(r.level==="query"){let e=`kysely:query:${r.isStream?"stream:":""}`;console.log(`${e} ${r.query.sql}`),console.log(`${e} duration: ${r.queryDurationMillis.toFixed(1)}ms`)}else r.level==="error"&&(r.error instanceof Error?console.error(`kysely:error: ${r.error.stack??r.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:r.error,query:r.query.sql,queryDurationMillis:r.queryDurationMillis})}`))}function An(r){return A(r)&&O(r.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");var Nr=class r extends Ze{#e;constructor(e){let t,n;if(ai(e))t={executor:e.executor},n={...e};else{let s=e.dialect,u=s.createDriver(),c=s.createQueryCompiler(),E=s.createAdapter(),I=new Qt(e.log??[]),B=new Dt(u,I),Rn=new qt(B),Qo=new It(c,E,Rn,e.plugins??[]);t={executor:Qo},n={config:e,executor:Qo,dialect:s,driver:B}}super(t),this.#e=o(n)}get schema(){return new At(this.#e.executor)}get dynamic(){return new Rt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new er({node:G.create(U(e)?void 0:V(e))})}get fn(){return at()}transaction(){return new Eo({...this.#e})}startTransaction(){return new Ao({...this.#e})}connection(){return new So({...this.#e})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new H(e))})}withTables(){return new r({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,t=x()){let n=An(e)?e.compile():e;return this.getExecutor().executeQuery(n,t)}async[Symbol.asyncDispose](){await this.destroy()}},Pt=class r extends Nr{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw new Error("calling the transaction method for a Transaction is not supported")}connection(){throw new Error("calling the connection method for a Transaction is not supported")}async destroy(){throw new Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new H(e))})}withTables(){return new r({...this.#e})}};function ai(r){return A(r)&&A(r.config)&&A(r.driver)&&A(r.executor)&&A(r.dialect)}var So=class{#e;constructor(e){this.#e=o(e)}async execute(e){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new fr(t)),s=new Nr({...this.#e,executor:n});return await e(s)})}},Eo=class r{#e;constructor(e){this.#e=o(e)}setAccessMode(e){return new r({...this.#e,accessMode:e})}setIsolationLevel(e){return new r({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:t,accessMode:n,...s}=this.#e,u={isolationLevel:t,accessMode:n};return To(u),this.#e.executor.provideConnection(async c=>{let E=this.#e.executor.withConnectionProvider(new fr(c)),I=new Pt({...s,executor:E});try{await this.#e.driver.beginTransaction(c,u);let B=await e(I);return await this.#e.driver.commitTransaction(c),B}catch(B){throw await this.#e.driver.rollbackTransaction(c),B}})}},Ao=class r{#e;constructor(e){this.#e=o(e)}setAccessMode(e){return new r({...this.#e,accessMode:e})}setIsolationLevel(e){return new r({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:t,...n}=this.#e,s={isolationLevel:e,accessMode:t};To(s);let u=await tt(this.#e.executor);return await this.#e.driver.beginTransaction(u.connection,s),new Ro({...n,connection:u,executor:this.#e.executor.withConnectionProvider(new fr(u.connection))})}},Ro=class r extends Pt{#e;#r;#t;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new qo(e.executor,t)};let{connection:n,...s}=e;super(s),this.#e=o(e),this.#t=t;let u=x();this.#r=c=>e.executor.compileQuery(c,u)}get isCommitted(){return this.#t.isCommitted}get isRolledBack(){return this.#t.isRolledBack}commit(){return ve(this.#t),new Pe(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#t.isCommitted=!0,this.#e.connection.release()})}rollback(){return ve(this.#t),new Pe(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#t.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return ve(this.#t),new Pe(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#r),new r({...this.#e})))}rollbackToSavepoint(e){return ve(this.#t),new Pe(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#r),new r({...this.#e})))}releaseSavepoint(e){return ve(this.#t),new Pe(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#r),new r({...this.#e})))}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new H(e))})}withTables(){return new r({...this.#e})}},Pe=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function ve(r){if(r.isCommitted)throw new Error("Transaction is already committed");if(r.isRolledBack)throw new Error("Transaction is already rolled back")}var qo=class r{#e;#r;constructor(e,t){e instanceof r?this.#e=e.#e:this.#e=e,this.#r=t}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e,t){return ve(this.#r),this.#e.executeQuery(e,t)}stream(e,t,n){return ve(this.#r),this.#e.stream(e,t,n)}withConnectionProvider(e){return new r(this.#e.withConnectionProvider(e),this.#r)}withPlugin(e){return new r(this.#e.withPlugin(e),this.#r)}withPlugins(e){return new r(this.#e.withPlugins(e),this.#r)}withPluginAtFront(e){return new r(this.#e.withPluginAtFront(e),this.#r)}withoutPlugins(){return new r(this.#e.withoutPlugins(),this.#r)}};var vt=class{async init(){}async acquireConnection(){return new Io}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}},Io=class{async executeQuery(){return{rows:[]}}async*streamQuery(){}};function wb(r){return new Nr({dialect:{createAdapter:()=>new r.Adapter,createDriver:()=>new vt,createIntrospector:()=>null,createQueryCompiler:()=>new r.QueryCompiler},plugins:[...r.noParameters?[new Bo]:[]]})}var Bo=class{#e=new Do;transformQuery(e){return this.#e.transformNode(e.node)}transformResult(e){return Promise.resolve(e.result)}},Do=class extends Se{transformPrimitiveValueList(e){return ae.create(e.values.map(b.createImmediate))}transformValue(e){return{...super.transformValue(e),immediate:!0}}};function xb(r){let e=r.compile();return{parameters:e.parameters,sql:e.sql}}function Ob(r,e){let t=di(r,e);return n=>n.where(s=>s.or(t.map(u=>s.and(u.map(([c,E])=>s(c,E===null?"is":"=",E))))))}function ui(r,e){return Object.entries(Object.values(e).reduce((t,n)=>{let{isInPrimaryKey:s,name:u}=n;return s&&(t[u]=r[u]??null),t},{}))}function di(r,e){return r.map(t=>ui(t,e))}export{W as a,Le as b,qr as c,Ir as d,ci as e,Br as f,o as g,d as h,M as i,P as j,g as k,Z as l,v as m,ze as n,ee as o,b as p,w as q,be as r,C as s,K as t,a as u,x as v,Xe as w,fn as x,l as y,Oe as z,wb as A,xb as B,Ob as C,ui as D};
@@ -1 +0,0 @@
1
- import{A as ei,B as g,C as B,a as E,b as z,c as Q,d as j,e as V,f as U,g as m,h as C,i as F,j as W,k as I,l as J,m as f,n as K,o as $,p as G,q as k,r as Y,s as H,t as w,u as T,v,w as X,x as Z,y as ii,z as ti}from"./chunk-P72NBTYE.js";var si={bool:{group:"boolean"},boolean:{group:"boolean"},bytea:{group:"string"},char:{group:"string"},citext:{group:"string"},date:{group:"datetime"},interval:{group:"string"},name:{group:"string"},varchar:{group:"string"},text:{group:"string"},time:{group:"time"},timestamp:{group:"datetime"},timestamptz:{group:"datetime"},"timestamp without time zone":{group:"datetime"},"timestamp with time zone":{group:"datetime"},timetz:{group:"time"},"time without time zone":{group:"time"},"time with time zone":{group:"datetime"},uuid:{group:"string"},int2:{group:"numeric"},int4:{group:"numeric"},int8:{group:"numeric"},smallint:{group:"numeric"},integer:{group:"numeric"},bigint:{group:"numeric"},decimal:{group:"numeric"},numeric:{group:"numeric"},real:{group:"numeric"},float4:{group:"numeric"},float8:{group:"numeric"},"double precision":{group:"numeric"},json:{group:"json"},jsonb:{group:"json"}};var P=class e{#i;constructor(i){this.#i=m(i)}get expressionType(){}get isRawBuilder(){return!0}as(i){return new q(this,i)}$castTo(){return new e({...this.#i})}$notNull(){return new e(this.#i)}withPlugin(i){return new e({...this.#i,plugins:this.#i.plugins!==void 0?m([...this.#i.plugins,i]):m([i])})}toOperationNode(){return this.#e(this.#t())}compile(i){return this.#s(this.#t(i))}async execute(i){let t=this.#t(i);return t.executeQuery(this.#s(t),this.#i.queryId)}#t(i){let t=i!==void 0?i.getExecutor():X;return this.#i.plugins!==void 0?t.withPlugins(this.#i.plugins):t}#e(i){return i.transformQuery(this.#i.rawNode,this.#i.queryId)}#s(i){return i.compileQuery(this.#e(i),this.#i.queryId)}};function N(e){return new P(e)}var q=class{#i;#t;constructor(i,t){this.#i=i,this.#t=t}get expression(){return this.#i}get alias(){return this.#t}get rawBuilder(){return this.#i}toOperationNode(){return W.create(this.#i.toOperationNode(),I(this.#t)?this.#t.toOperationNode():C.create(this.#t))}};var o=Object.assign((e,...i)=>N({queryId:v(),rawNode:f.create(e,i?.map(ri)??[])}),{ref(e){return N({queryId:v(),rawNode:f.createWithChild($(e))})},val(e){return N({queryId:v(),rawNode:f.createWithChild(k(e))})},value(e){return this.val(e)},table(e){return N({queryId:v(),rawNode:f.createWithChild(ii(e))})},id(...e){let i=new Array(e.length+1).fill(".");return i[0]="",i[i.length-1]="",N({queryId:v(),rawNode:f.create(i,e.map(C.create))})},lit(e){return N({queryId:v(),rawNode:f.createWithChild(G.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return N({queryId:v(),rawNode:f.createWithSql(e)})},join(e,i=o`, `){let t=new Array(Math.max(2*e.length-1,0)),s=i.toOperationNode();for(let r=0;r<e.length;++r)t[2*r]=ri(e[r]),r!==e.length-1&&(t[2*r+1]=s);return N({queryId:v(),rawNode:f.createWithChildren(t)})}});function ri(e){return I(e)?e.toOperationNode():k(e)}var O=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#i=m({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=i=>{this.nodeStack.push(i),this.#i[i.kind](i),this.nodeStack.pop()}};var Ni=/'/g,D=class extends O{#i="";#t=[];get numParameters(){return this.#t.length}compileQuery(i,t){return this.#i="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(i),m({query:i,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#i}visitSelectQuery(i){let t=this.parentNode!==void 0&&!Y.is(this.parentNode)&&!H.is(this.parentNode)&&!F.is(this.parentNode)&&!ti.is(this.parentNode)&&!Z.is(this.parentNode);this.parentNode===void 0&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("select"),i.distinctOn&&(this.append(" "),this.compileDistinctOn(i.distinctOn)),i.frontModifiers?.length&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.top&&(this.append(" "),this.visitNode(i.top)),i.selections&&(this.append(" "),this.compileList(i.selections)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.groupBy&&(this.append(" "),this.visitNode(i.groupBy)),i.having&&(this.append(" "),this.visitNode(i.having)),i.setOperations&&(this.append(" "),this.compileList(i.setOperations," ")),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.offset&&(this.append(" "),this.visitNode(i.offset)),i.fetch&&(this.append(" "),this.visitNode(i.fetch)),i.endModifiers?.length&&(this.append(" "),this.compileList(this.sortSelectModifiers([...i.endModifiers])," ")),t&&this.append(")")}visitFrom(i){this.append("from "),this.compileList(i.froms)}visitSelection(i){this.visitNode(i.selection)}visitColumn(i){this.visitNode(i.column)}compileDistinctOn(i){this.append("distinct on ("),this.compileList(i),this.append(")")}compileList(i,t=", "){let s=i.length-1;for(let r=0;r<=s;r++)this.visitNode(i[r]),r<s&&this.append(t)}visitWhere(i){this.append("where "),this.visitNode(i.where)}visitHaving(i){this.append("having "),this.visitNode(i.having)}visitInsertQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append(i.replace?"replace":"insert"),i.ignore&&(K("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),i.orAction&&(this.append(" "),this.visitNode(i.orAction)),i.top&&(this.append(" "),this.visitNode(i.top)),i.into&&(this.append(" into "),this.visitNode(i.into)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.output&&(this.append(" "),this.visitNode(i.output)),i.values&&(this.append(" "),this.visitNode(i.values)),i.defaultValues&&(this.append(" "),this.append("default values")),i.onConflict&&(this.append(" "),this.visitNode(i.onConflict)),i.onDuplicateKey&&(this.append(" "),this.visitNode(i.onDuplicateKey)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitValues(i){this.append("values "),this.compileList(i.values)}visitDeleteQuery(i){let t=this.nodeStack.find(T.is)!==i;!t&&i.explain&&(this.visitNode(i.explain),this.append(" ")),t&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("delete "),i.top&&(this.visitNode(i.top),this.append(" ")),this.visitNode(i.from),i.output&&(this.append(" "),this.visitNode(i.output)),i.using&&(this.append(" "),this.visitNode(i.using)),i.joins&&(this.append(" "),this.compileList(i.joins," ")),i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),t&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitReturning(i){this.append("returning "),this.compileList(i.selections)}visitAlias(i){this.visitNode(i.node),this.append(" as "),this.visitNode(i.alias)}visitReference(i){i.table&&(this.visitNode(i.table),this.append(".")),this.visitNode(i.column)}visitSelectAll(i){this.append("*")}visitIdentifier(i){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(i),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(i){if(!E(i.name))throw new Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(i.name))}visitAnd(i){this.visitNode(i.left),this.append(" and "),this.visitNode(i.right)}visitOr(i){this.visitNode(i.left),this.append(" or "),this.visitNode(i.right)}visitValue(i){i.immediate?this.appendImmediateValue(i.value):this.appendValue(i.value)}visitValueList(i){this.append("("),this.compileList(i.values),this.append(")")}visitTuple(i){this.append("("),this.compileList(i.values),this.append(")")}visitPrimitiveValueList(i){this.append("(");let{values:t}=i;for(let s=0;s<t.length;++s)this.appendValue(t[s]),s!==t.length-1&&this.append(", ");this.append(")")}visitParens(i){this.append("("),this.visitNode(i.node),this.append(")")}visitJoin(i){this.append(yi[i.joinType]),this.append(" "),this.visitNode(i.table),i.on&&(this.append(" "),this.visitNode(i.on))}visitOn(i){this.append("on "),this.visitNode(i.on)}visitRaw(i){let{sqlFragments:t,parameters:s}=i;for(let r=0;r<t.length;++r)this.append(t[r]),s.length>r&&this.visitNode(s[r])}visitOperator(i){this.append(i.operator)}visitTable(i){this.visitNode(i.table)}visitSchemableIdentifier(i){i.schema&&(this.visitNode(i.schema),this.append(".")),this.visitNode(i.identifier)}visitCreateTable(i){this.append("create "),i.frontModifiers&&i.frontModifiers.length>0&&(this.compileList(i.frontModifiers," "),this.append(" ")),i.temporary&&this.append("temporary "),this.append("table "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.table),i.selectQuery?(this.append(" as "),this.visitNode(i.selectQuery)):(this.append(" ("),this.compileList([...i.columns,...i.constraints??[]]),this.append(")"),i.onCommit&&(this.append(" on commit "),this.append(i.onCommit)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," ")))}visitColumnDefinition(i){i.ifNotExists&&this.append("if not exists "),this.visitNode(i.column),this.append(" "),this.visitNode(i.dataType),i.unsigned&&this.append(" unsigned"),i.frontModifiers&&i.frontModifiers.length>0&&(this.append(" "),this.compileList(i.frontModifiers," ")),i.generated&&(this.append(" "),this.visitNode(i.generated)),i.identity&&this.append(" identity"),i.defaultTo&&(this.append(" "),this.visitNode(i.defaultTo)),i.notNull&&this.append(" not null"),i.unique&&this.append(" unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.primaryKey&&this.append(" primary key"),i.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),i.references&&(this.append(" "),this.visitNode(i.references)),i.check&&(this.append(" "),this.visitNode(i.check)),i.endModifiers&&i.endModifiers.length>0&&(this.append(" "),this.compileList(i.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(i){this.append("references "),this.visitNode(i.table),this.append(" ("),this.compileList(i.columns),this.append(")"),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate))}visitDropTable(i){this.append("drop table "),i.ifExists&&this.append("if exists "),this.visitNode(i.table),i.cascade&&this.append(" cascade")}visitDataType(i){this.append(i.dataType)}visitOrderBy(i){this.append("order by "),this.compileList(i.items)}visitOrderByItem(i){this.visitNode(i.orderBy),i.collation&&(this.append(" "),this.visitNode(i.collation)),i.direction&&(this.append(" "),this.visitNode(i.direction)),i.nulls&&(this.append(" nulls "),this.append(i.nulls))}visitGroupBy(i){this.append("group by "),this.compileList(i.items)}visitGroupByItem(i){this.visitNode(i.groupBy)}visitUpdateQuery(i){let t=this.nodeStack.find(T.is),s=t!==i;if(!s&&i.explain&&(this.visitNode(i.explain),this.append(" ")),s&&!w.is(t)&&this.append("("),i.with&&(this.visitNode(i.with),this.append(" ")),this.append("update "),i.top&&(this.visitNode(i.top),this.append(" ")),i.table&&(this.visitNode(i.table),this.append(" ")),this.append("set "),i.updates&&this.compileList(i.updates),i.output&&(this.append(" "),this.visitNode(i.output)),i.from&&(this.append(" "),this.visitNode(i.from)),i.joins){if(!i.from)throw new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(i.joins," ")}i.where&&(this.append(" "),this.visitNode(i.where)),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),i.limit&&(this.append(" "),this.visitNode(i.limit)),i.returning&&(this.append(" "),this.visitNode(i.returning)),s&&!w.is(t)&&this.append(")"),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitColumnUpdate(i){this.visitNode(i.column),this.append(" = "),this.visitNode(i.value)}visitLimit(i){this.append("limit "),this.visitNode(i.limit)}visitOffset(i){this.append("offset "),this.visitNode(i.offset)}visitOnConflict(i){this.append("on conflict"),i.columns?(this.append(" ("),this.compileList(i.columns),this.append(")")):i.constraint?(this.append(" on constraint "),this.visitNode(i.constraint)):i.indexExpression&&(this.append(" ("),this.visitNode(i.indexExpression),this.append(")")),i.indexWhere&&(this.append(" "),this.visitNode(i.indexWhere)),i.doNothing===!0?this.append(" do nothing"):i.updates&&(this.append(" do update set "),this.compileList(i.updates),i.updateWhere&&(this.append(" "),this.visitNode(i.updateWhere)))}visitOnDuplicateKey(i){this.append("on duplicate key update "),this.compileList(i.updates)}visitCreateIndex(i){this.append("create "),i.unique&&this.append("unique "),this.append("index "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.using&&(this.append(" using "),this.visitNode(i.using)),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.nullsNotDistinct&&this.append(" nulls not distinct"),i.where&&(this.append(" "),this.visitNode(i.where))}visitDropIndex(i){this.append("drop index "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.table&&(this.append(" on "),this.visitNode(i.table)),i.cascade&&this.append(" cascade")}visitCreateSchema(i){this.append("create schema "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.schema)}visitDropSchema(i){this.append("drop schema "),i.ifExists&&this.append("if exists "),this.visitNode(i.schema),i.cascade&&this.append(" cascade")}visitPrimaryKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("primary key ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}buildDeferrable(i){i.deferrable!==void 0&&(i.deferrable?this.append(" deferrable"):this.append(" not deferrable")),i.initiallyDeferred!==void 0&&(i.initiallyDeferred?this.append(" initially deferred"):this.append(" initially immediate"))}visitUniqueConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("unique"),i.nullsNotDistinct&&this.append(" nulls not distinct"),this.append(" ("),this.compileList(i.columns),this.append(")"),this.buildDeferrable(i)}visitCheckConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("check ("),this.visitNode(i.expression),this.append(")")}visitForeignKeyConstraint(i){i.name&&(this.append("constraint "),this.visitNode(i.name),this.append(" ")),this.append("foreign key ("),this.compileList(i.columns),this.append(") "),this.visitNode(i.references),i.onDelete&&(this.append(" on delete "),this.append(i.onDelete)),i.onUpdate&&(this.append(" on update "),this.append(i.onUpdate)),this.buildDeferrable(i)}visitList(i){this.compileList(i.items)}visitWith(i){this.append("with "),i.recursive&&this.append("recursive "),this.compileList(i.expressions)}visitCommonTableExpression(i){this.visitNode(i.name),this.append(" as "),Q(i.materialized)&&(i.materialized||this.append("not "),this.append("materialized ")),this.visitNode(i.expression)}visitCommonTableExpressionName(i){this.visitNode(i.table),i.columns&&(this.append("("),this.compileList(i.columns),this.append(")"))}visitAlterTable(i){this.append("alter table "),this.visitNode(i.table),this.append(" "),i.renameTo&&(this.append("rename to "),this.visitNode(i.renameTo)),i.setSchema&&(this.append("set schema "),this.visitNode(i.setSchema)),i.addConstraint&&this.visitNode(i.addConstraint),i.dropConstraint&&this.visitNode(i.dropConstraint),i.renameConstraint&&this.visitNode(i.renameConstraint),i.columnAlterations&&this.compileColumnAlterations(i.columnAlterations),i.addIndex&&this.visitNode(i.addIndex),i.dropIndex&&this.visitNode(i.dropIndex)}visitAddColumn(i){this.append("add column "),this.visitNode(i.column)}visitRenameColumn(i){this.append("rename column "),this.visitNode(i.column),this.append(" to "),this.visitNode(i.renameTo)}visitDropColumn(i){this.append("drop column "),this.visitNode(i.column)}visitAlterColumn(i){this.append("alter column "),this.visitNode(i.column),this.append(" "),i.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(i.dataType),i.dataTypeExpression&&(this.append("using "),this.visitNode(i.dataTypeExpression))),i.setDefault&&(this.append("set default "),this.visitNode(i.setDefault)),i.dropDefault&&this.append("drop default"),i.setNotNull&&this.append("set not null"),i.dropNotNull&&this.append("drop not null")}visitModifyColumn(i){this.append("modify column "),this.visitNode(i.column)}visitAddConstraint(i){this.append("add "),this.visitNode(i.constraint)}visitDropConstraint(i){this.append("drop constraint "),i.ifExists&&this.append("if exists "),this.visitNode(i.constraintName),i.modifier==="cascade"?this.append(" cascade"):i.modifier==="restrict"&&this.append(" restrict")}visitRenameConstraint(i){this.append("rename constraint "),this.visitNode(i.oldName),this.append(" to "),this.visitNode(i.newName)}visitSetOperation(i){this.append(i.operator),this.append(" "),i.all&&this.append("all "),this.visitNode(i.expression)}visitCreateView(i){this.append("create "),i.orReplace&&this.append("or replace "),i.materialized&&this.append("materialized "),i.temporary&&this.append("temporary "),this.append("view "),i.ifNotExists&&this.append("if not exists "),this.visitNode(i.name),this.append(" "),i.columns&&(this.append("("),this.compileList(i.columns),this.append(") ")),i.as&&(this.append("as "),this.visitNode(i.as))}visitRefreshMaterializedView(i){this.append("refresh materialized view "),i.concurrently&&this.append("concurrently "),this.visitNode(i.name),i.withNoData?this.append(" with no data"):this.append(" with data")}visitDropView(i){this.append("drop "),i.materialized&&this.append("materialized "),this.append("view "),i.ifExists&&this.append("if exists "),this.visitNode(i.name),i.cascade&&this.append(" cascade")}visitGenerated(i){this.append("generated "),i.always&&this.append("always "),i.byDefault&&this.append("by default "),this.append("as "),i.identity&&this.append("identity"),i.expression&&(this.append("("),this.visitNode(i.expression),this.append(")")),i.stored&&this.append(" stored")}visitDefaultValue(i){this.append("default "),this.visitNode(i.defaultValue)}visitSelectModifier(i){i.rawModifier?this.visitNode(i.rawModifier):this.append(gi[i.modifier]),i.of&&(this.append(" of "),this.compileList(i.of,", "))}visitCreateType(i){this.append("create type "),this.visitNode(i.name),i.enum&&(this.append(" as enum "),this.visitNode(i.enum))}visitDropType(i){this.append("drop type "),i.ifExists&&this.append("if exists "),this.visitNode(i.name)}visitExplain(i){this.append("explain"),(i.options||i.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),i.options&&(this.visitNode(i.options),i.format&&this.append(this.getExplainOptionsDelimiter())),i.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(i.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(i){this.append("default")}visitAggregateFunction(i){this.append(i.func),this.append("("),i.distinct&&this.append("distinct "),this.compileList(i.aggregated),i.orderBy&&(this.append(" "),this.visitNode(i.orderBy)),this.append(")"),i.withinGroup&&(this.append(" within group ("),this.visitNode(i.withinGroup),this.append(")")),i.filter&&(this.append(" filter("),this.visitNode(i.filter),this.append(")")),i.over&&(this.append(" "),this.visitNode(i.over))}visitOver(i){this.append("over("),i.partitionBy&&(this.visitNode(i.partitionBy),i.orderBy&&this.append(" ")),i.orderBy&&this.visitNode(i.orderBy),this.append(")")}visitPartitionBy(i){this.append("partition by "),this.compileList(i.items)}visitPartitionByItem(i){this.visitNode(i.partitionBy)}visitBinaryOperation(i){this.visitNode(i.leftOperand),this.append(" "),this.visitNode(i.operator),this.append(" "),this.visitNode(i.rightOperand)}visitUnaryOperation(i){this.visitNode(i.operator),this.isMinusOperator(i.operator)||this.append(" "),this.visitNode(i.operand)}isMinusOperator(i){return J.is(i)&&i.operator==="-"}visitUsing(i){this.append("using "),this.compileList(i.tables)}visitFunction(i){this.append(i.func),this.append("("),this.compileList(i.arguments),this.append(")")}visitCase(i){this.append("case"),i.value&&(this.append(" "),this.visitNode(i.value)),i.when&&(this.append(" "),this.compileList(i.when," ")),i.else&&(this.append(" else "),this.visitNode(i.else)),this.append(" end"),i.isStatement&&this.append(" case")}visitWhen(i){this.append("when "),this.visitNode(i.condition),i.result&&(this.append(" then "),this.visitNode(i.result))}visitJSONReference(i){this.visitNode(i.reference),this.visitNode(i.traversal)}visitJSONPath(i){i.inOperator&&this.visitNode(i.inOperator),this.append("'$");for(let t of i.pathLegs)this.visitNode(t);this.append("'")}visitJSONPathLeg(i){let t=i.type==="ArrayLocation";this.append(t?"[":"."),this.append(String(i.value)),t&&this.append("]")}visitJSONOperatorChain(i){for(let t=0,s=i.values.length;t<s;t++)t===s-1?this.visitNode(i.operator):this.append("->"),this.visitNode(i.values[t])}visitMergeQuery(i){i.with&&(this.visitNode(i.with),this.append(" ")),this.append("merge "),i.top&&(this.visitNode(i.top),this.append(" ")),this.append("into "),this.visitNode(i.into),i.using&&(this.append(" "),this.visitNode(i.using)),i.whens&&(this.append(" "),this.compileList(i.whens," ")),i.returning&&(this.append(" "),this.visitNode(i.returning)),i.output&&(this.append(" "),this.visitNode(i.output)),i.endModifiers?.length&&(this.append(" "),this.compileList(i.endModifiers," "))}visitMatched(i){i.not&&this.append("not "),this.append("matched"),i.bySource&&this.append(" by source")}visitAddIndex(i){this.append("add "),i.unique&&this.append("unique "),this.append("index "),this.visitNode(i.name),i.columns&&(this.append(" ("),this.compileList(i.columns),this.append(")")),i.using&&(this.append(" using "),this.visitNode(i.using))}visitCast(i){this.append("cast("),this.visitNode(i.expression),this.append(" as "),this.visitNode(i.dataType),this.append(")")}visitFetch(i){this.append("fetch next "),this.visitNode(i.rowCount),this.append(` rows ${i.modifier}`)}visitOutput(i){this.append("output "),this.compileList(i.selections)}visitTop(i){this.append(`top(${i.expression})`),i.modifiers&&this.append(` ${i.modifiers}`)}visitOrAction(i){this.append(i.action)}visitCollate(i){this.append("collate "),this.visitNode(i.collation)}append(i){this.#i+=i}appendValue(i){this.addParameter(i),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(i){let t=this.getLeftIdentifierWrapper(),s=this.getRightIdentifierWrapper(),r="";for(let a of i)r+=a,a===t?r+=t:a===s&&(r+=s);return r}sanitizeStringLiteral(i){return i.replace(Ni,"''")}addParameter(i){this.#t.push(i)}appendImmediateValue(i){if(E(i))this.appendStringLiteral(i);else if(z(i)||Q(i))this.append(i.toString());else if(j(i))this.append("null");else if(V(i))this.appendImmediateValue(i.toISOString());else if(U(i))this.appendImmediateValue(i.toString());else throw new Error(`invalid immediate value ${i}`)}appendStringLiteral(i){this.append("'"),this.append(this.sanitizeStringLiteral(i)),this.append("'")}sortSelectModifiers(i){return i.sort((t,s)=>t.modifier&&s.modifier?ai[t.modifier]-ai[s.modifier]:1),m(i)}compileColumnAlterations(i){this.compileList(i)}announcesNewColumnDataType(){return!0}},gi=m({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),ai=m({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),yi=m({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var S=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var bi=/"/g,L=class extends D{sanitizeIdentifier(i){return i.replace(bi,'""')}};var xi=BigInt("3853314791062309107"),A=class extends S{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(i,t){await o`select pg_advisory_xact_lock(${o.lit(xi)})`.execute(i)}async releaseMigrationLock(i,t){}};function y(e){return ei({...e,Adapter:A,QueryCompiler:L})}function ni(e,i){let{table:t,rows:s}=e,{name:r,schema:a,columns:n}=t,p=y(i),h=Object.keys(n),l={[h[0]]:o`default`};return g(p.withSchema(a).insertInto(r).values(s.map(u=>Object.keys(u).length===0?l:u)).returning(h).returning(u=>u.cast("ctid","text").as("ctid")))}function pi(e,i){let{pageIndex:t,pageSize:s,sortOrder:r,table:{name:a,schema:n,columns:p}}=e,h=y(i),l=Object.keys(p),u=h.withSchema(n).selectFrom(a).select(d=>d.cast(d.fn.coalesce(d.fn.countAll(),o.lit(0)),"text").as("oid"));return g(h.with("count",()=>u).withSchema(n).selectFrom([a,"count"]).select(o.ref("count.oid").$castTo().as("oid")).select(d=>d.cast("ctid","text").as("ctid")).select(l).$call(d=>r.reduce((b,x)=>b.orderBy(x.column,x.direction),d)).limit(s).offset(o.lit(BigInt(t)*BigInt(s))))}function It(){return[{created_at:new Date("2025-01-26T21:56:12.345Z"),ctid:"(0,1)",deleted_at:null,id:1,name:"John Doe",oid:"2",role:"admin"},{created_at:new Date("2025-01-26T20:56:12.345Z"),ctid:"(0,2)",deleted_at:null,id:2,name:"Jane Doe",oid:"2",role:"poweruser"}]}function oi(e,i){let{changes:t,row:s,table:{columns:r,name:a,schema:n}}=e,p=y(i),h=Object.keys(r);return g(p.withSchema(n).updateTable(a).set(t).$call(B([s],r)).returning(h).returning(l=>[l.cast("ctid","text").as("ctid"),l.cast(l.fn("floor",[l(l.fn("extract",[o`epoch from now()`]),"*",1e6)]),"text").as("__ps_updated_at__")]))}function hi(e,i){let{rows:t,table:{columns:s,name:r,schema:a}}=e,n=y(i);return g(n.withSchema(a).deleteFrom(r).$call(B(t,s)))}function di(e){return o`(select coalesce(json_agg(agg), '[]') from ${e} as agg)`}var wi="r",Ci="v",Ii=[wi,Ci];function li(e){return g(y(e).selectFrom("pg_catalog.pg_class as cls").innerJoin("pg_catalog.pg_namespace as ns","cls.relnamespace","ns.oid").$call(Ti).where("cls.relkind","in",Ii).select(i=>["ns.nspname as schema","cls.relname as name",di(i.selectFrom("pg_catalog.pg_attribute as att").innerJoin("pg_catalog.pg_type as typ","typ.oid","att.atttypid").innerJoin("pg_catalog.pg_namespace as tns","tns.oid","typ.typnamespace").leftJoin("pg_catalog.pg_constraint as con",t=>t.on("con.contype","=","p").onRef("con.conrelid","=","cls.oid").on(s=>s("att.attnum","=",s.fn.any("con.conkey")))).whereRef("att.attrelid","=","cls.oid").where("att.attnum",">=",0).where("att.attisdropped","!=",!0).where("att.attgenerated","=","").select(["att.attname as name","typ.typname as datatype","tns.nspname as datatype_schema"]).select(t=>[t("con.conkey","is not",null).$castTo().as("pk"),t("att.attgenerated","!=","").$castTo().as("computed"),t("att.attnotnull","!=",!0).$castTo().as("nullable"),t.fn.coalesce(t.selectFrom("pg_catalog.pg_enum as enm").whereRef("enm.enumtypid","=","typ.oid").select(s=>s.fn.jsonAgg(s.ref("enm.enumlabel")).as("o")),o`'[]'`).as("options")])).as("columns")]))}function ui(){return[{schema:"public",name:"users",columns:[{name:"id",datatype:"bigint",datatype_schema:"public",pk:!0,computed:!1,options:[],nullable:!0},{name:"name",datatype:"varchar",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"role",datatype:"role",datatype_schema:"public",pk:!1,computed:!1,options:["admin","maintainer","member"],nullable:!0},{name:"created_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0},{name:"deleted_at",datatype:"timestamptz",datatype_schema:"public",pk:!1,computed:!1,options:[],nullable:!0}]}]}function ci(){let e=y();return g(e.selectNoFrom(e.fn("current_setting",[o.lit("timezone")]).as("timezone")))}function mi(){return[{timezone:"UTC"}]}function Ti(e){return e.where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema")}function Mt(e){let{executor:i,...t}=e;return{defaultSchema:"public",async introspect(s){try{let r=li(t),a=ci(),[[n,p],[h,l]]=await Promise.all([i.execute(r,s),i.execute(a,s)]),u=n||h;if(u)return[u];let[d]=l;return d?[null,fi(p,d.timezone)]:[new Error("Timezone not found")]}catch(r){return[r]}},async query(s,r){try{let a=pi(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{filteredRowCount:p[0]?.oid||"0",rows:p}]}catch(a){return[a]}},async insert(s,r){try{let a=ni(s,t),[n,p]=await i.execute(a,r);return n?[n]:[null,{rows:p}]}catch(a){return[a]}},async update(s,r){try{let a=oi(s,t),[n,p]=await i.execute(a,r);if(n)return[n];let[h]=p;return h?[null,{row:h}]:[new Error("Update failed")]}catch(a){return[a]}},async delete(s,r){try{let a=hi(s,t),[n]=await i.execute(a,r);return n?[n]:[null,s]}catch(a){return[a]}}}}function fi(e,i){return e.reduce((t,s)=>{let{schemas:r}=t,{columns:a,name:n,schema:p}=s,h=a.reduce((l,u)=>{let{datatype:d,datatype_schema:b,name:x,options:M,nullable:vi}=u,_=d.startsWith("_"),R=_?d.slice(1):d;return{...l,[x]:{datatype:{...si[R]||{group:M.length>0?"enum":"raw"},isArray:_,isNative:b==="pg_catalog",name:_?`${R}[]`:R,options:M,schema:b},isComputed:u.computed,isInPrimaryKey:u.pk,name:x,nullable:vi,schema:p,table:n}}},{});return(r[p]||={tables:{}}).tables[n]={columns:h,name:n,schema:p},t},{schemas:{public:{tables:{}}},timezone:i})}function zt(){let e=ui(),[{timezone:i}]=mi();return fi(e,i)}export{ni as a,pi as b,It as c,oi as d,hi as e,li as f,ui as g,ci as h,mi as i,Mt as j,zt as k};
@@ -1,48 +0,0 @@
1
- import { T as Table, E as Either } from './adapter-CKFCHq71.js';
2
- import { WhereInterface, DialectAdapter, QueryCompiler } from 'kysely';
3
-
4
- interface BuilderRequirements {
5
- Adapter: {
6
- new (): DialectAdapter;
7
- };
8
- noParameters?: boolean;
9
- QueryCompiler: {
10
- new (): QueryCompiler;
11
- };
12
- }
13
- declare const queryType: unique symbol;
14
- interface Query<T = unknown> {
15
- [queryType]?: T;
16
- parameters: readonly unknown[];
17
- sql: string;
18
- }
19
- type QueryResult<T> = T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
20
- /**
21
- * Applies a filter to the given rows based on the primary key columns of the table.
22
- *
23
- * @example db.selectFrom("users").$call(applyInferredRowFilters(rows, columns)).selectAll()
24
- */
25
- declare function applyInferredRowFilters(rows: Record<string, unknown>[], columns: Table["columns"]): <QB extends WhereInterface<any, any>>(qb: QB) => QB;
26
- /**
27
- * Part of a filter that predicts a match.
28
- * ie. ... WHERE $ColumName = $Value ...
29
- */
30
- type RowFilterPredicate = [ColumnName: string, Value: unknown];
31
- /**
32
- * A row filter is comprised of one or more predicates.
33
- */
34
- type RowFilter = RowFilterPredicate[];
35
- /**
36
- * Infers the filter that is necessary to uniquely identify a given row
37
- * individually.
38
- */
39
- declare function inferRowFilter(row: Record<string, unknown>, columns: Table["columns"]): RowFilter;
40
-
41
- interface Executor {
42
- execute<Q extends Query>(query: Q, options?: ExecuteOptions): Promise<Either<Error, QueryResult<Q>>>;
43
- }
44
- interface ExecuteOptions {
45
- abortSignal?: AbortSignal;
46
- }
47
-
48
- export { type BuilderRequirements as B, type Executor as E, type Query as Q, type ExecuteOptions as a, type QueryResult as b, applyInferredRowFilters as c, inferRowFilter as i };
@@ -1,48 +0,0 @@
1
- import { T as Table, E as Either } from './adapter-CKFCHq71.cjs';
2
- import { WhereInterface, DialectAdapter, QueryCompiler } from 'kysely';
3
-
4
- interface BuilderRequirements {
5
- Adapter: {
6
- new (): DialectAdapter;
7
- };
8
- noParameters?: boolean;
9
- QueryCompiler: {
10
- new (): QueryCompiler;
11
- };
12
- }
13
- declare const queryType: unique symbol;
14
- interface Query<T = unknown> {
15
- [queryType]?: T;
16
- parameters: readonly unknown[];
17
- sql: string;
18
- }
19
- type QueryResult<T> = T extends Query<infer R> ? R[] : T extends (...args: any[]) => Query<infer R> ? R[] : never;
20
- /**
21
- * Applies a filter to the given rows based on the primary key columns of the table.
22
- *
23
- * @example db.selectFrom("users").$call(applyInferredRowFilters(rows, columns)).selectAll()
24
- */
25
- declare function applyInferredRowFilters(rows: Record<string, unknown>[], columns: Table["columns"]): <QB extends WhereInterface<any, any>>(qb: QB) => QB;
26
- /**
27
- * Part of a filter that predicts a match.
28
- * ie. ... WHERE $ColumName = $Value ...
29
- */
30
- type RowFilterPredicate = [ColumnName: string, Value: unknown];
31
- /**
32
- * A row filter is comprised of one or more predicates.
33
- */
34
- type RowFilter = RowFilterPredicate[];
35
- /**
36
- * Infers the filter that is necessary to uniquely identify a given row
37
- * individually.
38
- */
39
- declare function inferRowFilter(row: Record<string, unknown>, columns: Table["columns"]): RowFilter;
40
-
41
- interface Executor {
42
- execute<Q extends Query>(query: Q, options?: ExecuteOptions): Promise<Either<Error, QueryResult<Q>>>;
43
- }
44
- interface ExecuteOptions {
45
- abortSignal?: AbortSignal;
46
- }
47
-
48
- export { type BuilderRequirements as B, type Executor as E, type Query as Q, type ExecuteOptions as a, type QueryResult as b, applyInferredRowFilters as c, inferRowFilter as i };