appos 0.1.18-0 → 0.1.20-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.
Files changed (113) hide show
  1. package/build/exports/adapter-factory-CLtf7vT5-djMsiEBl.mjs +88 -0
  2. package/build/exports/appos.d.ts +82 -0
  3. package/build/exports/bun-sqlite-dialect-DN7EKoIB-B0dpsiEy.mjs +1 -0
  4. package/build/exports/chunk-BYI67GdN.mjs +1 -0
  5. package/build/exports/chunk-DQj_Q5LL.mjs +1 -0
  6. package/build/exports/client-Cf0k1wnb.mjs +7 -0
  7. package/build/exports/client.d.ts +2093 -2082
  8. package/build/exports/client.js +22 -60
  9. package/build/exports/date.d.ts +1 -1
  10. package/build/exports/date.js +1 -1
  11. package/build/exports/db.d.mts +5195 -0
  12. package/build/exports/db.mjs +8 -0
  13. package/build/exports/dialect-BeMwdQoz-BUgv8nHa.mjs +1 -0
  14. package/build/exports/dist-cjs-6zIKAlZR.mjs +1 -0
  15. package/build/exports/dist-cjs-8ShtoC4L.mjs +1 -0
  16. package/build/exports/dist-cjs-8w9IfsHf.mjs +1 -0
  17. package/build/exports/dist-cjs-B5EVkyOL.mjs +1 -0
  18. package/build/exports/dist-cjs-BCXEF6CM.mjs +1 -0
  19. package/build/exports/dist-cjs-BEWqPJiY.mjs +1 -0
  20. package/build/exports/dist-cjs-BY2gcA7W.mjs +22 -0
  21. package/build/exports/dist-cjs-BilOG_GK.mjs +5 -0
  22. package/build/exports/dist-cjs-BurjEDDY.mjs +1 -0
  23. package/build/exports/dist-cjs-CkmP5Wcr.mjs +1 -0
  24. package/build/exports/dist-cjs-D9iFq61w.mjs +1 -0
  25. package/build/exports/dist-cjs-DBYzdOBR.mjs +10 -0
  26. package/build/exports/dist-cjs-DO06FS0-.mjs +1 -0
  27. package/build/exports/dist-cjs-Ddwe8ROf.mjs +1 -0
  28. package/build/exports/dist-cjs-DpVGmjIF.mjs +1 -0
  29. package/build/exports/esm-FzcFIiBQ.mjs +3 -0
  30. package/build/exports/event-streams-BOfsfbfw.mjs +1 -0
  31. package/build/exports/file-preview-dialog-BquzKbRO.mjs +59 -0
  32. package/build/exports/kysely-adapter-WhLCdqvu.mjs +1 -0
  33. package/build/exports/magic-string.es-jZcifc5m.mjs +14 -0
  34. package/build/exports/memory-adapter-CBfVsIEf.mjs +1 -0
  35. package/build/exports/node-ponyfill-PofhX7d2.mjs +1 -0
  36. package/build/exports/node-sqlite-dialect-BqISUSC3-DSS_lf2e.mjs +1 -0
  37. package/build/exports/package-DfozRyK6.mjs +1 -0
  38. package/build/exports/react-dom-DRJH8-Wa.mjs +42 -0
  39. package/build/exports/server.d.mts +71688 -0
  40. package/build/exports/server.mjs +325 -0
  41. package/build/exports/sso-oidc-DMxhsWZu.mjs +1 -0
  42. package/build/exports/sts-CqD3bswo.mjs +1 -0
  43. package/build/exports/sts-DJilo-ly.mjs +1 -0
  44. package/build/exports/test.d.mts +8922 -0
  45. package/build/exports/test.mjs +1255 -0
  46. package/build/exports/ui/index.d.ts +1595 -568
  47. package/build/exports/ui/index.js +112 -162
  48. package/build/exports/utils.d.ts +6 -4
  49. package/build/exports/utils.js +1 -1
  50. package/build/exports/zod.d.ts +2 -1
  51. package/build/exports/zod.js +13 -13
  52. package/package.json +9 -8
  53. package/build/exports/bun-sqlite-dialect-DN7EKoIB-U6HWGDKS.js +0 -1
  54. package/build/exports/chunk-2LU65C2X.js +0 -1
  55. package/build/exports/chunk-3RRIQKOV.js +0 -2
  56. package/build/exports/chunk-A2LPCJPF.js +0 -5
  57. package/build/exports/chunk-CWTDMDIJ.js +0 -2
  58. package/build/exports/chunk-FBFACBKZ.js +0 -20
  59. package/build/exports/chunk-FZ26Y4SI.js +0 -1
  60. package/build/exports/chunk-GQYUAAFT.js +0 -1
  61. package/build/exports/chunk-HZYRJBRQ.js +0 -1
  62. package/build/exports/chunk-IAPQO6XO.js +0 -1
  63. package/build/exports/chunk-JIMTVXLP.js +0 -5
  64. package/build/exports/chunk-KNTGSRCW.js +0 -20
  65. package/build/exports/chunk-KRQ2L5OP.js +0 -1
  66. package/build/exports/chunk-MQK6VFZR.js +0 -1
  67. package/build/exports/chunk-N756FM5W.js +0 -6
  68. package/build/exports/chunk-NJ2TZAVN.js +0 -169
  69. package/build/exports/chunk-NM7CITTT.js +0 -2
  70. package/build/exports/chunk-PECJ5CRS.js +0 -1
  71. package/build/exports/chunk-PYGCG54X.js +0 -94
  72. package/build/exports/chunk-QMFB7WUQ.js +0 -1
  73. package/build/exports/chunk-QWUKON2B.js +0 -4
  74. package/build/exports/chunk-S3F2U5VR.js +0 -1
  75. package/build/exports/chunk-S6CGHQRG.js +0 -2
  76. package/build/exports/chunk-TLDYRTHH.js +0 -1
  77. package/build/exports/chunk-TX6WXZHJ.js +0 -1
  78. package/build/exports/chunk-Y6DVQ7FD.js +0 -1
  79. package/build/exports/chunk-YBDDYGAW.js +0 -1
  80. package/build/exports/db.d.ts +0 -5194
  81. package/build/exports/db.js +0 -9
  82. package/build/exports/dist-es-442MVKMG.js +0 -1
  83. package/build/exports/dist-es-5NPX4IPA.js +0 -2
  84. package/build/exports/dist-es-AAGJZOKW.js +0 -1
  85. package/build/exports/dist-es-BA4XRQMD.js +0 -1
  86. package/build/exports/dist-es-CEXBPGKD.js +0 -1
  87. package/build/exports/dist-es-D7P74EQC.js +0 -2
  88. package/build/exports/dist-es-K23RHFIG.js +0 -2
  89. package/build/exports/dist-es-K6CZFUD7.js +0 -5
  90. package/build/exports/dist-es-PV5MXZPQ.js +0 -5
  91. package/build/exports/dist-es-PV6DSUWC.js +0 -1
  92. package/build/exports/dist-es-PYWXCUQO.js +0 -2
  93. package/build/exports/dist-es-QLJ2PEMO.js +0 -1
  94. package/build/exports/dist-es-TDQNJYF5.js +0 -1
  95. package/build/exports/dist-es-VXQY2642.js +0 -1
  96. package/build/exports/event-streams-JL44VPIA.js +0 -1
  97. package/build/exports/file-preview-dialog-XJMPJ764.js +0 -15
  98. package/build/exports/kysely-adapter-UB5EKM3L.js +0 -1
  99. package/build/exports/loadSso-ATQGBCEY.js +0 -1
  100. package/build/exports/loadSso-ILXKFPPV.js +0 -1
  101. package/build/exports/magic-string.es-TEACLLHX.js +0 -13
  102. package/build/exports/memory-adapter-LJJR2XXS.js +0 -1
  103. package/build/exports/node-ponyfill-6NJTIN4I.js +0 -1
  104. package/build/exports/node-sqlite-dialect-BqISUSC3-3545EWOZ.js +0 -1
  105. package/build/exports/plugin-56OEBMME.js +0 -4
  106. package/build/exports/server.d.ts +0 -71779
  107. package/build/exports/server.js +0 -435
  108. package/build/exports/sso-oidc-7POVDJYK.js +0 -1
  109. package/build/exports/sso-oidc-TUR3VC4Y.js +0 -1
  110. package/build/exports/sts-35P3OWOX.js +0 -6
  111. package/build/exports/sts-ZDKVF6HW.js +0 -1
  112. package/build/exports/test.d.ts +0 -8942
  113. package/build/exports/test.js +0 -1583
