@shumai-one/shumai 0.4.7 → 0.4.8

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 (139) hide show
  1. package/bin/{chunk-6rjkbwz6.js → chunk-07pgpftg.js} +7 -7
  2. package/bin/{chunk-wvq717b5.js → chunk-0b5s5ge0.js} +2 -2
  3. package/bin/{chunk-zz0522zr.js → chunk-0jaj2807.js} +3 -3
  4. package/bin/{chunk-5qkwpy8c.js → chunk-1qk4e3j9.js} +2 -2
  5. package/bin/{chunk-3b6h719s.js → chunk-1y7nvhgx.js} +2 -2
  6. package/bin/{chunk-yqvhgtez.js → chunk-1ymyhrh2.js} +2 -2
  7. package/bin/{chunk-j41mya13.js → chunk-1zpsbvq9.js} +2 -2
  8. package/bin/{chunk-vdnmq163.js → chunk-251rat7t.js} +1 -1
  9. package/bin/{chunk-p5fwjk5c.js → chunk-29wjvgwv.js} +1 -1
  10. package/bin/{chunk-fk712d68.js → chunk-2ftmxhr5.js} +1 -1
  11. package/bin/{chunk-fvgb6rps.js → chunk-2y7y60pc.js} +2 -2
  12. package/bin/{chunk-rkqpnyzx.js → chunk-3rjdkmhb.js} +1 -1
  13. package/bin/{chunk-q6jsw0rr.js → chunk-43dzhk24.js} +48 -48
  14. package/bin/{chunk-3g5pyw2e.js → chunk-45mheqnm.js} +2 -2
  15. package/bin/{chunk-b3aqmcps.js → chunk-4sq35ks7.js} +2 -2
  16. package/bin/{chunk-fhazy8f9.js → chunk-4tm9cw4v.js} +1 -1
  17. package/bin/{chunk-kg2c445x.js → chunk-4tpkx2ft.js} +1 -1
  18. package/bin/chunk-55n569j1.js +1 -0
  19. package/bin/{chunk-887pj9xd.js → chunk-5pcv139g.js} +2 -2
  20. package/bin/{chunk-8gna37dd.js → chunk-65ets3f0.js} +1 -1
  21. package/bin/{chunk-8ystwvdt.js → chunk-67ewr4j4.js} +1 -1
  22. package/bin/{chunk-xca338dw.js → chunk-6h76kqv2.js} +3 -3
  23. package/bin/chunk-6jaf9hxa.js +1 -0
  24. package/bin/{chunk-k810fstm.js → chunk-6t5r26bm.js} +1 -1
  25. package/bin/{chunk-camzbwqh.js → chunk-6vst0k0k.js} +1 -1
  26. package/bin/{chunk-an6nsq1t.js → chunk-6xqpbkb6.js} +1 -1
  27. package/bin/{chunk-radcwage.js → chunk-75x3b8ds.js} +2 -2
  28. package/bin/chunk-7hxd4st0.js +1 -0
  29. package/bin/{chunk-3h9c5ak3.js → chunk-7nv7r7zx.js} +1 -1
  30. package/bin/{chunk-s41mgkse.js → chunk-7rvyq5gr.js} +1 -1
  31. package/bin/{chunk-m638fg4n.js → chunk-9ht2kr33.js} +5 -5
  32. package/bin/chunk-9kb55e6b.js +1 -0
  33. package/bin/{chunk-h3wr8nnk.js → chunk-9v10mkts.js} +1 -1
  34. package/bin/{chunk-05tnmf8h.js → chunk-afsm0ct9.js} +2 -2
  35. package/bin/{chunk-njabdtvb.js → chunk-b93qxjts.js} +2 -2
  36. package/bin/{chunk-xzyfnfck.js → chunk-b9p9yhky.js} +2 -2
  37. package/bin/{chunk-v1sgrg0r.js → chunk-bbk5v964.js} +1 -1
  38. package/bin/{chunk-rdscv38p.js → chunk-bcjkapyp.js} +1 -1
  39. package/bin/{chunk-4a88wwg2.js → chunk-bcqhjbpy.js} +1 -1
  40. package/bin/{chunk-zcdqsp1e.js → chunk-bxksbrcm.js} +1 -1
  41. package/bin/chunk-c1a1srsw.js +2 -0
  42. package/bin/chunk-c7yxnyep.js +1 -0
  43. package/bin/{chunk-8b1w6bj9.js → chunk-czwpfv0w.js} +1 -1
  44. package/bin/{chunk-ebx3bd4c.js → chunk-d9dmr2vc.js} +1 -1
  45. package/bin/chunk-da4fd4f8.js +2 -0
  46. package/bin/{chunk-kq2qbwx1.js → chunk-dk2trprj.js} +1 -1
  47. package/bin/{chunk-m2h7a172.js → chunk-dmewtzbe.js} +1 -1
  48. package/bin/{chunk-pa1fmskf.js → chunk-dp1mrw7m.js} +1 -1
  49. package/bin/{chunk-dyq6h9ha.js → chunk-dpn61sht.js} +1 -1
  50. package/bin/{chunk-781990k7.js → chunk-drpdjxmw.js} +1 -1
  51. package/bin/{chunk-b0rjvx5g.js → chunk-e333evwr.js} +2 -2
  52. package/bin/{chunk-gf4n4ahk.js → chunk-e3qxpswy.js} +1 -1
  53. package/bin/chunk-faaqparg.js +2 -0
  54. package/bin/{chunk-4jgq9m51.js → chunk-fezar34g.js} +2 -2
  55. package/bin/{chunk-pcspeqwq.js → chunk-fnca3xqw.js} +2 -2
  56. package/bin/{chunk-6kdf411z.js → chunk-frma9pgq.js} +1 -1
  57. package/bin/chunk-g82qnxw6.js +2 -0
  58. package/bin/{chunk-4f5pnnah.js → chunk-gj3vrbkx.js} +12 -12
  59. package/bin/{chunk-mm1a0zja.js → chunk-hed37kyr.js} +1 -1
  60. package/bin/{chunk-nnq8g9yy.js → chunk-ht64xpjp.js} +3 -3
  61. package/bin/{chunk-nn5hyf6f.js → chunk-j3qz3wa3.js} +1 -1
  62. package/bin/chunk-j6ptdqp9.js +2 -0
  63. package/bin/{chunk-9va1mzeq.js → chunk-j95fjg69.js} +1 -1
  64. package/bin/{chunk-q1d7x1cc.js → chunk-jgnp68ez.js} +1 -1
  65. package/bin/{chunk-0ygtayqf.js → chunk-jhxcm88f.js} +1 -1
  66. package/bin/{chunk-ccvjwhqq.js → chunk-jwhgybtg.js} +1 -1
  67. package/bin/chunk-kdg245g7.js +1 -0
  68. package/bin/{chunk-8sf106rq.js → chunk-mcq3pe4v.js} +1 -1
  69. package/bin/chunk-mg4p33eg.js +2 -0
  70. package/bin/{chunk-z9jpgxf1.js → chunk-mn9ax7qa.js} +1 -1
  71. package/bin/chunk-mrdznst9.js +1 -0
  72. package/bin/chunk-msg8j3hj.css +1 -0
  73. package/bin/{chunk-1ntn42d2.js → chunk-n4f1he1g.js} +3 -3
  74. package/bin/{chunk-twyxs4z2.js → chunk-nradb5py.js} +1 -1
  75. package/bin/chunk-nsvfcp3f.js +1 -0
  76. package/bin/{chunk-9v6eqa3n.js → chunk-nx782n1x.js} +2 -2
  77. package/bin/{chunk-3m5kwcj7.js → chunk-p4hwyysm.js} +1 -1
  78. package/bin/{chunk-dkzyv61a.js → chunk-p706vjvr.js} +2 -2
  79. package/bin/{chunk-jde9r5mj.js → chunk-pbmkewt5.js} +1 -1
  80. package/bin/{chunk-3tyk9xgf.js → chunk-pbq64m5k.js} +2 -2
  81. package/bin/{chunk-njqf50vw.js → chunk-pg5mayjc.js} +1 -1
  82. package/bin/{chunk-rbagbd0e.js → chunk-pq3pyrvy.js} +1 -1
  83. package/bin/{chunk-e17daz1x.js → chunk-qje7g7t7.js} +1 -1
  84. package/bin/{chunk-r55htzxr.js → chunk-qn37fsy3.js} +1 -1
  85. package/bin/{chunk-3r5yc5wm.js → chunk-qrmkkxjh.js} +4 -4
  86. package/bin/chunk-qw4v0qdg.js +1 -0
  87. package/bin/{chunk-zr11zfwc.js → chunk-qw76wcrb.js} +1 -1
  88. package/bin/{chunk-ebf1r872.js → chunk-r8ss8xm1.js} +4 -4
  89. package/bin/{chunk-s63vj79f.js → chunk-rvj965cr.js} +1 -1
  90. package/bin/{chunk-4m8gk79m.js → chunk-rzannb5e.js} +2 -2
  91. package/bin/{chunk-yr03tf5r.js → chunk-s26a26h3.js} +1 -1
  92. package/bin/{chunk-jt04mf5s.js → chunk-sf9ezxgy.js} +1 -1
  93. package/bin/{chunk-hye75kp0.js → chunk-t2sqtc9p.js} +2 -2
  94. package/bin/{chunk-k3qypq3x.js → chunk-tf3hke5h.js} +1 -1
  95. package/bin/{chunk-vx66rms0.js → chunk-tjhbr5ks.js} +1 -1
  96. package/bin/chunk-twwpbp8d.js +2 -0
  97. package/bin/{chunk-xznabrt2.js → chunk-twx715xf.js} +1 -1
  98. package/bin/{chunk-zmjtv19e.js → chunk-tycap2k9.js} +1 -1
  99. package/bin/chunk-v3yfee88.js +2 -0
  100. package/bin/{chunk-typ46eqd.js → chunk-v6tjp5qt.js} +4 -4
  101. package/bin/{chunk-ycw3rwhx.js → chunk-vfv27kve.js} +3 -3
  102. package/bin/chunk-vq24vj88.js +1 -0
  103. package/bin/{chunk-53vtc74g.js → chunk-w53gqdnw.js} +2 -2
  104. package/bin/{chunk-q45n02fs.js → chunk-wdbew0hx.js} +1 -1
  105. package/bin/{chunk-11c93g1m.js → chunk-wqqdy0xb.js} +2 -2
  106. package/bin/{chunk-s30fjvzs.js → chunk-ws216bmf.js} +1 -1
  107. package/bin/{chunk-5v4s2kp4.js → chunk-x33bf3ay.js} +1 -1
  108. package/bin/{chunk-5rk7dyx9.js → chunk-x79scans.js} +51 -51
  109. package/bin/chunk-xktxk53n.js +1 -0
  110. package/bin/{chunk-rkafv27g.js → chunk-xmn5v64e.js} +1 -1
  111. package/bin/{chunk-zbt4h7n0.js → chunk-y4pe65d1.js} +1 -1
  112. package/bin/{chunk-ny7qjn6s.js → chunk-ybnykjsg.js} +1 -1
  113. package/bin/{chunk-3p1bb08a.js → chunk-yeb5bcxz.js} +1 -1
  114. package/bin/{chunk-ayq8dskd.js → chunk-yvz2b957.js} +1 -1
  115. package/bin/{chunk-t3t7dcfq.js → chunk-ze3msq86.js} +1 -1
  116. package/bin/{chunk-5wp37g6w.js → chunk-zhx4vsgt.js} +2 -2
  117. package/bin/shumai-app.html +1 -1
  118. package/bin/shumai-app.js +258 -257
  119. package/package.json +7 -7
  120. package/bin/chunk-0xsgx9ep.js +0 -1
  121. package/bin/chunk-1ajgdv26.js +0 -1
  122. package/bin/chunk-30dsxm8s.js +0 -1
  123. package/bin/chunk-58e1a3re.js +0 -2
  124. package/bin/chunk-6ksrrayx.css +0 -1
  125. package/bin/chunk-bgm76rzj.js +0 -1
  126. package/bin/chunk-btmxr226.js +0 -1
  127. package/bin/chunk-ee3mrvqp.js +0 -2
  128. package/bin/chunk-fg6zf2gb.js +0 -2
  129. package/bin/chunk-g9gmht89.js +0 -2
  130. package/bin/chunk-htpjtarr.js +0 -2
  131. package/bin/chunk-j547gtag.js +0 -2
  132. package/bin/chunk-jf4kcad0.js +0 -1
  133. package/bin/chunk-k5hnrtrt.js +0 -1
  134. package/bin/chunk-qjzyze00.js +0 -1
  135. package/bin/chunk-rfhmk32e.js +0 -1
  136. package/bin/chunk-xbge27m4.js +0 -1
  137. package/bin/chunk-xcsz1wp7.js +0 -1
  138. package/bin/chunk-zb0az2tq.js +0 -2
  139. package/bin/chunk-zej27b5c.js +0 -2
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{On,Qt,qo,Ts,oa,sa,Kt,Ir,f,Ac,Fn,ze,Sn,fm,Ro,pf,Zt,cs,No,Tr,Ho,Mu}from"./chunk-njabdtvb.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 Ji=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:Ji.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)&&fm.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 uf{#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:Ji.create()})},createSelectAllFromTable(e){return f({kind:"SelectionNode",selection:te.createSelectAll(e)})}});class ff{#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 Eu(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=Eu(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 Cu(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 Cu(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)=>Mu.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 Iu(){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=Iu(),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(pf(r))return fe.create(t,Qe.create(Ro.create(r)));let o=r.slice(0,-1);if(pf(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 df(e){return Lt.create(e)}function Xi(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 df(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,Ji,uf,Mo,df,Xi,za,jr,sr,de,Gt,Eu,Ye,mc,is,ja,Cu,hc,Is,Iu,ko,gc,ls,ho,ff,zt,De,fr};
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};
@@ -1,4 +1,4 @@
1
- import{O,P,h,D,b,u,S,L,t,o,B,A,I,Wa,ve,Xt,er,Ii,we,Re,E,fn,pn,mn,hn,Ce,Ie,Te,Y0,$y,lb,Gf,Vw,UE,GE,VE,q1,lt,_a,mt,ht,gt,js,Ur,$t,pe}from"./chunk-q6jsw0rr.js";import{Hs,yn,Wr,ci}from"./chunk-887pj9xd.js";var Et=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],du=I("arrow-left",Et);var It=[["path",{d:"m11 10 3 3",key:"fzmg1i"}],["path",{d:"M6.5 21A3.5 3.5 0 1 0 3 17.5a2.62 2.62 0 0 1-.708 1.792A1 1 0 0 0 3 21z",key:"p4q2r7"}],["path",{d:"M9.969 17.031 21.378 5.624a1 1 0 0 0-3.002-3.002L6.967 14.031",key:"wy6l02"}]],ze=I("brush",It);var Rt=[["path",{d:"M21 7v6h-6",key:"3ptur4"}],["path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7",key:"1kgawr"}]],je=I("redo",Rt);var Dt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],$e=I("square",Dt);var Lt=[["path",{d:"M3 7v6h6",key:"1v2h90"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13",key:"1r6uu6"}]],Be=I("undo",Lt);S();var Tt=["#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#a855f7","#ec4899","#000000","#ffffff"],qs=O(({projectId:y,onSendMessage:He,replyingTo:d,onCancelReply:ne,placeholder:Oe,initialText:V="",value:T,onChangeText:_,disabled:fe=!1,allowMentions:qe,disableMentions:We=!1,allowAttachments:Ke=!0,workspaceAssets:w,onRemoveWorkspaceAsset:ge,allowMarkup:Ve,hideAnnotationControl:Xe=!1,canMarkup:Qe=!0,markupDisabledTooltip:Ge,allowTimestamp:Je=!0,currentTime:p,frameRate:f,startTimecode:be,formatTimestamp:N,bottomLeftExtra:Ye,isStreaming:oe=!1,onAbort:Ze,onTyping:F},et)=>{let[g,U]=u([]),[re,X]=u(null),[x,tt]=u(!0),z=qe??!We,nt=Ve??!Xe,j=Je,{videoTimeDisplayMode:Q}=$t(),ot=D(()=>{if(p===void 0)return"";if(N)return N(p);if(!f)return"";let e=Math.round(p*f);return yn(e,f,Q,be)},[p,f,Q,be,N]),{teamId:G,ensureTeamIdForProject:he}=lt(),{members:xe,loading:ye,fetchMembers:rt,fetchProjectMembers:at}=Ur();h(()=>{if(y&&!G)he(y)},[y,G,he]);let{isDrawing:st,setIsDrawing:H,currentTool:J,setTool:Y,currentColor:Ne,setColor:it,undo:ct,redo:dt,history:ut,historyIndex:ke,annotations:ae,reset:Me}=Wr(),[se,k]=u(!1),[le,pt]=u(""),[q,W]=u(0),[v,Ae]=u({bots:!1,users:!1}),[ie,C]=u(!1),ft=D(()=>{if(!x||!j||p===void 0||!N&&!f||ie)return"";if(Q==="timecode")return"pl-[120px]";return"pl-[85px]"},[x,j,p,f,ie,Q,N]),s=b(null),Z=b(null),M=b(null),Ee=b(null),R=b(!1),{mutateAsync:De}=B({mutationFn:async({projectId:e,data:n})=>{let r=await A.api.projects[":projectId"].attachments.$post({param:{projectId:e},json:n});if(!r.ok)throw Error("Failed to create attachment");return await r.json()}});h(()=>{if(T!==void 0&&s.current){if(R.current){R.current=!1;return}if(s.current.innerText!==T)s.current.innerText=T,C(!!T.trim())}else if(V&&s.current){s.current.innerText=V,C(!!V.trim()),s.current.focus();let e=document.createRange(),n=window.getSelection();e.selectNodeContents(s.current),e.collapse(!1),n?.removeAllRanges(),n?.addRange(e)}},[T,V]);let ce=b(null),Le=P((e)=>{if(!s.current)return;let n=document.createElement("span");n.contentEditable="false",n.dataset.type="mention",n.dataset.id=e.id,n.className="inline-block bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300 px-1.5 py-0.5 rounded-md text-sm font-medium align-middle select-none mx-0.5",n.innerText=`@${e.name}`;let r=document.createTextNode(" ");s.current.appendChild(n),s.current.appendChild(r);let l=document.createRange(),i=window.getSelection();l.setStartAfter(r),l.collapse(!0),i?.removeAllRanges(),i?.addRange(l),C(!0);let a=s.current.innerText||"";R.current=!0,_?.(a),F?.(),s.current.focus()},[_,F]);h(()=>{if(d&&s.current){if(d.id!==ce.current){if(ce.current=d.id,z&&d.creator?.id&&d.creator?.name){let r=s.current.querySelectorAll('span[data-type="mention"]');if(!Array.from(r).some((i)=>i.dataset.id===d.creator.id)){Le({id:d.creator.id,name:d.creator.name});return}}}s.current.focus();let e=document.createRange(),n=window.getSelection();e.selectNodeContents(s.current),e.collapse(!1),n?.removeAllRanges(),n?.addRange(e)}else if(!d)ce.current=null},[d,z,Le]),h(()=>()=>{H(!1)},[H]);let K=xe.filter((e)=>e.type==="agent"&&e.name?.toLowerCase().startsWith(le.toLowerCase())).map((e)=>({type:"user",data:e})),ee=xe.filter((e)=>e.type!=="agent"&&e.name?.toLowerCase().startsWith(le.toLowerCase())).map((e)=>({type:"user",data:e})),te=[...v.bots?[]:K,...v.users?[]:ee];h(()=>{W(0)},[le,se,v]),h(()=>{Ee.current?.querySelector(`[data-index="${q}"]`)?.scrollIntoView({block:"nearest"})},[q]);let Se=(e)=>e.split(" ").map((n)=>n[0]).slice(0,2).join("").toUpperCase(),Pe=()=>{if(!s.current)return;let e=s.current.innerText||"";if(C(!!e.trim()),R.current=!0,_?.(e),F?.(),!z){k(!1),M.current=null;return}let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),{startContainer:l,startOffset:i}=r;if(l.nodeType===Node.TEXT_NODE){let c=(l.textContent||"").slice(0,i),m=c.lastIndexOf("@");if(m!==-1){let Mt=m===0,At=c[m-1];if(Mt||/\s/.test(At)){let Ue=c.slice(m+1);if(!/\s/.test(Ue)){if(pt(Ue),k(!0),y)at(y,!0,!0);else if(G)rt(G,!0,!0);let me=document.createRange();me.setStart(l,m),me.setEnd(l,i),M.current=me;return}}}}k(!1),M.current=null},de=(e)=>{if(!M.current||!s.current)return;let n=M.current;n.deleteContents();let r=document.createElement("span");r.contentEditable="false",r.dataset.type="mention",r.dataset.id=e.data.id,r.className="inline-block bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300 px-1.5 py-0.5 rounded-md text-sm font-medium align-middle select-none mx-0.5",r.innerText=`@${e.data.name}`,n.insertNode(r);let l=document.createTextNode(" ");r.after(l);let i=document.createRange(),a=window.getSelection();i.setStartAfter(l),i.collapse(!0),a?.removeAllRanges(),a?.addRange(i),k(!1),M.current=null,C(!0);let c=s.current.innerText||"";R.current=!0,_?.(c),F?.(),s.current.focus()},bt=(e)=>{e.preventDefault();let n=e.clipboardData.getData("text/plain");if(!n)return;let r=window.getSelection();if(!r||r.rangeCount===0||!s.current?.contains(r.anchorNode)){if(s.current){s.current.focus();let i=document.createRange();i.selectNodeContents(s.current),i.collapse(!1),r=window.getSelection(),r?.removeAllRanges(),r?.addRange(i)}}if(!(typeof document.execCommand==="function"&&document.queryCommandSupported?.("insertText")&&document.execCommand("insertText",!1,n))){let i=window.getSelection();if(i&&i.rangeCount>0){let a=i.getRangeAt(0);a.deleteContents();let c=document.createTextNode(n);a.insertNode(c),a.setStartAfter(c),a.collapse(!0),i.removeAllRanges(),i.addRange(a)}else if(s.current)s.current.innerText+=n}Pe()},xt=(e)=>{if(e.nativeEvent.isComposing)return;if(se&&z&&te.length>0){if(e.key==="ArrowUp"){e.preventDefault(),W((n)=>n>0?n-1:te.length-1);return}if(e.key==="ArrowDown"){e.preventDefault(),W((n)=>n<te.length-1?n+1:0);return}if(e.key==="Enter"||e.key==="Tab"){e.preventDefault(),de(te[q]);return}if(e.key==="Escape"){e.preventDefault(),k(!1);return}}if(e.key==="Enter"&&!e.shiftKey)e.preventDefault(),_e()},vt=P(async(e)=>{if(!e.target.files)return;let n=Array.from(e.target.files);for(let r of n){let l=`${Date.now()}-${r.name}`,i={id:l,file:r,progress:0};U((a)=>[...a,i]);try{let a=await De({projectId:y,data:{fileName:r.name,contentType:r.type,size:r.size}});if(a.uploadUrl&&a.id)await fetch(a.uploadUrl,{method:"PUT",body:r,headers:{"Content-Type":r.type}}),U((c)=>c.map((m)=>m.id===l?{...m,progress:100,attachmentId:a.id}:m))}catch(a){U((c)=>c.map((m)=>m.id===l?{...m,error:a instanceof Error?a.message:"Upload failed"}:m))}}if(Z.current)Z.current.value=""},[y,De]),yt=(e)=>{U((n)=>n.filter((r)=>r.id!==e))},_e=()=>{if(!s.current)return;if(g.some((a)=>!a.attachmentId&&!a.error))return;let n=g.map((a)=>a.attachmentId).filter((a)=>!!a),r=g.filter((a)=>!a.error&&!!a.attachmentId).map((a)=>({id:a.attachmentId,name:a.file.name,type:a.file.type,url:a.file.type.startsWith("image/")||js(a.file.name)?URL.createObjectURL(a.file):void 0})),l="";s.current.childNodes.forEach((a)=>{if(a.nodeType===Node.TEXT_NODE)l+=a.textContent;else if(a.nodeType===Node.ELEMENT_NODE){let c=a;if(c.dataset.type==="mention")l+=`<@${c.dataset.id}>`;else if(c.tagName==="BR")l+=`
1
+ import{O,P,h,D,b,u,S,L,t,o,B,A,I,Wa,ve,Xt,er,Ii,we,Re,E,fn,pn,mn,hn,Ce,Ie,Te,J0,Gy,cb,Vf,Qw,zE,VE,QE,H1,lt,_a,mt,ht,gt,js,Ur,$t,pe}from"./chunk-43dzhk24.js";import{Hs,yn,Wr,ci}from"./chunk-5pcv139g.js";var Et=[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]],fu=I("arrow-left",Et);var It=[["path",{d:"m11 10 3 3",key:"fzmg1i"}],["path",{d:"M6.5 21A3.5 3.5 0 1 0 3 17.5a2.62 2.62 0 0 1-.708 1.792A1 1 0 0 0 3 21z",key:"p4q2r7"}],["path",{d:"M9.969 17.031 21.378 5.624a1 1 0 0 0-3.002-3.002L6.967 14.031",key:"wy6l02"}]],ze=I("brush",It);var Rt=[["path",{d:"M21 7v6h-6",key:"3ptur4"}],["path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7",key:"1kgawr"}]],je=I("redo",Rt);var Dt=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]],$e=I("square",Dt);var Lt=[["path",{d:"M3 7v6h6",key:"1v2h90"}],["path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13",key:"1r6uu6"}]],Be=I("undo",Lt);S();var Tt=["#ef4444","#f97316","#eab308","#22c55e","#3b82f6","#a855f7","#ec4899","#000000","#ffffff"],qs=O(({projectId:y,onSendMessage:He,replyingTo:d,onCancelReply:ne,placeholder:Oe,initialText:V="",value:T,onChangeText:_,disabled:fe=!1,allowMentions:qe,disableMentions:We=!1,allowAttachments:Ke=!0,workspaceAssets:w,onRemoveWorkspaceAsset:ge,allowMarkup:Ve,hideAnnotationControl:Xe=!1,canMarkup:Qe=!0,markupDisabledTooltip:Ge,allowTimestamp:Je=!0,currentTime:p,frameRate:f,startTimecode:be,formatTimestamp:N,bottomLeftExtra:Ye,isStreaming:oe=!1,onAbort:Ze,onTyping:F},et)=>{let[g,U]=u([]),[re,X]=u(null),[x,tt]=u(!0),z=qe??!We,nt=Ve??!Xe,j=Je,{videoTimeDisplayMode:Q}=$t(),ot=D(()=>{if(p===void 0)return"";if(N)return N(p);if(!f)return"";let e=Math.round(p*f);return yn(e,f,Q,be)},[p,f,Q,be,N]),{teamId:G,ensureTeamIdForProject:he}=lt(),{members:xe,loading:ye,fetchMembers:rt,fetchProjectMembers:at}=Ur();h(()=>{if(y&&!G)he(y)},[y,G,he]);let{isDrawing:st,setIsDrawing:H,currentTool:J,setTool:Y,currentColor:Ne,setColor:it,undo:ct,redo:dt,history:ut,historyIndex:ke,annotations:ae,reset:Me}=Wr(),[se,k]=u(!1),[le,pt]=u(""),[q,W]=u(0),[v,Ae]=u({bots:!1,users:!1}),[ie,C]=u(!1),ft=D(()=>{if(!x||!j||p===void 0||!N&&!f||ie)return"";if(Q==="timecode")return"pl-[120px]";return"pl-[85px]"},[x,j,p,f,ie,Q,N]),s=b(null),Z=b(null),M=b(null),Ee=b(null),R=b(!1),{mutateAsync:De}=B({mutationFn:async({projectId:e,data:n})=>{let r=await A.api.projects[":projectId"].attachments.$post({param:{projectId:e},json:n});if(!r.ok)throw Error("Failed to create attachment");return await r.json()}});h(()=>{if(T!==void 0&&s.current){if(R.current){R.current=!1;return}if(s.current.innerText!==T)s.current.innerText=T,C(!!T.trim())}else if(V&&s.current){s.current.innerText=V,C(!!V.trim()),s.current.focus();let e=document.createRange(),n=window.getSelection();e.selectNodeContents(s.current),e.collapse(!1),n?.removeAllRanges(),n?.addRange(e)}},[T,V]);let ce=b(null),Le=P((e)=>{if(!s.current)return;let n=document.createElement("span");n.contentEditable="false",n.dataset.type="mention",n.dataset.id=e.id,n.className="inline-block bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300 px-1.5 py-0.5 rounded-md text-sm font-medium align-middle select-none mx-0.5",n.innerText=`@${e.name}`;let r=document.createTextNode(" ");s.current.appendChild(n),s.current.appendChild(r);let l=document.createRange(),i=window.getSelection();l.setStartAfter(r),l.collapse(!0),i?.removeAllRanges(),i?.addRange(l),C(!0);let a=s.current.innerText||"";R.current=!0,_?.(a),F?.(),s.current.focus()},[_,F]);h(()=>{if(d&&s.current){if(d.id!==ce.current){if(ce.current=d.id,z&&d.creator?.id&&d.creator?.name){let r=s.current.querySelectorAll('span[data-type="mention"]');if(!Array.from(r).some((i)=>i.dataset.id===d.creator.id)){Le({id:d.creator.id,name:d.creator.name});return}}}s.current.focus();let e=document.createRange(),n=window.getSelection();e.selectNodeContents(s.current),e.collapse(!1),n?.removeAllRanges(),n?.addRange(e)}else if(!d)ce.current=null},[d,z,Le]),h(()=>()=>{H(!1)},[H]);let K=xe.filter((e)=>e.type==="agent"&&e.name?.toLowerCase().startsWith(le.toLowerCase())).map((e)=>({type:"user",data:e})),ee=xe.filter((e)=>e.type!=="agent"&&e.name?.toLowerCase().startsWith(le.toLowerCase())).map((e)=>({type:"user",data:e})),te=[...v.bots?[]:K,...v.users?[]:ee];h(()=>{W(0)},[le,se,v]),h(()=>{Ee.current?.querySelector(`[data-index="${q}"]`)?.scrollIntoView({block:"nearest"})},[q]);let Se=(e)=>e.split(" ").map((n)=>n[0]).slice(0,2).join("").toUpperCase(),Pe=()=>{if(!s.current)return;let e=s.current.innerText||"";if(C(!!e.trim()),R.current=!0,_?.(e),F?.(),!z){k(!1),M.current=null;return}let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),{startContainer:l,startOffset:i}=r;if(l.nodeType===Node.TEXT_NODE){let c=(l.textContent||"").slice(0,i),m=c.lastIndexOf("@");if(m!==-1){let Mt=m===0,At=c[m-1];if(Mt||/\s/.test(At)){let Ue=c.slice(m+1);if(!/\s/.test(Ue)){if(pt(Ue),k(!0),y)at(y,!0,!0);else if(G)rt(G,!0,!0);let me=document.createRange();me.setStart(l,m),me.setEnd(l,i),M.current=me;return}}}}k(!1),M.current=null},de=(e)=>{if(!M.current||!s.current)return;let n=M.current;n.deleteContents();let r=document.createElement("span");r.contentEditable="false",r.dataset.type="mention",r.dataset.id=e.data.id,r.className="inline-block bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-300 px-1.5 py-0.5 rounded-md text-sm font-medium align-middle select-none mx-0.5",r.innerText=`@${e.data.name}`,n.insertNode(r);let l=document.createTextNode(" ");r.after(l);let i=document.createRange(),a=window.getSelection();i.setStartAfter(l),i.collapse(!0),a?.removeAllRanges(),a?.addRange(i),k(!1),M.current=null,C(!0);let c=s.current.innerText||"";R.current=!0,_?.(c),F?.(),s.current.focus()},bt=(e)=>{e.preventDefault();let n=e.clipboardData.getData("text/plain");if(!n)return;let r=window.getSelection();if(!r||r.rangeCount===0||!s.current?.contains(r.anchorNode)){if(s.current){s.current.focus();let i=document.createRange();i.selectNodeContents(s.current),i.collapse(!1),r=window.getSelection(),r?.removeAllRanges(),r?.addRange(i)}}if(!(typeof document.execCommand==="function"&&document.queryCommandSupported?.("insertText")&&document.execCommand("insertText",!1,n))){let i=window.getSelection();if(i&&i.rangeCount>0){let a=i.getRangeAt(0);a.deleteContents();let c=document.createTextNode(n);a.insertNode(c),a.setStartAfter(c),a.collapse(!0),i.removeAllRanges(),i.addRange(a)}else if(s.current)s.current.innerText+=n}Pe()},xt=(e)=>{if(e.nativeEvent.isComposing)return;if(se&&z&&te.length>0){if(e.key==="ArrowUp"){e.preventDefault(),W((n)=>n>0?n-1:te.length-1);return}if(e.key==="ArrowDown"){e.preventDefault(),W((n)=>n<te.length-1?n+1:0);return}if(e.key==="Enter"||e.key==="Tab"){e.preventDefault(),de(te[q]);return}if(e.key==="Escape"){e.preventDefault(),k(!1);return}}if(e.key==="Enter"&&!e.shiftKey)e.preventDefault(),_e()},vt=P(async(e)=>{if(!e.target.files)return;let n=Array.from(e.target.files);for(let r of n){let l=`${Date.now()}-${r.name}`,i={id:l,file:r,progress:0};U((a)=>[...a,i]);try{let a=await De({projectId:y,data:{fileName:r.name,contentType:r.type,size:r.size}});if(a.uploadUrl&&a.id)await fetch(a.uploadUrl,{method:"PUT",body:r,headers:{"Content-Type":r.type}}),U((c)=>c.map((m)=>m.id===l?{...m,progress:100,attachmentId:a.id}:m))}catch(a){U((c)=>c.map((m)=>m.id===l?{...m,error:a instanceof Error?a.message:"Upload failed"}:m))}}if(Z.current)Z.current.value=""},[y,De]),yt=(e)=>{U((n)=>n.filter((r)=>r.id!==e))},_e=()=>{if(!s.current)return;if(g.some((a)=>!a.attachmentId&&!a.error))return;let n=g.map((a)=>a.attachmentId).filter((a)=>!!a),r=g.filter((a)=>!a.error&&!!a.attachmentId).map((a)=>({id:a.attachmentId,name:a.file.name,type:a.file.type,url:a.file.type.startsWith("image/")||js(a.file.name)?URL.createObjectURL(a.file):void 0})),l="";s.current.childNodes.forEach((a)=>{if(a.nodeType===Node.TEXT_NODE)l+=a.textContent;else if(a.nodeType===Node.ELEMENT_NODE){let c=a;if(c.dataset.type==="mention")l+=`<@${c.dataset.id}>`;else if(c.tagName==="BR")l+=`
2
2
  `;else if(c.tagName==="DIV"||c.tagName==="P")l+=`
3
3
  `+c.innerText;else l+=c.innerText}}),l=l.trim();let i=(w?.length??0)>0;if(!l&&n.length===0&&ae.length===0&&!i)return;if(He(l,n,ae,d?.id,j&&x?p:void 0,r),s.current.innerHTML="",C(!1),R.current=!0,_?.(""),U([]),X(null),H(!1),Me(),k(!1),ne)ne()},ue=g.some((e)=>!e.attachmentId&&!e.error),wt=g.some((e)=>!!e.attachmentId),Nt=(w?.length??0)>0,kt=fe||oe,Fe=(ie||wt||ae.length>0||Nt)&&!kt,Ct=w&&w.length>0||g.length>0||!!d;return o("div",{ref:et,className:"relative flex flex-col w-full border border-foreground/35 rounded-3xl shadow-sm transition-all duration-200 bg-background",children:[t("style",{children:`
4
4
  [contenteditable]:empty:before {
@@ -6,5 +6,5 @@ import{O,P,h,D,b,u,S,L,t,o,B,A,I,Wa,ve,Xt,er,Ii,we,Re,E,fn,pn,mn,hn,Ce,Ie,Te,Y0,
6
6
  color: #9ca3af;
7
7
  cursor: text;
8
8
  }
9
- `}),se&&z&&(ye||K.length>0||ee.length>0)&&t("div",{onMouseDown:(e)=>e.preventDefault(),className:"absolute bottom-full left-4 mb-2 w-64 rounded-xl shadow-lg border border-border overflow-hidden z-20 bg-popover text-popover-foreground animate-in fade-in slide-in-from-bottom-2 duration-200",children:t("div",{ref:Ee,className:"h-64 overflow-y-auto",children:ye?o("div",{className:"p-2 space-y-4 animate-pulse",children:[o("div",{className:"space-y-2",children:[t("div",{className:"px-3 py-1.5 bg-muted/50 border-b border-border",children:t(pe,{className:"h-3 w-16"})}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-28"})]}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-20"})]})]}),o("div",{className:"space-y-2",children:[t("div",{className:"px-3 py-1.5 bg-muted/50 border-b border-border",children:t(pe,{className:"h-3 w-16"})}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-32"})]}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-24"})]})]})]}):o(L,{children:[K.length>0&&o(L,{children:[o("button",{type:"button",onMouseDown:(e)=>e.preventDefault(),onClick:(e)=>{e.preventDefault(),e.stopPropagation(),Ae((n)=>({...n,bots:!n.bots})),s.current?.focus()},className:"w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border flex items-center justify-between hover:bg-muted transition-colors cursor-pointer select-none",children:[t("span",{children:"Agents"}),t(ve,{className:`w-3 h-3 transition-transform ${v.bots?"-rotate-90":""}`})]}),!v.bots&&K.map((e,n)=>{let r=n;return o("button",{type:"button","data-index":r,onMouseDown:(l)=>l.preventDefault(),onClick:()=>de(e),onMouseEnter:()=>W(r),className:`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left cursor-pointer ${r===q?"bg-accent text-accent-foreground":"hover:bg-accent/50"}`,children:[o(Ce,{className:"w-6 h-6",children:[e.type==="user"&&e.data.image&&t(Ie,{src:e.data.image,alt:e.data.name,className:"object-cover"}),t(Te,{className:"text-[10px] bg-purple-400 text-black font-semibold",children:Se(e.data.name)})]}),t("span",{className:"text-sm",children:e.data.name})]},e.data.id)})]}),ee.length>0&&o(L,{children:[o("button",{type:"button",onMouseDown:(e)=>e.preventDefault(),onClick:(e)=>{e.preventDefault(),e.stopPropagation(),Ae((n)=>({...n,users:!n.users})),s.current?.focus()},className:"w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border flex items-center justify-between hover:bg-muted transition-colors cursor-pointer select-none",children:[t("span",{children:"Members"}),t(ve,{className:`w-3 h-3 transition-transform ${v.users?"-rotate-90":""}`})]}),!v.users&&ee.map((e,n)=>{let r=v.bots?0:K.length,l=n+r;return o("button",{type:"button","data-index":l,onMouseDown:(i)=>i.preventDefault(),onClick:()=>de(e),onMouseEnter:()=>W(l),className:`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left cursor-pointer ${l===q?"bg-accent text-accent-foreground":"hover:bg-accent/50"}`,children:[o(Ce,{className:"w-6 h-6",children:[e.type==="user"&&e.data.image&&t(Ie,{src:e.data.image,alt:e.data.name,className:"object-cover"}),t(Te,{className:"text-[10px] bg-purple-400 text-black font-semibold",children:Se(e.data.name)})]}),t("span",{className:"text-sm",children:e.data.name})]},e.data.id)})]})]})})}),Ct&&o("div",{className:"flex flex-col gap-2 p-3 pb-0 animate-in fade-in slide-in-from-bottom-2 duration-200",children:[w&&w.length>0&&t("div",{className:"flex flex-col gap-1.5 min-h-0 max-h-[160px] overflow-y-auto border border-border/60 rounded-lg bg-muted/20 p-2.5 divide-y divide-border/50",children:w.map((e)=>o("div",{className:"flex items-center justify-between py-1 text-xs group",children:[o("div",{className:"flex items-baseline gap-1.5 min-w-0 pr-2",children:[t("span",{className:"truncate font-medium text-foreground",children:e.name}),t("span",{className:"text-[9px] text-muted-foreground uppercase flex-shrink-0",children:e.type})]}),ge&&t("button",{onClick:()=>ge(e.id),className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",title:UE?.()||"Remove from context",children:t(we,{className:"h-3.5 w-3.5"})})]},e.id))}),d&&o("div",{className:"flex items-center justify-between bg-muted p-2 px-3 rounded-lg border border-border",children:[t("div",{className:"text-xs text-muted-foreground truncate mr-2",children:VE({message:d.message||""})}),t("button",{onClick:ne,className:"text-muted-foreground hover:text-foreground p-1 rounded-full hover:bg-muted-foreground/10 shrink-0",children:t(Re,{className:"w-3.5 h-3.5"})})]}),g.length>0&&t("div",{className:"flex gap-3 overflow-x-auto py-2 px-1 scrollbar-hide",children:g.map((e)=>o("div",{className:"relative group flex-shrink-0",children:[o("div",{className:"w-16 h-16 rounded-lg border border-gray-200 overflow-hidden bg-gray-50 flex items-center justify-center",children:[e.file.type.startsWith("image/")?t("img",{src:URL.createObjectURL(e.file),alt:"preview",onClick:()=>X(e.file),className:`w-full h-full object-cover ${!e.attachmentId?"opacity-50":""}`}):t(er,{className:"w-8 h-8 text-gray-400"}),ue&&!e.attachmentId&&!e.error&&t("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:t(ci,{progress:e.progress,className:"w-10 h-10"})})]}),t("button",{onClick:()=>yt(e.id),className:"absolute -top-1.5 -right-1.5 bg-gray-500 text-white rounded-full p-0.5 shadow-md opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500 z-10 cursor-pointer",children:t(Re,{className:"w-3 h-3"})}),t("span",{className:"text-[10px] text-gray-500 mt-1 block max-w-[4rem] truncate text-center",children:e.file.name})]},e.id))})]}),o("div",{onClick:()=>s.current?.focus(),className:"w-full px-4 pt-1 pb-1 cursor-text flow-root max-h-60 overflow-y-auto",children:[j&&x&&p!==void 0&&(f!==void 0||N!==void 0)&&t("div",{onClick:(e)=>{e.stopPropagation(),s.current?.focus()},className:"float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-0.5 mt-3 mr-2 rounded-sm text-xs font-mono font-bold flex items-center gap-1 cursor-text",children:ot}),t("div",{ref:s,contentEditable:!fe&&!oe,suppressContentEditableWarning:!0,onInput:Pe,onKeyDown:xt,onPaste:bt,"data-placeholder":Oe||(d?GE():Vw()),className:`bg-transparent border-none focus:ring-0 resize-none min-h-[40px] leading-relaxed py-2 focus:outline-none block whitespace-pre-wrap break-words ${ft}`})]}),o("div",{className:"flex justify-between items-center px-2 pb-2",children:[st?o("div",{className:"flex items-center gap-2 overflow-x-auto scrollbar-hide w-full mr-2",children:[t(E,{onClick:()=>{H(!1),Me()},variant:"ghost",size:"icon",className:"p-2 rounded-full cursor-pointer text-gray-500 hover:text-gray-700 hover:bg-gray-100 mr-2",title:"Back",children:t(du,{className:"w-4 h-4"})}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),t("button",{onClick:()=>Y("arrow"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="arrow"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Arrow",children:t(Wa,{size:16,className:"rotate-45"})}),t("button",{onClick:()=>Y("line"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="line"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Line",children:t(Hs,{size:16,className:"-rotate-45"})}),t("button",{onClick:()=>Y("box"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="box"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Box",children:t($e,{size:16})}),t("button",{onClick:()=>Y("freehand"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="freehand"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Freehand",children:t(ze,{size:16})}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),o(mt,{children:[t(ht,{asChild:!0,children:o("button",{className:"flex items-center gap-1 p-1 rounded hover:bg-gray-100",children:[t("div",{className:"w-4 h-4 rounded-full border border-gray-200",style:{backgroundColor:Ne}}),t(ve,{size:12,className:"text-gray-500"})]})}),t(gt,{className:"w-auto p-2",align:"center",side:"top",children:t("div",{className:"flex items-center gap-1",children:Tt.map((e)=>t("button",{onClick:()=>it(e),className:`w-6 h-6 rounded-full border border-gray-200 transition-transform hover:scale-110 ${Ne===e?"ring-2 ring-blue-500 ring-offset-1":""}`,style:{backgroundColor:e}},e))})})]}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),t("button",{onClick:ct,disabled:ke<=0,className:"p-1.5 rounded hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-500",children:t(Be,{size:16})}),t("button",{onClick:dt,disabled:ke>=ut.length-1,className:"p-1.5 rounded hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-500",children:t(je,{size:16})})]}):o("div",{className:"flex items-center gap-1.5 min-w-0 max-w-[80%]",children:[Ye,Ke&&o(L,{children:[t("input",{type:"file",ref:Z,className:"hidden",multiple:!0,onChange:vt}),t(E,{onClick:()=>Z.current?.click(),className:"p-2 rounded-full cursor-pointer shrink-0",variant:"ghost",size:"icon",title:Y0(),children:t(Ii,{className:"w-4 h-4"})})]}),j&&p!==void 0&&(f!==void 0||N!==void 0)&&t(E,{onClick:()=>tt(!x),variant:x?"secondary":"ghost",size:"icon",className:`p-2 rounded-full cursor-pointer shrink-0 ${x?"text-blue-600 bg-blue-50 dark:bg-blue-900/20":""}`,title:x?$y():lb(),children:t(Xt,{className:"w-4 h-4"})}),nt&&(Qe?t(E,{onClick:()=>{F?.(),H(!0)},variant:"ghost",size:"icon",className:"p-2 rounded-full cursor-pointer shrink-0",title:q1(),children:t(_a,{className:"w-4 h-4"})}):t(fn,{children:o(pn,{children:[t(mn,{asChild:!0,children:t("span",{className:"inline-block cursor-not-allowed shrink-0",children:t(E,{disabled:!0,variant:"ghost",size:"icon",className:"p-2 rounded-full opacity-40 cursor-not-allowed pointer-events-none",children:t(_a,{className:"w-4 h-4"})})})}),t(hn,{side:"top",children:t("p",{className:"text-xs",children:Ge||Gf()})})]})}))]}),oe?t("button",{onClick:Ze,className:"p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 shadow-sm bg-destructive text-destructive-foreground hover:bg-destructive/90 transform hover:-translate-y-0.5 cursor-pointer",title:"Stop generation",children:t("div",{className:"h-4 w-4 flex items-center justify-center",children:t("div",{className:"h-3 w-3 rounded-[2px] bg-white"})})}):t("button",{onClick:_e,disabled:!Fe||ue,className:`p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 ${Fe&&!ue?"bg-blue-600 text-white shadow-md hover:bg-blue-700 hover:shadow-lg transform hover:-translate-y-0.5 cursor-pointer":"bg-gray-400 cursor-not-allowed opacity-50"}`,children:t(Wa,{className:"w-4 h-4"})})]}),re&&o("div",{className:"fixed inset-0 z-[100] bg-black/95 flex flex-col items-center justify-center p-4 animate-in fade-in duration-200",onClick:()=>X(null),children:[t("button",{className:"absolute top-4 right-4 text-white/70 hover:text-white hover:bg-white/20 rounded-full p-2 transition-colors z-50",children:t(Re,{className:"w-8 h-8"})}),t("div",{className:"w-full h-full flex items-center justify-center p-2",children:t("img",{src:URL.createObjectURL(re),alt:"Enlarged view",className:"max-w-full max-h-[85vh] object-contain rounded shadow-2xl cursor-zoom-out",onClick:(e)=>{e.stopPropagation(),X(null)}})}),t("div",{className:"absolute bottom-6 text-white text-sm font-medium bg-black/50 px-4 py-2 rounded-full backdrop-blur-sm",children:re.name})]})]})});qs.displayName="ChatInput";
10
- export{du,qs};
9
+ `}),se&&z&&(ye||K.length>0||ee.length>0)&&t("div",{onMouseDown:(e)=>e.preventDefault(),className:"absolute bottom-full left-4 mb-2 w-64 rounded-xl shadow-lg border border-border overflow-hidden z-20 bg-popover text-popover-foreground animate-in fade-in slide-in-from-bottom-2 duration-200",children:t("div",{ref:Ee,className:"h-64 overflow-y-auto",children:ye?o("div",{className:"p-2 space-y-4 animate-pulse",children:[o("div",{className:"space-y-2",children:[t("div",{className:"px-3 py-1.5 bg-muted/50 border-b border-border",children:t(pe,{className:"h-3 w-16"})}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-28"})]}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-20"})]})]}),o("div",{className:"space-y-2",children:[t("div",{className:"px-3 py-1.5 bg-muted/50 border-b border-border",children:t(pe,{className:"h-3 w-16"})}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-32"})]}),o("div",{className:"flex items-center gap-2 px-3 py-2",children:[t(pe,{className:"w-6 h-6 rounded-full"}),t(pe,{className:"h-4 w-24"})]})]})]}):o(L,{children:[K.length>0&&o(L,{children:[o("button",{type:"button",onMouseDown:(e)=>e.preventDefault(),onClick:(e)=>{e.preventDefault(),e.stopPropagation(),Ae((n)=>({...n,bots:!n.bots})),s.current?.focus()},className:"w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border flex items-center justify-between hover:bg-muted transition-colors cursor-pointer select-none",children:[t("span",{children:"Agents"}),t(ve,{className:`w-3 h-3 transition-transform ${v.bots?"-rotate-90":""}`})]}),!v.bots&&K.map((e,n)=>{let r=n;return o("button",{type:"button","data-index":r,onMouseDown:(l)=>l.preventDefault(),onClick:()=>de(e),onMouseEnter:()=>W(r),className:`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left cursor-pointer ${r===q?"bg-accent text-accent-foreground":"hover:bg-accent/50"}`,children:[o(Ce,{className:"w-6 h-6",children:[e.type==="user"&&e.data.image&&t(Ie,{src:e.data.image,alt:e.data.name,className:"object-cover"}),t(Te,{className:"text-[10px] bg-purple-400 text-black font-semibold",children:Se(e.data.name)})]}),t("span",{className:"text-sm",children:e.data.name})]},e.data.id)})]}),ee.length>0&&o(L,{children:[o("button",{type:"button",onMouseDown:(e)=>e.preventDefault(),onClick:(e)=>{e.preventDefault(),e.stopPropagation(),Ae((n)=>({...n,users:!n.users})),s.current?.focus()},className:"w-full text-xs font-semibold text-muted-foreground px-3 py-2 bg-muted/50 border-b border-border flex items-center justify-between hover:bg-muted transition-colors cursor-pointer select-none",children:[t("span",{children:"Members"}),t(ve,{className:`w-3 h-3 transition-transform ${v.users?"-rotate-90":""}`})]}),!v.users&&ee.map((e,n)=>{let r=v.bots?0:K.length,l=n+r;return o("button",{type:"button","data-index":l,onMouseDown:(i)=>i.preventDefault(),onClick:()=>de(e),onMouseEnter:()=>W(l),className:`w-full flex items-center gap-2 px-3 py-2 transition-colors text-left cursor-pointer ${l===q?"bg-accent text-accent-foreground":"hover:bg-accent/50"}`,children:[o(Ce,{className:"w-6 h-6",children:[e.type==="user"&&e.data.image&&t(Ie,{src:e.data.image,alt:e.data.name,className:"object-cover"}),t(Te,{className:"text-[10px] bg-purple-400 text-black font-semibold",children:Se(e.data.name)})]}),t("span",{className:"text-sm",children:e.data.name})]},e.data.id)})]})]})})}),Ct&&o("div",{className:"flex flex-col gap-2 p-3 pb-0 animate-in fade-in slide-in-from-bottom-2 duration-200",children:[w&&w.length>0&&t("div",{className:"flex flex-col gap-1.5 min-h-0 max-h-[160px] overflow-y-auto border border-border/60 rounded-lg bg-muted/20 p-2.5 divide-y divide-border/50",children:w.map((e)=>o("div",{className:"flex items-center justify-between py-1 text-xs group",children:[o("div",{className:"flex items-baseline gap-1.5 min-w-0 pr-2",children:[t("span",{className:"truncate font-medium text-foreground",children:e.name}),t("span",{className:"text-[9px] text-muted-foreground uppercase flex-shrink-0",children:e.type})]}),ge&&t("button",{onClick:()=>ge(e.id),className:"text-muted-foreground hover:text-destructive transition-colors p-0.5 cursor-pointer",title:zE?.()||"Remove from context",children:t(we,{className:"h-3.5 w-3.5"})})]},e.id))}),d&&o("div",{className:"flex items-center justify-between bg-muted p-2 px-3 rounded-lg border border-border",children:[t("div",{className:"text-xs text-muted-foreground truncate mr-2",children:QE({message:d.message||""})}),t("button",{onClick:ne,className:"text-muted-foreground hover:text-foreground p-1 rounded-full hover:bg-muted-foreground/10 shrink-0",children:t(Re,{className:"w-3.5 h-3.5"})})]}),g.length>0&&t("div",{className:"flex gap-3 overflow-x-auto py-2 px-1 scrollbar-hide",children:g.map((e)=>o("div",{className:"relative group flex-shrink-0",children:[o("div",{className:"w-16 h-16 rounded-lg border border-gray-200 overflow-hidden bg-gray-50 flex items-center justify-center",children:[e.file.type.startsWith("image/")?t("img",{src:URL.createObjectURL(e.file),alt:"preview",onClick:()=>X(e.file),className:`w-full h-full object-cover ${!e.attachmentId?"opacity-50":""}`}):t(er,{className:"w-8 h-8 text-gray-400"}),ue&&!e.attachmentId&&!e.error&&t("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:t(ci,{progress:e.progress,className:"w-10 h-10"})})]}),t("button",{onClick:()=>yt(e.id),className:"absolute -top-1.5 -right-1.5 bg-gray-500 text-white rounded-full p-0.5 shadow-md opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500 z-10 cursor-pointer",children:t(Re,{className:"w-3 h-3"})}),t("span",{className:"text-[10px] text-gray-500 mt-1 block max-w-[4rem] truncate text-center",children:e.file.name})]},e.id))})]}),o("div",{onClick:()=>s.current?.focus(),className:"w-full px-4 pt-1 pb-1 cursor-text flow-root max-h-60 overflow-y-auto",children:[j&&x&&p!==void 0&&(f!==void 0||N!==void 0)&&t("div",{onClick:(e)=>{e.stopPropagation(),s.current?.focus()},className:"float-left select-none bg-blue-100 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 px-2.5 py-0.5 mt-3 mr-2 rounded-sm text-xs font-mono font-bold flex items-center gap-1 cursor-text",children:ot}),t("div",{ref:s,contentEditable:!fe&&!oe,suppressContentEditableWarning:!0,onInput:Pe,onKeyDown:xt,onPaste:bt,"data-placeholder":Oe||(d?VE():Qw()),className:`bg-transparent border-none focus:ring-0 resize-none min-h-[40px] leading-relaxed py-2 focus:outline-none block whitespace-pre-wrap break-words ${ft}`})]}),o("div",{className:"flex justify-between items-center px-2 pb-2",children:[st?o("div",{className:"flex items-center gap-2 overflow-x-auto scrollbar-hide w-full mr-2",children:[t(E,{onClick:()=>{H(!1),Me()},variant:"ghost",size:"icon",className:"p-2 rounded-full cursor-pointer text-gray-500 hover:text-gray-700 hover:bg-gray-100 mr-2",title:"Back",children:t(fu,{className:"w-4 h-4"})}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),t("button",{onClick:()=>Y("arrow"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="arrow"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Arrow",children:t(Wa,{size:16,className:"rotate-45"})}),t("button",{onClick:()=>Y("line"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="line"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Line",children:t(Hs,{size:16,className:"-rotate-45"})}),t("button",{onClick:()=>Y("box"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="box"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Box",children:t($e,{size:16})}),t("button",{onClick:()=>Y("freehand"),className:`p-1.5 rounded hover:bg-gray-100 ${J==="freehand"?"text-blue-500 bg-blue-50":"text-gray-500"}`,title:"Freehand",children:t(ze,{size:16})}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),o(mt,{children:[t(ht,{asChild:!0,children:o("button",{className:"flex items-center gap-1 p-1 rounded hover:bg-gray-100",children:[t("div",{className:"w-4 h-4 rounded-full border border-gray-200",style:{backgroundColor:Ne}}),t(ve,{size:12,className:"text-gray-500"})]})}),t(gt,{className:"w-auto p-2",align:"center",side:"top",children:t("div",{className:"flex items-center gap-1",children:Tt.map((e)=>t("button",{onClick:()=>it(e),className:`w-6 h-6 rounded-full border border-gray-200 transition-transform hover:scale-110 ${Ne===e?"ring-2 ring-blue-500 ring-offset-1":""}`,style:{backgroundColor:e}},e))})})]}),t("div",{className:"h-4 w-px bg-gray-300 mx-1"}),t("button",{onClick:ct,disabled:ke<=0,className:"p-1.5 rounded hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-500",children:t(Be,{size:16})}),t("button",{onClick:dt,disabled:ke>=ut.length-1,className:"p-1.5 rounded hover:bg-gray-100 disabled:opacity-30 disabled:cursor-not-allowed text-gray-500",children:t(je,{size:16})})]}):o("div",{className:"flex items-center gap-1.5 min-w-0 max-w-[80%]",children:[Ye,Ke&&o(L,{children:[t("input",{type:"file",ref:Z,className:"hidden",multiple:!0,onChange:vt}),t(E,{onClick:()=>Z.current?.click(),className:"p-2 rounded-full cursor-pointer shrink-0",variant:"ghost",size:"icon",title:J0(),children:t(Ii,{className:"w-4 h-4"})})]}),j&&p!==void 0&&(f!==void 0||N!==void 0)&&t(E,{onClick:()=>tt(!x),variant:x?"secondary":"ghost",size:"icon",className:`p-2 rounded-full cursor-pointer shrink-0 ${x?"text-blue-600 bg-blue-50 dark:bg-blue-900/20":""}`,title:x?Gy():cb(),children:t(Xt,{className:"w-4 h-4"})}),nt&&(Qe?t(E,{onClick:()=>{F?.(),H(!0)},variant:"ghost",size:"icon",className:"p-2 rounded-full cursor-pointer shrink-0",title:H1(),children:t(_a,{className:"w-4 h-4"})}):t(fn,{children:o(pn,{children:[t(mn,{asChild:!0,children:t("span",{className:"inline-block cursor-not-allowed shrink-0",children:t(E,{disabled:!0,variant:"ghost",size:"icon",className:"p-2 rounded-full opacity-40 cursor-not-allowed pointer-events-none",children:t(_a,{className:"w-4 h-4"})})})}),t(hn,{side:"top",children:t("p",{className:"text-xs",children:Ge||Vf()})})]})}))]}),oe?t("button",{onClick:Ze,className:"p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 shadow-sm bg-destructive text-destructive-foreground hover:bg-destructive/90 transform hover:-translate-y-0.5 cursor-pointer",title:"Stop generation",children:t("div",{className:"h-4 w-4 flex items-center justify-center",children:t("div",{className:"h-3 w-3 rounded-[2px] bg-white"})})}):t("button",{onClick:_e,disabled:!Fe||ue,className:`p-2 rounded-full transition-all duration-200 flex items-center justify-center shrink-0 ${Fe&&!ue?"bg-blue-600 text-white shadow-md hover:bg-blue-700 hover:shadow-lg transform hover:-translate-y-0.5 cursor-pointer":"bg-gray-400 cursor-not-allowed opacity-50"}`,children:t(Wa,{className:"w-4 h-4"})})]}),re&&o("div",{className:"fixed inset-0 z-[100] bg-black/95 flex flex-col items-center justify-center p-4 animate-in fade-in duration-200",onClick:()=>X(null),children:[t("button",{className:"absolute top-4 right-4 text-white/70 hover:text-white hover:bg-white/20 rounded-full p-2 transition-colors z-50",children:t(Re,{className:"w-8 h-8"})}),t("div",{className:"w-full h-full flex items-center justify-center p-2",children:t("img",{src:URL.createObjectURL(re),alt:"Enlarged view",className:"max-w-full max-h-[85vh] object-contain rounded shadow-2xl cursor-zoom-out",onClick:(e)=>{e.stopPropagation(),X(null)}})}),t("div",{className:"absolute bottom-6 text-white text-sm font-medium bg-black/50 px-4 py-2 rounded-full backdrop-blur-sm",children:re.name})]})]})});qs.displayName="ChatInput";
10
+ export{fu,qs};