@shumai-one/shumai 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/bin/{chunk-2xgvs3as.js → chunk-07h4b77v.js} +2 -2
  2. package/bin/{chunk-gazp5662.js → chunk-0t4n4d5w.js} +2 -2
  3. package/bin/{chunk-x9akgj7w.js → chunk-1611z9jg.js} +2 -2
  4. package/bin/{chunk-kvnfgr29.js → chunk-1phqxp6z.js} +1 -1
  5. package/bin/chunk-23hckrrz.js +2 -0
  6. package/bin/{chunk-ymr5ybxk.js → chunk-30z44j1g.js} +2 -2
  7. package/bin/{chunk-fcsfssar.js → chunk-3j463k1g.js} +1 -1
  8. package/bin/{chunk-zye42cfp.js → chunk-4181tdds.js} +1 -1
  9. package/bin/chunk-480jtqng.js +4 -0
  10. package/bin/{chunk-m8z8jvdq.js → chunk-4c3g146q.js} +2 -2
  11. package/bin/chunk-4ca0zt5e.js +1 -0
  12. package/bin/chunk-4d9bgmf2.js +2 -0
  13. package/bin/{chunk-fvbd5dk7.js → chunk-4ev56fss.js} +5 -5
  14. package/bin/{chunk-zmyawgth.js → chunk-4gk52tjq.js} +1 -1
  15. package/bin/chunk-4mdqkj4d.js +1 -0
  16. package/bin/{chunk-mhps85dd.js → chunk-4r91fggc.js} +1 -1
  17. package/bin/chunk-50fb1x3w.js +1 -0
  18. package/bin/chunk-59gj1njz.js +1 -0
  19. package/bin/{chunk-j04sztp3.js → chunk-5pr0t7fb.js} +1 -1
  20. package/bin/chunk-5vewxmz7.js +3 -0
  21. package/bin/chunk-62zx96pe.js +2 -0
  22. package/bin/chunk-63y0eb07.js +2 -0
  23. package/bin/chunk-6d5xrgfx.js +2 -0
  24. package/bin/{chunk-etprs58p.js → chunk-6gbtz5bf.js} +2 -2
  25. package/bin/{chunk-wrgwjg2g.js → chunk-6gjg5egq.js} +1 -1
  26. package/bin/{chunk-4q782s34.js → chunk-6m4jz9s1.js} +3 -3
  27. package/bin/{chunk-wehhpcm1.js → chunk-6s4x525w.js} +1 -1
  28. package/bin/{chunk-xzag8w1v.js → chunk-6w2wmvqs.js} +1 -1
  29. package/bin/{chunk-r2shjtte.js → chunk-77d23vcn.js} +2 -2
  30. package/bin/{chunk-vhcqazqf.js → chunk-77m5p188.js} +2 -2
  31. package/bin/chunk-7bvx087f.js +1 -0
  32. package/bin/chunk-7pfjfrjg.js +5 -0
  33. package/bin/{chunk-1qr0ajc8.js → chunk-7q10s127.js} +1 -1
  34. package/bin/{chunk-c3msq02x.js → chunk-7thx8ctx.js} +2 -2
  35. package/bin/{chunk-vvhs586e.js → chunk-8t4s91gh.js} +1 -1
  36. package/bin/{chunk-k3r97v7j.js → chunk-98ey5p2e.js} +1 -1
  37. package/bin/{chunk-44edgqvy.js → chunk-9amndcyh.js} +3 -3
  38. package/bin/chunk-9bk23g9x.js +1 -0
  39. package/bin/chunk-9mkcfy43.js +1 -0
  40. package/bin/{chunk-0h8rjeyj.js → chunk-9t3nsq5n.js} +2 -2
  41. package/bin/{chunk-j536e9nx.js → chunk-9tjq99ds.js} +2 -2
  42. package/bin/chunk-9wm9rwh1.js +2 -0
  43. package/bin/{chunk-nz2v1jmd.js → chunk-ab16fyg4.js} +2 -2
  44. package/bin/chunk-arv0g2av.js +1 -0
  45. package/bin/{chunk-hx2mvd20.js → chunk-aytj4zxg.js} +2 -2
  46. package/bin/{chunk-02afmyqy.js → chunk-b1ypjqgp.js} +2 -2
  47. package/bin/{chunk-93ecxcy4.js → chunk-bdjv0ykq.js} +1 -1
  48. package/bin/chunk-c1k86mfa.js +10 -0
  49. package/bin/{chunk-wy2f6mby.js → chunk-caa96dgd.js} +1 -1
  50. package/bin/chunk-ce4v2yjy.js +1 -0
  51. package/bin/{chunk-m2tbft2c.js → chunk-cqh60y54.js} +2 -2
  52. package/bin/chunk-cvq7zgw7.js +1 -0
  53. package/bin/{chunk-tcm57j8r.js → chunk-d9mjbtp2.js} +2 -2
  54. package/bin/{chunk-xkhwj8mw.js → chunk-dn7sbjws.js} +2 -2
  55. package/bin/{chunk-p49h5fxs.js → chunk-dxyq9h8n.js} +1 -1
  56. package/bin/{chunk-3twtxs5m.js → chunk-e3cabksx.js} +1 -1
  57. package/bin/{chunk-52dr035y.js → chunk-egcrbj94.js} +2 -2
  58. package/bin/chunk-ev17v1mv.js +2 -0
  59. package/bin/chunk-evtpwg71.js +2 -0
  60. package/bin/{chunk-2rbexbv0.js → chunk-f3e0nsv2.js} +1 -1
  61. package/bin/chunk-f40gjqpq.js +2 -0
  62. package/bin/chunk-fe7822ak.js +299 -0
  63. package/bin/{chunk-4b7jcpgv.js → chunk-g8tkhw9j.js} +2 -2
  64. package/bin/{chunk-mgnxa0vy.js → chunk-g9r0p4t8.js} +1 -1
  65. package/bin/chunk-gbjyh9ms.js +1 -0
  66. package/bin/{chunk-thbfw1ed.js → chunk-gtbsb39v.js} +1 -1
  67. package/bin/{chunk-zh752hw8.js → chunk-gytz1q13.js} +1 -1
  68. package/bin/chunk-h0fxysxs.js +7 -0
  69. package/bin/{chunk-aw5zkdma.js → chunk-h8bdvsqt.js} +2 -2
  70. package/bin/{chunk-76433x4d.js → chunk-hag024w8.js} +2 -2
  71. package/bin/chunk-hc6w5nw4.js +7 -0
  72. package/bin/chunk-j69dqc48.js +2 -0
  73. package/bin/{chunk-yfqz6f72.js → chunk-jbtw1zym.js} +1 -1
  74. package/bin/{chunk-9k76s3y6.js → chunk-jc1vb7rj.js} +2 -2
  75. package/bin/{chunk-41d9gkx7.js → chunk-jdv78w9r.js} +1 -1
  76. package/bin/{chunk-dag45evp.js → chunk-jjs70y9v.js} +1 -1
  77. package/bin/{chunk-ysvhtgve.js → chunk-jmdar2gz.js} +2 -2
  78. package/bin/chunk-jvwz10n4.js +2 -0
  79. package/bin/{chunk-ck6msfch.js → chunk-k47md1g4.js} +2 -2
  80. package/bin/{chunk-yyjx8nbq.js → chunk-k4v0brcb.js} +1 -1
  81. package/bin/chunk-k6n7c07e.js +1 -0
  82. package/bin/{chunk-kjjhvrk1.js → chunk-kk2cstsg.js} +1 -1
  83. package/bin/{chunk-3r33kewe.js → chunk-knz4h56q.js} +3 -3
  84. package/bin/{chunk-j5rx3x1q.js → chunk-kqqtt6bd.js} +1 -1
  85. package/bin/{chunk-ez6veng7.js → chunk-kvyp1t4j.js} +1 -1
  86. package/bin/{chunk-djx2r4nj.js → chunk-kxskpgsq.js} +2 -2
  87. package/bin/{chunk-3gjn4pyp.js → chunk-m6srbjcs.js} +2 -2
  88. package/bin/{chunk-8956rryj.js → chunk-mcc1scxs.js} +2 -2
  89. package/bin/{chunk-0bfqrx5q.js → chunk-mq83a0kk.js} +2 -2
  90. package/bin/chunk-mxm8g4q0.js +1 -0
  91. package/bin/{chunk-6m1k317a.js → chunk-nhpgdqq5.js} +2 -2
  92. package/bin/{chunk-pdjar480.js → chunk-nne496aa.js} +2 -2
  93. package/bin/{chunk-s73c0brj.js → chunk-nqpb0r9h.js} +1 -1
  94. package/bin/chunk-ns0zww9g.js +2 -0
  95. package/bin/{chunk-9cmvymm5.js → chunk-ps4xfp23.js} +1 -1
  96. package/bin/chunk-pz2ec6xt.js +2 -0
  97. package/bin/{chunk-vkgxrn1h.js → chunk-q163k309.js} +2 -2
  98. package/bin/chunk-q1da61ps.js +1 -0
  99. package/bin/{chunk-7x1vkftb.js → chunk-qrf0ady6.js} +2 -2
  100. package/bin/{chunk-d7en47eh.js → chunk-qy28f25e.js} +1 -1
  101. package/bin/{chunk-xjnghr99.js → chunk-r7s4ypw1.js} +1 -1
  102. package/bin/chunk-ran23vm9.js +1 -0
  103. package/bin/chunk-rfvdc4n0.js +2 -0
  104. package/bin/{chunk-8rcfhfq5.js → chunk-rgthkvgx.js} +1 -1
  105. package/bin/chunk-s39n3yw3.js +2 -0
  106. package/bin/{chunk-xv5h4dv1.js → chunk-s7wdd0g7.js} +1 -1
  107. package/bin/{chunk-n8gsjwht.js → chunk-s88ha5kx.js} +2 -2
  108. package/bin/chunk-sf91bt9m.js +2 -0
  109. package/bin/{chunk-2x46963w.js → chunk-sjwbjf9j.js} +1 -1
  110. package/bin/chunk-t62076pv.js +1 -0
  111. package/bin/{chunk-he1ywtxx.js → chunk-tbbwss3v.js} +1 -1
  112. package/bin/{chunk-06spnkta.js → chunk-tjcc7a6y.js} +1 -1
  113. package/bin/{chunk-qac5hr5h.js → chunk-tp6ab26e.js} +1 -1
  114. package/bin/{chunk-md12a1sf.js → chunk-v2wxk9p5.js} +2 -2
  115. package/bin/chunk-vbk6y4hk.js +2 -0
  116. package/bin/{chunk-vcf2qk9h.js → chunk-vfgfg5fk.js} +2 -2
  117. package/bin/{chunk-gjnrd32m.js → chunk-vm6c3xx9.js} +2 -2
  118. package/bin/{chunk-agabtxrc.js → chunk-vsx96mt6.js} +1 -1
  119. package/bin/{chunk-et0cewj7.js → chunk-wbyw1shz.js} +2 -2
  120. package/bin/chunk-whh2vh50.css +1 -0
  121. package/bin/{chunk-792t2653.js → chunk-wjkcq65s.js} +2 -2
  122. package/bin/{chunk-5yhn31rd.js → chunk-wkefwkfp.js} +1 -1
  123. package/bin/{chunk-gcc6pte2.js → chunk-x7bsnk1e.js} +2 -2
  124. package/bin/{chunk-tn67sjb2.js → chunk-xbhw6bpz.js} +2 -2
  125. package/bin/{chunk-34kaja59.js → chunk-xg5yrcj5.js} +2 -2
  126. package/bin/{chunk-wzmpvadf.js → chunk-xw2gpcsh.js} +1 -1
  127. package/bin/{chunk-sx6y697s.js → chunk-ycq8ank7.js} +1 -1
  128. package/bin/chunk-yp9hvkc5.js +73 -0
  129. package/bin/{chunk-dkjkn8t3.js → chunk-ytypyfkc.js} +2 -2
  130. package/bin/{chunk-62ebss6h.js → chunk-z1kjmf60.js} +2 -2
  131. package/bin/chunk-z36bx86r.js +2 -0
  132. package/bin/chunk-z7hdnecp.js +3 -0
  133. package/bin/chunk-zeby1cq7.js +2 -0
  134. package/bin/chunk-zs5e8z1w.js +1 -0
  135. package/bin/chunk-zxnyefg5.js +2 -0
  136. package/bin/shumai-app.html +1 -1
  137. package/bin/shumai-app.js +312 -342
  138. package/package.json +7 -7
  139. package/prisma/schema.prisma +1 -1
  140. package/bin/chunk-045f1bw7.js +0 -2
  141. package/bin/chunk-0n1wfwcm.js +0 -2
  142. package/bin/chunk-1fwzepfn.js +0 -2
  143. package/bin/chunk-2xevs82j.js +0 -2
  144. package/bin/chunk-31y5j4hr.js +0 -1
  145. package/bin/chunk-34adtqqh.js +0 -1
  146. package/bin/chunk-4j8fbckp.js +0 -1
  147. package/bin/chunk-57s7yj35.js +0 -1
  148. package/bin/chunk-6tse78c7.js +0 -2
  149. package/bin/chunk-8nyve0cr.js +0 -7
  150. package/bin/chunk-ajndx51c.js +0 -2
  151. package/bin/chunk-bbyc2jfq.js +0 -1
  152. package/bin/chunk-br7d2qwc.js +0 -1
  153. package/bin/chunk-by6g0vye.js +0 -2
  154. package/bin/chunk-c24fvhm6.js +0 -1
  155. package/bin/chunk-c6aszz6p.js +0 -1
  156. package/bin/chunk-csqvmx1m.js +0 -2
  157. package/bin/chunk-dg8c91j5.js +0 -1
  158. package/bin/chunk-dk8vk17v.js +0 -2
  159. package/bin/chunk-ex2ym5pz.js +0 -2
  160. package/bin/chunk-f2zbsrc9.js +0 -2
  161. package/bin/chunk-gcpr2a24.js +0 -7
  162. package/bin/chunk-gpjkegdp.js +0 -1
  163. package/bin/chunk-jt6d0zb1.js +0 -2
  164. package/bin/chunk-jwgfkpek.js +0 -3
  165. package/bin/chunk-k2065y29.js +0 -2
  166. package/bin/chunk-k514bttd.js +0 -1
  167. package/bin/chunk-k7chm9a9.js +0 -2
  168. package/bin/chunk-kjgejwjp.css +0 -1
  169. package/bin/chunk-kqpzx5az.js +0 -73
  170. package/bin/chunk-kxr8fjsq.js +0 -2
  171. package/bin/chunk-mha3rsh7.js +0 -2
  172. package/bin/chunk-nn0px81k.js +0 -307
  173. package/bin/chunk-ns804tmv.js +0 -2
  174. package/bin/chunk-p1temt1j.js +0 -1
  175. package/bin/chunk-rkz6x3r0.js +0 -2
  176. package/bin/chunk-svz0ds0g.js +0 -1
  177. package/bin/chunk-t31basc5.js +0 -1
  178. package/bin/chunk-t6qdrw24.js +0 -1
  179. package/bin/chunk-wvwqgff4.js +0 -1
  180. package/bin/chunk-ww1cy08p.js +0 -1
  181. package/bin/chunk-xfp27ya9.js +0 -2
  182. package/bin/chunk-y0f4bc9f.js +0 -2
  183. package/bin/chunk-y2s0tjaa.js +0 -3
  184. package/bin/chunk-y3dy4pdt.js +0 -2
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  function ct(t){return typeof t>"u"||t===void 0}function V(t){return typeof t==="string"}function F(t){return typeof t==="number"}function J(t){return typeof t==="boolean"}function Y(t){return t===null}function Z(t){return t instanceof Date}function $(t){return typeof t==="bigint"}function pt(t){return typeof Buffer<"u"&&Buffer.isBuffer(t)}function St(t){return typeof t==="function"}function X(t){return typeof t==="object"&&t!==null}function G(t){return t[t.length-1]}function N(t){return Object.freeze(t)}function Wt(t){if(r(t))return t;else return[t]}function r(t){return Array.isArray(t)}function Vt(t){return t}var Bt=["preserve rows","delete rows","drop"],L=N({is(t){return t.kind==="CreateTableNode"},create(t){return N({kind:"CreateTableNode",table:t,columns:N([])})},cloneWithColumn(t,i){return N({...t,columns:N([...t.columns,i])})},cloneWithConstraint(t,i){return N({...t,constraints:t.constraints?N([...t.constraints,i]):N([i])})},cloneWithFrontModifier(t,i){return N({...t,frontModifiers:t.frontModifiers?N([...t.frontModifiers,i]):N([i])})},cloneWithEndModifier(t,i){return N({...t,endModifiers:t.endModifiers?N([...t.endModifiers,i]):N([i])})},cloneWith(t,i){return N({...t,...i})}});var x=N({is(t){return t.kind==="InsertQueryNode"},create(t,i,h){return N({kind:"InsertQueryNode",into:t,...i&&{with:i},replace:h})},createWithoutInto(){return N({kind:"InsertQueryNode"})},cloneWith(t,i){return N({...t,...i})}});class U{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#t=N({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=(t)=>{this.nodeStack.push(t),this.#t[t.kind](t),this.nodeStack.pop()}}var q=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],n=["+","-","*","/","%","^","&","|","#","<<",">>"],_=["->","->>"],o=[...q,...n,"&&","||"],d=["exists","not exists"],e=["not","-",...d],Ht=[...o,..._,...e,"between","between symmetric"],m=N({is(t){return t.kind==="OperatorNode"},create(t){return N({kind:"OperatorNode",operator:t})}});function Kt(t){return V(t)&&_.includes(t)}var R=N({is(t){return t.kind==="ParensNode"},create(t){return N({kind:"ParensNode",node:t})}});var c=N({is(t){return t.kind==="RawNode"},create(t,i){return N({kind:"RawNode",sqlFragments:N(t),parameters:N(i)})},createWithSql(t){return c.create([t],[])},createWithChild(t){return c.create(["",""],[t])},createWithChildren(t){return c.create(Array(t.length+1).fill(""),t)}});var S=N({is(t){return t.kind==="IdentifierNode"},create(t){return N({kind:"IdentifierNode",name:t})}});var p=N({is(t){return t.kind==="SchemableIdentifierNode"},create(t){return N({kind:"SchemableIdentifierNode",identifier:S.create(t)})},createWithSchema(t,i){return N({kind:"SchemableIdentifierNode",schema:S.create(t),identifier:S.create(i)})}});var E=N({is(t){return t.kind==="CreateViewNode"},create(t){return N({kind:"CreateViewNode",name:p.create(t)})},cloneWith(t,i){return N({...t,...i})}});var M=N({is(t){return t.kind==="SetOperationNode"},create(t,i,h){return N({kind:"SetOperationNode",operator:t,expression:i,all:h})}});var Q=N({is(t){return t.kind==="WhenNode"},create(t){return N({kind:"WhenNode",condition:t})},cloneWithResult(t,i){return N({...t,result:i})}});var A=new Set;function b(t){if(A.has(t))return;A.add(t),console.log(t)}var tt=/'/g,it=/['"]/g;class ht extends U{#t="";#i=[];get numParameters(){return this.#i.length}compileQuery(t,i){return this.#t="",this.#i=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(t),N({query:t,queryId:i,sql:this.getSql(),parameters:[...this.#i]})}getSql(){return this.#t}visitSelectQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!x.is(this.parentNode)&&!L.is(this.parentNode)&&!E.is(this.parentNode)&&!M.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("select"),t.distinctOn)this.append(" "),this.compileDistinctOn(t.distinctOn);if(t.frontModifiers?.length)this.append(" "),this.compileList(t.frontModifiers," ");if(t.top)this.append(" "),this.visitNode(t.top);if(t.selections)this.append(" "),this.compileList(t.selections);if(t.from)this.append(" "),this.visitNode(t.from);if(t.joins)this.append(" "),this.compileList(t.joins," ");if(t.where)this.append(" "),this.visitNode(t.where);if(t.groupBy)this.append(" "),this.visitNode(t.groupBy);if(t.having)this.append(" "),this.visitNode(t.having);if(t.setOperations)this.append(" "),this.compileList(t.setOperations," ");if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(t.offset)this.append(" "),this.visitNode(t.offset);if(t.fetch)this.append(" "),this.visitNode(t.fetch);if(t.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...t.endModifiers])," ");if(i)this.append(")")}visitFrom(t){this.append("from "),this.compileList(t.froms)}visitSelection(t){this.visitNode(t.selection)}visitColumn(t){this.visitNode(t.column)}compileDistinctOn(t){this.append("distinct on ("),this.compileList(t),this.append(")")}compileList(t,i=", "){let h=t.length-1;for(let f=0;f<=h;f++)if(this.visitNode(t[f]),f<h)this.append(i)}visitWhere(t){this.append("where "),this.visitNode(t.where)}visitHaving(t){this.append("having "),this.visitNode(t.having)}visitInsertQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode)&&!Q.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append(t.replace?"replace":"insert"),t.ignore)b("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(t.orAction)this.append(" "),this.visitNode(t.orAction);if(t.top)this.append(" "),this.visitNode(t.top);if(t.into)this.append(" into "),this.visitNode(t.into);if(t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.output)this.append(" "),this.visitNode(t.output);if(t.values)this.append(" "),this.visitNode(t.values);if(t.defaultValues)this.append(" "),this.append("default values");if(t.onConflict)this.append(" "),this.visitNode(t.onConflict);if(t.onDuplicateKey)this.append(" "),this.visitNode(t.onDuplicateKey);if(t.returning)this.append(" "),this.visitNode(t.returning);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitValues(t){this.append("values "),this.compileList(t.values)}visitDeleteQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("delete "),t.top)this.visitNode(t.top),this.append(" ");if(this.visitNode(t.from),t.output)this.append(" "),this.visitNode(t.output);if(t.using)this.append(" "),this.visitNode(t.using);if(t.joins)this.append(" "),this.compileList(t.joins," ");if(t.where)this.append(" "),this.visitNode(t.where);if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(t.returning)this.append(" "),this.visitNode(t.returning);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitReturning(t){this.append("returning "),this.compileList(t.selections)}visitAlias(t){this.visitNode(t.node),this.append(" as "),this.visitNode(t.alias)}visitReference(t){if(t.table)this.visitNode(t.table),this.append(".");this.visitNode(t.column)}visitSelectAll(t){this.append("*")}visitIdentifier(t){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(t),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(t){if(!V(t.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(t.name))}visitAnd(t){this.visitNode(t.left),this.append(" and "),this.visitNode(t.right)}visitOr(t){this.visitNode(t.left),this.append(" or "),this.visitNode(t.right)}visitValue(t){if(t.immediate)this.appendImmediateValue(t.value);else this.appendValue(t.value)}visitValueList(t){this.append("("),this.compileList(t.values),this.append(")")}visitTuple(t){this.append("("),this.compileList(t.values),this.append(")")}visitPrimitiveValueList(t){this.append("(");let{values:i}=t;for(let h=0;h<i.length;++h)if(this.appendValue(i[h]),h!==i.length-1)this.append(", ");this.append(")")}visitParens(t){this.append("("),this.visitNode(t.node),this.append(")")}visitJoin(t){if(this.append(st[t.joinType]),this.append(" "),this.visitNode(t.table),t.on)this.append(" "),this.visitNode(t.on)}visitOn(t){this.append("on "),this.visitNode(t.on)}visitRaw(t){let{sqlFragments:i,parameters:h}=t;for(let f=0;f<i.length;++f)if(this.append(i[f]),h.length>f)this.visitNode(h[f])}visitOperator(t){this.append(t.operator)}visitTable(t){this.visitNode(t.table)}visitSchemableIdentifier(t){if(t.schema)this.visitNode(t.schema),this.append(".");this.visitNode(t.identifier)}visitCreateTable(t){if(this.append("create "),t.frontModifiers?.length)this.compileList(t.frontModifiers," "),this.append(" ");if(t.temporary)this.append("temporary ");if(this.append("table "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.table),!t.selectQuery)this.append(" ("),this.compileList([...t.columns,...t.constraints??[]]),this.append(")");if(t.onCommit)this.append(" on commit "),this.append(t.onCommit);if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ");if(t.selectQuery)this.append(" as "),this.visitNode(t.selectQuery)}visitColumnDefinition(t){if(t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.column),this.append(" "),this.visitNode(t.dataType),t.unsigned)this.append(" unsigned");if(t.frontModifiers&&t.frontModifiers.length>0)this.append(" "),this.compileList(t.frontModifiers," ");if(t.generated)this.append(" "),this.visitNode(t.generated);if(t.identity)this.append(" identity");if(t.defaultTo)this.append(" "),this.visitNode(t.defaultTo);if(t.notNull)this.append(" not null");if(t.unique)this.append(" unique");if(t.nullsNotDistinct)this.append(" nulls not distinct");if(t.primaryKey)this.append(" primary key");if(t.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(t.references)this.append(" "),this.visitNode(t.references);if(t.check)this.append(" "),this.visitNode(t.check);if(t.endModifiers&&t.endModifiers.length>0)this.append(" "),this.compileList(t.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(t){if(this.append("references "),this.visitNode(t.table),this.append(" ("),this.compileList(t.columns),this.append(")"),t.onDelete)this.append(" on delete "),this.append(t.onDelete);if(t.onUpdate)this.append(" on update "),this.append(t.onUpdate)}visitDropTable(t){if(this.append("drop table "),t.ifExists)this.append("if exists ");if(this.visitNode(t.table),t.cascade)this.append(" cascade")}visitDataType(t){this.append(t.dataType)}visitOrderBy(t){this.append("order by "),this.compileList(t.items)}visitOrderByItem(t){if(this.visitNode(t.orderBy),t.collation)this.append(" "),this.visitNode(t.collation);if(t.direction)this.append(" "),this.visitNode(t.direction);if(t.nulls)this.append(" nulls "),this.append(t.nulls)}visitGroupBy(t){this.append("group by "),this.compileList(t.items)}visitGroupByItem(t){this.visitNode(t.groupBy)}visitUpdateQuery(t){let i=this.parentNode!==void 0&&!R.is(this.parentNode)&&!c.is(this.parentNode)&&!Q.is(this.parentNode);if(this.parentNode===void 0&&t.explain)this.visitNode(t.explain),this.append(" ");if(i)this.append("(");if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("update "),t.top)this.visitNode(t.top),this.append(" ");if(t.table)this.visitNode(t.table),this.append(" ");if(this.append("set "),t.updates)this.compileList(t.updates);if(t.output)this.append(" "),this.visitNode(t.output);if(t.from)this.append(" "),this.visitNode(t.from);if(t.joins){if(!t.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(t.joins," ")}if(t.where)this.append(" "),this.visitNode(t.where);if(t.returning)this.append(" "),this.visitNode(t.returning);if(t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(t.limit)this.append(" "),this.visitNode(t.limit);if(i)this.append(")");if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitColumnUpdate(t){this.visitNode(t.column),this.append(" = "),this.visitNode(t.value)}visitLimit(t){this.append("limit "),this.visitNode(t.limit)}visitOffset(t){this.append("offset "),this.visitNode(t.offset)}visitOnConflict(t){if(this.append("on conflict"),t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");else if(t.constraint)this.append(" on constraint "),this.visitNode(t.constraint);else if(t.indexExpression)this.append(" ("),this.visitNode(t.indexExpression),this.append(")");if(t.indexWhere)this.append(" "),this.visitNode(t.indexWhere);if(t.doNothing===!0)this.append(" do nothing");else if(t.updates){if(this.append(" do update set "),this.compileList(t.updates),t.updateWhere)this.append(" "),this.visitNode(t.updateWhere)}}visitOnDuplicateKey(t){this.append("on duplicate key update "),this.compileList(t.updates)}visitCreateIndex(t){if(this.append("create "),t.unique)this.append("unique ");if(this.append("index "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.name),t.table)this.append(" on "),this.visitNode(t.table);if(t.using)this.append(" using "),this.visitNode(t.using);if(t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.nullsNotDistinct)this.append(" nulls not distinct");if(t.where)this.append(" "),this.visitNode(t.where)}visitDropIndex(t){if(this.append("drop index "),t.ifExists)this.append("if exists ");if(this.visitNode(t.name),t.table)this.append(" on "),this.visitNode(t.table);if(t.cascade)this.append(" cascade")}visitCreateSchema(t){if(this.append("create schema "),t.ifNotExists)this.append("if not exists ");this.visitNode(t.schema)}visitDropSchema(t){if(this.append("drop schema "),t.ifExists)this.append("if exists ");if(this.visitNode(t.schema),t.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");this.append("primary key ("),this.compileList(t.columns),this.append(")"),this.buildDeferrable(t)}buildDeferrable(t){if(t.deferrable!==void 0)if(t.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(t.initiallyDeferred!==void 0)if(t.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");if(this.append("unique"),t.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(t.columns),this.append(")"),this.buildDeferrable(t)}visitCheckConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");this.append("check ("),this.visitNode(t.expression),this.append(")")}visitForeignKeyConstraint(t){if(t.name)this.append("constraint "),this.visitNode(t.name),this.append(" ");if(this.append("foreign key ("),this.compileList(t.columns),this.append(") "),this.visitNode(t.references),t.onDelete)this.append(" on delete "),this.append(t.onDelete);if(t.onUpdate)this.append(" on update "),this.append(t.onUpdate);this.buildDeferrable(t)}visitList(t){this.compileList(t.items)}visitWith(t){if(this.append("with "),t.recursive)this.append("recursive ");this.compileList(t.expressions)}visitCommonTableExpression(t){if(this.visitNode(t.name),this.append(" as "),J(t.materialized)){if(!t.materialized)this.append("not ");this.append("materialized ")}this.visitNode(t.expression)}visitCommonTableExpressionName(t){if(this.visitNode(t.table),t.columns)this.append("("),this.compileList(t.columns),this.append(")")}visitAlterTable(t){if(this.append("alter table "),this.visitNode(t.table),this.append(" "),t.renameTo)this.append("rename to "),this.visitNode(t.renameTo);if(t.setSchema)this.append("set schema "),this.visitNode(t.setSchema);if(t.addConstraint)this.visitNode(t.addConstraint);if(t.dropConstraint)this.visitNode(t.dropConstraint);if(t.renameConstraint)this.visitNode(t.renameConstraint);if(t.columnAlterations)this.compileColumnAlterations(t.columnAlterations);if(t.addIndex)this.visitNode(t.addIndex);if(t.dropIndex)this.visitNode(t.dropIndex)}visitAddColumn(t){this.append("add column "),this.visitNode(t.column)}visitRenameColumn(t){this.append("rename column "),this.visitNode(t.column),this.append(" to "),this.visitNode(t.renameTo)}visitDropColumn(t){this.append("drop column "),this.visitNode(t.column)}visitAlterColumn(t){if(this.append("alter column "),this.visitNode(t.column),this.append(" "),t.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(t.dataType),t.dataTypeExpression)this.append("using "),this.visitNode(t.dataTypeExpression)}if(t.setDefault)this.append("set default "),this.visitNode(t.setDefault);if(t.dropDefault)this.append("drop default");if(t.setNotNull)this.append("set not null");if(t.dropNotNull)this.append("drop not null")}visitModifyColumn(t){this.append("modify column "),this.visitNode(t.column)}visitAddConstraint(t){this.append("add "),this.visitNode(t.constraint)}visitDropConstraint(t){if(this.append("drop constraint "),t.ifExists)this.append("if exists ");if(this.visitNode(t.constraintName),t.modifier==="cascade")this.append(" cascade");else if(t.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(t){this.append("rename constraint "),this.visitNode(t.oldName),this.append(" to "),this.visitNode(t.newName)}visitSetOperation(t){if(this.append(t.operator),this.append(" "),t.all)this.append("all ");this.visitNode(t.expression)}visitCreateView(t){if(this.append("create "),t.orReplace)this.append("or replace ");if(t.materialized)this.append("materialized ");if(t.temporary)this.append("temporary ");if(this.append("view "),t.ifNotExists)this.append("if not exists ");if(this.visitNode(t.name),this.append(" "),t.columns)this.append("("),this.compileList(t.columns),this.append(") ");if(t.as)this.append("as "),this.visitNode(t.as)}visitRefreshMaterializedView(t){if(this.append("refresh materialized view "),t.concurrently)this.append("concurrently ");if(this.visitNode(t.name),t.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(t){if(this.append("drop "),t.materialized)this.append("materialized ");if(this.append("view "),t.ifExists)this.append("if exists ");if(this.visitNode(t.name),t.cascade)this.append(" cascade")}visitGenerated(t){if(this.append("generated "),t.always)this.append("always ");if(t.byDefault)this.append("by default ");if(this.append("as "),t.identity)this.append("identity");if(t.expression)this.append("("),this.visitNode(t.expression),this.append(")");if(t.stored)this.append(" stored")}visitDefaultValue(t){this.append("default "),this.visitNode(t.defaultValue)}visitSelectModifier(t){if(t.rawModifier)this.visitNode(t.rawModifier);else this.append(Nt[t.modifier]);if(t.of)this.append(" of "),this.compileList(t.of,", ")}visitCreateType(t){if(this.append("create type "),this.visitNode(t.name),t.enum)this.append(" as enum "),this.visitNode(t.enum)}visitDropType(t){if(this.append("drop type "),t.ifExists)this.append("if exists ");this.visitNode(t.name)}visitExplain(t){if(this.append("explain"),t.options||t.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),t.options){if(this.visitNode(t.options),t.format)this.append(this.getExplainOptionsDelimiter())}if(t.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(t.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(t){this.append("default")}visitAggregateFunction(t){if(this.append(t.func),this.append("("),t.distinct)this.append("distinct ");if(this.compileList(t.aggregated),t.orderBy)this.append(" "),this.visitNode(t.orderBy);if(this.append(")"),t.withinGroup)this.append(" within group ("),this.visitNode(t.withinGroup),this.append(")");if(t.filter)this.append(" filter("),this.visitNode(t.filter),this.append(")");if(t.over)this.append(" "),this.visitNode(t.over)}visitOver(t){if(this.append("over("),t.partitionBy){if(this.visitNode(t.partitionBy),t.orderBy)this.append(" ")}if(t.orderBy)this.visitNode(t.orderBy);this.append(")")}visitPartitionBy(t){this.append("partition by "),this.compileList(t.items)}visitPartitionByItem(t){this.visitNode(t.partitionBy)}visitBinaryOperation(t){this.visitNode(t.leftOperand),this.append(" "),this.visitNode(t.operator),this.append(" "),this.visitNode(t.rightOperand)}visitUnaryOperation(t){if(this.visitNode(t.operator),!this.isMinusOperator(t.operator))this.append(" ");this.visitNode(t.operand)}isMinusOperator(t){return m.is(t)&&t.operator==="-"}visitUsing(t){this.append("using "),this.compileList(t.tables)}visitFunction(t){this.append(t.func),this.append("("),this.compileList(t.arguments),this.append(")")}visitCase(t){if(this.append("case"),t.value)this.append(" "),this.visitNode(t.value);if(t.when)this.append(" "),this.compileList(t.when," ");if(t.else)this.append(" else "),this.visitNode(t.else);if(this.append(" end"),t.isStatement)this.append(" case")}visitWhen(t){if(this.append("when "),this.visitNode(t.condition),t.result)this.append(" then "),this.visitNode(t.result)}visitJSONReference(t){this.visitNode(t.reference),this.visitNode(t.traversal)}visitJSONPath(t){if(t.inOperator)this.visitNode(t.inOperator);this.append("'$");for(let i of t.pathLegs)this.visitNode(i);this.append("'")}visitJSONPathLeg(t){let i=t.type==="ArrayLocation",h=String(t.value);if(i)this.append("["),this.append(this.sanitizeStringLiteral(h)),this.append("]");else this.append('."'),this.append(this.sanitizeJSONPathMemberValue(h)),this.append('"')}visitJSONOperatorChain(t){for(let i=0,h=t.values.length;i<h;i++){if(i===h-1)this.visitNode(t.operator);else this.append("->");this.visitNode(t.values[i])}}visitMergeQuery(t){if(t.with)this.visitNode(t.with),this.append(" ");if(this.append("merge "),t.top)this.visitNode(t.top),this.append(" ");if(this.append("into "),this.visitNode(t.into),t.using)this.append(" "),this.visitNode(t.using);if(t.whens)this.append(" "),this.compileList(t.whens," ");if(t.returning)this.append(" "),this.visitNode(t.returning);if(t.output)this.append(" "),this.visitNode(t.output);if(t.endModifiers?.length)this.append(" "),this.compileList(t.endModifiers," ")}visitMatched(t){if(t.not)this.append("not ");if(this.append("matched"),t.bySource)this.append(" by source")}visitAddIndex(t){if(this.append("add "),t.unique)this.append("unique ");if(this.append("index "),this.visitNode(t.name),t.columns)this.append(" ("),this.compileList(t.columns),this.append(")");if(t.using)this.append(" using "),this.visitNode(t.using)}visitCast(t){this.append("cast("),this.visitNode(t.expression),this.append(" as "),this.visitNode(t.dataType),this.append(")")}visitFetch(t){this.append("fetch next "),this.visitNode(t.rowCount),this.append(` rows ${t.modifier}`)}visitOutput(t){this.append("output "),this.compileList(t.selections)}visitTop(t){if(this.append(`top(${t.expression})`),t.modifiers)this.append(` ${t.modifiers}`)}visitOrAction(t){this.append(t.action)}visitCollate(t){this.append("collate "),this.visitNode(t.collation)}append(t){this.#t+=t}appendValue(t){this.addParameter(t),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(t){let i=this.getLeftIdentifierWrapper(),h=this.getRightIdentifierWrapper(),f="";for(let C of t)if(f+=C,C===i)f+=i;else if(C===h)f+=h;return f}sanitizeStringLiteral(t){return t.replace(tt,"''")}sanitizeJSONPathMemberValue(t){return t.replace(it,(i)=>i==="'"?"''":"\\\"")}addParameter(t){this.#i.push(t)}appendImmediateValue(t){if(V(t))this.appendStringLiteral(t);else if(F(t)||J(t)||$(t))this.append(t.toString());else if(Y(t))this.append("null");else if(Z(t))this.appendImmediateValue(t.toISOString());else throw Error(`invalid immediate value ${t}`)}appendStringLiteral(t){this.append("'"),this.append(this.sanitizeStringLiteral(t)),this.append("'")}sortSelectModifiers(t){return t.sort((i,h)=>i.modifier&&h.modifier?P[i.modifier]-P[h.modifier]:1),N(t)}compileColumnAlterations(t){this.compileList(t)}announcesNewColumnDataType(){return!0}}var Nt=N({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),P=N({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),st=N({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});class D{transformQuery(t){return t.node}async transformResult(t){return t.result}}var j=N({is(t){return t.kind==="AliasNode"},create(t,i){return N({kind:"AliasNode",node:t,alias:i})}});var g=N({is(t){return t.kind==="AndNode"},create(t,i){return N({kind:"AndNode",left:t,right:i})}});var l=N({is(t){return t.kind==="OrNode"},create(t,i){return N({kind:"OrNode",left:t,right:i})}});var w=N({is(t){return t.kind==="OnNode"},create(t){return N({kind:"OnNode",on:t})},cloneWithOperation(t,i,h){return N({...t,on:i==="And"?g.create(t.on,h):l.create(t.on,h)})}});var a=N({is(t){return t.kind==="JoinNode"},create(t,i){return N({kind:"JoinNode",joinType:t,table:i,on:void 0})},createWithOn(t,i,h){return N({kind:"JoinNode",joinType:t,table:i,on:w.create(h)})},cloneWithOn(t,i){return N({...t,on:t.on?w.cloneWithOperation(t.on,"And",i):w.create(i)})}});var y=N({is(t){return t.kind==="ListNode"},create(t){return N({kind:"ListNode",items:N(t)})}});function s(t){return t}class T{nodeStack=[];#t=N({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(t,i){if(!t)return t;this.nodeStack.push(t);let h=this.transformNodeImpl(t,i);return this.nodeStack.pop(),N(h)}transformNodeImpl(t,i){return this.#t[t.kind](t,i)}transformNodeList(t,i){if(!t)return t;return N(t.map((h)=>this.transformNode(h,i)))}transformSelectQuery(t,i){return s({kind:"SelectQueryNode",from:this.transformNode(t.from,i),selections:this.transformNodeList(t.selections,i),distinctOn:this.transformNodeList(t.distinctOn,i),joins:this.transformNodeList(t.joins,i),groupBy:this.transformNode(t.groupBy,i),orderBy:this.transformNode(t.orderBy,i),where:this.transformNode(t.where,i),frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),limit:this.transformNode(t.limit,i),offset:this.transformNode(t.offset,i),with:this.transformNode(t.with,i),having:this.transformNode(t.having,i),explain:this.transformNode(t.explain,i),setOperations:this.transformNodeList(t.setOperations,i),fetch:this.transformNode(t.fetch,i),top:this.transformNode(t.top,i)})}transformSelection(t,i){return s({kind:"SelectionNode",selection:this.transformNode(t.selection,i)})}transformColumn(t,i){return s({kind:"ColumnNode",column:this.transformNode(t.column,i)})}transformAlias(t,i){return s({kind:"AliasNode",node:this.transformNode(t.node,i),alias:this.transformNode(t.alias,i)})}transformTable(t,i){return s({kind:"TableNode",table:this.transformNode(t.table,i)})}transformFrom(t,i){return s({kind:"FromNode",froms:this.transformNodeList(t.froms,i)})}transformReference(t,i){return s({kind:"ReferenceNode",column:this.transformNode(t.column,i),table:this.transformNode(t.table,i)})}transformAnd(t,i){return s({kind:"AndNode",left:this.transformNode(t.left,i),right:this.transformNode(t.right,i)})}transformOr(t,i){return s({kind:"OrNode",left:this.transformNode(t.left,i),right:this.transformNode(t.right,i)})}transformValueList(t,i){return s({kind:"ValueListNode",values:this.transformNodeList(t.values,i)})}transformParens(t,i){return s({kind:"ParensNode",node:this.transformNode(t.node,i)})}transformJoin(t,i){return s({kind:"JoinNode",joinType:t.joinType,table:this.transformNode(t.table,i),on:this.transformNode(t.on,i)})}transformRaw(t,i){return s({kind:"RawNode",sqlFragments:N([...t.sqlFragments]),parameters:this.transformNodeList(t.parameters,i)})}transformWhere(t,i){return s({kind:"WhereNode",where:this.transformNode(t.where,i)})}transformInsertQuery(t,i){return s({kind:"InsertQueryNode",into:this.transformNode(t.into,i),columns:this.transformNodeList(t.columns,i),values:this.transformNode(t.values,i),returning:this.transformNode(t.returning,i),onConflict:this.transformNode(t.onConflict,i),onDuplicateKey:this.transformNode(t.onDuplicateKey,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),ignore:t.ignore,orAction:this.transformNode(t.orAction,i),replace:t.replace,explain:this.transformNode(t.explain,i),defaultValues:t.defaultValues,top:this.transformNode(t.top,i),output:this.transformNode(t.output,i)})}transformValues(t,i){return s({kind:"ValuesNode",values:this.transformNodeList(t.values,i)})}transformDeleteQuery(t,i){return s({kind:"DeleteQueryNode",from:this.transformNode(t.from,i),using:this.transformNode(t.using,i),joins:this.transformNodeList(t.joins,i),where:this.transformNode(t.where,i),returning:this.transformNode(t.returning,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),orderBy:this.transformNode(t.orderBy,i),limit:this.transformNode(t.limit,i),explain:this.transformNode(t.explain,i),top:this.transformNode(t.top,i),output:this.transformNode(t.output,i)})}transformReturning(t,i){return s({kind:"ReturningNode",selections:this.transformNodeList(t.selections,i)})}transformCreateTable(t,i){return s({kind:"CreateTableNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),constraints:this.transformNodeList(t.constraints,i),temporary:t.temporary,ifNotExists:t.ifNotExists,onCommit:t.onCommit,frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),selectQuery:this.transformNode(t.selectQuery,i)})}transformColumnDefinition(t,i){return s({kind:"ColumnDefinitionNode",column:this.transformNode(t.column,i),dataType:this.transformNode(t.dataType,i),references:this.transformNode(t.references,i),primaryKey:t.primaryKey,autoIncrement:t.autoIncrement,unique:t.unique,notNull:t.notNull,unsigned:t.unsigned,defaultTo:this.transformNode(t.defaultTo,i),check:this.transformNode(t.check,i),generated:this.transformNode(t.generated,i),frontModifiers:this.transformNodeList(t.frontModifiers,i),endModifiers:this.transformNodeList(t.endModifiers,i),nullsNotDistinct:t.nullsNotDistinct,identity:t.identity,ifNotExists:t.ifNotExists})}transformAddColumn(t,i){return s({kind:"AddColumnNode",column:this.transformNode(t.column,i)})}transformDropTable(t,i){return s({kind:"DropTableNode",table:this.transformNode(t.table,i),ifExists:t.ifExists,cascade:t.cascade})}transformOrderBy(t,i){return s({kind:"OrderByNode",items:this.transformNodeList(t.items,i)})}transformOrderByItem(t,i){return s({kind:"OrderByItemNode",orderBy:this.transformNode(t.orderBy,i),direction:this.transformNode(t.direction,i),collation:this.transformNode(t.collation,i),nulls:t.nulls})}transformGroupBy(t,i){return s({kind:"GroupByNode",items:this.transformNodeList(t.items,i)})}transformGroupByItem(t,i){return s({kind:"GroupByItemNode",groupBy:this.transformNode(t.groupBy,i)})}transformUpdateQuery(t,i){return s({kind:"UpdateQueryNode",table:this.transformNode(t.table,i),from:this.transformNode(t.from,i),joins:this.transformNodeList(t.joins,i),where:this.transformNode(t.where,i),updates:this.transformNodeList(t.updates,i),returning:this.transformNode(t.returning,i),endModifiers:this.transformNodeList(t.endModifiers,i),with:this.transformNode(t.with,i),explain:this.transformNode(t.explain,i),limit:this.transformNode(t.limit,i),top:this.transformNode(t.top,i),output:this.transformNode(t.output,i),orderBy:this.transformNode(t.orderBy,i)})}transformColumnUpdate(t,i){return s({kind:"ColumnUpdateNode",column:this.transformNode(t.column,i),value:this.transformNode(t.value,i)})}transformLimit(t,i){return s({kind:"LimitNode",limit:this.transformNode(t.limit,i)})}transformOffset(t,i){return s({kind:"OffsetNode",offset:this.transformNode(t.offset,i)})}transformOnConflict(t,i){return s({kind:"OnConflictNode",columns:this.transformNodeList(t.columns,i),constraint:this.transformNode(t.constraint,i),indexExpression:this.transformNode(t.indexExpression,i),indexWhere:this.transformNode(t.indexWhere,i),updates:this.transformNodeList(t.updates,i),updateWhere:this.transformNode(t.updateWhere,i),doNothing:t.doNothing})}transformOnDuplicateKey(t,i){return s({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(t.updates,i)})}transformCreateIndex(t,i){return s({kind:"CreateIndexNode",name:this.transformNode(t.name,i),table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),unique:t.unique,using:this.transformNode(t.using,i),ifNotExists:t.ifNotExists,where:this.transformNode(t.where,i),nullsNotDistinct:t.nullsNotDistinct})}transformList(t,i){return s({kind:"ListNode",items:this.transformNodeList(t.items,i)})}transformDropIndex(t,i){return s({kind:"DropIndexNode",name:this.transformNode(t.name,i),table:this.transformNode(t.table,i),ifExists:t.ifExists,cascade:t.cascade})}transformPrimaryKeyConstraint(t,i){return s({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(t.columns,i),name:this.transformNode(t.name,i),deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformUniqueConstraint(t,i){return s({kind:"UniqueConstraintNode",columns:this.transformNodeList(t.columns,i),name:this.transformNode(t.name,i),nullsNotDistinct:t.nullsNotDistinct,deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformForeignKeyConstraint(t,i){return s({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(t.columns,i),references:this.transformNode(t.references,i),name:this.transformNode(t.name,i),onDelete:t.onDelete,onUpdate:t.onUpdate,deferrable:t.deferrable,initiallyDeferred:t.initiallyDeferred})}transformSetOperation(t,i){return s({kind:"SetOperationNode",operator:t.operator,expression:this.transformNode(t.expression,i),all:t.all})}transformReferences(t,i){return s({kind:"ReferencesNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i),onDelete:t.onDelete,onUpdate:t.onUpdate})}transformCheckConstraint(t,i){return s({kind:"CheckConstraintNode",expression:this.transformNode(t.expression,i),name:this.transformNode(t.name,i)})}transformWith(t,i){return s({kind:"WithNode",expressions:this.transformNodeList(t.expressions,i),recursive:t.recursive})}transformCommonTableExpression(t,i){return s({kind:"CommonTableExpressionNode",name:this.transformNode(t.name,i),materialized:t.materialized,expression:this.transformNode(t.expression,i)})}transformCommonTableExpressionName(t,i){return s({kind:"CommonTableExpressionNameNode",table:this.transformNode(t.table,i),columns:this.transformNodeList(t.columns,i)})}transformHaving(t,i){return s({kind:"HavingNode",having:this.transformNode(t.having,i)})}transformCreateSchema(t,i){return s({kind:"CreateSchemaNode",schema:this.transformNode(t.schema,i),ifNotExists:t.ifNotExists})}transformDropSchema(t,i){return s({kind:"DropSchemaNode",schema:this.transformNode(t.schema,i),ifExists:t.ifExists,cascade:t.cascade})}transformAlterTable(t,i){return s({kind:"AlterTableNode",table:this.transformNode(t.table,i),renameTo:this.transformNode(t.renameTo,i),setSchema:this.transformNode(t.setSchema,i),columnAlterations:this.transformNodeList(t.columnAlterations,i),addConstraint:this.transformNode(t.addConstraint,i),dropConstraint:this.transformNode(t.dropConstraint,i),renameConstraint:this.transformNode(t.renameConstraint,i),addIndex:this.transformNode(t.addIndex,i),dropIndex:this.transformNode(t.dropIndex,i)})}transformDropColumn(t,i){return s({kind:"DropColumnNode",column:this.transformNode(t.column,i)})}transformRenameColumn(t,i){return s({kind:"RenameColumnNode",column:this.transformNode(t.column,i),renameTo:this.transformNode(t.renameTo,i)})}transformAlterColumn(t,i){return s({kind:"AlterColumnNode",column:this.transformNode(t.column,i),dataType:this.transformNode(t.dataType,i),dataTypeExpression:this.transformNode(t.dataTypeExpression,i),setDefault:this.transformNode(t.setDefault,i),dropDefault:t.dropDefault,setNotNull:t.setNotNull,dropNotNull:t.dropNotNull})}transformModifyColumn(t,i){return s({kind:"ModifyColumnNode",column:this.transformNode(t.column,i)})}transformAddConstraint(t,i){return s({kind:"AddConstraintNode",constraint:this.transformNode(t.constraint,i)})}transformDropConstraint(t,i){return s({kind:"DropConstraintNode",constraintName:this.transformNode(t.constraintName,i),ifExists:t.ifExists,modifier:t.modifier})}transformRenameConstraint(t,i){return s({kind:"RenameConstraintNode",oldName:this.transformNode(t.oldName,i),newName:this.transformNode(t.newName,i)})}transformCreateView(t,i){return s({kind:"CreateViewNode",name:this.transformNode(t.name,i),temporary:t.temporary,orReplace:t.orReplace,ifNotExists:t.ifNotExists,materialized:t.materialized,columns:this.transformNodeList(t.columns,i),as:this.transformNode(t.as,i)})}transformRefreshMaterializedView(t,i){return s({kind:"RefreshMaterializedViewNode",name:this.transformNode(t.name,i),concurrently:t.concurrently,withNoData:t.withNoData})}transformDropView(t,i){return s({kind:"DropViewNode",name:this.transformNode(t.name,i),ifExists:t.ifExists,materialized:t.materialized,cascade:t.cascade})}transformGenerated(t,i){return s({kind:"GeneratedNode",byDefault:t.byDefault,always:t.always,identity:t.identity,stored:t.stored,expression:this.transformNode(t.expression,i)})}transformDefaultValue(t,i){return s({kind:"DefaultValueNode",defaultValue:this.transformNode(t.defaultValue,i)})}transformOn(t,i){return s({kind:"OnNode",on:this.transformNode(t.on,i)})}transformSelectModifier(t,i){return s({kind:"SelectModifierNode",modifier:t.modifier,rawModifier:this.transformNode(t.rawModifier,i),of:this.transformNodeList(t.of,i)})}transformCreateType(t,i){return s({kind:"CreateTypeNode",name:this.transformNode(t.name,i),enum:this.transformNode(t.enum,i)})}transformDropType(t,i){return s({kind:"DropTypeNode",name:this.transformNode(t.name,i),ifExists:t.ifExists})}transformExplain(t,i){return s({kind:"ExplainNode",format:t.format,options:this.transformNode(t.options,i)})}transformSchemableIdentifier(t,i){return s({kind:"SchemableIdentifierNode",schema:this.transformNode(t.schema,i),identifier:this.transformNode(t.identifier,i)})}transformAggregateFunction(t,i){return s({kind:"AggregateFunctionNode",func:t.func,aggregated:this.transformNodeList(t.aggregated,i),distinct:t.distinct,orderBy:this.transformNode(t.orderBy,i),withinGroup:this.transformNode(t.withinGroup,i),filter:this.transformNode(t.filter,i),over:this.transformNode(t.over,i)})}transformOver(t,i){return s({kind:"OverNode",orderBy:this.transformNode(t.orderBy,i),partitionBy:this.transformNode(t.partitionBy,i)})}transformPartitionBy(t,i){return s({kind:"PartitionByNode",items:this.transformNodeList(t.items,i)})}transformPartitionByItem(t,i){return s({kind:"PartitionByItemNode",partitionBy:this.transformNode(t.partitionBy,i)})}transformBinaryOperation(t,i){return s({kind:"BinaryOperationNode",leftOperand:this.transformNode(t.leftOperand,i),operator:this.transformNode(t.operator,i),rightOperand:this.transformNode(t.rightOperand,i)})}transformUnaryOperation(t,i){return s({kind:"UnaryOperationNode",operator:this.transformNode(t.operator,i),operand:this.transformNode(t.operand,i)})}transformUsing(t,i){return s({kind:"UsingNode",tables:this.transformNodeList(t.tables,i)})}transformFunction(t,i){return s({kind:"FunctionNode",func:t.func,arguments:this.transformNodeList(t.arguments,i)})}transformCase(t,i){return s({kind:"CaseNode",value:this.transformNode(t.value,i),when:this.transformNodeList(t.when,i),else:this.transformNode(t.else,i),isStatement:t.isStatement})}transformWhen(t,i){return s({kind:"WhenNode",condition:this.transformNode(t.condition,i),result:this.transformNode(t.result,i)})}transformJSONReference(t,i){return s({kind:"JSONReferenceNode",reference:this.transformNode(t.reference,i),traversal:this.transformNode(t.traversal,i)})}transformJSONPath(t,i){return s({kind:"JSONPathNode",inOperator:this.transformNode(t.inOperator,i),pathLegs:this.transformNodeList(t.pathLegs,i)})}transformJSONPathLeg(t,i){return s({kind:"JSONPathLegNode",type:t.type,value:t.value})}transformJSONOperatorChain(t,i){return s({kind:"JSONOperatorChainNode",operator:this.transformNode(t.operator,i),values:this.transformNodeList(t.values,i)})}transformTuple(t,i){return s({kind:"TupleNode",values:this.transformNodeList(t.values,i)})}transformMergeQuery(t,i){return s({kind:"MergeQueryNode",into:this.transformNode(t.into,i),using:this.transformNode(t.using,i),whens:this.transformNodeList(t.whens,i),with:this.transformNode(t.with,i),top:this.transformNode(t.top,i),endModifiers:this.transformNodeList(t.endModifiers,i),output:this.transformNode(t.output,i),returning:this.transformNode(t.returning,i)})}transformMatched(t,i){return s({kind:"MatchedNode",not:t.not,bySource:t.bySource})}transformAddIndex(t,i){return s({kind:"AddIndexNode",name:this.transformNode(t.name,i),columns:this.transformNodeList(t.columns,i),unique:t.unique,using:this.transformNode(t.using,i),ifNotExists:t.ifNotExists})}transformCast(t,i){return s({kind:"CastNode",expression:this.transformNode(t.expression,i),dataType:this.transformNode(t.dataType,i)})}transformFetch(t,i){return s({kind:"FetchNode",rowCount:this.transformNode(t.rowCount,i),modifier:t.modifier})}transformTop(t,i){return s({kind:"TopNode",expression:t.expression,modifiers:t.modifiers})}transformOutput(t,i){return s({kind:"OutputNode",selections:this.transformNodeList(t.selections,i)})}transformDataType(t,i){return t}transformSelectAll(t,i){return t}transformIdentifier(t,i){return t}transformValue(t,i){return t}transformPrimitiveValueList(t,i){return t}transformOperator(t,i){return t}transformDefaultInsertValue(t,i){return t}transformOrAction(t,i){return t}transformCollate(t,i){return t}}var W=N({is(t){return t.kind==="TableNode"},create(t){return N({kind:"TableNode",table:p.create(t)})},createWithSchema(t,i){return N({kind:"TableNode",table:p.createWithSchema(t,i)})}});var u=N({is(t){return t.kind==="UsingNode"},create(t){return N({kind:"UsingNode",tables:N(t)})},cloneWithTables(t,i){return N({...t,tables:N([...t.tables,...i])})}});var ft=N({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}),vt={json_agg:!0,to_json:!0};class z extends T{#t;#i=new Set;#h=new Set;constructor(t){super();this.#t=t}transformNodeImpl(t,i){if(!this.#v(t))return super.transformNodeImpl(t,i);let h=this.#s(t);for(let v of h)this.#h.add(v);let f=this.#k(t);for(let v of f)this.#i.add(v);let C=super.transformNodeImpl(t,i);for(let v of f)this.#i.delete(v);for(let v of h)this.#h.delete(v);return C}transformSchemableIdentifier(t,i){let h=super.transformSchemableIdentifier(t,i);if(h.schema||!this.#i.has(t.identifier.name))return h;return{...h,schema:S.create(this.#t)}}transformReferences(t,i){let h=super.transformReferences(t,i);if(h.table.table.schema)return h;return{...h,table:W.createWithSchema(this.#t,h.table.table.identifier.name)}}transformAggregateFunction(t,i){return{...super.transformAggregateFunction({...t,aggregated:[]},i),aggregated:this.#N(t,i,"aggregated")}}transformFunction(t,i){return{...super.transformFunction({...t,arguments:[]},i),arguments:this.#N(t,i,"arguments")}}transformSelectModifier(t,i){return{...super.transformSelectModifier({...t,of:void 0},i),of:t.of?.map((h)=>W.is(h)&&!h.table.schema?{...h,table:this.transformIdentifier(h.table.identifier,i)}:this.transformNode(h,i))}}#N(t,i,h){return vt[t.func]?t[h].map((f)=>!W.is(f)||f.table.schema?this.transformNode(f,i):{...f,table:this.transformIdentifier(f.table.identifier,i)}):this.transformNodeList(t[h],i)}#v(t){return t.kind in ft}#k(t){let i=new Set;if("name"in t&&t.name&&p.is(t.name))this.#C(t.name,i);if("from"in t&&t.from)for(let h of t.from.froms)this.#f(h,i);if("into"in t&&t.into)this.#f(t.into,i);if("table"in t&&t.table)this.#f(t.table,i);if("joins"in t&&t.joins)for(let h of t.joins)this.#f(h.table,i);if("using"in t&&t.using)if(a.is(t.using))this.#f(t.using.table,i);else this.#f(t.using,i);return i}#s(t){let i=new Set;if("with"in t&&t.with)this.#c(t.with,i);return i}#f(t,i){if(W.is(t))return this.#C(t.table,i);if(j.is(t)&&W.is(t.node))return this.#C(t.node.table,i);if(y.is(t)){for(let h of t.items)this.#f(h,i);return}if(u.is(t)){for(let h of t.tables)this.#f(h,i);return}}#C(t,i){let h=t.identifier.name;if(!this.#i.has(h)&&!this.#h.has(h))i.add(h)}#c(t,i){for(let h of t.expressions){let f=h.name.table.table.identifier.name;if(!this.#h.has(f))i.add(f)}}}class H{#t;constructor(t){this.#t=new z(t)}transformQuery(t){return this.#t.transformNode(t.node,t.queryId)}async transformResult(t){return t.result}}var Ct="kysely_migration",I="kysely_migration_lock",Ot=!1,K="migration_lock",gi=N({__noMigrations__:!0});class kt{#t;constructor(t){this.#t=N(t)}async getMigrations(){let i=await this.#O(this.#N)?await this.#t.db.withPlugin(this.#s).selectFrom(this.#N).select(["name","timestamp"]).$narrowType().execute():[];return(await this.#V()).map(({name:f,...C})=>{let v=i.find((O)=>O.name===f);return{name:f,migration:C,executedAt:v?new Date(v.timestamp):void 0}})}async migrateToLatest(){return this.#i(()=>({direction:"Up",step:1/0}))}async migrateTo(t){return this.#i(({migrations:i,executedMigrations:h,pendingMigrations:f})=>{if(X(t)&&t.__noMigrations__===!0)return{direction:"Down",step:1/0};if(!i.find((O)=>O.name===t))throw Error(`migration "${t}" doesn't exist`);let C=h.indexOf(t),v=f.findIndex((O)=>O.name===t);if(C!==-1)return{direction:"Down",step:h.length-C-1};else if(v!==-1)return{direction:"Up",step:v+1};else throw Error(`migration "${t}" isn't executed or pending`)})}async migrateUp(){return this.#i(()=>({direction:"Up",step:1}))}async migrateDown(){return this.#i(()=>({direction:"Down",step:1}))}async#i(t){try{return await this.#f(),await this.#C(),await this.#c(),await this.#R(),await this.#w(t)}catch(i){if(i instanceof B)return i.resultSet;return{error:i}}}get#h(){return this.#t.migrationTableSchema}get#N(){return this.#t.migrationTableName??Ct}get#v(){return this.#t.migrationLockTableName??I}get#k(){return this.#t.allowUnorderedMigrations??Ot}get#s(){if(this.#h)return new H(this.#h);return new D}async#f(){if(!this.#h)return;if(await this.#S())return;try{await this.#p(this.#t.db.schema.createSchema(this.#h))}catch(i){if(!await this.#S())throw i}}async#C(){if(await this.#O(this.#N))return;try{await this.#p(this.#t.db.schema.withPlugin(this.#s).createTable(this.#N).addColumn("name","varchar(255)",(i)=>i.notNull().primaryKey()).addColumn("timestamp","varchar(255)",(i)=>i.notNull()))}catch(i){if(!await this.#O(this.#N))throw i}}async#c(){if(await this.#O(this.#v))return;try{await this.#p(this.#t.db.schema.withPlugin(this.#s).createTable(this.#v).addColumn("id","varchar(255)",(i)=>i.notNull().primaryKey()).addColumn("is_locked","integer",(i)=>i.notNull().defaultTo(0)))}catch(i){if(!await this.#O(this.#v))throw i}}async#R(){if(await this.#W())return;try{await this.#t.db.withPlugin(this.#s).insertInto(this.#v).values({id:K,is_locked:0}).execute()}catch(i){if(!await this.#W())throw i}}async#S(){return(await this.#t.db.introspection.getSchemas()).some((i)=>i.name===this.#h)}async#O(t){let i=this.#h;return(await this.#t.db.introspection.getTables({withInternalKyselyTables:!0})).some((f)=>f.name===t&&(!i||f.schema===i))}async#W(){return!!await this.#t.db.withPlugin(this.#s).selectFrom(this.#v).where("id","=",K).select("id").executeTakeFirst()}async#w(t){let i=this.#t.db.getExecutor().adapter,h=N({lockTable:this.#t.migrationLockTableName??I,lockRowId:K,lockTableSchema:this.#t.migrationTableSchema}),f=async(C)=>{try{await i.acquireMigrationLock(C,h);let v=await this.#B(C);if(v.migrations.length===0)return{results:[]};let{direction:O,step:k}=t(v);if(k<=0)return{results:[]};if(O==="Down")return await this.#T(C,v,k);else if(O==="Up")return await this.#z(C,v,k);return{results:[]}}finally{await i.releaseMigrationLock(C,h)}};if(i.supportsTransactionalDdl&&!this.#t.disableTransactions)return this.#t.db.transaction().execute(f);else return this.#t.db.connection().execute(f)}async#B(t){let i=await this.#V(),h=await this.#U(t);if(this.#Q(i,h),!this.#k)this.#D(i,h);let f=this.#J(i,h);return N({migrations:i,executedMigrations:h,lastMigration:G(h),pendingMigrations:f})}#J(t,i){return t.filter((h)=>{return!i.includes(h.name)})}async#V(){let t=await this.#t.provider.getMigrations();return Object.keys(t).sort().map((i)=>({...t[i],name:i}))}async#U(t){let i=await t.withPlugin(this.#s).selectFrom(this.#N).select(["name","timestamp"]).$narrowType().execute(),h=this.#t.nameComparator||((f,C)=>f.localeCompare(C));return i.sort((f,C)=>{if(f.timestamp===C.timestamp)return h(f.name,C.name);return new Date(f.timestamp).getTime()-new Date(C.timestamp).getTime()}).map((f)=>f.name)}#Q(t,i){for(let h of i)if(!t.some((f)=>f.name===h))throw Error(`corrupted migrations: previously executed migration ${h} is missing`)}#D(t,i){for(let h=0;h<i.length;++h)if(t[h].name!==i[h])throw Error(`corrupted migrations: expected previously executed migration ${i[h]} to be at index ${h} but ${t[h].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)}async#T(t,i,h){let f=i.executedMigrations.slice().reverse().slice(0,h).map((v)=>{return i.migrations.find((O)=>O.name===v)}),C=f.map((v)=>{return{migrationName:v.name,direction:"Down",status:"NotExecuted"}});for(let v=0;v<C.length;++v){let O=f[v];try{if(O.down)await O.down(t),await t.withPlugin(this.#s).deleteFrom(this.#N).where("name","=",O.name).execute(),C[v]={migrationName:O.name,direction:"Down",status:"Success"}}catch(k){throw C[v]={migrationName:O.name,direction:"Down",status:"Error"},new B({error:k,results:C})}}return{results:C}}async#z(t,i,h){let C=i.pendingMigrations.slice(0,h).map((v)=>{return{migrationName:v.name,direction:"Up",status:"NotExecuted"}});for(let v=0;v<C.length;v++){let O=i.pendingMigrations[v];try{await O.up(t),await t.withPlugin(this.#s).insertInto(this.#N).values({name:O.name,timestamp:new Date().toISOString()}).execute(),C[v]={migrationName:O.name,direction:"Up",status:"Success"}}catch(k){throw C[v]={migrationName:O.name,direction:"Up",status:"Error"},new B({error:k,results:C})}}return{results:C}}async#p(t){if(this.#t.db.getExecutor().adapter.supportsCreateIfNotExists)t=t.ifNotExists();await t.execute()}}class B extends Error{#t;constructor(t){super();this.#t=t}get resultSet(){return this.#t}}
3
- export{ct as Wb,V as Xb,F as Yb,J as Zb,Y as _b,Z as $b,$ as ac,pt as bc,St as cc,X as dc,N as ec,Wt as fc,r as gc,Vt as hc,S as ic,Bt as jc,L as kc,p as lc,j as mc,W as nc,g as oc,l as pc,a as qc,Ht as rc,m as sc,Kt as tc,c as uc,b as vc,R as wc,x as xc,y as yc,u as zc,Q as Ac,T as Bc,H as Cc,M as Dc,E as Ec,ht as Fc,Ct as Gc,I as Hc};
3
+ export{ct as Xb,V as Yb,F as Zb,J as _b,Y as $b,Z as ac,$ as bc,pt as cc,St as dc,X as ec,N as fc,Wt as gc,r as hc,Vt as ic,S as jc,Bt as kc,L as lc,p as mc,j as nc,W as oc,g as pc,l as qc,a as rc,Ht as sc,m as tc,Kt as uc,c as vc,b as wc,R as xc,x as yc,y as zc,u as Ac,Q as Bc,T as Cc,H as Dc,M as Ec,E as Fc,ht as Gc,Ct as Hc,I as Ic};
@@ -0,0 +1,2 @@
1
+ import{X as Tz}from"./chunk-c1k86mfa.js";import{_ as wz}from"./chunk-6d5xrgfx.js";import{ag as M}from"./chunk-5vewxmz7.js";import{bg as vz}from"./chunk-ev17v1mv.js";import{eg as Fz,fg as Hz,gg as Bz,hg as Cz,ig as Rz}from"./chunk-k4v0brcb.js";import{jg as r}from"./chunk-4181tdds.js";import{og as kz}from"./chunk-63y0eb07.js";import{fh as qz}from"./chunk-qrf0ady6.js";import{ih as n}from"./chunk-k47md1g4.js";import{wh as Ez}from"./chunk-mq83a0kk.js";import{Jh as Oz}from"./chunk-07h4b77v.js";import{qi as Pz}from"./chunk-b1ypjqgp.js";import{Gi as _z,ui as Yz,xi as Zz}from"./chunk-h0fxysxs.js";import{Ej as $z,Gk as Lz,Gl as Qz,Pj as Uz,Sl as Nz,Tl as Dz,Xl as v,Yj as T,Zj as Vz,aj as az,bj as x,cj as z,ck as d,dj as K,jl as c,pk as Wz,sk as m,um as J,yk as Xz}from"./chunk-yp9hvkc5.js";import{sn as iz}from"./chunk-dxyq9h8n.js";var X=iz(az(),1);function NG({projectId:Q,contextAssetId:C,file:q,currentTime:Mz,frameRate:y,startTimecode:i,formatTimestamp:S,onTyping:yz,onSelectMessage:a,selectedMessageId:bz}){let{isHistoryMode:P,setIsHistoryMode:b,currentSessionId:hz,chatAssets:Az,removeAsset:Sz,messages:E,historySessions:o,isStreaming:k,fetchHistorySessions:t,loadSession:uz,deleteSession:fz,startNewSession:s,sendMessage:pz,abortActiveSession:Iz,selectedAgentId:w,setSelectedAgentId:h,inputText:gz,setInputText:jz}=M(),{teamId:N,ensureTeamIdForProject:e}=Pz(),{videoTimeDisplayMode:lz}=kz(),[A,u]=X.useState(null);X.useEffect(()=>{if(Q)e(Q)},[Q,e]);let{data:xz=[],isSuccess:zz}=Zz({queryKey:["chat-agents",Q],queryFn:async()=>{if(!Q)return[];let G=await _z.api.projects[":projectId"]["chat-agents"].$get({param:{projectId:Q}});if(!G.ok)throw Error("failed to fetch agents");return G.json()},enabled:!!Q}),R=xz.filter((G)=>G.type==="chat"&&G.enabled);X.useEffect(()=>{if(!zz)return;if(R.length>0){if(!R.some((Y)=>Y.id===w))h(R[0].id)}else if(w!==null)h(null)},[zz,R,w,h]);let Gz=X.useRef(null),f=X.useRef(null),p=X.useRef(!0),I=X.useRef(!0);X.useEffect(()=>{I.current=!0,p.current=!0},[Q,C,P]),X.useEffect(()=>{let G=f.current?.querySelector('[data-slot="scroll-area-viewport"]');if(!G)return;let{scrollTop:Y,isAtBottom:V}=M.getState(),Z=setTimeout(()=>{if(V)G.scrollTop=G.scrollHeight;else G.scrollTop=Y;let L=setTimeout(()=>{I.current=!1},50);return()=>clearTimeout(L)},0);return()=>clearTimeout(Z)},[Q,C,P]),X.useEffect(()=>{let G=f.current?.querySelector('[data-slot="scroll-area-viewport"]');if(!G)return;let Y=()=>{if(I.current)return;let V=G.scrollTop,Z=G.scrollHeight-V-G.clientHeight<10;M.getState().setScrollState(V,Z)};return G.addEventListener("scroll",Y),()=>{G.removeEventListener("scroll",Y)}},[Q,C,P]);let{ref:dz,isDropTarget:mz}=qz({id:"chatbot-sidebar",data:{type:"chatbot-sidebar"}});X.useEffect(()=>{if(!P){let{isAtBottom:G}=M.getState();if(G||k){let Y=p.current?"auto":"smooth";Gz.current?.scrollIntoView({behavior:Y})}p.current=!1}},[E,k,P]),X.useEffect(()=>{if(P&&N)t(N)},[P,t,N]);let H=Yz(),cz=X.useCallback(()=>{H.invalidateQueries({queryKey:["search"]}),H.invalidateQueries({queryKey:["folders"]}),H.invalidateQueries({queryKey:["files"]}),H.invalidateQueries({queryKey:["file"]}),H.invalidateQueries({queryKey:["version_stacks"]}),H.invalidateQueries({queryKey:["projects"]})},[H]),g=(G)=>{if(typeof G==="string")return G;if(Array.isArray(G))return G.map((Y)=>{if(typeof Y==="string")return Y;if(Y&&typeof Y==="object"&&"type"in Y&&Y.type==="text"&&"text"in Y)return String(Y.text);return""}).join("");return""},Jz=(G)=>{return G.replace(/<@([a-zA-Z0-9_-]+)>/g,"@$1").replace(/^\[([^\]]+)\]:/gm,"\\[$1\\]:")},nz=(G)=>{switch(G.role){case"user":case"custom":{let Y=G;if(G.role==="custom"&&Y.customType==="context_display_info"){let L=Y.details?.assets||[];if(L.length===0)return null;return K("div",{className:"text-xs text-muted-foreground bg-muted/40 p-2.5 rounded-lg border border-border/50 space-y-1 my-1",children:[z("div",{className:"font-semibold",children:J.assets_added_to_context()}),z("ul",{className:"list-disc list-inside space-y-0.5",children:L.map(($)=>K("li",{className:"truncate",children:[$.name," ",K("span",{className:"text-muted-foreground/70",children:["(",$.type,")"]})]},$.id))})]},G.id)}if(G.role==="user"||Y.customType==="shumai_message"){let Z=Y.details,L=Z?.referencedAssets||[],$=Z?.attachedFiles||[],U=Z?.position,D=Z?.annotation||Z?.annotations&&Z.annotations.length>0,W=!Z?.currentAsset?.id||C&&Z.currentAsset.id===C||q?.id&&Z.currentAsset.id===q.id,O=bz===G.id,B="";if(U?.type==="time")if(S)B=S(U.seconds);else if(y){let _=Math.round(U.seconds*y);B=wz(_,y,lz,i)}else{let _=Math.floor(U.seconds/60),F=Math.floor(U.seconds%60);B=`${_.toString().padStart(2,"0")}:${F.toString().padStart(2,"0")}`}else if(U?.type==="page")B=J.page_prefix({page:U.page});let Kz=g(Y.content),rz=$.length>0||L.length>0;return z("div",{onClick:()=>{if(W&&a)a(G)},className:v("flex flex-col items-end w-full group transition-all duration-150",W&&(D||U)&&"cursor-pointer"),children:K("div",{className:v("bg-primary text-primary-foreground rounded-lg px-3 py-2 text-sm whitespace-pre-wrap shadow-xs break-words transition-all border",rz?"w-full":"max-w-[85%]",O?"border-blue-500 dark:border-blue-400":"border-transparent"),children:[K("div",{className:"text-sm leading-relaxed whitespace-pre-wrap break-words",children:[D&&z("span",{className:"inline-flex items-center align-middle mr-1.5 p-0.5 rounded bg-primary-foreground/20 text-primary-foreground",title:J.contains_drawing_annotations(),children:z(Ez,{className:"w-3.5 h-3.5"})}),U&&z("span",{className:"inline-flex items-center align-middle mr-1.5 px-1.5 py-0.5 rounded text-xs font-mono font-bold bg-primary-foreground/20 text-primary-foreground",children:B}),Kz&&z("span",{children:Kz})]}),$.length>0&&K("div",{className:"mt-2.5 w-full",children:[z("div",{className:"text-xs font-medium text-primary-foreground/70 mb-1",children:J.attachments()}),z("div",{className:"flex flex-col gap-1.5 w-full",children:$.map((_)=>{let F=_.name||"file",j=vz(F)||_.mediaType==="image"||_.mimeType?.startsWith("image/");return K("div",{className:v("group/att relative flex items-center w-full max-w-full rounded-lg border border-primary-foreground/15 bg-primary-foreground/10 hover:bg-primary-foreground/15 transition-colors overflow-hidden",j?"h-18 p-1.5 gap-2.5 cursor-pointer":"h-9 px-2.5 gap-2.5"),onClick:(l)=>{if(l.stopPropagation(),_.url)if(j)u({url:_.url,name:F});else window.open(_.url,"_blank","noreferrer")},children:[j&&_.url?z("div",{className:"h-full aspect-square rounded-md overflow-hidden bg-black/20 shrink-0",children:z("img",{src:_.url,alt:F,className:"w-full h-full object-cover group-hover/att:scale-105 transition-transform duration-200"})}):z(m,{className:"w-4 h-4 text-primary-foreground/70 shrink-0"}),z("div",{className:"min-w-0 flex-1 overflow-hidden",children:z("p",{className:"text-xs font-medium text-primary-foreground truncate block w-full",title:F,children:F})}),_.url&&z("a",{href:_.url,target:"_blank",rel:"noreferrer",download:F,className:"p-1 text-primary-foreground/70 hover:text-primary-foreground shrink-0 rounded-md hover:bg-primary-foreground/20 transition-colors opacity-0 group-hover/att:opacity-100",onClick:(l)=>l.stopPropagation(),title:J.download(),children:z(Wz,{className:"w-3.5 h-3.5"})})]},_.id)})})]}),L.length>0&&K("div",{className:"mt-2.5 w-full",children:[z("div",{className:"text-xs font-medium text-primary-foreground/70 mb-1",children:J.assets()}),z("div",{className:"flex flex-col gap-1.5 w-full",children:L.map((_)=>K("div",{className:"flex items-center justify-between w-full h-9 px-2.5 rounded-lg border border-primary-foreground/15 bg-primary-foreground/10 hover:bg-primary-foreground/15 transition-colors overflow-hidden",children:[K("div",{className:"flex items-center gap-2.5 min-w-0 flex-1",children:[_.type==="folder"?z(Xz,{className:"w-4 h-4 text-primary-foreground/70 shrink-0"}):z(m,{className:"w-4 h-4 text-primary-foreground/70 shrink-0"}),z("span",{className:"text-xs font-medium truncate text-primary-foreground",title:_.name,children:_.name})]}),z("span",{className:"text-[10px] text-primary-foreground/60 uppercase shrink-0 font-mono ml-2",children:_.type})]},_.id))})]})]})},G.id)}let V=Y.content||"";return z("div",{className:"text-center text-xs text-muted-foreground italic bg-muted/20 py-1.5 rounded",children:g(V)},G.id)}case"assistant":{let V=G.content;if(!V)return null;let Z=[];if(V.forEach(($,U)=>{if(!$||typeof $!=="object")return;let D=$;switch(D.type){case"text":{let W=D.text;if(typeof W!=="string"||!W.trim())return;Z.push(z("div",{className:"text-sm leading-[1.8] prose prose-sm dark:prose-invert max-w-none break-words",children:z(r,{components:{pre:({node:O,...B})=>z("pre",{className:"whitespace-pre-wrap break-all break-words bg-muted text-foreground p-4 rounded-md border border-border/50 font-mono text-sm",...B})},children:Jz(W)})},`txt-${U}`));break}case"thinking":{let W=D.thinking;if(typeof W!=="string"||!W.trim())return;Z.push(K("details",{className:"group border border-border/50 rounded-lg bg-muted/20 my-2 overflow-hidden",children:[K("summary",{className:"flex items-center gap-2 p-2.5 text-xs font-medium text-muted-foreground select-none cursor-pointer hover:bg-muted/40 transition-colors list-none [&::-webkit-details-marker]:hidden",children:[z(Vz,{className:"h-3.5 w-3.5 text-primary/70 animate-pulse"}),z("span",{children:J.role_thinking()||"Thinking"}),z(d,{className:"h-3 w-3 ml-auto transition-transform group-open:rotate-180"})]}),z("div",{className:"p-3 pt-0 text-xs text-muted-foreground/90 border-t border-border/40 bg-muted/10 leading-relaxed prose prose-sm dark:prose-invert max-w-none whitespace-pre-wrap font-sans",children:z(r,{children:Jz(W)})})]},`think-${U}`));break}case"toolCall":{let W=String(D.name||D.toolName||J.unknown()),O=D.arguments||D.args;Z.push(K("details",{className:"group border border-border/50 rounded-lg bg-violet-500/5 my-2 overflow-hidden",children:[K("summary",{className:"flex items-center gap-2 p-2.5 text-xs font-semibold text-violet-600 dark:text-violet-400 select-none cursor-pointer hover:bg-violet-500/10 transition-colors list-none [&::-webkit-details-marker]:hidden",children:[z(Nz,{className:"h-3.5 w-3.5"}),z("span",{children:J.calling_tool()}),z("span",{className:"font-mono bg-violet-500/10 px-1.5 py-0.5 rounded text-[11px] text-violet-700 dark:text-violet-300",children:W}),z(d,{className:"h-3 w-3 ml-auto transition-transform group-open:rotate-180"})]}),!!O&&K("div",{className:"p-3 pt-0 text-[10px] text-muted-foreground/90 border-t border-border/40 bg-violet-500/5 font-sans",children:[z("div",{className:"text-[9px] text-muted-foreground/60 uppercase font-bold tracking-wider mb-1.5",children:J.tool_arguments()||"Arguments"}),z("pre",{className:"font-mono bg-muted/30 p-2 rounded border border-border/30 overflow-x-auto max-h-32",children:JSON.stringify(O,null,2)})]})]},`tool-${U}`));break}case"image":{let W=String(D.mimeType||"image/png"),O=String(D.data||"");Z.push(z("div",{className:"my-2 max-w-full",children:O?z("img",{src:O.startsWith("data:")?O:`data:${W};base64,${O}`,alt:"Attached asset",className:"max-h-60 rounded border border-border/50 object-contain shadow-xs"}):z("div",{className:"text-xs text-muted-foreground italic flex items-center gap-1.5 py-1",children:J.image_object()})},`img-${U}`));break}default:{let W=JSON.stringify($,null,2);if(W==="{}")return;Z.push(z("pre",{className:"text-xs text-foreground/80 font-mono whitespace-pre-wrap break-words bg-muted/20 p-2 rounded",children:W},`other-${U}`))}}}),Z.length===0)return null;let L=!1;if(V.length>0){let $=V[V.length-1];if(typeof $==="string"&&$.trim().length>0)L=!0;else if($&&typeof $==="object"){let U=$;if(U.type==="text"&&typeof U.text==="string"&&U.text.trim().length>0)L=!0}}return K("div",{className:"flex flex-col w-full space-y-1",children:[z("div",{className:"space-y-2 w-full",children:Z}),L&&z("div",{className:"text-[10px] text-muted-foreground self-start italic pt-1",children:J.created_by_agent()})]},G.id)}case"toolResult":return z("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-muted/40 p-2 rounded-md border border-border/50",children:z("span",{className:"font-semibold",children:J.tool_result_with_name({name:G.toolName||"tool"})})},G.id);case"thinking_level_change":{let V=G.content||"";return z("div",{className:"text-center text-xs text-muted-foreground italic bg-muted/20 py-1.5 rounded",children:g(V)},G.id)}default:return null}};return K("div",{ref:dz,className:v("relative flex flex-col h-full bg-background transition-colors duration-200 min-h-0"),children:[mz&&z("div",{className:"absolute inset-0 bg-accent/30 border-2 border-primary z-50 pointer-events-none flex items-center justify-center p-6 text-center animate-in fade-in duration-150",children:K("div",{className:"bg-background/95 text-foreground px-4 py-3 rounded-xl border border-border/80 flex flex-col items-center gap-2 shadow-lg max-w-[80%] animate-in zoom-in-95 duration-150",children:[z(T,{className:"h-6 w-6 text-primary animate-bounce"}),z("span",{className:"text-sm font-semibold text-foreground",children:J.chatbot_drag_drop_hint()})]})}),K("div",{className:"h-12 border-b border-border flex items-center justify-between px-4 flex-shrink-0 bg-background/50 backdrop-blur-sm",children:[K("div",{className:"flex items-center gap-2",children:[P&&z("button",{onClick:()=>b(!1),className:"p-1 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer",title:J.back_to_chat(),children:z(Uz,{className:"h-4 w-4"})}),z(T,{className:"h-5 w-5 text-primary"}),z("span",{className:"font-semibold text-sm",children:P?J.history():J.shumai_agent()})]}),z("div",{className:"flex items-center gap-1",children:!P?K(x,{children:[z("button",{onClick:s,className:"p-1.5 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer",title:J.new_chat(),children:z(c,{className:"h-4 w-4"})}),z("button",{onClick:()=>b(!0),className:"p-1.5 rounded-md hover:bg-muted text-muted-foreground hover:text-foreground transition-colors cursor-pointer",title:J.history(),children:z(Lz,{className:"h-4 w-4"})})]}):K("button",{onClick:()=>{s(),b(!1)},className:"flex items-center gap-1 text-xs bg-primary text-primary-foreground px-2.5 py-1 rounded-md hover:bg-primary/90 transition-colors shadow-xs cursor-pointer",children:[z(c,{className:"h-3.5 w-3.5"}),z("span",{children:J.new_chat()})]})})]}),P?z(n,{className:"flex-1 p-3",children:o.length===0?z("div",{className:"text-center text-xs text-muted-foreground py-8",children:J.no_history_sessions()}):z("div",{className:"space-y-1",children:o.map((G)=>{let Y=G.id===hz;return K("div",{onClick:()=>{if(N)uz(N,G.id),b(!1)},className:v("group flex items-center justify-between p-2.5 rounded-lg text-xs cursor-pointer transition-all border border-transparent",Y?"bg-accent/80 text-accent-foreground font-medium border-border/40":"hover:bg-muted/60 text-muted-foreground hover:text-foreground"),children:[K("div",{className:"flex flex-col min-w-0 pr-2",children:[z("span",{className:"truncate text-foreground font-medium text-xs",children:G.name||J.untitled_session()}),z("span",{className:"text-[10px] text-muted-foreground",children:Oz(G.updatedAt)})]}),z("button",{onClick:(V)=>{if(V.stopPropagation(),N&&window.confirm(J.delete_session_confirm()))fz(N,G.id)},className:"opacity-0 group-hover:opacity-100 focus:opacity-100 transition-opacity text-muted-foreground hover:text-destructive p-1 rounded hover:bg-muted cursor-pointer",title:J.delete_session(),children:z(Qz,{className:"h-4 w-4"})})]},G.id)})})}):K(x,{children:[z(n,{ref:f,className:"flex-1 p-4 min-h-0 [&>div>div]:!block",children:E.length===0?K("div",{className:"flex flex-col items-center justify-center h-48 border-2 border-dashed border-border rounded-lg text-muted-foreground p-4 text-center",children:[z(T,{className:"h-8 w-8 mb-2 opacity-50 text-muted-foreground"}),z("p",{className:"text-sm",children:J.chatbot_drag_drop_hint()})]}):K("div",{className:"space-y-4 pb-4",children:[E.map(nz),k&&E.length>0&&(E[E.length-1].role==="user"||E[E.length-1].customType==="shumai_message")&&K("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground italic",children:[z($z,{className:"h-3 w-3 animate-spin text-primary"}),z("span",{children:J.thinking_status()})]}),z("div",{ref:Gz})]})}),z("div",{className:"p-2 flex-shrink-0 bg-background",children:z(Tz,{projectId:Q,value:gz,onChangeText:jz,placeholder:J.type_a_message(),disabled:!w||!N,isStreaming:k,onAbort:()=>{if(N)Iz(N)},allowMentions:!1,allowAttachments:!0,workspaceAssets:Az,onRemoveWorkspaceAsset:Sz,allowMarkup:!0,canMarkup:!!q&&["image","video","pdf"].includes(q.proxyType||""),markupDisabledTooltip:!q?J.open_file_to_add_markup():J.markup_not_supported_for_this_file(),allowTimestamp:q?.proxyType==="video"||q?.proxyType==="pdf",currentTime:Mz,frameRate:y||q?.media?.metadata?.frameRate||30,startTimecode:i||q?.media?.metadata?.startTimecode,formatTimestamp:S||(q?.proxyType==="pdf"?(G)=>J.page_prefix({page:Math.round(G)}):void 0),onTyping:yz,onSendMessage:(G,Y,V,Z,L,$)=>{if(!N)return;pz(N,G,Q,C,cz,Y,V,L,$)},bottomLeftExtra:z("div",{className:"flex items-center gap-1.5 min-w-0 max-w-full",children:R.length>0?K(Fz,{value:w||"",onValueChange:(G)=>h(G),disabled:k,children:[z(Bz,{className:"h-8 border-none bg-transparent hover:bg-muted text-muted-foreground hover:text-foreground focus:ring-0 focus:ring-offset-0 px-2 py-0 gap-1.5 text-xs shrink-0 select-none shadow-none max-w-full cursor-pointer",children:z(Hz,{placeholder:J.select_agent()})}),z(Cz,{children:R.map((G)=>z(Rz,{value:G.id,className:"cursor-pointer",children:K("div",{className:"flex items-center gap-2",children:[G.avatar?z("img",{src:G.avatar,alt:G.name,className:"w-4 h-4 rounded-full object-cover"}):z(T,{className:"w-4 h-4 text-muted-foreground"}),z("span",{className:"text-xs",children:G.name})]})},G.id))})]}):z("div",{className:"flex items-center gap-1.5 px-2 py-1 text-[11px] text-muted-foreground/60 italic select-none",children:z("span",{children:J.no_chat_agents_warning()})})})})})]}),A&&K("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:()=>u(null),children:[z("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 cursor-pointer",children:z(Dz,{className:"w-8 h-8"})}),z("div",{className:"w-full h-full flex items-center justify-center p-2",children:z("img",{src:A.url,alt:A.name,className:"max-w-full max-h-[85vh] object-contain rounded shadow-2xl cursor-zoom-out",onClick:(G)=>{G.stopPropagation(),u(null)}})}),z("div",{className:"absolute bottom-6 text-white text-sm font-medium bg-black/50 px-4 py-2 rounded-full backdrop-blur-sm",children:A.name})]})]})}
2
+ export{NG as h};
@@ -1,5 +1,5 @@
1
1
  // @bun
2
- import{zm as K}from"./chunk-tn67sjb2.js";import{Bm as C}from"./chunk-9k76s3y6.js";import{$m as j,_m as T}from"./chunk-xzag8w1v.js";import{gn as _,in as $,jn as V}from"./chunk-kvnfgr29.js";import"./chunk-p49h5fxs.js";class W extends Error{code;diagnosticDetails;constructor(F,q,z){super(F);this.name="PiMessagesResponseError",this.code=q,this.diagnosticDetails=z}}function A(F){try{let q=JSON.parse(F),z=q?.error;return q&&typeof z==="object"&&z!==null&&!Array.isArray(z)?q:void 0}catch{return}}function D(F){return F.length>8192?`${F.slice(0,8192)}\u2026`:F}function h(F,q,z){let k=typeof z?.error?.message==="string"?z.error.message:void 0,G=typeof z?.error?.code==="string"?z.error.code:void 0,H=k??q,I=G?` (${G})`:"";return`${F.status} ${F.statusText}: ${H}${I}`}function J(F,q,z,k){let G=A(k),H=typeof G?.error?.code==="string"?G.error.code:void 0;return new W(h(z,k,G),H,{version:1,provider:F.provider,model:F.id,url:q.toString(),status:z.status,statusText:z.statusText,error:G?.error,body:G?void 0:D(k),timestampMs:Date.now()})}function U(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function Y(F,q){if(!q)return;V(F,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...q}})}function w(F){let q={role:"assistant",content:[],api:F.api,provider:F.provider,model:F.id,usage:U(),stopReason:"stop",timestamp:Date.now()},z=new Map;return(k)=>{switch(k.type){case"done":return Object.assign(q,{stopReason:k.reason,usage:k.usage,responseId:k.responseId}),Y(q,k.rewrite),{type:"done",reason:k.reason,message:q};case"error":return Object.assign(q,{stopReason:k.reason,usage:k.usage,errorMessage:k.errorMessage,responseId:k.responseId}),Y(q,k.rewrite),{type:"error",reason:k.reason,error:q};case"start":break;case"text_start":q.content[k.contentIndex]={type:"text",text:""};break;case"text_delta":q.content[k.contentIndex].text+=k.delta;break;case"text_end":Object.assign(q.content[k.contentIndex],{text:k.content,textSignature:k.contentSignature});break;case"thinking_start":q.content[k.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":q.content[k.contentIndex].thinking+=k.delta;break;case"thinking_end":Object.assign(q.content[k.contentIndex],{thinking:k.content,thinkingSignature:k.contentSignature,redacted:k.redacted});break;case"toolcall_start":q.content[k.contentIndex]={type:"toolCall",id:k.id,name:k.toolName,arguments:{}},z.set(k.contentIndex,"");break;case"toolcall_delta":{let G=`${z.get(k.contentIndex)??""}${k.delta}`;z.set(k.contentIndex,G),q.content[k.contentIndex].arguments=C(G);break}case"toolcall_end":return Object.assign(q.content[k.contentIndex],k.toolCall),z.delete(k.contentIndex),{type:"toolcall_end",contentIndex:k.contentIndex,toolCall:q.content[k.contentIndex],partial:q}}return{...k,partial:q}}}async function*S(F){let q=new TextDecoder,z=F.getReader(),k="";try{while(!0){let{done:G,value:H}=await z.read();k+=G?q.decode():q.decode(H,{stream:!0}),k=k.replace(/\r\n/g,`
2
+ import{Hm as K}from"./chunk-xbhw6bpz.js";import{Jm as C}from"./chunk-jc1vb7rj.js";import{gn as T,hn as j}from"./chunk-6w2wmvqs.js";import{on as _,qn as $,rn as V}from"./chunk-1phqxp6z.js";import"./chunk-dxyq9h8n.js";class W extends Error{code;diagnosticDetails;constructor(F,q,z){super(F);this.name="PiMessagesResponseError",this.code=q,this.diagnosticDetails=z}}function A(F){try{let q=JSON.parse(F),z=q?.error;return q&&typeof z==="object"&&z!==null&&!Array.isArray(z)?q:void 0}catch{return}}function D(F){return F.length>8192?`${F.slice(0,8192)}\u2026`:F}function h(F,q,z){let k=typeof z?.error?.message==="string"?z.error.message:void 0,G=typeof z?.error?.code==="string"?z.error.code:void 0,H=k??q,I=G?` (${G})`:"";return`${F.status} ${F.statusText}: ${H}${I}`}function J(F,q,z,k){let G=A(k),H=typeof G?.error?.code==="string"?G.error.code:void 0;return new W(h(z,k,G),H,{version:1,provider:F.provider,model:F.id,url:q.toString(),status:z.status,statusText:z.statusText,error:G?.error,body:G?void 0:D(k),timestampMs:Date.now()})}function U(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function Y(F,q){if(!q)return;V(F,{type:"pi_messages_rewrite",timestamp:Date.now(),details:{...q}})}function w(F){let q={role:"assistant",content:[],api:F.api,provider:F.provider,model:F.id,usage:U(),stopReason:"stop",timestamp:Date.now()},z=new Map;return(k)=>{switch(k.type){case"done":return Object.assign(q,{stopReason:k.reason,usage:k.usage,responseId:k.responseId}),Y(q,k.rewrite),{type:"done",reason:k.reason,message:q};case"error":return Object.assign(q,{stopReason:k.reason,usage:k.usage,errorMessage:k.errorMessage,responseId:k.responseId}),Y(q,k.rewrite),{type:"error",reason:k.reason,error:q};case"start":break;case"text_start":q.content[k.contentIndex]={type:"text",text:""};break;case"text_delta":q.content[k.contentIndex].text+=k.delta;break;case"text_end":Object.assign(q.content[k.contentIndex],{text:k.content,textSignature:k.contentSignature});break;case"thinking_start":q.content[k.contentIndex]={type:"thinking",thinking:""};break;case"thinking_delta":q.content[k.contentIndex].thinking+=k.delta;break;case"thinking_end":Object.assign(q.content[k.contentIndex],{thinking:k.content,thinkingSignature:k.contentSignature,redacted:k.redacted});break;case"toolcall_start":q.content[k.contentIndex]={type:"toolCall",id:k.id,name:k.toolName,arguments:{}},z.set(k.contentIndex,"");break;case"toolcall_delta":{let G=`${z.get(k.contentIndex)??""}${k.delta}`;z.set(k.contentIndex,G),q.content[k.contentIndex].arguments=C(G);break}case"toolcall_end":return Object.assign(q.content[k.contentIndex],k.toolCall),z.delete(k.contentIndex),{type:"toolcall_end",contentIndex:k.contentIndex,toolCall:q.content[k.contentIndex],partial:q}}return{...k,partial:q}}}async function*S(F){let q=new TextDecoder,z=F.getReader(),k="";try{while(!0){let{done:G,value:H}=await z.read();k+=G?q.decode():q.decode(H,{stream:!0}),k=k.replace(/\r\n/g,`
3
3
  `);let I=k.indexOf(`
4
4
 
5
5
  `);while(I!==-1){let N=Z(k.slice(0,I));if(N)yield N;k=k.slice(I+2),I=k.indexOf(`
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{Ac as Mk,Cc as YW,Dc as Ch,Wb as c,Xb as V,Yb as _k,Zb as ek,_b as kW,ac as GW,cc as _,dc as kk,ec as h,fc as dk,gc as j,ic as J,mc as I,nc as zk,oc as x,pc as hk,qc as Kk,rc as pW,sc as y,tc as dW,uc as v,vc as fk,wc as Xk,xc as w,yc as sW,zc as TW}from"./chunk-8rcfhfq5.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["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 Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{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(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["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"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
3
- export{z as sb,S as tb,pk as ub,ah as vb,t as wb,D$ as xb,R3 as yb,rk as zb,Q as Ab,L as Bb,K as Cb,Y as Db,Vh as Eb,T as Fb,ZW as Gb,Th as Hb,QW as Ib,Pk as Jb,Oh as Kb,l as Lb,yW as Mb,gh as Nb,p as Ob,oh as Pb,F as Qb,J$ as Rb,l3 as Sb};
2
+ import{$b as kW,Ac as TW,Bc as Mk,Dc as YW,Ec as Ch,Xb as c,Yb as V,Zb as _k,_b as ek,bc as GW,dc as _,ec as kk,fc as h,gc as dk,hc as j,jc as J,nc as I,oc as zk,pc as x,qc as hk,rc as Kk,sc as pW,tc as y,uc as dW,vc as v,wc as fk,xc as Xk,yc as w,zc as sW}from"./chunk-rgthkvgx.js";function z(k){return kk(k)&&_(k.toOperationNode)}var Q=h({is(k){return k.kind==="ValueNode"},create(k){return h({kind:"ValueNode",value:k})},createImmediate(k){return h({kind:"ValueNode",value:k,immediate:!0})}});var S=h({is(k){return k.kind==="ColumnNode"},create(k){return h({kind:"ColumnNode",column:J.create(k)})}});var pk=h({is(k){return k.kind==="SelectAllNode"},create(){return h({kind:"SelectAllNode"})}});var Ak=h({is(k){return k.kind==="ReferenceNode"},create(k,W){return h({kind:"ReferenceNode",table:W,column:k})},createSelectAll(k){return h({kind:"ReferenceNode",table:k,column:pk.create()})}});function ok(k){return kk(k)&&"expressionType"in k&&z(k)}function iW(k){return kk(k)&&"expression"in k&&V(k.alias)&&z(k)}var a=h({is(k){return k.kind==="SelectModifierNode"},create(k,W){return h({kind:"SelectModifierNode",modifier:k,of:W})},createWithExpression(k){return h({kind:"SelectModifierNode",rawModifier:k})}});var Yk=h({is(k){return k.kind==="BinaryOperationNode"},create(k,W,$){return h({kind:"BinaryOperationNode",leftOperand:k,operator:W,rightOperand:$})}});var sk=h({is(k){return k.kind==="PrimitiveValueListNode"},create(k){return h({kind:"PrimitiveValueListNode",values:h([...k])})}});var rk=h({is(k){return k.kind==="ValueListNode"},create(k){return h({kind:"ValueListNode",values:h(k)})}});function lW(k){if(j(k))return ih(k);return X(k)}function X(k){if(Wk(k))return p(k);return Q.create(k)}function WW(k){return _k(k)||ek(k)||kW(k)}function Bk(k){if(!WW(k))throw Error(`unsafe immediate value ${JSON.stringify(k)}`);return Q.createImmediate(k)}function ih(k){if(k.some(Wk))return rk.create(k.map((W)=>X(W)));return sk.create(k)}function L(k){if(k.length===3)return hW(k[0],k[1],k[2]);else if(k.length===1)return X(k[0]);throw Error(`invalid arguments: ${JSON.stringify(k)}`)}function hW(k,W,$){if(lh(W)&&oW($))return Yk.create(f(k),PW(W),Q.createImmediate($));return Yk.create(f(k),PW(W),lW($))}function m(k,W,$){return Yk.create(f(k),PW(W),f($))}function UW(k,W){return mk(Object.entries(k).filter(([,$])=>!c($)).map(([$,M])=>hW($,oW(M)?"is":"=",M)),W)}function mk(k,W,$=!0){let M=W==="and"?x.create:hk.create;if(k.length===0)return Yk.create(Q.createImmediate(1),y.create("="),Q.createImmediate(W==="and"?1:0));let G=aW(k[0]);for(let q=1;q<k.length;++q)G=M(G,aW(k[q]));if(k.length>1&&$)return Xk.create(G);return G}function lh(k){return k==="is"||k==="is not"}function oW(k){return kW(k)||ek(k)}function PW(k){if(V(k)&&pW.includes(k))return y.create(k);if(z(k))return k.toOperationNode();throw Error(`invalid operator ${JSON.stringify(k)}`)}function aW(k){return z(k)?k.toOperationNode():k}var $k=h({is(k){return k.kind==="OrderByNode"},create(k){return h({kind:"OrderByNode",items:h([...k])})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var VW=h({is(k){return k.kind==="PartitionByNode"},create(k){return h({kind:"PartitionByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var xk=h({is(k){return k.kind==="OverNode"},create(){return h({kind:"OverNode"})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithPartitionByItems(k,W){return h({...k,partitionBy:k.partitionBy?VW.cloneWithItems(k.partitionBy,W):VW.create(W)})}});var Vk=h({is(k){return k.kind==="FromNode"},create(k){return h({kind:"FromNode",froms:h(k)})},cloneWithFroms(k,W){return h({...k,froms:h([...k.froms,...W])})}});var wW=h({is(k){return k.kind==="GroupByNode"},create(k){return h({kind:"GroupByNode",items:h(k)})},cloneWithItems(k,W){return h({...k,items:h([...k.items,...W])})}});var FW=h({is(k){return k.kind==="HavingNode"},create(k){return h({kind:"HavingNode",having:k})},cloneWithOperation(k,W,$){return h({...k,having:W==="And"?x.create(k.having,$):hk.create(k.having,$)})}});var o=h({is(k){return k.kind==="UpdateQueryNode"},create(k,W){return h({kind:"UpdateQueryNode",table:k.length===1?k[0]:sW.create(k),...W&&{with:W}})},createWithoutTable(){return h({kind:"UpdateQueryNode"})},cloneWithFromItems(k,W){return h({...k,from:k.from?Vk.cloneWithFroms(k.from,W):Vk.create(W)})},cloneWithUpdates(k,W){return h({...k,updates:k.updates?h([...k.updates,...W]):W})},cloneWithLimit(k,W){return h({...k,limit:W})}});var Dk=h({is(k){return k.kind==="DeleteQueryNode"},create(k,W){return h({kind:"DeleteQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithUsing(k,W){return h({...k,using:k.using!==void 0?TW.cloneWithTables(k.using,W):TW.create(W)})}});var C=h({is(k){return k.kind==="WhereNode"},create(k){return h({kind:"WhereNode",where:k})},cloneWithOperation(k,W,$){return h({...k,where:W==="And"?x.create(k.where,$):hk.create(k.where,$)})}});var vW=h({is(k){return k.kind==="ReturningNode"},create(k){return h({kind:"ReturningNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var rW=h({is(k){return k.kind==="ExplainNode"},create(k,W){return h({kind:"ExplainNode",format:k,options:W})}});var N=h({is(k){return k.kind==="MergeQueryNode"},create(k,W){return h({kind:"MergeQueryNode",into:k,...W&&{with:W}})},cloneWithUsing(k,W){return h({...k,using:W})},cloneWithWhen(k,W){return h({...k,whens:k.whens?h([...k.whens,W]):h([W])})},cloneWithThen(k,W){return h({...k,whens:k.whens?h([...k.whens.slice(0,-1),Mk.cloneWithResult(k.whens[k.whens.length-1],W)]):void 0})}});var AW=h({is(k){return k.kind==="OutputNode"},create(k){return h({kind:"OutputNode",selections:h(k)})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})}});var K=h({is(k){return Y.is(k)||w.is(k)||o.is(k)||Dk.is(k)||N.is(k)},cloneWithEndModifier(k,W){return h({...k,endModifiers:k.endModifiers?h([...k.endModifiers,W]):h([W])})},cloneWithWhere(k,W){return h({...k,where:k.where?C.cloneWithOperation(k.where,"And",W):C.create(W)})},cloneWithJoin(k,W){return h({...k,joins:k.joins?h([...k.joins,W]):h([W])})},cloneWithReturning(k,W){return h({...k,returning:k.returning?vW.cloneWithSelections(k.returning,W):vW.create(W)})},cloneWithoutReturning(k){return h({...k,returning:void 0})},cloneWithoutWhere(k){return h({...k,where:void 0})},cloneWithExplain(k,W,$){return h({...k,explain:rW.create(W,$?.toOperationNode())})},cloneWithTop(k,W){return h({...k,top:W})},cloneWithOutput(k,W){return h({...k,output:k.output?AW.cloneWithSelections(k.output,W):AW.create(W)})},cloneWithOrderByItems(k,W){return h({...k,orderBy:k.orderBy?$k.cloneWithItems(k.orderBy,W):$k.create(W)})},cloneWithoutOrderBy(k){return h({...k,orderBy:void 0})}});var Y=h({is(k){return k.kind==="SelectQueryNode"},create(k){return h({kind:"SelectQueryNode",...k&&{with:k}})},createFrom(k,W){return h({kind:"SelectQueryNode",from:Vk.create(k),...W&&{with:W}})},cloneWithSelections(k,W){return h({...k,selections:k.selections?h([...k.selections,...W]):h(W)})},cloneWithDistinctOn(k,W){return h({...k,distinctOn:k.distinctOn?h([...k.distinctOn,...W]):h(W)})},cloneWithFrontModifier(k,W){return h({...k,frontModifiers:k.frontModifiers?h([...k.frontModifiers,W]):h([W])})},cloneWithOrderByItems:(k,W)=>K.cloneWithOrderByItems(k,W),cloneWithGroupByItems(k,W){return h({...k,groupBy:k.groupBy?wW.cloneWithItems(k.groupBy,W):wW.create(W)})},cloneWithLimit(k,W){return h({...k,limit:W})},cloneWithOffset(k,W){return h({...k,offset:W})},cloneWithFetch(k,W){return h({...k,fetch:W})},cloneWithHaving(k,W){return h({...k,having:k.having?FW.cloneWithOperation(k.having,"And",W):FW.create(W)})},cloneWithSetOperations(k,W){return h({...k,setOperations:k.setOperations?h([...k.setOperations,...W]):h([...W])})},cloneWithoutSelections(k){return h({...k,selections:[]})},cloneWithoutLimit(k){return h({...k,limit:void 0})},cloneWithoutOffset(k){return h({...k,offset:void 0})},cloneWithoutOrderBy:(k)=>K.cloneWithoutOrderBy(k),cloneWithoutGroupBy(k){return h({...k,groupBy:void 0})}});class Rk{#k;constructor(k){this.#k=h(k)}on(...k){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,L(k))})}onRef(k,W,$){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,m(k,W,$))})}onTrue(){return new Rk({...this.#k,joinNode:Kk.cloneWithOn(this.#k.joinNode,v.createWithSql("true"))})}$call(k){return k(this)}toOperationNode(){return this.#k.joinNode}}class ah{#k;get dynamicReference(){return this.#k}get refType(){return}constructor(k){this.#k=k}toOperationNode(){return _W(this.#k)}}function $W(k){return kk(k)&&z(k)&&V(k.dynamicReference)}var g=h({is(k){return k.kind==="OrderByItemNode"},create(k,W){return h({kind:"OrderByItemNode",orderBy:k,direction:W})},cloneWith(k,W){return h({...k,...W})}});var eW=h({is(k){return k.kind==="CollateNode"},create(k){return h({kind:"CollateNode",collation:J.create(k)})}});class Lk{#k;constructor(k){this.#k=h(k)}desc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("desc")})})}asc(){return new Lk({node:g.cloneWith(this.#k.node,{direction:v.createWithSql("asc")})})}nullsLast(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"last"})})}nullsFirst(){return new Lk({node:g.cloneWith(this.#k.node,{nulls:"first"})})}collate(k){return new Lk({node:g.cloneWith(this.#k.node,{collation:eW.create(k)})})}toOperationNode(){return this.#k.node}}function RW(k){return k==="asc"||k==="desc"}function B(k){if(k.length===2)return[mW(k[0],k[1])];if(k.length===1){let[W]=k;if(Array.isArray(W))return fk("orderBy(array) is deprecated, use multiple orderBy calls instead."),W.map(($)=>mW($));return[mW(W)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${k.length}`)}function mW(k,W){let $=ph(k);if(g.is($)){if(W)throw Error("Cannot specify direction twice!");return $}return kh($,W)}function ph(k){if(Wk(k))return p(k);if($W(k))return k.toOperationNode();let[W,$]=k.split(" ");if($)return fk("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),kh(t(W),$);return t(k)}function kh(k,W){if(typeof W==="string"){if(!RW(W))throw Error(`Invalid order by direction: ${W}`);return g.create(k,v.createWithSql(W))}if(ok(W))return fk("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),g.create(k,W.toOperationNode());let $=g.create(k);if(!W)return $;return W(new Lk({node:$})).toOperationNode()}var Wh=h({is(k){return k.kind==="PartitionByItemNode"},create(k){return h({kind:"PartitionByItemNode",partitionBy:k})}});function hh(k){return Gk(k).map(Wh.create)}class Ck{#k;constructor(k){this.#k=h(k)}orderBy(...k){return new Ck({overNode:xk.cloneWithOrderByItems(this.#k.overNode,B(k))})}clearOrderBy(){return new Ck({overNode:K.cloneWithoutOrderBy(this.#k.overNode)})}partitionBy(k){return new Ck({overNode:xk.cloneWithPartitionByItems(this.#k.overNode,hh(k))})}$call(k){return k(this)}toOperationNode(){return this.#k.overNode}}var Sk=h({is(k){return k.kind==="SelectionNode"},create(k){return h({kind:"SelectionNode",selection:k})},createSelectAll(){return h({kind:"SelectionNode",selection:pk.create()})},createSelectAllFromTable(k){return h({kind:"SelectionNode",selection:Ak.createSelectAll(k)})}});class oh{#k;get table(){return this.#k}constructor(k){this.#k=k}as(k){return new $h(this.#k,k)}}class $h{#k;#W;get table(){return this.#k}get alias(){return this.#W}constructor(k,W){this.#k=k,this.#W=W}toOperationNode(){return I.create(F(this.#k),J.create(this.#W))}}function Mh(k){return kk(k)&&z(k)&&V(k.table)&&V(k.alias)}function n(k){if(j(k))return k.map((W)=>wk(W));else return[wk(k)]}function wk(k){if(V(k))return fW(k);else if(Mh(k))return k.toOperationNode();else return MW(k)}function fW(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(Kh);return I.create(F($),J.create(M))}else return F(k)}function F(k){if(k.includes(".")){let[$,M]=k.split(".").map(Kh);return zk.createWithSchema($,M)}else return zk.create(k)}function Kh(k){return k.trim()}function A(k){if(_(k))return A(k(d()));else if(j(k))return k.map((W)=>Gh(W));else return[Gh(k)]}function Gh(k){if(V(k))return Sk.create(Zh(k));else if($W(k))return Sk.create(k.toOperationNode());else return Sk.create(MW(k))}function R(k){if(!k)return[Sk.createSelectAll()];else if(Array.isArray(k))return k.map(Hh);else return[Hh(k)]}function Hh(k){if(V(k))return Sk.createSelectAllFromTable(F(k));throw Error(`invalid value selectAll expression: ${JSON.stringify(k)}`)}var Yh=h({is(k){return k.kind==="ValuesNode"},create(k){return h({kind:"ValuesNode",values:h(k)})}});var Xh=h({is(k){return k.kind==="DefaultInsertValueNode"},create(){return h({kind:"DefaultInsertValueNode"})}});function KW(k){let W=_(k)?k(d()):k,$=j(W)?W:h([W]);return sh($)}function sh(k){let W=rh(k);return[h([...W.keys()].map(S.create)),Yh.create(k.map(($)=>eh($,W)))]}function rh(k){let W=new Map;for(let $ of k){let M=Object.keys($);for(let G of M)if(!W.has(G)&&$[G]!==void 0)W.set(G,W.size)}return W}function eh(k,W){let $=Object.keys(k),M=Array.from({length:W.size}),G=!1,q=$.length;for(let ak of $){let Nk=W.get(ak);if(c(Nk)){q--;continue}let qW=k[ak];if(c(qW)||Wk(qW))G=!0;M[Nk]=qW}if(q<W.size||G){let ak=Xh.create();return rk.create(M.map((Nk)=>c(Nk)?ak:X(Nk)))}return sk.create(M)}var CW=h({is(k){return k.kind==="ColumnUpdateNode"},create(k,W){return h({kind:"ColumnUpdateNode",column:k,value:W})}});function Dh(...k){if(k.length===2)return[CW.create(f(k[0]),X(k[1]))];return ck(k[0])}function ck(k){let W=_(k)?k(d()):k;return Object.entries(W).filter(([$,M])=>M!==void 0).map(([$,M])=>{return CW.create(S.create($),X(M))})}var Lh=h({is(k){return k.kind==="OnDuplicateKeyNode"},create(k){return h({kind:"OnDuplicateKeyNode",updates:k})}});class SW{insertId;numInsertedOrUpdatedRows;constructor(k,W){this.insertId=k,this.numInsertedOrUpdatedRows=W}}class u extends Error{node;constructor(k){super("no result");this.node=k}}function s(k){return Object.prototype.hasOwnProperty.call(k,"prototype")}var E=h({is(k){return k.kind==="OnConflictNode"},create(){return h({kind:"OnConflictNode"})},cloneWith(k,W){return h({...k,...W})},cloneWithIndexWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"And",W):C.create(W)})},cloneWithIndexOrWhere(k,W){return h({...k,indexWhere:k.indexWhere?C.cloneWithOperation(k.indexWhere,"Or",W):C.create(W)})},cloneWithUpdateWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"And",W):C.create(W)})},cloneWithUpdateOrWhere(k,W){return h({...k,updateWhere:k.updateWhere?C.cloneWithOperation(k.updateWhere,"Or",W):C.create(W)})},cloneWithoutIndexWhere(k){return h({...k,indexWhere:void 0})},cloneWithoutUpdateWhere(k){return h({...k,updateWhere:void 0})}});class r{#k;constructor(k){this.#k=h(k)}column(k){let W=S.create(k);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,W]):h([W])})})}columns(k){let W=k.map(S.create);return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{columns:this.#k.onConflictNode.columns?h([...this.#k.onConflictNode.columns,...W]):h(W)})})}constraint(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{constraint:J.create(k)})})}expression(k){return new r({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{indexExpression:k.toOperationNode()})})}where(...k){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new r({...this.#k,onConflictNode:E.cloneWithIndexWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new r({...this.#k,onConflictNode:E.cloneWithoutIndexWhere(this.#k.onConflictNode)})}doNothing(){return new zh({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{doNothing:!0})})}doUpdateSet(k){return new yk({...this.#k,onConflictNode:E.cloneWith(this.#k.onConflictNode,{updates:ck(k)})})}$call(k){return k(this)}}class zh{#k;constructor(k){this.#k=h(k)}toOperationNode(){return this.#k.onConflictNode}}class yk{#k;constructor(k){this.#k=h(k)}where(...k){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,L(k))})}whereRef(k,W,$){return new yk({...this.#k,onConflictNode:E.cloneWithUpdateWhere(this.#k.onConflictNode,m(k,W,$))})}clearWhere(){return new yk({...this.#k,onConflictNode:E.cloneWithoutUpdateWhere(this.#k.onConflictNode)})}$call(k){return k(this)}toOperationNode(){return this.#k.onConflictNode}}var Jh=h({is(k){return k.kind==="TopNode"},create(k,W){return h({kind:"TopNode",expression:k,modifiers:W})}});function i(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid top expression: ${k}`);if(!c(W)&&!k$(W))throw Error(`Invalid top modifiers: ${W}`);return Jh.create(k,W)}function k$(k){return k==="percent"||k==="with ties"||k==="percent with ties"}var Fk=h({is(k){return k.kind==="OrActionNode"},create(k){return h({kind:"OrActionNode",action:k})}});class D{#k;constructor(k){this.#k=h(k)}values(k){let[W,$]=KW(k);return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:W,values:$})})}columns(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{columns:h(k.map(S.create))})})}expression(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{values:p(k)})})}defaultValues(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{defaultValues:!0})})}modifyEnd(k){return new D({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}ignore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orIgnore(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("ignore")})})}orAbort(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("abort")})})}orFail(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("fail")})})}orReplace(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("replace")})})}orRollback(){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{orAction:Fk.create("rollback")})})}top(k,W){return new D({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}onConflict(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onConflict:k(new r({onConflictNode:E.create()})).toOperationNode()})})}onDuplicateKeyUpdate(k){return new D({...this.#k,queryNode:w.cloneWith(this.#k.queryNode,{onDuplicateKey:Lh.create(ck(k))})})}returning(k){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(){return new D({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R())})}output(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new D({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new D({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new D({...this.#k})}$castTo(){return new D(this.#k)}$narrowType(){return new D(this.#k)}$assertType(){return new D(this.#k)}withPlugin(k){return new D({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new SW(W.insertId,W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new D({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}class IW{numDeletedRows;constructor(k){this.numDeletedRows=k}}var Ik=h({is(k){return k.kind==="LimitNode"},create(k){return h({kind:"LimitNode",limit:k})}});var P;class HW{#k;constructor(k){this.#k=h(k)}where(...k){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new P({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new P({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new P({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(k){return new P({...this.#k,queryNode:Dk.cloneWithUsing(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new P({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}returning(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new P({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new P({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}clearReturning(){return new P({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}clearLimit(){return new P({...this.#k,queryNode:Dk.cloneWithoutLimit(this.#k.queryNode)})}orderBy(...k){return new P({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new P({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new P({...this.#k,queryNode:Dk.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}modifyEnd(k){return new P({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new P({...this.#k})}$castTo(){return new P(this.#k)}$narrowType(){return new P(this.#k)}$assertType(){return new P(this.#k)}withPlugin(k){return new P({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new IW(W.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new P({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}P=HW;class jW{numUpdatedRows;numChangedRows;constructor(k,W){this.numUpdatedRows=k,this.numChangedRows=W}}var U;class jk{#k;constructor(k){this.#k=h(k)}where(...k){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new U({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}clearWhere(){return new U({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}top(k,W){return new U({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}from(k){return new U({...this.#k,queryNode:o.cloneWithFromItems(this.#k.queryNode,n(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}#W(k,W){return new U({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new U({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}clearOrderBy(){return new U({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}limit(k){return new U({...this.#k,queryNode:o.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}set(...k){return new U({...this.#k,queryNode:o.cloneWithUpdates(this.#k.queryNode,Dh(...k))})}returning(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new U({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new U({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}modifyEnd(k){return new U({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}clearReturning(){return new U({...this.#k,queryNode:K.cloneWithoutReturning(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new U({...this.#k})}$castTo(){return new U(this.#k)}$narrowType(){return new U(this.#k)}$assertType(){return new U(this.#k)}withPlugin(k){return new U({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new jW(W.numAffectedRows??BigInt(0),W.numChangedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new U({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}U=jk;var EW=h({is(k){return k.kind==="CommonTableExpressionNameNode"},create(k,W){return h({kind:"CommonTableExpressionNameNode",table:zk.create(k),columns:W?h(W.map(S.create)):void 0})}});var Ek=h({is(k){return k.kind==="CommonTableExpressionNode"},create(k,W){return h({kind:"CommonTableExpressionNode",name:k,expression:W})},cloneWith(k,W){return h({...k,...W})}});class gk{#k;constructor(k){this.#k=h(k)}materialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!0})})}notMaterialized(){return new gk({...this.#k,node:Ek.cloneWith(this.#k.node,{materialized:!1})})}toOperationNode(){return this.#k.node}}function OW(k,W){let $=W(Ph()).toOperationNode();if(_(k))return k(W$($)).toOperationNode();return Ek.create(qh(k),$)}function W$(k){return(W)=>{return new gk({node:Ek.create(qh(W),k)})}}function qh(k){if(k.includes("(")){let W=k.split(/[\(\)]/),$=W[0],M=W[1].split(",").map((G)=>G.trim());return EW.create($,M)}else return EW.create(k)}var tk=h({is(k){return k.kind==="WithNode"},create(k,W){return h({kind:"WithNode",expressions:h([k]),...W})},cloneWithExpression(k,W){return h({...k,expressions:h([...k.expressions,W])})}});var Uh=["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 Vh(k){let W="";for(let $=0;$<k;++$)W+=h$();return W}function h$(){return Uh[~~(Math.random()*Uh.length)]}function T(){return new wh}class wh{#k;get queryId(){if(this.#k===void 0)this.#k=Vh(8);return this.#k}}var Fh=h({is(k){return k.kind==="MatchedNode"},create(k,W=!1){return h({kind:"MatchedNode",not:k,bySource:W})}});function bW(k,W,$){return Mk.create(mk([Fh.create(!k.isMatched,k.bySource),...W&&W.length>0?[W.length===3&&$?m(W[0],W[1],W[2]):L(W)]:[]],"and",!1))}function Ok(k){if(V(k))return v.create([k],[]);if(z(k))return k.toOperationNode();return k}class ZW{#k;#W;#h;constructor(){this.#k=new Promise((k,W)=>{this.#h=W,this.#W=k})}get promise(){return this.#k}resolve=(k)=>{if(this.#W)this.#W(k)};reject=(k)=>{if(this.#h)this.#h(k)}}async function Th(k){let W=new ZW,$=new ZW;return k.provideConnection(async(M)=>{return W.resolve(M),await $.promise}).catch((M)=>W.reject(M)),h({connection:await W.promise,release:$.resolve})}var $$=h([]);class QW{#k;constructor(k=$$){this.#k=k}get plugins(){return this.#k}transformQuery(k,W){for(let $ of this.#k){let M=$.transformQuery({node:k,queryId:W});if(M.kind===k.kind)k=M;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${k.kind}`,`but it returned a ${M.kind}`].join(" "))}return k}async executeQuery(k){return await this.provideConnection(async(W)=>{let $=await W.executeQuery(k);if("numUpdatedOrDeletedRows"in $)fk("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#W($,k.queryId)})}async*stream(k,W){let{connection:$,release:M}=await Th(this);try{for await(let G of $.streamQuery(k,W))yield await this.#W(G,k.queryId)}finally{M()}}async#W(k,W){for(let $ of this.#k)k=await $.transformResult({result:k,queryId:W});return k}}class bk extends QW{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(k){return new bk([...this.plugins,k])}withPlugins(k){return new bk([...this.plugins,...k])}withPluginAtFront(k){return new bk([k,...this.plugins])}withoutPlugins(){return new bk([])}}var qk=new bk;class NW{numChangedRows;constructor(k){this.numChangedRows=k}}class Hk{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new Hk({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new Hk({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}using(...k){return new O({...this.#k,queryNode:N.cloneWithUsing(this.#k.queryNode,Jk("Using",k))})}returning(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new Hk({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new Hk({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}}class O{#k;constructor(k){this.#k=h(k)}modifyEnd(k){return new O({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,k.toOperationNode())})}top(k,W){return new O({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}whenMatched(){return this.#W([])}whenMatchedAnd(...k){return this.#W(k)}whenMatchedAndRef(k,W,$){return this.#W([k,W,$],!0)}#W(k,W){return new BW({...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!0},k,W))})}whenNotMatched(){return this.#h([])}whenNotMatchedAnd(...k){return this.#h(k)}whenNotMatchedAndRef(k,W,$){return this.#h([k,W,$],!0)}whenNotMatchedBySource(){return this.#h([],!1,!0)}whenNotMatchedBySourceAnd(...k){return this.#h(k,!1,!0)}whenNotMatchedBySourceAndRef(k,W,$){return this.#h([k,W,$],!0,!0)}returning(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,A(k))})}returningAll(k){return new O({...this.#k,queryNode:K.cloneWithReturning(this.#k.queryNode,R(k))})}output(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,A(k))})}outputAll(k){return new O({...this.#k,queryNode:K.cloneWithOutput(this.#k.queryNode,R(k))})}#h(k,W=!1,$=!1){let M={...this.#k,queryNode:N.cloneWithWhen(this.#k.queryNode,bW({isMatched:!1,bySource:$},k,W))};return new($?BW:vh)(M)}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new O({...this.#k})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile(),W=await this.#k.executor.executeQuery(k),{adapter:$}=this.#k.executor,M=k.query;if(M.returning&&$.supportsReturning||M.output&&$.supportsOutput)return W.rows;return[new NW(W.numAffectedRows)]}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}}class BW{#k;constructor(k){this.#k=h(k)}thenDelete(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("delete"))})}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenUpdate(k){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(k(new jk({queryId:this.#k.queryId,executor:qk,queryNode:o.createWithoutTable()}))))})}thenUpdateSet(...k){return this.thenUpdate((W)=>W.set(...k))}}class vh{#k;constructor(k){this.#k=h(k)}thenDoNothing(){return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok("do nothing"))})}thenInsertValues(k){let[W,$]=KW(k);return new O({...this.#k,queryNode:N.cloneWithThen(this.#k.queryNode,Ok(w.cloneWith(w.createWithoutInto(),{columns:W,values:$})))})}}class Pk{#k;constructor(k){this.#k=h(k)}selectFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.createFrom(n(k),this.#k.withNode)})}selectNoFrom(k){return nk({queryId:T(),executor:this.#k.executor,queryNode:Y.cloneWithSelections(Y.create(this.#k.withNode),A(k))})}insertInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode)})}replaceInto(k){return new D({queryId:T(),executor:this.#k.executor,queryNode:w.create(F(k),this.#k.withNode,!0)})}deleteFrom(k){return new HW({queryId:T(),executor:this.#k.executor,queryNode:Dk.create(n(k),this.#k.withNode)})}updateTable(k){return new jk({queryId:T(),executor:this.#k.executor,queryNode:o.create(n(k),this.#k.withNode)})}mergeInto(k){return new Hk({queryId:T(),executor:this.#k.executor,queryNode:N.create(fW(k),this.#k.withNode)})}with(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($)})}withRecursive(k,W){let $=OW(k,W);return new Pk({...this.#k,withNode:this.#k.withNode?tk.cloneWithExpression(this.#k.withNode,$):tk.create($,{recursive:!0})})}withPlugin(k){return new Pk({...this.#k,executor:this.#k.executor.withPlugin(k)})}withoutPlugins(){return new Pk({...this.#k,executor:this.#k.executor.withoutPlugins()})}withSchema(k){return new Pk({...this.#k,executor:this.#k.executor.withPluginAtFront(new YW(k))})}}function Ph(){return new Pk({executor:qk})}function Ah(k,W){return new Rk({joinNode:Kk.create(k,wk(W))})}function _h(){return new Ck({overNode:xk.create()})}function Jk(k,W){if(W.length===3)return K$(k,W[0],W[1],W[2]);else if(W.length===2)return M$(k,W[0],W[1]);else if(W.length===1)return G$(k,W[0]);else throw Error("not implemented")}function M$(k,W,$){return $(Ah(k,W)).toOperationNode()}function K$(k,W,$,M){return Kk.createWithOn(k,wk(W),m($,"=",M))}function G$(k,W){return Kk.create(k,wk(W))}var mh=h({is(k){return k.kind==="OffsetNode"},create(k){return h({kind:"OffsetNode",offset:k})}});var Rh=h({is(k){return k.kind==="GroupByItemNode"},create(k){return h({kind:"GroupByItemNode",groupBy:k})}});function fh(k){return k=_(k)?k(d()):k,Gk(k).map(Rh.create)}function Tk(k,W,$){if(_(W))W=W(XW());if(!j(W))W=[W];return W.map((M)=>Ch.create(k,p(M),$))}class Z{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new Z(this.#k)}$notNull(){return new Z(this.#k)}toOperationNode(){return this.#k}}class zW{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}class DW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}or(...k){return new DW(hk.create(this.#k,L(k)))}$castTo(){return new DW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}class LW{#k;constructor(k){this.#k=k}get expressionType(){return}as(k){return new zW(this,k)}and(...k){return new LW(x.create(this.#k,L(k)))}$castTo(){return new LW(this.#k)}toOperationNode(){return Xk.create(this.#k)}}var Sh=h({is(k){return k.kind==="FetchNode"},create(k,W){return{kind:"FetchNode",rowCount:Q.create(k),modifier:W}}});function Ih(k,W){if(!_k(k)&&!GW(k))throw Error(`Invalid fetch row count: ${k}`);if(!H$(W))throw Error(`Invalid fetch modifier: ${W}`);return Sh.create(k,W)}function H$(k){return k==="only"||k==="with ties"}var H;class xW{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...k){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,L(k))})}whereRef(k,W,$){return new H({...this.#k,queryNode:K.cloneWithWhere(this.#k.queryNode,m(k,W,$))})}having(...k){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,L(k))})}havingRef(k,W,$){return new H({...this.#k,queryNode:Y.cloneWithHaving(this.#k.queryNode,m(k,W,$))})}select(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,A(k))})}distinctOn(k){return new H({...this.#k,queryNode:Y.cloneWithDistinctOn(this.#k.queryNode,Gk(k))})}modifyFront(k){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}modifyEnd(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.createWithExpression(k.toOperationNode()))})}distinct(){return new H({...this.#k,queryNode:Y.cloneWithFrontModifier(this.#k.queryNode,a.create("Distinct"))})}forUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForUpdate",k?dk(k).map(F):void 0))})}forShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForShare",k?dk(k).map(F):void 0))})}forKeyShare(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForKeyShare",k?dk(k).map(F):void 0))})}forNoKeyUpdate(k){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("ForNoKeyUpdate",k?dk(k).map(F):void 0))})}skipLocked(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("SkipLocked"))})}noWait(){return new H({...this.#k,queryNode:K.cloneWithEndModifier(this.#k.queryNode,a.create("NoWait"))})}selectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSelections(this.#k.queryNode,R(k))})}innerJoin(...k){return this.#W("InnerJoin",k)}leftJoin(...k){return this.#W("LeftJoin",k)}rightJoin(...k){return this.#W("RightJoin",k)}fullJoin(...k){return this.#W("FullJoin",k)}crossJoin(...k){return this.#W("CrossJoin",k)}innerJoinLateral(...k){return this.#W("LateralInnerJoin",k)}leftJoinLateral(...k){return this.#W("LateralLeftJoin",k)}crossJoinLateral(...k){return this.#W("LateralCrossJoin",k)}crossApply(...k){return this.#W("CrossApply",k)}outerApply(...k){return this.#W("OuterApply",k)}#W(k,W){return new H({...this.#k,queryNode:K.cloneWithJoin(this.#k.queryNode,Jk(k,W))})}orderBy(...k){return new H({...this.#k,queryNode:K.cloneWithOrderByItems(this.#k.queryNode,B(k))})}groupBy(k){return new H({...this.#k,queryNode:Y.cloneWithGroupByItems(this.#k.queryNode,fh(k))})}limit(k){return new H({...this.#k,queryNode:Y.cloneWithLimit(this.#k.queryNode,Ik.create(X(k)))})}offset(k){return new H({...this.#k,queryNode:Y.cloneWithOffset(this.#k.queryNode,mh.create(X(k)))})}fetch(k,W="only"){return new H({...this.#k,queryNode:Y.cloneWithFetch(this.#k.queryNode,Ih(k,W))})}top(k,W){return new H({...this.#k,queryNode:K.cloneWithTop(this.#k.queryNode,i(k,W))})}union(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!1))})}unionAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("union",k,!0))})}intersect(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!1))})}intersectAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("intersect",k,!0))})}except(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!1))})}exceptAll(k){return new H({...this.#k,queryNode:Y.cloneWithSetOperations(this.#k.queryNode,Tk("except",k,!0))})}as(k){return new jh(this,k)}clearSelect(){return new H({...this.#k,queryNode:Y.cloneWithoutSelections(this.#k.queryNode)})}clearWhere(){return new H({...this.#k,queryNode:K.cloneWithoutWhere(this.#k.queryNode)})}clearLimit(){return new H({...this.#k,queryNode:Y.cloneWithoutLimit(this.#k.queryNode)})}clearOffset(){return new H({...this.#k,queryNode:Y.cloneWithoutOffset(this.#k.queryNode)})}clearOrderBy(){return new H({...this.#k,queryNode:K.cloneWithoutOrderBy(this.#k.queryNode)})}clearGroupBy(){return new H({...this.#k,queryNode:Y.cloneWithoutGroupBy(this.#k.queryNode)})}$call(k){return k(this)}$if(k,W){if(k)return W(this);return new H({...this.#k})}$castTo(){return new H(this.#k)}$narrowType(){return new H(this.#k)}$assertType(){return new H(this.#k)}$asTuple(){return new Z(this.toOperationNode())}$asScalar(){return new Z(this.toOperationNode())}withPlugin(k){return new H({...this.#k,executor:this.#k.executor.withPlugin(k)})}toOperationNode(){return this.#k.executor.transformQuery(this.#k.queryNode,this.#k.queryId)}compile(){return this.#k.executor.compileQuery(this.toOperationNode(),this.#k.queryId)}async execute(){let k=this.compile();return(await this.#k.executor.executeQuery(k)).rows}async executeTakeFirst(){let[k]=await this.execute();return k}async executeTakeFirstOrThrow(k=u){let W=await this.executeTakeFirst();if(W===void 0)throw s(k)?new k(this.toOperationNode()):k(this.toOperationNode());return W}async*stream(k=100){let W=this.compile(),$=this.#k.executor.stream(W,k);for await(let M of $)yield*M.rows}async explain(k,W){return await new H({...this.#k,queryNode:K.cloneWithExplain(this.#k.queryNode,k,W)}).execute()}}H=xW;function nk(k){return new xW(k)}class jh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}var e=h({is(k){return k.kind==="AggregateFunctionNode"},create(k,W=[]){return h({kind:"AggregateFunctionNode",func:k,aggregated:W})},cloneWithDistinct(k){return h({...k,distinct:!0})},cloneWithOrderBy(k,W,$=!1){let M=$?"withinGroup":"orderBy";return h({...k,[M]:k[M]?$k.cloneWithItems(k[M],W):$k.create(W)})},cloneWithFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"And",W):C.create(W)})},cloneWithOrFilter(k,W){return h({...k,filter:k.filter?C.cloneWithOperation(k.filter,"Or",W):C.create(W)})},cloneWithOver(k,W){return h({...k,over:W})}});var cW=h({is(k){return k.kind==="FunctionNode"},create(k,W){return h({kind:"FunctionNode",func:k,arguments:W})}});class b{#k;constructor(k){this.#k=h(k)}get expressionType(){return}as(k){return new Eh(this,k)}distinct(){return new b({...this.#k,aggregateFunctionNode:e.cloneWithDistinct(this.#k.aggregateFunctionNode)})}orderBy(...k){return new b({...this.#k,aggregateFunctionNode:K.cloneWithOrderByItems(this.#k.aggregateFunctionNode,B(k))})}clearOrderBy(){return new b({...this.#k,aggregateFunctionNode:K.cloneWithoutOrderBy(this.#k.aggregateFunctionNode)})}withinGroupOrderBy(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithOrderBy(this.#k.aggregateFunctionNode,B(k),!0)})}filterWhere(...k){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,L(k))})}filterWhereRef(k,W,$){return new b({...this.#k,aggregateFunctionNode:e.cloneWithFilter(this.#k.aggregateFunctionNode,m(k,W,$))})}over(k){let W=_h();return new b({...this.#k,aggregateFunctionNode:e.cloneWithOver(this.#k.aggregateFunctionNode,(k?k(W):W).toOperationNode())})}$call(k){return k(this)}$castTo(){return new b(this.#k)}$notNull(){return new b(this.#k)}toOperationNode(){return this.#k.aggregateFunctionNode}}class Eh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),J.create(this.#W))}}function Oh(){let k=($,M)=>{return new Z(cW.create($,Gk(M??[])))},W=($,M)=>{return new b({aggregateFunctionNode:e.create($,M?Gk(M):void 0)})};return Object.assign(k,{agg:W,avg($){return W("avg",[$])},coalesce(...$){return k("coalesce",$)},count($){return W("count",[$])},countAll($){return new b({aggregateFunctionNode:e.create("count",R($))})},max($){return W("max",[$])},min($){return W("min",[$])},sum($){return W("sum",[$])},any($){return k("any",[$])},jsonAgg($){return new b({aggregateFunctionNode:e.create("json_agg",[V($)?F($):$.toOperationNode()])})},toJson($){return new Z(cW.create("to_json",[V($)?F($):$.toOperationNode()]))}})}var bh=h({is(k){return k.kind==="UnaryOperationNode"},create(k,W){return h({kind:"UnaryOperationNode",operator:k,operand:W})}});function Qh(k,W){return bh.create(y.create(k),f(W))}var l=h({is(k){return k.kind==="CaseNode"},create(k){return h({kind:"CaseNode",value:k})},cloneWithWhen(k,W){return h({...k,when:h(k.when?[...k.when,W]:[W])})},cloneWithThen(k,W){return h({...k,when:k.when?h([...k.when.slice(0,-1),Mk.cloneWithResult(k.when[k.when.length-1],W)]):void 0})},cloneWith(k,W){return h({...k,...W})}});class yW{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}}class gW{#k;constructor(k){this.#k=h(k)}then(k){return new Nh({...this.#k,node:l.cloneWithThen(this.#k.node,WW(k)?Bk(k):X(k))})}}class Nh{#k;constructor(k){this.#k=h(k)}when(...k){return new gW({...this.#k,node:l.cloneWithWhen(this.#k.node,Mk.create(L(k)))})}else(k){return new Bh({...this.#k,node:l.cloneWith(this.#k.node,{else:WW(k)?Bk(k):X(k)})})}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}class Bh{#k;constructor(k){this.#k=h(k)}end(){return new Z(l.cloneWith(this.#k.node,{isStatement:!1}))}endCase(){return new Z(l.cloneWith(this.#k.node,{isStatement:!0}))}}var JW=h({is(k){return k.kind==="JSONOperatorChainNode"},create(k){return h({kind:"JSONOperatorChainNode",operator:k,values:h([])})},cloneWithValue(k,W){return h({...k,values:h([...k.values,W])})}});var tW=h({is(k){return k.kind==="JSONPathLegNode"},create(k,W){return h({kind:"JSONPathLegNode",type:k,value:W})}});var Uk=h({is(k){return k.kind==="JSONPathNode"},create(k){return h({kind:"JSONPathNode",inOperator:k,pathLegs:h([])})},cloneWithLeg(k,W){return h({...k,pathLegs:h([...k.pathLegs,W])})}});var Qk=h({is(k){return k.kind==="JSONReferenceNode"},create(k,W){return h({kind:"JSONReferenceNode",reference:k,traversal:W})},cloneWithTraversal(k,W){return h({...k,traversal:W})}});var Z$=/^#-\d+$/;class ik{#k;constructor(k){this.#k=k}at(k){if(typeof k!=="number"&&typeof k!=="string"||typeof k==="number"&&!Number.isInteger(k)||typeof k==="string"&&k!=="last"&&!Z$.test(k))throw Error(`Unexpected index value in .at(...): ${k}`);return this.#W("ArrayLocation",k)}key(k){return this.#W("Member",k)}#W(k,W){if(Qk.is(this.#k))return new uk(Qk.cloneWithTraversal(this.#k,Uk.is(this.#k.traversal)?Uk.cloneWithLeg(this.#k.traversal,tW.create(k,W)):JW.cloneWithValue(this.#k.traversal,Q.createImmediate(W))));return new uk(Uk.cloneWithLeg(this.#k,tW.create(k,W)))}}class uk extends ik{#k;constructor(k){super(k);this.#k=k}get expressionType(){return}as(k){return new xh(this,k)}$castTo(){return new uk(this.#k)}$notNull(){return new uk(this.#k)}toOperationNode(){return this.#k}}class xh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var nW=h({is(k){return k.kind==="TupleNode"},create(k){return h({kind:"TupleNode",values:h(k)})}});var Y$=["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"],X$=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],ch=h({is(k){return k.kind==="DataTypeNode"},create(k){return h({kind:"DataTypeNode",dataType:k})}});function yh(k){if(Y$.includes(k))return!0;if(X$.some((W)=>W.test(k)))return!0;return!1}function gh(k){if(z(k))return k.toOperationNode();if(yh(k))return ch.create(k);throw Error(`invalid column data type ${JSON.stringify(k)}`)}var th=h({is(k){return k.kind==="CastNode"},create(k,W){return h({kind:"CastNode",expression:k,dataType:W})}});function XW(k=qk){function W(G,q,vk){return new Z(hW(G,q,vk))}function $(G,q){return new Z(Qh(G,q))}let M=Object.assign(W,{fn:void 0,eb:void 0,selectFrom(G){return nk({queryId:T(),executor:k,queryNode:Y.createFrom(n(G))})},case(G){return new yW({node:l.create(c(G)?void 0:f(G))})},ref(G,q){if(c(q))return new Z(t(G));return new ik(nh(G,q))},jsonPath(){return new ik(Uk.create())},table(G){return new Z(F(G))},val(G){return new Z(X(G))},refTuple(...G){return new Z(nW.create(G.map(f)))},tuple(...G){return new Z(nW.create(G.map(X)))},lit(G){return new Z(Bk(G))},unary:$,not(G){return $("not",G)},exists(G){return $("exists",G)},neg(G){return $("-",G)},between(G,q,vk){return new Z(Yk.create(f(G),y.create("between"),x.create(X(q),X(vk))))},betweenSymmetric(G,q,vk){return new Z(Yk.create(f(G),y.create("between symmetric"),x.create(X(q),X(vk))))},and(G){if(j(G))return new Z(mk(G,"and"));return new Z(UW(G,"and"))},or(G){if(j(G))return new Z(mk(G,"or"));return new Z(UW(G,"or"))},parens(...G){let q=L(G);if(Xk.is(q))return new Z(q);else return new Z(Xk.create(q))},cast(G,q){return new Z(th.create(f(G),gh(q)))},withSchema(G){return XW(k.withPluginAtFront(new YW(G)))}});return M.fn=Oh(),M.eb=M,M}function d(k){return XW()}function p(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(k)}`)}function MW(k){if(z(k))return k.toOperationNode();else if(_(k))return k(d()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(k)}`)}function Wk(k){return ok(k)||iW(k)||_(k)}function _W(k){if(V(k))return t(k);return k.toOperationNode()}function Gk(k){if(j(k))return k.map((W)=>f(W));else return[f(k)]}function f(k){if(Wk(k))return p(k);return _W(k)}function nh(k,W){let $=t(k);if(dW(W))return Qk.create($,JW.create(y.create(W)));let M=W.slice(0,-1);if(dW(M))return Qk.create($,Uk.create(y.create(M)));throw Error(`Invalid JSON operator: ${W}`)}function t(k){if(!k.includes("."))return Ak.create(S.create(k));let $=k.split(".").map(uW);if($.length===3)return L$($);if($.length===2)return z$($);throw Error(`invalid column reference ${k}`)}function Zh(k){if(k.includes(" as ")){let[$,M]=k.split(" as ").map(uW);return I.create(t($),J.create(M))}else return t(k)}function D$(k){return S.create(k)}function R3(k){if(k.includes(" ")){let[$,M]=k.split(" ").map(uW);if(!RW(M))throw Error(`invalid order direction "${M}" next to "${$}"`);return B([$,M])[0]}else return D$(k)}function L$(k){let[W,$,M]=k;return Ak.create(S.create(M),zk.createWithSchema(W,$))}function z$(k){let[W,$]=k;return Ak.create(S.create($),zk.create(W))}function uW(k){return k.trim()}class lk{#k;constructor(k){this.#k=h(k)}get expressionType(){return}get isRawBuilder(){return!0}as(k){return new dh(this,k)}$castTo(){return new lk({...this.#k})}$notNull(){return new lk(this.#k)}withPlugin(k){return new lk({...this.#k,plugins:this.#k.plugins!==void 0?h([...this.#k.plugins,k]):h([k])})}toOperationNode(){return this.#h(this.#W())}compile(k){return this.#$(this.#W(k))}async execute(k){let W=this.#W(k);return W.executeQuery(this.#$(W))}#W(k){let W=k!==void 0?k.getExecutor():qk;return this.#k.plugins!==void 0?W.withPlugins(this.#k.plugins):W}#h(k){return k.transformQuery(this.#k.rawNode,this.#k.queryId)}#$(k){return k.compileQuery(this.#h(k),this.#k.queryId)}}function Zk(k){return new lk(k)}class dh{#k;#W;constructor(k,W){this.#k=k,this.#W=W}get expression(){return this.#k}get alias(){return this.#W}get rawBuilder(){return this.#k}toOperationNode(){return I.create(this.#k.toOperationNode(),z(this.#W)?this.#W.toOperationNode():J.create(this.#W))}}var J$=Object.assign((k,...W)=>{return Zk({queryId:T(),rawNode:v.create(k,W?.map(uh)??[])})},{ref(k){return Zk({queryId:T(),rawNode:v.createWithChild(t(k))})},val(k){return Zk({queryId:T(),rawNode:v.createWithChild(X(k))})},value(k){return this.val(k)},table(k){return Zk({queryId:T(),rawNode:v.createWithChild(F(k))})},id(...k){let W=Array(k.length+1).fill(".");return W[0]="",W[W.length-1]="",Zk({queryId:T(),rawNode:v.create(W,k.map(J.create))})},lit(k){return Zk({queryId:T(),rawNode:v.createWithChild(Q.createImmediate(k))})},literal(k){return this.lit(k)},raw(k){return Zk({queryId:T(),rawNode:v.createWithSql(k)})},join(k,W=J$`, `){let $=Array(Math.max(2*k.length-1,0)),M=W.toOperationNode();for(let G=0;G<k.length;++G)if($[2*G]=uh(k[G]),G!==k.length-1)$[2*G+1]=M;return Zk({queryId:T(),rawNode:v.createWithChildren($)})}});function uh(k){if(z(k))return k.toOperationNode();return X(k)}var l3=h({raw(k,W=[]){return h({sql:k,query:v.createWithSql(k),parameters:h(W),queryId:T()})}});
3
+ export{z as tb,S as ub,pk as vb,ah as wb,t as xb,D$ as yb,R3 as zb,rk as Ab,Q as Bb,L as Cb,K as Db,Y as Eb,Vh as Fb,T as Gb,ZW as Hb,Th as Ib,QW as Jb,Pk as Kb,Oh as Lb,l as Mb,yW as Nb,gh as Ob,p as Pb,oh as Qb,F as Rb,J$ as Sb,l3 as Tb};
@@ -0,0 +1,2 @@
1
+ import{Oh as E,Ph as w,Uh as G}from"./chunk-ps4xfp23.js";function P(g){if(!g||g<=0)return"0 B";let $=1000,x=["B","KB","MB","GB","TB","PB","EB","ZB","YB"],B=Math.floor(Math.log(g)/Math.log($));if(B<0)B=0;if(B>=x.length)B=x.length-1;let v=g/Math.pow($,B);if(B===0)return`${Math.round(v)} B`;let r=parseFloat(v.toFixed(2));if(r>=1000&&B<x.length-1)return parseFloat((g/Math.pow($,B+1)).toFixed(2))+" "+x[B+1];return`${r} ${x[B]}`}function l(g,$,x){let B=w(g,x?.in);if(isNaN($))return E(x?.in||g,NaN);if(!$)return B;let v=B.getDate(),r=E(x?.in||g,B.getTime());r.setMonth(B.getMonth()+$+1,0);let K=r.getDate();if(v>=K)return r;else return B.setFullYear(r.getFullYear(),r.getMonth(),v),B}function A(g,$){let x=w(g,$?.in),B=x.getMonth();return x.setFullYear(x.getFullYear(),B+1,0),x.setHours(23,59,59,999),x}function I(g,$){return w(g,$?.in).getMonth()}function N(g,$){return w(g,$?.in).getFullYear()}function U(g,$){let[x,B]=G(g,$.start,$.end);return{start:x,end:B}}
2
+ export{l as Af,A as Bf,U as Cf,I as Df,N as Ef,P as Ff};
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- import{wm as L}from"./chunk-06spnkta.js";import{ym as E}from"./chunk-3twtxs5m.js";import{Om as M,Pm as S}from"./chunk-thbfw1ed.js";import{Zm as O}from"./chunk-he1ywtxx.js";import{$m as q,_m as b}from"./chunk-xzag8w1v.js";import"./chunk-p49h5fxs.js";var y=async(B,J,D)=>{let F={api:B.api,provider:B.provider,model:B.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let G=D?.apiKey;if(!G)throw Error(`No API key for provider: ${B.provider}`);let V=C(B,G,D?.headers),Q=H(B,J),X=await D?.onPayload?.(Q,B);if(X!==void 0)Q=X;let N={...D?.signal?{signal:D.signal}:{},...D?.timeoutMs!==void 0?{timeout:D.timeoutMs}:{},maxRetries:0},{data:z,response:A}=await E(()=>V.chat.completions.create(Q,N).withResponse(),{maxRetries:D?.maxRetries,maxRetryDelayMs:D?.maxRetryDelayMs,signal:D?.signal});await D?.onResponse?.({status:A.status,headers:b(A.headers)},B);let Y=z;if(F.responseId=Y.id,Y.usage)F.usage=K(Y.usage,B);let Z=Y.choices[0];if(Z){let _=Z.message.content;if(typeof _==="string"&&_.length>0)F.output.push({type:"text",text:_});for(let $ of Z.message.images??[]){let I=typeof $.image_url==="string"?$.image_url:$.image_url?.url;if(!I?.startsWith("data:"))continue;let f=I.match(/^data:([^;]+);base64,(.+)$/);if(!f)continue;F.output.push({type:"image",mimeType:f[1],data:f[2]})}}return F}catch(G){return F.stopReason=D?.signal?.aborted?"aborted":"error",F.errorMessage=S(M(G)),F}};function C(B,J,D){return new L({apiKey:J,baseURL:B.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:q({...B.headers,...D})})}function H(B,J){let D=J.input.map((F)=>{if(F.type==="text")return{type:"text",text:O(F.text)};return{type:"image_url",image_url:{url:`data:${F.mimeType};base64,${F.data}`}}});return{model:B.id,messages:[{role:"user",content:D}],stream:!1,modalities:B.output.includes("text")?["image","text"]:["image"]}}function K(B,J){let D=B.prompt_tokens||0,F=B.prompt_tokens_details?.cached_tokens||0,G=B.prompt_tokens_details?.cache_write_tokens||0,V=G>0?Math.max(0,F-G):F,Q=Math.max(0,D-V-G),X=B.completion_tokens||0,N={input:Q,output:X,cacheRead:V,cacheWrite:G,totalTokens:Q+X+V+G,cost:{input:J.cost.input/1e6*Q,output:J.cost.output/1e6*X,cacheRead:J.cost.cacheRead/1e6*V,cacheWrite:J.cost.cacheWrite/1e6*G,total:0}};return N.cost.total=N.cost.input+N.cost.output+N.cost.cacheRead+N.cost.cacheWrite,N}export{y as generateImages};
2
+ import{Em as L}from"./chunk-tjcc7a6y.js";import{Gm as E}from"./chunk-e3cabksx.js";import{Wm as M,Xm as S}from"./chunk-gtbsb39v.js";import{fn as O}from"./chunk-tbbwss3v.js";import{gn as b,hn as q}from"./chunk-6w2wmvqs.js";import"./chunk-dxyq9h8n.js";var y=async(B,J,D)=>{let F={api:B.api,provider:B.provider,model:B.id,output:[],stopReason:"stop",timestamp:Date.now()};try{let G=D?.apiKey;if(!G)throw Error(`No API key for provider: ${B.provider}`);let V=C(B,G,D?.headers),Q=H(B,J),X=await D?.onPayload?.(Q,B);if(X!==void 0)Q=X;let N={...D?.signal?{signal:D.signal}:{},...D?.timeoutMs!==void 0?{timeout:D.timeoutMs}:{},maxRetries:0},{data:z,response:A}=await E(()=>V.chat.completions.create(Q,N).withResponse(),{maxRetries:D?.maxRetries,maxRetryDelayMs:D?.maxRetryDelayMs,signal:D?.signal});await D?.onResponse?.({status:A.status,headers:b(A.headers)},B);let Y=z;if(F.responseId=Y.id,Y.usage)F.usage=K(Y.usage,B);let Z=Y.choices[0];if(Z){let _=Z.message.content;if(typeof _==="string"&&_.length>0)F.output.push({type:"text",text:_});for(let $ of Z.message.images??[]){let I=typeof $.image_url==="string"?$.image_url:$.image_url?.url;if(!I?.startsWith("data:"))continue;let f=I.match(/^data:([^;]+);base64,(.+)$/);if(!f)continue;F.output.push({type:"image",mimeType:f[1],data:f[2]})}}return F}catch(G){return F.stopReason=D?.signal?.aborted?"aborted":"error",F.errorMessage=S(M(G)),F}};function C(B,J,D){return new L({apiKey:J,baseURL:B.baseUrl,dangerouslyAllowBrowser:!0,defaultHeaders:q({...B.headers,...D})})}function H(B,J){let D=J.input.map((F)=>{if(F.type==="text")return{type:"text",text:O(F.text)};return{type:"image_url",image_url:{url:`data:${F.mimeType};base64,${F.data}`}}});return{model:B.id,messages:[{role:"user",content:D}],stream:!1,modalities:B.output.includes("text")?["image","text"]:["image"]}}function K(B,J){let D=B.prompt_tokens||0,F=B.prompt_tokens_details?.cached_tokens||0,G=B.prompt_tokens_details?.cache_write_tokens||0,V=G>0?Math.max(0,F-G):F,Q=Math.max(0,D-V-G),X=B.completion_tokens||0,N={input:Q,output:X,cacheRead:V,cacheWrite:G,totalTokens:Q+X+V+G,cost:{input:J.cost.input/1e6*Q,output:J.cost.output/1e6*X,cacheRead:J.cost.cacheRead/1e6*V,cacheWrite:J.cost.cacheWrite/1e6*G,total:0}};return N.cost.total=N.cost.input+N.cost.output+N.cost.cacheRead+N.cost.cacheWrite,N}export{y as generateImages};
@@ -0,0 +1 @@
1
+ import{h as U1}from"./chunk-s39n3yw3.js";import{p as G1,q as J1,r as _1}from"./chunk-9wm9rwh1.js";import{D as Y1,y as X1}from"./chunk-fe7822ak.js";import{I as K1}from"./chunk-z36bx86r.js";import"./chunk-480jtqng.js";import"./chunk-g8tkhw9j.js";import{W as Yz}from"./chunk-c1k86mfa.js";import"./chunk-6d5xrgfx.js";import{ca as Z1}from"./chunk-kxskpgsq.js";import"./chunk-jmdar2gz.js";import"./chunk-ns0zww9g.js";import"./chunk-zxnyefg5.js";import"./chunk-xg5yrcj5.js";import{wf as z1}from"./chunk-bdjv0ykq.js";import"./chunk-4r91fggc.js";import"./chunk-sf91bt9m.js";import"./chunk-77d23vcn.js";import"./chunk-30z44j1g.js";import"./chunk-7pfjfrjg.js";import{$f as sz,ag as ez}from"./chunk-5vewxmz7.js";import"./chunk-ev17v1mv.js";import{dg as iz}from"./chunk-pz2ec6xt.js";import"./chunk-k4v0brcb.js";import"./chunk-4181tdds.js";import"./chunk-62zx96pe.js";import{og as tz,qg as y1}from"./chunk-63y0eb07.js";import"./chunk-qrf0ady6.js";import"./chunk-k47md1g4.js";import"./chunk-77m5p188.js";import{lh as gz}from"./chunk-d9mjbtp2.js";import"./chunk-ytypyfkc.js";import"./chunk-mq83a0kk.js";import"./chunk-hag024w8.js";import"./chunk-07h4b77v.js";import"./chunk-ps4xfp23.js";import"./chunk-nhpgdqq5.js";import{qi as az}from"./chunk-b1ypjqgp.js";import{Gi as H,Ki as Cz,Li as fz,Mi as jz,Ni as Fz,Oi as pz,Pi as mz,Qi as cz,Ri as uz,Si as Iz,Ui as dz,Vi as lz,Wi as nz,Xi as oz,Zi as I,si as Gz,ui as vz,xi as u,zi as a}from"./chunk-h0fxysxs.js";import"./chunk-z1kjmf60.js";import{Ej as F,Tj as Nz,Xl as Mz,aj as bz,bj as Rz,cj as y,dj as W,ij as Dz,kj as hz,nj as Sz,rm as Jz,sk as Lz,um as w,vm as rz}from"./chunk-yp9hvkc5.js";import{sn as Ez}from"./chunk-dxyq9h8n.js";var k=Ez(bz(),1);var c1=({item:K})=>{if(K.preview?.thumbnailUrl)return y("img",{src:K.preview.thumbnailUrl,alt:"Preview",className:"w-full h-full object-cover"});if(K.preview?.proxyType==="audio"||K.proxyType==="audio")return y("div",{className:"w-full h-full flex items-center justify-center bg-muted",children:y(Nz,{className:"w-5 h-5 text-muted-foreground"})});return y("div",{className:"w-full h-full flex items-center justify-center bg-muted",children:y(Lz,{className:"w-5 h-5 text-muted-foreground"})})},xz=({projectId:K,currentAssetId:J,parentFolderId:E,initialFiles:B,initialNextCursor:N})=>{let{ref:Y,inView:x}=gz({threshold:0,rootMargin:"200px"}),b=k.useRef(null),A=k.useRef(!0),[U,Q]=k.useState(B),[$,p]=k.useState(N),[m,d]=k.useState(!!N),[R,T]=k.useState(!1);return k.useEffect(()=>{Q(B),p(N),d(!!N),A.current=!0},[B,N]),k.useEffect(()=>{(async()=>{if(!$||R||!x||!m)return;T(!0);try{let O=await H.api.folders[":folderId"].search.$post({param:{folderId:E},json:{assetType:"file",after:$,first:200,recursively:!1,conditions:[]}});if(!O.ok)throw Error("Failed to fetch next page");let v=await O.json(),D=v.data||[];Q((l)=>[...l,...D]),p(v.pageInfo?.cursor||void 0),d(!!v.pageInfo?.cursor&&D.length>0)}catch(O){console.error("Error fetching next page:",O)}finally{T(!1)}})()},[x,$,m,R,E]),k.useEffect(()=>{if(U.some((O)=>O?.id===J)&&b.current)if(A.current)b.current.scrollIntoView({block:"center",inline:"center",behavior:"auto"}),A.current=!1;else b.current.scrollIntoView({block:"nearest",inline:"nearest",behavior:"smooth"})},[U,J]),y("div",{className:"h-24 md:h-full w-full md:w-24 bg-gray-100 dark:bg-gray-950 flex flex-row md:flex-col flex-shrink-0 select-none",children:W("div",{className:"flex-1 overflow-x-auto overflow-y-hidden md:overflow-y-auto md:overflow-x-hidden px-4 md:px-0 py-2 md:py-4 flex flex-row md:flex-col items-center gap-3 no-scrollbar",children:[U.map((V)=>{if(!V)return null;let O=V.id===J;return y("div",{ref:V.id===J?b:null,className:"flex-shrink-0",children:y(hz,{to:"/projects/$projectId/files/$fileId",params:{projectId:K,fileId:V.id},search:{version:void 0},className:Mz("rounded-lg border overflow-hidden flex items-center justify-center transition-all bg-muted/30 block",O?"w-[62px] h-[62px] opacity-100":"w-[52px] h-[52px] opacity-60 hover:opacity-100"),children:y(c1,{item:V})})},V.id)}),m&&y("div",{ref:Y,className:"px-2 md:px-0 py-2 md:py-4 flex justify-center items-center h-full md:w-full flex-shrink-0",children:R&&y(F,{className:"h-5 w-5 animate-spin text-muted-foreground"})})]})})};var G=Ez(bz(),1);function u1(){let{projectId:K,fileId:J}=Az.useParams(),E=Az.useSearch(),B=E.version,N=E.start,Y=B||J,x=E.cmpLeft,b=E.cmpRight,A=E.cmpActive??"left",U=!!E.compare&&!!x&&!!b,Q=G.useRef(null),{teamId:$,ensureTeamIdForProject:p}=az(),[m,d]=G.useState(360),[R,T]=G.useState([]),{fileViewRightSidebarCollapsed:V}=tz(),{isChatbotOpen:O}=ez(),[v,D]=G.useState(0),[l,S]=G.useState(null),[Zz,W1]=G.useState(null),[w1,_z]=G.useState(void 0),[C,s]=G.useState({show:!1,files:[],nextCursor:void 0,folderId:void 0}),B1=H.api.files[":fileId"].metadata.$patch,{mutate:$1}=a({mutationFn:async(z)=>{let X=await B1(z);if(!X.ok)throw Error("Failed to patch metadata");return await X.json()}}),c=vz(),{members:H1,fetchProjectMembers:Uz}=iz(),Q1=z1();G.useEffect(()=>{p(K)},[K,p]),G.useEffect(()=>{if(K)Uz(K,!0)},[K,Uz]),G.useEffect(()=>{if(K&&J)H.api.projects[":projectId"].recents.view.$post({param:{projectId:K},json:{assetId:J}}).catch(()=>{})},[K,J]);let{data:Wz,isLoading:k1,isError:T1,isFetching:O1}=u({queryKey:["files",J],queryFn:async()=>{let z=await H.api.files[":fileId"].$get({param:{fileId:J}});if(!z.ok)throw Error("Failed to fetch stack");return await z.json()},enabled:!!$,placeholderData:Gz}),{data:V1,isLoading:P1,isError:q1,isFetching:E1}=u({queryKey:["files",B],queryFn:async()=>{let z=await H.api.files[":fileId"].$get({param:{fileId:B}});if(!z.ok)throw Error("Failed to fetch version");return await z.json()},enabled:!!$&&!!B,placeholderData:Gz}),{data:b1}=u({queryKey:["version_stacks",J,"versions"],queryFn:async()=>{let z=await H.api.version_stacks[":stackId"].versions.$get({param:{stackId:J}});if(!z.ok)throw Error("Failed to fetch versions");return await z.json()},enabled:!!K&&!!J&&(!!B||U)}),{data:L}=u({queryKey:["projects",K],queryFn:async()=>{let z=await H.api.projects[":projectId"].$get({param:{projectId:K}});if(!z.ok)throw Error("Failed to fetch project");return await z.json()}}),P=Dz(),{setProjectState:wz,clearProjectState:Bz}=sz(),h1=k1||!!B&&P1,N1=T1||!!B&&q1,L1=O1||!!B&&E1,Z=V1||Wz,h=B?b1:Wz?.versionStack?.versions,_=Z?.ancestorFolders?.[0]?.id??L?.rootFolder??"",[i,n]=G.useState(!1),[o,$z]=G.useState(""),t=G.useRef(null),e=G.useRef(!1),[M1,zz]=G.useState(!1),g1=H.api.files[":fileId"].$put,{mutate:x1,mutateAsync:A1,isPending:Hz}=a({mutationFn:async(z)=>{let X=await g1(z);if(!X.ok)throw Error("Failed to rename file");return await X.json()},onSuccess:()=>{c.invalidateQueries({queryKey:["files"]}),c.invalidateQueries({queryKey:["version_stacks"]}),I.success(w.renamed_successfully?.()||"Renamed successfully"),n(!1)},onError:()=>{I.error(w.failed_to_rename?.()||"Failed to rename")}}),R1=H.api.files.$delete,{mutate:v1,mutateAsync:D1,isPending:Qz}=a({mutationFn:async(z)=>{if(!(await R1(z)).ok)throw Error("Failed to delete file")},onSuccess:()=>{if(c.invalidateQueries({queryKey:["files"]}),c.invalidateQueries({queryKey:["version_stacks"]}),I.success(w.deleted?.()||"Deleted"),zz(!1),_&&_!==L?.rootFolder)P({to:"/projects/$projectId/folders/$folderId",params:{projectId:K,folderId:_}});else P({to:"/projects/$projectId",params:{projectId:K}})},onError:()=>{I.error(w.failed_to_delete?.()||"Failed to delete")}}),S1=(z)=>{if(z?.preventDefault(),!o.trim()||!Y)return;x1({param:{fileId:Y},json:{name:o.trim()}})},C1=()=>{if(!Y)return;v1({json:{ids:[Y]}})};G.useEffect(()=>{if(Z&&L&&$)wz({teamId:$,projectId:K,projectName:L.name??"",ancestorFolders:Z.ancestorFolders??[],currentAsset:{id:Y||J,name:Z.name,type:"file",version:h?h.find((z)=>z.id===Y)?.version??h.length:void 0,proxyType:Z.proxyType},isRootFolder:!1,fileId:J,downloadInfo:{originalKey:Z.media?.original?.key,videoTranscodes:Z.media?.videoTranscodes?.map((z)=>({key:z.key,width:z.width,height:z.height}))},versions:h,compareMode:U,canCompareVersions:(h?.length??0)>=2,onCompareVersions:()=>{let z=X1(h);if(!z)return;P({to:"/projects/$projectId/files/$fileId",params:{projectId:K,fileId:J},search:(X)=>({...X,version:void 0,compare:!0,cmpLeft:z.left.id,cmpRight:z.right.id,cmpActive:"left"})})},onFolderClick:(z)=>{P({to:"/projects/$projectId/folders/$folderId",params:{projectId:K,folderId:z}})},onRename:()=>{e.current=!1,$z(Z?.name??""),n(!0)},onDelete:()=>{zz(!0)}});return()=>Bz()},[$,K,L,Z,h,Y,J,U,wz,Bz,P]),G.useEffect(()=>{if(!i)return;let z=setTimeout(()=>{e.current=!0},1000);return()=>clearTimeout(z)},[i]);let f1=()=>{if(e.current)return;setTimeout(()=>{if(t.current)K1(t.current)},0)};if(G.useEffect(()=>{if(!_||!Y)return;if(C.folderId===_)return;let z=!0;return(async()=>{try{let q="",M=!1,g=[],Kz=void 0;for(let Vz=0;Vz<5;Vz++){let Pz=await H.api.folders[":folderId"].search.$post({param:{folderId:_},json:{assetType:"file",after:q,first:200,recursively:!1,conditions:[]}});if(!Pz.ok)throw Error("Failed to search parent folder for carousel");let j=await Pz.json(),Xz=j.data||[];if(g.push(...Xz),Xz.some((r)=>r.id===Y)){if(M=!0,Kz=j.pageInfo?.cursor||void 0,j.pageInfo?.cursor)try{let r=await H.api.folders[":folderId"].search.$post({param:{folderId:_},json:{assetType:"file",after:j.pageInfo.cursor,first:200,recursively:!1,conditions:[]}});if(r.ok){let qz=await r.json(),m1=qz.data||[];g.push(...m1),Kz=qz.pageInfo?.cursor||void 0}}catch{}break}if(!j.pageInfo?.cursor||Xz.length<200)break;q=j.pageInfo.cursor}if(z)if(M)s({show:!0,files:g,nextCursor:Kz,folderId:_});else s({show:!1,files:[],nextCursor:void 0,folderId:_})}catch(q){if(console.error(q),z)s({show:!1,files:[],nextCursor:void 0,folderId:_})}})(),()=>{z=!1}},[_,Y,C.folderId]),G.useEffect(()=>{D(0),S(null),T([])},[Z?.id]),G.useEffect(()=>{S(null),T([])},[Zz?.id]),G.useEffect(()=>{Yz.getState().reset(),Yz.getState().setIsDrawing(!1),T([]),S(null)},[Y]),h1&&!Z)return y(y1,{});if(N1||!Z||!L||!$)return y("div",{children:w.file_not_found()});let f=U?Zz:Z,kz=f?.id??Y,Tz=(z,X)=>{if(!$)return;$1({param:{fileId:kz},json:[{key:z,value:X}]},{onSuccess:()=>{c.invalidateQueries({queryKey:["files",kz]})}})},yz=(z)=>{P({to:"/projects/$projectId/files/$fileId",params:{projectId:K,fileId:J},search:(X)=>({...X,...z})})},j1=()=>{yz({compare:void 0,cmpLeft:void 0,cmpRight:void 0,cmpActive:void 0,version:A==="left"?x:b})},F1=(z)=>{S(z.id||null);let X=z.annotations;if(X&&X.length>0)T(X);else T([]);if(U){if(z.second!==null&&z.second!==void 0)_z({second:z.second,nonce:Date.now()});return}if(z.second!==null&&z.second!==void 0)Q.current?.seekTo(z.second),Q.current?.pause();else if(X&&X.length>0)Q.current?.pause()},p1=(z)=>{S(z.id||null);let q=z.details,M=q?.annotations;if(M&&M.length>0)T(M);else T([]);let g=q?.position?.type==="time"?q.position.seconds:q?.position?.type==="page"?q.position.page:void 0;if(U){if(g!==void 0)_z({second:g,nonce:Date.now()});return}if(g!==void 0)Q.current?.seekTo(g),Q.current?.pause();else if(M&&M.length>0)Q.current?.pause()},Oz=()=>{T([]),S(null)};if(Q1&&!U)return y(J1,{projectId:K,teamId:$,fileId:J,file:Z,projectInfo:L,ancestorFolders:Z.ancestorFolders??[],parentFolderId:_,versions:h,activeFileId:Y,startTime:N,siblingFiles:C.files,onNavigateToFile:(z)=>{P({to:"/projects/$projectId/files/$fileId",params:{projectId:K,fileId:z}})},onNavigateBack:()=>{if(_&&_!==L?.rootFolder)P({to:"/projects/$projectId/folders/$folderId",params:{projectId:K,folderId:_}});else P({to:"/projects/$projectId",params:{projectId:K}})},onSelectVersion:(z)=>{P({to:"/projects/$projectId/files/$fileId",params:{projectId:K,fileId:J},search:(X)=>({...X,version:z})})},onRenameFile:async(z)=>{await A1({param:{fileId:Y},json:{name:z}})},onDeleteFile:async()=>{await D1({json:{ids:[Y]}})},onSaveField:Tz});return W("div",{className:"h-full flex flex-1 flex-col bg-background",children:[W("div",{className:"h-full flex flex-1 overflow-hidden",children:[W("div",{className:"flex-1 relative",children:[L1&&!U&&y("div",{className:"absolute inset-0 z-10 flex items-center justify-center bg-background/50",children:y(F,{className:"h-8 w-8 animate-spin text-foreground"})}),U&&x&&b?y(_1,{versions:h??[],leftId:x,rightId:b,activeSide:A,annotations:R,seekRequest:w1,onActiveSideChange:(z)=>yz({cmpActive:z}),onSwitchVersion:(z,X)=>yz(z==="left"?{cmpLeft:X}:{cmpRight:X}),onExit:j1,onActiveAssetChange:W1,onPlay:Oz,onTimeUpdate:D}):y(G1,{file:Z,mediaControllerRef:Q,onPlay:Oz,onTimeUpdate:D,annotations:R,startTime:N,children:C.show&&y(xz,{projectId:K,currentAssetId:Y,parentFolderId:_,initialFiles:C.files,initialNextCursor:C.nextCursor})})]}),(!V||O)&&W(Rz,{children:[y(Z1,{onResize:(z)=>{d((X)=>Math.max(300,Math.min(600,X-z)))},className:"hidden md:block"}),y("div",{style:{width:m},className:"flex-shrink-0 bg-background flex flex-col",children:O?y(U1,{projectId:K,contextAssetId:Y,file:f,currentTime:v,frameRate:f?.media?.metadata?.frameRate||30,startTimecode:f?.media?.metadata?.startTimecode,onTyping:()=>{if(U)return;Q.current?.pause()},onSelectMessage:p1,selectedMessageId:l}):y(Y1,{teamId:$,projectId:K,file:f,onSaveField:Tz,members:H1,onCommentSelect:F1,currentTime:v,onTyping:()=>{if(U)return;Q.current?.pause()},selectedCommentId:l,hideAnnotationControl:f?.proxyType==="audio"})})]})]}),y(Iz,{open:i,onOpenChange:n,children:y(dz,{children:W("form",{onSubmit:S1,children:[y(lz,{children:y(oz,{children:w.rename()})}),y("div",{className:"py-4",children:y(rz,{ref:t,value:o,onChange:(z)=>$z(z.target.value),placeholder:w.enter_new_name?.()||"Enter new name",onFocus:f1,autoFocus:!0})}),W(nz,{children:[y(Jz,{type:"button",variant:"outline",onClick:()=>n(!1),children:w.cancel()}),W(Jz,{type:"submit",disabled:Hz||!o.trim(),children:[Hz&&y(F,{className:"mr-2 h-4 w-4 animate-spin"}),w.save()]})]})]})})}),y(Cz,{open:M1,onOpenChange:zz,children:W(fz,{children:[W(jz,{children:[y(pz,{children:w.delete_asset_title?.()||"Delete Asset?"}),y(mz,{children:w.delete_asset_description?.()||"Deleted items can be recovered for 30 days before being permanently deleted."})]}),W(Fz,{children:[y(uz,{children:w.cancel()}),W(cz,{onClick:C1,disabled:Qz,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[Qz&&y(F,{className:"mr-2 h-4 w-4 animate-spin"}),w.delete()]})]})]})})]})}var Az=Sz("/projects/$projectId/files/$fileId")({component:u1});export{Az as Route};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
2
  function f(b){return b.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g,"")}
3
- export{f as Zm};
3
+ export{f as fn};