@shumai-one/shumai 0.6.4 → 0.6.5

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 (158) hide show
  1. package/bin/chunk-0e0g5c55.js +2 -0
  2. package/bin/{chunk-ajr1w3vq.js → chunk-0gcemkpv.js} +5 -5
  3. package/bin/{chunk-7yv7shad.js → chunk-13ty4xke.js} +1 -1
  4. package/bin/{chunk-wmrrapwv.js → chunk-1dm7f6hy.js} +1 -1
  5. package/bin/{chunk-zc7wzcvh.js → chunk-1nwkxgqh.js} +5 -5
  6. package/bin/{chunk-gqkjx7rz.js → chunk-1rdgrtnf.js} +2 -2
  7. package/bin/{chunk-a283dh05.js → chunk-1tme4nbm.js} +2 -2
  8. package/bin/{chunk-q5k72jz9.js → chunk-1vx92153.js} +2 -2
  9. package/bin/{chunk-apq2gvvp.js → chunk-2168vwre.js} +2 -2
  10. package/bin/{chunk-fb9dedm2.js → chunk-24yh3wse.js} +1 -1
  11. package/bin/{chunk-d3brvxh7.js → chunk-2as0w380.js} +2 -2
  12. package/bin/chunk-2hk5cb40.js +2 -0
  13. package/bin/{chunk-598x693h.js → chunk-2nhp70zw.js} +2 -2
  14. package/bin/{chunk-e2p4s2pj.js → chunk-2scr7dh6.js} +3 -3
  15. package/bin/{chunk-bkzaw9p8.js → chunk-31v0zy13.js} +1 -1
  16. package/bin/{chunk-0njsjy6x.js → chunk-37mc5a09.js} +4 -4
  17. package/bin/{chunk-yncmfr39.js → chunk-3rde6gkg.js} +2 -2
  18. package/bin/{chunk-2qzmh3ae.js → chunk-3w0w0a55.js} +4 -4
  19. package/bin/{chunk-6ty4tfmf.js → chunk-4abr8vgg.js} +1 -1
  20. package/bin/chunk-4jj26kmx.js +1 -0
  21. package/bin/chunk-4yen4chz.js +2 -0
  22. package/bin/{chunk-396tfwdx.js → chunk-56h2f6s6.js} +1 -1
  23. package/bin/{chunk-ehgrp0f9.js → chunk-56qqbtkr.js} +1 -1
  24. package/bin/{chunk-f5bhcjhw.js → chunk-5pfagexe.js} +1 -1
  25. package/bin/{chunk-47fmhzwv.js → chunk-5sbcajbb.js} +2 -2
  26. package/bin/{chunk-akafypge.js → chunk-67p46cwk.js} +34 -34
  27. package/bin/{chunk-6ke13k69.js → chunk-6g2gv3py.js} +1 -1
  28. package/bin/{chunk-zg0b902x.js → chunk-7tdq7apk.js} +1 -1
  29. package/bin/{chunk-6j3beg6n.js → chunk-8cqpyrbp.js} +2 -2
  30. package/bin/{chunk-vf9s8b5t.js → chunk-8xn2mfp0.js} +1 -1
  31. package/bin/{chunk-4rjy7ybr.js → chunk-8z3hdcaf.js} +8 -8
  32. package/bin/chunk-95ygezr5.js +1 -0
  33. package/bin/{chunk-w4gqg27w.js → chunk-99szdzq8.js} +2 -2
  34. package/bin/{chunk-pemmtd8q.js → chunk-9s35n63t.js} +1 -1
  35. package/bin/chunk-9tqrbttj.js +2 -0
  36. package/bin/{chunk-m6v8rb39.js → chunk-9xv33vgz.js} +7 -7
  37. package/bin/{chunk-zmnvskn7.js → chunk-9yj86mgf.js} +9 -9
  38. package/bin/{chunk-rjhczkh3.js → chunk-a3dtyc64.js} +2 -2
  39. package/bin/{chunk-ka40gv72.js → chunk-a4xq9f8p.js} +1 -1
  40. package/bin/{chunk-4b2x2qba.js → chunk-am7ssc4m.js} +6 -6
  41. package/bin/chunk-anjvapqf.js +2 -0
  42. package/bin/chunk-at55wjdn.js +1 -0
  43. package/bin/{chunk-wzrzc07t.js → chunk-b119q3jq.js} +1 -1
  44. package/bin/{chunk-65dh7x4c.js → chunk-b9z3hasx.js} +2 -2
  45. package/bin/{chunk-y6h885fs.js → chunk-bdze4wyd.js} +1 -1
  46. package/bin/{chunk-nsbbseff.js → chunk-bp9g1ryv.js} +2 -2
  47. package/bin/{chunk-8zcfgz9c.js → chunk-bq6ejr4g.js} +1 -1
  48. package/bin/{chunk-978rm9a9.js → chunk-cxqn0b0p.js} +2 -2
  49. package/bin/{chunk-xk0jmx4s.js → chunk-d5nfx4q4.js} +1 -1
  50. package/bin/{chunk-h7f5370s.js → chunk-d7kcj1qb.js} +1 -1
  51. package/bin/{chunk-vbe8wred.js → chunk-dbz6z4px.js} +1 -1
  52. package/bin/{chunk-45pb3kzz.js → chunk-djzt77c5.js} +2 -2
  53. package/bin/{chunk-c61g9hfa.js → chunk-dvmc5582.js} +1 -1
  54. package/bin/{chunk-ways29d1.js → chunk-e0q5yk34.js} +1 -1
  55. package/bin/chunk-e572r4hv.js +2 -0
  56. package/bin/{chunk-66e2vrky.js → chunk-efst3j5m.js} +1 -1
  57. package/bin/chunk-enkjvx7r.js +2 -0
  58. package/bin/chunk-f5xv3hp5.js +1 -0
  59. package/bin/chunk-f9v2qyv7.js +1 -0
  60. package/bin/chunk-fwwed2e7.js +1 -0
  61. package/bin/chunk-gm16qx23.js +2 -0
  62. package/bin/{chunk-pzrqnnpg.js → chunk-h21qqtcm.js} +1 -1
  63. package/bin/chunk-h329v9bx.js +1 -0
  64. package/bin/{chunk-s0wxbybf.js → chunk-hgz8t5vr.js} +1 -1
  65. package/bin/{chunk-2zm7czk6.js → chunk-j26g68k6.js} +1 -1
  66. package/bin/{chunk-13rq2gtr.js → chunk-jc8e55pe.js} +2 -2
  67. package/bin/{chunk-y545vfn0.js → chunk-jcrxmzdh.js} +1 -1
  68. package/bin/{chunk-ff0mh9p3.js → chunk-jd8sv7fn.js} +28 -28
  69. package/bin/chunk-jpeqvw4x.js +2 -0
  70. package/bin/{chunk-8a7ymmd4.js → chunk-k7r26qtq.js} +1 -1
  71. package/bin/chunk-kj7ntaz0.js +2 -0
  72. package/bin/{chunk-yxnz4ypt.js → chunk-kvf4grps.js} +6 -6
  73. package/bin/{chunk-2tt0b8ym.js → chunk-kxydqne9.js} +2 -2
  74. package/bin/{chunk-k9vjs21p.js → chunk-m37nbhsq.js} +1 -1
  75. package/bin/{chunk-955kf5kc.js → chunk-m5nn6eqe.js} +1 -1
  76. package/bin/chunk-mbe02vkx.js +2 -0
  77. package/bin/{chunk-n54ftsdx.js → chunk-mg64qh5j.js} +1 -1
  78. package/bin/{chunk-cdcgjh8k.js → chunk-mxgztw4q.js} +1 -1
  79. package/bin/{chunk-m8spagwp.js → chunk-n7skpwvd.js} +3 -3
  80. package/bin/{chunk-8ac9at5y.js → chunk-n8q8hv6c.js} +2 -2
  81. package/bin/chunk-ncdzf0ry.js +1 -0
  82. package/bin/{chunk-bssb9tar.js → chunk-nd3fd097.js} +3 -3
  83. package/bin/{chunk-0jnstdgf.js → chunk-p50y3e5b.js} +1 -1
  84. package/bin/{chunk-n7cvj15k.js → chunk-p7ccvw8m.js} +1 -1
  85. package/bin/{chunk-edfaqwaq.js → chunk-pjkvwhfj.js} +1 -1
  86. package/bin/{chunk-22jbsrka.js → chunk-qax7bbp9.js} +1 -1
  87. package/bin/{chunk-dcb1nzf1.js → chunk-qrx5txys.js} +1 -1
  88. package/bin/{chunk-szta50g1.js → chunk-r5gqxy70.js} +1 -1
  89. package/bin/{chunk-v7jzc3ye.js → chunk-r6jg9baj.js} +1 -1
  90. package/bin/chunk-ra209cbg.js +12 -0
  91. package/bin/{chunk-bywk8mbc.js → chunk-s3a5g11a.js} +2 -2
  92. package/bin/{chunk-7q4mgd5x.js → chunk-s4hy0ved.js} +1 -1
  93. package/bin/{chunk-q9fsxakd.js → chunk-s8ff3cb2.js} +2 -2
  94. package/bin/chunk-svr8n1ah.js +2 -0
  95. package/bin/{chunk-b6kmj34z.js → chunk-swtgq58j.js} +2 -2
  96. package/bin/chunk-sxfq2z7e.js +1 -0
  97. package/bin/{chunk-gd3b5akr.js → chunk-t3dwzd1a.js} +2 -2
  98. package/bin/{chunk-wesg7tg9.js → chunk-t96f1wsa.js} +1 -1
  99. package/bin/{chunk-wrb4xq9v.js → chunk-tanzerf7.js} +1 -1
  100. package/bin/{chunk-mfh7mg5b.js → chunk-tjkhapvh.js} +1 -1
  101. package/bin/{chunk-7e9ws6dh.js → chunk-tzn128yj.js} +27 -27
  102. package/bin/{chunk-dfbzatq9.js → chunk-v1fwt3x3.js} +2 -2
  103. package/bin/chunk-v4gtta3t.js +2 -0
  104. package/bin/{chunk-vm9bbk97.js → chunk-v9zvfvrc.js} +4 -4
  105. package/bin/{chunk-av2w1sez.js → chunk-va39tgjj.js} +2 -2
  106. package/bin/{chunk-t6cb99gp.js → chunk-vgxtr5nw.js} +2 -2
  107. package/bin/chunk-vnsz4x0d.js +1 -0
  108. package/bin/{chunk-km70p970.js → chunk-vqpycf0d.js} +1 -1
  109. package/bin/{chunk-q57m34h0.js → chunk-w0ada4tc.js} +3 -3
  110. package/bin/{chunk-qeypjv4f.css → chunk-w6mpqhh2.css} +1 -1
  111. package/bin/{chunk-jxm0gzmf.js → chunk-wgnef4mm.js} +2 -2
  112. package/bin/{chunk-vk3eqr65.js → chunk-wvf465g9.js} +1 -1
  113. package/bin/chunk-wzkyz0ex.js +2 -0
  114. package/bin/{chunk-1aqs9sdh.js → chunk-x144hpna.js} +2 -2
  115. package/bin/{chunk-3mx4trvh.js → chunk-x243v26y.js} +3 -3
  116. package/bin/{chunk-81b8rfv7.js → chunk-xak0x4rg.js} +2 -2
  117. package/bin/{chunk-w6ym7tsd.js → chunk-xge7jvp6.js} +3 -3
  118. package/bin/chunk-xhm4w6k2.js +2 -0
  119. package/bin/{chunk-d277evce.js → chunk-xhmcdf36.js} +4 -4
  120. package/bin/{chunk-s4hkcw24.js → chunk-xz2pzjse.js} +1 -1
  121. package/bin/{chunk-p35ztj2z.js → chunk-y4v4jnvv.js} +1 -1
  122. package/bin/{chunk-gm1fy3hm.js → chunk-y63cy80d.js} +2 -2
  123. package/bin/{chunk-v4nqx084.js → chunk-ym7pb5vn.js} +4 -4
  124. package/bin/chunk-yq06kytp.js +2 -0
  125. package/bin/{chunk-7mdddkfc.js → chunk-yw34c12n.js} +1 -1
  126. package/bin/{chunk-6rqakmg0.js → chunk-zeq831pz.js} +2 -2
  127. package/bin/{chunk-01vx2chc.js → chunk-zhhg6att.js} +2 -2
  128. package/bin/{chunk-xd1axsdv.js → chunk-zkq96hyx.js} +2 -2
  129. package/bin/shumai-app.html +1 -1
  130. package/bin/shumai-app.js +137 -137
  131. package/package.json +7 -7
  132. package/bin/chunk-0epkrexd.js +0 -2
  133. package/bin/chunk-0h5239kt.js +0 -2
  134. package/bin/chunk-2qknebmd.js +0 -1
  135. package/bin/chunk-4awk4xhq.js +0 -2
  136. package/bin/chunk-5c7ztqs7.js +0 -1
  137. package/bin/chunk-aa2a06cc.js +0 -1
  138. package/bin/chunk-amk373q2.js +0 -2
  139. package/bin/chunk-bwvj1aqc.js +0 -1
  140. package/bin/chunk-e0bckx12.js +0 -2
  141. package/bin/chunk-e8zzg57c.js +0 -2
  142. package/bin/chunk-evs2aaav.js +0 -12
  143. package/bin/chunk-fpfby5tz.js +0 -1
  144. package/bin/chunk-hcyhsn8e.js +0 -2
  145. package/bin/chunk-n0cn0218.js +0 -2
  146. package/bin/chunk-na5fh7er.js +0 -2
  147. package/bin/chunk-neazdbxy.js +0 -1
  148. package/bin/chunk-nk24qw3m.js +0 -1
  149. package/bin/chunk-nseef85h.js +0 -1
  150. package/bin/chunk-pcjc9ygv.js +0 -2
  151. package/bin/chunk-qadpe0ct.js +0 -2
  152. package/bin/chunk-qw92z3wf.js +0 -2
  153. package/bin/chunk-r0byfq1t.js +0 -1
  154. package/bin/chunk-r0q88qw3.js +0 -2
  155. package/bin/chunk-tcr080b9.js +0 -1
  156. package/bin/chunk-wnwsjgj8.js +0 -2
  157. package/bin/chunk-zc1asygg.js +0 -2
  158. package/bin/chunk-zdvhh8mk.js +0 -2
@@ -0,0 +1,2 @@
1
+ // @bun
2
+ import{Xt}from"./chunk-dvmc5582.js";import{At}from"./chunk-9xv33vgz.js";import{ie}from"./chunk-b9z3hasx.js";var _=ie(Xt()),N=ie(At()),Sd="AWS_ACCESS_KEY_ID",Id="AWS_SECRET_ACCESS_KEY",S="AWS_SESSION_TOKEN",C="AWS_CREDENTIAL_EXPIRATION",A="AWS_CREDENTIAL_SCOPE",p="AWS_ACCOUNT_ID",op=(e)=>async()=>{e?.logger?.debug("@aws-sdk/credential-provider-env - fromEnv");let o=process.env[Sd],E=process.env[Id],r=process.env[S],n=process.env[C],s=process.env[A],t=process.env[p];if(o&&E){let c={accessKeyId:o,secretAccessKey:E,...r&&{sessionToken:r},...n&&{expiration:new Date(n)},...s&&{credentialScope:s},...t&&{accountId:t}};return _.setCredentialFeature(c,"CREDENTIALS_ENV_VARS","g"),c}throw new N.CredentialsProviderError("Unable to find environment variable credentials.",{logger:e?.logger})};export{Sd,Id,op};
@@ -1,12 +1,12 @@
1
1
  // @bun
