@shumai-one/shumai 0.4.3 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. package/bin/chunk-071x515q.js +4 -0
  2. package/bin/chunk-0cmx7k4c.js +1 -0
  3. package/bin/{chunk-cqb415s6.js → chunk-0qaq0sp8.js} +2 -2
  4. package/bin/chunk-0qjfahk9.js +2 -0
  5. package/bin/{chunk-9t1ne8xr.js → chunk-0zv3bks2.js} +2 -2
  6. package/bin/chunk-16xax8kk.js +1 -0
  7. package/bin/chunk-1gvscz88.js +5 -0
  8. package/bin/{chunk-6gg1ymer.js → chunk-1j27fzy1.js} +2 -2
  9. package/bin/chunk-1t167cvj.js +11 -0
  10. package/bin/{chunk-pb1zf0vb.js → chunk-1xh34aew.js} +2 -2
  11. package/bin/{chunk-zmv8cg4s.js → chunk-1zwajpwf.js} +3 -3
  12. package/bin/chunk-2w5xqhjm.js +1 -0
  13. package/bin/{chunk-f3ehv01n.js → chunk-3tedzb2j.js} +26 -26
  14. package/bin/{chunk-zehyn6vd.js → chunk-3ttrhqy3.js} +2 -2
  15. package/bin/chunk-3zkasqb8.js +1 -0
  16. package/bin/chunk-453ykvaw.js +2 -0
  17. package/bin/{chunk-3cyrcgm5.js → chunk-4991gz3y.js} +9 -9
  18. package/bin/chunk-4hkkdm2q.js +2 -0
  19. package/bin/chunk-4mjywsj8.js +3 -0
  20. package/bin/{chunk-cnxwmycy.js → chunk-4v41a1r9.js} +3 -3
  21. package/bin/{chunk-87zxtf66.js → chunk-4wy87hwd.js} +2 -2
  22. package/bin/{chunk-sfx2588q.js → chunk-579e4wv4.js} +2 -2
  23. package/bin/{chunk-1yacmegc.js → chunk-5adsx8x4.js} +2 -2
  24. package/bin/{chunk-b235azv4.js → chunk-5hg6kcfz.js} +13 -13
  25. package/bin/{chunk-rbj4fad9.js → chunk-5nm2jvg5.js} +13 -13
  26. package/bin/chunk-5tcdwep5.js +11 -0
  27. package/bin/chunk-5vzrpz50.js +2 -0
  28. package/bin/chunk-6ghcj4a9.js +3 -0
  29. package/bin/{chunk-b9yrw9et.js → chunk-77fmkpdz.js} +4 -4
  30. package/bin/chunk-7bcxj1jd.js +2 -0
  31. package/bin/{chunk-qf24e71w.js → chunk-7gmdnsdg.js} +1 -1
  32. package/bin/{chunk-fxswt9hc.js → chunk-7jtmwt5a.js} +2 -2
  33. package/bin/chunk-7kjgvxqa.js +2 -0
  34. package/bin/{chunk-bay038pj.js → chunk-7pw1550a.js} +2 -2
  35. package/bin/chunk-7rhz2gze.js +211 -0
  36. package/bin/chunk-837fky18.js +3 -0
  37. package/bin/chunk-84as6x83.js +1 -0
  38. package/bin/chunk-8e28hcny.js +2 -0
  39. package/bin/{chunk-k7hss0bd.js → chunk-914bp49r.js} +3 -3
  40. package/bin/chunk-97f2af6d.js +12 -0
  41. package/bin/{chunk-4r81ghg8.js → chunk-98715kc3.js} +2 -2
  42. package/bin/chunk-9ccw540k.js +2 -0
  43. package/bin/{chunk-ag6p3mbf.js → chunk-9t8n2des.js} +2 -2
  44. package/bin/chunk-9ybt6vbm.js +1 -0
  45. package/bin/{chunk-f15qyp41.js → chunk-a6gx7f5q.js} +1 -1
  46. package/bin/chunk-avwgktxb.js +2 -0
  47. package/bin/chunk-bkr5zm4h.js +2 -0
  48. package/bin/{chunk-2yxj593j.js → chunk-cbgq517y.js} +2 -2
  49. package/bin/chunk-d27mm390.js +1 -0
  50. package/bin/{chunk-185qefn1.js → chunk-dj92fss9.js} +2 -2
  51. package/bin/{chunk-v9w25rp2.js → chunk-dqxeztfa.js} +2 -2
  52. package/bin/chunk-drepsbb4.js +2 -0
  53. package/bin/chunk-f6svp4dp.js +2 -0
  54. package/bin/{chunk-q2bvyv39.js → chunk-fahk9h62.js} +2 -2
  55. package/bin/{chunk-v9b3w8q5.js → chunk-fb40xxz3.js} +2 -2
  56. package/bin/chunk-fnmwksnb.js +3 -0
  57. package/bin/chunk-fpc4p0j8.js +3 -0
  58. package/bin/{chunk-aqbrzx9z.js → chunk-fsyzs0tf.js} +1 -1
  59. package/bin/{chunk-e2mvmq2m.js → chunk-fxecgp5k.js} +1 -1
  60. package/bin/{chunk-wfzqnpc1.js → chunk-g3fpmyyn.js} +2 -2
  61. package/bin/{chunk-ehc9adfz.js → chunk-gc5sbfa5.js} +2 -2
  62. package/bin/chunk-gdm6yfqq.js +2 -0
  63. package/bin/{chunk-ea79xnn3.js → chunk-gk2q9a3f.js} +2 -2
  64. package/bin/{chunk-jje8nj8h.js → chunk-gt4csat6.js} +2 -2
  65. package/bin/chunk-gye8gabk.js +2 -0
  66. package/bin/{chunk-wry2hvrq.js → chunk-hk5rc6cd.js} +2 -2
  67. package/bin/{chunk-zqv0zhfb.js → chunk-hm0dkzed.js} +2 -2
  68. package/bin/chunk-hmpwg5za.js +16 -0
  69. package/bin/{chunk-rpywcvg1.js → chunk-j1tkmcae.js} +2 -2
  70. package/bin/chunk-j2bvj2yn.js +2 -0
  71. package/bin/chunk-jffktpqg.js +1 -0
  72. package/bin/chunk-jgs8an3h.js +18 -0
  73. package/bin/{chunk-8fmy5jtp.js → chunk-jmpb5633.js} +1 -1
  74. package/bin/{chunk-xp59apdb.js → chunk-jrjnqx78.js} +1 -1
  75. package/bin/chunk-k2k9vjq6.js +1 -0
  76. package/bin/{chunk-32pcmaqm.js → chunk-kpgfqkp0.js} +2 -2
  77. package/bin/{chunk-twdxayky.js → chunk-ks8xzc95.js} +2 -2
  78. package/bin/{chunk-qwqvt9v6.js → chunk-kswvyqq1.js} +2 -2
  79. package/bin/{chunk-gk3eqd50.js → chunk-m9pr03kn.js} +2 -2
  80. package/bin/chunk-mfn9qjm4.js +2 -0
  81. package/bin/{chunk-e99dv20z.js → chunk-msfw3jmc.js} +2 -2
  82. package/bin/chunk-mz0yjra0.js +5 -0
  83. package/bin/chunk-nbdw8fen.js +1 -0
  84. package/bin/{chunk-cak32x57.js → chunk-nkdk229f.js} +1 -1
  85. package/bin/chunk-nr20tvnw.js +3 -0
  86. package/bin/{chunk-ck8azecb.js → chunk-pazjhrnf.js} +5 -5
  87. package/bin/chunk-q806pqeh.js +1 -0
  88. package/bin/{chunk-abt0azmv.js → chunk-qka4mkmj.js} +2 -2
  89. package/bin/{chunk-0e4wawpq.js → chunk-qsr1a0rp.js} +1 -1
  90. package/bin/chunk-rchsme43.js +3 -0
  91. package/bin/{chunk-tf28796q.js → chunk-reyxk4bw.js} +1 -1
  92. package/bin/{chunk-av1a8fqp.js → chunk-rhvv1vvk.js} +2 -2
  93. package/bin/{chunk-a32vreya.js → chunk-rq0n0vcc.js} +2 -2
  94. package/bin/chunk-rqf7999q.js +42 -0
  95. package/bin/chunk-rssgmj7x.js +2 -0
  96. package/bin/chunk-ryzz5fht.js +2 -0
  97. package/bin/chunk-s2fnfyn9.js +2 -0
  98. package/bin/{chunk-83e12sjg.js → chunk-s2k4qntr.js} +2 -2
  99. package/bin/{chunk-c007p0t8.js → chunk-snhsjs4x.js} +56 -56
  100. package/bin/{chunk-j8fxp8ej.js → chunk-t2hy6tj9.js} +1 -1
  101. package/bin/chunk-t7nsgg5k.js +4 -0
  102. package/bin/chunk-tm7f32c7.js +14 -0
  103. package/bin/{chunk-2291ehh5.js → chunk-trveq4wg.js} +2 -2
  104. package/bin/chunk-vap4k11j.js +20 -0
  105. package/bin/chunk-vm5fx7td.js +3 -0
  106. package/bin/chunk-vy8gntez.js +1 -0
  107. package/bin/{chunk-awfwk64v.js → chunk-vyzptrea.js} +2 -2
  108. package/bin/{chunk-hfh0c082.js → chunk-w4ghe71n.js} +1 -1
  109. package/bin/chunk-wdsf44hs.js +2 -0
  110. package/bin/chunk-wjyaezs7.js +2 -0
  111. package/bin/{chunk-3a13dcs1.js → chunk-wndm3px3.js} +1 -1
  112. package/bin/chunk-x5jwwvs0.js +1 -0
  113. package/bin/chunk-x92cq59c.js +1 -0
  114. package/bin/{chunk-vgn5zcpv.js → chunk-xa18z1py.js} +2 -2
  115. package/bin/{chunk-4v5n0ayb.js → chunk-xarsrs08.js} +1 -1
  116. package/bin/{chunk-66hsjnw6.js → chunk-xx337zcw.js} +2 -2
  117. package/bin/chunk-xz6713tj.js +2 -0
  118. package/bin/chunk-yfnem6se.js +2 -0
  119. package/bin/{chunk-m7m9d4fb.js → chunk-ytdwk2fq.js} +2 -2
  120. package/bin/{chunk-jy006gcv.js → chunk-ze20rm02.js} +4 -4
  121. package/bin/chunk-zw86wnwe.js +7 -0
  122. package/bin/{chunk-h3tbf521.js → chunk-zxk7q0zk.js} +1 -1
  123. package/bin/shumai-app.html +1 -1
  124. package/bin/shumai-app.js +773 -776
  125. package/package.json +7 -7
  126. package/prisma/migrations/20260907021754_add_asset_upload_id/migration.sql +2 -0
  127. package/prisma/schema.prisma +1 -0
  128. package/bin/chunk-1kw2mbqb.js +0 -1
  129. package/bin/chunk-1wm6ptdx.js +0 -1
  130. package/bin/chunk-2520aq8j.js +0 -2
  131. package/bin/chunk-29zdp63z.js +0 -3
  132. package/bin/chunk-3swpwb9v.js +0 -1
  133. package/bin/chunk-3wmcx2bv.js +0 -2
  134. package/bin/chunk-5a8nt4me.js +0 -1
  135. package/bin/chunk-6bhn1p8v.js +0 -211
  136. package/bin/chunk-70c3xrgd.js +0 -2
  137. package/bin/chunk-7esm0hqb.js +0 -2
  138. package/bin/chunk-7fst8kdw.js +0 -12
  139. package/bin/chunk-8zqgaxvv.js +0 -1
  140. package/bin/chunk-a3dmtt2j.js +0 -1
  141. package/bin/chunk-ce8m4zeg.js +0 -3
  142. package/bin/chunk-e7mqtkzn.js +0 -2
  143. package/bin/chunk-ejbvfj4r.js +0 -1
  144. package/bin/chunk-ekfem7kf.js +0 -1
  145. package/bin/chunk-etwkk0xh.js +0 -1
  146. package/bin/chunk-evrdd32b.js +0 -2
  147. package/bin/chunk-fm6p03ad.js +0 -2
  148. package/bin/chunk-fyha3r13.js +0 -2
  149. package/bin/chunk-g0vs7k2x.js +0 -1
  150. package/bin/chunk-g84z2w7v.js +0 -16
  151. package/bin/chunk-h837fyed.js +0 -2
  152. package/bin/chunk-j20e0qsw.js +0 -7
  153. package/bin/chunk-n1jwdb0a.js +0 -1
  154. package/bin/chunk-p5gf1zdm.js +0 -4
  155. package/bin/chunk-pfgxggaj.js +0 -11
  156. package/bin/chunk-q16490pv.js +0 -2
  157. package/bin/chunk-qh81zhg1.js +0 -1
  158. package/bin/chunk-qwp3kwbz.js +0 -2
  159. package/bin/chunk-qydeqgyj.js +0 -5
  160. package/bin/chunk-r7dty1tg.js +0 -2
  161. package/bin/chunk-rhdxwebf.js +0 -2
  162. package/bin/chunk-rhh716z0.js +0 -42
  163. package/bin/chunk-rza4ae5z.js +0 -3
  164. package/bin/chunk-sk4e6rb1.js +0 -1
  165. package/bin/chunk-t2n1dbgx.js +0 -4
  166. package/bin/chunk-x8f4defx.js +0 -3
  167. package/bin/chunk-z3gkt8w1.js +0 -3
  168. package/bin/chunk-zh6fqq44.js +0 -1
@@ -1,6 +1,6 @@
1
1
  // @bun
