@shumai-one/shumai 0.4.3 → 0.4.4
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.
- package/bin/chunk-071x515q.js +4 -0
- package/bin/chunk-0cmx7k4c.js +1 -0
- package/bin/{chunk-cqb415s6.js → chunk-0qaq0sp8.js} +2 -2
- package/bin/chunk-0qjfahk9.js +2 -0
- package/bin/{chunk-9t1ne8xr.js → chunk-0zv3bks2.js} +2 -2
- package/bin/chunk-16xax8kk.js +1 -0
- package/bin/chunk-1gvscz88.js +5 -0
- package/bin/{chunk-6gg1ymer.js → chunk-1j27fzy1.js} +2 -2
- package/bin/chunk-1t167cvj.js +11 -0
- package/bin/{chunk-pb1zf0vb.js → chunk-1xh34aew.js} +2 -2
- package/bin/{chunk-zmv8cg4s.js → chunk-1zwajpwf.js} +3 -3
- package/bin/chunk-2w5xqhjm.js +1 -0
- package/bin/{chunk-f3ehv01n.js → chunk-3tedzb2j.js} +26 -26
- package/bin/{chunk-zehyn6vd.js → chunk-3ttrhqy3.js} +2 -2
- package/bin/chunk-3zkasqb8.js +1 -0
- package/bin/chunk-453ykvaw.js +2 -0
- package/bin/{chunk-3cyrcgm5.js → chunk-4991gz3y.js} +9 -9
- package/bin/chunk-4hkkdm2q.js +2 -0
- package/bin/chunk-4mjywsj8.js +3 -0
- package/bin/{chunk-cnxwmycy.js → chunk-4v41a1r9.js} +3 -3
- package/bin/{chunk-87zxtf66.js → chunk-4wy87hwd.js} +2 -2
- package/bin/{chunk-sfx2588q.js → chunk-579e4wv4.js} +2 -2
- package/bin/{chunk-1yacmegc.js → chunk-5adsx8x4.js} +2 -2
- package/bin/{chunk-b235azv4.js → chunk-5hg6kcfz.js} +13 -13
- package/bin/{chunk-rbj4fad9.js → chunk-5nm2jvg5.js} +13 -13
- package/bin/chunk-5tcdwep5.js +11 -0
- package/bin/chunk-5vzrpz50.js +2 -0
- package/bin/chunk-6ghcj4a9.js +3 -0
- package/bin/{chunk-b9yrw9et.js → chunk-77fmkpdz.js} +4 -4
- package/bin/chunk-7bcxj1jd.js +2 -0
- package/bin/{chunk-qf24e71w.js → chunk-7gmdnsdg.js} +1 -1
- package/bin/{chunk-fxswt9hc.js → chunk-7jtmwt5a.js} +2 -2
- package/bin/chunk-7kjgvxqa.js +2 -0
- package/bin/{chunk-bay038pj.js → chunk-7pw1550a.js} +2 -2
- package/bin/chunk-7rhz2gze.js +211 -0
- package/bin/chunk-837fky18.js +3 -0
- package/bin/chunk-84as6x83.js +1 -0
- package/bin/chunk-8e28hcny.js +2 -0
- package/bin/{chunk-k7hss0bd.js → chunk-914bp49r.js} +3 -3
- package/bin/chunk-97f2af6d.js +12 -0
- package/bin/{chunk-4r81ghg8.js → chunk-98715kc3.js} +2 -2
- package/bin/chunk-9ccw540k.js +2 -0
- package/bin/{chunk-ag6p3mbf.js → chunk-9t8n2des.js} +2 -2
- package/bin/chunk-9ybt6vbm.js +1 -0
- package/bin/{chunk-f15qyp41.js → chunk-a6gx7f5q.js} +1 -1
- package/bin/chunk-avwgktxb.js +2 -0
- package/bin/chunk-bkr5zm4h.js +2 -0
- package/bin/{chunk-2yxj593j.js → chunk-cbgq517y.js} +2 -2
- package/bin/chunk-d27mm390.js +1 -0
- package/bin/{chunk-185qefn1.js → chunk-dj92fss9.js} +2 -2
- package/bin/{chunk-v9w25rp2.js → chunk-dqxeztfa.js} +2 -2
- package/bin/chunk-drepsbb4.js +2 -0
- package/bin/chunk-f6svp4dp.js +2 -0
- package/bin/{chunk-q2bvyv39.js → chunk-fahk9h62.js} +2 -2
- package/bin/{chunk-v9b3w8q5.js → chunk-fb40xxz3.js} +2 -2
- package/bin/chunk-fnmwksnb.js +3 -0
- package/bin/chunk-fpc4p0j8.js +3 -0
- package/bin/{chunk-aqbrzx9z.js → chunk-fsyzs0tf.js} +1 -1
- package/bin/{chunk-e2mvmq2m.js → chunk-fxecgp5k.js} +1 -1
- package/bin/{chunk-wfzqnpc1.js → chunk-g3fpmyyn.js} +2 -2
- package/bin/{chunk-ehc9adfz.js → chunk-gc5sbfa5.js} +2 -2
- package/bin/chunk-gdm6yfqq.js +2 -0
- package/bin/{chunk-ea79xnn3.js → chunk-gk2q9a3f.js} +2 -2
- package/bin/{chunk-jje8nj8h.js → chunk-gt4csat6.js} +2 -2
- package/bin/chunk-gye8gabk.js +2 -0
- package/bin/{chunk-wry2hvrq.js → chunk-hk5rc6cd.js} +2 -2
- package/bin/{chunk-zqv0zhfb.js → chunk-hm0dkzed.js} +2 -2
- package/bin/chunk-hmpwg5za.js +16 -0
- package/bin/{chunk-rpywcvg1.js → chunk-j1tkmcae.js} +2 -2
- package/bin/chunk-j2bvj2yn.js +2 -0
- package/bin/chunk-jffktpqg.js +1 -0
- package/bin/chunk-jgs8an3h.js +18 -0
- package/bin/{chunk-8fmy5jtp.js → chunk-jmpb5633.js} +1 -1
- package/bin/{chunk-xp59apdb.js → chunk-jrjnqx78.js} +1 -1
- package/bin/chunk-k2k9vjq6.js +1 -0
- package/bin/{chunk-32pcmaqm.js → chunk-kpgfqkp0.js} +2 -2
- package/bin/{chunk-twdxayky.js → chunk-ks8xzc95.js} +2 -2
- package/bin/{chunk-qwqvt9v6.js → chunk-kswvyqq1.js} +2 -2
- package/bin/{chunk-gk3eqd50.js → chunk-m9pr03kn.js} +2 -2
- package/bin/chunk-mfn9qjm4.js +2 -0
- package/bin/{chunk-e99dv20z.js → chunk-msfw3jmc.js} +2 -2
- package/bin/chunk-mz0yjra0.js +5 -0
- package/bin/chunk-nbdw8fen.js +1 -0
- package/bin/{chunk-cak32x57.js → chunk-nkdk229f.js} +1 -1
- package/bin/chunk-nr20tvnw.js +3 -0
- package/bin/{chunk-ck8azecb.js → chunk-pazjhrnf.js} +5 -5
- package/bin/chunk-q806pqeh.js +1 -0
- package/bin/{chunk-abt0azmv.js → chunk-qka4mkmj.js} +2 -2
- package/bin/{chunk-0e4wawpq.js → chunk-qsr1a0rp.js} +1 -1
- package/bin/chunk-rchsme43.js +3 -0
- package/bin/{chunk-tf28796q.js → chunk-reyxk4bw.js} +1 -1
- package/bin/{chunk-av1a8fqp.js → chunk-rhvv1vvk.js} +2 -2
- package/bin/{chunk-a32vreya.js → chunk-rq0n0vcc.js} +2 -2
- package/bin/chunk-rqf7999q.js +42 -0
- package/bin/chunk-rssgmj7x.js +2 -0
- package/bin/chunk-ryzz5fht.js +2 -0
- package/bin/chunk-s2fnfyn9.js +2 -0
- package/bin/{chunk-83e12sjg.js → chunk-s2k4qntr.js} +2 -2
- package/bin/{chunk-c007p0t8.js → chunk-snhsjs4x.js} +56 -56
- package/bin/{chunk-j8fxp8ej.js → chunk-t2hy6tj9.js} +1 -1
- package/bin/chunk-t7nsgg5k.js +4 -0
- package/bin/chunk-tm7f32c7.js +14 -0
- package/bin/{chunk-2291ehh5.js → chunk-trveq4wg.js} +2 -2
- package/bin/chunk-vap4k11j.js +20 -0
- package/bin/chunk-vm5fx7td.js +3 -0
- package/bin/chunk-vy8gntez.js +1 -0
- package/bin/{chunk-awfwk64v.js → chunk-vyzptrea.js} +2 -2
- package/bin/{chunk-hfh0c082.js → chunk-w4ghe71n.js} +1 -1
- package/bin/chunk-wdsf44hs.js +2 -0
- package/bin/chunk-wjyaezs7.js +2 -0
- package/bin/{chunk-3a13dcs1.js → chunk-wndm3px3.js} +1 -1
- package/bin/chunk-x5jwwvs0.js +1 -0
- package/bin/chunk-x92cq59c.js +1 -0
- package/bin/{chunk-vgn5zcpv.js → chunk-xa18z1py.js} +2 -2
- package/bin/{chunk-4v5n0ayb.js → chunk-xarsrs08.js} +1 -1
- package/bin/{chunk-66hsjnw6.js → chunk-xx337zcw.js} +2 -2
- package/bin/chunk-xz6713tj.js +2 -0
- package/bin/chunk-yfnem6se.js +2 -0
- package/bin/{chunk-m7m9d4fb.js → chunk-ytdwk2fq.js} +2 -2
- package/bin/{chunk-jy006gcv.js → chunk-ze20rm02.js} +4 -4
- package/bin/chunk-zw86wnwe.js +7 -0
- package/bin/{chunk-h3tbf521.js → chunk-zxk7q0zk.js} +1 -1
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +773 -776
- package/package.json +7 -7
- package/prisma/migrations/20260907021754_add_asset_upload_id/migration.sql +2 -0
- package/prisma/schema.prisma +1 -0
- package/bin/chunk-1kw2mbqb.js +0 -1
- package/bin/chunk-1wm6ptdx.js +0 -1
- package/bin/chunk-2520aq8j.js +0 -2
- package/bin/chunk-29zdp63z.js +0 -3
- package/bin/chunk-3swpwb9v.js +0 -1
- package/bin/chunk-3wmcx2bv.js +0 -2
- package/bin/chunk-5a8nt4me.js +0 -1
- package/bin/chunk-6bhn1p8v.js +0 -211
- package/bin/chunk-70c3xrgd.js +0 -2
- package/bin/chunk-7esm0hqb.js +0 -2
- package/bin/chunk-7fst8kdw.js +0 -12
- package/bin/chunk-8zqgaxvv.js +0 -1
- package/bin/chunk-a3dmtt2j.js +0 -1
- package/bin/chunk-ce8m4zeg.js +0 -3
- package/bin/chunk-e7mqtkzn.js +0 -2
- package/bin/chunk-ejbvfj4r.js +0 -1
- package/bin/chunk-ekfem7kf.js +0 -1
- package/bin/chunk-etwkk0xh.js +0 -1
- package/bin/chunk-evrdd32b.js +0 -2
- package/bin/chunk-fm6p03ad.js +0 -2
- package/bin/chunk-fyha3r13.js +0 -2
- package/bin/chunk-g0vs7k2x.js +0 -1
- package/bin/chunk-g84z2w7v.js +0 -16
- package/bin/chunk-h837fyed.js +0 -2
- package/bin/chunk-j20e0qsw.js +0 -7
- package/bin/chunk-n1jwdb0a.js +0 -1
- package/bin/chunk-p5gf1zdm.js +0 -4
- package/bin/chunk-pfgxggaj.js +0 -11
- package/bin/chunk-q16490pv.js +0 -2
- package/bin/chunk-qh81zhg1.js +0 -1
- package/bin/chunk-qwp3kwbz.js +0 -2
- package/bin/chunk-qydeqgyj.js +0 -5
- package/bin/chunk-r7dty1tg.js +0 -2
- package/bin/chunk-rhdxwebf.js +0 -2
- package/bin/chunk-rhh716z0.js +0 -42
- package/bin/chunk-rza4ae5z.js +0 -3
- package/bin/chunk-sk4e6rb1.js +0 -1
- package/bin/chunk-t2n1dbgx.js +0 -4
- package/bin/chunk-x8f4defx.js +0 -3
- package/bin/chunk-z3gkt8w1.js +0 -3
- package/bin/chunk-zh6fqq44.js +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{u,C,B,t,o,L,be,ve,S,bn,wn,vn,xn,Ee,Ie,Te,ge,Ae,ye,Ec,la,gA,AA,vA,xA,SA,ym,ke,Ps,sh,mb,yb,wb,Wb,bw,ww,bv,wv,Zc,yS,rp,wS,vl,AC,yC,Os,AE,Nd,Ep,Je,Xe,et,tt,rt,nt,ot,st,pe,ue,me,de,H,R}from"./chunk-7rhz2gze.js";import{ao}from"./chunk-rq0n0vcc.js";import{Rr}from"./chunk-0zv3bks2.js";C();function Fl({open:F,onOpenChange:V,title:U,members:_,isOwner:i,onInvite:g,onUpdateRole:D,onRemoveMember:y,currentUserId:q,availableMembersToAdd:M,onAddMember:c,type:n="team"}){let[x,b]=u("editor"),[m,A]=u(null),[T,j]=u(!1),[f,p]=u(null),[l,w]=u(null),[I,k]=u({}),[s,d]=u(null),v=(e)=>{if(!e)return"";switch(e.toLowerCase()){case"owner":return Zc();case"editor":return Ps();case"reviewer":return Os();default:return e}},z=(e,a)=>{k((r)=>({...r,[e]:a}))},E=async(e,a)=>{if(!D)return;p(e);try{await D(e,a),R.success(wv())}catch(r){console.error(r),R.error(wb())}finally{p(null)}},J=async()=>{if(!y||!l?.id)return;p(l.id);try{await y(l.id),R.success(bv()),w(null)}catch(e){console.error(e),R.error(yb())}finally{p(null)}},K=async()=>{if(!g)return;j(!0);try{let e=await g(x),a=`${window.location.origin}/signup?inviteCode=${e}`;A(a)}catch(e){console.error(e),R.error(mb())}finally{j(!1)}},O=async()=>{if(m){if(await ao(m))R.success(bw())}},h=(e)=>{if(!e)return"??";return e.split(" ").map((a)=>a[0]).slice(0,2).join("").toUpperCase()},Q=(e)=>{if(!e)A(null),b("editor"),k({}),d(null);V(e)},N=Array.isArray(_)?_:[],W=Array.isArray(M)?M:[],X=n==="project"&&i?N.filter((e)=>e.role==="owner"||e.scope==="project"||e.hasCustomRole):N,P=n==="project"&&i?N.filter((e)=>e.scope==="team"&&e.role!=="owner"&&!e.hasCustomRole):[],G=n==="project"&&i?W.filter((e)=>e.scope==="project"):[];return t(pe,{open:F,onOpenChange:Q,children:o(ue,{className:"sm:max-w-xl",onOpenAutoFocus:(e)=>e.preventDefault(),children:[t(me,{children:t(de,{children:U})}),o("div",{className:"space-y-4",children:[t("div",{className:"max-h-[300px] overflow-y-auto space-y-2",children:X.map((e)=>{let a=n==="team"&&e.scope==="project";return o("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-muted/50",children:[o("div",{className:"flex items-center gap-3",children:[o(Ee,{children:[e.image&&t(Ie,{src:e.image,alt:e.name,className:"object-cover"}),t(Te,{children:h(e.name)})]}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:e.name}),o("div",{className:"flex items-center gap-2",children:[!a&&t("span",{className:"text-xs text-muted-foreground capitalize",children:v(e.role)}),e.scope&&o(B,{children:[!a&&t("span",{className:"text-[10px] text-muted-foreground/70",children:"•"}),t("span",{className:"text-xs text-muted-foreground capitalize",children:e.scope==="team"?Ep():rp()})]})]})]})]}),i&&e.role!=="owner"&&e.id!==q&&o("div",{className:"flex items-center gap-2",children:[a?t(bn,{children:o(wn,{children:[t(vn,{asChild:!0,children:t("span",{children:t(S,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs capitalize w-26 justify-between",disabled:!0,children:t(be,{className:"ml-auto h-3 w-3 opacity-50"})})})}),t(xn,{side:"top",children:t("p",{className:"text-xs",children:wS()})})]})}):o(ge,{children:[t(Ae,{asChild:!0,children:o(S,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs capitalize w-26",disabled:f===e.id,children:[v(e.role),t(be,{className:"ml-1 h-3 w-3 opacity-50"})]})}),t(ye,{children:o(Ec,{value:e.role,onValueChange:(r)=>E(e.id,r),children:[t(la,{value:"editor",className:"text-xs",children:Ps()}),t(la,{value:"reviewer",className:"text-xs",children:Os()})]})})]}),t(S,{variant:"ghost",size:"icon",className:"h-8 w-8 text-destructive hover:text-destructive hover:bg-destructive/10",onClick:()=>w(e),disabled:f===e.id,children:f===e.id?t(L,{className:"h-3 w-3 animate-spin"}):t(ve,{className:"h-3 w-3"})})]})]},e.id)})}),t(Je,{open:!!l,onOpenChange:(e)=>!e&&w(null),children:o(Xe,{children:[o(et,{children:[t(rt,{children:AC()}),t(nt,{children:yC({name:l?.name||"",type:n==="project"?yS():Nd()})})]}),o(tt,{children:[t(st,{children:ke()}),t(ot,{onClick:J,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:vl()})]})]})})," ",i&&c&&P.length>0&&o("div",{className:"border-t pt-4",children:[t("h4",{className:"text-sm font-medium mb-1",children:vA()}),t("p",{className:"text-xs text-muted-foreground mb-3 font-normal",children:xA()}),t("div",{className:"max-h-[200px] overflow-y-auto space-y-2 pr-1",children:P.map((e)=>{let a=I[e.id]||"editor";return o("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-muted/50",children:[o("div",{className:"flex items-center gap-3",children:[o(Ee,{children:[e.image&&t(Ie,{src:e.image,alt:e.name,className:"object-cover"}),t(Te,{children:h(e.name)})]}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:e.name}),t("span",{className:"text-xs text-muted-foreground capitalize",children:e.scope==="team"?Ep():rp()})]})]}),o("div",{className:"flex items-center gap-2",children:[o(ge,{children:[t(Ae,{asChild:!0,children:o(S,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs capitalize w-26",disabled:s===e.id,children:[v(a),t(be,{className:"ml-1 h-3 w-3 opacity-50"})]})}),t(ye,{children:o(Ec,{value:a,onValueChange:(r)=>z(e.id,r),children:[t(la,{value:"editor",className:"text-xs",children:Ps()}),t(la,{value:"reviewer",className:"text-xs",children:Os()})]})})]}),t(S,{onClick:async()=>{d(e.id);try{await c(e.id,a),R.success(ym({name:e.name||""}))}catch(r){console.error(r),R.error(sh({name:e.name||""}))}finally{d(null)}},disabled:s!==null,size:"sm",className:"h-8 text-xs px-3",children:s===e.id?t(L,{className:"h-3 w-3 animate-spin"}):AE()})]})]},e.id)})})]}),i&&c&&G.length>0&&o("div",{className:"border-t pt-4",children:[t("h4",{className:"text-sm font-medium mb-1",children:gA()}),t("p",{className:"text-xs text-muted-foreground mb-3 font-normal",children:AA()}),t("div",{className:"max-h-[200px] overflow-y-auto space-y-2 pr-1",children:G.map((e)=>{let a=I[e.id]||"editor";return o("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-muted/50",children:[o("div",{className:"flex items-center gap-3",children:[o(Ee,{children:[e.image&&t(Ie,{src:e.image,alt:e.name,className:"object-cover"}),t(Te,{children:h(e.name)})]}),o("div",{className:"flex flex-col",children:[t("span",{className:"text-sm font-medium",children:e.name}),t("span",{className:"text-xs text-muted-foreground capitalize",children:e.scope==="team"?Ep():rp()})]})]}),o("div",{className:"flex items-center gap-2",children:[o(ge,{children:[t(Ae,{asChild:!0,children:o(S,{variant:"outline",size:"sm",className:"h-8 px-2 text-xs capitalize w-26",disabled:s===e.id,children:[v(a),t(be,{className:"ml-1 h-3 w-3 opacity-50"})]})}),t(ye,{children:o(Ec,{value:a,onValueChange:(r)=>z(e.id,r),children:[t(la,{value:"editor",className:"text-xs",children:Ps()}),t(la,{value:"reviewer",className:"text-xs",children:Os()})]})})]}),t(S,{onClick:async()=>{d(e.id);try{await c(e.id,a),R.success(ym({name:e.name||""}))}catch(r){console.error(r),R.error(sh({name:e.name||""}))}finally{d(null)}},disabled:s!==null,size:"sm",className:"h-8 text-xs px-3",children:s===e.id?t(L,{className:"h-3 w-3 animate-spin"}):SA()})]})]},e.id)})})]}),i&&g&&o("div",{className:"border-t pt-4",children:[t("h4",{className:"text-sm font-medium mb-3",children:ww()}),o("div",{className:"space-y-3",children:[o("div",{className:"flex gap-2",children:[o(ge,{children:[t(Ae,{asChild:!0,children:o(S,{variant:"outline",className:"w-[120px] justify-between",children:[x==="editor"?Ps():Os(),t(be,{className:"h-4 w-4 opacity-50"})]})}),t(ye,{children:o(Ec,{value:x,onValueChange:(e)=>b(e),children:[t(la,{value:"editor",children:Ps()}),t(la,{value:"reviewer",children:Os()})]})})]}),o(S,{onClick:K,disabled:T,className:"flex-1",children:[T&&t(L,{className:"mr-2 h-4 w-4 animate-spin"}),Wb()]})]}),m&&o("div",{className:"flex gap-2",children:[t(H,{value:m,readOnly:!0}),t(S,{variant:"outline",size:"icon",onClick:O,children:t(Rr,{className:"h-4 w-4"})})]})]})]})]})]})})}
|
|
2
|
+
export{Fl};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{kt}from"./chunk-5tcdwep5.js";import{He}from"./chunk-jgs8an3h.js";import{z}from"./chunk-fnmwksnb.js";var f=z(He());var N=z(He());var m=z(kt()),l=z(He());var E=z(kt()),d=z(He()),P=(e,t,r)=>{let o={EcsContainer:async(s)=>{let{fromHttp:i}=await import("./chunk-zw86wnwe.js"),{fromContainerMetadata:n}=await import("./chunk-6ghcj4a9.js");return r?.debug("@aws-sdk/credential-provider-ini - credential_source is EcsContainer"),async()=>d.chain(i(s??{}),n(s))().then(_)},Ec2InstanceMetadata:async(s)=>{r?.debug("@aws-sdk/credential-provider-ini - credential_source is Ec2InstanceMetadata");let{fromInstanceMetadata:i}=await import("./chunk-6ghcj4a9.js");return async()=>i(s)().then(_)},Environment:async(s)=>{r?.debug("@aws-sdk/credential-provider-ini - credential_source is Environment");let{fromEnv:i}=await import("./chunk-gye8gabk.js");return async()=>i(s)().then(_)}};if(e in o)return o[e];else throw new d.CredentialsProviderError(`Unsupported credential source in profile ${t}. Got ${e}, expected EcsContainer or Ec2InstanceMetadata or Environment.`,{logger:r})},_=(e)=>E.setCredentialFeature(e,"CREDENTIALS_PROFILE_NAMED_PROVIDER","p");var v=(e,{profile:t="default",logger:r}={})=>Boolean(e)&&typeof e==="object"&&typeof e.role_arn==="string"&&["undefined","string"].indexOf(typeof e.role_session_name)>-1&&["undefined","string"].indexOf(typeof e.external_id)>-1&&["undefined","string"].indexOf(typeof e.mfa_serial)>-1&&(K(e,{profile:t,logger:r})||G(e,{profile:t,logger:r})),K=(e,{profile:t,logger:r})=>{let o=typeof e.source_profile==="string"&&typeof e.credential_source>"u";if(o)r?.debug?.(` ${t} isAssumeRoleWithSourceProfile source_profile=${e.source_profile}`);return o},G=(e,{profile:t,logger:r})=>{let o=typeof e.credential_source==="string"&&typeof e.source_profile>"u";if(o)r?.debug?.(` ${t} isCredentialSourceProfile credential_source=${e.credential_source}`);return o},I=async(e,t,r,o,s={},i)=>{r.logger?.debug("@aws-sdk/credential-provider-ini - resolveAssumeRoleCredentials (STS)");let n=t[e],{source_profile:a,region:j}=n;if(!r.roleAssumer){let{getDefaultRoleAssumer:c}=await import("./chunk-7bcxj1jd.js");r.roleAssumer=c({...r.clientConfig,credentialProviderLogger:r.logger,parentClientConfig:{...o,...r?.parentClientConfig,region:j??r?.parentClientConfig?.region??o?.region}},r.clientPlugins)}if(a&&a in s)throw new l.CredentialsProviderError(`Detected a cycle attempting to resolve credentials for profile ${l.getProfileName(r)}. Profiles visited: `+Object.keys(s).join(", "),{logger:r.logger});r.logger?.debug(`@aws-sdk/credential-provider-ini - finding credential resolver using ${a?`source_profile=[${a}]`:`profile=[${e}]`}`);let w=a?i(a,t,r,o,{...s,[a]:!0},S(t[a]??{})):(await P(n.credential_source,e,r.logger)(r))();if(S(n))return w.then((c)=>m.setCredentialFeature(c,"CREDENTIALS_PROFILE_SOURCE_PROFILE","o"));else{let c={RoleArn:n.role_arn,RoleSessionName:n.role_session_name||`aws-sdk-js-${Date.now()}`,ExternalId:n.external_id,DurationSeconds:parseInt(n.duration_seconds||"3600",10)},{mfa_serial:u}=n;if(u){if(!r.mfaCodeProvider)throw new l.CredentialsProviderError(`Profile ${e} requires multi-factor authentication, but no MFA code callback was provided.`,{logger:r.logger,tryNextLink:!1});c.SerialNumber=u,c.TokenCode=await r.mfaCodeProvider(u)}let M=await w;return r.roleAssumer(M,c).then((B)=>m.setCredentialFeature(B,"CREDENTIALS_PROFILE_SOURCE_PROFILE","o"))}},S=(e)=>!e.role_arn&&!!e.credential_source;var R=z(kt()),A=(e)=>Boolean(e&&e.login_session),L=async(e,t,r)=>{let{fromLoginCredentials:o}=await import("./chunk-drepsbb4.js"),s=await o({...t,profile:e})({callerClientConfig:r});return R.setCredentialFeature(s,"CREDENTIALS_PROFILE_LOGIN","AC")};var O=z(kt()),b=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.credential_process==="string",x=async(e,t)=>{let{fromProcess:r}=await import("./chunk-wjyaezs7.js"),o=await r({...e,profile:t})();return O.setCredentialFeature(o,"CREDENTIALS_PROFILE_PROCESS","v")};var p=z(kt()),k=async(e,t,r={},o)=>{let{fromSSO:s}=await import("./chunk-vm5fx7td.js");return s({profile:e,logger:r.logger,parentClientConfig:r.parentClientConfig,clientConfig:r.clientConfig})({callerClientConfig:o}).then((i)=>{if(t.sso_session)return p.setCredentialFeature(i,"CREDENTIALS_PROFILE_SSO","r");else return p.setCredentialFeature(i,"CREDENTIALS_PROFILE_SSO_LEGACY","t")})},F=(e)=>e&&(typeof e.sso_start_url==="string"||typeof e.sso_account_id==="string"||typeof e.sso_session==="string"||typeof e.sso_region==="string"||typeof e.sso_role_name==="string");var h=z(kt()),C=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.aws_access_key_id==="string"&&typeof e.aws_secret_access_key==="string"&&["undefined","string"].indexOf(typeof e.aws_session_token)>-1&&["undefined","string"].indexOf(typeof e.aws_account_id)>-1,y=async(e,t)=>{t?.logger?.debug("@aws-sdk/credential-provider-ini - resolveStaticCredentials");let r={accessKeyId:e.aws_access_key_id,secretAccessKey:e.aws_secret_access_key,sessionToken:e.aws_session_token,...e.aws_credential_scope&&{credentialScope:e.aws_credential_scope},...e.aws_account_id&&{accountId:e.aws_account_id}};return h.setCredentialFeature(r,"CREDENTIALS_PROFILE","n")};var D=z(kt()),T=(e)=>Boolean(e)&&typeof e==="object"&&typeof e.web_identity_token_file==="string"&&typeof e.role_arn==="string"&&["undefined","string"].indexOf(typeof e.role_session_name)>-1,W=async(e,t,r)=>{let{fromTokenFile:o}=await import("./chunk-s2fnfyn9.js"),s=await o({webIdentityTokenFile:e.web_identity_token_file,roleArn:e.role_arn,roleSessionName:e.role_session_name,roleAssumerWithWebIdentity:t.roleAssumerWithWebIdentity,logger:t.logger,parentClientConfig:t.parentClientConfig})({callerClientConfig:r});return D.setCredentialFeature(s,"CREDENTIALS_PROFILE_STS_WEB_ID_TOKEN","q")};var g=async(e,t,r,o,s={},i=!1)=>{let n=t[e];if(Object.keys(s).length>0&&C(n))return y(n,r);if(i||v(n,{profile:e,logger:r.logger}))return I(e,t,r,o,s,g);if(C(n))return y(n,r);if(T(n))return W(n,r,o);if(b(n))return x(r,e);if(F(n))return await k(e,n,r,o);if(A(n))return L(e,r,o);throw new N.CredentialsProviderError(`Could not resolve credentials using profile: [${e}] in configuration/credentials file(s).`,{logger:r.logger})};var U=(e={})=>async({callerClientConfig:t}={})=>{e.logger?.debug("@aws-sdk/credential-provider-ini - fromIni");let r=await f.parseKnownFiles(e);return g(f.getProfileName({profile:e.profile??t?.profile}),r,e,t)};export{U as fromIni};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{kt}from"./chunk-5tcdwep5.js";import{He}from"./chunk-jgs8an3h.js";import{z}from"./chunk-fnmwksnb.js";var a=z(kt()),t=z(He());import{readFileSync as p}from"fs";var c=(e)=>async(s)=>{e.logger?.debug("@aws-sdk/credential-provider-web-identity - fromWebToken");let{roleArn:o,roleSessionName:r,webIdentityToken:i,providerId:n,policyArns:m,policy:f,durationSeconds:g}=e,{roleAssumerWithWebIdentity:l}=e;if(!l){let{getDefaultRoleAssumerWithWebIdentity:E}=await import("./chunk-7bcxj1jd.js");l=E({...e.clientConfig,credentialProviderLogger:e.logger,parentClientConfig:{...s?.callerClientConfig,...e.parentClientConfig}},e.clientPlugins)}return l({RoleArn:o,RoleSessionName:r??`aws-sdk-js-session-${Date.now()}`,WebIdentityToken:i,ProviderId:n,PolicyArns:m,Policy:f,DurationSeconds:g})};var d="AWS_WEB_IDENTITY_TOKEN_FILE",_="AWS_ROLE_ARN",S="AWS_ROLE_SESSION_NAME",T=(e={})=>async(s)=>{e.logger?.debug("@aws-sdk/credential-provider-web-identity - fromTokenFile");let o=e?.webIdentityTokenFile??process.env[d],r=e?.roleArn??process.env[_],i=e?.roleSessionName??process.env[S];if(!o||!r)throw new t.CredentialsProviderError("Web identity configuration not specified",{logger:e.logger});let n=await c({...e,webIdentityToken:t.externalDataInterceptor?.getTokenRecord?.()[o]??p(o,{encoding:"ascii"}),roleArn:r,roleSessionName:i})(s);if(o===process.env[d])a.setCredentialFeature(n,"CREDENTIALS_ENV_VARS_STS_WEB_ID_TOKEN","h");return n};export{T as fromTokenFile};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{Cn,$t,No,sa,Na,Oa,Qt,vr,f,Fl,En,ze,sn,Dp,_o,Dd,Zt,qo,bo,wr,Oo,nu}from"./chunk-v9b3w8q5.js";function rr(e){return vr(e)&&Qt(e.toOperationNode)}var Lr=f({is(e){return e.kind==="ValueNode"},create(e){return f({kind:"ValueNode",value:e})},createImmediate(e){return f({kind:"ValueNode",value:e,immediate:!0})}});var l=f({is(e){return e.kind==="AliasNode"},create(e,r){return f({kind:"AliasNode",node:e,alias:r})}});var Dt=f({is(e){return e.kind==="ColumnNode"},create(e){return f({kind:"ColumnNode",column:ze.create(e)})}});var Pi=f({is(e){return e.kind==="SelectAllNode"},create(){return f({kind:"SelectAllNode"})}});var te=f({is(e){return e.kind==="ReferenceNode"},create(e,r){return f({kind:"ReferenceNode",table:r,column:e})},createSelectAll(e){return f({kind:"ReferenceNode",table:e,column:Pi.create()})}});var g=f({is(e){return e.kind==="TableNode"},create(e){return f({kind:"TableNode",table:sn.create(e)})},createWithSchema(e,r){return f({kind:"TableNode",table:sn.createWithSchema(e,r)})}});function Ce(e){return vr(e)&&"expressionType"in e&&rr(e)}function Wr(e){return vr(e)&&"expression"in e&&$t(e.alias)&&rr(e)}var D=f({is(e){return e.kind==="SelectModifierNode"},create(e,r){return f({kind:"SelectModifierNode",modifier:e,of:r})},createWithExpression(e){return f({kind:"SelectModifierNode",rawModifier:e})}});var W=f({is(e){return e.kind==="AndNode"},create(e,r){return f({kind:"AndNode",left:e,right:r})}});var C=f({is(e){return e.kind==="OrNode"},create(e,r){return f({kind:"OrNode",left:e,right:r})}});var Re=f({is(e){return e.kind==="OnNode"},create(e){return f({kind:"OnNode",on:e})},cloneWithOperation(e,r,t){return f({...e,on:r==="And"?W.create(e.on,t):C.create(e.on,t)})}});var R=f({is(e){return e.kind==="JoinNode"},create(e,r){return f({kind:"JoinNode",joinType:e,table:r,on:void 0})},createWithOn(e,r,t){return f({kind:"JoinNode",joinType:e,table:r,on:Re.create(t)})},cloneWithOn(e,r){return f({...e,on:e.on?Re.cloneWithOperation(e.on,"And",r):Re.create(r)})}});var I=f({is(e){return e.kind==="BinaryOperationNode"},create(e,r,t){return f({kind:"BinaryOperationNode",leftOperand:e,operator:r,rightOperand:t})}});var Te=f({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return f({kind:"PrimitiveValueListNode",values:f([...e])})}});var ys=f({is(e){return e.kind==="ValueListNode"},create(e){return f({kind:"ValueListNode",values:f(e)})}});function br(e){if(En(e))return yt(e);return m(e)}function m(e){if(V(e))return to(e);return Lr.create(e)}function Ae(e){return No(e)||sa(e)||Na(e)}function pe(e){if(!Ae(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return Lr.createImmediate(e)}function yt(e){if(e.some(V))return ys.create(e.map((r)=>m(r)));return Te.create(e)}function Yt(e){if(e.length===3)return qe(e[0],e[1],e[2]);else if(e.length===1)return m(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function qe(e,r,t){if(wt(r)&&kr(t))return I.create(w(e),_e(r),Lr.createImmediate(t));return I.create(w(e),_e(r),br(t))}function N(e,r,t){return I.create(w(e),_e(r),w(t))}function je(e,r){return oe(Object.entries(e).filter(([,t])=>!Cn(t)).map(([t,o])=>qe(t,kr(o)?"is":"=",o)),r)}function oe(e,r,t=!0){let o=r==="and"?W.create:C.create;if(e.length===0)return I.create(Lr.createImmediate(1),_o.create("="),Lr.createImmediate(r==="and"?1:0));let n=Sr(e[0]);for(let u=1;u<e.length;++u)n=o(n,Sr(e[u]));if(e.length>1&&t)return bo.create(n);return n}function wt(e){return e==="is"||e==="is not"}function kr(e){return Na(e)||sa(e)}function _e(e){if($t(e)&&Dp.includes(e))return _o.create(e);if(rr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function Sr(e){return rr(e)?e.toOperationNode():e}var U=f({is(e){return e.kind==="OrderByNode"},create(e){return f({kind:"OrderByNode",items:f([...e])})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var Ge=f({is(e){return e.kind==="PartitionByNode"},create(e){return f({kind:"PartitionByNode",items:f(e)})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var Ne=f({is(e){return e.kind==="OverNode"},create(){return f({kind:"OverNode"})},cloneWithOrderByItems(e,r){return f({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithPartitionByItems(e,r){return f({...e,partitionBy:e.partitionBy?Ge.cloneWithItems(e.partitionBy,r):Ge.create(r)})}});var X=f({is(e){return e.kind==="FromNode"},create(e){return f({kind:"FromNode",froms:f(e)})},cloneWithFroms(e,r){return f({...e,froms:f([...e.froms,...r])})}});var Ke=f({is(e){return e.kind==="GroupByNode"},create(e){return f({kind:"GroupByNode",items:f(e)})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var He=f({is(e){return e.kind==="HavingNode"},create(e){return f({kind:"HavingNode",having:e})},cloneWithOperation(e,r,t){return f({...e,having:r==="And"?W.create(e.having,t):C.create(e.having,t)})}});var Le=f({is(e){return e.kind==="ListNode"},create(e){return f({kind:"ListNode",items:f(e)})}});var F=f({is(e){return e.kind==="UpdateQueryNode"},create(e,r){return f({kind:"UpdateQueryNode",table:e.length===1?e[0]:Le.create(e),...r&&{with:r}})},createWithoutTable(){return f({kind:"UpdateQueryNode"})},cloneWithFromItems(e,r){return f({...e,from:e.from?X.cloneWithFroms(e.from,r):X.create(r)})},cloneWithUpdates(e,r){return f({...e,updates:e.updates?f([...e.updates,...r]):r})},cloneWithLimit(e,r){return f({...e,limit:r})}});var ye=f({is(e){return e.kind==="UsingNode"},create(e){return f({kind:"UsingNode",tables:f(e)})},cloneWithTables(e,r){return f({...e,tables:f([...e.tables,...r])})}});var _=f({is(e){return e.kind==="DeleteQueryNode"},create(e,r){return f({kind:"DeleteQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithOrderByItems:(e,r)=>le.cloneWithOrderByItems(e,r),cloneWithoutOrderBy:(e)=>le.cloneWithoutOrderBy(e),cloneWithLimit(e,r){return f({...e,limit:r})},cloneWithoutLimit(e){return f({...e,limit:void 0})},cloneWithUsing(e,r){return f({...e,using:e.using!==void 0?ye.cloneWithTables(e.using,r):ye.create(r)})}});var O=f({is(e){return e.kind==="WhereNode"},create(e){return f({kind:"WhereNode",where:e})},cloneWithOperation(e,r,t){return f({...e,where:r==="And"?W.create(e.where,t):C.create(e.where,t)})}});var Xe=f({is(e){return e.kind==="ReturningNode"},create(e){return f({kind:"ReturningNode",selections:f(e)})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})}});var Er=f({is(e){return e.kind==="ExplainNode"},create(e,r){return f({kind:"ExplainNode",format:e,options:r})}});var k=f({is(e){return e.kind==="MergeQueryNode"},create(e,r){return f({kind:"MergeQueryNode",into:e,...r&&{with:r}})},cloneWithUsing(e,r){return f({...e,using:r})},cloneWithWhen(e,r){return f({...e,whens:e.whens?f([...e.whens,r]):f([r])})},cloneWithThen(e,r){return f({...e,whens:e.whens?f([...e.whens.slice(0,-1),Oo.cloneWithResult(e.whens[e.whens.length-1],r)]):void 0})}});var Ye=f({is(e){return e.kind==="OutputNode"},create(e){return f({kind:"OutputNode",selections:f(e)})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})}});var le=f({is(e){return jt.is(e)||wr.is(e)||F.is(e)||_.is(e)||k.is(e)},cloneWithEndModifier(e,r){return f({...e,endModifiers:e.endModifiers?f([...e.endModifiers,r]):f([r])})},cloneWithWhere(e,r){return f({...e,where:e.where?O.cloneWithOperation(e.where,"And",r):O.create(r)})},cloneWithJoin(e,r){return f({...e,joins:e.joins?f([...e.joins,r]):f([r])})},cloneWithReturning(e,r){return f({...e,returning:e.returning?Xe.cloneWithSelections(e.returning,r):Xe.create(r)})},cloneWithoutReturning(e){return f({...e,returning:void 0})},cloneWithoutWhere(e){return f({...e,where:void 0})},cloneWithExplain(e,r,t){return f({...e,explain:Er.create(r,t?.toOperationNode())})},cloneWithTop(e,r){return f({...e,top:r})},cloneWithOutput(e,r){return f({...e,output:e.output?Ye.cloneWithSelections(e.output,r):Ye.create(r)})},cloneWithOrderByItems(e,r){return f({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithoutOrderBy(e){return f({...e,orderBy:void 0})}});var jt=f({is(e){return e.kind==="SelectQueryNode"},create(e){return f({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,r){return f({kind:"SelectQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})},cloneWithDistinctOn(e,r){return f({...e,distinctOn:e.distinctOn?f([...e.distinctOn,...r]):f(r)})},cloneWithFrontModifier(e,r){return f({...e,frontModifiers:e.frontModifiers?f([...e.frontModifiers,r]):f([r])})},cloneWithOrderByItems:(e,r)=>le.cloneWithOrderByItems(e,r),cloneWithGroupByItems(e,r){return f({...e,groupBy:e.groupBy?Ke.cloneWithItems(e.groupBy,r):Ke.create(r)})},cloneWithLimit(e,r){return f({...e,limit:r})},cloneWithOffset(e,r){return f({...e,offset:r})},cloneWithFetch(e,r){return f({...e,fetch:r})},cloneWithHaving(e,r){return f({...e,having:e.having?He.cloneWithOperation(e.having,"And",r):He.create(r)})},cloneWithSetOperations(e,r){return f({...e,setOperations:e.setOperations?f([...e.setOperations,...r]):f([...r])})},cloneWithoutSelections(e){return f({...e,selections:[]})},cloneWithoutLimit(e){return f({...e,limit:void 0})},cloneWithoutOffset(e){return f({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>le.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return f({...e,groupBy:void 0})}});class ie{#e;constructor(e){this.#e=f(e)}on(...e){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,Yt(e))})}onRef(e,r,t){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,N(e,r,t))})}onTrue(){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,Zt.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}}class Pd{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return Ze(this.#e)}}function Be(e){return vr(e)&&rr(e)&&$t(e.dynamicReference)}var T=f({is(e){return e.kind==="OrderByItemNode"},create(e,r){return f({kind:"OrderByItemNode",orderBy:e,direction:r})},cloneWith(e,r){return f({...e,...r})}});var Cr=f({is(e){return e.kind==="CollateNode"},create(e){return f({kind:"CollateNode",collation:ze.create(e)})}});class j{#e;constructor(e){this.#e=f(e)}desc(){return new j({node:T.cloneWith(this.#e.node,{direction:Zt.createWithSql("desc")})})}asc(){return new j({node:T.cloneWith(this.#e.node,{direction:Zt.createWithSql("asc")})})}nullsLast(){return new j({node:T.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new j({node:T.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new j({node:T.cloneWith(this.#e.node,{collation:Cr.create(e)})})}toOperationNode(){return this.#e.node}}function tr(e){return e==="asc"||e==="desc"}function E(e){if(e.length===2)return[er(e[0],e[1])];if(e.length===1){let[r]=e;if(Array.isArray(r))return qo("orderBy(array) is deprecated, use multiple orderBy calls instead."),r.map((t)=>er(t));return[er(r)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function er(e,r){let t=Ot(e);if(T.is(t)){if(r)throw Error("Cannot specify direction twice!");return t}return Rr(t,r)}function Ot(e){if(V(e))return to(e);if(Be(e))return e.toOperationNode();let[r,t]=e.split(" ");if(t)return qo("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Rr(Ao(r),t);return Ao(e)}function Rr(e,r){if(typeof r==="string"){if(!tr(r))throw Error(`Invalid order by direction: ${r}`);return T.create(e,Zt.createWithSql(r))}if(Ce(r))return qo("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),T.create(e,r.toOperationNode());let t=T.create(e);if(!r)return t;return r(new j({node:t})).toOperationNode()}var Tr=f({is(e){return e.kind==="PartitionByItemNode"},create(e){return f({kind:"PartitionByItemNode",partitionBy:e})}});function Ar(e){return z(e).map(Tr.create)}class ne{#e;constructor(e){this.#e=f(e)}orderBy(...e){return new ne({overNode:Ne.cloneWithOrderByItems(this.#e.overNode,E(e))})}clearOrderBy(){return new ne({overNode:le.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new ne({overNode:Ne.cloneWithPartitionByItems(this.#e.overNode,Ar(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var se=f({is(e){return e.kind==="SelectionNode"},create(e){return f({kind:"SelectionNode",selection:e})},createSelectAll(){return f({kind:"SelectionNode",selection:Pi.create()})},createSelectAllFromTable(e){return f({kind:"SelectionNode",selection:te.createSelectAll(e)})}});class Od{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new qr(this.#e,e)}}class qr{#e;#r;get table(){return this.#e}get alias(){return this.#r}constructor(e,r){this.#e=e,this.#r=r}toOperationNode(){return l.create(Ut(this.#e),ze.create(this.#r))}}function Br(e){return vr(e)&&rr(e)&&$t(e.table)&&$t(e.alias)}function A(e){if(En(e))return e.map((r)=>Y(r));else return[Y(e)]}function Y(e){if($t(e))return or(e);else if(Br(e))return e.toOperationNode();else return De(e)}function or(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(Dr);return l.create(Ut(t),ze.create(o))}else return Ut(e)}function Ut(e){if(e.includes(".")){let[t,o]=e.split(".").map(Dr);return g.createWithSchema(t,o)}else return g.create(e)}function Dr(e){return e.trim()}function p(e){if(Qt(e))return p(e(q()));else if(En(e))return e.map((r)=>Fr(r));else return[Fr(e)]}function Fr(e){if($t(e))return se.create(Mr(e));else if(Be(e))return se.create(e.toOperationNode());else return se.create(De(e))}function y(e){if(!e)return[se.createSelectAll()];else if(Array.isArray(e))return e.map(Pr);else return[Pr(e)]}function Pr(e){if($t(e))return se.createSelectAllFromTable(Ut(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Vr=f({is(e){return e.kind==="ValuesNode"},create(e){return f({kind:"ValuesNode",values:f(e)})}});var Ur=f({is(e){return e.kind==="DefaultInsertValueNode"},create(){return f({kind:"DefaultInsertValueNode"})}});function Fe(e){let r=Qt(e)?e(q()):e,t=En(r)?r:f([r]);return xt(t)}function xt(e){let r=gt(e);return[f([...r.keys()].map(Dt.create)),Vr.create(e.map((t)=>Wt(t,r)))]}function gt(e){let r=new Map;for(let t of e){let o=Object.keys(t);for(let n of o)if(!r.has(n)&&t[n]!==void 0)r.set(n,r.size)}return r}function Wt(e,r){let t=Object.keys(e),o=Array.from({length:r.size}),n=!1,u=t.length;for(let Ee of t){let fe=r.get(Ee);if(Cn(fe)){u--;continue}let $e=e[Ee];if(Cn($e)||V($e))n=!0;o[fe]=$e}if(u<r.size||n){let Ee=Ur.create();return ys.create(o.map((fe)=>Cn(fe)?Ee:m(fe)))}return Te.create(o)}var ir=f({is(e){return e.kind==="ColumnUpdateNode"},create(e,r){return f({kind:"ColumnUpdateNode",column:e,value:r})}});function zr(...e){if(e.length===2)return[ir.create(w(e[0]),m(e[1]))];return we(e[0])}function we(e){let r=Qt(e)?e(q()):e;return Object.entries(r).filter(([t,o])=>o!==void 0).map(([t,o])=>ir.create(Dt.create(t),m(o)))}var Jr=f({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return f({kind:"OnDuplicateKeyNode",updates:e})}});class nr{insertId;numInsertedOrUpdatedRows;constructor(e,r){this.insertId=e,this.numInsertedOrUpdatedRows=r}}class L extends Error{node;constructor(e){super("no result");this.node=e}}function v(e){return Object.prototype.hasOwnProperty.call(e,"prototype")}var x=f({is(e){return e.kind==="OnConflictNode"},create(){return f({kind:"OnConflictNode"})},cloneWith(e,r){return f({...e,...r})},cloneWithIndexWhere(e,r){return f({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",r):O.create(r)})},cloneWithIndexOrWhere(e,r){return f({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",r):O.create(r)})},cloneWithUpdateWhere(e,r){return f({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",r):O.create(r)})},cloneWithUpdateOrWhere(e,r){return f({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",r):O.create(r)})},cloneWithoutIndexWhere(e){return f({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return f({...e,updateWhere:void 0})}});class P{#e;constructor(e){this.#e=f(e)}column(e){let r=Dt.create(e);return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?f([...this.#e.onConflictNode.columns,r]):f([r])})})}columns(e){let r=e.map(Dt.create);return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?f([...this.#e.onConflictNode.columns,...r]):f(r)})})}constraint(e){return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{constraint:ze.create(e)})})}expression(e){return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new P({...this.#e,onConflictNode:x.cloneWithIndexWhere(this.#e.onConflictNode,Yt(e))})}whereRef(e,r,t){return new P({...this.#e,onConflictNode:x.cloneWithIndexWhere(this.#e.onConflictNode,N(e,r,t))})}clearWhere(){return new P({...this.#e,onConflictNode:x.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Qr({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Oe({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{updates:we(e)})})}$call(e){return e(this)}}class Qr{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.onConflictNode}}class Oe{#e;constructor(e){this.#e=f(e)}where(...e){return new Oe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,Yt(e))})}whereRef(e,r,t){return new Oe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,N(e,r,t))})}clearWhere(){return new Oe({...this.#e,onConflictNode:x.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var Ir=f({is(e){return e.kind==="TopNode"},create(e,r){return f({kind:"TopNode",expression:e,modifiers:r})}});function B(e,r){if(!No(e)&&!Oa(e))throw Error(`Invalid top expression: ${e}`);if(!Cn(r)&&!bt(r))throw Error(`Invalid top modifiers: ${r}`);return Ir.create(e,r)}function bt(e){return e==="percent"||e==="with ties"||e==="percent with ties"}var Z=f({is(e){return e.kind==="OrActionNode"},create(e){return f({kind:"OrActionNode",action:e})}});class d{#e;constructor(e){this.#e=f(e)}values(e){let[r,t]=Fe(e);return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{columns:r,values:t})})}columns(e){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{columns:f(e.map(Dt.create))})})}expression(e){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{values:to(e)})})}defaultValues(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new d({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orIgnore(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orAbort(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("abort")})})}orFail(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("fail")})})}orReplace(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("replace")})})}orRollback(){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{orAction:Z.create("rollback")})})}top(e,r){return new d({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}onConflict(e){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{onConflict:e(new P({onConflictNode:x.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new d({...this.#e,queryNode:wr.cloneWith(this.#e.queryNode,{onDuplicateKey:Jr.create(we(e))})})}returning(e){return new d({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(){return new d({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new d({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new d({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new d({...this.#e,queryNode:le.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new d({...this.#e})}$castTo(){return new d(this.#e)}$narrowType(){return new d(this.#e)}$assertType(){return new d(this.#e)}withPlugin(e){return new d({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new nr(r.insertId,r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new d({...this.#e,queryNode:le.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}class ar{numDeletedRows;constructor(e){this.numDeletedRows=e}}var ae=f({is(e){return e.kind==="LimitNode"},create(e){return f({kind:"LimitNode",limit:e})}});var c;class ve{#e;constructor(e){this.#e=f(e)}where(...e){return new c({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,Yt(e))})}whereRef(e,r,t){return new c({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new c({...this.#e,queryNode:le.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new c({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}using(e){return new c({...this.#e,queryNode:_.cloneWithUsing(this.#e.queryNode,A(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,r){return new c({...this.#e,queryNode:le.cloneWithJoin(this.#e.queryNode,G(e,r))})}returning(e){return new c({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new c({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new c({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new c({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new c({...this.#e,queryNode:le.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new c({...this.#e,queryNode:_.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new c({...this.#e,queryNode:le.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new c({...this.#e,queryNode:le.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new c({...this.#e,queryNode:_.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}modifyEnd(e){return new c({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new c({...this.#e})}$castTo(){return new c(this.#e)}$narrowType(){return new c(this.#e)}$assertType(){return new c(this.#e)}withPlugin(e){return new c({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new ar(r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new c({...this.#e,queryNode:le.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}c=ve;class ur{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}}var h;class ue{#e;constructor(e){this.#e=f(e)}where(...e){return new h({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,Yt(e))})}whereRef(e,r,t){return new h({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new h({...this.#e,queryNode:le.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new h({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}from(e){return new h({...this.#e,queryNode:F.cloneWithFromItems(this.#e.queryNode,A(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,r){return new h({...this.#e,queryNode:le.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new h({...this.#e,queryNode:le.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new h({...this.#e,queryNode:le.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new h({...this.#e,queryNode:F.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}set(...e){return new h({...this.#e,queryNode:F.cloneWithUpdates(this.#e.queryNode,zr(...e))})}returning(e){return new h({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new h({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new h({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new h({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new h({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new h({...this.#e,queryNode:le.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new h({...this.#e})}$castTo(){return new h(this.#e)}$narrowType(){return new h(this.#e)}$assertType(){return new h(this.#e)}withPlugin(e){return new h({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new ur(r.numAffectedRows??BigInt(0),r.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new h({...this.#e,queryNode:le.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}h=ue;var mr=f({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,r){return f({kind:"CommonTableExpressionNameNode",table:g.create(e),columns:r?f(r.map(Dt.create)):void 0})}});var me=f({is(e){return e.kind==="CommonTableExpressionNode"},create(e,r){return f({kind:"CommonTableExpressionNode",name:e,expression:r})},cloneWith(e,r){return f({...e,...r})}});class xe{#e;constructor(e){this.#e=f(e)}materialized(){return new xe({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new xe({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function dr(e,r){let t=r(_r()).toOperationNode();if(Qt(e))return e(St(t)).toOperationNode();return me.create($r(e),t)}function St(e){return(r)=>new xe({node:me.create($r(r),e)})}function $r(e){if(e.includes("(")){let r=e.split(/[\(\)]/),t=r[0],o=r[1].split(",").map((n)=>n.trim());return mr.create(t,o)}else return mr.create(e)}var ge=f({is(e){return e.kind==="WithNode"},create(e,r){return f({kind:"WithNode",expressions:f([e]),...r})},cloneWithExpression(e,r){return f({...e,expressions:f([...e.expressions,r])})}});var jr=["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 Xc(e){let r="";for(let t=0;t<e;++t)r+=kt();return r}function kt(){return jr[~~(Math.random()*jr.length)]}function Ve(){return new Gr}class Gr{#e;get queryId(){if(this.#e===void 0)this.#e=Xc(8);return this.#e}}function i(e){return e}class Bl{nodeStack=[];#e=f({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,r){if(!e)return e;this.nodeStack.push(e);let t=this.transformNodeImpl(e,r);return this.nodeStack.pop(),f(t)}transformNodeImpl(e,r){return this.#e[e.kind](e,r)}transformNodeList(e,r){if(!e)return e;return f(e.map((t)=>this.transformNode(t,r)))}transformSelectQuery(e,r){return i({kind:"SelectQueryNode",from:this.transformNode(e.from,r),selections:this.transformNodeList(e.selections,r),distinctOn:this.transformNodeList(e.distinctOn,r),joins:this.transformNodeList(e.joins,r),groupBy:this.transformNode(e.groupBy,r),orderBy:this.transformNode(e.orderBy,r),where:this.transformNode(e.where,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),limit:this.transformNode(e.limit,r),offset:this.transformNode(e.offset,r),with:this.transformNode(e.with,r),having:this.transformNode(e.having,r),explain:this.transformNode(e.explain,r),setOperations:this.transformNodeList(e.setOperations,r),fetch:this.transformNode(e.fetch,r),top:this.transformNode(e.top,r)})}transformSelection(e,r){return i({kind:"SelectionNode",selection:this.transformNode(e.selection,r)})}transformColumn(e,r){return i({kind:"ColumnNode",column:this.transformNode(e.column,r)})}transformAlias(e,r){return i({kind:"AliasNode",node:this.transformNode(e.node,r),alias:this.transformNode(e.alias,r)})}transformTable(e,r){return i({kind:"TableNode",table:this.transformNode(e.table,r)})}transformFrom(e,r){return i({kind:"FromNode",froms:this.transformNodeList(e.froms,r)})}transformReference(e,r){return i({kind:"ReferenceNode",column:this.transformNode(e.column,r),table:this.transformNode(e.table,r)})}transformAnd(e,r){return i({kind:"AndNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)})}transformOr(e,r){return i({kind:"OrNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)})}transformValueList(e,r){return i({kind:"ValueListNode",values:this.transformNodeList(e.values,r)})}transformParens(e,r){return i({kind:"ParensNode",node:this.transformNode(e.node,r)})}transformJoin(e,r){return i({kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,r),on:this.transformNode(e.on,r)})}transformRaw(e,r){return i({kind:"RawNode",sqlFragments:f([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,r)})}transformWhere(e,r){return i({kind:"WhereNode",where:this.transformNode(e.where,r)})}transformInsertQuery(e,r){return i({kind:"InsertQueryNode",into:this.transformNode(e.into,r),columns:this.transformNodeList(e.columns,r),values:this.transformNode(e.values,r),returning:this.transformNode(e.returning,r),onConflict:this.transformNode(e.onConflict,r),onDuplicateKey:this.transformNode(e.onDuplicateKey,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),ignore:e.ignore,orAction:this.transformNode(e.orAction,r),replace:e.replace,explain:this.transformNode(e.explain,r),defaultValues:e.defaultValues,top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)})}transformValues(e,r){return i({kind:"ValuesNode",values:this.transformNodeList(e.values,r)})}transformDeleteQuery(e,r){return i({kind:"DeleteQueryNode",from:this.transformNode(e.from,r),using:this.transformNode(e.using,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),orderBy:this.transformNode(e.orderBy,r),limit:this.transformNode(e.limit,r),explain:this.transformNode(e.explain,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)})}transformReturning(e,r){return i({kind:"ReturningNode",selections:this.transformNodeList(e.selections,r)})}transformCreateTable(e,r){return i({kind:"CreateTableNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),constraints:this.transformNodeList(e.constraints,r),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),selectQuery:this.transformNode(e.selectQuery,r)})}transformColumnDefinition(e,r){return i({kind:"ColumnDefinitionNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),references:this.transformNode(e.references,r),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,r),check:this.transformNode(e.check,r),generated:this.transformNode(e.generated,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists})}transformAddColumn(e,r){return i({kind:"AddColumnNode",column:this.transformNode(e.column,r)})}transformDropTable(e,r){return i({kind:"DropTableNode",table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade})}transformOrderBy(e,r){return i({kind:"OrderByNode",items:this.transformNodeList(e.items,r)})}transformOrderByItem(e,r){return i({kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,r),direction:this.transformNode(e.direction,r),collation:this.transformNode(e.collation,r),nulls:e.nulls})}transformGroupBy(e,r){return i({kind:"GroupByNode",items:this.transformNodeList(e.items,r)})}transformGroupByItem(e,r){return i({kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,r)})}transformUpdateQuery(e,r){return i({kind:"UpdateQueryNode",table:this.transformNode(e.table,r),from:this.transformNode(e.from,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),updates:this.transformNodeList(e.updates,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),explain:this.transformNode(e.explain,r),limit:this.transformNode(e.limit,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r),orderBy:this.transformNode(e.orderBy,r)})}transformColumnUpdate(e,r){return i({kind:"ColumnUpdateNode",column:this.transformNode(e.column,r),value:this.transformNode(e.value,r)})}transformLimit(e,r){return i({kind:"LimitNode",limit:this.transformNode(e.limit,r)})}transformOffset(e,r){return i({kind:"OffsetNode",offset:this.transformNode(e.offset,r)})}transformOnConflict(e,r){return i({kind:"OnConflictNode",columns:this.transformNodeList(e.columns,r),constraint:this.transformNode(e.constraint,r),indexExpression:this.transformNode(e.indexExpression,r),indexWhere:this.transformNode(e.indexWhere,r),updates:this.transformNodeList(e.updates,r),updateWhere:this.transformNode(e.updateWhere,r),doNothing:e.doNothing})}transformOnDuplicateKey(e,r){return i({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,r)})}transformCreateIndex(e,r){return i({kind:"CreateIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,r),nullsNotDistinct:e.nullsNotDistinct})}transformList(e,r){return i({kind:"ListNode",items:this.transformNodeList(e.items,r)})}transformDropIndex(e,r){return i({kind:"DropIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade})}transformPrimaryKeyConstraint(e,r){return i({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformUniqueConstraint(e,r){return i({kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformForeignKeyConstraint(e,r){return i({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,r),references:this.transformNode(e.references,r),name:this.transformNode(e.name,r),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformSetOperation(e,r){return i({kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,r),all:e.all})}transformReferences(e,r){return i({kind:"ReferencesNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),onDelete:e.onDelete,onUpdate:e.onUpdate})}transformCheckConstraint(e,r){return i({kind:"CheckConstraintNode",expression:this.transformNode(e.expression,r),name:this.transformNode(e.name,r)})}transformWith(e,r){return i({kind:"WithNode",expressions:this.transformNodeList(e.expressions,r),recursive:e.recursive})}transformCommonTableExpression(e,r){return i({kind:"CommonTableExpressionNode",name:this.transformNode(e.name,r),materialized:e.materialized,expression:this.transformNode(e.expression,r)})}transformCommonTableExpressionName(e,r){return i({kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r)})}transformHaving(e,r){return i({kind:"HavingNode",having:this.transformNode(e.having,r)})}transformCreateSchema(e,r){return i({kind:"CreateSchemaNode",schema:this.transformNode(e.schema,r),ifNotExists:e.ifNotExists})}transformDropSchema(e,r){return i({kind:"DropSchemaNode",schema:this.transformNode(e.schema,r),ifExists:e.ifExists,cascade:e.cascade})}transformAlterTable(e,r){return i({kind:"AlterTableNode",table:this.transformNode(e.table,r),renameTo:this.transformNode(e.renameTo,r),setSchema:this.transformNode(e.setSchema,r),columnAlterations:this.transformNodeList(e.columnAlterations,r),addConstraint:this.transformNode(e.addConstraint,r),dropConstraint:this.transformNode(e.dropConstraint,r),renameConstraint:this.transformNode(e.renameConstraint,r),addIndex:this.transformNode(e.addIndex,r),dropIndex:this.transformNode(e.dropIndex,r)})}transformDropColumn(e,r){return i({kind:"DropColumnNode",column:this.transformNode(e.column,r)})}transformRenameColumn(e,r){return i({kind:"RenameColumnNode",column:this.transformNode(e.column,r),renameTo:this.transformNode(e.renameTo,r)})}transformAlterColumn(e,r){return i({kind:"AlterColumnNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),dataTypeExpression:this.transformNode(e.dataTypeExpression,r),setDefault:this.transformNode(e.setDefault,r),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull})}transformModifyColumn(e,r){return i({kind:"ModifyColumnNode",column:this.transformNode(e.column,r)})}transformAddConstraint(e,r){return i({kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,r)})}transformDropConstraint(e,r){return i({kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,r),ifExists:e.ifExists,modifier:e.modifier})}transformRenameConstraint(e,r){return i({kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,r),newName:this.transformNode(e.newName,r)})}transformCreateView(e,r){return i({kind:"CreateViewNode",name:this.transformNode(e.name,r),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,r),as:this.transformNode(e.as,r)})}transformRefreshMaterializedView(e,r){return i({kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,r),concurrently:e.concurrently,withNoData:e.withNoData})}transformDropView(e,r){return i({kind:"DropViewNode",name:this.transformNode(e.name,r),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade})}transformGenerated(e,r){return i({kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,r)})}transformDefaultValue(e,r){return i({kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,r)})}transformOn(e,r){return i({kind:"OnNode",on:this.transformNode(e.on,r)})}transformSelectModifier(e,r){return i({kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,r),of:this.transformNodeList(e.of,r)})}transformCreateType(e,r){return i({kind:"CreateTypeNode",name:this.transformNode(e.name,r),enum:this.transformNode(e.enum,r)})}transformDropType(e,r){return i({kind:"DropTypeNode",name:this.transformNode(e.name,r),ifExists:e.ifExists})}transformExplain(e,r){return i({kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,r)})}transformSchemableIdentifier(e,r){return i({kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,r),identifier:this.transformNode(e.identifier,r)})}transformAggregateFunction(e,r){return i({kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,r),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,r),withinGroup:this.transformNode(e.withinGroup,r),filter:this.transformNode(e.filter,r),over:this.transformNode(e.over,r)})}transformOver(e,r){return i({kind:"OverNode",orderBy:this.transformNode(e.orderBy,r),partitionBy:this.transformNode(e.partitionBy,r)})}transformPartitionBy(e,r){return i({kind:"PartitionByNode",items:this.transformNodeList(e.items,r)})}transformPartitionByItem(e,r){return i({kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,r)})}transformBinaryOperation(e,r){return i({kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,r),operator:this.transformNode(e.operator,r),rightOperand:this.transformNode(e.rightOperand,r)})}transformUnaryOperation(e,r){return i({kind:"UnaryOperationNode",operator:this.transformNode(e.operator,r),operand:this.transformNode(e.operand,r)})}transformUsing(e,r){return i({kind:"UsingNode",tables:this.transformNodeList(e.tables,r)})}transformFunction(e,r){return i({kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,r)})}transformCase(e,r){return i({kind:"CaseNode",value:this.transformNode(e.value,r),when:this.transformNodeList(e.when,r),else:this.transformNode(e.else,r),isStatement:e.isStatement})}transformWhen(e,r){return i({kind:"WhenNode",condition:this.transformNode(e.condition,r),result:this.transformNode(e.result,r)})}transformJSONReference(e,r){return i({kind:"JSONReferenceNode",reference:this.transformNode(e.reference,r),traversal:this.transformNode(e.traversal,r)})}transformJSONPath(e,r){return i({kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,r),pathLegs:this.transformNodeList(e.pathLegs,r)})}transformJSONPathLeg(e,r){return i({kind:"JSONPathLegNode",type:e.type,value:e.value})}transformJSONOperatorChain(e,r){return i({kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,r),values:this.transformNodeList(e.values,r)})}transformTuple(e,r){return i({kind:"TupleNode",values:this.transformNodeList(e.values,r)})}transformMergeQuery(e,r){return i({kind:"MergeQueryNode",into:this.transformNode(e.into,r),using:this.transformNode(e.using,r),whens:this.transformNodeList(e.whens,r),with:this.transformNode(e.with,r),top:this.transformNode(e.top,r),endModifiers:this.transformNodeList(e.endModifiers,r),output:this.transformNode(e.output,r),returning:this.transformNode(e.returning,r)})}transformMatched(e,r){return i({kind:"MatchedNode",not:e.not,bySource:e.bySource})}transformAddIndex(e,r){return i({kind:"AddIndexNode",name:this.transformNode(e.name,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists})}transformCast(e,r){return i({kind:"CastNode",expression:this.transformNode(e.expression,r),dataType:this.transformNode(e.dataType,r)})}transformFetch(e,r){return i({kind:"FetchNode",rowCount:this.transformNode(e.rowCount,r),modifier:e.modifier})}transformTop(e,r){return i({kind:"TopNode",expression:e.expression,modifiers:e.modifiers})}transformOutput(e,r){return i({kind:"OutputNode",selections:this.transformNodeList(e.selections,r)})}transformDataType(e,r){return e}transformSelectAll(e,r){return e}transformIdentifier(e,r){return e}transformValue(e,r){return e}transformPrimitiveValueList(e,r){return e}transformOperator(e,r){return e}transformDefaultInsertValue(e,r){return e}transformOrAction(e,r){return e}transformCollate(e,r){return e}}var Et=f({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}),Ct={json_agg:!0,to_json:!0};class cr extends Bl{#e;#r=new Set;#t=new Set;constructor(e){super();this.#e=e}transformNodeImpl(e,r){if(!this.#s(e))return super.transformNodeImpl(e,r);let t=this.#u(e);for(let u of t)this.#t.add(u);let o=this.#a(e);for(let u of o)this.#r.add(u);let n=super.transformNodeImpl(e,r);for(let u of o)this.#r.delete(u);for(let u of t)this.#t.delete(u);return n}transformSchemableIdentifier(e,r){let t=super.transformSchemableIdentifier(e,r);if(t.schema||!this.#r.has(e.identifier.name))return t;return{...t,schema:ze.create(this.#e)}}transformReferences(e,r){let t=super.transformReferences(e,r);if(t.table.table.schema)return t;return{...t,table:g.createWithSchema(this.#e,t.table.table.identifier.name)}}transformAggregateFunction(e,r){return{...super.transformAggregateFunction({...e,aggregated:[]},r),aggregated:this.#i(e,r,"aggregated")}}transformFunction(e,r){return{...super.transformFunction({...e,arguments:[]},r),arguments:this.#i(e,r,"arguments")}}transformSelectModifier(e,r){return{...super.transformSelectModifier({...e,of:void 0},r),of:e.of?.map((t)=>g.is(t)&&!t.table.schema?{...t,table:this.transformIdentifier(t.table.identifier,r)}:this.transformNode(t,r))}}#i(e,r,t){return Ct[e.func]?e[t].map((o)=>!g.is(o)||o.table.schema?this.transformNode(o,r):{...o,table:this.transformIdentifier(o.table.identifier,r)}):this.transformNodeList(e[t],r)}#s(e){return e.kind in Et}#a(e){let r=new Set;if("name"in e&&e.name&&sn.is(e.name))this.#n(e.name,r);if("from"in e&&e.from)for(let t of e.from.froms)this.#o(t,r);if("into"in e&&e.into)this.#o(e.into,r);if("table"in e&&e.table)this.#o(e.table,r);if("joins"in e&&e.joins)for(let t of e.joins)this.#o(t.table,r);if("using"in e&&e.using)if(R.is(e.using))this.#o(e.using.table,r);else this.#o(e.using,r);return r}#u(e){let r=new Set;if("with"in e&&e.with)this.#m(e.with,r);return r}#o(e,r){if(g.is(e))return this.#n(e.table,r);if(l.is(e)&&g.is(e.node))return this.#n(e.node.table,r);if(Le.is(e)){for(let t of e.items)this.#o(t,r);return}if(ye.is(e)){for(let t of e.tables)this.#o(t,r);return}}#n(e,r){let t=e.identifier.name;if(!this.#r.has(t)&&!this.#t.has(t))r.add(t)}#m(e,r){for(let t of e.expressions){let o=t.name.table.table.identifier.name;if(!this.#t.has(o))r.add(o)}}}class Fo{#e;constructor(e){this.#e=new cr(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}}var Kr=f({is(e){return e.kind==="MatchedNode"},create(e,r=!1){return f({kind:"MatchedNode",not:e,bySource:r})}});function hr(e,r,t){return Oo.create(oe([Kr.create(!e.isMatched,e.bySource),...r&&r.length>0?[r.length===3&&t?N(r[0],r[1],r[2]):Yt(r)]:[]],"and",!1))}function de(e){if($t(e))return Zt.create([e],[]);if(rr(e))return e.toOperationNode();return e}class _s{#e;#r;#t;constructor(){this.#e=new Promise((e,r)=>{this.#t=r,this.#r=e})}get promise(){return this.#e}resolve=(e)=>{if(this.#r)this.#r(e)};reject=(e)=>{if(this.#t)this.#t(e)}}async function eu(e){let r=new _s,t=new _s;return e.provideConnection(async(o)=>(r.resolve(o),await t.promise)).catch((o)=>r.reject(o)),f({connection:await r.promise,release:t.resolve})}var Rt=f([]);class Ul{#e;constructor(e=Rt){this.#e=e}get plugins(){return this.#e}transformQuery(e,r){for(let t of this.#e){let o=t.transformQuery({node:e,queryId:r});if(o.kind===e.kind)e=o;else throw 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 ${o.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async(r)=>{let t=await r.executeQuery(e);if("numUpdatedOrDeletedRows"in t)qo("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#r(t,e.queryId)})}async*stream(e,r){let{connection:t,release:o}=await eu(this);try{for await(let n of t.streamQuery(e,r))yield await this.#r(n,e.queryId)}finally{o()}}async#r(e,r){for(let t of this.#e)e=await t.transformResult({result:e,queryId:r});return e}}class ce extends Ul{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(e){return new ce([...this.plugins,e])}withPlugins(e){return new ce([...this.plugins,...e])}withPluginAtFront(e){return new ce([e,...this.plugins])}withoutPlugins(){return new ce([])}}var K=new ce;class fr{numChangedRows;constructor(e){this.numChangedRows=e}}class J{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new J({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new J({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}using(...e){return new b({...this.#e,queryNode:k.cloneWithUsing(this.#e.queryNode,G("Using",e))})}returning(e){return new J({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new J({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new J({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new J({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new b({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new b({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,r,t){return this.#r([e,r,t],!0)}#r(e,r){return new pr({...this.#e,queryNode:k.cloneWithWhen(this.#e.queryNode,hr({isMatched:!0},e,r))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,r,t){return this.#t([e,r,t],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,r,t){return this.#t([e,r,t],!0,!0)}returning(e){return new b({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new b({...this.#e,queryNode:le.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new b({...this.#e,queryNode:le.cloneWithOutput(this.#e.queryNode,y(e))})}#t(e,r=!1,t=!1){let o={...this.#e,queryNode:k.cloneWithWhen(this.#e.queryNode,hr({isMatched:!1,bySource:t},e,r))};return new(t?pr:Hr)(o)}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new b({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new fr(r.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}}class pr{#e;constructor(e){this.#e=f(e)}thenDelete(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de(e(new ue({queryId:this.#e.queryId,executor:K,queryNode:F.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate((r)=>r.set(...e))}}class Hr{#e;constructor(e){this.#e=f(e)}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("do nothing"))})}thenInsertValues(e){let[r,t]=Fe(e);return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de(wr.cloneWith(wr.createWithoutInto(),{columns:r,values:t})))})}}class aa{#e;constructor(e){this.#e=f(e)}selectFrom(e){return We({queryId:Ve(),executor:this.#e.executor,queryNode:jt.createFrom(A(e),this.#e.withNode)})}selectNoFrom(e){return We({queryId:Ve(),executor:this.#e.executor,queryNode:jt.cloneWithSelections(jt.create(this.#e.withNode),p(e))})}insertInto(e){return new d({queryId:Ve(),executor:this.#e.executor,queryNode:wr.create(Ut(e),this.#e.withNode)})}replaceInto(e){return new d({queryId:Ve(),executor:this.#e.executor,queryNode:wr.create(Ut(e),this.#e.withNode,!0)})}deleteFrom(e){return new ve({queryId:Ve(),executor:this.#e.executor,queryNode:_.create(A(e),this.#e.withNode)})}updateTable(e){return new ue({queryId:Ve(),executor:this.#e.executor,queryNode:F.create(A(e),this.#e.withNode)})}mergeInto(e){return new J({queryId:Ve(),executor:this.#e.executor,queryNode:k.create(or(e),this.#e.withNode)})}with(e,r){let t=dr(e,r);return new aa({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t)})}withRecursive(e,r){let t=dr(e,r);return new aa({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t,{recursive:!0})})}withPlugin(e){return new aa({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new aa({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new aa({...this.#e,executor:this.#e.executor.withPluginAtFront(new Fo(e))})}}function _r(){return new aa({executor:K})}function Xr(e,r){return new ie({joinNode:R.create(e,Y(r))})}function Yr(){return new ne({overNode:Ne.create()})}function G(e,r){if(r.length===3)return At(e,r[0],r[1],r[2]);else if(r.length===2)return Tt(e,r[0],r[1]);else if(r.length===1)return qt(e,r[0]);else throw Error("not implemented")}function Tt(e,r,t){return t(Xr(e,r)).toOperationNode()}function At(e,r,t,o){return R.createWithOn(e,Y(r),N(t,"=",o))}function qt(e,r){return R.create(e,Y(r))}var Zr=f({is(e){return e.kind==="OffsetNode"},create(e){return f({kind:"OffsetNode",offset:e})}});var et=f({is(e){return e.kind==="GroupByItemNode"},create(e){return f({kind:"GroupByItemNode",groupBy:e})}});function rt(e){return e=Qt(e)?e(q()):e,z(e).map(et.create)}function ee(e,r,t){if(Qt(r))r=r(Me());if(!En(r))r=[r];return r.map((o)=>nu.create(e,to(o),t))}class a{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Qe(this,e)}or(...e){return new Ue(C.create(this.#e,Yt(e)))}and(...e){return new Je(W.create(this.#e,Yt(e)))}$castTo(){return new a(this.#e)}$notNull(){return new a(this.#e)}toOperationNode(){return this.#e}}class Qe{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),rr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}class Ue{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Qe(this,e)}or(...e){return new Ue(C.create(this.#e,Yt(e)))}$castTo(){return new Ue(this.#e)}toOperationNode(){return bo.create(this.#e)}}class Je{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Qe(this,e)}and(...e){return new Je(W.create(this.#e,Yt(e)))}$castTo(){return new Je(this.#e)}toOperationNode(){return bo.create(this.#e)}}var tt=f({is(e){return e.kind==="FetchNode"},create(e,r){return{kind:"FetchNode",rowCount:Lr.create(e),modifier:r}}});function ot(e,r){if(!No(e)&&!Oa(e))throw Error(`Invalid fetch row count: ${e}`);if(!Lt(r))throw Error(`Invalid fetch modifier: ${r}`);return tt.create(e,r)}function Lt(e){return e==="only"||e==="with ties"}var s;class lr{#e;constructor(e){this.#e=f(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new s({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,Yt(e))})}whereRef(e,r,t){return new s({...this.#e,queryNode:le.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}having(...e){return new s({...this.#e,queryNode:jt.cloneWithHaving(this.#e.queryNode,Yt(e))})}havingRef(e,r,t){return new s({...this.#e,queryNode:jt.cloneWithHaving(this.#e.queryNode,N(e,r,t))})}select(e){return new s({...this.#e,queryNode:jt.cloneWithSelections(this.#e.queryNode,p(e))})}distinctOn(e){return new s({...this.#e,queryNode:jt.cloneWithDistinctOn(this.#e.queryNode,z(e))})}modifyFront(e){return new s({...this.#e,queryNode:jt.cloneWithFrontModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:jt.cloneWithFrontModifier(this.#e.queryNode,D.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("ForUpdate",e?Fl(e).map(Ut):void 0))})}forShare(e){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("ForShare",e?Fl(e).map(Ut):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("ForKeyShare",e?Fl(e).map(Ut):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("ForNoKeyUpdate",e?Fl(e).map(Ut):void 0))})}skipLocked(){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:le.cloneWithEndModifier(this.#e.queryNode,D.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:jt.cloneWithSelections(this.#e.queryNode,y(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,r){return new s({...this.#e,queryNode:le.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new s({...this.#e,queryNode:le.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new s({...this.#e,queryNode:jt.cloneWithGroupByItems(this.#e.queryNode,rt(e))})}limit(e){return new s({...this.#e,queryNode:jt.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}offset(e){return new s({...this.#e,queryNode:jt.cloneWithOffset(this.#e.queryNode,Zr.create(m(e)))})}fetch(e,r="only"){return new s({...this.#e,queryNode:jt.cloneWithFetch(this.#e.queryNode,ot(e,r))})}top(e,r){return new s({...this.#e,queryNode:le.cloneWithTop(this.#e.queryNode,B(e,r))})}union(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:jt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!0))})}as(e){return new it(this,e)}clearSelect(){return new s({...this.#e,queryNode:jt.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:le.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:jt.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:jt.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:le.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:jt.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new s({...this.#e})}$castTo(){return new s(this.#e)}$narrowType(){return new s(this.#e)}$assertType(){return new s(this.#e)}$asTuple(){return new a(this.toOperationNode())}$asScalar(){return new a(this.toOperationNode())}withPlugin(e){return new s({...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)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new s({...this.#e,queryNode:le.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}s=lr;function We(e){return new lr(e)}class it{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return l.create(this.#e.toOperationNode(),ze.create(this.#r))}}var M=f({is(e){return e.kind==="AggregateFunctionNode"},create(e,r=[]){return f({kind:"AggregateFunctionNode",func:e,aggregated:r})},cloneWithDistinct(e){return f({...e,distinct:!0})},cloneWithOrderBy(e,r,t=!1){let o=t?"withinGroup":"orderBy";return f({...e,[o]:e[o]?U.cloneWithItems(e[o],r):U.create(r)})},cloneWithFilter(e,r){return f({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",r):O.create(r)})},cloneWithOrFilter(e,r){return f({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",r):O.create(r)})},cloneWithOver(e,r){return f({...e,over:r})}});var Nr=f({is(e){return e.kind==="FunctionNode"},create(e,r){return f({kind:"FunctionNode",func:e,arguments:r})}});class S{#e;constructor(e){this.#e=f(e)}get expressionType(){return}as(e){return new nt(this,e)}distinct(){return new S({...this.#e,aggregateFunctionNode:M.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new S({...this.#e,aggregateFunctionNode:le.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(e))})}clearOrderBy(){return new S({...this.#e,aggregateFunctionNode:le.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new S({...this.#e,aggregateFunctionNode:M.cloneWithOrderBy(this.#e.aggregateFunctionNode,E(e),!0)})}filterWhere(...e){return new S({...this.#e,aggregateFunctionNode:M.cloneWithFilter(this.#e.aggregateFunctionNode,Yt(e))})}filterWhereRef(e,r,t){return new S({...this.#e,aggregateFunctionNode:M.cloneWithFilter(this.#e.aggregateFunctionNode,N(e,r,t))})}over(e){let r=Yr();return new S({...this.#e,aggregateFunctionNode:M.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(r):r).toOperationNode())})}$call(e){return e(this)}$castTo(){return new S(this.#e)}$notNull(){return new S(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}}class nt{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),ze.create(this.#r))}}function tu(){let e=(t,o)=>new a(Nr.create(t,z(o??[]))),r=(t,o)=>new S({aggregateFunctionNode:M.create(t,o?z(o):void 0)});return Object.assign(e,{agg:r,avg(t){return r("avg",[t])},coalesce(...t){return e("coalesce",t)},count(t){return r("count",[t])},countAll(t){return new S({aggregateFunctionNode:M.create("count",y(t))})},max(t){return r("max",[t])},min(t){return r("min",[t])},sum(t){return r("sum",[t])},any(t){return e("any",[t])},jsonAgg(t){return new S({aggregateFunctionNode:M.create("json_agg",[$t(t)?Ut(t):t.toOperationNode()])})},toJson(t){return new a(Nr.create("to_json",[$t(t)?Ut(t):t.toOperationNode()]))}})}var st=f({is(e){return e.kind==="UnaryOperationNode"},create(e,r){return f({kind:"UnaryOperationNode",operator:e,operand:r})}});function at(e,r){return st.create(_o.create(e),w(r))}var yo=f({is(e){return e.kind==="CaseNode"},create(e){return f({kind:"CaseNode",value:e})},cloneWithWhen(e,r){return f({...e,when:f(e.when?[...e.when,r]:[r])})},cloneWithThen(e,r){return f({...e,when:e.when?f([...e.when.slice(0,-1),Oo.cloneWithResult(e.when[e.when.length-1],r)]):void 0})},cloneWith(e,r){return f({...e,...r})}});class zl{#e;constructor(e){this.#e=f(e)}when(...e){return new yr({...this.#e,node:yo.cloneWithWhen(this.#e.node,Oo.create(Yt(e)))})}}class yr{#e;constructor(e){this.#e=f(e)}then(e){return new ut({...this.#e,node:yo.cloneWithThen(this.#e.node,Ae(e)?pe(e):m(e))})}}class ut{#e;constructor(e){this.#e=f(e)}when(...e){return new yr({...this.#e,node:yo.cloneWithWhen(this.#e.node,Oo.create(Yt(e)))})}else(e){return new mt({...this.#e,node:yo.cloneWith(this.#e.node,{else:Ae(e)?pe(e):m(e)})})}end(){return new a(yo.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(yo.cloneWith(this.#e.node,{isStatement:!0}))}}class mt{#e;constructor(e){this.#e=f(e)}end(){return new a(yo.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(yo.cloneWith(this.#e.node,{isStatement:!0}))}}var Ie=f({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return f({kind:"JSONOperatorChainNode",operator:e,values:f([])})},cloneWithValue(e,r){return f({...e,values:f([...e.values,r])})}});var Or=f({is(e){return e.kind==="JSONPathLegNode"},create(e,r){return f({kind:"JSONPathLegNode",type:e,value:r})}});var H=f({is(e){return e.kind==="JSONPathNode"},create(e){return f({kind:"JSONPathNode",inOperator:e,pathLegs:f([])})},cloneWithLeg(e,r){return f({...e,pathLegs:f([...e.pathLegs,r])})}});var he=f({is(e){return e.kind==="JSONReferenceNode"},create(e,r){return f({kind:"JSONReferenceNode",reference:e,traversal:r})},cloneWithTraversal(e,r){return f({...e,traversal:r})}});var Bt=/^#-\d+$/;class Se{#e;constructor(e){this.#e=e}at(e){if(typeof e!=="number"&&typeof e!=="string"||typeof e==="number"&&!Number.isInteger(e)||typeof e==="string"&&e!=="last"&&!Bt.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,r){if(he.is(this.#e))return new be(he.cloneWithTraversal(this.#e,H.is(this.#e.traversal)?H.cloneWithLeg(this.#e.traversal,Or.create(e,r)):Ie.cloneWithValue(this.#e.traversal,Lr.createImmediate(r))));return new be(H.cloneWithLeg(this.#e,Or.create(e,r)))}}class be extends Se{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new dt(this,e)}$castTo(){return new be(this.#e)}$notNull(){return new be(this.#e)}toOperationNode(){return this.#e}}class dt{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),rr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}var xr=f({is(e){return e.kind==="TupleNode"},create(e){return f({kind:"TupleNode",values:f(e)})}});var Ft=["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"],vt=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ct=f({is(e){return e.kind==="DataTypeNode"},create(e){return f({kind:"DataTypeNode",dataType:e})}});function ht(e){if(Ft.includes(e))return!0;if(vt.some((r)=>r.test(e)))return!0;return!1}function jo(e){if(rr(e))return e.toOperationNode();if(ht(e))return ct.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var ft=f({is(e){return e.kind==="CastNode"},create(e,r){return f({kind:"CastNode",expression:e,dataType:r})}});function Me(e=K){function r(n,u,re){return new a(qe(n,u,re))}function t(n,u){return new a(at(n,u))}let o=Object.assign(r,{fn:void 0,eb:void 0,selectFrom(n){return We({queryId:Ve(),executor:e,queryNode:jt.createFrom(A(n))})},case(n){return new zl({node:yo.create(Cn(n)?void 0:w(n))})},ref(n,u){if(Cn(u))return new a(Ao(n));return new Se(pt(n,u))},jsonPath(){return new Se(H.create())},table(n){return new a(Ut(n))},val(n){return new a(m(n))},refTuple(...n){return new a(xr.create(n.map(w)))},tuple(...n){return new a(xr.create(n.map(m)))},lit(n){return new a(pe(n))},unary:t,not(n){return t("not",n)},exists(n){return t("exists",n)},neg(n){return t("-",n)},between(n,u,re){return new a(I.create(w(n),_o.create("between"),W.create(m(u),m(re))))},betweenSymmetric(n,u,re){return new a(I.create(w(n),_o.create("between symmetric"),W.create(m(u),m(re))))},and(n){if(En(n))return new a(oe(n,"and"));return new a(je(n,"and"))},or(n){if(En(n))return new a(oe(n,"or"));return new a(je(n,"or"))},parens(...n){let u=Yt(n);if(bo.is(u))return new a(u);else return new a(bo.create(u))},cast(n,u){return new a(ft.create(w(n),jo(u)))},withSchema(n){return Me(e.withPluginAtFront(new Fo(n)))}});return o.fn=tu(),o.eb=o,o}function q(e){return Me()}function to(e){if(rr(e))return e.toOperationNode();else if(Qt(e))return e(q()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function De(e){if(rr(e))return e.toOperationNode();else if(Qt(e))return e(q()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function V(e){return Ce(e)||Wr(e)||Qt(e)}function Ze(e){if($t(e))return Ao(e);return e.toOperationNode()}function z(e){if(En(e))return e.map((r)=>w(r));else return[w(e)]}function w(e){if(V(e))return to(e);return Ze(e)}function pt(e,r){let t=Ao(e);if(Dd(r))return he.create(t,Ie.create(_o.create(r)));let o=r.slice(0,-1);if(Dd(o))return he.create(t,H.create(_o.create(o)));throw Error(`Invalid JSON operator: ${r}`)}function Ao(e){if(!e.includes("."))return te.create(Dt.create(e));let t=e.split(".").map(gr);if(t.length===3)return Pt(t);if(t.length===2)return Mt(t);throw Error(`invalid column reference ${e}`)}function Mr(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(gr);return l.create(Ao(t),ze.create(o))}else return Ao(e)}function Nd(e){return Dt.create(e)}function Ni(e){if(e.includes(" ")){let[t,o]=e.split(" ").map(gr);if(!tr(o))throw Error(`invalid order direction "${o}" next to "${t}"`);return E([t,o])[0]}else return Nd(e)}function Pt(e){let[r,t,o]=e;return te.create(Dt.create(o),g.createWithSchema(r,t))}function Mt(e){let[r,t]=e;return te.create(Dt.create(t),g.create(r))}function gr(e){return e.trim()}class ke{#e;constructor(e){this.#e=f(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new lt(this,e)}$castTo(){return new ke({...this.#e})}$notNull(){return new ke(this.#e)}withPlugin(e){return new ke({...this.#e,plugins:this.#e.plugins!==void 0?f([...this.#e.plugins,e]):f([e])})}toOperationNode(){return this.#t(this.#r())}compile(e){return this.#i(this.#r(e))}async execute(e){let r=this.#r(e);return r.executeQuery(this.#i(r))}#r(e){let r=e!==void 0?e.getExecutor():K;return this.#e.plugins!==void 0?r.withPlugins(this.#e.plugins):r}#t(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#t(e),this.#e.queryId)}}function Q(e){return new ke(e)}class lt{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}get rawBuilder(){return this.#e}toOperationNode(){return l.create(this.#e.toOperationNode(),rr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}var Pe=Object.assign((e,...r)=>Q({queryId:Ve(),rawNode:Zt.create(e,r?.map(Nt)??[])}),{ref(e){return Q({queryId:Ve(),rawNode:Zt.createWithChild(Ao(e))})},val(e){return Q({queryId:Ve(),rawNode:Zt.createWithChild(m(e))})},value(e){return this.val(e)},table(e){return Q({queryId:Ve(),rawNode:Zt.createWithChild(Ut(e))})},id(...e){let r=Array(e.length+1).fill(".");return r[0]="",r[r.length-1]="",Q({queryId:Ve(),rawNode:Zt.create(r,e.map(ze.create))})},lit(e){return Q({queryId:Ve(),rawNode:Zt.createWithChild(Lr.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return Q({queryId:Ve(),rawNode:Zt.createWithSql(e)})},join(e,r=Pe`, `){let t=Array(Math.max(2*e.length-1,0)),o=r.toOperationNode();for(let n=0;n<e.length;++n)if(t[2*n]=Nt(e[n]),n!==e.length-1)t[2*n+1]=o;return Q({queryId:Ve(),rawNode:Zt.createWithChildren(t)})}});function Nt(e){if(rr(e))return e.toOperationNode();return m(e)}var sr=f({raw(e,r=[]){return f({sql:e,query:Zt.createWithSql(e),parameters:f(r),queryId:Ve()})}});
|
|
3
|
-
export{
|
|
2
|
+
import{Pn,Vt,jo,vs,Xs,ea,Kt,Er,f,pc,Nn,ze,gn,sm,Mo,lf,Bt,os,Ro,Ir,qo,Cu}from"./chunk-fb40xxz3.js";function lr(e){return Er(e)&&Kt(e.toOperationNode)}var zr=f({is(e){return e.kind==="ValueNode"},create(e){return f({kind:"ValueNode",value:e})},createImmediate(e){return f({kind:"ValueNode",value:e,immediate:!0})}});var l=f({is(e){return e.kind==="AliasNode"},create(e,r){return f({kind:"AliasNode",node:e,alias:r})}});var Zt=f({is(e){return e.kind==="ColumnNode"},create(e){return f({kind:"ColumnNode",column:ze.create(e)})}});var Ki=f({is(e){return e.kind==="SelectAllNode"},create(){return f({kind:"SelectAllNode"})}});var te=f({is(e){return e.kind==="ReferenceNode"},create(e,r){return f({kind:"ReferenceNode",table:r,column:e})},createSelectAll(e){return f({kind:"ReferenceNode",table:e,column:Ki.create()})}});var g=f({is(e){return e.kind==="TableNode"},create(e){return f({kind:"TableNode",table:gn.create(e)})},createWithSchema(e,r){return f({kind:"TableNode",table:gn.createWithSchema(e,r)})}});function Ce(e){return Er(e)&&"expressionType"in e&&lr(e)}function Wr(e){return Er(e)&&"expression"in e&&Vt(e.alias)&&lr(e)}var D=f({is(e){return e.kind==="SelectModifierNode"},create(e,r){return f({kind:"SelectModifierNode",modifier:e,of:r})},createWithExpression(e){return f({kind:"SelectModifierNode",rawModifier:e})}});var W=f({is(e){return e.kind==="AndNode"},create(e,r){return f({kind:"AndNode",left:e,right:r})}});var C=f({is(e){return e.kind==="OrNode"},create(e,r){return f({kind:"OrNode",left:e,right:r})}});var Re=f({is(e){return e.kind==="OnNode"},create(e){return f({kind:"OnNode",on:e})},cloneWithOperation(e,r,t){return f({...e,on:r==="And"?W.create(e.on,t):C.create(e.on,t)})}});var R=f({is(e){return e.kind==="JoinNode"},create(e,r){return f({kind:"JoinNode",joinType:e,table:r,on:void 0})},createWithOn(e,r,t){return f({kind:"JoinNode",joinType:e,table:r,on:Re.create(t)})},cloneWithOn(e,r){return f({...e,on:e.on?Re.cloneWithOperation(e.on,"And",r):Re.create(r)})}});var I=f({is(e){return e.kind==="BinaryOperationNode"},create(e,r,t){return f({kind:"BinaryOperationNode",leftOperand:e,operator:r,rightOperand:t})}});var Te=f({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return f({kind:"PrimitiveValueListNode",values:f([...e])})}});var Da=f({is(e){return e.kind==="ValueListNode"},create(e){return f({kind:"ValueListNode",values:f(e)})}});function br(e){if(Nn(e))return wt(e);return m(e)}function m(e){if(V(e))return fo(e);return zr.create(e)}function Ae(e){return jo(e)||vs(e)||Xs(e)}function le(e){if(!Ae(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return zr.createImmediate(e)}function wt(e){if(e.some(V))return Da.create(e.map((r)=>m(r)));return Te.create(e)}function rr(e){if(e.length===3)return qe(e[0],e[1],e[2]);else if(e.length===1)return m(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function qe(e,r,t){if(Ot(r)&&kr(t))return I.create(w(e),$e(r),zr.createImmediate(t));return I.create(w(e),$e(r),br(t))}function N(e,r,t){return I.create(w(e),$e(r),w(t))}function _e(e,r){return oe(Object.entries(e).filter(([,t])=>!Pn(t)).map(([t,o])=>qe(t,kr(o)?"is":"=",o)),r)}function oe(e,r,t=!0){let o=r==="and"?W.create:C.create;if(e.length===0)return I.create(zr.createImmediate(1),Mo.create("="),zr.createImmediate(r==="and"?1:0));let n=Sr(e[0]);for(let u=1;u<e.length;++u)n=o(n,Sr(e[u]));if(e.length>1&&t)return Ro.create(n);return n}function Ot(e){return e==="is"||e==="is not"}function kr(e){return Xs(e)||vs(e)}function $e(e){if(Vt(e)&&sm.includes(e))return Mo.create(e);if(lr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function Sr(e){return lr(e)?e.toOperationNode():e}var U=f({is(e){return e.kind==="OrderByNode"},create(e){return f({kind:"OrderByNode",items:f([...e])})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var je=f({is(e){return e.kind==="PartitionByNode"},create(e){return f({kind:"PartitionByNode",items:f(e)})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var Ne=f({is(e){return e.kind==="OverNode"},create(){return f({kind:"OverNode"})},cloneWithOrderByItems(e,r){return f({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithPartitionByItems(e,r){return f({...e,partitionBy:e.partitionBy?je.cloneWithItems(e.partitionBy,r):je.create(r)})}});var X=f({is(e){return e.kind==="FromNode"},create(e){return f({kind:"FromNode",froms:f(e)})},cloneWithFroms(e,r){return f({...e,froms:f([...e.froms,...r])})}});var Ge=f({is(e){return e.kind==="GroupByNode"},create(e){return f({kind:"GroupByNode",items:f(e)})},cloneWithItems(e,r){return f({...e,items:f([...e.items,...r])})}});var Ke=f({is(e){return e.kind==="HavingNode"},create(e){return f({kind:"HavingNode",having:e})},cloneWithOperation(e,r,t){return f({...e,having:r==="And"?W.create(e.having,t):C.create(e.having,t)})}});var Le=f({is(e){return e.kind==="ListNode"},create(e){return f({kind:"ListNode",items:f(e)})}});var F=f({is(e){return e.kind==="UpdateQueryNode"},create(e,r){return f({kind:"UpdateQueryNode",table:e.length===1?e[0]:Le.create(e),...r&&{with:r}})},createWithoutTable(){return f({kind:"UpdateQueryNode"})},cloneWithFromItems(e,r){return f({...e,from:e.from?X.cloneWithFroms(e.from,r):X.create(r)})},cloneWithUpdates(e,r){return f({...e,updates:e.updates?f([...e.updates,...r]):r})},cloneWithLimit(e,r){return f({...e,limit:r})}});var ye=f({is(e){return e.kind==="UsingNode"},create(e){return f({kind:"UsingNode",tables:f(e)})},cloneWithTables(e,r){return f({...e,tables:f([...e.tables,...r])})}});var _=f({is(e){return e.kind==="DeleteQueryNode"},create(e,r){return f({kind:"DeleteQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithOrderByItems:(e,r)=>ce.cloneWithOrderByItems(e,r),cloneWithoutOrderBy:(e)=>ce.cloneWithoutOrderBy(e),cloneWithLimit(e,r){return f({...e,limit:r})},cloneWithoutLimit(e){return f({...e,limit:void 0})},cloneWithUsing(e,r){return f({...e,using:e.using!==void 0?ye.cloneWithTables(e.using,r):ye.create(r)})}});var O=f({is(e){return e.kind==="WhereNode"},create(e){return f({kind:"WhereNode",where:e})},cloneWithOperation(e,r,t){return f({...e,where:r==="And"?W.create(e.where,t):C.create(e.where,t)})}});var He=f({is(e){return e.kind==="ReturningNode"},create(e){return f({kind:"ReturningNode",selections:f(e)})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})}});var Cr=f({is(e){return e.kind==="ExplainNode"},create(e,r){return f({kind:"ExplainNode",format:e,options:r})}});var k=f({is(e){return e.kind==="MergeQueryNode"},create(e,r){return f({kind:"MergeQueryNode",into:e,...r&&{with:r}})},cloneWithUsing(e,r){return f({...e,using:r})},cloneWithWhen(e,r){return f({...e,whens:e.whens?f([...e.whens,r]):f([r])})},cloneWithThen(e,r){return f({...e,whens:e.whens?f([...e.whens.slice(0,-1),qo.cloneWithResult(e.whens[e.whens.length-1],r)]):void 0})}});var Xe=f({is(e){return e.kind==="OutputNode"},create(e){return f({kind:"OutputNode",selections:f(e)})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})}});var ce=f({is(e){return $t.is(e)||Ir.is(e)||F.is(e)||_.is(e)||k.is(e)},cloneWithEndModifier(e,r){return f({...e,endModifiers:e.endModifiers?f([...e.endModifiers,r]):f([r])})},cloneWithWhere(e,r){return f({...e,where:e.where?O.cloneWithOperation(e.where,"And",r):O.create(r)})},cloneWithJoin(e,r){return f({...e,joins:e.joins?f([...e.joins,r]):f([r])})},cloneWithReturning(e,r){return f({...e,returning:e.returning?He.cloneWithSelections(e.returning,r):He.create(r)})},cloneWithoutReturning(e){return f({...e,returning:void 0})},cloneWithoutWhere(e){return f({...e,where:void 0})},cloneWithExplain(e,r,t){return f({...e,explain:Cr.create(r,t?.toOperationNode())})},cloneWithTop(e,r){return f({...e,top:r})},cloneWithOutput(e,r){return f({...e,output:e.output?Xe.cloneWithSelections(e.output,r):Xe.create(r)})},cloneWithOrderByItems(e,r){return f({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithoutOrderBy(e){return f({...e,orderBy:void 0})}});var $t=f({is(e){return e.kind==="SelectQueryNode"},create(e){return f({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,r){return f({kind:"SelectQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithSelections(e,r){return f({...e,selections:e.selections?f([...e.selections,...r]):f(r)})},cloneWithDistinctOn(e,r){return f({...e,distinctOn:e.distinctOn?f([...e.distinctOn,...r]):f(r)})},cloneWithFrontModifier(e,r){return f({...e,frontModifiers:e.frontModifiers?f([...e.frontModifiers,r]):f([r])})},cloneWithOrderByItems:(e,r)=>ce.cloneWithOrderByItems(e,r),cloneWithGroupByItems(e,r){return f({...e,groupBy:e.groupBy?Ge.cloneWithItems(e.groupBy,r):Ge.create(r)})},cloneWithLimit(e,r){return f({...e,limit:r})},cloneWithOffset(e,r){return f({...e,offset:r})},cloneWithFetch(e,r){return f({...e,fetch:r})},cloneWithHaving(e,r){return f({...e,having:e.having?Ke.cloneWithOperation(e.having,"And",r):Ke.create(r)})},cloneWithSetOperations(e,r){return f({...e,setOperations:e.setOperations?f([...e.setOperations,...r]):f([...r])})},cloneWithoutSelections(e){return f({...e,selections:[]})},cloneWithoutLimit(e){return f({...e,limit:void 0})},cloneWithoutOffset(e){return f({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>ce.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return f({...e,groupBy:void 0})}});class ie{#e;constructor(e){this.#e=f(e)}on(...e){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,rr(e))})}onRef(e,r,t){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,N(e,r,t))})}onTrue(){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,Bt.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}}class of{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return Ze(this.#e)}}function Be(e){return Er(e)&&lr(e)&&Vt(e.dynamicReference)}var T=f({is(e){return e.kind==="OrderByItemNode"},create(e,r){return f({kind:"OrderByItemNode",orderBy:e,direction:r})},cloneWith(e,r){return f({...e,...r})}});var Rr=f({is(e){return e.kind==="CollateNode"},create(e){return f({kind:"CollateNode",collation:ze.create(e)})}});class j{#e;constructor(e){this.#e=f(e)}desc(){return new j({node:T.cloneWith(this.#e.node,{direction:Bt.createWithSql("desc")})})}asc(){return new j({node:T.cloneWith(this.#e.node,{direction:Bt.createWithSql("asc")})})}nullsLast(){return new j({node:T.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new j({node:T.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new j({node:T.cloneWith(this.#e.node,{collation:Rr.create(e)})})}toOperationNode(){return this.#e.node}}function tr(e){return e==="asc"||e==="desc"}function E(e){if(e.length===2)return[er(e[0],e[1])];if(e.length===1){let[r]=e;if(Array.isArray(r))return os("orderBy(array) is deprecated, use multiple orderBy calls instead."),r.map((t)=>er(t));return[er(r)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function er(e,r){let t=xt(e);if(T.is(t)){if(r)throw Error("Cannot specify direction twice!");return t}return Tr(t,r)}function xt(e){if(V(e))return fo(e);if(Be(e))return e.toOperationNode();let[r,t]=e.split(" ");if(t)return os("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Tr(Io(r),t);return Io(e)}function Tr(e,r){if(typeof r==="string"){if(!tr(r))throw Error(`Invalid order by direction: ${r}`);return T.create(e,Bt.createWithSql(r))}if(Ce(r))return os("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),T.create(e,r.toOperationNode());let t=T.create(e);if(!r)return t;return r(new j({node:t})).toOperationNode()}var Ar=f({is(e){return e.kind==="PartitionByItemNode"},create(e){return f({kind:"PartitionByItemNode",partitionBy:e})}});function qr(e){return z(e).map(Ar.create)}class ne{#e;constructor(e){this.#e=f(e)}orderBy(...e){return new ne({overNode:Ne.cloneWithOrderByItems(this.#e.overNode,E(e))})}clearOrderBy(){return new ne({overNode:ce.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new ne({overNode:Ne.cloneWithPartitionByItems(this.#e.overNode,qr(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var se=f({is(e){return e.kind==="SelectionNode"},create(e){return f({kind:"SelectionNode",selection:e})},createSelectAll(){return f({kind:"SelectionNode",selection:Ki.create()})},createSelectAllFromTable(e){return f({kind:"SelectionNode",selection:te.createSelectAll(e)})}});class af{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Lr(this.#e,e)}}class Lr{#e;#r;get table(){return this.#e}get alias(){return this.#r}constructor(e,r){this.#e=e,this.#r=r}toOperationNode(){return l.create(Ft(this.#e),ze.create(this.#r))}}function Br(e){return Er(e)&&lr(e)&&Vt(e.table)&&Vt(e.alias)}function A(e){if(Nn(e))return e.map((r)=>Y(r));else return[Y(e)]}function Y(e){if(Vt(e))return or(e);else if(Br(e))return e.toOperationNode();else return De(e)}function or(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(Dr);return l.create(Ft(t),ze.create(o))}else return Ft(e)}function Ft(e){if(e.includes(".")){let[t,o]=e.split(".").map(Dr);return g.createWithSchema(t,o)}else return g.create(e)}function Dr(e){return e.trim()}function p(e){if(Kt(e))return p(e(q()));else if(Nn(e))return e.map((r)=>Fr(r));else return[Fr(e)]}function Fr(e){if(Vt(e))return se.create(Pr(e));else if(Be(e))return se.create(e.toOperationNode());else return se.create(De(e))}function y(e){if(!e)return[se.createSelectAll()];else if(Array.isArray(e))return e.map(vr);else return[vr(e)]}function vr(e){if(Vt(e))return se.createSelectAllFromTable(Ft(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Mr=f({is(e){return e.kind==="ValuesNode"},create(e){return f({kind:"ValuesNode",values:f(e)})}});var Vr=f({is(e){return e.kind==="DefaultInsertValueNode"},create(){return f({kind:"DefaultInsertValueNode"})}});function Fe(e){let r=Kt(e)?e(q()):e,t=Nn(r)?r:f([r]);return gt(t)}function gt(e){let r=Wt(e);return[f([...r.keys()].map(Zt.create)),Mr.create(e.map((t)=>bt(t,r)))]}function Wt(e){let r=new Map;for(let t of e){let o=Object.keys(t);for(let n of o)if(!r.has(n)&&t[n]!==void 0)r.set(n,r.size)}return r}function bt(e,r){let t=Object.keys(e),o=Array.from({length:r.size}),n=!1,u=t.length;for(let Ee of t){let pe=r.get(Ee);if(Pn(pe)){u--;continue}let Ie=e[Ee];if(Pn(Ie)||V(Ie))n=!0;o[pe]=Ie}if(u<r.size||n){let Ee=Vr.create();return Da.create(o.map((pe)=>Pn(pe)?Ee:m(pe)))}return Te.create(o)}var ir=f({is(e){return e.kind==="ColumnUpdateNode"},create(e,r){return f({kind:"ColumnUpdateNode",column:e,value:r})}});function Ur(...e){if(e.length===2)return[ir.create(w(e[0]),m(e[1]))];return we(e[0])}function we(e){let r=Kt(e)?e(q()):e;return Object.entries(r).filter(([t,o])=>o!==void 0).map(([t,o])=>ir.create(Zt.create(t),m(o)))}var Jr=f({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return f({kind:"OnDuplicateKeyNode",updates:e})}});class nr{insertId;numInsertedOrUpdatedRows;constructor(e,r){this.insertId=e,this.numInsertedOrUpdatedRows=r}}class L extends Error{node;constructor(e){super("no result");this.node=e}}function v(e){return Object.prototype.hasOwnProperty.call(e,"prototype")}var x=f({is(e){return e.kind==="OnConflictNode"},create(){return f({kind:"OnConflictNode"})},cloneWith(e,r){return f({...e,...r})},cloneWithIndexWhere(e,r){return f({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",r):O.create(r)})},cloneWithIndexOrWhere(e,r){return f({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",r):O.create(r)})},cloneWithUpdateWhere(e,r){return f({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",r):O.create(r)})},cloneWithUpdateOrWhere(e,r){return f({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",r):O.create(r)})},cloneWithoutIndexWhere(e){return f({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return f({...e,updateWhere:void 0})}});class P{#e;constructor(e){this.#e=f(e)}column(e){let r=Zt.create(e);return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?f([...this.#e.onConflictNode.columns,r]):f([r])})})}columns(e){let r=e.map(Zt.create);return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?f([...this.#e.onConflictNode.columns,...r]):f(r)})})}constraint(e){return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{constraint:ze.create(e)})})}expression(e){return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new P({...this.#e,onConflictNode:x.cloneWithIndexWhere(this.#e.onConflictNode,rr(e))})}whereRef(e,r,t){return new P({...this.#e,onConflictNode:x.cloneWithIndexWhere(this.#e.onConflictNode,N(e,r,t))})}clearWhere(){return new P({...this.#e,onConflictNode:x.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Qr({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Oe({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{updates:we(e)})})}$call(e){return e(this)}}class Qr{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.onConflictNode}}class Oe{#e;constructor(e){this.#e=f(e)}where(...e){return new Oe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,rr(e))})}whereRef(e,r,t){return new Oe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,N(e,r,t))})}clearWhere(){return new Oe({...this.#e,onConflictNode:x.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var $r=f({is(e){return e.kind==="TopNode"},create(e,r){return f({kind:"TopNode",expression:e,modifiers:r})}});function B(e,r){if(!jo(e)&&!ea(e))throw Error(`Invalid top expression: ${e}`);if(!Pn(r)&&!St(r))throw Error(`Invalid top modifiers: ${r}`);return $r.create(e,r)}function St(e){return e==="percent"||e==="with ties"||e==="percent with ties"}var Z=f({is(e){return e.kind==="OrActionNode"},create(e){return f({kind:"OrActionNode",action:e})}});class d{#e;constructor(e){this.#e=f(e)}values(e){let[r,t]=Fe(e);return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{columns:r,values:t})})}columns(e){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{columns:f(e.map(Zt.create))})})}expression(e){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{values:fo(e)})})}defaultValues(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new d({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orIgnore(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orAbort(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("abort")})})}orFail(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("fail")})})}orReplace(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("replace")})})}orRollback(){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{orAction:Z.create("rollback")})})}top(e,r){return new d({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}onConflict(e){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{onConflict:e(new P({onConflictNode:x.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new d({...this.#e,queryNode:Ir.cloneWith(this.#e.queryNode,{onDuplicateKey:Jr.create(we(e))})})}returning(e){return new d({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(){return new d({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new d({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new d({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new d({...this.#e,queryNode:ce.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new d({...this.#e})}$castTo(){return new d(this.#e)}$narrowType(){return new d(this.#e)}$assertType(){return new d(this.#e)}withPlugin(e){return new d({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new nr(r.insertId,r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new d({...this.#e,queryNode:ce.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}class sr{numDeletedRows;constructor(e){this.numDeletedRows=e}}var ae=f({is(e){return e.kind==="LimitNode"},create(e){return f({kind:"LimitNode",limit:e})}});var c;class ve{#e;constructor(e){this.#e=f(e)}where(...e){return new c({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,rr(e))})}whereRef(e,r,t){return new c({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new c({...this.#e,queryNode:ce.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new c({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}using(e){return new c({...this.#e,queryNode:_.cloneWithUsing(this.#e.queryNode,A(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,r){return new c({...this.#e,queryNode:ce.cloneWithJoin(this.#e.queryNode,G(e,r))})}returning(e){return new c({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new c({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new c({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new c({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new c({...this.#e,queryNode:ce.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new c({...this.#e,queryNode:_.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new c({...this.#e,queryNode:ce.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new c({...this.#e,queryNode:ce.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new c({...this.#e,queryNode:_.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}modifyEnd(e){return new c({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new c({...this.#e})}$castTo(){return new c(this.#e)}$narrowType(){return new c(this.#e)}$assertType(){return new c(this.#e)}withPlugin(e){return new c({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new sr(r.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new c({...this.#e,queryNode:ce.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}c=ve;class ar{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}}var h;class ue{#e;constructor(e){this.#e=f(e)}where(...e){return new h({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,rr(e))})}whereRef(e,r,t){return new h({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new h({...this.#e,queryNode:ce.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new h({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}from(e){return new h({...this.#e,queryNode:F.cloneWithFromItems(this.#e.queryNode,A(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,r){return new h({...this.#e,queryNode:ce.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new h({...this.#e,queryNode:ce.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new h({...this.#e,queryNode:ce.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new h({...this.#e,queryNode:F.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}set(...e){return new h({...this.#e,queryNode:F.cloneWithUpdates(this.#e.queryNode,Ur(...e))})}returning(e){return new h({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new h({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new h({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new h({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new h({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new h({...this.#e,queryNode:ce.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new h({...this.#e})}$castTo(){return new h(this.#e)}$narrowType(){return new h(this.#e)}$assertType(){return new h(this.#e)}withPlugin(e){return new h({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new ar(r.numAffectedRows??BigInt(0),r.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new h({...this.#e,queryNode:ce.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}h=ue;var mr=f({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,r){return f({kind:"CommonTableExpressionNameNode",table:g.create(e),columns:r?f(r.map(Zt.create)):void 0})}});var me=f({is(e){return e.kind==="CommonTableExpressionNode"},create(e,r){return f({kind:"CommonTableExpressionNode",name:e,expression:r})},cloneWith(e,r){return f({...e,...r})}});class xe{#e;constructor(e){this.#e=f(e)}materialized(){return new xe({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new xe({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function dr(e,r){let t=r(jr()).toOperationNode();if(Kt(e))return e(kt(t)).toOperationNode();return me.create(_r(e),t)}function kt(e){return(r)=>new xe({node:me.create(_r(r),e)})}function _r(e){if(e.includes("(")){let r=e.split(/[\(\)]/),t=r[0],o=r[1].split(",").map((n)=>n.trim());return mr.create(t,o)}else return mr.create(e)}var ge=f({is(e){return e.kind==="WithNode"},create(e,r){return f({kind:"WithNode",expressions:f([e]),...r})},cloneWithExpression(e,r){return f({...e,expressions:f([...e.expressions,r])})}});var Gr=["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 wu(e){let r="";for(let t=0;t<e;++t)r+=Et();return r}function Et(){return Gr[~~(Math.random()*Gr.length)]}function Ye(){return new Kr}class Kr{#e;get queryId(){if(this.#e===void 0)this.#e=wu(8);return this.#e}}function i(e){return e}class uc{nodeStack=[];#e=f({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,r){if(!e)return e;this.nodeStack.push(e);let t=this.transformNodeImpl(e,r);return this.nodeStack.pop(),f(t)}transformNodeImpl(e,r){return this.#e[e.kind](e,r)}transformNodeList(e,r){if(!e)return e;return f(e.map((t)=>this.transformNode(t,r)))}transformSelectQuery(e,r){return i({kind:"SelectQueryNode",from:this.transformNode(e.from,r),selections:this.transformNodeList(e.selections,r),distinctOn:this.transformNodeList(e.distinctOn,r),joins:this.transformNodeList(e.joins,r),groupBy:this.transformNode(e.groupBy,r),orderBy:this.transformNode(e.orderBy,r),where:this.transformNode(e.where,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),limit:this.transformNode(e.limit,r),offset:this.transformNode(e.offset,r),with:this.transformNode(e.with,r),having:this.transformNode(e.having,r),explain:this.transformNode(e.explain,r),setOperations:this.transformNodeList(e.setOperations,r),fetch:this.transformNode(e.fetch,r),top:this.transformNode(e.top,r)})}transformSelection(e,r){return i({kind:"SelectionNode",selection:this.transformNode(e.selection,r)})}transformColumn(e,r){return i({kind:"ColumnNode",column:this.transformNode(e.column,r)})}transformAlias(e,r){return i({kind:"AliasNode",node:this.transformNode(e.node,r),alias:this.transformNode(e.alias,r)})}transformTable(e,r){return i({kind:"TableNode",table:this.transformNode(e.table,r)})}transformFrom(e,r){return i({kind:"FromNode",froms:this.transformNodeList(e.froms,r)})}transformReference(e,r){return i({kind:"ReferenceNode",column:this.transformNode(e.column,r),table:this.transformNode(e.table,r)})}transformAnd(e,r){return i({kind:"AndNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)})}transformOr(e,r){return i({kind:"OrNode",left:this.transformNode(e.left,r),right:this.transformNode(e.right,r)})}transformValueList(e,r){return i({kind:"ValueListNode",values:this.transformNodeList(e.values,r)})}transformParens(e,r){return i({kind:"ParensNode",node:this.transformNode(e.node,r)})}transformJoin(e,r){return i({kind:"JoinNode",joinType:e.joinType,table:this.transformNode(e.table,r),on:this.transformNode(e.on,r)})}transformRaw(e,r){return i({kind:"RawNode",sqlFragments:f([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,r)})}transformWhere(e,r){return i({kind:"WhereNode",where:this.transformNode(e.where,r)})}transformInsertQuery(e,r){return i({kind:"InsertQueryNode",into:this.transformNode(e.into,r),columns:this.transformNodeList(e.columns,r),values:this.transformNode(e.values,r),returning:this.transformNode(e.returning,r),onConflict:this.transformNode(e.onConflict,r),onDuplicateKey:this.transformNode(e.onDuplicateKey,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),ignore:e.ignore,orAction:this.transformNode(e.orAction,r),replace:e.replace,explain:this.transformNode(e.explain,r),defaultValues:e.defaultValues,top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)})}transformValues(e,r){return i({kind:"ValuesNode",values:this.transformNodeList(e.values,r)})}transformDeleteQuery(e,r){return i({kind:"DeleteQueryNode",from:this.transformNode(e.from,r),using:this.transformNode(e.using,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),orderBy:this.transformNode(e.orderBy,r),limit:this.transformNode(e.limit,r),explain:this.transformNode(e.explain,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r)})}transformReturning(e,r){return i({kind:"ReturningNode",selections:this.transformNodeList(e.selections,r)})}transformCreateTable(e,r){return i({kind:"CreateTableNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),constraints:this.transformNodeList(e.constraints,r),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),selectQuery:this.transformNode(e.selectQuery,r)})}transformColumnDefinition(e,r){return i({kind:"ColumnDefinitionNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),references:this.transformNode(e.references,r),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,r),check:this.transformNode(e.check,r),generated:this.transformNode(e.generated,r),frontModifiers:this.transformNodeList(e.frontModifiers,r),endModifiers:this.transformNodeList(e.endModifiers,r),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists})}transformAddColumn(e,r){return i({kind:"AddColumnNode",column:this.transformNode(e.column,r)})}transformDropTable(e,r){return i({kind:"DropTableNode",table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade})}transformOrderBy(e,r){return i({kind:"OrderByNode",items:this.transformNodeList(e.items,r)})}transformOrderByItem(e,r){return i({kind:"OrderByItemNode",orderBy:this.transformNode(e.orderBy,r),direction:this.transformNode(e.direction,r),collation:this.transformNode(e.collation,r),nulls:e.nulls})}transformGroupBy(e,r){return i({kind:"GroupByNode",items:this.transformNodeList(e.items,r)})}transformGroupByItem(e,r){return i({kind:"GroupByItemNode",groupBy:this.transformNode(e.groupBy,r)})}transformUpdateQuery(e,r){return i({kind:"UpdateQueryNode",table:this.transformNode(e.table,r),from:this.transformNode(e.from,r),joins:this.transformNodeList(e.joins,r),where:this.transformNode(e.where,r),updates:this.transformNodeList(e.updates,r),returning:this.transformNode(e.returning,r),endModifiers:this.transformNodeList(e.endModifiers,r),with:this.transformNode(e.with,r),explain:this.transformNode(e.explain,r),limit:this.transformNode(e.limit,r),top:this.transformNode(e.top,r),output:this.transformNode(e.output,r),orderBy:this.transformNode(e.orderBy,r)})}transformColumnUpdate(e,r){return i({kind:"ColumnUpdateNode",column:this.transformNode(e.column,r),value:this.transformNode(e.value,r)})}transformLimit(e,r){return i({kind:"LimitNode",limit:this.transformNode(e.limit,r)})}transformOffset(e,r){return i({kind:"OffsetNode",offset:this.transformNode(e.offset,r)})}transformOnConflict(e,r){return i({kind:"OnConflictNode",columns:this.transformNodeList(e.columns,r),constraint:this.transformNode(e.constraint,r),indexExpression:this.transformNode(e.indexExpression,r),indexWhere:this.transformNode(e.indexWhere,r),updates:this.transformNodeList(e.updates,r),updateWhere:this.transformNode(e.updateWhere,r),doNothing:e.doNothing})}transformOnDuplicateKey(e,r){return i({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(e.updates,r)})}transformCreateIndex(e,r){return i({kind:"CreateIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,r),nullsNotDistinct:e.nullsNotDistinct})}transformList(e,r){return i({kind:"ListNode",items:this.transformNodeList(e.items,r)})}transformDropIndex(e,r){return i({kind:"DropIndexNode",name:this.transformNode(e.name,r),table:this.transformNode(e.table,r),ifExists:e.ifExists,cascade:e.cascade})}transformPrimaryKeyConstraint(e,r){return i({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformUniqueConstraint(e,r){return i({kind:"UniqueConstraintNode",columns:this.transformNodeList(e.columns,r),name:this.transformNode(e.name,r),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformForeignKeyConstraint(e,r){return i({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(e.columns,r),references:this.transformNode(e.references,r),name:this.transformNode(e.name,r),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformSetOperation(e,r){return i({kind:"SetOperationNode",operator:e.operator,expression:this.transformNode(e.expression,r),all:e.all})}transformReferences(e,r){return i({kind:"ReferencesNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r),onDelete:e.onDelete,onUpdate:e.onUpdate})}transformCheckConstraint(e,r){return i({kind:"CheckConstraintNode",expression:this.transformNode(e.expression,r),name:this.transformNode(e.name,r)})}transformWith(e,r){return i({kind:"WithNode",expressions:this.transformNodeList(e.expressions,r),recursive:e.recursive})}transformCommonTableExpression(e,r){return i({kind:"CommonTableExpressionNode",name:this.transformNode(e.name,r),materialized:e.materialized,expression:this.transformNode(e.expression,r)})}transformCommonTableExpressionName(e,r){return i({kind:"CommonTableExpressionNameNode",table:this.transformNode(e.table,r),columns:this.transformNodeList(e.columns,r)})}transformHaving(e,r){return i({kind:"HavingNode",having:this.transformNode(e.having,r)})}transformCreateSchema(e,r){return i({kind:"CreateSchemaNode",schema:this.transformNode(e.schema,r),ifNotExists:e.ifNotExists})}transformDropSchema(e,r){return i({kind:"DropSchemaNode",schema:this.transformNode(e.schema,r),ifExists:e.ifExists,cascade:e.cascade})}transformAlterTable(e,r){return i({kind:"AlterTableNode",table:this.transformNode(e.table,r),renameTo:this.transformNode(e.renameTo,r),setSchema:this.transformNode(e.setSchema,r),columnAlterations:this.transformNodeList(e.columnAlterations,r),addConstraint:this.transformNode(e.addConstraint,r),dropConstraint:this.transformNode(e.dropConstraint,r),renameConstraint:this.transformNode(e.renameConstraint,r),addIndex:this.transformNode(e.addIndex,r),dropIndex:this.transformNode(e.dropIndex,r)})}transformDropColumn(e,r){return i({kind:"DropColumnNode",column:this.transformNode(e.column,r)})}transformRenameColumn(e,r){return i({kind:"RenameColumnNode",column:this.transformNode(e.column,r),renameTo:this.transformNode(e.renameTo,r)})}transformAlterColumn(e,r){return i({kind:"AlterColumnNode",column:this.transformNode(e.column,r),dataType:this.transformNode(e.dataType,r),dataTypeExpression:this.transformNode(e.dataTypeExpression,r),setDefault:this.transformNode(e.setDefault,r),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull})}transformModifyColumn(e,r){return i({kind:"ModifyColumnNode",column:this.transformNode(e.column,r)})}transformAddConstraint(e,r){return i({kind:"AddConstraintNode",constraint:this.transformNode(e.constraint,r)})}transformDropConstraint(e,r){return i({kind:"DropConstraintNode",constraintName:this.transformNode(e.constraintName,r),ifExists:e.ifExists,modifier:e.modifier})}transformRenameConstraint(e,r){return i({kind:"RenameConstraintNode",oldName:this.transformNode(e.oldName,r),newName:this.transformNode(e.newName,r)})}transformCreateView(e,r){return i({kind:"CreateViewNode",name:this.transformNode(e.name,r),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,r),as:this.transformNode(e.as,r)})}transformRefreshMaterializedView(e,r){return i({kind:"RefreshMaterializedViewNode",name:this.transformNode(e.name,r),concurrently:e.concurrently,withNoData:e.withNoData})}transformDropView(e,r){return i({kind:"DropViewNode",name:this.transformNode(e.name,r),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade})}transformGenerated(e,r){return i({kind:"GeneratedNode",byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,r)})}transformDefaultValue(e,r){return i({kind:"DefaultValueNode",defaultValue:this.transformNode(e.defaultValue,r)})}transformOn(e,r){return i({kind:"OnNode",on:this.transformNode(e.on,r)})}transformSelectModifier(e,r){return i({kind:"SelectModifierNode",modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,r),of:this.transformNodeList(e.of,r)})}transformCreateType(e,r){return i({kind:"CreateTypeNode",name:this.transformNode(e.name,r),enum:this.transformNode(e.enum,r)})}transformDropType(e,r){return i({kind:"DropTypeNode",name:this.transformNode(e.name,r),ifExists:e.ifExists})}transformExplain(e,r){return i({kind:"ExplainNode",format:e.format,options:this.transformNode(e.options,r)})}transformSchemableIdentifier(e,r){return i({kind:"SchemableIdentifierNode",schema:this.transformNode(e.schema,r),identifier:this.transformNode(e.identifier,r)})}transformAggregateFunction(e,r){return i({kind:"AggregateFunctionNode",func:e.func,aggregated:this.transformNodeList(e.aggregated,r),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,r),withinGroup:this.transformNode(e.withinGroup,r),filter:this.transformNode(e.filter,r),over:this.transformNode(e.over,r)})}transformOver(e,r){return i({kind:"OverNode",orderBy:this.transformNode(e.orderBy,r),partitionBy:this.transformNode(e.partitionBy,r)})}transformPartitionBy(e,r){return i({kind:"PartitionByNode",items:this.transformNodeList(e.items,r)})}transformPartitionByItem(e,r){return i({kind:"PartitionByItemNode",partitionBy:this.transformNode(e.partitionBy,r)})}transformBinaryOperation(e,r){return i({kind:"BinaryOperationNode",leftOperand:this.transformNode(e.leftOperand,r),operator:this.transformNode(e.operator,r),rightOperand:this.transformNode(e.rightOperand,r)})}transformUnaryOperation(e,r){return i({kind:"UnaryOperationNode",operator:this.transformNode(e.operator,r),operand:this.transformNode(e.operand,r)})}transformUsing(e,r){return i({kind:"UsingNode",tables:this.transformNodeList(e.tables,r)})}transformFunction(e,r){return i({kind:"FunctionNode",func:e.func,arguments:this.transformNodeList(e.arguments,r)})}transformCase(e,r){return i({kind:"CaseNode",value:this.transformNode(e.value,r),when:this.transformNodeList(e.when,r),else:this.transformNode(e.else,r),isStatement:e.isStatement})}transformWhen(e,r){return i({kind:"WhenNode",condition:this.transformNode(e.condition,r),result:this.transformNode(e.result,r)})}transformJSONReference(e,r){return i({kind:"JSONReferenceNode",reference:this.transformNode(e.reference,r),traversal:this.transformNode(e.traversal,r)})}transformJSONPath(e,r){return i({kind:"JSONPathNode",inOperator:this.transformNode(e.inOperator,r),pathLegs:this.transformNodeList(e.pathLegs,r)})}transformJSONPathLeg(e,r){return i({kind:"JSONPathLegNode",type:e.type,value:e.value})}transformJSONOperatorChain(e,r){return i({kind:"JSONOperatorChainNode",operator:this.transformNode(e.operator,r),values:this.transformNodeList(e.values,r)})}transformTuple(e,r){return i({kind:"TupleNode",values:this.transformNodeList(e.values,r)})}transformMergeQuery(e,r){return i({kind:"MergeQueryNode",into:this.transformNode(e.into,r),using:this.transformNode(e.using,r),whens:this.transformNodeList(e.whens,r),with:this.transformNode(e.with,r),top:this.transformNode(e.top,r),endModifiers:this.transformNodeList(e.endModifiers,r),output:this.transformNode(e.output,r),returning:this.transformNode(e.returning,r)})}transformMatched(e,r){return i({kind:"MatchedNode",not:e.not,bySource:e.bySource})}transformAddIndex(e,r){return i({kind:"AddIndexNode",name:this.transformNode(e.name,r),columns:this.transformNodeList(e.columns,r),unique:e.unique,using:this.transformNode(e.using,r),ifNotExists:e.ifNotExists})}transformCast(e,r){return i({kind:"CastNode",expression:this.transformNode(e.expression,r),dataType:this.transformNode(e.dataType,r)})}transformFetch(e,r){return i({kind:"FetchNode",rowCount:this.transformNode(e.rowCount,r),modifier:e.modifier})}transformTop(e,r){return i({kind:"TopNode",expression:e.expression,modifiers:e.modifiers})}transformOutput(e,r){return i({kind:"OutputNode",selections:this.transformNodeList(e.selections,r)})}transformDataType(e,r){return e}transformSelectAll(e,r){return e}transformIdentifier(e,r){return e}transformValue(e,r){return e}transformPrimitiveValueList(e,r){return e}transformOperator(e,r){return e}transformDefaultInsertValue(e,r){return e}transformOrAction(e,r){return e}transformCollate(e,r){return e}}var Ct=f({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}),Rt={json_agg:!0,to_json:!0};class cr extends uc{#e;#r=new Set;#t=new Set;constructor(e){super();this.#e=e}transformNodeImpl(e,r){if(!this.#s(e))return super.transformNodeImpl(e,r);let t=this.#u(e);for(let u of t)this.#t.add(u);let o=this.#a(e);for(let u of o)this.#r.add(u);let n=super.transformNodeImpl(e,r);for(let u of o)this.#r.delete(u);for(let u of t)this.#t.delete(u);return n}transformSchemableIdentifier(e,r){let t=super.transformSchemableIdentifier(e,r);if(t.schema||!this.#r.has(e.identifier.name))return t;return{...t,schema:ze.create(this.#e)}}transformReferences(e,r){let t=super.transformReferences(e,r);if(t.table.table.schema)return t;return{...t,table:g.createWithSchema(this.#e,t.table.table.identifier.name)}}transformAggregateFunction(e,r){return{...super.transformAggregateFunction({...e,aggregated:[]},r),aggregated:this.#i(e,r,"aggregated")}}transformFunction(e,r){return{...super.transformFunction({...e,arguments:[]},r),arguments:this.#i(e,r,"arguments")}}transformSelectModifier(e,r){return{...super.transformSelectModifier({...e,of:void 0},r),of:e.of?.map((t)=>g.is(t)&&!t.table.schema?{...t,table:this.transformIdentifier(t.table.identifier,r)}:this.transformNode(t,r))}}#i(e,r,t){return Rt[e.func]?e[t].map((o)=>!g.is(o)||o.table.schema?this.transformNode(o,r):{...o,table:this.transformIdentifier(o.table.identifier,r)}):this.transformNodeList(e[t],r)}#s(e){return e.kind in Ct}#a(e){let r=new Set;if("name"in e&&e.name&&gn.is(e.name))this.#n(e.name,r);if("from"in e&&e.from)for(let t of e.from.froms)this.#o(t,r);if("into"in e&&e.into)this.#o(e.into,r);if("table"in e&&e.table)this.#o(e.table,r);if("joins"in e&&e.joins)for(let t of e.joins)this.#o(t.table,r);if("using"in e&&e.using)if(R.is(e.using))this.#o(e.using.table,r);else this.#o(e.using,r);return r}#u(e){let r=new Set;if("with"in e&&e.with)this.#m(e.with,r);return r}#o(e,r){if(g.is(e))return this.#n(e.table,r);if(l.is(e)&&g.is(e.node))return this.#n(e.node.table,r);if(Le.is(e)){for(let t of e.items)this.#o(t,r);return}if(ye.is(e)){for(let t of e.tables)this.#o(t,r);return}}#n(e,r){let t=e.identifier.name;if(!this.#r.has(t)&&!this.#t.has(t))r.add(t)}#m(e,r){for(let t of e.expressions){let o=t.name.table.table.identifier.name;if(!this.#t.has(o))r.add(o)}}}class rs{#e;constructor(e){this.#e=new cr(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}}var Hr=f({is(e){return e.kind==="MatchedNode"},create(e,r=!1){return f({kind:"MatchedNode",not:e,bySource:r})}});function hr(e,r,t){return qo.create(oe([Hr.create(!e.isMatched,e.bySource),...r&&r.length>0?[r.length===3&&t?N(r[0],r[1],r[2]):rr(r)]:[]],"and",!1))}function de(e){if(Vt(e))return Bt.create([e],[]);if(lr(e))return e.toOperationNode();return e}class La{#e;#r;#t;constructor(){this.#e=new Promise((e,r)=>{this.#t=r,this.#r=e})}get promise(){return this.#e}resolve=(e)=>{if(this.#r)this.#r(e)};reject=(e)=>{if(this.#t)this.#t(e)}}async function vu(e){let r=new La,t=new La;return e.provideConnection(async(o)=>(r.resolve(o),await t.promise)).catch((o)=>r.reject(o)),f({connection:await r.promise,release:t.resolve})}var Tt=f([]);class dc{#e;constructor(e=Tt){this.#e=e}get plugins(){return this.#e}transformQuery(e,r){for(let t of this.#e){let o=t.transformQuery({node:e,queryId:r});if(o.kind===e.kind)e=o;else throw 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 ${o.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async(r)=>{let t=await r.executeQuery(e);if("numUpdatedOrDeletedRows"in t)os("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#r(t,e.queryId)})}async*stream(e,r){let{connection:t,release:o}=await vu(this);try{for await(let n of t.streamQuery(e,r))yield await this.#r(n,e.queryId)}finally{o()}}async#r(e,r){for(let t of this.#e)e=await t.transformResult({result:e,queryId:r});return e}}class he extends dc{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(e){return new he([...this.plugins,e])}withPlugins(e){return new he([...this.plugins,...e])}withPluginAtFront(e){return new he([e,...this.plugins])}withoutPlugins(){return new he([])}}var K=new he;class fr{numChangedRows;constructor(e){this.numChangedRows=e}}class J{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new J({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new J({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}using(...e){return new b({...this.#e,queryNode:k.cloneWithUsing(this.#e.queryNode,G("Using",e))})}returning(e){return new J({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new J({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new J({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new J({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new b({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new b({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,r,t){return this.#r([e,r,t],!0)}#r(e,r){return new pr({...this.#e,queryNode:k.cloneWithWhen(this.#e.queryNode,hr({isMatched:!0},e,r))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,r,t){return this.#t([e,r,t],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,r,t){return this.#t([e,r,t],!0,!0)}returning(e){return new b({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new b({...this.#e,queryNode:ce.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new b({...this.#e,queryNode:ce.cloneWithOutput(this.#e.queryNode,y(e))})}#t(e,r=!1,t=!1){let o={...this.#e,queryNode:k.cloneWithWhen(this.#e.queryNode,hr({isMatched:!1,bySource:t},e,r))};return new(t?pr:Xr)(o)}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new b({...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(),r=await this.#e.executor.executeQuery(e),{adapter:t}=this.#e.executor,o=e.query;if(o.returning&&t.supportsReturning||o.output&&t.supportsOutput)return r.rows;return[new fr(r.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}}class pr{#e;constructor(e){this.#e=f(e)}thenDelete(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de(e(new ue({queryId:this.#e.queryId,executor:K,queryNode:F.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate((r)=>r.set(...e))}}class Xr{#e;constructor(e){this.#e=f(e)}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de("do nothing"))})}thenInsertValues(e){let[r,t]=Fe(e);return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,de(Ir.cloneWith(Ir.createWithoutInto(),{columns:r,values:t})))})}}class ws{#e;constructor(e){this.#e=f(e)}selectFrom(e){return We({queryId:Ye(),executor:this.#e.executor,queryNode:$t.createFrom(A(e),this.#e.withNode)})}selectNoFrom(e){return We({queryId:Ye(),executor:this.#e.executor,queryNode:$t.cloneWithSelections($t.create(this.#e.withNode),p(e))})}insertInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:Ir.create(Ft(e),this.#e.withNode)})}replaceInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:Ir.create(Ft(e),this.#e.withNode,!0)})}deleteFrom(e){return new ve({queryId:Ye(),executor:this.#e.executor,queryNode:_.create(A(e),this.#e.withNode)})}updateTable(e){return new ue({queryId:Ye(),executor:this.#e.executor,queryNode:F.create(A(e),this.#e.withNode)})}mergeInto(e){return new J({queryId:Ye(),executor:this.#e.executor,queryNode:k.create(or(e),this.#e.withNode)})}with(e,r){let t=dr(e,r);return new ws({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t)})}withRecursive(e,r){let t=dr(e,r);return new ws({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t,{recursive:!0})})}withPlugin(e){return new ws({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new ws({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new ws({...this.#e,executor:this.#e.executor.withPluginAtFront(new rs(e))})}}function jr(){return new ws({executor:K})}function Yr(e,r){return new ie({joinNode:R.create(e,Y(r))})}function Zr(){return new ne({overNode:Ne.create()})}function G(e,r){if(r.length===3)return qt(e,r[0],r[1],r[2]);else if(r.length===2)return At(e,r[0],r[1]);else if(r.length===1)return Lt(e,r[0]);else throw Error("not implemented")}function At(e,r,t){return t(Yr(e,r)).toOperationNode()}function qt(e,r,t,o){return R.createWithOn(e,Y(r),N(t,"=",o))}function Lt(e,r){return R.create(e,Y(r))}var et=f({is(e){return e.kind==="OffsetNode"},create(e){return f({kind:"OffsetNode",offset:e})}});var rt=f({is(e){return e.kind==="GroupByItemNode"},create(e){return f({kind:"GroupByItemNode",groupBy:e})}});function tt(e){return e=Kt(e)?e(q()):e,z(e).map(rt.create)}function ee(e,r,t){if(Kt(r))r=r(Me());if(!Nn(r))r=[r];return r.map((o)=>Cu.create(e,fo(o),t))}class a{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Je(this,e)}or(...e){return new Ve(C.create(this.#e,rr(e)))}and(...e){return new Ue(W.create(this.#e,rr(e)))}$castTo(){return new a(this.#e)}$notNull(){return new a(this.#e)}toOperationNode(){return this.#e}}class Je{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),lr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}class Ve{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Je(this,e)}or(...e){return new Ve(C.create(this.#e,rr(e)))}$castTo(){return new Ve(this.#e)}toOperationNode(){return Ro.create(this.#e)}}class Ue{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new Je(this,e)}and(...e){return new Ue(W.create(this.#e,rr(e)))}$castTo(){return new Ue(this.#e)}toOperationNode(){return Ro.create(this.#e)}}var ot=f({is(e){return e.kind==="FetchNode"},create(e,r){return{kind:"FetchNode",rowCount:zr.create(e),modifier:r}}});function it(e,r){if(!jo(e)&&!ea(e))throw Error(`Invalid fetch row count: ${e}`);if(!Dt(r))throw Error(`Invalid fetch modifier: ${r}`);return ot.create(e,r)}function Dt(e){return e==="only"||e==="with ties"}var s;class Nr{#e;constructor(e){this.#e=f(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new s({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,rr(e))})}whereRef(e,r,t){return new s({...this.#e,queryNode:ce.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}having(...e){return new s({...this.#e,queryNode:$t.cloneWithHaving(this.#e.queryNode,rr(e))})}havingRef(e,r,t){return new s({...this.#e,queryNode:$t.cloneWithHaving(this.#e.queryNode,N(e,r,t))})}select(e){return new s({...this.#e,queryNode:$t.cloneWithSelections(this.#e.queryNode,p(e))})}distinctOn(e){return new s({...this.#e,queryNode:$t.cloneWithDistinctOn(this.#e.queryNode,z(e))})}modifyFront(e){return new s({...this.#e,queryNode:$t.cloneWithFrontModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:$t.cloneWithFrontModifier(this.#e.queryNode,D.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("ForUpdate",e?pc(e).map(Ft):void 0))})}forShare(e){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("ForShare",e?pc(e).map(Ft):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("ForKeyShare",e?pc(e).map(Ft):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("ForNoKeyUpdate",e?pc(e).map(Ft):void 0))})}skipLocked(){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:ce.cloneWithEndModifier(this.#e.queryNode,D.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:$t.cloneWithSelections(this.#e.queryNode,y(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,r){return new s({...this.#e,queryNode:ce.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new s({...this.#e,queryNode:ce.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new s({...this.#e,queryNode:$t.cloneWithGroupByItems(this.#e.queryNode,tt(e))})}limit(e){return new s({...this.#e,queryNode:$t.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}offset(e){return new s({...this.#e,queryNode:$t.cloneWithOffset(this.#e.queryNode,et.create(m(e)))})}fetch(e,r="only"){return new s({...this.#e,queryNode:$t.cloneWithFetch(this.#e.queryNode,it(e,r))})}top(e,r){return new s({...this.#e,queryNode:ce.cloneWithTop(this.#e.queryNode,B(e,r))})}union(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:$t.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!0))})}as(e){return new nt(this,e)}clearSelect(){return new s({...this.#e,queryNode:$t.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:ce.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:$t.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:$t.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:ce.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:$t.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,r){if(e)return r(this);return new s({...this.#e})}$castTo(){return new s(this.#e)}$narrowType(){return new s(this.#e)}$assertType(){return new s(this.#e)}$asTuple(){return new a(this.toOperationNode())}$asScalar(){return new a(this.toOperationNode())}withPlugin(e){return new s({...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)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=L){let r=await this.executeTakeFirst();if(r===void 0)throw v(e)?new e(this.toOperationNode()):e(this.toOperationNode());return r}async*stream(e=100){let r=this.compile(),t=this.#e.executor.stream(r,e);for await(let o of t)yield*o.rows}async explain(e,r){return await new s({...this.#e,queryNode:ce.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}s=Nr;function We(e){return new Nr(e)}class nt{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return l.create(this.#e.toOperationNode(),ze.create(this.#r))}}var M=f({is(e){return e.kind==="AggregateFunctionNode"},create(e,r=[]){return f({kind:"AggregateFunctionNode",func:e,aggregated:r})},cloneWithDistinct(e){return f({...e,distinct:!0})},cloneWithOrderBy(e,r,t=!1){let o=t?"withinGroup":"orderBy";return f({...e,[o]:e[o]?U.cloneWithItems(e[o],r):U.create(r)})},cloneWithFilter(e,r){return f({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",r):O.create(r)})},cloneWithOrFilter(e,r){return f({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",r):O.create(r)})},cloneWithOver(e,r){return f({...e,over:r})}});var yr=f({is(e){return e.kind==="FunctionNode"},create(e,r){return f({kind:"FunctionNode",func:e,arguments:r})}});class S{#e;constructor(e){this.#e=f(e)}get expressionType(){return}as(e){return new st(this,e)}distinct(){return new S({...this.#e,aggregateFunctionNode:M.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new S({...this.#e,aggregateFunctionNode:ce.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(e))})}clearOrderBy(){return new S({...this.#e,aggregateFunctionNode:ce.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new S({...this.#e,aggregateFunctionNode:M.cloneWithOrderBy(this.#e.aggregateFunctionNode,E(e),!0)})}filterWhere(...e){return new S({...this.#e,aggregateFunctionNode:M.cloneWithFilter(this.#e.aggregateFunctionNode,rr(e))})}filterWhereRef(e,r,t){return new S({...this.#e,aggregateFunctionNode:M.cloneWithFilter(this.#e.aggregateFunctionNode,N(e,r,t))})}over(e){let r=Zr();return new S({...this.#e,aggregateFunctionNode:M.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(r):r).toOperationNode())})}$call(e){return e(this)}$castTo(){return new S(this.#e)}$notNull(){return new S(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}}class st{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),ze.create(this.#r))}}function xu(){let e=(t,o)=>new a(yr.create(t,z(o??[]))),r=(t,o)=>new S({aggregateFunctionNode:M.create(t,o?z(o):void 0)});return Object.assign(e,{agg:r,avg(t){return r("avg",[t])},coalesce(...t){return e("coalesce",t)},count(t){return r("count",[t])},countAll(t){return new S({aggregateFunctionNode:M.create("count",y(t))})},max(t){return r("max",[t])},min(t){return r("min",[t])},sum(t){return r("sum",[t])},any(t){return e("any",[t])},jsonAgg(t){return new S({aggregateFunctionNode:M.create("json_agg",[Vt(t)?Ft(t):t.toOperationNode()])})},toJson(t){return new a(yr.create("to_json",[Vt(t)?Ft(t):t.toOperationNode()]))}})}var at=f({is(e){return e.kind==="UnaryOperationNode"},create(e,r){return f({kind:"UnaryOperationNode",operator:e,operand:r})}});function ut(e,r){return at.create(Mo.create(e),w(r))}var To=f({is(e){return e.kind==="CaseNode"},create(e){return f({kind:"CaseNode",value:e})},cloneWithWhen(e,r){return f({...e,when:f(e.when?[...e.when,r]:[r])})},cloneWithThen(e,r){return f({...e,when:e.when?f([...e.when.slice(0,-1),qo.cloneWithResult(e.when[e.when.length-1],r)]):void 0})},cloneWith(e,r){return f({...e,...r})}});class fc{#e;constructor(e){this.#e=f(e)}when(...e){return new wr({...this.#e,node:To.cloneWithWhen(this.#e.node,qo.create(rr(e)))})}}class wr{#e;constructor(e){this.#e=f(e)}then(e){return new mt({...this.#e,node:To.cloneWithThen(this.#e.node,Ae(e)?le(e):m(e))})}}class mt{#e;constructor(e){this.#e=f(e)}when(...e){return new wr({...this.#e,node:To.cloneWithWhen(this.#e.node,qo.create(rr(e)))})}else(e){return new dt({...this.#e,node:To.cloneWith(this.#e.node,{else:Ae(e)?le(e):m(e)})})}end(){return new a(To.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(To.cloneWith(this.#e.node,{isStatement:!0}))}}class dt{#e;constructor(e){this.#e=f(e)}end(){return new a(To.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(To.cloneWith(this.#e.node,{isStatement:!0}))}}var Qe=f({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return f({kind:"JSONOperatorChainNode",operator:e,values:f([])})},cloneWithValue(e,r){return f({...e,values:f([...e.values,r])})}});var Or=f({is(e){return e.kind==="JSONPathLegNode"},create(e,r){return f({kind:"JSONPathLegNode",type:e,value:r})}});var H=f({is(e){return e.kind==="JSONPathNode"},create(e){return f({kind:"JSONPathNode",inOperator:e,pathLegs:f([])})},cloneWithLeg(e,r){return f({...e,pathLegs:f([...e.pathLegs,r])})}});var fe=f({is(e){return e.kind==="JSONReferenceNode"},create(e,r){return f({kind:"JSONReferenceNode",reference:e,traversal:r})},cloneWithTraversal(e,r){return f({...e,traversal:r})}});var vt=/^#-\d+$/;class Se{#e;constructor(e){this.#e=e}at(e){if(typeof e!=="number"&&typeof e!=="string"||typeof e==="number"&&!Number.isInteger(e)||typeof e==="string"&&e!=="last"&&!vt.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,r){if(fe.is(this.#e))return new be(fe.cloneWithTraversal(this.#e,H.is(this.#e.traversal)?H.cloneWithLeg(this.#e.traversal,Or.create(e,r)):Qe.cloneWithValue(this.#e.traversal,zr.createImmediate(r))));return new be(H.cloneWithLeg(this.#e,Or.create(e,r)))}}class be extends Se{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new ct(this,e)}$castTo(){return new be(this.#e)}$notNull(){return new be(this.#e)}toOperationNode(){return this.#e}}class ct{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return l.create(this.#e.toOperationNode(),lr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}var xr=f({is(e){return e.kind==="TupleNode"},create(e){return f({kind:"TupleNode",values:f(e)})}});var Pt=["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"],Mt=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ht=f({is(e){return e.kind==="DataTypeNode"},create(e){return f({kind:"DataTypeNode",dataType:e})}});function ft(e){if(Pt.includes(e))return!0;if(Mt.some((r)=>r.test(e)))return!0;return!1}function ns(e){if(lr(e))return e.toOperationNode();if(ft(e))return ht.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var pt=f({is(e){return e.kind==="CastNode"},create(e,r){return f({kind:"CastNode",expression:e,dataType:r})}});function Me(e=K){function r(n,u,re){return new a(qe(n,u,re))}function t(n,u){return new a(ut(n,u))}let o=Object.assign(r,{fn:void 0,eb:void 0,selectFrom(n){return We({queryId:Ye(),executor:e,queryNode:$t.createFrom(A(n))})},case(n){return new fc({node:To.create(Pn(n)?void 0:w(n))})},ref(n,u){if(Pn(u))return new a(Io(n));return new Se(lt(n,u))},jsonPath(){return new Se(H.create())},table(n){return new a(Ft(n))},val(n){return new a(m(n))},refTuple(...n){return new a(xr.create(n.map(w)))},tuple(...n){return new a(xr.create(n.map(m)))},lit(n){return new a(le(n))},unary:t,not(n){return t("not",n)},exists(n){return t("exists",n)},neg(n){return t("-",n)},between(n,u,re){return new a(I.create(w(n),Mo.create("between"),W.create(m(u),m(re))))},betweenSymmetric(n,u,re){return new a(I.create(w(n),Mo.create("between symmetric"),W.create(m(u),m(re))))},and(n){if(Nn(n))return new a(oe(n,"and"));return new a(_e(n,"and"))},or(n){if(Nn(n))return new a(oe(n,"or"));return new a(_e(n,"or"))},parens(...n){let u=rr(n);if(Ro.is(u))return new a(u);else return new a(Ro.create(u))},cast(n,u){return new a(pt.create(w(n),ns(u)))},withSchema(n){return Me(e.withPluginAtFront(new rs(n)))}});return o.fn=xu(),o.eb=o,o}function q(e){return Me()}function fo(e){if(lr(e))return e.toOperationNode();else if(Kt(e))return e(q()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function De(e){if(lr(e))return e.toOperationNode();else if(Kt(e))return e(q()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function V(e){return Ce(e)||Wr(e)||Kt(e)}function Ze(e){if(Vt(e))return Io(e);return e.toOperationNode()}function z(e){if(Nn(e))return e.map((r)=>w(r));else return[w(e)]}function w(e){if(V(e))return fo(e);return Ze(e)}function lt(e,r){let t=Io(e);if(lf(r))return fe.create(t,Qe.create(Mo.create(r)));let o=r.slice(0,-1);if(lf(o))return fe.create(t,H.create(Mo.create(o)));throw Error(`Invalid JSON operator: ${r}`)}function Io(e){if(!e.includes("."))return te.create(Zt.create(e));let t=e.split(".").map(gr);if(t.length===3)return Ut(t);if(t.length===2)return zt(t);throw Error(`invalid column reference ${e}`)}function Pr(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(gr);return l.create(Io(t),ze.create(o))}else return Io(e)}function sf(e){return Zt.create(e)}function Wi(e){if(e.includes(" ")){let[t,o]=e.split(" ").map(gr);if(!tr(o))throw Error(`invalid order direction "${o}" next to "${t}"`);return E([t,o])[0]}else return sf(e)}function Ut(e){let[r,t,o]=e;return te.create(Zt.create(o),g.createWithSchema(r,t))}function zt(e){let[r,t]=e;return te.create(Zt.create(t),g.create(r))}function gr(e){return e.trim()}class ke{#e;constructor(e){this.#e=f(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new Nt(this,e)}$castTo(){return new ke({...this.#e})}$notNull(){return new ke(this.#e)}withPlugin(e){return new ke({...this.#e,plugins:this.#e.plugins!==void 0?f([...this.#e.plugins,e]):f([e])})}toOperationNode(){return this.#t(this.#r())}compile(e){return this.#i(this.#r(e))}async execute(e){let r=this.#r(e);return r.executeQuery(this.#i(r))}#r(e){let r=e!==void 0?e.getExecutor():K;return this.#e.plugins!==void 0?r.withPlugins(this.#e.plugins):r}#t(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#i(e){return e.compileQuery(this.#t(e),this.#e.queryId)}}function Q(e){return new ke(e)}class Nt{#e;#r;constructor(e,r){this.#e=e,this.#r=r}get expression(){return this.#e}get alias(){return this.#r}get rawBuilder(){return this.#e}toOperationNode(){return l.create(this.#e.toOperationNode(),lr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}var Pe=Object.assign((e,...r)=>Q({queryId:Ye(),rawNode:Bt.create(e,r?.map(yt)??[])}),{ref(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(Io(e))})},val(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(m(e))})},value(e){return this.val(e)},table(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(Ft(e))})},id(...e){let r=Array(e.length+1).fill(".");return r[0]="",r[r.length-1]="",Q({queryId:Ye(),rawNode:Bt.create(r,e.map(ze.create))})},lit(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(zr.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return Q({queryId:Ye(),rawNode:Bt.createWithSql(e)})},join(e,r=Pe`, `){let t=Array(Math.max(2*e.length-1,0)),o=r.toOperationNode();for(let n=0;n<e.length;++n)if(t[2*n]=yt(e[n]),n!==e.length-1)t[2*n+1]=o;return Q({queryId:Ye(),rawNode:Bt.createWithChildren(t)})}});function yt(e){if(lr(e))return e.toOperationNode();return m(e)}var ur=f({raw(e,r=[]){return f({sql:e,query:Bt.createWithSql(e),parameters:f(r),queryId:Ye()})}});
|
|
3
|
+
export{lr,Zt,Ki,of,Io,sf,Wi,Da,zr,rr,ce,$t,wu,Ye,uc,rs,La,vu,dc,ws,xu,To,fc,ns,fo,af,Ft,Pe,ur};
|