@shumai-one/shumai 0.4.8 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/bin/{chunk-qw76wcrb.js → chunk-03bfjh8k.js} +2 -2
  2. package/bin/{chunk-6xqpbkb6.js → chunk-0tf15vee.js} +2 -2
  3. package/bin/{chunk-e333evwr.js → chunk-0vtk7wrf.js} +2 -2
  4. package/bin/{chunk-b93qxjts.js → chunk-0yv0nnmh.js} +2 -2
  5. package/bin/{chunk-pg5mayjc.js → chunk-12npypek.js} +2 -2
  6. package/bin/chunk-13d525jm.js +2 -0
  7. package/bin/{chunk-qrmkkxjh.js → chunk-1k16xsqq.js} +10 -10
  8. package/bin/{chunk-dk2trprj.js → chunk-1yt1gsyy.js} +1 -1
  9. package/bin/{chunk-wqqdy0xb.js → chunk-20anqpf1.js} +2 -2
  10. package/bin/{chunk-tjhbr5ks.js → chunk-2g5qdx4s.js} +1 -1
  11. package/bin/{chunk-0b5s5ge0.js → chunk-31vx01aw.js} +2 -2
  12. package/bin/{chunk-tycap2k9.js → chunk-32japja5.js} +1 -1
  13. package/bin/chunk-35mpp84e.js +2 -0
  14. package/bin/{chunk-d9dmr2vc.js → chunk-36r20sj7.js} +1 -1
  15. package/bin/{chunk-67ewr4j4.js → chunk-3btc8a0p.js} +2 -2
  16. package/bin/{chunk-2y7y60pc.js → chunk-3cvbb6kh.js} +2 -2
  17. package/bin/chunk-3ewmtf1c.js +1 -0
  18. package/bin/chunk-3fjgf7eb.js +3 -0
  19. package/bin/chunk-3xw70yr4.js +2 -0
  20. package/bin/{chunk-1qk4e3j9.js → chunk-3z20b2hz.js} +2 -2
  21. package/bin/{chunk-hed37kyr.js → chunk-3zvvct3r.js} +1 -1
  22. package/bin/{chunk-1zpsbvq9.js → chunk-51h2bgpf.js} +3 -3
  23. package/bin/{chunk-5vvvgjvz.js → chunk-5bpvwv66.js} +2 -2
  24. package/bin/{chunk-4tpkx2ft.js → chunk-5jbx9gqe.js} +1 -1
  25. package/bin/{chunk-vfv27kve.js → chunk-5patxztz.js} +4 -4
  26. package/bin/chunk-5seey9ee.js +2 -0
  27. package/bin/{chunk-251rat7t.js → chunk-5t05jpna.js} +3 -3
  28. package/bin/{chunk-pbq64m5k.js → chunk-5yd9cv7f.js} +5 -5
  29. package/bin/chunk-66hdwm6f.js +2 -0
  30. package/bin/{chunk-mcq3pe4v.js → chunk-6bgbx563.js} +2 -2
  31. package/bin/{chunk-j3qz3wa3.js → chunk-6vvs18bw.js} +1 -1
  32. package/bin/chunk-756mr32b.js +2 -0
  33. package/bin/{chunk-fezar34g.js → chunk-7vd5yajk.js} +5 -5
  34. package/bin/chunk-7wb3dga5.js +2 -0
  35. package/bin/{chunk-tf3hke5h.js → chunk-9h6nn1a3.js} +1 -1
  36. package/bin/chunk-9k86d2a3.js +4 -0
  37. package/bin/chunk-9wk11jtz.js +1 -0
  38. package/bin/chunk-a1crhhzy.js +1 -0
  39. package/bin/chunk-axfwh5et.js +2 -0
  40. package/bin/{chunk-yeb5bcxz.js → chunk-b9j5575n.js} +2 -2
  41. package/bin/chunk-cgsxyw07.js +2 -0
  42. package/bin/{chunk-5pcv139g.js → chunk-cw8z9w5c.js} +2 -2
  43. package/bin/{chunk-4tm9cw4v.js → chunk-czny5thj.js} +2 -2
  44. package/bin/{chunk-jwhgybtg.js → chunk-d7mgjqf8.js} +1 -1
  45. package/bin/{chunk-jgnp68ez.js → chunk-d9btz95y.js} +1 -1
  46. package/bin/chunk-dckdnqc0.js +2 -0
  47. package/bin/chunk-dx0wz749.js +211 -0
  48. package/bin/{chunk-mn9ax7qa.js → chunk-dz33q4v1.js} +2 -2
  49. package/bin/chunk-dz4fdrmk.js +1 -0
  50. package/bin/{chunk-29wjvgwv.js → chunk-e3r1m6rb.js} +1 -1
  51. package/bin/chunk-edjtb7pk.js +2 -0
  52. package/bin/{chunk-j95fjg69.js → chunk-eez1yncf.js} +2 -2
  53. package/bin/{chunk-x33bf3ay.js → chunk-exgtwask.js} +1 -1
  54. package/bin/{chunk-ws216bmf.js → chunk-f22nrm6r.js} +4 -4
  55. package/bin/{chunk-xmn5v64e.js → chunk-fhq5m9ya.js} +2 -2
  56. package/bin/{chunk-gj3vrbkx.js → chunk-fyssg02c.js} +31 -31
  57. package/bin/{chunk-rzannb5e.js → chunk-g8h1e1kh.js} +2 -2
  58. package/bin/{chunk-qje7g7t7.js → chunk-ghjhyajn.js} +2 -2
  59. package/bin/{chunk-9v10mkts.js → chunk-gptzcgte.js} +1 -1
  60. package/bin/{chunk-r8ss8xm1.js → chunk-grsgkkrb.js} +5 -5
  61. package/bin/{chunk-dpn61sht.js → chunk-gy8z8sd7.js} +1 -1
  62. package/bin/{chunk-e3qxpswy.js → chunk-h153xefb.js} +1 -1
  63. package/bin/chunk-h82r29wm.js +129 -0
  64. package/bin/{chunk-ze3msq86.js → chunk-h9x81yp6.js} +1 -1
  65. package/bin/{chunk-b9p9yhky.js → chunk-hr2027z3.js} +8 -8
  66. package/bin/{chunk-7rvyq5gr.js → chunk-hx76pje1.js} +1 -1
  67. package/bin/chunk-hz9stgvn.js +1 -0
  68. package/bin/chunk-hzr8100w.js +3 -0
  69. package/bin/{chunk-4sq35ks7.js → chunk-j3xaq9s3.js} +2 -2
  70. package/bin/{chunk-pbmkewt5.js → chunk-j909v9p5.js} +1 -1
  71. package/bin/chunk-jb6d142z.js +1 -0
  72. package/bin/chunk-k9cgfzgk.js +3 -0
  73. package/bin/{chunk-zhx4vsgt.js → chunk-kgfa5y9w.js} +10 -10
  74. package/bin/{chunk-1ymyhrh2.js → chunk-kzsdp31a.js} +2 -2
  75. package/bin/{chunk-9ht2kr33.js → chunk-m1xc3t0p.js} +7 -7
  76. package/bin/{chunk-wdbew0hx.js → chunk-m7dp8rqv.js} +1 -1
  77. package/bin/{chunk-0jaj2807.js → chunk-m9sp00a9.js} +4 -4
  78. package/bin/{chunk-qn37fsy3.js → chunk-mcd7zas7.js} +2 -2
  79. package/bin/chunk-meyvvmgk.js +1 -0
  80. package/bin/{chunk-y4pe65d1.js → chunk-mqr096rn.js} +1 -1
  81. package/bin/{chunk-ybnykjsg.js → chunk-mt532a33.js} +1 -1
  82. package/bin/{chunk-twx715xf.js → chunk-myd3wg9a.js} +2 -2
  83. package/bin/chunk-n1b3pt17.js +14 -0
  84. package/bin/chunk-n5v48hz5.js +2 -0
  85. package/bin/{chunk-65ets3f0.js → chunk-p5v22g5n.js} +2 -2
  86. package/bin/chunk-phzemmmy.js +2 -0
  87. package/bin/{chunk-w53gqdnw.js → chunk-q5mkbnr9.js} +2 -2
  88. package/bin/chunk-qhzat67w.js +2 -0
  89. package/bin/{chunk-7nv7r7zx.js → chunk-r1m4q8vw.js} +1 -1
  90. package/bin/{chunk-jhxcm88f.js → chunk-r5rpdhed.js} +2 -2
  91. package/bin/{chunk-v6tjp5qt.js → chunk-r6gkv98n.js} +6 -6
  92. package/bin/{chunk-s26a26h3.js → chunk-rkq6jvhb.js} +3 -3
  93. package/bin/{chunk-drpdjxmw.js → chunk-rn9rktp4.js} +5 -5
  94. package/bin/{chunk-dscq4a4k.js → chunk-rq2h2bwt.js} +2 -2
  95. package/bin/{chunk-dp1mrw7m.js → chunk-sg7n2g3z.js} +1 -1
  96. package/bin/chunk-smcn7ep7.js +2 -0
  97. package/bin/{chunk-p706vjvr.js → chunk-tcat7q9p.js} +2 -2
  98. package/bin/chunk-tf8q7h6b.js +1 -0
  99. package/bin/{chunk-6t5r26bm.js → chunk-trndqdaa.js} +1 -1
  100. package/bin/chunk-tvr5rm1g.js +1 -0
  101. package/bin/chunk-ty88m3yg.js +2 -0
  102. package/bin/chunk-v2x9915x.js +1 -0
  103. package/bin/{chunk-fnca3xqw.js → chunk-v42jcex0.js} +4 -4
  104. package/bin/{chunk-pq3pyrvy.js → chunk-vbbn4hth.js} +1 -1
  105. package/bin/chunk-vnk2p7mq.css +1 -0
  106. package/bin/{chunk-r7e2fmmx.js → chunk-wkxm6yny.js} +2 -2
  107. package/bin/{chunk-t2sqtc9p.js → chunk-wydd7sz7.js} +2 -2
  108. package/bin/chunk-x8hky9td.js +1 -0
  109. package/bin/{chunk-frma9pgq.js → chunk-xvdd04gy.js} +1 -1
  110. package/bin/{chunk-ht64xpjp.js → chunk-y03z5rrg.js} +3 -3
  111. package/bin/chunk-y12ah7c6.js +1 -0
  112. package/bin/chunk-y7jz31ay.js +1 -0
  113. package/bin/chunk-ydk3edsw.js +1 -0
  114. package/bin/{chunk-6h76kqv2.js → chunk-yfe6hkzk.js} +3 -3
  115. package/bin/{chunk-afsm0ct9.js → chunk-z1r86fna.js} +2 -2
  116. package/bin/{chunk-bcjkapyp.js → chunk-z8mmqfm4.js} +1 -1
  117. package/bin/chunk-zbma2zeh.js +1 -0
  118. package/bin/{chunk-45mheqnm.js → chunk-zcrtr8qd.js} +2 -2
  119. package/bin/{chunk-czwpfv0w.js → chunk-zfqz72sd.js} +1 -1
  120. package/bin/{chunk-nradb5py.js → chunk-zhe16jvg.js} +1 -1
  121. package/bin/{chunk-75x3b8ds.js → chunk-zwb9kamp.js} +2 -2
  122. package/bin/shumai-app.html +1 -1
  123. package/bin/shumai-app.js +572 -321
  124. package/package.json +9 -8
  125. package/prisma/migrations/20260927092537_add_notification_email_status/migration.sql +11 -0
  126. package/prisma/migrations/20261001015042_migrate_video_strategy_multi_and_resolutions/migration.sql +16 -0
  127. package/prisma/migrations/20261002104921_add_asset_status_failed/migration.sql +2 -0
  128. package/prisma/schema.prisma +11 -0
  129. package/bin/chunk-07pgpftg.js +0 -14
  130. package/bin/chunk-1y7nvhgx.js +0 -3
  131. package/bin/chunk-2ftmxhr5.js +0 -2
  132. package/bin/chunk-2kxhdnma.js +0 -3
  133. package/bin/chunk-3rjdkmhb.js +0 -2
  134. package/bin/chunk-43dzhk24.js +0 -211
  135. package/bin/chunk-55n569j1.js +0 -1
  136. package/bin/chunk-6jaf9hxa.js +0 -1
  137. package/bin/chunk-6vst0k0k.js +0 -2
  138. package/bin/chunk-7hxd4st0.js +0 -1
  139. package/bin/chunk-9kb55e6b.js +0 -1
  140. package/bin/chunk-bbk5v964.js +0 -1
  141. package/bin/chunk-bcqhjbpy.js +0 -2
  142. package/bin/chunk-bxksbrcm.js +0 -1
  143. package/bin/chunk-c1a1srsw.js +0 -2
  144. package/bin/chunk-c7yxnyep.js +0 -1
  145. package/bin/chunk-da4fd4f8.js +0 -2
  146. package/bin/chunk-dmewtzbe.js +0 -1
  147. package/bin/chunk-faaqparg.js +0 -2
  148. package/bin/chunk-g82qnxw6.js +0 -2
  149. package/bin/chunk-gc6m7agb.js +0 -3
  150. package/bin/chunk-j6ptdqp9.js +0 -2
  151. package/bin/chunk-kdg245g7.js +0 -1
  152. package/bin/chunk-mg4p33eg.js +0 -2
  153. package/bin/chunk-mrdznst9.js +0 -1
  154. package/bin/chunk-msg8j3hj.css +0 -1
  155. package/bin/chunk-n4f1he1g.js +0 -4
  156. package/bin/chunk-nsvfcp3f.js +0 -1
  157. package/bin/chunk-nx782n1x.js +0 -2
  158. package/bin/chunk-p4hwyysm.js +0 -2
  159. package/bin/chunk-qw4v0qdg.js +0 -1
  160. package/bin/chunk-rvj965cr.js +0 -1
  161. package/bin/chunk-sf9ezxgy.js +0 -2
  162. package/bin/chunk-twwpbp8d.js +0 -2
  163. package/bin/chunk-v3yfee88.js +0 -2
  164. package/bin/chunk-vq24vj88.js +0 -1
  165. package/bin/chunk-x79scans.js +0 -299
  166. package/bin/chunk-xktxk53n.js +0 -1
  167. package/bin/chunk-yvz2b957.js +0 -2
