zen-code 4.9.2 → 4.10.0
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/dist/app.js +94 -128
- package/dist/chunk-075hks9v.js +1 -0
- package/dist/chunk-0fj768k4.js +112 -0
- package/dist/chunk-19mf2aa7.js +1 -0
- package/dist/chunk-1mq2jmfy.js +2 -0
- package/dist/chunk-1v863afn.js +278 -0
- package/dist/chunk-1vn8d8b8.js +1 -0
- package/dist/{chunk-hfypkhky.js → chunk-1w19w1bm.js} +1 -1
- package/dist/chunk-3dnayvgx.js +224 -0
- package/dist/chunk-4hg13vwj.js +1 -0
- package/dist/chunk-4scrkcqv.js +1 -0
- package/dist/chunk-54cdhhqm.js +1 -0
- package/dist/chunk-5m4yb9av.js +91 -0
- package/dist/chunk-5yd4ntp6.js +8 -0
- package/dist/{chunk-dxec2q4t.js → chunk-6scjjkn3.js} +1 -1
- package/dist/{chunk-hmemx3cw.js → chunk-7jatn15w.js} +2 -2
- package/dist/{chunk-0pss3s5r.js → chunk-7w9y11hj.js} +1 -1
- package/dist/chunk-7yzv6385.js +1 -0
- package/dist/{chunk-ce53j63y.js → chunk-875hayaj.js} +3 -3
- package/dist/chunk-8bs8r50r.js +1 -0
- package/dist/{chunk-x552nspp.js → chunk-8waww0j9.js} +2 -2
- package/dist/chunk-8ysg0rga.js +1 -0
- package/dist/chunk-9czhw5k6.js +4 -0
- package/dist/chunk-9tgp14v7.js +16 -0
- package/dist/{chunk-yndex7hs.js → chunk-a239dn0b.js} +1 -1
- package/dist/chunk-arv4h3h1.js +2 -0
- package/dist/chunk-b2551zfb.js +2 -0
- package/dist/chunk-b9emn03n.js +1 -0
- package/dist/chunk-bm7578sn.js +1 -0
- package/dist/{chunk-62zh99t6.js → chunk-bytq4kd1.js} +3 -125
- package/dist/chunk-c2wfgbj6.js +1 -0
- package/dist/{chunk-0zk0m93z.js → chunk-cef4vbtb.js} +1 -1
- package/dist/{chunk-hsev32dg.js → chunk-cnzhxgn5.js} +2 -2
- package/dist/chunk-d2770b2z.js +1 -0
- package/dist/chunk-d72063sm.js +2 -0
- package/dist/{chunk-6nfpdtn6.js → chunk-d988tv30.js} +1 -1
- package/dist/{chunk-55nx49pj.js → chunk-dx9k6sdd.js} +3 -3
- package/dist/chunk-e6ggkg36.js +2 -0
- package/dist/{chunk-x90r4sje.js → chunk-fjqtrakn.js} +1 -1
- package/dist/chunk-gbfpab0j.js +1 -0
- package/dist/chunk-gkvx829z.js +1 -0
- package/dist/{chunk-94jawhw7.js → chunk-gwf8b14k.js} +1 -1
- package/dist/chunk-gz7fz9fg.js +1 -0
- package/dist/{chunk-48vkm1yn.js → chunk-h0q3dvnv.js} +2 -2
- package/dist/chunk-h0qb9jk1.js +1 -0
- package/dist/chunk-h9y136h8.js +1 -0
- package/dist/chunk-hrcxdj3c.js +54 -0
- package/dist/chunk-hz9yw7cs.js +166 -0
- package/dist/{chunk-98wjxsna.js → chunk-j4y5rjne.js} +1 -1
- package/dist/chunk-k12y05c3.js +3 -0
- package/dist/{chunk-fkrydbn4.js → chunk-k6fxqssr.js} +3 -3
- package/dist/{chunk-vfwbx331.js → chunk-kmxdq21k.js} +2 -2
- package/dist/chunk-mcb8rewr.js +213 -0
- package/dist/{chunk-9k64296h.js → chunk-mm9w91rj.js} +1 -1
- package/dist/chunk-mv0xzmq8.js +2 -0
- package/dist/{chunk-rztre6k0.js → chunk-n849zsd3.js} +1 -1
- package/dist/chunk-nm253hhf.js +81 -0
- package/dist/{chunk-gyhxdxb4.js → chunk-prg6489q.js} +1 -1
- package/dist/{chunk-pwrscdkf.js → chunk-pxdgy0vr.js} +1 -1
- package/dist/{chunk-frhhpxxy.js → chunk-qhzm2qw9.js} +2 -2
- package/dist/{chunk-8f2zh5h6.js → chunk-qmxtys9q.js} +2 -2
- package/dist/chunk-r0cfe5c1.js +294 -0
- package/dist/chunk-rtjytfhh.js +1 -0
- package/dist/chunk-s7ttf0pm.js +2 -0
- package/dist/{chunk-k38fjqj7.js → chunk-t01t72t2.js} +2 -2
- package/dist/{chunk-fw3nrwpf.js → chunk-t0f66x64.js} +1 -1
- package/dist/chunk-tn356gwf.js +93 -0
- package/dist/chunk-vd8kwzra.js +41 -0
- package/dist/chunk-vhn13anh.js +233 -0
- package/dist/chunk-vnewbtjy.js +1 -0
- package/dist/{chunk-hfegb4pr.js → chunk-wbm7rn9w.js} +2 -2
- package/dist/chunk-wd3gkd45.js +3 -0
- package/dist/chunk-whdf0vbb.js +1 -0
- package/dist/{chunk-r019959h.js → chunk-ws232ksq.js} +2 -2
- package/dist/{chunk-rt5mpgbg.js → chunk-yerf10k7.js} +2 -2
- package/dist/{chunk-pndhbee8.js → chunk-yzv3n8mw.js} +2 -2
- package/dist/chunk-z3e4c424.js +2 -0
- package/dist/{chunk-jb4yt88g.js → chunk-znw7fpep.js} +2 -2
- package/dist/chunk-zq2g4rfd.js +1 -0
- package/dist/cli.js +1 -1
- package/dist/nonInteractive.js +314 -4
- package/dist/zen-keyboard.js +1 -1
- package/package.json +37 -37
- package/dist/chunk-0sxrk9sx.js +0 -1
- package/dist/chunk-178yjjsx.js +0 -1
- package/dist/chunk-1p9xzvpt.js +0 -3
- package/dist/chunk-2eh0sv3s.js +0 -2
- package/dist/chunk-43xrz4wp.js +0 -2
- package/dist/chunk-48ce2wt0.js +0 -1
- package/dist/chunk-578m1dhj.js +0 -2
- package/dist/chunk-5dsevrtz.js +0 -91
- package/dist/chunk-66890qd3.js +0 -2
- package/dist/chunk-738m8242.js +0 -53
- package/dist/chunk-8ty2zfve.js +0 -3
- package/dist/chunk-9b7nj74j.js +0 -1
- package/dist/chunk-9x562s6p.js +0 -1
- package/dist/chunk-a90fm6gz.js +0 -278
- package/dist/chunk-ac5t2ywn.js +0 -100
- package/dist/chunk-ad2hbq42.js +0 -1
- package/dist/chunk-afhxxkmv.js +0 -16
- package/dist/chunk-b4vvgbav.js +0 -1
- package/dist/chunk-b9pcntkv.js +0 -253
- package/dist/chunk-c7y5efa0.js +0 -1
- package/dist/chunk-cbjnwrt7.js +0 -2
- package/dist/chunk-dcs1r9as.js +0 -2
- package/dist/chunk-dcwnpdtk.js +0 -9
- package/dist/chunk-e3tyc24s.js +0 -310
- package/dist/chunk-e8hp8d68.js +0 -81
- package/dist/chunk-h1enhch1.js +0 -2
- package/dist/chunk-hcnx1j2z.js +0 -1
- package/dist/chunk-hra0748z.js +0 -2
- package/dist/chunk-hyf24r36.js +0 -2
- package/dist/chunk-jjcmm167.js +0 -1
- package/dist/chunk-jrepjpft.js +0 -2
- package/dist/chunk-kym9tb01.js +0 -1
- package/dist/chunk-mt1g6g89.js +0 -1
- package/dist/chunk-p0vzbr7s.js +0 -585
- package/dist/chunk-r10bn684.js +0 -1
- package/dist/chunk-r3pe49q4.js +0 -8
- package/dist/chunk-r4tq44hr.js +0 -1
- package/dist/chunk-rjrnaka2.js +0 -1
- package/dist/chunk-s77qbhtz.js +0 -3
- package/dist/chunk-t7rwtc17.js +0 -1
- package/dist/chunk-v8g52kan.js +0 -1
- package/dist/chunk-vd6c87cm.js +0 -2
- package/dist/chunk-vh9zd1v3.js +0 -5
- package/dist/chunk-w2hbsa9j.js +0 -86
- package/dist/chunk-wabmqprd.js +0 -184
- package/dist/chunk-wpy5r9ma.js +0 -40
- package/dist/chunk-yqwxbcc7.js +0 -31
- package/dist/chunk-z8n7y37k.js +0 -1
- package/dist/chunk-zr7sx9hd.js +0 -1
- package/dist/chunk-zxqmghzf.js +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function a(h){return typeof h>"u"||h===void 0}function M(h){return typeof h==="string"}function Mh(h){return typeof h==="number"}function yh(h){return typeof h==="boolean"}function h_(h){return h===null}function v_(h){return h instanceof Date}function __(h){return typeof h==="bigint"}function fk(h){return typeof Buffer<"u"&&Buffer.isBuffer(h)}function R(h){return typeof h==="function"}function O(h){return typeof h==="object"&&h!==null}function wk(h){if(!O(h)||l1(h)!=="[object Object]")return!1;if(Object.getPrototypeOf(h)===null)return!0;let _=h;while(Object.getPrototypeOf(_)!==null)_=Object.getPrototypeOf(_);return Object.getPrototypeOf(h)===_}function M$(h){return h[h.length-1]}function k(h){return Object.freeze(h)}function r_(h){if(q(h))return h;else return[h]}function q(h){return Array.isArray(h)}function s(h){return h}function Rk(h,_){if(q(h)&&q(_))return g1(h,_);else if(O(h)&&O(_))return c1(h,_);return h===_}function g1(h,_){if(h.length!==_.length)return!1;for(let W=0;W<h.length;++W)if(!Rk(h[W],_[W]))return!1;return!0}function c1(h,_){if(fk(h)&&fk(_))return y1(h,_);else if(v_(h)&&v_(_))return t1(h,_);return i1(h,_)}function y1(h,_){return Buffer.compare(h,_)===0}function t1(h,_){return h.getTime()===_.getTime()}function i1(h,_){let W=Object.keys(h),$=Object.keys(_);if(W.length!==$.length)return!1;for(let J of W)if(!Rk(h[J],_[J]))return!1;return!0}var u1=Object.prototype.toString;function l1(h){if(h==null)return h===void 0?"[object Undefined]":"[object Null]";return u1.call(h)}var U=k({is(h){return h.kind==="AlterTableNode"},create(h){return k({kind:"AlterTableNode",table:h})},cloneWithTableProps(h,_){return k({...h,..._})},cloneWithColumnAlteration(h,_){return k({...h,columnAlterations:h.columnAlterations?[...h.columnAlterations,_]:[_]})}});var X=k({is(h){return h.kind==="IdentifierNode"},create(h){return k({kind:"IdentifierNode",name:h})}});var Fh=k({is(h){return h.kind==="CreateIndexNode"},create(h){return k({kind:"CreateIndexNode",name:X.create(h)})},cloneWith(h,_){return k({...h,..._})},cloneWithColumns(h,_){return k({...h,columns:[...h.columns||[],..._]})}});var vk=k({is(h){return h.kind==="CreateSchemaNode"},create(h,_){return k({kind:"CreateSchemaNode",schema:X.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var F$=["preserve rows","delete rows","drop"],u=k({is(h){return h.kind==="CreateTableNode"},create(h){return k({kind:"CreateTableNode",table:h,columns:k([])})},cloneWithColumn(h,_){return k({...h,columns:k([...h.columns,_])})},cloneWithConstraint(h,_){return k({...h,constraints:h.constraints?k([...h.constraints,_]):k([_])})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):k([_])})},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):k([_])})},cloneWith(h,_){return k({...h,..._})}});var l=k({is(h){return h.kind==="SchemableIdentifierNode"},create(h){return k({kind:"SchemableIdentifierNode",identifier:X.create(h)})},createWithSchema(h,_){return k({kind:"SchemableIdentifierNode",schema:X.create(h),identifier:X.create(_)})}});var k_=k({is(h){return h.kind==="DropIndexNode"},create(h,_){return k({kind:"DropIndexNode",name:l.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var o_=k({is(h){return h.kind==="DropSchemaNode"},create(h,_){return k({kind:"DropSchemaNode",schema:X.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var e_=k({is(h){return h.kind==="DropTableNode"},create(h,_){return k({kind:"DropTableNode",table:h,..._})},cloneWith(h,_){return k({...h,..._})}});var I=k({is(h){return h.kind==="AliasNode"},create(h,_){return k({kind:"AliasNode",node:h,alias:_})}});var d=k({is(h){return h.kind==="TableNode"},create(h){return k({kind:"TableNode",table:l.create(h)})},createWithSchema(h,_){return k({kind:"TableNode",table:l.createWithSchema(h,_)})}});function T(h){return O(h)&&R(h.toOperationNode)}function Pk(h){return O(h)&&"expressionType"in h&&T(h)}function U$(h){return O(h)&&"expression"in h&&M(h.alias)&&T(h)}var Ch=k({is(h){return h.kind==="SelectModifierNode"},create(h,_){return k({kind:"SelectModifierNode",modifier:h,of:_})},createWithExpression(h){return k({kind:"SelectModifierNode",rawModifier:h})}});var r=k({is(h){return h.kind==="AndNode"},create(h,_){return k({kind:"AndNode",left:h,right:_})}});var Uh=k({is(h){return h.kind==="OrNode"},create(h,_){return k({kind:"OrNode",left:h,right:_})}});var Dk=k({is(h){return h.kind==="OnNode"},create(h){return k({kind:"OnNode",on:h})},cloneWithOperation(h,_,W){return k({...h,on:_==="And"?r.create(h.on,W):Uh.create(h.on,W)})}});var Vh=k({is(h){return h.kind==="JoinNode"},create(h,_){return k({kind:"JoinNode",joinType:h,table:_,on:void 0})},createWithOn(h,_,W){return k({kind:"JoinNode",joinType:h,table:_,on:Dk.create(W)})},cloneWithOn(h,_){return k({...h,on:h.on?Dk.cloneWithOperation(h.on,"And",_):Dk.create(_)})}});var fh=k({is(h){return h.kind==="BinaryOperationNode"},create(h,_,W){return k({kind:"BinaryOperationNode",leftOperand:h,operator:_,rightOperand:W})}});var V$=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],f$=["+","-","*","/","%","^","&","|","#","<<",">>"],w$=["->","->>"],R$=[...V$,...f$,"&&","||"],p1=["exists","not exists"],a1=["not","-",...p1],hW=[...R$,...w$,...a1,"between","between symmetric"],y=k({is(h){return h.kind==="OperatorNode"},create(h){return k({kind:"OperatorNode",operator:h})}});function o0(h){return M(h)&&hW.includes(h)}function e0(h){return M(h)&&R$.includes(h)}function hJ(h){return M(h)&&V$.includes(h)}function _J(h){return M(h)&&f$.includes(h)}function _W(h){return M(h)&&w$.includes(h)}var F=k({is(h){return h.kind==="ColumnNode"},create(h){return k({kind:"ColumnNode",column:X.create(h)})}});var P_=k({is(h){return h.kind==="SelectAllNode"},create(){return k({kind:"SelectAllNode"})}});var D_=k({is(h){return h.kind==="ReferenceNode"},create(h,_){return k({kind:"ReferenceNode",table:_,column:h})},createSelectAll(h){return k({kind:"ReferenceNode",table:h,column:P_.create()})}});class kW{#h;get dynamicReference(){return this.#h}get refType(){return}constructor(h){this.#h=h}toOperationNode(){return WW(this.#h)}}function Ok(h){return O(h)&&T(h)&&M(h.dynamicReference)}var wh=k({is(h){return h.kind==="OrderByItemNode"},create(h,_){return k({kind:"OrderByItemNode",orderBy:h,direction:_})},cloneWith(h,_){return k({...h,..._})}});var V=k({is(h){return h.kind==="RawNode"},create(h,_){return k({kind:"RawNode",sqlFragments:k(h),parameters:k(_)})},createWithSql(h){return V.create([h],[])},createWithChild(h){return V.create(["",""],[h])},createWithChildren(h){return V.create(Array(h.length+1).fill(""),h)}});var v$=k({is(h){return h.kind==="CollateNode"},create(h){return k({kind:"CollateNode",collation:X.create(h)})}});class W_{#h;constructor(h){this.#h=k(h)}desc(){return new W_({node:wh.cloneWith(this.#h.node,{direction:V.createWithSql("desc")})})}asc(){return new W_({node:wh.cloneWith(this.#h.node,{direction:V.createWithSql("asc")})})}nullsLast(){return new W_({node:wh.cloneWith(this.#h.node,{nulls:"last"})})}nullsFirst(){return new W_({node:wh.cloneWith(this.#h.node,{nulls:"first"})})}collate(h){return new W_({node:wh.cloneWith(this.#h.node,{collation:v$.create(h)})})}toOperationNode(){return this.#h.node}}var P$=new Set;function Rh(h){if(P$.has(h))return;P$.add(h),console.log(h)}function JW(h){return h==="asc"||h==="desc"}function Wh(h){if(h.length===2)return[$W(h[0],h[1])];if(h.length===1){let[_]=h;if(Array.isArray(_))return Rh("orderBy(array) is deprecated, use multiple orderBy calls instead."),_.map((W)=>$W(W));return[$W(_)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${h.length}`)}function $W(h,_){let W=s1(h);if(wh.is(W)){if(_)throw Error("Cannot specify direction twice!");return W}return D$(W,_)}function s1(h){if(th(h))return o(h);if(Ok(h))return h.toOperationNode();let[_,W]=h.split(" ");if(W)return Rh("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),D$(kh(_),W);return kh(h)}function D$(h,_){if(typeof _==="string"){if(!JW(_))throw Error(`Invalid order by direction: ${_}`);return wh.create(h,V.createWithSql(_))}if(Pk(_))return Rh("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),wh.create(h,_.toOperationNode());let W=wh.create(h);if(!_)return W;return _(new W_({node:W})).toOperationNode()}var O_=k({is(h){return h.kind==="JSONReferenceNode"},create(h,_){return k({kind:"JSONReferenceNode",reference:h,traversal:_})},cloneWithTraversal(h,_){return k({...h,traversal:_})}});var Ak=k({is(h){return h.kind==="JSONOperatorChainNode"},create(h){return k({kind:"JSONOperatorChainNode",operator:h,values:k([])})},cloneWithValue(h,_){return k({...h,values:k([...h.values,_])})}});var $_=k({is(h){return h.kind==="JSONPathNode"},create(h){return k({kind:"JSONPathNode",inOperator:h,pathLegs:k([])})},cloneWithLeg(h,_){return k({...h,pathLegs:k([...h.pathLegs,_])})}});function WW(h){if(M(h))return kh(h);return h.toOperationNode()}function ih(h){if(q(h))return h.map((_)=>t(_));else return[t(h)]}function t(h){if(th(h))return o(h);return WW(h)}function O$(h,_){let W=kh(h);if(_W(_))return O_.create(W,Ak.create(y.create(_)));let $=_.slice(0,-1);if(_W($))return O_.create(W,$_.create(y.create($)));throw Error(`Invalid JSON operator: ${_}`)}function kh(h){if(!h.includes("."))return D_.create(F.create(h));let W=h.split(".").map(ZW);if(W.length===3)return n1(W);if(W.length===2)return d1(W);throw Error(`invalid column reference ${h}`)}function A$(h){if(h.includes(" as ")){let[W,$]=h.split(" as ").map(ZW);return I.create(kh(W),X.create($))}else return kh(h)}function YW(h){return F.create(h)}function A_(h){if(h.includes(" ")){let[W,$]=h.split(" ").map(ZW);if(!JW($))throw Error(`invalid order direction "${$}" next to "${W}"`);return Wh([W,$])[0]}else return YW(h)}function n1(h){let[_,W,$]=h;return D_.create(F.create($),d.createWithSchema(_,W))}function d1(h){let[_,W]=h;return D_.create(F.create(W),d.create(_))}function ZW(h){return h.trim()}var T_=k({is(h){return h.kind==="PrimitiveValueListNode"},create(h){return k({kind:"PrimitiveValueListNode",values:k([...h])})}});var $h=k({is(h){return h.kind==="ValueListNode"},create(h){return k({kind:"ValueListNode",values:k(h)})}});var C=k({is(h){return h.kind==="ValueNode"},create(h){return k({kind:"ValueNode",value:h})},createImmediate(h){return k({kind:"ValueNode",value:h,immediate:!0})}});function T$(h){if(q(h))return r1(h);return P(h)}function P(h){if(th(h))return o(h);return C.create(h)}function Tk(h){return Mh(h)||yh(h)||h_(h)}function hk(h){if(!Tk(h))throw Error(`unsafe immediate value ${JSON.stringify(h)}`);return C.createImmediate(h)}function r1(h){if(h.some(th))return $h.create(h.map((_)=>P(_)));return T_.create(h)}var Jh=k({is(h){return h.kind==="ParensNode"},create(h){return k({kind:"ParensNode",node:h})}});function A(h){if(h.length===3)return Ek(h[0],h[1],h[2]);else if(h.length===1)return P(h[0]);throw Error(`invalid arguments: ${JSON.stringify(h)}`)}function Ek(h,_,W){if(o1(_)&&S$(W))return fh.create(t(h),GW(_),C.createImmediate(W));return fh.create(t(h),GW(_),T$(W))}function g(h,_,W){return fh.create(t(h),GW(_),t(W))}function HW(h,_){return E_(Object.entries(h).filter(([,W])=>!a(W)).map(([W,$])=>Ek(W,S$($)?"is":"=",$)),_)}function E_(h,_,W=!0){let $=_==="and"?r.create:Uh.create;if(h.length===0)return fh.create(C.createImmediate(1),y.create("="),C.createImmediate(_==="and"?1:0));let J=E$(h[0]);for(let Y=1;Y<h.length;++Y)J=$(J,E$(h[Y]));if(h.length>1&&W)return Jh.create(J);return J}function o1(h){return h==="is"||h==="is not"}function S$(h){return h_(h)||yh(h)}function GW(h){if(M(h)&&hW.includes(h))return y.create(h);if(T(h))return h.toOperationNode();throw Error(`invalid operator ${JSON.stringify(h)}`)}function E$(h){return T(h)?h.toOperationNode():h}var uh=k({is(h){return h.kind==="OrderByNode"},create(h){return k({kind:"OrderByNode",items:k([...h])})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var XW=k({is(h){return h.kind==="PartitionByNode"},create(h){return k({kind:"PartitionByNode",items:k(h)})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var _k=k({is(h){return h.kind==="OverNode"},create(){return k({kind:"OverNode"})},cloneWithOrderByItems(h,_){return k({...h,orderBy:h.orderBy?uh.cloneWithItems(h.orderBy,_):uh.create(_)})},cloneWithPartitionByItems(h,_){return k({...h,partitionBy:h.partitionBy?XW.cloneWithItems(h.partitionBy,_):XW.create(_)})}});var K_=k({is(h){return h.kind==="FromNode"},create(h){return k({kind:"FromNode",froms:k(h)})},cloneWithFroms(h,_){return k({...h,froms:k([...h.froms,..._])})}});var LW=k({is(h){return h.kind==="GroupByNode"},create(h){return k({kind:"GroupByNode",items:k(h)})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var zW=k({is(h){return h.kind==="HavingNode"},create(h){return k({kind:"HavingNode",having:h})},cloneWithOperation(h,_,W){return k({...h,having:_==="And"?r.create(h.having,W):Uh.create(h.having,W)})}});var m=k({is(h){return h.kind==="InsertQueryNode"},create(h,_,W){return k({kind:"InsertQueryNode",into:h,..._&&{with:_},replace:W})},createWithoutInto(){return k({kind:"InsertQueryNode"})},cloneWith(h,_){return k({...h,..._})}});var Sk=k({is(h){return h.kind==="ListNode"},create(h){return k({kind:"ListNode",items:k(h)})}});var jh=k({is(h){return h.kind==="UpdateQueryNode"},create(h,_){return k({kind:"UpdateQueryNode",table:h.length===1?h[0]:Sk.create(h),..._&&{with:_}})},createWithoutTable(){return k({kind:"UpdateQueryNode"})},cloneWithFromItems(h,_){return k({...h,from:h.from?K_.cloneWithFroms(h.from,_):K_.create(_)})},cloneWithUpdates(h,_){return k({...h,updates:h.updates?k([...h.updates,..._]):_})},cloneWithLimit(h,_){return k({...h,limit:_})}});var kk=k({is(h){return h.kind==="UsingNode"},create(h){return k({kind:"UsingNode",tables:k(h)})},cloneWithTables(h,_){return k({...h,tables:k([...h.tables,..._])})}});var J_=k({is(h){return h.kind==="DeleteQueryNode"},create(h,_){return k({kind:"DeleteQueryNode",from:K_.create(h),..._&&{with:_}})},cloneWithOrderByItems:(h,_)=>G.cloneWithOrderByItems(h,_),cloneWithoutOrderBy:(h)=>G.cloneWithoutOrderBy(h),cloneWithLimit(h,_){return k({...h,limit:_})},cloneWithoutLimit(h){return k({...h,limit:void 0})},cloneWithUsing(h,_){return k({...h,using:h.using!==void 0?kk.cloneWithTables(h.using,_):kk.create(_)})}});var i=k({is(h){return h.kind==="WhereNode"},create(h){return k({kind:"WhereNode",where:h})},cloneWithOperation(h,_,W){return k({...h,where:_==="And"?r.create(h.where,W):Uh.create(h.where,W)})}});var KW=k({is(h){return h.kind==="ReturningNode"},create(h){return k({kind:"ReturningNode",selections:k(h)})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})}});var N$=k({is(h){return h.kind==="ExplainNode"},create(h,_){return k({kind:"ExplainNode",format:h,options:_})}});var Hh=k({is(h){return h.kind==="WhenNode"},create(h){return k({kind:"WhenNode",condition:h})},cloneWithResult(h,_){return k({...h,result:_})}});var Yh=k({is(h){return h.kind==="MergeQueryNode"},create(h,_){return k({kind:"MergeQueryNode",into:h,..._&&{with:_}})},cloneWithUsing(h,_){return k({...h,using:_})},cloneWithWhen(h,_){return k({...h,whens:h.whens?k([...h.whens,_]):k([_])})},cloneWithThen(h,_){return k({...h,whens:h.whens?k([...h.whens.slice(0,-1),Hh.cloneWithResult(h.whens[h.whens.length-1],_)]):void 0})}});var MW=k({is(h){return h.kind==="OutputNode"},create(h){return k({kind:"OutputNode",selections:k(h)})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})}});var G=k({is(h){return w.is(h)||m.is(h)||jh.is(h)||J_.is(h)||Yh.is(h)},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):k([_])})},cloneWithWhere(h,_){return k({...h,where:h.where?i.cloneWithOperation(h.where,"And",_):i.create(_)})},cloneWithJoin(h,_){return k({...h,joins:h.joins?k([...h.joins,_]):k([_])})},cloneWithReturning(h,_){return k({...h,returning:h.returning?KW.cloneWithSelections(h.returning,_):KW.create(_)})},cloneWithoutReturning(h){return k({...h,returning:void 0})},cloneWithoutWhere(h){return k({...h,where:void 0})},cloneWithExplain(h,_,W){return k({...h,explain:N$.create(_,W?.toOperationNode())})},cloneWithTop(h,_){return k({...h,top:_})},cloneWithOutput(h,_){return k({...h,output:h.output?MW.cloneWithSelections(h.output,_):MW.create(_)})},cloneWithOrderByItems(h,_){return k({...h,orderBy:h.orderBy?uh.cloneWithItems(h.orderBy,_):uh.create(_)})},cloneWithoutOrderBy(h){return k({...h,orderBy:void 0})}});var w=k({is(h){return h.kind==="SelectQueryNode"},create(h){return k({kind:"SelectQueryNode",...h&&{with:h}})},createFrom(h,_){return k({kind:"SelectQueryNode",from:K_.create(h),..._&&{with:_}})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})},cloneWithDistinctOn(h,_){return k({...h,distinctOn:h.distinctOn?k([...h.distinctOn,..._]):k(_)})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):k([_])})},cloneWithOrderByItems:(h,_)=>G.cloneWithOrderByItems(h,_),cloneWithGroupByItems(h,_){return k({...h,groupBy:h.groupBy?LW.cloneWithItems(h.groupBy,_):LW.create(_)})},cloneWithLimit(h,_){return k({...h,limit:_})},cloneWithOffset(h,_){return k({...h,offset:_})},cloneWithFetch(h,_){return k({...h,fetch:_})},cloneWithHaving(h,_){return k({...h,having:h.having?zW.cloneWithOperation(h.having,"And",_):zW.create(_)})},cloneWithSetOperations(h,_){return k({...h,setOperations:h.setOperations?k([...h.setOperations,..._]):k([..._])})},cloneWithoutSelections(h){return k({...h,selections:[]})},cloneWithoutLimit(h){return k({...h,limit:void 0})},cloneWithoutOffset(h){return k({...h,offset:void 0})},cloneWithoutOrderBy:(h)=>G.cloneWithoutOrderBy(h),cloneWithoutGroupBy(h){return k({...h,groupBy:void 0})}});class S_{#h;constructor(h){this.#h=k(h)}on(...h){return new S_({...this.#h,joinNode:Vh.cloneWithOn(this.#h.joinNode,A(h))})}onRef(h,_,W){return new S_({...this.#h,joinNode:Vh.cloneWithOn(this.#h.joinNode,g(h,_,W))})}onTrue(){return new S_({...this.#h,joinNode:Vh.cloneWithOn(this.#h.joinNode,V.createWithSql("true"))})}$call(h){return h(this)}toOperationNode(){return this.#h.joinNode}}var x$=k({is(h){return h.kind==="PartitionByItemNode"},create(h){return k({kind:"PartitionByItemNode",partitionBy:h})}});function C$(h){return ih(h).map(x$.create)}class N_{#h;constructor(h){this.#h=k(h)}orderBy(...h){return new N_({overNode:_k.cloneWithOrderByItems(this.#h.overNode,Wh(h))})}clearOrderBy(){return new N_({overNode:G.cloneWithoutOrderBy(this.#h.overNode)})}partitionBy(h){return new N_({overNode:_k.cloneWithPartitionByItems(this.#h.overNode,C$(h))})}$call(h){return h(this)}toOperationNode(){return this.#h.overNode}}var x_=k({is(h){return h.kind==="SelectionNode"},create(h){return k({kind:"SelectionNode",selection:h})},createSelectAll(){return k({kind:"SelectionNode",selection:P_.create()})},createSelectAllFromTable(h){return k({kind:"SelectionNode",selection:D_.createSelectAll(h)})}});function B(h){if(R(h))return B(h(Xh()));else if(q(h))return h.map((_)=>j$(_));else return[j$(h)]}function j$(h){if(M(h))return x_.create(A$(h));else if(Ok(h))return x_.create(h.toOperationNode());else return x_.create(Nk(h))}function c(h){if(!h)return[x_.createSelectAll()];else if(Array.isArray(h))return h.map(m$);else return[m$(h)]}function m$(h){if(M(h))return x_.createSelectAllFromTable(f(h));throw Error(`invalid value selectAll expression: ${JSON.stringify(h)}`)}var Q$=k({is(h){return h.kind==="ValuesNode"},create(h){return k({kind:"ValuesNode",values:k(h)})}});var b$=k({is(h){return h.kind==="DefaultInsertValueNode"},create(){return k({kind:"DefaultInsertValueNode"})}});function xk(h){let _=R(h)?h(Xh()):h,W=q(_)?_:k([_]);return e1(W)}function e1(h){let _=h8(h);return[k([..._.keys()].map(F.create)),Q$.create(h.map((W)=>_8(W,_)))]}function h8(h){let _=new Map;for(let W of h){let $=Object.keys(W);for(let J of $)if(!_.has(J)&&W[J]!==void 0)_.set(J,_.size)}return _}function _8(h,_){let W=Object.keys(h),$=Array.from({length:_.size}),J=!1,Y=W.length;for(let K of W){let b=_.get(K);if(a(b)){Y--;continue}let x=h[K];if(a(x)||th(x))J=!0;$[b]=x}if(Y<_.size||J){let K=b$.create();return $h.create($.map((b)=>a(b)?K:P(b)))}return T_.create($)}var FW=k({is(h){return h.kind==="ColumnUpdateNode"},create(h,_){return k({kind:"ColumnUpdateNode",column:h,value:_})}});function B$(...h){if(h.length===2)return[FW.create(t(h[0]),P(h[1]))];return Wk(h[0])}function Wk(h){let _=R(h)?h(Xh()):h;return Object.entries(_).filter(([W,$])=>$!==void 0).map(([W,$])=>{return FW.create(F.create(W),P($))})}var q$=k({is(h){return h.kind==="OnDuplicateKeyNode"},create(h){return k({kind:"OnDuplicateKeyNode",updates:h})}});class UW{insertId;numInsertedOrUpdatedRows;constructor(h,_){this.insertId=h,this.numInsertedOrUpdatedRows=_}}class vh extends Error{node;constructor(h){super("no result");this.node=h}}function mh(h){return Object.prototype.hasOwnProperty.call(h,"prototype")}var n=k({is(h){return h.kind==="OnConflictNode"},create(){return k({kind:"OnConflictNode"})},cloneWith(h,_){return k({...h,..._})},cloneWithIndexWhere(h,_){return k({...h,indexWhere:h.indexWhere?i.cloneWithOperation(h.indexWhere,"And",_):i.create(_)})},cloneWithIndexOrWhere(h,_){return k({...h,indexWhere:h.indexWhere?i.cloneWithOperation(h.indexWhere,"Or",_):i.create(_)})},cloneWithUpdateWhere(h,_){return k({...h,updateWhere:h.updateWhere?i.cloneWithOperation(h.updateWhere,"And",_):i.create(_)})},cloneWithUpdateOrWhere(h,_){return k({...h,updateWhere:h.updateWhere?i.cloneWithOperation(h.updateWhere,"Or",_):i.create(_)})},cloneWithoutIndexWhere(h){return k({...h,indexWhere:void 0})},cloneWithoutUpdateWhere(h){return k({...h,updateWhere:void 0})}});class Qh{#h;constructor(h){this.#h=k(h)}column(h){let _=F.create(h);return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{columns:this.#h.onConflictNode.columns?k([...this.#h.onConflictNode.columns,_]):k([_])})})}columns(h){let _=h.map(F.create);return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{columns:this.#h.onConflictNode.columns?k([...this.#h.onConflictNode.columns,..._]):k(_)})})}constraint(h){return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{constraint:X.create(h)})})}expression(h){return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{indexExpression:h.toOperationNode()})})}where(...h){return new Qh({...this.#h,onConflictNode:n.cloneWithIndexWhere(this.#h.onConflictNode,A(h))})}whereRef(h,_,W){return new Qh({...this.#h,onConflictNode:n.cloneWithIndexWhere(this.#h.onConflictNode,g(h,_,W))})}clearWhere(){return new Qh({...this.#h,onConflictNode:n.cloneWithoutIndexWhere(this.#h.onConflictNode)})}doNothing(){return new I$({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{doNothing:!0})})}doUpdateSet(h){return new $k({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{updates:Wk(h)})})}$call(h){return h(this)}}class I${#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.onConflictNode}}class $k{#h;constructor(h){this.#h=k(h)}where(...h){return new $k({...this.#h,onConflictNode:n.cloneWithUpdateWhere(this.#h.onConflictNode,A(h))})}whereRef(h,_,W){return new $k({...this.#h,onConflictNode:n.cloneWithUpdateWhere(this.#h.onConflictNode,g(h,_,W))})}clearWhere(){return new $k({...this.#h,onConflictNode:n.cloneWithoutUpdateWhere(this.#h.onConflictNode)})}$call(h){return h(this)}toOperationNode(){return this.#h.onConflictNode}}var g$=k({is(h){return h.kind==="TopNode"},create(h,_){return k({kind:"TopNode",expression:h,modifiers:_})}});function Ph(h,_){if(!Mh(h)&&!__(h))throw Error(`Invalid top expression: ${h}`);if(!a(_)&&!k8(_))throw Error(`Invalid top modifiers: ${_}`);return g$.create(h,_)}function k8(h){return h==="percent"||h==="with ties"||h==="percent with ties"}var M_=k({is(h){return h.kind==="OrActionNode"},create(h){return k({kind:"OrActionNode",action:h})}});class D{#h;constructor(h){this.#h=k(h)}values(h){let[_,W]=xk(h);return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{columns:_,values:W})})}columns(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{columns:k(h.map(F.create))})})}expression(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{values:o(h)})})}defaultValues(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{defaultValues:!0})})}modifyEnd(h){return new D({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}ignore(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("ignore")})})}orIgnore(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("ignore")})})}orAbort(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("abort")})})}orFail(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("fail")})})}orReplace(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("replace")})})}orRollback(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("rollback")})})}top(h,_){return new D({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}onConflict(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{onConflict:h(new Qh({onConflictNode:n.create()})).toOperationNode()})})}onDuplicateKeyUpdate(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{onDuplicateKey:q$.create(Wk(h))})})}returning(h){return new D({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(){return new D({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c())})}output(h){return new D({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new D({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}clearReturning(){return new D({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new D({...this.#h})}$castTo(){return new D(this.#h)}$narrowType(){return new D(this.#h)}$assertType(){return new D(this.#h)}withPlugin(h){return new D({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new UW(_.insertId,_.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=vh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new D({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}class VW{numDeletedRows;constructor(h){this.numDeletedRows=h}}var C_=k({is(h){return h.kind==="LimitNode"},create(h){return k({kind:"LimitNode",limit:h})}});class j{#h;constructor(h){this.#h=k(h)}where(...h){return new j({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new j({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}clearWhere(){return new j({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}top(h,_){return new j({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}using(h){return new j({...this.#h,queryNode:J_.cloneWithUsing(this.#h.queryNode,Dh(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}#_(h,_){return new j({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}returning(h){return new j({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new j({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new j({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new j({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}clearReturning(){return new j({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}clearLimit(){return new j({...this.#h,queryNode:J_.cloneWithoutLimit(this.#h.queryNode)})}orderBy(...h){return new j({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}clearOrderBy(){return new j({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}limit(h){return new j({...this.#h,queryNode:J_.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}modifyEnd(h){return new j({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new j({...this.#h})}$castTo(){return new j(this.#h)}$narrowType(){return new j(this.#h)}$assertType(){return new j(this.#h)}withPlugin(h){return new j({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new VW(_.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=vh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new j({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}class fW{numUpdatedRows;numChangedRows;constructor(h,_){this.numUpdatedRows=h,this.numChangedRows=_}}class E{#h;constructor(h){this.#h=k(h)}where(...h){return new E({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new E({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}clearWhere(){return new E({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}top(h,_){return new E({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}from(h){return new E({...this.#h,queryNode:jh.cloneWithFromItems(this.#h.queryNode,Dh(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}#_(h,_){return new E({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}orderBy(...h){return new E({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}clearOrderBy(){return new E({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}limit(h){return new E({...this.#h,queryNode:jh.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}set(...h){return new E({...this.#h,queryNode:jh.cloneWithUpdates(this.#h.queryNode,B$(...h))})}returning(h){return new E({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new E({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new E({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new E({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}modifyEnd(h){return new E({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}clearReturning(){return new E({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new E({...this.#h})}$castTo(){return new E(this.#h)}$narrowType(){return new E(this.#h)}$assertType(){return new E(this.#h)}withPlugin(h){return new E({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new fW(_.numAffectedRows??BigInt(0),_.numChangedRows)]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=vh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new E({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}var wW=k({is(h){return h.kind==="CommonTableExpressionNameNode"},create(h,_){return k({kind:"CommonTableExpressionNameNode",table:d.create(h),columns:_?k(_.map(F.create)):void 0})}});var j_=k({is(h){return h.kind==="CommonTableExpressionNode"},create(h,_){return k({kind:"CommonTableExpressionNode",name:h,expression:_})},cloneWith(h,_){return k({...h,..._})}});class Jk{#h;constructor(h){this.#h=k(h)}materialized(){return new Jk({...this.#h,node:j_.cloneWith(this.#h.node,{materialized:!0})})}notMaterialized(){return new Jk({...this.#h,node:j_.cloneWith(this.#h.node,{materialized:!1})})}toOperationNode(){return this.#h.node}}function RW(h,_){let W=_(y$()).toOperationNode();if(R(h))return h(W8(W)).toOperationNode();return j_.create(c$(h),W)}function W8(h){return(_)=>{return new Jk({node:j_.create(c$(_),h)})}}function c$(h){if(h.includes("(")){let _=h.split(/[\(\)]/),W=_[0],$=_[1].split(",").map((J)=>J.trim());return wW.create(W,$)}else return wW.create(h)}var Yk=k({is(h){return h.kind==="WithNode"},create(h,_){return k({kind:"WithNode",expressions:k([h]),..._})},cloneWithExpression(h,_){return k({...h,expressions:k([...h.expressions,_])})}});var t$=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Ck(h){let _="";for(let W=0;W<h;++W)_+=$8();return _}function $8(){return t$[~~(Math.random()*t$.length)]}function L(){return new i$}class i${#h;get queryId(){if(this.#h===void 0)this.#h=Ck(8);return this.#h}}function Z(h){return h}class Oh{nodeStack=[];#h=k({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(h,_){if(!h)return h;this.nodeStack.push(h);let W=this.transformNodeImpl(h,_);return this.nodeStack.pop(),k(W)}transformNodeImpl(h,_){return this.#h[h.kind](h,_)}transformNodeList(h,_){if(!h)return h;return k(h.map((W)=>this.transformNode(W,_)))}transformSelectQuery(h,_){return Z({kind:"SelectQueryNode",from:this.transformNode(h.from,_),selections:this.transformNodeList(h.selections,_),distinctOn:this.transformNodeList(h.distinctOn,_),joins:this.transformNodeList(h.joins,_),groupBy:this.transformNode(h.groupBy,_),orderBy:this.transformNode(h.orderBy,_),where:this.transformNode(h.where,_),frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),limit:this.transformNode(h.limit,_),offset:this.transformNode(h.offset,_),with:this.transformNode(h.with,_),having:this.transformNode(h.having,_),explain:this.transformNode(h.explain,_),setOperations:this.transformNodeList(h.setOperations,_),fetch:this.transformNode(h.fetch,_),top:this.transformNode(h.top,_)})}transformSelection(h,_){return Z({kind:"SelectionNode",selection:this.transformNode(h.selection,_)})}transformColumn(h,_){return Z({kind:"ColumnNode",column:this.transformNode(h.column,_)})}transformAlias(h,_){return Z({kind:"AliasNode",node:this.transformNode(h.node,_),alias:this.transformNode(h.alias,_)})}transformTable(h,_){return Z({kind:"TableNode",table:this.transformNode(h.table,_)})}transformFrom(h,_){return Z({kind:"FromNode",froms:this.transformNodeList(h.froms,_)})}transformReference(h,_){return Z({kind:"ReferenceNode",column:this.transformNode(h.column,_),table:this.transformNode(h.table,_)})}transformAnd(h,_){return Z({kind:"AndNode",left:this.transformNode(h.left,_),right:this.transformNode(h.right,_)})}transformOr(h,_){return Z({kind:"OrNode",left:this.transformNode(h.left,_),right:this.transformNode(h.right,_)})}transformValueList(h,_){return Z({kind:"ValueListNode",values:this.transformNodeList(h.values,_)})}transformParens(h,_){return Z({kind:"ParensNode",node:this.transformNode(h.node,_)})}transformJoin(h,_){return Z({kind:"JoinNode",joinType:h.joinType,table:this.transformNode(h.table,_),on:this.transformNode(h.on,_)})}transformRaw(h,_){return Z({kind:"RawNode",sqlFragments:k([...h.sqlFragments]),parameters:this.transformNodeList(h.parameters,_)})}transformWhere(h,_){return Z({kind:"WhereNode",where:this.transformNode(h.where,_)})}transformInsertQuery(h,_){return Z({kind:"InsertQueryNode",into:this.transformNode(h.into,_),columns:this.transformNodeList(h.columns,_),values:this.transformNode(h.values,_),returning:this.transformNode(h.returning,_),onConflict:this.transformNode(h.onConflict,_),onDuplicateKey:this.transformNode(h.onDuplicateKey,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),ignore:h.ignore,orAction:this.transformNode(h.orAction,_),replace:h.replace,explain:this.transformNode(h.explain,_),defaultValues:h.defaultValues,top:this.transformNode(h.top,_),output:this.transformNode(h.output,_)})}transformValues(h,_){return Z({kind:"ValuesNode",values:this.transformNodeList(h.values,_)})}transformDeleteQuery(h,_){return Z({kind:"DeleteQueryNode",from:this.transformNode(h.from,_),using:this.transformNode(h.using,_),joins:this.transformNodeList(h.joins,_),where:this.transformNode(h.where,_),returning:this.transformNode(h.returning,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),orderBy:this.transformNode(h.orderBy,_),limit:this.transformNode(h.limit,_),explain:this.transformNode(h.explain,_),top:this.transformNode(h.top,_),output:this.transformNode(h.output,_)})}transformReturning(h,_){return Z({kind:"ReturningNode",selections:this.transformNodeList(h.selections,_)})}transformCreateTable(h,_){return Z({kind:"CreateTableNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),constraints:this.transformNodeList(h.constraints,_),temporary:h.temporary,ifNotExists:h.ifNotExists,onCommit:h.onCommit,frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),selectQuery:this.transformNode(h.selectQuery,_)})}transformColumnDefinition(h,_){return Z({kind:"ColumnDefinitionNode",column:this.transformNode(h.column,_),dataType:this.transformNode(h.dataType,_),references:this.transformNode(h.references,_),primaryKey:h.primaryKey,autoIncrement:h.autoIncrement,unique:h.unique,notNull:h.notNull,unsigned:h.unsigned,defaultTo:this.transformNode(h.defaultTo,_),check:this.transformNode(h.check,_),generated:this.transformNode(h.generated,_),frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),nullsNotDistinct:h.nullsNotDistinct,identity:h.identity,ifNotExists:h.ifNotExists})}transformAddColumn(h,_){return Z({kind:"AddColumnNode",column:this.transformNode(h.column,_)})}transformDropTable(h,_){return Z({kind:"DropTableNode",table:this.transformNode(h.table,_),ifExists:h.ifExists,cascade:h.cascade})}transformOrderBy(h,_){return Z({kind:"OrderByNode",items:this.transformNodeList(h.items,_)})}transformOrderByItem(h,_){return Z({kind:"OrderByItemNode",orderBy:this.transformNode(h.orderBy,_),direction:this.transformNode(h.direction,_),collation:this.transformNode(h.collation,_),nulls:h.nulls})}transformGroupBy(h,_){return Z({kind:"GroupByNode",items:this.transformNodeList(h.items,_)})}transformGroupByItem(h,_){return Z({kind:"GroupByItemNode",groupBy:this.transformNode(h.groupBy,_)})}transformUpdateQuery(h,_){return Z({kind:"UpdateQueryNode",table:this.transformNode(h.table,_),from:this.transformNode(h.from,_),joins:this.transformNodeList(h.joins,_),where:this.transformNode(h.where,_),updates:this.transformNodeList(h.updates,_),returning:this.transformNode(h.returning,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),explain:this.transformNode(h.explain,_),limit:this.transformNode(h.limit,_),top:this.transformNode(h.top,_),output:this.transformNode(h.output,_),orderBy:this.transformNode(h.orderBy,_)})}transformColumnUpdate(h,_){return Z({kind:"ColumnUpdateNode",column:this.transformNode(h.column,_),value:this.transformNode(h.value,_)})}transformLimit(h,_){return Z({kind:"LimitNode",limit:this.transformNode(h.limit,_)})}transformOffset(h,_){return Z({kind:"OffsetNode",offset:this.transformNode(h.offset,_)})}transformOnConflict(h,_){return Z({kind:"OnConflictNode",columns:this.transformNodeList(h.columns,_),constraint:this.transformNode(h.constraint,_),indexExpression:this.transformNode(h.indexExpression,_),indexWhere:this.transformNode(h.indexWhere,_),updates:this.transformNodeList(h.updates,_),updateWhere:this.transformNode(h.updateWhere,_),doNothing:h.doNothing})}transformOnDuplicateKey(h,_){return Z({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(h.updates,_)})}transformCreateIndex(h,_){return Z({kind:"CreateIndexNode",name:this.transformNode(h.name,_),table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),unique:h.unique,using:this.transformNode(h.using,_),ifNotExists:h.ifNotExists,where:this.transformNode(h.where,_),nullsNotDistinct:h.nullsNotDistinct})}transformList(h,_){return Z({kind:"ListNode",items:this.transformNodeList(h.items,_)})}transformDropIndex(h,_){return Z({kind:"DropIndexNode",name:this.transformNode(h.name,_),table:this.transformNode(h.table,_),ifExists:h.ifExists,cascade:h.cascade})}transformPrimaryKeyConstraint(h,_){return Z({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(h.columns,_),name:this.transformNode(h.name,_),deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformUniqueConstraint(h,_){return Z({kind:"UniqueConstraintNode",columns:this.transformNodeList(h.columns,_),name:this.transformNode(h.name,_),nullsNotDistinct:h.nullsNotDistinct,deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformForeignKeyConstraint(h,_){return Z({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(h.columns,_),references:this.transformNode(h.references,_),name:this.transformNode(h.name,_),onDelete:h.onDelete,onUpdate:h.onUpdate,deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformSetOperation(h,_){return Z({kind:"SetOperationNode",operator:h.operator,expression:this.transformNode(h.expression,_),all:h.all})}transformReferences(h,_){return Z({kind:"ReferencesNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),onDelete:h.onDelete,onUpdate:h.onUpdate})}transformCheckConstraint(h,_){return Z({kind:"CheckConstraintNode",expression:this.transformNode(h.expression,_),name:this.transformNode(h.name,_)})}transformWith(h,_){return Z({kind:"WithNode",expressions:this.transformNodeList(h.expressions,_),recursive:h.recursive})}transformCommonTableExpression(h,_){return Z({kind:"CommonTableExpressionNode",name:this.transformNode(h.name,_),materialized:h.materialized,expression:this.transformNode(h.expression,_)})}transformCommonTableExpressionName(h,_){return Z({kind:"CommonTableExpressionNameNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_)})}transformHaving(h,_){return Z({kind:"HavingNode",having:this.transformNode(h.having,_)})}transformCreateSchema(h,_){return Z({kind:"CreateSchemaNode",schema:this.transformNode(h.schema,_),ifNotExists:h.ifNotExists})}transformDropSchema(h,_){return Z({kind:"DropSchemaNode",schema:this.transformNode(h.schema,_),ifExists:h.ifExists,cascade:h.cascade})}transformAlterTable(h,_){return Z({kind:"AlterTableNode",table:this.transformNode(h.table,_),renameTo:this.transformNode(h.renameTo,_),setSchema:this.transformNode(h.setSchema,_),columnAlterations:this.transformNodeList(h.columnAlterations,_),addConstraint:this.transformNode(h.addConstraint,_),dropConstraint:this.transformNode(h.dropConstraint,_),renameConstraint:this.transformNode(h.renameConstraint,_),addIndex:this.transformNode(h.addIndex,_),dropIndex:this.transformNode(h.dropIndex,_)})}transformDropColumn(h,_){return Z({kind:"DropColumnNode",column:this.transformNode(h.column,_)})}transformRenameColumn(h,_){return Z({kind:"RenameColumnNode",column:this.transformNode(h.column,_),renameTo:this.transformNode(h.renameTo,_)})}transformAlterColumn(h,_){return Z({kind:"AlterColumnNode",column:this.transformNode(h.column,_),dataType:this.transformNode(h.dataType,_),dataTypeExpression:this.transformNode(h.dataTypeExpression,_),setDefault:this.transformNode(h.setDefault,_),dropDefault:h.dropDefault,setNotNull:h.setNotNull,dropNotNull:h.dropNotNull})}transformModifyColumn(h,_){return Z({kind:"ModifyColumnNode",column:this.transformNode(h.column,_)})}transformAddConstraint(h,_){return Z({kind:"AddConstraintNode",constraint:this.transformNode(h.constraint,_)})}transformDropConstraint(h,_){return Z({kind:"DropConstraintNode",constraintName:this.transformNode(h.constraintName,_),ifExists:h.ifExists,modifier:h.modifier})}transformRenameConstraint(h,_){return Z({kind:"RenameConstraintNode",oldName:this.transformNode(h.oldName,_),newName:this.transformNode(h.newName,_)})}transformCreateView(h,_){return Z({kind:"CreateViewNode",name:this.transformNode(h.name,_),temporary:h.temporary,orReplace:h.orReplace,ifNotExists:h.ifNotExists,materialized:h.materialized,columns:this.transformNodeList(h.columns,_),as:this.transformNode(h.as,_)})}transformRefreshMaterializedView(h,_){return Z({kind:"RefreshMaterializedViewNode",name:this.transformNode(h.name,_),concurrently:h.concurrently,withNoData:h.withNoData})}transformDropView(h,_){return Z({kind:"DropViewNode",name:this.transformNode(h.name,_),ifExists:h.ifExists,materialized:h.materialized,cascade:h.cascade})}transformGenerated(h,_){return Z({kind:"GeneratedNode",byDefault:h.byDefault,always:h.always,identity:h.identity,stored:h.stored,expression:this.transformNode(h.expression,_)})}transformDefaultValue(h,_){return Z({kind:"DefaultValueNode",defaultValue:this.transformNode(h.defaultValue,_)})}transformOn(h,_){return Z({kind:"OnNode",on:this.transformNode(h.on,_)})}transformSelectModifier(h,_){return Z({kind:"SelectModifierNode",modifier:h.modifier,rawModifier:this.transformNode(h.rawModifier,_),of:this.transformNodeList(h.of,_)})}transformCreateType(h,_){return Z({kind:"CreateTypeNode",name:this.transformNode(h.name,_),enum:this.transformNode(h.enum,_)})}transformDropType(h,_){return Z({kind:"DropTypeNode",name:this.transformNode(h.name,_),ifExists:h.ifExists})}transformExplain(h,_){return Z({kind:"ExplainNode",format:h.format,options:this.transformNode(h.options,_)})}transformSchemableIdentifier(h,_){return Z({kind:"SchemableIdentifierNode",schema:this.transformNode(h.schema,_),identifier:this.transformNode(h.identifier,_)})}transformAggregateFunction(h,_){return Z({kind:"AggregateFunctionNode",func:h.func,aggregated:this.transformNodeList(h.aggregated,_),distinct:h.distinct,orderBy:this.transformNode(h.orderBy,_),withinGroup:this.transformNode(h.withinGroup,_),filter:this.transformNode(h.filter,_),over:this.transformNode(h.over,_)})}transformOver(h,_){return Z({kind:"OverNode",orderBy:this.transformNode(h.orderBy,_),partitionBy:this.transformNode(h.partitionBy,_)})}transformPartitionBy(h,_){return Z({kind:"PartitionByNode",items:this.transformNodeList(h.items,_)})}transformPartitionByItem(h,_){return Z({kind:"PartitionByItemNode",partitionBy:this.transformNode(h.partitionBy,_)})}transformBinaryOperation(h,_){return Z({kind:"BinaryOperationNode",leftOperand:this.transformNode(h.leftOperand,_),operator:this.transformNode(h.operator,_),rightOperand:this.transformNode(h.rightOperand,_)})}transformUnaryOperation(h,_){return Z({kind:"UnaryOperationNode",operator:this.transformNode(h.operator,_),operand:this.transformNode(h.operand,_)})}transformUsing(h,_){return Z({kind:"UsingNode",tables:this.transformNodeList(h.tables,_)})}transformFunction(h,_){return Z({kind:"FunctionNode",func:h.func,arguments:this.transformNodeList(h.arguments,_)})}transformCase(h,_){return Z({kind:"CaseNode",value:this.transformNode(h.value,_),when:this.transformNodeList(h.when,_),else:this.transformNode(h.else,_),isStatement:h.isStatement})}transformWhen(h,_){return Z({kind:"WhenNode",condition:this.transformNode(h.condition,_),result:this.transformNode(h.result,_)})}transformJSONReference(h,_){return Z({kind:"JSONReferenceNode",reference:this.transformNode(h.reference,_),traversal:this.transformNode(h.traversal,_)})}transformJSONPath(h,_){return Z({kind:"JSONPathNode",inOperator:this.transformNode(h.inOperator,_),pathLegs:this.transformNodeList(h.pathLegs,_)})}transformJSONPathLeg(h,_){return Z({kind:"JSONPathLegNode",type:h.type,value:h.value})}transformJSONOperatorChain(h,_){return Z({kind:"JSONOperatorChainNode",operator:this.transformNode(h.operator,_),values:this.transformNodeList(h.values,_)})}transformTuple(h,_){return Z({kind:"TupleNode",values:this.transformNodeList(h.values,_)})}transformMergeQuery(h,_){return Z({kind:"MergeQueryNode",into:this.transformNode(h.into,_),using:this.transformNode(h.using,_),whens:this.transformNodeList(h.whens,_),with:this.transformNode(h.with,_),top:this.transformNode(h.top,_),endModifiers:this.transformNodeList(h.endModifiers,_),output:this.transformNode(h.output,_),returning:this.transformNode(h.returning,_)})}transformMatched(h,_){return Z({kind:"MatchedNode",not:h.not,bySource:h.bySource})}transformAddIndex(h,_){return Z({kind:"AddIndexNode",name:this.transformNode(h.name,_),columns:this.transformNodeList(h.columns,_),unique:h.unique,using:this.transformNode(h.using,_),ifNotExists:h.ifNotExists})}transformCast(h,_){return Z({kind:"CastNode",expression:this.transformNode(h.expression,_),dataType:this.transformNode(h.dataType,_)})}transformFetch(h,_){return Z({kind:"FetchNode",rowCount:this.transformNode(h.rowCount,_),modifier:h.modifier})}transformTop(h,_){return Z({kind:"TopNode",expression:h.expression,modifiers:h.modifiers})}transformOutput(h,_){return Z({kind:"OutputNode",selections:this.transformNodeList(h.selections,_)})}transformDataType(h,_){return h}transformSelectAll(h,_){return h}transformIdentifier(h,_){return h}transformValue(h,_){return h}transformPrimitiveValueList(h,_){return h}transformOperator(h,_){return h}transformDefaultInsertValue(h,_){return h}transformOrAction(h,_){return h}transformCollate(h,_){return h}}var J8=k({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),Y8={json_agg:!0,to_json:!0};class vW extends Oh{#h;#_=new Set;#k=new Set;constructor(h){super();this.#h=h}transformNodeImpl(h,_){if(!this.#$(h))return super.transformNodeImpl(h,_);let W=this.#J(h);for(let Y of W)this.#k.add(Y);let $=this.#Z(h);for(let Y of $)this.#_.add(Y);let J=super.transformNodeImpl(h,_);for(let Y of $)this.#_.delete(Y);for(let Y of W)this.#k.delete(Y);return J}transformSchemableIdentifier(h,_){let W=super.transformSchemableIdentifier(h,_);if(W.schema||!this.#_.has(h.identifier.name))return W;return{...W,schema:X.create(this.#h)}}transformReferences(h,_){let W=super.transformReferences(h,_);if(W.table.table.schema)return W;return{...W,table:d.createWithSchema(this.#h,W.table.table.identifier.name)}}transformAggregateFunction(h,_){return{...super.transformAggregateFunction({...h,aggregated:[]},_),aggregated:this.#W(h,_,"aggregated")}}transformFunction(h,_){return{...super.transformFunction({...h,arguments:[]},_),arguments:this.#W(h,_,"arguments")}}transformSelectModifier(h,_){return{...super.transformSelectModifier({...h,of:void 0},_),of:h.of?.map((W)=>d.is(W)&&!W.table.schema?{...W,table:this.transformIdentifier(W.table.identifier,_)}:this.transformNode(W,_))}}#W(h,_,W){return Y8[h.func]?h[W].map(($)=>!d.is($)||$.table.schema?this.transformNode($,_):{...$,table:this.transformIdentifier($.table.identifier,_)}):this.transformNodeList(h[W],_)}#$(h){return h.kind in J8}#Z(h){let _=new Set;if("name"in h&&h.name&&l.is(h.name))this.#G(h.name,_);if("from"in h&&h.from)for(let W of h.from.froms)this.#Y(W,_);if("into"in h&&h.into)this.#Y(h.into,_);if("table"in h&&h.table)this.#Y(h.table,_);if("joins"in h&&h.joins)for(let W of h.joins)this.#Y(W.table,_);if("using"in h&&h.using)if(Vh.is(h.using))this.#Y(h.using.table,_);else this.#Y(h.using,_);return _}#J(h){let _=new Set;if("with"in h&&h.with)this.#H(h.with,_);return _}#Y(h,_){if(d.is(h))return this.#G(h.table,_);if(I.is(h)&&d.is(h.node))return this.#G(h.node.table,_);if(Sk.is(h)){for(let W of h.items)this.#Y(W,_);return}if(kk.is(h)){for(let W of h.tables)this.#Y(W,_);return}}#G(h,_){let W=h.identifier.name;if(!this.#_.has(W)&&!this.#k.has(W))_.add(W)}#H(h,_){for(let W of h.expressions){let $=W.name.table.table.identifier.name;if(!this.#k.has($))_.add($)}}}class Zh{#h;constructor(h){this.#h=new vW(h)}transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}async transformResult(h){return h.result}}var u$=k({is(h){return h.kind==="MatchedNode"},create(h,_=!1){return k({kind:"MatchedNode",not:h,bySource:_})}});function PW(h,_,W){return Hh.create(E_([u$.create(!h.isMatched,h.bySource),..._&&_.length>0?[_.length===3&&W?g(_[0],_[1],_[2]):A(_)]:[]],"and",!1))}function m_(h){if(M(h))return V.create([h],[]);if(T(h))return h.toOperationNode();return h}class Z_{#h;#_;#k;constructor(){this.#h=new Promise((h,_)=>{this.#k=_,this.#_=h})}get promise(){return this.#h}resolve=(h)=>{if(this.#_)this.#_(h)};reject=(h)=>{if(this.#k)this.#k(h)}}async function jk(h){let _=new Z_,W=new Z_;return h.provideConnection(async($)=>{return _.resolve($),await W.promise}).catch(($)=>_.reject($)),k({connection:await _.promise,release:W.resolve})}var Z8=k([]);class Zk{#h;constructor(h=Z8){this.#h=h}get plugins(){return this.#h}transformQuery(h,_){for(let W of this.#h){let $=W.transformQuery({node:h,queryId:_});if($.kind===h.kind)h=$;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${h.kind}`,`but it returned a ${$.kind}`].join(" "))}return h}async executeQuery(h){return await this.provideConnection(async(_)=>{let W=await _.executeQuery(h);if("numUpdatedOrDeletedRows"in W)Rh("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#_(W,h.queryId)})}async*stream(h,_){let{connection:W,release:$}=await jk(this);try{for await(let J of W.streamQuery(h,_))yield await this.#_(J,h.queryId)}finally{$()}}async#_(h,_){for(let W of this.#h)h=await W.transformResult({result:h,queryId:_});return h}}class Q_ extends Zk{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(h){return new Q_([...this.plugins,h])}withPlugins(h){return new Q_([...this.plugins,...h])}withPluginAtFront(h){return new Q_([h,...this.plugins])}withoutPlugins(){return new Q_([])}}var G_=new Q_;class DW{numChangedRows;constructor(h){this.numChangedRows=h}}class lh{#h;constructor(h){this.#h=k(h)}modifyEnd(h){return new lh({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}top(h,_){return new lh({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}using(...h){return new e({...this.#h,queryNode:Yh.cloneWithUsing(this.#h.queryNode,Y_("Using",h))})}returning(h){return new lh({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new lh({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new lh({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new lh({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}}class e{#h;constructor(h){this.#h=k(h)}modifyEnd(h){return new e({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}top(h,_){return new e({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}whenMatched(){return this.#_([])}whenMatchedAnd(...h){return this.#_(h)}whenMatchedAndRef(h,_,W){return this.#_([h,_,W],!0)}#_(h,_){return new OW({...this.#h,queryNode:Yh.cloneWithWhen(this.#h.queryNode,PW({isMatched:!0},h,_))})}whenNotMatched(){return this.#k([])}whenNotMatchedAnd(...h){return this.#k(h)}whenNotMatchedAndRef(h,_,W){return this.#k([h,_,W],!0)}whenNotMatchedBySource(){return this.#k([],!1,!0)}whenNotMatchedBySourceAnd(...h){return this.#k(h,!1,!0)}whenNotMatchedBySourceAndRef(h,_,W){return this.#k([h,_,W],!0,!0)}returning(h){return new e({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new e({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new e({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new e({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}#k(h,_=!1,W=!1){let $={...this.#h,queryNode:Yh.cloneWithWhen(this.#h.queryNode,PW({isMatched:!1,bySource:W},h,_))};return new(W?OW:l$)($)}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new e({...this.#h})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new DW(_.numAffectedRows)]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=vh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}}class OW{#h;constructor(h){this.#h=k(h)}thenDelete(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("delete"))})}thenDoNothing(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("do nothing"))})}thenUpdate(h){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_(h(new E({queryId:this.#h.queryId,executor:G_,queryNode:jh.createWithoutTable()}))))})}thenUpdateSet(...h){return this.thenUpdate((_)=>_.set(...h))}}class l${#h;constructor(h){this.#h=k(h)}thenDoNothing(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("do nothing"))})}thenInsertValues(h){let[_,W]=xk(h);return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_(m.cloneWith(m.createWithoutInto(),{columns:_,values:W})))})}}class bh{#h;constructor(h){this.#h=k(h)}selectFrom(h){return b_({queryId:L(),executor:this.#h.executor,queryNode:w.createFrom(Dh(h),this.#h.withNode)})}selectNoFrom(h){return b_({queryId:L(),executor:this.#h.executor,queryNode:w.cloneWithSelections(w.create(this.#h.withNode),B(h))})}insertInto(h){return new D({queryId:L(),executor:this.#h.executor,queryNode:m.create(f(h),this.#h.withNode)})}replaceInto(h){return new D({queryId:L(),executor:this.#h.executor,queryNode:m.create(f(h),this.#h.withNode,!0)})}deleteFrom(h){return new j({queryId:L(),executor:this.#h.executor,queryNode:J_.create(Dh(h),this.#h.withNode)})}updateTable(h){return new E({queryId:L(),executor:this.#h.executor,queryNode:jh.create(Dh(h),this.#h.withNode)})}mergeInto(h){return new lh({queryId:L(),executor:this.#h.executor,queryNode:Yh.create(AW(h),this.#h.withNode)})}with(h,_){let W=RW(h,_);return new bh({...this.#h,withNode:this.#h.withNode?Yk.cloneWithExpression(this.#h.withNode,W):Yk.create(W)})}withRecursive(h,_){let W=RW(h,_);return new bh({...this.#h,withNode:this.#h.withNode?Yk.cloneWithExpression(this.#h.withNode,W):Yk.create(W,{recursive:!0})})}withPlugin(h){return new bh({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new bh({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new bh({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}}function y$(){return new bh({executor:G_})}function p$(h,_){return new S_({joinNode:Vh.create(h,F_(_))})}function a$(){return new N_({overNode:_k.create()})}function Y_(h,_){if(_.length===3)return H8(h,_[0],_[1],_[2]);else if(_.length===2)return G8(h,_[0],_[1]);else if(_.length===1)return X8(h,_[0]);else throw Error("not implemented")}function G8(h,_,W){return W(p$(h,_)).toOperationNode()}function H8(h,_,W,$){return Vh.createWithOn(h,F_(_),g(W,"=",$))}function X8(h,_){return Vh.create(h,F_(_))}var s$=k({is(h){return h.kind==="OffsetNode"},create(h){return k({kind:"OffsetNode",offset:h})}});var n$=k({is(h){return h.kind==="GroupByItemNode"},create(h){return k({kind:"GroupByItemNode",groupBy:h})}});function d$(h){return h=R(h)?h(Xh()):h,ih(h).map(n$.create)}var mk=k({is(h){return h.kind==="SetOperationNode"},create(h,_,W){return k({kind:"SetOperationNode",operator:h,expression:_,all:W})}});function U_(h,_,W){if(R(_))_=_(Qk());if(!q(_))_=[_];return _.map(($)=>mk.create(h,o($),W))}class v{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}or(...h){return new bk(Uh.create(this.#h,A(h)))}and(...h){return new Bk(r.create(this.#h,A(h)))}$castTo(){return new v(this.#h)}$notNull(){return new v(this.#h)}toOperationNode(){return this.#h}}class qk{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}class bk{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}or(...h){return new bk(Uh.create(this.#h,A(h)))}$castTo(){return new bk(this.#h)}toOperationNode(){return Jh.create(this.#h)}}class Bk{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}and(...h){return new Bk(r.create(this.#h,A(h)))}$castTo(){return new Bk(this.#h)}toOperationNode(){return Jh.create(this.#h)}}var r$=k({is(h){return h.kind==="FetchNode"},create(h,_){return{kind:"FetchNode",rowCount:C.create(h),modifier:_}}});function o$(h,_){if(!Mh(h)&&!__(h))throw Error(`Invalid fetch row count: ${h}`);if(!L8(_))throw Error(`Invalid fetch modifier: ${_}`);return r$.create(h,_)}function L8(h){return h==="only"||h==="with ties"}class z{#h;constructor(h){this.#h=k(h)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...h){return new z({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new z({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}having(...h){return new z({...this.#h,queryNode:w.cloneWithHaving(this.#h.queryNode,A(h))})}havingRef(h,_,W){return new z({...this.#h,queryNode:w.cloneWithHaving(this.#h.queryNode,g(h,_,W))})}select(h){return new z({...this.#h,queryNode:w.cloneWithSelections(this.#h.queryNode,B(h))})}distinctOn(h){return new z({...this.#h,queryNode:w.cloneWithDistinctOn(this.#h.queryNode,ih(h))})}modifyFront(h){return new z({...this.#h,queryNode:w.cloneWithFrontModifier(this.#h.queryNode,Ch.createWithExpression(h.toOperationNode()))})}modifyEnd(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.createWithExpression(h.toOperationNode()))})}distinct(){return new z({...this.#h,queryNode:w.cloneWithFrontModifier(this.#h.queryNode,Ch.create("Distinct"))})}forUpdate(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("ForUpdate",h?r_(h).map(f):void 0))})}forShare(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("ForShare",h?r_(h).map(f):void 0))})}forKeyShare(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("ForKeyShare",h?r_(h).map(f):void 0))})}forNoKeyUpdate(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("ForNoKeyUpdate",h?r_(h).map(f):void 0))})}skipLocked(){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("SkipLocked"))})}noWait(){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,Ch.create("NoWait"))})}selectAll(h){return new z({...this.#h,queryNode:w.cloneWithSelections(this.#h.queryNode,c(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}crossJoin(...h){return this.#_("CrossJoin",h)}innerJoinLateral(...h){return this.#_("LateralInnerJoin",h)}leftJoinLateral(...h){return this.#_("LateralLeftJoin",h)}crossJoinLateral(...h){return this.#_("LateralCrossJoin",h)}crossApply(...h){return this.#_("CrossApply",h)}outerApply(...h){return this.#_("OuterApply",h)}#_(h,_){return new z({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}orderBy(...h){return new z({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}groupBy(h){return new z({...this.#h,queryNode:w.cloneWithGroupByItems(this.#h.queryNode,d$(h))})}limit(h){return new z({...this.#h,queryNode:w.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}offset(h){return new z({...this.#h,queryNode:w.cloneWithOffset(this.#h.queryNode,s$.create(P(h)))})}fetch(h,_="only"){return new z({...this.#h,queryNode:w.cloneWithFetch(this.#h.queryNode,o$(h,_))})}top(h,_){return new z({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,Ph(h,_))})}union(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("union",h,!1))})}unionAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("union",h,!0))})}intersect(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("intersect",h,!1))})}intersectAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("intersect",h,!0))})}except(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("except",h,!1))})}exceptAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("except",h,!0))})}as(h){return new e$(this,h)}clearSelect(){return new z({...this.#h,queryNode:w.cloneWithoutSelections(this.#h.queryNode)})}clearWhere(){return new z({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}clearLimit(){return new z({...this.#h,queryNode:w.cloneWithoutLimit(this.#h.queryNode)})}clearOffset(){return new z({...this.#h,queryNode:w.cloneWithoutOffset(this.#h.queryNode)})}clearOrderBy(){return new z({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}clearGroupBy(){return new z({...this.#h,queryNode:w.cloneWithoutGroupBy(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new z({...this.#h})}$castTo(){return new z(this.#h)}$narrowType(){return new z(this.#h)}$assertType(){return new z(this.#h)}$asTuple(){return new v(this.toOperationNode())}$asScalar(){return new v(this.toOperationNode())}withPlugin(h){return new z({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile();return(await this.#h.executor.executeQuery(h)).rows}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=vh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new z({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}function b_(h){return new z(h)}class e${#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#h.toOperationNode(),X.create(this.#_))}}var Bh=k({is(h){return h.kind==="AggregateFunctionNode"},create(h,_=[]){return k({kind:"AggregateFunctionNode",func:h,aggregated:_})},cloneWithDistinct(h){return k({...h,distinct:!0})},cloneWithOrderBy(h,_,W=!1){let $=W?"withinGroup":"orderBy";return k({...h,[$]:h[$]?uh.cloneWithItems(h[$],_):uh.create(_)})},cloneWithFilter(h,_){return k({...h,filter:h.filter?i.cloneWithOperation(h.filter,"And",_):i.create(_)})},cloneWithOrFilter(h,_){return k({...h,filter:h.filter?i.cloneWithOperation(h.filter,"Or",_):i.create(_)})},cloneWithOver(h,_){return k({...h,over:_})}});var TW=k({is(h){return h.kind==="FunctionNode"},create(h,_){return k({kind:"FunctionNode",func:h,arguments:_})}});class hh{#h;constructor(h){this.#h=k(h)}get expressionType(){return}as(h){return new h1(this,h)}distinct(){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithDistinct(this.#h.aggregateFunctionNode)})}orderBy(...h){return new hh({...this.#h,aggregateFunctionNode:G.cloneWithOrderByItems(this.#h.aggregateFunctionNode,Wh(h))})}clearOrderBy(){return new hh({...this.#h,aggregateFunctionNode:G.cloneWithoutOrderBy(this.#h.aggregateFunctionNode)})}withinGroupOrderBy(...h){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithOrderBy(this.#h.aggregateFunctionNode,Wh(h),!0)})}filterWhere(...h){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithFilter(this.#h.aggregateFunctionNode,A(h))})}filterWhereRef(h,_,W){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithFilter(this.#h.aggregateFunctionNode,g(h,_,W))})}over(h){let _=a$();return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithOver(this.#h.aggregateFunctionNode,(h?h(_):_).toOperationNode())})}$call(h){return h(this)}$castTo(){return new hh(this.#h)}$notNull(){return new hh(this.#h)}toOperationNode(){return this.#h.aggregateFunctionNode}}class h1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),X.create(this.#_))}}function Ik(){let h=(W,$)=>{return new v(TW.create(W,ih($??[])))},_=(W,$)=>{return new hh({aggregateFunctionNode:Bh.create(W,$?ih($):void 0)})};return Object.assign(h,{agg:_,avg(W){return _("avg",[W])},coalesce(...W){return h("coalesce",W)},count(W){return _("count",[W])},countAll(W){return new hh({aggregateFunctionNode:Bh.create("count",c(W))})},max(W){return _("max",[W])},min(W){return _("min",[W])},sum(W){return _("sum",[W])},any(W){return h("any",[W])},jsonAgg(W){return new hh({aggregateFunctionNode:Bh.create("json_agg",[M(W)?f(W):W.toOperationNode()])})},toJson(W){return new v(TW.create("to_json",[M(W)?f(W):W.toOperationNode()]))}})}var _1=k({is(h){return h.kind==="UnaryOperationNode"},create(h,_){return k({kind:"UnaryOperationNode",operator:h,operand:_})}});function k1(h,_){return _1.create(y.create(h),t(_))}var Gh=k({is(h){return h.kind==="CaseNode"},create(h){return k({kind:"CaseNode",value:h})},cloneWithWhen(h,_){return k({...h,when:k(h.when?[...h.when,_]:[_])})},cloneWithThen(h,_){return k({...h,when:h.when?k([...h.when.slice(0,-1),Hh.cloneWithResult(h.when[h.when.length-1],_)]):void 0})},cloneWith(h,_){return k({...h,..._})}});class Gk{#h;constructor(h){this.#h=k(h)}when(...h){return new EW({...this.#h,node:Gh.cloneWithWhen(this.#h.node,Hh.create(A(h)))})}}class EW{#h;constructor(h){this.#h=k(h)}then(h){return new W1({...this.#h,node:Gh.cloneWithThen(this.#h.node,Tk(h)?hk(h):P(h))})}}class W1{#h;constructor(h){this.#h=k(h)}when(...h){return new EW({...this.#h,node:Gh.cloneWithWhen(this.#h.node,Hh.create(A(h)))})}else(h){return new $1({...this.#h,node:Gh.cloneWith(this.#h.node,{else:Tk(h)?hk(h):P(h)})})}end(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!1}))}endCase(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!0}))}}class $1{#h;constructor(h){this.#h=k(h)}end(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!1}))}endCase(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!0}))}}var SW=k({is(h){return h.kind==="JSONPathLegNode"},create(h,_){return k({kind:"JSONPathLegNode",type:h,value:_})}});class Xk{#h;constructor(h){this.#h=h}at(h){return this.#_("ArrayLocation",h)}key(h){return this.#_("Member",h)}#_(h,_){if(O_.is(this.#h))return new Hk(O_.cloneWithTraversal(this.#h,$_.is(this.#h.traversal)?$_.cloneWithLeg(this.#h.traversal,SW.create(h,_)):Ak.cloneWithValue(this.#h.traversal,C.createImmediate(_))));return new Hk($_.cloneWithLeg(this.#h,SW.create(h,_)))}}class Hk extends Xk{#h;constructor(h){super(h);this.#h=h}get expressionType(){return}as(h){return new J1(this,h)}$castTo(){return new Hk(this.#h)}$notNull(){return new Hk(this.#h)}toOperationNode(){return this.#h}}class J1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}var NW=k({is(h){return h.kind==="TupleNode"},create(h){return k({kind:"TupleNode",values:k(h)})}});var z8=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],K8=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],gk=k({is(h){return h.kind==="DataTypeNode"},create(h){return k({kind:"DataTypeNode",dataType:h})}});function Y1(h){if(z8.includes(h))return!0;if(K8.some((_)=>_.test(h)))return!0;return!1}function Ah(h){if(T(h))return h.toOperationNode();if(Y1(h))return gk.create(h);throw Error(`invalid column data type ${JSON.stringify(h)}`)}var ck=k({is(h){return h.kind==="CastNode"},create(h,_){return k({kind:"CastNode",expression:h,dataType:_})}});function Qk(h=G_){function _(J,Y,H){return new v(Ek(J,Y,H))}function W(J,Y){return new v(k1(J,Y))}let $=Object.assign(_,{fn:void 0,eb:void 0,selectFrom(J){return b_({queryId:L(),executor:h,queryNode:w.createFrom(Dh(J))})},case(J){return new Gk({node:Gh.create(a(J)?void 0:t(J))})},ref(J,Y){if(a(Y))return new v(kh(J));return new Xk(O$(J,Y))},jsonPath(){return new Xk($_.create())},table(J){return new v(f(J))},val(J){return new v(P(J))},refTuple(...J){return new v(NW.create(J.map(t)))},tuple(...J){return new v(NW.create(J.map(P)))},lit(J){return new v(hk(J))},unary:W,not(J){return W("not",J)},exists(J){return W("exists",J)},neg(J){return W("-",J)},between(J,Y,H){return new v(fh.create(t(J),y.create("between"),r.create(P(Y),P(H))))},betweenSymmetric(J,Y,H){return new v(fh.create(t(J),y.create("between symmetric"),r.create(P(Y),P(H))))},and(J){if(q(J))return new v(E_(J,"and"));return new v(HW(J,"and"))},or(J){if(q(J))return new v(E_(J,"or"));return new v(HW(J,"or"))},parens(...J){let Y=A(J);if(Jh.is(Y))return new v(Y);else return new v(Jh.create(Y))},cast(J,Y){return new v(ck.create(t(J),Ah(Y)))},withSchema(J){return Qk(h.withPluginAtFront(new Zh(J)))}});return $.fn=Ik(),$.eb=$,$}function Xh(h){return Qk()}function o(h){if(T(h))return h.toOperationNode();else if(R(h))return h(Xh()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(h)}`)}function Nk(h){if(T(h))return h.toOperationNode();else if(R(h))return h(Xh()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(h)}`)}function th(h){return Pk(h)||U$(h)||R(h)}class xW{#h;get table(){return this.#h}constructor(h){this.#h=h}as(h){return new Z1(this.#h,h)}}class Z1{#h;#_;get table(){return this.#h}get alias(){return this.#_}constructor(h,_){this.#h=h,this.#_=_}toOperationNode(){return I.create(f(this.#h),X.create(this.#_))}}function G1(h){return O(h)&&T(h)&&M(h.table)&&M(h.alias)}function Dh(h){if(q(h))return h.map((_)=>F_(_));else return[F_(h)]}function F_(h){if(M(h))return AW(h);else if(G1(h))return h.toOperationNode();else return Nk(h)}function AW(h){if(h.includes(" as ")){let[W,$]=h.split(" as ").map(H1);return I.create(f(W),X.create($))}else return f(h)}function f(h){if(h.includes(".")){let[W,$]=h.split(".").map(H1);return d.createWithSchema(W,$)}else return d.create(h)}function H1(h){return h.trim()}var CW=k({is(h){return h.kind==="AddColumnNode"},create(h){return k({kind:"AddColumnNode",column:h})}});var S=k({is(h){return h.kind==="ColumnDefinitionNode"},create(h,_){return k({kind:"ColumnDefinitionNode",column:F.create(h),dataType:_})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):[_]})},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):[_]})},cloneWith(h,_){return k({...h,..._})}});var jW=k({is(h){return h.kind==="DropColumnNode"},create(h){return k({kind:"DropColumnNode",column:F.create(h)})}});var mW=k({is(h){return h.kind==="RenameColumnNode"},create(h,_){return k({kind:"RenameColumnNode",column:F.create(h),renameTo:F.create(_)})}});var B_=k({is(h){return h.kind==="CheckConstraintNode"},create(h,_){return k({kind:"CheckConstraintNode",expression:h,name:_?X.create(_):void 0})}});var X1=["no action","restrict","cascade","set null","set default"],q_=k({is(h){return h.kind==="ReferencesNode"},create(h,_){return k({kind:"ReferencesNode",table:h,columns:k([..._])})},cloneWithOnDelete(h,_){return k({...h,onDelete:_})},cloneWithOnUpdate(h,_){return k({...h,onUpdate:_})}});function yk(h){return T(h)?h.toOperationNode():C.createImmediate(h)}var Lk=k({is(h){return h.kind==="GeneratedNode"},create(h){return k({kind:"GeneratedNode",...h})},createWithExpression(h){return k({kind:"GeneratedNode",always:!0,expression:h})},cloneWith(h,_){return k({...h,..._})}});var L1=k({is(h){return h.kind==="DefaultValueNode"},create(h){return k({kind:"DefaultValueNode",defaultValue:h})}});function I_(h){if(X1.includes(h))return h;throw Error(`invalid OnModifyForeignAction ${h}`)}class N{#h;constructor(h){this.#h=h}autoIncrement(){return new N(S.cloneWith(this.#h,{autoIncrement:!0}))}identity(){return new N(S.cloneWith(this.#h,{identity:!0}))}primaryKey(){return new N(S.cloneWith(this.#h,{primaryKey:!0}))}references(h){let _=kh(h);if(!_.table||P_.is(_.column))throw Error(`invalid call references('${h}'). The reference must have format table.column or schema.table.column`);return new N(S.cloneWith(this.#h,{references:q_.create(_.table,[_.column])}))}onDelete(h){if(!this.#h.references)throw Error("on delete constraint can only be added for foreign keys");return new N(S.cloneWith(this.#h,{references:q_.cloneWithOnDelete(this.#h.references,I_(h))}))}onUpdate(h){if(!this.#h.references)throw Error("on update constraint can only be added for foreign keys");return new N(S.cloneWith(this.#h,{references:q_.cloneWithOnUpdate(this.#h.references,I_(h))}))}unique(){return new N(S.cloneWith(this.#h,{unique:!0}))}notNull(){return new N(S.cloneWith(this.#h,{notNull:!0}))}unsigned(){return new N(S.cloneWith(this.#h,{unsigned:!0}))}defaultTo(h){return new N(S.cloneWith(this.#h,{defaultTo:L1.create(yk(h))}))}check(h){return new N(S.cloneWith(this.#h,{check:B_.create(h.toOperationNode())}))}generatedAlwaysAs(h){return new N(S.cloneWith(this.#h,{generated:Lk.createWithExpression(h.toOperationNode())}))}generatedAlwaysAsIdentity(){return new N(S.cloneWith(this.#h,{generated:Lk.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new N(S.cloneWith(this.#h,{generated:Lk.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#h.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new N(S.cloneWith(this.#h,{generated:Lk.cloneWith(this.#h.generated,{stored:!0})}))}modifyFront(h){return new N(S.cloneWithFrontModifier(this.#h,h.toOperationNode()))}nullsNotDistinct(){return new N(S.cloneWith(this.#h,{nullsNotDistinct:!0}))}ifNotExists(){return new N(S.cloneWith(this.#h,{ifNotExists:!0}))}modifyEnd(h){return new N(S.cloneWithEndModifier(this.#h,h.toOperationNode()))}$call(h){return h(this)}toOperationNode(){return this.#h}}var QW=k({is(h){return h.kind==="ModifyColumnNode"},create(h){return k({kind:"ModifyColumnNode",column:h})}});var Th=k({is(h){return h.kind==="ForeignKeyConstraintNode"},create(h,_,W,$){return k({kind:"ForeignKeyConstraintNode",columns:h,references:q_.create(_,W),name:$?X.create($):void 0})},cloneWith(h,_){return k({...h,..._})}});class Eh{#h;constructor(h){this.#h=h}onDelete(h){return new Eh(Th.cloneWith(this.#h,{onDelete:I_(h)}))}onUpdate(h){return new Eh(Th.cloneWith(this.#h,{onUpdate:I_(h)}))}deferrable(){return new Eh(Th.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new Eh(Th.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new Eh(Th.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new Eh(Th.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}var g_=k({is(h){return h.kind==="AddConstraintNode"},create(h){return k({kind:"AddConstraintNode",constraint:h})}});var qh=k({is(h){return h.kind==="UniqueConstraintNode"},create(h,_,W){return k({kind:"UniqueConstraintNode",columns:k(h.map(F.create)),name:_?X.create(_):void 0,nullsNotDistinct:W})},cloneWith(h,_){return k({...h,..._})}});var c_=k({is(h){return h.kind==="DropConstraintNode"},create(h){return k({kind:"DropConstraintNode",constraintName:X.create(h)})},cloneWith(h,_){return k({...h,..._})}});var y_=k({is(h){return h.kind==="AlterColumnNode"},create(h,_,W){return k({kind:"AlterColumnNode",column:F.create(h),[_]:W})}});class tk{#h;constructor(h){this.#h=h}setDataType(h){return new t_(y_.create(this.#h,"dataType",Ah(h)))}setDefault(h){return new t_(y_.create(this.#h,"setDefault",yk(h)))}dropDefault(){return new t_(y_.create(this.#h,"dropDefault",!0))}setNotNull(){return new t_(y_.create(this.#h,"setNotNull",!0))}dropNotNull(){return new t_(y_.create(this.#h,"dropNotNull",!0))}$call(h){return h(this)}}class t_{#h;constructor(h){this.#h=h}toOperationNode(){return this.#h}}class H_{#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class ph{#h;constructor(h){this.#h=k(h)}onDelete(h){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.onDelete(h)})}onUpdate(h){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.onUpdate(h)})}deferrable(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.deferrable()})}notDeferrable(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.initiallyImmediate()})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create(this.#h.constraintBuilder.toOperationNode())}),this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class V_{#h;constructor(h){this.#h=k(h)}ifExists(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{ifExists:!0})})})}cascade(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{modifier:"restrict"})})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var Ih=k({is(h){return h.kind==="PrimaryKeyConstraintNode"},create(h,_){return k({kind:"PrimaryKeyConstraintNode",columns:k(h.map(F.create)),name:_?X.create(_):void 0})},cloneWith(h,_){return k({...h,..._})}}),J2=Ih;var X_=k({is(h){return h.kind==="AddIndexNode"},create(h){return k({kind:"AddIndexNode",name:X.create(h)})},cloneWith(h,_){return k({...h,..._})},cloneWithColumns(h,_){return k({...h,columns:[...h.columns||[],..._]})}});class L_{#h;constructor(h){this.#h=k(h)}unique(){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWith(this.#h.node.addIndex,{unique:!0})})})}column(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,[A_(h)])})})}columns(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,h.map(A_))})})}expression(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,[h.toOperationNode()])})})}using(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWith(this.#h.node.addIndex,{using:V.createWithSql(h)})})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class gh{#h;constructor(h){this.#h=h}nullsNotDistinct(){return new gh(qh.cloneWith(this.#h,{nullsNotDistinct:!0}))}deferrable(){return new gh(qh.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new gh(qh.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new gh(qh.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new gh(qh.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}class ah{#h;constructor(h){this.#h=h}deferrable(){return new ah(Ih.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new ah(Ih.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new ah(Ih.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new ah(Ih.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}class zk{#h;constructor(h){this.#h=h}$call(h){return h(this)}toOperationNode(){return this.#h}}var z1=k({is(h){return h.kind==="RenameConstraintNode"},create(h,_){return k({kind:"RenameConstraintNode",oldName:X.create(h),newName:X.create(_)})}});class bW{#h;constructor(h){this.#h=k(h)}renameTo(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{renameTo:f(h)})})}setSchema(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{setSchema:X.create(h)})})}alterColumn(h,_){let W=_(new tk(h));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,W.toOperationNode())})}dropColumn(h){return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,jW.create(h))})}renameColumn(h,_){return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,mW.create(h,_))})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Ah(_))));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,CW.create($.toOperationNode()))})}modifyColumn(h,_,W=s){let $=W(new N(S.create(h,Ah(_))));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,QW.create($.toOperationNode()))})}addUniqueConstraint(h,_,W=s){let $=W(new gh(qh.create(_,h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}addCheckConstraint(h,_,W=s){let $=W(new zk(B_.create(_.toOperationNode(),h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}addForeignKeyConstraint(h,_,W,$,J=s){let Y=J(new Eh(Th.create(_.map(F.create),f(W),$.map(F.create),h)));return new ph({...this.#h,constraintBuilder:Y})}addPrimaryKeyConstraint(h,_,W=s){let $=W(new ah(Ih.create(_,h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}dropConstraint(h){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.create(h)})})}renameConstraint(h,_){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{renameConstraint:z1.create(h,_)})})}addIndex(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.create(h)})})}dropIndex(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropIndex:k_.create(h)})})}$call(h){return h(this)}}class Sh{#h;constructor(h){this.#h=k(h)}alterColumn(h,_){let W=_(new tk(h));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,W.toOperationNode())})}dropColumn(h){return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,jW.create(h))})}renameColumn(h,_){return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,mW.create(h,_))})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Ah(_))));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,CW.create($.toOperationNode()))})}modifyColumn(h,_,W=s){let $=W(new N(S.create(h,Ah(_))));return new Sh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,QW.create($.toOperationNode()))})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Kk extends Oh{transformPrimitiveValueList(h){return $h.create(h.values.map(C.createImmediate))}transformValue(h){return C.createImmediate(h.value)}}class Lh{#h;constructor(h){this.#h=k(h)}ifNotExists(){return new Lh({...this.#h,node:Fh.cloneWith(this.#h.node,{ifNotExists:!0})})}unique(){return new Lh({...this.#h,node:Fh.cloneWith(this.#h.node,{unique:!0})})}nullsNotDistinct(){return new Lh({...this.#h,node:Fh.cloneWith(this.#h.node,{nullsNotDistinct:!0})})}on(h){return new Lh({...this.#h,node:Fh.cloneWith(this.#h.node,{table:f(h)})})}column(h){return new Lh({...this.#h,node:Fh.cloneWithColumns(this.#h.node,[A_(h)])})}columns(h){return new Lh({...this.#h,node:Fh.cloneWithColumns(this.#h.node,h.map(A_))})}expression(h){return new Lh({...this.#h,node:Fh.cloneWithColumns(this.#h.node,[h.toOperationNode()])})}using(h){return new Lh({...this.#h,node:Fh.cloneWith(this.#h.node,{using:V.createWithSql(h)})})}where(...h){let _=new Kk;return new Lh({...this.#h,node:G.cloneWithWhere(this.#h.node,_.transformNode(A(h),this.#h.queryId))})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class ik{#h;constructor(h){this.#h=k(h)}ifNotExists(){return new ik({...this.#h,node:vk.cloneWith(this.#h.node,{ifNotExists:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}function K1(h){if(F$.includes(h))return h;throw Error(`invalid OnCommitAction ${h}`)}class _h{#h;constructor(h){this.#h=k(h)}temporary(){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{temporary:!0})})}onCommit(h){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{onCommit:K1(h)})})}ifNotExists(){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{ifNotExists:!0})})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Ah(_))));return new _h({...this.#h,node:u.cloneWithColumn(this.#h.node,$.toOperationNode())})}addPrimaryKeyConstraint(h,_,W=s){let $=W(new ah(Ih.create(_,h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addUniqueConstraint(h,_,W=s){let $=W(new gh(qh.create(_,h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addCheckConstraint(h,_,W=s){let $=W(new zk(B_.create(_.toOperationNode(),h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addForeignKeyConstraint(h,_,W,$,J=s){let Y=J(new Eh(Th.create(_.map(F.create),f(W),$.map(F.create),h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,Y.toOperationNode())})}modifyFront(h){return new _h({...this.#h,node:u.cloneWithFrontModifier(this.#h.node,h.toOperationNode())})}modifyEnd(h){return new _h({...this.#h,node:u.cloneWithEndModifier(this.#h.node,h.toOperationNode())})}as(h){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{selectQuery:o(h)})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class i_{#h;constructor(h){this.#h=k(h)}on(h){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{table:f(h)})})}ifExists(){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Mk{#h;constructor(h){this.#h=k(h)}ifExists(){return new Mk({...this.#h,node:o_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new Mk({...this.#h,node:o_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Fk{#h;constructor(h){this.#h=k(h)}ifExists(){return new Fk({...this.#h,node:e_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new Fk({...this.#h,node:e_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var Nh=k({is(h){return h.kind==="CreateViewNode"},create(h){return k({kind:"CreateViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class BW{#h=new Kk;transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}transformResult(h){return Promise.resolve(h.result)}}class sh{#h;constructor(h){this.#h=k(h)}temporary(){return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{temporary:!0})})}materialized(){return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{materialized:!0})})}ifNotExists(){return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{ifNotExists:!0})})}orReplace(){return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{orReplace:!0})})}columns(h){return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{columns:h.map(YW)})})}as(h){let _=h.withPlugin(new BW).toOperationNode();return new sh({...this.#h,node:Nh.cloneWith(this.#h.node,{as:_})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var u_=k({is(h){return h.kind==="DropViewNode"},create(h){return k({kind:"DropViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class l_{#h;constructor(h){this.#h=k(h)}materialized(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{materialized:!0})})}ifExists(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var uk=k({is(h){return h.kind==="CreateTypeNode"},create(h){return k({kind:"CreateTypeNode",name:h})},cloneWithEnum(h,_){return k({...h,enum:$h.create(_.map(C.createImmediate))})}});class lk{#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}asEnum(h){return new lk({...this.#h,node:uk.cloneWithEnum(this.#h.node,h)})}$call(h){return h(this)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var pk=k({is(h){return h.kind==="DropTypeNode"},create(h){return k({kind:"DropTypeNode",name:h})},cloneWith(h,_){return k({...h,..._})}});class ak{#h;constructor(h){this.#h=k(h)}ifExists(){return new ak({...this.#h,node:pk.cloneWith(this.#h.node,{ifExists:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}function qW(h){if(h.includes(".")){let W=h.split(".").map(M8);if(W.length===2)return l.createWithSchema(W[0],W[1]);else throw Error(`invalid schemable identifier ${h}`)}else return l.create(h)}function M8(h){return h.trim()}var p_=k({is(h){return h.kind==="RefreshMaterializedViewNode"},create(h){return k({kind:"RefreshMaterializedViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class a_{#h;constructor(h){this.#h=k(h)}concurrently(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{concurrently:!0,withNoData:!1})})}withData(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{withNoData:!1})})}withNoData(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{withNoData:!0,concurrently:!1})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class s_{#h;constructor(h){this.#h=h}createTable(h){return new _h({queryId:L(),executor:this.#h,node:u.create(f(h))})}dropTable(h){return new Fk({queryId:L(),executor:this.#h,node:e_.create(f(h))})}createIndex(h){return new Lh({queryId:L(),executor:this.#h,node:Fh.create(h)})}dropIndex(h){return new i_({queryId:L(),executor:this.#h,node:k_.create(h)})}createSchema(h){return new ik({queryId:L(),executor:this.#h,node:vk.create(h)})}dropSchema(h){return new Mk({queryId:L(),executor:this.#h,node:o_.create(h)})}alterTable(h){return new bW({queryId:L(),executor:this.#h,node:U.create(f(h))})}createView(h){return new sh({queryId:L(),executor:this.#h,node:Nh.create(h)})}refreshMaterializedView(h){return new a_({queryId:L(),executor:this.#h,node:p_.create(h)})}dropView(h){return new l_({queryId:L(),executor:this.#h,node:u_.create(h)})}createType(h){return new lk({queryId:L(),executor:this.#h,node:uk.create(qW(h))})}dropType(h){return new ak({queryId:L(),executor:this.#h,node:pk.create(qW(h))})}withPlugin(h){return new s_(this.#h.withPlugin(h))}withoutPlugins(){return new s_(this.#h.withoutPlugins())}withSchema(h){return new s_(this.#h.withPluginAtFront(new Zh(h)))}}class IW{ref(h){return new kW(h)}table(h){return new xW(h)}}class gW{#h;constructor(h){this.#h=h}async provideConnection(h){let _=await this.#h.acquireConnection();try{return await h(_)}finally{await this.#h.releaseConnection(_)}}}class z_ extends Zk{#h;#_;#k;constructor(h,_,W,$=[]){super($);this.#h=h,this.#_=_,this.#k=W}get adapter(){return this.#_}compileQuery(h,_){return this.#h.compileQuery(h,_)}provideConnection(h){return this.#k.provideConnection(h)}withPlugins(h){return new z_(this.#h,this.#_,this.#k,[...this.plugins,...h])}withPlugin(h){return new z_(this.#h,this.#_,this.#k,[...this.plugins,h])}withPluginAtFront(h){return new z_(this.#h,this.#_,this.#k,[h,...this.plugins])}withConnectionProvider(h){return new z_(this.#h,this.#_,h,[...this.plugins])}withoutPlugins(){return new z_(this.#h,this.#_,this.#k,[])}}function sk(){if(typeof performance<"u"&&R(performance.now))return performance.now();else return Date.now()}class cW{#h;#_;#k;#W;#$;#Z=new WeakSet;constructor(h,_){this.#W=!1,this.#h=h,this.#_=_}async init(){if(this.#$)throw Error("driver has already been destroyed");if(!this.#k)this.#k=this.#h.init().then(()=>{this.#W=!0}).catch((h)=>{return this.#k=void 0,Promise.reject(h)});await this.#k}async acquireConnection(){if(this.#$)throw Error("driver has already been destroyed");if(!this.#W)await this.init();let h=await this.#h.acquireConnection();if(!this.#Z.has(h)){if(this.#J())this.#Y(h);this.#Z.add(h)}return h}async releaseConnection(h){await this.#h.releaseConnection(h)}beginTransaction(h,_){return this.#h.beginTransaction(h,_)}commitTransaction(h){return this.#h.commitTransaction(h)}rollbackTransaction(h){return this.#h.rollbackTransaction(h)}savepoint(h,_,W){if(this.#h.savepoint)return this.#h.savepoint(h,_,W);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(h,_,W){if(this.#h.rollbackToSavepoint)return this.#h.rollbackToSavepoint(h,_,W);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(h,_,W){if(this.#h.releaseSavepoint)return this.#h.releaseSavepoint(h,_,W);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){if(!this.#k)return;if(await this.#k,!this.#$)this.#$=this.#h.destroy().catch((h)=>{return this.#$=void 0,Promise.reject(h)});await this.#$}#J(){return this.#_.isLevelEnabled("query")||this.#_.isLevelEnabled("error")}#Y(h){let{executeQuery:_,streamQuery:W}=h,$=this;h.executeQuery=async(J)=>{let Y,H=sk();try{return await _.call(h,J)}catch(K){throw Y=K,await $.#G(K,J,H),K}finally{if(!Y)await $.#H(J,H)}},h.streamQuery=async function*(J,Y){let H,K=sk();try{for await(let b of W.call(h,J,Y))yield b}catch(b){throw H=b,await $.#G(b,J,K),b}finally{if(!H)await $.#H(J,K,!0)}}}async#G(h,_,W){await this.#_.error(()=>({level:"error",error:h,query:_,queryDurationMillis:this.#L(W)}))}async#H(h,_,W=!1){await this.#_.query(()=>({level:"query",isStream:W,query:h,queryDurationMillis:this.#L(_)}))}#L(h){return sk()-h}}var F8=()=>{};class Uk{#h;#_;constructor(h){this.#h=h}async provideConnection(h){while(this.#_)await this.#_.catch(F8);return this.#_=this.#k(h).finally(()=>{this.#_=void 0}),this.#_}async#k(h){return await h(this.#h)}}var U8=["read only","read write"],V8=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function yW(h){if(h.accessMode&&!U8.includes(h.accessMode))throw Error(`invalid transaction access mode ${h.accessMode}`);if(h.isolationLevel&&!V8.includes(h.isolationLevel))throw Error(`invalid transaction isolation level ${h.isolationLevel}`)}var f8=["query","error"],V3=k(f8);class tW{#h;#_;constructor(h){if(R(h))this.#_=h,this.#h=k({query:!0,error:!0});else this.#_=w8,this.#h=k({query:h.includes("query"),error:h.includes("error")})}isLevelEnabled(h){return this.#h[h]}async query(h){if(this.#h.query)await this.#_(h())}async error(h){if(this.#h.error)await this.#_(h())}}function w8(h){if(h.level==="query"){let _=`kysely:query:${h.isStream?"stream:":""}`;console.log(`${_} ${h.query.sql}`),console.log(`${_} duration: ${h.queryDurationMillis.toFixed(1)}ms`)}else if(h.level==="error")if(h.error instanceof Error)console.error(`kysely:error: ${h.error.stack??h.error.message}`);else console.error(`kysely:error: ${JSON.stringify({error:h.error,query:h.query.sql,queryDurationMillis:h.queryDurationMillis})}`)}function M1(h){return O(h)&&R(h.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class w_ extends bh{#h;constructor(h){let _,W;if(R8(h))_={executor:h.executor},W={...h};else{let $=h.dialect,J=$.createDriver(),Y=$.createQueryCompiler(),H=$.createAdapter(),K=new tW(h.log??[]),b=new cW(J,K),x=new gW(b),Kh=new z_(Y,H,x,h.plugins??[]);_={executor:Kh},W={config:h,executor:Kh,dialect:$,driver:b}}super(_);this.#h=k(W)}get schema(){return new s_(this.#h.executor)}get dynamic(){return new IW}get introspection(){return this.#h.dialect.createIntrospector(this.withoutPlugins())}case(h){return new Gk({node:Gh.create(a(h)?void 0:o(h))})}get fn(){return Ik()}transaction(){return new nk({...this.#h})}startTransaction(){return new dk({...this.#h})}connection(){return new F1({...this.#h})}withPlugin(h){return new w_({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new w_({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new w_({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new w_({...this.#h})}async destroy(){await this.#h.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#h.executor}executeQuery(h,_){if(_!==void 0)Rh("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let W=M1(h)?h.compile():h;return this.getExecutor().executeQuery(W)}async[Symbol.asyncDispose](){await this.destroy()}}class R_ extends w_{#h;constructor(h){super(h);this.#h=h}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(h){return new R_({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new R_({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new R_({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new R_({...this.#h})}}function R8(h){return O(h)&&O(h.config)&&O(h.driver)&&O(h.executor)&&O(h.dialect)}class F1{#h;constructor(h){this.#h=k(h)}async execute(h){return this.#h.executor.provideConnection(async(_)=>{let W=this.#h.executor.withConnectionProvider(new Uk(_)),$=new w_({...this.#h,executor:W});return await h($)})}}class nk{#h;constructor(h){this.#h=k(h)}setAccessMode(h){return new nk({...this.#h,accessMode:h})}setIsolationLevel(h){return new nk({...this.#h,isolationLevel:h})}async execute(h){let{isolationLevel:_,accessMode:W,...$}=this.#h,J={isolationLevel:_,accessMode:W};return yW(J),this.#h.executor.provideConnection(async(Y)=>{let H={isCommitted:!1,isRolledBack:!1},K=new dh(this.#h.executor.withConnectionProvider(new Uk(Y)),H),b=new R_({...$,executor:K}),x=!1;try{await this.#h.driver.beginTransaction(Y,J),x=!0;let Kh=await h(b);return await this.#h.driver.commitTransaction(Y),H.isCommitted=!0,Kh}catch(Kh){if(x)await this.#h.driver.rollbackTransaction(Y),H.isRolledBack=!0;throw Kh}})}}class dk{#h;constructor(h){this.#h=k(h)}setAccessMode(h){return new dk({...this.#h,accessMode:h})}setIsolationLevel(h){return new dk({...this.#h,isolationLevel:h})}async execute(){let{isolationLevel:h,accessMode:_,...W}=this.#h,$={isolationLevel:h,accessMode:_};yW($);let J=await jk(this.#h.executor);return await this.#h.driver.beginTransaction(J.connection,$),new nh({...W,connection:J,executor:this.#h.executor.withConnectionProvider(new Uk(J.connection))})}}class nh extends R_{#h;#_;#k;constructor(h){let _={isCommitted:!1,isRolledBack:!1};h={...h,executor:new dh(h.executor,_)};let{connection:W,...$}=h;super($);this.#h=k(h),this.#k=_;let J=L();this.#_=(Y)=>h.executor.compileQuery(Y,J)}get isCommitted(){return this.#k.isCommitted}get isRolledBack(){return this.#k.isRolledBack}commit(){return f_(this.#k),new n_(async()=>{await this.#h.driver.commitTransaction(this.#h.connection.connection),this.#k.isCommitted=!0,this.#h.connection.release()})}rollback(){return f_(this.#k),new n_(async()=>{await this.#h.driver.rollbackTransaction(this.#h.connection.connection),this.#k.isRolledBack=!0,this.#h.connection.release()})}savepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.savepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}rollbackToSavepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.rollbackToSavepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}releaseSavepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.releaseSavepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}withPlugin(h){return new nh({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new nh({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new nh({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new nh({...this.#h})}}class n_{#h;constructor(h){this.#h=h}async execute(){return await this.#h()}}function f_(h){if(h.isCommitted)throw Error("Transaction is already committed");if(h.isRolledBack)throw Error("Transaction is already rolled back")}class dh{#h;#_;constructor(h,_){if(h instanceof dh)this.#h=h.#h;else this.#h=h;this.#_=_}get adapter(){return this.#h.adapter}get plugins(){return this.#h.plugins}transformQuery(h,_){return this.#h.transformQuery(h,_)}compileQuery(h,_){return this.#h.compileQuery(h,_)}provideConnection(h){return this.#h.provideConnection(h)}executeQuery(h){return f_(this.#_),this.#h.executeQuery(h)}stream(h,_){return f_(this.#_),this.#h.stream(h,_)}withConnectionProvider(h){return new dh(this.#h.withConnectionProvider(h),this.#_)}withPlugin(h){return new dh(this.#h.withPlugin(h),this.#_)}withPlugins(h){return new dh(this.#h.withPlugins(h),this.#_)}withPluginAtFront(h){return new dh(this.#h.withPluginAtFront(h),this.#_)}withoutPlugins(){return new dh(this.#h.withoutPlugins(),this.#_)}}class Vk{#h;constructor(h){this.#h=k(h)}get expressionType(){return}get isRawBuilder(){return!0}as(h){return new U1(this,h)}$castTo(){return new Vk({...this.#h})}$notNull(){return new Vk(this.#h)}withPlugin(h){return new Vk({...this.#h,plugins:this.#h.plugins!==void 0?k([...this.#h.plugins,h]):k([h])})}toOperationNode(){return this.#k(this.#_())}compile(h){return this.#W(this.#_(h))}async execute(h){let _=this.#_(h);return _.executeQuery(this.#W(_))}#_(h){let _=h!==void 0?h.getExecutor():G_;return this.#h.plugins!==void 0?_.withPlugins(this.#h.plugins):_}#k(h){return h.transformQuery(this.#h.rawNode,this.#h.queryId)}#W(h){return h.compileQuery(this.#k(h),this.#h.queryId)}}function rh(h){return new Vk(h)}class U1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}get rawBuilder(){return this.#h}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}var Q=Object.assign((h,..._)=>{return rh({queryId:L(),rawNode:V.create(h,_?.map(V1)??[])})},{ref(h){return rh({queryId:L(),rawNode:V.createWithChild(kh(h))})},val(h){return rh({queryId:L(),rawNode:V.createWithChild(P(h))})},value(h){return this.val(h)},table(h){return rh({queryId:L(),rawNode:V.createWithChild(f(h))})},id(...h){let _=Array(h.length+1).fill(".");return _[0]="",_[_.length-1]="",rh({queryId:L(),rawNode:V.create(_,h.map(X.create))})},lit(h){return rh({queryId:L(),rawNode:V.createWithChild(C.createImmediate(h))})},literal(h){return this.lit(h)},raw(h){return rh({queryId:L(),rawNode:V.createWithSql(h)})},join(h,_=Q`, `){let W=Array(Math.max(2*h.length-1,0)),$=_.toOperationNode();for(let J=0;J<h.length;++J)if(W[2*J]=V1(h[J]),J!==h.length-1)W[2*J+1]=$;return rh({queryId:L(),rawNode:V.createWithChildren(W)})}});function V1(h){if(T(h))return h.toOperationNode();return P(h)}class iW{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#h=k({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=(h)=>{this.nodeStack.push(h),this.#h[h.kind](h),this.nodeStack.pop()}}var v8=/'/g;class oh extends iW{#h="";#_=[];get numParameters(){return this.#_.length}compileQuery(h,_){return this.#h="",this.#_=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(h),k({query:h,queryId:_,sql:this.getSql(),parameters:[...this.#_]})}getSql(){return this.#h}visitSelectQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!m.is(this.parentNode)&&!u.is(this.parentNode)&&!Nh.is(this.parentNode)&&!mk.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("select"),h.distinctOn)this.append(" "),this.compileDistinctOn(h.distinctOn);if(h.frontModifiers?.length)this.append(" "),this.compileList(h.frontModifiers," ");if(h.top)this.append(" "),this.visitNode(h.top);if(h.selections)this.append(" "),this.compileList(h.selections);if(h.from)this.append(" "),this.visitNode(h.from);if(h.joins)this.append(" "),this.compileList(h.joins," ");if(h.where)this.append(" "),this.visitNode(h.where);if(h.groupBy)this.append(" "),this.visitNode(h.groupBy);if(h.having)this.append(" "),this.visitNode(h.having);if(h.setOperations)this.append(" "),this.compileList(h.setOperations," ");if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(h.offset)this.append(" "),this.visitNode(h.offset);if(h.fetch)this.append(" "),this.visitNode(h.fetch);if(h.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...h.endModifiers])," ");if(_)this.append(")")}visitFrom(h){this.append("from "),this.compileList(h.froms)}visitSelection(h){this.visitNode(h.selection)}visitColumn(h){this.visitNode(h.column)}compileDistinctOn(h){this.append("distinct on ("),this.compileList(h),this.append(")")}compileList(h,_=", "){let W=h.length-1;for(let $=0;$<=W;$++)if(this.visitNode(h[$]),$<W)this.append(_)}visitWhere(h){this.append("where "),this.visitNode(h.where)}visitHaving(h){this.append("having "),this.visitNode(h.having)}visitInsertQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode)&&!Hh.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append(h.replace?"replace":"insert"),h.ignore)Rh("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(h.orAction)this.append(" "),this.visitNode(h.orAction);if(h.top)this.append(" "),this.visitNode(h.top);if(h.into)this.append(" into "),this.visitNode(h.into);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.output)this.append(" "),this.visitNode(h.output);if(h.values)this.append(" "),this.visitNode(h.values);if(h.defaultValues)this.append(" "),this.append("default values");if(h.onConflict)this.append(" "),this.visitNode(h.onConflict);if(h.onDuplicateKey)this.append(" "),this.visitNode(h.onDuplicateKey);if(h.returning)this.append(" "),this.visitNode(h.returning);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitValues(h){this.append("values "),this.compileList(h.values)}visitDeleteQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("delete "),h.top)this.visitNode(h.top),this.append(" ");if(this.visitNode(h.from),h.output)this.append(" "),this.visitNode(h.output);if(h.using)this.append(" "),this.visitNode(h.using);if(h.joins)this.append(" "),this.compileList(h.joins," ");if(h.where)this.append(" "),this.visitNode(h.where);if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(h.returning)this.append(" "),this.visitNode(h.returning);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitReturning(h){this.append("returning "),this.compileList(h.selections)}visitAlias(h){this.visitNode(h.node),this.append(" as "),this.visitNode(h.alias)}visitReference(h){if(h.table)this.visitNode(h.table),this.append(".");this.visitNode(h.column)}visitSelectAll(h){this.append("*")}visitIdentifier(h){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(h),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(h){if(!M(h.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(h.name))}visitAnd(h){this.visitNode(h.left),this.append(" and "),this.visitNode(h.right)}visitOr(h){this.visitNode(h.left),this.append(" or "),this.visitNode(h.right)}visitValue(h){if(h.immediate)this.appendImmediateValue(h.value);else this.appendValue(h.value)}visitValueList(h){this.append("("),this.compileList(h.values),this.append(")")}visitTuple(h){this.append("("),this.compileList(h.values),this.append(")")}visitPrimitiveValueList(h){this.append("(");let{values:_}=h;for(let W=0;W<_.length;++W)if(this.appendValue(_[W]),W!==_.length-1)this.append(", ");this.append(")")}visitParens(h){this.append("("),this.visitNode(h.node),this.append(")")}visitJoin(h){if(this.append(D8[h.joinType]),this.append(" "),this.visitNode(h.table),h.on)this.append(" "),this.visitNode(h.on)}visitOn(h){this.append("on "),this.visitNode(h.on)}visitRaw(h){let{sqlFragments:_,parameters:W}=h;for(let $=0;$<_.length;++$)if(this.append(_[$]),W.length>$)this.visitNode(W[$])}visitOperator(h){this.append(h.operator)}visitTable(h){this.visitNode(h.table)}visitSchemableIdentifier(h){if(h.schema)this.visitNode(h.schema),this.append(".");this.visitNode(h.identifier)}visitCreateTable(h){if(this.append("create "),h.frontModifiers&&h.frontModifiers.length>0)this.compileList(h.frontModifiers," "),this.append(" ");if(h.temporary)this.append("temporary ");if(this.append("table "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.table),h.selectQuery)this.append(" as "),this.visitNode(h.selectQuery);else{if(this.append(" ("),this.compileList([...h.columns,...h.constraints??[]]),this.append(")"),h.onCommit)this.append(" on commit "),this.append(h.onCommit);if(h.endModifiers&&h.endModifiers.length>0)this.append(" "),this.compileList(h.endModifiers," ")}}visitColumnDefinition(h){if(h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.column),this.append(" "),this.visitNode(h.dataType),h.unsigned)this.append(" unsigned");if(h.frontModifiers&&h.frontModifiers.length>0)this.append(" "),this.compileList(h.frontModifiers," ");if(h.generated)this.append(" "),this.visitNode(h.generated);if(h.identity)this.append(" identity");if(h.defaultTo)this.append(" "),this.visitNode(h.defaultTo);if(h.notNull)this.append(" not null");if(h.unique)this.append(" unique");if(h.nullsNotDistinct)this.append(" nulls not distinct");if(h.primaryKey)this.append(" primary key");if(h.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(h.references)this.append(" "),this.visitNode(h.references);if(h.check)this.append(" "),this.visitNode(h.check);if(h.endModifiers&&h.endModifiers.length>0)this.append(" "),this.compileList(h.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(h){if(this.append("references "),this.visitNode(h.table),this.append(" ("),this.compileList(h.columns),this.append(")"),h.onDelete)this.append(" on delete "),this.append(h.onDelete);if(h.onUpdate)this.append(" on update "),this.append(h.onUpdate)}visitDropTable(h){if(this.append("drop table "),h.ifExists)this.append("if exists ");if(this.visitNode(h.table),h.cascade)this.append(" cascade")}visitDataType(h){this.append(h.dataType)}visitOrderBy(h){this.append("order by "),this.compileList(h.items)}visitOrderByItem(h){if(this.visitNode(h.orderBy),h.collation)this.append(" "),this.visitNode(h.collation);if(h.direction)this.append(" "),this.visitNode(h.direction);if(h.nulls)this.append(" nulls "),this.append(h.nulls)}visitGroupBy(h){this.append("group by "),this.compileList(h.items)}visitGroupByItem(h){this.visitNode(h.groupBy)}visitUpdateQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode)&&!Hh.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("update "),h.top)this.visitNode(h.top),this.append(" ");if(h.table)this.visitNode(h.table),this.append(" ");if(this.append("set "),h.updates)this.compileList(h.updates);if(h.output)this.append(" "),this.visitNode(h.output);if(h.from)this.append(" "),this.visitNode(h.from);if(h.joins){if(!h.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(h.joins," ")}if(h.where)this.append(" "),this.visitNode(h.where);if(h.returning)this.append(" "),this.visitNode(h.returning);if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitColumnUpdate(h){this.visitNode(h.column),this.append(" = "),this.visitNode(h.value)}visitLimit(h){this.append("limit "),this.visitNode(h.limit)}visitOffset(h){this.append("offset "),this.visitNode(h.offset)}visitOnConflict(h){if(this.append("on conflict"),h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");else if(h.constraint)this.append(" on constraint "),this.visitNode(h.constraint);else if(h.indexExpression)this.append(" ("),this.visitNode(h.indexExpression),this.append(")");if(h.indexWhere)this.append(" "),this.visitNode(h.indexWhere);if(h.doNothing===!0)this.append(" do nothing");else if(h.updates){if(this.append(" do update set "),this.compileList(h.updates),h.updateWhere)this.append(" "),this.visitNode(h.updateWhere)}}visitOnDuplicateKey(h){this.append("on duplicate key update "),this.compileList(h.updates)}visitCreateIndex(h){if(this.append("create "),h.unique)this.append("unique ");if(this.append("index "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),h.table)this.append(" on "),this.visitNode(h.table);if(h.using)this.append(" using "),this.visitNode(h.using);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.nullsNotDistinct)this.append(" nulls not distinct");if(h.where)this.append(" "),this.visitNode(h.where)}visitDropIndex(h){if(this.append("drop index "),h.ifExists)this.append("if exists ");if(this.visitNode(h.name),h.table)this.append(" on "),this.visitNode(h.table);if(h.cascade)this.append(" cascade")}visitCreateSchema(h){if(this.append("create schema "),h.ifNotExists)this.append("if not exists ");this.visitNode(h.schema)}visitDropSchema(h){if(this.append("drop schema "),h.ifExists)this.append("if exists ");if(this.visitNode(h.schema),h.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");this.append("primary key ("),this.compileList(h.columns),this.append(")"),this.buildDeferrable(h)}buildDeferrable(h){if(h.deferrable!==void 0)if(h.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(h.initiallyDeferred!==void 0)if(h.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");if(this.append("unique"),h.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(h.columns),this.append(")"),this.buildDeferrable(h)}visitCheckConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");this.append("check ("),this.visitNode(h.expression),this.append(")")}visitForeignKeyConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");if(this.append("foreign key ("),this.compileList(h.columns),this.append(") "),this.visitNode(h.references),h.onDelete)this.append(" on delete "),this.append(h.onDelete);if(h.onUpdate)this.append(" on update "),this.append(h.onUpdate);this.buildDeferrable(h)}visitList(h){this.compileList(h.items)}visitWith(h){if(this.append("with "),h.recursive)this.append("recursive ");this.compileList(h.expressions)}visitCommonTableExpression(h){if(this.visitNode(h.name),this.append(" as "),yh(h.materialized)){if(!h.materialized)this.append("not ");this.append("materialized ")}this.visitNode(h.expression)}visitCommonTableExpressionName(h){if(this.visitNode(h.table),h.columns)this.append("("),this.compileList(h.columns),this.append(")")}visitAlterTable(h){if(this.append("alter table "),this.visitNode(h.table),this.append(" "),h.renameTo)this.append("rename to "),this.visitNode(h.renameTo);if(h.setSchema)this.append("set schema "),this.visitNode(h.setSchema);if(h.addConstraint)this.visitNode(h.addConstraint);if(h.dropConstraint)this.visitNode(h.dropConstraint);if(h.renameConstraint)this.visitNode(h.renameConstraint);if(h.columnAlterations)this.compileColumnAlterations(h.columnAlterations);if(h.addIndex)this.visitNode(h.addIndex);if(h.dropIndex)this.visitNode(h.dropIndex)}visitAddColumn(h){this.append("add column "),this.visitNode(h.column)}visitRenameColumn(h){this.append("rename column "),this.visitNode(h.column),this.append(" to "),this.visitNode(h.renameTo)}visitDropColumn(h){this.append("drop column "),this.visitNode(h.column)}visitAlterColumn(h){if(this.append("alter column "),this.visitNode(h.column),this.append(" "),h.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(h.dataType),h.dataTypeExpression)this.append("using "),this.visitNode(h.dataTypeExpression)}if(h.setDefault)this.append("set default "),this.visitNode(h.setDefault);if(h.dropDefault)this.append("drop default");if(h.setNotNull)this.append("set not null");if(h.dropNotNull)this.append("drop not null")}visitModifyColumn(h){this.append("modify column "),this.visitNode(h.column)}visitAddConstraint(h){this.append("add "),this.visitNode(h.constraint)}visitDropConstraint(h){if(this.append("drop constraint "),h.ifExists)this.append("if exists ");if(this.visitNode(h.constraintName),h.modifier==="cascade")this.append(" cascade");else if(h.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(h){this.append("rename constraint "),this.visitNode(h.oldName),this.append(" to "),this.visitNode(h.newName)}visitSetOperation(h){if(this.append(h.operator),this.append(" "),h.all)this.append("all ");this.visitNode(h.expression)}visitCreateView(h){if(this.append("create "),h.orReplace)this.append("or replace ");if(h.materialized)this.append("materialized ");if(h.temporary)this.append("temporary ");if(this.append("view "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),this.append(" "),h.columns)this.append("("),this.compileList(h.columns),this.append(") ");if(h.as)this.append("as "),this.visitNode(h.as)}visitRefreshMaterializedView(h){if(this.append("refresh materialized view "),h.concurrently)this.append("concurrently ");if(this.visitNode(h.name),h.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(h){if(this.append("drop "),h.materialized)this.append("materialized ");if(this.append("view "),h.ifExists)this.append("if exists ");if(this.visitNode(h.name),h.cascade)this.append(" cascade")}visitGenerated(h){if(this.append("generated "),h.always)this.append("always ");if(h.byDefault)this.append("by default ");if(this.append("as "),h.identity)this.append("identity");if(h.expression)this.append("("),this.visitNode(h.expression),this.append(")");if(h.stored)this.append(" stored")}visitDefaultValue(h){this.append("default "),this.visitNode(h.defaultValue)}visitSelectModifier(h){if(h.rawModifier)this.visitNode(h.rawModifier);else this.append(P8[h.modifier]);if(h.of)this.append(" of "),this.compileList(h.of,", ")}visitCreateType(h){if(this.append("create type "),this.visitNode(h.name),h.enum)this.append(" as enum "),this.visitNode(h.enum)}visitDropType(h){if(this.append("drop type "),h.ifExists)this.append("if exists ");this.visitNode(h.name)}visitExplain(h){if(this.append("explain"),h.options||h.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),h.options){if(this.visitNode(h.options),h.format)this.append(this.getExplainOptionsDelimiter())}if(h.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(h.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(h){this.append("default")}visitAggregateFunction(h){if(this.append(h.func),this.append("("),h.distinct)this.append("distinct ");if(this.compileList(h.aggregated),h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(this.append(")"),h.withinGroup)this.append(" within group ("),this.visitNode(h.withinGroup),this.append(")");if(h.filter)this.append(" filter("),this.visitNode(h.filter),this.append(")");if(h.over)this.append(" "),this.visitNode(h.over)}visitOver(h){if(this.append("over("),h.partitionBy){if(this.visitNode(h.partitionBy),h.orderBy)this.append(" ")}if(h.orderBy)this.visitNode(h.orderBy);this.append(")")}visitPartitionBy(h){this.append("partition by "),this.compileList(h.items)}visitPartitionByItem(h){this.visitNode(h.partitionBy)}visitBinaryOperation(h){this.visitNode(h.leftOperand),this.append(" "),this.visitNode(h.operator),this.append(" "),this.visitNode(h.rightOperand)}visitUnaryOperation(h){if(this.visitNode(h.operator),!this.isMinusOperator(h.operator))this.append(" ");this.visitNode(h.operand)}isMinusOperator(h){return y.is(h)&&h.operator==="-"}visitUsing(h){this.append("using "),this.compileList(h.tables)}visitFunction(h){this.append(h.func),this.append("("),this.compileList(h.arguments),this.append(")")}visitCase(h){if(this.append("case"),h.value)this.append(" "),this.visitNode(h.value);if(h.when)this.append(" "),this.compileList(h.when," ");if(h.else)this.append(" else "),this.visitNode(h.else);if(this.append(" end"),h.isStatement)this.append(" case")}visitWhen(h){if(this.append("when "),this.visitNode(h.condition),h.result)this.append(" then "),this.visitNode(h.result)}visitJSONReference(h){this.visitNode(h.reference),this.visitNode(h.traversal)}visitJSONPath(h){if(h.inOperator)this.visitNode(h.inOperator);this.append("'$");for(let _ of h.pathLegs)this.visitNode(_);this.append("'")}visitJSONPathLeg(h){let _=h.type==="ArrayLocation";if(this.append(_?"[":"."),this.append(String(h.value)),_)this.append("]")}visitJSONOperatorChain(h){for(let _=0,W=h.values.length;_<W;_++){if(_===W-1)this.visitNode(h.operator);else this.append("->");this.visitNode(h.values[_])}}visitMergeQuery(h){if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("merge "),h.top)this.visitNode(h.top),this.append(" ");if(this.append("into "),this.visitNode(h.into),h.using)this.append(" "),this.visitNode(h.using);if(h.whens)this.append(" "),this.compileList(h.whens," ");if(h.returning)this.append(" "),this.visitNode(h.returning);if(h.output)this.append(" "),this.visitNode(h.output);if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitMatched(h){if(h.not)this.append("not ");if(this.append("matched"),h.bySource)this.append(" by source")}visitAddIndex(h){if(this.append("add "),h.unique)this.append("unique ");if(this.append("index "),this.visitNode(h.name),h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.using)this.append(" using "),this.visitNode(h.using)}visitCast(h){this.append("cast("),this.visitNode(h.expression),this.append(" as "),this.visitNode(h.dataType),this.append(")")}visitFetch(h){this.append("fetch next "),this.visitNode(h.rowCount),this.append(` rows ${h.modifier}`)}visitOutput(h){this.append("output "),this.compileList(h.selections)}visitTop(h){if(this.append(`top(${h.expression})`),h.modifiers)this.append(` ${h.modifiers}`)}visitOrAction(h){this.append(h.action)}visitCollate(h){this.append("collate "),this.visitNode(h.collation)}append(h){this.#h+=h}appendValue(h){this.addParameter(h),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(h){let _=this.getLeftIdentifierWrapper(),W=this.getRightIdentifierWrapper(),$="";for(let J of h)if($+=J,J===_)$+=_;else if(J===W)$+=W;return $}sanitizeStringLiteral(h){return h.replace(v8,"''")}addParameter(h){this.#_.push(h)}appendImmediateValue(h){if(M(h))this.appendStringLiteral(h);else if(Mh(h)||yh(h)||__(h))this.append(h.toString());else if(h_(h))this.append("null");else if(v_(h))this.appendImmediateValue(h.toISOString());else throw Error(`invalid immediate value ${h}`)}appendStringLiteral(h){this.append("'"),this.append(this.sanitizeStringLiteral(h)),this.append("'")}sortSelectModifiers(h){return h.sort((_,W)=>_.modifier&&W.modifier?f1[_.modifier]-f1[W.modifier]:1),k(h)}compileColumnAlterations(h){this.compileList(h)}announcesNewColumnDataType(){return!0}}var P8=k({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),f1=k({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),D8=k({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var p=k({raw(h,_=[]){return k({sql:h,query:V.createWithSql(h),parameters:k(_),queryId:L()})}});class O8{async init(){}async acquireConnection(){return new w1}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}}class w1{async executeQuery(){return{rows:[]}}async*streamQuery(){}}class eh{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}}function zh(h,_){return V.createWithChildren([V.createWithSql(`${h} `),X.create(_)])}class uW{#h;#_=new v1;#k;#W;constructor(h){this.#h=k({...h})}async init(){if(this.#k=R(this.#h.database)?await this.#h.database():this.#h.database,this.#W=new R1(this.#k),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#W)}async acquireConnection(){return await this.#_.lock(),this.#W}async beginTransaction(h){await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(zh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(zh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(zh("release",_),L()))}async releaseConnection(){this.#_.unlock()}async destroy(){this.#k?.close()}}class R1{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:_,parameters:W}=h,$=this.#h.prepare(_);if($.reader)return Promise.resolve({rows:$.all(W)});let{changes:J,lastInsertRowid:Y}=$.run(W);return Promise.resolve({numAffectedRows:J!==void 0&&J!==null?BigInt(J):void 0,insertId:Y!==void 0&&Y!==null?BigInt(Y):void 0,rows:[]})}async*streamQuery(h,_){let{sql:W,parameters:$,query:J}=h,Y=this.#h.prepare(W);if(w.is(J)){let H=Y.iterate($);for(let K of H)yield{rows:[K]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class v1{#h;#_;async lock(){while(this.#h)await this.#h;this.#h=new Promise((h)=>{this.#_=h})}unlock(){let h=this.#_;this.#h=void 0,this.#_=void 0,h?.()}}var A8=/"/g;class lW extends oh{visitOrAction(h){this.append("or "),this.append(h.action)}getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}sanitizeIdentifier(h){return h.replace(A8,'""')}visitDefaultInsertValue(h){this.append("null")}}class pW{transformQuery(h){return h.node}async transformResult(h){return h.result}}var xh="kysely_migration",ch="kysely_migration_lock",T8=!1,aW="migration_lock",IK=k({__noMigrations__:!0});class E8{#h;constructor(h){this.#h=k(h)}async getMigrations(){let _=await this.#X(this.#W)?await this.#h.db.withPlugin(this.#J).selectFrom(this.#W).select(["name","timestamp"]).$narrowType().execute():[];return(await this.#F()).map(({name:$,...J})=>{let Y=_.find((H)=>H.name===$);return{name:$,migration:J,executedAt:Y?new Date(Y.timestamp):void 0}})}async migrateToLatest(){return this.#_(()=>({direction:"Up",step:1/0}))}async migrateTo(h){return this.#_(({migrations:_,executedMigrations:W,pendingMigrations:$})=>{if(O(h)&&h.__noMigrations__===!0)return{direction:"Down",step:1/0};if(!_.find((H)=>H.name===h))throw Error(`migration "${h}" doesn't exist`);let J=W.indexOf(h),Y=$.findIndex((H)=>H.name===h);if(J!==-1)return{direction:"Down",step:W.length-J-1};else if(Y!==-1)return{direction:"Up",step:Y+1};else throw Error(`migration "${h}" isn't executed or pending`)})}async migrateUp(){return this.#_(()=>({direction:"Up",step:1}))}async migrateDown(){return this.#_(()=>({direction:"Down",step:1}))}async#_(h){try{return await this.#Y(),await this.#G(),await this.#H(),await this.#L(),await this.#U(h)}catch(_){if(_ instanceof rk)return _.resultSet;return{error:_}}}get#k(){return this.#h.migrationTableSchema}get#W(){return this.#h.migrationTableName??xh}get#$(){return this.#h.migrationLockTableName??ch}get#Z(){return this.#h.allowUnorderedMigrations??T8}get#J(){if(this.#k)return new Zh(this.#k);return new pW}async#Y(){if(!this.#k)return;if(await this.#K())return;try{await this.#z(this.#h.db.schema.createSchema(this.#k))}catch(_){if(!await this.#K())throw _}}async#G(){if(await this.#X(this.#W))return;try{await this.#z(this.#h.db.schema.withPlugin(this.#J).createTable(this.#W).addColumn("name","varchar(255)",(_)=>_.notNull().primaryKey()).addColumn("timestamp","varchar(255)",(_)=>_.notNull()))}catch(_){if(!await this.#X(this.#W))throw _}}async#H(){if(await this.#X(this.#$))return;try{await this.#z(this.#h.db.schema.withPlugin(this.#J).createTable(this.#$).addColumn("id","varchar(255)",(_)=>_.notNull().primaryKey()).addColumn("is_locked","integer",(_)=>_.notNull().defaultTo(0)))}catch(_){if(!await this.#X(this.#$))throw _}}async#L(){if(await this.#M())return;try{await this.#h.db.withPlugin(this.#J).insertInto(this.#$).values({id:aW,is_locked:0}).execute()}catch(_){if(!await this.#M())throw _}}async#K(){return(await this.#h.db.introspection.getSchemas()).some((_)=>_.name===this.#k)}async#X(h){let _=this.#k;return(await this.#h.db.introspection.getTables({withInternalKyselyTables:!0})).some(($)=>$.name===h&&(!_||$.schema===_))}async#M(){return!!await this.#h.db.withPlugin(this.#J).selectFrom(this.#$).where("id","=",aW).select("id").executeTakeFirst()}async#U(h){let _=this.#h.db.getExecutor().adapter,W=k({lockTable:this.#h.migrationLockTableName??ch,lockRowId:aW,lockTableSchema:this.#h.migrationTableSchema}),$=async(J)=>{try{await _.acquireMigrationLock(J,W);let Y=await this.#V(J);if(Y.migrations.length===0)return{results:[]};let{direction:H,step:K}=h(Y);if(K<=0)return{results:[]};if(H==="Down")return await this.#P(J,Y,K);else if(H==="Up")return await this.#D(J,Y,K);return{results:[]}}finally{await _.releaseMigrationLock(J,W)}};if(_.supportsTransactionalDdl&&!this.#h.disableTransactions)return this.#h.db.transaction().execute($);else return this.#h.db.connection().execute($)}async#V(h){let _=await this.#F(),W=await this.#w(h);if(this.#R(_,W),!this.#Z)this.#v(_,W);let $=this.#f(_,W);return k({migrations:_,executedMigrations:W,lastMigration:M$(W),pendingMigrations:$})}#f(h,_){return h.filter((W)=>{return!_.includes(W.name)})}async#F(){let h=await this.#h.provider.getMigrations();return Object.keys(h).sort().map((_)=>({...h[_],name:_}))}async#w(h){let _=await h.withPlugin(this.#J).selectFrom(this.#W).select(["name","timestamp"]).$narrowType().execute(),W=this.#h.nameComparator||(($,J)=>$.localeCompare(J));return _.sort(($,J)=>{if($.timestamp===J.timestamp)return W($.name,J.name);return new Date($.timestamp).getTime()-new Date(J.timestamp).getTime()}).map(($)=>$.name)}#R(h,_){for(let W of _)if(!h.some(($)=>$.name===W))throw Error(`corrupted migrations: previously executed migration ${W} is missing`)}#v(h,_){for(let W=0;W<_.length;++W)if(h[W].name!==_[W])throw Error(`corrupted migrations: expected previously executed migration ${_[W]} to be at index ${W} but ${h[W].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)}async#P(h,_,W){let $=_.executedMigrations.slice().reverse().slice(0,W).map((Y)=>{return _.migrations.find((H)=>H.name===Y)}),J=$.map((Y)=>{return{migrationName:Y.name,direction:"Down",status:"NotExecuted"}});for(let Y=0;Y<J.length;++Y){let H=$[Y];try{if(H.down)await H.down(h),await h.withPlugin(this.#J).deleteFrom(this.#W).where("name","=",H.name).execute(),J[Y]={migrationName:H.name,direction:"Down",status:"Success"}}catch(K){throw J[Y]={migrationName:H.name,direction:"Down",status:"Error"},new rk({error:K,results:J})}}return{results:J}}async#D(h,_,W){let J=_.pendingMigrations.slice(0,W).map((Y)=>{return{migrationName:Y.name,direction:"Up",status:"NotExecuted"}});for(let Y=0;Y<J.length;Y++){let H=_.pendingMigrations[Y];try{await H.up(h),await h.withPlugin(this.#J).insertInto(this.#W).values({name:H.name,timestamp:new Date().toISOString()}).execute(),J[Y]={migrationName:H.name,direction:"Up",status:"Success"}}catch(K){throw J[Y]={migrationName:H.name,direction:"Up",status:"Error"},new rk({error:K,results:J})}}return{results:J}}async#z(h){if(this.#h.db.getExecutor().adapter.supportsCreateIfNotExists)h=h.ifNotExists();await h.execute()}}class rk extends Error{#h;constructor(h){super();this.#h=h}get resultSet(){return this.#h}}class sW{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){return await this.#k(h)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h,_){let W=h.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").select(["name","sql","type"]).orderBy("name");if(!_.withInternalKyselyTables)W=W.where("name","!=",xh).where("name","!=",ch);return W}async#k(h){let _=await this.#_(this.#h,h).execute(),W=await this.#h.with("table_list",(J)=>this.#_(J,h)).selectFrom(["table_list as tl",Q`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(),$={};for(let J of W)$[J.table]??=[],$[J.table].push(J);return _.map(({name:J,sql:Y,type:H})=>{let K=Y?.split(/[\(\),]/)?.find((x)=>x.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),b=$[J]??[];if(!K){let x=b.filter((Kh)=>Kh.pk>0);if(x.length===1&&x[0].type.toLowerCase()==="integer")K=x[0].name}return{name:J,isView:H==="view",columns:b.map((x)=>({name:x.name,dataType:x.type,isNullable:!x.notnull,isAutoIncrementing:x.name===K,hasDefaultValue:x.dflt_value!=null,comment:void 0}))}})}}class nW extends eh{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(h,_){}async releaseMigrationLock(h,_){}}class S8{#h;constructor(h){this.#h=k({...h})}createDriver(){return new uW(this.#h)}createQueryCompiler(){return new lW}createAdapter(){return new nW}createIntrospector(h){return new sW(h)}}var N8=/"/g;class dW extends oh{sanitizeIdentifier(h){return h.replace(N8,'""')}}class rW{#h;constructor(h){this.#h=h}async getSchemas(){return(await this.#h.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((_)=>({name:_.nspname}))}async getTables(h={withInternalKyselyTables:!1}){let _=this.#h.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",Q`col_description(a.attrelid, a.attnum)`.as("column_description"),Q`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(Q`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(!h.withInternalKyselyTables)_=_.where("c.relname","!=",xh).where("c.relname","!=",ch);let W=await _.execute();return this.#_(W)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h){return h.reduce((_,W)=>{let $=_.find((J)=>J.name===W.table&&J.schema===W.schema);if(!$)$=k({name:W.table,isView:W.table_type==="v",schema:W.schema,columns:[]}),_.push($);return $.columns.push(k({name:W.column,dataType:W.type,dataTypeSchema:W.type_schema,isNullable:!W.not_null,isAutoIncrementing:W.auto_incrementing!==null,hasDefaultValue:W.has_default,comment:W.column_description??void 0})),_},[])}}var x8=BigInt("3853314791062309107");class oW extends eh{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(h,_){await Q`select pg_advisory_xact_lock(${Q.lit(x8)})`.execute(h)}async releaseMigrationLock(h,_){}}function d_(h,_){if(C8(h)&&_.stack){let W=_.stack.split(`
|
|
1
|
+
function a(h){return typeof h>"u"||h===void 0}function M(h){return typeof h==="string"}function Kh(h){return typeof h==="number"}function yh(h){return typeof h==="boolean"}function h_(h){return h===null}function v_(h){return h instanceof Date}function __(h){return typeof h==="bigint"}function fk(h){return typeof Buffer<"u"&&Buffer.isBuffer(h)}function R(h){return typeof h==="function"}function O(h){return typeof h==="object"&&h!==null}function wk(h){if(!O(h)||l1(h)!=="[object Object]")return!1;if(Object.getPrototypeOf(h)===null)return!0;let _=h;while(Object.getPrototypeOf(_)!==null)_=Object.getPrototypeOf(_);return Object.getPrototypeOf(h)===_}function M$(h){return h[h.length-1]}function k(h){return Object.freeze(h)}function r_(h){if(q(h))return h;else return[h]}function q(h){return Array.isArray(h)}function s(h){return h}function Rk(h,_){if(q(h)&&q(_))return g1(h,_);else if(O(h)&&O(_))return c1(h,_);return h===_}function g1(h,_){if(h.length!==_.length)return!1;for(let W=0;W<h.length;++W)if(!Rk(h[W],_[W]))return!1;return!0}function c1(h,_){if(fk(h)&&fk(_))return y1(h,_);else if(v_(h)&&v_(_))return t1(h,_);return i1(h,_)}function y1(h,_){return Buffer.compare(h,_)===0}function t1(h,_){return h.getTime()===_.getTime()}function i1(h,_){let W=Object.keys(h),$=Object.keys(_);if(W.length!==$.length)return!1;for(let J of W)if(!Rk(h[J],_[J]))return!1;return!0}var u1=Object.prototype.toString;function l1(h){if(h==null)return h===void 0?"[object Undefined]":"[object Null]";return u1.call(h)}var U=k({is(h){return h.kind==="AlterTableNode"},create(h){return k({kind:"AlterTableNode",table:h})},cloneWithTableProps(h,_){return k({...h,..._})},cloneWithColumnAlteration(h,_){return k({...h,columnAlterations:h.columnAlterations?[...h.columnAlterations,_]:[_]})}});var X=k({is(h){return h.kind==="IdentifierNode"},create(h){return k({kind:"IdentifierNode",name:h})}});var Mh=k({is(h){return h.kind==="CreateIndexNode"},create(h){return k({kind:"CreateIndexNode",name:X.create(h)})},cloneWith(h,_){return k({...h,..._})},cloneWithColumns(h,_){return k({...h,columns:[...h.columns||[],..._]})}});var vk=k({is(h){return h.kind==="CreateSchemaNode"},create(h,_){return k({kind:"CreateSchemaNode",schema:X.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var F$=["preserve rows","delete rows","drop"],u=k({is(h){return h.kind==="CreateTableNode"},create(h){return k({kind:"CreateTableNode",table:h,columns:k([])})},cloneWithColumn(h,_){return k({...h,columns:k([...h.columns,_])})},cloneWithConstraint(h,_){return k({...h,constraints:h.constraints?k([...h.constraints,_]):k([_])})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):k([_])})},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):k([_])})},cloneWith(h,_){return k({...h,..._})}});var l=k({is(h){return h.kind==="SchemableIdentifierNode"},create(h){return k({kind:"SchemableIdentifierNode",identifier:X.create(h)})},createWithSchema(h,_){return k({kind:"SchemableIdentifierNode",schema:X.create(h),identifier:X.create(_)})}});var k_=k({is(h){return h.kind==="DropIndexNode"},create(h,_){return k({kind:"DropIndexNode",name:l.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var o_=k({is(h){return h.kind==="DropSchemaNode"},create(h,_){return k({kind:"DropSchemaNode",schema:X.create(h),..._})},cloneWith(h,_){return k({...h,..._})}});var e_=k({is(h){return h.kind==="DropTableNode"},create(h,_){return k({kind:"DropTableNode",table:h,..._})},cloneWith(h,_){return k({...h,..._})}});var I=k({is(h){return h.kind==="AliasNode"},create(h,_){return k({kind:"AliasNode",node:h,alias:_})}});var d=k({is(h){return h.kind==="TableNode"},create(h){return k({kind:"TableNode",table:l.create(h)})},createWithSchema(h,_){return k({kind:"TableNode",table:l.createWithSchema(h,_)})}});function T(h){return O(h)&&R(h.toOperationNode)}function Pk(h){return O(h)&&"expressionType"in h&&T(h)}function U$(h){return O(h)&&"expression"in h&&M(h.alias)&&T(h)}var xh=k({is(h){return h.kind==="SelectModifierNode"},create(h,_){return k({kind:"SelectModifierNode",modifier:h,of:_})},createWithExpression(h){return k({kind:"SelectModifierNode",rawModifier:h})}});var r=k({is(h){return h.kind==="AndNode"},create(h,_){return k({kind:"AndNode",left:h,right:_})}});var Fh=k({is(h){return h.kind==="OrNode"},create(h,_){return k({kind:"OrNode",left:h,right:_})}});var Dk=k({is(h){return h.kind==="OnNode"},create(h){return k({kind:"OnNode",on:h})},cloneWithOperation(h,_,W){return k({...h,on:_==="And"?r.create(h.on,W):Fh.create(h.on,W)})}});var Uh=k({is(h){return h.kind==="JoinNode"},create(h,_){return k({kind:"JoinNode",joinType:h,table:_,on:void 0})},createWithOn(h,_,W){return k({kind:"JoinNode",joinType:h,table:_,on:Dk.create(W)})},cloneWithOn(h,_){return k({...h,on:h.on?Dk.cloneWithOperation(h.on,"And",_):Dk.create(_)})}});var Vh=k({is(h){return h.kind==="BinaryOperationNode"},create(h,_,W){return k({kind:"BinaryOperationNode",leftOperand:h,operator:_,rightOperand:W})}});var V$=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],f$=["+","-","*","/","%","^","&","|","#","<<",">>"],w$=["->","->>"],R$=[...V$,...f$,"&&","||"],p1=["exists","not exists"],a1=["not","-",...p1],hW=[...R$,...w$,...a1,"between","between symmetric"],y=k({is(h){return h.kind==="OperatorNode"},create(h){return k({kind:"OperatorNode",operator:h})}});function o0(h){return M(h)&&hW.includes(h)}function e0(h){return M(h)&&R$.includes(h)}function hJ(h){return M(h)&&V$.includes(h)}function _J(h){return M(h)&&f$.includes(h)}function _W(h){return M(h)&&w$.includes(h)}var F=k({is(h){return h.kind==="ColumnNode"},create(h){return k({kind:"ColumnNode",column:X.create(h)})}});var P_=k({is(h){return h.kind==="SelectAllNode"},create(){return k({kind:"SelectAllNode"})}});var D_=k({is(h){return h.kind==="ReferenceNode"},create(h,_){return k({kind:"ReferenceNode",table:_,column:h})},createSelectAll(h){return k({kind:"ReferenceNode",table:h,column:P_.create()})}});class kW{#h;get dynamicReference(){return this.#h}get refType(){return}constructor(h){this.#h=h}toOperationNode(){return WW(this.#h)}}function Ok(h){return O(h)&&T(h)&&M(h.dynamicReference)}var fh=k({is(h){return h.kind==="OrderByItemNode"},create(h,_){return k({kind:"OrderByItemNode",orderBy:h,direction:_})},cloneWith(h,_){return k({...h,..._})}});var V=k({is(h){return h.kind==="RawNode"},create(h,_){return k({kind:"RawNode",sqlFragments:k(h),parameters:k(_)})},createWithSql(h){return V.create([h],[])},createWithChild(h){return V.create(["",""],[h])},createWithChildren(h){return V.create(Array(h.length+1).fill(""),h)}});var v$=k({is(h){return h.kind==="CollateNode"},create(h){return k({kind:"CollateNode",collation:X.create(h)})}});class W_{#h;constructor(h){this.#h=k(h)}desc(){return new W_({node:fh.cloneWith(this.#h.node,{direction:V.createWithSql("desc")})})}asc(){return new W_({node:fh.cloneWith(this.#h.node,{direction:V.createWithSql("asc")})})}nullsLast(){return new W_({node:fh.cloneWith(this.#h.node,{nulls:"last"})})}nullsFirst(){return new W_({node:fh.cloneWith(this.#h.node,{nulls:"first"})})}collate(h){return new W_({node:fh.cloneWith(this.#h.node,{collation:v$.create(h)})})}toOperationNode(){return this.#h.node}}var P$=new Set;function Ch(h){if(P$.has(h))return;P$.add(h),console.log(h)}function JW(h){return h==="asc"||h==="desc"}function Wh(h){if(h.length===2)return[$W(h[0],h[1])];if(h.length===1){let[_]=h;if(Array.isArray(_))return Ch("orderBy(array) is deprecated, use multiple orderBy calls instead."),_.map((W)=>$W(W));return[$W(_)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${h.length}`)}function $W(h,_){let W=s1(h);if(fh.is(W)){if(_)throw Error("Cannot specify direction twice!");return W}return D$(W,_)}function s1(h){if(th(h))return o(h);if(Ok(h))return h.toOperationNode();let[_,W]=h.split(" ");if(W)return Ch("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),D$(kh(_),W);return kh(h)}function D$(h,_){if(typeof _==="string"){if(!JW(_))throw Error(`Invalid order by direction: ${_}`);return fh.create(h,V.createWithSql(_))}if(Pk(_))return Ch("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),fh.create(h,_.toOperationNode());let W=fh.create(h);if(!_)return W;return _(new W_({node:W})).toOperationNode()}var O_=k({is(h){return h.kind==="JSONReferenceNode"},create(h,_){return k({kind:"JSONReferenceNode",reference:h,traversal:_})},cloneWithTraversal(h,_){return k({...h,traversal:_})}});var Ak=k({is(h){return h.kind==="JSONOperatorChainNode"},create(h){return k({kind:"JSONOperatorChainNode",operator:h,values:k([])})},cloneWithValue(h,_){return k({...h,values:k([...h.values,_])})}});var $_=k({is(h){return h.kind==="JSONPathNode"},create(h){return k({kind:"JSONPathNode",inOperator:h,pathLegs:k([])})},cloneWithLeg(h,_){return k({...h,pathLegs:k([...h.pathLegs,_])})}});function WW(h){if(M(h))return kh(h);return h.toOperationNode()}function ih(h){if(q(h))return h.map((_)=>t(_));else return[t(h)]}function t(h){if(th(h))return o(h);return WW(h)}function O$(h,_){let W=kh(h);if(_W(_))return O_.create(W,Ak.create(y.create(_)));let $=_.slice(0,-1);if(_W($))return O_.create(W,$_.create(y.create($)));throw Error(`Invalid JSON operator: ${_}`)}function kh(h){if(!h.includes("."))return D_.create(F.create(h));let W=h.split(".").map(ZW);if(W.length===3)return n1(W);if(W.length===2)return d1(W);throw Error(`invalid column reference ${h}`)}function A$(h){if(h.includes(" as ")){let[W,$]=h.split(" as ").map(ZW);return I.create(kh(W),X.create($))}else return kh(h)}function YW(h){return F.create(h)}function A_(h){if(h.includes(" ")){let[W,$]=h.split(" ").map(ZW);if(!JW($))throw Error(`invalid order direction "${$}" next to "${W}"`);return Wh([W,$])[0]}else return YW(h)}function n1(h){let[_,W,$]=h;return D_.create(F.create($),d.createWithSchema(_,W))}function d1(h){let[_,W]=h;return D_.create(F.create(W),d.create(_))}function ZW(h){return h.trim()}var T_=k({is(h){return h.kind==="PrimitiveValueListNode"},create(h){return k({kind:"PrimitiveValueListNode",values:k([...h])})}});var $h=k({is(h){return h.kind==="ValueListNode"},create(h){return k({kind:"ValueListNode",values:k(h)})}});var C=k({is(h){return h.kind==="ValueNode"},create(h){return k({kind:"ValueNode",value:h})},createImmediate(h){return k({kind:"ValueNode",value:h,immediate:!0})}});function T$(h){if(q(h))return r1(h);return P(h)}function P(h){if(th(h))return o(h);return C.create(h)}function Tk(h){return Kh(h)||yh(h)||h_(h)}function hk(h){if(!Tk(h))throw Error(`unsafe immediate value ${JSON.stringify(h)}`);return C.createImmediate(h)}function r1(h){if(h.some(th))return $h.create(h.map((_)=>P(_)));return T_.create(h)}var Jh=k({is(h){return h.kind==="ParensNode"},create(h){return k({kind:"ParensNode",node:h})}});function A(h){if(h.length===3)return Ek(h[0],h[1],h[2]);else if(h.length===1)return P(h[0]);throw Error(`invalid arguments: ${JSON.stringify(h)}`)}function Ek(h,_,W){if(o1(_)&&S$(W))return Vh.create(t(h),GW(_),C.createImmediate(W));return Vh.create(t(h),GW(_),T$(W))}function g(h,_,W){return Vh.create(t(h),GW(_),t(W))}function HW(h,_){return E_(Object.entries(h).filter(([,W])=>!a(W)).map(([W,$])=>Ek(W,S$($)?"is":"=",$)),_)}function E_(h,_,W=!0){let $=_==="and"?r.create:Fh.create;if(h.length===0)return Vh.create(C.createImmediate(1),y.create("="),C.createImmediate(_==="and"?1:0));let J=E$(h[0]);for(let Y=1;Y<h.length;++Y)J=$(J,E$(h[Y]));if(h.length>1&&W)return Jh.create(J);return J}function o1(h){return h==="is"||h==="is not"}function S$(h){return h_(h)||yh(h)}function GW(h){if(M(h)&&hW.includes(h))return y.create(h);if(T(h))return h.toOperationNode();throw Error(`invalid operator ${JSON.stringify(h)}`)}function E$(h){return T(h)?h.toOperationNode():h}var uh=k({is(h){return h.kind==="OrderByNode"},create(h){return k({kind:"OrderByNode",items:k([...h])})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var XW=k({is(h){return h.kind==="PartitionByNode"},create(h){return k({kind:"PartitionByNode",items:k(h)})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var _k=k({is(h){return h.kind==="OverNode"},create(){return k({kind:"OverNode"})},cloneWithOrderByItems(h,_){return k({...h,orderBy:h.orderBy?uh.cloneWithItems(h.orderBy,_):uh.create(_)})},cloneWithPartitionByItems(h,_){return k({...h,partitionBy:h.partitionBy?XW.cloneWithItems(h.partitionBy,_):XW.create(_)})}});var K_=k({is(h){return h.kind==="FromNode"},create(h){return k({kind:"FromNode",froms:k(h)})},cloneWithFroms(h,_){return k({...h,froms:k([...h.froms,..._])})}});var LW=k({is(h){return h.kind==="GroupByNode"},create(h){return k({kind:"GroupByNode",items:k(h)})},cloneWithItems(h,_){return k({...h,items:k([...h.items,..._])})}});var zW=k({is(h){return h.kind==="HavingNode"},create(h){return k({kind:"HavingNode",having:h})},cloneWithOperation(h,_,W){return k({...h,having:_==="And"?r.create(h.having,W):Fh.create(h.having,W)})}});var m=k({is(h){return h.kind==="InsertQueryNode"},create(h,_,W){return k({kind:"InsertQueryNode",into:h,..._&&{with:_},replace:W})},createWithoutInto(){return k({kind:"InsertQueryNode"})},cloneWith(h,_){return k({...h,..._})}});var Sk=k({is(h){return h.kind==="ListNode"},create(h){return k({kind:"ListNode",items:k(h)})}});var jh=k({is(h){return h.kind==="UpdateQueryNode"},create(h,_){return k({kind:"UpdateQueryNode",table:h.length===1?h[0]:Sk.create(h),..._&&{with:_}})},createWithoutTable(){return k({kind:"UpdateQueryNode"})},cloneWithFromItems(h,_){return k({...h,from:h.from?K_.cloneWithFroms(h.from,_):K_.create(_)})},cloneWithUpdates(h,_){return k({...h,updates:h.updates?k([...h.updates,..._]):_})},cloneWithLimit(h,_){return k({...h,limit:_})}});var kk=k({is(h){return h.kind==="UsingNode"},create(h){return k({kind:"UsingNode",tables:k(h)})},cloneWithTables(h,_){return k({...h,tables:k([...h.tables,..._])})}});var J_=k({is(h){return h.kind==="DeleteQueryNode"},create(h,_){return k({kind:"DeleteQueryNode",from:K_.create(h),..._&&{with:_}})},cloneWithOrderByItems:(h,_)=>G.cloneWithOrderByItems(h,_),cloneWithoutOrderBy:(h)=>G.cloneWithoutOrderBy(h),cloneWithLimit(h,_){return k({...h,limit:_})},cloneWithoutLimit(h){return k({...h,limit:void 0})},cloneWithUsing(h,_){return k({...h,using:h.using!==void 0?kk.cloneWithTables(h.using,_):kk.create(_)})}});var i=k({is(h){return h.kind==="WhereNode"},create(h){return k({kind:"WhereNode",where:h})},cloneWithOperation(h,_,W){return k({...h,where:_==="And"?r.create(h.where,W):Fh.create(h.where,W)})}});var KW=k({is(h){return h.kind==="ReturningNode"},create(h){return k({kind:"ReturningNode",selections:k(h)})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})}});var N$=k({is(h){return h.kind==="ExplainNode"},create(h,_){return k({kind:"ExplainNode",format:h,options:_})}});var Hh=k({is(h){return h.kind==="WhenNode"},create(h){return k({kind:"WhenNode",condition:h})},cloneWithResult(h,_){return k({...h,result:_})}});var Yh=k({is(h){return h.kind==="MergeQueryNode"},create(h,_){return k({kind:"MergeQueryNode",into:h,..._&&{with:_}})},cloneWithUsing(h,_){return k({...h,using:_})},cloneWithWhen(h,_){return k({...h,whens:h.whens?k([...h.whens,_]):k([_])})},cloneWithThen(h,_){return k({...h,whens:h.whens?k([...h.whens.slice(0,-1),Hh.cloneWithResult(h.whens[h.whens.length-1],_)]):void 0})}});var MW=k({is(h){return h.kind==="OutputNode"},create(h){return k({kind:"OutputNode",selections:k(h)})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})}});var G=k({is(h){return w.is(h)||m.is(h)||jh.is(h)||J_.is(h)||Yh.is(h)},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):k([_])})},cloneWithWhere(h,_){return k({...h,where:h.where?i.cloneWithOperation(h.where,"And",_):i.create(_)})},cloneWithJoin(h,_){return k({...h,joins:h.joins?k([...h.joins,_]):k([_])})},cloneWithReturning(h,_){return k({...h,returning:h.returning?KW.cloneWithSelections(h.returning,_):KW.create(_)})},cloneWithoutReturning(h){return k({...h,returning:void 0})},cloneWithoutWhere(h){return k({...h,where:void 0})},cloneWithExplain(h,_,W){return k({...h,explain:N$.create(_,W?.toOperationNode())})},cloneWithTop(h,_){return k({...h,top:_})},cloneWithOutput(h,_){return k({...h,output:h.output?MW.cloneWithSelections(h.output,_):MW.create(_)})},cloneWithOrderByItems(h,_){return k({...h,orderBy:h.orderBy?uh.cloneWithItems(h.orderBy,_):uh.create(_)})},cloneWithoutOrderBy(h){return k({...h,orderBy:void 0})}});var w=k({is(h){return h.kind==="SelectQueryNode"},create(h){return k({kind:"SelectQueryNode",...h&&{with:h}})},createFrom(h,_){return k({kind:"SelectQueryNode",from:K_.create(h),..._&&{with:_}})},cloneWithSelections(h,_){return k({...h,selections:h.selections?k([...h.selections,..._]):k(_)})},cloneWithDistinctOn(h,_){return k({...h,distinctOn:h.distinctOn?k([...h.distinctOn,..._]):k(_)})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):k([_])})},cloneWithOrderByItems:(h,_)=>G.cloneWithOrderByItems(h,_),cloneWithGroupByItems(h,_){return k({...h,groupBy:h.groupBy?LW.cloneWithItems(h.groupBy,_):LW.create(_)})},cloneWithLimit(h,_){return k({...h,limit:_})},cloneWithOffset(h,_){return k({...h,offset:_})},cloneWithFetch(h,_){return k({...h,fetch:_})},cloneWithHaving(h,_){return k({...h,having:h.having?zW.cloneWithOperation(h.having,"And",_):zW.create(_)})},cloneWithSetOperations(h,_){return k({...h,setOperations:h.setOperations?k([...h.setOperations,..._]):k([..._])})},cloneWithoutSelections(h){return k({...h,selections:[]})},cloneWithoutLimit(h){return k({...h,limit:void 0})},cloneWithoutOffset(h){return k({...h,offset:void 0})},cloneWithoutOrderBy:(h)=>G.cloneWithoutOrderBy(h),cloneWithoutGroupBy(h){return k({...h,groupBy:void 0})}});class S_{#h;constructor(h){this.#h=k(h)}on(...h){return new S_({...this.#h,joinNode:Uh.cloneWithOn(this.#h.joinNode,A(h))})}onRef(h,_,W){return new S_({...this.#h,joinNode:Uh.cloneWithOn(this.#h.joinNode,g(h,_,W))})}onTrue(){return new S_({...this.#h,joinNode:Uh.cloneWithOn(this.#h.joinNode,V.createWithSql("true"))})}$call(h){return h(this)}toOperationNode(){return this.#h.joinNode}}var x$=k({is(h){return h.kind==="PartitionByItemNode"},create(h){return k({kind:"PartitionByItemNode",partitionBy:h})}});function C$(h){return ih(h).map(x$.create)}class N_{#h;constructor(h){this.#h=k(h)}orderBy(...h){return new N_({overNode:_k.cloneWithOrderByItems(this.#h.overNode,Wh(h))})}clearOrderBy(){return new N_({overNode:G.cloneWithoutOrderBy(this.#h.overNode)})}partitionBy(h){return new N_({overNode:_k.cloneWithPartitionByItems(this.#h.overNode,C$(h))})}$call(h){return h(this)}toOperationNode(){return this.#h.overNode}}var x_=k({is(h){return h.kind==="SelectionNode"},create(h){return k({kind:"SelectionNode",selection:h})},createSelectAll(){return k({kind:"SelectionNode",selection:P_.create()})},createSelectAllFromTable(h){return k({kind:"SelectionNode",selection:D_.createSelectAll(h)})}});function B(h){if(R(h))return B(h(wh()));else if(q(h))return h.map((_)=>j$(_));else return[j$(h)]}function j$(h){if(M(h))return x_.create(A$(h));else if(Ok(h))return x_.create(h.toOperationNode());else return x_.create(Nk(h))}function c(h){if(!h)return[x_.createSelectAll()];else if(Array.isArray(h))return h.map(m$);else return[m$(h)]}function m$(h){if(M(h))return x_.createSelectAllFromTable(f(h));throw Error(`invalid value selectAll expression: ${JSON.stringify(h)}`)}var Q$=k({is(h){return h.kind==="ValuesNode"},create(h){return k({kind:"ValuesNode",values:k(h)})}});var b$=k({is(h){return h.kind==="DefaultInsertValueNode"},create(){return k({kind:"DefaultInsertValueNode"})}});function xk(h){let _=R(h)?h(wh()):h,W=q(_)?_:k([_]);return e1(W)}function e1(h){let _=h8(h);return[k([..._.keys()].map(F.create)),Q$.create(h.map((W)=>_8(W,_)))]}function h8(h){let _=new Map;for(let W of h){let $=Object.keys(W);for(let J of $)if(!_.has(J)&&W[J]!==void 0)_.set(J,_.size)}return _}function _8(h,_){let W=Object.keys(h),$=Array.from({length:_.size}),J=!1,Y=W.length;for(let K of W){let b=_.get(K);if(a(b)){Y--;continue}let x=h[K];if(a(x)||th(x))J=!0;$[b]=x}if(Y<_.size||J){let K=b$.create();return $h.create($.map((b)=>a(b)?K:P(b)))}return T_.create($)}var FW=k({is(h){return h.kind==="ColumnUpdateNode"},create(h,_){return k({kind:"ColumnUpdateNode",column:h,value:_})}});function B$(...h){if(h.length===2)return[FW.create(t(h[0]),P(h[1]))];return Wk(h[0])}function Wk(h){let _=R(h)?h(wh()):h;return Object.entries(_).filter(([W,$])=>$!==void 0).map(([W,$])=>{return FW.create(F.create(W),P($))})}var q$=k({is(h){return h.kind==="OnDuplicateKeyNode"},create(h){return k({kind:"OnDuplicateKeyNode",updates:h})}});class UW{insertId;numInsertedOrUpdatedRows;constructor(h,_){this.insertId=h,this.numInsertedOrUpdatedRows=_}}class Rh extends Error{node;constructor(h){super("no result");this.node=h}}function mh(h){return Object.prototype.hasOwnProperty.call(h,"prototype")}var n=k({is(h){return h.kind==="OnConflictNode"},create(){return k({kind:"OnConflictNode"})},cloneWith(h,_){return k({...h,..._})},cloneWithIndexWhere(h,_){return k({...h,indexWhere:h.indexWhere?i.cloneWithOperation(h.indexWhere,"And",_):i.create(_)})},cloneWithIndexOrWhere(h,_){return k({...h,indexWhere:h.indexWhere?i.cloneWithOperation(h.indexWhere,"Or",_):i.create(_)})},cloneWithUpdateWhere(h,_){return k({...h,updateWhere:h.updateWhere?i.cloneWithOperation(h.updateWhere,"And",_):i.create(_)})},cloneWithUpdateOrWhere(h,_){return k({...h,updateWhere:h.updateWhere?i.cloneWithOperation(h.updateWhere,"Or",_):i.create(_)})},cloneWithoutIndexWhere(h){return k({...h,indexWhere:void 0})},cloneWithoutUpdateWhere(h){return k({...h,updateWhere:void 0})}});class Qh{#h;constructor(h){this.#h=k(h)}column(h){let _=F.create(h);return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{columns:this.#h.onConflictNode.columns?k([...this.#h.onConflictNode.columns,_]):k([_])})})}columns(h){let _=h.map(F.create);return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{columns:this.#h.onConflictNode.columns?k([...this.#h.onConflictNode.columns,..._]):k(_)})})}constraint(h){return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{constraint:X.create(h)})})}expression(h){return new Qh({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{indexExpression:h.toOperationNode()})})}where(...h){return new Qh({...this.#h,onConflictNode:n.cloneWithIndexWhere(this.#h.onConflictNode,A(h))})}whereRef(h,_,W){return new Qh({...this.#h,onConflictNode:n.cloneWithIndexWhere(this.#h.onConflictNode,g(h,_,W))})}clearWhere(){return new Qh({...this.#h,onConflictNode:n.cloneWithoutIndexWhere(this.#h.onConflictNode)})}doNothing(){return new I$({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{doNothing:!0})})}doUpdateSet(h){return new $k({...this.#h,onConflictNode:n.cloneWith(this.#h.onConflictNode,{updates:Wk(h)})})}$call(h){return h(this)}}class I${#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.onConflictNode}}class $k{#h;constructor(h){this.#h=k(h)}where(...h){return new $k({...this.#h,onConflictNode:n.cloneWithUpdateWhere(this.#h.onConflictNode,A(h))})}whereRef(h,_,W){return new $k({...this.#h,onConflictNode:n.cloneWithUpdateWhere(this.#h.onConflictNode,g(h,_,W))})}clearWhere(){return new $k({...this.#h,onConflictNode:n.cloneWithoutUpdateWhere(this.#h.onConflictNode)})}$call(h){return h(this)}toOperationNode(){return this.#h.onConflictNode}}var g$=k({is(h){return h.kind==="TopNode"},create(h,_){return k({kind:"TopNode",expression:h,modifiers:_})}});function vh(h,_){if(!Kh(h)&&!__(h))throw Error(`Invalid top expression: ${h}`);if(!a(_)&&!k8(_))throw Error(`Invalid top modifiers: ${_}`);return g$.create(h,_)}function k8(h){return h==="percent"||h==="with ties"||h==="percent with ties"}var M_=k({is(h){return h.kind==="OrActionNode"},create(h){return k({kind:"OrActionNode",action:h})}});class D{#h;constructor(h){this.#h=k(h)}values(h){let[_,W]=xk(h);return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{columns:_,values:W})})}columns(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{columns:k(h.map(F.create))})})}expression(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{values:o(h)})})}defaultValues(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{defaultValues:!0})})}modifyEnd(h){return new D({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}ignore(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("ignore")})})}orIgnore(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("ignore")})})}orAbort(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("abort")})})}orFail(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("fail")})})}orReplace(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("replace")})})}orRollback(){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{orAction:M_.create("rollback")})})}top(h,_){return new D({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}onConflict(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{onConflict:h(new Qh({onConflictNode:n.create()})).toOperationNode()})})}onDuplicateKeyUpdate(h){return new D({...this.#h,queryNode:m.cloneWith(this.#h.queryNode,{onDuplicateKey:q$.create(Wk(h))})})}returning(h){return new D({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(){return new D({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c())})}output(h){return new D({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new D({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}clearReturning(){return new D({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new D({...this.#h})}$castTo(){return new D(this.#h)}$narrowType(){return new D(this.#h)}$assertType(){return new D(this.#h)}withPlugin(h){return new D({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new UW(_.insertId,_.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=Rh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new D({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}class VW{numDeletedRows;constructor(h){this.numDeletedRows=h}}var C_=k({is(h){return h.kind==="LimitNode"},create(h){return k({kind:"LimitNode",limit:h})}});class j{#h;constructor(h){this.#h=k(h)}where(...h){return new j({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new j({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}clearWhere(){return new j({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}top(h,_){return new j({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}using(h){return new j({...this.#h,queryNode:J_.cloneWithUsing(this.#h.queryNode,Ph(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}#_(h,_){return new j({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}returning(h){return new j({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new j({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new j({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new j({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}clearReturning(){return new j({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}clearLimit(){return new j({...this.#h,queryNode:J_.cloneWithoutLimit(this.#h.queryNode)})}orderBy(...h){return new j({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}clearOrderBy(){return new j({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}limit(h){return new j({...this.#h,queryNode:J_.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}modifyEnd(h){return new j({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new j({...this.#h})}$castTo(){return new j(this.#h)}$narrowType(){return new j(this.#h)}$assertType(){return new j(this.#h)}withPlugin(h){return new j({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new VW(_.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=Rh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new j({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}class fW{numUpdatedRows;numChangedRows;constructor(h,_){this.numUpdatedRows=h,this.numChangedRows=_}}class E{#h;constructor(h){this.#h=k(h)}where(...h){return new E({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new E({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}clearWhere(){return new E({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}top(h,_){return new E({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}from(h){return new E({...this.#h,queryNode:jh.cloneWithFromItems(this.#h.queryNode,Ph(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}#_(h,_){return new E({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}orderBy(...h){return new E({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}clearOrderBy(){return new E({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}limit(h){return new E({...this.#h,queryNode:jh.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}set(...h){return new E({...this.#h,queryNode:jh.cloneWithUpdates(this.#h.queryNode,B$(...h))})}returning(h){return new E({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new E({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new E({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new E({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}modifyEnd(h){return new E({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}clearReturning(){return new E({...this.#h,queryNode:G.cloneWithoutReturning(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new E({...this.#h})}$castTo(){return new E(this.#h)}$narrowType(){return new E(this.#h)}$assertType(){return new E(this.#h)}withPlugin(h){return new E({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new fW(_.numAffectedRows??BigInt(0),_.numChangedRows)]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=Rh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new E({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}var wW=k({is(h){return h.kind==="CommonTableExpressionNameNode"},create(h,_){return k({kind:"CommonTableExpressionNameNode",table:d.create(h),columns:_?k(_.map(F.create)):void 0})}});var j_=k({is(h){return h.kind==="CommonTableExpressionNode"},create(h,_){return k({kind:"CommonTableExpressionNode",name:h,expression:_})},cloneWith(h,_){return k({...h,..._})}});class Jk{#h;constructor(h){this.#h=k(h)}materialized(){return new Jk({...this.#h,node:j_.cloneWith(this.#h.node,{materialized:!0})})}notMaterialized(){return new Jk({...this.#h,node:j_.cloneWith(this.#h.node,{materialized:!1})})}toOperationNode(){return this.#h.node}}function RW(h,_){let W=_(y$()).toOperationNode();if(R(h))return h(W8(W)).toOperationNode();return j_.create(c$(h),W)}function W8(h){return(_)=>{return new Jk({node:j_.create(c$(_),h)})}}function c$(h){if(h.includes("(")){let _=h.split(/[\(\)]/),W=_[0],$=_[1].split(",").map((J)=>J.trim());return wW.create(W,$)}else return wW.create(h)}var Yk=k({is(h){return h.kind==="WithNode"},create(h,_){return k({kind:"WithNode",expressions:k([h]),..._})},cloneWithExpression(h,_){return k({...h,expressions:k([...h.expressions,_])})}});var t$=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function Ck(h){let _="";for(let W=0;W<h;++W)_+=$8();return _}function $8(){return t$[~~(Math.random()*t$.length)]}function L(){return new i$}class i${#h;get queryId(){if(this.#h===void 0)this.#h=Ck(8);return this.#h}}function Z(h){return h}class Dh{nodeStack=[];#h=k({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(h,_){if(!h)return h;this.nodeStack.push(h);let W=this.transformNodeImpl(h,_);return this.nodeStack.pop(),k(W)}transformNodeImpl(h,_){return this.#h[h.kind](h,_)}transformNodeList(h,_){if(!h)return h;return k(h.map((W)=>this.transformNode(W,_)))}transformSelectQuery(h,_){return Z({kind:"SelectQueryNode",from:this.transformNode(h.from,_),selections:this.transformNodeList(h.selections,_),distinctOn:this.transformNodeList(h.distinctOn,_),joins:this.transformNodeList(h.joins,_),groupBy:this.transformNode(h.groupBy,_),orderBy:this.transformNode(h.orderBy,_),where:this.transformNode(h.where,_),frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),limit:this.transformNode(h.limit,_),offset:this.transformNode(h.offset,_),with:this.transformNode(h.with,_),having:this.transformNode(h.having,_),explain:this.transformNode(h.explain,_),setOperations:this.transformNodeList(h.setOperations,_),fetch:this.transformNode(h.fetch,_),top:this.transformNode(h.top,_)})}transformSelection(h,_){return Z({kind:"SelectionNode",selection:this.transformNode(h.selection,_)})}transformColumn(h,_){return Z({kind:"ColumnNode",column:this.transformNode(h.column,_)})}transformAlias(h,_){return Z({kind:"AliasNode",node:this.transformNode(h.node,_),alias:this.transformNode(h.alias,_)})}transformTable(h,_){return Z({kind:"TableNode",table:this.transformNode(h.table,_)})}transformFrom(h,_){return Z({kind:"FromNode",froms:this.transformNodeList(h.froms,_)})}transformReference(h,_){return Z({kind:"ReferenceNode",column:this.transformNode(h.column,_),table:this.transformNode(h.table,_)})}transformAnd(h,_){return Z({kind:"AndNode",left:this.transformNode(h.left,_),right:this.transformNode(h.right,_)})}transformOr(h,_){return Z({kind:"OrNode",left:this.transformNode(h.left,_),right:this.transformNode(h.right,_)})}transformValueList(h,_){return Z({kind:"ValueListNode",values:this.transformNodeList(h.values,_)})}transformParens(h,_){return Z({kind:"ParensNode",node:this.transformNode(h.node,_)})}transformJoin(h,_){return Z({kind:"JoinNode",joinType:h.joinType,table:this.transformNode(h.table,_),on:this.transformNode(h.on,_)})}transformRaw(h,_){return Z({kind:"RawNode",sqlFragments:k([...h.sqlFragments]),parameters:this.transformNodeList(h.parameters,_)})}transformWhere(h,_){return Z({kind:"WhereNode",where:this.transformNode(h.where,_)})}transformInsertQuery(h,_){return Z({kind:"InsertQueryNode",into:this.transformNode(h.into,_),columns:this.transformNodeList(h.columns,_),values:this.transformNode(h.values,_),returning:this.transformNode(h.returning,_),onConflict:this.transformNode(h.onConflict,_),onDuplicateKey:this.transformNode(h.onDuplicateKey,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),ignore:h.ignore,orAction:this.transformNode(h.orAction,_),replace:h.replace,explain:this.transformNode(h.explain,_),defaultValues:h.defaultValues,top:this.transformNode(h.top,_),output:this.transformNode(h.output,_)})}transformValues(h,_){return Z({kind:"ValuesNode",values:this.transformNodeList(h.values,_)})}transformDeleteQuery(h,_){return Z({kind:"DeleteQueryNode",from:this.transformNode(h.from,_),using:this.transformNode(h.using,_),joins:this.transformNodeList(h.joins,_),where:this.transformNode(h.where,_),returning:this.transformNode(h.returning,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),orderBy:this.transformNode(h.orderBy,_),limit:this.transformNode(h.limit,_),explain:this.transformNode(h.explain,_),top:this.transformNode(h.top,_),output:this.transformNode(h.output,_)})}transformReturning(h,_){return Z({kind:"ReturningNode",selections:this.transformNodeList(h.selections,_)})}transformCreateTable(h,_){return Z({kind:"CreateTableNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),constraints:this.transformNodeList(h.constraints,_),temporary:h.temporary,ifNotExists:h.ifNotExists,onCommit:h.onCommit,frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),selectQuery:this.transformNode(h.selectQuery,_)})}transformColumnDefinition(h,_){return Z({kind:"ColumnDefinitionNode",column:this.transformNode(h.column,_),dataType:this.transformNode(h.dataType,_),references:this.transformNode(h.references,_),primaryKey:h.primaryKey,autoIncrement:h.autoIncrement,unique:h.unique,notNull:h.notNull,unsigned:h.unsigned,defaultTo:this.transformNode(h.defaultTo,_),check:this.transformNode(h.check,_),generated:this.transformNode(h.generated,_),frontModifiers:this.transformNodeList(h.frontModifiers,_),endModifiers:this.transformNodeList(h.endModifiers,_),nullsNotDistinct:h.nullsNotDistinct,identity:h.identity,ifNotExists:h.ifNotExists})}transformAddColumn(h,_){return Z({kind:"AddColumnNode",column:this.transformNode(h.column,_)})}transformDropTable(h,_){return Z({kind:"DropTableNode",table:this.transformNode(h.table,_),ifExists:h.ifExists,cascade:h.cascade})}transformOrderBy(h,_){return Z({kind:"OrderByNode",items:this.transformNodeList(h.items,_)})}transformOrderByItem(h,_){return Z({kind:"OrderByItemNode",orderBy:this.transformNode(h.orderBy,_),direction:this.transformNode(h.direction,_),collation:this.transformNode(h.collation,_),nulls:h.nulls})}transformGroupBy(h,_){return Z({kind:"GroupByNode",items:this.transformNodeList(h.items,_)})}transformGroupByItem(h,_){return Z({kind:"GroupByItemNode",groupBy:this.transformNode(h.groupBy,_)})}transformUpdateQuery(h,_){return Z({kind:"UpdateQueryNode",table:this.transformNode(h.table,_),from:this.transformNode(h.from,_),joins:this.transformNodeList(h.joins,_),where:this.transformNode(h.where,_),updates:this.transformNodeList(h.updates,_),returning:this.transformNode(h.returning,_),endModifiers:this.transformNodeList(h.endModifiers,_),with:this.transformNode(h.with,_),explain:this.transformNode(h.explain,_),limit:this.transformNode(h.limit,_),top:this.transformNode(h.top,_),output:this.transformNode(h.output,_),orderBy:this.transformNode(h.orderBy,_)})}transformColumnUpdate(h,_){return Z({kind:"ColumnUpdateNode",column:this.transformNode(h.column,_),value:this.transformNode(h.value,_)})}transformLimit(h,_){return Z({kind:"LimitNode",limit:this.transformNode(h.limit,_)})}transformOffset(h,_){return Z({kind:"OffsetNode",offset:this.transformNode(h.offset,_)})}transformOnConflict(h,_){return Z({kind:"OnConflictNode",columns:this.transformNodeList(h.columns,_),constraint:this.transformNode(h.constraint,_),indexExpression:this.transformNode(h.indexExpression,_),indexWhere:this.transformNode(h.indexWhere,_),updates:this.transformNodeList(h.updates,_),updateWhere:this.transformNode(h.updateWhere,_),doNothing:h.doNothing})}transformOnDuplicateKey(h,_){return Z({kind:"OnDuplicateKeyNode",updates:this.transformNodeList(h.updates,_)})}transformCreateIndex(h,_){return Z({kind:"CreateIndexNode",name:this.transformNode(h.name,_),table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),unique:h.unique,using:this.transformNode(h.using,_),ifNotExists:h.ifNotExists,where:this.transformNode(h.where,_),nullsNotDistinct:h.nullsNotDistinct})}transformList(h,_){return Z({kind:"ListNode",items:this.transformNodeList(h.items,_)})}transformDropIndex(h,_){return Z({kind:"DropIndexNode",name:this.transformNode(h.name,_),table:this.transformNode(h.table,_),ifExists:h.ifExists,cascade:h.cascade})}transformPrimaryKeyConstraint(h,_){return Z({kind:"PrimaryKeyConstraintNode",columns:this.transformNodeList(h.columns,_),name:this.transformNode(h.name,_),deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformUniqueConstraint(h,_){return Z({kind:"UniqueConstraintNode",columns:this.transformNodeList(h.columns,_),name:this.transformNode(h.name,_),nullsNotDistinct:h.nullsNotDistinct,deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformForeignKeyConstraint(h,_){return Z({kind:"ForeignKeyConstraintNode",columns:this.transformNodeList(h.columns,_),references:this.transformNode(h.references,_),name:this.transformNode(h.name,_),onDelete:h.onDelete,onUpdate:h.onUpdate,deferrable:h.deferrable,initiallyDeferred:h.initiallyDeferred})}transformSetOperation(h,_){return Z({kind:"SetOperationNode",operator:h.operator,expression:this.transformNode(h.expression,_),all:h.all})}transformReferences(h,_){return Z({kind:"ReferencesNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_),onDelete:h.onDelete,onUpdate:h.onUpdate})}transformCheckConstraint(h,_){return Z({kind:"CheckConstraintNode",expression:this.transformNode(h.expression,_),name:this.transformNode(h.name,_)})}transformWith(h,_){return Z({kind:"WithNode",expressions:this.transformNodeList(h.expressions,_),recursive:h.recursive})}transformCommonTableExpression(h,_){return Z({kind:"CommonTableExpressionNode",name:this.transformNode(h.name,_),materialized:h.materialized,expression:this.transformNode(h.expression,_)})}transformCommonTableExpressionName(h,_){return Z({kind:"CommonTableExpressionNameNode",table:this.transformNode(h.table,_),columns:this.transformNodeList(h.columns,_)})}transformHaving(h,_){return Z({kind:"HavingNode",having:this.transformNode(h.having,_)})}transformCreateSchema(h,_){return Z({kind:"CreateSchemaNode",schema:this.transformNode(h.schema,_),ifNotExists:h.ifNotExists})}transformDropSchema(h,_){return Z({kind:"DropSchemaNode",schema:this.transformNode(h.schema,_),ifExists:h.ifExists,cascade:h.cascade})}transformAlterTable(h,_){return Z({kind:"AlterTableNode",table:this.transformNode(h.table,_),renameTo:this.transformNode(h.renameTo,_),setSchema:this.transformNode(h.setSchema,_),columnAlterations:this.transformNodeList(h.columnAlterations,_),addConstraint:this.transformNode(h.addConstraint,_),dropConstraint:this.transformNode(h.dropConstraint,_),renameConstraint:this.transformNode(h.renameConstraint,_),addIndex:this.transformNode(h.addIndex,_),dropIndex:this.transformNode(h.dropIndex,_)})}transformDropColumn(h,_){return Z({kind:"DropColumnNode",column:this.transformNode(h.column,_)})}transformRenameColumn(h,_){return Z({kind:"RenameColumnNode",column:this.transformNode(h.column,_),renameTo:this.transformNode(h.renameTo,_)})}transformAlterColumn(h,_){return Z({kind:"AlterColumnNode",column:this.transformNode(h.column,_),dataType:this.transformNode(h.dataType,_),dataTypeExpression:this.transformNode(h.dataTypeExpression,_),setDefault:this.transformNode(h.setDefault,_),dropDefault:h.dropDefault,setNotNull:h.setNotNull,dropNotNull:h.dropNotNull})}transformModifyColumn(h,_){return Z({kind:"ModifyColumnNode",column:this.transformNode(h.column,_)})}transformAddConstraint(h,_){return Z({kind:"AddConstraintNode",constraint:this.transformNode(h.constraint,_)})}transformDropConstraint(h,_){return Z({kind:"DropConstraintNode",constraintName:this.transformNode(h.constraintName,_),ifExists:h.ifExists,modifier:h.modifier})}transformRenameConstraint(h,_){return Z({kind:"RenameConstraintNode",oldName:this.transformNode(h.oldName,_),newName:this.transformNode(h.newName,_)})}transformCreateView(h,_){return Z({kind:"CreateViewNode",name:this.transformNode(h.name,_),temporary:h.temporary,orReplace:h.orReplace,ifNotExists:h.ifNotExists,materialized:h.materialized,columns:this.transformNodeList(h.columns,_),as:this.transformNode(h.as,_)})}transformRefreshMaterializedView(h,_){return Z({kind:"RefreshMaterializedViewNode",name:this.transformNode(h.name,_),concurrently:h.concurrently,withNoData:h.withNoData})}transformDropView(h,_){return Z({kind:"DropViewNode",name:this.transformNode(h.name,_),ifExists:h.ifExists,materialized:h.materialized,cascade:h.cascade})}transformGenerated(h,_){return Z({kind:"GeneratedNode",byDefault:h.byDefault,always:h.always,identity:h.identity,stored:h.stored,expression:this.transformNode(h.expression,_)})}transformDefaultValue(h,_){return Z({kind:"DefaultValueNode",defaultValue:this.transformNode(h.defaultValue,_)})}transformOn(h,_){return Z({kind:"OnNode",on:this.transformNode(h.on,_)})}transformSelectModifier(h,_){return Z({kind:"SelectModifierNode",modifier:h.modifier,rawModifier:this.transformNode(h.rawModifier,_),of:this.transformNodeList(h.of,_)})}transformCreateType(h,_){return Z({kind:"CreateTypeNode",name:this.transformNode(h.name,_),enum:this.transformNode(h.enum,_)})}transformDropType(h,_){return Z({kind:"DropTypeNode",name:this.transformNode(h.name,_),ifExists:h.ifExists})}transformExplain(h,_){return Z({kind:"ExplainNode",format:h.format,options:this.transformNode(h.options,_)})}transformSchemableIdentifier(h,_){return Z({kind:"SchemableIdentifierNode",schema:this.transformNode(h.schema,_),identifier:this.transformNode(h.identifier,_)})}transformAggregateFunction(h,_){return Z({kind:"AggregateFunctionNode",func:h.func,aggregated:this.transformNodeList(h.aggregated,_),distinct:h.distinct,orderBy:this.transformNode(h.orderBy,_),withinGroup:this.transformNode(h.withinGroup,_),filter:this.transformNode(h.filter,_),over:this.transformNode(h.over,_)})}transformOver(h,_){return Z({kind:"OverNode",orderBy:this.transformNode(h.orderBy,_),partitionBy:this.transformNode(h.partitionBy,_)})}transformPartitionBy(h,_){return Z({kind:"PartitionByNode",items:this.transformNodeList(h.items,_)})}transformPartitionByItem(h,_){return Z({kind:"PartitionByItemNode",partitionBy:this.transformNode(h.partitionBy,_)})}transformBinaryOperation(h,_){return Z({kind:"BinaryOperationNode",leftOperand:this.transformNode(h.leftOperand,_),operator:this.transformNode(h.operator,_),rightOperand:this.transformNode(h.rightOperand,_)})}transformUnaryOperation(h,_){return Z({kind:"UnaryOperationNode",operator:this.transformNode(h.operator,_),operand:this.transformNode(h.operand,_)})}transformUsing(h,_){return Z({kind:"UsingNode",tables:this.transformNodeList(h.tables,_)})}transformFunction(h,_){return Z({kind:"FunctionNode",func:h.func,arguments:this.transformNodeList(h.arguments,_)})}transformCase(h,_){return Z({kind:"CaseNode",value:this.transformNode(h.value,_),when:this.transformNodeList(h.when,_),else:this.transformNode(h.else,_),isStatement:h.isStatement})}transformWhen(h,_){return Z({kind:"WhenNode",condition:this.transformNode(h.condition,_),result:this.transformNode(h.result,_)})}transformJSONReference(h,_){return Z({kind:"JSONReferenceNode",reference:this.transformNode(h.reference,_),traversal:this.transformNode(h.traversal,_)})}transformJSONPath(h,_){return Z({kind:"JSONPathNode",inOperator:this.transformNode(h.inOperator,_),pathLegs:this.transformNodeList(h.pathLegs,_)})}transformJSONPathLeg(h,_){return Z({kind:"JSONPathLegNode",type:h.type,value:h.value})}transformJSONOperatorChain(h,_){return Z({kind:"JSONOperatorChainNode",operator:this.transformNode(h.operator,_),values:this.transformNodeList(h.values,_)})}transformTuple(h,_){return Z({kind:"TupleNode",values:this.transformNodeList(h.values,_)})}transformMergeQuery(h,_){return Z({kind:"MergeQueryNode",into:this.transformNode(h.into,_),using:this.transformNode(h.using,_),whens:this.transformNodeList(h.whens,_),with:this.transformNode(h.with,_),top:this.transformNode(h.top,_),endModifiers:this.transformNodeList(h.endModifiers,_),output:this.transformNode(h.output,_),returning:this.transformNode(h.returning,_)})}transformMatched(h,_){return Z({kind:"MatchedNode",not:h.not,bySource:h.bySource})}transformAddIndex(h,_){return Z({kind:"AddIndexNode",name:this.transformNode(h.name,_),columns:this.transformNodeList(h.columns,_),unique:h.unique,using:this.transformNode(h.using,_),ifNotExists:h.ifNotExists})}transformCast(h,_){return Z({kind:"CastNode",expression:this.transformNode(h.expression,_),dataType:this.transformNode(h.dataType,_)})}transformFetch(h,_){return Z({kind:"FetchNode",rowCount:this.transformNode(h.rowCount,_),modifier:h.modifier})}transformTop(h,_){return Z({kind:"TopNode",expression:h.expression,modifiers:h.modifiers})}transformOutput(h,_){return Z({kind:"OutputNode",selections:this.transformNodeList(h.selections,_)})}transformDataType(h,_){return h}transformSelectAll(h,_){return h}transformIdentifier(h,_){return h}transformValue(h,_){return h}transformPrimitiveValueList(h,_){return h}transformOperator(h,_){return h}transformDefaultInsertValue(h,_){return h}transformOrAction(h,_){return h}transformCollate(h,_){return h}}var J8=k({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),Y8={json_agg:!0,to_json:!0};class vW extends Dh{#h;#_=new Set;#k=new Set;constructor(h){super();this.#h=h}transformNodeImpl(h,_){if(!this.#$(h))return super.transformNodeImpl(h,_);let W=this.#J(h);for(let Y of W)this.#k.add(Y);let $=this.#Z(h);for(let Y of $)this.#_.add(Y);let J=super.transformNodeImpl(h,_);for(let Y of $)this.#_.delete(Y);for(let Y of W)this.#k.delete(Y);return J}transformSchemableIdentifier(h,_){let W=super.transformSchemableIdentifier(h,_);if(W.schema||!this.#_.has(h.identifier.name))return W;return{...W,schema:X.create(this.#h)}}transformReferences(h,_){let W=super.transformReferences(h,_);if(W.table.table.schema)return W;return{...W,table:d.createWithSchema(this.#h,W.table.table.identifier.name)}}transformAggregateFunction(h,_){return{...super.transformAggregateFunction({...h,aggregated:[]},_),aggregated:this.#W(h,_,"aggregated")}}transformFunction(h,_){return{...super.transformFunction({...h,arguments:[]},_),arguments:this.#W(h,_,"arguments")}}transformSelectModifier(h,_){return{...super.transformSelectModifier({...h,of:void 0},_),of:h.of?.map((W)=>d.is(W)&&!W.table.schema?{...W,table:this.transformIdentifier(W.table.identifier,_)}:this.transformNode(W,_))}}#W(h,_,W){return Y8[h.func]?h[W].map(($)=>!d.is($)||$.table.schema?this.transformNode($,_):{...$,table:this.transformIdentifier($.table.identifier,_)}):this.transformNodeList(h[W],_)}#$(h){return h.kind in J8}#Z(h){let _=new Set;if("name"in h&&h.name&&l.is(h.name))this.#G(h.name,_);if("from"in h&&h.from)for(let W of h.from.froms)this.#Y(W,_);if("into"in h&&h.into)this.#Y(h.into,_);if("table"in h&&h.table)this.#Y(h.table,_);if("joins"in h&&h.joins)for(let W of h.joins)this.#Y(W.table,_);if("using"in h&&h.using)if(Uh.is(h.using))this.#Y(h.using.table,_);else this.#Y(h.using,_);return _}#J(h){let _=new Set;if("with"in h&&h.with)this.#H(h.with,_);return _}#Y(h,_){if(d.is(h))return this.#G(h.table,_);if(I.is(h)&&d.is(h.node))return this.#G(h.node.table,_);if(Sk.is(h)){for(let W of h.items)this.#Y(W,_);return}if(kk.is(h)){for(let W of h.tables)this.#Y(W,_);return}}#G(h,_){let W=h.identifier.name;if(!this.#_.has(W)&&!this.#k.has(W))_.add(W)}#H(h,_){for(let W of h.expressions){let $=W.name.table.table.identifier.name;if(!this.#k.has($))_.add($)}}}class Zh{#h;constructor(h){this.#h=new vW(h)}transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}async transformResult(h){return h.result}}var u$=k({is(h){return h.kind==="MatchedNode"},create(h,_=!1){return k({kind:"MatchedNode",not:h,bySource:_})}});function PW(h,_,W){return Hh.create(E_([u$.create(!h.isMatched,h.bySource),..._&&_.length>0?[_.length===3&&W?g(_[0],_[1],_[2]):A(_)]:[]],"and",!1))}function m_(h){if(M(h))return V.create([h],[]);if(T(h))return h.toOperationNode();return h}class Z_{#h;#_;#k;constructor(){this.#h=new Promise((h,_)=>{this.#k=_,this.#_=h})}get promise(){return this.#h}resolve=(h)=>{if(this.#_)this.#_(h)};reject=(h)=>{if(this.#k)this.#k(h)}}async function jk(h){let _=new Z_,W=new Z_;return h.provideConnection(async($)=>{return _.resolve($),await W.promise}).catch(($)=>_.reject($)),k({connection:await _.promise,release:W.resolve})}var Z8=k([]);class Zk{#h;constructor(h=Z8){this.#h=h}get plugins(){return this.#h}transformQuery(h,_){for(let W of this.#h){let $=W.transformQuery({node:h,queryId:_});if($.kind===h.kind)h=$;else throw Error(["KyselyPlugin.transformQuery must return a node","of the same kind that was given to it.",`The plugin was given a ${h.kind}`,`but it returned a ${$.kind}`].join(" "))}return h}async executeQuery(h){return await this.provideConnection(async(_)=>{let W=await _.executeQuery(h);if("numUpdatedOrDeletedRows"in W)Ch("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`.");return await this.#_(W,h.queryId)})}async*stream(h,_){let{connection:W,release:$}=await jk(this);try{for await(let J of W.streamQuery(h,_))yield await this.#_(J,h.queryId)}finally{$()}}async#_(h,_){for(let W of this.#h)h=await W.transformResult({result:h,queryId:_});return h}}class Q_ extends Zk{get adapter(){throw Error("this query cannot be compiled to SQL")}compileQuery(){throw Error("this query cannot be compiled to SQL")}provideConnection(){throw Error("this query cannot be executed")}withConnectionProvider(){throw Error("this query cannot have a connection provider")}withPlugin(h){return new Q_([...this.plugins,h])}withPlugins(h){return new Q_([...this.plugins,...h])}withPluginAtFront(h){return new Q_([h,...this.plugins])}withoutPlugins(){return new Q_([])}}var G_=new Q_;class DW{numChangedRows;constructor(h){this.numChangedRows=h}}class lh{#h;constructor(h){this.#h=k(h)}modifyEnd(h){return new lh({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}top(h,_){return new lh({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}using(...h){return new e({...this.#h,queryNode:Yh.cloneWithUsing(this.#h.queryNode,Y_("Using",h))})}returning(h){return new lh({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new lh({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new lh({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new lh({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}}class e{#h;constructor(h){this.#h=k(h)}modifyEnd(h){return new e({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,h.toOperationNode())})}top(h,_){return new e({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}whenMatched(){return this.#_([])}whenMatchedAnd(...h){return this.#_(h)}whenMatchedAndRef(h,_,W){return this.#_([h,_,W],!0)}#_(h,_){return new OW({...this.#h,queryNode:Yh.cloneWithWhen(this.#h.queryNode,PW({isMatched:!0},h,_))})}whenNotMatched(){return this.#k([])}whenNotMatchedAnd(...h){return this.#k(h)}whenNotMatchedAndRef(h,_,W){return this.#k([h,_,W],!0)}whenNotMatchedBySource(){return this.#k([],!1,!0)}whenNotMatchedBySourceAnd(...h){return this.#k(h,!1,!0)}whenNotMatchedBySourceAndRef(h,_,W){return this.#k([h,_,W],!0,!0)}returning(h){return new e({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,B(h))})}returningAll(h){return new e({...this.#h,queryNode:G.cloneWithReturning(this.#h.queryNode,c(h))})}output(h){return new e({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,B(h))})}outputAll(h){return new e({...this.#h,queryNode:G.cloneWithOutput(this.#h.queryNode,c(h))})}#k(h,_=!1,W=!1){let $={...this.#h,queryNode:Yh.cloneWithWhen(this.#h.queryNode,PW({isMatched:!1,bySource:W},h,_))};return new(W?OW:l$)($)}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new e({...this.#h})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile(),_=await this.#h.executor.executeQuery(h),{adapter:W}=this.#h.executor,$=h.query;if($.returning&&W.supportsReturning||$.output&&W.supportsOutput)return _.rows;return[new DW(_.numAffectedRows)]}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=Rh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}}class OW{#h;constructor(h){this.#h=k(h)}thenDelete(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("delete"))})}thenDoNothing(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("do nothing"))})}thenUpdate(h){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_(h(new E({queryId:this.#h.queryId,executor:G_,queryNode:jh.createWithoutTable()}))))})}thenUpdateSet(...h){return this.thenUpdate((_)=>_.set(...h))}}class l${#h;constructor(h){this.#h=k(h)}thenDoNothing(){return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_("do nothing"))})}thenInsertValues(h){let[_,W]=xk(h);return new e({...this.#h,queryNode:Yh.cloneWithThen(this.#h.queryNode,m_(m.cloneWith(m.createWithoutInto(),{columns:_,values:W})))})}}class bh{#h;constructor(h){this.#h=k(h)}selectFrom(h){return b_({queryId:L(),executor:this.#h.executor,queryNode:w.createFrom(Ph(h),this.#h.withNode)})}selectNoFrom(h){return b_({queryId:L(),executor:this.#h.executor,queryNode:w.cloneWithSelections(w.create(this.#h.withNode),B(h))})}insertInto(h){return new D({queryId:L(),executor:this.#h.executor,queryNode:m.create(f(h),this.#h.withNode)})}replaceInto(h){return new D({queryId:L(),executor:this.#h.executor,queryNode:m.create(f(h),this.#h.withNode,!0)})}deleteFrom(h){return new j({queryId:L(),executor:this.#h.executor,queryNode:J_.create(Ph(h),this.#h.withNode)})}updateTable(h){return new E({queryId:L(),executor:this.#h.executor,queryNode:jh.create(Ph(h),this.#h.withNode)})}mergeInto(h){return new lh({queryId:L(),executor:this.#h.executor,queryNode:Yh.create(AW(h),this.#h.withNode)})}with(h,_){let W=RW(h,_);return new bh({...this.#h,withNode:this.#h.withNode?Yk.cloneWithExpression(this.#h.withNode,W):Yk.create(W)})}withRecursive(h,_){let W=RW(h,_);return new bh({...this.#h,withNode:this.#h.withNode?Yk.cloneWithExpression(this.#h.withNode,W):Yk.create(W,{recursive:!0})})}withPlugin(h){return new bh({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new bh({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new bh({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}}function y$(){return new bh({executor:G_})}function p$(h,_){return new S_({joinNode:Uh.create(h,F_(_))})}function a$(){return new N_({overNode:_k.create()})}function Y_(h,_){if(_.length===3)return H8(h,_[0],_[1],_[2]);else if(_.length===2)return G8(h,_[0],_[1]);else if(_.length===1)return X8(h,_[0]);else throw Error("not implemented")}function G8(h,_,W){return W(p$(h,_)).toOperationNode()}function H8(h,_,W,$){return Uh.createWithOn(h,F_(_),g(W,"=",$))}function X8(h,_){return Uh.create(h,F_(_))}var s$=k({is(h){return h.kind==="OffsetNode"},create(h){return k({kind:"OffsetNode",offset:h})}});var n$=k({is(h){return h.kind==="GroupByItemNode"},create(h){return k({kind:"GroupByItemNode",groupBy:h})}});function d$(h){return h=R(h)?h(wh()):h,ih(h).map(n$.create)}var mk=k({is(h){return h.kind==="SetOperationNode"},create(h,_,W){return k({kind:"SetOperationNode",operator:h,expression:_,all:W})}});function U_(h,_,W){if(R(_))_=_(Qk());if(!q(_))_=[_];return _.map(($)=>mk.create(h,o($),W))}class v{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}or(...h){return new bk(Fh.create(this.#h,A(h)))}and(...h){return new Bk(r.create(this.#h,A(h)))}$castTo(){return new v(this.#h)}$notNull(){return new v(this.#h)}toOperationNode(){return this.#h}}class qk{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}class bk{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}or(...h){return new bk(Fh.create(this.#h,A(h)))}$castTo(){return new bk(this.#h)}toOperationNode(){return Jh.create(this.#h)}}class Bk{#h;constructor(h){this.#h=h}get expressionType(){return}as(h){return new qk(this,h)}and(...h){return new Bk(r.create(this.#h,A(h)))}$castTo(){return new Bk(this.#h)}toOperationNode(){return Jh.create(this.#h)}}var r$=k({is(h){return h.kind==="FetchNode"},create(h,_){return{kind:"FetchNode",rowCount:C.create(h),modifier:_}}});function o$(h,_){if(!Kh(h)&&!__(h))throw Error(`Invalid fetch row count: ${h}`);if(!L8(_))throw Error(`Invalid fetch modifier: ${_}`);return r$.create(h,_)}function L8(h){return h==="only"||h==="with ties"}class z{#h;constructor(h){this.#h=k(h)}get expressionType(){return}get isSelectQueryBuilder(){return!0}where(...h){return new z({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,A(h))})}whereRef(h,_,W){return new z({...this.#h,queryNode:G.cloneWithWhere(this.#h.queryNode,g(h,_,W))})}having(...h){return new z({...this.#h,queryNode:w.cloneWithHaving(this.#h.queryNode,A(h))})}havingRef(h,_,W){return new z({...this.#h,queryNode:w.cloneWithHaving(this.#h.queryNode,g(h,_,W))})}select(h){return new z({...this.#h,queryNode:w.cloneWithSelections(this.#h.queryNode,B(h))})}distinctOn(h){return new z({...this.#h,queryNode:w.cloneWithDistinctOn(this.#h.queryNode,ih(h))})}modifyFront(h){return new z({...this.#h,queryNode:w.cloneWithFrontModifier(this.#h.queryNode,xh.createWithExpression(h.toOperationNode()))})}modifyEnd(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.createWithExpression(h.toOperationNode()))})}distinct(){return new z({...this.#h,queryNode:w.cloneWithFrontModifier(this.#h.queryNode,xh.create("Distinct"))})}forUpdate(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("ForUpdate",h?r_(h).map(f):void 0))})}forShare(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("ForShare",h?r_(h).map(f):void 0))})}forKeyShare(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("ForKeyShare",h?r_(h).map(f):void 0))})}forNoKeyUpdate(h){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("ForNoKeyUpdate",h?r_(h).map(f):void 0))})}skipLocked(){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("SkipLocked"))})}noWait(){return new z({...this.#h,queryNode:G.cloneWithEndModifier(this.#h.queryNode,xh.create("NoWait"))})}selectAll(h){return new z({...this.#h,queryNode:w.cloneWithSelections(this.#h.queryNode,c(h))})}innerJoin(...h){return this.#_("InnerJoin",h)}leftJoin(...h){return this.#_("LeftJoin",h)}rightJoin(...h){return this.#_("RightJoin",h)}fullJoin(...h){return this.#_("FullJoin",h)}crossJoin(...h){return this.#_("CrossJoin",h)}innerJoinLateral(...h){return this.#_("LateralInnerJoin",h)}leftJoinLateral(...h){return this.#_("LateralLeftJoin",h)}crossJoinLateral(...h){return this.#_("LateralCrossJoin",h)}crossApply(...h){return this.#_("CrossApply",h)}outerApply(...h){return this.#_("OuterApply",h)}#_(h,_){return new z({...this.#h,queryNode:G.cloneWithJoin(this.#h.queryNode,Y_(h,_))})}orderBy(...h){return new z({...this.#h,queryNode:G.cloneWithOrderByItems(this.#h.queryNode,Wh(h))})}groupBy(h){return new z({...this.#h,queryNode:w.cloneWithGroupByItems(this.#h.queryNode,d$(h))})}limit(h){return new z({...this.#h,queryNode:w.cloneWithLimit(this.#h.queryNode,C_.create(P(h)))})}offset(h){return new z({...this.#h,queryNode:w.cloneWithOffset(this.#h.queryNode,s$.create(P(h)))})}fetch(h,_="only"){return new z({...this.#h,queryNode:w.cloneWithFetch(this.#h.queryNode,o$(h,_))})}top(h,_){return new z({...this.#h,queryNode:G.cloneWithTop(this.#h.queryNode,vh(h,_))})}union(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("union",h,!1))})}unionAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("union",h,!0))})}intersect(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("intersect",h,!1))})}intersectAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("intersect",h,!0))})}except(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("except",h,!1))})}exceptAll(h){return new z({...this.#h,queryNode:w.cloneWithSetOperations(this.#h.queryNode,U_("except",h,!0))})}as(h){return new e$(this,h)}clearSelect(){return new z({...this.#h,queryNode:w.cloneWithoutSelections(this.#h.queryNode)})}clearWhere(){return new z({...this.#h,queryNode:G.cloneWithoutWhere(this.#h.queryNode)})}clearLimit(){return new z({...this.#h,queryNode:w.cloneWithoutLimit(this.#h.queryNode)})}clearOffset(){return new z({...this.#h,queryNode:w.cloneWithoutOffset(this.#h.queryNode)})}clearOrderBy(){return new z({...this.#h,queryNode:G.cloneWithoutOrderBy(this.#h.queryNode)})}clearGroupBy(){return new z({...this.#h,queryNode:w.cloneWithoutGroupBy(this.#h.queryNode)})}$call(h){return h(this)}$if(h,_){if(h)return _(this);return new z({...this.#h})}$castTo(){return new z(this.#h)}$narrowType(){return new z(this.#h)}$assertType(){return new z(this.#h)}$asTuple(){return new v(this.toOperationNode())}$asScalar(){return new v(this.toOperationNode())}withPlugin(h){return new z({...this.#h,executor:this.#h.executor.withPlugin(h)})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.queryNode,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){let h=this.compile();return(await this.#h.executor.executeQuery(h)).rows}async executeTakeFirst(){let[h]=await this.execute();return h}async executeTakeFirstOrThrow(h=Rh){let _=await this.executeTakeFirst();if(_===void 0)throw mh(h)?new h(this.toOperationNode()):h(this.toOperationNode());return _}async*stream(h=100){let _=this.compile(),W=this.#h.executor.stream(_,h);for await(let $ of W)yield*$.rows}async explain(h,_){return await new z({...this.#h,queryNode:G.cloneWithExplain(this.#h.queryNode,h,_)}).execute()}}function b_(h){return new z(h)}class e${#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return I.create(this.#h.toOperationNode(),X.create(this.#_))}}var Bh=k({is(h){return h.kind==="AggregateFunctionNode"},create(h,_=[]){return k({kind:"AggregateFunctionNode",func:h,aggregated:_})},cloneWithDistinct(h){return k({...h,distinct:!0})},cloneWithOrderBy(h,_,W=!1){let $=W?"withinGroup":"orderBy";return k({...h,[$]:h[$]?uh.cloneWithItems(h[$],_):uh.create(_)})},cloneWithFilter(h,_){return k({...h,filter:h.filter?i.cloneWithOperation(h.filter,"And",_):i.create(_)})},cloneWithOrFilter(h,_){return k({...h,filter:h.filter?i.cloneWithOperation(h.filter,"Or",_):i.create(_)})},cloneWithOver(h,_){return k({...h,over:_})}});var TW=k({is(h){return h.kind==="FunctionNode"},create(h,_){return k({kind:"FunctionNode",func:h,arguments:_})}});class hh{#h;constructor(h){this.#h=k(h)}get expressionType(){return}as(h){return new h1(this,h)}distinct(){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithDistinct(this.#h.aggregateFunctionNode)})}orderBy(...h){return new hh({...this.#h,aggregateFunctionNode:G.cloneWithOrderByItems(this.#h.aggregateFunctionNode,Wh(h))})}clearOrderBy(){return new hh({...this.#h,aggregateFunctionNode:G.cloneWithoutOrderBy(this.#h.aggregateFunctionNode)})}withinGroupOrderBy(...h){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithOrderBy(this.#h.aggregateFunctionNode,Wh(h),!0)})}filterWhere(...h){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithFilter(this.#h.aggregateFunctionNode,A(h))})}filterWhereRef(h,_,W){return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithFilter(this.#h.aggregateFunctionNode,g(h,_,W))})}over(h){let _=a$();return new hh({...this.#h,aggregateFunctionNode:Bh.cloneWithOver(this.#h.aggregateFunctionNode,(h?h(_):_).toOperationNode())})}$call(h){return h(this)}$castTo(){return new hh(this.#h)}$notNull(){return new hh(this.#h)}toOperationNode(){return this.#h.aggregateFunctionNode}}class h1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),X.create(this.#_))}}function Ik(){let h=(W,$)=>{return new v(TW.create(W,ih($??[])))},_=(W,$)=>{return new hh({aggregateFunctionNode:Bh.create(W,$?ih($):void 0)})};return Object.assign(h,{agg:_,avg(W){return _("avg",[W])},coalesce(...W){return h("coalesce",W)},count(W){return _("count",[W])},countAll(W){return new hh({aggregateFunctionNode:Bh.create("count",c(W))})},max(W){return _("max",[W])},min(W){return _("min",[W])},sum(W){return _("sum",[W])},any(W){return h("any",[W])},jsonAgg(W){return new hh({aggregateFunctionNode:Bh.create("json_agg",[M(W)?f(W):W.toOperationNode()])})},toJson(W){return new v(TW.create("to_json",[M(W)?f(W):W.toOperationNode()]))}})}var _1=k({is(h){return h.kind==="UnaryOperationNode"},create(h,_){return k({kind:"UnaryOperationNode",operator:h,operand:_})}});function k1(h,_){return _1.create(y.create(h),t(_))}var Gh=k({is(h){return h.kind==="CaseNode"},create(h){return k({kind:"CaseNode",value:h})},cloneWithWhen(h,_){return k({...h,when:k(h.when?[...h.when,_]:[_])})},cloneWithThen(h,_){return k({...h,when:h.when?k([...h.when.slice(0,-1),Hh.cloneWithResult(h.when[h.when.length-1],_)]):void 0})},cloneWith(h,_){return k({...h,..._})}});class Gk{#h;constructor(h){this.#h=k(h)}when(...h){return new EW({...this.#h,node:Gh.cloneWithWhen(this.#h.node,Hh.create(A(h)))})}}class EW{#h;constructor(h){this.#h=k(h)}then(h){return new W1({...this.#h,node:Gh.cloneWithThen(this.#h.node,Tk(h)?hk(h):P(h))})}}class W1{#h;constructor(h){this.#h=k(h)}when(...h){return new EW({...this.#h,node:Gh.cloneWithWhen(this.#h.node,Hh.create(A(h)))})}else(h){return new $1({...this.#h,node:Gh.cloneWith(this.#h.node,{else:Tk(h)?hk(h):P(h)})})}end(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!1}))}endCase(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!0}))}}class $1{#h;constructor(h){this.#h=k(h)}end(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!1}))}endCase(){return new v(Gh.cloneWith(this.#h.node,{isStatement:!0}))}}var SW=k({is(h){return h.kind==="JSONPathLegNode"},create(h,_){return k({kind:"JSONPathLegNode",type:h,value:_})}});class Xk{#h;constructor(h){this.#h=h}at(h){return this.#_("ArrayLocation",h)}key(h){return this.#_("Member",h)}#_(h,_){if(O_.is(this.#h))return new Hk(O_.cloneWithTraversal(this.#h,$_.is(this.#h.traversal)?$_.cloneWithLeg(this.#h.traversal,SW.create(h,_)):Ak.cloneWithValue(this.#h.traversal,C.createImmediate(_))));return new Hk($_.cloneWithLeg(this.#h,SW.create(h,_)))}}class Hk extends Xk{#h;constructor(h){super(h);this.#h=h}get expressionType(){return}as(h){return new J1(this,h)}$castTo(){return new Hk(this.#h)}$notNull(){return new Hk(this.#h)}toOperationNode(){return this.#h}}class J1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}var NW=k({is(h){return h.kind==="TupleNode"},create(h){return k({kind:"TupleNode",values:k(h)})}});var z8=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],K8=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],gk=k({is(h){return h.kind==="DataTypeNode"},create(h){return k({kind:"DataTypeNode",dataType:h})}});function Y1(h){if(z8.includes(h))return!0;if(K8.some((_)=>_.test(h)))return!0;return!1}function Oh(h){if(T(h))return h.toOperationNode();if(Y1(h))return gk.create(h);throw Error(`invalid column data type ${JSON.stringify(h)}`)}var ck=k({is(h){return h.kind==="CastNode"},create(h,_){return k({kind:"CastNode",expression:h,dataType:_})}});function Qk(h=G_){function _(J,Y,H){return new v(Ek(J,Y,H))}function W(J,Y){return new v(k1(J,Y))}let $=Object.assign(_,{fn:void 0,eb:void 0,selectFrom(J){return b_({queryId:L(),executor:h,queryNode:w.createFrom(Ph(J))})},case(J){return new Gk({node:Gh.create(a(J)?void 0:t(J))})},ref(J,Y){if(a(Y))return new v(kh(J));return new Xk(O$(J,Y))},jsonPath(){return new Xk($_.create())},table(J){return new v(f(J))},val(J){return new v(P(J))},refTuple(...J){return new v(NW.create(J.map(t)))},tuple(...J){return new v(NW.create(J.map(P)))},lit(J){return new v(hk(J))},unary:W,not(J){return W("not",J)},exists(J){return W("exists",J)},neg(J){return W("-",J)},between(J,Y,H){return new v(Vh.create(t(J),y.create("between"),r.create(P(Y),P(H))))},betweenSymmetric(J,Y,H){return new v(Vh.create(t(J),y.create("between symmetric"),r.create(P(Y),P(H))))},and(J){if(q(J))return new v(E_(J,"and"));return new v(HW(J,"and"))},or(J){if(q(J))return new v(E_(J,"or"));return new v(HW(J,"or"))},parens(...J){let Y=A(J);if(Jh.is(Y))return new v(Y);else return new v(Jh.create(Y))},cast(J,Y){return new v(ck.create(t(J),Oh(Y)))},withSchema(J){return Qk(h.withPluginAtFront(new Zh(J)))}});return $.fn=Ik(),$.eb=$,$}function wh(h){return Qk()}function o(h){if(T(h))return h.toOperationNode();else if(R(h))return h(wh()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(h)}`)}function Nk(h){if(T(h))return h.toOperationNode();else if(R(h))return h(wh()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(h)}`)}function th(h){return Pk(h)||U$(h)||R(h)}class xW{#h;get table(){return this.#h}constructor(h){this.#h=h}as(h){return new Z1(this.#h,h)}}class Z1{#h;#_;get table(){return this.#h}get alias(){return this.#_}constructor(h,_){this.#h=h,this.#_=_}toOperationNode(){return I.create(f(this.#h),X.create(this.#_))}}function G1(h){return O(h)&&T(h)&&M(h.table)&&M(h.alias)}function Ph(h){if(q(h))return h.map((_)=>F_(_));else return[F_(h)]}function F_(h){if(M(h))return AW(h);else if(G1(h))return h.toOperationNode();else return Nk(h)}function AW(h){if(h.includes(" as ")){let[W,$]=h.split(" as ").map(H1);return I.create(f(W),X.create($))}else return f(h)}function f(h){if(h.includes(".")){let[W,$]=h.split(".").map(H1);return d.createWithSchema(W,$)}else return d.create(h)}function H1(h){return h.trim()}var CW=k({is(h){return h.kind==="AddColumnNode"},create(h){return k({kind:"AddColumnNode",column:h})}});var S=k({is(h){return h.kind==="ColumnDefinitionNode"},create(h,_){return k({kind:"ColumnDefinitionNode",column:F.create(h),dataType:_})},cloneWithFrontModifier(h,_){return k({...h,frontModifiers:h.frontModifiers?k([...h.frontModifiers,_]):[_]})},cloneWithEndModifier(h,_){return k({...h,endModifiers:h.endModifiers?k([...h.endModifiers,_]):[_]})},cloneWith(h,_){return k({...h,..._})}});var jW=k({is(h){return h.kind==="DropColumnNode"},create(h){return k({kind:"DropColumnNode",column:F.create(h)})}});var mW=k({is(h){return h.kind==="RenameColumnNode"},create(h,_){return k({kind:"RenameColumnNode",column:F.create(h),renameTo:F.create(_)})}});var B_=k({is(h){return h.kind==="CheckConstraintNode"},create(h,_){return k({kind:"CheckConstraintNode",expression:h,name:_?X.create(_):void 0})}});var X1=["no action","restrict","cascade","set null","set default"],q_=k({is(h){return h.kind==="ReferencesNode"},create(h,_){return k({kind:"ReferencesNode",table:h,columns:k([..._])})},cloneWithOnDelete(h,_){return k({...h,onDelete:_})},cloneWithOnUpdate(h,_){return k({...h,onUpdate:_})}});function yk(h){return T(h)?h.toOperationNode():C.createImmediate(h)}var Lk=k({is(h){return h.kind==="GeneratedNode"},create(h){return k({kind:"GeneratedNode",...h})},createWithExpression(h){return k({kind:"GeneratedNode",always:!0,expression:h})},cloneWith(h,_){return k({...h,..._})}});var L1=k({is(h){return h.kind==="DefaultValueNode"},create(h){return k({kind:"DefaultValueNode",defaultValue:h})}});function I_(h){if(X1.includes(h))return h;throw Error(`invalid OnModifyForeignAction ${h}`)}class N{#h;constructor(h){this.#h=h}autoIncrement(){return new N(S.cloneWith(this.#h,{autoIncrement:!0}))}identity(){return new N(S.cloneWith(this.#h,{identity:!0}))}primaryKey(){return new N(S.cloneWith(this.#h,{primaryKey:!0}))}references(h){let _=kh(h);if(!_.table||P_.is(_.column))throw Error(`invalid call references('${h}'). The reference must have format table.column or schema.table.column`);return new N(S.cloneWith(this.#h,{references:q_.create(_.table,[_.column])}))}onDelete(h){if(!this.#h.references)throw Error("on delete constraint can only be added for foreign keys");return new N(S.cloneWith(this.#h,{references:q_.cloneWithOnDelete(this.#h.references,I_(h))}))}onUpdate(h){if(!this.#h.references)throw Error("on update constraint can only be added for foreign keys");return new N(S.cloneWith(this.#h,{references:q_.cloneWithOnUpdate(this.#h.references,I_(h))}))}unique(){return new N(S.cloneWith(this.#h,{unique:!0}))}notNull(){return new N(S.cloneWith(this.#h,{notNull:!0}))}unsigned(){return new N(S.cloneWith(this.#h,{unsigned:!0}))}defaultTo(h){return new N(S.cloneWith(this.#h,{defaultTo:L1.create(yk(h))}))}check(h){return new N(S.cloneWith(this.#h,{check:B_.create(h.toOperationNode())}))}generatedAlwaysAs(h){return new N(S.cloneWith(this.#h,{generated:Lk.createWithExpression(h.toOperationNode())}))}generatedAlwaysAsIdentity(){return new N(S.cloneWith(this.#h,{generated:Lk.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new N(S.cloneWith(this.#h,{generated:Lk.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#h.generated)throw Error("stored() can only be called after generatedAlwaysAs");return new N(S.cloneWith(this.#h,{generated:Lk.cloneWith(this.#h.generated,{stored:!0})}))}modifyFront(h){return new N(S.cloneWithFrontModifier(this.#h,h.toOperationNode()))}nullsNotDistinct(){return new N(S.cloneWith(this.#h,{nullsNotDistinct:!0}))}ifNotExists(){return new N(S.cloneWith(this.#h,{ifNotExists:!0}))}modifyEnd(h){return new N(S.cloneWithEndModifier(this.#h,h.toOperationNode()))}$call(h){return h(this)}toOperationNode(){return this.#h}}var QW=k({is(h){return h.kind==="ModifyColumnNode"},create(h){return k({kind:"ModifyColumnNode",column:h})}});var Ah=k({is(h){return h.kind==="ForeignKeyConstraintNode"},create(h,_,W,$){return k({kind:"ForeignKeyConstraintNode",columns:h,references:q_.create(_,W),name:$?X.create($):void 0})},cloneWith(h,_){return k({...h,..._})}});class Th{#h;constructor(h){this.#h=h}onDelete(h){return new Th(Ah.cloneWith(this.#h,{onDelete:I_(h)}))}onUpdate(h){return new Th(Ah.cloneWith(this.#h,{onUpdate:I_(h)}))}deferrable(){return new Th(Ah.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new Th(Ah.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new Th(Ah.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new Th(Ah.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}var g_=k({is(h){return h.kind==="AddConstraintNode"},create(h){return k({kind:"AddConstraintNode",constraint:h})}});var qh=k({is(h){return h.kind==="UniqueConstraintNode"},create(h,_,W){return k({kind:"UniqueConstraintNode",columns:k(h.map(F.create)),name:_?X.create(_):void 0,nullsNotDistinct:W})},cloneWith(h,_){return k({...h,..._})}});var c_=k({is(h){return h.kind==="DropConstraintNode"},create(h){return k({kind:"DropConstraintNode",constraintName:X.create(h)})},cloneWith(h,_){return k({...h,..._})}});var y_=k({is(h){return h.kind==="AlterColumnNode"},create(h,_,W){return k({kind:"AlterColumnNode",column:F.create(h),[_]:W})}});class tk{#h;constructor(h){this.#h=h}setDataType(h){return new t_(y_.create(this.#h,"dataType",Oh(h)))}setDefault(h){return new t_(y_.create(this.#h,"setDefault",yk(h)))}dropDefault(){return new t_(y_.create(this.#h,"dropDefault",!0))}setNotNull(){return new t_(y_.create(this.#h,"setNotNull",!0))}dropNotNull(){return new t_(y_.create(this.#h,"dropNotNull",!0))}$call(h){return h(this)}}class t_{#h;constructor(h){this.#h=h}toOperationNode(){return this.#h}}class H_{#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class ph{#h;constructor(h){this.#h=k(h)}onDelete(h){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.onDelete(h)})}onUpdate(h){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.onUpdate(h)})}deferrable(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.deferrable()})}notDeferrable(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new ph({...this.#h,constraintBuilder:this.#h.constraintBuilder.initiallyImmediate()})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create(this.#h.constraintBuilder.toOperationNode())}),this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class V_{#h;constructor(h){this.#h=k(h)}ifExists(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{ifExists:!0})})})}cascade(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.cloneWith(this.#h.node.dropConstraint,{modifier:"restrict"})})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var Ih=k({is(h){return h.kind==="PrimaryKeyConstraintNode"},create(h,_){return k({kind:"PrimaryKeyConstraintNode",columns:k(h.map(F.create)),name:_?X.create(_):void 0})},cloneWith(h,_){return k({...h,..._})}}),J2=Ih;var X_=k({is(h){return h.kind==="AddIndexNode"},create(h){return k({kind:"AddIndexNode",name:X.create(h)})},cloneWith(h,_){return k({...h,..._})},cloneWithColumns(h,_){return k({...h,columns:[...h.columns||[],..._]})}});class L_{#h;constructor(h){this.#h=k(h)}unique(){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWith(this.#h.node.addIndex,{unique:!0})})})}column(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,[A_(h)])})})}columns(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,h.map(A_))})})}expression(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWithColumns(this.#h.node.addIndex,[h.toOperationNode()])})})}using(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.cloneWith(this.#h.node.addIndex,{using:V.createWithSql(h)})})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class gh{#h;constructor(h){this.#h=h}nullsNotDistinct(){return new gh(qh.cloneWith(this.#h,{nullsNotDistinct:!0}))}deferrable(){return new gh(qh.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new gh(qh.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new gh(qh.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new gh(qh.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}class ah{#h;constructor(h){this.#h=h}deferrable(){return new ah(Ih.cloneWith(this.#h,{deferrable:!0}))}notDeferrable(){return new ah(Ih.cloneWith(this.#h,{deferrable:!1}))}initiallyDeferred(){return new ah(Ih.cloneWith(this.#h,{initiallyDeferred:!0}))}initiallyImmediate(){return new ah(Ih.cloneWith(this.#h,{initiallyDeferred:!1}))}$call(h){return h(this)}toOperationNode(){return this.#h}}class zk{#h;constructor(h){this.#h=h}$call(h){return h(this)}toOperationNode(){return this.#h}}var z1=k({is(h){return h.kind==="RenameConstraintNode"},create(h,_){return k({kind:"RenameConstraintNode",oldName:X.create(h),newName:X.create(_)})}});class bW{#h;constructor(h){this.#h=k(h)}renameTo(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{renameTo:f(h)})})}setSchema(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{setSchema:X.create(h)})})}alterColumn(h,_){let W=_(new tk(h));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,W.toOperationNode())})}dropColumn(h){return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,jW.create(h))})}renameColumn(h,_){return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,mW.create(h,_))})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Oh(_))));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,CW.create($.toOperationNode()))})}modifyColumn(h,_,W=s){let $=W(new N(S.create(h,Oh(_))));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,QW.create($.toOperationNode()))})}addUniqueConstraint(h,_,W=s){let $=W(new gh(qh.create(_,h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}addCheckConstraint(h,_,W=s){let $=W(new zk(B_.create(_.toOperationNode(),h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}addForeignKeyConstraint(h,_,W,$,J=s){let Y=J(new Th(Ah.create(_.map(F.create),f(W),$.map(F.create),h)));return new ph({...this.#h,constraintBuilder:Y})}addPrimaryKeyConstraint(h,_,W=s){let $=W(new ah(Ih.create(_,h)));return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addConstraint:g_.create($.toOperationNode())})})}dropConstraint(h){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropConstraint:c_.create(h)})})}renameConstraint(h,_){return new V_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{renameConstraint:z1.create(h,_)})})}addIndex(h){return new L_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{addIndex:X_.create(h)})})}dropIndex(h){return new H_({...this.#h,node:U.cloneWithTableProps(this.#h.node,{dropIndex:k_.create(h)})})}$call(h){return h(this)}}class Eh{#h;constructor(h){this.#h=k(h)}alterColumn(h,_){let W=_(new tk(h));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,W.toOperationNode())})}dropColumn(h){return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,jW.create(h))})}renameColumn(h,_){return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,mW.create(h,_))})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Oh(_))));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,CW.create($.toOperationNode()))})}modifyColumn(h,_,W=s){let $=W(new N(S.create(h,Oh(_))));return new Eh({...this.#h,node:U.cloneWithColumnAlteration(this.#h.node,QW.create($.toOperationNode()))})}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Kk extends Dh{transformPrimitiveValueList(h){return $h.create(h.values.map(C.createImmediate))}transformValue(h){return C.createImmediate(h.value)}}class Xh{#h;constructor(h){this.#h=k(h)}ifNotExists(){return new Xh({...this.#h,node:Mh.cloneWith(this.#h.node,{ifNotExists:!0})})}unique(){return new Xh({...this.#h,node:Mh.cloneWith(this.#h.node,{unique:!0})})}nullsNotDistinct(){return new Xh({...this.#h,node:Mh.cloneWith(this.#h.node,{nullsNotDistinct:!0})})}on(h){return new Xh({...this.#h,node:Mh.cloneWith(this.#h.node,{table:f(h)})})}column(h){return new Xh({...this.#h,node:Mh.cloneWithColumns(this.#h.node,[A_(h)])})}columns(h){return new Xh({...this.#h,node:Mh.cloneWithColumns(this.#h.node,h.map(A_))})}expression(h){return new Xh({...this.#h,node:Mh.cloneWithColumns(this.#h.node,[h.toOperationNode()])})}using(h){return new Xh({...this.#h,node:Mh.cloneWith(this.#h.node,{using:V.createWithSql(h)})})}where(...h){let _=new Kk;return new Xh({...this.#h,node:G.cloneWithWhere(this.#h.node,_.transformNode(A(h),this.#h.queryId))})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class ik{#h;constructor(h){this.#h=k(h)}ifNotExists(){return new ik({...this.#h,node:vk.cloneWith(this.#h.node,{ifNotExists:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}function K1(h){if(F$.includes(h))return h;throw Error(`invalid OnCommitAction ${h}`)}class _h{#h;constructor(h){this.#h=k(h)}temporary(){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{temporary:!0})})}onCommit(h){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{onCommit:K1(h)})})}ifNotExists(){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{ifNotExists:!0})})}addColumn(h,_,W=s){let $=W(new N(S.create(h,Oh(_))));return new _h({...this.#h,node:u.cloneWithColumn(this.#h.node,$.toOperationNode())})}addPrimaryKeyConstraint(h,_,W=s){let $=W(new ah(Ih.create(_,h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addUniqueConstraint(h,_,W=s){let $=W(new gh(qh.create(_,h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addCheckConstraint(h,_,W=s){let $=W(new zk(B_.create(_.toOperationNode(),h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,$.toOperationNode())})}addForeignKeyConstraint(h,_,W,$,J=s){let Y=J(new Th(Ah.create(_.map(F.create),f(W),$.map(F.create),h)));return new _h({...this.#h,node:u.cloneWithConstraint(this.#h.node,Y.toOperationNode())})}modifyFront(h){return new _h({...this.#h,node:u.cloneWithFrontModifier(this.#h.node,h.toOperationNode())})}modifyEnd(h){return new _h({...this.#h,node:u.cloneWithEndModifier(this.#h.node,h.toOperationNode())})}as(h){return new _h({...this.#h,node:u.cloneWith(this.#h.node,{selectQuery:o(h)})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class i_{#h;constructor(h){this.#h=k(h)}on(h){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{table:f(h)})})}ifExists(){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new i_({...this.#h,node:k_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Mk{#h;constructor(h){this.#h=k(h)}ifExists(){return new Mk({...this.#h,node:o_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new Mk({...this.#h,node:o_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class Fk{#h;constructor(h){this.#h=k(h)}ifExists(){return new Fk({...this.#h,node:e_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new Fk({...this.#h,node:e_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var Sh=k({is(h){return h.kind==="CreateViewNode"},create(h){return k({kind:"CreateViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class BW{#h=new Kk;transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}transformResult(h){return Promise.resolve(h.result)}}class sh{#h;constructor(h){this.#h=k(h)}temporary(){return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{temporary:!0})})}materialized(){return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{materialized:!0})})}ifNotExists(){return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{ifNotExists:!0})})}orReplace(){return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{orReplace:!0})})}columns(h){return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{columns:h.map(YW)})})}as(h){let _=h.withPlugin(new BW).toOperationNode();return new sh({...this.#h,node:Sh.cloneWith(this.#h.node,{as:_})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var u_=k({is(h){return h.kind==="DropViewNode"},create(h){return k({kind:"DropViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class l_{#h;constructor(h){this.#h=k(h)}materialized(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{materialized:!0})})}ifExists(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{ifExists:!0})})}cascade(){return new l_({...this.#h,node:u_.cloneWith(this.#h.node,{cascade:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var uk=k({is(h){return h.kind==="CreateTypeNode"},create(h){return k({kind:"CreateTypeNode",name:h})},cloneWithEnum(h,_){return k({...h,enum:$h.create(_.map(C.createImmediate))})}});class lk{#h;constructor(h){this.#h=k(h)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}asEnum(h){return new lk({...this.#h,node:uk.cloneWithEnum(this.#h.node,h)})}$call(h){return h(this)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}var pk=k({is(h){return h.kind==="DropTypeNode"},create(h){return k({kind:"DropTypeNode",name:h})},cloneWith(h,_){return k({...h,..._})}});class ak{#h;constructor(h){this.#h=k(h)}ifExists(){return new ak({...this.#h,node:pk.cloneWith(this.#h.node,{ifExists:!0})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}function qW(h){if(h.includes(".")){let W=h.split(".").map(M8);if(W.length===2)return l.createWithSchema(W[0],W[1]);else throw Error(`invalid schemable identifier ${h}`)}else return l.create(h)}function M8(h){return h.trim()}var p_=k({is(h){return h.kind==="RefreshMaterializedViewNode"},create(h){return k({kind:"RefreshMaterializedViewNode",name:l.create(h)})},cloneWith(h,_){return k({...h,..._})}});class a_{#h;constructor(h){this.#h=k(h)}concurrently(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{concurrently:!0,withNoData:!1})})}withData(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{withNoData:!1})})}withNoData(){return new a_({...this.#h,node:p_.cloneWith(this.#h.node,{withNoData:!0,concurrently:!1})})}$call(h){return h(this)}toOperationNode(){return this.#h.executor.transformQuery(this.#h.node,this.#h.queryId)}compile(){return this.#h.executor.compileQuery(this.toOperationNode(),this.#h.queryId)}async execute(){await this.#h.executor.executeQuery(this.compile())}}class s_{#h;constructor(h){this.#h=h}createTable(h){return new _h({queryId:L(),executor:this.#h,node:u.create(f(h))})}dropTable(h){return new Fk({queryId:L(),executor:this.#h,node:e_.create(f(h))})}createIndex(h){return new Xh({queryId:L(),executor:this.#h,node:Mh.create(h)})}dropIndex(h){return new i_({queryId:L(),executor:this.#h,node:k_.create(h)})}createSchema(h){return new ik({queryId:L(),executor:this.#h,node:vk.create(h)})}dropSchema(h){return new Mk({queryId:L(),executor:this.#h,node:o_.create(h)})}alterTable(h){return new bW({queryId:L(),executor:this.#h,node:U.create(f(h))})}createView(h){return new sh({queryId:L(),executor:this.#h,node:Sh.create(h)})}refreshMaterializedView(h){return new a_({queryId:L(),executor:this.#h,node:p_.create(h)})}dropView(h){return new l_({queryId:L(),executor:this.#h,node:u_.create(h)})}createType(h){return new lk({queryId:L(),executor:this.#h,node:uk.create(qW(h))})}dropType(h){return new ak({queryId:L(),executor:this.#h,node:pk.create(qW(h))})}withPlugin(h){return new s_(this.#h.withPlugin(h))}withoutPlugins(){return new s_(this.#h.withoutPlugins())}withSchema(h){return new s_(this.#h.withPluginAtFront(new Zh(h)))}}class IW{ref(h){return new kW(h)}table(h){return new xW(h)}}class gW{#h;constructor(h){this.#h=h}async provideConnection(h){let _=await this.#h.acquireConnection();try{return await h(_)}finally{await this.#h.releaseConnection(_)}}}class z_ extends Zk{#h;#_;#k;constructor(h,_,W,$=[]){super($);this.#h=h,this.#_=_,this.#k=W}get adapter(){return this.#_}compileQuery(h,_){return this.#h.compileQuery(h,_)}provideConnection(h){return this.#k.provideConnection(h)}withPlugins(h){return new z_(this.#h,this.#_,this.#k,[...this.plugins,...h])}withPlugin(h){return new z_(this.#h,this.#_,this.#k,[...this.plugins,h])}withPluginAtFront(h){return new z_(this.#h,this.#_,this.#k,[h,...this.plugins])}withConnectionProvider(h){return new z_(this.#h,this.#_,h,[...this.plugins])}withoutPlugins(){return new z_(this.#h,this.#_,this.#k,[])}}function sk(){if(typeof performance<"u"&&R(performance.now))return performance.now();else return Date.now()}class cW{#h;#_;#k;#W;#$;#Z=new WeakSet;constructor(h,_){this.#W=!1,this.#h=h,this.#_=_}async init(){if(this.#$)throw Error("driver has already been destroyed");if(!this.#k)this.#k=this.#h.init().then(()=>{this.#W=!0}).catch((h)=>{return this.#k=void 0,Promise.reject(h)});await this.#k}async acquireConnection(){if(this.#$)throw Error("driver has already been destroyed");if(!this.#W)await this.init();let h=await this.#h.acquireConnection();if(!this.#Z.has(h)){if(this.#J())this.#Y(h);this.#Z.add(h)}return h}async releaseConnection(h){await this.#h.releaseConnection(h)}beginTransaction(h,_){return this.#h.beginTransaction(h,_)}commitTransaction(h){return this.#h.commitTransaction(h)}rollbackTransaction(h){return this.#h.rollbackTransaction(h)}savepoint(h,_,W){if(this.#h.savepoint)return this.#h.savepoint(h,_,W);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(h,_,W){if(this.#h.rollbackToSavepoint)return this.#h.rollbackToSavepoint(h,_,W);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(h,_,W){if(this.#h.releaseSavepoint)return this.#h.releaseSavepoint(h,_,W);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){if(!this.#k)return;if(await this.#k,!this.#$)this.#$=this.#h.destroy().catch((h)=>{return this.#$=void 0,Promise.reject(h)});await this.#$}#J(){return this.#_.isLevelEnabled("query")||this.#_.isLevelEnabled("error")}#Y(h){let{executeQuery:_,streamQuery:W}=h,$=this;h.executeQuery=async(J)=>{let Y,H=sk();try{return await _.call(h,J)}catch(K){throw Y=K,await $.#G(K,J,H),K}finally{if(!Y)await $.#H(J,H)}},h.streamQuery=async function*(J,Y){let H,K=sk();try{for await(let b of W.call(h,J,Y))yield b}catch(b){throw H=b,await $.#G(b,J,K),b}finally{if(!H)await $.#H(J,K,!0)}}}async#G(h,_,W){await this.#_.error(()=>({level:"error",error:h,query:_,queryDurationMillis:this.#L(W)}))}async#H(h,_,W=!1){await this.#_.query(()=>({level:"query",isStream:W,query:h,queryDurationMillis:this.#L(_)}))}#L(h){return sk()-h}}var F8=()=>{};class Uk{#h;#_;constructor(h){this.#h=h}async provideConnection(h){while(this.#_)await this.#_.catch(F8);return this.#_=this.#k(h).finally(()=>{this.#_=void 0}),this.#_}async#k(h){return await h(this.#h)}}var U8=["read only","read write"],V8=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function yW(h){if(h.accessMode&&!U8.includes(h.accessMode))throw Error(`invalid transaction access mode ${h.accessMode}`);if(h.isolationLevel&&!V8.includes(h.isolationLevel))throw Error(`invalid transaction isolation level ${h.isolationLevel}`)}var f8=["query","error"],V3=k(f8);class tW{#h;#_;constructor(h){if(R(h))this.#_=h,this.#h=k({query:!0,error:!0});else this.#_=w8,this.#h=k({query:h.includes("query"),error:h.includes("error")})}isLevelEnabled(h){return this.#h[h]}async query(h){if(this.#h.query)await this.#_(h())}async error(h){if(this.#h.error)await this.#_(h())}}function w8(h){if(h.level==="query"){let _=`kysely:query:${h.isStream?"stream:":""}`;console.log(`${_} ${h.query.sql}`),console.log(`${_} duration: ${h.queryDurationMillis.toFixed(1)}ms`)}else if(h.level==="error")if(h.error instanceof Error)console.error(`kysely:error: ${h.error.stack??h.error.message}`);else console.error(`kysely:error: ${JSON.stringify({error:h.error,query:h.query.sql,queryDurationMillis:h.queryDurationMillis})}`)}function M1(h){return O(h)&&R(h.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");class w_ extends bh{#h;constructor(h){let _,W;if(R8(h))_={executor:h.executor},W={...h};else{let $=h.dialect,J=$.createDriver(),Y=$.createQueryCompiler(),H=$.createAdapter(),K=new tW(h.log??[]),b=new cW(J,K),x=new gW(b),zh=new z_(Y,H,x,h.plugins??[]);_={executor:zh},W={config:h,executor:zh,dialect:$,driver:b}}super(_);this.#h=k(W)}get schema(){return new s_(this.#h.executor)}get dynamic(){return new IW}get introspection(){return this.#h.dialect.createIntrospector(this.withoutPlugins())}case(h){return new Gk({node:Gh.create(a(h)?void 0:o(h))})}get fn(){return Ik()}transaction(){return new nk({...this.#h})}startTransaction(){return new dk({...this.#h})}connection(){return new F1({...this.#h})}withPlugin(h){return new w_({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new w_({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new w_({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new w_({...this.#h})}async destroy(){await this.#h.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#h.executor}executeQuery(h,_){if(_!==void 0)Ch("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let W=M1(h)?h.compile():h;return this.getExecutor().executeQuery(W)}async[Symbol.asyncDispose](){await this.destroy()}}class R_ extends w_{#h;constructor(h){super(h);this.#h=h}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(h){return new R_({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new R_({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new R_({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new R_({...this.#h})}}function R8(h){return O(h)&&O(h.config)&&O(h.driver)&&O(h.executor)&&O(h.dialect)}class F1{#h;constructor(h){this.#h=k(h)}async execute(h){return this.#h.executor.provideConnection(async(_)=>{let W=this.#h.executor.withConnectionProvider(new Uk(_)),$=new w_({...this.#h,executor:W});return await h($)})}}class nk{#h;constructor(h){this.#h=k(h)}setAccessMode(h){return new nk({...this.#h,accessMode:h})}setIsolationLevel(h){return new nk({...this.#h,isolationLevel:h})}async execute(h){let{isolationLevel:_,accessMode:W,...$}=this.#h,J={isolationLevel:_,accessMode:W};return yW(J),this.#h.executor.provideConnection(async(Y)=>{let H={isCommitted:!1,isRolledBack:!1},K=new dh(this.#h.executor.withConnectionProvider(new Uk(Y)),H),b=new R_({...$,executor:K}),x=!1;try{await this.#h.driver.beginTransaction(Y,J),x=!0;let zh=await h(b);return await this.#h.driver.commitTransaction(Y),H.isCommitted=!0,zh}catch(zh){if(x)await this.#h.driver.rollbackTransaction(Y),H.isRolledBack=!0;throw zh}})}}class dk{#h;constructor(h){this.#h=k(h)}setAccessMode(h){return new dk({...this.#h,accessMode:h})}setIsolationLevel(h){return new dk({...this.#h,isolationLevel:h})}async execute(){let{isolationLevel:h,accessMode:_,...W}=this.#h,$={isolationLevel:h,accessMode:_};yW($);let J=await jk(this.#h.executor);return await this.#h.driver.beginTransaction(J.connection,$),new nh({...W,connection:J,executor:this.#h.executor.withConnectionProvider(new Uk(J.connection))})}}class nh extends R_{#h;#_;#k;constructor(h){let _={isCommitted:!1,isRolledBack:!1};h={...h,executor:new dh(h.executor,_)};let{connection:W,...$}=h;super($);this.#h=k(h),this.#k=_;let J=L();this.#_=(Y)=>h.executor.compileQuery(Y,J)}get isCommitted(){return this.#k.isCommitted}get isRolledBack(){return this.#k.isRolledBack}commit(){return f_(this.#k),new n_(async()=>{await this.#h.driver.commitTransaction(this.#h.connection.connection),this.#k.isCommitted=!0,this.#h.connection.release()})}rollback(){return f_(this.#k),new n_(async()=>{await this.#h.driver.rollbackTransaction(this.#h.connection.connection),this.#k.isRolledBack=!0,this.#h.connection.release()})}savepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.savepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}rollbackToSavepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.rollbackToSavepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}releaseSavepoint(h){return f_(this.#k),new n_(async()=>{return await this.#h.driver.releaseSavepoint?.(this.#h.connection.connection,h,this.#_),new nh({...this.#h})})}withPlugin(h){return new nh({...this.#h,executor:this.#h.executor.withPlugin(h)})}withoutPlugins(){return new nh({...this.#h,executor:this.#h.executor.withoutPlugins()})}withSchema(h){return new nh({...this.#h,executor:this.#h.executor.withPluginAtFront(new Zh(h))})}withTables(){return new nh({...this.#h})}}class n_{#h;constructor(h){this.#h=h}async execute(){return await this.#h()}}function f_(h){if(h.isCommitted)throw Error("Transaction is already committed");if(h.isRolledBack)throw Error("Transaction is already rolled back")}class dh{#h;#_;constructor(h,_){if(h instanceof dh)this.#h=h.#h;else this.#h=h;this.#_=_}get adapter(){return this.#h.adapter}get plugins(){return this.#h.plugins}transformQuery(h,_){return this.#h.transformQuery(h,_)}compileQuery(h,_){return this.#h.compileQuery(h,_)}provideConnection(h){return this.#h.provideConnection(h)}executeQuery(h){return f_(this.#_),this.#h.executeQuery(h)}stream(h,_){return f_(this.#_),this.#h.stream(h,_)}withConnectionProvider(h){return new dh(this.#h.withConnectionProvider(h),this.#_)}withPlugin(h){return new dh(this.#h.withPlugin(h),this.#_)}withPlugins(h){return new dh(this.#h.withPlugins(h),this.#_)}withPluginAtFront(h){return new dh(this.#h.withPluginAtFront(h),this.#_)}withoutPlugins(){return new dh(this.#h.withoutPlugins(),this.#_)}}class Vk{#h;constructor(h){this.#h=k(h)}get expressionType(){return}get isRawBuilder(){return!0}as(h){return new U1(this,h)}$castTo(){return new Vk({...this.#h})}$notNull(){return new Vk(this.#h)}withPlugin(h){return new Vk({...this.#h,plugins:this.#h.plugins!==void 0?k([...this.#h.plugins,h]):k([h])})}toOperationNode(){return this.#k(this.#_())}compile(h){return this.#W(this.#_(h))}async execute(h){let _=this.#_(h);return _.executeQuery(this.#W(_))}#_(h){let _=h!==void 0?h.getExecutor():G_;return this.#h.plugins!==void 0?_.withPlugins(this.#h.plugins):_}#k(h){return h.transformQuery(this.#h.rawNode,this.#h.queryId)}#W(h){return h.compileQuery(this.#k(h),this.#h.queryId)}}function rh(h){return new Vk(h)}class U1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}get expression(){return this.#h}get alias(){return this.#_}get rawBuilder(){return this.#h}toOperationNode(){return I.create(this.#h.toOperationNode(),T(this.#_)?this.#_.toOperationNode():X.create(this.#_))}}var Q=Object.assign((h,..._)=>{return rh({queryId:L(),rawNode:V.create(h,_?.map(V1)??[])})},{ref(h){return rh({queryId:L(),rawNode:V.createWithChild(kh(h))})},val(h){return rh({queryId:L(),rawNode:V.createWithChild(P(h))})},value(h){return this.val(h)},table(h){return rh({queryId:L(),rawNode:V.createWithChild(f(h))})},id(...h){let _=Array(h.length+1).fill(".");return _[0]="",_[_.length-1]="",rh({queryId:L(),rawNode:V.create(_,h.map(X.create))})},lit(h){return rh({queryId:L(),rawNode:V.createWithChild(C.createImmediate(h))})},literal(h){return this.lit(h)},raw(h){return rh({queryId:L(),rawNode:V.createWithSql(h)})},join(h,_=Q`, `){let W=Array(Math.max(2*h.length-1,0)),$=_.toOperationNode();for(let J=0;J<h.length;++J)if(W[2*J]=V1(h[J]),J!==h.length-1)W[2*J+1]=$;return rh({queryId:L(),rawNode:V.createWithChildren(W)})}});function V1(h){if(T(h))return h.toOperationNode();return P(h)}class iW{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#h=k({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=(h)=>{this.nodeStack.push(h),this.#h[h.kind](h),this.nodeStack.pop()}}var v8=/'/g;class oh extends iW{#h="";#_=[];get numParameters(){return this.#_.length}compileQuery(h,_){return this.#h="",this.#_=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(h),k({query:h,queryId:_,sql:this.getSql(),parameters:[...this.#_]})}getSql(){return this.#h}visitSelectQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!m.is(this.parentNode)&&!u.is(this.parentNode)&&!Sh.is(this.parentNode)&&!mk.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("select"),h.distinctOn)this.append(" "),this.compileDistinctOn(h.distinctOn);if(h.frontModifiers?.length)this.append(" "),this.compileList(h.frontModifiers," ");if(h.top)this.append(" "),this.visitNode(h.top);if(h.selections)this.append(" "),this.compileList(h.selections);if(h.from)this.append(" "),this.visitNode(h.from);if(h.joins)this.append(" "),this.compileList(h.joins," ");if(h.where)this.append(" "),this.visitNode(h.where);if(h.groupBy)this.append(" "),this.visitNode(h.groupBy);if(h.having)this.append(" "),this.visitNode(h.having);if(h.setOperations)this.append(" "),this.compileList(h.setOperations," ");if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(h.offset)this.append(" "),this.visitNode(h.offset);if(h.fetch)this.append(" "),this.visitNode(h.fetch);if(h.endModifiers?.length)this.append(" "),this.compileList(this.sortSelectModifiers([...h.endModifiers])," ");if(_)this.append(")")}visitFrom(h){this.append("from "),this.compileList(h.froms)}visitSelection(h){this.visitNode(h.selection)}visitColumn(h){this.visitNode(h.column)}compileDistinctOn(h){this.append("distinct on ("),this.compileList(h),this.append(")")}compileList(h,_=", "){let W=h.length-1;for(let $=0;$<=W;$++)if(this.visitNode(h[$]),$<W)this.append(_)}visitWhere(h){this.append("where "),this.visitNode(h.where)}visitHaving(h){this.append("having "),this.visitNode(h.having)}visitInsertQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode)&&!Hh.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append(h.replace?"replace":"insert"),h.ignore)Ch("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore");if(h.orAction)this.append(" "),this.visitNode(h.orAction);if(h.top)this.append(" "),this.visitNode(h.top);if(h.into)this.append(" into "),this.visitNode(h.into);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.output)this.append(" "),this.visitNode(h.output);if(h.values)this.append(" "),this.visitNode(h.values);if(h.defaultValues)this.append(" "),this.append("default values");if(h.onConflict)this.append(" "),this.visitNode(h.onConflict);if(h.onDuplicateKey)this.append(" "),this.visitNode(h.onDuplicateKey);if(h.returning)this.append(" "),this.visitNode(h.returning);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitValues(h){this.append("values "),this.compileList(h.values)}visitDeleteQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("delete "),h.top)this.visitNode(h.top),this.append(" ");if(this.visitNode(h.from),h.output)this.append(" "),this.visitNode(h.output);if(h.using)this.append(" "),this.visitNode(h.using);if(h.joins)this.append(" "),this.compileList(h.joins," ");if(h.where)this.append(" "),this.visitNode(h.where);if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(h.returning)this.append(" "),this.visitNode(h.returning);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitReturning(h){this.append("returning "),this.compileList(h.selections)}visitAlias(h){this.visitNode(h.node),this.append(" as "),this.visitNode(h.alias)}visitReference(h){if(h.table)this.visitNode(h.table),this.append(".");this.visitNode(h.column)}visitSelectAll(h){this.append("*")}visitIdentifier(h){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(h),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(h){if(!M(h.name))throw Error("a non-string identifier was passed to compileUnwrappedIdentifier.");this.append(this.sanitizeIdentifier(h.name))}visitAnd(h){this.visitNode(h.left),this.append(" and "),this.visitNode(h.right)}visitOr(h){this.visitNode(h.left),this.append(" or "),this.visitNode(h.right)}visitValue(h){if(h.immediate)this.appendImmediateValue(h.value);else this.appendValue(h.value)}visitValueList(h){this.append("("),this.compileList(h.values),this.append(")")}visitTuple(h){this.append("("),this.compileList(h.values),this.append(")")}visitPrimitiveValueList(h){this.append("(");let{values:_}=h;for(let W=0;W<_.length;++W)if(this.appendValue(_[W]),W!==_.length-1)this.append(", ");this.append(")")}visitParens(h){this.append("("),this.visitNode(h.node),this.append(")")}visitJoin(h){if(this.append(D8[h.joinType]),this.append(" "),this.visitNode(h.table),h.on)this.append(" "),this.visitNode(h.on)}visitOn(h){this.append("on "),this.visitNode(h.on)}visitRaw(h){let{sqlFragments:_,parameters:W}=h;for(let $=0;$<_.length;++$)if(this.append(_[$]),W.length>$)this.visitNode(W[$])}visitOperator(h){this.append(h.operator)}visitTable(h){this.visitNode(h.table)}visitSchemableIdentifier(h){if(h.schema)this.visitNode(h.schema),this.append(".");this.visitNode(h.identifier)}visitCreateTable(h){if(this.append("create "),h.frontModifiers&&h.frontModifiers.length>0)this.compileList(h.frontModifiers," "),this.append(" ");if(h.temporary)this.append("temporary ");if(this.append("table "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.table),h.selectQuery)this.append(" as "),this.visitNode(h.selectQuery);else{if(this.append(" ("),this.compileList([...h.columns,...h.constraints??[]]),this.append(")"),h.onCommit)this.append(" on commit "),this.append(h.onCommit);if(h.endModifiers&&h.endModifiers.length>0)this.append(" "),this.compileList(h.endModifiers," ")}}visitColumnDefinition(h){if(h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.column),this.append(" "),this.visitNode(h.dataType),h.unsigned)this.append(" unsigned");if(h.frontModifiers&&h.frontModifiers.length>0)this.append(" "),this.compileList(h.frontModifiers," ");if(h.generated)this.append(" "),this.visitNode(h.generated);if(h.identity)this.append(" identity");if(h.defaultTo)this.append(" "),this.visitNode(h.defaultTo);if(h.notNull)this.append(" not null");if(h.unique)this.append(" unique");if(h.nullsNotDistinct)this.append(" nulls not distinct");if(h.primaryKey)this.append(" primary key");if(h.autoIncrement)this.append(" "),this.append(this.getAutoIncrement());if(h.references)this.append(" "),this.visitNode(h.references);if(h.check)this.append(" "),this.visitNode(h.check);if(h.endModifiers&&h.endModifiers.length>0)this.append(" "),this.compileList(h.endModifiers," ")}getAutoIncrement(){return"auto_increment"}visitReferences(h){if(this.append("references "),this.visitNode(h.table),this.append(" ("),this.compileList(h.columns),this.append(")"),h.onDelete)this.append(" on delete "),this.append(h.onDelete);if(h.onUpdate)this.append(" on update "),this.append(h.onUpdate)}visitDropTable(h){if(this.append("drop table "),h.ifExists)this.append("if exists ");if(this.visitNode(h.table),h.cascade)this.append(" cascade")}visitDataType(h){this.append(h.dataType)}visitOrderBy(h){this.append("order by "),this.compileList(h.items)}visitOrderByItem(h){if(this.visitNode(h.orderBy),h.collation)this.append(" "),this.visitNode(h.collation);if(h.direction)this.append(" "),this.visitNode(h.direction);if(h.nulls)this.append(" nulls "),this.append(h.nulls)}visitGroupBy(h){this.append("group by "),this.compileList(h.items)}visitGroupByItem(h){this.visitNode(h.groupBy)}visitUpdateQuery(h){let _=this.parentNode!==void 0&&!Jh.is(this.parentNode)&&!V.is(this.parentNode)&&!Hh.is(this.parentNode);if(this.parentNode===void 0&&h.explain)this.visitNode(h.explain),this.append(" ");if(_)this.append("(");if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("update "),h.top)this.visitNode(h.top),this.append(" ");if(h.table)this.visitNode(h.table),this.append(" ");if(this.append("set "),h.updates)this.compileList(h.updates);if(h.output)this.append(" "),this.visitNode(h.output);if(h.from)this.append(" "),this.visitNode(h.from);if(h.joins){if(!h.from)throw Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(h.joins," ")}if(h.where)this.append(" "),this.visitNode(h.where);if(h.returning)this.append(" "),this.visitNode(h.returning);if(h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(h.limit)this.append(" "),this.visitNode(h.limit);if(_)this.append(")");if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitColumnUpdate(h){this.visitNode(h.column),this.append(" = "),this.visitNode(h.value)}visitLimit(h){this.append("limit "),this.visitNode(h.limit)}visitOffset(h){this.append("offset "),this.visitNode(h.offset)}visitOnConflict(h){if(this.append("on conflict"),h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");else if(h.constraint)this.append(" on constraint "),this.visitNode(h.constraint);else if(h.indexExpression)this.append(" ("),this.visitNode(h.indexExpression),this.append(")");if(h.indexWhere)this.append(" "),this.visitNode(h.indexWhere);if(h.doNothing===!0)this.append(" do nothing");else if(h.updates){if(this.append(" do update set "),this.compileList(h.updates),h.updateWhere)this.append(" "),this.visitNode(h.updateWhere)}}visitOnDuplicateKey(h){this.append("on duplicate key update "),this.compileList(h.updates)}visitCreateIndex(h){if(this.append("create "),h.unique)this.append("unique ");if(this.append("index "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),h.table)this.append(" on "),this.visitNode(h.table);if(h.using)this.append(" using "),this.visitNode(h.using);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.nullsNotDistinct)this.append(" nulls not distinct");if(h.where)this.append(" "),this.visitNode(h.where)}visitDropIndex(h){if(this.append("drop index "),h.ifExists)this.append("if exists ");if(this.visitNode(h.name),h.table)this.append(" on "),this.visitNode(h.table);if(h.cascade)this.append(" cascade")}visitCreateSchema(h){if(this.append("create schema "),h.ifNotExists)this.append("if not exists ");this.visitNode(h.schema)}visitDropSchema(h){if(this.append("drop schema "),h.ifExists)this.append("if exists ");if(this.visitNode(h.schema),h.cascade)this.append(" cascade")}visitPrimaryKeyConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");this.append("primary key ("),this.compileList(h.columns),this.append(")"),this.buildDeferrable(h)}buildDeferrable(h){if(h.deferrable!==void 0)if(h.deferrable)this.append(" deferrable");else this.append(" not deferrable");if(h.initiallyDeferred!==void 0)if(h.initiallyDeferred)this.append(" initially deferred");else this.append(" initially immediate")}visitUniqueConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");if(this.append("unique"),h.nullsNotDistinct)this.append(" nulls not distinct");this.append(" ("),this.compileList(h.columns),this.append(")"),this.buildDeferrable(h)}visitCheckConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");this.append("check ("),this.visitNode(h.expression),this.append(")")}visitForeignKeyConstraint(h){if(h.name)this.append("constraint "),this.visitNode(h.name),this.append(" ");if(this.append("foreign key ("),this.compileList(h.columns),this.append(") "),this.visitNode(h.references),h.onDelete)this.append(" on delete "),this.append(h.onDelete);if(h.onUpdate)this.append(" on update "),this.append(h.onUpdate);this.buildDeferrable(h)}visitList(h){this.compileList(h.items)}visitWith(h){if(this.append("with "),h.recursive)this.append("recursive ");this.compileList(h.expressions)}visitCommonTableExpression(h){if(this.visitNode(h.name),this.append(" as "),yh(h.materialized)){if(!h.materialized)this.append("not ");this.append("materialized ")}this.visitNode(h.expression)}visitCommonTableExpressionName(h){if(this.visitNode(h.table),h.columns)this.append("("),this.compileList(h.columns),this.append(")")}visitAlterTable(h){if(this.append("alter table "),this.visitNode(h.table),this.append(" "),h.renameTo)this.append("rename to "),this.visitNode(h.renameTo);if(h.setSchema)this.append("set schema "),this.visitNode(h.setSchema);if(h.addConstraint)this.visitNode(h.addConstraint);if(h.dropConstraint)this.visitNode(h.dropConstraint);if(h.renameConstraint)this.visitNode(h.renameConstraint);if(h.columnAlterations)this.compileColumnAlterations(h.columnAlterations);if(h.addIndex)this.visitNode(h.addIndex);if(h.dropIndex)this.visitNode(h.dropIndex)}visitAddColumn(h){this.append("add column "),this.visitNode(h.column)}visitRenameColumn(h){this.append("rename column "),this.visitNode(h.column),this.append(" to "),this.visitNode(h.renameTo)}visitDropColumn(h){this.append("drop column "),this.visitNode(h.column)}visitAlterColumn(h){if(this.append("alter column "),this.visitNode(h.column),this.append(" "),h.dataType){if(this.announcesNewColumnDataType())this.append("type ");if(this.visitNode(h.dataType),h.dataTypeExpression)this.append("using "),this.visitNode(h.dataTypeExpression)}if(h.setDefault)this.append("set default "),this.visitNode(h.setDefault);if(h.dropDefault)this.append("drop default");if(h.setNotNull)this.append("set not null");if(h.dropNotNull)this.append("drop not null")}visitModifyColumn(h){this.append("modify column "),this.visitNode(h.column)}visitAddConstraint(h){this.append("add "),this.visitNode(h.constraint)}visitDropConstraint(h){if(this.append("drop constraint "),h.ifExists)this.append("if exists ");if(this.visitNode(h.constraintName),h.modifier==="cascade")this.append(" cascade");else if(h.modifier==="restrict")this.append(" restrict")}visitRenameConstraint(h){this.append("rename constraint "),this.visitNode(h.oldName),this.append(" to "),this.visitNode(h.newName)}visitSetOperation(h){if(this.append(h.operator),this.append(" "),h.all)this.append("all ");this.visitNode(h.expression)}visitCreateView(h){if(this.append("create "),h.orReplace)this.append("or replace ");if(h.materialized)this.append("materialized ");if(h.temporary)this.append("temporary ");if(this.append("view "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),this.append(" "),h.columns)this.append("("),this.compileList(h.columns),this.append(") ");if(h.as)this.append("as "),this.visitNode(h.as)}visitRefreshMaterializedView(h){if(this.append("refresh materialized view "),h.concurrently)this.append("concurrently ");if(this.visitNode(h.name),h.withNoData)this.append(" with no data");else this.append(" with data")}visitDropView(h){if(this.append("drop "),h.materialized)this.append("materialized ");if(this.append("view "),h.ifExists)this.append("if exists ");if(this.visitNode(h.name),h.cascade)this.append(" cascade")}visitGenerated(h){if(this.append("generated "),h.always)this.append("always ");if(h.byDefault)this.append("by default ");if(this.append("as "),h.identity)this.append("identity");if(h.expression)this.append("("),this.visitNode(h.expression),this.append(")");if(h.stored)this.append(" stored")}visitDefaultValue(h){this.append("default "),this.visitNode(h.defaultValue)}visitSelectModifier(h){if(h.rawModifier)this.visitNode(h.rawModifier);else this.append(P8[h.modifier]);if(h.of)this.append(" of "),this.compileList(h.of,", ")}visitCreateType(h){if(this.append("create type "),this.visitNode(h.name),h.enum)this.append(" as enum "),this.visitNode(h.enum)}visitDropType(h){if(this.append("drop type "),h.ifExists)this.append("if exists ");this.visitNode(h.name)}visitExplain(h){if(this.append("explain"),h.options||h.format){if(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),h.options){if(this.visitNode(h.options),h.format)this.append(this.getExplainOptionsDelimiter())}if(h.format)this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(h.format);this.append(this.getRightExplainOptionsWrapper())}}visitDefaultInsertValue(h){this.append("default")}visitAggregateFunction(h){if(this.append(h.func),this.append("("),h.distinct)this.append("distinct ");if(this.compileList(h.aggregated),h.orderBy)this.append(" "),this.visitNode(h.orderBy);if(this.append(")"),h.withinGroup)this.append(" within group ("),this.visitNode(h.withinGroup),this.append(")");if(h.filter)this.append(" filter("),this.visitNode(h.filter),this.append(")");if(h.over)this.append(" "),this.visitNode(h.over)}visitOver(h){if(this.append("over("),h.partitionBy){if(this.visitNode(h.partitionBy),h.orderBy)this.append(" ")}if(h.orderBy)this.visitNode(h.orderBy);this.append(")")}visitPartitionBy(h){this.append("partition by "),this.compileList(h.items)}visitPartitionByItem(h){this.visitNode(h.partitionBy)}visitBinaryOperation(h){this.visitNode(h.leftOperand),this.append(" "),this.visitNode(h.operator),this.append(" "),this.visitNode(h.rightOperand)}visitUnaryOperation(h){if(this.visitNode(h.operator),!this.isMinusOperator(h.operator))this.append(" ");this.visitNode(h.operand)}isMinusOperator(h){return y.is(h)&&h.operator==="-"}visitUsing(h){this.append("using "),this.compileList(h.tables)}visitFunction(h){this.append(h.func),this.append("("),this.compileList(h.arguments),this.append(")")}visitCase(h){if(this.append("case"),h.value)this.append(" "),this.visitNode(h.value);if(h.when)this.append(" "),this.compileList(h.when," ");if(h.else)this.append(" else "),this.visitNode(h.else);if(this.append(" end"),h.isStatement)this.append(" case")}visitWhen(h){if(this.append("when "),this.visitNode(h.condition),h.result)this.append(" then "),this.visitNode(h.result)}visitJSONReference(h){this.visitNode(h.reference),this.visitNode(h.traversal)}visitJSONPath(h){if(h.inOperator)this.visitNode(h.inOperator);this.append("'$");for(let _ of h.pathLegs)this.visitNode(_);this.append("'")}visitJSONPathLeg(h){let _=h.type==="ArrayLocation";if(this.append(_?"[":"."),this.append(String(h.value)),_)this.append("]")}visitJSONOperatorChain(h){for(let _=0,W=h.values.length;_<W;_++){if(_===W-1)this.visitNode(h.operator);else this.append("->");this.visitNode(h.values[_])}}visitMergeQuery(h){if(h.with)this.visitNode(h.with),this.append(" ");if(this.append("merge "),h.top)this.visitNode(h.top),this.append(" ");if(this.append("into "),this.visitNode(h.into),h.using)this.append(" "),this.visitNode(h.using);if(h.whens)this.append(" "),this.compileList(h.whens," ");if(h.returning)this.append(" "),this.visitNode(h.returning);if(h.output)this.append(" "),this.visitNode(h.output);if(h.endModifiers?.length)this.append(" "),this.compileList(h.endModifiers," ")}visitMatched(h){if(h.not)this.append("not ");if(this.append("matched"),h.bySource)this.append(" by source")}visitAddIndex(h){if(this.append("add "),h.unique)this.append("unique ");if(this.append("index "),this.visitNode(h.name),h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.using)this.append(" using "),this.visitNode(h.using)}visitCast(h){this.append("cast("),this.visitNode(h.expression),this.append(" as "),this.visitNode(h.dataType),this.append(")")}visitFetch(h){this.append("fetch next "),this.visitNode(h.rowCount),this.append(` rows ${h.modifier}`)}visitOutput(h){this.append("output "),this.compileList(h.selections)}visitTop(h){if(this.append(`top(${h.expression})`),h.modifiers)this.append(` ${h.modifiers}`)}visitOrAction(h){this.append(h.action)}visitCollate(h){this.append("collate "),this.visitNode(h.collation)}append(h){this.#h+=h}appendValue(h){this.addParameter(h),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(h){let _=this.getLeftIdentifierWrapper(),W=this.getRightIdentifierWrapper(),$="";for(let J of h)if($+=J,J===_)$+=_;else if(J===W)$+=W;return $}sanitizeStringLiteral(h){return h.replace(v8,"''")}addParameter(h){this.#_.push(h)}appendImmediateValue(h){if(M(h))this.appendStringLiteral(h);else if(Kh(h)||yh(h)||__(h))this.append(h.toString());else if(h_(h))this.append("null");else if(v_(h))this.appendImmediateValue(h.toISOString());else throw Error(`invalid immediate value ${h}`)}appendStringLiteral(h){this.append("'"),this.append(this.sanitizeStringLiteral(h)),this.append("'")}sortSelectModifiers(h){return h.sort((_,W)=>_.modifier&&W.modifier?f1[_.modifier]-f1[W.modifier]:1),k(h)}compileColumnAlterations(h){this.compileList(h)}announcesNewColumnDataType(){return!0}}var P8=k({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),f1=k({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),D8=k({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var p=k({raw(h,_=[]){return k({sql:h,query:V.createWithSql(h),parameters:k(_),queryId:L()})}});class O8{async init(){}async acquireConnection(){return new w1}async beginTransaction(){}async commitTransaction(){}async rollbackTransaction(){}async releaseConnection(){}async destroy(){}async releaseSavepoint(){}async rollbackToSavepoint(){}async savepoint(){}}class w1{async executeQuery(){return{rows:[]}}async*streamQuery(){}}class eh{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}}function Lh(h,_){return V.createWithChildren([V.createWithSql(`${h} `),X.create(_)])}class uW{#h;#_=new v1;#k;#W;constructor(h){this.#h=k({...h})}async init(){if(this.#k=R(this.#h.database)?await this.#h.database():this.#h.database,this.#W=new R1(this.#k),this.#h.onCreateConnection)await this.#h.onCreateConnection(this.#W)}async acquireConnection(){return await this.#_.lock(),this.#W}async beginTransaction(h){await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(Lh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(Lh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(Lh("release",_),L()))}async releaseConnection(){this.#_.unlock()}async destroy(){this.#k?.close()}}class R1{#h;constructor(h){this.#h=h}executeQuery(h){let{sql:_,parameters:W}=h,$=this.#h.prepare(_);if($.reader)return Promise.resolve({rows:$.all(W)});let{changes:J,lastInsertRowid:Y}=$.run(W);return Promise.resolve({numAffectedRows:J!==void 0&&J!==null?BigInt(J):void 0,insertId:Y!==void 0&&Y!==null?BigInt(Y):void 0,rows:[]})}async*streamQuery(h,_){let{sql:W,parameters:$,query:J}=h,Y=this.#h.prepare(W);if(w.is(J)){let H=Y.iterate($);for(let K of H)yield{rows:[K]}}else throw Error("Sqlite driver only supports streaming of select queries")}}class v1{#h;#_;async lock(){while(this.#h)await this.#h;this.#h=new Promise((h)=>{this.#_=h})}unlock(){let h=this.#_;this.#h=void 0,this.#_=void 0,h?.()}}var A8=/"/g;class lW extends oh{visitOrAction(h){this.append("or "),this.append(h.action)}getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getAutoIncrement(){return"autoincrement"}sanitizeIdentifier(h){return h.replace(A8,'""')}visitDefaultInsertValue(h){this.append("null")}}class pW{transformQuery(h){return h.node}async transformResult(h){return h.result}}var Nh="kysely_migration",ch="kysely_migration_lock",T8=!1,aW="migration_lock",IK=k({__noMigrations__:!0});class E8{#h;constructor(h){this.#h=k(h)}async getMigrations(){let _=await this.#X(this.#W)?await this.#h.db.withPlugin(this.#J).selectFrom(this.#W).select(["name","timestamp"]).$narrowType().execute():[];return(await this.#F()).map(({name:$,...J})=>{let Y=_.find((H)=>H.name===$);return{name:$,migration:J,executedAt:Y?new Date(Y.timestamp):void 0}})}async migrateToLatest(){return this.#_(()=>({direction:"Up",step:1/0}))}async migrateTo(h){return this.#_(({migrations:_,executedMigrations:W,pendingMigrations:$})=>{if(O(h)&&h.__noMigrations__===!0)return{direction:"Down",step:1/0};if(!_.find((H)=>H.name===h))throw Error(`migration "${h}" doesn't exist`);let J=W.indexOf(h),Y=$.findIndex((H)=>H.name===h);if(J!==-1)return{direction:"Down",step:W.length-J-1};else if(Y!==-1)return{direction:"Up",step:Y+1};else throw Error(`migration "${h}" isn't executed or pending`)})}async migrateUp(){return this.#_(()=>({direction:"Up",step:1}))}async migrateDown(){return this.#_(()=>({direction:"Down",step:1}))}async#_(h){try{return await this.#Y(),await this.#G(),await this.#H(),await this.#L(),await this.#U(h)}catch(_){if(_ instanceof rk)return _.resultSet;return{error:_}}}get#k(){return this.#h.migrationTableSchema}get#W(){return this.#h.migrationTableName??Nh}get#$(){return this.#h.migrationLockTableName??ch}get#Z(){return this.#h.allowUnorderedMigrations??T8}get#J(){if(this.#k)return new Zh(this.#k);return new pW}async#Y(){if(!this.#k)return;if(await this.#K())return;try{await this.#z(this.#h.db.schema.createSchema(this.#k))}catch(_){if(!await this.#K())throw _}}async#G(){if(await this.#X(this.#W))return;try{await this.#z(this.#h.db.schema.withPlugin(this.#J).createTable(this.#W).addColumn("name","varchar(255)",(_)=>_.notNull().primaryKey()).addColumn("timestamp","varchar(255)",(_)=>_.notNull()))}catch(_){if(!await this.#X(this.#W))throw _}}async#H(){if(await this.#X(this.#$))return;try{await this.#z(this.#h.db.schema.withPlugin(this.#J).createTable(this.#$).addColumn("id","varchar(255)",(_)=>_.notNull().primaryKey()).addColumn("is_locked","integer",(_)=>_.notNull().defaultTo(0)))}catch(_){if(!await this.#X(this.#$))throw _}}async#L(){if(await this.#M())return;try{await this.#h.db.withPlugin(this.#J).insertInto(this.#$).values({id:aW,is_locked:0}).execute()}catch(_){if(!await this.#M())throw _}}async#K(){return(await this.#h.db.introspection.getSchemas()).some((_)=>_.name===this.#k)}async#X(h){let _=this.#k;return(await this.#h.db.introspection.getTables({withInternalKyselyTables:!0})).some(($)=>$.name===h&&(!_||$.schema===_))}async#M(){return!!await this.#h.db.withPlugin(this.#J).selectFrom(this.#$).where("id","=",aW).select("id").executeTakeFirst()}async#U(h){let _=this.#h.db.getExecutor().adapter,W=k({lockTable:this.#h.migrationLockTableName??ch,lockRowId:aW,lockTableSchema:this.#h.migrationTableSchema}),$=async(J)=>{try{await _.acquireMigrationLock(J,W);let Y=await this.#V(J);if(Y.migrations.length===0)return{results:[]};let{direction:H,step:K}=h(Y);if(K<=0)return{results:[]};if(H==="Down")return await this.#P(J,Y,K);else if(H==="Up")return await this.#D(J,Y,K);return{results:[]}}finally{await _.releaseMigrationLock(J,W)}};if(_.supportsTransactionalDdl&&!this.#h.disableTransactions)return this.#h.db.transaction().execute($);else return this.#h.db.connection().execute($)}async#V(h){let _=await this.#F(),W=await this.#w(h);if(this.#R(_,W),!this.#Z)this.#v(_,W);let $=this.#f(_,W);return k({migrations:_,executedMigrations:W,lastMigration:M$(W),pendingMigrations:$})}#f(h,_){return h.filter((W)=>{return!_.includes(W.name)})}async#F(){let h=await this.#h.provider.getMigrations();return Object.keys(h).sort().map((_)=>({...h[_],name:_}))}async#w(h){let _=await h.withPlugin(this.#J).selectFrom(this.#W).select(["name","timestamp"]).$narrowType().execute(),W=this.#h.nameComparator||(($,J)=>$.localeCompare(J));return _.sort(($,J)=>{if($.timestamp===J.timestamp)return W($.name,J.name);return new Date($.timestamp).getTime()-new Date(J.timestamp).getTime()}).map(($)=>$.name)}#R(h,_){for(let W of _)if(!h.some(($)=>$.name===W))throw Error(`corrupted migrations: previously executed migration ${W} is missing`)}#v(h,_){for(let W=0;W<_.length;++W)if(h[W].name!==_[W])throw Error(`corrupted migrations: expected previously executed migration ${_[W]} to be at index ${W} but ${h[W].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`)}async#P(h,_,W){let $=_.executedMigrations.slice().reverse().slice(0,W).map((Y)=>{return _.migrations.find((H)=>H.name===Y)}),J=$.map((Y)=>{return{migrationName:Y.name,direction:"Down",status:"NotExecuted"}});for(let Y=0;Y<J.length;++Y){let H=$[Y];try{if(H.down)await H.down(h),await h.withPlugin(this.#J).deleteFrom(this.#W).where("name","=",H.name).execute(),J[Y]={migrationName:H.name,direction:"Down",status:"Success"}}catch(K){throw J[Y]={migrationName:H.name,direction:"Down",status:"Error"},new rk({error:K,results:J})}}return{results:J}}async#D(h,_,W){let J=_.pendingMigrations.slice(0,W).map((Y)=>{return{migrationName:Y.name,direction:"Up",status:"NotExecuted"}});for(let Y=0;Y<J.length;Y++){let H=_.pendingMigrations[Y];try{await H.up(h),await h.withPlugin(this.#J).insertInto(this.#W).values({name:H.name,timestamp:new Date().toISOString()}).execute(),J[Y]={migrationName:H.name,direction:"Up",status:"Success"}}catch(K){throw J[Y]={migrationName:H.name,direction:"Up",status:"Error"},new rk({error:K,results:J})}}return{results:J}}async#z(h){if(this.#h.db.getExecutor().adapter.supportsCreateIfNotExists)h=h.ifNotExists();await h.execute()}}class rk extends Error{#h;constructor(h){super();this.#h=h}get resultSet(){return this.#h}}class sW{#h;constructor(h){this.#h=h}async getSchemas(){return[]}async getTables(h={withInternalKyselyTables:!1}){return await this.#k(h)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h,_){let W=h.selectFrom("sqlite_master").where("type","in",["table","view"]).where("name","not like","sqlite_%").select(["name","sql","type"]).orderBy("name");if(!_.withInternalKyselyTables)W=W.where("name","!=",Nh).where("name","!=",ch);return W}async#k(h){let _=await this.#_(this.#h,h).execute(),W=await this.#h.with("table_list",(J)=>this.#_(J,h)).selectFrom(["table_list as tl",Q`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(),$={};for(let J of W)$[J.table]??=[],$[J.table].push(J);return _.map(({name:J,sql:Y,type:H})=>{let K=Y?.split(/[\(\),]/)?.find((x)=>x.toLowerCase().includes("autoincrement"))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,""),b=$[J]??[];if(!K){let x=b.filter((zh)=>zh.pk>0);if(x.length===1&&x[0].type.toLowerCase()==="integer")K=x[0].name}return{name:J,isView:H==="view",columns:b.map((x)=>({name:x.name,dataType:x.type,isNullable:!x.notnull,isAutoIncrementing:x.name===K,hasDefaultValue:x.dflt_value!=null,comment:void 0}))}})}}class nW extends eh{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(h,_){}async releaseMigrationLock(h,_){}}class S8{#h;constructor(h){this.#h=k({...h})}createDriver(){return new uW(this.#h)}createQueryCompiler(){return new lW}createAdapter(){return new nW}createIntrospector(h){return new sW(h)}}var N8=/"/g;class dW extends oh{sanitizeIdentifier(h){return h.replace(N8,'""')}}class rW{#h;constructor(h){this.#h=h}async getSchemas(){return(await this.#h.selectFrom("pg_catalog.pg_namespace").select("nspname").$castTo().execute()).map((_)=>({name:_.nspname}))}async getTables(h={withInternalKyselyTables:!1}){let _=this.#h.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",Q`col_description(a.attrelid, a.attnum)`.as("column_description"),Q`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(Q`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(!h.withInternalKyselyTables)_=_.where("c.relname","!=",Nh).where("c.relname","!=",ch);let W=await _.execute();return this.#_(W)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h){return h.reduce((_,W)=>{let $=_.find((J)=>J.name===W.table&&J.schema===W.schema);if(!$)$=k({name:W.table,isView:W.table_type==="v",schema:W.schema,columns:[]}),_.push($);return $.columns.push(k({name:W.column,dataType:W.type,dataTypeSchema:W.type_schema,isNullable:!W.not_null,isAutoIncrementing:W.auto_incrementing!==null,hasDefaultValue:W.has_default,comment:W.column_description??void 0})),_},[])}}var x8=BigInt("3853314791062309107");class oW extends eh{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(h,_){await Q`select pg_advisory_xact_lock(${Q.lit(x8)})`.execute(h)}async releaseMigrationLock(h,_){}}function d_(h,_){if(C8(h)&&_.stack){let W=_.stack.split(`
|
|
2
2
|
`).slice(1).join(`
|
|
3
3
|
`);return h.stack+=`
|
|
4
|
-
${W}`,h}return h}function C8(h){return O(h)&&M(h.stack)}var P1=Symbol();class eW{#h;#_=new WeakMap;#k;constructor(h){this.#h=k({...h})}async init(){this.#k=R(this.#h.pool)?await this.#h.pool():this.#h.pool}async acquireConnection(){let h=await this.#W(),_=this.#_.get(h);if(!_){if(_=new D1(h),this.#_.set(h,_),this.#h?.onCreateConnection)await this.#h.onCreateConnection(_)}if(this.#h?.onReserveConnection)await this.#h.onReserveConnection(_);return _}async#W(){return new Promise((h,_)=>{this.#k.getConnection(async(W,$)=>{if(W)_(W);else h($)})})}async beginTransaction(h,_){if(_.isolationLevel||_.accessMode){let W=[];if(_.isolationLevel)W.push(`isolation level ${_.isolationLevel}`);if(_.accessMode)W.push(_.accessMode);let $=`set transaction ${W.join(", ")}`;await h.executeQuery(p.raw($))}await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(zh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(zh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(zh("release savepoint",_),L()))}async releaseConnection(h){h[P1]()}async destroy(){return new Promise((h,_)=>{this.#k.end((W)=>{if(W)_(W);else h()})})}}function j8(h){return O(h)&&"insertId"in h&&"affectedRows"in h}class D1{#h;constructor(h){this.#h=h}async executeQuery(h){try{let _=await this.#_(h);if(j8(_)){let{insertId:W,affectedRows:$,changedRows:J}=_;return{insertId:W!==void 0&&W!==null&&W.toString()!=="0"?BigInt(W):void 0,numAffectedRows:$!==void 0&&$!==null?BigInt($):void 0,numChangedRows:J!==void 0&&J!==null?BigInt(J):void 0,rows:[]}}else if(Array.isArray(_))return{rows:_};return{rows:[]}}catch(_){throw d_(_,Error())}}#_(h){return new Promise((_,W)=>{this.#h.query(h.sql,h.parameters,($,J)=>{if($)W($);else _(J)})})}async*streamQuery(h,_){let W=this.#h.query(h.sql,h.parameters).stream({objectMode:!0});try{for await(let $ of W)yield{rows:[$]}}catch($){if($&&typeof $==="object"&&"code"in $&&$.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw $}}[P1](){this.#h.release()}}var m8=/`/g;class h$ extends oh{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return"`"}getRightIdentifierWrapper(){return"`"}sanitizeIdentifier(h){return h.replace(m8,"``")}visitCreateIndex(h){if(this.append("create "),h.unique)this.append("unique ");if(this.append("index "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),h.using)this.append(" using "),this.visitNode(h.using);if(h.table)this.append(" on "),this.visitNode(h.table);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.where)this.append(" "),this.visitNode(h.where)}}class _${#h;constructor(h){this.#h=h}async getSchemas(){return(await this.#h.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map((_)=>({name:_.SCHEMA_NAME}))}async getTables(h={withInternalKyselyTables:!1}){let _=this.#h.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",($)=>$.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","=",Q`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!h.withInternalKyselyTables)_=_.where("columns.TABLE_NAME","!=",xh).where("columns.TABLE_NAME","!=",ch);let W=await _.execute();return this.#_(W)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h){return h.reduce((_,W)=>{let $=_.find((J)=>J.name===W.TABLE_NAME);if(!$)$=k({name:W.TABLE_NAME,isView:W.TABLE_TYPE==="VIEW",schema:W.TABLE_SCHEMA,columns:[]}),_.push($);return $.columns.push(k({name:W.COLUMN_NAME,dataType:W.DATA_TYPE,isNullable:W.IS_NULLABLE==="YES",isAutoIncrementing:W.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:W.COLUMN_DEFAULT!==null,comment:W.COLUMN_COMMENT===""?void 0:W.COLUMN_COMMENT})),_},[])}}var O1="ea586330-2c93-47c8-908d-981d9d270f9d",Q8=3600;class k$ extends eh{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(h,_){await Q`select get_lock(${Q.lit(O1)}, ${Q.lit(Q8)})`.execute(h)}async releaseMigrationLock(h,_){await Q`select release_lock(${Q.lit(O1)})`.execute(h)}}class b8{#h;constructor(h){this.#h=h}createDriver(){return new eW(this.#h)}createQueryCompiler(){return new h$}createAdapter(){return new k$}createIntrospector(h){return new _$(h)}}var A1=Symbol();class W${#h;#_=new WeakMap;#k;constructor(h){this.#h=k({...h})}async init(){this.#k=R(this.#h.pool)?await this.#h.pool():this.#h.pool}async acquireConnection(){let h=await this.#k.connect(),_=this.#_.get(h);if(!_){if(_=new T1(h,{cursor:this.#h.cursor??null}),this.#_.set(h,_),this.#h.onCreateConnection)await this.#h.onCreateConnection(_)}if(this.#h.onReserveConnection)await this.#h.onReserveConnection(_);return _}async beginTransaction(h,_){if(_.isolationLevel||_.accessMode){let W="start transaction";if(_.isolationLevel)W+=` isolation level ${_.isolationLevel}`;if(_.accessMode)W+=` ${_.accessMode}`;await h.executeQuery(p.raw(W))}else await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(zh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(zh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(zh("release",_),L()))}async releaseConnection(h){h[A1]()}async destroy(){if(this.#k){let h=this.#k;this.#k=void 0,await h.end()}}}class T1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}async executeQuery(h){try{let{command:_,rowCount:W,rows:$}=await this.#h.query(h.sql,[...h.parameters]);return{numAffectedRows:_==="INSERT"||_==="UPDATE"||_==="DELETE"||_==="MERGE"?BigInt(W):void 0,rows:$??[]}}catch(_){throw d_(_,Error())}}async*streamQuery(h,_){if(!this.#_.cursor)throw Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");if(!Number.isInteger(_)||_<=0)throw Error("chunkSize must be a positive integer");let W=this.#h.query(new this.#_.cursor(h.sql,h.parameters.slice()));try{while(!0){let $=await W.read(_);if($.length===0)break;yield{rows:$}}}finally{await W.close()}}[A1](){this.#h.release()}}class B8{#h;constructor(h){this.#h=h}createDriver(){return new W$(this.#h)}createQueryCompiler(){return new dW}createAdapter(){return new oW}createIntrospector(h){return new rW(h)}}class $$ extends eh{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(h){await Q`exec sp_getapplock @DbPrincipal = ${Q.lit("dbo")}, @Resource = ${Q.lit(xh)}, @LockMode = ${Q.lit("Exclusive")}`.execute(h)}async releaseMigrationLock(){}}var E1=Symbol(),S1=Symbol(),N1=Symbol();class J${#h;#_;constructor(h){this.#h=k({...h});let{tarn:_,tedious:W,validateConnections:$}=this.#h,{validateConnections:J,...Y}=_.options;this.#_=new _.Pool({...Y,create:async()=>{let H=await W.connectionFactory();return await new x1(H,W).connect()},destroy:async(H)=>{await H[S1]()},validate:$===!1||J===!1?void 0:(H)=>H[N1]()})}async init(){}async acquireConnection(){return await this.#_.acquire().promise}async beginTransaction(h,_){await h.beginTransaction(_)}async commitTransaction(h){await h.commitTransaction()}async rollbackTransaction(h){await h.rollbackTransaction()}async savepoint(h,_){await h.savepoint(_)}async rollbackToSavepoint(h,_){await h.rollbackTransaction(_)}async releaseConnection(h){if(this.#h.resetConnectionsOnRelease||this.#h.tedious.resetConnectionOnRelease)await h[E1]();this.#_.release(h)}async destroy(){await this.#_.destroy()}}class x1{#h;#_;#k;constructor(h,_){this.#h=h,this.#_=!1,this.#k=_}async beginTransaction(h){let{isolationLevel:_}=h;await new Promise((W,$)=>this.#h.beginTransaction((J)=>{if(J)$(J);else W(void 0)},_?Ck(8):void 0,_?this.#W(_):void 0))}async commitTransaction(){await new Promise((h,_)=>this.#h.commitTransaction((W)=>{if(W)_(W);else h(void 0)}))}async connect(){let{promise:h,reject:_,resolve:W}=new Z_;this.#h.connect((J)=>{if(J)return _(J);W()}),this.#h.on("error",(J)=>{if(J instanceof Error&&"code"in J&&J.code==="ESOCKET")this.#_=!0;console.error(J),_(J)});function $(){_(Error("The connection ended without ever completing the connection"))}return this.#h.once("end",$),await h,this.#h.off("end",$),this}async executeQuery(h){try{let _=new Z_,W=new ok({compiledQuery:h,tedious:this.#k,onDone:_});this.#h.execSql(W.request);let{rowCount:$,rows:J}=await _.promise;return{numAffectedRows:$!==void 0?BigInt($):void 0,rows:J}}catch(_){throw d_(_,Error())}}async rollbackTransaction(h){await new Promise((_,W)=>this.#h.rollbackTransaction(($)=>{if($)W($);else _(void 0)},h))}async savepoint(h){await new Promise((_,W)=>this.#h.saveTransaction(($)=>{if($)W($);else _(void 0)},h))}async*streamQuery(h,_){if(!Number.isInteger(_)||_<=0)throw Error("chunkSize must be a positive integer");let W=new ok({compiledQuery:h,streamChunkSize:_,tedious:this.#k});this.#h.execSql(W.request);try{while(!0){let $=await W.readChunk();if($.length===0)break;if(yield{rows:$},$.length<_)break}}finally{await this.#$(W)}}#W(h){let{ISOLATION_LEVEL:_}=this.#k,$={"read committed":_.READ_COMMITTED,"read uncommitted":_.READ_UNCOMMITTED,"repeatable read":_.REPEATABLE_READ,serializable:_.SERIALIZABLE,snapshot:_.SNAPSHOT}[h];if($===void 0)throw Error(`Unknown isolation level: ${h}`);return $}#$(h){return new Promise((_)=>{if(h.request.once("requestCompleted",_),!this.#h.cancel())h.request.off("requestCompleted",_),_()})}[S1](){if("closed"in this.#h&&this.#h.closed)return Promise.resolve();return new Promise((h)=>{this.#h.once("end",h),this.#h.close()})}async[E1](){await new Promise((h,_)=>{this.#h.reset((W)=>{if(W)return _(W);h()})})}async[N1](){if(this.#_||this.#Z())return!1;try{let h=new Z_,_=new ok({compiledQuery:p.raw("select 1"),onDone:h,tedious:this.#k});return this.#h.execSql(_.request),await h.promise,!0}catch{return!1}}#Z(){return"closed"in this.#h&&Boolean(this.#h.closed)}}class ok{#h;#_;#k;#W;#$;#Z;constructor(h){let{compiledQuery:_,onDone:W,streamChunkSize:$,tedious:J}=h;if(this.#_=[],this.#k=$,this.#W={},this.#$=J,W)this.#W.onDone=(H,K)=>{if(H==="chunkReady")return;if(delete this.#W.onDone,H==="error")return W.reject(K);W.resolve({rowCount:this.#Z,rows:this.#_})};this.#h=new this.#$.Request(_.sql,(Y,H)=>{if(Y)return Object.values(this.#W).forEach((K)=>K("error",Y instanceof AggregateError?Y.errors:Y));this.#Z=H}),this.#J(_.parameters),this.#Y()}get request(){return this.#h}readChunk(){let h=this.readChunk.name;return new Promise((_,W)=>{this.#W[h]=($,J)=>{if(delete this.#W[h],$==="error")return W(J);_(this.#_.splice(0,this.#k))},this.#h.resume()})}#J(h){for(let _=0;_<h.length;_++){let W=h[_];this.#h.addParameter(String(_+1),this.#G(W),W)}}#Y(){let h=this.#k?()=>{if(this.#k<=this.#_.length)this.#h.pause(),Object.values(this.#W).forEach((W)=>W("chunkReady"))}:()=>{},_=(W)=>{let $={};for(let J of W)$[J.metadata.colName]=J.value;this.#_.push($),h()};this.#h.on("row",_),this.#h.once("requestCompleted",()=>{Object.values(this.#W).forEach((W)=>W("completed")),this.#h.off("row",_)})}#G(h){if(h_(h)||a(h)||M(h))return this.#$.TYPES.NVarChar;if(__(h)||Mh(h)&&h%1===0)if(h<-2147483648||h>2147483647)return this.#$.TYPES.BigInt;else return this.#$.TYPES.Int;if(Mh(h))return this.#$.TYPES.Float;if(yh(h))return this.#$.TYPES.Bit;if(v_(h))return this.#$.TYPES.DateTime;if(fk(h))return this.#$.TYPES.VarBinary;return this.#$.TYPES.NVarChar}}class Y${#h;constructor(h){this.#h=h}async getSchemas(){return await this.#h.selectFrom("sys.schemas").select("name").execute()}async getTables(h={withInternalKyselyTables:!1}){let _=await this.#h.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",($)=>$.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!h.withInternalKyselyTables,($)=>$.where("tables.name","!=",xh).where("tables.name","!=",ch)).select(["tables.name as table_name",($)=>$.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.#h.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",($)=>$.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(),W={};for(let $ of _){let J=`${$.table_schema_name}.${$.table_name}`;(W[J]=W[J]||k({columns:[],isView:$.table_type==="V ",name:$.table_name,schema:$.table_schema_name??void 0})).columns.push(k({dataType:$.type_name,dataTypeSchema:$.type_schema_name??void 0,hasDefaultValue:$.column_default_object_id>0||$.column_generated_always_type!=="NOT_APPLICABLE"||$.column_is_identity||$.column_is_computed||$.column_is_rowguidcol,isAutoIncrementing:$.column_is_identity,isNullable:$.column_is_nullable&&$.type_is_nullable,name:$.column_name,comment:$.column_comment??void 0}))}return Object.values(W)}async getMetadata(h){return{tables:await this.getTables(h)}}}var q8=/^[a-z0-9_]$/i;class Z$ extends oh{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(h){super.visitOffset(h),this.append(" rows")}compileColumnAlterations(h){let _={};for(let $ of h){if(!_[$.kind])_[$.kind]=[];_[$.kind].push($)}let W=!0;if(_.AddColumnNode)this.append("add "),this.compileList(_.AddColumnNode),W=!1;if(_.AlterColumnNode){if(!W)this.append(", ");this.compileList(_.AlterColumnNode)}if(_.DropColumnNode){if(!W)this.append(", ");this.append("drop column "),this.compileList(_.DropColumnNode)}if(_.ModifyColumnNode){if(!W)this.append(", ");this.compileList(_.ModifyColumnNode)}if(_.RenameColumnNode){if(!W)this.append(", ");this.compileList(_.RenameColumnNode)}}visitAddColumn(h){this.visitNode(h.column)}visitDropColumn(h){this.visitNode(h.column)}visitMergeQuery(h){super.visitMergeQuery(h),this.append(";")}visitCollate(h){this.append("collate ");let{name:_}=h.collation;for(let W of _)if(!q8.test(W))throw Error(`Invalid collation: ${_}`);this.append(_)}announcesNewColumnDataType(){return!1}}class I8{#h;constructor(h){this.#h=h}createDriver(){return new J$(this.#h)}createQueryCompiler(){return new Z$}createAdapter(){return new $$}createIntrospector(h){return new Y$(h)}}class g8{#h;constructor(h){this.#h=h}async getMigrations(){let h={},_=await this.#h.fs.readdir(this.#h.migrationFolder);for(let W of _)if(W.endsWith(".js")||W.endsWith(".ts")&&!W.endsWith(".d.ts")||W.endsWith(".mjs")||W.endsWith(".mts")&&!W.endsWith(".d.mts")){let $=await import(this.#h.path.join(this.#h.migrationFolder,W)),J=W.substring(0,W.lastIndexOf("."));if(C1($?.default))h[J]=$.default;else if(C1($))h[J]=$}return h}}function C1(h){return O(h)&&R(h.up)}class G$ extends Oh{#h;constructor(h){super();this.#h=h}transformIdentifier(h,_){return h=super.transformIdentifier(h,_),{...h,name:this.#h(h.name)}}}function m1({upperCase:h=!1,underscoreBeforeDigits:_=!1,underscoreBetweenUppercaseLetters:W=!1}={}){return b1(($)=>{if($.length===0)return $;let J=$.toUpperCase(),Y=$.toLowerCase(),H=Y[0];for(let K=1,b=$.length;K<b;++K){let x=$[K],Kh=$[K-1],z$=J[K],K$=J[K-1],ek=Y[K],I1=Y[K-1];if(_&&j1(x)&&!j1(Kh)&&!H.endsWith("_")){H+="_"+x;continue}if(x===z$&&z$!==ek)if(W||!(Kh===K$&&K$!==I1))H+="_"+ek;else H+=ek;else H+=x}if(h)return H.toUpperCase();else return H})}function Q1({upperCase:h=!1}={}){return b1((_)=>{if(_.length===0)return _;if(h&&c8(_))_=_.toLowerCase();let W=_[0];for(let $=1,J=_.length;$<J;++$){let Y=_[$],H=_[$-1];if(Y!=="_")if(H==="_")W+=Y.toUpperCase();else W+=Y}return W})}function c8(h){for(let _=1,W=h.length;_<W;++_){let $=h[_];if($!=="_"&&$!==$.toUpperCase())return!1}return!0}function j1(h){return h>="0"&&h<="9"}function b1(h){let _=new Map;return(W)=>{let $=_.get(W);if(!$)$=h(W),_.set(W,$);return $}}class y8{opt;#h;#_;#k;constructor(h={}){this.opt=h,this.#h=Q1(h),this.#_=m1(h),this.#k=new G$(this.snakeCase.bind(this))}transformQuery(h){return this.#k.transformNode(h.node,h.queryId)}async transformResult(h){if(h.result.rows&&Array.isArray(h.result.rows))return{...h.result,rows:h.result.rows.map((_)=>this.mapRow(_))};return h.result}mapRow(h){return Object.keys(h).reduce((_,W)=>{let $=h[W];if(Array.isArray($))$=$.map((J)=>B1(J,this.opt)?this.mapRow(J):J);else if(B1($,this.opt))$=this.mapRow($);return _[this.camelCase(W)]=$,_},{})}snakeCase(h){return this.#_(h)}camelCase(h){return this.#h(h)}}function B1(h,_){return wk(h)&&!_?.maintainNestedObjectKeys}class H$ extends Oh{transformSelectQuery(h,_){return this.#h(super.transformSelectQuery(h,_))}transformUpdateQuery(h,_){return this.#h(super.transformUpdateQuery(h,_))}transformDeleteQuery(h,_){return this.#h(super.transformDeleteQuery(h,_))}#h(h){if(!h.joins||h.joins.length===0)return h;return k({...h,joins:this.#_(h.joins)})}#_(h){let _=[];for(let W=0;W<h.length;++W){let $=!1;for(let J=0;J<_.length;++J)if(Rk(h[W],_[J])){$=!0;break}if(!$)_.push(h[W])}return k(_)}}class t8{#h=new H$;transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}transformResult(h){return Promise.resolve(h.result)}}class i8{opt;#h;constructor(h={}){this.opt=h,this.#h=h.objectStrategy||"in-place"}transformQuery(h){return h.node}async transformResult(h){return{...h.result,rows:q1(h.result.rows,this.#h)}}}function q1(h,_){let W=_==="create"?Array(h.length):h;for(let $=0;$<h.length;++$)W[$]=X$(h[$],_);return W}function X$(h,_){if(M(h))return u8(h);if(Array.isArray(h))return q1(h,_);if(wk(h))return p8(h,_);return h}function u8(h){if(l8(h))try{return X$(JSON.parse(h),"in-place")}catch(_){}return h}function l8(h){return h.match(/^[\[\{]/)!=null}function p8(h,_){let W=_==="create"?{}:h;for(let $ in h)W[$]=X$(h[$],_);return W}class L$ extends Oh{#h;constructor(h){super();this.#h=h}transformBinaryOperation(h){if(this.#_(h))return this.#h(h);return h}#_(h){let{operator:_,rightOperand:W}=h;return(T_.is(W)||$h.is(W))&&W.values.length===0&&y.is(_)&&(_.operator==="in"||_.operator==="not in")}}class a8{opt;#h;constructor(h){this.opt=h,this.#h=new L$(h.strategy)}transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}async transformResult(h){return h.result}}var s8,n8,d8,r8;function bF(h){let _=d8||=C.createImmediate(1),W=n8||=y.create("=");if(h.operator.operator==="in")return s8||=fh.create(_,W,C.createImmediate(0));return r8||=fh.create(_,W,_)}var o8,e8,h0;function BF(h){return function(W){if(W.operator.operator==="in")return k({...W,rightOperand:e8||=$h.create([C.createImmediate(null)])});return k({...W,leftOperand:ck.create(W.leftOperand,o8||=gk.create("char")),rightOperand:h0||=$h.create([C.createImmediate(h)])})}}export{U as _,X as $,Fh as aa,vk as ba,F$ as ca,u as da,l as ea,k_ as fa,o_ as ga,e_ as ha,I as ia,d as ja,T as ka,Pk as la,U$ as ma,Ch as na,r as oa,Uh as pa,Dk as qa,Vh as ra,fh as sa,V$ as ta,f$ as ua,w$ as va,R$ as wa,p1 as xa,a1 as ya,hW as za,y as Aa,o0 as Ba,e0 as Ca,hJ as Da,_J as Ea,_W as Fa,F as Ga,P_ as Ha,D_ as Ia,kW as Ja,Ok as Ka,wh as La,V as Ma,v$ as Na,W_ as Oa,Rh as Pa,O_ as Qa,Ak as Ra,$_ as Sa,T_ as Ta,$h as Ua,C as Va,Jh as Wa,uh as Xa,XW as Ya,_k as Za,K_ as _a,LW as $a,zW as ab,m as bb,Sk as cb,jh as db,kk as eb,J_ as fb,i as gb,KW as hb,N$ as ib,Hh as jb,Yh as kb,MW as lb,G as mb,w as nb,S_ as ob,x$ as pb,x_ as qb,Q$ as rb,b$ as sb,FW as tb,q$ as ub,UW as vb,vh as wb,mh as xb,n as yb,Qh as zb,I$ as Ab,$k as Bb,g$ as Cb,M_ as Db,D as Eb,VW as Fb,C_ as Gb,j as Hb,fW as Ib,E as Jb,wW as Kb,j_ as Lb,Yk as Mb,L as Nb,Oh as Ob,Zh as Pb,u$ as Qb,Q_ as Rb,G_ as Sb,DW as Tb,lh as Ub,e as Vb,OW as Wb,l$ as Xb,bh as Yb,s$ as Zb,n$ as _b,mk as $b,v as ac,qk as bc,bk as cc,Bk as dc,r$ as ec,b_ as fc,Bh as gc,TW as hc,hh as ic,h1 as jc,Ik as kc,_1 as lc,Gh as mc,Gk as nc,EW as oc,W1 as pc,$1 as qc,SW as rc,Xk as sc,Hk as tc,J1 as uc,NW as vc,gk as wc,Y1 as xc,ck as yc,Xh as zc,xW as Ac,Z1 as Bc,G1 as Cc,CW as Dc,S as Ec,jW as Fc,mW as Gc,B_ as Hc,X1 as Ic,q_ as Jc,Lk as Kc,L1 as Lc,N as Mc,QW as Nc,Th as Oc,Eh as Pc,g_ as Qc,qh as Rc,c_ as Sc,y_ as Tc,tk as Uc,t_ as Vc,Ih as Wc,J2 as Xc,X_ as Yc,z1 as Zc,bW as _c,Sh as $c,Lh as ad,ik as bd,_h as cd,i_ as dd,Mk as ed,Fk as fd,Nh as gd,sh as hd,u_ as id,l_ as jd,uk as kd,lk as ld,pk as md,ak as nd,p_ as od,a_ as pd,s_ as qd,IW as rd,gW as sd,z_ as td,Uk as ud,U8 as vd,V8 as wd,yW as xd,V3 as yd,tW as zd,M1 as Ad,w_ as Bd,R_ as Cd,R8 as Dd,F1 as Ed,nk as Fd,dk as Gd,nh as Hd,n_ as Id,rh as Jd,Q as Kd,iW as Ld,oh as Md,p as Nd,O8 as Od,eh as Pd,uW as Qd,lW as Rd,xh as Sd,ch as Td,T8 as Ud,aW as Vd,IK as Wd,E8 as Xd,sW as Yd,nW as Zd,S8 as _d,dW as $d,rW as ae,oW as be,eW as ce,h$ as de,_$ as ee,k$ as fe,b8 as ge,W$ as he,B8 as ie,$$ as je,J$ as ke,Y$ as le,Z$ as me,I8 as ne,g8 as oe,y8 as pe,t8 as qe,i8 as re,a8 as se,bF as te,BF as ue};
|
|
4
|
+
${W}`,h}return h}function C8(h){return O(h)&&M(h.stack)}var P1=Symbol();class eW{#h;#_=new WeakMap;#k;constructor(h){this.#h=k({...h})}async init(){this.#k=R(this.#h.pool)?await this.#h.pool():this.#h.pool}async acquireConnection(){let h=await this.#W(),_=this.#_.get(h);if(!_){if(_=new D1(h),this.#_.set(h,_),this.#h?.onCreateConnection)await this.#h.onCreateConnection(_)}if(this.#h?.onReserveConnection)await this.#h.onReserveConnection(_);return _}async#W(){return new Promise((h,_)=>{this.#k.getConnection(async(W,$)=>{if(W)_(W);else h($)})})}async beginTransaction(h,_){if(_.isolationLevel||_.accessMode){let W=[];if(_.isolationLevel)W.push(`isolation level ${_.isolationLevel}`);if(_.accessMode)W.push(_.accessMode);let $=`set transaction ${W.join(", ")}`;await h.executeQuery(p.raw($))}await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(Lh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(Lh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(Lh("release savepoint",_),L()))}async releaseConnection(h){h[P1]()}async destroy(){return new Promise((h,_)=>{this.#k.end((W)=>{if(W)_(W);else h()})})}}function j8(h){return O(h)&&"insertId"in h&&"affectedRows"in h}class D1{#h;constructor(h){this.#h=h}async executeQuery(h){try{let _=await this.#_(h);if(j8(_)){let{insertId:W,affectedRows:$,changedRows:J}=_;return{insertId:W!==void 0&&W!==null&&W.toString()!=="0"?BigInt(W):void 0,numAffectedRows:$!==void 0&&$!==null?BigInt($):void 0,numChangedRows:J!==void 0&&J!==null?BigInt(J):void 0,rows:[]}}else if(Array.isArray(_))return{rows:_};return{rows:[]}}catch(_){throw d_(_,Error())}}#_(h){return new Promise((_,W)=>{this.#h.query(h.sql,h.parameters,($,J)=>{if($)W($);else _(J)})})}async*streamQuery(h,_){let W=this.#h.query(h.sql,h.parameters).stream({objectMode:!0});try{for await(let $ of W)yield{rows:[$]}}catch($){if($&&typeof $==="object"&&"code"in $&&$.code==="ERR_STREAM_PREMATURE_CLOSE")return;throw $}}[P1](){this.#h.release()}}var m8=/`/g;class h$ extends oh{getCurrentParameterPlaceholder(){return"?"}getLeftExplainOptionsWrapper(){return""}getExplainOptionAssignment(){return"="}getExplainOptionsDelimiter(){return" "}getRightExplainOptionsWrapper(){return""}getLeftIdentifierWrapper(){return"`"}getRightIdentifierWrapper(){return"`"}sanitizeIdentifier(h){return h.replace(m8,"``")}visitCreateIndex(h){if(this.append("create "),h.unique)this.append("unique ");if(this.append("index "),h.ifNotExists)this.append("if not exists ");if(this.visitNode(h.name),h.using)this.append(" using "),this.visitNode(h.using);if(h.table)this.append(" on "),this.visitNode(h.table);if(h.columns)this.append(" ("),this.compileList(h.columns),this.append(")");if(h.where)this.append(" "),this.visitNode(h.where)}}class _${#h;constructor(h){this.#h=h}async getSchemas(){return(await this.#h.selectFrom("information_schema.schemata").select("schema_name").$castTo().execute()).map((_)=>({name:_.SCHEMA_NAME}))}async getTables(h={withInternalKyselyTables:!1}){let _=this.#h.selectFrom("information_schema.columns as columns").innerJoin("information_schema.tables as tables",($)=>$.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","=",Q`database()`).orderBy("columns.TABLE_NAME").orderBy("columns.ORDINAL_POSITION").$castTo();if(!h.withInternalKyselyTables)_=_.where("columns.TABLE_NAME","!=",Nh).where("columns.TABLE_NAME","!=",ch);let W=await _.execute();return this.#_(W)}async getMetadata(h){return{tables:await this.getTables(h)}}#_(h){return h.reduce((_,W)=>{let $=_.find((J)=>J.name===W.TABLE_NAME);if(!$)$=k({name:W.TABLE_NAME,isView:W.TABLE_TYPE==="VIEW",schema:W.TABLE_SCHEMA,columns:[]}),_.push($);return $.columns.push(k({name:W.COLUMN_NAME,dataType:W.DATA_TYPE,isNullable:W.IS_NULLABLE==="YES",isAutoIncrementing:W.EXTRA.toLowerCase().includes("auto_increment"),hasDefaultValue:W.COLUMN_DEFAULT!==null,comment:W.COLUMN_COMMENT===""?void 0:W.COLUMN_COMMENT})),_},[])}}var O1="ea586330-2c93-47c8-908d-981d9d270f9d",Q8=3600;class k$ extends eh{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(h,_){await Q`select get_lock(${Q.lit(O1)}, ${Q.lit(Q8)})`.execute(h)}async releaseMigrationLock(h,_){await Q`select release_lock(${Q.lit(O1)})`.execute(h)}}class b8{#h;constructor(h){this.#h=h}createDriver(){return new eW(this.#h)}createQueryCompiler(){return new h$}createAdapter(){return new k$}createIntrospector(h){return new _$(h)}}var A1=Symbol();class W${#h;#_=new WeakMap;#k;constructor(h){this.#h=k({...h})}async init(){this.#k=R(this.#h.pool)?await this.#h.pool():this.#h.pool}async acquireConnection(){let h=await this.#k.connect(),_=this.#_.get(h);if(!_){if(_=new T1(h,{cursor:this.#h.cursor??null}),this.#_.set(h,_),this.#h.onCreateConnection)await this.#h.onCreateConnection(_)}if(this.#h.onReserveConnection)await this.#h.onReserveConnection(_);return _}async beginTransaction(h,_){if(_.isolationLevel||_.accessMode){let W="start transaction";if(_.isolationLevel)W+=` isolation level ${_.isolationLevel}`;if(_.accessMode)W+=` ${_.accessMode}`;await h.executeQuery(p.raw(W))}else await h.executeQuery(p.raw("begin"))}async commitTransaction(h){await h.executeQuery(p.raw("commit"))}async rollbackTransaction(h){await h.executeQuery(p.raw("rollback"))}async savepoint(h,_,W){await h.executeQuery(W(Lh("savepoint",_),L()))}async rollbackToSavepoint(h,_,W){await h.executeQuery(W(Lh("rollback to",_),L()))}async releaseSavepoint(h,_,W){await h.executeQuery(W(Lh("release",_),L()))}async releaseConnection(h){h[A1]()}async destroy(){if(this.#k){let h=this.#k;this.#k=void 0,await h.end()}}}class T1{#h;#_;constructor(h,_){this.#h=h,this.#_=_}async executeQuery(h){try{let{command:_,rowCount:W,rows:$}=await this.#h.query(h.sql,[...h.parameters]);return{numAffectedRows:_==="INSERT"||_==="UPDATE"||_==="DELETE"||_==="MERGE"?BigInt(W):void 0,rows:$??[]}}catch(_){throw d_(_,Error())}}async*streamQuery(h,_){if(!this.#_.cursor)throw Error("'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.");if(!Number.isInteger(_)||_<=0)throw Error("chunkSize must be a positive integer");let W=this.#h.query(new this.#_.cursor(h.sql,h.parameters.slice()));try{while(!0){let $=await W.read(_);if($.length===0)break;yield{rows:$}}}finally{await W.close()}}[A1](){this.#h.release()}}class B8{#h;constructor(h){this.#h=h}createDriver(){return new W$(this.#h)}createQueryCompiler(){return new dW}createAdapter(){return new oW}createIntrospector(h){return new rW(h)}}class $$ extends eh{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(h){await Q`exec sp_getapplock @DbPrincipal = ${Q.lit("dbo")}, @Resource = ${Q.lit(Nh)}, @LockMode = ${Q.lit("Exclusive")}`.execute(h)}async releaseMigrationLock(){}}var E1=Symbol(),S1=Symbol(),N1=Symbol();class J${#h;#_;constructor(h){this.#h=k({...h});let{tarn:_,tedious:W,validateConnections:$}=this.#h,{validateConnections:J,...Y}=_.options;this.#_=new _.Pool({...Y,create:async()=>{let H=await W.connectionFactory();return await new x1(H,W).connect()},destroy:async(H)=>{await H[S1]()},validate:$===!1||J===!1?void 0:(H)=>H[N1]()})}async init(){}async acquireConnection(){return await this.#_.acquire().promise}async beginTransaction(h,_){await h.beginTransaction(_)}async commitTransaction(h){await h.commitTransaction()}async rollbackTransaction(h){await h.rollbackTransaction()}async savepoint(h,_){await h.savepoint(_)}async rollbackToSavepoint(h,_){await h.rollbackTransaction(_)}async releaseConnection(h){if(this.#h.resetConnectionsOnRelease||this.#h.tedious.resetConnectionOnRelease)await h[E1]();this.#_.release(h)}async destroy(){await this.#_.destroy()}}class x1{#h;#_;#k;constructor(h,_){this.#h=h,this.#_=!1,this.#k=_}async beginTransaction(h){let{isolationLevel:_}=h;await new Promise((W,$)=>this.#h.beginTransaction((J)=>{if(J)$(J);else W(void 0)},_?Ck(8):void 0,_?this.#W(_):void 0))}async commitTransaction(){await new Promise((h,_)=>this.#h.commitTransaction((W)=>{if(W)_(W);else h(void 0)}))}async connect(){let{promise:h,reject:_,resolve:W}=new Z_;this.#h.connect((J)=>{if(J)return _(J);W()}),this.#h.on("error",(J)=>{if(J instanceof Error&&"code"in J&&J.code==="ESOCKET")this.#_=!0;console.error(J),_(J)});function $(){_(Error("The connection ended without ever completing the connection"))}return this.#h.once("end",$),await h,this.#h.off("end",$),this}async executeQuery(h){try{let _=new Z_,W=new ok({compiledQuery:h,tedious:this.#k,onDone:_});this.#h.execSql(W.request);let{rowCount:$,rows:J}=await _.promise;return{numAffectedRows:$!==void 0?BigInt($):void 0,rows:J}}catch(_){throw d_(_,Error())}}async rollbackTransaction(h){await new Promise((_,W)=>this.#h.rollbackTransaction(($)=>{if($)W($);else _(void 0)},h))}async savepoint(h){await new Promise((_,W)=>this.#h.saveTransaction(($)=>{if($)W($);else _(void 0)},h))}async*streamQuery(h,_){if(!Number.isInteger(_)||_<=0)throw Error("chunkSize must be a positive integer");let W=new ok({compiledQuery:h,streamChunkSize:_,tedious:this.#k});this.#h.execSql(W.request);try{while(!0){let $=await W.readChunk();if($.length===0)break;if(yield{rows:$},$.length<_)break}}finally{await this.#$(W)}}#W(h){let{ISOLATION_LEVEL:_}=this.#k,$={"read committed":_.READ_COMMITTED,"read uncommitted":_.READ_UNCOMMITTED,"repeatable read":_.REPEATABLE_READ,serializable:_.SERIALIZABLE,snapshot:_.SNAPSHOT}[h];if($===void 0)throw Error(`Unknown isolation level: ${h}`);return $}#$(h){return new Promise((_)=>{if(h.request.once("requestCompleted",_),!this.#h.cancel())h.request.off("requestCompleted",_),_()})}[S1](){if("closed"in this.#h&&this.#h.closed)return Promise.resolve();return new Promise((h)=>{this.#h.once("end",h),this.#h.close()})}async[E1](){await new Promise((h,_)=>{this.#h.reset((W)=>{if(W)return _(W);h()})})}async[N1](){if(this.#_||this.#Z())return!1;try{let h=new Z_,_=new ok({compiledQuery:p.raw("select 1"),onDone:h,tedious:this.#k});return this.#h.execSql(_.request),await h.promise,!0}catch{return!1}}#Z(){return"closed"in this.#h&&Boolean(this.#h.closed)}}class ok{#h;#_;#k;#W;#$;#Z;constructor(h){let{compiledQuery:_,onDone:W,streamChunkSize:$,tedious:J}=h;if(this.#_=[],this.#k=$,this.#W={},this.#$=J,W)this.#W.onDone=(H,K)=>{if(H==="chunkReady")return;if(delete this.#W.onDone,H==="error")return W.reject(K);W.resolve({rowCount:this.#Z,rows:this.#_})};this.#h=new this.#$.Request(_.sql,(Y,H)=>{if(Y)return Object.values(this.#W).forEach((K)=>K("error",Y instanceof AggregateError?Y.errors:Y));this.#Z=H}),this.#J(_.parameters),this.#Y()}get request(){return this.#h}readChunk(){let h=this.readChunk.name;return new Promise((_,W)=>{this.#W[h]=($,J)=>{if(delete this.#W[h],$==="error")return W(J);_(this.#_.splice(0,this.#k))},this.#h.resume()})}#J(h){for(let _=0;_<h.length;_++){let W=h[_];this.#h.addParameter(String(_+1),this.#G(W),W)}}#Y(){let h=this.#k?()=>{if(this.#k<=this.#_.length)this.#h.pause(),Object.values(this.#W).forEach((W)=>W("chunkReady"))}:()=>{},_=(W)=>{let $={};for(let J of W)$[J.metadata.colName]=J.value;this.#_.push($),h()};this.#h.on("row",_),this.#h.once("requestCompleted",()=>{Object.values(this.#W).forEach((W)=>W("completed")),this.#h.off("row",_)})}#G(h){if(h_(h)||a(h)||M(h))return this.#$.TYPES.NVarChar;if(__(h)||Kh(h)&&h%1===0)if(h<-2147483648||h>2147483647)return this.#$.TYPES.BigInt;else return this.#$.TYPES.Int;if(Kh(h))return this.#$.TYPES.Float;if(yh(h))return this.#$.TYPES.Bit;if(v_(h))return this.#$.TYPES.DateTime;if(fk(h))return this.#$.TYPES.VarBinary;return this.#$.TYPES.NVarChar}}class Y${#h;constructor(h){this.#h=h}async getSchemas(){return await this.#h.selectFrom("sys.schemas").select("name").execute()}async getTables(h={withInternalKyselyTables:!1}){let _=await this.#h.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",($)=>$.onRef("comments.major_id","=","tables.object_id").onRef("comments.minor_id","=","columns.column_id").on("comments.name","=","MS_Description")).$if(!h.withInternalKyselyTables,($)=>$.where("tables.name","!=",Nh).where("tables.name","!=",ch)).select(["tables.name as table_name",($)=>$.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.#h.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",($)=>$.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(),W={};for(let $ of _){let J=`${$.table_schema_name}.${$.table_name}`;(W[J]=W[J]||k({columns:[],isView:$.table_type==="V ",name:$.table_name,schema:$.table_schema_name??void 0})).columns.push(k({dataType:$.type_name,dataTypeSchema:$.type_schema_name??void 0,hasDefaultValue:$.column_default_object_id>0||$.column_generated_always_type!=="NOT_APPLICABLE"||$.column_is_identity||$.column_is_computed||$.column_is_rowguidcol,isAutoIncrementing:$.column_is_identity,isNullable:$.column_is_nullable&&$.type_is_nullable,name:$.column_name,comment:$.column_comment??void 0}))}return Object.values(W)}async getMetadata(h){return{tables:await this.getTables(h)}}}var q8=/^[a-z0-9_]$/i;class Z$ extends oh{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(h){super.visitOffset(h),this.append(" rows")}compileColumnAlterations(h){let _={};for(let $ of h){if(!_[$.kind])_[$.kind]=[];_[$.kind].push($)}let W=!0;if(_.AddColumnNode)this.append("add "),this.compileList(_.AddColumnNode),W=!1;if(_.AlterColumnNode){if(!W)this.append(", ");this.compileList(_.AlterColumnNode)}if(_.DropColumnNode){if(!W)this.append(", ");this.append("drop column "),this.compileList(_.DropColumnNode)}if(_.ModifyColumnNode){if(!W)this.append(", ");this.compileList(_.ModifyColumnNode)}if(_.RenameColumnNode){if(!W)this.append(", ");this.compileList(_.RenameColumnNode)}}visitAddColumn(h){this.visitNode(h.column)}visitDropColumn(h){this.visitNode(h.column)}visitMergeQuery(h){super.visitMergeQuery(h),this.append(";")}visitCollate(h){this.append("collate ");let{name:_}=h.collation;for(let W of _)if(!q8.test(W))throw Error(`Invalid collation: ${_}`);this.append(_)}announcesNewColumnDataType(){return!1}}class I8{#h;constructor(h){this.#h=h}createDriver(){return new J$(this.#h)}createQueryCompiler(){return new Z$}createAdapter(){return new $$}createIntrospector(h){return new Y$(h)}}class g8{#h;constructor(h){this.#h=h}async getMigrations(){let h={},_=await this.#h.fs.readdir(this.#h.migrationFolder);for(let W of _)if(W.endsWith(".js")||W.endsWith(".ts")&&!W.endsWith(".d.ts")||W.endsWith(".mjs")||W.endsWith(".mts")&&!W.endsWith(".d.mts")){let $=await import(this.#h.path.join(this.#h.migrationFolder,W)),J=W.substring(0,W.lastIndexOf("."));if(C1($?.default))h[J]=$.default;else if(C1($))h[J]=$}return h}}function C1(h){return O(h)&&R(h.up)}class G$ extends Dh{#h;constructor(h){super();this.#h=h}transformIdentifier(h,_){return h=super.transformIdentifier(h,_),{...h,name:this.#h(h.name)}}}function m1({upperCase:h=!1,underscoreBeforeDigits:_=!1,underscoreBetweenUppercaseLetters:W=!1}={}){return b1(($)=>{if($.length===0)return $;let J=$.toUpperCase(),Y=$.toLowerCase(),H=Y[0];for(let K=1,b=$.length;K<b;++K){let x=$[K],zh=$[K-1],z$=J[K],K$=J[K-1],ek=Y[K],I1=Y[K-1];if(_&&j1(x)&&!j1(zh)&&!H.endsWith("_")){H+="_"+x;continue}if(x===z$&&z$!==ek)if(W||!(zh===K$&&K$!==I1))H+="_"+ek;else H+=ek;else H+=x}if(h)return H.toUpperCase();else return H})}function Q1({upperCase:h=!1}={}){return b1((_)=>{if(_.length===0)return _;if(h&&c8(_))_=_.toLowerCase();let W=_[0];for(let $=1,J=_.length;$<J;++$){let Y=_[$],H=_[$-1];if(Y!=="_")if(H==="_")W+=Y.toUpperCase();else W+=Y}return W})}function c8(h){for(let _=1,W=h.length;_<W;++_){let $=h[_];if($!=="_"&&$!==$.toUpperCase())return!1}return!0}function j1(h){return h>="0"&&h<="9"}function b1(h){let _=new Map;return(W)=>{let $=_.get(W);if(!$)$=h(W),_.set(W,$);return $}}class y8{opt;#h;#_;#k;constructor(h={}){this.opt=h,this.#h=Q1(h),this.#_=m1(h),this.#k=new G$(this.snakeCase.bind(this))}transformQuery(h){return this.#k.transformNode(h.node,h.queryId)}async transformResult(h){if(h.result.rows&&Array.isArray(h.result.rows))return{...h.result,rows:h.result.rows.map((_)=>this.mapRow(_))};return h.result}mapRow(h){return Object.keys(h).reduce((_,W)=>{let $=h[W];if(Array.isArray($))$=$.map((J)=>B1(J,this.opt)?this.mapRow(J):J);else if(B1($,this.opt))$=this.mapRow($);return _[this.camelCase(W)]=$,_},{})}snakeCase(h){return this.#_(h)}camelCase(h){return this.#h(h)}}function B1(h,_){return wk(h)&&!_?.maintainNestedObjectKeys}class H$ extends Dh{transformSelectQuery(h,_){return this.#h(super.transformSelectQuery(h,_))}transformUpdateQuery(h,_){return this.#h(super.transformUpdateQuery(h,_))}transformDeleteQuery(h,_){return this.#h(super.transformDeleteQuery(h,_))}#h(h){if(!h.joins||h.joins.length===0)return h;return k({...h,joins:this.#_(h.joins)})}#_(h){let _=[];for(let W=0;W<h.length;++W){let $=!1;for(let J=0;J<_.length;++J)if(Rk(h[W],_[J])){$=!0;break}if(!$)_.push(h[W])}return k(_)}}class t8{#h=new H$;transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}transformResult(h){return Promise.resolve(h.result)}}class i8{opt;#h;constructor(h={}){this.opt=h,this.#h=h.objectStrategy||"in-place"}transformQuery(h){return h.node}async transformResult(h){return{...h.result,rows:q1(h.result.rows,this.#h)}}}function q1(h,_){let W=_==="create"?Array(h.length):h;for(let $=0;$<h.length;++$)W[$]=X$(h[$],_);return W}function X$(h,_){if(M(h))return u8(h);if(Array.isArray(h))return q1(h,_);if(wk(h))return p8(h,_);return h}function u8(h){if(l8(h))try{return X$(JSON.parse(h),"in-place")}catch(_){}return h}function l8(h){return h.match(/^[\[\{]/)!=null}function p8(h,_){let W=_==="create"?{}:h;for(let $ in h)W[$]=X$(h[$],_);return W}class L$ extends Dh{#h;constructor(h){super();this.#h=h}transformBinaryOperation(h){if(this.#_(h))return this.#h(h);return h}#_(h){let{operator:_,rightOperand:W}=h;return(T_.is(W)||$h.is(W))&&W.values.length===0&&y.is(_)&&(_.operator==="in"||_.operator==="not in")}}class a8{opt;#h;constructor(h){this.opt=h,this.#h=new L$(h.strategy)}transformQuery(h){return this.#h.transformNode(h.node,h.queryId)}async transformResult(h){return h.result}}var s8,n8,d8,r8;function bF(h){let _=d8||=C.createImmediate(1),W=n8||=y.create("=");if(h.operator.operator==="in")return s8||=Vh.create(_,W,C.createImmediate(0));return r8||=Vh.create(_,W,_)}var o8,e8,h0;function BF(h){return function(W){if(W.operator.operator==="in")return k({...W,rightOperand:e8||=$h.create([C.createImmediate(null)])});return k({...W,leftOperand:ck.create(W.leftOperand,o8||=gk.create("char")),rightOperand:h0||=$h.create([C.createImmediate(h)])})}}export{U as Z,X as _,Mh as $,vk as aa,F$ as ba,u as ca,l as da,k_ as ea,o_ as fa,e_ as ga,I as ha,d as ia,T as ja,Pk as ka,U$ as la,xh as ma,r as na,Fh as oa,Dk as pa,Uh as qa,Vh as ra,V$ as sa,f$ as ta,w$ as ua,R$ as va,p1 as wa,a1 as xa,hW as ya,y as za,o0 as Aa,e0 as Ba,hJ as Ca,_J as Da,_W as Ea,F as Fa,P_ as Ga,D_ as Ha,kW as Ia,Ok as Ja,fh as Ka,V as La,v$ as Ma,W_ as Na,O_ as Oa,Ak as Pa,$_ as Qa,T_ as Ra,$h as Sa,C as Ta,Jh as Ua,uh as Va,XW as Wa,_k as Xa,K_ as Ya,LW as Za,zW as _a,m as $a,Sk as ab,jh as bb,kk as cb,J_ as db,i as eb,KW as fb,N$ as gb,Hh as hb,Yh as ib,MW as jb,G as kb,w as lb,S_ as mb,x$ as nb,x_ as ob,Q$ as pb,b$ as qb,FW as rb,q$ as sb,UW as tb,Rh as ub,mh as vb,n as wb,Qh as xb,I$ as yb,$k as zb,g$ as Ab,M_ as Bb,D as Cb,VW as Db,C_ as Eb,j as Fb,fW as Gb,E as Hb,wW as Ib,j_ as Jb,Yk as Kb,Dh as Lb,Zh as Mb,u$ as Nb,Q_ as Ob,G_ as Pb,DW as Qb,lh as Rb,e as Sb,OW as Tb,l$ as Ub,bh as Vb,s$ as Wb,n$ as Xb,mk as Yb,v as Zb,qk as _b,bk as $b,Bk as ac,r$ as bc,b_ as cc,Bh as dc,TW as ec,hh as fc,h1 as gc,Ik as hc,_1 as ic,Gh as jc,Gk as kc,EW as lc,W1 as mc,$1 as nc,SW as oc,Xk as pc,Hk as qc,J1 as rc,NW as sc,gk as tc,Y1 as uc,ck as vc,xW as wc,Z1 as xc,G1 as yc,CW as zc,S as Ac,jW as Bc,mW as Cc,B_ as Dc,X1 as Ec,q_ as Fc,Lk as Gc,L1 as Hc,N as Ic,QW as Jc,Ah as Kc,Th as Lc,g_ as Mc,qh as Nc,c_ as Oc,y_ as Pc,tk as Qc,t_ as Rc,Ih as Sc,J2 as Tc,X_ as Uc,z1 as Vc,bW as Wc,Eh as Xc,Xh as Yc,ik as Zc,_h as _c,i_ as $c,Mk as ad,Fk as bd,Sh as cd,sh as dd,u_ as ed,l_ as fd,uk as gd,lk as hd,pk as id,ak as jd,p_ as kd,a_ as ld,s_ as md,IW as nd,gW as od,z_ as pd,Uk as qd,U8 as rd,V8 as sd,yW as td,V3 as ud,tW as vd,M1 as wd,w_ as xd,R_ as yd,R8 as zd,F1 as Ad,nk as Bd,dk as Cd,nh as Dd,n_ as Ed,rh as Fd,Q as Gd,iW as Hd,oh as Id,p as Jd,O8 as Kd,eh as Ld,uW as Md,lW as Nd,Nh as Od,ch as Pd,T8 as Qd,aW as Rd,IK as Sd,E8 as Td,sW as Ud,nW as Vd,S8 as Wd,dW as Xd,rW as Yd,oW as Zd,eW as _d,h$ as $d,_$ as ae,k$ as be,b8 as ce,W$ as de,B8 as ee,$$ as fe,J$ as ge,Y$ as he,Z$ as ie,I8 as je,g8 as ke,y8 as le,t8 as me,i8 as ne,a8 as oe,bF as pe,BF as qe,iF as re,bw as se};
|