2
- import{te,Ee}from"./chunk-d277evce.js";import{Nr}from"./chunk-p35ztj2z.js";import{ea,xc,Cc}from"./chunk-dfbzatq9.js";import{Mo,fr,Vs,ta,Va,xf,Ka,fA,pr,an,C,Oo,it,pA,Ao,_o,yo,Or,Jt,Sc,Wa,Bm,nr,vi,ps,Um,Ic,Ja,bn,br,Oe,sr,Cf,kt,Ju,Ks,Ya,Sf,Yu,bi,If,ms,Xu,Ws,Vo,zm,ir,Js,je,vo,mA}from"./chunk-2qzmh3ae.js";import{Fc,sa,Lc,Zc,Uc}from"./chunk-e2p4s2pj.js";import{ei}from"./chunk-0njsjy6x.js";var A=C({is(e){return e.kind==="AlterTableNode"},create(e){return C({kind:"AlterTableNode",table:e})},cloneWithTableProps(e,t){return C({...e,...t})},cloneWithColumnAlteration(e,t){return C({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}});var P=C({is(e){return e.kind==="CreateIndexNode"},create(e){return C({kind:"CreateIndexNode",name:it.create(e)})},cloneWith(e,t){return C({...e,...t})},cloneWithColumns(e,t){return C({...e,columns:[...e.columns||[],...t]})}});var Me=C({is(e){return e.kind==="CreateSchemaNode"},create(e,t){return C({kind:"CreateSchemaNode",schema:it.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var X=C({is(e){return e.kind==="DropIndexNode"},create(e,t){return C({kind:"DropIndexNode",name:_o.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var Ce=C({is(e){return e.kind==="DropSchemaNode"},create(e,t){return C({kind:"DropSchemaNode",schema:it.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var be=C({is(e){return e.kind==="DropTableNode"},create(e,t){return C({kind:"DropTableNode",table:e,...t})},cloneWith(e,t){return C({...e,...t})}});var He=C({is(e){return e.kind==="AddColumnNode"},create(e){return C({kind:"AddColumnNode",column:e})}});var v=C({is(e){return e.kind==="ColumnDefinitionNode"},create(e,t){return C({kind:"ColumnDefinitionNode",column:Jt.create(e),dataType:t})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):[t]})},cloneWith(e,t){return C({...e,...t})}});var Ye=C({is(e){return e.kind==="DropColumnNode"},create(e){return C({kind:"DropColumnNode",column:Jt.create(e)})}});var Xe=C({is(e){return e.kind==="RenameColumnNode"},create(e,t){return C({kind:"RenameColumnNode",column:Jt.create(e),renameTo:Jt.create(t)})}});var ce=C({is(e){return e.kind==="CheckConstraintNode"},create(e,t){return C({kind:"CheckConstraintNode",expression:e,name:t?it.create(t):void 0})}});var Ot=["no action","restrict","cascade","set null","set default"],le=C({is(e){return e.kind==="ReferencesNode"},create(e,t){return C({kind:"ReferencesNode",table:e,columns:C([...t])})},cloneWithOnDelete(e,t){return C({...e,onDelete:t})},cloneWithOnUpdate(e,t){return C({...e,onUpdate:t})}});function Le(e){return Or(e)?e.toOperationNode():bn.createImmediate(e)}var Ie=C({is(e){return e.kind==="GeneratedNode"},create(e){return C({kind:"GeneratedNode",...e})},createWithExpression(e){return C({kind:"GeneratedNode",always:!0,expression:e})},cloneWith(e,t){return C({...e,...t})}});var qt=C({is(e){return e.kind==="DefaultValueNode"},create(e){return C({kind:"DefaultValueNode",defaultValue:e})}});function ue(e){if(Ot.includes(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}class k{#e;constructor(e){this.#e=e}autoIncrement(){return new k(v.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new k(v.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new k(v.cloneWith(this.#e,{primaryKey:!0}))}references(e){let t=ps(e);if(!t.table||Sc.is(t.column))throw Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new k(v.cloneWith(this.#e,{references:le.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 k(v.cloneWith(this.#e,{references:le.cloneWithOnDelete(this.#e.references,ue(e))}))}onUpdate(e){if(!this.#e.references)throw Error("on update constraint can only be added for foreign keys");return new k(v.cloneWith(this.#e,{references:le.cloneWithOnUpdate(this.#e.references,ue(e))}))}unique(){return new k(v.cloneWith(this.#e,{unique:!0}))}notNull(){return new k(v.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new k(v.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new k(v.cloneWith(this.#e,{defaultTo:qt.create(Le(e))}))}check(e){return new k(v.cloneWith(this.#e,{check:ce.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new k(v.cloneWith(this.#e,{generated:Ie.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new k(v.cloneWith(this.#e,{generated:Ie.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new k(v.cloneWith(this.#e,{generated:Ie.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new k(v.cloneWith(this.#e,{generated:Ie.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new k(v.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new k(v.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new k(v.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new k(v.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}}var Ze=C({is(e){return e.kind==="ModifyColumnNode"},create(e){return C({kind:"ModifyColumnNode",column:e})}});var W=C({is(e){return e.kind==="ForeignKeyConstraintNode"},create(e,t,r,n){return C({kind:"ForeignKeyConstraintNode",columns:e,references:le.create(t,r),name:n?it.create(n):void 0})},cloneWith(e,t){return C({...e,...t})}});class R{#e;constructor(e){this.#e=e}onDelete(e){return new R(W.cloneWith(this.#e,{onDelete:ue(e)}))}onUpdate(e){return new R(W.cloneWith(this.#e,{onUpdate:ue(e)}))}deferrable(){return new R(W.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new R(W.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new R(W.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new R(W.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}var me=C({is(e){return e.kind==="AddConstraintNode"},create(e){return C({kind:"AddConstraintNode",constraint:e})}});var F=C({is(e){return e.kind==="UniqueConstraintNode"},create(e,t,r){return C({kind:"UniqueConstraintNode",columns:C(e.map(Jt.create)),name:t?it.create(t):void 0,nullsNotDistinct:r})},cloneWith(e,t){return C({...e,...t})}});var de=C({is(e){return e.kind==="DropConstraintNode"},create(e){return C({kind:"DropConstraintNode",constraintName:it.create(e)})},cloneWith(e,t){return C({...e,...t})}});var he=C({is(e){return e.kind==="AlterColumnNode"},create(e,t,r){return C({kind:"AlterColumnNode",column:Jt.create(e),[t]:r})}});class Pe{#e;constructor(e){this.#e=e}setDataType(e){return new pe(he.create(this.#e,"dataType",Ws(e)))}setDefault(e){return new pe(he.create(this.#e,"setDefault",Le(e)))}dropDefault(){return new pe(he.create(this.#e,"dropDefault",!0))}setNotNull(){return new pe(he.create(this.#e,"setNotNull",!0))}dropNotNull(){return new pe(he.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}}class pe{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}}class Z{#e;constructor(e){this.#e=C(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 B{#e;constructor(e){this.#e=C(e)}onDelete(e){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(A.cloneWithTableProps(this.#e.node,{addConstraint:me.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 ie{#e;constructor(e){this.#e=C(e)}ifExists(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.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 G=C({is(e){return e.kind==="PrimaryKeyConstraintNode"},create(e,t){return C({kind:"PrimaryKeyConstraintNode",columns:C(e.map(Jt.create)),name:t?it.create(t):void 0})},cloneWith(e,t){return C({...e,...t})}});var ee=C({is(e){return e.kind==="AddIndexNode"},create(e){return C({kind:"AddIndexNode",name:it.create(e)})},cloneWith(e,t){return C({...e,...t})},cloneWithColumns(e,t){return C({...e,columns:[...e.columns||[],...t]})}});class re{#e;constructor(e){this.#e=C(e)}unique(){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,[Ic(e)])})})}columns(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,e.map(Ic))})})}expression(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWith(this.#e.node.addIndex,{using:nr.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 z{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new z(F.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new z(F.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new z(F.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new z(F.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new z(F.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class K{#e;constructor(e){this.#e=e}deferrable(){return new K(G.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new K(G.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new K(G.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new K(G.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class Ae{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}}var Mt=C({is(e){return e.kind==="RenameConstraintNode"},create(e,t){return C({kind:"RenameConstraintNode",oldName:it.create(e),newName:it.create(t)})}});class et{#e;constructor(e){this.#e=C(e)}renameTo(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{renameTo:ir(e)})})}setSchema(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{setSchema:it.create(e)})})}alterColumn(e,t){let r=t(new Pe(e));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ye.create(e))})}renameColumn(e,t){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Xe.create(e,t))})}addColumn(e,t,r=Oo){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Oo){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ze.create(n.toOperationNode()))})}addUniqueConstraint(e,t,r=Oo){let n=r(new z(F.create(t,e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}addCheckConstraint(e,t,r=Oo){let n=r(new Ae(ce.create(t.toOperationNode(),e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}addForeignKeyConstraint(e,t,r,n,o=Oo){let p=o(new R(W.create(t.map(Jt.create),ir(r),n.map(Jt.create),e)));return new B({...this.#e,constraintBuilder:p})}addPrimaryKeyConstraint(e,t,r=Oo){let n=r(new K(G.create(t,e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}dropConstraint(e){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.create(e)})})}renameConstraint(e,t){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{renameConstraint:Mt.create(e,t)})})}addIndex(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.create(e)})})}dropIndex(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropIndex:X.create(e)})})}$call(e){return e(this)}}class Q{#e;constructor(e){this.#e=C(e)}alterColumn(e,t){let r=t(new Pe(e));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ye.create(e))})}renameColumn(e,t){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Xe.create(e,t))})}addColumn(e,t,r=Oo){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Oo){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ze.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 Se extends Ju{transformPrimitiveValueList(e){return Ja.create(e.values.map(bn.createImmediate))}transformValue(e){return bn.createImmediate(e.value)}}class M{#e;constructor(e){this.#e=C(e)}ifNotExists(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new M({...this.#e,node:P.cloneWith(this.#e.node,{table:ir(e)})})}column(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,[Ic(e)])})}columns(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,e.map(Ic))})}expression(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new M({...this.#e,node:P.cloneWith(this.#e.node,{using:nr.createWithSql(e)})})}where(...e){let t=new Se;return new M({...this.#e,node:Oe.cloneWithWhere(this.#e.node,t.transformNode(br(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 We{#e;constructor(e){this.#e=C(e)}ifNotExists(){return new We({...this.#e,node:Me.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 Lt(e){if(pA.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}class q{#e;constructor(e){this.#e=C(e)}temporary(){return new q({...this.#e,node:Ao.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new q({...this.#e,node:Ao.cloneWith(this.#e.node,{onCommit:Lt(e)})})}ifNotExists(){return new q({...this.#e,node:Ao.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,r=Oo){let n=r(new k(v.create(e,Ws(t))));return new q({...this.#e,node:Ao.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,t,r=Oo){let n=r(new K(G.create(t,e)));return new q({...this.#e,node:Ao.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,t,r=Oo){let n=r(new z(F.create(t,e)));return new q({...this.#e,node:Ao.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,t,r=Oo){let n=r(new Ae(ce.create(t.toOperationNode(),e)));return new q({...this.#e,node:Ao.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,t,r,n,o=Oo){let p=o(new R(W.create(t.map(Jt.create),ir(r),n.map(Jt.create),e)));return new q({...this.#e,node:Ao.cloneWithConstraint(this.#e.node,p.toOperationNode())})}modifyFront(e){return new q({...this.#e,node:Ao.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new q({...this.#e,node:Ao.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new q({...this.#e,node:Ao.cloneWith(this.#e.node,{selectQuery:Vo(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 fe{#e;constructor(e){this.#e=C(e)}on(e){return new fe({...this.#e,node:X.cloneWith(this.#e.node,{table:ir(e)})})}ifExists(){return new fe({...this.#e,node:X.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new fe({...this.#e,node:X.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 ve{#e;constructor(e){this.#e=C(e)}ifExists(){return new ve({...this.#e,node:Ce.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ve({...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 ke{#e;constructor(e){this.#e=C(e)}ifExists(){return new ke({...this.#e,node:be.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ke({...this.#e,node:be.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 tt{#e=new Se;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}}class J{#e;constructor(e){this.#e=C(e)}temporary(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{columns:e.map(Um)})})}as(e){let t=e.withPlugin(new tt).toOperationNode();return new J({...this.#e,node:Js.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 we=C({is(e){return e.kind==="DropViewNode"},create(e){return C({kind:"DropViewNode",name:_o.create(e)})},cloneWith(e,t){return C({...e,...t})}});class ye{#e;constructor(e){this.#e=C(e)}materialized(){return new ye({...this.#e,node:we.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new ye({...this.#e,node:we.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ye({...this.#e,node:we.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 Re=C({is(e){return e.kind==="CreateTypeNode"},create(e){return C({kind:"CreateTypeNode",name:e})},cloneWithEnum(e,t){return C({...e,enum:Ja.create(t.map(bn.createImmediate))})}});class $e{#e;constructor(e){this.#e=C(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new $e({...this.#e,node:Re.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 Qe=C({is(e){return e.kind==="DropTypeNode"},create(e){return C({kind:"DropTypeNode",name:e})},cloneWith(e,t){return C({...e,...t})}});class Fe{#e;constructor(e){this.#e=C(e)}ifExists(){return new Fe({...this.#e,node:Qe.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 rt(e){if(e.includes(".")){let r=e.split(".").map(Zt);if(r.length===2)return _o.createWithSchema(r[0],r[1]);else throw Error(`invalid schemable identifier ${e}`)}else return _o.create(e)}function Zt(e){return e.trim()}var xe=C({is(e){return e.kind==="RefreshMaterializedViewNode"},create(e){return C({kind:"RefreshMaterializedViewNode",name:_o.create(e)})},cloneWith(e,t){return C({...e,...t})}});class Ne{#e;constructor(e){this.#e=C(e)}concurrently(){return new Ne({...this.#e,node:xe.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new Ne({...this.#e,node:xe.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new Ne({...this.#e,node:xe.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 ge{#e;constructor(e){this.#e=e}createTable(e){return new q({queryId:kt(),executor:this.#e,node:Ao.create(ir(e))})}dropTable(e){return new ke({queryId:kt(),executor:this.#e,node:be.create(ir(e))})}createIndex(e){return new M({queryId:kt(),executor:this.#e,node:P.create(e)})}dropIndex(e){return new fe({queryId:kt(),executor:this.#e,node:X.create(e)})}createSchema(e){return new We({queryId:kt(),executor:this.#e,node:Me.create(e)})}dropSchema(e){return new ve({queryId:kt(),executor:this.#e,node:Ce.create(e)})}alterTable(e){return new et({queryId:kt(),executor:this.#e,node:A.create(ir(e))})}createView(e){return new J({queryId:kt(),executor:this.#e,node:Js.create(e)})}refreshMaterializedView(e){return new Ne({queryId:kt(),executor:this.#e,node:xe.create(e)})}dropView(e){return new ye({queryId:kt(),executor:this.#e,node:we.create(e)})}createType(e){return new $e({queryId:kt(),executor:this.#e,node:Re.create(rt(e))})}dropType(e){return new Fe({queryId:kt(),executor:this.#e,node:Qe.create(rt(e))})}withPlugin(e){return new ge(this.#e.withPlugin(e))}withoutPlugins(){return new ge(this.#e.withoutPlugins())}withSchema(e){return new ge(this.#e.withPluginAtFront(new Ks(e)))}}class nt{ref(e){return new Bm(e)}table(e){return new zm(e)}}class ot{#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 ne extends Yu{#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 ne(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new ne(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new ne(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new ne(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new ne(this.#e,this.#t,this.#r,[])}}function ze(){if(typeof performance<"u"&&pr(performance.now))return performance.now();else return Date.now()}class st{#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 p,d=ze();try{return await t.call(e,o)}catch(c){throw p=c,await n.#s(c,o,d),c}finally{if(!p)await n.#l(o,d)}},e.streamQuery=async function*(o,p){let d,c=ze();try{for await(let S of r.call(e,o,p))yield S}catch(S){throw d=S,await n.#s(S,o,c),S}finally{if(!d)await n.#l(o,c,!0)}}}async#s(e,t,r){await this.#t.error(()=>({level:"error",error:e,query:t,queryDurationMillis:this.#u(r)}))}async#l(e,t,r=!1){await this.#t.query(()=>({level:"query",isStream:r,query:e,queryDurationMillis:this.#u(t)}))}#u(e){return ze()-e}}var er=()=>{};class De{#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"],rr=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function at(e){if(e.accessMode&&!tr.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!rr.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}var or=["query","error"],Ba=C(or);class ct{#e;#t;constructor(e){if(pr(e))this.#t=e,this.#e=C({query:!0,error:!0});else this.#t=ar,this.#e=C({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 Pt(e){return an(e)&&pr(e.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class U extends bi{#e;constructor(e){let t,r;if(cr(e))t={executor:e.executor},r={...e};else{let n=e.dialect,o=n.createDriver(),p=n.createQueryCompiler(),d=n.createAdapter(),c=new ct(e.log??[]),S=new st(o,c),I=new ot(S),O=new ne(p,d,I,e.plugins??[]);t={executor:O},r={config:e,executor:O,dialect:n,driver:S}}super(t);this.#e=C(r)}get schema(){return new ge(this.#e.executor)}get dynamic(){return new nt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new Xu({node:ms.create(Mo(e)?void 0:Vo(e))})}get fn(){return If()}transaction(){return new Ue({...this.#e})}startTransaction(){return new Ve({...this.#e})}connection(){return new Wt({...this.#e})}withPlugin(e){return new U({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new U({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new U({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new U({...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)vi("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let r=Pt(e)?e.compile():e;return this.getExecutor().executeQuery(r)}async[Symbol.asyncDispose](){await this.destroy()}}class ae extends U{#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 ae({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new ae({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new ae({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new ae({...this.#e})}}function cr(e){return an(e)&&an(e.config)&&an(e.driver)&&an(e.executor)&&an(e.dialect)}class Wt{#e;constructor(e){this.#e=C(e)}async execute(e){return this.#e.executor.provideConnection(async(t)=>{let r=this.#e.executor.withConnectionProvider(new De(t)),n=new U({...this.#e,executor:r});return await e(n)})}}class Ue{#e;constructor(e){this.#e=C(e)}setAccessMode(e){return new Ue({...this.#e,accessMode:e})}setIsolationLevel(e){return new Ue({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:t,accessMode:r,...n}=this.#e,o={isolationLevel:t,accessMode:r};return at(o),this.#e.executor.provideConnection(async(p)=>{let d={isCommitted:!1,isRolledBack:!1},c=new Y(this.#e.executor.withConnectionProvider(new De(p)),d),S=new ae({...n,executor:c}),I=!1;try{await this.#e.driver.beginTransaction(p,o),I=!0;let O=await e(S);return await this.#e.driver.commitTransaction(p),d.isCommitted=!0,O}catch(O){if(I)await this.#e.driver.rollbackTransaction(p),d.isRolledBack=!0;throw O}})}}class Ve{#e;constructor(e){this.#e=C(e)}setAccessMode(e){return new Ve({...this.#e,accessMode:e})}setIsolationLevel(e){return new Ve({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:t,...r}=this.#e,n={isolationLevel:e,accessMode:t};at(n);let o=await Sf(this.#e.executor);return await this.#e.driver.beginTransaction(o.connection,n),new H({...r,connection:o,executor:this.#e.executor.withConnectionProvider(new De(o.connection))})}}class H extends ae{#e;#t;#r;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Y(e.executor,t)};let{connection:r,...n}=e;super(n);this.#e=C(e),this.#r=t;let o=kt();this.#t=(p)=>e.executor.compileQuery(p,o)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return se(this.#r),new _e(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return se(this.#r),new _e(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}rollbackToSavepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}releaseSavepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}withPlugin(e){return new H({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new H({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new H({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new H({...this.#e})}}class _e{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}}function se(e){if(e.isCommitted)throw Error("Transaction is already committed");if(e.isRolledBack)throw Error("Transaction is already rolled back")}class Y{#e;#t;constructor(e,t){if(e instanceof Y)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 se(this.#t),this.#e.executeQuery(e)}stream(e,t){return se(this.#t),this.#e.stream(e,t)}withConnectionProvider(e){return new Y(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new Y(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new Y(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new Y(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new Y(this.#e.withoutPlugins(),this.#t)}}function L(e,t){return nr.createWithChildren([nr.createWithSql(`${e} `),it.create(t)])}class lt{#e;#t=new $t;#r;#n;constructor(e){this.#e=C({...e})}async init(){if(this.#r=pr(this.#e.database)?await this.#e.database():this.#e.database,this.#n=new Rt(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(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),kt()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#r?.close()}}class Rt{#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:p}=n.run(r);return Promise.resolve({numAffectedRows:o!==void 0&&o!==null?BigInt(o):void 0,insertId:p!==void 0&&p!==null?BigInt(p):void 0,rows:[]})}async*streamQuery(e,t){let{sql:r,parameters:n,query:o}=e,p=this.#e.prepare(r);if(sr.is(o)){let d=p.iterate(n);for(let c of d)yield{rows:[c]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class $t{#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?.()}}var j="kysely_migration",oe="kysely_migration_lock";var Mc=C({__noMigrations__:!0});class ut{#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","!=",j).where("name","!=",oe);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",je`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:p,type:d})=>{let c=p?.split(/[\(\),]/)?.find((I)=>I.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),S=n[o]??[];if(!c){let I=S.filter((O)=>O.pk>0);if(I.length===1&&I[0].type.toLowerCase()==="integer")c=I[0].name}return{name:o,isView:d==="view",columns:S.map((I)=>({name:I.name,dataType:I.type,isNullable:!I.notnull,isAutoIncrementing:I.name===c,hasDefaultValue:I.dflt_value!=null,comment:void 0}))}})}}class Be{#e;constructor(e){this.#e=C({...e})}createDriver(){return new lt(this.#e)}createQueryCompiler(){return new xc}createAdapter(){return new Cc}createIntrospector(e){return new ut(e)}}var lr=/"/g;class mt extends vo{sanitizeIdentifier(e){return e.replace(lr,'""')}}class dt{#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",je`col_description(a.attrelid, a.attnum)`.as("column_description"),je`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(je`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","!=",j).where("c.relname","!=",oe);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:p,table:d}=o,c=`schema:${p};table:${d}`;if(!t.has(c))t.set(c,C({columns:[],isView:o.table_type==="v",name:d,schema:p}));t.get(c).columns.push(C({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 ur=BigInt("3853314791062309107");class ht extends ea{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await je`select pg_advisory_xact_lock(${je.lit(ur)})`.execute(e)}async releaseMigrationLock(e,t){}}function Te(e,t){if(mr(e)&&t.stack){let r=t.stack.split(`
2
+ import{te,Ee}from"./chunk-xhmcdf36.js";import{Nr}from"./chunk-y4v4jnvv.js";import{ea,Sc,Ic}from"./chunk-v1fwt3x3.js";import{Oo,fr,Vs,ta,Va,Sf,Ka,pA,pr,an,C,Po,it,mA,_o,yo,vo,Or,Jt,Tc,Wa,qm,nr,vi,ps,$m,kc,Ja,bn,br,Oe,sr,If,kt,ed,Ks,Ya,Tf,td,bi,kf,ms,rd,Ws,Vo,Hm,ir,Js,je,bo,hA}from"./chunk-3w0w0a55.js";import{Zc,sa,Bc,Uc,jc}from"./chunk-2scr7dh6.js";import{ei}from"./chunk-37mc5a09.js";var A=C({is(e){return e.kind==="AlterTableNode"},create(e){return C({kind:"AlterTableNode",table:e})},cloneWithTableProps(e,t){return C({...e,...t})},cloneWithColumnAlteration(e,t){return C({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}});var P=C({is(e){return e.kind==="CreateIndexNode"},create(e){return C({kind:"CreateIndexNode",name:it.create(e)})},cloneWith(e,t){return C({...e,...t})},cloneWithColumns(e,t){return C({...e,columns:[...e.columns||[],...t]})}});var Me=C({is(e){return e.kind==="CreateSchemaNode"},create(e,t){return C({kind:"CreateSchemaNode",schema:it.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var X=C({is(e){return e.kind==="DropIndexNode"},create(e,t){return C({kind:"DropIndexNode",name:yo.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var Ce=C({is(e){return e.kind==="DropSchemaNode"},create(e,t){return C({kind:"DropSchemaNode",schema:it.create(e),...t})},cloneWith(e,t){return C({...e,...t})}});var be=C({is(e){return e.kind==="DropTableNode"},create(e,t){return C({kind:"DropTableNode",table:e,...t})},cloneWith(e,t){return C({...e,...t})}});var He=C({is(e){return e.kind==="AddColumnNode"},create(e){return C({kind:"AddColumnNode",column:e})}});var v=C({is(e){return e.kind==="ColumnDefinitionNode"},create(e,t){return C({kind:"ColumnDefinitionNode",column:Jt.create(e),dataType:t})},cloneWithFrontModifier(e,t){return C({...e,frontModifiers:e.frontModifiers?C([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return C({...e,endModifiers:e.endModifiers?C([...e.endModifiers,t]):[t]})},cloneWith(e,t){return C({...e,...t})}});var Ye=C({is(e){return e.kind==="DropColumnNode"},create(e){return C({kind:"DropColumnNode",column:Jt.create(e)})}});var Xe=C({is(e){return e.kind==="RenameColumnNode"},create(e,t){return C({kind:"RenameColumnNode",column:Jt.create(e),renameTo:Jt.create(t)})}});var ce=C({is(e){return e.kind==="CheckConstraintNode"},create(e,t){return C({kind:"CheckConstraintNode",expression:e,name:t?it.create(t):void 0})}});var Ot=["no action","restrict","cascade","set null","set default"],le=C({is(e){return e.kind==="ReferencesNode"},create(e,t){return C({kind:"ReferencesNode",table:e,columns:C([...t])})},cloneWithOnDelete(e,t){return C({...e,onDelete:t})},cloneWithOnUpdate(e,t){return C({...e,onUpdate:t})}});function Le(e){return Or(e)?e.toOperationNode():bn.createImmediate(e)}var Ie=C({is(e){return e.kind==="GeneratedNode"},create(e){return C({kind:"GeneratedNode",...e})},createWithExpression(e){return C({kind:"GeneratedNode",always:!0,expression:e})},cloneWith(e,t){return C({...e,...t})}});var qt=C({is(e){return e.kind==="DefaultValueNode"},create(e){return C({kind:"DefaultValueNode",defaultValue:e})}});function ue(e){if(Ot.includes(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}class k{#e;constructor(e){this.#e=e}autoIncrement(){return new k(v.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new k(v.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new k(v.cloneWith(this.#e,{primaryKey:!0}))}references(e){let t=ps(e);if(!t.table||Tc.is(t.column))throw Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new k(v.cloneWith(this.#e,{references:le.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 k(v.cloneWith(this.#e,{references:le.cloneWithOnDelete(this.#e.references,ue(e))}))}onUpdate(e){if(!this.#e.references)throw Error("on update constraint can only be added for foreign keys");return new k(v.cloneWith(this.#e,{references:le.cloneWithOnUpdate(this.#e.references,ue(e))}))}unique(){return new k(v.cloneWith(this.#e,{unique:!0}))}notNull(){return new k(v.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new k(v.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new k(v.cloneWith(this.#e,{defaultTo:qt.create(Le(e))}))}check(e){return new k(v.cloneWith(this.#e,{check:ce.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new k(v.cloneWith(this.#e,{generated:Ie.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new k(v.cloneWith(this.#e,{generated:Ie.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new k(v.cloneWith(this.#e,{generated:Ie.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new k(v.cloneWith(this.#e,{generated:Ie.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new k(v.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new k(v.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new k(v.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new k(v.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}}var Ze=C({is(e){return e.kind==="ModifyColumnNode"},create(e){return C({kind:"ModifyColumnNode",column:e})}});var W=C({is(e){return e.kind==="ForeignKeyConstraintNode"},create(e,t,r,n){return C({kind:"ForeignKeyConstraintNode",columns:e,references:le.create(t,r),name:n?it.create(n):void 0})},cloneWith(e,t){return C({...e,...t})}});class R{#e;constructor(e){this.#e=e}onDelete(e){return new R(W.cloneWith(this.#e,{onDelete:ue(e)}))}onUpdate(e){return new R(W.cloneWith(this.#e,{onUpdate:ue(e)}))}deferrable(){return new R(W.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new R(W.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new R(W.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new R(W.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}var me=C({is(e){return e.kind==="AddConstraintNode"},create(e){return C({kind:"AddConstraintNode",constraint:e})}});var F=C({is(e){return e.kind==="UniqueConstraintNode"},create(e,t,r){return C({kind:"UniqueConstraintNode",columns:C(e.map(Jt.create)),name:t?it.create(t):void 0,nullsNotDistinct:r})},cloneWith(e,t){return C({...e,...t})}});var de=C({is(e){return e.kind==="DropConstraintNode"},create(e){return C({kind:"DropConstraintNode",constraintName:it.create(e)})},cloneWith(e,t){return C({...e,...t})}});var he=C({is(e){return e.kind==="AlterColumnNode"},create(e,t,r){return C({kind:"AlterColumnNode",column:Jt.create(e),[t]:r})}});class Pe{#e;constructor(e){this.#e=e}setDataType(e){return new pe(he.create(this.#e,"dataType",Ws(e)))}setDefault(e){return new pe(he.create(this.#e,"setDefault",Le(e)))}dropDefault(){return new pe(he.create(this.#e,"dropDefault",!0))}setNotNull(){return new pe(he.create(this.#e,"setNotNull",!0))}dropNotNull(){return new pe(he.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}}class pe{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}}class Z{#e;constructor(e){this.#e=C(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 B{#e;constructor(e){this.#e=C(e)}onDelete(e){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new B({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(A.cloneWithTableProps(this.#e.node,{addConstraint:me.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 ie{#e;constructor(e){this.#e=C(e)}ifExists(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.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 G=C({is(e){return e.kind==="PrimaryKeyConstraintNode"},create(e,t){return C({kind:"PrimaryKeyConstraintNode",columns:C(e.map(Jt.create)),name:t?it.create(t):void 0})},cloneWith(e,t){return C({...e,...t})}});var ee=C({is(e){return e.kind==="AddIndexNode"},create(e){return C({kind:"AddIndexNode",name:it.create(e)})},cloneWith(e,t){return C({...e,...t})},cloneWithColumns(e,t){return C({...e,columns:[...e.columns||[],...t]})}});class re{#e;constructor(e){this.#e=C(e)}unique(){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,[kc(e)])})})}columns(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,e.map(kc))})})}expression(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWith(this.#e.node.addIndex,{using:nr.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 z{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new z(F.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new z(F.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new z(F.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new z(F.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new z(F.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class K{#e;constructor(e){this.#e=e}deferrable(){return new K(G.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new K(G.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new K(G.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new K(G.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}}class Ae{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}}var Mt=C({is(e){return e.kind==="RenameConstraintNode"},create(e,t){return C({kind:"RenameConstraintNode",oldName:it.create(e),newName:it.create(t)})}});class et{#e;constructor(e){this.#e=C(e)}renameTo(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{renameTo:ir(e)})})}setSchema(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{setSchema:it.create(e)})})}alterColumn(e,t){let r=t(new Pe(e));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ye.create(e))})}renameColumn(e,t){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Xe.create(e,t))})}addColumn(e,t,r=Po){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Po){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ze.create(n.toOperationNode()))})}addUniqueConstraint(e,t,r=Po){let n=r(new z(F.create(t,e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}addCheckConstraint(e,t,r=Po){let n=r(new Ae(ce.create(t.toOperationNode(),e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}addForeignKeyConstraint(e,t,r,n,o=Po){let p=o(new R(W.create(t.map(Jt.create),ir(r),n.map(Jt.create),e)));return new B({...this.#e,constraintBuilder:p})}addPrimaryKeyConstraint(e,t,r=Po){let n=r(new K(G.create(t,e)));return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addConstraint:me.create(n.toOperationNode())})})}dropConstraint(e){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropConstraint:de.create(e)})})}renameConstraint(e,t){return new ie({...this.#e,node:A.cloneWithTableProps(this.#e.node,{renameConstraint:Mt.create(e,t)})})}addIndex(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.create(e)})})}dropIndex(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{dropIndex:X.create(e)})})}$call(e){return e(this)}}class Q{#e;constructor(e){this.#e=C(e)}alterColumn(e,t){let r=t(new Pe(e));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(e){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ye.create(e))})}renameColumn(e,t){return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Xe.create(e,t))})}addColumn(e,t,r=Po){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Po){let n=r(new k(v.create(e,Ws(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ze.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 Se extends ed{transformPrimitiveValueList(e){return Ja.create(e.values.map(bn.createImmediate))}transformValue(e){return bn.createImmediate(e.value)}}class M{#e;constructor(e){this.#e=C(e)}ifNotExists(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new M({...this.#e,node:P.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new M({...this.#e,node:P.cloneWith(this.#e.node,{table:ir(e)})})}column(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,[kc(e)])})}columns(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,e.map(kc))})}expression(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new M({...this.#e,node:P.cloneWith(this.#e.node,{using:nr.createWithSql(e)})})}where(...e){let t=new Se;return new M({...this.#e,node:Oe.cloneWithWhere(this.#e.node,t.transformNode(br(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 We{#e;constructor(e){this.#e=C(e)}ifNotExists(){return new We({...this.#e,node:Me.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 Lt(e){if(mA.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}class q{#e;constructor(e){this.#e=C(e)}temporary(){return new q({...this.#e,node:_o.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new q({...this.#e,node:_o.cloneWith(this.#e.node,{onCommit:Lt(e)})})}ifNotExists(){return new q({...this.#e,node:_o.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,r=Po){let n=r(new k(v.create(e,Ws(t))));return new q({...this.#e,node:_o.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,t,r=Po){let n=r(new K(G.create(t,e)));return new q({...this.#e,node:_o.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,t,r=Po){let n=r(new z(F.create(t,e)));return new q({...this.#e,node:_o.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,t,r=Po){let n=r(new Ae(ce.create(t.toOperationNode(),e)));return new q({...this.#e,node:_o.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,t,r,n,o=Po){let p=o(new R(W.create(t.map(Jt.create),ir(r),n.map(Jt.create),e)));return new q({...this.#e,node:_o.cloneWithConstraint(this.#e.node,p.toOperationNode())})}modifyFront(e){return new q({...this.#e,node:_o.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new q({...this.#e,node:_o.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new q({...this.#e,node:_o.cloneWith(this.#e.node,{selectQuery:Vo(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 fe{#e;constructor(e){this.#e=C(e)}on(e){return new fe({...this.#e,node:X.cloneWith(this.#e.node,{table:ir(e)})})}ifExists(){return new fe({...this.#e,node:X.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new fe({...this.#e,node:X.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 ve{#e;constructor(e){this.#e=C(e)}ifExists(){return new ve({...this.#e,node:Ce.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ve({...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 ke{#e;constructor(e){this.#e=C(e)}ifExists(){return new ke({...this.#e,node:be.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ke({...this.#e,node:be.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 tt{#e=new Se;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}}class J{#e;constructor(e){this.#e=C(e)}temporary(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new J({...this.#e,node:Js.cloneWith(this.#e.node,{columns:e.map($m)})})}as(e){let t=e.withPlugin(new tt).toOperationNode();return new J({...this.#e,node:Js.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 we=C({is(e){return e.kind==="DropViewNode"},create(e){return C({kind:"DropViewNode",name:yo.create(e)})},cloneWith(e,t){return C({...e,...t})}});class ye{#e;constructor(e){this.#e=C(e)}materialized(){return new ye({...this.#e,node:we.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new ye({...this.#e,node:we.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new ye({...this.#e,node:we.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 Re=C({is(e){return e.kind==="CreateTypeNode"},create(e){return C({kind:"CreateTypeNode",name:e})},cloneWithEnum(e,t){return C({...e,enum:Ja.create(t.map(bn.createImmediate))})}});class $e{#e;constructor(e){this.#e=C(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new $e({...this.#e,node:Re.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 Qe=C({is(e){return e.kind==="DropTypeNode"},create(e){return C({kind:"DropTypeNode",name:e})},cloneWith(e,t){return C({...e,...t})}});class Fe{#e;constructor(e){this.#e=C(e)}ifExists(){return new Fe({...this.#e,node:Qe.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 rt(e){if(e.includes(".")){let r=e.split(".").map(Zt);if(r.length===2)return yo.createWithSchema(r[0],r[1]);else throw Error(`invalid schemable identifier ${e}`)}else return yo.create(e)}function Zt(e){return e.trim()}var xe=C({is(e){return e.kind==="RefreshMaterializedViewNode"},create(e){return C({kind:"RefreshMaterializedViewNode",name:yo.create(e)})},cloneWith(e,t){return C({...e,...t})}});class Ne{#e;constructor(e){this.#e=C(e)}concurrently(){return new Ne({...this.#e,node:xe.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new Ne({...this.#e,node:xe.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new Ne({...this.#e,node:xe.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 ge{#e;constructor(e){this.#e=e}createTable(e){return new q({queryId:kt(),executor:this.#e,node:_o.create(ir(e))})}dropTable(e){return new ke({queryId:kt(),executor:this.#e,node:be.create(ir(e))})}createIndex(e){return new M({queryId:kt(),executor:this.#e,node:P.create(e)})}dropIndex(e){return new fe({queryId:kt(),executor:this.#e,node:X.create(e)})}createSchema(e){return new We({queryId:kt(),executor:this.#e,node:Me.create(e)})}dropSchema(e){return new ve({queryId:kt(),executor:this.#e,node:Ce.create(e)})}alterTable(e){return new et({queryId:kt(),executor:this.#e,node:A.create(ir(e))})}createView(e){return new J({queryId:kt(),executor:this.#e,node:Js.create(e)})}refreshMaterializedView(e){return new Ne({queryId:kt(),executor:this.#e,node:xe.create(e)})}dropView(e){return new ye({queryId:kt(),executor:this.#e,node:we.create(e)})}createType(e){return new $e({queryId:kt(),executor:this.#e,node:Re.create(rt(e))})}dropType(e){return new Fe({queryId:kt(),executor:this.#e,node:Qe.create(rt(e))})}withPlugin(e){return new ge(this.#e.withPlugin(e))}withoutPlugins(){return new ge(this.#e.withoutPlugins())}withSchema(e){return new ge(this.#e.withPluginAtFront(new Ks(e)))}}class nt{ref(e){return new qm(e)}table(e){return new Hm(e)}}class ot{#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 ne extends td{#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 ne(this.#e,this.#t,this.#r,[...this.plugins,...e])}withPlugin(e){return new ne(this.#e,this.#t,this.#r,[...this.plugins,e])}withPluginAtFront(e){return new ne(this.#e,this.#t,this.#r,[e,...this.plugins])}withConnectionProvider(e){return new ne(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new ne(this.#e,this.#t,this.#r,[])}}function ze(){if(typeof performance<"u"&&pr(performance.now))return performance.now();else return Date.now()}class st{#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 p,d=ze();try{return await t.call(e,o)}catch(c){throw p=c,await n.#s(c,o,d),c}finally{if(!p)await n.#l(o,d)}},e.streamQuery=async function*(o,p){let d,c=ze();try{for await(let S of r.call(e,o,p))yield S}catch(S){throw d=S,await n.#s(S,o,c),S}finally{if(!d)await n.#l(o,c,!0)}}}async#s(e,t,r){await this.#t.error(()=>({level:"error",error:e,query:t,queryDurationMillis:this.#u(r)}))}async#l(e,t,r=!1){await this.#t.query(()=>({level:"query",isStream:r,query:e,queryDurationMillis:this.#u(t)}))}#u(e){return ze()-e}}var er=()=>{};class De{#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"],rr=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function at(e){if(e.accessMode&&!tr.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!rr.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}var or=["query","error"],Ba=C(or);class ct{#e;#t;constructor(e){if(pr(e))this.#t=e,this.#e=C({query:!0,error:!0});else this.#t=ar,this.#e=C({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 Pt(e){return an(e)&&pr(e.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class U extends bi{#e;constructor(e){let t,r;if(cr(e))t={executor:e.executor},r={...e};else{let n=e.dialect,o=n.createDriver(),p=n.createQueryCompiler(),d=n.createAdapter(),c=new ct(e.log??[]),S=new st(o,c),I=new ot(S),O=new ne(p,d,I,e.plugins??[]);t={executor:O},r={config:e,executor:O,dialect:n,driver:S}}super(t);this.#e=C(r)}get schema(){return new ge(this.#e.executor)}get dynamic(){return new nt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new rd({node:ms.create(Oo(e)?void 0:Vo(e))})}get fn(){return kf()}transaction(){return new Ue({...this.#e})}startTransaction(){return new Ve({...this.#e})}connection(){return new Wt({...this.#e})}withPlugin(e){return new U({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new U({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new U({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new U({...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)vi("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let r=Pt(e)?e.compile():e;return this.getExecutor().executeQuery(r)}async[Symbol.asyncDispose](){await this.destroy()}}class ae extends U{#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 ae({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new ae({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new ae({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new ae({...this.#e})}}function cr(e){return an(e)&&an(e.config)&&an(e.driver)&&an(e.executor)&&an(e.dialect)}class Wt{#e;constructor(e){this.#e=C(e)}async execute(e){return this.#e.executor.provideConnection(async(t)=>{let r=this.#e.executor.withConnectionProvider(new De(t)),n=new U({...this.#e,executor:r});return await e(n)})}}class Ue{#e;constructor(e){this.#e=C(e)}setAccessMode(e){return new Ue({...this.#e,accessMode:e})}setIsolationLevel(e){return new Ue({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:t,accessMode:r,...n}=this.#e,o={isolationLevel:t,accessMode:r};return at(o),this.#e.executor.provideConnection(async(p)=>{let d={isCommitted:!1,isRolledBack:!1},c=new Y(this.#e.executor.withConnectionProvider(new De(p)),d),S=new ae({...n,executor:c}),I=!1;try{await this.#e.driver.beginTransaction(p,o),I=!0;let O=await e(S);return await this.#e.driver.commitTransaction(p),d.isCommitted=!0,O}catch(O){if(I)await this.#e.driver.rollbackTransaction(p),d.isRolledBack=!0;throw O}})}}class Ve{#e;constructor(e){this.#e=C(e)}setAccessMode(e){return new Ve({...this.#e,accessMode:e})}setIsolationLevel(e){return new Ve({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:t,...r}=this.#e,n={isolationLevel:e,accessMode:t};at(n);let o=await Tf(this.#e.executor);return await this.#e.driver.beginTransaction(o.connection,n),new H({...r,connection:o,executor:this.#e.executor.withConnectionProvider(new De(o.connection))})}}class H extends ae{#e;#t;#r;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Y(e.executor,t)};let{connection:r,...n}=e;super(n);this.#e=C(e),this.#r=t;let o=kt();this.#t=(p)=>e.executor.compileQuery(p,o)}get isCommitted(){return this.#r.isCommitted}get isRolledBack(){return this.#r.isRolledBack}commit(){return se(this.#r),new _e(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#r.isCommitted=!0,this.#e.connection.release()})}rollback(){return se(this.#r),new _e(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#r.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}rollbackToSavepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}releaseSavepoint(e){return se(this.#r),new _e(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new H({...this.#e})))}withPlugin(e){return new H({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new H({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new H({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ks(e))})}withTables(){return new H({...this.#e})}}class _e{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}}function se(e){if(e.isCommitted)throw Error("Transaction is already committed");if(e.isRolledBack)throw Error("Transaction is already rolled back")}class Y{#e;#t;constructor(e,t){if(e instanceof Y)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 se(this.#t),this.#e.executeQuery(e)}stream(e,t){return se(this.#t),this.#e.stream(e,t)}withConnectionProvider(e){return new Y(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new Y(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new Y(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new Y(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new Y(this.#e.withoutPlugins(),this.#t)}}function L(e,t){return nr.createWithChildren([nr.createWithSql(`${e} `),it.create(t)])}class lt{#e;#t=new $t;#r;#n;constructor(e){this.#e=C({...e})}async init(){if(this.#r=pr(this.#e.database)?await this.#e.database():this.#e.database,this.#n=new Rt(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(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),kt()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#r?.close()}}class Rt{#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:p}=n.run(r);return Promise.resolve({numAffectedRows:o!==void 0&&o!==null?BigInt(o):void 0,insertId:p!==void 0&&p!==null?BigInt(p):void 0,rows:[]})}async*streamQuery(e,t){let{sql:r,parameters:n,query:o}=e,p=this.#e.prepare(r);if(sr.is(o)){let d=p.iterate(n);for(let c of d)yield{rows:[c]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class $t{#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?.()}}var j="kysely_migration",oe="kysely_migration_lock";var Mc=C({__noMigrations__:!0});class ut{#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","!=",j).where("name","!=",oe);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",je`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:p,type:d})=>{let c=p?.split(/[\(\),]/)?.find((I)=>I.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),S=n[o]??[];if(!c){let I=S.filter((O)=>O.pk>0);if(I.length===1&&I[0].type.toLowerCase()==="integer")c=I[0].name}return{name:o,isView:d==="view",columns:S.map((I)=>({name:I.name,dataType:I.type,isNullable:!I.notnull,isAutoIncrementing:I.name===c,hasDefaultValue:I.dflt_value!=null,comment:void 0}))}})}}class Be{#e;constructor(e){this.#e=C({...e})}createDriver(){return new lt(this.#e)}createQueryCompiler(){return new Sc}createAdapter(){return new Ic}createIntrospector(e){return new ut(e)}}var lr=/"/g;class mt extends bo{sanitizeIdentifier(e){return e.replace(lr,'""')}}class dt{#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",je`col_description(a.attrelid, a.attnum)`.as("column_description"),je`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(je`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","!=",j).where("c.relname","!=",oe);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:p,table:d}=o,c=`schema:${p};table:${d}`;if(!t.has(c))t.set(c,C({columns:[],isView:o.table_type==="v",name:d,schema:p}));t.get(c).columns.push(C({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 ur=BigInt("3853314791062309107");class ht extends ea{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await je`select pg_advisory_xact_lock(${je.lit(ur)})`.execute(e)}async releaseMigrationLock(e,t){}}function Te(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 an(e)&&fr(e.stack)}var Qt=Symbol();class pt{#e;#t=new WeakMap;#r;constructor(e){this.#e=C({...e})}async init(){this.#r=pr(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 Ft(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(Nr.raw(n))}await e.executeQuery(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release savepoint",t),kt()))}async releaseConnection(e){e[Qt]()}async destroy(){return new Promise((e,t)=>{this.#r.end((r)=>{if(r)t(r);else e()})})}}function dr(e){return an(e)&&"insertId"in e&&"affectedRows"in e}class Ft{#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 Te(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}}[Qt](){this.#e.release()}}var hr=/[\\']/g,ft=/`/g,wr=/[\\'"]/g;class wt extends vo{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return ft.source}getRightIdentifierWrapper(){return ft.source}sanitizeIdentifier(e){return e.replace(ft,"``")}sanitizeStringLiteral(e){return e.replace(hr,(t)=>t==="\\"?"\\\\":"''")}sanitizeJSONPathMemberValue(e){return e.replace(wr,(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 yt{#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","=",je`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!e.withInternalKyselyTables)t=t.where("columns.TABLE_NAME","!=",j).where("columns.TABLE_NAME","!=",oe);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=C({name:r.TABLE_NAME,isView:r.TABLE_TYPE==="VIEW",schema:r.TABLE_SCHEMA,columns:[]}),t.push(n);return n.columns.push(C({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 zt="ea586330-2c93-47c8-908d-981d9d270f9d",yr=3600;class xt extends ea{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await je`select get_lock(${je.lit(zt)}, ${je.lit(yr)})`.execute(e)}async releaseMigrationLock(e,t){await je`select release_lock(${je.lit(zt)})`.execute(e)}}class Ge{#e;constructor(e){this.#e=e}createDriver(){return new pt(this.#e)}createQueryCompiler(){return new wt}createAdapter(){return new xt}createIntrospector(e){return new yt(e)}}var Ut=Symbol();class Nt{#e;#t=new WeakMap;#r;constructor(e){this.#e=C({...e})}async init(){this.#r=pr(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 jt(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(Nr.raw(r))}else await e.executeQuery(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),kt()))}async releaseConnection(e){e[Ut]()}async destroy(){if(this.#r){let e=this.#r;this.#r=void 0,await e.end()}}}class jt{#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 Te(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()}}[Ut](){this.#e.release()}}class Ke{#e;constructor(e){this.#e=e}createDriver(){return new Nt(this.#e)}createQueryCompiler(){return new mt}createAdapter(){return new ht}createIntrospector(e){return new dt(e)}}class gt extends ea{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await je`exec sp_getapplock @DbPrincipal = ${je.lit("dbo")}, @Resource = ${je.lit(j)}, @LockMode = ${je.lit("Exclusive")}`.execute(e)}async releaseMigrationLock(){}}var Vt=Symbol(),Bt=Symbol(),Gt=Symbol();class _t{#e;#t;constructor(e){this.#e=C({...e});let{tarn:t,tedious:r,validateConnections:n}=this.#e,{validateConnections:o,...p}=t.options;this.#t=new t.Pool({...p,create:async()=>{let d=await r.connectionFactory();return await new Kt(d,r).connect()},destroy:async(d)=>{await d[Bt]()},validate:n===!1||o===!1?void 0:(d)=>d[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[Vt]();this.#t.release(e)}async destroy(){await this.#t.destroy()}}class Kt{#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?Cf(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 Ya;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 Ya,r=new Je({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 Te(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 Je({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()})}[Bt](){if("closed"in this.#e&&this.#e.closed)return Promise.resolve();return new Promise((e)=>{this.#e.once("end",e),this.#e.close()})}async[Vt](){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 Ya,t=new Je({compiledQuery:Nr.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 Je{#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=(d,c)=>{if(d==="chunkReady")return;if(delete this.#n.onDone,d==="error")return r.reject(c);r.resolve({rowCount:this.#i,rows:this.#t})};this.#e=new this.#o.Request(t.sql,(p,d)=>{if(p)return Object.values(this.#n).forEach((c)=>c("error",p instanceof AggregateError?p.errors:p));this.#i=d}),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(Va(e)||Mo(e)||fr(e))return this.#o.TYPES.NVarChar;if(Ka(e)||Vs(e)&&e%1===0)if(e<-2147483648||e>2147483647)return this.#o.TYPES.BigInt;else return this.#o.TYPES.Int;if(Vs(e))return this.#o.TYPES.Float;if(ta(e))return this.#o.TYPES.Bit;if(xf(e))return this.#o.TYPES.DateTime;if(fA(e))return this.#o.TYPES.VarBinary;return this.#o.TYPES.NVarChar}}class Tt{#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","!=",j).where("tables.name","!=",oe)).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]||C({columns:[],isView:n.table_type==="V ",name:n.table_name,schema:n.table_schema_name??void 0})).columns.push(C({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 xr=/^[a-z0-9_]$/i;class Et extends vo{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(!xr.test(r))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}}class Ct{#e;constructor(e){this.#e=e}createDriver(){return new _t(this.#e)}createQueryCompiler(){return new Et}createAdapter(){return new gt}createIntrospector(e){return new Tt(e)}}function bt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function wf(e){if(!e)return null;if("dialect"in e)return wf(e.dialect);if("createDriver"in e){if(e instanceof Be)return"sqlite";if(e instanceof Ge)return"mysql";if(e instanceof Ke)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}function Ht(e,t){if(e===void 0)return;if(typeof e!=="string"||e.length===0)throw new te("`database.schemaName` must be a non-empty schema name.");if(t!=="postgres")throw new te(`\`database.schemaName\` is only supported on PostgreSQL, but the configured database type is "${t??"unknown"}".`)}var Fm=async(e)=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,introspectIndexes:void 0,schemaName:void 0,transaction:void 0};if("db"in t){let d=t.schemaName;return Ht(d,t.type),{kysely:d?t.db.withSchema(d):t.db,databaseType:t.type,introspectIndexes:void 0,schemaName:d,transaction:t.transaction}}if("dialect"in t){let d=t.schemaName;Ht(d,t.type);let c=new U({dialect:t.dialect});return{kysely:d?c.withSchema(d):c,databaseType:t.type,introspectIndexes:void 0,schemaName:d,transaction:t.transaction}}let r=void 0,n=void 0,o=void 0,p=wf(t);if("createDriver"in t)r=t;if("aggregate"in t&&!("createSession"in t))r=new Be({database:t}),o=!0;if("getConnection"in t)r=new Ge(t),o=!0;if("connect"in t)r=new Ke({pool:t}),o=!0;if("fileControl"in t){let{BunSqliteDialect:d}=await import("./chunk-396tfwdx.js");r=new d({database:t}),o=!0}if("createSession"in t){let d=void 0;try{({DatabaseSync:d}=await import("node:sqlite"))}catch(c){if(c!==null&&typeof c==="object"&&"code"in c&&c.code!=="ERR_UNKNOWN_BUILTIN_MODULE")throw c}if(d&&t instanceof d){let{NodeSqliteDialect:c}=await import("./chunk-vk3eqr65.js");r=new c({database:t}),o=!0}}if("batch"in t&&"exec"in t&&"prepare"in t){let{createD1IndexIntrospector:d,D1SqliteDialect:c}=await import("./chunk-pemmtd8q.js");r=new c({database:t}),n=d(t),o=!1}return{kysely:r?new U({dialect:r}):null,databaseType:p,introspectIndexes:n,schemaName:void 0,transaction:o}};function It(e,t,r){return r==="postgres"?je`${je.ref(e)} ILIKE ${t}`:je`LOWER(${je.ref(e)}) LIKE LOWER(${t})`}function gr(e,t){return{lhs:je`LOWER(${je.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function _r(e,t){return{lhs:je`LOWER(${je.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function Tr(e,t){return{lhs:je`LOWER(${je.ref(e)})`,value:t.toLowerCase()}}function Er(e,t){return{lhs:je`LOWER(${je.ref(e)})`,value:t.toLowerCase()}}function Ef(e){return e.map((t)=>({name:t.name,schema:t.schema,columns:t.columns.map((r)=>({name:r.name,nullable:r.isNullable,hasDefault:r.hasDefaultValue||r.isAutoIncrementing}))}))}function Lm(e,t){let r={};for(let[n,o]of Object.entries(t)){let p=Object.entries(o.fields),d=Cr(e,n,[o.idColumn??"id",...p.map(([S])=>S)]),c={};p.forEach(([S,I],O)=>{c[d.columns[O+1]??S]=I}),r[d.table]={...o,fields:c,schema:d.schema??o.schema,...d.columns[0]!=="id"&&{idColumn:d.columns[0]}}}return r}function Cr(e,t,r){let{query:n}=e.selectFrom(t).select(r).compile();if(!sr.is(n))return{table:t,columns:[]};let o=n.from?.froms[0],p=o&&yo.is(o)?o.table:void 0;return{schema:p?.schema?.name,table:p?.identifier.name??t,columns:(n.selections??[]).map(({selection:d})=>Wa.is(d)&&Jt.is(d.column)?d.column.column.name:void 0)}}async function dA(e){return(await je`
5
+ ${r}`,e}return e}function mr(e){return an(e)&&fr(e.stack)}var Qt=Symbol();class pt{#e;#t=new WeakMap;#r;constructor(e){this.#e=C({...e})}async init(){this.#r=pr(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 Ft(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(Nr.raw(n))}await e.executeQuery(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release savepoint",t),kt()))}async releaseConnection(e){e[Qt]()}async destroy(){return new Promise((e,t)=>{this.#r.end((r)=>{if(r)t(r);else e()})})}}function dr(e){return an(e)&&"insertId"in e&&"affectedRows"in e}class Ft{#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 Te(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}}[Qt](){this.#e.release()}}var hr=/[\\']/g,ft=/`/g,wr=/[\\'"]/g;class wt extends bo{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return ft.source}getRightIdentifierWrapper(){return ft.source}sanitizeIdentifier(e){return e.replace(ft,"``")}sanitizeStringLiteral(e){return e.replace(hr,(t)=>t==="\\"?"\\\\":"''")}sanitizeJSONPathMemberValue(e){return e.replace(wr,(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 yt{#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","=",je`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!e.withInternalKyselyTables)t=t.where("columns.TABLE_NAME","!=",j).where("columns.TABLE_NAME","!=",oe);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=C({name:r.TABLE_NAME,isView:r.TABLE_TYPE==="VIEW",schema:r.TABLE_SCHEMA,columns:[]}),t.push(n);return n.columns.push(C({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 zt="ea586330-2c93-47c8-908d-981d9d270f9d",yr=3600;class xt extends ea{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await je`select get_lock(${je.lit(zt)}, ${je.lit(yr)})`.execute(e)}async releaseMigrationLock(e,t){await je`select release_lock(${je.lit(zt)})`.execute(e)}}class Ge{#e;constructor(e){this.#e=e}createDriver(){return new pt(this.#e)}createQueryCompiler(){return new wt}createAdapter(){return new xt}createIntrospector(e){return new yt(e)}}var Ut=Symbol();class Nt{#e;#t=new WeakMap;#r;constructor(e){this.#e=C({...e})}async init(){this.#r=pr(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 jt(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(Nr.raw(r))}else await e.executeQuery(Nr.raw("begin"))}async commitTransaction(e){await e.executeQuery(Nr.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Nr.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),kt()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),kt()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),kt()))}async releaseConnection(e){e[Ut]()}async destroy(){if(this.#r){let e=this.#r;this.#r=void 0,await e.end()}}}class jt{#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 Te(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()}}[Ut](){this.#e.release()}}class Ke{#e;constructor(e){this.#e=e}createDriver(){return new Nt(this.#e)}createQueryCompiler(){return new mt}createAdapter(){return new ht}createIntrospector(e){return new dt(e)}}class gt extends ea{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await je`exec sp_getapplock @DbPrincipal = ${je.lit("dbo")}, @Resource = ${je.lit(j)}, @LockMode = ${je.lit("Exclusive")}`.execute(e)}async releaseMigrationLock(){}}var Vt=Symbol(),Bt=Symbol(),Gt=Symbol();class _t{#e;#t;constructor(e){this.#e=C({...e});let{tarn:t,tedious:r,validateConnections:n}=this.#e,{validateConnections:o,...p}=t.options;this.#t=new t.Pool({...p,create:async()=>{let d=await r.connectionFactory();return await new Kt(d,r).connect()},destroy:async(d)=>{await d[Bt]()},validate:n===!1||o===!1?void 0:(d)=>d[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[Vt]();this.#t.release(e)}async destroy(){await this.#t.destroy()}}class Kt{#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?If(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 Ya;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 Ya,r=new Je({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 Te(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 Je({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()})}[Bt](){if("closed"in this.#e&&this.#e.closed)return Promise.resolve();return new Promise((e)=>{this.#e.once("end",e),this.#e.close()})}async[Vt](){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 Ya,t=new Je({compiledQuery:Nr.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 Je{#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=(d,c)=>{if(d==="chunkReady")return;if(delete this.#n.onDone,d==="error")return r.reject(c);r.resolve({rowCount:this.#i,rows:this.#t})};this.#e=new this.#o.Request(t.sql,(p,d)=>{if(p)return Object.values(this.#n).forEach((c)=>c("error",p instanceof AggregateError?p.errors:p));this.#i=d}),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(Va(e)||Oo(e)||fr(e))return this.#o.TYPES.NVarChar;if(Ka(e)||Vs(e)&&e%1===0)if(e<-2147483648||e>2147483647)return this.#o.TYPES.BigInt;else return this.#o.TYPES.Int;if(Vs(e))return this.#o.TYPES.Float;if(ta(e))return this.#o.TYPES.Bit;if(Sf(e))return this.#o.TYPES.DateTime;if(pA(e))return this.#o.TYPES.VarBinary;return this.#o.TYPES.NVarChar}}class Tt{#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","!=",j).where("tables.name","!=",oe)).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]||C({columns:[],isView:n.table_type==="V ",name:n.table_name,schema:n.table_schema_name??void 0})).columns.push(C({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 xr=/^[a-z0-9_]$/i;class Et extends bo{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(!xr.test(r))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}}class Ct{#e;constructor(e){this.#e=e}createDriver(){return new _t(this.#e)}createQueryCompiler(){return new Et}createAdapter(){return new gt}createIntrospector(e){return new Tt(e)}}function bt(e){return e.charAt(0).toUpperCase()+e.slice(1)}function xf(e){if(!e)return null;if("dialect"in e)return xf(e.dialect);if("createDriver"in e){if(e instanceof Be)return"sqlite";if(e instanceof Ge)return"mysql";if(e instanceof Ke)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}function Ht(e,t){if(e===void 0)return;if(typeof e!=="string"||e.length===0)throw new te("`database.schemaName` must be a non-empty schema name.");if(t!=="postgres")throw new te(`\`database.schemaName\` is only supported on PostgreSQL, but the configured database type is "${t??"unknown"}".`)}var Um=async(e)=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,introspectIndexes:void 0,schemaName:void 0,transaction:void 0};if("db"in t){let d=t.schemaName;return Ht(d,t.type),{kysely:d?t.db.withSchema(d):t.db,databaseType:t.type,introspectIndexes:void 0,schemaName:d,transaction:t.transaction}}if("dialect"in t){let d=t.schemaName;Ht(d,t.type);let c=new U({dialect:t.dialect});return{kysely:d?c.withSchema(d):c,databaseType:t.type,introspectIndexes:void 0,schemaName:d,transaction:t.transaction}}let r=void 0,n=void 0,o=void 0,p=xf(t);if("createDriver"in t)r=t;if("aggregate"in t&&!("createSession"in t))r=new Be({database:t}),o=!0;if("getConnection"in t)r=new Ge(t),o=!0;if("connect"in t)r=new Ke({pool:t}),o=!0;if("fileControl"in t){let{BunSqliteDialect:d}=await import("./chunk-56h2f6s6.js");r=new d({database:t}),o=!0}if("createSession"in t){let d=void 0;try{({DatabaseSync:d}=await import("node:sqlite"))}catch(c){if(c!==null&&typeof c==="object"&&"code"in c&&c.code!=="ERR_UNKNOWN_BUILTIN_MODULE")throw c}if(d&&t instanceof d){let{NodeSqliteDialect:c}=await import("./chunk-wvf465g9.js");r=new c({database:t}),o=!0}}if("batch"in t&&"exec"in t&&"prepare"in t){let{createD1IndexIntrospector:d,D1SqliteDialect:c}=await import("./chunk-9s35n63t.js");r=new c({database:t}),n=d(t),o=!1}return{kysely:r?new U({dialect:r}):null,databaseType:p,introspectIndexes:n,schemaName:void 0,transaction:o}};function It(e,t,r){return r==="postgres"?je`${je.ref(e)} ILIKE ${t}`:je`LOWER(${je.ref(e)}) LIKE LOWER(${t})`}function gr(e,t){return{lhs:je`LOWER(${je.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function _r(e,t){return{lhs:je`LOWER(${je.ref(e)})`,values:t.map((r)=>r.toLowerCase())}}function Tr(e,t){return{lhs:je`LOWER(${je.ref(e)})`,value:t.toLowerCase()}}function Er(e,t){return{lhs:je`LOWER(${je.ref(e)})`,value:t.toLowerCase()}}function Cf(e){return e.map((t)=>({name:t.name,schema:t.schema,columns:t.columns.map((r)=>({name:r.name,nullable:r.isNullable,hasDefault:r.hasDefaultValue||r.isAutoIncrementing}))}))}function zm(e,t){let r={};for(let[n,o]of Object.entries(t)){let p=Object.entries(o.fields),d=Cr(e,n,[o.idColumn??"id",...p.map(([S])=>S)]),c={};p.forEach(([S,I],O)=>{c[d.columns[O+1]??S]=I}),r[d.table]={...o,fields:c,schema:d.schema??o.schema,...d.columns[0]!=="id"&&{idColumn:d.columns[0]}}}return r}function Cr(e,t,r){let{query:n}=e.selectFrom(t).select(r).compile();if(!sr.is(n))return{table:t,columns:[]};let o=n.from?.froms[0],p=o&&vo.is(o)?o.table:void 0;return{schema:p?.schema?.name,table:p?.identifier.name??t,columns:(n.selections??[]).map(({selection:d})=>Wa.is(d)&&Jt.is(d.column)?d.column.column.name:void 0)}}async function fA(e){return(await je`
6
6
  SELECT pg_catalog.current_schema() AS schema
7
- `.execute(e.withoutPlugins())).rows[0]?.schema??"public"}async function Zm(e){return(await je`
7
+ `.execute(e.withoutPlugins())).rows[0]?.schema??"public"}async function jm(e){return(await je`
8
8
  SELECT SCHEMA_NAME() AS "schemaName"
9
9
  `.execute(e.withoutPlugins())).rows[0]?.schemaName||"dbo"}async function Ir(e,t){if(t==="postgres")return(await je`
10
10
  SELECT pg_catalog.current_schemas(true)::text[] AS schemas
11
- `.execute(e.withoutPlugins())).rows[0]?.schemas??[];if(t==="mssql")return[await Zm(e),"dbo"]}async function Ar(e,t,r){let n=Lm(e,r);if(t==="sqlite")return sa(n,Ef(await mA(e,Object.entries(n).flatMap(([o,p])=>p.disableMigrations?[]:[o]))));return e.connection().execute(async(o)=>{let p=await Ir(o,t),d=Ef(await o.introspection.getTables());for(let[c,S]of Object.entries(n)){if(S.schema!==void 0||!p)continue;S.schema=p.find((I)=>d.some((O)=>O.name===c&&O.schema===I))??""}return sa(n,d)})}var DD=(e,t)=>{let r=null,n=!1,o=(c,S=!1)=>({getFieldName:I,schema:O,getDefaultFieldName:Sr,getDefaultModelName:Yt,getFieldAttributes:vr,getModelName:kr,options:At})=>{if(t?.type==="mysql"&&At.advanced?.database?.generateId===!1&&!n)n=!0,Ee.warn(`[Kysely Adapter] MySQL does not support INSERT...RETURNING. With generateId set to false, the adapter uses best-effort fallback strategies (unique columns, full-field match) to retrieve inserted rows. For reliable behavior, use Better Auth's default ID generation, a custom generateId function, or generateId: "serial" for auto-increment.`);let St=(s)=>{let x=[],E=[];if(s)for(let[y,g]of Object.entries(s)){let f=O[g.modelKey??Yt(y)]?.fields,[m,a]=y.includes(".")?y.split("."):[void 0,y];if(!f)continue;f.id={type:"string"};for(let[h,N]of Object.entries(f))x.push(je`${je.ref(`join_${a}`)}.${je.ref(N.fieldName||h)} as ${je.ref(`_joined_${a}_${N.fieldName||h}`)}`),E.push({joinModel:y,joinModelRef:a,fieldName:N.fieldName||h})}return{allSelectsStr:E,allSelects:x}},vt=async(s,x,E,y,g)=>{if(t?.type==="mysql"){if(g.length>0){let m=await x.executeTakeFirst();if(!m||Number(m.numUpdatedRows??0)===0)return null;let a=g.find((i)=>i.field==="id"&&(i.operator===void 0||i.operator==="eq")&&i.connector!=="OR"&&i.value!==void 0&&i.value!==null),h,N;if(s.id!==void 0&&s.id!==null)h="id",N=s.id;else if(a)h="id",N=a.value;else if(g[0]?.field)h=g[0].field,N=s[h]!==void 0?s[h]:g[0].value;else return null;return await c.selectFrom(E).selectAll().where(I({model:y,field:h}),N===null?"is":"=",N).limit(1).executeTakeFirst()}await x.execute();let f=async(m)=>{if(s.id)return await m.selectFrom(E).selectAll().where(I({model:y,field:"id"}),"=",s.id).limit(1).executeTakeFirst();if(At.advanced?.database?.generateId==="serial"){let i=(await je`SELECT LAST_INSERT_ID() as id`.execute(m)).rows[0]?.id;if(i)return await m.selectFrom(E).selectAll().where(I({model:y,field:"id"}),"=",i).limit(1).executeTakeFirst()}let a=O[y]?.fields;if(a)for(let[i,b]of Object.entries(a)){if(!b.unique)continue;let _=I({model:y,field:i}),w=s[_];if(w===void 0||w===null)continue;let u=await m.selectFrom(E).selectAll().where(_,"=",w).limit(1).executeTakeFirst();if(u)return u}let h=m.selectFrom(E).selectAll(),N=!1;for(let[i,b]of Object.entries(s)){if(b===void 0)continue;h=h.where(i,b===null?"is":"=",b),N=!0}if(N){let i=await h.limit(2).execute();if(i.length===1)return i[0]}return Ee.warn(`[Kysely Adapter] Unable to safely identify the inserted "${E}" row on MySQL. Enable Better Auth ID generation or use generateId: "serial" for reliable behavior.`),null};return S?f(c):c.transaction().execute(f)}if(t?.type==="mssql")return await x.outputAll("inserted").executeTakeFirst();return await x.returningAll().executeTakeFirst()};function V(s,x,E){if(!E)return{and:null,or:null};let y={and:[],or:[]};return E.forEach((g)=>{let{field:f,value:m,operator:a="eq",connector:h="AND",mode:N="sensitive"}=g,i=m,b=I({model:x,field:f}),_=N==="insensitive"&&(typeof i==="string"||Array.isArray(i)&&i.every((u)=>typeof u==="string")),w=(u)=>{let l=`${s}.${b}`;if(a.toLowerCase()==="in"){if(_){let{lhs:T,values:D}=gr(l,Array.isArray(i)?i:[i]);return u(T,"in",D)}return u(l,"in",Array.isArray(i)?i:[i])}if(a.toLowerCase()==="not_in"){if(_){let{lhs:T,values:D}=_r(l,Array.isArray(i)?i:[i]);return u(T,"not in",D)}return u(l,"not in",Array.isArray(i)?i:[i])}if(a==="contains"){if(_&&typeof i==="string")return It(l,`%${i}%`,t?.type);return u(l,"like",`%${i}%`)}if(a==="starts_with"){if(_&&typeof i==="string")return It(l,`${i}%`,t?.type);return u(l,"like",`${i}%`)}if(a==="ends_with"){if(_&&typeof i==="string")return It(l,`%${i}`,t?.type);return u(l,"like",`%${i}`)}if(a==="eq"){if(i===null)return u(l,"is",null);if(_&&typeof i==="string"){let{lhs:T,value:D}=Tr(l,i);return u(T,"=",D)}return u(l,"=",i)}if(a==="ne"){if(i===null)return u(l,"is not",null);if(_&&typeof i==="string"){let{lhs:T,value:D}=Er(l,i);return u(T,"<>",D)}return u(l,"<>",i)}if(a==="gt")return u(l,">",i);if(a==="gte")return u(l,">=",i);if(a==="lt")return u(l,"<",i);if(a==="lte")return u(l,"<=",i);return u(l,a,i)};if(h==="OR")y.or.push(w);else y.and.push(w)}),{and:y.and.length?y.and:null,or:y.or.length?y.or:null}}function Dt(s,x,E){if(!x||!s.length)return s;let y=new Map;for(let f of s){let m={},a={};for(let[i]of Object.entries(x))a[i]={};for(let[i,b]of Object.entries(f)){let _=String(i),w=!1;for(let{joinModel:u,fieldName:l,joinModelRef:T}of E)if(_===`_joined_${T}_${l}`||_===`_Joined${bt(T)}${bt(l)}`){a[u][I({model:x[u]?.modelKey??u,field:l})]=b,w=!0;break}if(!w)m[i]=b}let h=m.id;if(!h)continue;if(!y.has(h)){let i={...m};for(let[b,_]of Object.entries(x))i[b]=_.relation==="one-to-one"?null:[];y.set(h,i)}let N=y.get(h);for(let[i,b]of Object.entries(x)){let _=b.relation==="one-to-one",w=b.limit??100,u=a[i],l=u&&Object.keys(u).length>0&&Object.values(u).some((T)=>T!==null&&T!==void 0);if(_)N[i]=l?u:null;else{let T=i;if(Array.isArray(N[T])&&l){if(N[T].length>=w)continue;let D=I({model:b.modelKey??i,field:"id"}),qe=u[D];if(qe){if(!N[T].some((Xt)=>Xt[D]===qe)&&N[T].length<w)N[T].push(u)}else if(N[T].length<w)N[T].push(u)}}}}let g=Array.from(y.values());for(let f of g)for(let[m,a]of Object.entries(x))if(a.relation!=="one-to-one"){let h=m;if(Array.isArray(f[h])){let N=a.limit??100;if(f[h].length>N)f[h]=f[h].slice(0,N)}}return g}return{async create({data:s,model:x,modelKey:E=x}){return await vt(s,c.insertInto(x).values(s),x,E,[])},async findOne({model:s,modelKey:x=s,where:E,select:y,join:g}){let{and:f,or:m}=V(s,x,E),a=c.selectFrom((_)=>{let w=_.selectFrom(s);if(f)w=w.where((u)=>u.and(f.map((l)=>l(u))));if(m)w=w.where((u)=>u.or(m.map((l)=>l(u))));if(y?.length&&y.length>0)w=w.select(y.map((u)=>I({model:x,field:u})));else w=w.selectAll();return w.as("primary")}).selectAll("primary");if(g)for(let[_,w]of Object.entries(g)){let[u,l]=_.includes(".")?_.split("."):[void 0,_];a=a.leftJoin(`${_} as join_${l}`,(T)=>T.onRef(`join_${l}.${w.on.to}`,"=",`primary.${w.on.from}`))}let{allSelectsStr:h,allSelects:N}=St(g);a=a.select(N);let i=await a.execute();if(!i||!Array.isArray(i)||i.length===0)return null;let b=i[0];if(g)return Dt(i,g,h)[0];return b},async findMany({model:s,modelKey:x=s,where:E,limit:y,select:g,offset:f,sortBy:m,join:a}){let{and:h,or:N}=V(s,x,E),i=c.selectFrom((u)=>{let l=u.selectFrom(s);if(t?.type==="mssql"){if(f!==void 0){if(!m)l=l.orderBy(I({model:x,field:"id"}));l=l.offset(f).fetch(y||100)}else if(y!==void 0)l=l.top(y)}else{if(y!==void 0)l=l.limit(y);if(f!==void 0)l=l.offset(f)}if(m?.field)l=l.orderBy(`${I({model:x,field:m.field})}`,m.direction);if(h)l=l.where((T)=>T.and(h.map((D)=>D(T))));if(N)l=l.where((T)=>T.or(N.map((D)=>D(T))));if(g?.length&&g.length>0)l=l.select(g.map((T)=>I({model:x,field:T})));else l=l.selectAll();return l.as("primary")}).selectAll("primary");if(a)for(let[u,l]of Object.entries(a)){let[T,D]=u.includes(".")?u.split("."):[void 0,u];i=i.leftJoin(`${u} as join_${D}`,(qe)=>qe.onRef(`join_${D}.${l.on.to}`,"=",`primary.${l.on.from}`))}let{allSelectsStr:b,allSelects:_}=St(a);if(i=i.select(_),m?.field)i=i.orderBy(`${I({model:x,field:m.field})}`,m.direction);let w=await i.execute();if(!w)return[];if(a)return Dt(w,a,b);return w},async update({model:s,modelKey:x=s,where:E,update:y}){if(E.length===0)return null;let{and:g,or:f}=V(s,x,E),m=c.updateTable(s).set(y);if(g)m=m.where((a)=>a.and(g.map((h)=>h(a))));if(f)m=m.where((a)=>a.or(f.map((h)=>h(a))));return await vt(y,m,s,x,E)},async updateMany({model:s,modelKey:x=s,where:E,update:y}){let{and:g,or:f}=V(s,x,E),m=c.updateTable(s).set(y);if(g)m=m.where((h)=>h.and(g.map((N)=>N(h))));if(f)m=m.where((h)=>h.or(f.map((N)=>N(h))));let a=(await m.executeTakeFirst()).numUpdatedRows;return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(a)},async count({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.selectFrom(s).select(c.fn.count("id").as("count"));if(y)f=f.where((a)=>a.and(y.map((h)=>h(a))));if(g)f=f.where((a)=>a.or(g.map((h)=>h(a))));let m=await f.execute();if(typeof m[0].count==="number")return m[0].count;if(typeof m[0].count==="bigint")return Number(m[0].count);return parseInt(m[0].count)},async delete({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.deleteFrom(s);if(y)f=f.where((m)=>m.and(y.map((a)=>a(m))));if(g)f=f.where((m)=>m.or(g.map((a)=>a(m))));await f.execute()},async deleteMany({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.deleteFrom(s);if(y)f=f.where((a)=>a.and(y.map((h)=>h(a))));if(g)f=f.where((a)=>a.or(g.map((h)=>h(a))));let m=(await f.executeTakeFirst()).numDeletedRows;return m>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(m)},async consumeOne({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=(b)=>{if(y)b=b.where((_)=>_.and(y.map((w)=>w(_))));if(g)b=b.where((_)=>_.or(g.map((w)=>w(_))));return b},m=I({model:x,field:"id"}),a=async(b,_)=>{let w=_[m]??_.id;if(w===void 0||w===null)return null;let u=b.deleteFrom(s).where(`${s}.${m}`,"=",w);if(t?.type==="mysql"){let l=await u.executeTakeFirst();return Number(l.numDeletedRows)>0?_:null}if(t?.type==="mssql")return await u.outputAll("deleted").executeTakeFirst()??null;return await u.returningAll().executeTakeFirst()??null},h=async(b)=>{if(t?.type==="mssql")return await b.outputAll("deleted").executeTakeFirst()??null;return await b.returningAll().executeTakeFirst()??null};if(t?.type==="mysql"){let b=async(_)=>{let w=await f(_.selectFrom(s).selectAll().forUpdate()).limit(1).executeTakeFirst();if(!w)return null;return a(_,w)};return S?b(c):c.transaction().execute(b)}let N=f(c.selectFrom(s).select(`${s}.${m}`)),i=t?.type==="mssql"?N.top(1):N.limit(1);return h(f(c.deleteFrom(s).where(`${s}.${m}`,"in",i)))},async incrementOne({model:s,modelKey:x=s,where:E,increment:y,set:g}){let{and:f,or:m}=V(s,x,E),a=(w)=>{if(f)w=w.where((u)=>u.and(f.map((l)=>l(u))));if(m)w=w.where((u)=>u.or(m.map((l)=>l(u))));return w},h={...g??{}};for(let[w,u]of Object.entries(y))h[w]=je`${je.ref(w)} + ${u}`;let N=I({model:x,field:"id"});if(t?.type==="mysql"){let w=async(u)=>{let l=await a(u.selectFrom(s).select(`${s}.${N}`).forUpdate()).limit(1).executeTakeFirst();if(!l)return null;let T=l[N]??l.id;if(T===void 0||T===null)return null;let D=await a(u.updateTable(s).set(h)).where(`${s}.${N}`,"=",T).executeTakeFirst();if(Number(D.numUpdatedRows)===0)return null;return await u.selectFrom(s).selectAll().where(`${s}.${N}`,"=",T).limit(1).executeTakeFirst()??null};return S?w(c):c.transaction().execute(w)}let i=a(c.selectFrom(s).select(`${s}.${N}`)),b=t?.type==="mssql"?i.top(1):i.limit(1),_=a(c.updateTable(s).set(h)).where(`${s}.${N}`,"in",b);if(t?.type==="mssql")return await _.outputAll("inserted").executeTakeFirst()??null;return await _.returningAll().executeTakeFirst()??null},options:t}},p=null;p={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?(c)=>e.transaction().execute((S)=>c(ei({config:{...p.config,transaction:!1},adapter:o(S,!0)})(r))):!1},adapter:o(e)};let d=ei(p);return(c)=>{r=c;let S=d(c);return Zc(S,Uc(()=>Ar(e,t?.type,Fc(c,{usePlural:t?.usePlural})),"database",c.database),{runtimeEnabled:Lc(c)}),S}};
12
- export{wf,Fm,Ef,Lm,dA,Zm,DD};
11
+ `.execute(e.withoutPlugins())).rows[0]?.schemas??[];if(t==="mssql")return[await jm(e),"dbo"]}async function Ar(e,t,r){let n=zm(e,r);if(t==="sqlite")return sa(n,Cf(await hA(e,Object.entries(n).flatMap(([o,p])=>p.disableMigrations?[]:[o]))));return e.connection().execute(async(o)=>{let p=await Ir(o,t),d=Cf(await o.introspection.getTables());for(let[c,S]of Object.entries(n)){if(S.schema!==void 0||!p)continue;S.schema=p.find((I)=>d.some((O)=>O.name===c&&O.schema===I))??""}return sa(n,d)})}var ND=(e,t)=>{let r=null,n=!1,o=(c,S=!1)=>({getFieldName:I,schema:O,getDefaultFieldName:Sr,getDefaultModelName:Yt,getFieldAttributes:vr,getModelName:kr,options:At})=>{if(t?.type==="mysql"&&At.advanced?.database?.generateId===!1&&!n)n=!0,Ee.warn(`[Kysely Adapter] MySQL does not support INSERT...RETURNING. With generateId set to false, the adapter uses best-effort fallback strategies (unique columns, full-field match) to retrieve inserted rows. For reliable behavior, use Better Auth's default ID generation, a custom generateId function, or generateId: "serial" for auto-increment.`);let St=(s)=>{let x=[],E=[];if(s)for(let[y,g]of Object.entries(s)){let f=O[g.modelKey??Yt(y)]?.fields,[m,a]=y.includes(".")?y.split("."):[void 0,y];if(!f)continue;f.id={type:"string"};for(let[h,N]of Object.entries(f))x.push(je`${je.ref(`join_${a}`)}.${je.ref(N.fieldName||h)} as ${je.ref(`_joined_${a}_${N.fieldName||h}`)}`),E.push({joinModel:y,joinModelRef:a,fieldName:N.fieldName||h})}return{allSelectsStr:E,allSelects:x}},vt=async(s,x,E,y,g)=>{if(t?.type==="mysql"){if(g.length>0){let m=await x.executeTakeFirst();if(!m||Number(m.numUpdatedRows??0)===0)return null;let a=g.find((i)=>i.field==="id"&&(i.operator===void 0||i.operator==="eq")&&i.connector!=="OR"&&i.value!==void 0&&i.value!==null),h,N;if(s.id!==void 0&&s.id!==null)h="id",N=s.id;else if(a)h="id",N=a.value;else if(g[0]?.field)h=g[0].field,N=s[h]!==void 0?s[h]:g[0].value;else return null;return await c.selectFrom(E).selectAll().where(I({model:y,field:h}),N===null?"is":"=",N).limit(1).executeTakeFirst()}await x.execute();let f=async(m)=>{if(s.id)return await m.selectFrom(E).selectAll().where(I({model:y,field:"id"}),"=",s.id).limit(1).executeTakeFirst();if(At.advanced?.database?.generateId==="serial"){let i=(await je`SELECT LAST_INSERT_ID() as id`.execute(m)).rows[0]?.id;if(i)return await m.selectFrom(E).selectAll().where(I({model:y,field:"id"}),"=",i).limit(1).executeTakeFirst()}let a=O[y]?.fields;if(a)for(let[i,b]of Object.entries(a)){if(!b.unique)continue;let _=I({model:y,field:i}),w=s[_];if(w===void 0||w===null)continue;let u=await m.selectFrom(E).selectAll().where(_,"=",w).limit(1).executeTakeFirst();if(u)return u}let h=m.selectFrom(E).selectAll(),N=!1;for(let[i,b]of Object.entries(s)){if(b===void 0)continue;h=h.where(i,b===null?"is":"=",b),N=!0}if(N){let i=await h.limit(2).execute();if(i.length===1)return i[0]}return Ee.warn(`[Kysely Adapter] Unable to safely identify the inserted "${E}" row on MySQL. Enable Better Auth ID generation or use generateId: "serial" for reliable behavior.`),null};return S?f(c):c.transaction().execute(f)}if(t?.type==="mssql")return await x.outputAll("inserted").executeTakeFirst();return await x.returningAll().executeTakeFirst()};function V(s,x,E){if(!E)return{and:null,or:null};let y={and:[],or:[]};return E.forEach((g)=>{let{field:f,value:m,operator:a="eq",connector:h="AND",mode:N="sensitive"}=g,i=m,b=I({model:x,field:f}),_=N==="insensitive"&&(typeof i==="string"||Array.isArray(i)&&i.every((u)=>typeof u==="string")),w=(u)=>{let l=`${s}.${b}`;if(a.toLowerCase()==="in"){if(_){let{lhs:T,values:D}=gr(l,Array.isArray(i)?i:[i]);return u(T,"in",D)}return u(l,"in",Array.isArray(i)?i:[i])}if(a.toLowerCase()==="not_in"){if(_){let{lhs:T,values:D}=_r(l,Array.isArray(i)?i:[i]);return u(T,"not in",D)}return u(l,"not in",Array.isArray(i)?i:[i])}if(a==="contains"){if(_&&typeof i==="string")return It(l,`%${i}%`,t?.type);return u(l,"like",`%${i}%`)}if(a==="starts_with"){if(_&&typeof i==="string")return It(l,`${i}%`,t?.type);return u(l,"like",`${i}%`)}if(a==="ends_with"){if(_&&typeof i==="string")return It(l,`%${i}`,t?.type);return u(l,"like",`%${i}`)}if(a==="eq"){if(i===null)return u(l,"is",null);if(_&&typeof i==="string"){let{lhs:T,value:D}=Tr(l,i);return u(T,"=",D)}return u(l,"=",i)}if(a==="ne"){if(i===null)return u(l,"is not",null);if(_&&typeof i==="string"){let{lhs:T,value:D}=Er(l,i);return u(T,"<>",D)}return u(l,"<>",i)}if(a==="gt")return u(l,">",i);if(a==="gte")return u(l,">=",i);if(a==="lt")return u(l,"<",i);if(a==="lte")return u(l,"<=",i);return u(l,a,i)};if(h==="OR")y.or.push(w);else y.and.push(w)}),{and:y.and.length?y.and:null,or:y.or.length?y.or:null}}function Dt(s,x,E){if(!x||!s.length)return s;let y=new Map;for(let f of s){let m={},a={};for(let[i]of Object.entries(x))a[i]={};for(let[i,b]of Object.entries(f)){let _=String(i),w=!1;for(let{joinModel:u,fieldName:l,joinModelRef:T}of E)if(_===`_joined_${T}_${l}`||_===`_Joined${bt(T)}${bt(l)}`){a[u][I({model:x[u]?.modelKey??u,field:l})]=b,w=!0;break}if(!w)m[i]=b}let h=m.id;if(!h)continue;if(!y.has(h)){let i={...m};for(let[b,_]of Object.entries(x))i[b]=_.relation==="one-to-one"?null:[];y.set(h,i)}let N=y.get(h);for(let[i,b]of Object.entries(x)){let _=b.relation==="one-to-one",w=b.limit??100,u=a[i],l=u&&Object.keys(u).length>0&&Object.values(u).some((T)=>T!==null&&T!==void 0);if(_)N[i]=l?u:null;else{let T=i;if(Array.isArray(N[T])&&l){if(N[T].length>=w)continue;let D=I({model:b.modelKey??i,field:"id"}),qe=u[D];if(qe){if(!N[T].some((Xt)=>Xt[D]===qe)&&N[T].length<w)N[T].push(u)}else if(N[T].length<w)N[T].push(u)}}}}let g=Array.from(y.values());for(let f of g)for(let[m,a]of Object.entries(x))if(a.relation!=="one-to-one"){let h=m;if(Array.isArray(f[h])){let N=a.limit??100;if(f[h].length>N)f[h]=f[h].slice(0,N)}}return g}return{async create({data:s,model:x,modelKey:E=x}){return await vt(s,c.insertInto(x).values(s),x,E,[])},async findOne({model:s,modelKey:x=s,where:E,select:y,join:g}){let{and:f,or:m}=V(s,x,E),a=c.selectFrom((_)=>{let w=_.selectFrom(s);if(f)w=w.where((u)=>u.and(f.map((l)=>l(u))));if(m)w=w.where((u)=>u.or(m.map((l)=>l(u))));if(y?.length&&y.length>0)w=w.select(y.map((u)=>I({model:x,field:u})));else w=w.selectAll();return w.as("primary")}).selectAll("primary");if(g)for(let[_,w]of Object.entries(g)){let[u,l]=_.includes(".")?_.split("."):[void 0,_];a=a.leftJoin(`${_} as join_${l}`,(T)=>T.onRef(`join_${l}.${w.on.to}`,"=",`primary.${w.on.from}`))}let{allSelectsStr:h,allSelects:N}=St(g);a=a.select(N);let i=await a.execute();if(!i||!Array.isArray(i)||i.length===0)return null;let b=i[0];if(g)return Dt(i,g,h)[0];return b},async findMany({model:s,modelKey:x=s,where:E,limit:y,select:g,offset:f,sortBy:m,join:a}){let{and:h,or:N}=V(s,x,E),i=c.selectFrom((u)=>{let l=u.selectFrom(s);if(t?.type==="mssql"){if(f!==void 0){if(!m)l=l.orderBy(I({model:x,field:"id"}));l=l.offset(f).fetch(y||100)}else if(y!==void 0)l=l.top(y)}else{if(y!==void 0)l=l.limit(y);if(f!==void 0)l=l.offset(f)}if(m?.field)l=l.orderBy(`${I({model:x,field:m.field})}`,m.direction);if(h)l=l.where((T)=>T.and(h.map((D)=>D(T))));if(N)l=l.where((T)=>T.or(N.map((D)=>D(T))));if(g?.length&&g.length>0)l=l.select(g.map((T)=>I({model:x,field:T})));else l=l.selectAll();return l.as("primary")}).selectAll("primary");if(a)for(let[u,l]of Object.entries(a)){let[T,D]=u.includes(".")?u.split("."):[void 0,u];i=i.leftJoin(`${u} as join_${D}`,(qe)=>qe.onRef(`join_${D}.${l.on.to}`,"=",`primary.${l.on.from}`))}let{allSelectsStr:b,allSelects:_}=St(a);if(i=i.select(_),m?.field)i=i.orderBy(`${I({model:x,field:m.field})}`,m.direction);let w=await i.execute();if(!w)return[];if(a)return Dt(w,a,b);return w},async update({model:s,modelKey:x=s,where:E,update:y}){if(E.length===0)return null;let{and:g,or:f}=V(s,x,E),m=c.updateTable(s).set(y);if(g)m=m.where((a)=>a.and(g.map((h)=>h(a))));if(f)m=m.where((a)=>a.or(f.map((h)=>h(a))));return await vt(y,m,s,x,E)},async updateMany({model:s,modelKey:x=s,where:E,update:y}){let{and:g,or:f}=V(s,x,E),m=c.updateTable(s).set(y);if(g)m=m.where((h)=>h.and(g.map((N)=>N(h))));if(f)m=m.where((h)=>h.or(f.map((N)=>N(h))));let a=(await m.executeTakeFirst()).numUpdatedRows;return a>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(a)},async count({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.selectFrom(s).select(c.fn.count("id").as("count"));if(y)f=f.where((a)=>a.and(y.map((h)=>h(a))));if(g)f=f.where((a)=>a.or(g.map((h)=>h(a))));let m=await f.execute();if(typeof m[0].count==="number")return m[0].count;if(typeof m[0].count==="bigint")return Number(m[0].count);return parseInt(m[0].count)},async delete({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.deleteFrom(s);if(y)f=f.where((m)=>m.and(y.map((a)=>a(m))));if(g)f=f.where((m)=>m.or(g.map((a)=>a(m))));await f.execute()},async deleteMany({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=c.deleteFrom(s);if(y)f=f.where((a)=>a.and(y.map((h)=>h(a))));if(g)f=f.where((a)=>a.or(g.map((h)=>h(a))));let m=(await f.executeTakeFirst()).numDeletedRows;return m>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:Number(m)},async consumeOne({model:s,modelKey:x=s,where:E}){let{and:y,or:g}=V(s,x,E),f=(b)=>{if(y)b=b.where((_)=>_.and(y.map((w)=>w(_))));if(g)b=b.where((_)=>_.or(g.map((w)=>w(_))));return b},m=I({model:x,field:"id"}),a=async(b,_)=>{let w=_[m]??_.id;if(w===void 0||w===null)return null;let u=b.deleteFrom(s).where(`${s}.${m}`,"=",w);if(t?.type==="mysql"){let l=await u.executeTakeFirst();return Number(l.numDeletedRows)>0?_:null}if(t?.type==="mssql")return await u.outputAll("deleted").executeTakeFirst()??null;return await u.returningAll().executeTakeFirst()??null},h=async(b)=>{if(t?.type==="mssql")return await b.outputAll("deleted").executeTakeFirst()??null;return await b.returningAll().executeTakeFirst()??null};if(t?.type==="mysql"){let b=async(_)=>{let w=await f(_.selectFrom(s).selectAll().forUpdate()).limit(1).executeTakeFirst();if(!w)return null;return a(_,w)};return S?b(c):c.transaction().execute(b)}let N=f(c.selectFrom(s).select(`${s}.${m}`)),i=t?.type==="mssql"?N.top(1):N.limit(1);return h(f(c.deleteFrom(s).where(`${s}.${m}`,"in",i)))},async incrementOne({model:s,modelKey:x=s,where:E,increment:y,set:g}){let{and:f,or:m}=V(s,x,E),a=(w)=>{if(f)w=w.where((u)=>u.and(f.map((l)=>l(u))));if(m)w=w.where((u)=>u.or(m.map((l)=>l(u))));return w},h={...g??{}};for(let[w,u]of Object.entries(y))h[w]=je`${je.ref(w)} + ${u}`;let N=I({model:x,field:"id"});if(t?.type==="mysql"){let w=async(u)=>{let l=await a(u.selectFrom(s).select(`${s}.${N}`).forUpdate()).limit(1).executeTakeFirst();if(!l)return null;let T=l[N]??l.id;if(T===void 0||T===null)return null;let D=await a(u.updateTable(s).set(h)).where(`${s}.${N}`,"=",T).executeTakeFirst();if(Number(D.numUpdatedRows)===0)return null;return await u.selectFrom(s).selectAll().where(`${s}.${N}`,"=",T).limit(1).executeTakeFirst()??null};return S?w(c):c.transaction().execute(w)}let i=a(c.selectFrom(s).select(`${s}.${N}`)),b=t?.type==="mssql"?i.top(1):i.limit(1),_=a(c.updateTable(s).set(h)).where(`${s}.${N}`,"in",b);if(t?.type==="mssql")return await _.outputAll("inserted").executeTakeFirst()??null;return await _.returningAll().executeTakeFirst()??null},options:t}},p=null;p={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?(c)=>e.transaction().execute((S)=>c(ei({config:{...p.config,transaction:!1},adapter:o(S,!0)})(r))):!1},adapter:o(e)};let d=ei(p);return(c)=>{r=c;let S=d(c);return Uc(S,jc(()=>Ar(e,t?.type,Zc(c,{usePlural:t?.usePlural})),"database",c.database),{runtimeEnabled:Bc(c)}),S}};
12
+ export{xf,Um,Cf,zm,fA,jm,ND};
@@ -1 +1 @@
1
- import{S,M,w,L,W,a,g,ae,ql,ee,X,We,Je,R,j,vr,V,qe,Re,Ke,U,N,$e,He,Qe,De,Ne,Fe,se,Sv,Iv,kw,Ge,BE,wx,Sx,wh,Dt,rC,nC,dC,JC,ES,xS,wa,cT,W1,Qk,Wk,Jp,Xk,eR,tR,rR,r0,nR,VR,zi,Hd,pu,SO,mu,Qd,Gd,TO,Vd,RO,dP,eD,nD,iD,aD,zg,gu,ct,ut,dt,ft,pt,mt,ht,gt,Se,xe,ke,ot,Ce,Nt,re,er,B,gv,fe,Ve,Br}from"./chunk-akafypge.js";import{Fu}from"./chunk-xd1axsdv.js";import{Tu}from"./chunk-4awk4xhq.js";import{bl}from"./chunk-rjhczkh3.js";import{Ho}from"./chunk-zg0b902x.js";import{Hn}from"./chunk-81b8rfv7.js";import"./chunk-wzrzc07t.js";var Ie=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M11 4h10",key:"1w87gc"}],["path",{d:"M11 8h7",key:"djye34"}],["path",{d:"M11 12h4",key:"q8tih4"}]],Z=j("arrow-down-wide-narrow",Ie);var _e=[["path",{d:"M10 8h4",key:"1sr2af"}],["path",{d:"M12 21v-9",key:"17s77i"}],["path",{d:"M12 8V3",key:"13r4qs"}],["path",{d:"M17 16h4",key:"h1uq16"}],["path",{d:"M19 12V3",key:"o1uvq1"}],["path",{d:"M19 21v-5",key:"qua636"}],["path",{d:"M3 14h4",key:"bcjad9"}],["path",{d:"M5 10V3",key:"cb8scm"}],["path",{d:"M5 21v-7",key:"1w1uti"}]],te=j("sliders-vertical",_e);L();function ne({open:o,onOpenChange:l,mode:c,teamId:f,project:i}){let p=ae(),m=We(),[s,h]=w(""),[k,b]=w(!0),[F,y]=w(void 0),[C,v]=w(void 0),[u,_]=w(!1),x=M(null);S(()=>{if(o)if(c==="edit"&&i)h(i.name||""),y(i.coverImageKey),v(i.coverImage),b(i.enableNotification!==!1);else h(""),y(void 0),v(void 0),b(!0)},[o,c,i]);let P=R.api.teams[":teamId"].projects.$post,{mutate:O}=X({mutationFn:async(n)=>{let r=await P({param:{teamId:f},json:n});if(!r.ok)throw Error(JC());return await r.json()},onSuccess:(n)=>{p.invalidateQueries({queryKey:["teams",f,"projects"]}),l(!1);let r=n;if(r&&typeof r.id==="string")m({to:"/projects/$projectId",params:{projectId:r.id}})}}),A=R.api.projects[":projectId"].$put,{mutate:z}=X({mutationFn:async(n)=>{let r=await A({param:{projectId:i.id},json:n});if(!r.ok)throw Error(ES());return await r.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["teams",f,"projects"]}),l(!1)}}),Q=R.api.teams[":teamId"].files.$post,{mutate:E}=X({mutationFn:async({file:n})=>{let r=await Q({param:{teamId:f},form:{file:n}});if(!r.ok)throw Error(wa());return await r.json()},onSuccess:(n)=>{let r=n;if(r&&typeof r.key==="string")y(r.key);_(!1)},onError:()=>{_(!1)}}),d=(n)=>{let r=n.target.files?.[0];if(r){_(!0);let H=URL.createObjectURL(r);v(H),E({file:r})}},D=()=>{x.current?.click()},T=(n)=>{n.stopPropagation(),y(void 0),v(void 0)},I=()=>{if(!s.trim())return;if(c==="create")O({name:s.trim(),coverImageKey:F,enableNotification:k});else if(c==="edit"&&i?.id)z({name:s.trim(),coverImageKey:F,enableNotification:k})};return a(Se,{open:o,onOpenChange:l,children:g(xe,{className:"sm:max-w-[550px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 backdrop-blur-md shadow-2xl p-0 gap-0",children:[g(ke,{className:"relative overflow-hidden bg-gradient-to-br from-primary/5 to-transparent p-6 border-b border-border/40",children:[a("div",{className:"absolute top-0 right-0 w-24 h-24 bg-primary/10 rounded-full blur-2xl pointer-events-none"}),a("div",{className:"absolute bottom-0 left-10 w-32 h-12 bg-primary/5 rounded-full blur-xl pointer-events-none"}),a("div",{className:"flex items-center gap-3",children:g("div",{children:[a(Ce,{className:"text-xl font-semibold tracking-tight text-foreground",children:c==="create"?Sx():r0()}),a(Nt,{className:"text-xs text-muted-foreground/80 mt-1",children:c==="create"?BE():cT()})]})})]}),g("div",{className:"space-y-6 p-6 max-h-[75vh] overflow-y-auto",children:[g("div",{className:"space-y-2",children:[a(fe,{htmlFor:"name",className:"text-sm font-semibold tracking-tight text-foreground",children:Jp()}),g("div",{className:"relative",children:[a(re,{id:"name",value:s,onChange:(n)=>h(n.target.value),placeholder:eR(),className:"h-11 px-4 rounded-xl border-border/80 focus-visible:ring-ring/25 focus-visible:border-primary transition-all shadow-xs pr-10"}),s.trim()&&a("div",{className:"absolute inset-y-0 right-3 flex items-center",children:a(qe,{className:"w-4 h-4 text-primary"})})]}),a("p",{className:"text-[11px] text-muted-foreground",children:Xk()})]}),g("div",{className:"space-y-3 border-t border-border/40 pt-5",children:[g("div",{className:"flex items-center justify-between",children:[g(fe,{className:"text-sm font-semibold tracking-tight text-foreground flex items-center gap-1.5",children:[a(Hn,{className:"w-4 h-4 text-primary"}),Wk()]}),C&&g("button",{type:"button",onClick:T,className:"text-xs text-muted-foreground hover:text-destructive hover:bg-destructive/5 px-2.5 py-1 rounded-lg transition-all flex items-center gap-1 font-medium",children:[a(Ke,{className:"w-3.5 h-3.5"}),VR()]})]}),g("div",{className:"relative aspect-square w-48 mx-auto rounded-2xl border border-dashed border-border flex items-center justify-center cursor-pointer overflow-hidden group shadow-inner bg-muted/20 transition-all duration-300 hover:border-primary/50 hover:bg-muted/40",onClick:D,children:[a("input",{type:"file",ref:x,className:"hidden",accept:"image/*",onChange:d}),u&&a("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-xs flex flex-col items-center justify-center gap-2 z-20",children:g("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-background border rounded-full shadow-lg",children:[a(V,{className:"w-4 h-4 animate-spin text-primary"}),a("span",{className:"text-xs font-semibold text-foreground",children:gu()})]})}),C?g(W,{children:[a("img",{src:C,alt:wx(),className:"w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"}),g("div",{className:"absolute inset-0 bg-black/45 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-col items-center justify-center gap-1.5 text-white z-10",children:[a(Ho,{className:"w-5 h-5 transform translate-y-1 group-hover:translate-y-0 transition-transform duration-300"}),a("span",{className:"text-xs font-semibold",children:zg()})]})]}):g("div",{className:"flex flex-col items-center gap-2 text-center p-4",children:[a("div",{className:"p-2.5 rounded-full bg-background border shadow-xs group-hover:scale-110 transition-transform duration-300",children:a(Ho,{className:"w-4 h-4 text-muted-foreground"})}),g("div",{children:[a("p",{className:"text-xs font-medium text-foreground",children:iD()}),a("p",{className:"text-[11px] text-muted-foreground mt-0.5 max-w-[140px] mx-auto leading-normal",children:aD()})]})]})]})]}),g("div",{className:"space-y-3 border-t border-border/40 pt-5",children:[g(fe,{className:"text-sm font-semibold tracking-tight text-foreground flex items-center gap-1.5",children:[a(te,{className:"w-4 h-4 text-primary"}),rR()]}),g("div",{className:"flex items-start justify-between rounded-xl border border-border/50 bg-muted/10 p-4 transition-all duration-300 hover:bg-muted/20",children:[g("div",{className:"space-y-1 pr-4",children:[g("div",{className:"text-sm font-semibold flex items-center gap-2 text-foreground",children:[a(bl,{className:"w-4 h-4 text-primary"}),Sv()]}),a("p",{className:"text-xs text-muted-foreground leading-normal",children:Iv()})]}),a(Ve,{checked:k,onCheckedChange:b,disabled:u,className:"mt-0.5"})]})]})]}),g(ot,{className:"flex items-center justify-end gap-3 px-6 py-4 bg-muted/20 border-t border-border/40",children:[a(N,{type:"button",variant:"ghost",onClick:()=>l(!1),disabled:u,className:"rounded-xl h-10 px-4 hover:bg-muted font-medium text-sm text-muted-foreground hover:text-foreground transition-colors",children:Ge()}),a(N,{type:"submit",onClick:I,disabled:!s.trim()||u,className:"rounded-xl h-10 px-5 bg-primary text-primary-foreground hover:bg-primary/90 font-semibold text-sm shadow-lg shadow-primary/10 hover:shadow-primary/20 active:scale-98 transition-all flex items-center gap-2",children:u?g(W,{children:[a(V,{className:"w-4 h-4 animate-spin"}),Qk()]}):c==="create"?wh():zi()})]})]})})}function ie({sortBy:o,sortDirection:l,onSortChange:c}){let f=(s)=>{c(s,l)},i=()=>{c(o,l==="asc"?"desc":"asc")},p=(s)=>{switch(s){case"name":return mu();case"created_at":return SO();case"updated_at":return TO();default:return s}},m=l==="asc";return g(De,{children:[a(Ne,{asChild:!0,children:g(N,{variant:"outline",className:"gap-2 bg-muted/50",children:[a("span",{className:"text-muted-foreground",children:RO()}),a("span",{className:"font-medium text-foreground",children:p(o)})]})}),g(Fe,{align:"end",className:"w-56 p-2",children:[a("div",{className:"text-xs font-semibold text-muted-foreground mb-2 px-2",children:pu()}),g(De,{children:[a(Ne,{asChild:!0,children:g(N,{variant:"ghost",className:"w-full justify-between font-normal px-2 h-10 bg-muted/50 hover:bg-muted mb-2 border",children:[a("span",{children:p(o)}),a(Z,{className:"h-4 w-4 opacity-50"})]})}),a(Fe,{className:"w-52",children:["name","created_at","updated_at"].map((s)=>g(se,{onClick:()=>f(s),className:"justify-between",children:[p(s),o===s&&a(qe,{className:"h-4 w-4"})]},s))})]}),g(N,{variant:"ghost",className:"w-full justify-between font-normal px-2 h-10 bg-muted/50 hover:bg-muted border",onClick:i,children:[a("span",{className:"text-muted-foreground",children:o==="name"?m?a(W,{children:Hd()}):a(W,{children:Vd()}):m?a(W,{children:Gd()}):a(W,{children:Qd()})}),m?a(Tu,{className:"h-4 w-4 opacity-50"}):a(Z,{className:"h-4 w-4 opacity-50"})]})]})]})}L();function Me(){let{teamId:o}=Pe.useParams(),{canEdit:l,canAdmin:c}=er(),f=We(),i=ae(),[p,m]=w(null),[s,h]=w(!1),[k,b]=w("create"),[F,y]=w(void 0),[C,v]=w(!1),[u,_]=w(void 0),[x,P]=w(""),[O,A]=w(!1),{metadata:z,setMetadata:Q}=Br(),E=`team:${o}:projects:sort`,d=z[E],[D,T]=w(()=>d?.sortBy||"name"),[I,n]=w(()=>d?.sortDirection||"asc");S(()=>{if(d?.sortBy&&d.sortBy!==D)T(d.sortBy);if(d?.sortDirection&&d.sortDirection!==I)n(d.sortDirection)},[d]);let r=R.api.teams[":teamId"].projects.$get,{data:H}=ee({queryKey:["teams",o,"projects",D,I],queryFn:async()=>{let e=await r({param:{teamId:o},query:{sortBy:D,sortDirection:I}});if(!e.ok)throw Error("Failed to fetch projects");return await e.json()},placeholderData:ql}),{data:Y}=ee({queryKey:["teams",o,"members"],queryFn:async()=>{let e=await R.api.teams[":teamId"].members.$get({param:{teamId:o},query:{}});if(!e.ok)throw Error("Failed to fetch members");return await e.json()}}),{data:G}=ee({queryKey:["teams",o,"me"],queryFn:async()=>{let e=await R.api.teams[":teamId"].me.$get({param:{teamId:o}});if(!e.ok)throw Error("Failed to fetch me");return await e.json()}}),le=R.api.teams[":teamId"].invite.$post,ce=X({mutationFn:async(e)=>{let t=await le(e);if(!t.ok)throw Error("Failed to invite");return await t.json()}}),q=X({mutationFn:async(e)=>{if(!(await R.api.projects[":projectId"].$delete({param:{projectId:e}})).ok)throw Error("Failed to delete project")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"projects"]})}}),de=X({mutationFn:async(e)=>{let t=await R.api.projects[":projectId"].$put({param:{projectId:e.id},json:{enableNotification:!e.enableNotification}});if(!t.ok)throw Error("Failed to update project notification settings");return await t.json()},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"projects"]}),B.success(tR())},onError:(e)=>{B.error(e instanceof Error?e.message:xS())}}),J=()=>{b("create"),y(void 0),h(!0)},me=()=>{m("create"),setTimeout(()=>{m(null)},100),setTimeout(()=>{J()},200)},pe=(e)=>{b("edit"),y(e),h(!0)},ue=(e)=>{_(e),P(""),v(!0)},ge=async()=>{if(u&&x==="delete")try{await q.mutateAsync(u.id),v(!1)}catch(e){console.error(e)}},ve=(e,t)=>{if(t.detail>1)return;m(e),setTimeout(()=>{m(null)},100),setTimeout(()=>{f({to:"/projects/$projectId",params:{projectId:e}})},200)},he=async(e)=>(await ce.mutateAsync({param:{teamId:o},json:{role:e}})).code,ye=X({mutationFn:async({userId:e,role:t})=>{if(!(await R.api.teams[":teamId"].members[":userId"].$patch({param:{teamId:o,userId:e},json:{role:t}})).ok)throw Error("Failed to update member role")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"members"]})}}),be=X({mutationFn:async(e)=>{if(!(await R.api.teams[":teamId"].members[":userId"].$delete({param:{teamId:o,userId:e}})).ok)throw Error("Failed to remove member")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"members"]})}}),we=(e)=>{if(!e)return"??";return e.split(" ").map((t)=>t[0]).slice(0,2).join("").toUpperCase()},je=(e,t)=>{T(e),n(t),Q(o,E,{sortBy:e,sortDirection:t})},K=Array.isArray(Y)?Y:[];return g("div",{className:"flex-1 overflow-y-auto p-4",children:[g("div",{className:"flex flex-wrap items-center justify-between mb-4 gap-4",children:[a("h1",{className:"text-2xl font-bold",children:nR()}),g("div",{className:"flex flex-wrap items-center gap-4",children:[g("div",{className:"flex items-center -space-x-2 cursor-pointer hover:opacity-90",onClick:()=>A(!0),"data-testid":"team-members-trigger",children:[K.slice(0,3).map((e)=>g($e,{className:"border-2 border-background w-8 h-8",children:[e.image&&a(He,{src:e.image,alt:e.name,className:"object-cover"}),a(Qe,{className:"text-[10px]",children:we(e.name)})]},e.id)),K.length>3&&g("div",{className:"flex items-center justify-center w-8 h-8 rounded-full border-2 border-background bg-muted text-[10px] font-medium",children:["+",K.length-3]})]}),a(ie,{sortBy:D,sortDirection:I,onSortChange:je}),l&&g(N,{className:"bg-orange-600 hover:bg-orange-700 text-white gap-2",onClick:J,children:[a(Re,{className:"w-4 h-4"}),wh()]})]})]}),g("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4",children:[H?.data?.map((e)=>a("div",{className:U("shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out",p===e.id?"scale-95":"scale-100"),onClick:(t)=>ve(e.id,t),children:g("div",{className:"flex flex-col",children:[g("div",{className:"relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20",children:[e.coverImage?a("img",{src:e.coverImage,alt:e.name,className:"w-full h-full object-cover rounded"}):g("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 180.95 164.7",preserveAspectRatio:"xMidYMid slice",className:"w-full h-full object-cover rounded",children:[a("polygon",{fill:"#FC9F8E",points:"0 18.5 0 76.0 151.69 164.7 180.95 164.7 180.95 113.6"}),a("polygon",{fill:"#FEBAB8",points:"0 0 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0"}),a("polyline",{fill:"#FAA5A5",points:"0 18.5 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0 0 0"}),a("polygon",{fill:"#EC5B6C",points:"0 76.0 0 164.7 151.69 164.7"}),a("polygon",{fill:"#E85C71",points:"180.95 18.9 110.33 63.9 117.37 68.0 117.26 73.4 180.95 113.6"}),a("polygon",{fill:"#C8405B",points:"117.26 73.4 117.37 99.0 90.53 114.9 174.35 164.7 180.95 164.7 180.95 113.6"}),a("polygon",{fill:"#FFCCBE",points:"90.53 51.6 63.69 68.1 90.53 83.4"}),a("path",{fill:"#FB9991",d:"M 90.53 51.6 L 90.53 61.3 L 100.87 67.4 L 90.53 73.5 L 90.53 83.4 L 117.37 68.0 C 117.15 67.6 90.53 51.6 90.53 51.6 Z"}),a("path",{fill:"#FFEACD",d:"M 63.69 68.1 C 63.47 68.5 64.02 99.3 64.02 99.3 C 64.02 99.3 64.46 99.6 64.9 99.9 L 90.53 83.4 L 63.69 68.1 Z"}),a("polygon",{fill:"#FFCFB5",points:"64.02 99.3 90.53 114.9 90.53 83.4"}),a("path",{fill:"#F67D73",d:"M 90.53 83.4 L 90.53 114.9 L 117.37 99.0 Z"}),a("path",{fill:"#F26560",d:"M 90.53 83.4 L 117.37 99.0 L 117.37 68.0 Z"}),a("polygon",{fill:"#EB5F5B",points:"80.08 67.5 90.53 73.5 90.53 61.3"}),a("polygon",{fill:"#DB4D50",points:"90.53 61.3 90.53 73.5 100.87 67.4"})]}),a("div",{className:"absolute bottom-0 left-0 w-full h-[65%] bg-linear-to-t from-black/35 to-black/0"}),a("p",{className:"absolute left-1 bottom-2 text-white",children:e.name})]}),g("div",{className:"px-2 h-10 flex justify-between items-center",children:[g("p",{className:"truncate pr-1 text-xs text-muted-foreground",children:[nD()," ",gv(e.updatedAt??"")]}),a("div",{onClick:(t)=>t.stopPropagation(),children:g(De,{modal:!1,children:[a(Ne,{asChild:!0,children:a("button",{className:"hover:bg-muted outline-none flex px-1",children:a(vr,{className:"w-5 h-5 text-muted-foreground"})})}),g(Fe,{align:"end",children:[l&&a(se,{onClick:(t)=>{t.stopPropagation(),pe(e)},children:r0()}),g(se,{className:"flex items-center justify-between gap-4 cursor-pointer",onSelect:(t)=>{t.preventDefault(),de.mutate(e)},children:[a("span",{children:W1()}),a(Ve,{checked:e.enableNotification??!0,className:"pointer-events-none"})]}),c&&a(se,{className:"text-destructive focus:text-destructive",onClick:()=>ue(e),children:Dt()})]})]})})]})]})},e.id)),l&&a("div",{className:U("shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group",p==="create"?"scale-95":"scale-100"),onClick:me,children:g("div",{className:"flex flex-col",children:[a("div",{className:"relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors",children:a(Re,{className:"w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors"})}),a("div",{className:"px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors",children:a("p",{className:"text-sm text-muted-foreground group-hover:text-orange-600 transition-colors",children:wh()})})]})})]}),a(ne,{open:s,onOpenChange:h,mode:k,teamId:o,project:F}),a(ct,{open:C,onOpenChange:v,children:g(ut,{children:[g(dt,{children:[a(pt,{children:kw()}),g(mt,{children:[nC({name:u?.name??""}),g("div",{className:"mt-4 flex flex-col gap-2 text-foreground",children:[a("span",{className:"text-sm font-medium",children:eD()}),a(re,{value:x,onChange:(e)=>P(e.target.value),placeholder:rC(),className:"h-9",autoFocus:!0})]})]})]}),g(ft,{children:[a(gt,{disabled:q.isPending,children:Ge()}),a(ht,{onClick:(e)=>{e.preventDefault(),ge()},disabled:x!=="delete"||q.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:q.isPending?dC():Dt()})]})]})}),a(Fu,{open:O,onOpenChange:A,title:dP(),type:"team",members:K,isOwner:G?.role==="owner",onInvite:he,onUpdateRole:async(e,t)=>{await ye.mutateAsync({userId:e,role:t})},onRemoveMember:async(e)=>{await be.mutateAsync(e)},currentUserId:G?.id})]})}var Pe=Je("/teams/$teamId/")({component:Me});export{Pe as Route};
1
+ import{S,M,w,L,W,a,g,ae,$l,ee,X,We,Je,R,j,vr,V,qe,ke,Ke,U,N,$e,He,Qe,De,Ne,Fe,oe,Iv,Tv,Rw,Ge,UE,Ex,Ix,Ch,Dt,nC,oC,fC,YC,xS,CS,wa,uT,J1,Gk,Jk,Xp,eR,tR,rR,nR,n0,oR,KR,zi,Vd,hu,IO,gu,Kd,Wd,kO,Jd,MO,fP,tD,oD,aD,lD,jg,_u,ct,ut,dt,ft,pt,mt,ht,gt,Se,xe,Re,ot,Ce,Nt,re,er,B,Av,fe,Ve,Br}from"./chunk-67p46cwk.js";import{Bu}from"./chunk-zkq96hyx.js";import{Ru}from"./chunk-kj7ntaz0.js";import{wl}from"./chunk-a3dtyc64.js";import{Ho}from"./chunk-7tdq7apk.js";import{Qn}from"./chunk-xak0x4rg.js";import"./chunk-b119q3jq.js";var Ie=[["path",{d:"m3 16 4 4 4-4",key:"1co6wj"}],["path",{d:"M7 20V4",key:"1yoxec"}],["path",{d:"M11 4h10",key:"1w87gc"}],["path",{d:"M11 8h7",key:"djye34"}],["path",{d:"M11 12h4",key:"q8tih4"}]],Z=j("arrow-down-wide-narrow",Ie);var _e=[["path",{d:"M10 8h4",key:"1sr2af"}],["path",{d:"M12 21v-9",key:"17s77i"}],["path",{d:"M12 8V3",key:"13r4qs"}],["path",{d:"M17 16h4",key:"h1uq16"}],["path",{d:"M19 12V3",key:"o1uvq1"}],["path",{d:"M19 21v-5",key:"qua636"}],["path",{d:"M3 14h4",key:"bcjad9"}],["path",{d:"M5 10V3",key:"cb8scm"}],["path",{d:"M5 21v-7",key:"1w1uti"}]],te=j("sliders-vertical",_e);L();function ne({open:o,onOpenChange:l,mode:c,teamId:f,project:i}){let p=ae(),m=We(),[s,h]=w(""),[k,b]=w(!0),[F,y]=w(void 0),[C,v]=w(void 0),[u,_]=w(!1),x=M(null);S(()=>{if(o)if(c==="edit"&&i)h(i.name||""),y(i.coverImageKey),v(i.coverImage),b(i.enableNotification!==!1);else h(""),y(void 0),v(void 0),b(!0)},[o,c,i]);let P=R.api.teams[":teamId"].projects.$post,{mutate:O}=X({mutationFn:async(n)=>{let r=await P({param:{teamId:f},json:n});if(!r.ok)throw Error(YC());return await r.json()},onSuccess:(n)=>{p.invalidateQueries({queryKey:["teams",f,"projects"]}),l(!1);let r=n;if(r&&typeof r.id==="string")m({to:"/projects/$projectId",params:{projectId:r.id}})}}),A=R.api.projects[":projectId"].$put,{mutate:z}=X({mutationFn:async(n)=>{let r=await A({param:{projectId:i.id},json:n});if(!r.ok)throw Error(xS());return await r.json()},onSuccess:()=>{p.invalidateQueries({queryKey:["teams",f,"projects"]}),l(!1)}}),Q=R.api.teams[":teamId"].files.$post,{mutate:E}=X({mutationFn:async({file:n})=>{let r=await Q({param:{teamId:f},form:{file:n}});if(!r.ok)throw Error(wa());return await r.json()},onSuccess:(n)=>{let r=n;if(r&&typeof r.key==="string")y(r.key);_(!1)},onError:()=>{_(!1)}}),d=(n)=>{let r=n.target.files?.[0];if(r){_(!0);let H=URL.createObjectURL(r);v(H),E({file:r})}},D=()=>{x.current?.click()},T=(n)=>{n.stopPropagation(),y(void 0),v(void 0)},I=()=>{if(!s.trim())return;if(c==="create")O({name:s.trim(),coverImageKey:F,enableNotification:k});else if(c==="edit"&&i?.id)z({name:s.trim(),coverImageKey:F,enableNotification:k})};return a(Se,{open:o,onOpenChange:l,children:g(xe,{className:"sm:max-w-[550px] overflow-hidden rounded-2xl border border-border/60 bg-background/95 backdrop-blur-md shadow-2xl p-0 gap-0",children:[g(Re,{className:"relative overflow-hidden bg-gradient-to-br from-primary/5 to-transparent p-6 border-b border-border/40",children:[a("div",{className:"absolute top-0 right-0 w-24 h-24 bg-primary/10 rounded-full blur-2xl pointer-events-none"}),a("div",{className:"absolute bottom-0 left-10 w-32 h-12 bg-primary/5 rounded-full blur-xl pointer-events-none"}),a("div",{className:"flex items-center gap-3",children:g("div",{children:[a(Ce,{className:"text-xl font-semibold tracking-tight text-foreground",children:c==="create"?Ix():n0()}),a(Nt,{className:"text-xs text-muted-foreground/80 mt-1",children:c==="create"?UE():uT()})]})})]}),g("div",{className:"space-y-6 p-6 max-h-[75vh] overflow-y-auto",children:[g("div",{className:"space-y-2",children:[a(fe,{htmlFor:"name",className:"text-sm font-semibold tracking-tight text-foreground",children:Xp()}),g("div",{className:"relative",children:[a(re,{id:"name",value:s,onChange:(n)=>h(n.target.value),placeholder:tR(),className:"h-11 px-4 rounded-xl border-border/80 focus-visible:ring-ring/25 focus-visible:border-primary transition-all shadow-xs pr-10"}),s.trim()&&a("div",{className:"absolute inset-y-0 right-3 flex items-center",children:a(qe,{className:"w-4 h-4 text-primary"})})]}),a("p",{className:"text-[11px] text-muted-foreground",children:eR()})]}),g("div",{className:"space-y-3 border-t border-border/40 pt-5",children:[g("div",{className:"flex items-center justify-between",children:[g(fe,{className:"text-sm font-semibold tracking-tight text-foreground flex items-center gap-1.5",children:[a(Qn,{className:"w-4 h-4 text-primary"}),Jk()]}),C&&g("button",{type:"button",onClick:T,className:"text-xs text-muted-foreground hover:text-destructive hover:bg-destructive/5 px-2.5 py-1 rounded-lg transition-all flex items-center gap-1 font-medium",children:[a(Ke,{className:"w-3.5 h-3.5"}),KR()]})]}),g("div",{className:"relative aspect-square w-48 mx-auto rounded-2xl border border-dashed border-border flex items-center justify-center cursor-pointer overflow-hidden group shadow-inner bg-muted/20 transition-all duration-300 hover:border-primary/50 hover:bg-muted/40",onClick:D,children:[a("input",{type:"file",ref:x,className:"hidden",accept:"image/*",onChange:d}),u&&a("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-xs flex flex-col items-center justify-center gap-2 z-20",children:g("div",{className:"flex items-center gap-2 px-3 py-1.5 bg-background border rounded-full shadow-lg",children:[a(V,{className:"w-4 h-4 animate-spin text-primary"}),a("span",{className:"text-xs font-semibold text-foreground",children:_u()})]})}),C?g(W,{children:[a("img",{src:C,alt:Ex(),className:"w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"}),g("div",{className:"absolute inset-0 bg-black/45 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex flex-col items-center justify-center gap-1.5 text-white z-10",children:[a(Ho,{className:"w-5 h-5 transform translate-y-1 group-hover:translate-y-0 transition-transform duration-300"}),a("span",{className:"text-xs font-semibold",children:jg()})]})]}):g("div",{className:"flex flex-col items-center gap-2 text-center p-4",children:[a("div",{className:"p-2.5 rounded-full bg-background border shadow-xs group-hover:scale-110 transition-transform duration-300",children:a(Ho,{className:"w-4 h-4 text-muted-foreground"})}),g("div",{children:[a("p",{className:"text-xs font-medium text-foreground",children:aD()}),a("p",{className:"text-[11px] text-muted-foreground mt-0.5 max-w-[140px] mx-auto leading-normal",children:lD()})]})]})]})]}),g("div",{className:"space-y-3 border-t border-border/40 pt-5",children:[g(fe,{className:"text-sm font-semibold tracking-tight text-foreground flex items-center gap-1.5",children:[a(te,{className:"w-4 h-4 text-primary"}),nR()]}),g("div",{className:"flex items-start justify-between rounded-xl border border-border/50 bg-muted/10 p-4 transition-all duration-300 hover:bg-muted/20",children:[g("div",{className:"space-y-1 pr-4",children:[g("div",{className:"text-sm font-semibold flex items-center gap-2 text-foreground",children:[a(wl,{className:"w-4 h-4 text-primary"}),Iv()]}),a("p",{className:"text-xs text-muted-foreground leading-normal",children:Tv()})]}),a(Ve,{checked:k,onCheckedChange:b,disabled:u,className:"mt-0.5"})]})]})]}),g(ot,{className:"flex items-center justify-end gap-3 px-6 py-4 bg-muted/20 border-t border-border/40",children:[a(N,{type:"button",variant:"ghost",onClick:()=>l(!1),disabled:u,className:"rounded-xl h-10 px-4 hover:bg-muted font-medium text-sm text-muted-foreground hover:text-foreground transition-colors",children:Ge()}),a(N,{type:"submit",onClick:I,disabled:!s.trim()||u,className:"rounded-xl h-10 px-5 bg-primary text-primary-foreground hover:bg-primary/90 font-semibold text-sm shadow-lg shadow-primary/10 hover:shadow-primary/20 active:scale-98 transition-all flex items-center gap-2",children:u?g(W,{children:[a(V,{className:"w-4 h-4 animate-spin"}),Gk()]}):c==="create"?Ch():zi()})]})]})})}function ie({sortBy:o,sortDirection:l,onSortChange:c}){let f=(s)=>{c(s,l)},i=()=>{c(o,l==="asc"?"desc":"asc")},p=(s)=>{switch(s){case"name":return gu();case"created_at":return IO();case"updated_at":return kO();default:return s}},m=l==="asc";return g(De,{children:[a(Ne,{asChild:!0,children:g(N,{variant:"outline",className:"gap-2 bg-muted/50",children:[a("span",{className:"text-muted-foreground",children:MO()}),a("span",{className:"font-medium text-foreground",children:p(o)})]})}),g(Fe,{align:"end",className:"w-56 p-2",children:[a("div",{className:"text-xs font-semibold text-muted-foreground mb-2 px-2",children:hu()}),g(De,{children:[a(Ne,{asChild:!0,children:g(N,{variant:"ghost",className:"w-full justify-between font-normal px-2 h-10 bg-muted/50 hover:bg-muted mb-2 border",children:[a("span",{children:p(o)}),a(Z,{className:"h-4 w-4 opacity-50"})]})}),a(Fe,{className:"w-52",children:["name","created_at","updated_at"].map((s)=>g(oe,{onClick:()=>f(s),className:"justify-between",children:[p(s),o===s&&a(qe,{className:"h-4 w-4"})]},s))})]}),g(N,{variant:"ghost",className:"w-full justify-between font-normal px-2 h-10 bg-muted/50 hover:bg-muted border",onClick:i,children:[a("span",{className:"text-muted-foreground",children:o==="name"?m?a(W,{children:Vd()}):a(W,{children:Jd()}):m?a(W,{children:Wd()}):a(W,{children:Kd()})}),m?a(Ru,{className:"h-4 w-4 opacity-50"}):a(Z,{className:"h-4 w-4 opacity-50"})]})]})]})}L();function Me(){let{teamId:o}=Pe.useParams(),{canEdit:l,canAdmin:c}=er(),f=We(),i=ae(),[p,m]=w(null),[s,h]=w(!1),[k,b]=w("create"),[F,y]=w(void 0),[C,v]=w(!1),[u,_]=w(void 0),[x,P]=w(""),[O,A]=w(!1),{metadata:z,setMetadata:Q}=Br(),E=`team:${o}:projects:sort`,d=z[E],[D,T]=w(()=>d?.sortBy||"name"),[I,n]=w(()=>d?.sortDirection||"asc");S(()=>{if(d?.sortBy&&d.sortBy!==D)T(d.sortBy);if(d?.sortDirection&&d.sortDirection!==I)n(d.sortDirection)},[d]);let r=R.api.teams[":teamId"].projects.$get,{data:H}=ee({queryKey:["teams",o,"projects",D,I],queryFn:async()=>{let e=await r({param:{teamId:o},query:{sortBy:D,sortDirection:I}});if(!e.ok)throw Error("Failed to fetch projects");return await e.json()},placeholderData:$l}),{data:Y}=ee({queryKey:["teams",o,"members"],queryFn:async()=>{let e=await R.api.teams[":teamId"].members.$get({param:{teamId:o},query:{}});if(!e.ok)throw Error("Failed to fetch members");return await e.json()}}),{data:G}=ee({queryKey:["teams",o,"me"],queryFn:async()=>{let e=await R.api.teams[":teamId"].me.$get({param:{teamId:o}});if(!e.ok)throw Error("Failed to fetch me");return await e.json()}}),le=R.api.teams[":teamId"].invite.$post,ce=X({mutationFn:async(e)=>{let t=await le(e);if(!t.ok)throw Error("Failed to invite");return await t.json()}}),q=X({mutationFn:async(e)=>{if(!(await R.api.projects[":projectId"].$delete({param:{projectId:e}})).ok)throw Error("Failed to delete project")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"projects"]})}}),de=X({mutationFn:async(e)=>{let t=await R.api.projects[":projectId"].$put({param:{projectId:e.id},json:{enableNotification:!e.enableNotification}});if(!t.ok)throw Error("Failed to update project notification settings");return await t.json()},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"projects"]}),B.success(rR())},onError:(e)=>{B.error(e instanceof Error?e.message:CS())}}),J=()=>{b("create"),y(void 0),h(!0)},me=()=>{m("create"),setTimeout(()=>{m(null)},100),setTimeout(()=>{J()},200)},pe=(e)=>{b("edit"),y(e),h(!0)},ue=(e)=>{_(e),P(""),v(!0)},ge=async()=>{if(u&&x==="delete")try{await q.mutateAsync(u.id),v(!1)}catch(e){console.error(e)}},ve=(e,t)=>{if(t.detail>1)return;m(e),setTimeout(()=>{m(null)},100),setTimeout(()=>{f({to:"/projects/$projectId",params:{projectId:e}})},200)},he=async(e)=>(await ce.mutateAsync({param:{teamId:o},json:{role:e}})).code,ye=X({mutationFn:async({userId:e,role:t})=>{if(!(await R.api.teams[":teamId"].members[":userId"].$patch({param:{teamId:o,userId:e},json:{role:t}})).ok)throw Error("Failed to update member role")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"members"]})}}),be=X({mutationFn:async(e)=>{if(!(await R.api.teams[":teamId"].members[":userId"].$delete({param:{teamId:o,userId:e}})).ok)throw Error("Failed to remove member")},onSuccess:()=>{i.invalidateQueries({queryKey:["teams",o,"members"]})}}),we=(e)=>{if(!e)return"??";return e.split(" ").map((t)=>t[0]).slice(0,2).join("").toUpperCase()},je=(e,t)=>{T(e),n(t),Q(o,E,{sortBy:e,sortDirection:t})},K=Array.isArray(Y)?Y:[];return g("div",{className:"flex-1 overflow-y-auto p-4",children:[g("div",{className:"flex flex-wrap items-center justify-between mb-4 gap-4",children:[a("h1",{className:"text-2xl font-bold",children:oR()}),g("div",{className:"flex flex-wrap items-center gap-4",children:[g("div",{className:"flex items-center -space-x-2 cursor-pointer hover:opacity-90",onClick:()=>A(!0),"data-testid":"team-members-trigger",children:[K.slice(0,3).map((e)=>g($e,{className:"border-2 border-background w-8 h-8",children:[e.image&&a(He,{src:e.image,alt:e.name,className:"object-cover"}),a(Qe,{className:"text-[10px]",children:we(e.name)})]},e.id)),K.length>3&&g("div",{className:"flex items-center justify-center w-8 h-8 rounded-full border-2 border-background bg-muted text-[10px] font-medium",children:["+",K.length-3]})]}),a(ie,{sortBy:D,sortDirection:I,onSortChange:je}),l&&g(N,{className:"bg-orange-600 hover:bg-orange-700 text-white gap-2",onClick:J,children:[a(ke,{className:"w-4 h-4"}),Ch()]})]})]}),g("div",{className:"grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4",children:[H?.data?.map((e)=>a("div",{className:U("shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out",p===e.id?"scale-95":"scale-100"),onClick:(t)=>ve(e.id,t),children:g("div",{className:"flex flex-col",children:[g("div",{className:"relative w-full h-full aspect-square flex items-center justify-center bg-zinc-400/20",children:[e.coverImage?a("img",{src:e.coverImage,alt:e.name,className:"w-full h-full object-cover rounded"}):g("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 180.95 164.7",preserveAspectRatio:"xMidYMid slice",className:"w-full h-full object-cover rounded",children:[a("polygon",{fill:"#FC9F8E",points:"0 18.5 0 76.0 151.69 164.7 180.95 164.7 180.95 113.6"}),a("polygon",{fill:"#FEBAB8",points:"0 0 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0"}),a("polyline",{fill:"#FAA5A5",points:"0 18.5 74.58 61.5 90.53 51.6 110.33 63.9 180.95 18.9 180.95 0 0 0"}),a("polygon",{fill:"#EC5B6C",points:"0 76.0 0 164.7 151.69 164.7"}),a("polygon",{fill:"#E85C71",points:"180.95 18.9 110.33 63.9 117.37 68.0 117.26 73.4 180.95 113.6"}),a("polygon",{fill:"#C8405B",points:"117.26 73.4 117.37 99.0 90.53 114.9 174.35 164.7 180.95 164.7 180.95 113.6"}),a("polygon",{fill:"#FFCCBE",points:"90.53 51.6 63.69 68.1 90.53 83.4"}),a("path",{fill:"#FB9991",d:"M 90.53 51.6 L 90.53 61.3 L 100.87 67.4 L 90.53 73.5 L 90.53 83.4 L 117.37 68.0 C 117.15 67.6 90.53 51.6 90.53 51.6 Z"}),a("path",{fill:"#FFEACD",d:"M 63.69 68.1 C 63.47 68.5 64.02 99.3 64.02 99.3 C 64.02 99.3 64.46 99.6 64.9 99.9 L 90.53 83.4 L 63.69 68.1 Z"}),a("polygon",{fill:"#FFCFB5",points:"64.02 99.3 90.53 114.9 90.53 83.4"}),a("path",{fill:"#F67D73",d:"M 90.53 83.4 L 90.53 114.9 L 117.37 99.0 Z"}),a("path",{fill:"#F26560",d:"M 90.53 83.4 L 117.37 99.0 L 117.37 68.0 Z"}),a("polygon",{fill:"#EB5F5B",points:"80.08 67.5 90.53 73.5 90.53 61.3"}),a("polygon",{fill:"#DB4D50",points:"90.53 61.3 90.53 73.5 100.87 67.4"})]}),a("div",{className:"absolute bottom-0 left-0 w-full h-[65%] bg-linear-to-t from-black/35 to-black/0"}),a("p",{className:"absolute left-1 bottom-2 text-white",children:e.name})]}),g("div",{className:"px-2 h-10 flex justify-between items-center",children:[g("p",{className:"truncate pr-1 text-xs text-muted-foreground",children:[oD()," ",Av(e.updatedAt??"")]}),a("div",{onClick:(t)=>t.stopPropagation(),children:g(De,{modal:!1,children:[a(Ne,{asChild:!0,children:a("button",{className:"hover:bg-muted outline-none flex px-1",children:a(vr,{className:"w-5 h-5 text-muted-foreground"})})}),g(Fe,{align:"end",children:[l&&a(oe,{onClick:(t)=>{t.stopPropagation(),pe(e)},children:n0()}),g(oe,{className:"flex items-center justify-between gap-4 cursor-pointer",onSelect:(t)=>{t.preventDefault(),de.mutate(e)},children:[a("span",{children:J1()}),a(Ve,{checked:e.enableNotification??!0,className:"pointer-events-none"})]}),c&&a(oe,{className:"text-destructive focus:text-destructive",onClick:()=>ue(e),children:Dt()})]})]})})]})]})},e.id)),l&&a("div",{className:U("shadow-md relative border rounded-xl overflow-hidden cursor-pointer transition-transform duration-100 ease-in-out border-dashed hover:border-orange-600/50 group",p==="create"?"scale-95":"scale-100"),onClick:me,children:g("div",{className:"flex flex-col",children:[a("div",{className:"relative w-full aspect-square flex items-center justify-center bg-zinc-400/5 group-hover:bg-orange-600/5 transition-colors",children:a(ke,{className:"w-8 h-8 text-zinc-400 group-hover:text-orange-600 transition-colors"})}),a("div",{className:"px-2 h-10 flex items-center justify-center bg-zinc-400/10 border-t group-hover:bg-orange-600/10 transition-colors",children:a("p",{className:"text-sm text-muted-foreground group-hover:text-orange-600 transition-colors",children:Ch()})})]})})]}),a(ne,{open:s,onOpenChange:h,mode:k,teamId:o,project:F}),a(ct,{open:C,onOpenChange:v,children:g(ut,{children:[g(dt,{children:[a(pt,{children:Rw()}),g(mt,{children:[oC({name:u?.name??""}),g("div",{className:"mt-4 flex flex-col gap-2 text-foreground",children:[a("span",{className:"text-sm font-medium",children:tD()}),a(re,{value:x,onChange:(e)=>P(e.target.value),placeholder:nC(),className:"h-9",autoFocus:!0})]})]})]}),g(ft,{children:[a(gt,{disabled:q.isPending,children:Ge()}),a(ht,{onClick:(e)=>{e.preventDefault(),ge()},disabled:x!=="delete"||q.isPending,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:q.isPending?fC():Dt()})]})]})}),a(Bu,{open:O,onOpenChange:A,title:fP(),type:"team",members:K,isOwner:G?.role==="owner",onInvite:he,onUpdateRole:async(e,t)=>{await ye.mutateAsync({userId:e,role:t})},onRemoveMember:async(e)=>{await be.mutateAsync(e)},currentUserId:G?.id})]})}var Pe=Je("/teams/$teamId/")({component:Me});export{Pe as Route};