@@ -0,0 +1,3 @@
1
+ function e(e){return e===void 0||e===void 0}function t(e){return typeof e==`string`}function n(e){return typeof e==`number`}function r(e){return typeof e==`boolean`}function i(e){return e===null}function a(e){return e instanceof Date}function o(e){return typeof e==`bigint`}function ee(e){return typeof Buffer<`u`&&Buffer.isBuffer(e)}function s(e){return typeof e==`function`}function c(e){return typeof e==`object`&&!!e}function l(e){return Object.freeze(e)}function te(e){return u(e)?e:[e]}function u(e){return Array.isArray(e)}function d(e){return e}const f=l({is(e){return e.kind===`AlterTableNode`},create(e){return l({kind:`AlterTableNode`,table:e})},cloneWithTableProps(e,t){return l({...e,...t})},cloneWithColumnAlteration(e,t){return l({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}}),p=l({is(e){return e.kind===`IdentifierNode`},create(e){return l({kind:`IdentifierNode`,name:e})}}),m=l({is(e){return e.kind===`CreateIndexNode`},create(e){return l({kind:`CreateIndexNode`,name:p.create(e)})},cloneWith(e,t){return l({...e,...t})},cloneWithColumns(e,t){return l({...e,columns:[...e.columns||[],...t]})}}),ne=l({is(e){return e.kind===`CreateSchemaNode`},create(e,t){return l({kind:`CreateSchemaNode`,schema:p.create(e),...t})},cloneWith(e,t){return l({...e,...t})}}),re=[`preserve rows`,`delete rows`,`drop`],h=l({is(e){return e.kind===`CreateTableNode`},create(e){return l({kind:`CreateTableNode`,table:e,columns:l([])})},cloneWithColumn(e,t){return l({...e,columns:l([...e.columns,t])})},cloneWithConstraint(e,t){return l({...e,constraints:e.constraints?l([...e.constraints,t]):l([t])})},cloneWithFrontModifier(e,t){return l({...e,frontModifiers:e.frontModifiers?l([...e.frontModifiers,t]):l([t])})},cloneWithEndModifier(e,t){return l({...e,endModifiers:e.endModifiers?l([...e.endModifiers,t]):l([t])})},cloneWith(e,t){return l({...e,...t})}}),g=l({is(e){return e.kind===`SchemableIdentifierNode`},create(e){return l({kind:`SchemableIdentifierNode`,identifier:p.create(e)})},createWithSchema(e,t){return l({kind:`SchemableIdentifierNode`,schema:p.create(e),identifier:p.create(t)})}}),ie=l({is(e){return e.kind===`DropIndexNode`},create(e,t){return l({kind:`DropIndexNode`,name:g.create(e),...t})},cloneWith(e,t){return l({...e,...t})}}),ae=l({is(e){return e.kind===`DropSchemaNode`},create(e,t){return l({kind:`DropSchemaNode`,schema:p.create(e),...t})},cloneWith(e,t){return l({...e,...t})}}),oe=l({is(e){return e.kind===`DropTableNode`},create(e,t){return l({kind:`DropTableNode`,table:e,...t})},cloneWith(e,t){return l({...e,...t})}}),_=l({is(e){return e.kind===`AliasNode`},create(e,t){return l({kind:`AliasNode`,node:e,alias:t})}}),v=l({is(e){return e.kind===`TableNode`},create(e){return l({kind:`TableNode`,table:g.create(e)})},createWithSchema(e,t){return l({kind:`TableNode`,table:g.createWithSchema(e,t)})}});function y(e){return c(e)&&s(e.toOperationNode)}function se(e){return c(e)&&`expressionType`in e&&y(e)}function ce(e){return c(e)&&`expression`in e&&t(e.alias)&&y(e)}const b=l({is(e){return e.kind===`SelectModifierNode`},create(e,t){return l({kind:`SelectModifierNode`,modifier:e,of:t})},createWithExpression(e){return l({kind:`SelectModifierNode`,rawModifier:e})}}),x=l({is(e){return e.kind===`AndNode`},create(e,t){return l({kind:`AndNode`,left:e,right:t})}}),le=l({is(e){return e.kind===`OrNode`},create(e,t){return l({kind:`OrNode`,left:e,right:t})}}),ue=l({is(e){return e.kind===`OnNode`},create(e){return l({kind:`OnNode`,on:e})},cloneWithOperation(e,t,n){return l({...e,on:t===`And`?x.create(e.on,n):le.create(e.on,n)})}}),de=l({is(e){return e.kind===`JoinNode`},create(e,t){return l({kind:`JoinNode`,joinType:e,table:t,on:void 0})},createWithOn(e,t,n){return l({kind:`JoinNode`,joinType:e,table:t,on:ue.create(n)})},cloneWithOn(e,t){return l({...e,on:e.on?ue.cloneWithOperation(e.on,`And`,t):ue.create(t)})}}),fe=l({is(e){return e.kind===`BinaryOperationNode`},create(e,t,n){return l({kind:`BinaryOperationNode`,leftOperand:e,operator:t,rightOperand:n})}}),pe=`=.==.!=.<>.>.>=.<.<=.in.not in.is.is not.like.not like.match.ilike.not ilike.@>.<@.^@.&&.?.?&.?|.!<.!>.<=>.!~.~.~*.!~*.@@.@@@.!!.<->.regexp.is distinct from.is not distinct from`.split(`.`),me=[`+`,`-`,`*`,`/`,`%`,`^`,`&`,`|`,`#`,`<<`,`>>`],he=[`->`,`->>`],ge=[...pe,...me,`&&`,`||`],_e=[`not`,`-`,...[`exists`,`not exists`]],ve=[...ge,...he,..._e,`between`,`between symmetric`],S=l({is(e){return e.kind===`OperatorNode`},create(e){return l({kind:`OperatorNode`,operator:e})}});function ye(e){return t(e)&&he.includes(e)}const C=l({is(e){return e.kind===`ColumnNode`},create(e){return l({kind:`ColumnNode`,column:p.create(e)})}}),be=l({is(e){return e.kind===`SelectAllNode`},create(){return l({kind:`SelectAllNode`})}}),xe=l({is(e){return e.kind===`ReferenceNode`},create(e,t){return l({kind:`ReferenceNode`,table:t,column:e})},createSelectAll(e){return l({kind:`ReferenceNode`,table:e,column:be.create()})}});var Se=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Ie(this.#e)}};function Ce(e){return c(e)&&y(e)&&t(e.dynamicReference)}const w=l({is(e){return e.kind===`OrderByItemNode`},create(e,t){return l({kind:`OrderByItemNode`,orderBy:e,direction:t})},cloneWith(e,t){return l({...e,...t})}}),T=l({is(e){return e.kind===`RawNode`},create(e,t){return l({kind:`RawNode`,sqlFragments:l(e),parameters:l(t)})},createWithSql(e){return T.create([e],[])},createWithChild(e){return T.create([``,``],[e])},createWithChildren(e){return T.create(Array(e.length+1).fill(``),e)}}),we={is(e){return e.kind===`CollateNode`},create(e){return l({kind:`CollateNode`,collation:p.create(e)})}};var Te=class e{#e;constructor(e){this.#e=l(e)}desc(){return new e({node:w.cloneWith(this.#e.node,{direction:T.createWithSql(`desc`)})})}asc(){return new e({node:w.cloneWith(this.#e.node,{direction:T.createWithSql(`asc`)})})}nullsLast(){return new e({node:w.cloneWith(this.#e.node,{nulls:`last`})})}nullsFirst(){return new e({node:w.cloneWith(this.#e.node,{nulls:`first`})})}collate(t){return new e({node:w.cloneWith(this.#e.node,{collation:we.create(t)})})}toOperationNode(){return this.#e.node}};const Ee=new Set;function De(e){Ee.has(e)||(Ee.add(e),console.log(e))}function Oe(e){return e===`asc`||e===`desc`}function ke(e){if(e.length===2)return[Ae(e[0],e[1])];if(e.length===1){let[t]=e;return Array.isArray(t)?(De(`orderBy(array) is deprecated, use multiple orderBy calls instead.`),t.map(e=>Ae(e))):[Ae(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function Ae(e,t){let n=je(e);if(w.is(n)){if(t)throw Error(`Cannot specify direction twice!`);return n}return Me(n,t)}function je(e){if(br(e))return vr(e);if(Ce(e))return e.toOperationNode();let[t,n]=e.split(` `);return n?(De("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Me(D(t),n)):D(e)}function Me(e,t){if(typeof t==`string`){if(!Oe(t))throw Error(`Invalid order by direction: ${t}`);return w.create(e,T.createWithSql(t))}if(se(t))return De("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),w.create(e,t.toOperationNode());let n=w.create(e);return t?t(new Te({node:n})).toOperationNode():n}const Ne=l({is(e){return e.kind===`JSONReferenceNode`},create(e,t){return l({kind:`JSONReferenceNode`,reference:e,traversal:t})},cloneWithTraversal(e,t){return l({...e,traversal:t})}}),Pe=l({is(e){return e.kind===`JSONOperatorChainNode`},create(e){return l({kind:`JSONOperatorChainNode`,operator:e,values:l([])})},cloneWithValue(e,t){return l({...e,values:l([...e.values,t])})}}),Fe=l({is(e){return e.kind===`JSONPathNode`},create(e){return l({kind:`JSONPathNode`,inOperator:e,pathLegs:l([])})},cloneWithLeg(e,t){return l({...e,pathLegs:l([...e.pathLegs,t])})}});function Ie(e){return t(e)?D(e):e.toOperationNode()}function Le(e){return u(e)?e.map(e=>E(e)):[E(e)]}function E(e){return br(e)?vr(e):Ie(e)}function Re(e,t){let n=D(e);if(ye(t))return Ne.create(n,Pe.create(S.create(t)));let r=t.slice(0,-1);if(ye(r))return Ne.create(n,Fe.create(S.create(r)));throw Error(`Invalid JSON operator: ${t}`)}function D(e){if(!e.includes(`.`))return xe.create(C.create(e));let t=e.split(`.`).map(We);if(t.length===3)return He(t);if(t.length===2)return Ue(t);throw Error(`invalid column reference ${e}`)}function ze(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(We);return _.create(D(n),p.create(r))}else return D(e)}function Be(e){return C.create(e)}function Ve(e){if(e.includes(` `)){let[t,n]=e.split(` `).map(We);if(!Oe(n))throw Error(`invalid order direction "${n}" next to "${t}"`);return ke([t,n])[0]}else return Be(e)}function He(e){let[t,n,r]=e;return xe.create(C.create(r),v.createWithSchema(t,n))}function Ue(e){let[t,n]=e;return xe.create(C.create(n),v.create(t))}function We(e){return e.trim()}const Ge=l({is(e){return e.kind===`PrimitiveValueListNode`},create(e){return l({kind:`PrimitiveValueListNode`,values:l([...e])})}}),Ke=l({is(e){return e.kind===`ValueListNode`},create(e){return l({kind:`ValueListNode`,values:l(e)})}}),O=l({is(e){return e.kind===`ValueNode`},create(e){return l({kind:`ValueNode`,value:e})},createImmediate(e){return l({kind:`ValueNode`,value:e,immediate:!0})}});function qe(e){return u(e)?Xe(e):k(e)}function k(e){return br(e)?vr(e):O.create(e)}function Je(e){return n(e)||r(e)||i(e)}function Ye(e){if(!Je(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return O.createImmediate(e)}function Xe(e){return e.some(br)?Ke.create(e.map(e=>k(e))):Ge.create(e)}const A=l({is(e){return e.kind===`ParensNode`},create(e){return l({kind:`ParensNode`,node:e})}});function j(e){if(e.length===3)return Ze(e[0],e[1],e[2]);if(e.length===1)return k(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Ze(e,t,n){return et(t)&&tt(n)?fe.create(E(e),nt(t),O.createImmediate(n)):fe.create(E(e),nt(t),qe(n))}function M(e,t,n){return fe.create(E(e),nt(t),E(n))}function Qe(t,n){return $e(Object.entries(t).filter(([,t])=>!e(t)).map(([e,t])=>Ze(e,tt(t)?`is`:`=`,t)),n)}function $e(e,t,n=!0){let r=t===`and`?x.create:le.create;if(e.length===0)return fe.create(O.createImmediate(1),S.create(`=`),O.createImmediate(t===`and`?1:0));let i=rt(e[0]);for(let t=1;t<e.length;++t)i=r(i,rt(e[t]));return e.length>1&&n?A.create(i):i}function et(e){return e===`is`||e===`is not`}function tt(e){return i(e)||r(e)}function nt(e){if(t(e)&&ve.includes(e))return S.create(e);if(y(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function rt(e){return y(e)?e.toOperationNode():e}const it=l({is(e){return e.kind===`OrderByNode`},create(e){return l({kind:`OrderByNode`,items:l([...e])})},cloneWithItems(e,t){return l({...e,items:l([...e.items,...t])})}}),at=l({is(e){return e.kind===`PartitionByNode`},create(e){return l({kind:`PartitionByNode`,items:l(e)})},cloneWithItems(e,t){return l({...e,items:l([...e.items,...t])})}}),ot=l({is(e){return e.kind===`OverNode`},create(){return l({kind:`OverNode`})},cloneWithOrderByItems(e,t){return l({...e,orderBy:e.orderBy?it.cloneWithItems(e.orderBy,t):it.create(t)})},cloneWithPartitionByItems(e,t){return l({...e,partitionBy:e.partitionBy?at.cloneWithItems(e.partitionBy,t):at.create(t)})}}),st=l({is(e){return e.kind===`FromNode`},create(e){return l({kind:`FromNode`,froms:l(e)})},cloneWithFroms(e,t){return l({...e,froms:l([...e.froms,...t])})}}),ct=l({is(e){return e.kind===`GroupByNode`},create(e){return l({kind:`GroupByNode`,items:l(e)})},cloneWithItems(e,t){return l({...e,items:l([...e.items,...t])})}}),lt=l({is(e){return e.kind===`HavingNode`},create(e){return l({kind:`HavingNode`,having:e})},cloneWithOperation(e,t,n){return l({...e,having:t===`And`?x.create(e.having,n):le.create(e.having,n)})}}),N=l({is(e){return e.kind===`InsertQueryNode`},create(e,t,n){return l({kind:`InsertQueryNode`,into:e,...t&&{with:t},replace:n})},createWithoutInto(){return l({kind:`InsertQueryNode`})},cloneWith(e,t){return l({...e,...t})}}),ut=l({is(e){return e.kind===`ListNode`},create(e){return l({kind:`ListNode`,items:l(e)})}}),dt=l({is(e){return e.kind===`UpdateQueryNode`},create(e,t){return l({kind:`UpdateQueryNode`,table:e.length===1?e[0]:ut.create(e),...t&&{with:t}})},createWithoutTable(){return l({kind:`UpdateQueryNode`})},cloneWithFromItems(e,t){return l({...e,from:e.from?st.cloneWithFroms(e.from,t):st.create(t)})},cloneWithUpdates(e,t){return l({...e,updates:e.updates?l([...e.updates,...t]):t})},cloneWithLimit(e,t){return l({...e,limit:t})}}),ft=l({is(e){return e.kind===`UsingNode`},create(e){return l({kind:`UsingNode`,tables:l(e)})},cloneWithTables(e,t){return l({...e,tables:l([...e.tables,...t])})}}),pt=l({is(e){return e.kind===`DeleteQueryNode`},create(e,t){return l({kind:`DeleteQueryNode`,from:st.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>I.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:e=>I.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return l({...e,limit:t})},cloneWithoutLimit(e){return l({...e,limit:void 0})},cloneWithUsing(e,t){return l({...e,using:e.using===void 0?ft.create(t):ft.cloneWithTables(e.using,t)})}}),P=l({is(e){return e.kind===`WhereNode`},create(e){return l({kind:`WhereNode`,where:e})},cloneWithOperation(e,t,n){return l({...e,where:t===`And`?x.create(e.where,n):le.create(e.where,n)})}}),mt=l({is(e){return e.kind===`ReturningNode`},create(e){return l({kind:`ReturningNode`,selections:l(e)})},cloneWithSelections(e,t){return l({...e,selections:e.selections?l([...e.selections,...t]):l(t)})}}),ht=l({is(e){return e.kind===`ExplainNode`},create(e,t){return l({kind:`ExplainNode`,format:e,options:t})}}),gt=l({is(e){return e.kind===`WhenNode`},create(e){return l({kind:`WhenNode`,condition:e})},cloneWithResult(e,t){return l({...e,result:t})}}),F=l({is(e){return e.kind===`MergeQueryNode`},create(e,t){return l({kind:`MergeQueryNode`,into:e,...t&&{with:t}})},cloneWithUsing(e,t){return l({...e,using:t})},cloneWithWhen(e,t){return l({...e,whens:e.whens?l([...e.whens,t]):l([t])})},cloneWithThen(e,t){return l({...e,whens:e.whens?l([...e.whens.slice(0,-1),gt.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}}),_t=l({is(e){return e.kind===`OutputNode`},create(e){return l({kind:`OutputNode`,selections:l(e)})},cloneWithSelections(e,t){return l({...e,selections:e.selections?l([...e.selections,...t]):l(t)})}}),I=l({is(e){return L.is(e)||N.is(e)||dt.is(e)||pt.is(e)||F.is(e)},cloneWithEndModifier(e,t){return l({...e,endModifiers:e.endModifiers?l([...e.endModifiers,t]):l([t])})},cloneWithWhere(e,t){return l({...e,where:e.where?P.cloneWithOperation(e.where,`And`,t):P.create(t)})},cloneWithJoin(e,t){return l({...e,joins:e.joins?l([...e.joins,t]):l([t])})},cloneWithReturning(e,t){return l({...e,returning:e.returning?mt.cloneWithSelections(e.returning,t):mt.create(t)})},cloneWithoutReturning(e){return l({...e,returning:void 0})},cloneWithoutWhere(e){return l({...e,where:void 0})},cloneWithExplain(e,t,n){return l({...e,explain:ht.create(t,n?.toOperationNode())})},cloneWithTop(e,t){return l({...e,top:t})},cloneWithOutput(e,t){return l({...e,output:e.output?_t.cloneWithSelections(e.output,t):_t.create(t)})},cloneWithOrderByItems(e,t){return l({...e,orderBy:e.orderBy?it.cloneWithItems(e.orderBy,t):it.create(t)})},cloneWithoutOrderBy(e){return l({...e,orderBy:void 0})}}),L=l({is(e){return e.kind===`SelectQueryNode`},create(e){return l({kind:`SelectQueryNode`,...e&&{with:e}})},createFrom(e,t){return l({kind:`SelectQueryNode`,from:st.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return l({...e,selections:e.selections?l([...e.selections,...t]):l(t)})},cloneWithDistinctOn(e,t){return l({...e,distinctOn:e.distinctOn?l([...e.distinctOn,...t]):l(t)})},cloneWithFrontModifier(e,t){return l({...e,frontModifiers:e.frontModifiers?l([...e.frontModifiers,t]):l([t])})},cloneWithOrderByItems:(e,t)=>I.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return l({...e,groupBy:e.groupBy?ct.cloneWithItems(e.groupBy,t):ct.create(t)})},cloneWithLimit(e,t){return l({...e,limit:t})},cloneWithOffset(e,t){return l({...e,offset:t})},cloneWithFetch(e,t){return l({...e,fetch:t})},cloneWithHaving(e,t){return l({...e,having:e.having?lt.cloneWithOperation(e.having,`And`,t):lt.create(t)})},cloneWithSetOperations(e,t){return l({...e,setOperations:e.setOperations?l([...e.setOperations,...t]):l([...t])})},cloneWithoutSelections(e){return l({...e,selections:[]})},cloneWithoutLimit(e){return l({...e,limit:void 0})},cloneWithoutOffset(e){return l({...e,offset:void 0})},cloneWithoutOrderBy:e=>I.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return l({...e,groupBy:void 0})}});var vt=class e{#e;constructor(e){this.#e=l(e)}on(...t){return new e({...this.#e,joinNode:de.cloneWithOn(this.#e.joinNode,j(t))})}onRef(t,n,r){return new e({...this.#e,joinNode:de.cloneWithOn(this.#e.joinNode,M(t,n,r))})}onTrue(){return new e({...this.#e,joinNode:de.cloneWithOn(this.#e.joinNode,T.createWithSql(`true`))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};const yt=l({is(e){return e.kind===`PartitionByItemNode`},create(e){return l({kind:`PartitionByItemNode`,partitionBy:e})}});function bt(e){return Le(e).map(yt.create)}var xt=class e{#e;constructor(e){this.#e=l(e)}orderBy(...t){return new e({overNode:ot.cloneWithOrderByItems(this.#e.overNode,ke(t))})}clearOrderBy(){return new e({overNode:I.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(t){return new e({overNode:ot.cloneWithPartitionByItems(this.#e.overNode,bt(t))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};const St=l({is(e){return e.kind===`SelectionNode`},create(e){return l({kind:`SelectionNode`,selection:e})},createSelectAll(){return l({kind:`SelectionNode`,selection:be.create()})},createSelectAllFromTable(e){return l({kind:`SelectionNode`,selection:xe.createSelectAll(e)})}});function R(e){return s(e)?R(e(_r())):u(e)?e.map(e=>Ct(e)):[Ct(e)]}function Ct(e){return t(e)?St.create(ze(e)):Ce(e)?St.create(e.toOperationNode()):St.create(yr(e))}function z(e){return e?Array.isArray(e)?e.map(wt):[wt(e)]:[St.createSelectAll()]}function wt(e){if(t(e))return St.createSelectAllFromTable(K(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}const Tt=l({is(e){return e.kind===`ValuesNode`},create(e){return l({kind:`ValuesNode`,values:l(e)})}}),Et=l({is(e){return e.kind===`DefaultInsertValueNode`},create(){return l({kind:`DefaultInsertValueNode`})}});function Dt(e){let t=s(e)?e(_r()):e;return Ot(u(t)?t:l([t]))}function Ot(e){let t=kt(e);return[l([...t.keys()].map(C.create)),Tt.create(e.map(e=>At(e,t)))]}function kt(e){let t=new Map;for(let n of e){let e=Object.keys(n);for(let r of e)!t.has(r)&&n[r]!==void 0&&t.set(r,t.size)}return t}function At(t,n){let r=Object.keys(t),i=Array.from({length:n.size}),a=!1,o=r.length;for(let ee of r){let r=n.get(ee);if(e(r)){o--;continue}let s=t[ee];(e(s)||br(s))&&(a=!0),i[r]=s}if(o<n.size||a){let t=Et.create();return Ke.create(i.map(n=>e(n)?t:k(n)))}return Ge.create(i)}const jt=l({is(e){return e.kind===`ColumnUpdateNode`},create(e,t){return l({kind:`ColumnUpdateNode`,column:e,value:t})}});function Mt(...e){return e.length===2?[jt.create(E(e[0]),k(e[1]))]:Nt(e[0])}function Nt(e){let t=s(e)?e(_r()):e;return Object.entries(t).filter(([e,t])=>t!==void 0).map(([e,t])=>jt.create(C.create(e),k(t)))}const Pt=l({is(e){return e.kind===`OnDuplicateKeyNode`},create(e){return l({kind:`OnDuplicateKeyNode`,updates:e})}});var Ft=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}},It=class extends Error{node;constructor(e){super(`no result`),this.node=e}};function Lt(e){return Object.prototype.hasOwnProperty.call(e,`prototype`)}const B=l({is(e){return e.kind===`OnConflictNode`},create(){return l({kind:`OnConflictNode`})},cloneWith(e,t){return l({...e,...t})},cloneWithIndexWhere(e,t){return l({...e,indexWhere:e.indexWhere?P.cloneWithOperation(e.indexWhere,`And`,t):P.create(t)})},cloneWithIndexOrWhere(e,t){return l({...e,indexWhere:e.indexWhere?P.cloneWithOperation(e.indexWhere,`Or`,t):P.create(t)})},cloneWithUpdateWhere(e,t){return l({...e,updateWhere:e.updateWhere?P.cloneWithOperation(e.updateWhere,`And`,t):P.create(t)})},cloneWithUpdateOrWhere(e,t){return l({...e,updateWhere:e.updateWhere?P.cloneWithOperation(e.updateWhere,`Or`,t):P.create(t)})},cloneWithoutIndexWhere(e){return l({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return l({...e,updateWhere:void 0})}});var Rt=class e{#e;constructor(e){this.#e=l(e)}column(t){let n=C.create(t);return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?l([...this.#e.onConflictNode.columns,n]):l([n])})})}columns(t){let n=t.map(C.create);return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?l([...this.#e.onConflictNode.columns,...n]):l(n)})})}constraint(t){return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{constraint:p.create(t)})})}expression(t){return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{indexExpression:t.toOperationNode()})})}where(...t){return new e({...this.#e,onConflictNode:B.cloneWithIndexWhere(this.#e.onConflictNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:B.cloneWithIndexWhere(this.#e.onConflictNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:B.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new zt({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Bt({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{updates:Nt(e)})})}$call(e){return e(this)}},zt=class{#e;constructor(e){this.#e=l(e)}toOperationNode(){return this.#e.onConflictNode}},Bt=class e{#e;constructor(e){this.#e=l(e)}where(...t){return new e({...this.#e,onConflictNode:B.cloneWithUpdateWhere(this.#e.onConflictNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:B.cloneWithUpdateWhere(this.#e.onConflictNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:B.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};const Vt=l({is(e){return e.kind===`TopNode`},create(e,t){return l({kind:`TopNode`,expression:e,modifiers:t})}});function Ht(t,r){if(!n(t)&&!o(t))throw Error(`Invalid top expression: ${t}`);if(!e(r)&&!Ut(r))throw Error(`Invalid top modifiers: ${r}`);return Vt.create(t,r)}function Ut(e){return e===`percent`||e===`with ties`||e===`percent with ties`}const Wt=l({is(e){return e.kind===`OrActionNode`},create(e){return l({kind:`OrActionNode`,action:e})}});var Gt=class e{#e;constructor(e){this.#e=l(e)}values(t){let[n,r]=Dt(t);return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{columns:n,values:r})})}columns(t){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{columns:l(t.map(C.create))})})}expression(t){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{values:vr(t)})})}defaultValues(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}ignore(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`ignore`)})})}orIgnore(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`ignore`)})})}orAbort(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`abort`)})})}orFail(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`fail`)})})}orReplace(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`replace`)})})}orRollback(){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{orAction:Wt.create(`rollback`)})})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}onConflict(t){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{onConflict:t(new Rt({onConflictNode:B.create()})).toOperationNode()})})}onDuplicateKeyUpdate(t){return new e({...this.#e,queryNode:N.cloneWith(this.#e.queryNode,{onDuplicateKey:Pt.create(Nt(t))})})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z())})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}clearReturning(){return new e({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}$castTo(){return new e(this.#e)}$narrowType(){return new e(this.#e)}$assertType(){return new e(this.#e)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,r=e.query;return r.returning&&n.supportsReturning||r.output&&n.supportsOutput?t.rows:[new Ft(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=It){let t=await this.executeTakeFirst();if(t===void 0)throw Lt(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let e of n)yield*e.rows}async explain(t,n){return await new e({...this.#e,queryNode:I.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}},Kt=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};const qt=l({is(e){return e.kind===`LimitNode`},create(e){return l({kind:`LimitNode`,limit:e})}});var Jt=class e{#e;constructor(e){this.#e=l(e)}where(...t){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}using(t){return new e({...this.#e,queryNode:pt.cloneWithUsing(this.#e.queryNode,wr(t))})}innerJoin(...e){return this.#t(`InnerJoin`,e)}leftJoin(...e){return this.#t(`LeftJoin`,e)}rightJoin(...e){return this.#t(`RightJoin`,e)}fullJoin(...e){return this.#t(`FullJoin`,e)}#t(t,n){return new e({...this.#e,queryNode:I.cloneWithJoin(this.#e.queryNode,jn(t,n))})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}clearReturning(){return new e({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new e({...this.#e,queryNode:pt.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...t){return new e({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,ke(t))})}clearOrderBy(){return new e({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}limit(t){return new e({...this.#e,queryNode:pt.cloneWithLimit(this.#e.queryNode,qt.create(k(t)))})}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}$castTo(){return new e(this.#e)}$narrowType(){return new e(this.#e)}$assertType(){return new e(this.#e)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,r=e.query;return r.returning&&n.supportsReturning||r.output&&n.supportsOutput?t.rows:[new Kt(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=It){let t=await this.executeTakeFirst();if(t===void 0)throw Lt(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let e of n)yield*e.rows}async explain(t,n){return await new e({...this.#e,queryNode:I.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}},Yt=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}},Xt=class e{#e;constructor(e){this.#e=l(e)}where(...t){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}from(t){return new e({...this.#e,queryNode:dt.cloneWithFromItems(this.#e.queryNode,wr(t))})}innerJoin(...e){return this.#t(`InnerJoin`,e)}leftJoin(...e){return this.#t(`LeftJoin`,e)}rightJoin(...e){return this.#t(`RightJoin`,e)}fullJoin(...e){return this.#t(`FullJoin`,e)}#t(t,n){return new e({...this.#e,queryNode:I.cloneWithJoin(this.#e.queryNode,jn(t,n))})}orderBy(...t){return new e({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,ke(t))})}clearOrderBy(){return new e({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}limit(t){return new e({...this.#e,queryNode:dt.cloneWithLimit(this.#e.queryNode,qt.create(k(t)))})}set(...t){return new e({...this.#e,queryNode:dt.cloneWithUpdates(this.#e.queryNode,Mt(...t))})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}clearReturning(){return new e({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}$castTo(){return new e(this.#e)}$narrowType(){return new e(this.#e)}$assertType(){return new e(this.#e)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,r=e.query;return r.returning&&n.supportsReturning||r.output&&n.supportsOutput?t.rows:[new Yt(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=It){let t=await this.executeTakeFirst();if(t===void 0)throw Lt(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let e of n)yield*e.rows}async explain(t,n){return await new e({...this.#e,queryNode:I.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}};const Zt=l({is(e){return e.kind===`CommonTableExpressionNameNode`},create(e,t){return l({kind:`CommonTableExpressionNameNode`,table:v.create(e),columns:t?l(t.map(C.create)):void 0})}}),Qt=l({is(e){return e.kind===`CommonTableExpressionNode`},create(e,t){return l({kind:`CommonTableExpressionNode`,name:e,expression:t})},cloneWith(e,t){return l({...e,...t})}});var $t=class e{#e;constructor(e){this.#e=l(e)}materialized(){return new e({...this.#e,node:Qt.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new e({...this.#e,node:Qt.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function en(e,t){let n=t(On()).toOperationNode();return s(e)?e(tn(n)).toOperationNode():Qt.create(nn(e),n)}function tn(e){return t=>new $t({node:Qt.create(nn(t),e)})}function nn(e){if(e.includes(`(`)){let t=e.split(/[\(\)]/),n=t[0],r=t[1].split(`,`).map(e=>e.trim());return Zt.create(n,r)}else return Zt.create(e)}const rn=l({is(e){return e.kind===`WithNode`},create(e,t){return l({kind:`WithNode`,expressions:l([e]),...t})},cloneWithExpression(e,t){return l({...e,expressions:l([...e.expressions,t])})}}),an=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.split(``);function on(e){let t=``;for(let n=0;n<e;++n)t+=sn();return t}function sn(){return an[~~(Math.random()*an.length)]}function V(){return new cn}var cn=class{#e;get queryId(){return this.#e===void 0&&(this.#e=on(8)),this.#e}};function H(e){return e}var ln=class{nodeStack=[];#e=l({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(e,t){if(!e)return e;this.nodeStack.push(e);let n=this.transformNodeImpl(e,t);return this.nodeStack.pop(),l(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&l(e.map(e=>this.transformNode(e,t)))}transformSelectQuery(e,t){return H({kind:`SelectQueryNode`,from:this.transformNode(e.from,t),selections:this.transformNodeList(e.selections,t),distinctOn:this.transformNodeList(e.distinctOn,t),joins:this.transformNodeList(e.joins,t),groupBy:this.transformNode(e.groupBy,t),orderBy:this.transformNode(e.orderBy,t),where:this.transformNode(e.where,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),limit:this.transformNode(e.limit,t),offset:this.transformNode(e.offset,t),with:this.transformNode(e.with,t),having:this.transformNode(e.having,t),explain:this.transformNode(e.explain,t),setOperations:this.transformNodeList(e.setOperations,t),fetch:this.transformNode(e.fetch,t),top:this.transformNode(e.top,t)})}transformSelection(e,t){return H({kind:`SelectionNode`,selection:this.transformNode(e.selection,t)})}transformColumn(e,t){return H({kind:`ColumnNode`,column:this.transformNode(e.column,t)})}transformAlias(e,t){return H({kind:`AliasNode`,node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)})}transformTable(e,t){return H({kind:`TableNode`,table:this.transformNode(e.table,t)})}transformFrom(e,t){return H({kind:`FromNode`,froms:this.transformNodeList(e.froms,t)})}transformReference(e,t){return H({kind:`ReferenceNode`,column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)})}transformAnd(e,t){return H({kind:`AndNode`,left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformOr(e,t){return H({kind:`OrNode`,left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)})}transformValueList(e,t){return H({kind:`ValueListNode`,values:this.transformNodeList(e.values,t)})}transformParens(e,t){return H({kind:`ParensNode`,node:this.transformNode(e.node,t)})}transformJoin(e,t){return H({kind:`JoinNode`,joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)})}transformRaw(e,t){return H({kind:`RawNode`,sqlFragments:l([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)})}transformWhere(e,t){return H({kind:`WhereNode`,where:this.transformNode(e.where,t)})}transformInsertQuery(e,t){return H({kind:`InsertQueryNode`,into:this.transformNode(e.into,t),columns:this.transformNodeList(e.columns,t),values:this.transformNode(e.values,t),returning:this.transformNode(e.returning,t),onConflict:this.transformNode(e.onConflict,t),onDuplicateKey:this.transformNode(e.onDuplicateKey,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformValues(e,t){return H({kind:`ValuesNode`,values:this.transformNodeList(e.values,t)})}transformDeleteQuery(e,t){return H({kind:`DeleteQueryNode`,from:this.transformNode(e.from,t),using:this.transformNode(e.using,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),orderBy:this.transformNode(e.orderBy,t),limit:this.transformNode(e.limit,t),explain:this.transformNode(e.explain,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)})}transformReturning(e,t){return H({kind:`ReturningNode`,selections:this.transformNodeList(e.selections,t)})}transformCreateTable(e,t){return H({kind:`CreateTableNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),temporary:e.temporary,ifNotExists:e.ifNotExists,onCommit:e.onCommit,frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),selectQuery:this.transformNode(e.selectQuery,t)})}transformColumnDefinition(e,t){return H({kind:`ColumnDefinitionNode`,column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),references:this.transformNode(e.references,t),primaryKey:e.primaryKey,autoIncrement:e.autoIncrement,unique:e.unique,notNull:e.notNull,unsigned:e.unsigned,defaultTo:this.transformNode(e.defaultTo,t),check:this.transformNode(e.check,t),generated:this.transformNode(e.generated,t),frontModifiers:this.transformNodeList(e.frontModifiers,t),endModifiers:this.transformNodeList(e.endModifiers,t),nullsNotDistinct:e.nullsNotDistinct,identity:e.identity,ifNotExists:e.ifNotExists})}transformAddColumn(e,t){return H({kind:`AddColumnNode`,column:this.transformNode(e.column,t)})}transformDropTable(e,t){return H({kind:`DropTableNode`,table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformOrderBy(e,t){return H({kind:`OrderByNode`,items:this.transformNodeList(e.items,t)})}transformOrderByItem(e,t){return H({kind:`OrderByItemNode`,orderBy:this.transformNode(e.orderBy,t),direction:this.transformNode(e.direction,t),collation:this.transformNode(e.collation,t),nulls:e.nulls})}transformGroupBy(e,t){return H({kind:`GroupByNode`,items:this.transformNodeList(e.items,t)})}transformGroupByItem(e,t){return H({kind:`GroupByItemNode`,groupBy:this.transformNode(e.groupBy,t)})}transformUpdateQuery(e,t){return H({kind:`UpdateQueryNode`,table:this.transformNode(e.table,t),from:this.transformNode(e.from,t),joins:this.transformNodeList(e.joins,t),where:this.transformNode(e.where,t),updates:this.transformNodeList(e.updates,t),returning:this.transformNode(e.returning,t),endModifiers:this.transformNodeList(e.endModifiers,t),with:this.transformNode(e.with,t),explain:this.transformNode(e.explain,t),limit:this.transformNode(e.limit,t),top:this.transformNode(e.top,t),output:this.transformNode(e.output,t),orderBy:this.transformNode(e.orderBy,t)})}transformColumnUpdate(e,t){return H({kind:`ColumnUpdateNode`,column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)})}transformLimit(e,t){return H({kind:`LimitNode`,limit:this.transformNode(e.limit,t)})}transformOffset(e,t){return H({kind:`OffsetNode`,offset:this.transformNode(e.offset,t)})}transformOnConflict(e,t){return H({kind:`OnConflictNode`,columns:this.transformNodeList(e.columns,t),constraint:this.transformNode(e.constraint,t),indexExpression:this.transformNode(e.indexExpression,t),indexWhere:this.transformNode(e.indexWhere,t),updates:this.transformNodeList(e.updates,t),updateWhere:this.transformNode(e.updateWhere,t),doNothing:e.doNothing})}transformOnDuplicateKey(e,t){return H({kind:`OnDuplicateKeyNode`,updates:this.transformNodeList(e.updates,t)})}transformCreateIndex(e,t){return H({kind:`CreateIndexNode`,name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists,where:this.transformNode(e.where,t),nullsNotDistinct:e.nullsNotDistinct})}transformList(e,t){return H({kind:`ListNode`,items:this.transformNodeList(e.items,t)})}transformDropIndex(e,t){return H({kind:`DropIndexNode`,name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade})}transformPrimaryKeyConstraint(e,t){return H({kind:`PrimaryKeyConstraintNode`,columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformUniqueConstraint(e,t){return H({kind:`UniqueConstraintNode`,columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),nullsNotDistinct:e.nullsNotDistinct,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformForeignKeyConstraint(e,t){return H({kind:`ForeignKeyConstraintNode`,columns:this.transformNodeList(e.columns,t),references:this.transformNode(e.references,t),name:this.transformNode(e.name,t),onDelete:e.onDelete,onUpdate:e.onUpdate,deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred})}transformSetOperation(e,t){return H({kind:`SetOperationNode`,operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all})}transformReferences(e,t){return H({kind:`ReferencesNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate})}transformCheckConstraint(e,t){return H({kind:`CheckConstraintNode`,expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)})}transformWith(e,t){return H({kind:`WithNode`,expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive})}transformCommonTableExpression(e,t){return H({kind:`CommonTableExpressionNode`,name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)})}transformCommonTableExpressionName(e,t){return H({kind:`CommonTableExpressionNameNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)})}transformHaving(e,t){return H({kind:`HavingNode`,having:this.transformNode(e.having,t)})}transformCreateSchema(e,t){return H({kind:`CreateSchemaNode`,schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists})}transformDropSchema(e,t){return H({kind:`DropSchemaNode`,schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade})}transformAlterTable(e,t){return H({kind:`AlterTableNode`,table:this.transformNode(e.table,t),renameTo:this.transformNode(e.renameTo,t),setSchema:this.transformNode(e.setSchema,t),columnAlterations:this.transformNodeList(e.columnAlterations,t),addConstraint:this.transformNode(e.addConstraint,t),dropConstraint:this.transformNode(e.dropConstraint,t),renameConstraint:this.transformNode(e.renameConstraint,t),addIndex:this.transformNode(e.addIndex,t),dropIndex:this.transformNode(e.dropIndex,t)})}transformDropColumn(e,t){return H({kind:`DropColumnNode`,column:this.transformNode(e.column,t)})}transformRenameColumn(e,t){return H({kind:`RenameColumnNode`,column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)})}transformAlterColumn(e,t){return H({kind:`AlterColumnNode`,column:this.transformNode(e.column,t),dataType:this.transformNode(e.dataType,t),dataTypeExpression:this.transformNode(e.dataTypeExpression,t),setDefault:this.transformNode(e.setDefault,t),dropDefault:e.dropDefault,setNotNull:e.setNotNull,dropNotNull:e.dropNotNull})}transformModifyColumn(e,t){return H({kind:`ModifyColumnNode`,column:this.transformNode(e.column,t)})}transformAddConstraint(e,t){return H({kind:`AddConstraintNode`,constraint:this.transformNode(e.constraint,t)})}transformDropConstraint(e,t){return H({kind:`DropConstraintNode`,constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier})}transformRenameConstraint(e,t){return H({kind:`RenameConstraintNode`,oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)})}transformCreateView(e,t){return H({kind:`CreateViewNode`,name:this.transformNode(e.name,t),temporary:e.temporary,orReplace:e.orReplace,ifNotExists:e.ifNotExists,materialized:e.materialized,columns:this.transformNodeList(e.columns,t),as:this.transformNode(e.as,t)})}transformRefreshMaterializedView(e,t){return H({kind:`RefreshMaterializedViewNode`,name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData})}transformDropView(e,t){return H({kind:`DropViewNode`,name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade})}transformGenerated(e,t){return H({kind:`GeneratedNode`,byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)})}transformDefaultValue(e,t){return H({kind:`DefaultValueNode`,defaultValue:this.transformNode(e.defaultValue,t)})}transformOn(e,t){return H({kind:`OnNode`,on:this.transformNode(e.on,t)})}transformSelectModifier(e,t){return H({kind:`SelectModifierNode`,modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)})}transformCreateType(e,t){return H({kind:`CreateTypeNode`,name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)})}transformDropType(e,t){return H({kind:`DropTypeNode`,name:this.transformNode(e.name,t),ifExists:e.ifExists})}transformExplain(e,t){return H({kind:`ExplainNode`,format:e.format,options:this.transformNode(e.options,t)})}transformSchemableIdentifier(e,t){return H({kind:`SchemableIdentifierNode`,schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)})}transformAggregateFunction(e,t){return H({kind:`AggregateFunctionNode`,func:e.func,aggregated:this.transformNodeList(e.aggregated,t),distinct:e.distinct,orderBy:this.transformNode(e.orderBy,t),withinGroup:this.transformNode(e.withinGroup,t),filter:this.transformNode(e.filter,t),over:this.transformNode(e.over,t)})}transformOver(e,t){return H({kind:`OverNode`,orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)})}transformPartitionBy(e,t){return H({kind:`PartitionByNode`,items:this.transformNodeList(e.items,t)})}transformPartitionByItem(e,t){return H({kind:`PartitionByItemNode`,partitionBy:this.transformNode(e.partitionBy,t)})}transformBinaryOperation(e,t){return H({kind:`BinaryOperationNode`,leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)})}transformUnaryOperation(e,t){return H({kind:`UnaryOperationNode`,operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)})}transformUsing(e,t){return H({kind:`UsingNode`,tables:this.transformNodeList(e.tables,t)})}transformFunction(e,t){return H({kind:`FunctionNode`,func:e.func,arguments:this.transformNodeList(e.arguments,t)})}transformCase(e,t){return H({kind:`CaseNode`,value:this.transformNode(e.value,t),when:this.transformNodeList(e.when,t),else:this.transformNode(e.else,t),isStatement:e.isStatement})}transformWhen(e,t){return H({kind:`WhenNode`,condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)})}transformJSONReference(e,t){return H({kind:`JSONReferenceNode`,reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)})}transformJSONPath(e,t){return H({kind:`JSONPathNode`,inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)})}transformJSONPathLeg(e,t){return H({kind:`JSONPathLegNode`,type:e.type,value:e.value})}transformJSONOperatorChain(e,t){return H({kind:`JSONOperatorChainNode`,operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)})}transformTuple(e,t){return H({kind:`TupleNode`,values:this.transformNodeList(e.values,t)})}transformMergeQuery(e,t){return H({kind:`MergeQueryNode`,into:this.transformNode(e.into,t),using:this.transformNode(e.using,t),whens:this.transformNodeList(e.whens,t),with:this.transformNode(e.with,t),top:this.transformNode(e.top,t),endModifiers:this.transformNodeList(e.endModifiers,t),output:this.transformNode(e.output,t),returning:this.transformNode(e.returning,t)})}transformMatched(e,t){return H({kind:`MatchedNode`,not:e.not,bySource:e.bySource})}transformAddIndex(e,t){return H({kind:`AddIndexNode`,name:this.transformNode(e.name,t),columns:this.transformNodeList(e.columns,t),unique:e.unique,using:this.transformNode(e.using,t),ifNotExists:e.ifNotExists})}transformCast(e,t){return H({kind:`CastNode`,expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)})}transformFetch(e,t){return H({kind:`FetchNode`,rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier})}transformTop(e,t){return H({kind:`TopNode`,expression:e.expression,modifiers:e.modifiers})}transformOutput(e,t){return H({kind:`OutputNode`,selections:this.transformNodeList(e.selections,t)})}transformDataType(e,t){return e}transformSelectAll(e,t){return e}transformIdentifier(e,t){return e}transformValue(e,t){return e}transformPrimitiveValueList(e,t){return e}transformOperator(e,t){return e}transformDefaultInsertValue(e,t){return e}transformOrAction(e,t){return e}transformCollate(e,t){return e}};const un=l({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}),dn={json_agg:!0,to_json:!0};var fn=class extends ln{#e;#t=new Set;#n=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!this.#i(e))return super.transformNodeImpl(e,t);let n=this.#o(e);for(let e of n)this.#n.add(e);let r=this.#a(e);for(let e of r)this.#t.add(e);let i=super.transformNodeImpl(e,t);for(let e of r)this.#t.delete(e);for(let e of n)this.#n.delete(e);return i}transformSchemableIdentifier(e,t){let n=super.transformSchemableIdentifier(e,t);return n.schema||!this.#t.has(e.identifier.name)?n:{...n,schema:p.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:v.createWithSchema(this.#e,n.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#r(e,t,`aggregated`)}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#r(e,t,`arguments`)}}#r(e,t,n){return dn[e.func]?e[n].map(e=>!v.is(e)||e.table.schema?this.transformNode(e,t):{...e,table:this.transformIdentifier(e.table.identifier,t)}):this.transformNodeList(e[n],t)}#i(e){return e.kind in un}#a(e){let t=new Set;if(`name`in e&&e.name&&g.is(e.name)&&this.#c(e.name,t),`from`in e&&e.from)for(let n of e.from.froms)this.#s(n,t);if(`into`in e&&e.into&&this.#s(e.into,t),`table`in e&&e.table&&this.#s(e.table,t),`joins`in e&&e.joins)for(let n of e.joins)this.#s(n.table,t);return`using`in e&&e.using&&(de.is(e.using)?this.#s(e.using.table,t):this.#s(e.using,t)),t}#o(e){let t=new Set;return`with`in e&&e.with&&this.#l(e.with,t),t}#s(e,t){if(v.is(e))this.#c(e.table,t);else if(_.is(e)&&v.is(e.node))this.#c(e.node.table,t);else if(ut.is(e))for(let n of e.items)this.#s(n,t)}#c(e,t){let n=e.identifier.name;!this.#t.has(n)&&!this.#n.has(n)&&t.add(n)}#l(e,t){for(let n of e.expressions){let e=n.name.table.table.identifier.name;this.#n.has(e)||t.add(e)}}},pn=class{#e;constructor(e){this.#e=new fn(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};const mn=l({is(e){return e.kind===`MatchedNode`},create(e,t=!1){return l({kind:`MatchedNode`,not:e,bySource:t})}});function hn(e,t,n){return gt.create($e([mn.create(!e.isMatched,e.bySource),...t&&t.length>0?[t.length===3&&n?M(t[0],t[1],t[2]):j(t)]:[]],`and`,!1))}function gn(e){return t(e)?T.create([e],[]):y(e)?e.toOperationNode():e}var _n=class{#e;#t;#n;constructor(){this.#e=new Promise((e,t)=>{this.#n=t,this.#t=e})}get promise(){return this.#e}resolve=e=>{this.#t&&this.#t(e)};reject=e=>{this.#n&&this.#n(e)}};async function vn(e){let t=new _n,n=new _n;return e.provideConnection(async e=>(t.resolve(e),await n.promise)).catch(e=>t.reject(e)),l({connection:await t.promise,release:n.resolve})}const yn=l([]);var bn=class{#e;constructor(e=yn){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let n of this.#e){let r=n.transformQuery({node:e,queryId:t});if(r.kind===e.kind)e=r;else throw Error([`KyselyPlugin.transformQuery must return a node`,`of the same kind that was given to it.`,`The plugin was given a ${e.kind}`,`but it returned a ${r.kind}`].join(` `))}return e}async executeQuery(e){return await this.provideConnection(async t=>{let n=await t.executeQuery(e);return`numUpdatedOrDeletedRows`in n&&De("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#t(n,e.queryId)})}async*stream(e,t){let{connection:n,release:r}=await vn(this);try{for await(let r of n.streamQuery(e,t))yield await this.#t(r,e.queryId)}finally{r()}}async#t(e,t){for(let n of this.#e)e=await n.transformResult({result:e,queryId:t});return e}};const xn=new class e extends bn{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(t){return new e([...this.plugins,t])}withPlugins(t){return new e([...this.plugins,...t])}withPluginAtFront(t){return new e([t,...this.plugins])}withoutPlugins(){return new e([])}};var Sn=class{numChangedRows;constructor(e){this.numChangedRows=e}},Cn=class e{#e;constructor(e){this.#e=l(e)}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}using(...e){return new wn({...this.#e,queryNode:F.cloneWithUsing(this.#e.queryNode,jn(`Using`,e))})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}},wn=class e{#e;constructor(e){this.#e=l(e)}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,t,n){return this.#t([e,t,n],!0)}#t(e,t){return new Tn({...this.#e,queryNode:F.cloneWithWhen(this.#e.queryNode,hn({isMatched:!0},e,t))})}whenNotMatched(){return this.#n([])}whenNotMatchedAnd(...e){return this.#n(e)}whenNotMatchedAndRef(e,t,n){return this.#n([e,t,n],!0)}whenNotMatchedBySource(){return this.#n([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#n(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,n){return this.#n([e,t,n],!0,!0)}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}#n(e,t=!1,n=!1){let r={...this.#e,queryNode:F.cloneWithWhen(this.#e.queryNode,hn({isMatched:!1,bySource:n},e,t))};return new(n?Tn:En)(r)}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,r=e.query;return r.returning&&n.supportsReturning||r.output&&n.supportsOutput?t.rows:[new Sn(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=It){let t=await this.executeTakeFirst();if(t===void 0)throw Lt(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}},Tn=class{#e;constructor(e){this.#e=l(e)}thenDelete(){return new wn({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,gn(`delete`))})}thenDoNothing(){return new wn({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,gn(`do nothing`))})}thenUpdate(e){return new wn({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,gn(e(new Xt({queryId:this.#e.queryId,executor:xn,queryNode:dt.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},En=class{#e;constructor(e){this.#e=l(e)}thenDoNothing(){return new wn({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,gn(`do nothing`))})}thenInsertValues(e){let[t,n]=Dt(e);return new wn({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,gn(N.cloneWith(N.createWithoutInto(),{columns:t,values:n})))})}},Dn=class e{#e;constructor(e){this.#e=l(e)}selectFrom(e){return qn({queryId:V(),executor:this.#e.executor,queryNode:L.createFrom(wr(e),this.#e.withNode)})}selectNoFrom(e){return qn({queryId:V(),executor:this.#e.executor,queryNode:L.cloneWithSelections(L.create(this.#e.withNode),R(e))})}insertInto(e){return new Gt({queryId:V(),executor:this.#e.executor,queryNode:N.create(K(e),this.#e.withNode)})}replaceInto(e){return new Gt({queryId:V(),executor:this.#e.executor,queryNode:N.create(K(e),this.#e.withNode,!0)})}deleteFrom(e){return new Jt({queryId:V(),executor:this.#e.executor,queryNode:pt.create(wr(e),this.#e.withNode)})}updateTable(e){return new Xt({queryId:V(),executor:this.#e.executor,queryNode:dt.create(wr(e),this.#e.withNode)})}mergeInto(e){return new Cn({queryId:V(),executor:this.#e.executor,queryNode:F.create(Er(e),this.#e.withNode)})}with(t,n){let r=en(t,n);return new e({...this.#e,withNode:this.#e.withNode?rn.cloneWithExpression(this.#e.withNode,r):rn.create(r)})}withRecursive(t,n){let r=en(t,n);return new e({...this.#e,withNode:this.#e.withNode?rn.cloneWithExpression(this.#e.withNode,r):rn.create(r,{recursive:!0})})}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new pn(t))})}};function On(){return new Dn({executor:xn})}function kn(e,t){return new vt({joinNode:de.create(e,Tr(t))})}function An(){return new xt({overNode:ot.create()})}function jn(e,t){if(t.length===3)return Nn(e,t[0],t[1],t[2]);if(t.length===2)return Mn(e,t[0],t[1]);if(t.length===1)return Pn(e,t[0]);throw Error(`not implemented`)}function Mn(e,t,n){return n(kn(e,t)).toOperationNode()}function Nn(e,t,n,r){return de.createWithOn(e,Tr(t),M(n,`=`,r))}function Pn(e,t){return de.create(e,Tr(t))}const Fn=l({is(e){return e.kind===`OffsetNode`},create(e){return l({kind:`OffsetNode`,offset:e})}}),In=l({is(e){return e.kind===`GroupByItemNode`},create(e){return l({kind:`GroupByItemNode`,groupBy:e})}});function Ln(e){return e=s(e)?e(_r()):e,Le(e).map(In.create)}const Rn=l({is(e){return e.kind===`SetOperationNode`},create(e,t,n){return l({kind:`SetOperationNode`,operator:e,expression:t,all:n})}});function zn(e,t,n){return s(t)&&(t=t(gr())),u(t)||(t=[t]),t.map(t=>Rn.create(e,vr(t),n))}var U=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Bn(this,e)}or(...e){return new Vn(le.create(this.#e,j(e)))}and(...e){return new Hn(x.create(this.#e,j(e)))}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},Bn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return _.create(this.#e.toOperationNode(),y(this.#t)?this.#t.toOperationNode():p.create(this.#t))}},Vn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Bn(this,e)}or(...t){return new e(le.create(this.#e,j(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return A.create(this.#e)}},Hn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Bn(this,e)}and(...t){return new e(x.create(this.#e,j(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return A.create(this.#e)}};const Un={is(e){return e.kind===`FetchNode`},create(e,t){return{kind:`FetchNode`,rowCount:O.create(e),modifier:t}}};function Wn(e,t){if(!n(e)&&!o(e))throw Error(`Invalid fetch row count: ${e}`);if(!Gn(t))throw Error(`Invalid fetch modifier: ${t}`);return Un.create(e,t)}function Gn(e){return e===`only`||e===`with ties`}var Kn=class e{#e;constructor(e){this.#e=l(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...t){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,M(t,n,r))})}having(...t){return new e({...this.#e,queryNode:L.cloneWithHaving(this.#e.queryNode,j(t))})}havingRef(t,n,r){return new e({...this.#e,queryNode:L.cloneWithHaving(this.#e.queryNode,M(t,n,r))})}select(t){return new e({...this.#e,queryNode:L.cloneWithSelections(this.#e.queryNode,R(t))})}distinctOn(t){return new e({...this.#e,queryNode:L.cloneWithDistinctOn(this.#e.queryNode,Le(t))})}modifyFront(t){return new e({...this.#e,queryNode:L.cloneWithFrontModifier(this.#e.queryNode,b.createWithExpression(t.toOperationNode()))})}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.createWithExpression(t.toOperationNode()))})}distinct(){return new e({...this.#e,queryNode:L.cloneWithFrontModifier(this.#e.queryNode,b.create(`Distinct`))})}forUpdate(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`ForUpdate`,t?te(t).map(K):void 0))})}forShare(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`ForShare`,t?te(t).map(K):void 0))})}forKeyShare(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`ForKeyShare`,t?te(t).map(K):void 0))})}forNoKeyUpdate(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`ForNoKeyUpdate`,t?te(t).map(K):void 0))})}skipLocked(){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`SkipLocked`))})}noWait(){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,b.create(`NoWait`))})}selectAll(t){return new e({...this.#e,queryNode:L.cloneWithSelections(this.#e.queryNode,z(t))})}innerJoin(...e){return this.#t(`InnerJoin`,e)}leftJoin(...e){return this.#t(`LeftJoin`,e)}rightJoin(...e){return this.#t(`RightJoin`,e)}fullJoin(...e){return this.#t(`FullJoin`,e)}crossJoin(...e){return this.#t(`CrossJoin`,e)}innerJoinLateral(...e){return this.#t(`LateralInnerJoin`,e)}leftJoinLateral(...e){return this.#t(`LateralLeftJoin`,e)}crossJoinLateral(...e){return this.#t(`LateralCrossJoin`,e)}crossApply(...e){return this.#t(`CrossApply`,e)}outerApply(...e){return this.#t(`OuterApply`,e)}#t(t,n){return new e({...this.#e,queryNode:I.cloneWithJoin(this.#e.queryNode,jn(t,n))})}orderBy(...t){return new e({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,ke(t))})}groupBy(t){return new e({...this.#e,queryNode:L.cloneWithGroupByItems(this.#e.queryNode,Ln(t))})}limit(t){return new e({...this.#e,queryNode:L.cloneWithLimit(this.#e.queryNode,qt.create(k(t)))})}offset(t){return new e({...this.#e,queryNode:L.cloneWithOffset(this.#e.queryNode,Fn.create(k(t)))})}fetch(t,n=`only`){return new e({...this.#e,queryNode:L.cloneWithFetch(this.#e.queryNode,Wn(t,n))})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}union(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`union`,t,!1))})}unionAll(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`union`,t,!0))})}intersect(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`intersect`,t,!1))})}intersectAll(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`intersect`,t,!0))})}except(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`except`,t,!1))})}exceptAll(t){return new e({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,zn(`except`,t,!0))})}as(e){return new Jn(this,e)}clearSelect(){return new e({...this.#e,queryNode:L.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new e({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new e({...this.#e,queryNode:L.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new e({...this.#e,queryNode:L.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new e({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new e({...this.#e,queryNode:L.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}$castTo(){return new e(this.#e)}$narrowType(){return new e(this.#e)}$assertType(){return new e(this.#e)}$asTuple(){return new U(this.toOperationNode())}$asScalar(){return new U(this.toOperationNode())}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile();return(await this.#e.executor.executeQuery(e)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=It){let t=await this.executeTakeFirst();if(t===void 0)throw Lt(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let e of n)yield*e.rows}async explain(t,n){return await new e({...this.#e,queryNode:I.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}};function qn(e){return new Kn(e)}var Jn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return _.create(this.#e.toOperationNode(),p.create(this.#t))}};const W=l({is(e){return e.kind===`AggregateFunctionNode`},create(e,t=[]){return l({kind:`AggregateFunctionNode`,func:e,aggregated:t})},cloneWithDistinct(e){return l({...e,distinct:!0})},cloneWithOrderBy(e,t,n=!1){let r=n?`withinGroup`:`orderBy`;return l({...e,[r]:e[r]?it.cloneWithItems(e[r],t):it.create(t)})},cloneWithFilter(e,t){return l({...e,filter:e.filter?P.cloneWithOperation(e.filter,`And`,t):P.create(t)})},cloneWithOrFilter(e,t){return l({...e,filter:e.filter?P.cloneWithOperation(e.filter,`Or`,t):P.create(t)})},cloneWithOver(e,t){return l({...e,over:t})}}),Yn=l({is(e){return e.kind===`FunctionNode`},create(e,t){return l({kind:`FunctionNode`,func:e,arguments:t})}});var Xn=class e{#e;constructor(e){this.#e=l(e)}get expressionType(){}as(e){return new Zn(this,e)}distinct(){return new e({...this.#e,aggregateFunctionNode:W.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...t){return new e({...this.#e,aggregateFunctionNode:I.cloneWithOrderByItems(this.#e.aggregateFunctionNode,ke(t))})}clearOrderBy(){return new e({...this.#e,aggregateFunctionNode:I.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...t){return new e({...this.#e,aggregateFunctionNode:W.cloneWithOrderBy(this.#e.aggregateFunctionNode,ke(t),!0)})}filterWhere(...t){return new e({...this.#e,aggregateFunctionNode:W.cloneWithFilter(this.#e.aggregateFunctionNode,j(t))})}filterWhereRef(t,n,r){return new e({...this.#e,aggregateFunctionNode:W.cloneWithFilter(this.#e.aggregateFunctionNode,M(t,n,r))})}over(t){let n=An();return new e({...this.#e,aggregateFunctionNode:W.cloneWithOver(this.#e.aggregateFunctionNode,(t?t(n):n).toOperationNode())})}$call(e){return e(this)}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}},Zn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return _.create(this.#e.toOperationNode(),p.create(this.#t))}};function Qn(){let e=(e,t)=>new U(Yn.create(e,Le(t??[]))),n=(e,t)=>new Xn({aggregateFunctionNode:W.create(e,t?Le(t):void 0)});return Object.assign(e,{agg:n,avg(e){return n(`avg`,[e])},coalesce(...t){return e(`coalesce`,t)},count(e){return n(`count`,[e])},countAll(e){return new Xn({aggregateFunctionNode:W.create(`count`,z(e))})},max(e){return n(`max`,[e])},min(e){return n(`min`,[e])},sum(e){return n(`sum`,[e])},any(t){return e(`any`,[t])},jsonAgg(e){return new Xn({aggregateFunctionNode:W.create(`json_agg`,[t(e)?K(e):e.toOperationNode()])})},toJson(e){return new U(Yn.create(`to_json`,[t(e)?K(e):e.toOperationNode()]))}})}const $n=l({is(e){return e.kind===`UnaryOperationNode`},create(e,t){return l({kind:`UnaryOperationNode`,operator:e,operand:t})}});function er(e,t){return $n.create(S.create(e),E(t))}const G=l({is(e){return e.kind===`CaseNode`},create(e){return l({kind:`CaseNode`,value:e})},cloneWithWhen(e,t){return l({...e,when:l(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return l({...e,when:e.when?l([...e.when.slice(0,-1),gt.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return l({...e,...t})}});var tr=class{#e;constructor(e){this.#e=l(e)}when(...e){return new nr({...this.#e,node:G.cloneWithWhen(this.#e.node,gt.create(j(e)))})}},nr=class{#e;constructor(e){this.#e=l(e)}then(e){return new rr({...this.#e,node:G.cloneWithThen(this.#e.node,Je(e)?Ye(e):k(e))})}},rr=class{#e;constructor(e){this.#e=l(e)}when(...e){return new nr({...this.#e,node:G.cloneWithWhen(this.#e.node,gt.create(j(e)))})}else(e){return new ir({...this.#e,node:G.cloneWith(this.#e.node,{else:Je(e)?Ye(e):k(e)})})}end(){return new U(G.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new U(G.cloneWith(this.#e.node,{isStatement:!0}))}},ir=class{#e;constructor(e){this.#e=l(e)}end(){return new U(G.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new U(G.cloneWith(this.#e.node,{isStatement:!0}))}};const ar=l({is(e){return e.kind===`JSONPathLegNode`},create(e,t){return l({kind:`JSONPathLegNode`,type:e,value:t})}});var or=class{#e;constructor(e){this.#e=e}at(e){return this.#t(`ArrayLocation`,e)}key(e){return this.#t(`Member`,e)}#t(e,t){return Ne.is(this.#e)?new sr(Ne.cloneWithTraversal(this.#e,Fe.is(this.#e.traversal)?Fe.cloneWithLeg(this.#e.traversal,ar.create(e,t)):Pe.cloneWithValue(this.#e.traversal,O.createImmediate(t)))):new sr(Fe.cloneWithLeg(this.#e,ar.create(e,t)))}},sr=class e extends or{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new cr(this,e)}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},cr=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return _.create(this.#e.toOperationNode(),y(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};const lr=l({is(e){return e.kind===`TupleNode`},create(e){return l({kind:`TupleNode`,values:l(e)})}}),ur=`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`.split(`.`),dr=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],fr=l({is(e){return e.kind===`DataTypeNode`},create(e){return l({kind:`DataTypeNode`,dataType:e})}});function pr(e){return!!(ur.includes(e)||dr.some(t=>t.test(e)))}function mr(e){if(y(e))return e.toOperationNode();if(pr(e))return fr.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}const hr=l({is(e){return e.kind===`CastNode`},create(e,t){return l({kind:`CastNode`,expression:e,dataType:t})}});function gr(t=xn){function n(e,t,n){return new U(Ze(e,t,n))}function r(e,t){return new U(er(e,t))}let i=Object.assign(n,{fn:void 0,eb:void 0,selectFrom(e){return qn({queryId:V(),executor:t,queryNode:L.createFrom(wr(e))})},case(t){return new tr({node:G.create(e(t)?void 0:E(t))})},ref(t,n){return e(n)?new U(D(t)):new or(Re(t,n))},jsonPath(){return new or(Fe.create())},table(e){return new U(K(e))},val(e){return new U(k(e))},refTuple(...e){return new U(lr.create(e.map(E)))},tuple(...e){return new U(lr.create(e.map(k)))},lit(e){return new U(Ye(e))},unary:r,not(e){return r(`not`,e)},exists(e){return r(`exists`,e)},neg(e){return r(`-`,e)},between(e,t,n){return new U(fe.create(E(e),S.create(`between`),x.create(k(t),k(n))))},betweenSymmetric(e,t,n){return new U(fe.create(E(e),S.create(`between symmetric`),x.create(k(t),k(n))))},and(e){return u(e)?new U($e(e,`and`)):new U(Qe(e,`and`))},or(e){return u(e)?new U($e(e,`or`)):new U(Qe(e,`or`))},parens(...e){let t=j(e);return A.is(t)?new U(t):new U(A.create(t))},cast(e,t){return new U(hr.create(E(e),mr(t)))},withSchema(e){return gr(t.withPluginAtFront(new pn(e)))}});return i.fn=Qn(),i.eb=i,i}function _r(e){return gr()}function vr(e){if(y(e))return e.toOperationNode();if(s(e))return e(_r()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function yr(e){if(y(e))return e.toOperationNode();if(s(e))return e(_r()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function br(e){return se(e)||ce(e)||s(e)}var xr=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Sr(this.#e,e)}},Sr=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return _.create(K(this.#e),p.create(this.#t))}};function Cr(e){return c(e)&&y(e)&&t(e.table)&&t(e.alias)}function wr(e){return u(e)?e.map(e=>Tr(e)):[Tr(e)]}function Tr(e){return t(e)?Er(e):Cr(e)?e.toOperationNode():yr(e)}function Er(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(Dr);return _.create(K(n),p.create(r))}else return K(e)}function K(e){if(e.includes(`.`)){let[t,n]=e.split(`.`).map(Dr);return v.createWithSchema(t,n)}else return v.create(e)}function Dr(e){return e.trim()}const Or=l({is(e){return e.kind===`AddColumnNode`},create(e){return l({kind:`AddColumnNode`,column:e})}}),q=l({is(e){return e.kind===`ColumnDefinitionNode`},create(e,t){return l({kind:`ColumnDefinitionNode`,column:C.create(e),dataType:t})},cloneWithFrontModifier(e,t){return l({...e,frontModifiers:e.frontModifiers?l([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return l({...e,endModifiers:e.endModifiers?l([...e.endModifiers,t]):[t]})},cloneWith(e,t){return l({...e,...t})}}),kr=l({is(e){return e.kind===`DropColumnNode`},create(e){return l({kind:`DropColumnNode`,column:C.create(e)})}}),Ar=l({is(e){return e.kind===`RenameColumnNode`},create(e,t){return l({kind:`RenameColumnNode`,column:C.create(e),renameTo:C.create(t)})}}),jr=l({is(e){return e.kind===`CheckConstraintNode`},create(e,t){return l({kind:`CheckConstraintNode`,expression:e,name:t?p.create(t):void 0})}}),Mr=[`no action`,`restrict`,`cascade`,`set null`,`set default`],Nr=l({is(e){return e.kind===`ReferencesNode`},create(e,t){return l({kind:`ReferencesNode`,table:e,columns:l([...t])})},cloneWithOnDelete(e,t){return l({...e,onDelete:t})},cloneWithOnUpdate(e,t){return l({...e,onUpdate:t})}});function Pr(e){return y(e)?e.toOperationNode():O.createImmediate(e)}const Fr=l({is(e){return e.kind===`GeneratedNode`},create(e){return l({kind:`GeneratedNode`,...e})},createWithExpression(e){return l({kind:`GeneratedNode`,always:!0,expression:e})},cloneWith(e,t){return l({...e,...t})}}),Ir=l({is(e){return e.kind===`DefaultValueNode`},create(e){return l({kind:`DefaultValueNode`,defaultValue:e})}});function Lr(e){if(Mr.includes(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}var Rr=class e{#e;constructor(e){this.#e=e}autoIncrement(){return new e(q.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new e(q.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new e(q.cloneWith(this.#e,{primaryKey:!0}))}references(t){let n=D(t);if(!n.table||be.is(n.column))throw Error(`invalid call references('${t}'). The reference must have format table.column or schema.table.column`);return new e(q.cloneWith(this.#e,{references:Nr.create(n.table,[n.column])}))}onDelete(t){if(!this.#e.references)throw Error(`on delete constraint can only be added for foreign keys`);return new e(q.cloneWith(this.#e,{references:Nr.cloneWithOnDelete(this.#e.references,Lr(t))}))}onUpdate(t){if(!this.#e.references)throw Error(`on update constraint can only be added for foreign keys`);return new e(q.cloneWith(this.#e,{references:Nr.cloneWithOnUpdate(this.#e.references,Lr(t))}))}unique(){return new e(q.cloneWith(this.#e,{unique:!0}))}notNull(){return new e(q.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new e(q.cloneWith(this.#e,{unsigned:!0}))}defaultTo(t){return new e(q.cloneWith(this.#e,{defaultTo:Ir.create(Pr(t))}))}check(t){return new e(q.cloneWith(this.#e,{check:jr.create(t.toOperationNode())}))}generatedAlwaysAs(t){return new e(q.cloneWith(this.#e,{generated:Fr.createWithExpression(t.toOperationNode())}))}generatedAlwaysAsIdentity(){return new e(q.cloneWith(this.#e,{generated:Fr.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new e(q.cloneWith(this.#e,{generated:Fr.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error(`stored() can only be called after generatedAlwaysAs`);return new e(q.cloneWith(this.#e,{generated:Fr.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(t){return new e(q.cloneWithFrontModifier(this.#e,t.toOperationNode()))}nullsNotDistinct(){return new e(q.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new e(q.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(t){return new e(q.cloneWithEndModifier(this.#e,t.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};const zr=l({is(e){return e.kind===`ModifyColumnNode`},create(e){return l({kind:`ModifyColumnNode`,column:e})}}),J=l({is(e){return e.kind===`ForeignKeyConstraintNode`},create(e,t,n,r){return l({kind:`ForeignKeyConstraintNode`,columns:e,references:Nr.create(t,n),name:r?p.create(r):void 0})},cloneWith(e,t){return l({...e,...t})}});var Br=class e{#e;constructor(e){this.#e=e}onDelete(t){return new e(J.cloneWith(this.#e,{onDelete:Lr(t)}))}onUpdate(t){return new e(J.cloneWith(this.#e,{onUpdate:Lr(t)}))}deferrable(){return new e(J.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(J.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(J.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(J.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};const Vr=l({is(e){return e.kind===`AddConstraintNode`},create(e){return l({kind:`AddConstraintNode`,constraint:e})}}),Hr=l({is(e){return e.kind===`UniqueConstraintNode`},create(e,t,n){return l({kind:`UniqueConstraintNode`,columns:l(e.map(C.create)),name:t?p.create(t):void 0,nullsNotDistinct:n})},cloneWith(e,t){return l({...e,...t})}}),Ur=l({is(e){return e.kind===`DropConstraintNode`},create(e){return l({kind:`DropConstraintNode`,constraintName:p.create(e)})},cloneWith(e,t){return l({...e,...t})}}),Wr=l({is(e){return e.kind===`AlterColumnNode`},create(e,t,n){return l({kind:`AlterColumnNode`,column:C.create(e),[t]:n})}});var Gr=class{#e;constructor(e){this.#e=e}setDataType(e){return new Kr(Wr.create(this.#e,`dataType`,mr(e)))}setDefault(e){return new Kr(Wr.create(this.#e,`setDefault`,Pr(e)))}dropDefault(){return new Kr(Wr.create(this.#e,`dropDefault`,!0))}setNotNull(){return new Kr(Wr.create(this.#e,`setNotNull`,!0))}dropNotNull(){return new Kr(Wr.create(this.#e,`dropNotNull`,!0))}$call(e){return e(this)}},Kr=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}},qr=class{#e;constructor(e){this.#e=l(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},Jr=class e{#e;constructor(e){this.#e=l(e)}onDelete(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(t)})}onUpdate(t){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(t)})}deferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new e({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(f.cloneWithTableProps(this.#e.node,{addConstraint:Vr.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},Yr=class e{#e;constructor(e){this.#e=l(e)}ifExists(){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:Ur.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:Ur.cloneWith(this.#e.node.dropConstraint,{modifier:`cascade`})})})}restrict(){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:Ur.cloneWith(this.#e.node.dropConstraint,{modifier:`restrict`})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};const Xr=l({is(e){return e.kind===`PrimaryKeyConstraintNode`},create(e,t){return l({kind:`PrimaryKeyConstraintNode`,columns:l(e.map(C.create)),name:t?p.create(t):void 0})},cloneWith(e,t){return l({...e,...t})}}),Zr=l({is(e){return e.kind===`AddIndexNode`},create(e){return l({kind:`AddIndexNode`,name:p.create(e)})},cloneWith(e,t){return l({...e,...t})},cloneWithColumns(e,t){return l({...e,columns:[...e.columns||[],...t]})}});var Qr=class e{#e;constructor(e){this.#e=l(e)}unique(){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(t){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.cloneWithColumns(this.#e.node.addIndex,[Ve(t)])})})}columns(t){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.cloneWithColumns(this.#e.node.addIndex,t.map(Ve))})})}expression(t){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.cloneWithColumns(this.#e.node.addIndex,[t.toOperationNode()])})})}using(t){return new e({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.cloneWith(this.#e.node.addIndex,{using:T.createWithSql(t)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},$r=class e{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new e(Hr.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new e(Hr.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(Hr.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(Hr.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(Hr.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ei=class e{#e;constructor(e){this.#e=e}deferrable(){return new e(Xr.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(Xr.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(Xr.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(Xr.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ti=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};const ni=l({is(e){return e.kind===`RenameConstraintNode`},create(e,t){return l({kind:`RenameConstraintNode`,oldName:p.create(e),newName:p.create(t)})}});var ri=class{#e;constructor(e){this.#e=l(e)}renameTo(e){return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameTo:K(e)})})}setSchema(e){return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{setSchema:p.create(e)})})}alterColumn(e,t){let n=t(new Gr(e));return new ii({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e){return new ii({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,kr.create(e))})}renameColumn(e,t){return new ii({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ar.create(e,t))})}addColumn(e,t,n=d){let r=n(new Rr(q.create(e,mr(t))));return new ii({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Or.create(r.toOperationNode()))})}modifyColumn(e,t,n=d){let r=n(new Rr(q.create(e,mr(t))));return new ii({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,zr.create(r.toOperationNode()))})}addUniqueConstraint(e,t,n=d){let r=n(new $r(Hr.create(t,e)));return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:Vr.create(r.toOperationNode())})})}addCheckConstraint(e,t,n=d){let r=n(new ti(jr.create(t.toOperationNode(),e)));return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:Vr.create(r.toOperationNode())})})}addForeignKeyConstraint(e,t,n,r,i=d){let a=i(new Br(J.create(t.map(C.create),K(n),r.map(C.create),e)));return new Jr({...this.#e,constraintBuilder:a})}addPrimaryKeyConstraint(e,t,n=d){let r=n(new ei(Xr.create(t,e)));return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addConstraint:Vr.create(r.toOperationNode())})})}dropConstraint(e){return new Yr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropConstraint:Ur.create(e)})})}renameConstraint(e,t){return new Yr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{renameConstraint:ni.create(e,t)})})}addIndex(e){return new Qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{addIndex:Zr.create(e)})})}dropIndex(e){return new qr({...this.#e,node:f.cloneWithTableProps(this.#e.node,{dropIndex:ie.create(e)})})}$call(e){return e(this)}},ii=class e{#e;constructor(e){this.#e=l(e)}alterColumn(t,n){let r=n(new Gr(t));return new e({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(t){return new e({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,kr.create(t))})}renameColumn(t,n){return new e({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Ar.create(t,n))})}addColumn(t,n,r=d){let i=r(new Rr(q.create(t,mr(n))));return new e({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,Or.create(i.toOperationNode()))})}modifyColumn(t,n,r=d){let i=r(new Rr(q.create(t,mr(n))));return new e({...this.#e,node:f.cloneWithColumnAlteration(this.#e.node,zr.create(i.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},ai=class extends ln{transformPrimitiveValueList(e){return Ke.create(e.values.map(O.createImmediate))}transformValue(e){return O.createImmediate(e.value)}},oi=class e{#e;constructor(e){this.#e=l(e)}ifNotExists(){return new e({...this.#e,node:m.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new e({...this.#e,node:m.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new e({...this.#e,node:m.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(t){return new e({...this.#e,node:m.cloneWith(this.#e.node,{table:K(t)})})}column(t){return new e({...this.#e,node:m.cloneWithColumns(this.#e.node,[Ve(t)])})}columns(t){return new e({...this.#e,node:m.cloneWithColumns(this.#e.node,t.map(Ve))})}expression(t){return new e({...this.#e,node:m.cloneWithColumns(this.#e.node,[t.toOperationNode()])})}using(t){return new e({...this.#e,node:m.cloneWith(this.#e.node,{using:T.createWithSql(t)})})}where(...t){let n=new ai;return new e({...this.#e,node:I.cloneWithWhere(this.#e.node,n.transformNode(j(t),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},si=class e{#e;constructor(e){this.#e=l(e)}ifNotExists(){return new e({...this.#e,node:ne.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};function ci(e){if(re.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}var li=class e{#e;constructor(e){this.#e=l(e)}temporary(){return new e({...this.#e,node:h.cloneWith(this.#e.node,{temporary:!0})})}onCommit(t){return new e({...this.#e,node:h.cloneWith(this.#e.node,{onCommit:ci(t)})})}ifNotExists(){return new e({...this.#e,node:h.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(t,n,r=d){let i=r(new Rr(q.create(t,mr(n))));return new e({...this.#e,node:h.cloneWithColumn(this.#e.node,i.toOperationNode())})}addPrimaryKeyConstraint(t,n,r=d){let i=r(new ei(Xr.create(n,t)));return new e({...this.#e,node:h.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addUniqueConstraint(t,n,r=d){let i=r(new $r(Hr.create(n,t)));return new e({...this.#e,node:h.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addCheckConstraint(t,n,r=d){let i=r(new ti(jr.create(n.toOperationNode(),t)));return new e({...this.#e,node:h.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addForeignKeyConstraint(t,n,r,i,a=d){let o=a(new Br(J.create(n.map(C.create),K(r),i.map(C.create),t)));return new e({...this.#e,node:h.cloneWithConstraint(this.#e.node,o.toOperationNode())})}modifyFront(t){return new e({...this.#e,node:h.cloneWithFrontModifier(this.#e.node,t.toOperationNode())})}modifyEnd(t){return new e({...this.#e,node:h.cloneWithEndModifier(this.#e.node,t.toOperationNode())})}as(t){return new e({...this.#e,node:h.cloneWith(this.#e.node,{selectQuery:vr(t)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},ui=class e{#e;constructor(e){this.#e=l(e)}on(t){return new e({...this.#e,node:ie.cloneWith(this.#e.node,{table:K(t)})})}ifExists(){return new e({...this.#e,node:ie.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:ie.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},di=class e{#e;constructor(e){this.#e=l(e)}ifExists(){return new e({...this.#e,node:ae.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:ae.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},fi=class e{#e;constructor(e){this.#e=l(e)}ifExists(){return new e({...this.#e,node:oe.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:oe.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};const Y=l({is(e){return e.kind===`CreateViewNode`},create(e){return l({kind:`CreateViewNode`,name:g.create(e)})},cloneWith(e,t){return l({...e,...t})}});var pi=class{#e=new ai;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}},mi=class e{#e;constructor(e){this.#e=l(e)}temporary(){return new e({...this.#e,node:Y.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new e({...this.#e,node:Y.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new e({...this.#e,node:Y.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new e({...this.#e,node:Y.cloneWith(this.#e.node,{orReplace:!0})})}columns(t){return new e({...this.#e,node:Y.cloneWith(this.#e.node,{columns:t.map(Be)})})}as(t){let n=t.withPlugin(new pi).toOperationNode();return new e({...this.#e,node:Y.cloneWith(this.#e.node,{as:n})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};const hi=l({is(e){return e.kind===`DropViewNode`},create(e){return l({kind:`DropViewNode`,name:g.create(e)})},cloneWith(e,t){return l({...e,...t})}});var gi=class e{#e;constructor(e){this.#e=l(e)}materialized(){return new e({...this.#e,node:hi.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new e({...this.#e,node:hi.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:hi.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};const _i=l({is(e){return e.kind===`CreateTypeNode`},create(e){return l({kind:`CreateTypeNode`,name:e})},cloneWithEnum(e,t){return l({...e,enum:Ke.create(t.map(O.createImmediate))})}});var vi=class e{#e;constructor(e){this.#e=l(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(t){return new e({...this.#e,node:_i.cloneWithEnum(this.#e.node,t)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};const yi=l({is(e){return e.kind===`DropTypeNode`},create(e){return l({kind:`DropTypeNode`,name:e})},cloneWith(e,t){return l({...e,...t})}});var bi=class e{#e;constructor(e){this.#e=l(e)}ifExists(){return new e({...this.#e,node:yi.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};function xi(e){if(e.includes(`.`)){let t=e.split(`.`).map(Si);if(t.length===2)return g.createWithSchema(t[0],t[1]);throw Error(`invalid schemable identifier ${e}`)}else return g.create(e)}function Si(e){return e.trim()}const Ci=l({is(e){return e.kind===`RefreshMaterializedViewNode`},create(e){return l({kind:`RefreshMaterializedViewNode`,name:g.create(e)})},cloneWith(e,t){return l({...e,...t})}});var wi=class e{#e;constructor(e){this.#e=l(e)}concurrently(){return new e({...this.#e,node:Ci.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new e({...this.#e,node:Ci.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new e({...this.#e,node:Ci.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}},Ti=class e{#e;constructor(e){this.#e=e}createTable(e){return new li({queryId:V(),executor:this.#e,node:h.create(K(e))})}dropTable(e){return new fi({queryId:V(),executor:this.#e,node:oe.create(K(e))})}createIndex(e){return new oi({queryId:V(),executor:this.#e,node:m.create(e)})}dropIndex(e){return new ui({queryId:V(),executor:this.#e,node:ie.create(e)})}createSchema(e){return new si({queryId:V(),executor:this.#e,node:ne.create(e)})}dropSchema(e){return new di({queryId:V(),executor:this.#e,node:ae.create(e)})}alterTable(e){return new ri({queryId:V(),executor:this.#e,node:f.create(K(e))})}createView(e){return new mi({queryId:V(),executor:this.#e,node:Y.create(e)})}refreshMaterializedView(e){return new wi({queryId:V(),executor:this.#e,node:Ci.create(e)})}dropView(e){return new gi({queryId:V(),executor:this.#e,node:hi.create(e)})}createType(e){return new vi({queryId:V(),executor:this.#e,node:_i.create(xi(e))})}dropType(e){return new bi({queryId:V(),executor:this.#e,node:yi.create(xi(e))})}withPlugin(t){return new e(this.#e.withPlugin(t))}withoutPlugins(){return new e(this.#e.withoutPlugins())}withSchema(t){return new e(this.#e.withPluginAtFront(new pn(t)))}},Ei=class{ref(e){return new Se(e)}table(e){return new xr(e)}},Di=class{#e;constructor(e){this.#e=e}async provideConnection(e){let t=await this.#e.acquireConnection();try{return await e(t)}finally{await this.#e.releaseConnection(t)}}},Oi=class e extends bn{#e;#t;#n;constructor(e,t,n,r=[]){super(r),this.#e=e,this.#t=t,this.#n=n}get adapter(){return this.#t}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#n.provideConnection(e)}withPlugins(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,...t])}withPlugin(t){return new e(this.#e,this.#t,this.#n,[...this.plugins,t])}withPluginAtFront(t){return new e(this.#e,this.#t,this.#n,[t,...this.plugins])}withConnectionProvider(t){return new e(this.#e,this.#t,t,[...this.plugins])}withoutPlugins(){return new e(this.#e,this.#t,this.#n,[])}};function ki(){return typeof performance<`u`&&s(performance.now)?performance.now():Date.now()}var Ai=class{#e;#t;#n;#r;#i;#a=new WeakSet;constructor(e,t){this.#r=!1,this.#e=e,this.#t=t}async init(){if(this.#i)throw Error(`driver has already been destroyed`);this.#n||=this.#e.init().then(()=>{this.#r=!0}).catch(e=>(this.#n=void 0,Promise.reject(e))),await this.#n}async acquireConnection(){if(this.#i)throw Error(`driver has already been destroyed`);this.#r||await this.init();let e=await this.#e.acquireConnection();return this.#a.has(e)||(this.#o()&&this.#s(e),this.#a.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,t){return this.#e.beginTransaction(e,t)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,t,n){if(this.#e.savepoint)return this.#e.savepoint(e,t,n);throw Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,t,n);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,t,n);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){this.#n&&(await this.#n,this.#i||=this.#e.destroy().catch(e=>(this.#i=void 0,Promise.reject(e))),await this.#i)}#o(){return this.#t.isLevelEnabled(`query`)||this.#t.isLevelEnabled(`error`)}#s(e){let t=e.executeQuery,n=e.streamQuery,r=this;e.executeQuery=async n=>{let i,a=ki();try{return await t.call(e,n)}catch(e){throw i=e,await r.#c(e,n,a),e}finally{i||await r.#l(n,a)}},e.streamQuery=async function*(t,i){let a,o=ki();try{for await(let r of n.call(e,t,i))yield r}catch(e){throw a=e,await r.#c(e,t,o),e}finally{a||await r.#l(t,o,!0)}}}async#c(e,t,n){await this.#t.error(()=>({level:`error`,error:e,query:t,queryDurationMillis:this.#u(n)}))}async#l(e,t,n=!1){await this.#t.query(()=>({level:`query`,isStream:n,query:e,queryDurationMillis:this.#u(t)}))}#u(e){return ki()-e}};const ji=()=>{};var Mi=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(ji);return this.#t=this.#n(e).finally(()=>{this.#t=void 0}),this.#t}async#n(e){return await e(this.#e)}};const Ni=[`read only`,`read write`],Pi=[`read uncommitted`,`read committed`,`repeatable read`,`serializable`,`snapshot`];function Fi(e){if(e.accessMode&&!Ni.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!Pi.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}l([`query`,`error`]);var Ii=class{#e;#t;constructor(e){s(e)?(this.#t=e,this.#e=l({query:!0,error:!0})):(this.#t=Li,this.#e=l({query:e.includes(`query`),error:e.includes(`error`)}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function Li(e){if(e.level===`query`){let t=`kysely:query:${e.isStream?`stream:`:``}`;console.log(`${t} ${e.query.sql}`),console.log(`${t} duration: ${e.queryDurationMillis.toFixed(1)}ms`)}else e.level===`error`&&(e.error instanceof Error?console.error(`kysely:error: ${e.error.stack??e.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:e.error,query:e.query.sql,queryDurationMillis:e.queryDurationMillis})}`))}function Ri(e){return c(e)&&s(e.compile)}Symbol.asyncDispose??=Symbol(`Symbol.asyncDispose`);var zi=class t extends Dn{#e;constructor(e){let t,n;if(Vi(e))t={executor:e.executor},n={...e};else{let r=e.dialect,i=r.createDriver(),a=r.createQueryCompiler(),o=r.createAdapter(),ee=new Ai(i,new Ii(e.log??[])),s=new Oi(a,o,new Di(ee),e.plugins??[]);t={executor:s},n={config:e,executor:s,dialect:r,driver:ee}}super(t),this.#e=l(n)}get schema(){return new Ti(this.#e.executor)}get dynamic(){return new Ei}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(t){return new tr({node:G.create(e(t)?void 0:vr(t))})}get fn(){return Qn()}transaction(){return new Ui({...this.#e})}startTransaction(){return new Wi({...this.#e})}connection(){return new Hi({...this.#e})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new pn(e))})}withTables(){return new t({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,t){t!==void 0&&De("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let n=Ri(e)?e.compile():e;return this.getExecutor().executeQuery(n)}async[Symbol.asyncDispose](){await this.destroy()}},Bi=class e extends zi{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw Error(`calling the transaction method for a Transaction is not supported`)}connection(){throw Error(`calling the connection method for a Transaction is not supported`)}async destroy(){throw Error(`calling the destroy method for a Transaction is not supported`)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new pn(t))})}withTables(){return new e({...this.#e})}};function Vi(e){return c(e)&&c(e.config)&&c(e.driver)&&c(e.executor)&&c(e.dialect)}var Hi=class{#e;constructor(e){this.#e=l(e)}async execute(e){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new Mi(t));return await e(new zi({...this.#e,executor:n}))})}},Ui=class e{#e;constructor(e){this.#e=l(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(e){let{isolationLevel:t,accessMode:n,...r}=this.#e,i={isolationLevel:t,accessMode:n};return Fi(i),this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new Mi(t)),a=new Bi({...r,executor:n}),o=!1;try{await this.#e.driver.beginTransaction(t,i),o=!0;let n=await e(a);return await this.#e.driver.commitTransaction(t),n}catch(e){throw o&&await this.#e.driver.rollbackTransaction(t),e}})}},Wi=class e{#e;constructor(e){this.#e=l(e)}setAccessMode(t){return new e({...this.#e,accessMode:t})}setIsolationLevel(t){return new e({...this.#e,isolationLevel:t})}async execute(){let{isolationLevel:e,accessMode:t,...n}=this.#e,r={isolationLevel:e,accessMode:t};Fi(r);let i=await vn(this.#e.executor);return await this.#e.driver.beginTransaction(i.connection,r),new Gi({...n,connection:i,executor:this.#e.executor.withConnectionProvider(new Mi(i.connection))})}},Gi=class e extends Bi{#e;#t;#n;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Ji(e.executor,t)};let{connection:n,...r}=e;super(r),this.#e=l(e),this.#n=t;let i=V();this.#t=t=>e.executor.compileQuery(t,i)}get isCommitted(){return this.#n.isCommitted}get isRolledBack(){return this.#n.isRolledBack}commit(){return qi(this.#n),new Ki(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#n.isCommitted=!0,this.#e.connection.release()})}rollback(){return qi(this.#n),new Ki(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#n.isRolledBack=!0,this.#e.connection.release()})}savepoint(t){return qi(this.#n),new Ki(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}rollbackToSavepoint(t){return qi(this.#n),new Ki(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}releaseSavepoint(t){return qi(this.#n),new Ki(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new pn(t))})}withTables(){return new e({...this.#e})}},Ki=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function qi(e){if(e.isCommitted)throw Error(`Transaction is already committed`);if(e.isRolledBack)throw Error(`Transaction is already rolled back`)}var Ji=class e{#e;#t;constructor(t,n){t instanceof e?this.#e=t.#e:this.#e=t,this.#t=n}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,t){return this.#e.transformQuery(e,t)}compileQuery(e,t){return this.#e.compileQuery(e,t)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e){return qi(this.#t),this.#e.executeQuery(e)}stream(e,t){return qi(this.#t),this.#e.stream(e,t)}withConnectionProvider(t){return new e(this.#e.withConnectionProvider(t),this.#t)}withPlugin(t){return new e(this.#e.withPlugin(t),this.#t)}withPlugins(t){return new e(this.#e.withPlugins(t),this.#t)}withPluginAtFront(t){return new e(this.#e.withPluginAtFront(t),this.#t)}withoutPlugins(){return new e(this.#e.withoutPlugins(),this.#t)}},Yi=class e{#e;constructor(e){this.#e=l(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Xi(this,e)}$castTo(){return new e({...this.#e})}$notNull(){return new e(this.#e)}withPlugin(t){return new e({...this.#e,plugins:this.#e.plugins===void 0?l([t]):l([...this.#e.plugins,t])})}toOperationNode(){return this.#n(this.#t())}compile(e){return this.#r(this.#t(e))}async execute(e){let t=this.#t(e);return t.executeQuery(this.#r(t))}#t(e){let t=e===void 0?xn:e.getExecutor();return this.#e.plugins===void 0?t:t.withPlugins(this.#e.plugins)}#n(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#r(e){return e.compileQuery(this.#n(e),this.#e.queryId)}};function X(e){return new Yi(e)}var Xi=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}get rawBuilder(){return this.#e}toOperationNode(){return _.create(this.#e.toOperationNode(),y(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};const Z=Object.assign((e,...t)=>X({queryId:V(),rawNode:T.create(e,t?.map(Zi)??[])}),{ref(e){return X({queryId:V(),rawNode:T.createWithChild(D(e))})},val(e){return X({queryId:V(),rawNode:T.createWithChild(k(e))})},value(e){return this.val(e)},table(e){return X({queryId:V(),rawNode:T.createWithChild(K(e))})},id(...e){let t=Array(e.length+1).fill(`.`);return t[0]=``,t[t.length-1]=``,X({queryId:V(),rawNode:T.create(t,e.map(p.create))})},lit(e){return X({queryId:V(),rawNode:T.createWithChild(O.createImmediate(e))})},literal(e){return this.lit(e)},raw(e){return X({queryId:V(),rawNode:T.createWithSql(e)})},join(e,t=Z`, `){let n=Array(Math.max(2*e.length-1,0)),r=t.toOperationNode();for(let t=0;t<e.length;++t)n[2*t]=Zi(e[t]),t!==e.length-1&&(n[2*t+1]=r);return X({queryId:V(),rawNode:T.createWithChildren(n)})}});function Zi(e){return y(e)?e.toOperationNode():k(e)}var Qi=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=l({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=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};const $i=/'/g;var ea=class extends Qi{#e=``;#t=[];get numParameters(){return this.#t.length}compileQuery(e,t){return this.#e=``,this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),l({query:e,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let t=this.parentNode!==void 0&&!A.is(this.parentNode)&&!N.is(this.parentNode)&&!h.is(this.parentNode)&&!Y.is(this.parentNode)&&!Rn.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(` `)),t&&this.append(`(`),e.with&&(this.visitNode(e.with),this.append(` `)),this.append(`select`),e.distinctOn&&(this.append(` `),this.compileDistinctOn(e.distinctOn)),e.frontModifiers?.length&&(this.append(` `),this.compileList(e.frontModifiers,` `)),e.top&&(this.append(` `),this.visitNode(e.top)),e.selections&&(this.append(` `),this.compileList(e.selections)),e.from&&(this.append(` `),this.visitNode(e.from)),e.joins&&(this.append(` `),this.compileList(e.joins,` `)),e.where&&(this.append(` `),this.visitNode(e.where)),e.groupBy&&(this.append(` `),this.visitNode(e.groupBy)),e.having&&(this.append(` `),this.visitNode(e.having)),e.setOperations&&(this.append(` `),this.compileList(e.setOperations,` `)),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),e.limit&&(this.append(` `),this.visitNode(e.limit)),e.offset&&(this.append(` `),this.visitNode(e.offset)),e.fetch&&(this.append(` `),this.visitNode(e.fetch)),e.endModifiers?.length&&(this.append(` `),this.compileList(this.sortSelectModifiers([...e.endModifiers]),` `)),t&&this.append(`)`)}visitFrom(e){this.append(`from `),this.compileList(e.froms)}visitSelection(e){this.visitNode(e.selection)}visitColumn(e){this.visitNode(e.column)}compileDistinctOn(e){this.append(`distinct on (`),this.compileList(e),this.append(`)`)}compileList(e,t=`, `){let n=e.length-1;for(let r=0;r<=n;r++)this.visitNode(e[r]),r<n&&this.append(t)}visitWhere(e){this.append(`where `),this.visitNode(e.where)}visitHaving(e){this.append(`having `),this.visitNode(e.having)}visitInsertQuery(e){let t=this.parentNode!==void 0&&!A.is(this.parentNode)&&!T.is(this.parentNode)&&!gt.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(` `)),t&&this.append(`(`),e.with&&(this.visitNode(e.with),this.append(` `)),this.append(e.replace?`replace`:`insert`),e.ignore&&(De("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(` ignore`)),e.orAction&&(this.append(` `),this.visitNode(e.orAction)),e.top&&(this.append(` `),this.visitNode(e.top)),e.into&&(this.append(` into `),this.visitNode(e.into)),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.output&&(this.append(` `),this.visitNode(e.output)),e.values&&(this.append(` `),this.visitNode(e.values)),e.defaultValues&&(this.append(` `),this.append(`default values`)),e.onConflict&&(this.append(` `),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(` `),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(` `),this.visitNode(e.returning)),t&&this.append(`)`),e.endModifiers?.length&&(this.append(` `),this.compileList(e.endModifiers,` `))}visitValues(e){this.append(`values `),this.compileList(e.values)}visitDeleteQuery(e){let t=this.parentNode!==void 0&&!A.is(this.parentNode)&&!T.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(` `)),t&&this.append(`(`),e.with&&(this.visitNode(e.with),this.append(` `)),this.append(`delete `),e.top&&(this.visitNode(e.top),this.append(` `)),this.visitNode(e.from),e.output&&(this.append(` `),this.visitNode(e.output)),e.using&&(this.append(` `),this.visitNode(e.using)),e.joins&&(this.append(` `),this.compileList(e.joins,` `)),e.where&&(this.append(` `),this.visitNode(e.where)),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),e.limit&&(this.append(` `),this.visitNode(e.limit)),e.returning&&(this.append(` `),this.visitNode(e.returning)),t&&this.append(`)`),e.endModifiers?.length&&(this.append(` `),this.compileList(e.endModifiers,` `))}visitReturning(e){this.append(`returning `),this.compileList(e.selections)}visitAlias(e){this.visitNode(e.node),this.append(` as `),this.visitNode(e.alias)}visitReference(e){e.table&&(this.visitNode(e.table),this.append(`.`)),this.visitNode(e.column)}visitSelectAll(e){this.append(`*`)}visitIdentifier(e){this.append(this.getLeftIdentifierWrapper()),this.compileUnwrappedIdentifier(e),this.append(this.getRightIdentifierWrapper())}compileUnwrappedIdentifier(e){if(!t(e.name))throw Error(`a non-string identifier was passed to compileUnwrappedIdentifier.`);this.append(this.sanitizeIdentifier(e.name))}visitAnd(e){this.visitNode(e.left),this.append(` and `),this.visitNode(e.right)}visitOr(e){this.visitNode(e.left),this.append(` or `),this.visitNode(e.right)}visitValue(e){e.immediate?this.appendImmediateValue(e.value):this.appendValue(e.value)}visitValueList(e){this.append(`(`),this.compileList(e.values),this.append(`)`)}visitTuple(e){this.append(`(`),this.compileList(e.values),this.append(`)`)}visitPrimitiveValueList(e){this.append(`(`);let{values:t}=e;for(let e=0;e<t.length;++e)this.appendValue(t[e]),e!==t.length-1&&this.append(`, `);this.append(`)`)}visitParens(e){this.append(`(`),this.visitNode(e.node),this.append(`)`)}visitJoin(e){this.append(ra[e.joinType]),this.append(` `),this.visitNode(e.table),e.on&&(this.append(` `),this.visitNode(e.on))}visitOn(e){this.append(`on `),this.visitNode(e.on)}visitRaw(e){let{sqlFragments:t,parameters:n}=e;for(let e=0;e<t.length;++e)this.append(t[e]),n.length>e&&this.visitNode(n[e])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){e.schema&&(this.visitNode(e.schema),this.append(`.`)),this.visitNode(e.identifier)}visitCreateTable(e){this.append(`create `),e.frontModifiers&&e.frontModifiers.length>0&&(this.compileList(e.frontModifiers,` `),this.append(` `)),e.temporary&&this.append(`temporary `),this.append(`table `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.table),e.selectQuery?(this.append(` as `),this.visitNode(e.selectQuery)):(this.append(` (`),this.compileList([...e.columns,...e.constraints??[]]),this.append(`)`),e.onCommit&&(this.append(` on commit `),this.append(e.onCommit)),e.endModifiers&&e.endModifiers.length>0&&(this.append(` `),this.compileList(e.endModifiers,` `)))}visitColumnDefinition(e){e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.column),this.append(` `),this.visitNode(e.dataType),e.unsigned&&this.append(` unsigned`),e.frontModifiers&&e.frontModifiers.length>0&&(this.append(` `),this.compileList(e.frontModifiers,` `)),e.generated&&(this.append(` `),this.visitNode(e.generated)),e.identity&&this.append(` identity`),e.defaultTo&&(this.append(` `),this.visitNode(e.defaultTo)),e.notNull&&this.append(` not null`),e.unique&&this.append(` unique`),e.nullsNotDistinct&&this.append(` nulls not distinct`),e.primaryKey&&this.append(` primary key`),e.autoIncrement&&(this.append(` `),this.append(this.getAutoIncrement())),e.references&&(this.append(` `),this.visitNode(e.references)),e.check&&(this.append(` `),this.visitNode(e.check)),e.endModifiers&&e.endModifiers.length>0&&(this.append(` `),this.compileList(e.endModifiers,` `))}getAutoIncrement(){return`auto_increment`}visitReferences(e){this.append(`references `),this.visitNode(e.table),this.append(` (`),this.compileList(e.columns),this.append(`)`),e.onDelete&&(this.append(` on delete `),this.append(e.onDelete)),e.onUpdate&&(this.append(` on update `),this.append(e.onUpdate))}visitDropTable(e){this.append(`drop table `),e.ifExists&&this.append(`if exists `),this.visitNode(e.table),e.cascade&&this.append(` cascade`)}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append(`order by `),this.compileList(e.items)}visitOrderByItem(e){this.visitNode(e.orderBy),e.collation&&(this.append(` `),this.visitNode(e.collation)),e.direction&&(this.append(` `),this.visitNode(e.direction)),e.nulls&&(this.append(` nulls `),this.append(e.nulls))}visitGroupBy(e){this.append(`group by `),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let t=this.parentNode!==void 0&&!A.is(this.parentNode)&&!T.is(this.parentNode)&&!gt.is(this.parentNode);if(this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(` `)),t&&this.append(`(`),e.with&&(this.visitNode(e.with),this.append(` `)),this.append(`update `),e.top&&(this.visitNode(e.top),this.append(` `)),e.table&&(this.visitNode(e.table),this.append(` `)),this.append(`set `),e.updates&&this.compileList(e.updates),e.output&&(this.append(` `),this.visitNode(e.output)),e.from&&(this.append(` `),this.visitNode(e.from)),e.joins){if(!e.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(e.joins,` `)}e.where&&(this.append(` `),this.visitNode(e.where)),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),e.limit&&(this.append(` `),this.visitNode(e.limit)),e.returning&&(this.append(` `),this.visitNode(e.returning)),t&&this.append(`)`),e.endModifiers?.length&&(this.append(` `),this.compileList(e.endModifiers,` `))}visitColumnUpdate(e){this.visitNode(e.column),this.append(` = `),this.visitNode(e.value)}visitLimit(e){this.append(`limit `),this.visitNode(e.limit)}visitOffset(e){this.append(`offset `),this.visitNode(e.offset)}visitOnConflict(e){this.append(`on conflict`),e.columns?(this.append(` (`),this.compileList(e.columns),this.append(`)`)):e.constraint?(this.append(` on constraint `),this.visitNode(e.constraint)):e.indexExpression&&(this.append(` (`),this.visitNode(e.indexExpression),this.append(`)`)),e.indexWhere&&(this.append(` `),this.visitNode(e.indexWhere)),e.doNothing===!0?this.append(` do nothing`):e.updates&&(this.append(` do update set `),this.compileList(e.updates),e.updateWhere&&(this.append(` `),this.visitNode(e.updateWhere)))}visitOnDuplicateKey(e){this.append(`on duplicate key update `),this.compileList(e.updates)}visitCreateIndex(e){this.append(`create `),e.unique&&this.append(`unique `),this.append(`index `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.name),e.table&&(this.append(` on `),this.visitNode(e.table)),e.using&&(this.append(` using `),this.visitNode(e.using)),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.nullsNotDistinct&&this.append(` nulls not distinct`),e.where&&(this.append(` `),this.visitNode(e.where))}visitDropIndex(e){this.append(`drop index `),e.ifExists&&this.append(`if exists `),this.visitNode(e.name),e.table&&(this.append(` on `),this.visitNode(e.table)),e.cascade&&this.append(` cascade`)}visitCreateSchema(e){this.append(`create schema `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.schema)}visitDropSchema(e){this.append(`drop schema `),e.ifExists&&this.append(`if exists `),this.visitNode(e.schema),e.cascade&&this.append(` cascade`)}visitPrimaryKeyConstraint(e){e.name&&(this.append(`constraint `),this.visitNode(e.name),this.append(` `)),this.append(`primary key (`),this.compileList(e.columns),this.append(`)`),this.buildDeferrable(e)}buildDeferrable(e){e.deferrable!==void 0&&(e.deferrable?this.append(` deferrable`):this.append(` not deferrable`)),e.initiallyDeferred!==void 0&&(e.initiallyDeferred?this.append(` initially deferred`):this.append(` initially immediate`))}visitUniqueConstraint(e){e.name&&(this.append(`constraint `),this.visitNode(e.name),this.append(` `)),this.append(`unique`),e.nullsNotDistinct&&this.append(` nulls not distinct`),this.append(` (`),this.compileList(e.columns),this.append(`)`),this.buildDeferrable(e)}visitCheckConstraint(e){e.name&&(this.append(`constraint `),this.visitNode(e.name),this.append(` `)),this.append(`check (`),this.visitNode(e.expression),this.append(`)`)}visitForeignKeyConstraint(e){e.name&&(this.append(`constraint `),this.visitNode(e.name),this.append(` `)),this.append(`foreign key (`),this.compileList(e.columns),this.append(`) `),this.visitNode(e.references),e.onDelete&&(this.append(` on delete `),this.append(e.onDelete)),e.onUpdate&&(this.append(` on update `),this.append(e.onUpdate)),this.buildDeferrable(e)}visitList(e){this.compileList(e.items)}visitWith(e){this.append(`with `),e.recursive&&this.append(`recursive `),this.compileList(e.expressions)}visitCommonTableExpression(e){this.visitNode(e.name),this.append(` as `),r(e.materialized)&&(e.materialized||this.append(`not `),this.append(`materialized `)),this.visitNode(e.expression)}visitCommonTableExpressionName(e){this.visitNode(e.table),e.columns&&(this.append(`(`),this.compileList(e.columns),this.append(`)`))}visitAlterTable(e){this.append(`alter table `),this.visitNode(e.table),this.append(` `),e.renameTo&&(this.append(`rename to `),this.visitNode(e.renameTo)),e.setSchema&&(this.append(`set schema `),this.visitNode(e.setSchema)),e.addConstraint&&this.visitNode(e.addConstraint),e.dropConstraint&&this.visitNode(e.dropConstraint),e.renameConstraint&&this.visitNode(e.renameConstraint),e.columnAlterations&&this.compileColumnAlterations(e.columnAlterations),e.addIndex&&this.visitNode(e.addIndex),e.dropIndex&&this.visitNode(e.dropIndex)}visitAddColumn(e){this.append(`add column `),this.visitNode(e.column)}visitRenameColumn(e){this.append(`rename column `),this.visitNode(e.column),this.append(` to `),this.visitNode(e.renameTo)}visitDropColumn(e){this.append(`drop column `),this.visitNode(e.column)}visitAlterColumn(e){this.append(`alter column `),this.visitNode(e.column),this.append(` `),e.dataType&&(this.announcesNewColumnDataType()&&this.append(`type `),this.visitNode(e.dataType),e.dataTypeExpression&&(this.append(`using `),this.visitNode(e.dataTypeExpression))),e.setDefault&&(this.append(`set default `),this.visitNode(e.setDefault)),e.dropDefault&&this.append(`drop default`),e.setNotNull&&this.append(`set not null`),e.dropNotNull&&this.append(`drop not null`)}visitModifyColumn(e){this.append(`modify column `),this.visitNode(e.column)}visitAddConstraint(e){this.append(`add `),this.visitNode(e.constraint)}visitDropConstraint(e){this.append(`drop constraint `),e.ifExists&&this.append(`if exists `),this.visitNode(e.constraintName),e.modifier===`cascade`?this.append(` cascade`):e.modifier===`restrict`&&this.append(` restrict`)}visitRenameConstraint(e){this.append(`rename constraint `),this.visitNode(e.oldName),this.append(` to `),this.visitNode(e.newName)}visitSetOperation(e){this.append(e.operator),this.append(` `),e.all&&this.append(`all `),this.visitNode(e.expression)}visitCreateView(e){this.append(`create `),e.orReplace&&this.append(`or replace `),e.materialized&&this.append(`materialized `),e.temporary&&this.append(`temporary `),this.append(`view `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.name),this.append(` `),e.columns&&(this.append(`(`),this.compileList(e.columns),this.append(`) `)),e.as&&(this.append(`as `),this.visitNode(e.as))}visitRefreshMaterializedView(e){this.append(`refresh materialized view `),e.concurrently&&this.append(`concurrently `),this.visitNode(e.name),e.withNoData?this.append(` with no data`):this.append(` with data`)}visitDropView(e){this.append(`drop `),e.materialized&&this.append(`materialized `),this.append(`view `),e.ifExists&&this.append(`if exists `),this.visitNode(e.name),e.cascade&&this.append(` cascade`)}visitGenerated(e){this.append(`generated `),e.always&&this.append(`always `),e.byDefault&&this.append(`by default `),this.append(`as `),e.identity&&this.append(`identity`),e.expression&&(this.append(`(`),this.visitNode(e.expression),this.append(`)`)),e.stored&&this.append(` stored`)}visitDefaultValue(e){this.append(`default `),this.visitNode(e.defaultValue)}visitSelectModifier(e){e.rawModifier?this.visitNode(e.rawModifier):this.append(ta[e.modifier]),e.of&&(this.append(` of `),this.compileList(e.of,`, `))}visitCreateType(e){this.append(`create type `),this.visitNode(e.name),e.enum&&(this.append(` as enum `),this.visitNode(e.enum))}visitDropType(e){this.append(`drop type `),e.ifExists&&this.append(`if exists `),this.visitNode(e.name)}visitExplain(e){this.append(`explain`),(e.options||e.format)&&(this.append(` `),this.append(this.getLeftExplainOptionsWrapper()),e.options&&(this.visitNode(e.options),e.format&&this.append(this.getExplainOptionsDelimiter())),e.format&&(this.append(`format`),this.append(this.getExplainOptionAssignment()),this.append(e.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(e){this.append(`default`)}visitAggregateFunction(e){this.append(e.func),this.append(`(`),e.distinct&&this.append(`distinct `),this.compileList(e.aggregated),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),this.append(`)`),e.withinGroup&&(this.append(` within group (`),this.visitNode(e.withinGroup),this.append(`)`)),e.filter&&(this.append(` filter(`),this.visitNode(e.filter),this.append(`)`)),e.over&&(this.append(` `),this.visitNode(e.over))}visitOver(e){this.append(`over(`),e.partitionBy&&(this.visitNode(e.partitionBy),e.orderBy&&this.append(` `)),e.orderBy&&this.visitNode(e.orderBy),this.append(`)`)}visitPartitionBy(e){this.append(`partition by `),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(` `),this.visitNode(e.operator),this.append(` `),this.visitNode(e.rightOperand)}visitUnaryOperation(e){this.visitNode(e.operator),this.isMinusOperator(e.operator)||this.append(` `),this.visitNode(e.operand)}isMinusOperator(e){return S.is(e)&&e.operator===`-`}visitUsing(e){this.append(`using `),this.compileList(e.tables)}visitFunction(e){this.append(e.func),this.append(`(`),this.compileList(e.arguments),this.append(`)`)}visitCase(e){this.append(`case`),e.value&&(this.append(` `),this.visitNode(e.value)),e.when&&(this.append(` `),this.compileList(e.when,` `)),e.else&&(this.append(` else `),this.visitNode(e.else)),this.append(` end`),e.isStatement&&this.append(` case`)}visitWhen(e){this.append(`when `),this.visitNode(e.condition),e.result&&(this.append(` then `),this.visitNode(e.result))}visitJSONReference(e){this.visitNode(e.reference),this.visitNode(e.traversal)}visitJSONPath(e){e.inOperator&&this.visitNode(e.inOperator),this.append(`'$`);for(let t of e.pathLegs)this.visitNode(t);this.append(`'`)}visitJSONPathLeg(e){let t=e.type===`ArrayLocation`;this.append(t?`[`:`.`),this.append(String(e.value)),t&&this.append(`]`)}visitJSONOperatorChain(e){for(let t=0,n=e.values.length;t<n;t++)t===n-1?this.visitNode(e.operator):this.append(`->`),this.visitNode(e.values[t])}visitMergeQuery(e){e.with&&(this.visitNode(e.with),this.append(` `)),this.append(`merge `),e.top&&(this.visitNode(e.top),this.append(` `)),this.append(`into `),this.visitNode(e.into),e.using&&(this.append(` `),this.visitNode(e.using)),e.whens&&(this.append(` `),this.compileList(e.whens,` `)),e.returning&&(this.append(` `),this.visitNode(e.returning)),e.output&&(this.append(` `),this.visitNode(e.output)),e.endModifiers?.length&&(this.append(` `),this.compileList(e.endModifiers,` `))}visitMatched(e){e.not&&this.append(`not `),this.append(`matched`),e.bySource&&this.append(` by source`)}visitAddIndex(e){this.append(`add `),e.unique&&this.append(`unique `),this.append(`index `),this.visitNode(e.name),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.using&&(this.append(` using `),this.visitNode(e.using))}visitCast(e){this.append(`cast(`),this.visitNode(e.expression),this.append(` as `),this.visitNode(e.dataType),this.append(`)`)}visitFetch(e){this.append(`fetch next `),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append(`output `),this.compileList(e.selections)}visitTop(e){this.append(`top(${e.expression})`),e.modifiers&&this.append(` ${e.modifiers}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append(`collate `),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return`"`}getRightIdentifierWrapper(){return`"`}getCurrentParameterPlaceholder(){return`$`+this.numParameters}getLeftExplainOptionsWrapper(){return`(`}getExplainOptionAssignment(){return` `}getExplainOptionsDelimiter(){return`, `}getRightExplainOptionsWrapper(){return`)`}sanitizeIdentifier(e){let t=this.getLeftIdentifierWrapper(),n=this.getRightIdentifierWrapper(),r=``;for(let i of e)r+=i,i===t?r+=t:i===n&&(r+=n);return r}sanitizeStringLiteral(e){return e.replace($i,`''`)}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(t(e))this.appendStringLiteral(e);else if(n(e)||r(e)||o(e))this.append(e.toString());else if(i(e))this.append(`null`);else if(a(e))this.appendImmediateValue(e.toISOString());else throw Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append(`'`),this.append(this.sanitizeStringLiteral(e)),this.append(`'`)}sortSelectModifiers(e){return e.sort((e,t)=>e.modifier&&t.modifier?na[e.modifier]-na[t.modifier]:1),l(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}};const ta=l({ForKeyShare:`for key share`,ForNoKeyUpdate:`for no key update`,ForUpdate:`for update`,ForShare:`for share`,NoWait:`nowait`,SkipLocked:`skip locked`,Distinct:`distinct`}),na=l({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),ra=l({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`}),Q=l({raw(e,t=[]){return l({sql:e,query:T.createWithSql(e),parameters:l(t),queryId:V()})}});var ia=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};function $(e,t){return T.createWithChildren([T.createWithSql(`${e} `),p.create(t)])}var aa=class{#e;#t=new sa;#n;#r;constructor(e){this.#e=l({...e})}async init(){this.#n=s(this.#e.database)?await this.#e.database():this.#e.database,this.#r=new oa(this.#n),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#r)}async acquireConnection(){return await this.#t.lock(),this.#r}async beginTransaction(e){await e.executeQuery(Q.raw(`begin`))}async commitTransaction(e){await e.executeQuery(Q.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(Q.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n($(`savepoint`,t),V()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n($(`rollback to`,t),V()))}async releaseSavepoint(e,t,n){await e.executeQuery(n($(`release`,t),V()))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#n?.close()}},oa=class{#e;constructor(e){this.#e=e}executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t);if(r.reader)return Promise.resolve({rows:r.all(n)});let{changes:i,lastInsertRowid:a}=r.run(n);return Promise.resolve({numAffectedRows:i==null?void 0:BigInt(i),insertId:a==null?void 0:BigInt(a),rows:[]})}async*streamQuery(e,t){let{sql:n,parameters:r,query:i}=e,a=this.#e.prepare(n);if(L.is(i)){let e=a.iterate(r);for(let t of e)yield{rows:[t]}}else throw Error(`Sqlite driver only supports streaming of select queries`)}},sa=class{#e;#t;async lock(){for(;this.#e;)await this.#e;this.#e=new Promise(e=>{this.#t=e})}unlock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}};const ca=/"/g;var la=class extends ea{visitOrAction(e){this.append(`or `),this.append(e.action)}getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return`"`}getRightIdentifierWrapper(){return`"`}getAutoIncrement(){return`autoincrement`}sanitizeIdentifier(e){return e.replace(ca,`""`)}visitDefaultInsertValue(e){this.append(`null`)}};const ua=`kysely_migration`,da=`kysely_migration_lock`;l({__noMigrations__:!0});var fa=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#n(e)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e,t){let n=e.selectFrom(`sqlite_master`).where(`type`,`in`,[`table`,`view`]).where(`name`,`not like`,`sqlite_%`).select([`name`,`sql`,`type`]).orderBy(`name`);return t.withInternalKyselyTables||(n=n.where(`name`,`!=`,ua).where(`name`,`!=`,da)),n}async#n(e){let t=await this.#t(this.#e,e).execute(),n=await this.#e.with(`table_list`,t=>this.#t(t,e)).selectFrom([`table_list as tl`,Z`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(),r={};for(let e of n)r[e.table]??=[],r[e.table].push(e);return t.map(({name:e,sql:t,type:n})=>{let i=t?.split(/[\(\),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.trimStart()?.split(/\s+/)?.[0]?.replace(/["`]/g,``),a=r[e]??[];if(!i){let e=a.filter(e=>e.pk>0);e.length===1&&e[0].type.toLowerCase()===`integer`&&(i=e[0].name)}return{name:e,isView:n===`view`,columns:a.map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===i,hasDefaultValue:e.dflt_value!=null,comment:void 0}))}})}},pa=class extends ia{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(e,t){}async releaseMigrationLock(e,t){}},ma=class{#e;constructor(e){this.#e=l({...e})}createDriver(){return new aa(this.#e)}createQueryCompiler(){return new la}createAdapter(){return new pa}createIntrospector(e){return new fa(e)}};const ha=/"/g;var ga=class extends ea{sanitizeIdentifier(e){return e.replace(ha,`""`)}},_a=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`pg_catalog.pg_namespace`).select(`nspname`).$castTo().execute()).map(e=>({name:e.nspname}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`pg_catalog.pg_attribute as a`).innerJoin(`pg_catalog.pg_class as c`,`a.attrelid`,`c.oid`).innerJoin(`pg_catalog.pg_namespace as ns`,`c.relnamespace`,`ns.oid`).innerJoin(`pg_catalog.pg_type as typ`,`a.atttypid`,`typ.oid`).innerJoin(`pg_catalog.pg_namespace as dtns`,`typ.typnamespace`,`dtns.oid`).select([`a.attname as column`,`a.attnotnull as not_null`,`a.atthasdef as has_default`,`c.relname as table`,`c.relkind as table_type`,`ns.nspname as schema`,`typ.typname as type`,`dtns.nspname as type_schema`,Z`col_description(a.attrelid, a.attnum)`.as(`column_description`),Z`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(Z`has_schema_privilege(ns.nspname, 'USAGE')`).where(`a.attnum`,`>=`,0).where(`a.attisdropped`,`!=`,!0).orderBy(`ns.nspname`).orderBy(`c.relname`).orderBy(`a.attnum`).$castTo();e.withInternalKyselyTables||(t=t.where(`c.relname`,`!=`,ua).where(`c.relname`,`!=`,da));let n=await t.execute();return this.#t(n)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){return e.reduce((e,t)=>{let n=e.find(e=>e.name===t.table&&e.schema===t.schema);return n||(n=l({name:t.table,isView:t.table_type===`v`,schema:t.schema,columns:[]}),e.push(n)),n.columns.push(l({name:t.column,dataType:t.type,dataTypeSchema:t.type_schema,isNullable:!t.not_null,isAutoIncrementing:t.auto_incrementing!==null,hasDefaultValue:t.has_default,comment:t.column_description??void 0})),e},[])}};const va=BigInt(`3853314791062309107`);var ya=class extends ia{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await Z`select pg_advisory_xact_lock(${Z.lit(va)})`.execute(e)}async releaseMigrationLock(e,t){}};function ba(e,t){if(xa(e)&&t.stack){let n=t.stack.split(`
2
+ `).slice(1).join(`
3
+ `);return e.stack+=`\n${n}`,e}return e}function xa(e){return c(e)&&t(e.stack)}const Sa=Symbol();var Ca=class{#e;#t=new WeakMap;#n;constructor(e){this.#e=l({...e})}async init(){this.#n=s(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#r(),t=this.#t.get(e);return t||(t=new Ta(e),this.#t.set(e,t),this.#e?.onCreateConnection&&await this.#e.onCreateConnection(t)),this.#e?.onReserveConnection&&await this.#e.onReserveConnection(t),t}async#r(){return new Promise((e,t)=>{this.#n.getConnection(async(n,r)=>{n?t(n):e(r)})})}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let n=[];t.isolationLevel&&n.push(`isolation level ${t.isolationLevel}`),t.accessMode&&n.push(t.accessMode);let r=`set transaction ${n.join(`, `)}`;await e.executeQuery(Q.raw(r))}await e.executeQuery(Q.raw(`begin`))}async commitTransaction(e){await e.executeQuery(Q.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(Q.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n($(`savepoint`,t),V()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n($(`rollback to`,t),V()))}async releaseSavepoint(e,t,n){await e.executeQuery(n($(`release savepoint`,t),V()))}async releaseConnection(e){e[Sa]()}async destroy(){return new Promise((e,t)=>{this.#n.end(n=>{n?t(n):e()})})}};function wa(e){return c(e)&&`insertId`in e&&`affectedRows`in e}var Ta=class{#e;constructor(e){this.#e=e}async executeQuery(e){try{let t=await this.#t(e);if(wa(t)){let{insertId:e,affectedRows:n,changedRows:r}=t;return{insertId:e!=null&&e.toString()!==`0`?BigInt(e):void 0,numAffectedRows:n==null?void 0:BigInt(n),numChangedRows:r==null?void 0:BigInt(r),rows:[]}}else if(Array.isArray(t))return{rows:t};return{rows:[]}}catch(e){throw ba(e,Error())}}#t(e){return new Promise((t,n)=>{this.#e.query(e.sql,e.parameters,(e,r)=>{e?n(e):t(r)})})}async*streamQuery(e,t){let n=this.#e.query(e.sql,e.parameters).stream({objectMode:!0});try{for await(let e of n)yield{rows:[e]}}catch(e){if(e&&typeof e==`object`&&`code`in e&&e.code===`ERR_STREAM_PREMATURE_CLOSE`)return;throw e}}[Sa](){this.#e.release()}};const Ea=/`/g;var Da=class extends ea{getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getExplainOptionAssignment(){return`=`}getExplainOptionsDelimiter(){return` `}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return"`"}getRightIdentifierWrapper(){return"`"}sanitizeIdentifier(e){return e.replace(Ea,"``")}visitCreateIndex(e){this.append(`create `),e.unique&&this.append(`unique `),this.append(`index `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.name),e.using&&(this.append(` using `),this.visitNode(e.using)),e.table&&(this.append(` on `),this.visitNode(e.table)),e.columns&&(this.append(` (`),this.compileList(e.columns),this.append(`)`)),e.where&&(this.append(` `),this.visitNode(e.where))}},Oa=class{#e;constructor(e){this.#e=e}async getSchemas(){return(await this.#e.selectFrom(`information_schema.schemata`).select(`schema_name`).$castTo().execute()).map(e=>({name:e.SCHEMA_NAME}))}async getTables(e={withInternalKyselyTables:!1}){let t=this.#e.selectFrom(`information_schema.columns as columns`).innerJoin(`information_schema.tables as tables`,e=>e.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`,`=`,Z`database()`).orderBy(`columns.TABLE_NAME`).orderBy(`columns.ORDINAL_POSITION`).$castTo();e.withInternalKyselyTables||(t=t.where(`columns.TABLE_NAME`,`!=`,ua).where(`columns.TABLE_NAME`,`!=`,da));let n=await t.execute();return this.#t(n)}async getMetadata(e){return{tables:await this.getTables(e)}}#t(e){return e.reduce((e,t)=>{let n=e.find(e=>e.name===t.TABLE_NAME);return n||(n=l({name:t.TABLE_NAME,isView:t.TABLE_TYPE===`VIEW`,schema:t.TABLE_SCHEMA,columns:[]}),e.push(n)),n.columns.push(l({name:t.COLUMN_NAME,dataType:t.DATA_TYPE,isNullable:t.IS_NULLABLE===`YES`,isAutoIncrementing:t.EXTRA.toLowerCase().includes(`auto_increment`),hasDefaultValue:t.COLUMN_DEFAULT!==null,comment:t.COLUMN_COMMENT===``?void 0:t.COLUMN_COMMENT})),e},[])}};const ka=`ea586330-2c93-47c8-908d-981d9d270f9d`;var Aa=class extends ia{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await Z`select get_lock(${Z.lit(ka)}, ${Z.lit(3600)})`.execute(e)}async releaseMigrationLock(e,t){await Z`select release_lock(${Z.lit(ka)})`.execute(e)}},ja=class{#e;constructor(e){this.#e=e}createDriver(){return new Ca(this.#e)}createQueryCompiler(){return new Da}createAdapter(){return new Aa}createIntrospector(e){return new Oa(e)}};const Ma=Symbol();var Na=class{#e;#t=new WeakMap;#n;constructor(e){this.#e=l({...e})}async init(){this.#n=s(this.#e.pool)?await this.#e.pool():this.#e.pool}async acquireConnection(){let e=await this.#n.connect(),t=this.#t.get(e);return t||(t=new Pa(e,{cursor:this.#e.cursor??null}),this.#t.set(e,t),this.#e.onCreateConnection&&await this.#e.onCreateConnection(t)),this.#e.onReserveConnection&&await this.#e.onReserveConnection(t),t}async beginTransaction(e,t){if(t.isolationLevel||t.accessMode){let n=`start transaction`;t.isolationLevel&&(n+=` isolation level ${t.isolationLevel}`),t.accessMode&&(n+=` ${t.accessMode}`),await e.executeQuery(Q.raw(n))}else await e.executeQuery(Q.raw(`begin`))}async commitTransaction(e){await e.executeQuery(Q.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(Q.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n($(`savepoint`,t),V()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n($(`rollback to`,t),V()))}async releaseSavepoint(e,t,n){await e.executeQuery(n($(`release`,t),V()))}async releaseConnection(e){e[Ma]()}async destroy(){if(this.#n){let e=this.#n;this.#n=void 0,await e.end()}}},Pa=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async executeQuery(e){try{let{command:t,rowCount:n,rows:r}=await this.#e.query(e.sql,[...e.parameters]);return{numAffectedRows:t===`INSERT`||t===`UPDATE`||t===`DELETE`||t===`MERGE`?BigInt(n):void 0,rows:r??[]}}catch(e){throw ba(e,Error())}}async*streamQuery(e,t){if(!this.#t.cursor)throw Error(`'cursor' is not present in your postgres dialect config. It's required to make streaming work in postgres.`);if(!Number.isInteger(t)||t<=0)throw Error(`chunkSize must be a positive integer`);let n=this.#e.query(new this.#t.cursor(e.sql,e.parameters.slice()));try{for(;;){let e=await n.read(t);if(e.length===0)break;yield{rows:e}}}finally{await n.close()}}[Ma](){this.#e.release()}},Fa=class{#e;constructor(e){this.#e=e}createDriver(){return new Na(this.#e)}createQueryCompiler(){return new ga}createAdapter(){return new ya}createIntrospector(e){return new _a(e)}},Ia=class extends ia{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e){await Z`exec sp_getapplock @DbPrincipal = ${Z.lit(`dbo`)}, @Resource = ${Z.lit(ua)}, @LockMode = ${Z.lit(`Exclusive`)}`.execute(e)}async releaseMigrationLock(){}};const La=Symbol(),Ra=Symbol(),za=Symbol();var Ba=class{#e;#t;constructor(e){this.#e=l({...e});let{tarn:t,tedious:n,validateConnections:r}=this.#e,{validateConnections:i,...a}=t.options;this.#t=new t.Pool({...a,create:async()=>await new Va(await n.connectionFactory(),n).connect(),destroy:async e=>{await e[Ra]()},validate:r===!1||i===!1?void 0:e=>e[za]()})}async init(){}async acquireConnection(){return await this.#t.acquire().promise}async beginTransaction(e,t){await e.beginTransaction(t)}async commitTransaction(e){await e.commitTransaction()}async rollbackTransaction(e){await e.rollbackTransaction()}async savepoint(e,t){await e.savepoint(t)}async rollbackToSavepoint(e,t){await e.rollbackTransaction(t)}async releaseConnection(e){(this.#e.resetConnectionsOnRelease||this.#e.tedious.resetConnectionOnRelease)&&await e[La](),this.#t.release(e)}async destroy(){await this.#t.destroy()}},Va=class{#e;#t;#n;constructor(e,t){this.#e=e,this.#t=!1,this.#n=t}async beginTransaction(e){let{isolationLevel:t}=e;await new Promise((e,n)=>this.#e.beginTransaction(t=>{t?n(t):e(void 0)},t?on(8):void 0,t?this.#r(t):void 0))}async commitTransaction(){await new Promise((e,t)=>this.#e.commitTransaction(n=>{n?t(n):e(void 0)}))}async connect(){let{promise:e,reject:t,resolve:n}=new _n;this.#e.connect(e=>{if(e)return t(e);n()}),this.#e.on(`error`,e=>{e instanceof Error&&`code`in e&&e.code===`ESOCKET`&&(this.#t=!0),console.error(e),t(e)});function r(){t(Error(`The connection ended without ever completing the connection`))}return this.#e.once(`end`,r),await e,this.#e.off(`end`,r),this}async executeQuery(e){try{let t=new _n,n=new Ha({compiledQuery:e,tedious:this.#n,onDone:t});this.#e.execSql(n.request);let{rowCount:r,rows:i}=await t.promise;return{numAffectedRows:r===void 0?void 0:BigInt(r),rows:i}}catch(e){throw ba(e,Error())}}async rollbackTransaction(e){await new Promise((t,n)=>this.#e.rollbackTransaction(e=>{e?n(e):t(void 0)},e))}async savepoint(e){await new Promise((t,n)=>this.#e.saveTransaction(e=>{e?n(e):t(void 0)},e))}async*streamQuery(e,t){if(!Number.isInteger(t)||t<=0)throw Error(`chunkSize must be a positive integer`);let n=new Ha({compiledQuery:e,streamChunkSize:t,tedious:this.#n});this.#e.execSql(n.request);try{for(;;){let e=await n.readChunk();if(e.length===0||(yield{rows:e},e.length<t))break}}finally{await this.#i(n)}}#r(e){let{ISOLATION_LEVEL:t}=this.#n,n={"read committed":t.READ_COMMITTED,"read uncommitted":t.READ_UNCOMMITTED,"repeatable read":t.REPEATABLE_READ,serializable:t.SERIALIZABLE,snapshot:t.SNAPSHOT}[e];if(n===void 0)throw Error(`Unknown isolation level: ${e}`);return n}#i(e){return new Promise(t=>{e.request.once(`requestCompleted`,t),this.#e.cancel()||(e.request.off(`requestCompleted`,t),t())})}[Ra](){return`closed`in this.#e&&this.#e.closed?Promise.resolve():new Promise(e=>{this.#e.once(`end`,e),this.#e.close()})}async[La](){await new Promise((e,t)=>{this.#e.reset(n=>{if(n)return t(n);e()})})}async[za](){if(this.#t||this.#a())return!1;try{let e=new _n,t=new Ha({compiledQuery:Q.raw(`select 1`),onDone:e,tedious:this.#n});return this.#e.execSql(t.request),await e.promise,!0}catch{return!1}}#a(){return`closed`in this.#e&&!!this.#e.closed}},Ha=class{#e;#t;#n;#r;#i;#a;constructor(e){let{compiledQuery:t,onDone:n,streamChunkSize:r,tedious:i}=e;if(this.#t=[],this.#n=r,this.#r={},this.#i=i,n){let e=`onDone`;this.#r[e]=(t,r)=>{if(t!==`chunkReady`){if(delete this.#r[e],t===`error`)return n.reject(r);n.resolve({rowCount:this.#a,rows:this.#t})}}}this.#e=new this.#i.Request(t.sql,(e,t)=>{if(e)return Object.values(this.#r).forEach(t=>t(`error`,e instanceof AggregateError?e.errors:e));this.#a=t}),this.#o(t.parameters),this.#s()}get request(){return this.#e}readChunk(){let e=this.readChunk.name;return new Promise((t,n)=>{this.#r[e]=(r,i)=>{if(delete this.#r[e],r===`error`)return n(i);t(this.#t.splice(0,this.#n))},this.#e.resume()})}#o(e){for(let t=0;t<e.length;t++){let n=e[t];this.#e.addParameter(String(t+1),this.#c(n),n)}}#s(){let e=this.#n?()=>{this.#n<=this.#t.length&&(this.#e.pause(),Object.values(this.#r).forEach(e=>e(`chunkReady`)))}:()=>{},t=t=>{let n={};for(let e of t)n[e.metadata.colName]=e.value;this.#t.push(n),e()};this.#e.on(`row`,t),this.#e.once(`requestCompleted`,()=>{Object.values(this.#r).forEach(e=>e(`completed`)),this.#e.off(`row`,t)})}#c(s){return i(s)||e(s)||t(s)?this.#i.TYPES.NVarChar:o(s)||n(s)&&s%1==0?s<-2147483648||s>2147483647?this.#i.TYPES.BigInt:this.#i.TYPES.Int:n(s)?this.#i.TYPES.Float:r(s)?this.#i.TYPES.Bit:a(s)?this.#i.TYPES.DateTime:ee(s)?this.#i.TYPES.VarBinary:this.#i.TYPES.NVarChar}},Ua=class{#e;constructor(e){this.#e=e}async getSchemas(){return await this.#e.selectFrom(`sys.schemas`).select(`name`).execute()}async getTables(e={withInternalKyselyTables:!1}){let t=await this.#e.selectFrom(`sys.tables as tables`).leftJoin(`sys.schemas as table_schemas`,`table_schemas.schema_id`,`tables.schema_id`).innerJoin(`sys.columns as columns`,`columns.object_id`,`tables.object_id`).innerJoin(`sys.types as types`,`types.user_type_id`,`columns.user_type_id`).leftJoin(`sys.schemas as type_schemas`,`type_schemas.schema_id`,`types.schema_id`).leftJoin(`sys.extended_properties as comments`,e=>e.onRef(`comments.major_id`,`=`,`tables.object_id`).onRef(`comments.minor_id`,`=`,`columns.column_id`).on(`comments.name`,`=`,`MS_Description`)).$if(!e.withInternalKyselyTables,e=>e.where(`tables.name`,`!=`,ua).where(`tables.name`,`!=`,da)).select([`tables.name as table_name`,e=>e.ref(`tables.type`).$castTo().as(`table_type`),`table_schemas.name as table_schema_name`,`columns.default_object_id as column_default_object_id`,`columns.generated_always_type_desc as column_generated_always_type`,`columns.is_computed as column_is_computed`,`columns.is_identity as column_is_identity`,`columns.is_nullable as column_is_nullable`,`columns.is_rowguidcol as column_is_rowguidcol`,`columns.name as column_name`,`types.is_nullable as type_is_nullable`,`types.name as type_name`,`type_schemas.name as type_schema_name`,`comments.value as column_comment`]).unionAll(this.#e.selectFrom(`sys.views as views`).leftJoin(`sys.schemas as view_schemas`,`view_schemas.schema_id`,`views.schema_id`).innerJoin(`sys.columns as columns`,`columns.object_id`,`views.object_id`).innerJoin(`sys.types as types`,`types.user_type_id`,`columns.user_type_id`).leftJoin(`sys.schemas as type_schemas`,`type_schemas.schema_id`,`types.schema_id`).leftJoin(`sys.extended_properties as comments`,e=>e.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(),n={};for(let e of t){let t=`${e.table_schema_name}.${e.table_name}`;(n[t]=n[t]||l({columns:[],isView:e.table_type===`V `,name:e.table_name,schema:e.table_schema_name??void 0})).columns.push(l({dataType:e.type_name,dataTypeSchema:e.type_schema_name??void 0,hasDefaultValue:e.column_default_object_id>0||e.column_generated_always_type!==`NOT_APPLICABLE`||e.column_is_identity||e.column_is_computed||e.column_is_rowguidcol,isAutoIncrementing:e.column_is_identity,isNullable:e.column_is_nullable&&e.type_is_nullable,name:e.column_name,comment:e.column_comment??void 0}))}return Object.values(n)}async getMetadata(e){return{tables:await this.getTables(e)}}};const Wa=/^[a-z0-9_]$/i;var Ga=class extends ea{getCurrentParameterPlaceholder(){return`@${this.numParameters}`}visitOffset(e){super.visitOffset(e),this.append(` rows`)}compileColumnAlterations(e){let t={};for(let n of e)t[n.kind]||(t[n.kind]=[]),t[n.kind].push(n);let n=!0;t.AddColumnNode&&(this.append(`add `),this.compileList(t.AddColumnNode),n=!1),t.AlterColumnNode&&(n||this.append(`, `),this.compileList(t.AlterColumnNode)),t.DropColumnNode&&(n||this.append(`, `),this.append(`drop column `),this.compileList(t.DropColumnNode)),t.ModifyColumnNode&&(n||this.append(`, `),this.compileList(t.ModifyColumnNode)),t.RenameColumnNode&&(n||this.append(`, `),this.compileList(t.RenameColumnNode))}visitAddColumn(e){this.visitNode(e.column)}visitDropColumn(e){this.visitNode(e.column)}visitMergeQuery(e){super.visitMergeQuery(e),this.append(`;`)}visitCollate(e){this.append(`collate `);let{name:t}=e.collation;for(let e of t)if(!Wa.test(e))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}},Ka=class{#e;constructor(e){this.#e=e}createDriver(){return new Ba(this.#e)}createQueryCompiler(){return new Ga}createAdapter(){return new Ia}createIntrospector(e){return new Ua(e)}};export{da as a,ea as c,ma as i,Z as l,Fa as n,ua as o,ja as r,Q as s,Ka as t,zi as u};
@@ -0,0 +1 @@
1
+ import{n as e}from"./chunk-DQj_Q5LL.mjs";import{t}from"./dist-cjs-6zIKAlZR.mjs";var n,r,i=e((()=>{n=t(),r=class{marshaller;serializer;deserializer;serdeContext;defaultContentType;constructor({marshaller:e,serializer:t,deserializer:n,serdeContext:r,defaultContentType:i}){this.marshaller=e,this.serializer=t,this.deserializer=n,this.serdeContext=r,this.defaultContentType=i}async serializeEventStream({eventStream:e,requestSchema:t,initialRequest:n}){let r=this.marshaller,i=t.getEventStreamMember(),a=t.getMemberSchema(i),o=this.serializer,s=this.defaultContentType,c=Symbol(`initialRequestMarker`),l={async*[Symbol.asyncIterator](){if(n){let e={":event-type":{type:`string`,value:`initial-request`},":message-type":{type:`string`,value:`event`},":content-type":{type:`string`,value:s}};o.write(t,n);let r=o.flush();yield{[c]:!0,headers:e,body:r}}for await(let t of e)yield t}};return r.serialize(l,e=>{if(e[c])return{headers:e.headers,body:e.body};let t=Object.keys(e).find(e=>e!==`__type`)??``,{additionalHeaders:n,body:r,eventType:i,explicitPayloadContentType:o}=this.writeEventBody(t,a,e);return{headers:{":event-type":{type:`string`,value:i},":message-type":{type:`string`,value:`event`},":content-type":{type:`string`,value:o??s},...n},body:r}})}async deserializeEventStream({response:e,responseSchema:t,initialResponseContainer:n}){let r=this.marshaller,i=t.getEventStreamMember(),a=t.getMemberSchema(i).getMemberSchemas(),o=Symbol(`initialResponseMarker`),s=r.deserialize(e.body,async e=>{let n=Object.keys(e).find(e=>e!==`__type`)??``;if(n===`initial-response`){let r=await this.deserializer.read(t,e[n].body);return delete r[i],{[o]:!0,...r}}else if(n in a){let t=a[n];return{[n]:await this.deserializer.read(t,e[n].body)}}else return{$unknown:e}}),c=s[Symbol.asyncIterator](),l=await c.next();if(l.done)return s;if(l.value?.[o]){if(!t)throw Error(`@smithy::core/protocols - initial-response event encountered in event stream but no response schema given.`);for(let[e,t]of Object.entries(l.value))n[e]=t}return{async*[Symbol.asyncIterator](){for(l?.value?.[o]||(yield l.value);;){let{done:e,value:t}=await c.next();if(e)break;yield t}}}}writeEventBody(e,t,r){let i=this.serializer,a=e,o=null,s,c=(()=>t.getSchema()[4].includes(e))(),l={};if(c){let n=t.getMemberSchema(e);if(n.isStructSchema()){for(let[t,i]of n.structIterator()){let{eventHeader:n,eventPayload:a}=i.getMergedTraits();if(a){o=t;break}else if(n){let n=r[e][t],a=`binary`;i.isNumericSchema()?a=(-2)**31<=n&&n<=2**31-1?`integer`:`long`:i.isTimestampSchema()?a=`timestamp`:i.isStringSchema()?a=`string`:i.isBooleanSchema()&&(a=`boolean`),n!=null&&(l[t]={type:a,value:n},delete r[e][t])}}if(o!==null){let t=n.getMemberSchema(o);t.isBlobSchema()?s=`application/octet-stream`:t.isStringSchema()&&(s=`text/plain`),i.write(t,r[e][o])}else i.write(n,r[e])}else throw Error(`@smithy/core/event-streams - non-struct member not supported in event stream union.`)}else{let[t,n]=r[e];a=t,i.write(15,n)}let u=i.flush();return{body:typeof u==`string`?(this.serdeContext?.utf8Decoder??n.fromUtf8)(u):u,eventType:a,explicitPayloadContentType:s,additionalHeaders:l}}}}));e((()=>{i()}))();export{r as EventStreamSerde};