@gjermundgaraba/clankerauth-dev 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +38 -0
- package/dist/THIRD_PARTY_NOTICES.txt +1576 -0
- package/dist/access-OpW0SRxm.mjs +1 -0
- package/dist/bun-sqlite-dialect-C7ftEUSI-DFKViJQ3.mjs +1 -0
- package/dist/compiled-query-xtJR566p.mjs +1 -0
- package/dist/d1-sqlite-dialect-D4qp4-wW-Rqu1eTED.mjs +1 -0
- package/dist/default-query-compiler-DTJtuKGc.mjs +1 -0
- package/dist/dist-DpbKAALD.mjs +1 -0
- package/dist/dist-lqtcybuJ.mjs +17 -0
- package/dist/esm-CdWTLqG7.mjs +1 -0
- package/dist/factory-BZXyDHm6.mjs +6 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.mjs +517 -0
- package/dist/kysely-adapter-C-VVCuVS.mjs +1 -0
- package/dist/kysely-migration-tables-DFfmKhq--DIOBV7Sd.mjs +1 -0
- package/dist/organization-Bz1iQbJ0.mjs +1 -0
- package/dist/random-D6srtOfs.mjs +1 -0
- package/dist/schema-check-2a0t7Pu_.mjs +8 -0
- package/dist/schemas-CYxWglEB.mjs +118 -0
- package/dist/sqlite-adapter-BG0MClj_.mjs +1 -0
- package/dist/web/assets/index-9VtsK-ro.css +1 -0
- package/dist/web/assets/index-HxNynbde.js +53 -0
- package/dist/web/index.html +14 -0
- package/package.json +40 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{N as e}from"./schemas-CYxWglEB.mjs";function t(e){return{success:!1,error:`You are not allowed to access resource: ${e}`}}function n(e){return{success:!1,error:`unauthorized to access resource "${e}"`}}function r(e){return e===`OR`?`OR`:`AND`}function i(e){return Array.isArray(e)}function a(t){if(i(t))return{actions:t,connector:`AND`};if(!t||typeof t!=`object`)throw new e(`Invalid access control request`);let{actions:n,connector:a}=t;return i(n)?{actions:n,connector:r(a)}:{actions:[],connector:r(a)}}function o(e,t){return typeof t==`string`&&e.includes(t)}function s(e,{actions:t,connector:n}){return t.length===0?!1:n===`OR`?t.some(t=>o(e,t)):t.every(t=>o(e,t))}function c(e){return{authorize(r,i=`AND`){let o=!1;for(let[c,l]of Object.entries(r)){let r=e[c];if(!r){if(i===`AND`)return t(c);continue}let u=s(r,a(l));if(u&&(o=!0),u&&i===`OR`)return{success:!0};if(!u&&i===`AND`)return n(c)}return o?{success:!0}:{success:!1,error:`Not authorized`}},statements:e}}function l(e){return{newRole(e){return c(e)},statements:e}}export{c as n,l as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./kysely-migration-tables-DFfmKhq--DIOBV7Sd.mjs";import{t as n}from"./default-query-compiler-DTJtuKGc.mjs";import{n as r,t as i}from"./compiled-query-xtJR566p.mjs";var a=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(){}async releaseMigrationLock(){}get supportsOutput(){return!0}},o=class{#e;#t=new c;#n;#r;constructor(e){this.#e={...e}}async init(){this.#n=this.#e.database,this.#r=new s(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(i.raw(`begin`))}async commitTransaction(e){await e.executeQuery(i.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(i.raw(`rollback`))}async releaseConnection(){this.#t.unlock()}async destroy(){this.#n?.close()}},s=class{#e;constructor(e){this.#e=e}executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t),i=n;if(r.columnNames.length>0)return Promise.resolve({rows:r.all(...i)});let{changes:a,lastInsertRowid:o}=r.run(...i);return Promise.resolve({rows:[],numAffectedRows:BigInt(a),insertId:typeof o==`bigint`?o:BigInt(o)})}async*streamQuery(){throw Error(`Streaming query is not supported by SQLite driver.`)}},c=class{#e;#t;async lock(){for(;this.#e!==void 0;)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?.()}},l=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(n={withInternalKyselyTables:!1}){let r=this.#e.selectFrom(`sqlite_schema`).where(`type`,`=`,`table`).where(`name`,`not like`,`sqlite_%`).select(`name`).$castTo();n.withInternalKyselyTables||(r=r.where(`name`,`!=`,e).where(`name`,`!=`,t));let i=await r.execute();return Promise.all(i.map(({name:e})=>this.#t(e)))}async getMetadata(e){return{tables:await this.getTables(e)}}async#t(e){let t=this.#e,n=(await t.selectFrom(`sqlite_master`).where(`name`,`=`,e).select(`sql`).$castTo().execute())[0]?.sql?.split(/[\(\),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.split(/\s+/)?.[0]?.replace(/["`]/g,``);return{name:e,columns:(await t.selectFrom(r`pragma_table_info(${e})`.as(`table_info`)).select([`name`,`type`,`notnull`,`dflt_value`]).execute()).map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===n,hasDefaultValue:e.dflt_value!=null})),isView:!1}}},u=class extends n{getCurrentParameterPlaceholder(){return`?`}getLeftIdentifierWrapper(){return`"`}getRightIdentifierWrapper(){return`"`}getAutoIncrement(){return`autoincrement`}},d=class{#e;constructor(e){this.#e={...e}}createDriver(){return new o(this.#e)}createQueryCompiler(){return new u}createAdapter(){return new a}createIntrospector(e){return new l(e)}};export{d as BunSqliteDialect};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{C as e,D as t,E as n,O as r,T as i,_ as a,a as o,b as s,c,d as l,f as u,g as d,h as f,i as p,k as m,l as ee,o as te,r as ne,s as h,u as re,v as ie,w as ae,y as oe}from"./default-query-compiler-DTJtuKGc.mjs";const g=a({is(e){return e.kind===`AliasNode`},create(e,t){return a({kind:`AliasNode`,node:e,alias:t})}}),_=a({is(e){return e.kind===`TableNode`},create(e){return a({kind:`TableNode`,table:u.create(e)})},createWithSchema(e,t){return a({kind:`TableNode`,table:u.createWithSchema(e,t)})}});function v(t){return n(t)&&e(t.toOperationNode)}function se(e){return n(e)&&`expressionType`in e&&v(e)}function ce(e){return n(e)&&`expression`in e&&r(e.alias)&&v(e)}const y=a({is(e){return e.kind===`SelectModifierNode`},create(e,t){return a({kind:`SelectModifierNode`,modifier:e,of:t})},createWithExpression(e){return a({kind:`SelectModifierNode`,rawModifier:e})}}),b=a({is(e){return e.kind===`AndNode`},create(e,t){return a({kind:`AndNode`,left:e,right:t})}}),x=a({is(e){return e.kind===`OrNode`},create(e,t){return a({kind:`OrNode`,left:e,right:t})}}),le=a({is(e){return e.kind===`OnNode`},create(e){return a({kind:`OnNode`,on:e})},cloneWithOperation(e,t,n){return a({...e,on:t===`And`?b.create(e.on,n):x.create(e.on,n)})}}),S=a({is(e){return e.kind===`JoinNode`},create(e,t){return a({kind:`JoinNode`,joinType:e,table:t,on:void 0})},createWithOn(e,t,n){return a({kind:`JoinNode`,joinType:e,table:t,on:le.create(n)})},cloneWithOn(e,t){return a({...e,on:e.on?le.cloneWithOperation(e.on,`And`,t):le.create(t)})}}),C=a({is(e){return e.kind===`BinaryOperationNode`},create(e,t,n){return a({kind:`BinaryOperationNode`,leftOperand:e,operator:t,rightOperand:n})}}),w=a({is(e){return e.kind===`ColumnNode`},create(e){return a({kind:`ColumnNode`,column:f.create(e)})}}),ue=a({is(e){return e.kind===`SelectAllNode`},create(){return a({kind:`SelectAllNode`})}}),de=a({is(e){return e.kind===`ReferenceNode`},create(e,t){return a({kind:`ReferenceNode`,table:t,column:e})},createSelectAll(e){return a({kind:`ReferenceNode`,table:e,column:ue.create()})}});var fe=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Te(this.#e)}};function pe(e){return n(e)&&v(e)&&r(e.dynamicReference)}const T=a({is(e){return e.kind===`OrderByItemNode`},create(e,t){return a({kind:`OrderByItemNode`,orderBy:e,direction:t})},cloneWith(e,t){return a({...e,...t})}}),me=a({is(e){return e.kind===`CollateNode`},create(e){return a({kind:`CollateNode`,collation:f.create(e)})}});var he=class e{#e;constructor(e){this.#e=a(e)}desc(){return new e({node:T.cloneWith(this.#e.node,{direction:h.createWithSql(`desc`)})})}asc(){return new e({node:T.cloneWith(this.#e.node,{direction:h.createWithSql(`asc`)})})}nullsLast(){return new e({node:T.cloneWith(this.#e.node,{nulls:`last`})})}nullsFirst(){return new e({node:T.cloneWith(this.#e.node,{nulls:`first`})})}collate(t){return new e({node:T.cloneWith(this.#e.node,{collation:me.create(t)})})}toOperationNode(){return this.#e.node}};const ge=/* @__PURE__ */ new Set;function _e(e){ge.has(e)||(ge.add(e),console.log(e))}function ve(e){return e===`asc`||e===`desc`}function E(e){if(e.length===2)return[ye(e[0],e[1])];if(e.length===1){let[t]=e;return Array.isArray(t)?(_e(`orderBy(array) is deprecated, use multiple orderBy calls instead.`),t.map(e=>ye(e))):[ye(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function ye(e,t){let n=be(e);if(T.is(n)){if(t)throw Error(`Cannot specify direction twice!`);return n}return xe(n,t)}function be(e){if(pr(e))return dr(e);if(pe(e))return e.toOperationNode();let[t,n]=e.split(` `);return n?(_e("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),xe(O(t),n)):O(e)}function xe(e,t){if(typeof t==`string`){if(!ve(t))throw Error(`Invalid order by direction: ${t}`);return T.create(e,h.createWithSql(t))}if(se(t))return _e("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),T.create(e,t.toOperationNode());let n=T.create(e);return t?t(new he({node:n})).toOperationNode():n}const Se=a({is(e){return e.kind===`JSONReferenceNode`},create(e,t){return a({kind:`JSONReferenceNode`,reference:e,traversal:t})},cloneWithTraversal(e,t){return a({...e,traversal:t})}}),Ce=a({is(e){return e.kind===`JSONOperatorChainNode`},create(e){return a({kind:`JSONOperatorChainNode`,operator:e,values:a([])})},cloneWithValue(e,t){return a({...e,values:a([...e.values,t])})}}),we=a({is(e){return e.kind===`JSONPathNode`},create(e){return a({kind:`JSONPathNode`,inOperator:e,pathLegs:a([])})},cloneWithLeg(e,t){return a({...e,pathLegs:a([...e.pathLegs,t])})}});function Te(e){return r(e)?O(e):e.toOperationNode()}function Ee(e){return t(e)?e.map(e=>D(e)):[D(e)]}function D(e){return pr(e)?dr(e):Te(e)}function De(e,t){if(re(t))return Se.create(O(e),Ce.create(c.create(t)));if(t===`->$`||t===`->>$`)return Se.create(O(e),we.create(c.create(t.slice(0,-1))));throw Error(`Invalid JSON operator: ${t}`)}function O(e){if(!e.includes(`.`))return de.create(w.create(e));let t=e.split(`.`).map(Ne);if(t.length===3)return je(t);if(t.length===2)return Me(t);throw Error(`invalid column reference ${e}`)}function Oe(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(Ne);return g.create(O(n),f.create(r))}return O(e)}function ke(e){return w.create(e)}function Ae(e){if(e.includes(` `)){let[t,n]=e.split(` `).map(Ne);if(!ve(n))throw Error(`invalid order direction "${n}" next to "${t}"`);return E([t,n])[0]}return ke(e)}function je(e){let[t,n,r]=e;return de.create(w.create(r),_.createWithSchema(t,n))}function Me(e){let[t,n]=e;return de.create(w.create(n),_.create(t))}function Ne(e){return e.trim()}const Pe=a({is(e){return e.kind===`PrimitiveValueListNode`},create(e){return a({kind:`PrimitiveValueListNode`,values:a([...e])})}}),Fe=a({is(e){return e.kind===`ValueListNode`},create(e){return a({kind:`ValueListNode`,values:a(e)})}}),k=a({is(e){return e.kind===`ValueNode`},create(e){return a({kind:`ValueNode`,value:e})},createImmediate(e){return a({kind:`ValueNode`,value:e,immediate:!0})}});function Ie(e){return t(e)?ze(e):A(e)}function A(e){return pr(e)?dr(e):k.create(e)}function Le(e){return i(e)||s(e)||ae(e)}function Re(e){if(!Le(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return k.createImmediate(e)}function ze(e){return e.some(pr)?Fe.create(e.map(e=>A(e))):Pe.create(e)}function j(e){if(e.length===3)return Be(e[0],e[1],e[2]);if(e.length===1)return A(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Be(e,t,n){return Ue(t)&&We(n)?C.create(D(e),Ge(t),k.createImmediate(n)):C.create(D(e),Ge(t),Ie(n))}function M(e,t,n){return C.create(D(e),Ge(t),D(n))}function Ve(e,t){return He(Object.entries(e).filter(([,e])=>!m(e)).map(([e,t])=>Be(e,We(t)?`is`:`=`,t)),t)}function He(e,t,n=!0){let r=t===`and`?b.create:x.create;if(e.length===0)return C.create(k.createImmediate(1),c.create(`=`),k.createImmediate(+(t===`and`)));let i=Ke(e[0]);for(let t=1;t<e.length;++t)i=r(i,Ke(e[t]));return e.length>1&&n?te.create(i):i}function Ue(e){return e===`is`||e===`is not`}function We(e){return ae(e)||s(e)}function Ge(e){if(ee(e))return c.create(e);if(v(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function Ke(e){return v(e)?e.toOperationNode():e}const qe=a({is(e){return e.kind===`OrderByNode`},create(e){return a({kind:`OrderByNode`,items:a([...e])})},cloneWithItems(e,t){return a({...e,items:a([...e.items,...t])})}}),Je=a({is(e){return e.kind===`PartitionByNode`},create(e){return a({kind:`PartitionByNode`,items:a(e)})},cloneWithItems(e,t){return a({...e,items:a([...e.items,...t])})}}),Ye=a({is(e){return e.kind===`OverNode`},create(){return a({kind:`OverNode`})},cloneWithOrderByItems(e,t){return a({...e,orderBy:e.orderBy?qe.cloneWithItems(e.orderBy,t):qe.create(t)})},cloneWithPartitionByItems(e,t){return a({...e,partitionBy:e.partitionBy?Je.cloneWithItems(e.partitionBy,t):Je.create(t)})}}),Xe=a({is(e){return e.kind===`FromNode`},create(e){return a({kind:`FromNode`,froms:a(e)})},cloneWithFroms(e,t){return a({...e,froms:a([...e.froms,...t])})}}),Ze=a({is(e){return e.kind===`GroupByNode`},create(e){return a({kind:`GroupByNode`,items:a(e)})},cloneWithItems(e,t){return a({...e,items:a([...e.items,...t])})}}),Qe=a({is(e){return e.kind===`HavingNode`},create(e){return a({kind:`HavingNode`,having:e})},cloneWithOperation(e,t,n){return a({...e,having:t===`And`?b.create(e.having,n):x.create(e.having,n)})}}),$e=a({is(e){return e.kind===`ListNode`},create(e){return a({kind:`ListNode`,items:a(e)})}}),et=a({is(e){return e.kind===`UpdateQueryNode`},create(e,t){return a({kind:`UpdateQueryNode`,table:e.length===1?e[0]:$e.create(e),...t&&{with:t}})},createWithoutTable(){return a({kind:`UpdateQueryNode`})},cloneWithFromItems(e,t){return a({...e,from:e.from?Xe.cloneWithFroms(e.from,t):Xe.create(t)})},cloneWithUpdates(e,t){return a({...e,updates:e.updates?a([...e.updates,...t]):t})},cloneWithLimit(e,t){return a({...e,limit:t})}}),tt=a({is(e){return e.kind===`UsingNode`},create(e){return a({kind:`UsingNode`,tables:a(e)})},cloneWithTables(e,t){return a({...e,tables:a([...e.tables,...t])})}}),nt=a({is(e){return e.kind===`DeleteQueryNode`},create(e,t){return a({kind:`DeleteQueryNode`,from:Xe.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>F.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:e=>F.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return a({...e,limit:t})},cloneWithoutLimit(e){return a({...e,limit:void 0})},cloneWithUsing(e,t){return a({...e,using:e.using===void 0?tt.create(t):tt.cloneWithTables(e.using,t)})}}),N=a({is(e){return e.kind===`WhereNode`},create(e){return a({kind:`WhereNode`,where:e})},cloneWithOperation(e,t,n){return a({...e,where:t===`And`?b.create(e.where,n):x.create(e.where,n)})}}),rt=a({is(e){return e.kind===`ReturningNode`},create(e){return a({kind:`ReturningNode`,selections:a(e)})},cloneWithSelections(e,t){return a({...e,selections:e.selections?a([...e.selections,...t]):a(t)})}}),it=a({is(e){return e.kind===`ExplainNode`},create(e,t){return a({kind:`ExplainNode`,format:e,options:t})}}),P=a({is(e){return e.kind===`MergeQueryNode`},create(e,t){return a({kind:`MergeQueryNode`,into:e,...t&&{with:t}})},cloneWithUsing(e,t){return a({...e,using:t})},cloneWithWhen(e,t){return a({...e,whens:e.whens?a([...e.whens,t]):a([t])})},cloneWithThen(e,t){return a({...e,whens:e.whens?a([...e.whens.slice(0,-1),p.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}}),at=a({is(e){return e.kind===`OutputNode`},create(e){return a({kind:`OutputNode`,selections:a(e)})},cloneWithSelections(e,t){return a({...e,selections:e.selections?a([...e.selections,...t]):a(t)})}}),F=a({is(e){return I.is(e)||o.is(e)||et.is(e)||nt.is(e)||P.is(e)},cloneWithEndModifier(e,t){return a({...e,endModifiers:e.endModifiers?a([...e.endModifiers,t]):a([t])})},cloneWithWhere(e,t){return a({...e,where:e.where?N.cloneWithOperation(e.where,`And`,t):N.create(t)})},cloneWithJoin(e,t){return a({...e,joins:e.joins?a([...e.joins,t]):a([t])})},cloneWithReturning(e,t){return a({...e,returning:e.returning?rt.cloneWithSelections(e.returning,t):rt.create(t)})},cloneWithoutReturning(e){return a({...e,returning:void 0})},cloneWithoutWhere(e){return a({...e,where:void 0})},cloneWithExplain(e,t,n){return a({...e,explain:it.create(t,n?.toOperationNode())})},cloneWithTop(e,t){return a({...e,top:t})},cloneWithOutput(e,t){return a({...e,output:e.output?at.cloneWithSelections(e.output,t):at.create(t)})},cloneWithOrderByItems(e,t){return a({...e,orderBy:e.orderBy?qe.cloneWithItems(e.orderBy,t):qe.create(t)})},cloneWithoutOrderBy(e){return a({...e,orderBy:void 0})}}),I=a({is(e){return e.kind===`SelectQueryNode`},create(e){return a({kind:`SelectQueryNode`,...e&&{with:e}})},createFrom(e,t){return a({kind:`SelectQueryNode`,from:Xe.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return a({...e,selections:e.selections?a([...e.selections,...t]):a(t)})},cloneWithDistinctOn(e,t){return a({...e,distinctOn:e.distinctOn?a([...e.distinctOn,...t]):a(t)})},cloneWithFrontModifier(e,t){return a({...e,frontModifiers:e.frontModifiers?a([...e.frontModifiers,t]):a([t])})},cloneWithOrderByItems:(e,t)=>F.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return a({...e,groupBy:e.groupBy?Ze.cloneWithItems(e.groupBy,t):Ze.create(t)})},cloneWithLimit(e,t){return a({...e,limit:t})},cloneWithOffset(e,t){return a({...e,offset:t})},cloneWithFetch(e,t){return a({...e,fetch:t})},cloneWithHaving(e,t){return a({...e,having:e.having?Qe.cloneWithOperation(e.having,`And`,t):Qe.create(t)})},cloneWithSetOperations(e,t){return a({...e,setOperations:e.setOperations?a([...e.setOperations,...t]):a([...t])})},cloneWithoutSelections(e){return a({...e,selections:[]})},cloneWithoutLimit(e){return a({...e,limit:void 0})},cloneWithoutOffset(e){return a({...e,offset:void 0})},cloneWithoutOrderBy:e=>F.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return a({...e,groupBy:void 0})}});var ot=class e{#e;constructor(e){this.#e=a(e)}on(...t){return new e({...this.#e,joinNode:S.cloneWithOn(this.#e.joinNode,j(t))})}onRef(t,n,r){return new e({...this.#e,joinNode:S.cloneWithOn(this.#e.joinNode,M(t,n,r))})}onTrue(){return new e({...this.#e,joinNode:S.cloneWithOn(this.#e.joinNode,h.createWithSql(`true`))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};const st=a({is(e){return e.kind===`PartitionByItemNode`},create(e){return a({kind:`PartitionByItemNode`,partitionBy:e})}});function ct(e){return Ee(e).map(st.create)}var lt=class e{#e;constructor(e){this.#e=a(e)}orderBy(...t){return new e({overNode:Ye.cloneWithOrderByItems(this.#e.overNode,E(t))})}clearOrderBy(){return new e({overNode:F.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(t){return new e({overNode:Ye.cloneWithPartitionByItems(this.#e.overNode,ct(t))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};const ut=a({is(e){return e.kind===`SelectionNode`},create(e){return a({kind:`SelectionNode`,selection:e})},createSelectAll(){return a({kind:`SelectionNode`,selection:ue.create()})},createSelectAllFromTable(e){return a({kind:`SelectionNode`,selection:de.createSelectAll(e)})}});function L(n){return e(n)?L(n(ur())):t(n)?n.map(e=>dt(e)):[dt(n)]}function dt(e){return r(e)?ut.create(Oe(e)):pe(e)?ut.create(e.toOperationNode()):ut.create(fr(e))}function R(e){return e?Array.isArray(e)?e.map(ft):[ft(e)]:[ut.createSelectAll()]}function ft(e){if(r(e))return ut.createSelectAllFromTable(Q(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}const pt=a({is(e){return e.kind===`ValuesNode`},create(e){return a({kind:`ValuesNode`,values:a(e)})}}),mt=a({is(e){return e.kind===`DefaultInsertValueNode`},create(){return a({kind:`DefaultInsertValueNode`})}});function ht(n){let r=e(n)?n(ur()):n;return gt(t(r)?r:a([r]))}function gt(e){let t=_t(e);return[a([...t.keys()].map(w.create)),pt.create(e.map(e=>vt(e,t)))]}function _t(e){let t=/* @__PURE__ */ 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 vt(e,t){let n=Object.keys(e),r=Array.from({length:t.size}),i=!1,a=n.length;for(let o of n){let n=t.get(o);if(m(n)){a--;continue}let s=e[o];(m(s)||pr(s))&&(i=!0),r[n]=s}if(a<t.size||i){let e=mt.create();return Fe.create(r.map(t=>m(t)?e:A(t)))}return Pe.create(r)}const yt=a({is(e){return e.kind===`ColumnUpdateNode`},create(e,t){return a({kind:`ColumnUpdateNode`,column:e,value:t})}});function bt(...e){return e.length===2?[yt.create(D(e[0]),A(e[1]))]:xt(e[0])}function xt(t){let n=e(t)?t(ur()):t;return Object.entries(n).filter(([e,t])=>t!==void 0).map(([e,t])=>yt.create(w.create(e),A(t)))}const St=a({is(e){return e.kind===`OnDuplicateKeyNode`},create(e){return a({kind:`OnDuplicateKeyNode`,updates:e})}});var Ct=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}},wt=class extends Error{node;constructor(e){super(`no result`),this.node=e}};function Tt(e){return Object.prototype.hasOwnProperty.call(e,`prototype`)}const z=a({is(e){return e.kind===`OnConflictNode`},create(){return a({kind:`OnConflictNode`})},cloneWith(e,t){return a({...e,...t})},cloneWithIndexWhere(e,t){return a({...e,indexWhere:e.indexWhere?N.cloneWithOperation(e.indexWhere,`And`,t):N.create(t)})},cloneWithIndexOrWhere(e,t){return a({...e,indexWhere:e.indexWhere?N.cloneWithOperation(e.indexWhere,`Or`,t):N.create(t)})},cloneWithUpdateWhere(e,t){return a({...e,updateWhere:e.updateWhere?N.cloneWithOperation(e.updateWhere,`And`,t):N.create(t)})},cloneWithUpdateOrWhere(e,t){return a({...e,updateWhere:e.updateWhere?N.cloneWithOperation(e.updateWhere,`Or`,t):N.create(t)})},cloneWithoutIndexWhere(e){return a({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return a({...e,updateWhere:void 0})}});var Et=class e{#e;constructor(e){this.#e=a(e)}column(t){let n=w.create(t);return new e({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?a([...this.#e.onConflictNode.columns,n]):a([n])})})}columns(t){let n=t.map(w.create);return new e({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?a([...this.#e.onConflictNode.columns,...n]):a(n)})})}constraint(t){return new e({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{constraint:f.create(t)})})}expression(t){return new e({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{indexExpression:t.toOperationNode()})})}where(...t){return new e({...this.#e,onConflictNode:z.cloneWithIndexWhere(this.#e.onConflictNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:z.cloneWithIndexWhere(this.#e.onConflictNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:z.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Dt({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Ot({...this.#e,onConflictNode:z.cloneWith(this.#e.onConflictNode,{updates:xt(e)})})}$call(e){return e(this)}},Dt=class{#e;constructor(e){this.#e=a(e)}toOperationNode(){return this.#e.onConflictNode}},Ot=class e{#e;constructor(e){this.#e=a(e)}where(...t){return new e({...this.#e,onConflictNode:z.cloneWithUpdateWhere(this.#e.onConflictNode,j(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:z.cloneWithUpdateWhere(this.#e.onConflictNode,M(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:z.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};const kt=a({is(e){return e.kind===`TopNode`},create(e,t){return a({kind:`TopNode`,expression:e,modifiers:t})}});function At(e,t){if(!i(e)&&!oe(e))throw Error(`Invalid top expression: ${e}`);if(!m(t)&&!jt(t))throw Error(`Invalid top modifiers: ${t}`);return kt.create(e,t)}function jt(e){return e===`percent`||e===`with ties`||e===`percent with ties`}const Mt=a({is(e){return e.kind===`OrActionNode`},create(e){return a({kind:`OrActionNode`,action:e})}});var Nt=class e{#e;constructor(e){this.#e=a(e)}values(t){let[n,r]=ht(t);return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{columns:n,values:r})})}columns(t){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{columns:a(t.map(w.create))})})}expression(t){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{values:dr(t)})})}defaultValues(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(t){return new e({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}ignore(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`ignore`)})})}orIgnore(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`ignore`)})})}orAbort(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`abort`)})})}orFail(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`fail`)})})}orReplace(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`replace`)})})}orRollback(){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{orAction:Mt.create(`rollback`)})})}top(t,n){return new e({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(t,n))})}onConflict(t){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{onConflict:t(new Et({onConflictNode:z.create()})).toOperationNode()})})}onDuplicateKeyUpdate(t){return new e({...this.#e,queryNode:o.cloneWith(this.#e.queryNode,{onDuplicateKey:St.create(xt(t))})})}returning(t){return new e({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,L(t))})}returningAll(){return new e({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,R())})}output(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,L(t))})}outputAll(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,R(t))})}clearReturning(){return new e({...this.#e,queryNode:F.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(e){let t=this.compile(),n=await this.#e.executor.executeQuery(t,e),{adapter:r}=this.#e.executor,i=t.query;return i.returning&&r.supportsReturning||i.output&&r.supportsOutput?n.rows:[new Ct(n.insertId,n.numAffectedRows??BigInt(0))]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){typeof e==`function`&&(e={errorConstructor:e});let t=await this.executeTakeFirst(e);if(t===void 0){let t=e?.errorConstructor??wt;throw Tt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}async*stream(e){typeof e!=`object`&&(e={chunkSize:e});let t=this.compile(),n=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let e of n)yield*e.rows}async explain(t,n){return await new e({...this.#e,queryNode:F.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}},Pt=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};const Ft=a({is(e){return e.kind===`LimitNode`},create(e){return a({kind:`LimitNode`,limit:e})}});var B,It=class{#e;constructor(e){this.#e=a(e)}where(...e){return new B({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,j(e))})}whereRef(e,t,n){return new B({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,M(e,t,n))})}clearWhere(){return new B({...this.#e,queryNode:F.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new B({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(e,t))})}using(e){return new B({...this.#e,queryNode:nt.cloneWithUsing(this.#e.queryNode,_r(e))})}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(e,t){return new B({...this.#e,queryNode:F.cloneWithJoin(this.#e.queryNode,Tn(e,t))})}returning(e){return new B({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,L(e))})}returningAll(e){return new B({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,R(e))})}output(e){return new B({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,L(e))})}outputAll(e){return new B({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,R(e))})}clearReturning(){return new B({...this.#e,queryNode:F.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new B({...this.#e,queryNode:nt.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new B({...this.#e,queryNode:F.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new B({...this.#e,queryNode:F.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new B({...this.#e,queryNode:nt.cloneWithLimit(this.#e.queryNode,Ft.create(A(e)))})}modifyEnd(e){return new B({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){return e?t(this):new B({...this.#e})}$castTo(){return new B(this.#e)}$narrowType(){return new B(this.#e)}$assertType(){return new B(this.#e)}withPlugin(e){return new B({...this.#e,executor:this.#e.executor.withPlugin(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(e){let t=this.compile(),n=await this.#e.executor.executeQuery(t,e),{adapter:r}=this.#e.executor,i=t.query;return i.returning&&r.supportsReturning||i.output&&r.supportsOutput?n.rows:[new Pt(n.numAffectedRows??BigInt(0))]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){typeof e==`function`&&(e={errorConstructor:e});let t=await this.executeTakeFirst(e);if(t===void 0){let t=e?.errorConstructor??wt;throw Tt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}async*stream(e){typeof e!=`object`&&(e={chunkSize:e});let t=this.compile(),n=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let e of n)yield*e.rows}async explain(e,t){return await new B({...this.#e,queryNode:F.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};B=It;var Lt=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}},V,Rt=class{#e;constructor(e){this.#e=a(e)}where(...e){return new V({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,j(e))})}whereRef(e,t,n){return new V({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,M(e,t,n))})}clearWhere(){return new V({...this.#e,queryNode:F.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new V({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(e,t))})}from(e){return new V({...this.#e,queryNode:et.cloneWithFromItems(this.#e.queryNode,_r(e))})}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(e,t){return new V({...this.#e,queryNode:F.cloneWithJoin(this.#e.queryNode,Tn(e,t))})}orderBy(...e){return new V({...this.#e,queryNode:F.cloneWithOrderByItems(this.#e.queryNode,E(e))})}clearOrderBy(){return new V({...this.#e,queryNode:F.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new V({...this.#e,queryNode:et.cloneWithLimit(this.#e.queryNode,Ft.create(A(e)))})}set(...e){return new V({...this.#e,queryNode:et.cloneWithUpdates(this.#e.queryNode,bt(...e))})}returning(e){return new V({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,L(e))})}returningAll(e){return new V({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,R(e))})}output(e){return new V({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,L(e))})}outputAll(e){return new V({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,R(e))})}modifyEnd(e){return new V({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new V({...this.#e,queryNode:F.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new V({...this.#e})}$castTo(){return new V(this.#e)}$narrowType(){return new V(this.#e)}$assertType(){return new V(this.#e)}withPlugin(e){return new V({...this.#e,executor:this.#e.executor.withPlugin(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(e){let t=this.compile(),n=await this.#e.executor.executeQuery(t,e),{adapter:r}=this.#e.executor,i=t.query;return i.returning&&r.supportsReturning||i.output&&r.supportsOutput?n.rows:[new Lt(n.numAffectedRows??BigInt(0),n.numChangedRows)]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){typeof e==`function`&&(e={errorConstructor:e});let t=await this.executeTakeFirst(e);if(t===void 0){let t=e?.errorConstructor??wt;throw Tt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}async*stream(e){typeof e!=`object`&&(e={chunkSize:e});let t=this.compile(),n=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let e of n)yield*e.rows}async explain(e,t){return await new V({...this.#e,queryNode:F.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};V=Rt;const zt=a({is(e){return e.kind===`CommonTableExpressionNameNode`},create(e,t){return a({kind:`CommonTableExpressionNameNode`,table:_.create(e),columns:t?a(t.map(w.create)):void 0})}}),Bt=a({is(e){return e.kind===`CommonTableExpressionNode`},create(e,t){return a({kind:`CommonTableExpressionNode`,name:e,expression:t})},cloneWith(e,t){return a({...e,...t})}});var Vt=class e{#e;constructor(e){this.#e=a(e)}materialized(){return new e({...this.#e,node:Bt.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new e({...this.#e,node:Bt.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function Ht(t,n){let r=v(n)?n.toOperationNode():n(Sn()).toOperationNode();return e(t)?t(Ut(r)).toOperationNode():Bt.create(Wt(t),r)}function Ut(e){return t=>new Vt({node:Bt.create(Wt(t),e)})}function Wt(e){if(e.includes(`(`)){let t=e.split(/[\(\)]/),n=t[0],r=t[1].split(`,`).map(e=>e.trim());return zt.create(n,r)}return zt.create(e)}const Gt=a({is(e){return e.kind===`WithNode`},create(e,t){return a({kind:`WithNode`,expressions:a([e]),...t})},cloneWithExpression(e,t){return a({...e,expressions:a([...e.expressions,t])})}}),Kt=/* @__PURE__ */ `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.split(``);function qt(e){let t=``;for(let n=0;n<e;++n)t+=Jt();return t}function Jt(){return Kt[~~(Math.random()*Kt.length)]}function H(){return new Yt}var Yt=class{#e;get queryId(){return this.#e===void 0&&(this.#e=qt(8)),this.#e}},Xt=class{nodeStack=[];#e=a({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),AlterTypeNode:this.transformAlterType.bind(this),AddValueNode:this.transformAddValue.bind(this),RenameValueNode:this.transformRenameValue.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let n=this.transformNodeImpl(e,t);return this.nodeStack.pop(),a(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&a(e.map(e=>this.transformNode(e,t)))}transformSelectQuery(e,t){return{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{kind:`SelectionNode`,selection:this.transformNode(e.selection,t)}}transformColumn(e,t){return{kind:`ColumnNode`,column:this.transformNode(e.column,t)}}transformAlias(e,t){return{kind:`AliasNode`,node:this.transformNode(e.node,t),alias:this.transformNode(e.alias,t)}}transformTable(e,t){return{kind:`TableNode`,table:this.transformNode(e.table,t)}}transformFrom(e,t){return{kind:`FromNode`,froms:this.transformNodeList(e.froms,t)}}transformReference(e,t){return{kind:`ReferenceNode`,column:this.transformNode(e.column,t),table:this.transformNode(e.table,t)}}transformAnd(e,t){return{kind:`AndNode`,left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformOr(e,t){return{kind:`OrNode`,left:this.transformNode(e.left,t),right:this.transformNode(e.right,t)}}transformValueList(e,t){return{kind:`ValueListNode`,values:this.transformNodeList(e.values,t)}}transformParens(e,t){return{kind:`ParensNode`,node:this.transformNode(e.node,t)}}transformJoin(e,t){return{kind:`JoinNode`,joinType:e.joinType,table:this.transformNode(e.table,t),on:this.transformNode(e.on,t)}}transformRaw(e,t){return{kind:`RawNode`,sqlFragments:a([...e.sqlFragments]),parameters:this.transformNodeList(e.parameters,t)}}transformWhere(e,t){return{kind:`WhereNode`,where:this.transformNode(e.where,t)}}transformInsertQuery(e,t){return{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),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{kind:`ValuesNode`,values:this.transformNodeList(e.values,t)}}transformDeleteQuery(e,t){return{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{kind:`ReturningNode`,selections:this.transformNodeList(e.selections,t)}}transformCreateTable(e,t){return{kind:`CreateTableNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),constraints:this.transformNodeList(e.constraints,t),indexes:this.transformNodeList(e.indexes,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{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{kind:`AddColumnNode`,column:this.transformNode(e.column,t)}}transformDropTable(e,t){return{kind:`DropTableNode`,table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade,temporary:e.temporary}}transformOrderBy(e,t){return{kind:`OrderByNode`,items:this.transformNodeList(e.items,t)}}transformOrderByItem(e,t){return{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{kind:`GroupByNode`,items:this.transformNodeList(e.items,t)}}transformGroupByItem(e,t){return{kind:`GroupByItemNode`,groupBy:this.transformNode(e.groupBy,t)}}transformUpdateQuery(e,t){return{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{kind:`ColumnUpdateNode`,column:this.transformNode(e.column,t),value:this.transformNode(e.value,t)}}transformLimit(e,t){return{kind:`LimitNode`,limit:this.transformNode(e.limit,t)}}transformOffset(e,t){return{kind:`OffsetNode`,offset:this.transformNode(e.offset,t)}}transformOnConflict(e,t){return{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{kind:`OnDuplicateKeyNode`,updates:this.transformNodeList(e.updates,t)}}transformCreateIndex(e,t){return{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{kind:`ListNode`,items:this.transformNodeList(e.items,t)}}transformDropIndex(e,t){return{kind:`DropIndexNode`,name:this.transformNode(e.name,t),table:this.transformNode(e.table,t),ifExists:e.ifExists,cascade:e.cascade}}transformPrimaryKeyConstraint(e,t){return{kind:`PrimaryKeyConstraintNode`,columns:this.transformNodeList(e.columns,t),name:this.transformNode(e.name,t),deferrable:e.deferrable,initiallyDeferred:e.initiallyDeferred}}transformUniqueConstraint(e,t){return{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{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{kind:`SetOperationNode`,operator:e.operator,expression:this.transformNode(e.expression,t),all:e.all}}transformReferences(e,t){return{kind:`ReferencesNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t),onDelete:e.onDelete,onUpdate:e.onUpdate}}transformCheckConstraint(e,t){return{kind:`CheckConstraintNode`,expression:this.transformNode(e.expression,t),name:this.transformNode(e.name,t)}}transformWith(e,t){return{kind:`WithNode`,expressions:this.transformNodeList(e.expressions,t),recursive:e.recursive}}transformCommonTableExpression(e,t){return{kind:`CommonTableExpressionNode`,name:this.transformNode(e.name,t),materialized:e.materialized,expression:this.transformNode(e.expression,t)}}transformCommonTableExpressionName(e,t){return{kind:`CommonTableExpressionNameNode`,table:this.transformNode(e.table,t),columns:this.transformNodeList(e.columns,t)}}transformHaving(e,t){return{kind:`HavingNode`,having:this.transformNode(e.having,t)}}transformCreateSchema(e,t){return{kind:`CreateSchemaNode`,schema:this.transformNode(e.schema,t),ifNotExists:e.ifNotExists}}transformDropSchema(e,t){return{kind:`DropSchemaNode`,schema:this.transformNode(e.schema,t),ifExists:e.ifExists,cascade:e.cascade}}transformAlterTable(e,t){return{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{kind:`DropColumnNode`,column:this.transformNode(e.column,t),ifExists:e.ifExists}}transformRenameColumn(e,t){return{kind:`RenameColumnNode`,column:this.transformNode(e.column,t),renameTo:this.transformNode(e.renameTo,t)}}transformAlterColumn(e,t){return{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{kind:`ModifyColumnNode`,column:this.transformNode(e.column,t)}}transformAddConstraint(e,t){return{kind:`AddConstraintNode`,constraint:this.transformNode(e.constraint,t)}}transformDropConstraint(e,t){return{kind:`DropConstraintNode`,constraintName:this.transformNode(e.constraintName,t),ifExists:e.ifExists,modifier:e.modifier}}transformRenameConstraint(e,t){return{kind:`RenameConstraintNode`,oldName:this.transformNode(e.oldName,t),newName:this.transformNode(e.newName,t)}}transformCreateView(e,t){return{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{kind:`RefreshMaterializedViewNode`,name:this.transformNode(e.name,t),concurrently:e.concurrently,withNoData:e.withNoData}}transformDropView(e,t){return{kind:`DropViewNode`,name:this.transformNode(e.name,t),ifExists:e.ifExists,materialized:e.materialized,cascade:e.cascade}}transformGenerated(e,t){return{kind:`GeneratedNode`,byDefault:e.byDefault,always:e.always,identity:e.identity,stored:e.stored,expression:this.transformNode(e.expression,t)}}transformDefaultValue(e,t){return{kind:`DefaultValueNode`,defaultValue:this.transformNode(e.defaultValue,t)}}transformOn(e,t){return{kind:`OnNode`,on:this.transformNode(e.on,t)}}transformSelectModifier(e,t){return{kind:`SelectModifierNode`,modifier:e.modifier,rawModifier:this.transformNode(e.rawModifier,t),of:this.transformNodeList(e.of,t)}}transformCreateType(e,t){return{kind:`CreateTypeNode`,name:this.transformNode(e.name,t),enum:this.transformNode(e.enum,t)}}transformDropType(e,t){return{kind:`DropTypeNode`,name:this.transformNode(e.name,t),additionalNames:this.transformNodeList(e.additionalNames,t),cascade:e.cascade,ifExists:e.ifExists}}transformExplain(e,t){return{kind:`ExplainNode`,format:e.format,options:this.transformNode(e.options,t)}}transformSchemableIdentifier(e,t){return{kind:`SchemableIdentifierNode`,schema:this.transformNode(e.schema,t),identifier:this.transformNode(e.identifier,t)}}transformAggregateFunction(e,t){return{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{kind:`OverNode`,orderBy:this.transformNode(e.orderBy,t),partitionBy:this.transformNode(e.partitionBy,t)}}transformPartitionBy(e,t){return{kind:`PartitionByNode`,items:this.transformNodeList(e.items,t)}}transformPartitionByItem(e,t){return{kind:`PartitionByItemNode`,partitionBy:this.transformNode(e.partitionBy,t)}}transformBinaryOperation(e,t){return{kind:`BinaryOperationNode`,leftOperand:this.transformNode(e.leftOperand,t),operator:this.transformNode(e.operator,t),rightOperand:this.transformNode(e.rightOperand,t)}}transformUnaryOperation(e,t){return{kind:`UnaryOperationNode`,operator:this.transformNode(e.operator,t),operand:this.transformNode(e.operand,t)}}transformUsing(e,t){return{kind:`UsingNode`,tables:this.transformNodeList(e.tables,t)}}transformFunction(e,t){return{kind:`FunctionNode`,func:e.func,arguments:this.transformNodeList(e.arguments,t)}}transformCase(e,t){return{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{kind:`WhenNode`,condition:this.transformNode(e.condition,t),result:this.transformNode(e.result,t)}}transformJSONReference(e,t){return{kind:`JSONReferenceNode`,reference:this.transformNode(e.reference,t),traversal:this.transformNode(e.traversal,t)}}transformJSONPath(e,t){return{kind:`JSONPathNode`,inOperator:this.transformNode(e.inOperator,t),pathLegs:this.transformNodeList(e.pathLegs,t)}}transformJSONPathLeg(e,t){return{kind:`JSONPathLegNode`,type:e.type,value:e.value}}transformJSONOperatorChain(e,t){return{kind:`JSONOperatorChainNode`,operator:this.transformNode(e.operator,t),values:this.transformNodeList(e.values,t)}}transformTuple(e,t){return{kind:`TupleNode`,values:this.transformNodeList(e.values,t)}}transformMergeQuery(e,t){return{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{kind:`MatchedNode`,not:e.not,bySource:e.bySource}}transformAddIndex(e,t){return{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{kind:`CastNode`,expression:this.transformNode(e.expression,t),dataType:this.transformNode(e.dataType,t)}}transformFetch(e,t){return{kind:`FetchNode`,rowCount:this.transformNode(e.rowCount,t),modifier:e.modifier}}transformTop(e,t){return{kind:`TopNode`,expression:e.expression,modifiers:e.modifiers}}transformOutput(e,t){return{kind:`OutputNode`,selections:this.transformNodeList(e.selections,t)}}transformAlterType(e,t){return{kind:`AlterTypeNode`,name:this.transformNode(e.name,t),addValue:this.transformNode(e.addValue,t),renameTo:this.transformNode(e.renameTo,t),renameValue:this.transformNode(e.renameValue,t),setSchema:this.transformNode(e.setSchema,t)}}transformAddValue(e,t){return{kind:`AddValueNode`,value:this.transformNode(e.value,t),ifNotExists:e.ifNotExists,isBefore:e.isBefore,neighborValue:this.transformNode(e.neighborValue,t)}}transformRenameValue(e,t){return{kind:`RenameValueNode`,oldValue:this.transformNode(e.oldValue,t),newValue:this.transformNode(e.newValue,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}};function Zt(e){return n(e)&&r(e.kind)}const Qt={AlterTableNode:!0,AlterTypeNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,RefreshMaterializedViewNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0};function $t(e){return Zt(e)&&Qt[e.kind]===!0}const en=a({json_agg:!0,to_json:!0});var tn=class extends Xt{#e;#t=/* @__PURE__ */ new Set;#n=/* @__PURE__ */ new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!$t(e))return super.transformNodeImpl(e,t);let n=this.#a(e);for(let e of n)this.#n.add(e);let r=this.#i(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:f.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:_.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`)}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map(e=>_.is(e)&&!e.table.schema?{...e,table:this.transformIdentifier(e.table.identifier,t)}:this.transformNode(e,t))}}#r(e,t,n){return en[e.func]?e[n].map(e=>!_.is(e)||e.table.schema?this.transformNode(e,t):{...e,table:this.transformIdentifier(e.table.identifier,t)}):this.transformNodeList(e[n],t)}#i(e){let t=/* @__PURE__ */ new Set;if(`name`in e&&e.name&&u.is(e.name)&&this.#s(e.name,t),`from`in e&&e.from)for(let n of e.from.froms)this.#o(n,t);if(`into`in e&&e.into&&this.#o(e.into,t),`table`in e&&e.table&&this.#o(e.table,t),`joins`in e&&e.joins)for(let n of e.joins)this.#o(n.table,t);return`using`in e&&e.using&&(S.is(e.using)?this.#o(e.using.table,t):this.#o(e.using,t)),t}#a(e){let t=/* @__PURE__ */ new Set;return`with`in e&&e.with&&this.#c(e.with,t),t}#o(e,t){if(_.is(e))return this.#s(e.table,t);if(g.is(e)&&_.is(e.node))return this.#s(e.node.table,t);if($e.is(e)){for(let n of e.items)this.#o(n,t);return}if(tt.is(e)){for(let n of e.tables)this.#o(n,t);return}}#s(e,t){let n=e.identifier.name;!this.#t.has(n)&&!this.#n.has(n)&&t.add(n)}#c(e,t){for(let n of e.expressions){let e=n.name.table.table.identifier.name;this.#n.has(e)||t.add(e)}}},nn=class{#e;constructor(e){this.#e=new tn(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};const rn=a({is(e){return e.kind===`MatchedNode`},create(e,t=!1){return a({kind:`MatchedNode`,not:e,bySource:t})}});function an(e,t,n){return p.create(He([rn.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 on(e){return r(e)?h.create([e],[]):v(e)?e.toOperationNode():e}var sn=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?.(e),this.#t=this.#n=void 0};reject=e=>{this.#n?.(e),this.#n=this.#t=void 0}};async function cn(e,t){let n=new sn,r=new sn;return e.provideConnection(async e=>(n.resolve(e),await r.promise),t).catch(e=>n.reject(e)),a({connection:await n.promise,release:r.resolve})}function ln(e=`ignore query`,t,n){if(e!==`ignore query`){if(e===`cancel query`){let r=t.cancelQuery;return r||(n(),un(e,t.killSession?`kill session`:void 0)),r.bind(t)}if(e===`kill session`){let r=t.killSession;return r||(n(),un(e,t.cancelQuery?`cancel query`:void 0)),r.bind(t)}throw n(),Error(`Unexpected \`inflightQueryAbortStrategy\`: "${e}"`)}}function un(e,t){throw Error(`This dialect doesn't support \`inflightQueryAbortStrategy\` "${e}". Use "ignore query"${t?` or "${t}"`:``} instead.`)}function U(e,t,n){e?.aborted&&(n?.(),W(e.reason,t))}function W(e,t){throw fn(e,t),e}const G={};async function dn(e,t,n,r){if(!t)return e;U(t,`before ${n}`,r);let{promise:i,resolve:a}=new sn,o=()=>a(G);t.addEventListener(`abort`,o);try{U(t,`before ${n}`,r);let a=await Promise.race([e,i]);if(a!==G)return a;r?.(),W(t.reason,`during ${n}`)}finally{t.removeEventListener(`abort`,o),a(G)}}function K(e){return t=>console.error(`\`${e}\` failed in the background after abortion: ${ie(t)}`)}function fn(e,t){typeof e==`object`&&e&&!Object.isFrozen(e)&&Object.defineProperty(e,"__kysely_timing__",{configurable:!0,enumerable:!1,value:t,writable:!1})}const pn=a([]);var mn=class{#e;constructor(e=pn){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,t){let{inflightQueryAbortStrategy:n=`ignore query`,signal:r}=t||{};if(!r){let n=await this.provideConnection(async t=>await t.executeQuery(e),t);return await this.#t(n,e.queryId)}U(r,`before query execution`),t=a({signal:r});let{connection:i,release:o}=await cn(this,t),s=this.provideConnection.bind(this),{promise:c,resolve:l}=new sn,u=()=>l(G);r.addEventListener(`abort`,u,{once:!0});try{U(r,`before query execution`,o);let a=ln(n,i,o);if(a&&i.collectSessionInfo){U(r,`before query execution`,o);let e=i.collectSessionInfo();await Promise.race([c,e]).catch(e=>{throw o(),e})===G&&(e.catch(K(`collectSessionInfo`)).finally(o),W(r.reason,`before query execution`))}let l=i.executeQuery(e,t),u=await Promise.race([c,l]).catch(e=>{throw o(),e});u===G?(Promise.allSettled([l.catch(K(`query`)),a?.(s).catch(K(`inflightQueryAbortHandler`))]).finally(o),W(r.reason,`during query execution`)):o();let d=this.#t(u,e.queryId,t),f=await Promise.race([c,d]);return f===G&&(d.catch(K(`plugins.transformResult`)),W(r.reason,`during result transformation`)),f}finally{l(G),r.removeEventListener(`abort`,u)}}async*stream(e,t,n){let{signal:r}=n||{};if(!r){let{connection:r,release:i}=await cn(this);try{for await(let i of r.streamQuery(e,t))yield await this.#t(i,e.queryId,n)}finally{i()}return}n=a({signal:r}),U(r,`before connection acquisition`);let{connection:i,release:o}=await cn(this,n),{promise:s,resolve:c}=new sn,l=()=>c(G);r.addEventListener(`abort`,l,{once:!0});let u,d;U(r,`before query streaming`,o);let{queryId:f}=e;try{for(u=i.streamQuery(e,t,n);;){U(r,`during query streaming`);let e=u.next(),t=await Promise.race([s,e]);if(t===G&&(d=e.catch(K(`iterator.next`)),W(r.reason,`during query streaming`)),t.done)break;let i=this.#t(t.value,f,n),a=await Promise.race([s,i]);a===G&&(d=i.catch(K(`plugins.transformResult`)),W(r.reason,`during result transformation`)),yield a}}finally{c(G),r.removeEventListener(`abort`,l);let e=(u?.return?.()||Promise.resolve()).finally(()=>d).finally(o);d||await e}}async#t(e,t,n){let{signal:r}=n||{};for(let n of this.#e)e=await n.transformResult(a({queryId:t,result:e,signal:r}));return e}};const hn=new class e extends mn{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 gn=class{numChangedRows;constructor(e){this.numChangedRows=e}},_n=class e{#e;constructor(e){this.#e=a(e)}modifyEnd(t){return new e({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(t,n))})}using(...e){return new vn({...this.#e,queryNode:P.cloneWithUsing(this.#e.queryNode,Tn(`Using`,e))})}returning(t){return new e({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,L(t))})}returningAll(t){return new e({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,R(t))})}output(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,L(t))})}outputAll(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,R(t))})}},vn=class e{#e;constructor(e){this.#e=a(e)}modifyEnd(t){return new e({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(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 yn({...this.#e,queryNode:P.cloneWithWhen(this.#e.queryNode,an({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:F.cloneWithReturning(this.#e.queryNode,L(t))})}returningAll(t){return new e({...this.#e,queryNode:F.cloneWithReturning(this.#e.queryNode,R(t))})}output(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,L(t))})}outputAll(t){return new e({...this.#e,queryNode:F.cloneWithOutput(this.#e.queryNode,R(t))})}#n(e,t=!1,n=!1){let r={...this.#e,queryNode:P.cloneWithWhen(this.#e.queryNode,an({isMatched:!1,bySource:n},e,t))};return new(n?yn:bn)(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(e){let t=this.compile(),n=await this.#e.executor.executeQuery(t,e),{adapter:r}=this.#e.executor,i=t.query;return i.returning&&r.supportsReturning||i.output&&r.supportsOutput?n.rows:[new gn(n.numAffectedRows)]}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){typeof e==`function`&&(e={errorConstructor:e});let t=await this.executeTakeFirst(e);if(t===void 0){let t=e?.errorConstructor??wt;throw Tt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}},yn=class{#e;constructor(e){this.#e=a(e)}thenDelete(){return new vn({...this.#e,queryNode:P.cloneWithThen(this.#e.queryNode,on(`delete`))})}thenDoNothing(){return new vn({...this.#e,queryNode:P.cloneWithThen(this.#e.queryNode,on(`do nothing`))})}thenUpdate(e){return new vn({...this.#e,queryNode:P.cloneWithThen(this.#e.queryNode,on(e(new Rt({queryId:this.#e.queryId,executor:hn,queryNode:et.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},bn=class{#e;constructor(e){this.#e=a(e)}thenDoNothing(){return new vn({...this.#e,queryNode:P.cloneWithThen(this.#e.queryNode,on(`do nothing`))})}thenInsertValues(e){let[t,n]=ht(e);return new vn({...this.#e,queryNode:P.cloneWithThen(this.#e.queryNode,on(o.cloneWith(o.createWithoutInto(),{columns:t,values:n})))})}},xn=class e{#e;constructor(e){this.#e=a(e)}selectFrom(e){return zn({queryId:H(),executor:this.#e.executor,queryNode:I.createFrom(_r(e),this.#e.withNode)})}selectNoFrom(e){return zn({queryId:H(),executor:this.#e.executor,queryNode:I.cloneWithSelections(I.create(this.#e.withNode),L(e))})}insertInto(e){return new Nt({queryId:H(),executor:this.#e.executor,queryNode:o.create(Q(e),this.#e.withNode)})}replaceInto(e){return new Nt({queryId:H(),executor:this.#e.executor,queryNode:o.create(Q(e),this.#e.withNode,!0)})}deleteFrom(e){return new It({queryId:H(),executor:this.#e.executor,queryNode:nt.create(_r(e),this.#e.withNode)})}updateTable(e){return new Rt({queryId:H(),executor:this.#e.executor,queryNode:et.create(_r(e),this.#e.withNode)})}mergeInto(e){return new _n({queryId:H(),executor:this.#e.executor,queryNode:P.create(yr(e),this.#e.withNode)})}with(t,n){let r=Ht(t,n);return new e({...this.#e,withNode:this.#e.withNode?Gt.cloneWithExpression(this.#e.withNode,r):Gt.create(r)})}withRecursive(t,n){let r=Ht(t,n);return new e({...this.#e,withNode:this.#e.withNode?Gt.cloneWithExpression(this.#e.withNode,r):Gt.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 nn(t))})}};function Sn(){return new xn({executor:hn})}function Cn(e,t){return new ot({joinNode:S.create(e,vr(t))})}function wn(){return new lt({overNode:Ye.create()})}function Tn(e,t){if(t.length===3)return Dn(e,t[0],t[1],t[2]);if(t.length===2)return En(e,t[0],t[1]);if(t.length===1)return On(e,t[0]);throw Error(`not implemented`)}function En(e,t,n){return n(Cn(e,t)).toOperationNode()}function Dn(e,t,n,r){return S.createWithOn(e,vr(t),M(n,`=`,r))}function On(e,t){return S.create(e,vr(t))}const kn=a({is(e){return e.kind===`OffsetNode`},create(e){return a({kind:`OffsetNode`,offset:e})}}),An=a({is(e){return e.kind===`GroupByItemNode`},create(e){return a({kind:`GroupByItemNode`,groupBy:e})}});function jn(t){return t=e(t)?t(ur()):t,Ee(t).map(An.create)}function q(n,r,i){return e(r)&&(r=r(lr())),t(r)||(r=[r]),r.map(e=>ne.create(n,dr(e),i))}var J=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Mn(this,e)}or(...e){return new Nn(x.create(this.#e,j(e)))}and(...e){return new Pn(b.create(this.#e,j(e)))}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},Mn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return g.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():f.create(this.#t))}},Nn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Mn(this,e)}or(...t){return new e(x.create(this.#e,j(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return te.create(this.#e)}},Pn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Mn(this,e)}and(...t){return new e(b.create(this.#e,j(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return te.create(this.#e)}};const Fn=a({is(e){return e.kind===`FetchNode`},create(e,t){return{kind:`FetchNode`,rowCount:k.create(e),modifier:t}}});function In(e,t){if(!i(e)&&!oe(e))throw Error(`Invalid fetch row count: ${e}`);if(!Ln(t))throw Error(`Invalid fetch modifier: ${t}`);return Fn.create(e,t)}function Ln(e){return e===`only`||e===`with ties`}var Y,Rn=class{#e;constructor(e){this.#e=a(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new Y({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,j(e))})}whereRef(e,t,n){return new Y({...this.#e,queryNode:F.cloneWithWhere(this.#e.queryNode,M(e,t,n))})}having(...e){return new Y({...this.#e,queryNode:I.cloneWithHaving(this.#e.queryNode,j(e))})}havingRef(e,t,n){return new Y({...this.#e,queryNode:I.cloneWithHaving(this.#e.queryNode,M(e,t,n))})}select(e){return new Y({...this.#e,queryNode:I.cloneWithSelections(this.#e.queryNode,L(e))})}distinctOn(e){return new Y({...this.#e,queryNode:I.cloneWithDistinctOn(this.#e.queryNode,Ee(e))})}modifyFront(e){return new Y({...this.#e,queryNode:I.cloneWithFrontModifier(this.#e.queryNode,y.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.createWithExpression(e.toOperationNode()))})}distinct(){return new Y({...this.#e,queryNode:I.cloneWithFrontModifier(this.#e.queryNode,y.create(`Distinct`))})}forUpdate(e){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`ForUpdate`,e?d(e).map(Q):void 0))})}forShare(e){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`ForShare`,e?d(e).map(Q):void 0))})}forKeyShare(e){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`ForKeyShare`,e?d(e).map(Q):void 0))})}forNoKeyUpdate(e){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`ForNoKeyUpdate`,e?d(e).map(Q):void 0))})}skipLocked(){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`SkipLocked`))})}noWait(){return new Y({...this.#e,queryNode:F.cloneWithEndModifier(this.#e.queryNode,y.create(`NoWait`))})}selectAll(e){return new Y({...this.#e,queryNode:I.cloneWithSelections(this.#e.queryNode,R(e))})}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(e,t){return new Y({...this.#e,queryNode:F.cloneWithJoin(this.#e.queryNode,Tn(e,t))})}orderBy(...e){return new Y({...this.#e,queryNode:F.cloneWithOrderByItems(this.#e.queryNode,E(e))})}groupBy(e){return new Y({...this.#e,queryNode:I.cloneWithGroupByItems(this.#e.queryNode,jn(e))})}limit(e){return new Y({...this.#e,queryNode:I.cloneWithLimit(this.#e.queryNode,Ft.create(A(e)))})}offset(e){return new Y({...this.#e,queryNode:I.cloneWithOffset(this.#e.queryNode,kn.create(A(e)))})}fetch(e,t=`only`){return new Y({...this.#e,queryNode:I.cloneWithFetch(this.#e.queryNode,In(e,t))})}top(e,t){return new Y({...this.#e,queryNode:F.cloneWithTop(this.#e.queryNode,At(e,t))})}union(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`union`,e,!1))})}unionAll(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`union`,e,!0))})}intersect(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`intersect`,e,!1))})}intersectAll(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`intersect`,e,!0))})}except(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`except`,e,!1))})}exceptAll(e){return new Y({...this.#e,queryNode:I.cloneWithSetOperations(this.#e.queryNode,q(`except`,e,!0))})}as(e){return new Bn(this,e)}clearSelect(){return new Y({...this.#e,queryNode:I.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new Y({...this.#e,queryNode:F.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new Y({...this.#e,queryNode:I.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new Y({...this.#e,queryNode:I.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new Y({...this.#e,queryNode:F.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new Y({...this.#e,queryNode:I.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new Y({...this.#e})}$castTo(){return new Y(this.#e)}$narrowType(){return new Y(this.#e)}$assertType(){return new Y(this.#e)}$asTuple(){return new J(this.toOperationNode())}$asScalar(){return new J(this.toOperationNode())}withPlugin(e){return new Y({...this.#e,executor:this.#e.executor.withPlugin(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(e){let t=this.compile();return(await this.#e.executor.executeQuery(t,e)).rows}async executeTakeFirst(e){let[t]=await this.execute(e);return t}async executeTakeFirstOrThrow(e){typeof e==`function`&&(e={errorConstructor:e});let t=await this.executeTakeFirst(e);if(t===void 0){let t=e?.errorConstructor??wt;throw Tt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}async*stream(e){typeof e!=`object`&&(e={chunkSize:e});let t=this.compile(),n=this.#e.executor.stream(t,e.chunkSize??100,e);for await(let e of n)yield*e.rows}async explain(e,t){return await new Y({...this.#e,queryNode:F.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};Y=Rn;function zn(e){return new Rn(e)}var Bn=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 g.create(this.#e.toOperationNode(),f.create(this.#t))}};const X=a({is(e){return e.kind===`AggregateFunctionNode`},create(e,t=[]){return a({kind:`AggregateFunctionNode`,func:e,aggregated:t})},cloneWithDistinct(e){return a({...e,distinct:!0})},cloneWithOrderBy(e,t,n=!1){let r=n?`withinGroup`:`orderBy`;return a({...e,[r]:e[r]?qe.cloneWithItems(e[r],t):qe.create(t)})},cloneWithFilter(e,t){return a({...e,filter:e.filter?N.cloneWithOperation(e.filter,`And`,t):N.create(t)})},cloneWithOrFilter(e,t){return a({...e,filter:e.filter?N.cloneWithOperation(e.filter,`Or`,t):N.create(t)})},cloneWithOver(e,t){return a({...e,over:t})}}),Vn=a({is(e){return e.kind===`FunctionNode`},create(e,t){return a({kind:`FunctionNode`,func:e,arguments:t})}});var Hn=class e{#e;constructor(e){this.#e=a(e)}get expressionType(){}as(e){return new Un(this,e)}distinct(){return new e({...this.#e,aggregateFunctionNode:X.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...t){return new e({...this.#e,aggregateFunctionNode:F.cloneWithOrderByItems(this.#e.aggregateFunctionNode,E(t))})}clearOrderBy(){return new e({...this.#e,aggregateFunctionNode:F.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...t){return new e({...this.#e,aggregateFunctionNode:X.cloneWithOrderBy(this.#e.aggregateFunctionNode,E(t),!0)})}filterWhere(...t){return new e({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,j(t))})}filterWhereRef(t,n,r){return new e({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,M(t,n,r))})}over(t){let n=wn();return new e({...this.#e,aggregateFunctionNode:X.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}},Un=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return g.create(this.#e.toOperationNode(),f.create(this.#t))}};function Wn(){let e=(e,t)=>new J(Vn.create(e,Ee(t??[]))),t=(e,t)=>new Hn({aggregateFunctionNode:X.create(e,t?Ee(t):void 0)});return Object.assign(e,{agg:t,avg(e){return t(`avg`,[e])},coalesce(...t){return e(`coalesce`,t)},count(e){return t(`count`,[e])},countAll(e){return new Hn({aggregateFunctionNode:X.create(`count`,R(e))})},max(e){return t(`max`,[e])},min(e){return t(`min`,[e])},sum(e){return t(`sum`,[e])},any(t){return e(`any`,[t])},jsonAgg(e){return new Hn({aggregateFunctionNode:X.create(`json_agg`,[r(e)?Q(e):e.toOperationNode()])})},toJson(e){return new J(Vn.create(`to_json`,[r(e)?Q(e):e.toOperationNode()]))}})}const Gn=a({is(e){return e.kind===`UnaryOperationNode`},create(e,t){return a({kind:`UnaryOperationNode`,operator:e,operand:t})}});function Kn(e,t){if(l(e))return Gn.create(c.create(e),D(t));throw Error(`invalid unary operator ${JSON.stringify(e)}`)}const Z=a({is(e){return e.kind===`CaseNode`},create(e){return a({kind:`CaseNode`,value:e})},cloneWithWhen(e,t){return a({...e,when:a(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return a({...e,when:e.when?a([...e.when.slice(0,-1),p.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return a({...e,...t})}});var qn=class{#e;constructor(e){this.#e=a(e)}when(...e){return new Jn({...this.#e,node:Z.cloneWithWhen(this.#e.node,p.create(j(e)))})}whenRef(e,t,n){return new Jn({...this.#e,node:Z.cloneWithWhen(this.#e.node,p.create(M(e,t,n)))})}},Jn=class{#e;constructor(e){this.#e=a(e)}then(e){return new Yn({...this.#e,node:Z.cloneWithThen(this.#e.node,Le(e)?Re(e):A(e))})}thenRef(e){return new Yn({...this.#e,node:Z.cloneWithThen(this.#e.node,D(e))})}},Yn=class{#e;constructor(e){this.#e=a(e)}when(...e){return new Jn({...this.#e,node:Z.cloneWithWhen(this.#e.node,p.create(j(e)))})}whenRef(e,t,n){return new Jn({...this.#e,node:Z.cloneWithWhen(this.#e.node,p.create(M(e,t,n)))})}else(e){return new Xn({...this.#e,node:Z.cloneWith(this.#e.node,{else:Le(e)?Re(e):A(e)})})}elseRef(e){return new Xn({...this.#e,node:Z.cloneWith(this.#e.node,{else:D(e)})})}end(){return new J(Z.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new J(Z.cloneWith(this.#e.node,{isStatement:!0}))}},Xn=class{#e;constructor(e){this.#e=a(e)}end(){return new J(Z.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new J(Z.cloneWith(this.#e.node,{isStatement:!0}))}};const Zn=a({is(e){return e.kind===`JSONPathLegNode`},create(e,t){return a({kind:`JSONPathLegNode`,type:e,value:t})}}),Qn=/^#-\d+$/;var $n=class{#e;constructor(e){this.#e=e}at(e){if(typeof e!=`number`&&typeof e!=`string`||typeof e==`number`&&!Number.isInteger(e)||typeof e==`string`&&e!==`last`&&!Qn.test(e))throw Error(`Unexpected index value in .at(...): ${e}`);return this.#t(`ArrayLocation`,e)}key(e){return this.#t(`Member`,e)}#t(e,t){return Se.is(this.#e)?new er(Se.cloneWithTraversal(this.#e,we.is(this.#e.traversal)?we.cloneWithLeg(this.#e.traversal,Zn.create(e,t)):Ce.cloneWithValue(this.#e.traversal,k.createImmediate(t)))):new er(we.cloneWithLeg(this.#e,Zn.create(e,t)))}},er=class e extends $n{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new tr(this,e)}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},tr=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return g.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():f.create(this.#t))}};const nr=a({is(e){return e.kind===`TupleNode`},create(e){return a({kind:`TupleNode`,values:a(e)})}}),rr=a({bigint:!0,bigserial:!0,binary:!0,blob:!0,boolean:!0,bytea:!0,char:!0,date:!0,datemultirange:!0,daterange:!0,datetime:!0,datetime2:!0,decimal:!0,"double precision":!0,float4:!0,float8:!0,int2:!0,int4:!0,int4multirange:!0,int4range:!0,int8:!0,int8multirange:!0,int8range:!0,integer:!0,json:!0,jsonb:!0,numeric:!0,nummultirange:!0,numrange:!0,real:!0,serial:!0,smallint:!0,text:!0,time:!0,timestamp:!0,timestamptz:!0,timetz:!0,tsmultirange:!0,tsrange:!0,tstzmultirange:!0,tstzrange:!0,uuid:!0,varbinary:!0,varchar:!0}),ir=a([/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^datetime2\(\d+\)$/,/^varbinary\(\d+\)$/]),ar=a({is(e){return e.kind===`DataTypeNode`},create(e){return a({kind:`DataTypeNode`,dataType:e})}});function or(e){return rr[e]||ir.some(t=>t.test(e))}function sr(e){if(v(e))return e.toOperationNode();if(or(e))return ar.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}const cr=a({is(e){return e.kind===`CastNode`},create(e,t){return a({kind:`CastNode`,expression:e,dataType:t})}});function lr(e=hn){function n(e,t,n){return new J(Be(e,t,n))}function r(e,t){return new J(Kn(e,t))}let i=Object.assign(n,{fn:void 0,eb:void 0,selectFrom(t){return zn({queryId:H(),executor:e,queryNode:I.createFrom(_r(t))})},case(e){return new qn({node:Z.create(m(e)?void 0:D(e))})},ref(e,t){return m(t)?new J(O(e)):new $n(De(e,t))},jsonPath(){return new $n(we.create())},table(e){return new J(Q(e))},val(e){return new J(A(e))},refTuple(...e){return new J(nr.create(e.map(D)))},tuple(...e){return new J(nr.create(e.map(A)))},lit(e){return new J(Re(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 J(C.create(D(e),c.create(`between`),b.create(A(t),A(n))))},betweenSymmetric(e,t,n){return new J(C.create(D(e),c.create(`between symmetric`),b.create(A(t),A(n))))},and(e){return t(e)?new J(He(e,`and`)):new J(Ve(e,`and`))},or(e){return t(e)?new J(He(e,`or`)):new J(Ve(e,`or`))},parens(...e){let t=j(e);return te.is(t)?new J(t):new J(te.create(t))},cast(e,t){return new J(cr.create(D(e),sr(t)))}});return i.fn=Wn(),i.eb=i,i}function ur(e){return lr()}function dr(t){if(v(t))return t.toOperationNode();if(e(t))return t(ur()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(t)}`)}function fr(t){if(v(t))return t.toOperationNode();if(e(t))return t(ur()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(t)}`)}function pr(t){return se(t)||ce(t)||e(t)}var mr=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new hr(this.#e,e)}},hr=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return g.create(Q(this.#e),f.create(this.#t))}};function gr(e){return n(e)&&v(e)&&r(e.table)&&r(e.alias)}function _r(e){return t(e)?e.map(e=>vr(e)):[vr(e)]}function vr(e){return r(e)?yr(e):gr(e)?e.toOperationNode():fr(e)}function yr(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(br);return g.create(Q(n),f.create(r))}return Q(e)}function Q(e){if(e.includes(`.`)){let[t,n]=e.split(`.`).map(br);return _.createWithSchema(t,n)}return _.create(e)}function br(e){return e.trim()}var xr=class e{#e;constructor(e){this.#e=a(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Sr(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?a([t]):a([...this.#e.plugins,t])})}toOperationNode(){return this.#n(this.#t())}compile(e){return this.#r(this.#t(e))}async execute(e,t){let n=this.#t(e);return n.executeQuery(this.#r(n),t)}#t(e){let t=e===void 0?hn: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 $(e){return new xr(e)}var Sr=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 g.create(this.#e.toOperationNode(),v(this.#t)?this.#t.toOperationNode():f.create(this.#t))}};const Cr=Object.assign((e,...t)=>$({queryId:H(),rawNode:h.create(e,t?.map(wr)??[])}),{ref(e){return $({queryId:H(),rawNode:h.createWithChild(O(e))})},val(e){return $({queryId:H(),rawNode:h.createWithChild(A(e))})},table(e){return $({queryId:H(),rawNode:h.createWithChild(Q(e))})},id(...e){let t=Array(e.length+1).fill(`.`);return t[0]=``,t[t.length-1]=``,$({queryId:H(),rawNode:h.create(t,e.map(f.create))})},lit(e){return $({queryId:H(),rawNode:h.createWithChild(k.createImmediate(e))})},raw(e){return $({queryId:H(),rawNode:h.createWithSql(e)})},join(e,t=Cr`, `){let n=Array(Math.max(2*e.length-1,0)),r=t.toOperationNode();for(let t=0;t<e.length;++t)n[2*t]=wr(e[t]),t!==e.length-1&&(n[2*t+1]=r);return $({queryId:H(),rawNode:h.createWithChildren(n)})}});function wr(e){return v(e)?e.toOperationNode():A(e)}const Tr=a({raw(e,t=[]){return a({sql:e,query:h.createWithSql(e),parameters:a(t),queryId:H()})}});export{de as A,k as C,O as D,Ae as E,w as M,v as N,_e as O,_ as P,j as S,ke as T,Xt as _,dr as a,I as b,Z as c,mn as d,K as f,nn as g,sn as h,mr as i,ue as j,fe as k,Wn as l,cn as m,Cr as n,sr as o,dn as p,Q as r,qn as s,Tr as t,xn as u,H as v,Fe as w,F as x,qt as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./kysely-migration-tables-DFfmKhq--DIOBV7Sd.mjs";import{n,t as r}from"./sqlite-adapter-BG0MClj_.mjs";function i(e){return`'${e.replaceAll(`'`,`''`)}'`}function a(e){return async t=>{if(t.length===0)return[];let n=(await e.batch(t.map(t=>e.prepare(`PRAGMA index_list(${i(t)})`)))).flatMap((e,n)=>{let r=t[n];return r?e.results.map(e=>({...e,tableName:r})):[]});if(n.length===0)return[];let r=await e.batch(n.map(t=>e.prepare(`PRAGMA index_info(${i(t.name)})`)));return n.map((e,t)=>({columns:(r[t]?.results??[]).map(e=>({fullLength:e.name!==null,name:e.name,position:e.seqno})),name:e.name,partial:e.partial!==0,table:e.tableName,unique:e.unique!==0,valid:!0}))}}var o=class extends r{},s=class{#e;#t;constructor(e){this.#e={...e}}async init(){this.#t=new c(this.#e.database),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#t)}async acquireConnection(){return this.#t}async beginTransaction(){throw Error(`D1 does not support interactive transactions. Use the D1 batch() API instead.`)}async commitTransaction(){throw Error(`D1 does not support interactive transactions. Use the D1 batch() API instead.`)}async rollbackTransaction(){throw Error(`D1 does not support interactive transactions. Use the D1 batch() API instead.`)}async releaseConnection(){}async destroy(){}},c=class{#e;constructor(e){this.#e=e}async executeQuery(e){let t=await this.#e.prepare(e.sql).bind(...e.parameters).all(),n=t.meta.changes==null?void 0:BigInt(t.meta.changes);return{insertId:t.meta.last_row_id===void 0||t.meta.last_row_id===null?void 0:BigInt(t.meta.last_row_id),rows:t?.results||[],numAffectedRows:n}}async*streamQuery(){throw Error(`D1 does not support streaming queries.`)}},l=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}async getSchemas(){return[]}async getTables(n={withInternalKyselyTables:!1}){let r=this.#e.selectFrom(`sqlite_master`).where(`type`,`in`,[`table`,`view`]).where(`name`,`not like`,`sqlite_%`).where(`name`,`not like`,`_cf_%`).select([`name`,`type`,`sql`]).$castTo();n.withInternalKyselyTables||(r=r.where(`name`,`!=`,e).where(`name`,`!=`,t));let i=await r.execute();if(i.length===0)return[];let a=i.map(e=>this.#t.prepare(`SELECT * FROM pragma_table_info(?)`).bind(e.name)),o=await this.#t.batch(a);return i.map((e,t)=>{let n=o[t]?.results??[],r=e.sql?.split(/[(),]/)?.find(e=>e.toLowerCase().includes(`autoincrement`))?.split(/\s+/)?.filter(Boolean)?.[0]?.replace(/["`]/g,``);if(!r){let e=n.filter(e=>e.pk>0),t=e.length===1?e[0]:void 0;t&&t.type.toLowerCase()===`integer`&&(r=t.name)}return{name:e.name,isView:e.type===`view`,columns:n.map(e=>({name:e.name,dataType:e.type,isNullable:!e.notnull,isAutoIncrementing:e.name===r,hasDefaultValue:e.dflt_value!=null}))}})}async getMetadata(e){return{tables:await this.getTables(e)}}},u=class extends n{},d=class{#e;constructor(e){this.#e={...e}}createDriver(){return new s(this.#e)}createQueryCompiler(){return new u}createAdapter(){return new o}createIntrospector(e){return new l(e,this.#e.database)}};export{d as D1SqliteDialect,a as createD1IndexIntrospector};
|
|
@@ -0,0 +1 @@
|
|
|
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 s(e){return typeof Buffer<`u`&&Buffer.isBuffer(e)}function c(e){return typeof e==`function`}function l(e){return typeof e==`object`&&!!e}function u(e){return Object.freeze(e)}function d(e){return f(e)?e:[e]}function f(e){return Array.isArray(e)}function p(e){return e}function m(e){return e instanceof Error?e.message:String(e)}const h=u({is(e){return e.kind===`IdentifierNode`},create(e){return u({kind:`IdentifierNode`,name:e})}}),g=[`preserve rows`,`delete rows`,`drop`],_=u({is(e){return e.kind===`CreateTableNode`},create(e){return u({kind:`CreateTableNode`,table:e,columns:u([])})},cloneWithColumn(e,t){return u({...e,columns:u([...e.columns,t])})},cloneWithConstraint(e,t){return u({...e,constraints:e.constraints?u([...e.constraints,t]):u([t])})},cloneWithIndex(e,t){return u({...e,indexes:e.indexes?u([...e.indexes,t]):u([t])})},cloneWithFrontModifier(e,t){return u({...e,frontModifiers:e.frontModifiers?u([...e.frontModifiers,t]):u([t])})},cloneWithEndModifier(e,t){return u({...e,endModifiers:e.endModifiers?u([...e.endModifiers,t]):u([t])})},cloneWith(e,t){return u({...e,...t})}}),v=u({is(e){return e.kind===`SchemableIdentifierNode`},create(e){return u({kind:`SchemableIdentifierNode`,identifier:h.create(e)})},createWithSchema(e,t){return u({kind:`SchemableIdentifierNode`,schema:h.create(e),identifier:h.create(t)})}}),y=u({"=":!0,"==":!0,"!=":!0,"<>":!0,">":!0,">=":!0,"<":!0,"<=":!0,in:!0,"not in":!0,is:!0,"is not":!0,like:!0,"not like":!0,match:!0,ilike:!0,"not ilike":!0,"@>":!0,"<@":!0,"^@":!0,"&&":!0,"?":!0,"?&":!0,"?|":!0,"!<":!0,"!>":!0,"<=>":!0,"!~":!0,"~":!0,"~*":!0,"!~*":!0,"@@":!0,"@@@":!0,"!!":!0,"<->":!0,regexp:!0,"is distinct from":!0,"is not distinct from":!0});Object.keys(y);const b=u({"+":!0,"-":!0,"*":!0,"/":!0,"%":!0,"^":!0,"&":!0,"|":!0,"#":!0,"<<":!0,">>":!0});Object.keys(b);const x=u({"->":!0,"->>":!0}),S=Object.keys(x),C=u({...y,...b,"||":!0}),w=Object.keys(C),T=u({exists:!0,"not exists":!0});Object.keys(T);const E=u({...T,"-":!0,not:!0}),D=Object.keys(E);[...w,...S,...D];const O=u({is(e){return e.kind===`OperatorNode`},create(e){return u({kind:`OperatorNode`,operator:e})}});function k(e){return t(e)&&C[e]}function A(e){return t(e)&&x[e]}function j(e){return t(e)&&E[e]}const M=u({is(e){return e.kind===`RawNode`},create(e,t){return u({kind:`RawNode`,sqlFragments:u(e),parameters:u(t)})},createWithSql(e){return M.create([e],[])},createWithChild(e){return M.create([``,``],[e])},createWithChildren(e){return M.create(Array(e.length+1).fill(``),e)}}),N=u({is(e){return e.kind===`ParensNode`},create(e){return u({kind:`ParensNode`,node:e})}}),P=u({is(e){return e.kind===`InsertQueryNode`},create(e,t,n){return u({kind:`InsertQueryNode`,into:e,...t&&{with:t},replace:n})},createWithoutInto(){return u({kind:`InsertQueryNode`})},cloneWith(e,t){return u({...e,...t})}}),F=u({is(e){return e.kind===`WhenNode`},create(e){return u({kind:`WhenNode`,condition:e})},cloneWithResult(e,t){return u({...e,result:t})}}),I=u({is(e){return e.kind===`SetOperationNode`},create(e,t,n){return u({kind:`SetOperationNode`,operator:e,expression:t,all:n})}}),L=u({is(e){return e.kind===`CreateViewNode`},create(e){return u({kind:`CreateViewNode`,name:v.create(e)})},cloneWith(e,t){return u({...e,...t})}});var R=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=u({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),AlterTypeNode:this.visitAlterType.bind(this),AddValueNode:this.visitAddValue.bind(this),RenameValueNode:this.visitRenameValue.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};const z=/'/g,B=/['"]/g;var V=class extends R{#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),u({query:e,queryId:t,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let t=this.parentNode!==void 0&&!N.is(this.parentNode)&&!P.is(this.parentNode)&&!_.is(this.parentNode)&&!L.is(this.parentNode)&&!I.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&&!N.is(this.parentNode)&&!M.is(this.parentNode)&&!F.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.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&&!N.is(this.parentNode)&&!M.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.returning&&(this.append(` `),this.visitNode(e.returning)),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),e.limit&&(this.append(` `),this.visitNode(e.limit)),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(W[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?.length&&(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(` (`),this.compileList([...e.columns,...e.constraints??[],...e.indexes??[]]),this.append(`)`)),e.onCommit&&(this.append(` on commit `),this.append(e.onCommit)),e.endModifiers?.length&&(this.append(` `),this.compileList(e.endModifiers,` `)),e.selectQuery&&(this.append(` as `),this.visitNode(e.selectQuery))}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 `),e.temporary&&this.append(`temporary `),this.append(`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&&!N.is(this.parentNode)&&!M.is(this.parentNode)&&!F.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.returning&&(this.append(` `),this.visitNode(e.returning)),e.orderBy&&(this.append(` `),this.visitNode(e.orderBy)),e.limit&&(this.append(` `),this.visitNode(e.limit)),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 `),e.ifExists&&this.append(`if exists `),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(H[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),e.additionalNames?.length&&(this.append(`, `),this.compileList(e.additionalNames)),e.cascade&&this.append(` cascade`)}visitAlterType(e){this.append(`alter type `),this.visitNode(e.name),this.append(` `),e.addValue?this.visitNode(e.addValue):e.renameTo?(this.append(`rename to `),this.visitNode(e.renameTo)):e.renameValue?this.visitNode(e.renameValue):e.setSchema&&(this.append(`set schema `),this.visitNode(e.setSchema))}visitAddValue(e){this.append(`add value `),e.ifNotExists&&this.append(`if not exists `),this.visitNode(e.value),e.neighborValue&&(this.append(e.isBefore?` before `:` after `),this.visitNode(e.neighborValue))}visitRenameValue(e){this.append(`rename value `),this.visitNode(e.oldValue),this.append(` to `),this.visitNode(e.newValue)}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 O.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`,n=String(e.value);t?(this.append(`[`),this.append(this.sanitizeStringLiteral(n)),this.append(`]`)):(this.append(`."`),this.append(this.sanitizeJSONPathMemberValue(n)),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.parentNode||!_.is(this.parentNode))&&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(z,`''`)}sanitizeJSONPathMemberValue(e){return e.replace(B,e=>e===`'`?`''`:`\\"`)}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 u(e.toSorted((e,t)=>e.modifier&&t.modifier?U[e.modifier]-U[t.modifier]:1))}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}};const H=u({ForKeyShare:`for key share`,ForNoKeyUpdate:`for no key update`,ForUpdate:`for update`,ForShare:`for share`,NoWait:`nowait`,SkipLocked:`skip locked`,Distinct:`distinct`}),U=u({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),W=u({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`});export{p as A,c as C,f as D,l as E,t as O,a as S,n as T,u as _,P as a,r as b,O as c,j as d,v as f,d as g,h,F as i,e as k,k as l,g as m,L as n,N as o,_ as p,I as r,M as s,V as t,A as u,m as v,i as w,s as x,o as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{h as e}from"./random-D6srtOfs.mjs";import{t}from"./factory-BZXyDHm6.mjs";function n(e,t){return typeof e==`string`&&typeof t==`string`?e.toLowerCase()===t.toLowerCase():e===t}function r(e,t){return typeof e==`string`?t.some(t=>typeof t==`string`&&e.toLowerCase()===t.toLowerCase()):t.includes(e)}function i(e,t){return!r(e,t)}function a(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().includes(t.toLowerCase())}function o(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().startsWith(t.toLowerCase())}function s(e,t){return typeof e!=`string`||typeof t!=`string`?!1:e.toLowerCase().endsWith(t.toLowerCase())}function c(e){let t=/* @__PURE__ */ new Map;for(let n of e)t.set(n.id,n);return t}function l(e,t,n){let r=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);for(let i of r){if(!(i in n)){delete e[i];continue}let r=c(t[i]??[]),a=n[i]??[],o=c(a),s=e[i]??[],l=[],d=/* @__PURE__ */ new Set;for(let e of s){let t=e.id,n=r.get(t),i=o.get(t);(n===void 0||i!==void 0)&&(i!==void 0&&u(n,i)?l.push(i):l.push(e),d.add(t))}for(let e of a)!r.has(e.id)&&!d.has(e.id)&&l.push(e);e[i]=l}}function u(e,t){return e===void 0||JSON.stringify(e)!==JSON.stringify(t)}const d=(c,u)=>{let d=null,f=c=>t({config:{adapterId:`memory`,adapterName:`Memory Adapter`,usePlural:!1,debugLogs:u?.debugLogs||!1,supportsArrays:!0,customTransformInput(e){return e.options.advanced?.database?.generateId===`serial`&&e.field===`id`&&e.action===`create`?c[e.model].length+1:e.data},transaction:async e=>{let t=structuredClone(c),n=structuredClone(c),r=await e(f(n)(d));return l(c,t,n),r}},adapter:({getFieldName:t,getDefaultFieldName:l,options:u,getModelName:d})=>{let f=(e,n,r)=>n?e.sort((e,i)=>{let a=t({model:r,field:n.field}),o=e[a],s=i[a],c=0;return c=o==null&&s==null?0:o==null?-1:s==null?1:typeof o==`string`&&typeof s==`string`?o.localeCompare(s):o instanceof Date&&s instanceof Date?o.getTime()-s.getTime():typeof o==`number`&&typeof s==`number`?o-s:typeof o==`boolean`&&typeof s==`boolean`?o===s?0:o?1:-1:String(o).localeCompare(String(s)),n.direction===`asc`?c:-c}):e;function p(t,u,f,p){let m=(()=>{let d=c[u];if(!d)throw e.error(`[MemoryAdapter] Model ${u} not found in the DB`,Object.keys(c)),Error(`Model ${u} not found`);let f=(e,t)=>{let{field:c,value:l,operator:u,mode:d=`sensitive`}=t,f=d===`insensitive`&&(typeof l==`string`||Array.isArray(l)&&l.every(e=>typeof e==`string`));switch(u){case`in`:if(!Array.isArray(l))throw Error(`Value must be an array`);return f?r(e[c],l):l.includes(e[c]);case`not_in`:if(!Array.isArray(l))throw Error(`Value must be an array`);return f?i(e[c],l):!l.includes(e[c]);case`contains`:return f?a(e[c],l):e[c]?.includes(l);case`starts_with`:return f?o(e[c],l):e[c].startsWith(l);case`ends_with`:return f?s(e[c],l):e[c].endsWith(l);case`ne`:return f?!n(e[c],l):e[c]!==l;case`gt`:return l!=null&&e[c]>l;case`gte`:return l!=null&&e[c]>=l;case`lt`:return l!=null&&e[c]<l;case`lte`:return l!=null&&e[c]<=l;default:return f?n(e[c],l):l===null?e[c]==null:e[c]===l}},m=d.filter(e=>{if(!t.length||t.length===0)return!0;let n=f(e,t[0]);for(let r of t){let t=f(e,r);r.connector===`OR`?n||=t:n&&=t}return n});return p?.length&&p.length>0&&(m=m.map(e=>Object.fromEntries(Object.entries(e).filter(([e])=>p.includes(l({model:u,field:e})))))),m})();if(!f)return m;let h=/* @__PURE__ */ new Map,g=/* @__PURE__ */ new Map;for(let t of m){let n=String(t.id);if(!h.has(n)){let e={...t};for(let[t,r]of Object.entries(f)){let i=d(t);r.relation===`one-to-one`?e[i]=null:(e[i]=[],g.set(`${n}-${t}`,/* @__PURE__ */ new Set))}h.set(n,e)}let r=h.get(n);for(let[i,a]of Object.entries(f)){let o=d(i),s=c[o];if(!s)throw e.error(`[MemoryAdapter] JoinOption model ${o} not found in the DB`,Object.keys(c)),Error(`JoinOption model ${o} not found`);let l=s.filter(e=>e[a.on.to]===t[a.on.from]);if(a.relation===`one-to-one`)r[o]=l[0]||null;else{let e=g.get(`${n}-${i}`),t=a.limit??100,s=0;for(let n of l){if(s>=t)break;e.has(n.id)||(r[o].push(n),e.add(n.id),s++)}}}}return Array.from(h.values())}return{create:async({model:e,data:t})=>(u.advanced?.database?.generateId===`serial`&&(t.id=c[d(e)].length+1),c[e]||(c[e]=[]),c[e].push(t),t),findOne:async({model:e,where:t,select:n,join:r})=>{let i=p(t,e,r,n);if(r){let e=i;return e.length?e[0]:null}return i[0]||null},findMany:async({model:e,where:t,sortBy:n,limit:r,select:i,offset:a,join:o})=>{let s=p(t||[],e,o,i);if(o){let t=s;if(!t.length)return[];f(t,n,e);let i=t;return a!==void 0&&(i=i.slice(a)),r!==void 0&&(i=i.slice(0,r)),i}let c=f(s,n,e);return a!==void 0&&(c=c.slice(a)),r!==void 0&&(c=c.slice(0,r)),c||[]},count:async({model:e,where:t})=>t?p(t,e).length:c[e].length,update:async({model:e,where:t,update:n})=>{if(t.length===0)return null;let r=p(t,e);return r.forEach(e=>{Object.assign(e,n)}),r[0]||null},delete:async({model:e,where:t})=>{if(t.length===0)return;let n=c[e],r=p(t,e);c[e]=n.filter(e=>!r.includes(e))},deleteMany:async({model:e,where:t})=>{let n=c[e],r=p(t,e),i=0;return c[e]=n.filter(e=>r.includes(e)?(i++,!1):!r.includes(e)),i},consumeOne:async({model:e,where:t})=>{let n=c[e],r=p(t,e)[0];return r?(c[e]=n.filter(e=>e!==r),r):null},incrementOne:async({model:e,where:t,increment:n,set:r})=>{let i=p(t,e)[0];if(!i)return null;for(let[e,t]of Object.entries(n))i[e]=(typeof i[e]==`number`?i[e]:0)+t;return r&&Object.assign(i,r),i},updateMany:async({model:e,where:t,update:n})=>{let r=p(t,e);return r.forEach(e=>{Object.assign(e,n)}),r.length}}}}),p=f(c);return e=>(d=e,p(e))};export{d as memoryAdapter};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{N as e}from"./schemas-CYxWglEB.mjs";import{h as t}from"./random-D6srtOfs.mjs";import{i as n,l as r,n as i,s as a,t as o}from"./schema-check-2a0t7Pu_.mjs";import{t as s}from"./factory-BZXyDHm6.mjs";import{A as c,C as l,E as u,O as d,S as f,T as p,_ as m,b as ee,f as h,h as g,k as _,m as te,n as v,p as y,s as b,t as ne,w as re,x as ie,y as ae}from"./default-query-compiler-DTJtuKGc.mjs";import{A as oe,C as x,D as se,E as S,M as C,N as ce,O as le,P as ue,S as de,T as fe,_ as pe,a as w,b as me,c as he,d as ge,f as _e,g as T,h as ve,i as ye,j as be,k as xe,l as Se,m as Ce,n as E,o as D,p as O,r as k,s as we,t as A,u as Te,v as j,w as Ee,x as De,y as Oe}from"./compiled-query-xtJR566p.mjs";import{n as ke,r as Ae,t as je}from"./sqlite-adapter-BG0MClj_.mjs";const M=m({is(e){return e.kind===`AlterTableNode`},create(e){return m({kind:`AlterTableNode`,table:e})},cloneWithTableProps(e,t){return m({...e,...t})},cloneWithColumnAlteration(e,t){return m({...e,columnAlterations:e.columnAlterations?[...e.columnAlterations,t]:[t]})}}),N=m({is(e){return e.kind===`CreateIndexNode`},create(e){return m({kind:`CreateIndexNode`,name:g.create(e)})},cloneWith(e,t){return m({...e,...t})},cloneWithColumns(e,t){return m({...e,columns:[...e.columns||[],...t]})}}),Me=m({is(e){return e.kind===`CreateSchemaNode`},create(e,t){return m({kind:`CreateSchemaNode`,schema:g.create(e),...t})},cloneWith(e,t){return m({...e,...t})}}),P=m({is(e){return e.kind===`DropIndexNode`},create(e,t){return m({kind:`DropIndexNode`,name:h.create(e),...t})},cloneWith(e,t){return m({...e,...t})}}),Ne=m({is(e){return e.kind===`DropSchemaNode`},create(e,t){return m({kind:`DropSchemaNode`,schema:g.create(e),...t})},cloneWith(e,t){return m({...e,...t})}}),F=m({is(e){return e.kind===`DropTableNode`},create(e,t){return m({kind:`DropTableNode`,table:e,...t})},cloneWith(e,t){return m({...e,...t})}}),Pe=m({is(e){return e.kind===`AddColumnNode`},create(e){return m({kind:`AddColumnNode`,column:e})}}),I=m({is(e){return e.kind===`ColumnDefinitionNode`},create(e,t){return m({kind:`ColumnDefinitionNode`,column:C.create(e),dataType:t})},cloneWithFrontModifier(e,t){return m({...e,frontModifiers:e.frontModifiers?m([...e.frontModifiers,t]):[t]})},cloneWithEndModifier(e,t){return m({...e,endModifiers:e.endModifiers?m([...e.endModifiers,t]):[t]})},cloneWith(e,t){return m({...e,...t})}}),Fe=m({is(e){return e.kind===`DropColumnNode`},create(e){return m({kind:`DropColumnNode`,column:C.create(e)})},cloneWith(e,t){return m({...e,...t})}}),Ie=m({is(e){return e.kind===`RenameColumnNode`},create(e,t){return m({kind:`RenameColumnNode`,column:C.create(e),renameTo:C.create(t)})}}),Le=m({is(e){return e.kind===`CheckConstraintNode`},create(e,t){return m({kind:`CheckConstraintNode`,expression:e,name:t?g.create(t):void 0})}}),Re=m({cascade:!0,"no action":!0,restrict:!0,"set default":!0,"set null":!0});Object.keys(Re);const ze=m({is(e){return e.kind===`ReferencesNode`},create(e,t){return m({kind:`ReferencesNode`,table:e,columns:m([...t])})},cloneWithOnDelete(e,t){return m({...e,onDelete:t})},cloneWithOnUpdate(e,t){return m({...e,onUpdate:t})}});function Be(e){return d(e)&&Re[e]}function Ve(e){return ce(e)?e.toOperationNode():x.createImmediate(e)}const He=m({is(e){return e.kind===`GeneratedNode`},create(e){return m({kind:`GeneratedNode`,...e})},createWithExpression(e){return m({kind:`GeneratedNode`,always:!0,expression:e})},cloneWith(e,t){return m({...e,...t})}}),Ue=m({is(e){return e.kind===`DefaultValueNode`},create(e){return m({kind:`DefaultValueNode`,defaultValue:e})}});function We(e){if(Be(e))return e;throw Error(`invalid OnModifyForeignAction ${e}`)}var L=class e{#e;constructor(e){this.#e=e}autoIncrement(){return new e(I.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new e(I.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new e(I.cloneWith(this.#e,{primaryKey:!0}))}references(t){let n=se(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(I.cloneWith(this.#e,{references:ze.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(I.cloneWith(this.#e,{references:ze.cloneWithOnDelete(this.#e.references,We(t))}))}onUpdate(t){if(!this.#e.references)throw Error(`on update constraint can only be added for foreign keys`);return new e(I.cloneWith(this.#e,{references:ze.cloneWithOnUpdate(this.#e.references,We(t))}))}unique(){return new e(I.cloneWith(this.#e,{unique:!0}))}notNull(){return new e(I.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new e(I.cloneWith(this.#e,{unsigned:!0}))}defaultTo(t){return new e(I.cloneWith(this.#e,{defaultTo:Ue.create(Ve(t))}))}check(t){return new e(I.cloneWith(this.#e,{check:Le.create(t.toOperationNode())}))}generatedAlwaysAs(t){return new e(I.cloneWith(this.#e,{generated:He.createWithExpression(t.toOperationNode())}))}generatedAlwaysAsIdentity(){return new e(I.cloneWith(this.#e,{generated:He.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new e(I.cloneWith(this.#e,{generated:He.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw Error(`stored() can only be called after generatedAlwaysAs`);return new e(I.cloneWith(this.#e,{generated:He.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(t){return new e(I.cloneWithFrontModifier(this.#e,t.toOperationNode()))}nullsNotDistinct(){return new e(I.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new e(I.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(t){return new e(I.cloneWithEndModifier(this.#e,t.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};const Ge=m({is(e){return e.kind===`ModifyColumnNode`},create(e){return m({kind:`ModifyColumnNode`,column:e})}}),R=m({is(e){return e.kind===`ForeignKeyConstraintNode`},create(e,t,n,r){return m({kind:`ForeignKeyConstraintNode`,columns:e,references:ze.create(t,n),name:r?g.create(r):void 0})},cloneWith(e,t){return m({...e,...t})}});var Ke=class e{#e;constructor(e){this.#e=e}onDelete(t){return new e(R.cloneWith(this.#e,{onDelete:We(t)}))}onUpdate(t){return new e(R.cloneWith(this.#e,{onUpdate:We(t)}))}deferrable(){return new e(R.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(R.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(R.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(R.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};const z=m({is(e){return e.kind===`AddConstraintNode`},create(e){return m({kind:`AddConstraintNode`,constraint:e})}}),B=m({is(e){return e.kind===`UniqueConstraintNode`},create(e,t,n){return d(e.at(0))&&(le("`UniqueConstraintNode.create(columns: string[], ...)` is deprecated - pass `ColumnNode[]` instead."),e=e.map(C.create)),m({kind:`UniqueConstraintNode`,columns:m(e),name:t?g.create(t):void 0,nullsNotDistinct:n})},cloneWith(e,t){return m({...e,...t})}}),V=m({is(e){return e.kind===`DropConstraintNode`},create(e){return m({kind:`DropConstraintNode`,constraintName:g.create(e)})},cloneWith(e,t){return m({...e,...t})}}),H=m({is(e){return e.kind===`AlterColumnNode`},create(e,t,n){return m({kind:`AlterColumnNode`,column:C.create(e),[t]:n})}});var qe=class{#e;constructor(e){this.#e=e}setDataType(e){return new U(H.create(this.#e,`dataType`,D(e)))}setDefault(e){return new U(H.create(this.#e,`setDefault`,Ve(e)))}dropDefault(){return new U(H.create(this.#e,`dropDefault`,!0))}setNotNull(){return new U(H.create(this.#e,`setNotNull`,!0))}dropNotNull(){return new U(H.create(this.#e,`dropNotNull`,!0))}$call(e){return e(this)}},U=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}},W=class{#e;constructor(e){this.#e=m(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(e){await this.#e.executor.executeQuery(this.compile(),e)}},Je=class e{#e;constructor(e){this.#e=m(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(M.cloneWithTableProps(this.#e.node,{addConstraint:z.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ye=class e{#e;constructor(e){this.#e=m(e)}ifExists(){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{dropConstraint:V.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{dropConstraint:V.cloneWith(this.#e.node.dropConstraint,{modifier:`cascade`})})})}restrict(){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{dropConstraint:V.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(e){await this.#e.executor.executeQuery(this.compile(),e)}};const G=m({is(e){return e.kind===`PrimaryKeyConstraintNode`},create(e,t){return m({kind:`PrimaryKeyConstraintNode`,columns:m(e.map(C.create)),name:t?g.create(t):void 0})},cloneWith(e,t){return m({...e,...t})}}),K=m({is(e){return e.kind===`AddIndexNode`},create(e){return m({kind:`AddIndexNode`,name:g.create(e)})},cloneWith(e,t){return m({...e,...t})},cloneWithColumns(e,t){return m({...e,columns:[...e.columns||[],...t]})}});var Xe=class e{#e;constructor(e){this.#e=m(e)}unique(){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(t){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.cloneWithColumns(this.#e.node.addIndex,[d(t)?S(t):t.toOperationNode()])})})}columns(t){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.cloneWithColumns(this.#e.node.addIndex,t.map(e=>d(e)?S(e):e.toOperationNode()))})})}expression(t){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.cloneWithColumns(this.#e.node.addIndex,[t.toOperationNode()])})})}using(t){return new e({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.cloneWith(this.#e.node.addIndex,{using:b.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(e){await this.#e.executor.executeQuery(this.compile(),e)}},Ze=class e{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new e(B.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new e(B.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(B.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(B.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(B.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},Qe=class e{#e;constructor(e){this.#e=e}deferrable(){return new e(G.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new e(G.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new e(G.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new e(G.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}},$e=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};const et=m({is(e){return e.kind===`RenameConstraintNode`},create(e,t){return m({kind:`RenameConstraintNode`,oldName:g.create(e),newName:g.create(t)})}});var tt=class e{#e;constructor(e){this.#e=m({...e})}ifExists(){return new e({...this.#e,node:Fe.cloneWith(this.#e.node,{ifExists:!0})})}toOperationNode(){return this.#e.node}},nt=class{#e;constructor(e){this.#e=m(e)}renameTo(e){return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{renameTo:k(e)})})}setSchema(e){return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{setSchema:g.create(e)})})}alterColumn(e,t){let n=t(new qe(e));return new q({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}dropColumn(e,t=c){let n=t(new tt({node:Fe.create(e)}));return new q({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,n.toOperationNode())})}renameColumn(e,t){return new q({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Ie.create(e,t))})}addColumn(e,t,n=c){let r=n(new L(I.create(e,D(t))));return new q({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Pe.create(r.toOperationNode()))})}modifyColumn(e,t,n=c){let r=n(new L(I.create(e,D(t))));return new q({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Ge.create(r.toOperationNode()))})}addUniqueConstraint(e,t,n=c){let r=n(new Ze(B.create(t.map(e=>d(e)?C.create(e):w(e)),e)));return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addConstraint:z.create(r.toOperationNode())})})}addCheckConstraint(e,t,n=c){let r=n(new $e(Le.create(t.toOperationNode(),e)));return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addConstraint:z.create(r.toOperationNode())})})}addForeignKeyConstraint(e,t,n,r,i=c){let a=i(new Ke(R.create(t.map(C.create),k(n),r.map(C.create),e)));return new Je({...this.#e,constraintBuilder:a})}addPrimaryKeyConstraint(e,t,n=c){let r=n(new Qe(G.create(t,e)));return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addConstraint:z.create(r.toOperationNode())})})}dropConstraint(e){return new Ye({...this.#e,node:M.cloneWithTableProps(this.#e.node,{dropConstraint:V.create(e)})})}renameConstraint(e,t){return new Ye({...this.#e,node:M.cloneWithTableProps(this.#e.node,{renameConstraint:et.create(e,t)})})}addIndex(e){return new Xe({...this.#e,node:M.cloneWithTableProps(this.#e.node,{addIndex:K.create(e)})})}dropIndex(e){return new W({...this.#e,node:M.cloneWithTableProps(this.#e.node,{dropIndex:P.create(e)})})}$call(e){return e(this)}},q=class e{#e;constructor(e){this.#e=m(e)}alterColumn(t,n){let r=n(new qe(t));return new e({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}dropColumn(t,n=c){let r=n(new tt({node:Fe.create(t)}));return new e({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,r.toOperationNode())})}renameColumn(t,n){return new e({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Ie.create(t,n))})}addColumn(t,n,r=c){let i=r(new L(I.create(t,D(n))));return new e({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Pe.create(i.toOperationNode()))})}modifyColumn(t,n,r=c){let i=r(new L(I.create(t,D(n))));return new e({...this.#e,node:M.cloneWithColumnAlteration(this.#e.node,Ge.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(e){await this.#e.executor.executeQuery(this.compile(),e)}},rt=class extends pe{transformPrimitiveValueList(e){return Ee.create(e.values.map(x.createImmediate))}transformValue(e){return x.createImmediate(e.value)}},it=class e{#e;constructor(e){this.#e=m(e)}ifNotExists(){return new e({...this.#e,node:N.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new e({...this.#e,node:N.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new e({...this.#e,node:N.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(t){return new e({...this.#e,node:N.cloneWith(this.#e.node,{table:k(t)})})}column(t){return new e({...this.#e,node:N.cloneWithColumns(this.#e.node,[d(t)?S(t):t.toOperationNode()])})}columns(t){return new e({...this.#e,node:N.cloneWithColumns(this.#e.node,t.map(e=>d(e)?S(e):e.toOperationNode()))})}expression(t){return new e({...this.#e,node:N.cloneWithColumns(this.#e.node,[t.toOperationNode()])})}using(t){return new e({...this.#e,node:N.cloneWith(this.#e.node,{using:b.createWithSql(t)})})}where(...t){let n=new rt;return new e({...this.#e,node:De.cloneWithWhere(this.#e.node,n.transformNode(de(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(e){await this.#e.executor.executeQuery(this.compile(),e)}},at=class e{#e;constructor(e){this.#e=m(e)}ifNotExists(){return new e({...this.#e,node:Me.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};function ot(e){if(te.includes(e))return e;throw Error(`invalid OnCommitAction ${e}`)}var st=class e{#e;constructor(e){this.#e=e}using(t){return new e(K.cloneWith(this.#e,{using:b.createWithSql(t)}))}$call(e){return e(this)}toOperationNode(){return this.#e}},ct=class e{#e;constructor(e){this.#e=m(e)}temporary(){return new e({...this.#e,node:y.cloneWith(this.#e.node,{temporary:!0})})}onCommit(t){return new e({...this.#e,node:y.cloneWith(this.#e.node,{onCommit:ot(t)})})}ifNotExists(){return new e({...this.#e,node:y.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(t,n,r=c){let i=r(new L(I.create(t,D(n))));return new e({...this.#e,node:y.cloneWithColumn(this.#e.node,i.toOperationNode())})}addPrimaryKeyConstraint(t,n,r=c){let i=r(new Qe(G.create(n,t)));return new e({...this.#e,node:y.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addUniqueConstraint(t,n,r=c){let i=r(new Ze(B.create(n.map(e=>d(e)?C.create(e):w(e)),t)));return new e({...this.#e,node:y.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addIndex(t,n,r=c){let i=r(new st(K.cloneWithColumns(K.create(t),n.map(e=>d(e)?C.create(e):w(e)))));return new e({...this.#e,node:y.cloneWithIndex(this.#e.node,i.toOperationNode())})}addCheckConstraint(t,n,r=c){let i=r(new $e(Le.create(n.toOperationNode(),t)));return new e({...this.#e,node:y.cloneWithConstraint(this.#e.node,i.toOperationNode())})}addForeignKeyConstraint(t,n,r,i,a=c){let o=a(new Ke(R.create(n.map(C.create),k(r),i.map(C.create),t)));return new e({...this.#e,node:y.cloneWithConstraint(this.#e.node,o.toOperationNode())})}modifyFront(t){return new e({...this.#e,node:y.cloneWithFrontModifier(this.#e.node,t.toOperationNode())})}modifyEnd(t){return new e({...this.#e,node:y.cloneWithEndModifier(this.#e.node,t.toOperationNode())})}as(t){return new e({...this.#e,node:y.cloneWith(this.#e.node,{selectQuery:w(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(e){await this.#e.executor.executeQuery(this.compile(),e)}},lt=class e{#e;constructor(e){this.#e=m(e)}on(t){return new e({...this.#e,node:P.cloneWith(this.#e.node,{table:k(t)})})}ifExists(){return new e({...this.#e,node:P.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:P.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(e){await this.#e.executor.executeQuery(this.compile(),e)}},ut=class e{#e;constructor(e){this.#e=m(e)}ifExists(){return new e({...this.#e,node:Ne.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:Ne.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(e){await this.#e.executor.executeQuery(this.compile(),e)}},dt=class e{#e;constructor(e){this.#e=m(e)}temporary(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{temporary:!0})})}ifExists(){return new e({...this.#e,node:F.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:F.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(e){await this.#e.executor.executeQuery(this.compile(),e)}},ft=class{#e=new rt;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}},pt=class e{#e;constructor(e){this.#e=m(e)}temporary(){return new e({...this.#e,node:v.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new e({...this.#e,node:v.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new e({...this.#e,node:v.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new e({...this.#e,node:v.cloneWith(this.#e.node,{orReplace:!0})})}columns(t){return new e({...this.#e,node:v.cloneWith(this.#e.node,{columns:t.map(fe)})})}as(t){let n=t.withPlugin(new ft).toOperationNode();return new e({...this.#e,node:v.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(e){await this.#e.executor.executeQuery(this.compile(),e)}};const mt=m({is(e){return e.kind===`DropViewNode`},create(e){return m({kind:`DropViewNode`,name:h.create(e)})},cloneWith(e,t){return m({...e,...t})}});var ht=class e{#e;constructor(e){this.#e=m(e)}materialized(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new e({...this.#e,node:mt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:mt.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(e){await this.#e.executor.executeQuery(this.compile(),e)}};const gt=m({is(e){return e.kind===`CreateTypeNode`},create(e){return m({kind:`CreateTypeNode`,name:e})},cloneWithEnum(e,t){return m({...e,enum:Ee.create(t.map(x.createImmediate))})}});var _t=class e{#e;constructor(e){this.#e=m(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(t){return new e({...this.#e,node:gt.cloneWithEnum(this.#e.node,t)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(e){await this.#e.executor.executeQuery(this.compile(),e)}};const vt=m({is(e){return e.kind===`DropTypeNode`},create(e){return Array.isArray(e)||(e=[e]),m({kind:`DropTypeNode`,name:e[0],additionalNames:e.slice(1)})},cloneWith(e,t){return m({...e,...t})}});var yt=class e{#e;constructor(e){this.#e=m(e)}ifExists(){return new e({...this.#e,node:vt.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new e({...this.#e,node:vt.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(e){await this.#e.executor.executeQuery(this.compile(),e)}};function bt(e){if(e.includes(`.`)){let t=e.split(`.`).map(St);if(t.length===2)return h.createWithSchema(t[0],t[1]);throw Error(`invalid schemable identifier ${e}`)}return h.create(e)}function xt(e){return Array.isArray(e)||(e=[e]),e.map(bt)}function St(e){return e.trim()}const Ct=m({is(e){return e.kind===`RefreshMaterializedViewNode`},create(e){return m({kind:`RefreshMaterializedViewNode`,name:h.create(e)})},cloneWith(e,t){return m({...e,...t})}});var wt=class e{#e;constructor(e){this.#e=m(e)}concurrently(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new e({...this.#e,node:Ct.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new e({...this.#e,node:Ct.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(e){await this.#e.executor.executeQuery(this.compile(),e)}};const J=m({is(e){return e.kind===`AlterTypeNode`},create(e){return m({kind:`AlterTypeNode`,name:e})},cloneWith(e,t){return m({...e,...t})}}),Tt=m({is(e){return e.kind===`AddValueNode`},create(e){return m({kind:`AddValueNode`,value:e})},cloneWith(e,t){return m({...e,...t})}});var Et=class{#e;constructor(e){this.#e=m(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(e){return await this.#e.executor.executeQuery(this.compile(),e)}},Dt,Ot=class extends Et{#e;constructor(e){super(e),this.#e=e}ifNotExists(){return new Dt({...this.#e,node:J.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{ifNotExists:!0})})})}before(e){return this.#t(e,!0)}after(e){return this.#t(e,!1)}#t(e,t){return new Dt({...this.#e,node:J.cloneWith(this.#e.node,{addValue:Tt.cloneWith(this.#e.node.addValue,{isBefore:t,neighborValue:x.createImmediate(e)})})})}};Dt=Ot;const kt=m({is(e){return e.kind===`RenameValueNode`},create(e,t){return m({kind:`RenameValueNode`,oldValue:e,newValue:t})}});var At=class{#e;constructor(e){this.#e=m(e)}addValue(e){return new Ot({...this.#e,node:J.cloneWith(this.#e.node,{addValue:Tt.create(x.createImmediate(e))})})}renameTo(e){return new Et({...this.#e,node:J.cloneWith(this.#e.node,{renameTo:g.create(e)})})}renameValue(e,t){return new Et({...this.#e,node:J.cloneWith(this.#e.node,{renameValue:kt.create(x.createImmediate(e),x.createImmediate(t))})})}setSchema(e){return new Et({...this.#e,node:J.cloneWith(this.#e.node,{setSchema:g.create(e)})})}},jt=class e{#e;constructor(e){this.#e=e}createTable(e){return new ct({queryId:j(),executor:this.#e,node:y.create(k(e))})}dropTable(e){return new dt({queryId:j(),executor:this.#e,node:F.create(k(e))})}createIndex(e){return new it({queryId:j(),executor:this.#e,node:N.create(e)})}dropIndex(e){return new lt({queryId:j(),executor:this.#e,node:P.create(e)})}createSchema(e){return new at({queryId:j(),executor:this.#e,node:Me.create(e)})}dropSchema(e){return new ut({queryId:j(),executor:this.#e,node:Ne.create(e)})}alterTable(e){return new nt({queryId:j(),executor:this.#e,node:M.create(k(e))})}createView(e){return new pt({queryId:j(),executor:this.#e,node:v.create(e)})}refreshMaterializedView(e){return new wt({queryId:j(),executor:this.#e,node:Ct.create(e)})}dropView(e){return new ht({queryId:j(),executor:this.#e,node:mt.create(e)})}createType(e){return new _t({queryId:j(),executor:this.#e,node:gt.create(bt(e))})}alterType(e){return new At({executor:this.#e,node:J.create(bt(e)),queryId:j()})}dropType(e){return new yt({queryId:j(),executor:this.#e,node:vt.create(xt(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 T(t)))}},Mt=class{ref(e){return new xe(e)}table(e){return new ye(e)}},Nt=class{#e;constructor(e){this.#e=e}async provideConnection(e,t){let n=await this.#e.acquireConnection(t);try{return await e(n)}finally{await this.#e.releaseConnection(n,t)}}},Pt=class e extends ge{#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,t){return this.#n.provideConnection(e,t)}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 Ft(){return typeof performance<`u`&&l(performance.now)?performance.now():Date.now()}var It=class{#e;#t;async obtainLock(){for(;this.#e;)await this.#e;this.#e=new Promise(e=>{this.#t=e})}releaseLock(){let e=this.#t;this.#e=void 0,this.#t=void 0,e?.()}},Lt=class{#e;#t;#n;#r;#i;#a=/* @__PURE__ */ new WeakSet;#o;constructor(e,t,n){this.#e=e,this.#r=!1,this.#t=n,t.supportsMultipleConnections===!1&&(this.#o=new It)}async init(e){if(this.#i)throw Error(`driver has already been destroyed`);this.#n??=this.#e.init(e).then(()=>{this.#r=!0}).catch(e=>{throw this.#n=void 0,e}),await O(this.#n,e?.signal,`init`)}async acquireConnection(e){if(this.#i)throw Error(`driver has already been destroyed`);if(this.#r||await this.init(e),this.#o){let t=this.#o.obtainLock();await O(t,e?.signal,`acquireConnection:mutex`,()=>t.then(()=>this.#o?.releaseLock()))}let t=this.#e.acquireConnection(e),n=await O(t,e?.signal,`acquireConnection:acquire`,()=>t?.then(e=>this.releaseConnection(e).catch(_e(`driver.releaseConnection`))).catch(_e(`driver.acquireConnection`)));return this.#a.has(n)||(this.#s()&&this.#c(n),this.#a.add(n)),n}async releaseConnection(e,t){await this.#e.releaseConnection(e,t),this.#o?.releaseLock()}async beginTransaction(e,t){return await this.#e.beginTransaction(e,t)}async commitTransaction(e){return await this.#e.commitTransaction(e)}async rollbackTransaction(e){return await this.#e.rollbackTransaction(e)}async savepoint(e,t,n){if(this.#e.savepoint)return await this.#e.savepoint(e,t,n);throw Error("The `savepoint` method is not supported by this driver")}async rollbackToSavepoint(e,t,n){if(this.#e.rollbackToSavepoint)return await this.#e.rollbackToSavepoint(e,t,n);throw Error("The `rollbackToSavepoint` method is not supported by this driver")}async releaseSavepoint(e,t,n){if(this.#e.releaseSavepoint)return await this.#e.releaseSavepoint(e,t,n);throw Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(e){this.#n&&(await O(this.#n,e?.signal,`destroy:initPromise`),this.#i??=this.#e.destroy(e).catch(e=>{throw this.#i=void 0,e}),await O(this.#i,e?.signal,`destroy`))}#s(){return this.#t.isLevelEnabled(`query`)||this.#t.isLevelEnabled(`error`)}#c(e){let t=e.executeQuery,n=e.streamQuery,r=this;e.executeQuery=async(n,i)=>{let a,o=Ft();try{return await t.call(e,n,i)}catch(e){throw a=e,await r.#l(e,n,o),e}finally{a||await r.#u(n,o)}},e.streamQuery=async function*(t,i,a){let o,s=Ft();try{for await(let r of n.call(e,t,i,a))yield r}catch(e){throw o=e,await r.#l(e,t,s),e}finally{o||await r.#u(t,s,!0)}}}async#l(e,t,n){await this.#t.error(()=>({level:`error`,error:e,query:t,queryDurationMillis:this.#d(n)}))}async#u(e,t,n=!1){await this.#t.query(()=>({level:`query`,isStream:n,query:e,queryDurationMillis:this.#d(t)}))}#d(e){return Ft()-e}};const Rt=()=>{};var zt=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(Rt);return this.#t=this.#n(e).finally(()=>{this.#t=void 0}),this.#t}async#n(e){return await e(this.#e)}};const Bt=[`read only`,`read write`],Vt=[`read uncommitted`,`read committed`,`repeatable read`,`serializable`,`snapshot`];function Ht(e){if(e.accessMode&&!Bt.includes(e.accessMode))throw Error(`invalid transaction access mode ${e.accessMode}`);if(e.isolationLevel&&!Vt.includes(e.isolationLevel))throw Error(`invalid transaction isolation level ${e.isolationLevel}`)}m([`query`,`error`]);var Ut=class{#e;#t;constructor(e){l(e)?(this.#t=e,this.#e=m({query:!0,error:!0})):(this.#t=Wt,this.#e=m({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 Wt(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 Gt(e){return u(e)&&l(e.compile)}Symbol.asyncDispose??=Symbol(`Symbol.asyncDispose`);var Y=class e extends Te{#e;constructor(e){let t,n;if(qt(e))t={executor:e.executor},n={...e};else{let r=e.dialect,i=r.createDriver(),a=r.createQueryCompiler(),o=r.createAdapter(),s=new Lt(i,o,new Ut(e.log??[])),c=new Pt(a,o,new Nt(s),e.plugins??[]);t={executor:c},n={config:e,executor:c,dialect:r,driver:s}}super(t),this.#e=m(n)}get schema(){return new jt(this.#e.executor)}get dynamic(){return new Mt}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new we({node:he.create(_(e)?void 0:w(e))})}get fn(){return Se()}transaction(){return new Yt({...this.#e})}startTransaction(){return new Xt({...this.#e})}connection(){return new Jt({...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 T(t))})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}withTables(){return this.$extendTables()}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}async executeQuery(e,t){let n=Gt(e)?e.compile():e;return await this.#e.executor.executeQuery(n,t)}async[Symbol.asyncDispose](){await this.destroy()}},Kt=class e extends Y{#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`)}startTransaction(){throw Error(`calling the controlled transaction method for a Transaction is not supported`)}connection(){throw Error(`calling the connection method for a Transaction is not supported`)}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 T(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}};function qt(e){return u(e)&&u(e.config)&&u(e.driver)&&u(e.executor)&&u(e.dialect)}var Jt=class{#e;constructor(e){this.#e=m(e)}async execute(e,t){return this.#e.executor.provideConnection(async t=>{let n=this.#e.executor.withConnectionProvider(new zt(t));return await e(new Y({...this.#e,executor:n}))},m({signal:t?.signal}))}},Yt=class e{#e;constructor(e){this.#e=m(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 Ht(i),this.#e.executor.provideConnection(async t=>{let n={isCommitted:!1,isRolledBack:!1},a=new Qt(this.#e.executor.withConnectionProvider(new zt(t)),n),o=new Kt({...r,executor:a}),s=!1;try{await this.#e.driver.beginTransaction(t,i),s=!0;let r=await e(o);return await this.#e.driver.commitTransaction(t),n.isCommitted=!0,r}catch(e){throw s&&(await this.#e.driver.rollbackTransaction(t),n.isRolledBack=!0),e}})}},Xt=class e{#e;constructor(e){this.#e=m(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};Ht(r);let i=await Ce(this.#e.executor);return await this.#e.driver.beginTransaction(i.connection,r),new Zt({...n,connection:i,executor:this.#e.executor.withConnectionProvider(new zt(i.connection))})}},Zt=class e extends Kt{#e;#t;#n;constructor(e){let t={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Qt(e.executor,t)};let{connection:n,...r}=e;super(r),this.#e=m(e),this.#n=t;let i=j();this.#t=t=>e.executor.compileQuery(t,i)}get isCommitted(){return this.#n.isCommitted}get isRolledBack(){return this.#n.isRolledBack}commit(){return Z(this.#n),new X(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#n.isCommitted=!0,this.#e.connection.release()})}rollback(){return Z(this.#n),new X(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#n.isRolledBack=!0,this.#e.connection.release()})}savepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}rollbackToSavepoint(t){return Z(this.#n),new X(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,t,this.#t),new e({...this.#e})))}releaseSavepoint(t){return Z(this.#n),new X(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 T(t))})}withTables(){return new e({...this.#e})}$extendTables(){return new e({...this.#e})}$omitTables(){return new e({...this.#e})}$pickTables(){return new e({...this.#e})}},X=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function Z(e){if(e.isCommitted)throw Error(`Transaction is already committed`);if(e.isRolledBack)throw Error(`Transaction is already rolled back`)}var Qt=class e{#e;#t;constructor(t,n){this.#e=t instanceof e?t.#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,t){return this.#e.provideConnection(e,t)}executeQuery(e,t){return Z(this.#t),this.#e.executeQuery(e,t)}stream(e,t,n){return Z(this.#t),this.#e.stream(e,t,n)}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)}};function Q(e,t){return b.createWithChildren([b.createWithSql(`${e} `),g.create(t)])}var $t=class{#e;#t;#n;constructor(e){this.#e=m({...e})}async init(e){this.#t=l(this.#e.database)?await this.#e.database(e):this.#e.database,this.#n=new en(this.#t),this.#e.onCreateConnection&&await this.#e.onCreateConnection(this.#n,e)}async acquireConnection(){return this.#n}async beginTransaction(e){await e.executeQuery(A.raw(`begin`))}async commitTransaction(e){await e.executeQuery(A.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(A.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),j()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),j()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),j()))}async releaseConnection(){}async destroy(){this.#t?.close()}},en=class{#e;constructor(e){this.#e=e}async executeQuery(e){let{sql:t,parameters:n}=e,r=this.#e.prepare(t);if(r.reader)return{rows:r.all(n)};let{changes:i,lastInsertRowid:a}=r.run(n);return{insertId:a==null?void 0:BigInt(a),numAffectedRows:i==null?void 0:BigInt(i),rows:[]}}async*streamQuery(e,t){let{sql:n,parameters:r,query:i}=e,a=this.#e.prepare(n);if(!me.is(i))throw Error(`Sqlite driver only supports streaming of select queries`);let o=a.iterate(r);for(let e of o)yield{rows:[e]}}};const $=`kysely_migration`,tn=`kysely_migration_lock`;m({__noMigrations__:!0});var nn=class{#e;constructor(e){this.#e=e}async getSchemas(){return[]}async getTables(e={withInternalKyselyTables:!1}){return await this.#n(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`,`!=`,$).where(`name`,`!=`,tn)),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`,E`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`,isForeign:!1,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}))}})}},rn=class{#e;constructor(e){this.#e=m({...e})}createDriver(){return new $t(this.#e)}createQueryCompiler(){return new ke}createAdapter(){return new je}createIntrospector(e){return new nn(e)}};function an(e,t){if(on(e)&&t.stack){let n=t.stack.split(`
|
|
2
|
+
`).slice(1).join(`
|
|
3
|
+
`);return e.stack+=`\n${n}`,e}return e}function on(e){return u(e)&&d(e.stack)}const sn=Symbol();var cn=class{#e;#t=/* @__PURE__ */ new WeakMap;#n;constructor(e){this.#e=m({...e})}async init(e){this.#n=l(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#r(),n=this.#t.get(t);return n||(n=new un(t,this.#e.controlConnection),this.#t.set(t,n),this.#e?.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e?.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}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(A.raw(r))}await e.executeQuery(A.raw(`begin`))}async commitTransaction(e){await e.executeQuery(A.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(A.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),j()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),j()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release savepoint`,t),j()))}async releaseConnection(e){e[sn]()}async destroy(){return new Promise((e,t)=>{this.#n.end(n=>{n?t(n):e()})})}async#r(){return new Promise((e,t)=>{this.#n.getConnection(async(n,r)=>{n?t(n):e(r)})})}};function ln(e){return u(e)&&`insertId`in e&&`affectedRows`in e}var un=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){await this.#a(`kill query ${this.#n}`,e)}async collectSessionInfo(){if(this.#n)return;let{threadId:e}=this.#e;if(e!=null)this.#n=e;else{let[{cid:e}]=await this.#i(A.raw(`select connection_id() as cid`));this.#n=Number(e)}}async executeQuery(e){try{this.#r=e.queryId;let t=await this.#i(e);if(!ln(t))return{rows:Array.isArray(t)?t:[]};let{insertId:n,affectedRows:r,changedRows:i}=t;return{insertId:n!=null&&n.toString()!==`0`?BigInt(n):void 0,numAffectedRows:r==null?void 0:BigInt(r),numChangedRows:i==null?void 0:BigInt(i),rows:[]}}catch(e){throw an(e,/* @__PURE__ */ Error())}finally{this.#r=void 0}}async killSession(e){try{this.#e.destroy()}catch{}await this.#a(`kill connection ${this.#n}`,e)}async*streamQuery(e,t){this.#r=e.queryId;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(u(e)&&`code`in e&&e.code===`ERR_STREAM_PREMATURE_CLOSE`)return;throw e}finally{this.#r=void 0}}[sn](){this.#e.release()}#i(e){return new Promise((t,n)=>{this.#e.query(e.sql,e.parameters,(e,r)=>{e?n(e):t(r)})})}async#a(e,t){if(!this.#r)return;let{config:n}=this.#e,r=this.#r;if(!this.#t||!n)return await t(async t=>{r.queryId===this.#r?.queryId&&await t.executeQuery(A.raw(e,[]))});let{clientFlags:i,maxPacketSize:a,...o}=n,s=this.#t(o);try{await new Promise((t,n)=>{s.connect(i=>{if(i)return n(i);if(r.queryId!==this.#r?.queryId)return t();s.query(e,[],e=>{if(e)return n(e);t()})})})}finally{s.destroy()}}};const dn=/[\\']/g,fn=/`/g,pn=/[\\'"]/g;var mn=class extends ne{getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getExplainOptionAssignment(){return`=`}getExplainOptionsDelimiter(){return` `}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return fn.source}getRightIdentifierWrapper(){return fn.source}sanitizeIdentifier(e){return e.replace(fn,"``")}sanitizeStringLiteral(e){return e.replace(dn,e=>e===`\\`?`\\\\`:`''`)}sanitizeJSONPathMemberValue(e){return e.replace(pn,e=>e===`\\`?`\\\\\\\\`:e===`'`?`''`:`\\\\"`)}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))}},hn=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`,`tables.ENGINE`,`columns.IS_NULLABLE`,`columns.DATA_TYPE`,`columns.EXTRA`,`columns.COLUMN_COMMENT`]).where(`columns.TABLE_SCHEMA`,`=`,E`database()`).orderBy(`columns.TABLE_NAME`).orderBy(`columns.ORDINAL_POSITION`).$castTo();e.withInternalKyselyTables||(t=t.where(`columns.TABLE_NAME`,`!=`,$).where(`columns.TABLE_NAME`,`!=`,tn));let n=await t.execute();return this.#t(n)}#t(e){return e.reduce((e,t)=>{let n=e.find(e=>e.name===t.TABLE_NAME);return n||(n=m({name:t.TABLE_NAME,isView:t.TABLE_TYPE===`VIEW`,isForeign:t.ENGINE===`FEDERATED`,schema:t.TABLE_SCHEMA,columns:[]}),e.push(n)),n.columns.push(m({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 gn=`ea586330-2c93-47c8-908d-981d9d270f9d`;var _n=class extends Ae{get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}async acquireMigrationLock(e,t){await E`select get_lock(${E.lit(gn)}, ${E.lit(3600)})`.execute(e)}async releaseMigrationLock(e,t){await E`select release_lock(${E.lit(gn)})`.execute(e)}},vn=class{#e;constructor(e){this.#e=e}createDriver(){return new cn(this.#e)}createQueryCompiler(){return new mn}createAdapter(){return new _n}createIntrospector(e){return new hn(e)}};const yn=Symbol();var bn=class{#e;#t=/* @__PURE__ */ new WeakMap;#n;constructor(e){this.#e=m({...e})}async init(e){this.#n=l(this.#e.pool)?await this.#e.pool(e):this.#e.pool}async acquireConnection(e){let t=await this.#n.connect(),n=this.#t.get(t);return n||(n=new xn(t,{controlClient:this.#e.controlClient||this.#n.Client,cursor:this.#e.cursor??null,poolOptions:this.#n.options}),this.#t.set(t,n),this.#e.onCreateConnection&&await this.#e.onCreateConnection(n,e)),this.#e.onReserveConnection&&await this.#e.onReserveConnection(n,e),n}async beginTransaction(e,t){let n=`begin`;(t.isolationLevel||t.accessMode)&&(n=`start transaction`,t.isolationLevel&&(n+=` isolation level ${t.isolationLevel}`),t.accessMode&&(n+=` ${t.accessMode}`)),await e.executeQuery(A.raw(n))}async commitTransaction(e){await e.executeQuery(A.raw(`commit`))}async rollbackTransaction(e){await e.executeQuery(A.raw(`rollback`))}async savepoint(e,t,n){await e.executeQuery(n(Q(`savepoint`,t),j()))}async rollbackToSavepoint(e,t,n){await e.executeQuery(n(Q(`rollback to`,t),j()))}async releaseSavepoint(e,t,n){await e.executeQuery(n(Q(`release`,t),j()))}async releaseConnection(e){e[yn]()}async destroy(){if(this.#n){let e=this.#n;this.#n=void 0,await e.end()}}},xn=class{#e;#t;#n;#r;constructor(e,t){this.#e=e,this.#t=t}async cancelQuery(e){return await this.#i(`select pg_cancel_backend(${this.#r})`,e)}async collectSessionInfo(){if(this.#r)return;let{processID:e}=this.#e;if(e)this.#r=e;else{let{rows:[{pid:e}]}=await this.#e.query(`select pg_backend_pid() as pid`,[]);this.#r=Number(e)}}async executeQuery(e){try{this.#n=e.queryId;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 an(e,/* @__PURE__ */ Error())}finally{this.#n=void 0}}async killSession(e){return await this.#i(`select pg_terminate_backend(${this.#r})`,e)}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.");this.#n=e.queryId;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(),this.#n=void 0}}[yn](){this.#e.release()}async#i(e,t){if(!this.#n)return;let{controlClient:n,poolOptions:r}=this.#t,i=this.#n;if(!n)return await t(async t=>{i.queryId===this.#n?.queryId&&await t.executeQuery(A.raw(e,[]))});let a=new n({...r,password:`password`in r?r.password:void 0});try{if(await a.connect(),i.queryId!==this.#n.queryId)return;await a.query(e,[])}finally{a.end()}}},Sn=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`,E`col_description(a.attrelid, a.attnum)`.as(`column_description`),E`pg_get_serial_sequence(quote_ident(ns.nspname) || '.' || quote_ident(c.relname), a.attname)`.as(`auto_incrementing`)]).where(`c.relkind`,`in`,[`r`,`v`,`p`,`f`]).where(`ns.nspname`,`!~`,`^pg_`).where(`ns.nspname`,`!=`,`information_schema`).where(`ns.nspname`,`!=`,`crdb_internal`).where(E`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`,`!=`,$).where(`c.relname`,`!=`,tn));let n=await t.execute();return this.#t(n)}#t(e){let t=[],n=/* @__PURE__ */ new Map;for(let r of e){let e=n.get(r.schema);e||(e=/* @__PURE__ */ new Map,n.set(r.schema,e));let i=e.get(r.table);i||(i=m({columns:[],isForeign:r.table_type===`f`,isView:r.table_type===`v`,name:r.table,schema:r.schema}),e.set(r.table,i),t.push(i)),i.columns.push(m({comment:r.column_description??void 0,dataType:r.type,dataTypeSchema:r.type_schema,hasDefaultValue:r.has_default,isAutoIncrementing:r.auto_incrementing!==null,isNullable:!r.not_null,name:r.column}))}return t}};const Cn=/"/g;var wn=class extends ne{sanitizeIdentifier(e){return e.replace(Cn,`""`)}};const Tn=BigInt(`3853314791062309107`);var En=class extends Ae{get supportsTransactionalDdl(){return!0}get supportsReturning(){return!0}async acquireMigrationLock(e,t){await E`
|
|
4
|
+
with set_timeout as (
|
|
5
|
+
select set_config('lock_timeout', '${E.lit(36e5)}', true) as config_val
|
|
6
|
+
)
|
|
7
|
+
select pg_advisory_lock(${E.lit(Tn)})
|
|
8
|
+
from set_timeout`.execute(e)}async releaseMigrationLock(e,t){await E`select pg_advisory_unlock(${E.lit(Tn)})`.execute(e)}},Dn=class{#e;constructor(e){this.#e=e}createDriver(){return new bn(this.#e)}createQueryCompiler(){return new wn}createAdapter(){return new En}createIntrospector(e){return new Sn(e)}},On=class extends Ae{get supportsCreateIfNotExists(){return!1}get supportsTransactionalDdl(){return!0}get supportsOutput(){return!0}async acquireMigrationLock(e,t){await E`exec sp_getapplock @DbPrincipal = ${E.lit(`dbo`)}, @Resource = ${E.lit($)}, @LockMode = ${E.lit(`Exclusive`)}, @LockOwner = ${E.lit(`Session`)}`.execute(e)}async releaseMigrationLock(e,t){await E`exec sp_releaseapplock @DbPrincipal = ${E.lit(`dbo`)}, @Resource = ${E.lit($)}, @LockOwner = ${E.lit(`Session`)}`.execute(e)}};const kn=Symbol(),An=Symbol(),jn=Symbol();var Mn=class{#e;#t;constructor(e){this.#e=m({...e});let{tarn:t,tedious:n,validateConnections:r}=this.#e;this.#t=new t.Pool({...t.options,create:async()=>await new Nn(await n.connectionFactory(),n).connect(),destroy:async e=>{await e[An]()},validate:r===!1?void 0:e=>e[jn]()})}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&&await e[kn](),this.#t.release(e)}async destroy(){await this.#t.destroy()}},Nn=class{#e;#t;#n;#r;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?Oe(8):void 0,t?this.#i(t):void 0))}async cancelQuery(){if(this.#r)return new Promise(e=>{this.#r?.request.once(`requestCompleted`,e),this.#e.cancel()||(this.#r?.request.off(`requestCompleted`,e),e())})}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 ve;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(/* @__PURE__ */ 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 ve;this.#r=new Pn({compiledQuery:e,tedious:this.#n,onDone:t}),this.#e.execSql(this.#r.request);let{rowCount:n,rows:r}=await t.promise;return{numAffectedRows:n===void 0?void 0:BigInt(n),rows:r}}catch(e){throw an(e,/* @__PURE__ */ Error())}finally{this.#r=void 0}}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){this.#r=new Pn({compiledQuery:e,streamChunkSize:t,tedious:this.#n}),this.#e.execSql(this.#r.request);try{for(;;){let e=await this.#r.readChunk();if(e.length===0||(yield{rows:e},e.length<t))break}}finally{await this.cancelQuery(),this.#r=void 0}}#i(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}[An](){return`closed`in this.#e&&this.#e.closed?Promise.resolve():new Promise(e=>{this.#e.once(`end`,e),this.#e.close()})}async[kn](){await new Promise((e,t)=>{this.#e.reset(n=>{if(n)return t(n);e()})})}async[jn](){if(this.#t||this.#a())return!1;try{let e=new ve,t=new Pn({compiledQuery:A.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}},Pn=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(e){return re(e)||_(e)||d(e)?this.#i.TYPES.NVarChar:ae(e)||p(e)&&e%1==0?e<-2147483648||e>2147483647?this.#i.TYPES.BigInt:this.#i.TYPES.Int:p(e)?this.#i.TYPES.Float:ee(e)?this.#i.TYPES.Bit:f(e)?this.#i.TYPES.DateTime:ie(e)?this.#i.TYPES.VarBinary:this.#i.TYPES.NVarChar}},Fn=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`,`!=`,$).where(`tables.name`,`!=`,tn)).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]||m({columns:[],isForeign:!1,isView:e.table_type===`V `,name:e.table_name,schema:e.table_schema_name??void 0})).columns.push(m({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)}};const In=/^[a-z0-9_]$/i;var Ln=class extends ne{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 `),this.compileList(t.DropColumnNode),n=!1),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.append(`column `),e.ifExists&&this.append(`if exists `),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(!In.test(e))throw Error(`Invalid collation: ${t}`);this.append(t)}announcesNewColumnDataType(){return!1}},Rn=class{#e;constructor(e){this.#e=e}createDriver(){return new Mn(this.#e)}createQueryCompiler(){return new Ln}createAdapter(){return new On}createIntrospector(e){return new Fn(e)}};function zn(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Bn(e){if(!e)return null;if(`dialect`in e)return Bn(e.dialect);if(`createDriver`in e){if(e instanceof rn)return`sqlite`;if(e instanceof vn)return`mysql`;if(e instanceof Dn)return`postgres`;if(e instanceof Rn)return`mssql`}return`aggregate`in e?`sqlite`:`getConnection`in e?`mysql`:`connect`in e?`postgres`:`fileControl`in e||`open`in e&&`close`in e&&`prepare`in e||`batch`in e&&`exec`in e&&`prepare`in e?`sqlite`:null}function Vn(t,n){if(t!==void 0){if(typeof t!=`string`||t.length===0)throw new e("`database.schemaName` must be a non-empty schema name.");if(n!==`postgres`)throw new e(`\`database.schemaName\` is only supported on PostgreSQL, but the configured database type is "${n??`unknown`}".`)}}const Hn=async e=>{let t=e.database;if(!t)return{kysely:null,databaseType:null,introspectIndexes:void 0,schemaName:void 0,transaction:void 0};if(`db`in t){let e=t.schemaName;return Vn(e,t.type),{kysely:e?t.db.withSchema(e):t.db,databaseType:t.type,introspectIndexes:void 0,schemaName:e,transaction:t.transaction}}if(`dialect`in t){let e=t.schemaName;Vn(e,t.type);let n=new Y({dialect:t.dialect});return{kysely:e?n.withSchema(e):n,databaseType:t.type,introspectIndexes:void 0,schemaName:e,transaction:t.transaction}}let n,r,i,a=Bn(t);if(`createDriver`in t&&(n=t),`aggregate`in t&&!(`createSession`in t)&&(n=new rn({database:t}),i=!0),`getConnection`in t&&(n=new vn(t),i=!0),`connect`in t&&(n=new Dn({pool:t}),i=!0),`fileControl`in t){let{BunSqliteDialect:e}=await import(`./bun-sqlite-dialect-C7ftEUSI-DFKViJQ3.mjs`);n=new e({database:t}),i=!0}if(`createSession`in t){let e;try{({DatabaseSync:e}=await import(
|
|
9
|
+
/* @vite-ignore */
|
|
10
|
+
/* webpackIgnore: true */
|
|
11
|
+
`node:sqlite`))}catch(e){if(typeof e==`object`&&e&&`code`in e&&e.code!==`ERR_UNKNOWN_BUILTIN_MODULE`)throw e}if(e&&t instanceof e){let{NodeSqliteDialect:e}=await import(`./index.mjs`).then(e=>e.t);n=new e({database:t}),i=!0}}if(`batch`in t&&`exec`in t&&`prepare`in t){let{createD1IndexIntrospector:e,D1SqliteDialect:a}=await import(`./d1-sqlite-dialect-D4qp4-wW-Rqu1eTED.mjs`);n=new a({database:t}),r=e(t),i=!1}return{kysely:n?new Y({dialect:n}):null,databaseType:a,introspectIndexes:r,schemaName:void 0,transaction:i}};function Un(e,t,n){return n===`postgres`?E`${E.ref(e)} ILIKE ${t}`:E`LOWER(${E.ref(e)}) LIKE LOWER(${t})`}function Wn(e,t){return{lhs:E`LOWER(${E.ref(e)})`,values:t.map(e=>e.toLowerCase())}}function Gn(e,t){return{lhs:E`LOWER(${E.ref(e)})`,values:t.map(e=>e.toLowerCase())}}function Kn(e,t){return{lhs:E`LOWER(${E.ref(e)})`,value:t.toLowerCase()}}function qn(e,t){return{lhs:E`LOWER(${E.ref(e)})`,value:t.toLowerCase()}}function Jn(e){return e.map(e=>({name:e.name,schema:e.schema,columns:e.columns.map(e=>({name:e.name,nullable:e.isNullable,hasDefault:e.hasDefaultValue||e.isAutoIncrementing}))}))}function Yn(e,t){let n={};for(let[r,i]of Object.entries(t)){let t=Object.entries(i.fields),a=Xn(e,r,[i.idColumn??`id`,...t.map(([e])=>e)]),o={};t.forEach(([e,t],n)=>{o[a.columns[n+1]??e]=t}),n[a.table]={...i,fields:o,schema:a.schema??i.schema,...a.columns[0]!==`id`&&{idColumn:a.columns[0]}}}return n}function Xn(e,t,n){let{query:r}=e.selectFrom(t).select(n).compile();if(!me.is(r))return{table:t,columns:[]};let i=r.from?.froms[0],a=i&&ue.is(i)?i.table:void 0;return{schema:a?.schema?.name,table:a?.identifier.name??t,columns:(r.selections??[]).map(({selection:e})=>oe.is(e)&&C.is(e.column)?e.column.column.name:void 0)}}async function Zn(e){return(await E`
|
|
12
|
+
SELECT pg_catalog.current_schema() AS schema
|
|
13
|
+
`.execute(e.withoutPlugins())).rows[0]?.schema??`public`}async function Qn(e){return(await E`
|
|
14
|
+
SELECT SCHEMA_NAME() AS "schemaName"
|
|
15
|
+
`.execute(e.withoutPlugins())).rows[0]?.schemaName||`dbo`}async function $n(e,t){if(t===`postgres`)return(await E`
|
|
16
|
+
SELECT pg_catalog.current_schemas(true)::text[] AS schemas
|
|
17
|
+
`.execute(e.withoutPlugins())).rows[0]?.schemas??[];if(t===`mssql`)return[await Qn(e),`dbo`]}async function er(e,t,n){let r=Yn(e,n);return e.connection().execute(async e=>{let n=await $n(e,t),i=Jn(await e.introspection.getTables());for(let[e,t]of Object.entries(r))t.schema===void 0&&n&&(t.schema=n.find(t=>i.some(n=>n.name===e&&n.schema===t))??``);return a(r,i)})}const tr=(e,a)=>{let c=null,l=!1,u=(e,n=!1)=>({getFieldName:r,schema:i,getDefaultFieldName:o,getDefaultModelName:s,getFieldAttributes:c,getModelName:u,options:d})=>{a?.type===`mysql`&&d.advanced?.database?.generateId===!1&&!l&&(l=!0,t.warn(`[Kysely Adapter] MySQL does not support INSERT...RETURNING. With generateId set to false, the adapter uses best-effort fallback strategies (unique columns, full-field match) to retrieve inserted rows. For reliable behavior, use Better Auth's default ID generation, a custom generateId function, or generateId: "serial" for auto-increment.`));let f=e=>{let t=[],n=[];if(e)for(let[r,a]of Object.entries(e)){let e=i[s(r)]?.fields,[a,o]=r.includes(`.`)?r.split(`.`):[void 0,r];if(e){e.id={type:`string`};for(let[i,a]of Object.entries(e))t.push(E`${E.ref(`join_${o}`)}.${E.ref(a.fieldName||i)} as ${E.ref(`_joined_${o}_${a.fieldName||i}`)}`),n.push({joinModel:r,joinModelRef:o,fieldName:a.fieldName||i})}}return{allSelectsStr:n,allSelects:t}},p=async(o,c,l,u)=>{if(a?.type===`mysql`){if(u.length>0){let t=await c.executeTakeFirst();if(!t||Number(t.numUpdatedRows??0)===0)return null;let n=u.find(e=>e.field===`id`&&(e.operator===void 0||e.operator===`eq`)&&e.connector!==`OR`&&e.value!==void 0&&e.value!==null),i,a;if(o.id!==void 0&&o.id!==null)i=`id`,a=o.id;else if(n)i=`id`,a=n.value;else if(u[0]?.field)i=u[0].field,a=o[i]===void 0?u[0].value:o[i];else return null;return await e.selectFrom(l).selectAll().where(r({model:l,field:i}),a===null?`is`:`=`,a).limit(1).executeTakeFirst()}await c.execute();let a=async e=>{if(o.id)return await e.selectFrom(l).selectAll().where(r({model:l,field:`id`}),`=`,o.id).limit(1).executeTakeFirst();if(d.advanced?.database?.generateId===`serial`){let t=(await E`SELECT LAST_INSERT_ID() as id`.execute(e)).rows[0]?.id;if(t)return await e.selectFrom(l).selectAll().where(r({model:l,field:`id`}),`=`,t).limit(1).executeTakeFirst()}let n=i[s(l)]?.fields;if(n)for(let[t,i]of Object.entries(n)){if(!i.unique)continue;let n=r({model:l,field:t}),a=o[n];if(a==null)continue;let s=await e.selectFrom(l).selectAll().where(n,`=`,a).limit(1).executeTakeFirst();if(s)return s}let a=e.selectFrom(l).selectAll(),c=!1;for(let[e,t]of Object.entries(o))t!==void 0&&(a=a.where(e,t===null?`is`:`=`,t),c=!0);if(c){let e=await a.limit(2).execute();if(e.length===1)return e[0]}return t.warn(`[Kysely Adapter] Unable to safely identify the inserted "${l}" row on MySQL. Enable Better Auth ID generation or use generateId: "serial" for reliable behavior.`),null};return n?a(e):e.transaction().execute(a)}return a?.type===`mssql`?await c.outputAll(`inserted`).executeTakeFirst():await c.returningAll().executeTakeFirst()};function m(e,t){if(!t)return{and:null,or:null};let n={and:[],or:[]};return t.forEach(t=>{let{field:i,value:o,operator:s=`eq`,connector:c=`AND`,mode:l=`sensitive`}=t,u=o,d=r({model:e,field:i}),f=l===`insensitive`&&(typeof u==`string`||Array.isArray(u)&&u.every(e=>typeof e==`string`)),p=t=>{let n=`${e}.${d}`;if(s.toLowerCase()===`in`){if(f){let{lhs:e,values:r}=Wn(n,Array.isArray(u)?u:[u]);return t(e,`in`,r)}return t(n,`in`,Array.isArray(u)?u:[u])}if(s.toLowerCase()===`not_in`){if(f){let{lhs:e,values:r}=Gn(n,Array.isArray(u)?u:[u]);return t(e,`not in`,r)}return t(n,`not in`,Array.isArray(u)?u:[u])}if(s===`contains`)return f&&typeof u==`string`?Un(n,`%${u}%`,a?.type):t(n,`like`,`%${u}%`);if(s===`starts_with`)return f&&typeof u==`string`?Un(n,`${u}%`,a?.type):t(n,`like`,`${u}%`);if(s===`ends_with`)return f&&typeof u==`string`?Un(n,`%${u}`,a?.type):t(n,`like`,`%${u}`);if(s===`eq`){if(u===null)return t(n,`is`,null);if(f&&typeof u==`string`){let{lhs:e,value:r}=Kn(n,u);return t(e,`=`,r)}return t(n,`=`,u)}if(s===`ne`){if(u===null)return t(n,`is not`,null);if(f&&typeof u==`string`){let{lhs:e,value:r}=qn(n,u);return t(e,`<>`,r)}return t(n,`<>`,u)}return s===`gt`?t(n,`>`,u):s===`gte`?t(n,`>=`,u):s===`lt`?t(n,`<`,u):s===`lte`?t(n,`<=`,u):t(n,s,u)};c===`OR`?n.or.push(p):n.and.push(p)}),{and:n.and.length?n.and:null,or:n.or.length?n.or:null}}function ee(e,t,n){if(!t||!e.length)return e;let i=/* @__PURE__ */ new Map;for(let a of e){let e={},o={};for(let[e]of Object.entries(t))o[u(e)]={};for(let[t,i]of Object.entries(a)){let a=String(t),s=!1;for(let{joinModel:e,fieldName:t,joinModelRef:c}of n)if(a===`_joined_${c}_${t}`||a===`_Joined${zn(c)}${zn(t)}`){o[u(e)][r({model:e,field:t})]=i,s=!0;break}s||(e[t]=i)}let s=e.id;if(!s)continue;if(!i.has(s)){let n={...e};for(let[e,r]of Object.entries(t))n[u(e)]=r.relation===`one-to-one`?null:[];i.set(s,n)}let c=i.get(s);for(let[e,n]of Object.entries(t)){let t=n.relation===`one-to-one`,i=n.limit??100,a=o[u(e)],s=a&&Object.keys(a).length>0&&Object.values(a).some(e=>e!=null);if(t)c[u(e)]=s?a:null;else{let t=u(e);if(Array.isArray(c[t])&&s){if(c[t].length>=i)continue;let n=r({model:e,field:`id`}),o=a[n];o?!c[t].some(e=>e[n]===o)&&c[t].length<i&&c[t].push(a):c[t].length<i&&c[t].push(a)}}}}let a=Array.from(i.values());for(let e of a)for(let[n,r]of Object.entries(t))if(r.relation!==`one-to-one`){let t=u(n);if(Array.isArray(e[t])){let n=r.limit??100;e[t].length>n&&(e[t]=e[t].slice(0,n))}}return a}return{async create({data:t,model:n}){return await p(t,e.insertInto(n).values(t),n,[])},async findOne({model:t,where:n,select:i,join:a}){let{and:o,or:s}=m(t,n),c=e.selectFrom(e=>{let n=e.selectFrom(t);return o&&(n=n.where(e=>e.and(o.map(t=>t(e))))),s&&(n=n.where(e=>e.or(s.map(t=>t(e))))),n=i?.length&&i.length>0?n.select(i.map(e=>r({model:t,field:e}))):n.selectAll(),n.as(`primary`)}).selectAll(`primary`);if(a)for(let[e,t]of Object.entries(a)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];c=c.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:l,allSelects:u}=f(a);c=c.select(u);let d=await c.execute();if(!d||!Array.isArray(d)||d.length===0)return null;let p=d[0];return a?ee(d,a,l)[0]:p},async findMany({model:t,where:n,limit:i,select:o,offset:s,sortBy:c,join:l}){let{and:u,or:d}=m(t,n),p=e.selectFrom(e=>{let n=e.selectFrom(t);return a?.type===`mssql`?s===void 0?i!==void 0&&(n=n.top(i)):(c||(n=n.orderBy(r({model:t,field:`id`}))),n=n.offset(s).fetch(i||100)):(i!==void 0&&(n=n.limit(i)),s!==void 0&&(n=n.offset(s))),c?.field&&(n=n.orderBy(`${r({model:t,field:c.field})}`,c.direction)),u&&(n=n.where(e=>e.and(u.map(t=>t(e))))),d&&(n=n.where(e=>e.or(d.map(t=>t(e))))),n=o?.length&&o.length>0?n.select(o.map(e=>r({model:t,field:e}))):n.selectAll(),n.as(`primary`)}).selectAll(`primary`);if(l)for(let[e,t]of Object.entries(l)){let[n,r]=e.includes(`.`)?e.split(`.`):[void 0,e];p=p.leftJoin(`${e} as join_${r}`,e=>e.onRef(`join_${r}.${t.on.to}`,`=`,`primary.${t.on.from}`))}let{allSelectsStr:h,allSelects:g}=f(l);p=p.select(g),c?.field&&(p=p.orderBy(`${r({model:t,field:c.field})}`,c.direction));let _=await p.execute();return _?l?ee(_,l,h):_:[]},async update({model:t,where:n,update:r}){if(n.length===0)return null;let{and:i,or:a}=m(t,n),o=e.updateTable(t).set(r);return i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e))))),await p(r,o,t,n)},async updateMany({model:t,where:n,update:r}){let{and:i,or:a}=m(t,n),o=e.updateTable(t).set(r);i&&(o=o.where(e=>e.and(i.map(t=>t(e))))),a&&(o=o.where(e=>e.or(a.map(t=>t(e)))));let s=(await o.executeTakeFirst()).numUpdatedRows;return s>2**53-1?2**53-1:Number(s)},async count({model:t,where:n}){let{and:r,or:i}=m(t,n),a=e.selectFrom(t).select(e.fn.count(`id`).as(`count`));r&&(a=a.where(e=>e.and(r.map(t=>t(e))))),i&&(a=a.where(e=>e.or(i.map(t=>t(e)))));let o=await a.execute();return typeof o[0].count==`number`?o[0].count:typeof o[0].count==`bigint`?Number(o[0].count):parseInt(o[0].count)},async delete({model:t,where:n}){let{and:r,or:i}=m(t,n),a=e.deleteFrom(t);r&&(a=a.where(e=>e.and(r.map(t=>t(e))))),i&&(a=a.where(e=>e.or(i.map(t=>t(e))))),await a.execute()},async deleteMany({model:t,where:n}){let{and:r,or:i}=m(t,n),a=e.deleteFrom(t);r&&(a=a.where(e=>e.and(r.map(t=>t(e))))),i&&(a=a.where(e=>e.or(i.map(t=>t(e)))));let o=(await a.executeTakeFirst()).numDeletedRows;return o>2**53-1?2**53-1:Number(o)},async consumeOne({model:t,where:i}){let{and:o,or:s}=m(t,i),c=e=>(o&&(e=e.where(e=>e.and(o.map(t=>t(e))))),s&&(e=e.where(e=>e.or(s.map(t=>t(e))))),e),l=r({model:t,field:`id`}),u=async(e,n)=>{let r=n[l]??n.id;if(r==null)return null;let i=e.deleteFrom(t).where(`${t}.${l}`,`=`,r);if(a?.type===`mysql`){let e=await i.executeTakeFirst();return Number(e.numDeletedRows)>0?n:null}return a?.type===`mssql`?await i.outputAll(`deleted`).executeTakeFirst()??null:await i.returningAll().executeTakeFirst()??null},d=async e=>a?.type===`mssql`?await e.outputAll(`deleted`).executeTakeFirst()??null:await e.returningAll().executeTakeFirst()??null;if(a?.type===`mysql`){let r=async e=>{let n=await c(e.selectFrom(t).selectAll().forUpdate()).limit(1).executeTakeFirst();return n?u(e,n):null};return n?r(e):e.transaction().execute(r)}let f=c(e.selectFrom(t).select(`${t}.${l}`)),p=a?.type===`mssql`?f.top(1):f.limit(1);return d(e.deleteFrom(t).where(`${t}.${l}`,`in`,p))},async incrementOne({model:t,where:i,increment:o,set:s}){let{and:c,or:l}=m(t,i),u=e=>(c&&(e=e.where(e=>e.and(c.map(t=>t(e))))),l&&(e=e.where(e=>e.or(l.map(t=>t(e))))),e),d={...s??{}};for(let[e,t]of Object.entries(o))d[e]=E`${E.ref(e)} + ${t}`;let f=r({model:t,field:`id`});if(a?.type===`mysql`){let r=async e=>{let n=await u(e.selectFrom(t).select(`${t}.${f}`).forUpdate()).limit(1).executeTakeFirst();if(!n)return null;let r=n[f]??n.id;if(r==null)return null;let i=await u(e.updateTable(t).set(d)).where(`${t}.${f}`,`=`,r).executeTakeFirst();return Number(i.numUpdatedRows)===0?null:await e.selectFrom(t).selectAll().where(`${t}.${f}`,`=`,r).limit(1).executeTakeFirst()??null};return n?r(e):e.transaction().execute(r)}let p=u(e.selectFrom(t).select(`${t}.${f}`)),ee=a?.type===`mssql`?p.top(1):p.limit(1),h=u(e.updateTable(t).set(d)).where(`${t}.${f}`,`in`,ee);return a?.type===`mssql`?await h.outputAll(`inserted`).executeTakeFirst()??null:await h.returningAll().executeTakeFirst()??null},options:a}},d=null;d={config:{adapterId:`kysely`,adapterName:`Kysely Adapter`,usePlural:a?.usePlural,debugLogs:a?.debugLogs,supportsBooleans:!(a?.type===`sqlite`||a?.type===`mssql`||a?.type===`mysql`||!a?.type),supportsDates:!(a?.type===`sqlite`||a?.type===`mssql`||!a?.type),supportsJSON:a?.type===`postgres`,supportsArrays:!1,supportsUUIDs:a?.type===`postgres`,transaction:a?.transaction?t=>e.transaction().execute(e=>t(s({config:{...d.config,transaction:!1},adapter:u(e,!0)})(c))):!1},adapter:u(e)};let f=s(d);return t=>{c=t;let s=f(t);return o(t)&&n(s,i(()=>er(e,a?.type,r(t,{usePlural:a?.usePlural})),`database`,t.database)),s}};export{tr as a,Y as c,Zn as i,Bn as n,Jn as o,Qn as r,Yn as s,Hn as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=Object.defineProperty,t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n||e(r,Symbol.toStringTag,{value:`Module`}),r},r,i=t((()=>{r=`1.9.1`}));function a(e){let t=/* @__PURE__ */ new Set([e]),n=/* @__PURE__ */ new Set,r=e.match(o);if(!r)return()=>!1;let i={major:+r[1],minor:+r[2],patch:+r[3],prerelease:r[4]};if(i.prerelease!=null)return function(t){return t===e};function a(e){return n.add(e),!1}function s(e){return t.add(e),!0}return function(e){if(t.has(e))return!0;if(n.has(e))return!1;let r=e.match(o);if(!r)return a(e);let c={major:+r[1],minor:+r[2],patch:+r[3],prerelease:r[4]};return c.prerelease!=null||i.major!==c.major?a(e):i.major===0?i.minor===c.minor&&i.patch<=c.patch?s(e):a(e):i.minor<=c.minor?s(e):a(e)}}var o,s,c=t((()=>{i(),o=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/,s=a(r)}));function l(e,t,n,i=!1){let a=p[f]=p[f]??{version:r};if(!i&&a[e]){let t=/* @__PURE__ */ Error(`@opentelemetry/api: Attempted duplicate registration of API: ${e}`);return n.error(t.stack||t.message),!1}if(a.version!==`1.9.1`){let t=/* @__PURE__ */ Error(`@opentelemetry/api: Registration of version v${a.version} for ${e} does not match previously registered API v${r}`);return n.error(t.stack||t.message),!1}return a[e]=t,n.debug(`@opentelemetry/api: Registered a global for ${e} v${r}.`),!0}function u(e){let t=p[f]?.version;if(t&&s(t))return p[f]?.[e]}function d(e,t){t.debug(`@opentelemetry/api: Unregistering a global for ${e} v${r}.`);let n=p[f];n&&delete n[e]}var ee,f,p,m=t((()=>{i(),c(),ee=r.split(`.`)[0],f=Symbol.for(`opentelemetry.js.api.${ee}`),p=typeof globalThis==`object`?globalThis:typeof self==`object`?self:typeof window==`object`?window:typeof global==`object`?global:{}}));function h(e,t,n){let r=u(`diag`);if(r)return r[e](t,...n)}var te,ne=t((()=>{m(),te=class{constructor(e){this._namespace=e.namespace||`DiagComponentLogger`}debug(...e){return h(`debug`,this._namespace,e)}error(...e){return h(`error`,this._namespace,e)}info(...e){return h(`info`,this._namespace,e)}warn(...e){return h(`warn`,this._namespace,e)}verbose(...e){return h(`verbose`,this._namespace,e)}}})),g,_=t((()=>{(function(e){e[e.NONE=0]=`NONE`,e[e.ERROR=30]=`ERROR`,e[e.WARN=50]=`WARN`,e[e.INFO=60]=`INFO`,e[e.DEBUG=70]=`DEBUG`,e[e.VERBOSE=80]=`VERBOSE`,e[e.ALL=9999]=`ALL`})(g||={})}));function re(e,t){e<g.NONE?e=g.NONE:e>g.ALL&&(e=g.ALL),t||={};function n(n,r){let i=t[n];return typeof i==`function`&&e>=r?i.bind(t):function(){}}return{error:n(`error`,g.ERROR),warn:n(`warn`,g.WARN),info:n(`info`,g.INFO),debug:n(`debug`,g.DEBUG),verbose:n(`verbose`,g.VERBOSE)}}var ie=t((()=>{_()})),ae,v,y=t((()=>{ne(),ie(),_(),m(),ae=`diag`,v=class e{static instance(){return this._instance||=new e,this._instance}constructor(){function e(e){return function(...t){let n=u(`diag`);if(n)return n[e](...t)}}let t=this;t.setLogger=(e,n={logLevel:g.INFO})=>{if(e===t){let e=/* @__PURE__ */ Error(`Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation`);return t.error(e.stack??e.message),!1}typeof n==`number`&&(n={logLevel:n});let r=u(`diag`),i=re(n.logLevel??g.INFO,e);if(r&&!n.suppressOverrideMessage){let e=(/* @__PURE__ */ Error()).stack??`<failed to generate stacktrace>`;r.warn(`Current logger will be overwritten from ${e}`),i.warn(`Current logger will overwrite one already registered from ${e}`)}return l(`diag`,i,t,!0)},t.disable=()=>{d(ae,t)},t.createComponentLogger=e=>new te(e),t.verbose=e(`verbose`),t.debug=e(`debug`),t.info=e(`info`),t.warn=e(`warn`),t.error=e(`error`)}}})),oe,se=t((()=>{oe=class e{constructor(e){this._entries=e?new Map(e):/* @__PURE__ */ new Map}getEntry(e){let t=this._entries.get(e);if(t)return Object.assign({},t)}getAllEntries(){return Array.from(this._entries.entries())}setEntry(t,n){let r=new e(this._entries);return r._entries.set(t,n),r}removeEntry(t){let n=new e(this._entries);return n._entries.delete(t),n}removeEntries(...t){let n=new e(this._entries);for(let e of t)n._entries.delete(e);return n}clear(){return new e}}})),ce,le=t((()=>{ce=Symbol(`BaggageEntryMetadata`)}));function ue(e={}){return new oe(new Map(Object.entries(e)))}function de(e){return typeof e!=`string`&&(fe.error(`Cannot create baggage metadata from unknown type: ${typeof e}`),e=``),{__TYPE__:ce,toString(){return e}}}var fe,pe=t((()=>{y(),se(),le(),fe=v.instance()}));function me(e){return Symbol.for(e)}var he,ge,b=t((()=>{he=class e{constructor(t){let n=this;n._currentContext=t?new Map(t):/* @__PURE__ */ new Map,n.getValue=e=>n._currentContext.get(e),n.setValue=(t,r)=>{let i=new e(n._currentContext);return i._currentContext.set(t,r),i},n.deleteValue=t=>{let r=new e(n._currentContext);return r._currentContext.delete(t),r}}},ge=new he})),x,S,_e,ve=t((()=>{if(x=[{n:`error`,c:`error`},{n:`warn`,c:`warn`},{n:`info`,c:`info`},{n:`debug`,c:`debug`},{n:`verbose`,c:`trace`}],S={},typeof console<`u`)for(let e of[`error`,`warn`,`info`,`debug`,`trace`,`log`])typeof console[e]==`function`&&(S[e]=console[e]);_e=class{constructor(){function e(e){return function(...t){let n=S[e];if(typeof n!=`function`&&(n=S.log),typeof n!=`function`&&console&&(n=console[e],typeof n!=`function`&&(n=console.log)),typeof n==`function`)return n.apply(console,t)}}for(let t=0;t<x.length;t++)this[x[t].n]=e(x[t].c)}}}));function ye(){return T}var be,C,xe,Se,Ce,we,w,Te,Ee,De,T,Oe,ke,Ae,je,Me,Ne,Pe,Fe=t((()=>{be=class{constructor(){}createGauge(e,t){return ke}createHistogram(e,t){return Ae}createCounter(e,t){return Oe}createUpDownCounter(e,t){return je}createObservableGauge(e,t){return Ne}createObservableCounter(e,t){return Me}createObservableUpDownCounter(e,t){return Pe}addBatchObservableCallback(e,t){}removeBatchObservableCallback(e){}},C=class{},xe=class extends C{add(e,t){}},Se=class extends C{add(e,t){}},Ce=class extends C{record(e,t){}},we=class extends C{record(e,t){}},w=class{addCallback(e){}removeCallback(e){}},Te=class extends w{},Ee=class extends w{},De=class extends w{},T=new be,Oe=new xe,ke=new Ce,Ae=new we,je=new Se,Me=new Te,Ne=new Ee,Pe=new De})),Ie,Le=t((()=>{(function(e){e[e.INT=0]=`INT`,e[e.DOUBLE=1]=`DOUBLE`})(Ie||={})})),E,D,Re=t((()=>{E={get(e,t){if(e!=null)return e[t]},keys(e){return e==null?[]:Object.keys(e)}},D={set(e,t,n){e!=null&&(e[t]=n)}}})),ze,Be=t((()=>{b(),ze=class{active(){return ge}with(e,t,n,...r){return t.call(n,...r)}bind(e,t){return t}enable(){return this}disable(){return this}}})),O,Ve,k,A=t((()=>{Be(),m(),y(),O=`context`,Ve=new ze,k=class e{constructor(){}static getInstance(){return this._instance||=new e,this._instance}setGlobalContextManager(e){return l(O,e,v.instance())}active(){return this._getContextManager().active()}with(e,t,n,...r){return this._getContextManager().with(e,t,n,...r)}bind(e,t){return this._getContextManager().bind(e,t)}_getContextManager(){return u(O)||Ve}disable(){this._getContextManager().disable(),d(O,v.instance())}}})),j,He=t((()=>{(function(e){e[e.NONE=0]=`NONE`,e[e.SAMPLED=1]=`SAMPLED`})(j||={})})),M,N,P,F=t((()=>{He(),M=`0000000000000000`,N=`00000000000000000000000000000000`,P={traceId:N,spanId:M,traceFlags:j.NONE}})),I,L=t((()=>{F(),I=class{constructor(e=P){this._spanContext=e}spanContext(){return this._spanContext}setAttribute(e,t){return this}setAttributes(e){return this}addEvent(e,t){return this}addLink(e){return this}addLinks(e){return this}setStatus(e){return this}updateName(e){return this}end(e){}isRecording(){return!1}recordException(e,t){}}}));function R(e){return e.getValue(B)||void 0}function Ue(){return R(k.getInstance().active())}function z(e,t){return e.setValue(B,t)}function We(e){return e.deleteValue(B)}function Ge(e,t){return z(e,new I(t))}function Ke(e){return R(e)?.spanContext()}var B,qe=t((()=>{b(),L(),A(),B=me(`OpenTelemetry Context Key SPAN`)}));function Je(e,t){if(typeof e!=`string`||e.length!==t)return!1;let n=0;for(let t=0;t<e.length;t+=4)n+=(H[e.charCodeAt(t)]|0)+(H[e.charCodeAt(t+1)]|0)+(H[e.charCodeAt(t+2)]|0)+(H[e.charCodeAt(t+3)]|0);return n===t}function Ye(e){return Je(e,32)&&e!==`00000000000000000000000000000000`}function Xe(e){return Je(e,16)&&e!==`0000000000000000`}function V(e){return Ye(e.traceId)&&Xe(e.spanId)}function Ze(e){return new I(e)}var H,U=t((()=>{F(),L(),H=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1])}));function Qe(e){return typeof e==`object`&&!!e&&`spanId`in e&&typeof e.spanId==`string`&&`traceId`in e&&typeof e.traceId==`string`&&`traceFlags`in e&&typeof e.traceFlags==`number`}var W,G,$e=t((()=>{A(),qe(),L(),U(),W=k.getInstance(),G=class{startSpan(e,t,n=W.active()){if(t?.root)return new I;let r=n&&Ke(n);return Qe(r)&&V(r)?new I(r):new I}startActiveSpan(e,t,n,r){let i,a,o;if(arguments.length<2)return;arguments.length===2?o=t:arguments.length===3?(i=t,o=n):(i=t,a=n,o=r);let s=a??W.active(),c=this.startSpan(e,i,s),l=z(s,c);return W.with(l,o,void 0,c)}}})),et,K,tt=t((()=>{$e(),et=new G,K=class{constructor(e,t,n,r){this._provider=e,this.name=t,this.version=n,this.options=r}startSpan(e,t,n){return this._getTracer().startSpan(e,t,n)}startActiveSpan(e,t,n,r){let i=this._getTracer();return Reflect.apply(i.startActiveSpan,i,arguments)}_getTracer(){if(this._delegate)return this._delegate;let e=this._provider.getDelegateTracer(this.name,this.version,this.options);return e?(this._delegate=e,this._delegate):et}}})),nt,rt=t((()=>{$e(),nt=class{getTracer(e,t,n){return new G}}})),it,q,at=t((()=>{tt(),rt(),it=new nt,q=class{getTracer(e,t,n){return this.getDelegateTracer(e,t,n)??new K(this,e,t,n)}getDelegate(){return this._delegate??it}setDelegate(e){this._delegate=e}getDelegateTracer(e,t,n){return this._delegate?.getTracer(e,t,n)}}})),ot,st=t((()=>{(function(e){e[e.NOT_RECORD=0]=`NOT_RECORD`,e[e.RECORD=1]=`RECORD`,e[e.RECORD_AND_SAMPLED=2]=`RECORD_AND_SAMPLED`})(ot||={})})),ct,lt=t((()=>{(function(e){e[e.INTERNAL=0]=`INTERNAL`,e[e.SERVER=1]=`SERVER`,e[e.CLIENT=2]=`CLIENT`,e[e.PRODUCER=3]=`PRODUCER`,e[e.CONSUMER=4]=`CONSUMER`})(ct||={})})),ut,dt=t((()=>{(function(e){e[e.UNSET=0]=`UNSET`,e[e.OK=1]=`OK`,e[e.ERROR=2]=`ERROR`})(ut||={})}));function ft(e){return mt.test(e)}function pt(e){return ht.test(e)&&!gt.test(e)}var J,mt,ht,gt,_t=t((()=>{J=`[_0-9a-z-*/]`,mt=RegExp(`^(?:${`[a-z]${J}{0,255}`}|${`[a-z0-9]${J}{0,240}@[a-z]${J}{0,13}`})$`),ht=/^[ -~]{0,255}[!-~]$/,gt=/,|=/})),vt,yt,bt,xt,St,Ct=t((()=>{_t(),vt=32,yt=512,bt=`,`,xt=`=`,St=class e{constructor(e){this._internalState=/* @__PURE__ */ new Map,e&&this._parse(e)}set(e,t){let n=this._clone();return n._internalState.has(e)&&n._internalState.delete(e),n._internalState.set(e,t),n}unset(e){let t=this._clone();return t._internalState.delete(e),t}get(e){return this._internalState.get(e)}serialize(){return Array.from(this._internalState.keys()).reduceRight((e,t)=>(e.push(t+xt+this.get(t)),e),[]).join(bt)}_parse(e){e.length>yt||(this._internalState=e.split(bt).reduceRight((e,t)=>{let n=t.trim(),r=n.indexOf(xt);if(r!==-1){let i=n.slice(0,r),a=n.slice(r+1,t.length);ft(i)&&pt(a)&&e.set(i,a)}return e},/* @__PURE__ */ new Map),this._internalState.size>vt&&(this._internalState=new Map(Array.from(this._internalState.entries()).reverse().slice(0,vt))))}_keys(){return Array.from(this._internalState.keys()).reverse()}_clone(){let t=new e;return t._internalState=new Map(this._internalState),t}}}));function wt(e){return new St(e)}var Tt=t((()=>{Ct()})),Et,Dt=t((()=>{A(),Et=k.getInstance()})),Ot,kt=t((()=>{y(),Ot=v.instance()})),At,jt,Mt=t((()=>{Fe(),At=class{getMeter(e,t,n){return T}},jt=new At})),Y,Nt,Pt=t((()=>{Mt(),m(),y(),Y=`metrics`,Nt=class e{constructor(){}static getInstance(){return this._instance||=new e,this._instance}setGlobalMeterProvider(e){return l(Y,e,v.instance())}getMeterProvider(){return u(Y)||jt}getMeter(e,t,n){return this.getMeterProvider().getMeter(e,t,n)}disable(){d(Y,v.instance())}}})),Ft,It=t((()=>{Pt(),Ft=Nt.getInstance()})),Lt,Rt=t((()=>{Lt=class{inject(e,t){}extract(e,t){return e}fields(){return[]}}}));function zt(e){return e.getValue(X)||void 0}function Bt(){return zt(k.getInstance().active())}function Vt(e,t){return e.setValue(X,t)}function Ht(e){return e.deleteValue(X)}var X,Ut=t((()=>{A(),b(),X=me(`OpenTelemetry Baggage Key`)})),Z,Wt,Gt,Kt=t((()=>{m(),Rt(),Re(),Ut(),pe(),y(),Z=`propagation`,Wt=new Lt,Gt=class e{constructor(){this.createBaggage=ue,this.getBaggage=zt,this.getActiveBaggage=Bt,this.setBaggage=Vt,this.deleteBaggage=Ht}static getInstance(){return this._instance||=new e,this._instance}setGlobalPropagator(e){return l(Z,e,v.instance())}inject(e,t,n=D){return this._getGlobalPropagator().inject(e,t,n)}extract(e,t,n=E){return this._getGlobalPropagator().extract(e,t,n)}fields(){return this._getGlobalPropagator().fields()}disable(){d(Z,v.instance())}_getGlobalPropagator(){return u(Z)||Wt}}})),qt,Jt=t((()=>{Kt(),qt=Gt.getInstance()})),Q,Yt,Xt=t((()=>{m(),at(),U(),qe(),y(),Q=`trace`,Yt=class e{constructor(){this._proxyTracerProvider=new q,this.wrapSpanContext=Ze,this.isSpanContextValid=V,this.deleteSpan=We,this.getSpan=R,this.getActiveSpan=Ue,this.getSpanContext=Ke,this.setSpan=z,this.setSpanContext=Ge}static getInstance(){return this._instance||=new e,this._instance}setGlobalTracerProvider(e){let t=l(Q,this._proxyTracerProvider,v.instance());return t&&this._proxyTracerProvider.setDelegate(e),t}getTracerProvider(){return u(Q)||this._proxyTracerProvider}getTracer(e,t){return this.getTracerProvider().getTracer(e,t)}disable(){d(Q,v.instance()),this._proxyTracerProvider=new q}}})),$,Zt=t((()=>{Xt(),$=Yt.getInstance()})),Qt;t((()=>{pe(),b(),ve(),_(),Fe(),Le(),Re(),tt(),at(),st(),lt(),dt(),He(),Tt(),U(),F(),Dt(),kt(),It(),Jt(),Zt(),Qt={context:Et,diag:Ot,metrics:Ft,propagation:qt,trace:$}}))();export{_e as DiagConsoleLogger,g as DiagLogLevel,M as INVALID_SPANID,P as INVALID_SPAN_CONTEXT,N as INVALID_TRACEID,K as ProxyTracer,q as ProxyTracerProvider,ge as ROOT_CONTEXT,ot as SamplingDecision,ct as SpanKind,ut as SpanStatusCode,j as TraceFlags,Ie as ValueType,de as baggageEntryMetadataFromString,Et as context,me as createContextKey,ye as createNoopMeter,wt as createTraceState,Qt as default,E as defaultTextMapGetter,D as defaultTextMapSetter,Ot as diag,V as isSpanContextValid,Xe as isValidSpanId,Ye as isValidTraceId,Ft as metrics,qt as propagation,n as t,$ as trace};
|