2
- import{oa}from"./chunk-7fst8kdw.js";import{rr,Dt,Pi,Pd,Ao,Nd,Ni,ys,Lr,Yt,le,jt,Xc,Ve,Bl,Fo,_s,eu,Ul,aa,tu,yo,zl,jo,to,Od,Ut,Pe,sr}from"./chunk-83e12sjg.js";import{Pa,Oi,Di}from"./chunk-rpywcvg1.js";import{Cn,$t,No,sa,Na,ru,Oa,Np,Qt,vr,f,Un,ze,Op,In,sn,Zt,qo,Ho,Tn,$r,ln}from"./chunk-v9b3w8q5.js";var _=f({is(e){return e.kind==="AlterTableNode"},create(e){return f({kind:"AlterTableNode",table:e})},cloneWithTableProps(e,t){return f({...e,...t})},cloneWithColumnAlteration(e,t){return f({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}});var M=f({is(e){return e.kind==="CreateIndexNode"},create(e){return f({kind:"CreateIndexNode",name:ze.create(e)})},cloneWith(e,t){return f({...e,...t})},cloneWithColumns(e,t){return f({...e,columns:[...e.columns||[],...t]})}});var De=f({is(e){return e.kind==="CreateSchemaNode"},create(e,t){return f({kind:"CreateSchemaNode",schema:ze.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var H=f({is(e){return e.kind==="DropIndexNode"},create(e,t){return f({kind:"DropIndexNode",name:sn.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var Ce=f({is(e){return e.kind==="DropSchemaNode"},create(e,t){return f({kind:"DropSchemaNode",schema:ze.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var Te=f({is(e){return e.kind==="DropTableNode"},create(e,t){return f({kind:"DropTableNode",table:e,...t})},cloneWith(e,t){return f({...e,...t})}});var Ge=f({is(e){return e.kind==="AddColumnNode"},create(e){return f({kind:"AddColumnNode",column:e})}});var b=f({is(e){return e.kind==="ColumnDefinitionNode"},create(e,t){return f({kind:"ColumnDefinitionNode",column:Dt.create(e),dataType:t})},cloneWithFrontModifier(e,t){return f({...e,frontModifiers:e.frontModifiers?f([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return f({...e,endModifiers:e.endModifiers?f([...e.endModifiers,t]):[t]})},cloneWith(e,t){return f({...e,...t})}});var Je=f({is(e){return e.kind==="DropColumnNode"},create(e){return f({kind:"DropColumnNode",column:Dt.create(e)})}});var He=f({is(e){return e.kind==="RenameColumnNode"},create(e,t){return f({kind:"RenameColumnNode",column:Dt.create(e),renameTo:Dt.create(t)})}});var ie=f({is(e){return e.kind==="CheckConstraintNode"},create(e,t){return f({kind:"CheckConstraintNode",expression:e,name:t?ze.create(t):void 0})}});var vt=["no action","restrict","cascade","set null","set default"],se=f({is(e){return e.kind==="ReferencesNode"},create(e,t){return f({kind:"ReferencesNode",table:e,columns:f([...t])})},cloneWithOnDelete(e,t){return f({...e,onDelete:t})},cloneWithOnUpdate(e,t){return f({...e,onUpdate:t})}});function Oe(e){return rr(e)?e.toOperationNode():Lr.createImmediate(e)}var ge=f({is(e){return e.kind==="GeneratedNode"},create(e){return f({kind:"GeneratedNode",...e})},createWithExpression(e){return f({kind:"GeneratedNode",always:!0,expression:e})},cloneWith(e,t){return f({...e,...t})}});var qt=f({is(e){return e.kind==="DefaultValueNode"},create(e){return f({kind:"DefaultValueNode",defaultValue:e})}});function ae(e){if(vt.includes(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}class I{#e;constructor(e){this.#e=e}autoIncrement(){return new I(b.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new I(b.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new I(b.cloneWith(this.#e,{primaryKey:!0}))}references(e){let t=Ao(e);if(!t.table||Pi.is(t.column))throw Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new I(b.cloneWith(this.#e,{references:se.create(t.table,[t.column])}))}onDelete(e){if(!this.#e.references)throw Error("on delete constraint can only be added for foreign keys");return new I(b.cloneWith(this.#e,{references:se.cloneWithOnDelete(this.#e.references,ae(e))}))}onUpdate(e){if(!this.#e.references)throw Error("on update constraint can only be added for foreign keys");return new I(b.cloneWith(this.#e,{references:se.cloneWithOnUpdate(this.#e.references,ae(e))}))}unique(){return new I(b.cloneWith(this.#e,{unique:!0}))}notNull(){return new I(b.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new I(b.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new I(b.cloneWith(this.#e,{defaultTo:qt.create(Oe(e))}))}check(e){return new I(b.cloneWith(this.#e,{check:ie.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new I(b.cloneWith(this.#e,{generated:ge.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new I(b.cloneWith(this.#e,{generated:ge.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new I(b.cloneWith(this.#e,{generated:ge.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new I(b.cloneWith(this.#e,{generated:ge.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new I(b.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new I(b.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new I(b.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new I(b.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}}var Ye=f({is(e){return e.kind==="ModifyColumnNode"},create(e){return f({kind:"ModifyColumnNode",column:e})}});var W=f({is(e){return e.kind==="ForeignKeyConstraintNode"},create(e,t,r,n){return f({kind:"ForeignKeyConstraintNode",columns:e,references:se.create(t,r),name:n?ze.create(n):void 0})},cloneWith(e,t){return f({...e,...t})}});class P{#e;constructor(e){this.#e=e}onDelete(e){return new P(W.cloneWith(this.#e,{onDelete:ae(e)}))}onUpdate(e){return new P(W.cloneWith(this.#e,{onUpdate:ae(e)}))}deferrable(){return new P(W.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new P(W.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new P(W.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new P(W.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}var ce=f({is(e){return e.kind==="AddConstraintNode"},create(e){return f({kind:"AddConstraintNode",constraint:e})}});var R=f({is(e){return e.kind==="UniqueConstraintNode"},create(e,t,r){return f({kind:"UniqueConstraintNode",columns:f(e.map(Dt.create)),name:t?ze.create(t):void 0,nullsNotDistinct:r})},cloneWith(e,t){return f({...e,...t})}});var ue=f({is(e){return e.kind==="DropConstraintNode"},create(e){return f({kind:"DropConstraintNode",constraintName:ze.create(e)})},cloneWith(e,t){return f({...e,...t})}});var me=f({is(e){return e.kind==="AlterColumnNode"},create(e,t,r){return f({kind:"AlterColumnNode",column:Dt.create(e),[t]:r})}});class Se{#e;constructor(e){this.#e=e}setDataType(e){return new de(me.create(this.#e,"dataType",jo(e)))}setDefault(e){return new de(me.create(this.#e,"setDefault",Oe(e)))}dropDefault(){return new de(me.create(this.#e,"dropDefault",!0))}setNotNull(){return new de(me.create(this.#e,"setNotNull",!0))}dropNotNull(){return new de(me.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}}class de{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}}class Y{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class j{#e;constructor(e){this.#e=f(e)}onDelete(e){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(_.cloneWithTableProps(this.#e.node,{addConstraint:ce.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class re{#e;constructor(e){this.#e=f(e)}ifExists(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:ue.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:ue.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:ue.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var V=f({is(e){return e.kind==="PrimaryKeyConstraintNode"},create(e,t){return f({kind:"PrimaryKeyConstraintNode",columns:f(e.map(Dt.create)),name:t?ze.create(t):void 0})},cloneWith(e,t){return f({...e,...t})}});var X=f({is(e){return e.kind==="AddIndexNode"},create(e){return f({kind:"AddIndexNode",name:ze.create(e)})},cloneWith(e,t){return f({...e,...t})},cloneWithColumns(e,t){return f({...e,columns:[...e.columns||[],...t]})}});class Z{#e;constructor(e){this.#e=f(e)}unique(){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,[Ni(e)])})})}columns(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,e.map(Ni))})})}expression(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWith(this.#e.node.addIndex,{using:Zt.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Q{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new Q(R.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new Q(R.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new Q(R.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new Q(R.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new Q(R.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class U{#e;constructor(e){this.#e=e}deferrable(){return new U(V.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new U(V.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new U(V.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new U(V.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class Ee{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}}var Ot=f({is(e){return e.kind==="RenameConstraintNode"},create(e,t){return f({kind:"RenameConstraintNode",oldName:ze.create(e),newName:ze.create(t)})}});class Xe{#e;constructor(e){this.#e=f(e)}renameTo(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{renameTo:Ut(e)})})}setSchema(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{setSchema:ze.create(e)})})}alterColumn(e,t){let r=t(new Se(e));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Je.create(e))})}renameColumn(e,t){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,He.create(e,t))})}addColumn(e,t,r=Un){let n=r(new I(b.create(e,jo(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ge.create(n.toOperationNode()))})}modifyColumn(e,t,r=Un){let n=r(new I(b.create(e,jo(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ye.create(n.toOperationNode()))})}addUniqueConstraint(e,t,r=Un){let n=r(new Q(R.create(t,e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ce.create(n.toOperationNode())})})}addCheckConstraint(e,t,r=Un){let n=r(new Ee(ie.create(t.toOperationNode(),e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ce.create(n.toOperationNode())})})}addForeignKeyConstraint(e,t,r,n,o=Un){let d=o(new P(W.create(t.map(Dt.create),Ut(r),n.map(Dt.create),e)));return new j({...this.#e,constraintBuilder:d})}addPrimaryKeyConstraint(e,t,r=Un){let n=r(new U(V.create(t,e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ce.create(n.toOperationNode())})})}dropConstraint(e){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:ue.create(e)})})}renameConstraint(e,t){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{renameConstraint:Ot.create(e,t)})})}addIndex(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.create(e)})})}dropIndex(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropIndex:H.create(e)})})}$call(e){return e(this)}}class L{#e;constructor(e){this.#e=f(e)}alterColumn(e,t){let r=t(new Se(e));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Je.create(e))})}renameColumn(e,t){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,He.create(e,t))})}addColumn(e,t,r=Un){let n=r(new I(b.create(e,jo(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ge.create(n.toOperationNode()))})}modifyColumn(e,t,r=Un){let n=r(new I(b.create(e,jo(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ye.create(n.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class be extends Bl{transformPrimitiveValueList(e){return ys.create(e.values.map(Lr.createImmediate))}transformValue(e){return Lr.createImmediate(e.value)}}class S{#e;constructor(e){this.#e=f(e)}ifNotExists(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new S({...this.#e,node:M.cloneWith(this.#e.node,{table:Ut(e)})})}column(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,[Ni(e)])})}columns(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,e.map(Ni))})}expression(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new S({...this.#e,node:M.cloneWith(this.#e.node,{using:Zt.createWithSql(e)})})}where(...e){let t=new be;return new S({...this.#e,node:le.cloneWithWhere(this.#e.node,t.transformNode(Yt(e),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class ke{#e;constructor(e){this.#e=f(e)}ifNotExists(){return new ke({...this.#e,node:De.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}function St(e){if(Op.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}class O{#e;constructor(e){this.#e=f(e)}temporary(){return new O({...this.#e,node:In.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new O({...this.#e,node:In.cloneWith(this.#e.node,{onCommit:St(e)})})}ifNotExists(){return new O({...this.#e,node:In.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,r=Un){let n=r(new I(b.create(e,jo(t))));return new O({...this.#e,node:In.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,t,r=Un){let n=r(new U(V.create(t,e)));return new O({...this.#e,node:In.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,t,r=Un){let n=r(new Q(R.create(t,e)));return new O({...this.#e,node:In.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,t,r=Un){let n=r(new Ee(ie.create(t.toOperationNode(),e)));return new O({...this.#e,node:In.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,t,r,n,o=Un){let d=o(new P(W.create(t.map(Dt.create),Ut(r),n.map(Dt.create),e)));return new O({...this.#e,node:In.cloneWithConstraint(this.#e.node,d.toOperationNode())})}modifyFront(e){return new O({...this.#e,node:In.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new O({...this.#e,node:In.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new O({...this.#e,node:In.cloneWith(this.#e.node,{selectQuery:to(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class he{#e;constructor(e){this.#e=f(e)}on(e){return new he({...this.#e,node:H.cloneWith(this.#e.node,{table:Ut(e)})})}ifExists(){return new he({...this.#e,node:H.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new he({...this.#e,node:H.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ie{#e;constructor(e){this.#e=f(e)}ifExists(){return new Ie({...this.#e,node:Ce.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new Ie({...this.#e,node:Ce.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ae{#e;constructor(e){this.#e=f(e)}ifExists(){return new Ae({...this.#e,node:Te.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new Ae({...this.#e,node:Te.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ze{#e=new be;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}}class B{#e;constructor(e){this.#e=f(e)}temporary(){return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{columns:e.map(Nd)})})}as(e){let t=e.withPlugin(new Ze).toOperationNode();return new B({...this.#e,node:Ho.cloneWith(this.#e.node,{as:t})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var pe=f({is(e){return e.kind==="DropViewNode"},create(e){return f({kind:"DropViewNode",name:sn.create(e)})},cloneWith(e,t){return f({...e,...t})}});class fe{#e;constructor(e){this.#e=f(e)}materialized(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var Me=f({is(e){return e.kind==="CreateTypeNode"},create(e){return f({kind:"CreateTypeNode",name:e})},cloneWithEnum(e,t){return f({...e,enum:ys.create(t.map(Lr.createImmediate))})}});class We{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new We({...this.#e,node:Me.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var Le=f({is(e){return e.kind==="DropTypeNode"},create(e){return f({kind:"DropTypeNode",name:e})},cloneWith(e,t){return f({...e,...t})}});class Re{#e;constructor(e){this.#e=f(e)}ifExists(){return new Re({...this.#e,node:Le.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}function et(e){if(e.includes(".")){let r=e.split(".").map(er);if(r.length===2)return sn.createWithSchema(r[0],r[1]);else throw Error(`invalid schemable identifier ${e}`)}else return sn.create(e)}function er(e){return e.trim()}var ye=f({is(e){return e.kind==="RefreshMaterializedViewNode"},create(e){return f({kind:"RefreshMaterializedViewNode",name:sn.create(e)})},cloneWith(e,t){return f({...e,...t})}});class we{#e;constructor(e){this.#e=f(e)}concurrently(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class xe{#e;constructor(e){this.#e=e}createTable(e){return new O({queryId:Ve(),executor:this.#e,node:In.create(Ut(e))})}dropTable(e){return new Ae({queryId:Ve(),executor:this.#e,node:Te.create(Ut(e))})}createIndex(e){return new S({queryId:Ve(),executor:this.#e,node:M.create(e)})}dropIndex(e){return new he({queryId:Ve(),executor:this.#e,node:H.create(e)})}createSchema(e){return new ke({queryId:Ve(),executor:this.#e,node:De.create(e)})}dropSchema(e){return new Ie({queryId:Ve(),executor:this.#e,node:Ce.create(e)})}alterTable(e){return new Xe({queryId:Ve(),executor:this.#e,node:_.create(Ut(e))})}createView(e){return new B({queryId:Ve(),executor:this.#e,node:Ho.create(e)})}refreshMaterializedView(e){return new we({queryId:Ve(),executor:this.#e,node:ye.create(e)})}dropView(e){return new fe({queryId:Ve(),executor:this.#e,node:pe.create(e)})}createType(e){return new We({queryId:Ve(),executor:this.#e,node:Me.create(et(e))})}dropType(e){return new Re({queryId:Ve(),executor:this.#e,node:Le.create(et(e))})}withPlugin(e){return new xe(this.#e.withPlugin(e))}withoutPlugins(){return new xe(this.#e.withoutPlugins())}withSchema(e){return new xe(this.#e.withPluginAtFront(new Fo(e)))}}class tt{ref(e){return new Pd(e)}table(e){return new Od(e)}}class rt{#e;constructor(e){this.#e=e}async provideConnection(e){let t=await this.#e.acquireConnection();try{return await e(t)}finally{await this.#e.releaseConnection(t)}}}class ee extends Ul{#e;#t;#r;constructor(e,t,r,n=[]){super(n);this.#e=e,this.#t=t,this.#r=r}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#r.provideConnection(e)}withPlugins(e){return new ee(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new ee(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new ee(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new ee(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new ee(this.#e,this.#t,this.#r,[])}}function Qe(){if(typeof performance<"u"&&Qt(performance.now))return performance.now();else return Date.now()}class nt{#e;#t;#r;#n;#o;#i=new WeakSet;constructor(e,t){this.#n=!1,this.#e=e,this.#t=t}async init(){if(this.#o)throw Error("driver has already been destroyed");if(!this.#r)this.#r=this.#e.init().then(()=>{this.#n=!0}).catch((e)=>(this.#r=void 0,Promise.reject(e)));await this.#r}async acquireConnection(){if(this.#o)throw Error("driver has already been destroyed");if(!this.#n)await this.init();let e=await this.#e.acquireConnection();if(!this.#i.has(e)){if(this.#a())this.#c(e);this.#i.add(e)}return e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,t){return this.#e.beginTransaction(e,t)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,t,r){if(this.#e.savepoint)return this.#e.savepoint(e,t,r);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,t,r){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,t,r);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,t,r){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,t,r);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){if(!this.#r)return;if(await this.#r,!this.#o)this.#o=this.#e.destroy().catch((e)=>(this.#o=void 0,Promise.reject(e)));await this.#o}#a(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#c(e){let{executeQuery:t,streamQuery:r}=e,n=this;e.executeQuery=async(o)=>{let d,l=Qe();try{return await t.call(e,o)}catch(g){throw d=g,await n.#s(g,o,l),g}finally{if(!d)await n.#u(o,l)}},e.streamQuery=async function*(o,d){let l,g=Qe();try{for await(let A of r.call(e,o,d))yield A}catch(A){throw l=A,await n.#s(A,o,g),A}finally{if(!l)await n.#u(o,g,!0)}}}async#s(e,t,r){await this.#t.error(()=>({level:"error",error:e,query:t,queryDurationMillis:this.#l(r)}))}async#u(e,t,r=!1){await this.#t.query(()=>({level:"query",isStream:r,query:e,queryDurationMillis:this.#l(t)}))}#l(e){return Qe()-e}}var tr=()=>{};class ve{#e;#t;constructor(e){this.#e=e}async provideConnection(e){while(this.#t)await this.#t.catch(tr);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}}var nr=["read only","read write"],or=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function ot(e){if(e.accessMode&&!nr.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!or.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}var ir=["query","error"],za=f(ir);class it{#e;#t;constructor(e){if(Qt(e))this.#t=e,this.#e=f({query:!0,error:!0});else this.#t=ar,this.#e=f({query:e.includes("query"),error:e.includes("error")})}isLevelEnabled(e){return this.#e[e]}async query(e){if(this.#e.query)await this.#t(e())}async error(e){if(this.#e.error)await this.#t(e())}}function ar(e){if(e.level==="query"){let t=`kysely:query:${e.isStream?"stream:":""}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else if(e.level==="error")if(e.error instanceof Error)console.error(`kysely:error: ${e.error.stack??e.error.message}`);else console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`)}function kt(e){return vr(e)&&Qt(e.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class F extends aa{#e;constructor(e){let t,r;if(cr(e))t={executor:e.executor},r={...e};else{let n=e.dialect,o=n.createDriver(),d=n.createQueryCompiler(),l=n.createAdapter(),g=new it(e.log??[]),A=new nt(o,g),D=new rt(A),z=new ee(d,l,D,e.plugins??[]);t={executor:z},r={config:e,executor:z,dialect:n,driver:A}}super(t);this.#e=f(r)}get schema(){return new xe(this.#e.executor)}get dynamic(){return new tt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new zl({node:yo.create(Cn(e)?void 0:to(e))})}get fn(){return tu()}transaction(){return new $e({...this.#e})}startTransaction(){return new Fe({...this.#e})}connection(){return new Mt({...this.#e})}withPlugin(e){return new F({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new F({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new F({...this.#e,executor:this.#e.executor.withPluginAtFront(new Fo(e))})}withTables(){return new F({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,t){if(t!==void 0)qo("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let r=kt(e)?e.compile():e;return this.getExecutor().executeQuery(r)}async[Symbol.asyncDispose](){await this.destroy()}}class oe extends F{#e;constructor(e){super(e);this.#e=e}get isTransaction(){return!0}transaction(){throw Error("calling the transaction method for a Transaction is not supported")}connection(){throw Error("calling the connection method for a Transaction is not supported")}async destroy(){throw Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new oe({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new oe({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new oe({...this.#e,executor:this.#e.executor.withPluginAtFront(new Fo(e))})}withTables(){return new oe({...this.#e})}}function cr(e){return vr(e)&&vr(e.config)&&vr(e.driver)&&vr(e.executor)&&vr(e.dialect)}class Mt{#e;constructor(e){this.#e=f(e)}async execute(e){return this.#e.executor.provideConnection(async(t)=>{let r=this.#e.executor.withConnectionProvider(new ve(t)),n=new F({...this.#e,executor:r});return await e(n)})}}class $e{#e;constructor(e){this.#e=f(e)}setAccessMode(e){return new $e({...this.#e,accessMode:e})}setIsolationLevel(e){return new $e({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:t,accessMode:r,...n}=this.#e,o={isolationLevel:t,accessMode:r};return ot(o),this.#e.executor.provideConnection(async(d)=>{let l={isCommitted:!1,isRolledBack:!1},g=new G(this.#e.executor.withConnectionProvider(new ve(d)),l),A=new oe({...n,executor:g}),D=!1;try{await this.#e.driver.beginTransaction(d,o),D=!0;let z=await e(A);return await this.#e.driver.commitTransaction(d),l.isCommitted=!0,z}catch(z){if(D)await this.#e.driver.rollbackTransaction(d),l.isRolledBack=!0;throw z}})}}class Fe{#e;constructor(e){this.#e=f(e)}setAccessMode(e){return new Fe({...this.#e,accessMode:e})}setIsolationLevel(e){return new Fe({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:t,...r}=this.#e,n={isolationLevel:e,accessMode:t};ot(n);let o=await eu(this.#e.executor);return await this.#e.driver.beginTransaction(o.connection,n),new K({...r,connection:o,executor:this.#e.executor.withConnectionProvider(new ve(o.connection))})}}class K extends oe{#e;#t;#r;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new G(e.executor,t)};let{connection:r,...n}=e;super(n);this.#e=f(e),this.#r=t;let o=Ve();this.#t=(d)=>e.executor.compileQuery(d,o)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return ne(this.#r),new Ne(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return ne(this.#r),new Ne(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}rollbackToSavepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}releaseSavepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}withPlugin(e){return new K({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new K({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new K({...this.#e,executor:this.#e.executor.withPluginAtFront(new Fo(e))})}withTables(){return new K({...this.#e})}}class Ne{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}}function ne(e){if(e.isCommitted)throw Error("Transaction is already committed");if(e.isRolledBack)throw Error("Transaction is already rolled back")}class G{#e;#t;constructor(e,t){if(e instanceof G)this.#e=e.#e;else this.#e=e;this.#t=t}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e){return ne(this.#t),this.#e.executeQuery(e)}stream(e,t){return ne(this.#t),this.#e.stream(e,t)}withConnectionProvider(e){return new G(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new G(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new G(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new G(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new G(this.#e.withoutPlugins(),this.#t)}}function k(e,t){return Zt.createWithChildren([Zt.createWithSql(`${e} `),ze.create(t)])}class st{#e;#t=new Pt;#r;#n;constructor(e){this.#e=f({...e})}async init(){if(this.#r=Qt(this.#e.database)?await this.#e.database():this.#e.database,this.#n=new Wt(this.#r),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#n)}async acquireConnection(){return await this.#t.lock(),this.#n}async beginTransaction(e){await e.executeQuery(sr.raw("begin"))}async commitTransaction(e){await e.executeQuery(sr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(sr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ve()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ve()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release",t),Ve()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#r?.close()}}class Wt{#e;constructor(e){this.#e=e}executeQuery(e){let{sql:t,parameters:r}=e,n=this.#e.prepare(t);if(n.reader)return Promise.resolve({rows:n.all(r)});let{changes:o,lastInsertRowid:d}=n.run(r);return Promise.resolve({numAffectedRows:o!==void 0&&o!==null?BigInt(o):void 0,insertId:d!==void 0&&d!==null?BigInt(d):void 0,rows:[]})}async*streamQuery(e,t){let{sql:r,parameters:n,query:o}=e,d=this.#e.prepare(r);if(jt.is(o)){let l=d.iterate(n);for(let g of l)yield{rows:[g]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class Pt{#e;#t;async lock(){while(this.#e)await this.#e;this.#e=new Promise((e)=>{this.#t=e})}unlock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}}class at{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#r(e)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e,t){let r=e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").select(["name","sql","type"]).orderBy("name");if(!t.withInternalKyselyTables)r=r.where("name","!=",$r).where("name","!=",ln);return r}async#r(e){let t=await this.#t(this.#e,e).execute(),r=await this.#e.with("table_list",(o)=>this.#t(o,e)).selectFrom(["table_list as tl",Pe`pragma_table_info(tl.name)`.as("p")]).select(["tl.name as table","p.cid","p.name","p.type","p.notnull","p.dflt_value","p.pk"]).orderBy("tl.name").orderBy("p.cid").execute(),n={};for(let o of r)n[o.table]??=[],n[o.table].push(o);return t.map(({name:o,sql:d,type:l})=>{let g=d?.split(/[\(\),]/)?.find((D)=>D.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),A=n[o]??[];if(!g){let D=A.filter((z)=>z.pk>0);if(D.length===1&&D[0].type.toLowerCase()==="integer")g=D[0].name}return{name:o,isView:l==="view",columns:A.map((D)=>({name:D.name,dataType:D.type,isNullable:!D.notnull,isAutoIncrementing:D.name===g,hasDefaultValue:D.dflt_value!=null,comment:void 0}))}})}}class je{#e;constructor(e){this.#e=f({...e})}createDriver(){return new st(this.#e)}createQueryCompiler(){return new Oi}createAdapter(){return new Di}createIntrospector(e){return new at(e)}}var ur=/"/g;class ct extends Tn{sanitizeIdentifier(e){return e.replace(ur,'""')}}class ut{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((t)=>({name:t.nspname}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("pg_catalog.pg_attribute as a").innerJoin("pg_catalog.pg_class as c","a.attrelid","c.oid").innerJoin("pg_catalog.pg_namespace as ns","c.relnamespace","ns.oid").innerJoin("pg_catalog.pg_type as typ","a.atttypid","typ.oid").innerJoin("pg_catalog.pg_namespace as dtns","typ.typnamespace","dtns.oid").select(["a.attname as column","a.attnotnull as not_null","a.atthasdef as has_default","c.relname as table","c.relkind as table_type","ns.nspname as schema","typ.typname as type","dtns.nspname as type_schema",Pe`col_description(a.attrelid, a.attnum)`.as("column_description"),Pe`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as("auto_incrementing")]).where("c.relkind","in",["r","v","p"]).where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema").where("ns.nspname","!=","crdb_internal").where(Pe`has_schema_privilege(ns.nspname, 'USAGE')`).where("a.attnum",">=",0).where("a.attisdropped","!=",!0).orderBy("ns.nspname").orderBy("c.relname").orderBy("a.attnum").$castTo();if(!e.withInternalKyselyTables)t=t.where("c.relname","!=",$r).where("c.relname","!=",ln);let r=await t.execute();return this.#t(r)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){let t=new Map;for(let r=0,n=e.length;r<n;r++){let o=e[r],{schema:d,table:l}=o,g=`schema:${d};table:${l}`;if(!t.has(g))t.set(g,f({columns:[],isView:o.table_type==="v",name:l,schema:d}));t.get(g).columns.push(f({comment:o.column_description??void 0,dataType:o.type,dataTypeSchema:o.type_schema,hasDefaultValue:o.has_default,isAutoIncrementing:o.auto_incrementing!==null,isNullable:!o.not_null,name:o.column}))}return Array.from(t.values())}}var lr=BigInt("3853314791062309107");class lt extends Pa{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await Pe`select pg_advisory_xact_lock(${Pe.lit(lr)})`.execute(e)}async releaseMigrationLock(e,t){}}function _e(e,t){if(mr(e)&&t.stack){let r=t.stack.split(`
2
+ import{xs}from"./chunk-97f2af6d.js";import{lr,Zt,Ki,of,Io,sf,Wi,Da,zr,rr,ce,$t,wu,Ye,uc,rs,La,vu,dc,ws,xu,To,fc,ns,fo,af,Ft,Pe,ur}from"./chunk-s2k4qntr.js";import{Js,Yi,Ji}from"./chunk-j1tkmcae.js";import{Pn,Vt,jo,vs,Xs,Su,ea,nm,Kt,Er,f,Gn,ze,om,On,gn,Bt,os,ss,Dn,Yr,An}from"./chunk-fb40xxz3.js";var _=f({is(e){return e.kind==="AlterTableNode"},create(e){return f({kind:"AlterTableNode",table:e})},cloneWithTableProps(e,t){return f({...e,...t})},cloneWithColumnAlteration(e,t){return f({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}});var M=f({is(e){return e.kind==="CreateIndexNode"},create(e){return f({kind:"CreateIndexNode",name:ze.create(e)})},cloneWith(e,t){return f({...e,...t})},cloneWithColumns(e,t){return f({...e,columns:[...e.columns||[],...t]})}});var De=f({is(e){return e.kind==="CreateSchemaNode"},create(e,t){return f({kind:"CreateSchemaNode",schema:ze.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var H=f({is(e){return e.kind==="DropIndexNode"},create(e,t){return f({kind:"DropIndexNode",name:gn.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var Ce=f({is(e){return e.kind==="DropSchemaNode"},create(e,t){return f({kind:"DropSchemaNode",schema:ze.create(e),...t})},cloneWith(e,t){return f({...e,...t})}});var Te=f({is(e){return e.kind==="DropTableNode"},create(e,t){return f({kind:"DropTableNode",table:e,...t})},cloneWith(e,t){return f({...e,...t})}});var Ke=f({is(e){return e.kind==="AddColumnNode"},create(e){return f({kind:"AddColumnNode",column:e})}});var b=f({is(e){return e.kind==="ColumnDefinitionNode"},create(e,t){return f({kind:"ColumnDefinitionNode",column:Zt.create(e),dataType:t})},cloneWithFrontModifier(e,t){return f({...e,frontModifiers:e.frontModifiers?f([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return f({...e,endModifiers:e.endModifiers?f([...e.endModifiers,t]):[t]})},cloneWith(e,t){return f({...e,...t})}});var Ge=f({is(e){return e.kind==="DropColumnNode"},create(e){return f({kind:"DropColumnNode",column:Zt.create(e)})}});var Je=f({is(e){return e.kind==="RenameColumnNode"},create(e,t){return f({kind:"RenameColumnNode",column:Zt.create(e),renameTo:Zt.create(t)})}});var ie=f({is(e){return e.kind==="CheckConstraintNode"},create(e,t){return f({kind:"CheckConstraintNode",expression:e,name:t?ze.create(t):void 0})}});var vt=["no action","restrict","cascade","set null","set default"],se=f({is(e){return e.kind==="ReferencesNode"},create(e,t){return f({kind:"ReferencesNode",table:e,columns:f([...t])})},cloneWithOnDelete(e,t){return f({...e,onDelete:t})},cloneWithOnUpdate(e,t){return f({...e,onUpdate:t})}});function Oe(e){return lr(e)?e.toOperationNode():zr.createImmediate(e)}var ge=f({is(e){return e.kind==="GeneratedNode"},create(e){return f({kind:"GeneratedNode",...e})},createWithExpression(e){return f({kind:"GeneratedNode",always:!0,expression:e})},cloneWith(e,t){return f({...e,...t})}});var qt=f({is(e){return e.kind==="DefaultValueNode"},create(e){return f({kind:"DefaultValueNode",defaultValue:e})}});function ae(e){if(vt.includes(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}class I{#e;constructor(e){this.#e=e}autoIncrement(){return new I(b.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new I(b.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new I(b.cloneWith(this.#e,{primaryKey:!0}))}references(e){let t=Io(e);if(!t.table||Ki.is(t.column))throw Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new I(b.cloneWith(this.#e,{references:se.create(t.table,[t.column])}))}onDelete(e){if(!this.#e.references)throw Error("on delete constraint can only be added for foreign keys");return new I(b.cloneWith(this.#e,{references:se.cloneWithOnDelete(this.#e.references,ae(e))}))}onUpdate(e){if(!this.#e.references)throw Error("on update constraint can only be added for foreign keys");return new I(b.cloneWith(this.#e,{references:se.cloneWithOnUpdate(this.#e.references,ae(e))}))}unique(){return new I(b.cloneWith(this.#e,{unique:!0}))}notNull(){return new I(b.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new I(b.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new I(b.cloneWith(this.#e,{defaultTo:qt.create(Oe(e))}))}check(e){return new I(b.cloneWith(this.#e,{check:ie.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new I(b.cloneWith(this.#e,{generated:ge.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new I(b.cloneWith(this.#e,{generated:ge.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new I(b.cloneWith(this.#e,{generated:ge.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new I(b.cloneWith(this.#e,{generated:ge.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new I(b.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new I(b.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new I(b.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new I(b.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}}var He=f({is(e){return e.kind==="ModifyColumnNode"},create(e){return f({kind:"ModifyColumnNode",column:e})}});var W=f({is(e){return e.kind==="ForeignKeyConstraintNode"},create(e,t,r,n){return f({kind:"ForeignKeyConstraintNode",columns:e,references:se.create(t,r),name:n?ze.create(n):void 0})},cloneWith(e,t){return f({...e,...t})}});class P{#e;constructor(e){this.#e=e}onDelete(e){return new P(W.cloneWith(this.#e,{onDelete:ae(e)}))}onUpdate(e){return new P(W.cloneWith(this.#e,{onUpdate:ae(e)}))}deferrable(){return new P(W.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new P(W.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new P(W.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new P(W.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}var ue=f({is(e){return e.kind==="AddConstraintNode"},create(e){return f({kind:"AddConstraintNode",constraint:e})}});var R=f({is(e){return e.kind==="UniqueConstraintNode"},create(e,t,r){return f({kind:"UniqueConstraintNode",columns:f(e.map(Zt.create)),name:t?ze.create(t):void 0,nullsNotDistinct:r})},cloneWith(e,t){return f({...e,...t})}});var le=f({is(e){return e.kind==="DropConstraintNode"},create(e){return f({kind:"DropConstraintNode",constraintName:ze.create(e)})},cloneWith(e,t){return f({...e,...t})}});var me=f({is(e){return e.kind==="AlterColumnNode"},create(e,t,r){return f({kind:"AlterColumnNode",column:Zt.create(e),[t]:r})}});class Se{#e;constructor(e){this.#e=e}setDataType(e){return new de(me.create(this.#e,"dataType",ns(e)))}setDefault(e){return new de(me.create(this.#e,"setDefault",Oe(e)))}dropDefault(){return new de(me.create(this.#e,"dropDefault",!0))}setNotNull(){return new de(me.create(this.#e,"setNotNull",!0))}dropNotNull(){return new de(me.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}}class de{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}}class Y{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class j{#e;constructor(e){this.#e=f(e)}onDelete(e){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new j({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(_.cloneWithTableProps(this.#e.node,{addConstraint:ue.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class re{#e;constructor(e){this.#e=f(e)}ifExists(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:le.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:le.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:le.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var V=f({is(e){return e.kind==="PrimaryKeyConstraintNode"},create(e,t){return f({kind:"PrimaryKeyConstraintNode",columns:f(e.map(Zt.create)),name:t?ze.create(t):void 0})},cloneWith(e,t){return f({...e,...t})}});var X=f({is(e){return e.kind==="AddIndexNode"},create(e){return f({kind:"AddIndexNode",name:ze.create(e)})},cloneWith(e,t){return f({...e,...t})},cloneWithColumns(e,t){return f({...e,columns:[...e.columns||[],...t]})}});class Z{#e;constructor(e){this.#e=f(e)}unique(){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,[Wi(e)])})})}columns(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,e.map(Wi))})})}expression(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.cloneWith(this.#e.node.addIndex,{using:Bt.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Q{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new Q(R.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new Q(R.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new Q(R.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new Q(R.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new Q(R.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class U{#e;constructor(e){this.#e=e}deferrable(){return new U(V.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new U(V.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new U(V.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new U(V.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class Ee{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}}var Dt=f({is(e){return e.kind==="RenameConstraintNode"},create(e,t){return f({kind:"RenameConstraintNode",oldName:ze.create(e),newName:ze.create(t)})}});class Xe{#e;constructor(e){this.#e=f(e)}renameTo(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{renameTo:Ft(e)})})}setSchema(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{setSchema:ze.create(e)})})}alterColumn(e,t){let r=t(new Se(e));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ge.create(e))})}renameColumn(e,t){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Je.create(e,t))})}addColumn(e,t,r=Gn){let n=r(new I(b.create(e,ns(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ke.create(n.toOperationNode()))})}modifyColumn(e,t,r=Gn){let n=r(new I(b.create(e,ns(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}addUniqueConstraint(e,t,r=Gn){let n=r(new Q(R.create(t,e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ue.create(n.toOperationNode())})})}addCheckConstraint(e,t,r=Gn){let n=r(new Ee(ie.create(t.toOperationNode(),e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ue.create(n.toOperationNode())})})}addForeignKeyConstraint(e,t,r,n,o=Gn){let d=o(new P(W.create(t.map(Zt.create),Ft(r),n.map(Zt.create),e)));return new j({...this.#e,constraintBuilder:d})}addPrimaryKeyConstraint(e,t,r=Gn){let n=r(new U(V.create(t,e)));return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addConstraint:ue.create(n.toOperationNode())})})}dropConstraint(e){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropConstraint:le.create(e)})})}renameConstraint(e,t){return new re({...this.#e,node:_.cloneWithTableProps(this.#e.node,{renameConstraint:Dt.create(e,t)})})}addIndex(e){return new Z({...this.#e,node:_.cloneWithTableProps(this.#e.node,{addIndex:X.create(e)})})}dropIndex(e){return new Y({...this.#e,node:_.cloneWithTableProps(this.#e.node,{dropIndex:H.create(e)})})}$call(e){return e(this)}}class L{#e;constructor(e){this.#e=f(e)}alterColumn(e,t){let r=t(new Se(e));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ge.create(e))})}renameColumn(e,t){return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Je.create(e,t))})}addColumn(e,t,r=Gn){let n=r(new I(b.create(e,ns(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,Ke.create(n.toOperationNode()))})}modifyColumn(e,t,r=Gn){let n=r(new I(b.create(e,ns(t))));return new L({...this.#e,node:_.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class be extends uc{transformPrimitiveValueList(e){return Da.create(e.values.map(zr.createImmediate))}transformValue(e){return zr.createImmediate(e.value)}}class S{#e;constructor(e){this.#e=f(e)}ifNotExists(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new S({...this.#e,node:M.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new S({...this.#e,node:M.cloneWith(this.#e.node,{table:Ft(e)})})}column(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,[Wi(e)])})}columns(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,e.map(Wi))})}expression(e){return new S({...this.#e,node:M.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new S({...this.#e,node:M.cloneWith(this.#e.node,{using:Bt.createWithSql(e)})})}where(...e){let t=new be;return new S({...this.#e,node:ce.cloneWithWhere(this.#e.node,t.transformNode(rr(e),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class ke{#e;constructor(e){this.#e=f(e)}ifNotExists(){return new ke({...this.#e,node:De.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}function Ot(e){if(om.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}class O{#e;constructor(e){this.#e=f(e)}temporary(){return new O({...this.#e,node:On.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new O({...this.#e,node:On.cloneWith(this.#e.node,{onCommit:Ot(e)})})}ifNotExists(){return new O({...this.#e,node:On.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,r=Gn){let n=r(new I(b.create(e,ns(t))));return new O({...this.#e,node:On.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,t,r=Gn){let n=r(new U(V.create(t,e)));return new O({...this.#e,node:On.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,t,r=Gn){let n=r(new Q(R.create(t,e)));return new O({...this.#e,node:On.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,t,r=Gn){let n=r(new Ee(ie.create(t.toOperationNode(),e)));return new O({...this.#e,node:On.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,t,r,n,o=Gn){let d=o(new P(W.create(t.map(Zt.create),Ft(r),n.map(Zt.create),e)));return new O({...this.#e,node:On.cloneWithConstraint(this.#e.node,d.toOperationNode())})}modifyFront(e){return new O({...this.#e,node:On.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new O({...this.#e,node:On.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new O({...this.#e,node:On.cloneWith(this.#e.node,{selectQuery:fo(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class he{#e;constructor(e){this.#e=f(e)}on(e){return new he({...this.#e,node:H.cloneWith(this.#e.node,{table:Ft(e)})})}ifExists(){return new he({...this.#e,node:H.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new he({...this.#e,node:H.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ie{#e;constructor(e){this.#e=f(e)}ifExists(){return new Ie({...this.#e,node:Ce.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new Ie({...this.#e,node:Ce.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ae{#e;constructor(e){this.#e=f(e)}ifExists(){return new Ae({...this.#e,node:Te.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new Ae({...this.#e,node:Te.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class Ze{#e=new be;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}}class B{#e;constructor(e){this.#e=f(e)}temporary(){return new B({...this.#e,node:ss.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new B({...this.#e,node:ss.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new B({...this.#e,node:ss.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new B({...this.#e,node:ss.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new B({...this.#e,node:ss.cloneWith(this.#e.node,{columns:e.map(sf)})})}as(e){let t=e.withPlugin(new Ze).toOperationNode();return new B({...this.#e,node:ss.cloneWith(this.#e.node,{as:t})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var pe=f({is(e){return e.kind==="DropViewNode"},create(e){return f({kind:"DropViewNode",name:gn.create(e)})},cloneWith(e,t){return f({...e,...t})}});class fe{#e;constructor(e){this.#e=f(e)}materialized(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new fe({...this.#e,node:pe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var Me=f({is(e){return e.kind==="CreateTypeNode"},create(e){return f({kind:"CreateTypeNode",name:e})},cloneWithEnum(e,t){return f({...e,enum:Da.create(t.map(zr.createImmediate))})}});class We{#e;constructor(e){this.#e=f(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new We({...this.#e,node:Me.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}var Le=f({is(e){return e.kind==="DropTypeNode"},create(e){return f({kind:"DropTypeNode",name:e})},cloneWith(e,t){return f({...e,...t})}});class Re{#e;constructor(e){this.#e=f(e)}ifExists(){return new Re({...this.#e,node:Le.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}function et(e){if(e.includes(".")){let r=e.split(".").map(Xt);if(r.length===2)return gn.createWithSchema(r[0],r[1]);else throw Error(`invalid schemable identifier ${e}`)}else return gn.create(e)}function Xt(e){return e.trim()}var ye=f({is(e){return e.kind==="RefreshMaterializedViewNode"},create(e){return f({kind:"RefreshMaterializedViewNode",name:gn.create(e)})},cloneWith(e,t){return f({...e,...t})}});class we{#e;constructor(e){this.#e=f(e)}concurrently(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new we({...this.#e,node:ye.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}}class xe{#e;constructor(e){this.#e=e}createTable(e){return new O({queryId:Ye(),executor:this.#e,node:On.create(Ft(e))})}dropTable(e){return new Ae({queryId:Ye(),executor:this.#e,node:Te.create(Ft(e))})}createIndex(e){return new S({queryId:Ye(),executor:this.#e,node:M.create(e)})}dropIndex(e){return new he({queryId:Ye(),executor:this.#e,node:H.create(e)})}createSchema(e){return new ke({queryId:Ye(),executor:this.#e,node:De.create(e)})}dropSchema(e){return new Ie({queryId:Ye(),executor:this.#e,node:Ce.create(e)})}alterTable(e){return new Xe({queryId:Ye(),executor:this.#e,node:_.create(Ft(e))})}createView(e){return new B({queryId:Ye(),executor:this.#e,node:ss.create(e)})}refreshMaterializedView(e){return new we({queryId:Ye(),executor:this.#e,node:ye.create(e)})}dropView(e){return new fe({queryId:Ye(),executor:this.#e,node:pe.create(e)})}createType(e){return new We({queryId:Ye(),executor:this.#e,node:Me.create(et(e))})}dropType(e){return new Re({queryId:Ye(),executor:this.#e,node:Le.create(et(e))})}withPlugin(e){return new xe(this.#e.withPlugin(e))}withoutPlugins(){return new xe(this.#e.withoutPlugins())}withSchema(e){return new xe(this.#e.withPluginAtFront(new rs(e)))}}class tt{ref(e){return new of(e)}table(e){return new af(e)}}class rt{#e;constructor(e){this.#e=e}async provideConnection(e){let t=await this.#e.acquireConnection();try{return await e(t)}finally{await this.#e.releaseConnection(t)}}}class ee extends dc{#e;#t;#r;constructor(e,t,r,n=[]){super(n);this.#e=e,this.#t=t,this.#r=r}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#r.provideConnection(e)}withPlugins(e){return new ee(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new ee(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new ee(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new ee(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new ee(this.#e,this.#t,this.#r,[])}}function Qe(){if(typeof performance<"u"&&Kt(performance.now))return performance.now();else return Date.now()}class nt{#e;#t;#r;#n;#o;#i=new WeakSet;constructor(e,t){this.#n=!1,this.#e=e,this.#t=t}async init(){if(this.#o)throw Error("driver has already been destroyed");if(!this.#r)this.#r=this.#e.init().then(()=>{this.#n=!0}).catch((e)=>(this.#r=void 0,Promise.reject(e)));await this.#r}async acquireConnection(){if(this.#o)throw Error("driver has already been destroyed");if(!this.#n)await this.init();let e=await this.#e.acquireConnection();if(!this.#i.has(e)){if(this.#a())this.#c(e);this.#i.add(e)}return e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,t){return this.#e.beginTransaction(e,t)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,t,r){if(this.#e.savepoint)return this.#e.savepoint(e,t,r);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,t,r){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,t,r);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,t,r){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,t,r);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){if(!this.#r)return;if(await this.#r,!this.#o)this.#o=this.#e.destroy().catch((e)=>(this.#o=void 0,Promise.reject(e)));await this.#o}#a(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#c(e){let{executeQuery:t,streamQuery:r}=e,n=this;e.executeQuery=async(o)=>{let d,l=Qe();try{return await t.call(e,o)}catch(g){throw d=g,await n.#s(g,o,l),g}finally{if(!d)await n.#u(o,l)}},e.streamQuery=async function*(o,d){let l,g=Qe();try{for await(let A of r.call(e,o,d))yield A}catch(A){throw l=A,await n.#s(A,o,g),A}finally{if(!l)await n.#u(o,g,!0)}}}async#s(e,t,r){await this.#t.error(()=>({level:"error",error:e,query:t,queryDurationMillis:this.#l(r)}))}async#u(e,t,r=!1){await this.#t.query(()=>({level:"query",isStream:r,query:e,queryDurationMillis:this.#l(t)}))}#l(e){return Qe()-e}}var er=()=>{};class ve{#e;#t;constructor(e){this.#e=e}async provideConnection(e){while(this.#t)await this.#t.catch(er);return this.#t=this.#r(e).finally(()=>{this.#t=void 0}),this.#t}async#r(e){return await e(this.#e)}}var tr=["read only","read write"],nr=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function ot(e){if(e.accessMode&&!tr.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!nr.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}var or=["query","error"],za=f(or);class it{#e;#t;constructor(e){if(Kt(e))this.#t=e,this.#e=f({query:!0,error:!0});else this.#t=ir,this.#e=f({query:e.includes("query"),error:e.includes("error")})}isLevelEnabled(e){return this.#e[e]}async query(e){if(this.#e.query)await this.#t(e())}async error(e){if(this.#e.error)await this.#t(e())}}function ir(e){if(e.level==="query"){let t=`kysely:query:${e.isStream?"stream:":""}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else if(e.level==="error")if(e.error instanceof Error)console.error(`kysely:error: ${e.error.stack??e.error.message}`);else console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`)}function St(e){return Er(e)&&Kt(e.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class F extends ws{#e;constructor(e){let t,r;if(sr(e))t={executor:e.executor},r={...e};else{let n=e.dialect,o=n.createDriver(),d=n.createQueryCompiler(),l=n.createAdapter(),g=new it(e.log??[]),A=new nt(o,g),D=new rt(A),z=new ee(d,l,D,e.plugins??[]);t={executor:z},r={config:e,executor:z,dialect:n,driver:A}}super(t);this.#e=f(r)}get schema(){return new xe(this.#e.executor)}get dynamic(){return new tt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new fc({node:To.create(Pn(e)?void 0:fo(e))})}get fn(){return xu()}transaction(){return new $e({...this.#e})}startTransaction(){return new Fe({...this.#e})}connection(){return new kt({...this.#e})}withPlugin(e){return new F({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new F({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new F({...this.#e,executor:this.#e.executor.withPluginAtFront(new rs(e))})}withTables(){return new F({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,t){if(t!==void 0)os("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let r=St(e)?e.compile():e;return this.getExecutor().executeQuery(r)}async[Symbol.asyncDispose](){await this.destroy()}}class oe extends F{#e;constructor(e){super(e);this.#e=e}get isTransaction(){return!0}transaction(){throw Error("calling the transaction method for a Transaction is not supported")}connection(){throw Error("calling the connection method for a Transaction is not supported")}async destroy(){throw Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new oe({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new oe({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new oe({...this.#e,executor:this.#e.executor.withPluginAtFront(new rs(e))})}withTables(){return new oe({...this.#e})}}function sr(e){return Er(e)&&Er(e.config)&&Er(e.driver)&&Er(e.executor)&&Er(e.dialect)}class kt{#e;constructor(e){this.#e=f(e)}async execute(e){return this.#e.executor.provideConnection(async(t)=>{let r=this.#e.executor.withConnectionProvider(new ve(t)),n=new F({...this.#e,executor:r});return await e(n)})}}class $e{#e;constructor(e){this.#e=f(e)}setAccessMode(e){return new $e({...this.#e,accessMode:e})}setIsolationLevel(e){return new $e({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:t,accessMode:r,...n}=this.#e,o={isolationLevel:t,accessMode:r};return ot(o),this.#e.executor.provideConnection(async(d)=>{let l={isCommitted:!1,isRolledBack:!1},g=new G(this.#e.executor.withConnectionProvider(new ve(d)),l),A=new oe({...n,executor:g}),D=!1;try{await this.#e.driver.beginTransaction(d,o),D=!0;let z=await e(A);return await this.#e.driver.commitTransaction(d),l.isCommitted=!0,z}catch(z){if(D)await this.#e.driver.rollbackTransaction(d),l.isRolledBack=!0;throw z}})}}class Fe{#e;constructor(e){this.#e=f(e)}setAccessMode(e){return new Fe({...this.#e,accessMode:e})}setIsolationLevel(e){return new Fe({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:t,...r}=this.#e,n={isolationLevel:e,accessMode:t};ot(n);let o=await vu(this.#e.executor);return await this.#e.driver.beginTransaction(o.connection,n),new K({...r,connection:o,executor:this.#e.executor.withConnectionProvider(new ve(o.connection))})}}class K extends oe{#e;#t;#r;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new G(e.executor,t)};let{connection:r,...n}=e;super(n);this.#e=f(e),this.#r=t;let o=Ye();this.#t=(d)=>e.executor.compileQuery(d,o)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return ne(this.#r),new Ne(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return ne(this.#r),new Ne(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}rollbackToSavepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}releaseSavepoint(e){return ne(this.#r),new Ne(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new K({...this.#e})))}withPlugin(e){return new K({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new K({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new K({...this.#e,executor:this.#e.executor.withPluginAtFront(new rs(e))})}withTables(){return new K({...this.#e})}}class Ne{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}}function ne(e){if(e.isCommitted)throw Error("Transaction is already committed");if(e.isRolledBack)throw Error("Transaction is already rolled back")}class G{#e;#t;constructor(e,t){if(e instanceof G)this.#e=e.#e;else this.#e=e;this.#t=t}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e){return ne(this.#t),this.#e.executeQuery(e)}stream(e,t){return ne(this.#t),this.#e.stream(e,t)}withConnectionProvider(e){return new G(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new G(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new G(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new G(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new G(this.#e.withoutPlugins(),this.#t)}}function k(e,t){return Bt.createWithChildren([Bt.createWithSql(`${e} `),ze.create(t)])}class st{#e;#t=new Wt;#r;#n;constructor(e){this.#e=f({...e})}async init(){if(this.#r=Kt(this.#e.database)?await this.#e.database():this.#e.database,this.#n=new Mt(this.#r),this.#e.onCreateConnection)await this.#e.onCreateConnection(this.#n)}async acquireConnection(){return await this.#t.lock(),this.#n}async beginTransaction(e){await e.executeQuery(ur.raw("begin"))}async commitTransaction(e){await e.executeQuery(ur.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(ur.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ye()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ye()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release",t),Ye()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#r?.close()}}class Mt{#e;constructor(e){this.#e=e}executeQuery(e){let{sql:t,parameters:r}=e,n=this.#e.prepare(t);if(n.reader)return Promise.resolve({rows:n.all(r)});let{changes:o,lastInsertRowid:d}=n.run(r);return Promise.resolve({numAffectedRows:o!==void 0&&o!==null?BigInt(o):void 0,insertId:d!==void 0&&d!==null?BigInt(d):void 0,rows:[]})}async*streamQuery(e,t){let{sql:r,parameters:n,query:o}=e,d=this.#e.prepare(r);if($t.is(o)){let l=d.iterate(n);for(let g of l)yield{rows:[g]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class Wt{#e;#t;async lock(){while(this.#e)await this.#e;this.#e=new Promise((e)=>{this.#t=e})}unlock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}}class at{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#r(e)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e,t){let r=e.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").select(["name","sql","type"]).orderBy("name");if(!t.withInternalKyselyTables)r=r.where("name","!=",Yr).where("name","!=",An);return r}async#r(e){let t=await this.#t(this.#e,e).execute(),r=await this.#e.with("table_list",(o)=>this.#t(o,e)).selectFrom(["table_list as tl",Pe`pragma_table_info(tl.name)`.as("p")]).select(["tl.name as table","p.cid","p.name","p.type","p.notnull","p.dflt_value","p.pk"]).orderBy("tl.name").orderBy("p.cid").execute(),n={};for(let o of r)n[o.table]??=[],n[o.table].push(o);return t.map(({name:o,sql:d,type:l})=>{let g=d?.split(/[\(\),]/)?.find((D)=>D.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),A=n[o]??[];if(!g){let D=A.filter((z)=>z.pk>0);if(D.length===1&&D[0].type.toLowerCase()==="integer")g=D[0].name}return{name:o,isView:l==="view",columns:A.map((D)=>({name:D.name,dataType:D.type,isNullable:!D.notnull,isAutoIncrementing:D.name===g,hasDefaultValue:D.dflt_value!=null,comment:void 0}))}})}}class je{#e;constructor(e){this.#e=f({...e})}createDriver(){return new st(this.#e)}createQueryCompiler(){return new Yi}createAdapter(){return new Ji}createIntrospector(e){return new at(e)}}var ar=/"/g;class ct extends Dn{sanitizeIdentifier(e){return e.replace(ar,'""')}}class ut{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((t)=>({name:t.nspname}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("pg_catalog.pg_attribute as a").innerJoin("pg_catalog.pg_class as c","a.attrelid","c.oid").innerJoin("pg_catalog.pg_namespace as ns","c.relnamespace","ns.oid").innerJoin("pg_catalog.pg_type as typ","a.atttypid","typ.oid").innerJoin("pg_catalog.pg_namespace as dtns","typ.typnamespace","dtns.oid").select(["a.attname as column","a.attnotnull as not_null","a.atthasdef as has_default","c.relname as table","c.relkind as table_type","ns.nspname as schema","typ.typname as type","dtns.nspname as type_schema",Pe`col_description(a.attrelid, a.attnum)`.as("column_description"),Pe`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as("auto_incrementing")]).where("c.relkind","in",["r","v","p"]).where("ns.nspname","!~","^pg_").where("ns.nspname","!=","information_schema").where("ns.nspname","!=","crdb_internal").where(Pe`has_schema_privilege(ns.nspname, 'USAGE')`).where("a.attnum",">=",0).where("a.attisdropped","!=",!0).orderBy("ns.nspname").orderBy("c.relname").orderBy("a.attnum").$castTo();if(!e.withInternalKyselyTables)t=t.where("c.relname","!=",Yr).where("c.relname","!=",An);let r=await t.execute();return this.#t(r)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){let t=new Map;for(let r=0,n=e.length;r<n;r++){let o=e[r],{schema:d,table:l}=o,g=`schema:${d};table:${l}`;if(!t.has(g))t.set(g,f({columns:[],isView:o.table_type==="v",name:l,schema:d}));t.get(g).columns.push(f({comment:o.column_description??void 0,dataType:o.type,dataTypeSchema:o.type_schema,hasDefaultValue:o.has_default,isAutoIncrementing:o.auto_incrementing!==null,isNullable:!o.not_null,name:o.column}))}return Array.from(t.values())}}var cr=BigInt("3853314791062309107");class lt extends Js{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await Pe`select pg_advisory_xact_lock(${Pe.lit(cr)})`.execute(e)}async releaseMigrationLock(e,t){}}function _e(e,t){if(mr(e)&&t.stack){let r=t.stack.split(`
3
3
  `).slice(1).join(`
4
4
  `);return e.stack+=`
5
- ${r}`,e}return e}function mr(e){return vr(e)&&$t(e.stack)}var Lt=Symbol();class mt{#e;#t=new WeakMap;#r;constructor(e){this.#e=f({...e})}async init(){this.#r=Qt(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#n(),t=this.#t.get(e);if(!t){if(t=new Rt(e),this.#t.set(e,t),this.#e?.onCreateConnection)await this.#e.onCreateConnection(t)}if(this.#e?.onReserveConnection)await this.#e.onReserveConnection(t);return t}async#n(){return new Promise((e,t)=>{this.#r.getConnection(async(r,n)=>{if(r)t(r);else e(n)})})}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let r=[];if(t.isolationLevel)r.push(`isolation level ${t.isolationLevel}`);if(t.accessMode)r.push(t.accessMode);let n=`set transaction ${r.join(", ")}`;await e.executeQuery(sr.raw(n))}await e.executeQuery(sr.raw("begin"))}async commitTransaction(e){await e.executeQuery(sr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(sr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ve()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ve()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release savepoint",t),Ve()))}async releaseConnection(e){e[Lt]()}async destroy(){return new Promise((e,t)=>{this.#r.end((r)=>{if(r)t(r);else e()})})}}function dr(e){return vr(e)&&"insertId"in e&&"affectedRows"in e}class Rt{#e;constructor(e){this.#e=e}async executeQuery(e){try{let t=await this.#t(e);if(dr(t)){let{insertId:r,affectedRows:n,changedRows:o}=t;return{insertId:r!==void 0&&r!==null&&r.toString()!=="0"?BigInt(r):void 0,numAffectedRows:n!==void 0&&n!==null?BigInt(n):void 0,numChangedRows:o!==void 0&&o!==null?BigInt(o):void 0,rows:[]}}else if(Array.isArray(t))return{rows:t};return{rows:[]}}catch(t){throw _e(t,Error())}}#t(e){return new Promise((t,r)=>{this.#e.query(e.sql,e.parameters,(n,o)=>{if(n)r(n);else t(o)})})}async*streamQuery(e,t){let r=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let n of r)yield{rows:[n]}}catch(n){if(n&&typeof n==="object"&&"code"in n&&n.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw n}}[Lt](){this.#e.release()}}var hr=/[\\']/g,dt=/`/g,pr=/[\\'"]/g;class ht extends Tn{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return dt.source}getRightIdentifierWrapper(){return dt.source}sanitizeIdentifier(e){return e.replace(dt,"``")}sanitizeStringLiteral(e){return e.replace(hr,(t)=>t==="\\"?"\\\\":"''")}sanitizeJSONPathMemberValue(e){return e.replace(pr,(t)=>t==="\\"?"\\\\\\\\":t==="'"?"''":'\\\\"')}visitCreateIndex(e){if(this.append("create "),e.unique)this.append("unique ");if(this.append("index "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),e.using)this.append(" using "),this.visitNode(e.using);if(e.table)this.append(" on "),this.visitNode(e.table);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.where)this.append(" "),this.visitNode(e.where)}}class pt{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map((t)=>({name:t.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",(n)=>n.onRef("columns.TABLE_CATALOG","=","tables.TABLE_CATALOG").onRef("columns.TABLE_SCHEMA","=","tables.TABLE_SCHEMA").onRef("columns.TABLE_NAME","=","tables.TABLE_NAME")).select(["columns.COLUMN_NAME","columns.COLUMN_DEFAULT","columns.TABLE_NAME","columns.TABLE_SCHEMA","tables.TABLE_TYPE","columns.IS_NULLABLE","columns.DATA_TYPE","columns.EXTRA","columns.COLUMN_COMMENT"]).where("columns.TABLE_SCHEMA","=",Pe`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!e.withInternalKyselyTables)t=t.where("columns.TABLE_NAME","!=",$r).where("columns.TABLE_NAME","!=",ln);let r=await t.execute();return this.#t(r)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){return e.reduce((t,r)=>{let n=t.find((o)=>o.name===r.TABLE_NAME);if(!n)n=f({name:r.TABLE_NAME,isView:r.TABLE_TYPE==="VIEW",schema:r.TABLE_SCHEMA,columns:[]}),t.push(n);return n.columns.push(f({name:r.COLUMN_NAME,dataType:r.DATA_TYPE,isNullable:r.IS_NULLABLE==="YES",isAutoIncrementing:r.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:r.COLUMN_DEFAULT!==null,comment:r.COLUMN_COMMENT===""?void 0:r.COLUMN_COMMENT})),t},[])}}var Ft="ea586330-2c93-47c8-908d-981d9d270f9d",fr=3600;class ft extends Pa{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await Pe`select get_lock(${Pe.lit(Ft)}, ${Pe.lit(fr)})`.execute(e)}async releaseMigrationLock(e,t){await Pe`select release_lock(${Pe.lit(Ft)})`.execute(e)}}class Ue{#e;constructor(e){this.#e=e}createDriver(){return new mt(this.#e)}createQueryCompiler(){return new ht}createAdapter(){return new ft}createIntrospector(e){return new pt(e)}}var zt=Symbol();class yt{#e;#t=new WeakMap;#r;constructor(e){this.#e=f({...e})}async init(){this.#r=Qt(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#r.connect(),t=this.#t.get(e);if(!t){if(t=new Vt(e,{cursor:this.#e.cursor??null}),this.#t.set(e,t),this.#e.onCreateConnection)await this.#e.onCreateConnection(t)}if(this.#e.onReserveConnection)await this.#e.onReserveConnection(t);return t}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let r="start transaction";if(t.isolationLevel)r+=` isolation level ${t.isolationLevel}`;if(t.accessMode)r+=` ${t.accessMode}`;await e.executeQuery(sr.raw(r))}else await e.executeQuery(sr.raw("begin"))}async commitTransaction(e){await e.executeQuery(sr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(sr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ve()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ve()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release",t),Ve()))}async releaseConnection(e){e[zt]()}async destroy(){if(this.#r){let e=this.#r;this.#r=void 0,await e.end()}}}class Vt{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async executeQuery(e){try{let{command:t,rowCount:r,rows:n}=await this.#e.query(e.sql,[...e.parameters]);return{numAffectedRows:t==="INSERT"||t==="UPDATE"||t==="DELETE"||t==="MERGE"?BigInt(r):void 0,rows:n??[]}}catch(t){throw _e(t,Error())}}async*streamQuery(e,t){if(!this.#t.cursor)throw Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");if(!Number.isInteger(t)||t<=0)throw Error("chunkSize must be a positive integer");let r=this.#e.query(new this.#t.cursor(e.sql,e.parameters.slice()));try{while(!0){let n=await r.read(t);if(n.length===0)break;yield{rows:n}}}finally{await r.close()}}[zt](){this.#e.release()}}class Be{#e;constructor(e){this.#e=e}createDriver(){return new yt(this.#e)}createQueryCompiler(){return new ct}createAdapter(){return new lt}createIntrospector(e){return new ut(e)}}class wt extends Pa{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await Pe`exec sp_getapplock @DbPrincipal = ${Pe.lit("dbo")}, @Resource = ${Pe.lit($r)}, @LockMode = ${Pe.lit("Exclusive")}`.execute(e)}async releaseMigrationLock(){}}var Bt=Symbol(),Kt=Symbol(),Gt=Symbol();class xt{#e;#t;constructor(e){this.#e=f({...e});let{tarn:t,tedious:r,validateConnections:n}=this.#e,{validateConnections:o,...d}=t.options;this.#t=new t.Pool({...d,create:async()=>{let l=await r.connectionFactory();return await new Jt(l,r).connect()},destroy:async(l)=>{await l[Kt]()},validate:n===!1||o===!1?void 0:(l)=>l[Gt]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){if(this.#e.resetConnectionsOnRelease||this.#e.tedious.resetConnectionOnRelease)await e[Bt]();this.#t.release(e)}async destroy(){await this.#t.destroy()}}class Jt{#e;#t;#r;constructor(e,t){this.#e=e,this.#t=!1,this.#r=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((r,n)=>this.#e.beginTransaction((o)=>{if(o)n(o);else r(void 0)},t?Xc(8):void 0,t?this.#n(t):void 0))}async commitTransaction(){await new Promise((e,t)=>this.#e.commitTransaction((r)=>{if(r)t(r);else e(void 0)}))}async connect(){let{promise:e,reject:t,resolve:r}=new _s;this.#e.connect((o)=>{if(o)return t(o);r()}),this.#e.on("error",(o)=>{if(o instanceof Error&&"code"in o&&o.code==="ESOCKET")this.#t=!0;console.error(o),t(o)});function n(){t(Error("The connection ended without ever completing the connection"))}return this.#e.once("end",n),await e,this.#e.off("end",n),this}async executeQuery(e){try{let t=new _s,r=new Ke({compiledQuery:e,tedious:this.#r,onDone:t});this.#e.execSql(r.request);let{rowCount:n,rows:o}=await t.promise;return{numAffectedRows:n!==void 0?BigInt(n):void 0,rows:o}}catch(t){throw _e(t,Error())}}async rollbackTransaction(e){await new Promise((t,r)=>this.#e.rollbackTransaction((n)=>{if(n)r(n);else t(void 0)},e))}async savepoint(e){await new Promise((t,r)=>this.#e.saveTransaction((n)=>{if(n)r(n);else t(void 0)},e))}async*streamQuery(e,t){if(!Number.isInteger(t)||t<=0)throw Error("chunkSize must be a positive integer");let r=new Ke({compiledQuery:e,streamChunkSize:t,tedious:this.#r});this.#e.execSql(r.request);try{while(!0){let n=await r.readChunk();if(n.length===0)break;if(yield{rows:n},n.length<t)break}}finally{await this.#o(r)}}#n(e){let{ISOLATION_LEVEL:t}=this.#r,n={"read committed":t.READ_COMMITTED,"read uncommitted":t.READ_UNCOMMITTED,"repeatable read":t.REPEATABLE_READ,serializable:t.SERIALIZABLE,snapshot:t.SNAPSHOT}[e];if(n===void 0)throw Error(`Unknown isolation level: ${e}`);return n}#o(e){return new Promise((t)=>{if(e.request.once("requestCompleted",t),!this.#e.cancel())e.request.off("requestCompleted",t),t()})}[Kt](){if("closed"in this.#e&&this.#e.closed)return Promise.resolve();return new Promise((e)=>{this.#e.once("end",e),this.#e.close()})}async[Bt](){await new Promise((e,t)=>{this.#e.reset((r)=>{if(r)return t(r);e()})})}async[Gt](){if(this.#t||this.#i())return!1;try{let e=new _s,t=new Ke({compiledQuery:sr.raw("select 1"),onDone:e,tedious:this.#r});return this.#e.execSql(t.request),await e.promise,!0}catch{return!1}}#i(){return"closed"in this.#e&&Boolean(this.#e.closed)}}class Ke{#e;#t;#r;#n;#o;#i;constructor(e){let{compiledQuery:t,onDone:r,streamChunkSize:n,tedious:o}=e;if(this.#t=[],this.#r=n,this.#n={},this.#o=o,r)this.#n.onDone=(l,g)=>{if(l==="chunkReady")return;if(delete this.#n.onDone,l==="error")return r.reject(g);r.resolve({rowCount:this.#i,rows:this.#t})};this.#e=new this.#o.Request(t.sql,(d,l)=>{if(d)return Object.values(this.#n).forEach((g)=>g("error",d instanceof AggregateError?d.errors:d));this.#i=l}),this.#a(t.parameters),this.#c()}get request(){return this.#e}readChunk(){let e=this.readChunk.name;return new Promise((t,r)=>{this.#n[e]=(n,o)=>{if(delete this.#n[e],n==="error")return r(o);t(this.#t.splice(0,this.#r))},this.#e.resume()})}#a(e){for(let t=0;t<e.length;t++){let r=e[t];this.#e.addParameter(String(t+1),this.#s(r),r)}}#c(){let e=this.#r?()=>{if(this.#r<=this.#t.length)this.#e.pause(),Object.values(this.#n).forEach((r)=>r("chunkReady"))}:()=>{},t=(r)=>{let n={};for(let o of r)n[o.metadata.colName]=o.value;this.#t.push(n),e()};this.#e.on("row",t),this.#e.once("requestCompleted",()=>{Object.values(this.#n).forEach((r)=>r("completed")),this.#e.off("row",t)})}#s(e){if(Na(e)||Cn(e)||$t(e))return this.#o.TYPES.NVarChar;if(Oa(e)||No(e)&&e%1===0)if(e<-2147483648||e>2147483647)return this.#o.TYPES.BigInt;else return this.#o.TYPES.Int;if(No(e))return this.#o.TYPES.Float;if(sa(e))return this.#o.TYPES.Bit;if(ru(e))return this.#o.TYPES.DateTime;if(Np(e))return this.#o.TYPES.VarBinary;return this.#o.TYPES.NVarChar}}class Nt{#e;constructor(e){this.#e=e}async getSchemas(){return await this.#e.selectFrom("sys.schemas").select("name").execute()}async getTables(e={withInternalKyselyTables:!1}){let t=await this.#e.selectFrom("sys.tables as tables").leftJoin("sys.schemas as table_schemas","table_schemas.schema_id","tables.schema_id").innerJoin("sys.columns as columns","columns.object_id","tables.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(n)=>n.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!e.withInternalKyselyTables,(n)=>n.where("tables.name","!=",$r).where("tables.name","!=",ln)).select(["tables.name as table_name",(n)=>n.ref("tables.type").$castTo().as("table_type"),"table_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"]).unionAll(this.#e.selectFrom("sys.views as views").leftJoin("sys.schemas as view_schemas","view_schemas.schema_id","views.schema_id").innerJoin("sys.columns as columns","columns.object_id","views.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(n)=>n.onRef("comments.major_id","=","views.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).select(["views.name as table_name","views.type as table_type","view_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"])).orderBy("table_schema_name").orderBy("table_name").orderBy("column_name").execute(),r={};for(let n of t){let o=`${n.table_schema_name}.${n.table_name}`;(r[o]=r[o]||f({columns:[],isView:n.table_type==="V ",name:n.table_name,schema:n.table_schema_name??void 0})).columns.push(f({dataType:n.type_name,dataTypeSchema:n.type_schema_name??void 0,hasDefaultValue:n.column_default_object_id>0||n.column_generated_always_type!=="NOT_APPLICABLE"||n.column_is_identity||n.column_is_computed||n.column_is_rowguidcol,isAutoIncrementing:n.column_is_identity,isNullable:n.column_is_nullable&&n.type_is_nullable,name:n.column_name,comment:n.column_comment??void 0}))}return Object.values(r)}async getMetadata(e){return{tables:await this.getTables(e)}}}var yr=/^[a-z0-9_]$/i;class _t extends Tn{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(e){super.visitOffset(e),this.append(" rows")}compileColumnAlterations(e){let t={};for(let n of e){if(!t[n.kind])t[n.kind]=[];t[n.kind].push(n)}let r=!0;if(t.AddColumnNode)this.append("add "),this.compileList(t.AddColumnNode),r=!1;if(t.AlterColumnNode){if(!r)this.append(", ");this.compileList(t.AlterColumnNode)}if(t.DropColumnNode){if(!r)this.append(", ");this.append("drop column "),this.compileList(t.DropColumnNode)}if(t.ModifyColumnNode){if(!r)this.append(", ");this.compileList(t.ModifyColumnNode)}if(t.RenameColumnNode){if(!r)this.append(", ");this.compileList(t.RenameColumnNode)}}visitAddColumn(e){this.visitNode(e.column)}visitDropColumn(e){this.visitNode(e.column)}visitMergeQuery(e){super.visitMergeQuery(e),this.append(";")}visitCollate(e){this.append("collate ");let{name:t}=e.collation;for(let r of t)if(!yr.test(r))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}}class Ct{#e;constructor(e){this.#e=e}createDriver(){return new xt(this.#e)}createQueryCompiler(){return new _t}createAdapter(){return new wt}createIntrospector(e){return new Nt(e)}}function Tt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Kc(e){if(!e)return null;if("dialect"in e)return Kc(e.dialect);if("createDriver"in e){if(e instanceof je)return"sqlite";if(e instanceof Ue)return"mysql";if(e instanceof Be)return"postgres";if(e instanceof Ct)return"mssql"}if("aggregate"in e)return"sqlite";if("getConnection"in e)return"mysql";if("connect"in e)return"postgres";if("fileControl"in e)return"sqlite";if("open"in e&&"close"in e&&"prepare"in e)return"sqlite";if("batch"in e&&"exec"in e&&"prepare"in e)return"sqlite";return null}var Rd=async(e)=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,transaction:void 0};if("db"in t)return{kysely:t.db,databaseType:t.type,transaction:t.transaction};if("dialect"in t)return{kysely:new F({dialect:t.dialect}),databaseType:t.type,transaction:t.transaction};let r=void 0,n=Kc(t);if("createDriver"in t)r=t;if("aggregate"in t&&!("createSession"in t))r=new je({database:t});if("getConnection"in t)r=new Ue(t);if("connect"in t)r=new Be({pool:t});if("fileControl"in t){let{BunSqliteDialect:o}=await import("./chunk-hfh0c082.js");r=new o({database:t})}if("createSession"in t){let o=void 0;try{({DatabaseSync:o}=await import("node:sqlite"))}catch(d){if(d!==null&&typeof d==="object"&&"code"in d&&d.code!=="ERR_UNKNOWN_BUILTIN_MODULE")throw d}if(o&&t instanceof o){let{NodeSqliteDialect:d}=await import("./chunk-4v5n0ayb.js");r=new d({database:t})}}if("batch"in t&&"exec"in t&&"prepare"in t){let{D1SqliteDialect:o}=await import("./chunk-qf24e71w.js");r=new o({database:t})}return{kysely:r?new F({dialect:r}):null,databaseType:n,transaction:void 0}};function gt(e,t,r){return r==="postgres"?Pe`${Pe.ref(e)} ILIKE ${t}`:Pe`LOWER(${Pe.ref(e)}) LIKE LOWER(${t})`}function wr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function xr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function Nr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,value:t.toLowerCase()}}function _r(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,value:t.toLowerCase()}}var LI=(e,t)=>{let r=null,n=(l,g=!1)=>({getFieldName:A,schema:D,getDefaultFieldName:z,getDefaultModelName:Ht,getFieldAttributes:Cr,getModelName:te})=>{let Et=(u)=>{let x=[],y=[];if(u)for(let[h,m]of Object.entries(u)){let a=D[Ht(h)]?.fields,[c,w]=h.includes(".")?h.split("."):[void 0,h];if(!a)continue;a.id={type:"string"};for(let[v,i]of Object.entries(a))x.push(Pe`${Pe.ref(`join_${w}`)}.${Pe.ref(i.fieldName||v)} as ${Pe.ref(`_joined_${w}_${i.fieldName||v}`)}`),y.push({joinModel:h,joinModelRef:w,fieldName:i.fieldName||v})}return{allSelectsStr:y,allSelects:x}},bt=async(u,x,y,h)=>{let m;if(t?.type==="mysql"){await x.execute();let a=u.id?"id":h.length>0&&h[0]?.field?h[0].field:"id";if(!u.id&&h.length===0)return m=await l.selectFrom(y).selectAll().orderBy(A({model:y,field:a}),"desc").limit(1).executeTakeFirst(),m;let c=u[a]!==void 0?u[a]:h[0]?.value;return m=await l.selectFrom(y).selectAll().orderBy(A({model:y,field:a}),"desc").where(A({model:y,field:a}),c===null?"is":"=",c).limit(1).executeTakeFirst(),m}if(t?.type==="mssql")return m=await x.outputAll("inserted").executeTakeFirst(),m;return m=await x.returningAll().executeTakeFirst(),m};function J(u,x){if(!x)return{and:null,or:null};let y={and:[],or:[]};return x.forEach((h)=>{let{field:m,value:a,operator:c="eq",connector:w="AND",mode:v="sensitive"}=h,i=a,C=A({model:u,field:m}),N=v==="insensitive"&&(typeof i==="string"||Array.isArray(i)&&i.every((p)=>typeof p==="string")),T=(p)=>{let s=`${u}.${C}`;if(c.toLowerCase()==="in"){if(N){let{lhs:q,values:E}=wr(s,Array.isArray(i)?i:[i]);return p(q,"in",E)}return p(s,"in",Array.isArray(i)?i:[i])}if(c.toLowerCase()==="not_in"){if(N){let{lhs:q,values:E}=xr(s,Array.isArray(i)?i:[i]);return p(q,"not in",E)}return p(s,"not in",Array.isArray(i)?i:[i])}if(c==="contains"){if(N&&typeof i==="string")return gt(s,`%${i}%`,t?.type);return p(s,"like",`%${i}%`)}if(c==="starts_with"){if(N&&typeof i==="string")return gt(s,`${i}%`,t?.type);return p(s,"like",`${i}%`)}if(c==="ends_with"){if(N&&typeof i==="string")return gt(s,`%${i}`,t?.type);return p(s,"like",`%${i}`)}if(c==="eq"){if(i===null)return p(s,"is",null);if(N&&typeof i==="string"){let{lhs:q,value:E}=Nr(s,i);return p(q,"=",E)}return p(s,"=",i)}if(c==="ne"){if(i===null)return p(s,"is not",null);if(N&&typeof i==="string"){let{lhs:q,value:E}=_r(s,i);return p(q,"<>",E)}return p(s,"<>",i)}if(c==="gt")return p(s,">",i);if(c==="gte")return p(s,">=",i);if(c==="lt")return p(s,"<",i);if(c==="lte")return p(s,"<=",i);return p(s,c,i)};if(w==="OR")y.or.push(T);else y.and.push(T)}),{and:y.and.length?y.and:null,or:y.or.length?y.or:null}}function It(u,x,y){if(!x||!u.length)return u;let h=new Map;for(let a of u){let c={},w={};for(let[C]of Object.entries(x))w[te(C)]={};for(let[C,N]of Object.entries(a)){let T=String(C),p=!1;for(let{joinModel:s,fieldName:q,joinModelRef:E}of y)if(T===`_joined_${E}_${q}`||T===`_Joined${Tt(E)}${Tt(q)}`){w[te(s)][A({model:s,field:q})]=N,p=!0;break}if(!p)c[C]=N}let v=c.id;if(!v)continue;if(!h.has(v)){let C={...c};for(let[N,T]of Object.entries(x))C[te(N)]=T.relation==="one-to-one"?null:[];h.set(v,C)}let i=h.get(v);for(let[C,N]of Object.entries(x)){let T=N.relation==="one-to-one",p=N.limit??100,s=w[te(C)],q=s&&Object.keys(s).length>0&&Object.values(s).some((E)=>E!==null&&E!==void 0);if(T)i[te(C)]=q?s:null;else{let E=te(C);if(Array.isArray(i[E])&&q){if(i[E].length>=p)continue;let qe=A({model:C,field:"id"}),At=s[qe];if(At){if(!i[E].some((Xt)=>Xt[qe]===At)&&i[E].length<p)i[E].push(s)}else if(i[E].length<p)i[E].push(s)}}}}let m=Array.from(h.values());for(let a of m)for(let[c,w]of Object.entries(x))if(w.relation!=="one-to-one"){let v=te(c);if(Array.isArray(a[v])){let i=w.limit??100;if(a[v].length>i)a[v]=a[v].slice(0,i)}}return m}return{async create({data:u,model:x}){return await bt(u,l.insertInto(x).values(u),x,[])},async findOne({model:u,where:x,select:y,join:h}){let{and:m,or:a}=J(u,x),c=l.selectFrom((N)=>{let T=N.selectFrom(u);if(m)T=T.where((p)=>p.and(m.map((s)=>s(p))));if(a)T=T.where((p)=>p.or(a.map((s)=>s(p))));if(y?.length&&y.length>0)T=T.select(y.map((p)=>A({model:u,field:p})));else T=T.selectAll();return T.as("primary")}).selectAll("primary");if(h)for(let[N,T]of Object.entries(h)){let[p,s]=N.includes(".")?N.split("."):[void 0,N];c=c.leftJoin(`${N} as join_${s}`,(q)=>q.onRef(`join_${s}.${T.on.to}`,"=",`primary.${T.on.from}`))}let{allSelectsStr:w,allSelects:v}=Et(h);c=c.select(v);let i=await c.execute();if(!i||!Array.isArray(i)||i.length===0)return null;let C=i[0];if(h)return It(i,h,w)[0];return C},async findMany({model:u,where:x,limit:y,select:h,offset:m,sortBy:a,join:c}){let{and:w,or:v}=J(u,x),i=l.selectFrom((p)=>{let s=p.selectFrom(u);if(t?.type==="mssql"){if(m!==void 0){if(!a)s=s.orderBy(A({model:u,field:"id"}));s=s.offset(m).fetch(y||100)}else if(y!==void 0)s=s.top(y)}else{if(y!==void 0)s=s.limit(y);if(m!==void 0)s=s.offset(m)}if(a?.field)s=s.orderBy(`${A({model:u,field:a.field})}`,a.direction);if(w)s=s.where((q)=>q.and(w.map((E)=>E(q))));if(v)s=s.where((q)=>q.or(v.map((E)=>E(q))));if(h?.length&&h.length>0)s=s.select(h.map((q)=>A({model:u,field:q})));else s=s.selectAll();return s.as("primary")}).selectAll("primary");if(c)for(let[p,s]of Object.entries(c)){let[q,E]=p.includes(".")?p.split("."):[void 0,p];i=i.leftJoin(`${p} as join_${E}`,(qe)=>qe.onRef(`join_${E}.${s.on.to}`,"=",`primary.${s.on.from}`))}let{allSelectsStr:C,allSelects:N}=Et(c);if(i=i.select(N),a?.field)i=i.orderBy(`${A({model:u,field:a.field})}`,a.direction);let T=await i.execute();if(!T)return[];if(c)return It(T,c,C);return T},async update({model:u,where:x,update:y}){let{and:h,or:m}=J(u,x),a=l.updateTable(u).set(y);if(h)a=a.where((c)=>c.and(h.map((w)=>w(c))));if(m)a=a.where((c)=>c.or(m.map((w)=>w(c))));return await bt(y,a,u,x)},async updateMany({model:u,where:x,update:y}){let{and:h,or:m}=J(u,x),a=l.updateTable(u).set(y);if(h)a=a.where((w)=>w.and(h.map((v)=>v(w))));if(m)a=a.where((w)=>w.or(m.map((v)=>v(w))));let c=(await a.executeTakeFirst()).numUpdatedRows;return c>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(c)},async count({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.selectFrom(u).select(l.fn.count("id").as("count"));if(y)m=m.where((c)=>c.and(y.map((w)=>w(c))));if(h)m=m.where((c)=>c.or(h.map((w)=>w(c))));let a=await m.execute();if(typeof a[0].count==="number")return a[0].count;if(typeof a[0].count==="bigint")return Number(a[0].count);return parseInt(a[0].count)},async delete({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.deleteFrom(u);if(y)m=m.where((a)=>a.and(y.map((c)=>c(a))));if(h)m=m.where((a)=>a.or(h.map((c)=>c(a))));await m.execute()},async deleteMany({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.deleteFrom(u);if(y)m=m.where((c)=>c.and(y.map((w)=>w(c))));if(h)m=m.where((c)=>c.or(h.map((w)=>w(c))));let a=(await m.executeTakeFirst()).numDeletedRows;return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(a)},async consumeOne({model:u,where:x}){let{and:y,or:h}=J(u,x),m=(i)=>{if(y)i=i.where((C)=>C.and(y.map((N)=>N(C))));if(h)i=i.where((C)=>C.or(h.map((N)=>N(C))));return i},a=A({model:u,field:"id"}),c=async(i,C)=>{let N=C[a]??C.id;if(N===void 0||N===null)return null;let T=i.deleteFrom(u).where(`${u}.${a}`,"=",N);if(t?.type==="mysql"){let p=await T.executeTakeFirst();return Number(p.numDeletedRows)>0?C:null}if(t?.type==="mssql")return await T.outputAll("deleted").executeTakeFirst()??null;return await T.returningAll().executeTakeFirst()??null},w=async(i)=>{if(t?.type==="mssql")return await i.outputAll("deleted").executeTakeFirst()??null;return await i.returningAll().executeTakeFirst()??null};if(t?.type==="mysql"){let i=async(C)=>{let N=await m(C.selectFrom(u).selectAll().forUpdate()).limit(1).executeTakeFirst();if(!N)return null;return c(C,N)};return g?i(l):l.transaction().execute(i)}let v=m(l.selectFrom(u).select(`${u}.${a}`)).limit(1);return w(l.deleteFrom(u).where(`${u}.${a}`,"in",v))},options:t}},o=null;o={config:{adapterId:"kysely",adapterName:"Kysely Adapter",usePlural:t?.usePlural,debugLogs:t?.debugLogs,supportsBooleans:t?.type==="sqlite"||t?.type==="mssql"||t?.type==="mysql"||!t?.type?!1:!0,supportsDates:t?.type==="sqlite"||t?.type==="mssql"||!t?.type?!1:!0,supportsJSON:t?.type==="postgres"?!0:!1,supportsArrays:!1,supportsUUIDs:t?.type==="postgres"?!0:!1,transaction:t?.transaction?(l)=>e.transaction().execute((g)=>l(oa({config:{...o.config,transaction:!1},adapter:n(g,!0)})(r))):!1},adapter:n(e)};let d=oa(o);return(l)=>(r=l,d(l))};
6
- export{Kc,Rd,LI};
5
+ ${r}`,e}return e}function mr(e){return Er(e)&&Vt(e.stack)}var Pt=Symbol();class mt{#e;#t=new WeakMap;#r;constructor(e){this.#e=f({...e})}async init(){this.#r=Kt(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#n(),t=this.#t.get(e);if(!t){if(t=new Lt(e),this.#t.set(e,t),this.#e?.onCreateConnection)await this.#e.onCreateConnection(t)}if(this.#e?.onReserveConnection)await this.#e.onReserveConnection(t);return t}async#n(){return new Promise((e,t)=>{this.#r.getConnection(async(r,n)=>{if(r)t(r);else e(n)})})}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let r=[];if(t.isolationLevel)r.push(`isolation level ${t.isolationLevel}`);if(t.accessMode)r.push(t.accessMode);let n=`set transaction ${r.join(", ")}`;await e.executeQuery(ur.raw(n))}await e.executeQuery(ur.raw("begin"))}async commitTransaction(e){await e.executeQuery(ur.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(ur.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ye()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ye()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release savepoint",t),Ye()))}async releaseConnection(e){e[Pt]()}async destroy(){return new Promise((e,t)=>{this.#r.end((r)=>{if(r)t(r);else e()})})}}function dr(e){return Er(e)&&"insertId"in e&&"affectedRows"in e}class Lt{#e;constructor(e){this.#e=e}async executeQuery(e){try{let t=await this.#t(e);if(dr(t)){let{insertId:r,affectedRows:n,changedRows:o}=t;return{insertId:r!==void 0&&r!==null&&r.toString()!=="0"?BigInt(r):void 0,numAffectedRows:n!==void 0&&n!==null?BigInt(n):void 0,numChangedRows:o!==void 0&&o!==null?BigInt(o):void 0,rows:[]}}else if(Array.isArray(t))return{rows:t};return{rows:[]}}catch(t){throw _e(t,Error())}}#t(e){return new Promise((t,r)=>{this.#e.query(e.sql,e.parameters,(n,o)=>{if(n)r(n);else t(o)})})}async*streamQuery(e,t){let r=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let n of r)yield{rows:[n]}}catch(n){if(n&&typeof n==="object"&&"code"in n&&n.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw n}}[Pt](){this.#e.release()}}var hr=/[\\']/g,dt=/`/g,pr=/[\\'"]/g;class ht extends Dn{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return dt.source}getRightIdentifierWrapper(){return dt.source}sanitizeIdentifier(e){return e.replace(dt,"``")}sanitizeStringLiteral(e){return e.replace(hr,(t)=>t==="\\"?"\\\\":"''")}sanitizeJSONPathMemberValue(e){return e.replace(pr,(t)=>t==="\\"?"\\\\\\\\":t==="'"?"''":'\\\\"')}visitCreateIndex(e){if(this.append("create "),e.unique)this.append("unique ");if(this.append("index "),e.ifNotExists)this.append("if not exists ");if(this.visitNode(e.name),e.using)this.append(" using "),this.visitNode(e.using);if(e.table)this.append(" on "),this.visitNode(e.table);if(e.columns)this.append(" ("),this.compileList(e.columns),this.append(")");if(e.where)this.append(" "),this.visitNode(e.where)}}class pt{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map((t)=>({name:t.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",(n)=>n.onRef("columns.TABLE_CATALOG","=","tables.TABLE_CATALOG").onRef("columns.TABLE_SCHEMA","=","tables.TABLE_SCHEMA").onRef("columns.TABLE_NAME","=","tables.TABLE_NAME")).select(["columns.COLUMN_NAME","columns.COLUMN_DEFAULT","columns.TABLE_NAME","columns.TABLE_SCHEMA","tables.TABLE_TYPE","columns.IS_NULLABLE","columns.DATA_TYPE","columns.EXTRA","columns.COLUMN_COMMENT"]).where("columns.TABLE_SCHEMA","=",Pe`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!e.withInternalKyselyTables)t=t.where("columns.TABLE_NAME","!=",Yr).where("columns.TABLE_NAME","!=",An);let r=await t.execute();return this.#t(r)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){return e.reduce((t,r)=>{let n=t.find((o)=>o.name===r.TABLE_NAME);if(!n)n=f({name:r.TABLE_NAME,isView:r.TABLE_TYPE==="VIEW",schema:r.TABLE_SCHEMA,columns:[]}),t.push(n);return n.columns.push(f({name:r.COLUMN_NAME,dataType:r.DATA_TYPE,isNullable:r.IS_NULLABLE==="YES",isAutoIncrementing:r.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:r.COLUMN_DEFAULT!==null,comment:r.COLUMN_COMMENT===""?void 0:r.COLUMN_COMMENT})),t},[])}}var Rt="ea586330-2c93-47c8-908d-981d9d270f9d",fr=3600;class ft extends Js{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await Pe`select get_lock(${Pe.lit(Rt)}, ${Pe.lit(fr)})`.execute(e)}async releaseMigrationLock(e,t){await Pe`select release_lock(${Pe.lit(Rt)})`.execute(e)}}class Ve{#e;constructor(e){this.#e=e}createDriver(){return new mt(this.#e)}createQueryCompiler(){return new ht}createAdapter(){return new ft}createIntrospector(e){return new pt(e)}}var Qt=Symbol();class yt{#e;#t=new WeakMap;#r;constructor(e){this.#e=f({...e})}async init(){this.#r=Kt(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#r.connect(),t=this.#t.get(e);if(!t){if(t=new zt(e,{cursor:this.#e.cursor??null}),this.#t.set(e,t),this.#e.onCreateConnection)await this.#e.onCreateConnection(t)}if(this.#e.onReserveConnection)await this.#e.onReserveConnection(t);return t}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let r="start transaction";if(t.isolationLevel)r+=` isolation level ${t.isolationLevel}`;if(t.accessMode)r+=` ${t.accessMode}`;await e.executeQuery(ur.raw(r))}else await e.executeQuery(ur.raw("begin"))}async commitTransaction(e){await e.executeQuery(ur.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(ur.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(k("savepoint",t),Ye()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(k("rollback to",t),Ye()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(k("release",t),Ye()))}async releaseConnection(e){e[Qt]()}async destroy(){if(this.#r){let e=this.#r;this.#r=void 0,await e.end()}}}class zt{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async executeQuery(e){try{let{command:t,rowCount:r,rows:n}=await this.#e.query(e.sql,[...e.parameters]);return{numAffectedRows:t==="INSERT"||t==="UPDATE"||t==="DELETE"||t==="MERGE"?BigInt(r):void 0,rows:n??[]}}catch(t){throw _e(t,Error())}}async*streamQuery(e,t){if(!this.#t.cursor)throw Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");if(!Number.isInteger(t)||t<=0)throw Error("chunkSize must be a positive integer");let r=this.#e.query(new this.#t.cursor(e.sql,e.parameters.slice()));try{while(!0){let n=await r.read(t);if(n.length===0)break;yield{rows:n}}}finally{await r.close()}}[Qt](){this.#e.release()}}class Ue{#e;constructor(e){this.#e=e}createDriver(){return new yt(this.#e)}createQueryCompiler(){return new ct}createAdapter(){return new lt}createIntrospector(e){return new ut(e)}}class wt extends Js{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await Pe`exec sp_getapplock @DbPrincipal = ${Pe.lit("dbo")}, @Resource = ${Pe.lit(Yr)}, @LockMode = ${Pe.lit("Exclusive")}`.execute(e)}async releaseMigrationLock(){}}var jt=Symbol(),Ut=Symbol(),Gt=Symbol();class xt{#e;#t;constructor(e){this.#e=f({...e});let{tarn:t,tedious:r,validateConnections:n}=this.#e,{validateConnections:o,...d}=t.options;this.#t=new t.Pool({...d,create:async()=>{let l=await r.connectionFactory();return await new Jt(l,r).connect()},destroy:async(l)=>{await l[Ut]()},validate:n===!1||o===!1?void 0:(l)=>l[Gt]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){if(this.#e.resetConnectionsOnRelease||this.#e.tedious.resetConnectionOnRelease)await e[jt]();this.#t.release(e)}async destroy(){await this.#t.destroy()}}class Jt{#e;#t;#r;constructor(e,t){this.#e=e,this.#t=!1,this.#r=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((r,n)=>this.#e.beginTransaction((o)=>{if(o)n(o);else r(void 0)},t?wu(8):void 0,t?this.#n(t):void 0))}async commitTransaction(){await new Promise((e,t)=>this.#e.commitTransaction((r)=>{if(r)t(r);else e(void 0)}))}async connect(){let{promise:e,reject:t,resolve:r}=new La;this.#e.connect((o)=>{if(o)return t(o);r()}),this.#e.on("error",(o)=>{if(o instanceof Error&&"code"in o&&o.code==="ESOCKET")this.#t=!0;console.error(o),t(o)});function n(){t(Error("The connection ended without ever completing the connection"))}return this.#e.once("end",n),await e,this.#e.off("end",n),this}async executeQuery(e){try{let t=new La,r=new Be({compiledQuery:e,tedious:this.#r,onDone:t});this.#e.execSql(r.request);let{rowCount:n,rows:o}=await t.promise;return{numAffectedRows:n!==void 0?BigInt(n):void 0,rows:o}}catch(t){throw _e(t,Error())}}async rollbackTransaction(e){await new Promise((t,r)=>this.#e.rollbackTransaction((n)=>{if(n)r(n);else t(void 0)},e))}async savepoint(e){await new Promise((t,r)=>this.#e.saveTransaction((n)=>{if(n)r(n);else t(void 0)},e))}async*streamQuery(e,t){if(!Number.isInteger(t)||t<=0)throw Error("chunkSize must be a positive integer");let r=new Be({compiledQuery:e,streamChunkSize:t,tedious:this.#r});this.#e.execSql(r.request);try{while(!0){let n=await r.readChunk();if(n.length===0)break;if(yield{rows:n},n.length<t)break}}finally{await this.#o(r)}}#n(e){let{ISOLATION_LEVEL:t}=this.#r,n={"read committed":t.READ_COMMITTED,"read uncommitted":t.READ_UNCOMMITTED,"repeatable read":t.REPEATABLE_READ,serializable:t.SERIALIZABLE,snapshot:t.SNAPSHOT}[e];if(n===void 0)throw Error(`Unknown isolation level: ${e}`);return n}#o(e){return new Promise((t)=>{if(e.request.once("requestCompleted",t),!this.#e.cancel())e.request.off("requestCompleted",t),t()})}[Ut](){if("closed"in this.#e&&this.#e.closed)return Promise.resolve();return new Promise((e)=>{this.#e.once("end",e),this.#e.close()})}async[jt](){await new Promise((e,t)=>{this.#e.reset((r)=>{if(r)return t(r);e()})})}async[Gt](){if(this.#t||this.#i())return!1;try{let e=new La,t=new Be({compiledQuery:ur.raw("select 1"),onDone:e,tedious:this.#r});return this.#e.execSql(t.request),await e.promise,!0}catch{return!1}}#i(){return"closed"in this.#e&&Boolean(this.#e.closed)}}class Be{#e;#t;#r;#n;#o;#i;constructor(e){let{compiledQuery:t,onDone:r,streamChunkSize:n,tedious:o}=e;if(this.#t=[],this.#r=n,this.#n={},this.#o=o,r)this.#n.onDone=(l,g)=>{if(l==="chunkReady")return;if(delete this.#n.onDone,l==="error")return r.reject(g);r.resolve({rowCount:this.#i,rows:this.#t})};this.#e=new this.#o.Request(t.sql,(d,l)=>{if(d)return Object.values(this.#n).forEach((g)=>g("error",d instanceof AggregateError?d.errors:d));this.#i=l}),this.#a(t.parameters),this.#c()}get request(){return this.#e}readChunk(){let e=this.readChunk.name;return new Promise((t,r)=>{this.#n[e]=(n,o)=>{if(delete this.#n[e],n==="error")return r(o);t(this.#t.splice(0,this.#r))},this.#e.resume()})}#a(e){for(let t=0;t<e.length;t++){let r=e[t];this.#e.addParameter(String(t+1),this.#s(r),r)}}#c(){let e=this.#r?()=>{if(this.#r<=this.#t.length)this.#e.pause(),Object.values(this.#n).forEach((r)=>r("chunkReady"))}:()=>{},t=(r)=>{let n={};for(let o of r)n[o.metadata.colName]=o.value;this.#t.push(n),e()};this.#e.on("row",t),this.#e.once("requestCompleted",()=>{Object.values(this.#n).forEach((r)=>r("completed")),this.#e.off("row",t)})}#s(e){if(Xs(e)||Pn(e)||Vt(e))return this.#o.TYPES.NVarChar;if(ea(e)||jo(e)&&e%1===0)if(e<-2147483648||e>2147483647)return this.#o.TYPES.BigInt;else return this.#o.TYPES.Int;if(jo(e))return this.#o.TYPES.Float;if(vs(e))return this.#o.TYPES.Bit;if(Su(e))return this.#o.TYPES.DateTime;if(nm(e))return this.#o.TYPES.VarBinary;return this.#o.TYPES.NVarChar}}class Nt{#e;constructor(e){this.#e=e}async getSchemas(){return await this.#e.selectFrom("sys.schemas").select("name").execute()}async getTables(e={withInternalKyselyTables:!1}){let t=await this.#e.selectFrom("sys.tables as tables").leftJoin("sys.schemas as table_schemas","table_schemas.schema_id","tables.schema_id").innerJoin("sys.columns as columns","columns.object_id","tables.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(n)=>n.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!e.withInternalKyselyTables,(n)=>n.where("tables.name","!=",Yr).where("tables.name","!=",An)).select(["tables.name as table_name",(n)=>n.ref("tables.type").$castTo().as("table_type"),"table_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"]).unionAll(this.#e.selectFrom("sys.views as views").leftJoin("sys.schemas as view_schemas","view_schemas.schema_id","views.schema_id").innerJoin("sys.columns as columns","columns.object_id","views.object_id").innerJoin("sys.types as types","types.user_type_id","columns.user_type_id").leftJoin("sys.schemas as type_schemas","type_schemas.schema_id","types.schema_id").leftJoin("sys.extended_properties as comments",(n)=>n.onRef("comments.major_id","=","views.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).select(["views.name as table_name","views.type as table_type","view_schemas.name as table_schema_name","columns.default_object_id as column_default_object_id","columns.generated_always_type_desc as column_generated_always_type","columns.is_computed as column_is_computed","columns.is_identity as column_is_identity","columns.is_nullable as column_is_nullable","columns.is_rowguidcol as column_is_rowguidcol","columns.name as column_name","types.is_nullable as type_is_nullable","types.name as type_name","type_schemas.name as type_schema_name","comments.value as column_comment"])).orderBy("table_schema_name").orderBy("table_name").orderBy("column_name").execute(),r={};for(let n of t){let o=`${n.table_schema_name}.${n.table_name}`;(r[o]=r[o]||f({columns:[],isView:n.table_type==="V ",name:n.table_name,schema:n.table_schema_name??void 0})).columns.push(f({dataType:n.type_name,dataTypeSchema:n.type_schema_name??void 0,hasDefaultValue:n.column_default_object_id>0||n.column_generated_always_type!=="NOT_APPLICABLE"||n.column_is_identity||n.column_is_computed||n.column_is_rowguidcol,isAutoIncrementing:n.column_is_identity,isNullable:n.column_is_nullable&&n.type_is_nullable,name:n.column_name,comment:n.column_comment??void 0}))}return Object.values(r)}async getMetadata(e){return{tables:await this.getTables(e)}}}var yr=/^[a-z0-9_]$/i;class _t extends Dn{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(e){super.visitOffset(e),this.append(" rows")}compileColumnAlterations(e){let t={};for(let n of e){if(!t[n.kind])t[n.kind]=[];t[n.kind].push(n)}let r=!0;if(t.AddColumnNode)this.append("add "),this.compileList(t.AddColumnNode),r=!1;if(t.AlterColumnNode){if(!r)this.append(", ");this.compileList(t.AlterColumnNode)}if(t.DropColumnNode){if(!r)this.append(", ");this.append("drop column "),this.compileList(t.DropColumnNode)}if(t.ModifyColumnNode){if(!r)this.append(", ");this.compileList(t.ModifyColumnNode)}if(t.RenameColumnNode){if(!r)this.append(", ");this.compileList(t.RenameColumnNode)}}visitAddColumn(e){this.visitNode(e.column)}visitDropColumn(e){this.visitNode(e.column)}visitMergeQuery(e){super.visitMergeQuery(e),this.append(";")}visitCollate(e){this.append("collate ");let{name:t}=e.collation;for(let r of t)if(!yr.test(r))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}}class Ct{#e;constructor(e){this.#e=e}createDriver(){return new xt(this.#e)}createQueryCompiler(){return new _t}createAdapter(){return new wt}createIntrospector(e){return new Nt(e)}}function Tt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function bu(e){if(!e)return null;if("dialect"in e)return bu(e.dialect);if("createDriver"in e){if(e instanceof je)return"sqlite";if(e instanceof Ve)return"mysql";if(e instanceof Ue)return"postgres";if(e instanceof Ct)return"mssql"}if("aggregate"in e)return"sqlite";if("getConnection"in e)return"mysql";if("connect"in e)return"postgres";if("fileControl"in e)return"sqlite";if("open"in e&&"close"in e&&"prepare"in e)return"sqlite";if("batch"in e&&"exec"in e&&"prepare"in e)return"sqlite";return null}var nf=async(e)=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,transaction:void 0};if("db"in t)return{kysely:t.db,databaseType:t.type,transaction:t.transaction};if("dialect"in t)return{kysely:new F({dialect:t.dialect}),databaseType:t.type,transaction:t.transaction};let r=void 0,n=bu(t);if("createDriver"in t)r=t;if("aggregate"in t&&!("createSession"in t))r=new je({database:t});if("getConnection"in t)r=new Ve(t);if("connect"in t)r=new Ue({pool:t});if("fileControl"in t){let{BunSqliteDialect:o}=await import("./chunk-w4ghe71n.js");r=new o({database:t})}if("createSession"in t){let o=void 0;try{({DatabaseSync:o}=await import("node:sqlite"))}catch(d){if(d!==null&&typeof d==="object"&&"code"in d&&d.code!=="ERR_UNKNOWN_BUILTIN_MODULE")throw d}if(o&&t instanceof o){let{NodeSqliteDialect:d}=await import("./chunk-xarsrs08.js");r=new d({database:t})}}if("batch"in t&&"exec"in t&&"prepare"in t){let{D1SqliteDialect:o}=await import("./chunk-7gmdnsdg.js");r=new o({database:t})}return{kysely:r?new F({dialect:r}):null,databaseType:n,transaction:void 0}};function gt(e,t,r){return r==="postgres"?Pe`${Pe.ref(e)} ILIKE ${t}`:Pe`LOWER(${Pe.ref(e)}) LIKE LOWER(${t})`}function wr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function xr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function Nr(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,value:t.toLowerCase()}}function _r(e,t){return{lhs:Pe`LOWER(${Pe.ref(e)})`,value:t.toLowerCase()}}var sT=(e,t)=>{let r=null,n=(l,g=!1)=>({getFieldName:A,schema:D,getDefaultFieldName:z,getDefaultModelName:Ht,getFieldAttributes:Cr,getModelName:te})=>{let Et=(u)=>{let x=[],y=[];if(u)for(let[h,m]of Object.entries(u)){let a=D[Ht(h)]?.fields,[c,w]=h.includes(".")?h.split("."):[void 0,h];if(!a)continue;a.id={type:"string"};for(let[v,i]of Object.entries(a))x.push(Pe`${Pe.ref(`join_${w}`)}.${Pe.ref(i.fieldName||v)} as ${Pe.ref(`_joined_${w}_${i.fieldName||v}`)}`),y.push({joinModel:h,joinModelRef:w,fieldName:i.fieldName||v})}return{allSelectsStr:y,allSelects:x}},bt=async(u,x,y,h)=>{let m;if(t?.type==="mysql"){await x.execute();let a=u.id?"id":h.length>0&&h[0]?.field?h[0].field:"id";if(!u.id&&h.length===0)return m=await l.selectFrom(y).selectAll().orderBy(A({model:y,field:a}),"desc").limit(1).executeTakeFirst(),m;let c=u[a]!==void 0?u[a]:h[0]?.value;return m=await l.selectFrom(y).selectAll().orderBy(A({model:y,field:a}),"desc").where(A({model:y,field:a}),c===null?"is":"=",c).limit(1).executeTakeFirst(),m}if(t?.type==="mssql")return m=await x.outputAll("inserted").executeTakeFirst(),m;return m=await x.returningAll().executeTakeFirst(),m};function J(u,x){if(!x)return{and:null,or:null};let y={and:[],or:[]};return x.forEach((h)=>{let{field:m,value:a,operator:c="eq",connector:w="AND",mode:v="sensitive"}=h,i=a,C=A({model:u,field:m}),N=v==="insensitive"&&(typeof i==="string"||Array.isArray(i)&&i.every((p)=>typeof p==="string")),T=(p)=>{let s=`${u}.${C}`;if(c.toLowerCase()==="in"){if(N){let{lhs:q,values:E}=wr(s,Array.isArray(i)?i:[i]);return p(q,"in",E)}return p(s,"in",Array.isArray(i)?i:[i])}if(c.toLowerCase()==="not_in"){if(N){let{lhs:q,values:E}=xr(s,Array.isArray(i)?i:[i]);return p(q,"not in",E)}return p(s,"not in",Array.isArray(i)?i:[i])}if(c==="contains"){if(N&&typeof i==="string")return gt(s,`%${i}%`,t?.type);return p(s,"like",`%${i}%`)}if(c==="starts_with"){if(N&&typeof i==="string")return gt(s,`${i}%`,t?.type);return p(s,"like",`${i}%`)}if(c==="ends_with"){if(N&&typeof i==="string")return gt(s,`%${i}`,t?.type);return p(s,"like",`%${i}`)}if(c==="eq"){if(i===null)return p(s,"is",null);if(N&&typeof i==="string"){let{lhs:q,value:E}=Nr(s,i);return p(q,"=",E)}return p(s,"=",i)}if(c==="ne"){if(i===null)return p(s,"is not",null);if(N&&typeof i==="string"){let{lhs:q,value:E}=_r(s,i);return p(q,"<>",E)}return p(s,"<>",i)}if(c==="gt")return p(s,">",i);if(c==="gte")return p(s,">=",i);if(c==="lt")return p(s,"<",i);if(c==="lte")return p(s,"<=",i);return p(s,c,i)};if(w==="OR")y.or.push(T);else y.and.push(T)}),{and:y.and.length?y.and:null,or:y.or.length?y.or:null}}function It(u,x,y){if(!x||!u.length)return u;let h=new Map;for(let a of u){let c={},w={};for(let[C]of Object.entries(x))w[te(C)]={};for(let[C,N]of Object.entries(a)){let T=String(C),p=!1;for(let{joinModel:s,fieldName:q,joinModelRef:E}of y)if(T===`_joined_${E}_${q}`||T===`_Joined${Tt(E)}${Tt(q)}`){w[te(s)][A({model:s,field:q})]=N,p=!0;break}if(!p)c[C]=N}let v=c.id;if(!v)continue;if(!h.has(v)){let C={...c};for(let[N,T]of Object.entries(x))C[te(N)]=T.relation==="one-to-one"?null:[];h.set(v,C)}let i=h.get(v);for(let[C,N]of Object.entries(x)){let T=N.relation==="one-to-one",p=N.limit??100,s=w[te(C)],q=s&&Object.keys(s).length>0&&Object.values(s).some((E)=>E!==null&&E!==void 0);if(T)i[te(C)]=q?s:null;else{let E=te(C);if(Array.isArray(i[E])&&q){if(i[E].length>=p)continue;let qe=A({model:C,field:"id"}),At=s[qe];if(At){if(!i[E].some((Yt)=>Yt[qe]===At)&&i[E].length<p)i[E].push(s)}else if(i[E].length<p)i[E].push(s)}}}}let m=Array.from(h.values());for(let a of m)for(let[c,w]of Object.entries(x))if(w.relation!=="one-to-one"){let v=te(c);if(Array.isArray(a[v])){let i=w.limit??100;if(a[v].length>i)a[v]=a[v].slice(0,i)}}return m}return{async create({data:u,model:x}){return await bt(u,l.insertInto(x).values(u),x,[])},async findOne({model:u,where:x,select:y,join:h}){let{and:m,or:a}=J(u,x),c=l.selectFrom((N)=>{let T=N.selectFrom(u);if(m)T=T.where((p)=>p.and(m.map((s)=>s(p))));if(a)T=T.where((p)=>p.or(a.map((s)=>s(p))));if(y?.length&&y.length>0)T=T.select(y.map((p)=>A({model:u,field:p})));else T=T.selectAll();return T.as("primary")}).selectAll("primary");if(h)for(let[N,T]of Object.entries(h)){let[p,s]=N.includes(".")?N.split("."):[void 0,N];c=c.leftJoin(`${N} as join_${s}`,(q)=>q.onRef(`join_${s}.${T.on.to}`,"=",`primary.${T.on.from}`))}let{allSelectsStr:w,allSelects:v}=Et(h);c=c.select(v);let i=await c.execute();if(!i||!Array.isArray(i)||i.length===0)return null;let C=i[0];if(h)return It(i,h,w)[0];return C},async findMany({model:u,where:x,limit:y,select:h,offset:m,sortBy:a,join:c}){let{and:w,or:v}=J(u,x),i=l.selectFrom((p)=>{let s=p.selectFrom(u);if(t?.type==="mssql"){if(m!==void 0){if(!a)s=s.orderBy(A({model:u,field:"id"}));s=s.offset(m).fetch(y||100)}else if(y!==void 0)s=s.top(y)}else{if(y!==void 0)s=s.limit(y);if(m!==void 0)s=s.offset(m)}if(a?.field)s=s.orderBy(`${A({model:u,field:a.field})}`,a.direction);if(w)s=s.where((q)=>q.and(w.map((E)=>E(q))));if(v)s=s.where((q)=>q.or(v.map((E)=>E(q))));if(h?.length&&h.length>0)s=s.select(h.map((q)=>A({model:u,field:q})));else s=s.selectAll();return s.as("primary")}).selectAll("primary");if(c)for(let[p,s]of Object.entries(c)){let[q,E]=p.includes(".")?p.split("."):[void 0,p];i=i.leftJoin(`${p} as join_${E}`,(qe)=>qe.onRef(`join_${E}.${s.on.to}`,"=",`primary.${s.on.from}`))}let{allSelectsStr:C,allSelects:N}=Et(c);if(i=i.select(N),a?.field)i=i.orderBy(`${A({model:u,field:a.field})}`,a.direction);let T=await i.execute();if(!T)return[];if(c)return It(T,c,C);return T},async update({model:u,where:x,update:y}){let{and:h,or:m}=J(u,x),a=l.updateTable(u).set(y);if(h)a=a.where((c)=>c.and(h.map((w)=>w(c))));if(m)a=a.where((c)=>c.or(m.map((w)=>w(c))));return await bt(y,a,u,x)},async updateMany({model:u,where:x,update:y}){let{and:h,or:m}=J(u,x),a=l.updateTable(u).set(y);if(h)a=a.where((w)=>w.and(h.map((v)=>v(w))));if(m)a=a.where((w)=>w.or(m.map((v)=>v(w))));let c=(await a.executeTakeFirst()).numUpdatedRows;return c>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(c)},async count({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.selectFrom(u).select(l.fn.count("id").as("count"));if(y)m=m.where((c)=>c.and(y.map((w)=>w(c))));if(h)m=m.where((c)=>c.or(h.map((w)=>w(c))));let a=await m.execute();if(typeof a[0].count==="number")return a[0].count;if(typeof a[0].count==="bigint")return Number(a[0].count);return parseInt(a[0].count)},async delete({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.deleteFrom(u);if(y)m=m.where((a)=>a.and(y.map((c)=>c(a))));if(h)m=m.where((a)=>a.or(h.map((c)=>c(a))));await m.execute()},async deleteMany({model:u,where:x}){let{and:y,or:h}=J(u,x),m=l.deleteFrom(u);if(y)m=m.where((c)=>c.and(y.map((w)=>w(c))));if(h)m=m.where((c)=>c.or(h.map((w)=>w(c))));let a=(await m.executeTakeFirst()).numDeletedRows;return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(a)},async consumeOne({model:u,where:x}){let{and:y,or:h}=J(u,x),m=(i)=>{if(y)i=i.where((C)=>C.and(y.map((N)=>N(C))));if(h)i=i.where((C)=>C.or(h.map((N)=>N(C))));return i},a=A({model:u,field:"id"}),c=async(i,C)=>{let N=C[a]??C.id;if(N===void 0||N===null)return null;let T=i.deleteFrom(u).where(`${u}.${a}`,"=",N);if(t?.type==="mysql"){let p=await T.executeTakeFirst();return Number(p.numDeletedRows)>0?C:null}if(t?.type==="mssql")return await T.outputAll("deleted").executeTakeFirst()??null;return await T.returningAll().executeTakeFirst()??null},w=async(i)=>{if(t?.type==="mssql")return await i.outputAll("deleted").executeTakeFirst()??null;return await i.returningAll().executeTakeFirst()??null};if(t?.type==="mysql"){let i=async(C)=>{let N=await m(C.selectFrom(u).selectAll().forUpdate()).limit(1).executeTakeFirst();if(!N)return null;return c(C,N)};return g?i(l):l.transaction().execute(i)}let v=m(l.selectFrom(u).select(`${u}.${a}`)).limit(1);return w(l.deleteFrom(u).where(`${u}.${a}`,"in",v))},options:t}},o=null;o={config:{adapterId:"kysely",adapterName:"Kysely Adapter",usePlural:t?.usePlural,debugLogs:t?.debugLogs,supportsBooleans:t?.type==="sqlite"||t?.type==="mssql"||t?.type==="mysql"||!t?.type?!1:!0,supportsDates:t?.type==="sqlite"||t?.type==="mssql"||!t?.type?!1:!0,supportsJSON:t?.type==="postgres"?!0:!1,supportsArrays:!1,supportsUUIDs:t?.type==="postgres"?!0:!1,transaction:t?.transaction?(l)=>e.transaction().execute((g)=>l(xs({config:{...o.config,transaction:!1},adapter:n(g,!0)})(r))):!1},adapter:n(e)};let d=xs(o);return(l)=>(r=l,d(l))};
6
+ export{bu,nf,sT};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- function cn(t){if(!(t instanceof Error))return{message:u(t),messageCarriesBody:!1};let e=t,n=r(e),s=f(e),d=s===void 0||t.message.includes(s);return{status:n,body:s,message:t.message,messageCarriesBody:d}}function r(t){if(typeof t.statusCode==="number")return t.statusCode;if(typeof t.status==="number")return t.status;if(typeof t.$metadata?.httpStatusCode==="number")return t.$metadata.httpStatusCode;if(typeof t.$response?.statusCode==="number")return t.$response.statusCode;return}function f(t){let e=o(t);if(e===void 0)return;let n=e.trim();if(n.length===0)return;return c(n,4000)}function o(t){if(typeof t.body==="string")return t.body;if(i(t.error))return u(t.error);let e=t.$response?.body;if(typeof e==="string")return e;if(a(e))return;if(i(e))return u(e);return}function a(t){return typeof t==="object"&&t!==null&&"pipe"in t&&typeof t.pipe==="function"}function i(t){return typeof t==="object"&&t!==null&&Object.keys(t).length>0}function un(t,e){if(t.messageCarriesBody||t.status===void 0||t.body===void 0)return e!==void 0&&t.status!==void 0?`${e} (${t.status}): ${t.message}`:t.message;return e!==void 0?`${e} (${t.status}): ${t.body}`:`${t.status}: ${t.body}`}function c(t,e){if(t.length<=e)return t;return`${t.slice(0,e)}... [truncated ${t.length-e} chars]`}function u(t){try{let e=JSON.stringify(t);return e===void 0?String(t):e}catch{return String(t)}}
3
- export{cn,un};
2
+ function mn(t){if(!(t instanceof Error))return{message:u(t),messageCarriesBody:!1};let e=t,n=r(e),s=f(e),d=s===void 0||t.message.includes(s);return{status:n,body:s,message:t.message,messageCarriesBody:d}}function r(t){if(typeof t.statusCode==="number")return t.statusCode;if(typeof t.status==="number")return t.status;if(typeof t.$metadata?.httpStatusCode==="number")return t.$metadata.httpStatusCode;if(typeof t.$response?.statusCode==="number")return t.$response.statusCode;return}function f(t){let e=o(t);if(e===void 0)return;let n=e.trim();if(n.length===0)return;return c(n,4000)}function o(t){if(typeof t.body==="string")return t.body;if(i(t.error))return u(t.error);let e=t.$response?.body;if(typeof e==="string")return e;if(a(e))return;if(i(e))return u(e);return}function a(t){return typeof t==="object"&&t!==null&&"pipe"in t&&typeof t.pipe==="function"}function i(t){return typeof t==="object"&&t!==null&&Object.keys(t).length>0}function hn(t,e){if(t.messageCarriesBody||t.status===void 0||t.body===void 0)return e!==void 0&&t.status!==void 0?`${e} (${t.status}): ${t.message}`:t.message;return e!==void 0?`${e} (${t.status}): ${t.body}`:`${t.status}: ${t.body}`}function c(t,e){if(t.length<=e)return t;return`${t.slice(0,e)}... [truncated ${t.length-e} chars]`}function u(t){try{let e=JSON.stringify(t);return e===void 0?String(t):e}catch{return String(t)}}
3
+ export{mn,hn};
@@ -1,3 +1,3 @@
1
1
  // @bun
2
- import{W}from"./chunk-rza4ae5z.js";var n=null;function c(e){if(typeof process>"u"||!process.versions?.bun||Object.keys(process.env).length>0)return;if(n===null){n=new Map;try{let{readFileSync:t}=W("fs"),s=t("/proc/self/environ","utf-8");for(let r of s.split("\x00")){let o=r.indexOf("=");if(o>0)n.set(r.slice(0,o),r.slice(o+1))}}catch{}}return n.get(e)}function nr(e,t){return t?.[e]||(typeof process<"u"?process.env[e]:void 0)||c(e)||void 0}
3
- export{nr};
2
+ import{G}from"./chunk-fnmwksnb.js";var n=null;function c(e){if(typeof process>"u"||!process.versions?.bun||Object.keys(process.env).length>0)return;if(n===null){n=new Map;try{let{readFileSync:t}=G("fs"),s=t("/proc/self/environ","utf-8");for(let r of s.split("\x00")){let o=r.indexOf("=");if(o>0)n.set(r.slice(0,o),r.slice(o+1))}}catch{}}return n.get(e)}function ar(e,t){return t?.[e]||(typeof process<"u"?process.env[e]:void 0)||c(e)||void 0}
3
+ export{ar};
@@ -1,2 +1,2 @@
1
- import{T}from"./chunk-6bhn1p8v.js";var c=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],mo=T("wrench",c);
2
- export{mo};
1
+ import{T}from"./chunk-7rhz2gze.js";var c=[["path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z",key:"1ngwbx"}]],So=T("wrench",c);
2
+ export{So};