@shumai-one/shumai 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/{chunk-y3haqtr8.js → chunk-01vx2chc.js} +2 -2
- package/bin/chunk-0epkrexd.js +2 -0
- package/bin/chunk-0h5239kt.js +2 -0
- package/bin/{chunk-tfrevef9.js → chunk-0jnstdgf.js} +1 -1
- package/bin/{chunk-w6g84d59.js → chunk-0njsjy6x.js} +4 -4
- package/bin/{chunk-f8hgy69t.js → chunk-13rq2gtr.js} +2 -2
- package/bin/chunk-1aqs9sdh.js +3 -0
- package/bin/{chunk-09mj32d7.js → chunk-22jbsrka.js} +1 -1
- package/bin/chunk-2qknebmd.js +1 -0
- package/bin/{chunk-bd3v8mp1.js → chunk-2qzmh3ae.js} +4 -4
- package/bin/{chunk-p2vsdnd1.js → chunk-2tt0b8ym.js} +2 -2
- package/bin/{chunk-3s2ga6mt.js → chunk-2zm7czk6.js} +1 -1
- package/bin/{chunk-vmwys2ch.js → chunk-396tfwdx.js} +1 -1
- package/bin/chunk-3mx4trvh.js +10 -0
- package/bin/{chunk-j2txsbxz.js → chunk-45pb3kzz.js} +2 -2
- package/bin/{chunk-dkhdn92k.js → chunk-47fmhzwv.js} +2 -2
- package/bin/chunk-4awk4xhq.js +2 -0
- package/bin/{chunk-5ddg5ezb.js → chunk-4b2x2qba.js} +21 -21
- package/bin/{chunk-9x42vgeq.js → chunk-4rjy7ybr.js} +8 -8
- package/bin/{chunk-enax4303.js → chunk-598x693h.js} +2 -2
- package/bin/chunk-5c7ztqs7.js +1 -0
- package/bin/{chunk-4p31kxjh.js → chunk-65dh7x4c.js} +2 -2
- package/bin/{chunk-s74g9vsk.js → chunk-66e2vrky.js} +1 -1
- package/bin/{chunk-q8xr1a8j.js → chunk-6j3beg6n.js} +2 -2
- package/bin/{chunk-95b4mwyq.js → chunk-6ke13k69.js} +1 -1
- package/bin/{chunk-a859y4e1.js → chunk-6rqakmg0.js} +2 -2
- package/bin/{chunk-yb4mzqrd.js → chunk-6ty4tfmf.js} +3 -3
- package/bin/chunk-7e9ws6dh.js +129 -0
- package/bin/chunk-7mdddkfc.js +1 -0
- package/bin/{chunk-qvp24w0q.js → chunk-7q4mgd5x.js} +2 -2
- package/bin/chunk-7yv7shad.js +1 -0
- package/bin/{chunk-25npafhz.js → chunk-81b8rfv7.js} +2 -2
- package/bin/{chunk-etrm28sy.js → chunk-8a7ymmd4.js} +2 -2
- package/bin/chunk-8ac9at5y.js +2 -0
- package/bin/{chunk-sz19nn1x.js → chunk-8zcfgz9c.js} +1 -1
- package/bin/{chunk-te484xtb.js → chunk-955kf5kc.js} +3 -3
- package/bin/{chunk-h2bphev9.js → chunk-978rm9a9.js} +2 -2
- package/bin/{chunk-jt02kpfc.js → chunk-9qzbrp4d.js} +2 -2
- package/bin/{chunk-20bamhwa.js → chunk-a283dh05.js} +2 -2
- package/bin/chunk-aa2a06cc.js +1 -0
- package/bin/{chunk-esj0kwe5.js → chunk-ajr1w3vq.js} +6 -6
- package/bin/chunk-akafypge.js +218 -0
- package/bin/chunk-amk373q2.js +2 -0
- package/bin/{chunk-mn71dffh.js → chunk-apq2gvvp.js} +2 -2
- package/bin/chunk-av2w1sez.js +2 -0
- package/bin/{chunk-atpt99h4.js → chunk-b6kmj34z.js} +12 -12
- package/bin/chunk-bkzaw9p8.js +1 -0
- package/bin/{chunk-pq6kdp83.js → chunk-bssb9tar.js} +3 -3
- package/bin/chunk-bwvj1aqc.js +1 -0
- package/bin/chunk-by9esjn7.js +3 -0
- package/bin/chunk-bywk8mbc.js +2 -0
- package/bin/{chunk-r6t0j0jx.js → chunk-c61g9hfa.js} +4 -4
- package/bin/{chunk-mn0kt3p6.js → chunk-cdcgjh8k.js} +1 -1
- package/bin/{chunk-atdfqdkj.js → chunk-d277evce.js} +4 -4
- package/bin/{chunk-9405hzv2.js → chunk-d3brvxh7.js} +2 -2
- package/bin/{chunk-4vjgdj0h.js → chunk-dcb1nzf1.js} +1 -1
- package/bin/{chunk-q5x0yywj.js → chunk-dfbzatq9.js} +2 -2
- package/bin/chunk-e0bckx12.js +2 -0
- package/bin/{chunk-wgvgtttc.js → chunk-e2p4s2pj.js} +3 -3
- package/bin/chunk-e8zzg57c.js +2 -0
- package/bin/{chunk-npeapp7e.js → chunk-edfaqwaq.js} +2 -2
- package/bin/{chunk-6nqqe7w9.js → chunk-ehgrp0f9.js} +1 -1
- package/bin/chunk-evs2aaav.js +12 -0
- package/bin/{chunk-cp96e9pq.js → chunk-f5bhcjhw.js} +1 -1
- package/bin/{chunk-34f64q0q.js → chunk-fb9dedm2.js} +2 -2
- package/bin/{chunk-zx1c4vm5.js → chunk-ff0mh9p3.js} +31 -31
- package/bin/chunk-fpfby5tz.js +1 -0
- package/bin/{chunk-eyjfhdp9.js → chunk-gd3b5akr.js} +2 -2
- package/bin/{chunk-3hgrw1m0.js → chunk-gm1fy3hm.js} +5 -5
- package/bin/{chunk-ezjxx44x.js → chunk-gqkjx7rz.js} +3 -3
- package/bin/{chunk-1y6h4vge.js → chunk-h7f5370s.js} +1 -1
- package/bin/chunk-hcyhsn8e.js +2 -0
- package/bin/{chunk-erfkd3z9.js → chunk-jxm0gzmf.js} +2 -2
- package/bin/{chunk-09mpcg9x.js → chunk-k3ggy3xk.js} +2 -2
- package/bin/{chunk-0a298n62.js → chunk-k9vjs21p.js} +2 -2
- package/bin/chunk-ka40gv72.js +1 -0
- package/bin/chunk-km70p970.js +2 -0
- package/bin/{chunk-vnmggrd6.js → chunk-m6v8rb39.js} +8 -8
- package/bin/{chunk-bbxwyhz3.js → chunk-m8spagwp.js} +3 -3
- package/bin/{chunk-addssm8d.js → chunk-mfh7mg5b.js} +1 -1
- package/bin/chunk-n0cn0218.js +2 -0
- package/bin/chunk-n54ftsdx.js +2 -0
- package/bin/{chunk-v0yevesp.js → chunk-n7cvj15k.js} +5 -5
- package/bin/chunk-na5fh7er.js +2 -0
- package/bin/chunk-neazdbxy.js +1 -0
- package/bin/chunk-nk24qw3m.js +1 -0
- package/bin/{chunk-7mawxsk3.js → chunk-nsbbseff.js} +2 -2
- package/bin/chunk-nseef85h.js +1 -0
- package/bin/chunk-p35ztj2z.js +3 -0
- package/bin/chunk-pcjc9ygv.js +2 -0
- package/bin/{chunk-brgns7hv.js → chunk-pemmtd8q.js} +1 -1
- package/bin/{chunk-7jz3cmq6.js → chunk-pzrqnnpg.js} +1 -1
- package/bin/{chunk-a74g6h8a.js → chunk-q43m934j.js} +2 -2
- package/bin/{chunk-6f3zhq64.js → chunk-q57m34h0.js} +3 -3
- package/bin/chunk-q5k72jz9.js +3 -0
- package/bin/chunk-q9fsxakd.js +2 -0
- package/bin/chunk-qadpe0ct.js +2 -0
- package/bin/chunk-qeypjv4f.css +1 -0
- package/bin/chunk-qw92z3wf.js +2 -0
- package/bin/chunk-r0byfq1t.js +1 -0
- package/bin/chunk-r0q88qw3.js +2 -0
- package/bin/chunk-rjhczkh3.js +2 -0
- package/bin/{chunk-19zbh4fr.js → chunk-s0wxbybf.js} +1 -1
- package/bin/{chunk-d55138xx.js → chunk-s4hkcw24.js} +2 -2
- package/bin/chunk-szta50g1.js +1 -0
- package/bin/chunk-t6cb99gp.js +2 -0
- package/bin/chunk-tcr080b9.js +1 -0
- package/bin/{chunk-s6pk2zyg.js → chunk-v4nqx084.js} +5 -5
- package/bin/{chunk-gyv3yrhj.js → chunk-v7jzc3ye.js} +1 -1
- package/bin/{chunk-hsyfrzdd.js → chunk-vbe8wred.js} +1 -1
- package/bin/{chunk-sz5zawfw.js → chunk-vf9s8b5t.js} +2 -2
- package/bin/{chunk-e55sgg8t.js → chunk-vk3eqr65.js} +1 -1
- package/bin/{chunk-vv0m0m2f.js → chunk-vm9bbk97.js} +4 -4
- package/bin/{chunk-1e1q1hyg.js → chunk-w4gqg27w.js} +2 -2
- package/bin/{chunk-z0de127n.js → chunk-w6ym7tsd.js} +4 -4
- package/bin/{chunk-3vpz5nat.js → chunk-ways29d1.js} +1 -1
- package/bin/chunk-wesg7tg9.js +1 -0
- package/bin/chunk-wmrrapwv.js +2 -0
- package/bin/chunk-wnwsjgj8.js +2 -0
- package/bin/{chunk-zkvezz89.js → chunk-wrb4xq9v.js} +1 -1
- package/bin/{chunk-7kah3zb5.js → chunk-wzrzc07t.js} +2 -2
- package/bin/chunk-xd1axsdv.js +2 -0
- package/bin/{chunk-k7vbk8v4.js → chunk-xk0jmx4s.js} +2 -2
- package/bin/{chunk-jc7dycy6.js → chunk-y545vfn0.js} +1 -1
- package/bin/{chunk-1ja2zw4w.js → chunk-y6h885fs.js} +1 -1
- package/bin/{chunk-0rgbxp24.js → chunk-yncmfr39.js} +2 -2
- package/bin/{chunk-7546ptwg.js → chunk-yxnz4ypt.js} +8 -8
- package/bin/chunk-zc1asygg.js +2 -0
- package/bin/{chunk-hg3rkp41.js → chunk-zc7wzcvh.js} +7 -7
- package/bin/chunk-zdvhh8mk.js +2 -0
- package/bin/{chunk-femnbfkj.js → chunk-zg0b902x.js} +2 -2
- package/bin/{chunk-ddmf9gqv.js → chunk-zhq7a7hs.js} +2 -2
- package/bin/{chunk-dygj751y.js → chunk-zmnvskn7.js} +11 -11
- package/bin/shumai-app.html +1 -1
- package/bin/shumai-app.js +470 -389
- package/package.json +7 -7
- package/prisma/migrations/20261102032402_add_archive_storage/migration.sql +25 -0
- package/prisma/schema.prisma +12 -6
- package/bin/chunk-02b5bcmc.js +0 -1
- package/bin/chunk-1tar0x8s.js +0 -7
- package/bin/chunk-20w1w9x7.js +0 -2
- package/bin/chunk-2qgagdb7.js +0 -1
- package/bin/chunk-2t6g3pny.js +0 -3
- package/bin/chunk-50pfmxt1.js +0 -2
- package/bin/chunk-5ngftxjb.js +0 -218
- package/bin/chunk-6t525bmg.js +0 -1
- package/bin/chunk-88jg9dq5.js +0 -2
- package/bin/chunk-8qdtvfx3.css +0 -1
- package/bin/chunk-8ww98y1m.js +0 -2
- package/bin/chunk-9vxmgvc8.js +0 -2
- package/bin/chunk-ajq9sxg0.js +0 -129
- package/bin/chunk-amp9h878.js +0 -2
- package/bin/chunk-awshe30f.js +0 -1
- package/bin/chunk-b3t7gbhm.js +0 -2
- package/bin/chunk-c02727j9.js +0 -2
- package/bin/chunk-c1wvs81k.js +0 -2
- package/bin/chunk-c8frmqsk.js +0 -2
- package/bin/chunk-cagzye3j.js +0 -2
- package/bin/chunk-djb65frk.js +0 -1
- package/bin/chunk-dx9f5wab.js +0 -1
- package/bin/chunk-ex3174e3.js +0 -2
- package/bin/chunk-f4xnx4n6.js +0 -1
- package/bin/chunk-fakph5jp.js +0 -1
- package/bin/chunk-ffjdkdcv.js +0 -2
- package/bin/chunk-gd016e9p.js +0 -2
- package/bin/chunk-h3atwgx2.js +0 -1
- package/bin/chunk-h7xny3de.js +0 -2
- package/bin/chunk-hpzk9k55.js +0 -1
- package/bin/chunk-hvyy8vct.js +0 -3
- package/bin/chunk-j2s311yc.js +0 -3
- package/bin/chunk-j6x53e33.js +0 -1
- package/bin/chunk-jacanzp7.js +0 -1
- package/bin/chunk-pdw77q09.js +0 -2
- package/bin/chunk-ptcz4ed3.js +0 -2
- package/bin/chunk-q1fzgqsv.js +0 -2
- package/bin/chunk-q4ny4hpt.js +0 -2
- package/bin/chunk-q8ysc5ex.js +0 -1
- package/bin/chunk-qm50g4n5.js +0 -10
- package/bin/chunk-s1j4v33x.js +0 -2
- package/bin/chunk-t68y25gf.js +0 -1
- package/bin/chunk-thpw6tcj.js +0 -2
- package/bin/chunk-vj4gamdn.js +0 -2
- package/bin/chunk-xy9qpn6b.js +0 -1
- package/bin/chunk-y5dv67mg.js +0 -2
- package/bin/chunk-z8t6e0ee.js +0 -1
- package/bin/chunk-zfg4yy3c.js +0 -2
- package/bin/chunk-zrrnvdxq.js +0 -3
- package/bin/chunk-zzqse5qc.js +0 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a,Je}from"./chunk-akafypge.js";import"./chunk-evs2aaav.js";import"./chunk-fb9dedm2.js";import"./chunk-7q4mgd5x.js";import"./chunk-7e9ws6dh.js";import"./chunk-d3brvxh7.js";import"./chunk-xd1axsdv.js";import"./chunk-zdvhh8mk.js";import"./chunk-bssb9tar.js";import"./chunk-q57m34h0.js";import"./chunk-3mx4trvh.js";import"./chunk-q9fsxakd.js";import"./chunk-s4hkcw24.js";import{Ma}from"./chunk-zc1asygg.js";import"./chunk-av2w1sez.js";import"./chunk-km70p970.js";import"./chunk-8a7ymmd4.js";import"./chunk-k9vjs21p.js";import"./chunk-n54ftsdx.js";import"./chunk-na5fh7er.js";import"./chunk-qw92z3wf.js";import"./chunk-zg0b902x.js";import"./chunk-81b8rfv7.js";import"./chunk-wzrzc07t.js";function n(){let{shareId:r,fileId:i}=e.useParams(),{start:t,version:o,compare:c,cmpLeft:m,cmpRight:s,cmpActive:p}=e.useSearch();return a(Ma,{shareId:r,initialFileId:i,startTime:t,versionId:o,compare:c,compareLeftId:m,compareRightId:s,compareActiveSide:p})}var e=Je("/share/$shareId/files/$fileId")({component:n});export{e as Route};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{te,Ee}from"./chunk-atdfqdkj.js";import{Or}from"./chunk-zrrnvdxq.js";import{Gi,uc,dc}from"./chunk-q5x0yywj.js";import{So,fr,zs,Vi,La,nf,Za,qg,pr,sn,C,Io,st,$g,fo,po,mo,Rr,Wt,fc,Ba,hm,rr,hi,is,gm,pc,Ua,yn,yr,Oe,or,of,It,Fu,js,za,sf,Lu,gi,af,as,Zu,qs,Ho,Am,sr,$s,je,ho,Hg}from"./chunk-bd3v8mp1.js";import{wc,Yi,Ec,xc,Sc}from"./chunk-wgvgtttc.js";import{Gs}from"./chunk-w6g84d59.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:st.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:st.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:po.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:st.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:Wt.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:Wt.create(e)})}});var Xe=C({is(e){return e.kind==="RenameColumnNode"},create(e,t){return C({kind:"RenameColumnNode",column:Wt.create(e),renameTo:Wt.create(t)})}});var ce=C({is(e){return e.kind==="CheckConstraintNode"},create(e,t){return C({kind:"CheckConstraintNode",expression:e,name:t?st.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 Rr(e)?e.toOperationNode():yn.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=is(e);if(!t.table||fc.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?st.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(Wt.create)),name:t?st.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:st.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:Wt.create(e),[t]:r})}});class Pe{#e;constructor(e){this.#e=e}setDataType(e){return new pe(he.create(this.#e,"dataType",qs(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(Wt.create)),name:t?st.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:st.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,[pc(e)])})})}columns(e){return new re({...this.#e,node:A.cloneWithTableProps(this.#e.node,{addIndex:ee.cloneWithColumns(this.#e.node.addIndex,e.map(pc))})})}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:rr.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:st.create(e),newName:st.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:sr(e)})})}setSchema(e){return new Z({...this.#e,node:A.cloneWithTableProps(this.#e.node,{setSchema:st.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=Io){let n=r(new k(v.create(e,qs(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Io){let n=r(new k(v.create(e,qs(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,Ze.create(n.toOperationNode()))})}addUniqueConstraint(e,t,r=Io){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=Io){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=Io){let p=o(new R(W.create(t.map(Wt.create),sr(r),n.map(Wt.create),e)));return new B({...this.#e,constraintBuilder:p})}addPrimaryKeyConstraint(e,t,r=Io){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=Io){let n=r(new k(v.create(e,qs(t))));return new Q({...this.#e,node:A.cloneWithColumnAlteration(this.#e.node,He.create(n.toOperationNode()))})}modifyColumn(e,t,r=Io){let n=r(new k(v.create(e,qs(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 Fu{transformPrimitiveValueList(e){return Ua.create(e.values.map(yn.createImmediate))}transformValue(e){return yn.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:sr(e)})})}column(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,[pc(e)])})}columns(e){return new M({...this.#e,node:P.cloneWithColumns(this.#e.node,e.map(pc))})}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:rr.createWithSql(e)})})}where(...e){let t=new Se;return new M({...this.#e,node:Oe.cloneWithWhere(this.#e.node,t.transformNode(yr(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($g.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:fo.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new q({...this.#e,node:fo.cloneWith(this.#e.node,{onCommit:Lt(e)})})}ifNotExists(){return new q({...this.#e,node:fo.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,t,r=Io){let n=r(new k(v.create(e,qs(t))));return new q({...this.#e,node:fo.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,t,r=Io){let n=r(new K(G.create(t,e)));return new q({...this.#e,node:fo.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,t,r=Io){let n=r(new z(F.create(t,e)));return new q({...this.#e,node:fo.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,t,r=Io){let n=r(new Ae(ce.create(t.toOperationNode(),e)));return new q({...this.#e,node:fo.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,t,r,n,o=Io){let p=o(new R(W.create(t.map(Wt.create),sr(r),n.map(Wt.create),e)));return new q({...this.#e,node:fo.cloneWithConstraint(this.#e.node,p.toOperationNode())})}modifyFront(e){return new q({...this.#e,node:fo.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new q({...this.#e,node:fo.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new q({...this.#e,node:fo.cloneWith(this.#e.node,{selectQuery:Ho(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:sr(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:$s.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new J({...this.#e,node:$s.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new J({...this.#e,node:$s.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new J({...this.#e,node:$s.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new J({...this.#e,node:$s.cloneWith(this.#e.node,{columns:e.map(gm)})})}as(e){let t=e.withPlugin(new tt).toOperationNode();return new J({...this.#e,node:$s.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:po.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:Ua.create(t.map(yn.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 po.createWithSchema(r[0],r[1]);else throw Error(`invalid schemable identifier ${e}`)}else return po.create(e)}function Zt(e){return e.trim()}var xe=C({is(e){return e.kind==="RefreshMaterializedViewNode"},create(e){return C({kind:"RefreshMaterializedViewNode",name:po.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:It(),executor:this.#e,node:fo.create(sr(e))})}dropTable(e){return new ke({queryId:It(),executor:this.#e,node:be.create(sr(e))})}createIndex(e){return new M({queryId:It(),executor:this.#e,node:P.create(e)})}dropIndex(e){return new fe({queryId:It(),executor:this.#e,node:X.create(e)})}createSchema(e){return new We({queryId:It(),executor:this.#e,node:Me.create(e)})}dropSchema(e){return new ve({queryId:It(),executor:this.#e,node:Ce.create(e)})}alterTable(e){return new et({queryId:It(),executor:this.#e,node:A.create(sr(e))})}createView(e){return new J({queryId:It(),executor:this.#e,node:$s.create(e)})}refreshMaterializedView(e){return new Ne({queryId:It(),executor:this.#e,node:xe.create(e)})}dropView(e){return new ye({queryId:It(),executor:this.#e,node:we.create(e)})}createType(e){return new $e({queryId:It(),executor:this.#e,node:Re.create(rt(e))})}dropType(e){return new Fe({queryId:It(),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 js(e)))}}class nt{ref(e){return new hm(e)}table(e){return new Am(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 Lu{#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 it{#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"],nr=["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&&!nr.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}var ir=["query","error"],Ka=C(ir);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 sn(e)&&pr(e.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class U extends gi{#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 it(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 Zu({node:as.create(So(e)?void 0:Ho(e))})}get fn(){return af()}transaction(){return new Ue({...this.#e})}startTransaction(){return new Ve({...this.#e})}connection(){return new Rt({...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 js(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)hi("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 js(e))})}withTables(){return new ae({...this.#e})}}function cr(e){return sn(e)&&sn(e.config)&&sn(e.driver)&&sn(e.executor)&&sn(e.dialect)}class Rt{#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=It();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 js(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 rr.createWithChildren([rr.createWithSql(`${e} `),st.create(t)])}class lt{#e;#t=new Qt;#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 $t(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(Or.raw("begin"))}async commitTransaction(e){await e.executeQuery(Or.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Or.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),It()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),It()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),It()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#r?.close()}}class $t{#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(or.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 Qt{#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 Rc=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 uc}createAdapter(){return new dc}createIntrospector(e){return new ut(e)}}var lr=/"/g;class mt extends ho{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 Gi{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-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(`
|
|
3
3
|
`).slice(1).join(`
|
|
4
4
|
`);return e.stack+=`
|
|
5
|
-
${r}`,e}return e}function mr(e){return sn(e)&&fr(e.stack)}var Ft=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 zt(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(Or.raw(n))}await e.executeQuery(Or.raw("begin"))}async commitTransaction(e){await e.executeQuery(Or.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Or.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),It()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),It()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release savepoint",t),It()))}async releaseConnection(e){e[Ft]()}async destroy(){return new Promise((e,t)=>{this.#r.end((r)=>{if(r)t(r);else e()})})}}function dr(e){return sn(e)&&"insertId"in e&&"affectedRows"in e}class zt{#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}}[Ft](){this.#e.release()}}var hr=/[\\']/g,ft=/`/g,wr=/[\\'"]/g;class wt extends ho{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 Ut="ea586330-2c93-47c8-908d-981d9d270f9d",xr=3600;class xt extends Gi{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await je`select get_lock(${je.lit(Ut)}, ${je.lit(xr)})`.execute(e)}async releaseMigrationLock(e,t){await je`select release_lock(${je.lit(Ut)})`.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 jt=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 Vt(e,{cursor:this.#e.cursor??null}),this.#t.set(e,t),this.#e.onCreateConnection)await this.#e.onCreateConnection(t)}if(this.#e.onReserveConnection)await this.#e.onReserveConnection(t);return t}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let r="start transaction";if(t.isolationLevel)r+=` isolation level ${t.isolationLevel}`;if(t.accessMode)r+=` ${t.accessMode}`;await e.executeQuery(Or.raw(r))}else await e.executeQuery(Or.raw("begin"))}async commitTransaction(e){await e.executeQuery(Or.raw("commit"))}async rollbackTransaction(e){await e.executeQuery(Or.raw("rollback"))}async savepoint(e,t,r){await e.executeQuery(r(L("savepoint",t),It()))}async rollbackToSavepoint(e,t,r){await e.executeQuery(r(L("rollback to",t),It()))}async releaseSavepoint(e,t,r){await e.executeQuery(r(L("release",t),It()))}async releaseConnection(e){e[jt]()}async destroy(){if(this.#r){let e=this.#r;this.#r=void 0,await e.end()}}}class Vt{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async executeQuery(e){try{let{command:t,rowCount:r,rows:n}=await this.#e.query(e.sql,[...e.parameters]);return{numAffectedRows:t==="INSERT"||t==="UPDATE"||t==="DELETE"||t==="MERGE"?BigInt(r):void 0,rows:n??[]}}catch(t){throw 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()}}[jt](){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 Gi{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 Bt=Symbol(),Gt=Symbol(),Kt=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 Jt(d,r).connect()},destroy:async(d)=>{await d[Gt]()},validate:n===!1||o===!1?void 0:(d)=>d[Kt]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){if(this.#e.resetConnectionsOnRelease||this.#e.tedious.resetConnectionOnRelease)await e[Bt]();this.#t.release(e)}async destroy(){await this.#t.destroy()}}class Jt{#e;#t;#r;constructor(e,t){this.#e=e,this.#t=!1,this.#r=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((r,n)=>this.#e.beginTransaction((o)=>{if(o)n(o);else r(void 0)},t?of(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 za;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 za,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()})}[Gt](){if("closed"in this.#e&&this.#e.closed)return Promise.resolve();return new Promise((e)=>{this.#e.once("end",e),this.#e.close()})}async[Bt](){await new Promise((e,t)=>{this.#e.reset((r)=>{if(r)return t(r);e()})})}async[Kt](){if(this.#t||this.#i())return!1;try{let e=new za,t=new Je({compiledQuery:Or.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(La(e)||So(e)||fr(e))return this.#o.TYPES.NVarChar;if(Za(e)||zs(e)&&e%1===0)if(e<-2147483648||e>2147483647)return this.#o.TYPES.BigInt;else return this.#o.TYPES.Int;if(zs(e))return this.#o.TYPES.Float;if(Vi(e))return this.#o.TYPES.Bit;if(nf(e))return this.#o.TYPES.DateTime;if(qg(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 Nr=/^[a-z0-9_]$/i;class Et extends ho{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(!Nr.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 tf(e){if(!e)return null;if("dialect"in e)return tf(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=tf(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-vmwys2ch.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-e55sgg8t.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-brgns7hv.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 At(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 rf(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 pm(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(!or.is(n))return{table:t,columns:[]};let o=n.from?.froms[0],p=o&&mo.is(o)?o.table:void 0;return{schema:p?.schema?.name,table:p?.identifier.name??t,columns:(n.selections??[]).map(({selection:d})=>Ba.is(d)&&Wt.is(d.column)?d.column.column.name:void 0)}}async function jg(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 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`
|
|
6
6
|
SELECT pg_catalog.current_schema() AS schema
|
|
7
|
-
`.execute(e.withoutPlugins())).rows[0]?.schema??"public"}async function
|
|
7
|
+
`.execute(e.withoutPlugins())).rows[0]?.schema??"public"}async function Zm(e){return(await je`
|
|
8
8
|
SELECT SCHEMA_NAME() AS "schemaName"
|
|
9
|
-
`.execute(e.withoutPlugins())).rows[0]?.schemaName||"dbo"}async function
|
|
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 mm(e),"dbo"]}async function Ir(e,t,r){let n=pm(e,r);if(t==="sqlite")return Yi(n,rf(await Hg(e,Object.entries(n).flatMap(([o,p])=>p.disableMigrations?[]:[o]))));return e.connection().execute(async(o)=>{let p=await br(o,t),d=rf(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 Yi(n,d)})}var aP=(e,t)=>{let r=null,n=!1,o=(c,S=!1)=>({getFieldName:I,schema:O,getDefaultFieldName:Ar,getDefaultModelName:Yt,getFieldAttributes:Sr,getModelName:vr,options:St})=>{if(t?.type==="mysql"&&St.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 vt=(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}},kt=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(St.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 At(l,`%${i}%`,t?.type);return u(l,"like",`%${i}%`)}if(a==="starts_with"){if(_&&typeof i==="string")return At(l,`${i}%`,t?.type);return u(l,"like",`${i}%`)}if(a==="ends_with"){if(_&&typeof i==="string")return At(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 kt(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}=vt(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:_}=vt(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 kt(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(Gs({config:{...p.config,transaction:!1},adapter:o(S,!0)})(r))):!1},adapter:o(e)};let d=Gs(p);return(c)=>{r=c;let S=d(c);return xc(S,Sc(()=>Ir(e,t?.type,wc(c,{usePlural:t?.usePlural})),"database",c.database),{runtimeEnabled:Ec(c)}),S}};
|
|
12
|
-
export{
|
|
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};
|