@@ -1,2 +1,2 @@
1
- import{h,D,b,u,S,L,t,o,K,Z,B,ft,Me,A,C,Ig,Tg,gC,Pt,As,Nr,An,$n,Qc,yr,on,Ur,$t,lr,gr,Lo}from"./chunk-43dzhk24.js";import{Or}from"./chunk-x79scans.js";import{xa}from"./chunk-07pgpftg.js";import{wa}from"./chunk-xmn5v64e.js";import{ai,Zl}from"./chunk-qn37fsy3.js";import{Bl}from"./chunk-bcqhjbpy.js";import{Sa}from"./chunk-6h76kqv2.js";import{Er}from"./chunk-twx715xf.js";S();function ke(i,s,P,r,c,f){let O=i.type==="folder",y=s.type==="folder";if(O!==y)return null;let w=y?r:c,k=w.findIndex((a)=>a.id===P),v=w.findIndex((a)=>a.id===s.id);if(k===-1||v===-1)return null;let W=Math.min(k,v),U=Math.max(k,v),N=w.slice(W,U+1),l=new Set(f);return N.forEach((a)=>{if(a.id)l.add(a.id)}),l}function Gn({teamId:i,projectId:s,projectName:P,assetId:r,rootFolderId:c,collection:f,onUpdateCollection:O}){let y=Me(),w=K(),{canEdit:k}=Pt(s),{setFields:v}=Or(),W=A.api.files[":fileId"].metadata.$patch,{mutate:U}=B({mutationFn:async(e)=>{if(!(await W(e)).ok)throw Error("Failed to patch metadata");return null}}),{data:N}=Z({queryKey:["fields",s],queryFn:async()=>{let e=await A.api.projects[":projectId"].fields.$get({param:{projectId:s}});if(!e.ok)throw Error("Failed to fetch fields");return await e.json()},enabled:!!s});h(()=>{if(N)v(N,s)},[N,s,v]);let l=r==="recently-deleted",a=r==="recents",[_,M]=u(null),[p,z]=u(new Set),[H,E]=u(null),[Ne,Ae]=u(240),[ze,Le]=u(360),{isChatbotOpen:V}=lr(),{members:Re,fetchMembers:oe}=Ur(),{metadata:ae,fetchMetadata:re,setMetadata:je}=gr(),ie=Boolean(ae["appearance.hideAgent"]);h(()=>{if(i)oe(i),re(i)},[i,oe,re]);let X=D(()=>f?.filter?.searchFilter?.conditions||[],[f]),[R,G]=u(X);h(()=>{G(X)},[X]);let le=`project:${s}:sort`,j=ae[le]||{field:"custom",order:"asc"},De=(e)=>{if(e)je(i,le,e)},x=!!f,Q=R.length>0||x,{fileListLeftSidebarCollapsed:de,setFileListLeftSidebarCollapsed:$e,fileListRightSidebarCollapsed:ce,setFileListRightSidebarCollapsed:Te,viewModes:qe}=$t(),fe=qe[s]??"card",Ee=b(null),{data:T}=l||a?{data:void 0}:Z({queryKey:["folders",r],queryFn:async()=>{let e=await A.api.folders[":folderId"].$get({param:{folderId:r}});if(!e.ok)throw Error("failed to fetch folder");return await e.json()}}),{setProjectState:pe,clearProjectState:ue}=on();h(()=>(pe({teamId:i,projectId:s,projectName:P,rootFolderId:c,ancestorFolders:T?.ancestorFolders??[],currentAsset:l?{name:Ig(),type:"folder"}:a?{name:Tg(),type:"folder"}:x?{id:f.id,name:f.name,type:"folder"}:{id:T?.id||r,name:T?.name,type:"folder"},isRootFolder:!l&&!a&&!x&&r===c,onFolderClick:(e)=>{y({to:"/projects/$projectId/folders/$folderId",params:{projectId:s,folderId:e}})}}),()=>ue()),[i,s,P,T,l,a,r,c,pe,ue,y]);let{data:J,fetchNextPage:ge,hasNextPage:he,isFetchingNextPage:me,isLoading:Ke}=ft({queryKey:l?["projects",s,"recently-deleted","folder"]:a?["projects",s,"recents","folder"]:["search",i,r,"folder",R,j,x],queryFn:async({pageParam:e})=>{if(l||x||a){if(l){let d=await A.api.projects[":projectId"]["recently-deleted"].$get({param:{projectId:s},query:{assetType:"folder",after:e}});if(!d.ok)throw Error("failed to fetch recently deleted folders");return await d.json()}return{data:[],pageInfo:{total:0}}}if(Q)return{data:[],pageInfo:{total:0}};let n=await A.api.folders[":folderId"].search.$post({param:{folderId:r},json:{assetType:"folder",after:e,recursively:!1,sort:j,conditions:[]}});if(!n.ok)throw Error("failed to search folders");return await n.json()},enabled:!Q&&!a,initialPageParam:"",getNextPageParam:(e)=>e.pageInfo?.cursor||void 0}),{data:Y,fetchNextPage:ye,hasNextPage:xe,isFetchingNextPage:Se,isLoading:Qe}=ft({queryKey:l?["projects",s,"recently-deleted","file"]:a?["projects",s,"recents","file"]:["search",i,r,"file",R,j,x],queryFn:async({pageParam:e})=>{if(l){let d=await A.api.projects[":projectId"]["recently-deleted"].$get({param:{projectId:s},query:{assetType:"file",after:e}});if(!d.ok)throw Error("failed to fetch recently deleted files");return await d.json()}if(a){let d=await A.api.projects[":projectId"].recents.$get({param:{projectId:s},query:{after:e,first:"20"}});if(!d.ok)throw Error("failed to fetch recent files");return await d.json()}let n=await A.api.folders[":folderId"].search.$post({param:{folderId:r},json:{assetType:"file",after:e,recursively:Q||x,conditions:R,sort:j}});if(!n.ok)throw Error("failed to search files");return await n.json()},initialPageParam:"",getNextPageParam:(e)=>e.pageInfo?.cursor||void 0}),I=J?.pages.flatMap((e)=>e.data??[])??[],g=Y?.pages.flatMap((e)=>e.data??[])??[],Fe=(!Q&&!a?Ke:!1)||Qe,we=J?.pages[0]?.pageInfo?.total,be=Y?.pages[0]?.pageInfo?.total,ve=J?.pages[0]?.pageInfo?.totalSize,Ie=Y?.pages[0]?.pageInfo?.totalSize,ee=()=>{z(new Set),M(null),E(null)},{dragState:q,handleDragStart:Oe,handleDragEnd:We}=Zl({teamId:i,projectId:s,assetId:r,folders:I,files:g,selectedIds:p,onClearSelection:ee}),te=D(()=>{if(p.size!==1)return null;let e=Array.from(p)[0];return g.find((d)=>d.id===e)||null},[p,g]),Ce=(e)=>{if(l)return;if(e.type==="folder")G([]),y({to:"/projects/$projectId/folders/$folderId",params:{projectId:s,folderId:e.id}});else y({to:"/projects/$projectId/files/$fileId",params:{projectId:s,fileId:e.versionStack?e.versionStack.id:e.id},search:{version:void 0}})},Pe=(e,n)=>{let d=n.metaKey||n.ctrlKey;if(n.shiftKey&&H){let ne=[...I,...g].find((m)=>m.id===H);if(ne){let m=ke(ne,e,H,I,g,p);if(m){z(m),M(e);return}}}if(d){let F=new Set(p);if(F.has(e.id)){if(F.delete(e.id),z(F),_?.id===e.id){let m=[...I,...g].find((Ue)=>F.has(Ue.id));M(m||null),E(m?m.id:null)}}else F.add(e.id),z(F),E(e.id),M(e);return}z(new Set([e.id])),E(e.id),M(e)},se=(e,n,d)=>{U({param:{fileId:e},json:[{key:n,value:d}]},{onSuccess:()=>{w.invalidateQueries({queryKey:["folders",r,"children",{assetType:"file"}]}),w.invalidateQueries({queryKey:["search",i,r]})}})};if(Lo())return t(Bl,{teamId:i,projectId:s,assetId:r,folders:I,files:g,totalFolders:we,totalFiles:be,totalFoldersSize:ve,totalFilesSize:Ie,selectedItem:_,selectedIds:p,onItemSelect:Pe,onItemDoubleClick:Ce,onSaveField:se,onClearSelection:ee,fetchNextFoldersPage:ge,hasNextFoldersPage:he||!1,isFetchingNextFoldersPage:me,fetchNextFilesPage:ye,hasNextFilesPage:xe||!1,isFetchingNextFilesPage:Se,isRecentlyDeleted:l,isRecents:a,isLoading:Fe,rootFolderId:c});return o($n,{modifiers:[ai.configure({anchor:{x:0,y:0}})],plugins:(e)=>e.map((n)=>{if(n===As)return As.configure({dropAnimation:null});if(typeof n==="object"&&n!==null&&"plugin"in n&&n.plugin===As)return As.configure({dropAnimation:null});return n}),sensors:l||a||!k?[]:[An.configure({activationConstraints:[new Nr.Distance({value:10})]})],onDragStart:Oe,onDragEnd:We,children:[t("div",{className:"flex flex-1 flex-col bg-background min-h-0",children:o("div",{ref:Ee,className:"flex flex-1 overflow-hidden relative",children:[!de&&t("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>$e(!0)}),(!ce||V)&&t("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>{Te(!0),lr.getState().setIsChatbotOpen(!1)}}),!de&&o(L,{children:[t("div",{className:"bg-background",style:{width:Ne},children:t(yr,{teamId:i,projectId:s,projectName:P,rootFolderId:c,dragState:q,ancestorFolders:T?.ancestorFolders??[]})}),t(Er,{onResize:(e)=>{Ae((n)=>Math.max(180,Math.min(400,n+e)))},className:"hidden md:block"})]}),t(xa,{teamId:i,projectId:s,assetId:r,folders:I,files:g,totalFolders:we,totalFiles:be,totalFoldersSize:ve,totalFilesSize:Ie,selectedItem:_,selectedIds:p,onItemSelect:Pe,onItemDoubleClick:Ce,onSaveField:se,displayStyle:fe,onClearSelection:ee,fetchNextFoldersPage:ge,hasNextFoldersPage:he||!1,isFetchingNextFoldersPage:me,fetchNextFilesPage:ye,hasNextFilesPage:xe||!1,isFetchingNextFilesPage:Se,isRecentlyDeleted:l,isRecents:a,isLoading:Fe,filterConditions:R,onFilterChange:G,sort:j,onSortChange:De,dragState:q,collection:f,onUpdateCollection:O,rootFolderId:c}),(!ce||V&&!ie)&&o(L,{children:[t(Er,{onResize:(e)=>{Le((n)=>Math.max(240,Math.min(600,n-e)))},className:"hidden md:block"}),t("div",{style:{width:ze},className:"bg-background flex flex-col flex-shrink-0",children:V&&!ie?t(wa,{projectId:s,contextAssetId:r}):te?t(Sa,{teamId:i,projectId:s,file:te,onSaveField:(e,n)=>se(te.id,e,n),members:Re,hideAnnotationControl:!0}):t("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:gC()})})]})]})}),t(Qc,{children:q?.isActive?t("div",{className:C("flex items-center gap-2 rounded-md bg-popover px-3 py-2 text-sm font-medium text-popover-foreground shadow-md ring-1 ring-border cursor-grabbing",fe==="list"&&"w-30 h-[40px] px-0 flex-none overflow-hidden justify-center"),style:{transform:"translate(0px, 0px)"},children:o("span",{children:["Moving ",q.itemCount," item",q.itemCount!==1?"s":""]})}):null})]})}
1
+ import{h,N,y,u,S,L,t,o,Q,Z,B,pt,Re,A,C,zg,jg,GC,Dt,_s,Dr,_n,$n,Xc,br,un,zr,$t,lr,Ar,Lo}from"./chunk-dx0wz749.js";import{Fr}from"./chunk-h82r29wm.js";import{Ci}from"./chunk-n1b3pt17.js";import{Ei}from"./chunk-fhq5m9ya.js";import{ua,jl}from"./chunk-mcd7zas7.js";import{ql}from"./chunk-smcn7ep7.js";import{Ii}from"./chunk-yfe6hkzk.js";import{Ir}from"./chunk-myd3wg9a.js";S();function ke(i,s,P,r,c,f){let O=i.type==="folder",x=s.type==="folder";if(O!==x)return null;let b=x?r:c,k=b.findIndex((a)=>a.id===P),v=b.findIndex((a)=>a.id===s.id);if(k===-1||v===-1)return null;let W=Math.min(k,v),U=Math.max(k,v),M=b.slice(W,U+1),l=new Set(f);return M.forEach((a)=>{if(a.id)l.add(a.id)}),l}function Gn({teamId:i,projectId:s,projectName:P,assetId:r,rootFolderId:c,collection:f,onUpdateCollection:O}){let x=Re(),b=Q(),{canEdit:k}=Dt(s),{setFields:v}=Fr(),W=A.api.files[":fileId"].metadata.$patch,{mutate:U}=B({mutationFn:async(e)=>{if(!(await W(e)).ok)throw Error("Failed to patch metadata");return null}}),{data:M}=Z({queryKey:["fields",s],queryFn:async()=>{let e=await A.api.projects[":projectId"].fields.$get({param:{projectId:s}});if(!e.ok)throw Error("Failed to fetch fields");return await e.json()},enabled:!!s});h(()=>{if(M)v(M,s)},[M,s,v]);let l=r==="recently-deleted",a=r==="recents",[_,z]=u(null),[p,R]=u(new Set),[H,E]=u(null),[Ne,Me]=u(240),[Ae,ze]=u(360),{isChatbotOpen:V}=lr(),{members:Le,fetchMembers:oe}=zr(),{metadata:ae,fetchMetadata:re,setMetadata:je}=Ar(),ie=Boolean(ae["appearance.hideAgent"]);h(()=>{if(i)oe(i),re(i)},[i,oe,re]);let X=N(()=>f?.filter?.searchFilter?.conditions||[],[f]),[j,G]=u(X);h(()=>{G(X)},[X]);let le=`project:${s}:sort`,D=ae[le]||{field:"custom",order:"asc"},De=(e)=>{if(e)je(i,le,e)},F=!!f,K=j.length>0||F,{fileListLeftSidebarCollapsed:de,setFileListLeftSidebarCollapsed:$e,fileListRightSidebarCollapsed:ce,setFileListRightSidebarCollapsed:Te,viewModes:qe}=$t(),fe=qe[s]??"card",Ee=y(null),{data:T}=l||a?{data:void 0}:Z({queryKey:["folders",r],queryFn:async()=>{let e=await A.api.folders[":folderId"].$get({param:{folderId:r}});if(!e.ok)throw Error("failed to fetch folder");return await e.json()}}),{setProjectState:pe,clearProjectState:ue}=un();h(()=>(pe({teamId:i,projectId:s,projectName:P,rootFolderId:c,ancestorFolders:T?.ancestorFolders??[],currentAsset:l?{name:zg(),type:"folder"}:a?{name:jg(),type:"folder"}:F?{id:f.id,name:f.name,type:"folder"}:{id:T?.id||r,name:T?.name,type:"folder"},isRootFolder:!l&&!a&&!F&&r===c,onFolderClick:(e)=>{x({to:"/projects/$projectId/folders/$folderId",params:{projectId:s,folderId:e}})}}),()=>ue()),[i,s,P,T,l,a,r,c,pe,ue,x]);let{data:J,fetchNextPage:ge,hasNextPage:he,isFetchingNextPage:me,isLoading:Ke}=pt({queryKey:l?["projects",s,"recently-deleted","folder"]:a?["projects",s,"recents","folder"]:["search",i,r,"folder",j,D,F],queryFn:async({pageParam:e})=>{if(l||F||a){if(l){let d=await A.api.projects[":projectId"]["recently-deleted"].$get({param:{projectId:s},query:{assetType:"folder",after:e}});if(!d.ok)throw Error("failed to fetch recently deleted folders");return await d.json()}return{data:[],pageInfo:{total:0}}}if(K)return{data:[],pageInfo:{total:0}};let n=await A.api.folders[":folderId"].search.$post({param:{folderId:r},json:{assetType:"folder",after:e,recursively:!1,sort:D,conditions:[]}});if(!n.ok)throw Error("failed to search folders");return await n.json()},enabled:!K&&!a,initialPageParam:"",getNextPageParam:(e)=>e.pageInfo?.cursor||void 0}),{data:Y,fetchNextPage:ye,hasNextPage:xe,isFetchingNextPage:Se,isLoading:Qe}=pt({queryKey:l?["projects",s,"recently-deleted","file"]:a?["projects",s,"recents","file"]:["search",i,r,"file",j,D,F],queryFn:async({pageParam:e})=>{if(l){let d=await A.api.projects[":projectId"]["recently-deleted"].$get({param:{projectId:s},query:{assetType:"file",after:e}});if(!d.ok)throw Error("failed to fetch recently deleted files");return await d.json()}if(a){let d=await A.api.projects[":projectId"].recents.$get({param:{projectId:s},query:{after:e,first:"20"}});if(!d.ok)throw Error("failed to fetch recent files");return await d.json()}let n=await A.api.folders[":folderId"].search.$post({param:{folderId:r},json:{assetType:"file",after:e,recursively:K||F,conditions:j,sort:D}});if(!n.ok)throw Error("failed to search files");return await n.json()},initialPageParam:"",getNextPageParam:(e)=>e.pageInfo?.cursor||void 0}),I=J?.pages.flatMap((e)=>e.data??[])??[],g=Y?.pages.flatMap((e)=>e.data??[])??[],Fe=(!K&&!a?Ke:!1)||Qe,we=J?.pages[0]?.pageInfo?.total,be=Y?.pages[0]?.pageInfo?.total,ve=J?.pages[0]?.pageInfo?.totalSize,Ie=Y?.pages[0]?.pageInfo?.totalSize,ee=()=>{R(new Set),z(null),E(null)},{dragState:q,handleDragStart:Oe,handleDragEnd:We}=jl({teamId:i,projectId:s,assetId:r,folders:I,files:g,selectedIds:p,onClearSelection:ee}),te=N(()=>{if(p.size!==1)return null;let e=Array.from(p)[0];return g.find((d)=>d.id===e)||null},[p,g]),Ce=(e)=>{if(l)return;if(e.type==="folder")G([]),x({to:"/projects/$projectId/folders/$folderId",params:{projectId:s,folderId:e.id}});else x({to:"/projects/$projectId/files/$fileId",params:{projectId:s,fileId:e.versionStack?e.versionStack.id:e.id},search:{version:void 0}})},Pe=(e,n)=>{let d=n.metaKey||n.ctrlKey;if(n.shiftKey&&H){let ne=[...I,...g].find((m)=>m.id===H);if(ne){let m=ke(ne,e,H,I,g,p);if(m){R(m),z(e);return}}}if(d){let w=new Set(p);if(w.has(e.id)){if(w.delete(e.id),R(w),_?.id===e.id){let m=[...I,...g].find((Ue)=>w.has(Ue.id));z(m||null),E(m?m.id:null)}}else w.add(e.id),R(w),E(e.id),z(e);return}R(new Set([e.id])),E(e.id),z(e)},se=(e,n,d)=>{U({param:{fileId:e},json:[{key:n,value:d}]},{onSuccess:()=>{b.invalidateQueries({queryKey:["folders",r,"children",{assetType:"file"}]}),b.invalidateQueries({queryKey:["search",i,r]})}})};if(Lo())return t(ql,{teamId:i,projectId:s,assetId:r,folders:I,files:g,totalFolders:we,totalFiles:be,totalFoldersSize:ve,totalFilesSize:Ie,selectedItem:_,selectedIds:p,onItemSelect:Pe,onItemDoubleClick:Ce,onSaveField:se,onClearSelection:ee,fetchNextFoldersPage:ge,hasNextFoldersPage:he||!1,isFetchingNextFoldersPage:me,fetchNextFilesPage:ye,hasNextFilesPage:xe||!1,isFetchingNextFilesPage:Se,isRecentlyDeleted:l,isRecents:a,isLoading:Fe,rootFolderId:c});return o($n,{modifiers:[ua.configure({anchor:{x:0,y:0}})],plugins:(e)=>e.map((n)=>{if(n===_s)return _s.configure({dropAnimation:null});if(typeof n==="object"&&n!==null&&"plugin"in n&&n.plugin===_s)return _s.configure({dropAnimation:null});return n}),sensors:l||a||!k?[]:[_n.configure({activationConstraints:[new Dr.Distance({value:10})]})],onDragStart:Oe,onDragEnd:We,children:[t("div",{className:"flex flex-1 flex-col bg-background min-h-0",children:o("div",{ref:Ee,className:"flex flex-1 overflow-hidden relative",children:[!de&&t("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>$e(!0)}),(!ce||V)&&t("div",{className:"md:hidden fixed inset-0 bg-black/50 z-40",onClick:()=>{Te(!0),lr.getState().setIsChatbotOpen(!1)}}),!de&&o(L,{children:[t("div",{className:"bg-background",style:{width:Ne},children:t(br,{teamId:i,projectId:s,projectName:P,rootFolderId:c,dragState:q,ancestorFolders:T?.ancestorFolders??[]})}),t(Ir,{onResize:(e)=>{Me((n)=>Math.max(180,Math.min(400,n+e)))},className:"hidden md:block"})]}),t(Ci,{teamId:i,projectId:s,assetId:r,folders:I,files:g,totalFolders:we,totalFiles:be,totalFoldersSize:ve,totalFilesSize:Ie,selectedItem:_,selectedIds:p,onItemSelect:Pe,onItemDoubleClick:Ce,onSaveField:se,displayStyle:fe,onClearSelection:ee,fetchNextFoldersPage:ge,hasNextFoldersPage:he||!1,isFetchingNextFoldersPage:me,fetchNextFilesPage:ye,hasNextFilesPage:xe||!1,isFetchingNextFilesPage:Se,isRecentlyDeleted:l,isRecents:a,isLoading:Fe,filterConditions:j,onFilterChange:G,sort:D,onSortChange:De,dragState:q,collection:f,onUpdateCollection:O,rootFolderId:c}),(!ce||V&&!ie)&&o(L,{children:[t(Ir,{onResize:(e)=>{ze((n)=>Math.max(240,Math.min(600,n-e)))},className:"hidden md:block"}),t("div",{style:{width:Ae},className:"bg-background flex flex-col flex-shrink-0",children:V&&!ie?t(Ei,{projectId:s,contextAssetId:r}):te?t(Ii,{teamId:i,projectId:s,file:te,onSaveField:(e,n)=>se(te.id,e,n),members:Le,hideAnnotationControl:!0}):t("div",{className:"flex h-full items-center justify-center p-4 text-center text-sm text-muted-foreground",children:GC()})})]})]})}),t(Xc,{children:q?.isActive?t("div",{className:C("flex items-center gap-2 rounded-md bg-popover px-3 py-2 text-sm font-medium text-popover-foreground shadow-md ring-1 ring-border cursor-grabbing",fe==="list"&&"w-30 h-[40px] px-0 flex-none overflow-hidden justify-center"),style:{transform:"translate(0px, 0px)"},children:o("span",{children:["Moving ",q.itemCount," item",q.itemCount!==1?"s":""]})}):null})]})}
2
2
  export{Gn};
@@ -1,8 +1,8 @@
1
1
  // @bun
2
- import{Yr}from"./chunk-vfv27kve.js";import{cr}from"./chunk-7nv7r7zx.js";import{ln,Ba}from"./chunk-gc6m7agb.js";import{yc,nl,Yt}from"./chunk-4sq35ks7.js";class g extends Error{code;diagnosticDetails;constructor(r,t,n){super(r);this.name="PiMessagesResponseError",this.code=t,this.diagnosticDetails=n}}function x(r){try{let t=JSON.parse(r),n=t?.error;return t&&typeof n==="object"&&n!==null&&!Array.isArray(n)?t:void 0}catch{return}}function m(r){return r.length>8192?`${r.slice(0,8192)}\u2026`:r}function y(r,t,n){let e=typeof n?.error?.message==="string"?n.error.message:void 0,s=typeof n?.error?.code==="string"?n.error.code:void 0,a=e??t,o=s?` (${s})`:"";return`${r.status} ${r.statusText}: ${a}${o}`}function w(r,t,n,e){let s=x(e),a=typeof s?.error?.code==="string"?s.error.code:void 0;return new g(y(n,e,s),a,{version:1,provider:r.provider,model:r.id,url:t.toString(),status:n.status,statusText:n.statusText,error:s?.error,body:s?void 0:m(e),timestampMs:Date.now()})}function h(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function l(r,t){if(!t)return;nl(r,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...t}})}function b(r){let t={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:"stop",timestamp:Date.now()},n=new Map;return(e)=>{switch(e.type){case"done":return Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),l(t,e.rewrite),{type:"done",reason:e.reason,message:t};case"error":return Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),l(t,e.rewrite),{type:"error",reason:e.reason,error:t};case"start":break;case"text_start":t.content[e.contentIndex]={type:"text",text:""};break;case"text_delta":t.content[e.contentIndex].text+=e.delta;break;case"text_end":Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case"thinking_start":t.content[e.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":t.content[e.contentIndex].thinking+=e.delta;break;case"thinking_end":Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case"toolcall_start":t.content[e.contentIndex]={type:"toolCall",id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,"");break;case"toolcall_delta":{let s=`${n.get(e.contentIndex)??""}${e.delta}`;n.set(e.contentIndex,s),t.content[e.contentIndex].arguments=Yr(s);break}case"toolcall_end":return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:"toolcall_end",contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*I(r){let t=new TextDecoder,n=r.getReader(),e="";try{while(!0){let{done:s,value:a}=await n.read();e+=s?t.decode():t.decode(a,{stream:!0}),e=e.replace(/\r\n/g,`
2
+ import{Jr}from"./chunk-5patxztz.js";import{cr}from"./chunk-r1m4q8vw.js";import{pn,qi}from"./chunk-3fjgf7eb.js";import{xc,il,Jt}from"./chunk-j3xaq9s3.js";class g extends Error{code;diagnosticDetails;constructor(r,t,n){super(r);this.name="PiMessagesResponseError",this.code=t,this.diagnosticDetails=n}}function x(r){try{let t=JSON.parse(r),n=t?.error;return t&&typeof n==="object"&&n!==null&&!Array.isArray(n)?t:void 0}catch{return}}function m(r){return r.length>8192?`${r.slice(0,8192)}\u2026`:r}function y(r,t,n){let e=typeof n?.error?.message==="string"?n.error.message:void 0,s=typeof n?.error?.code==="string"?n.error.code:void 0,a=e??t,o=s?` (${s})`:"";return`${r.status} ${r.statusText}: ${a}${o}`}function w(r,t,n,e){let s=x(e),a=typeof s?.error?.code==="string"?s.error.code:void 0;return new g(y(n,e,s),a,{version:1,provider:r.provider,model:r.id,url:t.toString(),status:n.status,statusText:n.statusText,error:s?.error,body:s?void 0:m(e),timestampMs:Date.now()})}function h(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function l(r,t){if(!t)return;il(r,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...t}})}function b(r){let t={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:"stop",timestamp:Date.now()},n=new Map;return(e)=>{switch(e.type){case"done":return Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),l(t,e.rewrite),{type:"done",reason:e.reason,message:t};case"error":return Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),l(t,e.rewrite),{type:"error",reason:e.reason,error:t};case"start":break;case"text_start":t.content[e.contentIndex]={type:"text",text:""};break;case"text_delta":t.content[e.contentIndex].text+=e.delta;break;case"text_end":Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case"thinking_start":t.content[e.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":t.content[e.contentIndex].thinking+=e.delta;break;case"thinking_end":Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case"toolcall_start":t.content[e.contentIndex]={type:"toolCall",id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,"");break;case"toolcall_delta":{let s=`${n.get(e.contentIndex)??""}${e.delta}`;n.set(e.contentIndex,s),t.content[e.contentIndex].arguments=Jr(s);break}case"toolcall_end":return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:"toolcall_end",contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*I(r){let t=new TextDecoder,n=r.getReader(),e="";try{while(!0){let{done:s,value:a}=await n.read();e+=s?t.decode():t.decode(a,{stream:!0}),e=e.replace(/\r\n/g,`
3
3
  `);let o=e.indexOf(`
4
4
 
5
5
  `);while(o!==-1){let c=f(e.slice(0,o));if(c)yield c;e=e.slice(o+2),o=e.indexOf(`
6
6
 
7
7
  `)}if(s)break}if(e.trim()){let s=f(e);if(s)yield s}}finally{n.releaseLock()}}function f(r){let t=r.split(`
8
- `).find((n)=>n.startsWith("data:"))?.slice(5).trim();return t&&t!=="[DONE]"?JSON.parse(t):void 0}function k(r,t,n){let e=n?"aborted":"error",s={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:e,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};if(!n&&t instanceof g)nl(s,yc("pi_messages_response_failure",t,t.diagnosticDetails));return{type:"error",reason:e,error:s}}function E(r,t){if(r)return r;return cr("PI_CACHE_RETENTION",t)==="long"?"long":void 0}var R=(r,t,n)=>{let e=new Yt,s=b(r);return(async()=>{try{let a=n?.apiKey;if(!a)throw Error(`No API key provided for provider "${r.provider}"`);let o=new URL(`${r.baseUrl.replace(/\/+$/u,"")}/messages`);if(n?.debug)o.searchParams.set("debug","1");let c={model:r.id,context:t,options:{temperature:n?.temperature,maxTokens:n?.maxTokens,reasoning:n?.reasoning,cacheRetention:E(n?.cacheRetention,n?.env),sessionId:n?.sessionId,toolChoice:n?.toolChoice}},p=await n?.onPayload?.(c,r);if(p!==void 0)c=p;let i=await fetch(o,{method:"POST",headers:{authorization:`Bearer ${a}`,accept:"text/event-stream","content-type":"application/json",...Ba(n?.headers)},body:JSON.stringify(c),signal:n?.signal});if(await n?.onResponse?.({status:i.status,headers:ln(i.headers)},r),!i.ok){let d=await i.text();throw w(r,o,i,d)}if(!i.body)throw Error(`${r.provider} response has no body`);for await(let d of I(i.body)){let u=s(d);if(e.push(u),u.type==="done"||u.type==="error")return}throw Error(`${r.provider} stream ended without a terminal event`)}catch(a){e.push(k(r,a,n?.signal?.aborted??!1))}})(),e},P=(r,t,n)=>{let e=n;return R(r,t,{...n,reasoning:n?.reasoning,toolChoice:e?.toolChoice,debug:e?.debug})};export{g as PiMessagesResponseError,R as stream,P as streamSimple};
8
+ `).find((n)=>n.startsWith("data:"))?.slice(5).trim();return t&&t!=="[DONE]"?JSON.parse(t):void 0}function k(r,t,n){let e=n?"aborted":"error",s={role:"assistant",content:[],api:r.api,provider:r.provider,model:r.id,usage:h(),stopReason:e,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};if(!n&&t instanceof g)il(s,xc("pi_messages_response_failure",t,t.diagnosticDetails));return{type:"error",reason:e,error:s}}function E(r,t){if(r)return r;return cr("PI_CACHE_RETENTION",t)==="long"?"long":void 0}var R=(r,t,n)=>{let e=new Jt,s=b(r);return(async()=>{try{let a=n?.apiKey;if(!a)throw Error(`No API key provided for provider "${r.provider}"`);let o=new URL(`${r.baseUrl.replace(/\/+$/u,"")}/messages`);if(n?.debug)o.searchParams.set("debug","1");let c={model:r.id,context:t,options:{temperature:n?.temperature,maxTokens:n?.maxTokens,reasoning:n?.reasoning,cacheRetention:E(n?.cacheRetention,n?.env),sessionId:n?.sessionId,toolChoice:n?.toolChoice}},p=await n?.onPayload?.(c,r);if(p!==void 0)c=p;let i=await fetch(o,{method:"POST",headers:{authorization:`Bearer ${a}`,accept:"text/event-stream","content-type":"application/json",...qi(n?.headers)},body:JSON.stringify(c),signal:n?.signal});if(await n?.onResponse?.({status:i.status,headers:pn(i.headers)},r),!i.ok){let d=await i.text();throw w(r,o,i,d)}if(!i.body)throw Error(`${r.provider} response has no body`);for await(let d of I(i.body)){let u=s(d);if(e.push(u),u.type==="done"||u.type==="error")return}throw Error(`${r.provider} stream ended without a terminal event`)}catch(a){e.push(k(r,a,n?.signal?.aborted??!1))}})(),e},P=(r,t,n)=>{let e=n;return R(r,t,{...n,reasoning:n?.reasoning,toolChoice:e?.toolChoice,debug:e?.debug})};export{g as PiMessagesResponseError,R as stream,P as streamSimple};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{Jt,qt}from"./chunk-drpdjxmw.js";import{w,G}from"./chunk-1ymyhrh2.js";var Vo=w(function(he){var{hasOwn:V}=Jt(),{streamCollector:te}=Jt();he.streamCollector=te;var{buildQueryString:K,HttpResponse:Q}=qt(),H=G("https"),{Readable:oe}=G("stream"),N=G("http2");function I(e){let t=e&&typeof e==="object"&&"reason"in e?e.reason:void 0;if(t){if(t instanceof Error){let s=Error("Request aborted");return s.name="AbortError",s.cause=t,s}let n=Error(String(t));return n.name="AbortError",n}let o=Error("Request aborted");return o.name="AbortError",o}var ne=["ECONNRESET","EPIPE","ETIMEDOUT"],J=(e)=>{let t={};for(let o in e){if(!V(e,o))continue;let n=e[o];t[o]=Array.isArray(n)?n.join(","):n}return t},h={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)},F=1000,se=(e,t,o=0)=>{if(!o)return-1;let n=(s)=>{let i=h.setTimeout(()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${o} ms.`),{name:"TimeoutError"}))},o-s),c=(a)=>{if(a?.connecting)a.on("connect",()=>{h.clearTimeout(i)});else h.clearTimeout(i)};if(e.socket)c(e.socket);else e.on("socket",c)};if(o<2000)return n(0),0;return h.setTimeout(n.bind(null,F),F)},re=(e,t,o=0,n,s)=>{if(o)return h.setTimeout(()=>{let i=`@smithy/node-http-handler - [${n?"ERROR":"WARN"}] a request has exceeded the configured ${o} ms requestTimeout.`;if(n){let c=Object.assign(Error(i),{name:"TimeoutError",code:"ETIMEDOUT"});e.destroy(c),t(c)}else i+=" Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.",s?.warn?.(i)},o);return-1},ie=3000,ce=(e,{keepAlive:t,keepAliveMsecs:o},n=ie)=>{if(t!==!0)return-1;let s=()=>{if(e.socket)e.socket.setKeepAlive(t,o||0);else e.on("socket",(i)=>{i.setKeepAlive(t,o||0)})};if(n===0)return s(),0;return h.setTimeout(s,n)},j=3000,ae=(e,t,o=0)=>{let n=(s)=>{let i=o-s,c=()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket timed out after ${o} ms of inactivity (configured by client requestHandler).`),{name:"TimeoutError"}))};if(e.socket)e.socket.setTimeout(i,c),e.on("close",()=>e.socket?.removeListener("timeout",c));else e.setTimeout(i,c)};if(0<o&&o<6000)return n(0),0;return h.setTimeout(n.bind(null,o===0?0:j),j)},B=6000;async function X(e,t,o=B,n=!1){let s=t.headers,i=s?s.Expect||s.expect:void 0,c=-1,a=!0;if(!n&&i==="100-continue")a=await Promise.race([new Promise((u)=>{c=Number(h.setTimeout(()=>u(!0),Math.max(B,o)))}),new Promise((u)=>{e.on("continue",()=>{h.clearTimeout(c),u(!0)}),e.on("response",()=>{h.clearTimeout(c),u(!1)}),e.on("error",()=>{h.clearTimeout(c),u(!1)})})]);if(a)ue(e,t.body)}function ue(e,t){if(t instanceof oe){t.pipe(e);return}if(t){let o=Buffer.isBuffer(t);if(o||typeof t==="string"){if(o&&t.byteLength===0)e.end();else e.end(t);return}let s=t;if(typeof s==="object"&&s.buffer&&typeof s.byteOffset==="number"&&typeof s.byteLength==="number"){e.end(Buffer.from(s.buffer,s.byteOffset,s.byteLength));return}e.end(Buffer.from(t));return}e.end()}var fe=0,O=void 0,W=void 0;class L{config;configProvider;socketWarningTimestamp=0;externalAgent=!1;metadata={handlerProtocol:"http/1.1"};static create(e){if(typeof e?.handle==="function")return e;return new L(e)}static checkSocketUsage(e,t,o=console){let{sockets:n,requests:s,maxSockets:i}=e;if(typeof i!=="number"||i===1/0)return t;let c=15000;if(Date.now()-c<t)return t;if(n&&s)for(let a in n){if(!V(n,a))continue;let u=n[a]?.length??0,l=s[a]?.length??0;if(u>=i&&l>=2*i)return o?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${u} and ${l} additional requests are enqueued.
2
+ import{Xt,qt}from"./chunk-rn9rktp4.js";import{w,G}from"./chunk-kzsdp31a.js";var Vo=w(function(he){var{hasOwn:V}=Xt(),{streamCollector:te}=Xt();he.streamCollector=te;var{buildQueryString:K,HttpResponse:Q}=qt(),H=G("https"),{Readable:oe}=G("stream"),N=G("http2");function I(e){let t=e&&typeof e==="object"&&"reason"in e?e.reason:void 0;if(t){if(t instanceof Error){let s=Error("Request aborted");return s.name="AbortError",s.cause=t,s}let n=Error(String(t));return n.name="AbortError",n}let o=Error("Request aborted");return o.name="AbortError",o}var ne=["ECONNRESET","EPIPE","ETIMEDOUT"],J=(e)=>{let t={};for(let o in e){if(!V(e,o))continue;let n=e[o];t[o]=Array.isArray(n)?n.join(","):n}return t},h={setTimeout:(e,t)=>setTimeout(e,t),clearTimeout:(e)=>clearTimeout(e)},F=1000,se=(e,t,o=0)=>{if(!o)return-1;let n=(s)=>{let i=h.setTimeout(()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket did not establish a connection with the server within the configured timeout of ${o} ms.`),{name:"TimeoutError"}))},o-s),c=(a)=>{if(a?.connecting)a.on("connect",()=>{h.clearTimeout(i)});else h.clearTimeout(i)};if(e.socket)c(e.socket);else e.on("socket",c)};if(o<2000)return n(0),0;return h.setTimeout(n.bind(null,F),F)},re=(e,t,o=0,n,s)=>{if(o)return h.setTimeout(()=>{let i=`@smithy/node-http-handler - [${n?"ERROR":"WARN"}] a request has exceeded the configured ${o} ms requestTimeout.`;if(n){let c=Object.assign(Error(i),{name:"TimeoutError",code:"ETIMEDOUT"});e.destroy(c),t(c)}else i+=" Init client requestHandler with throwOnRequestTimeout=true to turn this into an error.",s?.warn?.(i)},o);return-1},ie=3000,ce=(e,{keepAlive:t,keepAliveMsecs:o},n=ie)=>{if(t!==!0)return-1;let s=()=>{if(e.socket)e.socket.setKeepAlive(t,o||0);else e.on("socket",(i)=>{i.setKeepAlive(t,o||0)})};if(n===0)return s(),0;return h.setTimeout(s,n)},j=3000,ae=(e,t,o=0)=>{let n=(s)=>{let i=o-s,c=()=>{e.destroy(),t(Object.assign(Error(`@smithy/node-http-handler - the request socket timed out after ${o} ms of inactivity (configured by client requestHandler).`),{name:"TimeoutError"}))};if(e.socket)e.socket.setTimeout(i,c),e.on("close",()=>e.socket?.removeListener("timeout",c));else e.setTimeout(i,c)};if(0<o&&o<6000)return n(0),0;return h.setTimeout(n.bind(null,o===0?0:j),j)},B=6000;async function X(e,t,o=B,n=!1){let s=t.headers,i=s?s.Expect||s.expect:void 0,c=-1,a=!0;if(!n&&i==="100-continue")a=await Promise.race([new Promise((u)=>{c=Number(h.setTimeout(()=>u(!0),Math.max(B,o)))}),new Promise((u)=>{e.on("continue",()=>{h.clearTimeout(c),u(!0)}),e.on("response",()=>{h.clearTimeout(c),u(!1)}),e.on("error",()=>{h.clearTimeout(c),u(!1)})})]);if(a)ue(e,t.body)}function ue(e,t){if(t instanceof oe){t.pipe(e);return}if(t){let o=Buffer.isBuffer(t);if(o||typeof t==="string"){if(o&&t.byteLength===0)e.end();else e.end(t);return}let s=t;if(typeof s==="object"&&s.buffer&&typeof s.byteOffset==="number"&&typeof s.byteLength==="number"){e.end(Buffer.from(s.buffer,s.byteOffset,s.byteLength));return}e.end(Buffer.from(t));return}e.end()}var fe=0,O=void 0,W=void 0;class L{config;configProvider;socketWarningTimestamp=0;externalAgent=!1;metadata={handlerProtocol:"http/1.1"};static create(e){if(typeof e?.handle==="function")return e;return new L(e)}static checkSocketUsage(e,t,o=console){let{sockets:n,requests:s,maxSockets:i}=e;if(typeof i!=="number"||i===1/0)return t;let c=15000;if(Date.now()-c<t)return t;if(n&&s)for(let a in n){if(!V(n,a))continue;let u=n[a]?.length??0,l=s[a]?.length??0;if(u>=i&&l>=2*i)return o?.warn?.(`@smithy/node-http-handler:WARN - socket usage at capacity=${u} and ${l} additional requests are enqueued.
3
3
  See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-configuring-maxsockets.html
4
4
  or increase socketAcquisitionWarningTimeout=(millis) in the NodeHttpHandler config.`),Date.now()}return t}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(this.resolveDefaultConfig(n))}).catch(o);else t(this.resolveDefaultConfig(e))})}destroy(){this.config?.httpAgent?.destroy(),this.config?.httpsAgent?.destroy()}async handle(e,{abortSignal:t,requestTimeout:o}={}){if(!this.config)this.config=await this.configProvider;let n=this.config,s=n.logger,i=e.protocol==="https:";if(!i&&!this.config.httpAgent)this.config.httpAgent=await this.config.httpAgentProvider();return new Promise((c,a)=>{let u=void 0,l=-1,m=-1,T=-1,C=-1,E=-1,k=()=>{h.clearTimeout(l),h.clearTimeout(m),h.clearTimeout(T),h.clearTimeout(C),h.clearTimeout(E)},U=async(r)=>{await u,k(),c(r)},p=async(r)=>{await u,k(),a(r)};if(t?.aborted){let r=I(t);p(r);return}let S=e.headers,R=S?(S.Expect??S.expect)==="100-continue":!1,x=i?n.httpsAgent:n.httpAgent;if(R&&!this.externalAgent)x=new(i?H.Agent:O)({keepAlive:!1,maxSockets:1/0});l=h.setTimeout(()=>{this.socketWarningTimestamp=L.checkSocketUsage(x,this.socketWarningTimestamp,s)},n.socketAcquisitionWarningTimeout??(n.requestTimeout??2000)+(n.connectionTimeout??1000));let D=e.query?K(e.query):"",v=void 0;if(e.username!=null||e.password!=null){let r=e.username??"",f=e.password??"";v=`${r}:${f}`}let P=e.path;if(D)P+=`?${D}`;if(e.fragment)P+=`#${e.fragment}`;let y=e.hostname??"";if(y[0]==="["&&y.endsWith("]"))y=e.hostname.slice(1,-1);else y=e.hostname;let _={headers:e.headers,host:y,method:e.method,path:P,port:e.port,agent:x,auth:v},g=(i?H.request:W)(_,(r)=>{let f=new Q({statusCode:r.statusCode||-1,reason:r.statusMessage,headers:J(r.headers),body:r});U({response:f})});if(g.on("error",(r)=>{if(ne.includes(r.code))p(Object.assign(r,{name:"TimeoutError"}));else p(r)}),t){let r=()=>{g.destroy();let f=I(t);p(f)};if(typeof t.addEventListener==="function"){let f=t;f.addEventListener("abort",r,{once:!0}),g.once("close",()=>f.removeEventListener("abort",r))}else t.onabort=r}let b=o??n.requestTimeout;m=se(g,p,n.connectionTimeout),T=re(g,p,b,n.throwOnRequestTimeout,s??console),C=ae(g,p,n.socketTimeout);let d=_.agent;if(typeof d==="object"&&"keepAlive"in d)E=ce(g,{keepAlive:d.keepAlive,keepAliveMsecs:d.keepAliveMsecs});u=X(g,e,b,this.externalAgent).catch((r)=>(k(),a(r)))})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>{if(e===Symbol.for("logger"))return{...o,logger:o.logger??t};return{...o,[e]:t}})}httpHandlerConfigs(){return this.config??{}}resolveDefaultConfig(e){let{requestTimeout:t,connectionTimeout:o,socketTimeout:n,socketAcquisitionWarningTimeout:s,httpAgent:i,httpsAgent:c,throwOnRequestTimeout:a,logger:u}=e||{},l=!0,m=50;return{connectionTimeout:o,requestTimeout:t,socketTimeout:n,socketAcquisitionWarningTimeout:s,throwOnRequestTimeout:a,httpAgentProvider:async()=>{let T=G("http"),{Agent:C,request:E}=T.default??T;if(W=E,O=C,i instanceof O||typeof i?.destroy==="function")return this.externalAgent=!0,i;return new O({keepAlive:!0,maxSockets:50,...i})},httpsAgent:(()=>{if(c instanceof H.Agent||typeof c?.destroy==="function")return this.externalAgent=!0,c;return new H.Agent({keepAlive:!0,maxSockets:50,...c})})(),logger:u}}}var de=new Uint16Array(1);class M{id=de[0]++;total=0;max=0;session;refs=0;constructor(e){e.unref(),this.session=e}retain(){if(this.session.destroyed)throw Error("@smithy/node-http-handler - cannot acquire reference to destroyed session.");this.refs+=1,this.total+=1,this.max=Math.max(this.refs,this.max),this.session.ref()}free(){if(this.session.destroyed)return;if(this.refs-=1,this.refs===0)this.session.unref();if(this.refs<0)throw Error("@smithy/node-http-handler - ClientHttp2Session refcount at zero, cannot decrement.")}deref(){return this.session}close(){if(!this.session.closed)this.session.close()}destroy(){if(this.refs=0,!this.session.destroyed)this.session.destroy()}useCount(){return this.refs}}class Y{sessions=[];maxConcurrency=0;constructor(e){this.sessions=(e??[]).map((t)=>new M(t))}poll(){let e=!1;for(let t of this.sessions){if(t.deref().destroyed){e=!0;continue}if(!this.maxConcurrency||t.useCount()<this.maxConcurrency)return t}if(e){for(let t of this.sessions)if(t.deref().destroyed)this.remove(t)}}offerLast(e){this.sessions.push(e)}remove(e){let t=this.sessions.indexOf(e);if(t>-1)this.sessions.splice(t,1)}[Symbol.iterator](){return this.sessions[Symbol.iterator]()}setMaxConcurrency(e){this.maxConcurrency=e}destroy(e){this.remove(e),e.destroy()}}class Z{config;connectOptions;connectionPools=new Map;constructor(e){if(this.config=e,this.config.maxConcurrency&&this.config.maxConcurrency<=0)throw RangeError("maxConcurrency must be greater than zero.")}lease(e,t){let o=this.getUrlString(e),n=this.getPool(o);if(!this.config.disableConcurrency&&!t.isEventStream){let u=n.poll();if(u)return u.retain(),u}let s=new M(this.connect(o)),i=s.deref();if(this.config.maxConcurrency)i.settings({maxConcurrentStreams:this.config.maxConcurrency},(u)=>{if(u)throw Error("Fail to set maxConcurrentStreams to "+this.config.maxConcurrency+"when creating new session for "+e.destination.toString())});let c=()=>{this.removeFromPoolAndClose(o,s)},a=()=>{this.removeFromPoolAndCheckedDestroy(o,s)};if(i.on("goaway",c),i.on("error",a),i.on("frameError",a),i.on("close",a),t.requestTimeout)i.setTimeout(t.requestTimeout,a);return n.offerLast(s),s.retain(),s}release(e,t){t.free()}createIsolatedSession(e,t){let o=this.getUrlString(e),n=new M(this.connect(o)),s=n.deref();s.settings({maxConcurrentStreams:1});let i=()=>{n.destroy()};if(s.on("error",i),s.on("frameError",i),s.on("close",i),t.requestTimeout)s.setTimeout(t.requestTimeout,i);return n.retain(),n}destroy(){for(let[e,t]of this.connectionPools){for(let o of[...t])o.destroy();this.connectionPools.delete(e)}}setMaxConcurrentStreams(e){if(e&&e<=0)throw RangeError("maxConcurrentStreams must be greater than zero.");this.config.maxConcurrency=e;for(let t of this.connectionPools.values())t.setMaxConcurrency(e)}setDisableConcurrentStreams(e){this.config.disableConcurrency=e}setNodeHttp2ConnectOptions(e){this.connectOptions=e}debug(){let e={};for(let[t,o]of this.connectionPools){let n=[];for(let s of o)n.push({id:s.id,active:s.useCount(),maxConcurrent:s.max,totalRequests:s.total});e[t]={sessions:n}}return e}removeFromPoolAndClose(e,t){this.connectionPools.get(e)?.remove(t),t.close()}removeFromPoolAndCheckedDestroy(e,t){this.connectionPools.get(e)?.remove(t),t.destroy()}getPool(e){if(!this.connectionPools.has(e)){let t=new Y;if(this.config.maxConcurrency)t.setMaxConcurrency(this.config.maxConcurrency);this.connectionPools.set(e,t)}return this.connectionPools.get(e)}getUrlString(e){return e.destination.toString()}connect(e){return this.connectOptions===void 0?N.connect(e):N.connect(e,this.connectOptions)}}var{constants:z}=N;class q{config;configProvider;metadata={handlerProtocol:"h2"};connectionManager=new Z({});static create(e){if(typeof e?.handle==="function")return e;return new q(e)}constructor(e){this.configProvider=new Promise((t,o)=>{if(typeof e==="function")e().then((n)=>{t(n||{})}).catch(o);else t(e||{})})}destroy(){this.connectionManager.destroy()}async handle(e,{abortSignal:t,requestTimeout:o,isEventStream:n}={}){if(!this.config){this.config=await this.configProvider;let{disableConcurrentStreams:u,maxConcurrentStreams:l,nodeHttp2ConnectOptions:m}=this.config;if(this.connectionManager.setDisableConcurrentStreams(u??!1),l)this.connectionManager.setMaxConcurrentStreams(l);if(m)this.connectionManager.setNodeHttp2ConnectOptions(m)}let{requestTimeout:s,disableConcurrentStreams:i}=this.config,c=i||n,a=o??s;return new Promise((u,l)=>{let m=!1,T=void 0,C=async(r)=>{await T,u(r)},E=async(r)=>{await T,l(r)};if(t?.aborted){m=!0;let r=I(t);E(r);return}let{hostname:k,method:U,port:p,protocol:S,query:R}=e,x="";if(e.username!=null||e.password!=null){let r=e.username??"",f=e.password??"";x=`${r}:${f}@`}let D=`${S}//${x}${k}${p?`:${p}`:""}`,v={destination:new URL(D)},P={requestTimeout:this.config?.sessionTimeout,isEventStream:n},y=c?this.connectionManager.createIsolatedSession(v,P):this.connectionManager.lease(v,P),_=y.deref(),A=(r)=>{if(c)y.destroy();m=!0,E(r)},g=R?K(R):"",b=e.path;if(g)b+=`?${g}`;if(e.fragment)b+=`#${e.fragment}`;let d=_.request({...e.headers,[z.HTTP2_HEADER_PATH]:b,[z.HTTP2_HEADER_METHOD]:U});if(a)d.setTimeout(a,()=>{d.close();let r=Error(`Stream timed out because of no activity for ${a} ms`);r.name="TimeoutError",A(r)});if(t){let r=()=>{d.close();let f=I(t);A(f)};if(typeof t.addEventListener==="function"){let f=t;f.addEventListener("abort",r,{once:!0}),d.once("close",()=>f.removeEventListener("abort",r))}else t.onabort=r}d.on("frameError",(r,f,ee)=>{A(Error(`Frame type id ${r} in stream id ${ee} has failed with code ${f}.`))}),d.on("error",A),d.on("aborted",()=>{A(Error(`HTTP/2 stream is abnormally aborted in mid-communication with result code ${d.rstCode}.`))}),d.on("response",(r)=>{let f=new Q({statusCode:r[":status"]??-1,headers:J(r),body:d});if(m=!0,C({response:f}),c)_.close()}),d.on("close",()=>{if(c)y.destroy();else this.connectionManager.release(v,y);if(!m)A(Error("Unexpected error: http2 request did not get a response"))}),T=X(d,e,a)})}updateHttpClientConfig(e,t){this.config=void 0,this.configProvider=this.configProvider.then((o)=>({...o,[e]:t}))}httpHandlerConfigs(){return this.config??{}}}he.DEFAULT_REQUEST_TIMEOUT=fe;he.NodeHttp2Handler=q;he.NodeHttpHandler=L});
5
5
  export{Vo};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{On,Qt,qo,Ts,oa,sa,Kt,Ir,f,Ac,Fn,ze,Sn,pm,Ro,mf,Zt,cs,No,Tr,Ho,ku}from"./chunk-b93qxjts.js";function dr(e){return Ir(e)&&Kt(e.toOperationNode)}var jr=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 Lt=f({is(e){return e.kind==="ColumnNode"},create(e){return f({kind:"ColumnNode",column:ze.create(e)})}});var Xi=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:Xi.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 Ir(e)&&"expressionType"in e&&dr(e)}function Wr(e){return Ir(e)&&"expression"in e&&Qt(e.alias)&&dr(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 za=f({is(e){return e.kind==="ValueListNode"},create(e){return f({kind:"ValueListNode",values:f(e)})}});function br(e){if(Fn(e))return wt(e);return m(e)}function m(e){if(V(e))return ho(e);return jr.create(e)}function Ae(e){return qo(e)||Ts(e)||oa(e)}function le(e){if(!Ae(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return jr.createImmediate(e)}function wt(e){if(e.some(V))return za.create(e.map((r)=>m(r)));return Te.create(e)}function sr(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),jr.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])=>!On(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(jr.createImmediate(1),Ro.create("="),jr.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 No.create(n);return n}function Ot(e){return e==="is"||e==="is not"}function kr(e){return oa(e)||Ts(e)}function $e(e){if(Qt(e)&&pm.includes(e))return Ro.create(e);if(dr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function Sr(e){return dr(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)=>de.cloneWithOrderByItems(e,r),cloneWithoutOrderBy:(e)=>de.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 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),Ho.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 de=f({is(e){return Gt.is(e)||Tr.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:Er.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 Gt=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)=>de.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)=>de.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,sr(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 df{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return Ze(this.#e)}}function Be(e){return Ir(e)&&dr(e)&&Qt(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 rr(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 cs("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 Rr(t,r)}function xt(e){if(V(e))return ho(e);if(Be(e))return e.toOperationNode();let[r,t]=e.split(" ");if(t)return cs("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Rr(Mo(r),t);return Mo(e)}function Rr(e,r){if(typeof r==="string"){if(!rr(r))throw Error(`Invalid order by direction: ${r}`);return T.create(e,Zt.createWithSql(r))}if(Ce(r))return cs("`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:de.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:Xi.create()})},createSelectAllFromTable(e){return f({kind:"SelectionNode",selection:te.createSelectAll(e)})}});class pf{#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(zt(this.#e),ze.create(this.#r))}}function Br(e){return Ir(e)&&dr(e)&&Qt(e.table)&&Qt(e.alias)}function A(e){if(Fn(e))return e.map((r)=>Y(r));else return[Y(e)]}function Y(e){if(Qt(e))return tr(e);else if(Br(e))return e.toOperationNode();else return Fe(e)}function tr(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(Dr);return l.create(zt(t),ze.create(o))}else return zt(e)}function zt(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(Fn(e))return e.map((r)=>Fr(r));else return[Fr(e)]}function Fr(e){if(Qt(e))return se.create(Pr(e));else if(Be(e))return se.create(e.toOperationNode());else return se.create(Fe(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(Qt(e))return se.createSelectAllFromTable(zt(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 ve(e){let r=Kt(e)?e(q()):e,t=Fn(r)?r:f([r]);return gt(t)}function gt(e){let r=Wt(e);return[f([...r.keys()].map(Lt.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(On(pe)){u--;continue}let Ie=e[Ee];if(On(Ie)||V(Ie))n=!0;o[pe]=Ie}if(u<r.size||n){let Ee=Vr.create();return za.create(o.map((pe)=>On(pe)?Ee:m(pe)))}return Te.create(o)}var or=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[or.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])=>or.create(Lt.create(t),m(o)))}var zr=f({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return f({kind:"OnDuplicateKeyNode",updates:e})}});class ir{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=Lt.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(Lt.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,sr(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 Jr({...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 Jr{#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,sr(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 Qr=f({is(e){return e.kind==="TopNode"},create(e,r){return f({kind:"TopNode",expression:e,modifiers:r})}});function B(e,r){if(!qo(e)&&!sa(e))throw Error(`Invalid top expression: ${e}`);if(!On(r)&&!St(r))throw Error(`Invalid top modifiers: ${r}`);return Qr.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]=ve(e);return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{columns:r,values:t})})}columns(e){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{columns:f(e.map(Lt.create))})})}expression(e){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{values:ho(e)})})}defaultValues(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new d({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orIgnore(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orAbort(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("abort")})})}orFail(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("fail")})})}orReplace(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("replace")})})}orRollback(){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{orAction:Z.create("rollback")})})}top(e,r){return new d({...this.#e,queryNode:de.cloneWithTop(this.#e.queryNode,B(e,r))})}onConflict(e){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{onConflict:e(new P({onConflictNode:x.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new d({...this.#e,queryNode:Tr.cloneWith(this.#e.queryNode,{onDuplicateKey:zr.create(we(e))})})}returning(e){return new d({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(){return new d({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new d({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new d({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new d({...this.#e,queryNode:de.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 ir(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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}class nr{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 Pe{#e;constructor(e){this.#e=f(e)}where(...e){return new c({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new c({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new c({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new c({...this.#e,queryNode:de.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}returning(e){return new c({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new c({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new c({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new c({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new c({...this.#e,queryNode:de.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new c({...this.#e,queryNode:_.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new c({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new c({...this.#e,queryNode:de.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:de.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 nr(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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}c=Pe;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:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new h({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new h({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new h({...this.#e,queryNode:de.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new h({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new h({...this.#e,queryNode:de.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:de.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new h({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new h({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new h({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new h({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new h({...this.#e,queryNode:de.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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}h=ue;var ur=f({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,r){return f({kind:"CommonTableExpressionNameNode",table:g.create(e),columns:r?f(r.map(Lt.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 mr(e,r){let t=r(_r()).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 ur.create(t,o)}else return ur.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 Cu(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=Cu(8);return this.#e}}function i(e){return e}class mc{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 mc{#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&&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 is{#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 Ho.create(oe([Hr.create(!e.isMatched,e.bySource),...r&&r.length>0?[r.length===3&&t?N(r[0],r[1],r[2]):sr(r)]:[]],"and",!1))}function ce(e){if(Qt(e))return Zt.create([e],[]);if(dr(e))return e.toOperationNode();return e}class ja{#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 Iu(e){let r=new ja,t=new ja;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 hc{#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)cs("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 Iu(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 hc{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 pr{numChangedRows;constructor(e){this.numChangedRows=e}}class J{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new J({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new J({...this.#e,queryNode:de.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:de.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new J({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new J({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new J({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=f(e)}modifyEnd(e){return new b({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new b({...this.#e,queryNode:de.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 lr({...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:de.cloneWithReturning(this.#e.queryNode,p(e))})}returningAll(e){return new b({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,p(e))})}outputAll(e){return new b({...this.#e,queryNode:de.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?lr: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 pr(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 lr{#e;constructor(e){this.#e=f(e)}thenDelete(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce(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,ce("do nothing"))})}thenInsertValues(e){let[r,t]=ve(e);return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce(Tr.cloneWith(Tr.createWithoutInto(),{columns:r,values:t})))})}}class Is{#e;constructor(e){this.#e=f(e)}selectFrom(e){return We({queryId:Ye(),executor:this.#e.executor,queryNode:Gt.createFrom(A(e),this.#e.withNode)})}selectNoFrom(e){return We({queryId:Ye(),executor:this.#e.executor,queryNode:Gt.cloneWithSelections(Gt.create(this.#e.withNode),p(e))})}insertInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:Tr.create(zt(e),this.#e.withNode)})}replaceInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:Tr.create(zt(e),this.#e.withNode,!0)})}deleteFrom(e){return new Pe({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(tr(e),this.#e.withNode)})}with(e,r){let t=mr(e,r);return new Is({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t)})}withRecursive(e,r){let t=mr(e,r);return new Is({...this.#e,withNode:this.#e.withNode?ge.cloneWithExpression(this.#e.withNode,t):ge.create(t,{recursive:!0})})}withPlugin(e){return new Is({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new Is({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new Is({...this.#e,executor:this.#e.executor.withPluginAtFront(new is(e))})}}function _r(){return new Is({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 Bt(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 Bt(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(!Fn(r))r=[r];return r.map((o)=>ku.create(e,ho(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,sr(e)))}and(...e){return new Ue(W.create(this.#e,sr(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(),dr(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,sr(e)))}$castTo(){return new Ve(this.#e)}toOperationNode(){return No.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,sr(e)))}$castTo(){return new Ue(this.#e)}toOperationNode(){return No.create(this.#e)}}var ot=f({is(e){return e.kind==="FetchNode"},create(e,r){return{kind:"FetchNode",rowCount:jr.create(e),modifier:r}}});function it(e,r){if(!qo(e)&&!sa(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:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new s({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}having(...e){return new s({...this.#e,queryNode:Gt.cloneWithHaving(this.#e.queryNode,sr(e))})}havingRef(e,r,t){return new s({...this.#e,queryNode:Gt.cloneWithHaving(this.#e.queryNode,N(e,r,t))})}select(e){return new s({...this.#e,queryNode:Gt.cloneWithSelections(this.#e.queryNode,p(e))})}distinctOn(e){return new s({...this.#e,queryNode:Gt.cloneWithDistinctOn(this.#e.queryNode,z(e))})}modifyFront(e){return new s({...this.#e,queryNode:Gt.cloneWithFrontModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:Gt.cloneWithFrontModifier(this.#e.queryNode,D.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForUpdate",e?Ac(e).map(zt):void 0))})}forShare(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForShare",e?Ac(e).map(zt):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForKeyShare",e?Ac(e).map(zt):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForNoKeyUpdate",e?Ac(e).map(zt):void 0))})}skipLocked(){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:Gt.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new s({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new s({...this.#e,queryNode:Gt.cloneWithGroupByItems(this.#e.queryNode,tt(e))})}limit(e){return new s({...this.#e,queryNode:Gt.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}offset(e){return new s({...this.#e,queryNode:Gt.cloneWithOffset(this.#e.queryNode,et.create(m(e)))})}fetch(e,r="only"){return new s({...this.#e,queryNode:Gt.cloneWithFetch(this.#e.queryNode,it(e,r))})}top(e,r){return new s({...this.#e,queryNode:de.cloneWithTop(this.#e.queryNode,B(e,r))})}union(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!0))})}as(e){return new nt(this,e)}clearSelect(){return new s({...this.#e,queryNode:Gt.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:Gt.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:Gt.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:de.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:Gt.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:de.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:de.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(e))})}clearOrderBy(){return new S({...this.#e,aggregateFunctionNode:de.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,sr(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 Tu(){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",[Qt(t)?zt(t):t.toOperationNode()])})},toJson(t){return new a(yr.create("to_json",[Qt(t)?zt(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(Ro.create(e),w(r))}var ko=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),Ho.cloneWithResult(e.when[e.when.length-1],r)]):void 0})},cloneWith(e,r){return f({...e,...r})}});class gc{#e;constructor(e){this.#e=f(e)}when(...e){return new wr({...this.#e,node:ko.cloneWithWhen(this.#e.node,Ho.create(sr(e)))})}}class wr{#e;constructor(e){this.#e=f(e)}then(e){return new mt({...this.#e,node:ko.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:ko.cloneWithWhen(this.#e.node,Ho.create(sr(e)))})}else(e){return new dt({...this.#e,node:ko.cloneWith(this.#e.node,{else:Ae(e)?le(e):m(e)})})}end(){return new a(ko.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(ko.cloneWith(this.#e.node,{isStatement:!0}))}}class dt{#e;constructor(e){this.#e=f(e)}end(){return new a(ko.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(ko.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 Ft=/^#-\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"&&!Ft.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,jr.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(),dr(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 vt=["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"],Pt=[/^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(vt.includes(e))return!0;if(Pt.some((r)=>r.test(e)))return!0;return!1}function ls(e){if(dr(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:Gt.createFrom(A(n))})},case(n){return new gc({node:ko.create(On(n)?void 0:w(n))})},ref(n,u){if(On(u))return new a(Mo(n));return new Se(lt(n,u))},jsonPath(){return new Se(H.create())},table(n){return new a(zt(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),Ro.create("between"),W.create(m(u),m(re))))},betweenSymmetric(n,u,re){return new a(I.create(w(n),Ro.create("between symmetric"),W.create(m(u),m(re))))},and(n){if(Fn(n))return new a(oe(n,"and"));return new a(_e(n,"and"))},or(n){if(Fn(n))return new a(oe(n,"or"));return new a(_e(n,"or"))},parens(...n){let u=sr(n);if(No.is(u))return new a(u);else return new a(No.create(u))},cast(n,u){return new a(pt.create(w(n),ls(u)))},withSchema(n){return Me(e.withPluginAtFront(new is(n)))}});return o.fn=Tu(),o.eb=o,o}function q(e){return Me()}function ho(e){if(dr(e))return e.toOperationNode();else if(Kt(e))return e(q()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function Fe(e){if(dr(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(Qt(e))return Mo(e);return e.toOperationNode()}function z(e){if(Fn(e))return e.map((r)=>w(r));else return[w(e)]}function w(e){if(V(e))return ho(e);return Ze(e)}function lt(e,r){let t=Mo(e);if(mf(r))return fe.create(t,Qe.create(Ro.create(r)));let o=r.slice(0,-1);if(mf(o))return fe.create(t,H.create(Ro.create(o)));throw Error(`Invalid JSON operator: ${r}`)}function Mo(e){if(!e.includes("."))return te.create(Lt.create(e));let t=e.split(".").map(gr);if(t.length===3)return Mt(t);if(t.length===2)return Vt(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(Mo(t),ze.create(o))}else return Mo(e)}function ff(e){return Lt.create(e)}function el(e){if(e.includes(" ")){let[t,o]=e.split(" ").map(gr);if(!rr(o))throw Error(`invalid order direction "${o}" next to "${t}"`);return E([t,o])[0]}else return ff(e)}function Mt(e){let[r,t,o]=e;return te.create(Lt.create(o),g.createWithSchema(r,t))}function Vt(e){let[r,t]=e;return te.create(Lt.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(),dr(this.#r)?this.#r.toOperationNode():ze.create(this.#r))}}var De=Object.assign((e,...r)=>Q({queryId:Ye(),rawNode:Zt.create(e,r?.map(yt)??[])}),{ref(e){return Q({queryId:Ye(),rawNode:Zt.createWithChild(Mo(e))})},val(e){return Q({queryId:Ye(),rawNode:Zt.createWithChild(m(e))})},value(e){return this.val(e)},table(e){return Q({queryId:Ye(),rawNode:Zt.createWithChild(zt(e))})},id(...e){let r=Array(e.length+1).fill(".");return r[0]="",r[r.length-1]="",Q({queryId:Ye(),rawNode:Zt.create(r,e.map(ze.create))})},lit(e){return Q({queryId:Ye(),rawNode:Zt.createWithChild(jr.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return Q({queryId:Ye(),rawNode:Zt.createWithSql(e)})},join(e,r=De`, `){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:Zt.createWithChildren(t)})}});function yt(e){if(dr(e))return e.toOperationNode();return m(e)}var fr=f({raw(e,r=[]){return f({sql:e,query:Zt.createWithSql(e),parameters:f(r),queryId:Ye()})}});
3
- export{dr,Lt,Xi,df,Mo,ff,el,za,jr,sr,de,Gt,Cu,Ye,mc,is,ja,Iu,hc,Is,Tu,ko,gc,ls,ho,pf,zt,De,fr};
2
+ import{On,Qt,qo,ks,ai,li,Kt,Mr,p,vc,Fn,je,Sn,ym,Po,yf,Bt,us,No,kr,Ho,Du}from"./chunk-0yv0nnmh.js";function dr(e){return Mr(e)&&Kt(e.toOperationNode)}var qr=p({is(e){return e.kind==="ValueNode"},create(e){return p({kind:"ValueNode",value:e})},createImmediate(e){return p({kind:"ValueNode",value:e,immediate:!0})}});var l=p({is(e){return e.kind==="AliasNode"},create(e,r){return p({kind:"AliasNode",node:e,alias:r})}});var Zt=p({is(e){return e.kind==="ColumnNode"},create(e){return p({kind:"ColumnNode",column:je.create(e)})}});var rl=p({is(e){return e.kind==="SelectAllNode"},create(){return p({kind:"SelectAllNode"})}});var te=p({is(e){return e.kind==="ReferenceNode"},create(e,r){return p({kind:"ReferenceNode",table:r,column:e})},createSelectAll(e){return p({kind:"ReferenceNode",table:e,column:rl.create()})}});var g=p({is(e){return e.kind==="TableNode"},create(e){return p({kind:"TableNode",table:Sn.create(e)})},createWithSchema(e,r){return p({kind:"TableNode",table:Sn.createWithSchema(e,r)})}});function Re(e){return Mr(e)&&"expressionType"in e&&dr(e)}function Wr(e){return Mr(e)&&"expression"in e&&Qt(e.alias)&&dr(e)}var D=p({is(e){return e.kind==="SelectModifierNode"},create(e,r){return p({kind:"SelectModifierNode",modifier:e,of:r})},createWithExpression(e){return p({kind:"SelectModifierNode",rawModifier:e})}});var W=p({is(e){return e.kind==="AndNode"},create(e,r){return p({kind:"AndNode",left:e,right:r})}});var C=p({is(e){return e.kind==="OrNode"},create(e,r){return p({kind:"OrNode",left:e,right:r})}});var Te=p({is(e){return e.kind==="OnNode"},create(e){return p({kind:"OnNode",on:e})},cloneWithOperation(e,r,t){return p({...e,on:r==="And"?W.create(e.on,t):C.create(e.on,t)})}});var R=p({is(e){return e.kind==="JoinNode"},create(e,r){return p({kind:"JoinNode",joinType:e,table:r,on:void 0})},createWithOn(e,r,t){return p({kind:"JoinNode",joinType:e,table:r,on:Te.create(t)})},cloneWithOn(e,r){return p({...e,on:e.on?Te.cloneWithOperation(e.on,"And",r):Te.create(r)})}});var I=p({is(e){return e.kind==="BinaryOperationNode"},create(e,r,t){return p({kind:"BinaryOperationNode",leftOperand:e,operator:r,rightOperand:t})}});var Ae=p({is(e){return e.kind==="PrimitiveValueListNode"},create(e){return p({kind:"PrimitiveValueListNode",values:p([...e])})}});var $i=p({is(e){return e.kind==="ValueListNode"},create(e){return p({kind:"ValueListNode",values:p(e)})}});function br(e){if(Fn(e))return wt(e);return m(e)}function m(e){if(V(e))return ho(e);return qr.create(e)}function qe(e){return qo(e)||ks(e)||ai(e)}function le(e){if(!qe(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return qr.createImmediate(e)}function wt(e){if(e.some(V))return $i.create(e.map((r)=>m(r)));return Ae.create(e)}function sr(e){if(e.length===3)return Le(e[0],e[1],e[2]);else if(e.length===1)return m(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Le(e,r,t){if(Ot(r)&&Er(t))return I.create(w(e),Ie(r),qr.createImmediate(t));return I.create(w(e),Ie(r),br(t))}function N(e,r,t){return I.create(w(e),Ie(r),w(t))}function $e(e,r){return oe(Object.entries(e).filter(([,t])=>!On(t)).map(([t,o])=>Le(t,Er(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(qr.createImmediate(1),Po.create("="),qr.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 No.create(n);return n}function Ot(e){return e==="is"||e==="is not"}function Er(e){return ai(e)||ks(e)}function Ie(e){if(Qt(e)&&ym.includes(e))return Po.create(e);if(dr(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function Sr(e){return dr(e)?e.toOperationNode():e}var U=p({is(e){return e.kind==="OrderByNode"},create(e){return p({kind:"OrderByNode",items:p([...e])})},cloneWithItems(e,r){return p({...e,items:p([...e.items,...r])})}});var _e=p({is(e){return e.kind==="PartitionByNode"},create(e){return p({kind:"PartitionByNode",items:p(e)})},cloneWithItems(e,r){return p({...e,items:p([...e.items,...r])})}});var Ne=p({is(e){return e.kind==="OverNode"},create(){return p({kind:"OverNode"})},cloneWithOrderByItems(e,r){return p({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithPartitionByItems(e,r){return p({...e,partitionBy:e.partitionBy?_e.cloneWithItems(e.partitionBy,r):_e.create(r)})}});var X=p({is(e){return e.kind==="FromNode"},create(e){return p({kind:"FromNode",froms:p(e)})},cloneWithFroms(e,r){return p({...e,froms:p([...e.froms,...r])})}});var Ge=p({is(e){return e.kind==="GroupByNode"},create(e){return p({kind:"GroupByNode",items:p(e)})},cloneWithItems(e,r){return p({...e,items:p([...e.items,...r])})}});var Ke=p({is(e){return e.kind==="HavingNode"},create(e){return p({kind:"HavingNode",having:e})},cloneWithOperation(e,r,t){return p({...e,having:r==="And"?W.create(e.having,t):C.create(e.having,t)})}});var Be=p({is(e){return e.kind==="ListNode"},create(e){return p({kind:"ListNode",items:p(e)})}});var F=p({is(e){return e.kind==="UpdateQueryNode"},create(e,r){return p({kind:"UpdateQueryNode",table:e.length===1?e[0]:Be.create(e),...r&&{with:r}})},createWithoutTable(){return p({kind:"UpdateQueryNode"})},cloneWithFromItems(e,r){return p({...e,from:e.from?X.cloneWithFroms(e.from,r):X.create(r)})},cloneWithUpdates(e,r){return p({...e,updates:e.updates?p([...e.updates,...r]):r})},cloneWithLimit(e,r){return p({...e,limit:r})}});var ye=p({is(e){return e.kind==="UsingNode"},create(e){return p({kind:"UsingNode",tables:p(e)})},cloneWithTables(e,r){return p({...e,tables:p([...e.tables,...r])})}});var _=p({is(e){return e.kind==="DeleteQueryNode"},create(e,r){return p({kind:"DeleteQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithOrderByItems:(e,r)=>de.cloneWithOrderByItems(e,r),cloneWithoutOrderBy:(e)=>de.cloneWithoutOrderBy(e),cloneWithLimit(e,r){return p({...e,limit:r})},cloneWithoutLimit(e){return p({...e,limit:void 0})},cloneWithUsing(e,r){return p({...e,using:e.using!==void 0?ye.cloneWithTables(e.using,r):ye.create(r)})}});var O=p({is(e){return e.kind==="WhereNode"},create(e){return p({kind:"WhereNode",where:e})},cloneWithOperation(e,r,t){return p({...e,where:r==="And"?W.create(e.where,t):C.create(e.where,t)})}});var He=p({is(e){return e.kind==="ReturningNode"},create(e){return p({kind:"ReturningNode",selections:p(e)})},cloneWithSelections(e,r){return p({...e,selections:e.selections?p([...e.selections,...r]):p(r)})}});var Cr=p({is(e){return e.kind==="ExplainNode"},create(e,r){return p({kind:"ExplainNode",format:e,options:r})}});var k=p({is(e){return e.kind==="MergeQueryNode"},create(e,r){return p({kind:"MergeQueryNode",into:e,...r&&{with:r}})},cloneWithUsing(e,r){return p({...e,using:r})},cloneWithWhen(e,r){return p({...e,whens:e.whens?p([...e.whens,r]):p([r])})},cloneWithThen(e,r){return p({...e,whens:e.whens?p([...e.whens.slice(0,-1),Ho.cloneWithResult(e.whens[e.whens.length-1],r)]):void 0})}});var Xe=p({is(e){return e.kind==="OutputNode"},create(e){return p({kind:"OutputNode",selections:p(e)})},cloneWithSelections(e,r){return p({...e,selections:e.selections?p([...e.selections,...r]):p(r)})}});var de=p({is(e){return Gt.is(e)||kr.is(e)||F.is(e)||_.is(e)||k.is(e)},cloneWithEndModifier(e,r){return p({...e,endModifiers:e.endModifiers?p([...e.endModifiers,r]):p([r])})},cloneWithWhere(e,r){return p({...e,where:e.where?O.cloneWithOperation(e.where,"And",r):O.create(r)})},cloneWithJoin(e,r){return p({...e,joins:e.joins?p([...e.joins,r]):p([r])})},cloneWithReturning(e,r){return p({...e,returning:e.returning?He.cloneWithSelections(e.returning,r):He.create(r)})},cloneWithoutReturning(e){return p({...e,returning:void 0})},cloneWithoutWhere(e){return p({...e,where:void 0})},cloneWithExplain(e,r,t){return p({...e,explain:Cr.create(r,t?.toOperationNode())})},cloneWithTop(e,r){return p({...e,top:r})},cloneWithOutput(e,r){return p({...e,output:e.output?Xe.cloneWithSelections(e.output,r):Xe.create(r)})},cloneWithOrderByItems(e,r){return p({...e,orderBy:e.orderBy?U.cloneWithItems(e.orderBy,r):U.create(r)})},cloneWithoutOrderBy(e){return p({...e,orderBy:void 0})}});var Gt=p({is(e){return e.kind==="SelectQueryNode"},create(e){return p({kind:"SelectQueryNode",...e&&{with:e}})},createFrom(e,r){return p({kind:"SelectQueryNode",from:X.create(e),...r&&{with:r}})},cloneWithSelections(e,r){return p({...e,selections:e.selections?p([...e.selections,...r]):p(r)})},cloneWithDistinctOn(e,r){return p({...e,distinctOn:e.distinctOn?p([...e.distinctOn,...r]):p(r)})},cloneWithFrontModifier(e,r){return p({...e,frontModifiers:e.frontModifiers?p([...e.frontModifiers,r]):p([r])})},cloneWithOrderByItems:(e,r)=>de.cloneWithOrderByItems(e,r),cloneWithGroupByItems(e,r){return p({...e,groupBy:e.groupBy?Ge.cloneWithItems(e.groupBy,r):Ge.create(r)})},cloneWithLimit(e,r){return p({...e,limit:r})},cloneWithOffset(e,r){return p({...e,offset:r})},cloneWithFetch(e,r){return p({...e,fetch:r})},cloneWithHaving(e,r){return p({...e,having:e.having?Ke.cloneWithOperation(e.having,"And",r):Ke.create(r)})},cloneWithSetOperations(e,r){return p({...e,setOperations:e.setOperations?p([...e.setOperations,...r]):p([...r])})},cloneWithoutSelections(e){return p({...e,selections:[]})},cloneWithoutLimit(e){return p({...e,limit:void 0})},cloneWithoutOffset(e){return p({...e,offset:void 0})},cloneWithoutOrderBy:(e)=>de.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return p({...e,groupBy:void 0})}});class ie{#e;constructor(e){this.#e=p(e)}on(...e){return new ie({...this.#e,joinNode:R.cloneWithOn(this.#e.joinNode,sr(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 gf{#e;get dynamicReference(){return this.#e}get refType(){return}constructor(e){this.#e=e}toOperationNode(){return Ze(this.#e)}}function De(e){return Mr(e)&&dr(e)&&Qt(e.dynamicReference)}var T=p({is(e){return e.kind==="OrderByItemNode"},create(e,r){return p({kind:"OrderByItemNode",orderBy:e,direction:r})},cloneWith(e,r){return p({...e,...r})}});var Rr=p({is(e){return e.kind==="CollateNode"},create(e){return p({kind:"CollateNode",collation:je.create(e)})}});class j{#e;constructor(e){this.#e=p(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 rr(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 us("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 ho(e);if(De(e))return e.toOperationNode();let[r,t]=e.split(" ");if(t)return us("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Tr(ko(r),t);return ko(e)}function Tr(e,r){if(typeof r==="string"){if(!rr(r))throw Error(`Invalid order by direction: ${r}`);return T.create(e,Bt.createWithSql(r))}if(Re(r))return us("`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=p({is(e){return e.kind==="PartitionByItemNode"},create(e){return p({kind:"PartitionByItemNode",partitionBy:e})}});function Lr(e){return z(e).map(Ar.create)}class ne{#e;constructor(e){this.#e=p(e)}orderBy(...e){return new ne({overNode:Ne.cloneWithOrderByItems(this.#e.overNode,E(e))})}clearOrderBy(){return new ne({overNode:de.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new ne({overNode:Ne.cloneWithPartitionByItems(this.#e.overNode,Lr(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}}var se=p({is(e){return e.kind==="SelectionNode"},create(e){return p({kind:"SelectionNode",selection:e})},createSelectAll(){return p({kind:"SelectionNode",selection:rl.create()})},createSelectAllFromTable(e){return p({kind:"SelectionNode",selection:te.createSelectAll(e)})}});class _f{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Br(this.#e,e)}}class Br{#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(zt(this.#e),je.create(this.#r))}}function Dr(e){return Mr(e)&&dr(e)&&Qt(e.table)&&Qt(e.alias)}function A(e){if(Fn(e))return e.map((r)=>Y(r));else return[Y(e)]}function Y(e){if(Qt(e))return tr(e);else if(Dr(e))return e.toOperationNode();else return Fe(e)}function tr(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(Fr);return l.create(zt(t),je.create(o))}else return zt(e)}function zt(e){if(e.includes(".")){let[t,o]=e.split(".").map(Fr);return g.createWithSchema(t,o)}else return g.create(e)}function Fr(e){return e.trim()}function f(e){if(Kt(e))return f(e(q()));else if(Fn(e))return e.map((r)=>vr(r));else return[vr(e)]}function vr(e){if(Qt(e))return se.create(Vr(e));else if(De(e))return se.create(e.toOperationNode());else return se.create(Fe(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(Qt(e))return se.createSelectAllFromTable(zt(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}var Ur=p({is(e){return e.kind==="ValuesNode"},create(e){return p({kind:"ValuesNode",values:p(e)})}});var zr=p({is(e){return e.kind==="DefaultInsertValueNode"},create(){return p({kind:"DefaultInsertValueNode"})}});function ve(e){let r=Kt(e)?e(q()):e,t=Fn(r)?r:p([r]);return gt(t)}function gt(e){let r=Wt(e);return[p([...r.keys()].map(Zt.create)),Ur.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 Ce of t){let pe=r.get(Ce);if(On(pe)){u--;continue}let Qe=e[Ce];if(On(Qe)||V(Qe))n=!0;o[pe]=Qe}if(u<r.size||n){let Ce=zr.create();return $i.create(o.map((pe)=>On(pe)?Ce:m(pe)))}return Ae.create(o)}var or=p({is(e){return e.kind==="ColumnUpdateNode"},create(e,r){return p({kind:"ColumnUpdateNode",column:e,value:r})}});function Jr(...e){if(e.length===2)return[or.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])=>or.create(Zt.create(t),m(o)))}var Qr=p({is(e){return e.kind==="OnDuplicateKeyNode"},create(e){return p({kind:"OnDuplicateKeyNode",updates:e})}});class ir{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=p({is(e){return e.kind==="OnConflictNode"},create(){return p({kind:"OnConflictNode"})},cloneWith(e,r){return p({...e,...r})},cloneWithIndexWhere(e,r){return p({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"And",r):O.create(r)})},cloneWithIndexOrWhere(e,r){return p({...e,indexWhere:e.indexWhere?O.cloneWithOperation(e.indexWhere,"Or",r):O.create(r)})},cloneWithUpdateWhere(e,r){return p({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"And",r):O.create(r)})},cloneWithUpdateOrWhere(e,r){return p({...e,updateWhere:e.updateWhere?O.cloneWithOperation(e.updateWhere,"Or",r):O.create(r)})},cloneWithoutIndexWhere(e){return p({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return p({...e,updateWhere:void 0})}});class P{#e;constructor(e){this.#e=p(e)}column(e){let r=Zt.create(e);return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?p([...this.#e.onConflictNode.columns,r]):p([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?p([...this.#e.onConflictNode.columns,...r]):p(r)})})}constraint(e){return new P({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{constraint:je.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,sr(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 Ir({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new xe({...this.#e,onConflictNode:x.cloneWith(this.#e.onConflictNode,{updates:we(e)})})}$call(e){return e(this)}}class Ir{#e;constructor(e){this.#e=p(e)}toOperationNode(){return this.#e.onConflictNode}}class xe{#e;constructor(e){this.#e=p(e)}where(...e){return new xe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,sr(e))})}whereRef(e,r,t){return new xe({...this.#e,onConflictNode:x.cloneWithUpdateWhere(this.#e.onConflictNode,N(e,r,t))})}clearWhere(){return new xe({...this.#e,onConflictNode:x.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}}var $r=p({is(e){return e.kind==="TopNode"},create(e,r){return p({kind:"TopNode",expression:e,modifiers:r})}});function B(e,r){if(!qo(e)&&!li(e))throw Error(`Invalid top expression: ${e}`);if(!On(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=p({is(e){return e.kind==="OrActionNode"},create(e){return p({kind:"OrActionNode",action:e})}});class d{#e;constructor(e){this.#e=p(e)}values(e){let[r,t]=ve(e);return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{columns:r,values:t})})}columns(e){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{columns:p(e.map(Zt.create))})})}expression(e){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{values:ho(e)})})}defaultValues(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new d({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orIgnore(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("ignore")})})}orAbort(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("abort")})})}orFail(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("fail")})})}orReplace(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("replace")})})}orRollback(){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{orAction:Z.create("rollback")})})}top(e,r){return new d({...this.#e,queryNode:de.cloneWithTop(this.#e.queryNode,B(e,r))})}onConflict(e){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{onConflict:e(new P({onConflictNode:x.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new d({...this.#e,queryNode:kr.cloneWith(this.#e.queryNode,{onDuplicateKey:Qr.create(we(e))})})}returning(e){return new d({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,f(e))})}returningAll(){return new d({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y())})}output(e){return new d({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,f(e))})}outputAll(e){return new d({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new d({...this.#e,queryNode:de.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 ir(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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}class nr{numDeletedRows;constructor(e){this.numDeletedRows=e}}var ae=p({is(e){return e.kind==="LimitNode"},create(e){return p({kind:"LimitNode",limit:e})}});var c;class Pe{#e;constructor(e){this.#e=p(e)}where(...e){return new c({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new c({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new c({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new c({...this.#e,queryNode:de.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}returning(e){return new c({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,f(e))})}returningAll(e){return new c({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new c({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,f(e))})}outputAll(e){return new c({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}clearReturning(){return new c({...this.#e,queryNode:de.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new c({...this.#e,queryNode:_.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new c({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new c({...this.#e,queryNode:de.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:de.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 nr(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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}c=Pe;class ar{numUpdatedRows;numChangedRows;constructor(e,r){this.numUpdatedRows=e,this.numChangedRows=r}}var h;class ue{#e;constructor(e){this.#e=p(e)}where(...e){return new h({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new h({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}clearWhere(){return new h({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}top(e,r){return new h({...this.#e,queryNode:de.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new h({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new h({...this.#e,queryNode:de.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,Jr(...e))})}returning(e){return new h({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,f(e))})}returningAll(e){return new h({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new h({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,f(e))})}outputAll(e){return new h({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}modifyEnd(e){return new h({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new h({...this.#e,queryNode:de.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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}h=ue;var ur=p({is(e){return e.kind==="CommonTableExpressionNameNode"},create(e,r){return p({kind:"CommonTableExpressionNameNode",table:g.create(e),columns:r?p(r.map(Zt.create)):void 0})}});var me=p({is(e){return e.kind==="CommonTableExpressionNode"},create(e,r){return p({kind:"CommonTableExpressionNode",name:e,expression:r})},cloneWith(e,r){return p({...e,...r})}});class ge{#e;constructor(e){this.#e=p(e)}materialized(){return new ge({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new ge({...this.#e,node:me.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}}function mr(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 ge({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 ur.create(t,o)}else return ur.create(e)}var We=p({is(e){return e.kind==="WithNode"},create(e,r){return p({kind:"WithNode",expressions:p([e]),...r})},cloneWithExpression(e,r){return p({...e,expressions:p([...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 ku(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=ku(8);return this.#e}}function i(e){return e}class _c{nodeStack=[];#e=p({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(),p(t)}transformNodeImpl(e,r){return this.#e[e.kind](e,r)}transformNodeList(e,r){if(!e)return e;return p(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:p([...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=p({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 _c{#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:je.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&&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(Be.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 ls{#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=p({is(e){return e.kind==="MatchedNode"},create(e,r=!1){return p({kind:"MatchedNode",not:e,bySource:r})}});function hr(e,r,t){return Ho.create(oe([Hr.create(!e.isMatched,e.bySource),...r&&r.length>0?[r.length===3&&t?N(r[0],r[1],r[2]):sr(r)]:[]],"and",!1))}function ce(e){if(Qt(e))return Bt.create([e],[]);if(dr(e))return e.toOperationNode();return e}class Gi{#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 Ru(e){let r=new Gi,t=new Gi;return e.provideConnection(async(o)=>(r.resolve(o),await t.promise)).catch((o)=>r.reject(o)),p({connection:await r.promise,release:t.resolve})}var Tt=p([]);class yc{#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)us("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 Ru(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 yc{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=p(e)}modifyEnd(e){return new J({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new J({...this.#e,queryNode:de.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:de.cloneWithReturning(this.#e.queryNode,f(e))})}returningAll(e){return new J({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new J({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,f(e))})}outputAll(e){return new J({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,y(e))})}}class b{#e;constructor(e){this.#e=p(e)}modifyEnd(e){return new b({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,r){return new b({...this.#e,queryNode:de.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 lr({...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:de.cloneWithReturning(this.#e.queryNode,f(e))})}returningAll(e){return new b({...this.#e,queryNode:de.cloneWithReturning(this.#e.queryNode,y(e))})}output(e){return new b({...this.#e,queryNode:de.cloneWithOutput(this.#e.queryNode,f(e))})}outputAll(e){return new b({...this.#e,queryNode:de.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?lr: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 lr{#e;constructor(e){this.#e=p(e)}thenDelete(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce("delete"))})}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce("do nothing"))})}thenUpdate(e){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce(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=p(e)}thenDoNothing(){return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce("do nothing"))})}thenInsertValues(e){let[r,t]=ve(e);return new b({...this.#e,queryNode:k.cloneWithThen(this.#e.queryNode,ce(kr.cloneWith(kr.createWithoutInto(),{columns:r,values:t})))})}}class Ms{#e;constructor(e){this.#e=p(e)}selectFrom(e){return be({queryId:Ye(),executor:this.#e.executor,queryNode:Gt.createFrom(A(e),this.#e.withNode)})}selectNoFrom(e){return be({queryId:Ye(),executor:this.#e.executor,queryNode:Gt.cloneWithSelections(Gt.create(this.#e.withNode),f(e))})}insertInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:kr.create(zt(e),this.#e.withNode)})}replaceInto(e){return new d({queryId:Ye(),executor:this.#e.executor,queryNode:kr.create(zt(e),this.#e.withNode,!0)})}deleteFrom(e){return new Pe({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(tr(e),this.#e.withNode)})}with(e,r){let t=mr(e,r);return new Ms({...this.#e,withNode:this.#e.withNode?We.cloneWithExpression(this.#e.withNode,t):We.create(t)})}withRecursive(e,r){let t=mr(e,r);return new Ms({...this.#e,withNode:this.#e.withNode?We.cloneWithExpression(this.#e.withNode,t):We.create(t,{recursive:!0})})}withPlugin(e){return new Ms({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new Ms({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new Ms({...this.#e,executor:this.#e.executor.withPluginAtFront(new ls(e))})}}function jr(){return new Ms({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=p({is(e){return e.kind==="OffsetNode"},create(e){return p({kind:"OffsetNode",offset:e})}});var rt=p({is(e){return e.kind==="GroupByItemNode"},create(e){return p({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(!Fn(r))r=[r];return r.map((o)=>Du.create(e,ho(o),t))}class a{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new ze(this,e)}or(...e){return new Ve(C.create(this.#e,sr(e)))}and(...e){return new Ue(W.create(this.#e,sr(e)))}$castTo(){return new a(this.#e)}$notNull(){return new a(this.#e)}toOperationNode(){return this.#e}}class ze{#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(),dr(this.#r)?this.#r.toOperationNode():je.create(this.#r))}}class Ve{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new ze(this,e)}or(...e){return new Ve(C.create(this.#e,sr(e)))}$castTo(){return new Ve(this.#e)}toOperationNode(){return No.create(this.#e)}}class Ue{#e;constructor(e){this.#e=e}get expressionType(){return}as(e){return new ze(this,e)}and(...e){return new Ue(W.create(this.#e,sr(e)))}$castTo(){return new Ue(this.#e)}toOperationNode(){return No.create(this.#e)}}var ot=p({is(e){return e.kind==="FetchNode"},create(e,r){return{kind:"FetchNode",rowCount:qr.create(e),modifier:r}}});function it(e,r){if(!qo(e)&&!li(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=p(e)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...e){return new s({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,sr(e))})}whereRef(e,r,t){return new s({...this.#e,queryNode:de.cloneWithWhere(this.#e.queryNode,N(e,r,t))})}having(...e){return new s({...this.#e,queryNode:Gt.cloneWithHaving(this.#e.queryNode,sr(e))})}havingRef(e,r,t){return new s({...this.#e,queryNode:Gt.cloneWithHaving(this.#e.queryNode,N(e,r,t))})}select(e){return new s({...this.#e,queryNode:Gt.cloneWithSelections(this.#e.queryNode,f(e))})}distinctOn(e){return new s({...this.#e,queryNode:Gt.cloneWithDistinctOn(this.#e.queryNode,z(e))})}modifyFront(e){return new s({...this.#e,queryNode:Gt.cloneWithFrontModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.createWithExpression(e.toOperationNode()))})}distinct(){return new s({...this.#e,queryNode:Gt.cloneWithFrontModifier(this.#e.queryNode,D.create("Distinct"))})}forUpdate(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForUpdate",e?vc(e).map(zt):void 0))})}forShare(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForShare",e?vc(e).map(zt):void 0))})}forKeyShare(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForKeyShare",e?vc(e).map(zt):void 0))})}forNoKeyUpdate(e){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("ForNoKeyUpdate",e?vc(e).map(zt):void 0))})}skipLocked(){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("SkipLocked"))})}noWait(){return new s({...this.#e,queryNode:de.cloneWithEndModifier(this.#e.queryNode,D.create("NoWait"))})}selectAll(e){return new s({...this.#e,queryNode:Gt.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:de.cloneWithJoin(this.#e.queryNode,G(e,r))})}orderBy(...e){return new s({...this.#e,queryNode:de.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new s({...this.#e,queryNode:Gt.cloneWithGroupByItems(this.#e.queryNode,tt(e))})}limit(e){return new s({...this.#e,queryNode:Gt.cloneWithLimit(this.#e.queryNode,ae.create(m(e)))})}offset(e){return new s({...this.#e,queryNode:Gt.cloneWithOffset(this.#e.queryNode,et.create(m(e)))})}fetch(e,r="only"){return new s({...this.#e,queryNode:Gt.cloneWithFetch(this.#e.queryNode,it(e,r))})}top(e,r){return new s({...this.#e,queryNode:de.cloneWithTop(this.#e.queryNode,B(e,r))})}union(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!1))})}unionAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("union",e,!0))})}intersect(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!1))})}intersectAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("intersect",e,!0))})}except(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!1))})}exceptAll(e){return new s({...this.#e,queryNode:Gt.cloneWithSetOperations(this.#e.queryNode,ee("except",e,!0))})}as(e){return new nt(this,e)}clearSelect(){return new s({...this.#e,queryNode:Gt.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new s({...this.#e,queryNode:de.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new s({...this.#e,queryNode:Gt.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new s({...this.#e,queryNode:Gt.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new s({...this.#e,queryNode:de.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new s({...this.#e,queryNode:Gt.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:de.cloneWithExplain(this.#e.queryNode,e,r)}).execute()}}s=Nr;function be(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(),je.create(this.#r))}}var M=p({is(e){return e.kind==="AggregateFunctionNode"},create(e,r=[]){return p({kind:"AggregateFunctionNode",func:e,aggregated:r})},cloneWithDistinct(e){return p({...e,distinct:!0})},cloneWithOrderBy(e,r,t=!1){let o=t?"withinGroup":"orderBy";return p({...e,[o]:e[o]?U.cloneWithItems(e[o],r):U.create(r)})},cloneWithFilter(e,r){return p({...e,filter:e.filter?O.cloneWithOperation(e.filter,"And",r):O.create(r)})},cloneWithOrFilter(e,r){return p({...e,filter:e.filter?O.cloneWithOperation(e.filter,"Or",r):O.create(r)})},cloneWithOver(e,r){return p({...e,over:r})}});var yr=p({is(e){return e.kind==="FunctionNode"},create(e,r){return p({kind:"FunctionNode",func:e,arguments:r})}});class S{#e;constructor(e){this.#e=p(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:de.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(e))})}clearOrderBy(){return new S({...this.#e,aggregateFunctionNode:de.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,sr(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(),je.create(this.#r))}}function Pu(){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",[Qt(t)?zt(t):t.toOperationNode()])})},toJson(t){return new a(yr.create("to_json",[Qt(t)?zt(t):t.toOperationNode()]))}})}var at=p({is(e){return e.kind==="UnaryOperationNode"},create(e,r){return p({kind:"UnaryOperationNode",operator:e,operand:r})}});function ut(e,r){return at.create(Po.create(e),w(r))}var Ro=p({is(e){return e.kind==="CaseNode"},create(e){return p({kind:"CaseNode",value:e})},cloneWithWhen(e,r){return p({...e,when:p(e.when?[...e.when,r]:[r])})},cloneWithThen(e,r){return p({...e,when:e.when?p([...e.when.slice(0,-1),Ho.cloneWithResult(e.when[e.when.length-1],r)]):void 0})},cloneWith(e,r){return p({...e,...r})}});class bc{#e;constructor(e){this.#e=p(e)}when(...e){return new wr({...this.#e,node:Ro.cloneWithWhen(this.#e.node,Ho.create(sr(e)))})}}class wr{#e;constructor(e){this.#e=p(e)}then(e){return new mt({...this.#e,node:Ro.cloneWithThen(this.#e.node,qe(e)?le(e):m(e))})}}class mt{#e;constructor(e){this.#e=p(e)}when(...e){return new wr({...this.#e,node:Ro.cloneWithWhen(this.#e.node,Ho.create(sr(e)))})}else(e){return new dt({...this.#e,node:Ro.cloneWith(this.#e.node,{else:qe(e)?le(e):m(e)})})}end(){return new a(Ro.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(Ro.cloneWith(this.#e.node,{isStatement:!0}))}}class dt{#e;constructor(e){this.#e=p(e)}end(){return new a(Ro.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(Ro.cloneWith(this.#e.node,{isStatement:!0}))}}var Je=p({is(e){return e.kind==="JSONOperatorChainNode"},create(e){return p({kind:"JSONOperatorChainNode",operator:e,values:p([])})},cloneWithValue(e,r){return p({...e,values:p([...e.values,r])})}});var Or=p({is(e){return e.kind==="JSONPathLegNode"},create(e,r){return p({kind:"JSONPathLegNode",type:e,value:r})}});var H=p({is(e){return e.kind==="JSONPathNode"},create(e){return p({kind:"JSONPathNode",inOperator:e,pathLegs:p([])})},cloneWithLeg(e,r){return p({...e,pathLegs:p([...e.pathLegs,r])})}});var fe=p({is(e){return e.kind==="JSONReferenceNode"},create(e,r){return p({kind:"JSONReferenceNode",reference:e,traversal:r})},cloneWithTraversal(e,r){return p({...e,traversal:r})}});var Ft=/^#-\d+$/;class ke{#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"&&!Ft.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 Se(fe.cloneWithTraversal(this.#e,H.is(this.#e.traversal)?H.cloneWithLeg(this.#e.traversal,Or.create(e,r)):Je.cloneWithValue(this.#e.traversal,qr.createImmediate(r))));return new Se(H.cloneWithLeg(this.#e,Or.create(e,r)))}}class Se extends ke{#e;constructor(e){super(e);this.#e=e}get expressionType(){return}as(e){return new ct(this,e)}$castTo(){return new Se(this.#e)}$notNull(){return new Se(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(),dr(this.#r)?this.#r.toOperationNode():je.create(this.#r))}}var xr=p({is(e){return e.kind==="TupleNode"},create(e){return p({kind:"TupleNode",values:p(e)})}});var vt=["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"],Pt=[/^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=p({is(e){return e.kind==="DataTypeNode"},create(e){return p({kind:"DataTypeNode",dataType:e})}});function ft(e){if(vt.includes(e))return!0;if(Pt.some((r)=>r.test(e)))return!0;return!1}function cs(e){if(dr(e))return e.toOperationNode();if(ft(e))return ht.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}var pt=p({is(e){return e.kind==="CastNode"},create(e,r){return p({kind:"CastNode",expression:e,dataType:r})}});function Me(e=K){function r(n,u,re){return new a(Le(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 be({queryId:Ye(),executor:e,queryNode:Gt.createFrom(A(n))})},case(n){return new bc({node:Ro.create(On(n)?void 0:w(n))})},ref(n,u){if(On(u))return new a(ko(n));return new ke(lt(n,u))},jsonPath(){return new ke(H.create())},table(n){return new a(zt(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),Po.create("between"),W.create(m(u),m(re))))},betweenSymmetric(n,u,re){return new a(I.create(w(n),Po.create("between symmetric"),W.create(m(u),m(re))))},and(n){if(Fn(n))return new a(oe(n,"and"));return new a($e(n,"and"))},or(n){if(Fn(n))return new a(oe(n,"or"));return new a($e(n,"or"))},parens(...n){let u=sr(n);if(No.is(u))return new a(u);else return new a(No.create(u))},cast(n,u){return new a(pt.create(w(n),cs(u)))},withSchema(n){return Me(e.withPluginAtFront(new ls(n)))}});return o.fn=Pu(),o.eb=o,o}function q(e){return Me()}function ho(e){if(dr(e))return e.toOperationNode();else if(Kt(e))return e(q()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function Fe(e){if(dr(e))return e.toOperationNode();else if(Kt(e))return e(q()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function V(e){return Re(e)||Wr(e)||Kt(e)}function Ze(e){if(Qt(e))return ko(e);return e.toOperationNode()}function z(e){if(Fn(e))return e.map((r)=>w(r));else return[w(e)]}function w(e){if(V(e))return ho(e);return Ze(e)}function lt(e,r){let t=ko(e);if(yf(r))return fe.create(t,Je.create(Po.create(r)));let o=r.slice(0,-1);if(yf(o))return fe.create(t,H.create(Po.create(o)));throw Error(`Invalid JSON operator: ${r}`)}function ko(e){if(!e.includes("."))return te.create(Zt.create(e));let t=e.split(".").map(gr);if(t.length===3)return Mt(t);if(t.length===2)return Vt(t);throw Error(`invalid column reference ${e}`)}function Vr(e){if(e.includes(" as ")){let[t,o]=e.split(" as ").map(gr);return l.create(ko(t),je.create(o))}else return ko(e)}function Af(e){return Zt.create(e)}function nl(e){if(e.includes(" ")){let[t,o]=e.split(" ").map(gr);if(!rr(o))throw Error(`invalid order direction "${o}" next to "${t}"`);return E([t,o])[0]}else return Af(e)}function Mt(e){let[r,t,o]=e;return te.create(Zt.create(o),g.createWithSchema(r,t))}function Vt(e){let[r,t]=e;return te.create(Zt.create(t),g.create(r))}function gr(e){return e.trim()}class Ee{#e;constructor(e){this.#e=p(e)}get expressionType(){return}get isRawBuilder(){return!0}as(e){return new Nt(this,e)}$castTo(){return new Ee({...this.#e})}$notNull(){return new Ee(this.#e)}withPlugin(e){return new Ee({...this.#e,plugins:this.#e.plugins!==void 0?p([...this.#e.plugins,e]):p([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 Ee(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(),dr(this.#r)?this.#r.toOperationNode():je.create(this.#r))}}var Oe=Object.assign((e,...r)=>Q({queryId:Ye(),rawNode:Bt.create(e,r?.map(yt)??[])}),{ref(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(ko(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(zt(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(je.create))})},lit(e){return Q({queryId:Ye(),rawNode:Bt.createWithChild(qr.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return Q({queryId:Ye(),rawNode:Bt.createWithSql(e)})},join(e,r=Oe`, `){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(dr(e))return e.toOperationNode();return m(e)}var pr=p({raw(e,r=[]){return p({sql:e,query:Bt.createWithSql(e),parameters:p(r),queryId:Ye()})}});
3
+ export{dr,Zt,rl,gf,ko,Af,nl,$i,qr,sr,de,Gt,ku,Ye,_c,ls,Gi,Ru,yc,Ms,Pu,Ro,bc,cs,ho,_f,zt,Oe,pr};
@@ -1 +1 @@
1
- import{h,u,S,L,t,o,Me,Un,Ue,I,vr,F,Xn,nn,E,bm,U_,z_,zf,qf,qv,Ax,_x,cp,xS,SS,ES,kg,WE,YE,H,p,R,Q,Rl,Nl,Dl}from"./chunk-43dzhk24.js";import{vn}from"./chunk-mcq3pe4v.js";var v=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],f=I("key-round",v);S();var x=R({password:p().min(3,cp()),confirmPassword:p().min(3,cp())}).refine((s)=>s.password===s.confirmPassword,{message:ES(),path:["confirmPassword"]}),b=Ue("/reset-password")({component:N});function N(){let s=Me(),r=b.useSearch().token||"",[n,a]=u(null),[l,m]=u(!1),[i,w]=u(!1),e=Nl({resolver:Dl(x),defaultValues:{password:"",confirmPassword:""}});h(()=>{if(i){let d=setTimeout(()=>{s({to:"/login"})},3000);return()=>clearTimeout(d)}},[i,s]);let g=async(d)=>{if(!r){a(qf());return}m(!0),a(null);let{error:c}=await bm({newPassword:d.password,token:r});if(m(!1),c){a(c.message||qf());return}w(!0)};return o(Rl,{children:[o("div",{className:"mb-8",children:[t("h1",{className:"text-2xl font-bold tracking-tight text-foreground",children:kg()}),t("p",{className:"text-muted-foreground text-sm mt-1",children:WE()})]}),!r?o("div",{className:"space-y-6",children:[o("div",{className:"p-4 bg-destructive/10 border border-destructive/20 text-destructive rounded-xl text-sm flex items-start gap-3",children:[t(vn,{className:"w-5 h-5 shrink-0 mt-0.5"}),o("div",{className:"space-y-1",children:[t("p",{className:"font-semibold",children:qf()}),t("p",{className:"text-xs text-muted-foreground",children:qv()})]})]}),t(Un,{to:"/login",className:"block w-full",children:o(E,{variant:"outline",className:"w-full h-11 rounded-xl flex items-center justify-center gap-2",children:[zf(),t(Xn,{className:"w-4 h-4"})]})})]}):i?o("div",{className:"space-y-6",children:[o("div",{className:"p-4 bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 dark:text-emerald-400 rounded-xl text-sm flex items-start gap-3",children:[t(vr,{className:"w-5 h-5 shrink-0 mt-0.5"}),o("div",{className:"space-y-1",children:[t("p",{className:"font-semibold",children:xS()}),t("p",{className:"text-xs text-muted-foreground",children:SS()})]})]}),t(Un,{to:"/login",className:"block w-full",children:o(E,{className:"w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0",children:[zf(),t(Xn,{className:"w-4 h-4"})]})})]}):o("form",{onSubmit:e.handleSubmit(g),className:"space-y-5",children:[n&&t("div",{className:"p-3 bg-destructive/10 border border-destructive/20 text-destructive rounded-xl text-sm text-center font-medium",children:n}),o("div",{className:"space-y-2",children:[t(Q,{htmlFor:"password",className:"text-xs font-semibold text-muted-foreground tracking-wide uppercase",children:Ax()}),o("div",{className:"relative group",children:[t(nn,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground transition-colors group-focus-within:text-rose-500"}),t(H,{id:"password",type:"password",...e.register("password"),placeholder:_x(),className:"pl-10.5 h-11 border-border focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"})]}),e.formState.errors.password&&t("p",{className:"text-destructive text-xs font-medium",children:e.formState.errors.password.message})]}),o("div",{className:"space-y-2",children:[t(Q,{htmlFor:"confirmPassword",className:"text-xs font-semibold text-muted-foreground tracking-wide uppercase",children:U_()}),o("div",{className:"relative group",children:[t(nn,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground transition-colors group-focus-within:text-rose-500"}),t(H,{id:"confirmPassword",type:"password",...e.register("confirmPassword"),placeholder:z_(),className:"pl-10.5 h-11 border-border focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"})]}),e.formState.errors.confirmPassword&&t("p",{className:"text-destructive text-xs font-medium",children:e.formState.errors.confirmPassword.message})]}),t(E,{type:"submit",className:"w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0",disabled:l,children:l?o(L,{children:[t(F,{className:"h-4 w-4 animate-spin"}),YE()]}):o(L,{children:[t(f,{className:"w-4 h-4"}),kg()]})}),t("div",{className:"pt-2 text-center text-sm",children:t(Un,{to:"/login",className:"font-semibold text-rose-500 hover:text-rose-600 dark:text-rose-400 dark:hover:text-rose-300 transition-colors hover:underline inline-flex items-center gap-1",children:zf()})})]})]})}export{b as Route};
1
+ import{h,u,S,L,t,o,Re,Un,ze,I,xr,O,Xn,on,E,Cm,ey,ty,Vf,Kf,pw,Gx,Vx,hp,YS,JS,XS,Hg,EC,CC,q,f,R,W,Ol,Fl,Ll}from"./chunk-dx0wz749.js";import{fr}from"./chunk-6bgbx563.js";var v=[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]],p=I("key-round",v);S();var x=R({password:f().min(3,hp()),confirmPassword:f().min(3,hp())}).refine((s)=>s.password===s.confirmPassword,{message:XS(),path:["confirmPassword"]}),b=ze("/reset-password")({component:N});function N(){let s=Re(),r=b.useSearch().token||"",[n,a]=u(null),[l,m]=u(!1),[i,w]=u(!1),e=Fl({resolver:Ll(x),defaultValues:{password:"",confirmPassword:""}});h(()=>{if(i){let d=setTimeout(()=>{s({to:"/login"})},3000);return()=>clearTimeout(d)}},[i,s]);let g=async(d)=>{if(!r){a(Kf());return}m(!0),a(null);let{error:c}=await Cm({newPassword:d.password,token:r});if(m(!1),c){a(c.message||Kf());return}w(!0)};return o(Ol,{children:[o("div",{className:"mb-8",children:[t("h1",{className:"text-2xl font-bold tracking-tight text-foreground",children:Hg()}),t("p",{className:"text-muted-foreground text-sm mt-1",children:EC()})]}),!r?o("div",{className:"space-y-6",children:[o("div",{className:"p-4 bg-destructive/10 border border-destructive/20 text-destructive rounded-xl text-sm flex items-start gap-3",children:[t(fr,{className:"w-5 h-5 shrink-0 mt-0.5"}),o("div",{className:"space-y-1",children:[t("p",{className:"font-semibold",children:Kf()}),t("p",{className:"text-xs text-muted-foreground",children:pw()})]})]}),t(Un,{to:"/login",className:"block w-full",children:o(E,{variant:"outline",className:"w-full h-11 rounded-xl flex items-center justify-center gap-2",children:[Vf(),t(Xn,{className:"w-4 h-4"})]})})]}):i?o("div",{className:"space-y-6",children:[o("div",{className:"p-4 bg-emerald-500/10 border border-emerald-500/20 text-emerald-600 dark:text-emerald-400 rounded-xl text-sm flex items-start gap-3",children:[t(xr,{className:"w-5 h-5 shrink-0 mt-0.5"}),o("div",{className:"space-y-1",children:[t("p",{className:"font-semibold",children:YS()}),t("p",{className:"text-xs text-muted-foreground",children:JS()})]})]}),t(Un,{to:"/login",className:"block w-full",children:o(E,{className:"w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0",children:[Vf(),t(Xn,{className:"w-4 h-4"})]})})]}):o("form",{onSubmit:e.handleSubmit(g),className:"space-y-5",children:[n&&t("div",{className:"p-3 bg-destructive/10 border border-destructive/20 text-destructive rounded-xl text-sm text-center font-medium",children:n}),o("div",{className:"space-y-2",children:[t(W,{htmlFor:"password",className:"text-xs font-semibold text-muted-foreground tracking-wide uppercase",children:Gx()}),o("div",{className:"relative group",children:[t(on,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground transition-colors group-focus-within:text-rose-500"}),t(q,{id:"password",type:"password",...e.register("password"),placeholder:Vx(),className:"pl-10.5 h-11 border-border focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"})]}),e.formState.errors.password&&t("p",{className:"text-destructive text-xs font-medium",children:e.formState.errors.password.message})]}),o("div",{className:"space-y-2",children:[t(W,{htmlFor:"confirmPassword",className:"text-xs font-semibold text-muted-foreground tracking-wide uppercase",children:ey()}),o("div",{className:"relative group",children:[t(on,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground transition-colors group-focus-within:text-rose-500"}),t(q,{id:"confirmPassword",type:"password",...e.register("confirmPassword"),placeholder:ty(),className:"pl-10.5 h-11 border-border focus-visible:ring-rose-500/50 focus-visible:border-rose-500 rounded-xl transition-all shadow-sm"})]}),e.formState.errors.confirmPassword&&t("p",{className:"text-destructive text-xs font-medium",children:e.formState.errors.confirmPassword.message})]}),t(E,{type:"submit",className:"w-full h-11 bg-gradient-to-r from-rose-500 to-orange-500 hover:from-rose-600 hover:to-orange-600 text-white font-semibold rounded-xl shadow-md shadow-rose-500/10 hover:shadow-rose-500/20 active:scale-[0.98] transition-all flex items-center justify-center gap-2 border-0",disabled:l,children:l?o(L,{children:[t(O,{className:"h-4 w-4 animate-spin"}),CC()]}):o(L,{children:[t(p,{className:"w-4 h-4"}),Hg()]})}),t("div",{className:"pt-2 text-center text-sm",children:t(Un,{to:"/login",className:"font-semibold text-rose-500 hover:text-rose-600 dark:text-rose-400 dark:hover:text-rose-300 transition-colors hover:underline inline-flex items-center gap-1",children:Vf()})})]})]})}export{b as Route};
@@ -0,0 +1,2 @@
1
+ import{I,yp,bp,vp,wp,Md,kd,Rd,Pd,Nd,su}from"./chunk-dx0wz749.js";import{Io}from"./chunk-eez1yncf.js";import{To}from"./chunk-7wb3dga5.js";var o=[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]],Qs=I("activity",o);var a=[["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M17 20v2",key:"1rnc9c"}],["path",{d:"M17 2v2",key:"11trls"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M2 17h2",key:"7oei6x"}],["path",{d:"M2 7h2",key:"asdhe0"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"M20 17h2",key:"1fpfkl"}],["path",{d:"M20 7h2",key:"1o8tra"}],["path",{d:"M7 20v2",key:"4gnj0m"}],["path",{d:"M7 2v2",key:"1i4yhu"}],["rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",key:"1vbyd7"}],["rect",{x:"8",y:"8",width:"8",height:"8",rx:"1",key:"z9xiuo"}]],io=I("cpu",a);var r=[["path",{d:"m12 14 4-4",key:"9kzdfg"}],["path",{d:"M3.34 19a10 10 0 1 1 17.32 0",key:"19p75a"}]],Bo=I("gauge",r);var c=[["rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2",key:"ngkwjq"}],["rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2",key:"iecqi9"}],["line",{x1:"6",x2:"6.01",y1:"6",y2:"6",key:"16zg32"}],["line",{x1:"6",x2:"6.01",y1:"18",y2:"18",key:"nzw8ys"}]],vn=I("server",c);var n=[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"M12 8v4",key:"1got3b"}],["path",{d:"M12 16h.01",key:"1drbdi"}]],Wl=I("shield-alert",n);var i=[["line",{x1:"12",x2:"12",y1:"2",y2:"22",key:"7eqyqh"}],["path",{d:"M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6",key:"1b0p4s"}]],ma=I("dollar-sign",i);var Qa={agent_total_tokens:{label:()=>Nd(),icon:io,unit:"tokens"},agent_cost:{label:()=>kd(),icon:ma,unit:"$"},agent_mcp_call_count:{label:()=>Rd(),icon:vn,unit:"calls"},agent_bash_call_count:{label:()=>Md(),icon:To,unit:"calls"},agent_tool_call_count:{label:()=>Pd(),icon:Io,unit:"calls"}};function Oi(e,t){if(e==="agent_cost")return`$${t.toFixed(2)}`;return t.toLocaleString()}function Yl(e){switch(su(e)){case"1hour":return bp();case"5hour":return vp();case"1day":return yp();case"7day":return wp();default:return e}}
2
+ export{Qs,io,ma,Bo,vn,Wl,Qa,Oi,Yl};