@gjermundgaraba/clankerauth-dev 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/THIRD_PARTY_NOTICES.txt +12 -12
- package/dist/bun-sqlite-dialect-DoOVo4ja-BOb_Pvxr.mjs +1 -0
- package/dist/compiled-query-kXoVMG6q.mjs +1 -0
- package/dist/d1-sqlite-dialect-Cru74LbR-B7paX9dK.mjs +1 -0
- package/dist/dist-D9NNVevc.mjs +1 -0
- package/dist/dist-DmipO4_i.mjs +17 -0
- package/dist/factory-QgsYt4OE.mjs +6 -0
- package/dist/index.mjs +44 -42
- package/dist/kysely-adapter-BhjUN_Ts.mjs +1 -0
- package/dist/{random-D6srtOfs.mjs → random-CJ6fASpe.mjs} +1 -1
- package/dist/{schema-check-2a0t7Pu_.mjs → schema-check-BzXTKlLa.mjs} +2 -2
- package/dist/sqlite-adapter-C3S1ojF-.mjs +1 -0
- package/dist/sqlite-introspector-DSCAP82F-uK1vwYwN.mjs +5 -0
- package/dist/web/assets/index-DZ3X5haa.js +49 -0
- package/dist/web/index.html +1 -1
- package/package.json +6 -6
- package/dist/bun-sqlite-dialect-C7ftEUSI-DFKViJQ3.mjs +0 -1
- package/dist/compiled-query-xtJR566p.mjs +0 -1
- package/dist/d1-sqlite-dialect-D4qp4-wW-Rqu1eTED.mjs +0 -1
- package/dist/default-query-compiler-DTJtuKGc.mjs +0 -1
- package/dist/dist-DpbKAALD.mjs +0 -1
- package/dist/dist-lqtcybuJ.mjs +0 -17
- package/dist/factory-BZXyDHm6.mjs +0 -6
- package/dist/kysely-adapter-C-VVCuVS.mjs +0 -1
- package/dist/kysely-migration-tables-DFfmKhq--DIOBV7Sd.mjs +0 -1
- package/dist/sqlite-adapter-BG0MClj_.mjs +0 -1
- package/dist/web/assets/index-DRS92SVP.js +0 -49
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,t}from"./dist-DmipO4_i.mjs";export{t as createKyselyAdapter,e as kyselyAdapter};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{N as e}from"./schemas-CYxWglEB.mjs";const t=Symbol.for(`better-auth:global`);let n=null;const r={},i=`1.7.5`;function a(){return globalThis[t]||(globalThis[t]={version:i,epoch:1,context:r},n=globalThis[t]),n=globalThis[t],n.version!==i&&(n.version=i,n.epoch++),globalThis[t]}function o(){return a().context.endpointContextAsyncStorage?.getStore()}function s(){return a().version}const c=Object.create(null),l=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?c:globalThis),u=new Proxy(c,{get(e,t){return l()[t]??c[t]},has(e,t){return t in l()||t in c},set(e,t,n){let r=l(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=l(!0);return delete n[t],!0},ownKeys(){let e=l(!0);return Object.keys(e)}});function d(e){return e?e!==`false`:!1}const f=u.NODE_ENV??``,ee=f===`production`,p=()=>f===`dev`||f===`development`,m=()=>f===`test`||d(u.TEST);function h(e,t){return typeof process<`u`&&process.env?process.env[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}function te(e,t=!0){let n=h(e);return n?n!==`0`&&n.toLowerCase()!==`false`&&n!==``:t}const ne=Object.freeze({get BETTER_AUTH_SECRET(){return h(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return h(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return h(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return h(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return h(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return h(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return h(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}}),g={eterm:4,cons25:4,console:4,cygwin:4,dtterm:4,gnome:4,hurd:4,jfbterm:4,konsole:4,kterm:4,mlterm:4,mosh:24,putty:4,st:4,"rxvt-unicode-24bit":24,terminator:24,"xterm-kitty":24},_=new Map(Object.entries({APPVEYOR:8,BUILDKITE:8,CIRCLECI:24,DRONE:8,GITEA_ACTIONS:24,GITHUB_ACTIONS:24,GITLAB_CI:8,TRAVIS:8})),v=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function y(){if(h(`FORCE_COLOR`)!==void 0)switch(h(`FORCE_COLOR`)){case``:case`1`:case`true`:return 4;case`2`:return 8;case`3`:return 24;default:return 1}if(h(`NODE_DISABLE_COLORS`)!==void 0&&h(`NODE_DISABLE_COLORS`)!==``||h(`NO_COLOR`)!==void 0&&h(`NO_COLOR`)!==``||h(`TERM`)===`dumb`)return 1;if(h(`TMUX`))return 24;if(`TF_BUILD`in u&&`AGENT_NAME`in u)return 4;if(`CI`in u){for(let{0:e,1:t}of _)if(e in u)return t;return h(`CI_NAME`)===`codeship`?8:1}if(`TEAMCITY_VERSION`in u)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(h(`TEAMCITY_VERSION`))===null?1:4;switch(h(`TERM_PROGRAM`)){case`iTerm.app`:return!h(`TERM_PROGRAM_VERSION`)||/^[0-2]\./.exec(h(`TERM_PROGRAM_VERSION`))!==null?8:24;case`HyperTerm`:case`MacTerm`:return 24;case`Apple_Terminal`:return 8}if(h(`COLORTERM`)===`truecolor`||h(`COLORTERM`)===`24bit`)return 24;if(h(`TERM`)){if(/truecolor/.exec(h(`TERM`))!==null)return 24;if(/^xterm-256/.exec(h(`TERM`))!==null)return 8;let e=h(`TERM`).toLowerCase();if(g[e])return g[e];if(v.some(t=>t.exec(e)!==null))return 4}return h(`COLORTERM`)?4:1}const b={reset:`\x1B[0m`,bright:`\x1B[1m`,dim:`\x1B[2m`,undim:`\x1B[22m`,underscore:`\x1B[4m`,blink:`\x1B[5m`,reverse:`\x1B[7m`,hidden:`\x1B[8m`,fg:{black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},bg:{black:`\x1B[40m`,red:`\x1B[41m`,green:`\x1B[42m`,yellow:`\x1B[43m`,blue:`\x1B[44m`,magenta:`\x1B[45m`,cyan:`\x1B[46m`,white:`\x1B[47m`}},x=[`debug`,`info`,`success`,`warn`,`error`];function S(e,t){return x.indexOf(t)>=x.indexOf(e)}const re={info:b.fg.blue,success:b.fg.green,warn:b.fg.yellow,error:b.fg.red,debug:b.fg.magenta},C=(e,t,n)=>{let r=(/* @__PURE__ */ new Date()).toISOString();return n?`${b.dim}${r}${b.reset} ${re[e]}${e.toUpperCase()}${b.reset} ${b.bright}[Better Auth]:${b.reset} ${t}`:`${r} ${e.toUpperCase()} [Better Auth]: ${t}`},w=e=>{let t=e?.disabled!==!0,n=e?.level??`warn`,r=e?.disableColors===void 0?y()!==1:!e.disableColors,i=(i,a,o=[])=>{if(!t||!S(n,i))return;let s=C(i,a,r);if(!e||typeof e.log!=`function`){i===`error`?console.error(s,...o):i===`warn`?console.warn(s,...o):console.log(s,...o);return}e.log(i===`success`?`info`:i,a,...o)};return{...Object.fromEntries(x.map(e=>[e,(...[t,...n])=>i(e,t,n)])),get level(){return n}}},T=w(),E=()=>{let e=o()?.context.logger;return e&&e!==D?e:T},D={debug:(...e)=>E().debug(...e),info:(...e)=>E().info(...e),success:(...e)=>E().success(...e),warn:(...e)=>E().warn(...e),error:(...e)=>E().error(...e),get level(){return E().level}};function O(e){return e.toLowerCase()}function k(e){return new TextEncoder().encode(e).length}function ie(e,t){let n=``,r=0;for(let i of e){let e=k(i);if(r+e>t)break;n+=i,r+=e}return n}function ae(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,`0`)}function A(t,n){if(n.name!==void 0){if(n.name.trim().length===0)throw new e(`Database index names must contain at least one visible character.`);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(n.name))throw new e(`Database index names must start with a letter or underscore and contain only letters, numbers, and underscores.`);if(k(n.name)>63)throw new e(`Database index names must be at most 63 UTF-8 bytes.`);return n.name}let r=n.unique?`uidx`:`idx`,i=`${t}_${n.fields.join(`_`)}_${r}`;if(k(i)<=63)return i;let a=`_${ae(i)}_${r}`;return`${ie(i.slice(0,-r.length-1),63-k(a))}${a}`}function j(e,t,n){return A(e,{fields:[t],unique:n})}function M({fields:t,indexes:n,tableName:r}){let i=(n??[]).map(n=>{if(n.fields.length===0)throw new e(`Index on table "${r}" must include at least one field.`);if(n.fields.length>16)throw new e(`Index on table "${r}" can include at most 16 fields so it works across supported databases.`);if(new Set(n.fields).size!==n.fields.length)throw new e(`Index on table "${r}" contains the same field more than once.`);if(n.unique&&n.fields.some(e=>t[e]?.required===!1))throw new e(`Unique index on table "${r}" can only include required fields so its behavior is consistent across databases.`);let i=n.fields.find(e=>{let n=t[e]?.type;return n===`json`||n===`string[]`||n===`number[]`});if(i)throw new e(`Index on table "${r}" references field "${i}", whose type is not portably indexable.`);let a=n=>{let i=t[n];if(!i)throw new e(`Index on table "${r}" references unknown field "${n}".`);return i.fieldName||n},[o,...s]=n.fields,c=[a(o),...s.map(a)];if(new Set(c.map(O)).size!==c.length)throw new e(`Index on table "${r}" resolves more than one field to the same database column.`);return{columns:c,name:A(r,{...n,fields:c}),unique:n.unique}}),a=/* @__PURE__ */ new Map,o=[];for(let t of i){let n=JSON.stringify([t.columns,t.unique??!1]),i=O(t.name),s=a.get(i);if(s&&s!==n)throw new e(`Database index name "${t.name}" identifies more than one index on table "${r}".`);s||(a.set(i,n),o.push(t))}return o}function N({columnName:e,dialect:t,fields:n,indexes:r}){let i=new Map(Object.entries(n).map(([e,t])=>[t.fieldName||e,t])),a=r.filter(t=>t.columns.includes(e));if(a.length===0)return;let o=t===`mysql`?3072:1700,s=t===`mysql`?4:1,c=t===`mysql`?191:255;return a.reduce((e,t)=>{let n=t.columns.filter(e=>{let t=i.get(e)?.type;return t===`string`||Array.isArray(t)}).length;if(n===0)return e;let r=(t.columns.length-n)*16,a=Math.floor(Math.max(1,o-r)/s/n);return Math.min(e,a)},c)}function P(t){let n=/* @__PURE__ */ new Map;for(let r of t){let t=n.get(r.tableName);if(t){if(t.indexes.length>0||(r.indexes?.length??0)>0)throw new e(`Database schema resolves more than one indexed logical table to "${r.tableName}". Define table-level indexes through one logical schema key instead of aliasing multiple keys to the same database table.`);Object.assign(t.fields,r.fields);continue}let i={fields:{},indexes:[],tableName:r.tableName};Object.assign(i.fields,r.fields),i.indexes.push(...r.indexes??[]),n.set(r.tableName,i)}let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=new Map([...n.keys()].map(e=>[O(e),e])),o=/* @__PURE__ */ new Map;for(let t of n.values())for(let[n,r]of Object.entries(t.fields)){if(!r.index&&!r.unique)continue;let i=j(t.tableName,r.fieldName||n,r.unique??!1),s=O(i);if(a.has(s))throw new e(`Database index name "${i}" conflicts with a table name. Index and table names must be unique across the schema.`);let c=o.get(s);if(c)throw new e(`Database field-level index name "${i}" is used by both table "${c}" and table "${t.tableName}".`);o.set(s,t.tableName)}for(let t of n.values()){let n=M(t);r.set(t.tableName,[...n]);for(let r of n){let n=O(r.name);if(a.has(n))throw new e(`Database index name "${r.name}" conflicts with a table name. Index and table names must be unique across the schema.`);let s=o.get(n);if(s)throw new e(`Database index name "${r.name}" is already reserved by field-level index metadata on table "${s}". Remove the duplicate table-level index or give it a distinct name.`);let c=i.get(n);if(c&&c!==t.tableName)throw new e(`Database index name "${r.name}" is used by both table "${c}" and table "${t.tableName}". Index names must be unique across the schema.`);i.set(n,t.tableName)}}return r}function F(...e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e.flatMap(e=>e??[])){let e=JSON.stringify([r.name??null,r.fields,r.unique??!1]);n.has(e)||(n.add(e),t.push(r))}return t}const I=e=>{let t=(e.plugins??[]).reduce((e,t)=>{let n=t.schema;if(!n)return e;for(let[t,r]of Object.entries(n))e[t]={fields:{...e[t]?.fields,...r.fields},indexes:F(e[t]?.indexes,r.indexes),modelName:r.modelName||t,disableMigrations:r.disableMigration??e[t]?.disableMigrations};return e},{}),n=e.rateLimit?.storage===`database`,r={rateLimit:{modelName:e.rateLimit?.modelName||`rateLimit`,fields:{key:{type:`string`,unique:!0,required:!0,fieldName:e.rateLimit?.fields?.key||`key`},count:{type:`number`,required:!0,fieldName:e.rateLimit?.fields?.count||`count`},lastRequest:{type:`number`,bigint:!0,required:!0,fieldName:e.rateLimit?.fields?.lastRequest||`lastRequest`,defaultValue:()=>Date.now()}}}},{user:i,session:a,account:o,verification:s,...c}=t,l={verification:{modelName:e.verification?.modelName||`verification`,indexes:s?.indexes,fields:{identifier:{type:`string`,required:!0,fieldName:e.verification?.fields?.identifier||`identifier`,index:!0},value:{type:`string`,required:!0,fieldName:e.verification?.fields?.value||`value`},expiresAt:{type:`date`,required:!0,fieldName:e.verification?.fields?.expiresAt||`expiresAt`},createdAt:{type:`date`,required:!0,defaultValue:()=>/* @__PURE__ */ new Date,fieldName:e.verification?.fields?.createdAt||`createdAt`},updatedAt:{type:`date`,required:!0,defaultValue:()=>/* @__PURE__ */ new Date,onUpdate:()=>/* @__PURE__ */ new Date,fieldName:e.verification?.fields?.updatedAt||`updatedAt`},...s?.fields,...e.verification?.additionalFields},order:4}},u={session:{modelName:e.session?.modelName||`session`,indexes:a?.indexes,fields:{expiresAt:{type:`date`,required:!0,fieldName:e.session?.fields?.expiresAt||`expiresAt`},token:{type:`string`,required:!0,fieldName:e.session?.fields?.token||`token`,unique:!0},createdAt:{type:`date`,required:!0,fieldName:e.session?.fields?.createdAt||`createdAt`,defaultValue:()=>/* @__PURE__ */ new Date},updatedAt:{type:`date`,required:!0,fieldName:e.session?.fields?.updatedAt||`updatedAt`,onUpdate:()=>/* @__PURE__ */ new Date},ipAddress:{type:`string`,required:!1,fieldName:e.session?.fields?.ipAddress||`ipAddress`},userAgent:{type:`string`,required:!1,fieldName:e.session?.fields?.userAgent||`userAgent`},userId:{type:`string`,fieldName:e.session?.fields?.userId||`userId`,references:{model:`user`,field:`id`,onDelete:`cascade`},required:!0,index:!0},...a?.fields,...e.session?.additionalFields},order:2}};return{user:{modelName:e.user?.modelName||`user`,indexes:i?.indexes,fields:{name:{type:`string`,required:!0,fieldName:e.user?.fields?.name||`name`,sortable:!0},email:{type:`string`,unique:!0,required:!0,fieldName:e.user?.fields?.email||`email`,sortable:!0},emailVerified:{type:`boolean`,defaultValue:!1,required:!0,fieldName:e.user?.fields?.emailVerified||`emailVerified`,input:!1},image:{type:`string`,required:!1,fieldName:e.user?.fields?.image||`image`},createdAt:{type:`date`,defaultValue:()=>/* @__PURE__ */ new Date,required:!0,fieldName:e.user?.fields?.createdAt||`createdAt`},updatedAt:{type:`date`,defaultValue:()=>/* @__PURE__ */ new Date,onUpdate:()=>/* @__PURE__ */ new Date,required:!0,fieldName:e.user?.fields?.updatedAt||`updatedAt`},...i?.fields,...e.user?.additionalFields},order:1},...!e.secondaryStorage||e.session?.storeSessionInDatabase?u:{},account:{modelName:e.account?.modelName||`account`,indexes:o?.indexes,fields:{accountId:{type:`string`,required:!0,fieldName:e.account?.fields?.accountId||`accountId`},providerId:{type:`string`,required:!0,fieldName:e.account?.fields?.providerId||`providerId`},userId:{type:`string`,references:{model:`user`,field:`id`,onDelete:`cascade`},required:!0,fieldName:e.account?.fields?.userId||`userId`,index:!0},accessToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.accessToken||`accessToken`},refreshToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.refreshToken||`refreshToken`},idToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.idToken||`idToken`},accessTokenExpiresAt:{type:`date`,required:!1,returned:!1,fieldName:e.account?.fields?.accessTokenExpiresAt||`accessTokenExpiresAt`},refreshTokenExpiresAt:{type:`date`,required:!1,returned:!1,fieldName:e.account?.fields?.refreshTokenExpiresAt||`refreshTokenExpiresAt`},scope:{type:`string`,required:!1,fieldName:e.account?.fields?.scope||`scope`},password:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.password||`password`},createdAt:{type:`date`,required:!0,fieldName:e.account?.fields?.createdAt||`createdAt`,defaultValue:()=>/* @__PURE__ */ new Date},updatedAt:{type:`date`,required:!0,fieldName:e.account?.fields?.updatedAt||`updatedAt`,onUpdate:()=>/* @__PURE__ */ new Date},...o?.fields,...e.account?.additionalFields},order:3},...!e.secondaryStorage||e.verification?.storeInDatabase?l:{},...c,...n?r:{}}};function L(e){let t=I(e);return{indexesByTable:P(Object.values(t).filter(e=>!(`disableMigrations`in e)||!e.disableMigrations).map(e=>({fields:e.fields,indexes:`indexes`in e?e.indexes:void 0,tableName:e.modelName}))),tables:t}}const R=e=>L(e).tables,z=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;function B(e){if(typeof e==`string`&&z.test(e)){let t=new Date(e);if(!isNaN(t.getTime()))return t}return e}function V(e){if(e==null)return e;if(typeof e==`string`)return B(e);if(e instanceof Date)return e;if(Array.isArray(e))return e.map(V);if(typeof e==`object`){let t={};for(let n of Object.keys(e))t[n]=V(e[n]);return t}return e}function H(e){try{return typeof e==`string`?JSON.parse(e,(e,t)=>B(t)):e==null?null:V(e)}catch(e){return D.error(`Error parsing JSON`,{error:e}),null}}const U=`db.collection.name`,W=`db.operation.name`,G=`http.response.status_code`,K=`http.route`;function q(){let e={end(){},setAttribute(e,t){},setStatus(e){},recordException(e){},updateName(t){return e}};return e}function J(e){function t(t,...n){let r=n[n.length-1];return r(e)}return{startActiveSpan:t}}function oe(){let e=J(q());return{getTracer(t,n){return e},getActiveSpan(){}}}function se(){return{SpanStatusCode:{UNSET:0,OK:1,ERROR:2},trace:oe()}}const Y=se();function ce(e,t,n){return n()}let le,X;async function ue(){try{X=await import(`./esm-CdWTLqG7.mjs`)}catch{}}function Z(){return le||=ue(),X??Y}function de(e){if(typeof e==`object`&&e&&`name`in e&&e.name===`APIError`&&`statusCode`in e){let t=e.statusCode;return t>=300&&t<400}return!1}function Q(e,t){let{SpanStatusCode:n}=Z();de(t)?(e.setAttribute(G,t.statusCode),e.setStatus({code:n.OK})):(e.recordException(t),e.setStatus({code:n.ERROR,message:String(t?.message??t)})),e.end()}function fe(e,t,n){let{trace:r}=Z();return r.getTracer(`better-auth`,`1.7.5`).startActiveSpan(e,{attributes:t},e=>{try{let t=n();return t instanceof Promise?t.then(t=>(e.end(),t)).catch(t=>{throw Q(e,t),t}):(e.end(),t)}catch(t){throw Q(e,t),t}})}function pe(e){return e.experimental?.instrumentation?.enabled===!1?ce:fe}function $(e){switch(e){case`a-z`:return`abcdefghijklmnopqrstuvwxyz`;case`A-Z`:return`ABCDEFGHIJKLMNOPQRSTUVWXYZ`;case`0-9`:return`0123456789`;case`-_`:return`-_`;default:throw Error(`Unsupported alphabet: ${e}`)}}function me(...e){let t=e.map($).join(``);if(t.length===0)throw Error(`No valid characters provided for random string generation.`);let n=t.length;return(e,...r)=>{if(e<=0)throw Error(`Length must be a positive integer.`);let i=t,a=n;r.length>0&&(i=r.map($).join(``),a=i.length);let o=Math.floor(256/a)*a,s=new Uint8Array(e*2),c=s.length,l=``,u=c,d;for(;l.length<e;)u>=c&&(crypto.getRandomValues(s),u=0),d=s[u++],d<o&&(l+=i[d%a]);return l}}export{ee as C,s as D,o as E,p as S,a as T,y as _,G as a,te as b,R as c,N as d,O as f,S as g,D as h,W as i,L as l,w as m,pe as n,K as o,b as p,U as r,H as s,me as t,j as u,ne as v,m as w,h as x,u as y};
|
|
1
|
+
import{N as e}from"./schemas-CYxWglEB.mjs";const t=Symbol.for(`better-auth:global`);let n=null;const r={},i=`1.7.7`;function a(){return globalThis[t]||(globalThis[t]={version:i,epoch:1,context:r},n=globalThis[t]),n=globalThis[t],n.version!==i&&(n.version=i,n.epoch++),globalThis[t]}function o(){return a().context.endpointContextAsyncStorage?.getStore()}function s(){return a().version}const c=Object.create(null),l=e=>globalThis.process?.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?c:globalThis),u=new Proxy(c,{get(e,t){return l()[t]??c[t]},has(e,t){return t in l()||t in c},set(e,t,n){let r=l(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=l(!0);return delete n[t],!0},ownKeys(){let e=l(!0);return Object.keys(e)}});function d(e){return e?e!==`false`:!1}const f=u.NODE_ENV??``,ee=f===`production`,p=()=>f===`dev`||f===`development`,m=()=>f===`test`||d(u.TEST);function h(e,t){return typeof process<`u`&&process.env?process.env[e]??t:typeof Deno<`u`?Deno.env.get(e)??t:typeof Bun<`u`?Bun.env[e]??t:t}function te(e,t=!0){let n=h(e);return n?n!==`0`&&n.toLowerCase()!==`false`&&n!==``:t}const ne=Object.freeze({get BETTER_AUTH_SECRET(){return h(`BETTER_AUTH_SECRET`)},get AUTH_SECRET(){return h(`AUTH_SECRET`)},get BETTER_AUTH_TELEMETRY(){return h(`BETTER_AUTH_TELEMETRY`)},get BETTER_AUTH_TELEMETRY_ID(){return h(`BETTER_AUTH_TELEMETRY_ID`)},get NODE_ENV(){return h(`NODE_ENV`,`development`)},get PACKAGE_VERSION(){return h(`PACKAGE_VERSION`,`0.0.0`)},get BETTER_AUTH_TELEMETRY_ENDPOINT(){return h(`BETTER_AUTH_TELEMETRY_ENDPOINT`,``)}}),g={eterm:4,cons25:4,console:4,cygwin:4,dtterm:4,gnome:4,hurd:4,jfbterm:4,konsole:4,kterm:4,mlterm:4,mosh:24,putty:4,st:4,"rxvt-unicode-24bit":24,terminator:24,"xterm-kitty":24},_=new Map(Object.entries({APPVEYOR:8,BUILDKITE:8,CIRCLECI:24,DRONE:8,GITEA_ACTIONS:24,GITHUB_ACTIONS:24,GITLAB_CI:8,TRAVIS:8})),v=[/ansi/,/color/,/linux/,/direct/,/^con[0-9]*x[0-9]/,/^rxvt/,/^screen/,/^xterm/,/^vt100/,/^vt220/];function y(){if(h(`FORCE_COLOR`)!==void 0)switch(h(`FORCE_COLOR`)){case``:case`1`:case`true`:return 4;case`2`:return 8;case`3`:return 24;default:return 1}if(h(`NODE_DISABLE_COLORS`)!==void 0&&h(`NODE_DISABLE_COLORS`)!==``||h(`NO_COLOR`)!==void 0&&h(`NO_COLOR`)!==``||h(`TERM`)===`dumb`)return 1;if(h(`TMUX`))return 24;if(`TF_BUILD`in u&&`AGENT_NAME`in u)return 4;if(`CI`in u){for(let{0:e,1:t}of _)if(e in u)return t;return h(`CI_NAME`)===`codeship`?8:1}if(`TEAMCITY_VERSION`in u)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(h(`TEAMCITY_VERSION`))===null?1:4;switch(h(`TERM_PROGRAM`)){case`iTerm.app`:return!h(`TERM_PROGRAM_VERSION`)||/^[0-2]\./.exec(h(`TERM_PROGRAM_VERSION`))!==null?8:24;case`HyperTerm`:case`MacTerm`:return 24;case`Apple_Terminal`:return 8}if(h(`COLORTERM`)===`truecolor`||h(`COLORTERM`)===`24bit`)return 24;if(h(`TERM`)){if(/truecolor/.exec(h(`TERM`))!==null)return 24;if(/^xterm-256/.exec(h(`TERM`))!==null)return 8;let e=h(`TERM`).toLowerCase();if(g[e])return g[e];if(v.some(t=>t.exec(e)!==null))return 4}return h(`COLORTERM`)?4:1}const b={reset:`\x1B[0m`,bright:`\x1B[1m`,dim:`\x1B[2m`,undim:`\x1B[22m`,underscore:`\x1B[4m`,blink:`\x1B[5m`,reverse:`\x1B[7m`,hidden:`\x1B[8m`,fg:{black:`\x1B[30m`,red:`\x1B[31m`,green:`\x1B[32m`,yellow:`\x1B[33m`,blue:`\x1B[34m`,magenta:`\x1B[35m`,cyan:`\x1B[36m`,white:`\x1B[37m`},bg:{black:`\x1B[40m`,red:`\x1B[41m`,green:`\x1B[42m`,yellow:`\x1B[43m`,blue:`\x1B[44m`,magenta:`\x1B[45m`,cyan:`\x1B[46m`,white:`\x1B[47m`}},x=[`debug`,`info`,`success`,`warn`,`error`];function S(e,t){return x.indexOf(t)>=x.indexOf(e)}const re={info:b.fg.blue,success:b.fg.green,warn:b.fg.yellow,error:b.fg.red,debug:b.fg.magenta},C=(e,t,n)=>{let r=(/* @__PURE__ */ new Date()).toISOString();return n?`${b.dim}${r}${b.reset} ${re[e]}${e.toUpperCase()}${b.reset} ${b.bright}[Better Auth]:${b.reset} ${t}`:`${r} ${e.toUpperCase()} [Better Auth]: ${t}`},w=e=>{let t=e?.disabled!==!0,n=e?.level??`warn`,r=e?.disableColors===void 0?y()!==1:!e.disableColors,i=(i,a,o=[])=>{if(!t||!S(n,i))return;let s=C(i,a,r);if(!e||typeof e.log!=`function`){i===`error`?console.error(s,...o):i===`warn`?console.warn(s,...o):console.log(s,...o);return}e.log(i===`success`?`info`:i,a,...o)};return{...Object.fromEntries(x.map(e=>[e,(...[t,...n])=>i(e,t,n)])),get level(){return n}}},T=w(),E=()=>{let e=o()?.context.logger;return e&&e!==D?e:T},D={debug:(...e)=>E().debug(...e),info:(...e)=>E().info(...e),success:(...e)=>E().success(...e),warn:(...e)=>E().warn(...e),error:(...e)=>E().error(...e),get level(){return E().level}};function O(e){return e.toLowerCase()}function k(e){return new TextEncoder().encode(e).length}function ie(e,t){let n=``,r=0;for(let i of e){let e=k(i);if(r+e>t)break;n+=i,r+=e}return n}function ae(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,`0`)}function A(t,n){if(n.name!==void 0){if(n.name.trim().length===0)throw new e(`Database index names must contain at least one visible character.`);if(!/^[A-Za-z_][A-Za-z0-9_]*$/.test(n.name))throw new e(`Database index names must start with a letter or underscore and contain only letters, numbers, and underscores.`);if(k(n.name)>63)throw new e(`Database index names must be at most 63 UTF-8 bytes.`);return n.name}let r=n.unique?`uidx`:`idx`,i=`${t}_${n.fields.join(`_`)}_${r}`;if(k(i)<=63)return i;let a=`_${ae(i)}_${r}`;return`${ie(i.slice(0,-r.length-1),63-k(a))}${a}`}function j(e,t,n){return A(e,{fields:[t],unique:n})}function M({fields:t,indexes:n,tableName:r}){let i=(n??[]).map(n=>{if(n.fields.length===0)throw new e(`Index on table "${r}" must include at least one field.`);if(n.fields.length>16)throw new e(`Index on table "${r}" can include at most 16 fields so it works across supported databases.`);if(new Set(n.fields).size!==n.fields.length)throw new e(`Index on table "${r}" contains the same field more than once.`);if(n.unique&&n.fields.some(e=>t[e]?.required===!1))throw new e(`Unique index on table "${r}" can only include required fields so its behavior is consistent across databases.`);let i=n.fields.find(e=>{let n=t[e]?.type;return n===`json`||n===`string[]`||n===`number[]`});if(i)throw new e(`Index on table "${r}" references field "${i}", whose type is not portably indexable.`);let a=n=>{let i=t[n];if(!i)throw new e(`Index on table "${r}" references unknown field "${n}".`);return i.fieldName||n},[o,...s]=n.fields,c=[a(o),...s.map(a)];if(new Set(c.map(O)).size!==c.length)throw new e(`Index on table "${r}" resolves more than one field to the same database column.`);return{columns:c,name:A(r,{...n,fields:c}),unique:n.unique}}),a=/* @__PURE__ */ new Map,o=[];for(let t of i){let n=JSON.stringify([t.columns,t.unique??!1]),i=O(t.name),s=a.get(i);if(s&&s!==n)throw new e(`Database index name "${t.name}" identifies more than one index on table "${r}".`);s||(a.set(i,n),o.push(t))}return o}function N({columnName:e,dialect:t,fields:n,indexes:r}){let i=new Map(Object.entries(n).map(([e,t])=>[t.fieldName||e,t])),a=r.filter(t=>t.columns.includes(e));if(a.length===0)return;let o=t===`mysql`?3072:1700,s=t===`mysql`?4:1,c=t===`mysql`?191:255;return a.reduce((e,t)=>{let n=t.columns.filter(e=>{let t=i.get(e)?.type;return t===`string`||Array.isArray(t)}).length;if(n===0)return e;let r=(t.columns.length-n)*16,a=Math.floor(Math.max(1,o-r)/s/n);return Math.min(e,a)},c)}function P(t){let n=/* @__PURE__ */ new Map;for(let r of t){let t=n.get(r.tableName);if(t){if(t.indexes.length>0||(r.indexes?.length??0)>0)throw new e(`Database schema resolves more than one indexed logical table to "${r.tableName}". Define table-level indexes through one logical schema key instead of aliasing multiple keys to the same database table.`);Object.assign(t.fields,r.fields);continue}let i={fields:{},indexes:[],tableName:r.tableName};Object.assign(i.fields,r.fields),i.indexes.push(...r.indexes??[]),n.set(r.tableName,i)}let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=new Map([...n.keys()].map(e=>[O(e),e])),o=/* @__PURE__ */ new Map;for(let t of n.values())for(let[n,r]of Object.entries(t.fields)){if(!r.index&&!r.unique)continue;let i=j(t.tableName,r.fieldName||n,r.unique??!1),s=O(i);if(a.has(s))throw new e(`Database index name "${i}" conflicts with a table name. Index and table names must be unique across the schema.`);let c=o.get(s);if(c)throw new e(`Database field-level index name "${i}" is used by both table "${c}" and table "${t.tableName}".`);o.set(s,t.tableName)}for(let t of n.values()){let n=M(t);r.set(t.tableName,[...n]);for(let r of n){let n=O(r.name);if(a.has(n))throw new e(`Database index name "${r.name}" conflicts with a table name. Index and table names must be unique across the schema.`);let s=o.get(n);if(s)throw new e(`Database index name "${r.name}" is already reserved by field-level index metadata on table "${s}". Remove the duplicate table-level index or give it a distinct name.`);let c=i.get(n);if(c&&c!==t.tableName)throw new e(`Database index name "${r.name}" is used by both table "${c}" and table "${t.tableName}". Index names must be unique across the schema.`);i.set(n,t.tableName)}}return r}function F(...e){let t=[],n=/* @__PURE__ */ new Set;for(let r of e.flatMap(e=>e??[])){let e=JSON.stringify([r.name??null,r.fields,r.unique??!1]);n.has(e)||(n.add(e),t.push(r))}return t}const I=e=>{let t=(e.plugins??[]).reduce((e,t)=>{let n=t.schema;if(!n)return e;for(let[t,r]of Object.entries(n))e[t]={fields:{...e[t]?.fields,...r.fields},indexes:F(e[t]?.indexes,r.indexes),modelName:r.modelName||t,disableMigrations:r.disableMigration??e[t]?.disableMigrations};return e},{}),n=e.rateLimit?.storage===`database`,r={rateLimit:{modelName:e.rateLimit?.modelName||`rateLimit`,fields:{key:{type:`string`,unique:!0,required:!0,fieldName:e.rateLimit?.fields?.key||`key`},count:{type:`number`,required:!0,fieldName:e.rateLimit?.fields?.count||`count`},lastRequest:{type:`number`,bigint:!0,required:!0,fieldName:e.rateLimit?.fields?.lastRequest||`lastRequest`,defaultValue:()=>Date.now()}}}},{user:i,session:a,account:o,verification:s,...c}=t,l={verification:{modelName:e.verification?.modelName||`verification`,indexes:s?.indexes,fields:{identifier:{type:`string`,required:!0,fieldName:e.verification?.fields?.identifier||`identifier`,index:!0},value:{type:`string`,required:!0,fieldName:e.verification?.fields?.value||`value`},expiresAt:{type:`date`,required:!0,fieldName:e.verification?.fields?.expiresAt||`expiresAt`},createdAt:{type:`date`,required:!0,defaultValue:()=>/* @__PURE__ */ new Date,fieldName:e.verification?.fields?.createdAt||`createdAt`},updatedAt:{type:`date`,required:!0,defaultValue:()=>/* @__PURE__ */ new Date,onUpdate:()=>/* @__PURE__ */ new Date,fieldName:e.verification?.fields?.updatedAt||`updatedAt`},...s?.fields,...e.verification?.additionalFields},order:4}},u={session:{modelName:e.session?.modelName||`session`,indexes:a?.indexes,fields:{expiresAt:{type:`date`,required:!0,fieldName:e.session?.fields?.expiresAt||`expiresAt`},token:{type:`string`,required:!0,fieldName:e.session?.fields?.token||`token`,unique:!0},createdAt:{type:`date`,required:!0,fieldName:e.session?.fields?.createdAt||`createdAt`,defaultValue:()=>/* @__PURE__ */ new Date},updatedAt:{type:`date`,required:!0,fieldName:e.session?.fields?.updatedAt||`updatedAt`,onUpdate:()=>/* @__PURE__ */ new Date},ipAddress:{type:`string`,required:!1,fieldName:e.session?.fields?.ipAddress||`ipAddress`},userAgent:{type:`string`,required:!1,fieldName:e.session?.fields?.userAgent||`userAgent`},userId:{type:`string`,fieldName:e.session?.fields?.userId||`userId`,references:{model:`user`,field:`id`,onDelete:`cascade`},required:!0,index:!0},...a?.fields,...e.session?.additionalFields},order:2}};return{user:{modelName:e.user?.modelName||`user`,indexes:i?.indexes,fields:{name:{type:`string`,required:!0,fieldName:e.user?.fields?.name||`name`,sortable:!0},email:{type:`string`,unique:!0,required:!0,fieldName:e.user?.fields?.email||`email`,sortable:!0},emailVerified:{type:`boolean`,defaultValue:!1,required:!0,fieldName:e.user?.fields?.emailVerified||`emailVerified`,input:!1},image:{type:`string`,required:!1,fieldName:e.user?.fields?.image||`image`},createdAt:{type:`date`,defaultValue:()=>/* @__PURE__ */ new Date,required:!0,fieldName:e.user?.fields?.createdAt||`createdAt`},updatedAt:{type:`date`,defaultValue:()=>/* @__PURE__ */ new Date,onUpdate:()=>/* @__PURE__ */ new Date,required:!0,fieldName:e.user?.fields?.updatedAt||`updatedAt`},...i?.fields,...e.user?.additionalFields},order:1},...!e.secondaryStorage||e.session?.storeSessionInDatabase?u:{},account:{modelName:e.account?.modelName||`account`,indexes:o?.indexes,fields:{accountId:{type:`string`,required:!0,fieldName:e.account?.fields?.accountId||`accountId`},providerId:{type:`string`,required:!0,fieldName:e.account?.fields?.providerId||`providerId`},userId:{type:`string`,references:{model:`user`,field:`id`,onDelete:`cascade`},required:!0,fieldName:e.account?.fields?.userId||`userId`,index:!0},accessToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.accessToken||`accessToken`},refreshToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.refreshToken||`refreshToken`},idToken:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.idToken||`idToken`},accessTokenExpiresAt:{type:`date`,required:!1,returned:!1,fieldName:e.account?.fields?.accessTokenExpiresAt||`accessTokenExpiresAt`},refreshTokenExpiresAt:{type:`date`,required:!1,returned:!1,fieldName:e.account?.fields?.refreshTokenExpiresAt||`refreshTokenExpiresAt`},scope:{type:`string`,required:!1,fieldName:e.account?.fields?.scope||`scope`},password:{type:`string`,required:!1,returned:!1,fieldName:e.account?.fields?.password||`password`},createdAt:{type:`date`,required:!0,fieldName:e.account?.fields?.createdAt||`createdAt`,defaultValue:()=>/* @__PURE__ */ new Date},updatedAt:{type:`date`,required:!0,fieldName:e.account?.fields?.updatedAt||`updatedAt`,onUpdate:()=>/* @__PURE__ */ new Date},...o?.fields,...e.account?.additionalFields},order:3},...!e.secondaryStorage||e.verification?.storeInDatabase?l:{},...c,...n?r:{}}};function L(e){let t=I(e);return{indexesByTable:P(Object.values(t).filter(e=>!(`disableMigrations`in e)||!e.disableMigrations).map(e=>({fields:e.fields,indexes:`indexes`in e?e.indexes:void 0,tableName:e.modelName}))),tables:t}}const R=e=>L(e).tables,z=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;function B(e){if(typeof e==`string`&&z.test(e)){let t=new Date(e);if(!isNaN(t.getTime()))return t}return e}function V(e){if(e==null)return e;if(typeof e==`string`)return B(e);if(e instanceof Date)return e;if(Array.isArray(e))return e.map(V);if(typeof e==`object`){let t={};for(let n of Object.keys(e))t[n]=V(e[n]);return t}return e}function H(e){try{return typeof e==`string`?JSON.parse(e,(e,t)=>B(t)):e==null?null:V(e)}catch(e){return D.error(`Error parsing JSON`,{error:e}),null}}const U=`db.collection.name`,W=`db.operation.name`,G=`http.response.status_code`,K=`http.route`;function q(){let e={end(){},setAttribute(e,t){},setStatus(e){},recordException(e){},updateName(t){return e}};return e}function J(e){function t(t,...n){let r=n[n.length-1];return r(e)}return{startActiveSpan:t}}function oe(){let e=J(q());return{getTracer(t,n){return e},getActiveSpan(){}}}function se(){return{SpanStatusCode:{UNSET:0,OK:1,ERROR:2},trace:oe()}}const Y=se();function ce(e,t,n){return n()}let le,X;async function ue(){try{X=await import(`./esm-CdWTLqG7.mjs`)}catch{}}function Z(){return le||=ue(),X??Y}function de(e){if(typeof e==`object`&&e&&`name`in e&&e.name===`APIError`&&`statusCode`in e){let t=e.statusCode;return t>=300&&t<400}return!1}function Q(e,t){let{SpanStatusCode:n}=Z();de(t)?(e.setAttribute(G,t.statusCode),e.setStatus({code:n.OK})):(e.recordException(t),e.setStatus({code:n.ERROR,message:String(t?.message??t)})),e.end()}function fe(e,t,n){let{trace:r}=Z();return r.getTracer(`better-auth`,`1.7.7`).startActiveSpan(e,{attributes:t},e=>{try{let t=n();return t instanceof Promise?t.then(t=>(e.end(),t)).catch(t=>{throw Q(e,t),t}):(e.end(),t)}catch(t){throw Q(e,t),t}})}function pe(e){return e.experimental?.instrumentation?.enabled===!1?ce:fe}function $(e){switch(e){case`a-z`:return`abcdefghijklmnopqrstuvwxyz`;case`A-Z`:return`ABCDEFGHIJKLMNOPQRSTUVWXYZ`;case`0-9`:return`0123456789`;case`-_`:return`-_`;default:throw Error(`Unsupported alphabet: ${e}`)}}function me(...e){let t=e.map($).join(``);if(t.length===0)throw Error(`No valid characters provided for random string generation.`);let n=t.length;return(e,...r)=>{if(e<=0)throw Error(`Length must be a positive integer.`);let i=t,a=n;r.length>0&&(i=r.map($).join(``),a=i.length);let o=Math.floor(256/a)*a,s=new Uint8Array(e*2),c=s.length,l=``,u=c,d;for(;l.length<e;)u>=c&&(crypto.getRandomValues(s),u=0),d=s[u++],d<o&&(l+=i[d%a]);return l}}export{ee as C,s as D,o as E,p as S,a as T,y as _,G as a,te as b,R as c,N as d,O as f,S as g,D as h,W as i,L as l,w as m,pe as n,K as o,b as p,U as r,H as s,me as t,j as u,ne as v,m as w,h as x,u as y};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{N as e}from"./schemas-CYxWglEB.mjs";import{c as t}from"./random-
|
|
1
|
+
import{N as e}from"./schemas-CYxWglEB.mjs";import{c as t}from"./random-CJ6fASpe.mjs";function n(e,{usePlural:n=!1}={}){let r={};for(let i of Object.values(t(e))){let e=n?`${i.modelName}s`:i.modelName,t=r[e]??={fields:{},disableMigrations:!0};for(let[e,n]of Object.entries(i.fields))t.fields[n.fieldName||e]=n;t.disableMigrations=t.disableMigrations&&!!i.disableMigrations}return r}function r(e,t){let n=[];for(let[r,i]of Object.entries(e)){if(i.disableMigrations)continue;let e=t.find(e=>e.name===r&&(i.schema===void 0||e.schema===i.schema));if(!e){n.push({kind:`missing-table`,table:r});continue}let a=/* @__PURE__ */ new Set([i.idColumn??`id`,...Object.keys(i.fields)]);for(let t of a)e.columns.some(e=>e.name===t)||n.push({kind:`missing-column`,table:r,column:t});for(let t of e.columns)a.has(t.name)||t.nullable||t.hasDefault||n.push({kind:`unexpected-required-column`,table:r,column:t.name})}return n}const i={database:"Run `npx auth migrate` to add it.",drizzle:"Run `npx auth generate` to refresh the Drizzle schema, then apply it with your migration tool.",prisma:"Run `npx auth generate` to refresh the Prisma schema, then run `prisma migrate`."},a={database:`Drop the column, make it nullable, or give it a database default.`,drizzle:`Remove it from the Drizzle schema, make it nullable, or give it a default, then apply the change with your migration tool.`,prisma:"Remove it from the Prisma schema, make it optional, or give it a default, then run `prisma migrate`."},o={database:`Database`,drizzle:`Drizzle`,prisma:`Prisma`};function s(e,t){switch(e.kind){case`missing-table`:return`Table "${e.table}" is missing. ${i[t]}`;case`missing-column`:return`Column "${e.column}" is missing from table "${e.table}". ${i[t]}`;case`unexpected-required-column`:{let n=e.column===`issuer`?` If this column came from Better Auth 1.7.0 through 1.7.2, follow the upgrade guide before removing it: https://www.better-auth.com/docs/guides/1-7-upgrade-guide`:``;return`Column "${e.column}" on table "${e.table}" is required but Better Auth never writes it, so every insert into "${e.table}" fails. ${a[t]}${n}`}}}const c={database:`Make the listed columns nullable, give them defaults, or remove them.`,drizzle:`Make the listed columns nullable in your Drizzle schema, give them defaults, or remove them.`,prisma:`Make the listed fields optional in your Prisma schema, give them defaults, or remove them.`},l={...i,database:"Run `npx auth migrate` to add the missing tables and columns."};function u(e,t){let n=[],r=[],i=[],a=/* @__PURE__ */ new Set,s=!1;for(let t of e)switch(t.kind){case`missing-table`:n.push(t.table);break;case`missing-column`:r.push(`${t.table}.${t.column}`);break;case`unexpected-required-column`:i.push(`${t.table}.${t.column}`),a.add(t.table),s||=t.column===`issuer`}let u=[`${o[t]} schema mismatch`];n.length&&u.push(` Missing tables\n ${n.join(`, `)}`),r.length&&u.push(` Missing columns\n ${r.join(`
|
|
2
2
|
`)}`),i.length&&(u.push(` Required columns Better Auth never writes\n ${i.join(`
|
|
3
3
|
`)}`),u.push(` Inserts into ${[...a].join(`, `)} will fail.`));let d=[];return i.length&&d.push(c[t]),(n.length||r.length||i.length&&t!==`database`)&&d.push(l[t]),d.length&&u.push(` help: ${d.join(`
|
|
4
4
|
`)}`),s&&u.push(` note: If this column came from Better Auth 1.7.0 through 1.7.2,
|
|
5
5
|
follow the upgrade guide before removing it:
|
|
6
6
|
https://www.better-auth.com/docs/guides/1-7-upgrade-guide`),u.join(`
|
|
7
7
|
|
|
8
|
-
`)}var d=class extends e{code=`SCHEMA_MISMATCH`;constructor(e,t){super(u(e,t)),this.findings=e,this.source=t}};function f(e){return e.advanced?.database?.validateSchema!==!1}const p=/* @__PURE__ */ new WeakMap,m=/* @__PURE__ */ new WeakMap;function h(e){let t=m.get(e);t&&t.value++}function g(e,t){p.set(e,t)}function _(e){return p.get(e)}function v(e,t,n){let r=n?m.get(n):void 0;n&&!r&&(r={value:0},m.set(n,r));let i=r?.value,a=!1,o
|
|
8
|
+
`)}var d=class extends e{code=`SCHEMA_MISMATCH`;constructor(e,t){super(u(e,t)),this.findings=e,this.source=t}};function f(e){return e.advanced?.database?.validateSchema!==!1}const p=/* @__PURE__ */ new WeakMap,m=/* @__PURE__ */ new WeakMap;function h(e){let t=m.get(e);t&&t.value++}function g(e,t,n={}){let r=n.runtimeEnabled??!0;p.set(e,{check:t,runtimeEnabled:r})}function _(e){return p.get(e)?.check}function v(e){let t=p.get(e);return t?.runtimeEnabled?t.check:void 0}function y(e,t,n){let r=n?m.get(n):void 0;n&&!r&&(r={value:0},m.set(n,r));let i=r?.value,a=!1,o,s=function n(){let s=r?.value;if(i!==s&&(i=s,a=!1,o=void 0),!a)return o??=Promise.resolve().then(e).then(e=>{if(r?.value!==s)return n();if(e.length)throw new d(e,t);i===s&&(a=!0)},e=>{if(r?.value!==s)return n();throw i===s&&(o=void 0),e})};return s.source=t,s}export{v as a,r as c,g as i,s as l,y as n,_ as o,h as r,d as s,f as t,n as u};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{s as e}from"./sqlite-introspector-DSCAP82F-uK1vwYwN.mjs";var t=class{get supportsCreateIfNotExists(){return!0}get supportsMultipleConnections(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};const n=/"/g,r=/[\\'"]/g;var i=class extends e{visitOrAction(e){this.append(`or `),this.append(e.action)}getCurrentParameterPlaceholder(){return`?`}getLeftExplainOptionsWrapper(){return``}getRightExplainOptionsWrapper(){return``}getLeftIdentifierWrapper(){return`"`}getRightIdentifierWrapper(){return`"`}getAutoIncrement(){return`autoincrement`}sanitizeIdentifier(e){return e.replace(n,`""`)}sanitizeJSONPathMemberValue(e){return e.replace(r,e=>e===`\\`?`\\\\`:e===`'`?`''`:`\\"`)}visitDefaultInsertValue(e){this.append(`null`)}},a=class extends t{get supportsMultipleConnections(){return!1}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!0}async acquireMigrationLock(e,t){}async releaseMigrationLock(e,t){}};export{i as n,t as r,a as t};
|
|
@@ -0,0 +1,5 @@
|
|
|
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 ee(e){return e}function te(e){return e instanceof Error?e.message:String(e)}const p=u({is(e){return e.kind===`IdentifierNode`},create(e){return u({kind:`IdentifierNode`,name:e})}}),ne=[`preserve rows`,`delete rows`,`drop`],re=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})}}),ie=u({is(e){return e.kind===`SchemableIdentifierNode`},create(e){return u({kind:`SchemableIdentifierNode`,identifier:p.create(e)})},createWithSchema(e,t){return u({kind:`SchemableIdentifierNode`,schema:p.create(e),identifier:p.create(t)})}}),m=u({is(e){return e.kind===`AliasNode`},create(e,t){return u({kind:`AliasNode`,node:e,alias:t})}}),h=u({is(e){return e.kind===`TableNode`},create(e){return u({kind:`TableNode`,table:ie.create(e)})},createWithSchema(e,t){return u({kind:`TableNode`,table:ie.createWithSchema(e,t)})}});function g(e){return l(e)&&c(e.toOperationNode)}function ae(e){return l(e)&&`expressionType`in e&&g(e)}function oe(e){return l(e)&&`expression`in e&&t(e.alias)&&g(e)}const _=u({is(e){return e.kind===`SelectModifierNode`},create(e,t){return u({kind:`SelectModifierNode`,modifier:e,of:t})},createWithExpression(e){return u({kind:`SelectModifierNode`,rawModifier:e})}}),v=u({is(e){return e.kind===`AndNode`},create(e,t){return u({kind:`AndNode`,left:e,right:t})}}),se=u({is(e){return e.kind===`OrNode`},create(e,t){return u({kind:`OrNode`,left:e,right:t})}}),ce=u({is(e){return e.kind===`OnNode`},create(e){return u({kind:`OnNode`,on:e})},cloneWithOperation(e,t,n){return u({...e,on:t===`And`?v.create(e.on,n):se.create(e.on,n)})}}),y=u({is(e){return e.kind===`JoinNode`},create(e,t){return u({kind:`JoinNode`,joinType:e,table:t,on:void 0})},createWithOn(e,t,n){return u({kind:`JoinNode`,joinType:e,table:t,on:ce.create(n)})},cloneWithOn(e,t){return u({...e,on:e.on?ce.cloneWithOperation(e.on,`And`,t):ce.create(t)})}}),le=u({is(e){return e.kind===`BinaryOperationNode`},create(e,t,n){return u({kind:`BinaryOperationNode`,leftOperand:e,operator:t,rightOperand:n})}}),ue=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(ue);const de=u({"+":!0,"-":!0,"*":!0,"/":!0,"%":!0,"^":!0,"&":!0,"|":!0,"#":!0,"<<":!0,">>":!0});Object.keys(de);const fe=u({"->":!0,"->>":!0}),pe=Object.keys(fe),me=u({...ue,...de,"||":!0}),he=Object.keys(me),ge=u({exists:!0,"not exists":!0});Object.keys(ge);const _e=u({...ge,"-":!0,not:!0}),ve=Object.keys(_e);[...he,...pe,...ve];const b=u({is(e){return e.kind===`OperatorNode`},create(e){return u({kind:`OperatorNode`,operator:e})}});function ye(e){return t(e)&&me[e]}function be(e){return t(e)&&fe[e]}function xe(e){return t(e)&&_e[e]}const x=u({is(e){return e.kind===`ColumnNode`},create(e){return u({kind:`ColumnNode`,column:p.create(e)})}}),Se=u({is(e){return e.kind===`SelectAllNode`},create(){return u({kind:`SelectAllNode`})}}),Ce=u({is(e){return e.kind===`ReferenceNode`},create(e,t){return u({kind:`ReferenceNode`,table:t,column:e})},createSelectAll(e){return u({kind:`ReferenceNode`,table:e,column:Se.create()})}});var we=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Le(this.#e)}};function Te(e){return l(e)&&g(e)&&t(e.dynamicReference)}const S=u({is(e){return e.kind===`OrderByItemNode`},create(e,t){return u({kind:`OrderByItemNode`,orderBy:e,direction:t})},cloneWith(e,t){return u({...e,...t})}}),C=u({is(e){return e.kind===`RawNode`},create(e,t){return u({kind:`RawNode`,sqlFragments:u(e),parameters:u(t)})},createWithSql(e){return C.create([e],[])},createWithChild(e){return C.create([``,``],[e])},createWithChildren(e){return C.create(Array(e.length+1).fill(``),e)}}),Ee=u({is(e){return e.kind===`CollateNode`},create(e){return u({kind:`CollateNode`,collation:p.create(e)})}});var De=class e{#e;constructor(e){this.#e=u(e)}desc(){return new e({node:S.cloneWith(this.#e.node,{direction:C.createWithSql(`desc`)})})}asc(){return new e({node:S.cloneWith(this.#e.node,{direction:C.createWithSql(`asc`)})})}nullsLast(){return new e({node:S.cloneWith(this.#e.node,{nulls:`last`})})}nullsFirst(){return new e({node:S.cloneWith(this.#e.node,{nulls:`first`})})}collate(t){return new e({node:S.cloneWith(this.#e.node,{collation:Ee.create(t)})})}toOperationNode(){return this.#e.node}};const Oe=/* @__PURE__ */ new Set;function ke(e){Oe.has(e)||(Oe.add(e),console.log(e))}function Ae(e){return e===`asc`||e===`desc`}function w(e){if(e.length===2)return[je(e[0],e[1])];if(e.length===1){let[t]=e;return Array.isArray(t)?(ke(`orderBy(array) is deprecated, use multiple orderBy calls instead.`),t.map(e=>je(e))):[je(t)]}throw Error(`Invalid number of arguments at order by! expected 1-2, received ${e.length}`)}function je(e,t){let n=Me(e);if(S.is(n)){if(t)throw Error(`Cannot specify direction twice!`);return n}return Ne(n,t)}function Me(e){if(Dr(e))return Tr(e);if(Te(e))return e.toOperationNode();let[t,n]=e.split(` `);return n?(ke("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),Ne(E(t),n)):E(e)}function Ne(e,t){if(typeof t==`string`){if(!Ae(t))throw Error(`Invalid order by direction: ${t}`);return S.create(e,C.createWithSql(t))}if(ae(t))return ke("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),S.create(e,t.toOperationNode());let n=S.create(e);return t?t(new De({node:n})).toOperationNode():n}const Pe=u({is(e){return e.kind===`JSONReferenceNode`},create(e,t){return u({kind:`JSONReferenceNode`,reference:e,traversal:t})},cloneWithTraversal(e,t){return u({...e,traversal:t})}}),Fe=u({is(e){return e.kind===`JSONOperatorChainNode`},create(e){return u({kind:`JSONOperatorChainNode`,operator:e,values:u([])})},cloneWithValue(e,t){return u({...e,values:u([...e.values,t])})}}),Ie=u({is(e){return e.kind===`JSONPathNode`},create(e){return u({kind:`JSONPathNode`,inOperator:e,pathLegs:u([])})},cloneWithLeg(e,t){return u({...e,pathLegs:u([...e.pathLegs,t])})}});function Le(e){return t(e)?E(e):e.toOperationNode()}function Re(e){return f(e)?e.map(e=>T(e)):[T(e)]}function T(e){return Dr(e)?Tr(e):Le(e)}function ze(e,t){if(be(t))return Pe.create(E(e),Fe.create(b.create(t)));if(t===`->$`||t===`->>$`)return Pe.create(E(e),Ie.create(b.create(t.slice(0,-1))));throw Error(`Invalid JSON operator: ${t}`)}function E(e){if(!e.includes(`.`))return Ce.create(x.create(e));let t=e.split(`.`).map(Ge);if(t.length===3)return Ue(t);if(t.length===2)return We(t);throw Error(`invalid column reference ${e}`)}function Be(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(Ge);return m.create(E(n),p.create(r))}return E(e)}function Ve(e){return x.create(e)}function He(e){if(e.includes(` `)){let[t,n]=e.split(` `).map(Ge);if(!Ae(n))throw Error(`invalid order direction "${n}" next to "${t}"`);return w([t,n])[0]}return Ve(e)}function Ue(e){let[t,n,r]=e;return Ce.create(x.create(r),h.createWithSchema(t,n))}function We(e){let[t,n]=e;return Ce.create(x.create(n),h.create(t))}function Ge(e){return e.trim()}const Ke=u({is(e){return e.kind===`PrimitiveValueListNode`},create(e){return u({kind:`PrimitiveValueListNode`,values:u([...e])})}}),qe=u({is(e){return e.kind===`ValueListNode`},create(e){return u({kind:`ValueListNode`,values:u(e)})}}),D=u({is(e){return e.kind===`ValueNode`},create(e){return u({kind:`ValueNode`,value:e})},createImmediate(e){return u({kind:`ValueNode`,value:e,immediate:!0})}});function Je(e){return f(e)?Ze(e):O(e)}function O(e){return Dr(e)?Tr(e):D.create(e)}function Ye(e){return n(e)||r(e)||i(e)}function Xe(e){if(!Ye(e))throw Error(`unsafe immediate value ${JSON.stringify(e)}`);return D.createImmediate(e)}function Ze(e){return e.some(Dr)?qe.create(e.map(e=>O(e))):Ke.create(e)}const k=u({is(e){return e.kind===`ParensNode`},create(e){return u({kind:`ParensNode`,node:e})}});function A(e){if(e.length===3)return Qe(e[0],e[1],e[2]);if(e.length===1)return O(e[0]);throw Error(`invalid arguments: ${JSON.stringify(e)}`)}function Qe(e,t,n){return tt(t)&&nt(n)?le.create(T(e),rt(t),D.createImmediate(n)):le.create(T(e),rt(t),Je(n))}function j(e,t,n){return le.create(T(e),rt(t),T(n))}function $e(t,n){return et(Object.entries(t).filter(([,t])=>!e(t)).map(([e,t])=>Qe(e,nt(t)?`is`:`=`,t)),n)}function et(e,t,n=!0){let r=t===`and`?v.create:se.create;if(e.length===0)return le.create(D.createImmediate(1),b.create(`=`),D.createImmediate(+(t===`and`)));let i=it(e[0]);for(let t=1;t<e.length;++t)i=r(i,it(e[t]));return e.length>1&&n?k.create(i):i}function tt(e){return e===`is`||e===`is not`}function nt(e){return i(e)||r(e)}function rt(e){if(ye(e))return b.create(e);if(g(e))return e.toOperationNode();throw Error(`invalid operator ${JSON.stringify(e)}`)}function it(e){return g(e)?e.toOperationNode():e}const at=u({is(e){return e.kind===`OrderByNode`},create(e){return u({kind:`OrderByNode`,items:u([...e])})},cloneWithItems(e,t){return u({...e,items:u([...e.items,...t])})}}),ot=u({is(e){return e.kind===`PartitionByNode`},create(e){return u({kind:`PartitionByNode`,items:u(e)})},cloneWithItems(e,t){return u({...e,items:u([...e.items,...t])})}}),st=u({is(e){return e.kind===`OverNode`},create(){return u({kind:`OverNode`})},cloneWithOrderByItems(e,t){return u({...e,orderBy:e.orderBy?at.cloneWithItems(e.orderBy,t):at.create(t)})},cloneWithPartitionByItems(e,t){return u({...e,partitionBy:e.partitionBy?ot.cloneWithItems(e.partitionBy,t):ot.create(t)})}}),ct=u({is(e){return e.kind===`FromNode`},create(e){return u({kind:`FromNode`,froms:u(e)})},cloneWithFroms(e,t){return u({...e,froms:u([...e.froms,...t])})}}),lt=u({is(e){return e.kind===`GroupByNode`},create(e){return u({kind:`GroupByNode`,items:u(e)})},cloneWithItems(e,t){return u({...e,items:u([...e.items,...t])})}}),ut=u({is(e){return e.kind===`HavingNode`},create(e){return u({kind:`HavingNode`,having:e})},cloneWithOperation(e,t,n){return u({...e,having:t===`And`?v.create(e.having,n):se.create(e.having,n)})}}),M=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})}}),dt=u({is(e){return e.kind===`ListNode`},create(e){return u({kind:`ListNode`,items:u(e)})}}),ft=u({is(e){return e.kind===`UpdateQueryNode`},create(e,t){return u({kind:`UpdateQueryNode`,table:e.length===1?e[0]:dt.create(e),...t&&{with:t}})},createWithoutTable(){return u({kind:`UpdateQueryNode`})},cloneWithFromItems(e,t){return u({...e,from:e.from?ct.cloneWithFroms(e.from,t):ct.create(t)})},cloneWithUpdates(e,t){return u({...e,updates:e.updates?u([...e.updates,...t]):t})},cloneWithLimit(e,t){return u({...e,limit:t})}}),pt=u({is(e){return e.kind===`UsingNode`},create(e){return u({kind:`UsingNode`,tables:u(e)})},cloneWithTables(e,t){return u({...e,tables:u([...e.tables,...t])})}}),mt=u({is(e){return e.kind===`DeleteQueryNode`},create(e,t){return u({kind:`DeleteQueryNode`,from:ct.create(e),...t&&{with:t}})},cloneWithOrderByItems:(e,t)=>I.cloneWithOrderByItems(e,t),cloneWithoutOrderBy:e=>I.cloneWithoutOrderBy(e),cloneWithLimit(e,t){return u({...e,limit:t})},cloneWithoutLimit(e){return u({...e,limit:void 0})},cloneWithUsing(e,t){return u({...e,using:e.using===void 0?pt.create(t):pt.cloneWithTables(e.using,t)})}}),N=u({is(e){return e.kind===`WhereNode`},create(e){return u({kind:`WhereNode`,where:e})},cloneWithOperation(e,t,n){return u({...e,where:t===`And`?v.create(e.where,n):se.create(e.where,n)})}}),ht=u({is(e){return e.kind===`ReturningNode`},create(e){return u({kind:`ReturningNode`,selections:u(e)})},cloneWithSelections(e,t){return u({...e,selections:e.selections?u([...e.selections,...t]):u(t)})}}),gt=u({is(e){return e.kind===`ExplainNode`},create(e,t){return u({kind:`ExplainNode`,format:e,options:t})}}),P=u({is(e){return e.kind===`WhenNode`},create(e){return u({kind:`WhenNode`,condition:e})},cloneWithResult(e,t){return u({...e,result:t})}}),F=u({is(e){return e.kind===`MergeQueryNode`},create(e,t){return u({kind:`MergeQueryNode`,into:e,...t&&{with:t}})},cloneWithUsing(e,t){return u({...e,using:t})},cloneWithWhen(e,t){return u({...e,whens:e.whens?u([...e.whens,t]):u([t])})},cloneWithThen(e,t){return u({...e,whens:e.whens?u([...e.whens.slice(0,-1),P.cloneWithResult(e.whens[e.whens.length-1],t)]):void 0})}}),_t=u({is(e){return e.kind===`OutputNode`},create(e){return u({kind:`OutputNode`,selections:u(e)})},cloneWithSelections(e,t){return u({...e,selections:e.selections?u([...e.selections,...t]):u(t)})}}),I=u({is(e){return L.is(e)||M.is(e)||ft.is(e)||mt.is(e)||F.is(e)},cloneWithEndModifier(e,t){return u({...e,endModifiers:e.endModifiers?u([...e.endModifiers,t]):u([t])})},cloneWithWhere(e,t){return u({...e,where:e.where?N.cloneWithOperation(e.where,`And`,t):N.create(t)})},cloneWithJoin(e,t){return u({...e,joins:e.joins?u([...e.joins,t]):u([t])})},cloneWithReturning(e,t){return u({...e,returning:e.returning?ht.cloneWithSelections(e.returning,t):ht.create(t)})},cloneWithoutReturning(e){return u({...e,returning:void 0})},cloneWithoutWhere(e){return u({...e,where:void 0})},cloneWithExplain(e,t,n){return u({...e,explain:gt.create(t,n?.toOperationNode())})},cloneWithTop(e,t){return u({...e,top:t})},cloneWithOutput(e,t){return u({...e,output:e.output?_t.cloneWithSelections(e.output,t):_t.create(t)})},cloneWithOrderByItems(e,t){return u({...e,orderBy:e.orderBy?at.cloneWithItems(e.orderBy,t):at.create(t)})},cloneWithoutOrderBy(e){return u({...e,orderBy:void 0})}}),L=u({is(e){return e.kind===`SelectQueryNode`},create(e){return u({kind:`SelectQueryNode`,...e&&{with:e}})},createFrom(e,t){return u({kind:`SelectQueryNode`,from:ct.create(e),...t&&{with:t}})},cloneWithSelections(e,t){return u({...e,selections:e.selections?u([...e.selections,...t]):u(t)})},cloneWithDistinctOn(e,t){return u({...e,distinctOn:e.distinctOn?u([...e.distinctOn,...t]):u(t)})},cloneWithFrontModifier(e,t){return u({...e,frontModifiers:e.frontModifiers?u([...e.frontModifiers,t]):u([t])})},cloneWithOrderByItems:(e,t)=>I.cloneWithOrderByItems(e,t),cloneWithGroupByItems(e,t){return u({...e,groupBy:e.groupBy?lt.cloneWithItems(e.groupBy,t):lt.create(t)})},cloneWithLimit(e,t){return u({...e,limit:t})},cloneWithOffset(e,t){return u({...e,offset:t})},cloneWithFetch(e,t){return u({...e,fetch:t})},cloneWithHaving(e,t){return u({...e,having:e.having?ut.cloneWithOperation(e.having,`And`,t):ut.create(t)})},cloneWithSetOperations(e,t){return u({...e,setOperations:e.setOperations?u([...e.setOperations,...t]):u([...t])})},cloneWithoutSelections(e){return u({...e,selections:[]})},cloneWithoutLimit(e){return u({...e,limit:void 0})},cloneWithoutOffset(e){return u({...e,offset:void 0})},cloneWithoutOrderBy:e=>I.cloneWithoutOrderBy(e),cloneWithoutGroupBy(e){return u({...e,groupBy:void 0})}});var vt=class e{#e;constructor(e){this.#e=u(e)}on(...t){return new e({...this.#e,joinNode:y.cloneWithOn(this.#e.joinNode,A(t))})}onRef(t,n,r){return new e({...this.#e,joinNode:y.cloneWithOn(this.#e.joinNode,j(t,n,r))})}onTrue(){return new e({...this.#e,joinNode:y.cloneWithOn(this.#e.joinNode,C.createWithSql(`true`))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};const yt=u({is(e){return e.kind===`PartitionByItemNode`},create(e){return u({kind:`PartitionByItemNode`,partitionBy:e})}});function bt(e){return Re(e).map(yt.create)}var xt=class e{#e;constructor(e){this.#e=u(e)}orderBy(...t){return new e({overNode:st.cloneWithOrderByItems(this.#e.overNode,w(t))})}clearOrderBy(){return new e({overNode:I.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(t){return new e({overNode:st.cloneWithPartitionByItems(this.#e.overNode,bt(t))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};const St=u({is(e){return e.kind===`SelectionNode`},create(e){return u({kind:`SelectionNode`,selection:e})},createSelectAll(){return u({kind:`SelectionNode`,selection:Se.create()})},createSelectAllFromTable(e){return u({kind:`SelectionNode`,selection:Ce.createSelectAll(e)})}});function R(e){return c(e)?R(e(wr())):f(e)?e.map(e=>Ct(e)):[Ct(e)]}function Ct(e){return t(e)?St.create(Be(e)):Te(e)?St.create(e.toOperationNode()):St.create(Er(e))}function z(e){return e?Array.isArray(e)?e.map(wt):[wt(e)]:[St.createSelectAll()]}function wt(e){if(t(e))return St.createSelectAllFromTable(Q(e));throw Error(`invalid value selectAll expression: ${JSON.stringify(e)}`)}const Tt=u({is(e){return e.kind===`ValuesNode`},create(e){return u({kind:`ValuesNode`,values:u(e)})}}),Et=u({is(e){return e.kind===`DefaultInsertValueNode`},create(){return u({kind:`DefaultInsertValueNode`})}});function Dt(e){let t=c(e)?e(wr()):e;return Ot(f(t)?t:u([t]))}function Ot(e){let t=kt(e);return[u([...t.keys()].map(x.create)),Tt.create(e.map(e=>At(e,t)))]}function kt(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 At(t,n){let r=Object.keys(t),i=Array.from({length:n.size}),a=!1,o=r.length;for(let s of r){let r=n.get(s);if(e(r)){o--;continue}let c=t[s];(e(c)||Dr(c))&&(a=!0),i[r]=c}if(o<n.size||a){let t=Et.create();return qe.create(i.map(n=>e(n)?t:O(n)))}return Ke.create(i)}const jt=u({is(e){return e.kind===`ColumnUpdateNode`},create(e,t){return u({kind:`ColumnUpdateNode`,column:e,value:t})}});function Mt(...e){return e.length===2?[jt.create(T(e[0]),O(e[1]))]:Nt(e[0])}function Nt(e){let t=c(e)?e(wr()):e;return Object.entries(t).filter(([e,t])=>t!==void 0).map(([e,t])=>jt.create(x.create(e),O(t)))}const Pt=u({is(e){return e.kind===`OnDuplicateKeyNode`},create(e){return u({kind:`OnDuplicateKeyNode`,updates:e})}});var Ft=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}},It=class extends Error{node;constructor(e){super(`no result`),this.node=e}};function Lt(e){return Object.prototype.hasOwnProperty.call(e,`prototype`)}const B=u({is(e){return e.kind===`OnConflictNode`},create(){return u({kind:`OnConflictNode`})},cloneWith(e,t){return u({...e,...t})},cloneWithIndexWhere(e,t){return u({...e,indexWhere:e.indexWhere?N.cloneWithOperation(e.indexWhere,`And`,t):N.create(t)})},cloneWithIndexOrWhere(e,t){return u({...e,indexWhere:e.indexWhere?N.cloneWithOperation(e.indexWhere,`Or`,t):N.create(t)})},cloneWithUpdateWhere(e,t){return u({...e,updateWhere:e.updateWhere?N.cloneWithOperation(e.updateWhere,`And`,t):N.create(t)})},cloneWithUpdateOrWhere(e,t){return u({...e,updateWhere:e.updateWhere?N.cloneWithOperation(e.updateWhere,`Or`,t):N.create(t)})},cloneWithoutIndexWhere(e){return u({...e,indexWhere:void 0})},cloneWithoutUpdateWhere(e){return u({...e,updateWhere:void 0})}});var Rt=class e{#e;constructor(e){this.#e=u(e)}column(t){let n=x.create(t);return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?u([...this.#e.onConflictNode.columns,n]):u([n])})})}columns(t){let n=t.map(x.create);return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?u([...this.#e.onConflictNode.columns,...n]):u(n)})})}constraint(t){return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{constraint:p.create(t)})})}expression(t){return new e({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{indexExpression:t.toOperationNode()})})}where(...t){return new e({...this.#e,onConflictNode:B.cloneWithIndexWhere(this.#e.onConflictNode,A(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:B.cloneWithIndexWhere(this.#e.onConflictNode,j(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:B.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new zt({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Bt({...this.#e,onConflictNode:B.cloneWith(this.#e.onConflictNode,{updates:Nt(e)})})}$call(e){return e(this)}},zt=class{#e;constructor(e){this.#e=u(e)}toOperationNode(){return this.#e.onConflictNode}},Bt=class e{#e;constructor(e){this.#e=u(e)}where(...t){return new e({...this.#e,onConflictNode:B.cloneWithUpdateWhere(this.#e.onConflictNode,A(t))})}whereRef(t,n,r){return new e({...this.#e,onConflictNode:B.cloneWithUpdateWhere(this.#e.onConflictNode,j(t,n,r))})}clearWhere(){return new e({...this.#e,onConflictNode:B.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};const Vt=u({is(e){return e.kind===`TopNode`},create(e,t){return u({kind:`TopNode`,expression:e,modifiers:t})}});function Ht(t,r){if(!n(t)&&!o(t))throw Error(`Invalid top expression: ${t}`);if(!e(r)&&!Ut(r))throw Error(`Invalid top modifiers: ${r}`);return Vt.create(t,r)}function Ut(e){return e===`percent`||e===`with ties`||e===`percent with ties`}const Wt=u({is(e){return e.kind===`OrActionNode`},create(e){return u({kind:`OrActionNode`,action:e})}});var Gt=class e{#e;constructor(e){this.#e=u(e)}values(t){let[n,r]=Dt(t);return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{columns:n,values:r})})}columns(t){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{columns:u(t.map(x.create))})})}expression(t){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{values:Tr(t)})})}defaultValues(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}ignore(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`ignore`)})})}orIgnore(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`ignore`)})})}orAbort(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`abort`)})})}orFail(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`fail`)})})}orReplace(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`replace`)})})}orRollback(){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{orAction:Wt.create(`rollback`)})})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}onConflict(t){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{onConflict:t(new Rt({onConflictNode:B.create()})).toOperationNode()})})}onDuplicateKeyUpdate(t){return new e({...this.#e,queryNode:M.cloneWith(this.#e.queryNode,{onDuplicateKey:Pt.create(Nt(t))})})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z())})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}clearReturning(){return new e({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(t,n){return t?n(this):new e({...this.#e})}$castTo(){return new e(this.#e)}$narrowType(){return new e(this.#e)}$assertType(){return new e(this.#e)}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(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 Ft(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??It;throw Lt(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:I.cloneWithExplain(this.#e.queryNode,t,n)}).execute()}},Kt=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};const qt=u({is(e){return e.kind===`LimitNode`},create(e){return u({kind:`LimitNode`,limit:e})}});var V,Jt=class{#e;constructor(e){this.#e=u(e)}where(...e){return new V({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,t,n){return new V({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(e,t,n))})}clearWhere(){return new V({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new V({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(e,t))})}using(e){return new V({...this.#e,queryNode:mt.cloneWithUsing(this.#e.queryNode,jr(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:I.cloneWithJoin(this.#e.queryNode,Ln(e,t))})}returning(e){return new V({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(e))})}returningAll(e){return new V({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(e))})}output(e){return new V({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(e))})}outputAll(e){return new V({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(e))})}clearReturning(){return new V({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new V({...this.#e,queryNode:mt.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new V({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,w(e))})}clearOrderBy(){return new V({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new V({...this.#e,queryNode:mt.cloneWithLimit(this.#e.queryNode,qt.create(O(e)))})}modifyEnd(e){return new V({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$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 Kt(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??It;throw Lt(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:I.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};V=Jt;var Yt=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}},H,Xt=class{#e;constructor(e){this.#e=u(e)}where(...e){return new H({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,t,n){return new H({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(e,t,n))})}clearWhere(){return new H({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new H({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(e,t))})}from(e){return new H({...this.#e,queryNode:ft.cloneWithFromItems(this.#e.queryNode,jr(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 H({...this.#e,queryNode:I.cloneWithJoin(this.#e.queryNode,Ln(e,t))})}orderBy(...e){return new H({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,w(e))})}clearOrderBy(){return new H({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new H({...this.#e,queryNode:ft.cloneWithLimit(this.#e.queryNode,qt.create(O(e)))})}set(...e){return new H({...this.#e,queryNode:ft.cloneWithUpdates(this.#e.queryNode,Mt(...e))})}returning(e){return new H({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(e))})}returningAll(e){return new H({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(e))})}output(e){return new H({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(e))})}outputAll(e){return new H({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(e))})}modifyEnd(e){return new H({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new H({...this.#e,queryNode:I.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new H({...this.#e})}$castTo(){return new H(this.#e)}$narrowType(){return new H(this.#e)}$assertType(){return new H(this.#e)}withPlugin(e){return new H({...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 Yt(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??It;throw Lt(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 H({...this.#e,queryNode:I.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};H=Xt;const Zt=u({is(e){return e.kind===`CommonTableExpressionNameNode`},create(e,t){return u({kind:`CommonTableExpressionNameNode`,table:h.create(e),columns:t?u(t.map(x.create)):void 0})}}),Qt=u({is(e){return e.kind===`CommonTableExpressionNode`},create(e,t){return u({kind:`CommonTableExpressionNode`,name:e,expression:t})},cloneWith(e,t){return u({...e,...t})}});var $t=class e{#e;constructor(e){this.#e=u(e)}materialized(){return new e({...this.#e,node:Qt.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new e({...this.#e,node:Qt.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function en(e,t){let n=g(t)?t.toOperationNode():t(Pn()).toOperationNode();return c(e)?e(tn(n)).toOperationNode():Qt.create(nn(e),n)}function tn(e){return t=>new $t({node:Qt.create(nn(t),e)})}function nn(e){if(e.includes(`(`)){let t=e.split(/[\(\)]/),n=t[0],r=t[1].split(`,`).map(e=>e.trim());return Zt.create(n,r)}return Zt.create(e)}const rn=u({is(e){return e.kind===`WithNode`},create(e,t){return u({kind:`WithNode`,expressions:u([e]),...t})},cloneWithExpression(e,t){return u({...e,expressions:u([...e.expressions,t])})}}),an=/* @__PURE__ */ `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`.split(``);function on(e){let t=``;for(let n=0;n<e;++n)t+=sn();return t}function sn(){return an[~~(Math.random()*an.length)]}function U(){return new cn}var cn=class{#e;get queryId(){return this.#e===void 0&&(this.#e=on(8)),this.#e}},ln=class{nodeStack=[];#e=u({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(),u(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&u(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:u([...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 un(e){return l(e)&&t(e.kind)}const dn={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 fn(e){return un(e)&&dn[e.kind]===!0}const pn=u({json_agg:!0,to_json:!0});var mn=class extends ln{#e;#t=/* @__PURE__ */ new Set;#n=/* @__PURE__ */ new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!fn(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:p.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:h.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=>h.is(e)&&!e.table.schema?{...e,table:this.transformIdentifier(e.table.identifier,t)}:this.transformNode(e,t))}}#r(e,t,n){return pn[e.func]?e[n].map(e=>!h.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&&ie.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&&(y.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(h.is(e))return this.#s(e.table,t);if(m.is(e)&&h.is(e.node))return this.#s(e.node.table,t);if(dt.is(e)){for(let n of e.items)this.#o(n,t);return}if(pt.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)}}},hn=class{#e;constructor(e){this.#e=new mn(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};const gn=u({is(e){return e.kind===`MatchedNode`},create(e,t=!1){return u({kind:`MatchedNode`,not:e,bySource:t})}});function _n(e,t,n){return P.create(et([gn.create(!e.isMatched,e.bySource),...t&&t.length>0?[t.length===3&&n?j(t[0],t[1],t[2]):A(t)]:[]],`and`,!1))}function vn(e){return t(e)?C.create([e],[]):g(e)?e.toOperationNode():e}var yn=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 bn(e,t){let n=new yn,r=new yn;return e.provideConnection(async e=>(n.resolve(e),await r.promise),t).catch(e=>n.reject(e)),u({connection:await n.promise,release:r.resolve})}function xn(e=`ignore query`,t,n){if(e!==`ignore query`){if(e===`cancel query`){let r=t.cancelQuery;return r||(n(),Sn(e,t.killSession?`kill session`:void 0)),r.bind(t)}if(e===`kill session`){let r=t.killSession;return r||(n(),Sn(e,t.cancelQuery?`cancel query`:void 0)),r.bind(t)}throw n(),Error(`Unexpected \`inflightQueryAbortStrategy\`: "${e}"`)}}function Sn(e,t){throw Error(`This dialect doesn't support \`inflightQueryAbortStrategy\` "${e}". Use "ignore query"${t?` or "${t}"`:``} instead.`)}function W(e,t,n){e?.aborted&&(n?.(),G(e.reason,t))}function G(e,t){throw wn(e,t),e}const K={};async function Cn(e,t,n,r){if(!t)return e;W(t,`before ${n}`,r);let{promise:i,resolve:a}=new yn,o=()=>a(K);t.addEventListener(`abort`,o);try{W(t,`before ${n}`,r);let a=await Promise.race([e,i]);if(a!==K)return a;r?.(),G(t.reason,`during ${n}`)}finally{t.removeEventListener(`abort`,o),a(K)}}function q(e){return t=>console.error(`\`${e}\` failed in the background after abortion: ${te(t)}`)}function wn(e,t){typeof e==`object`&&e&&!Object.isFrozen(e)&&Object.defineProperty(e,"__kysely_timing__",{configurable:!0,enumerable:!1,value:t,writable:!1})}const Tn=u([]);var En=class{#e;constructor(e=Tn){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)}W(r,`before query execution`),t=u({signal:r});let{connection:i,release:a}=await bn(this,t),o=this.provideConnection.bind(this),{promise:s,resolve:c}=new yn,l=()=>c(K);r.addEventListener(`abort`,l,{once:!0});try{W(r,`before query execution`,a);let c=xn(n,i,a);if(c&&i.collectSessionInfo){W(r,`before query execution`,a);let e=i.collectSessionInfo();await Promise.race([s,e]).catch(e=>{throw a(),e})===K&&(e.catch(q(`collectSessionInfo`)).finally(a),G(r.reason,`before query execution`))}let l=i.executeQuery(e,t),u=await Promise.race([s,l]).catch(e=>{throw a(),e});u===K?(Promise.allSettled([l.catch(q(`query`)),c?.(o).catch(q(`inflightQueryAbortHandler`))]).finally(a),G(r.reason,`during query execution`)):a();let d=this.#t(u,e.queryId,t),f=await Promise.race([s,d]);return f===K&&(d.catch(q(`plugins.transformResult`)),G(r.reason,`during result transformation`)),f}finally{c(K),r.removeEventListener(`abort`,l)}}async*stream(e,t,n){let{signal:r}=n||{};if(!r){let{connection:r,release:i}=await bn(this);try{for await(let i of r.streamQuery(e,t))yield await this.#t(i,e.queryId,n)}finally{i()}return}n=u({signal:r}),W(r,`before connection acquisition`);let{connection:i,release:a}=await bn(this,n),{promise:o,resolve:s}=new yn,c=()=>s(K);r.addEventListener(`abort`,c,{once:!0});let l,d;W(r,`before query streaming`,a);let{queryId:f}=e;try{for(l=i.streamQuery(e,t,n);;){W(r,`during query streaming`);let e=l.next(),t=await Promise.race([o,e]);if(t===K&&(d=e.catch(q(`iterator.next`)),G(r.reason,`during query streaming`)),t.done)break;let i=this.#t(t.value,f,n),a=await Promise.race([o,i]);a===K&&(d=i.catch(q(`plugins.transformResult`)),G(r.reason,`during result transformation`)),yield a}}finally{s(K),r.removeEventListener(`abort`,c);let e=(l?.return?.()||Promise.resolve()).finally(()=>d).finally(a);d||await e}}async#t(e,t,n){let{signal:r}=n||{};for(let n of this.#e)e=await n.transformResult(u({queryId:t,result:e,signal:r}));return e}};const Dn=new class e extends En{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 On=class{numChangedRows;constructor(e){this.numChangedRows=e}},kn=class e{#e;constructor(e){this.#e=u(e)}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}using(...e){return new An({...this.#e,queryNode:F.cloneWithUsing(this.#e.queryNode,Ln(`Using`,e))})}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}},An=class e{#e;constructor(e){this.#e=u(e)}modifyEnd(t){return new e({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,t.toOperationNode())})}top(t,n){return new e({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(t,n))})}whenMatched(){return this.#t([])}whenMatchedAnd(...e){return this.#t(e)}whenMatchedAndRef(e,t,n){return this.#t([e,t,n],!0)}#t(e,t){return new jn({...this.#e,queryNode:F.cloneWithWhen(this.#e.queryNode,_n({isMatched:!0},e,t))})}whenNotMatched(){return this.#n([])}whenNotMatchedAnd(...e){return this.#n(e)}whenNotMatchedAndRef(e,t,n){return this.#n([e,t,n],!0)}whenNotMatchedBySource(){return this.#n([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#n(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,n){return this.#n([e,t,n],!0,!0)}returning(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,R(t))})}returningAll(t){return new e({...this.#e,queryNode:I.cloneWithReturning(this.#e.queryNode,z(t))})}output(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,R(t))})}outputAll(t){return new e({...this.#e,queryNode:I.cloneWithOutput(this.#e.queryNode,z(t))})}#n(e,t=!1,n=!1){let r={...this.#e,queryNode:F.cloneWithWhen(this.#e.queryNode,_n({isMatched:!1,bySource:n},e,t))};return new(n?jn:Mn)(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 On(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??It;throw Lt(t)?new t(this.toOperationNode()):t(this.toOperationNode())}return t}},jn=class{#e;constructor(e){this.#e=u(e)}thenDelete(){return new An({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,vn(`delete`))})}thenDoNothing(){return new An({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,vn(`do nothing`))})}thenUpdate(e){return new An({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,vn(e(new Xt({queryId:this.#e.queryId,executor:Dn,queryNode:ft.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},Mn=class{#e;constructor(e){this.#e=u(e)}thenDoNothing(){return new An({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,vn(`do nothing`))})}thenInsertValues(e){let[t,n]=Dt(e);return new An({...this.#e,queryNode:F.cloneWithThen(this.#e.queryNode,vn(M.cloneWith(M.createWithoutInto(),{columns:t,values:n})))})}},Nn=class e{#e;constructor(e){this.#e=u(e)}selectFrom(e){return $n({queryId:U(),executor:this.#e.executor,queryNode:L.createFrom(jr(e),this.#e.withNode)})}selectNoFrom(e){return $n({queryId:U(),executor:this.#e.executor,queryNode:L.cloneWithSelections(L.create(this.#e.withNode),R(e))})}insertInto(e){return new Gt({queryId:U(),executor:this.#e.executor,queryNode:M.create(Q(e),this.#e.withNode)})}replaceInto(e){return new Gt({queryId:U(),executor:this.#e.executor,queryNode:M.create(Q(e),this.#e.withNode,!0)})}deleteFrom(e){return new Jt({queryId:U(),executor:this.#e.executor,queryNode:mt.create(jr(e),this.#e.withNode)})}updateTable(e){return new Xt({queryId:U(),executor:this.#e.executor,queryNode:ft.create(jr(e),this.#e.withNode)})}mergeInto(e){return new kn({queryId:U(),executor:this.#e.executor,queryNode:F.create(Nr(e),this.#e.withNode)})}with(t,n){let r=en(t,n);return new e({...this.#e,withNode:this.#e.withNode?rn.cloneWithExpression(this.#e.withNode,r):rn.create(r)})}withRecursive(t,n){let r=en(t,n);return new e({...this.#e,withNode:this.#e.withNode?rn.cloneWithExpression(this.#e.withNode,r):rn.create(r,{recursive:!0})})}withPlugin(t){return new e({...this.#e,executor:this.#e.executor.withPlugin(t)})}withoutPlugins(){return new e({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(t){return new e({...this.#e,executor:this.#e.executor.withPluginAtFront(new hn(t))})}};function Pn(){return new Nn({executor:Dn})}function Fn(e,t){return new vt({joinNode:y.create(e,Mr(t))})}function In(){return new xt({overNode:st.create()})}function Ln(e,t){if(t.length===3)return zn(e,t[0],t[1],t[2]);if(t.length===2)return Rn(e,t[0],t[1]);if(t.length===1)return Bn(e,t[0]);throw Error(`not implemented`)}function Rn(e,t,n){return n(Fn(e,t)).toOperationNode()}function zn(e,t,n,r){return y.createWithOn(e,Mr(t),j(n,`=`,r))}function Bn(e,t){return y.create(e,Mr(t))}const Vn=u({is(e){return e.kind===`OffsetNode`},create(e){return u({kind:`OffsetNode`,offset:e})}}),Hn=u({is(e){return e.kind===`GroupByItemNode`},create(e){return u({kind:`GroupByItemNode`,groupBy:e})}});function Un(e){return e=c(e)?e(wr()):e,Re(e).map(Hn.create)}const Wn=u({is(e){return e.kind===`SetOperationNode`},create(e,t,n){return u({kind:`SetOperationNode`,operator:e,expression:t,all:n})}});function Gn(e,t,n){return c(t)&&(t=t(Cr())),f(t)||(t=[t]),t.map(t=>Wn.create(e,Tr(t),n))}var J=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Kn(this,e)}or(...e){return new qn(se.create(this.#e,A(e)))}and(...e){return new Jn(v.create(this.#e,A(e)))}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},Kn=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return m.create(this.#e.toOperationNode(),g(this.#t)?this.#t.toOperationNode():p.create(this.#t))}},qn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Kn(this,e)}or(...t){return new e(se.create(this.#e,A(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return k.create(this.#e)}},Jn=class e{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new Kn(this,e)}and(...t){return new e(v.create(this.#e,A(t)))}$castTo(){return new e(this.#e)}toOperationNode(){return k.create(this.#e)}};const Yn=u({is(e){return e.kind===`FetchNode`},create(e,t){return{kind:`FetchNode`,rowCount:D.create(e),modifier:t}}});function Xn(e,t){if(!n(e)&&!o(e))throw Error(`Invalid fetch row count: ${e}`);if(!Zn(t))throw Error(`Invalid fetch modifier: ${t}`);return Yn.create(e,t)}function Zn(e){return e===`only`||e===`with ties`}var Y,Qn=class{#e;constructor(e){this.#e=u(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new Y({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,A(e))})}whereRef(e,t,n){return new Y({...this.#e,queryNode:I.cloneWithWhere(this.#e.queryNode,j(e,t,n))})}having(...e){return new Y({...this.#e,queryNode:L.cloneWithHaving(this.#e.queryNode,A(e))})}havingRef(e,t,n){return new Y({...this.#e,queryNode:L.cloneWithHaving(this.#e.queryNode,j(e,t,n))})}select(e){return new Y({...this.#e,queryNode:L.cloneWithSelections(this.#e.queryNode,R(e))})}distinctOn(e){return new Y({...this.#e,queryNode:L.cloneWithDistinctOn(this.#e.queryNode,Re(e))})}modifyFront(e){return new Y({...this.#e,queryNode:L.cloneWithFrontModifier(this.#e.queryNode,_.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.createWithExpression(e.toOperationNode()))})}distinct(){return new Y({...this.#e,queryNode:L.cloneWithFrontModifier(this.#e.queryNode,_.create(`Distinct`))})}forUpdate(e){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`ForUpdate`,e?d(e).map(Q):void 0))})}forShare(e){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`ForShare`,e?d(e).map(Q):void 0))})}forKeyShare(e){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`ForKeyShare`,e?d(e).map(Q):void 0))})}forNoKeyUpdate(e){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`ForNoKeyUpdate`,e?d(e).map(Q):void 0))})}skipLocked(){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`SkipLocked`))})}noWait(){return new Y({...this.#e,queryNode:I.cloneWithEndModifier(this.#e.queryNode,_.create(`NoWait`))})}selectAll(e){return new Y({...this.#e,queryNode:L.cloneWithSelections(this.#e.queryNode,z(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:I.cloneWithJoin(this.#e.queryNode,Ln(e,t))})}orderBy(...e){return new Y({...this.#e,queryNode:I.cloneWithOrderByItems(this.#e.queryNode,w(e))})}groupBy(e){return new Y({...this.#e,queryNode:L.cloneWithGroupByItems(this.#e.queryNode,Un(e))})}limit(e){return new Y({...this.#e,queryNode:L.cloneWithLimit(this.#e.queryNode,qt.create(O(e)))})}offset(e){return new Y({...this.#e,queryNode:L.cloneWithOffset(this.#e.queryNode,Vn.create(O(e)))})}fetch(e,t=`only`){return new Y({...this.#e,queryNode:L.cloneWithFetch(this.#e.queryNode,Xn(e,t))})}top(e,t){return new Y({...this.#e,queryNode:I.cloneWithTop(this.#e.queryNode,Ht(e,t))})}union(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`union`,e,!1))})}unionAll(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`union`,e,!0))})}intersect(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`intersect`,e,!1))})}intersectAll(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`intersect`,e,!0))})}except(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`except`,e,!1))})}exceptAll(e){return new Y({...this.#e,queryNode:L.cloneWithSetOperations(this.#e.queryNode,Gn(`except`,e,!0))})}as(e){return new er(this,e)}clearSelect(){return new Y({...this.#e,queryNode:L.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new Y({...this.#e,queryNode:I.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new Y({...this.#e,queryNode:L.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new Y({...this.#e,queryNode:L.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new Y({...this.#e,queryNode:I.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new Y({...this.#e,queryNode:L.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??It;throw Lt(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:I.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};Y=Qn;function $n(e){return new Qn(e)}var er=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 m.create(this.#e.toOperationNode(),p.create(this.#t))}};const X=u({is(e){return e.kind===`AggregateFunctionNode`},create(e,t=[]){return u({kind:`AggregateFunctionNode`,func:e,aggregated:t})},cloneWithDistinct(e){return u({...e,distinct:!0})},cloneWithOrderBy(e,t,n=!1){let r=n?`withinGroup`:`orderBy`;return u({...e,[r]:e[r]?at.cloneWithItems(e[r],t):at.create(t)})},cloneWithFilter(e,t){return u({...e,filter:e.filter?N.cloneWithOperation(e.filter,`And`,t):N.create(t)})},cloneWithOrFilter(e,t){return u({...e,filter:e.filter?N.cloneWithOperation(e.filter,`Or`,t):N.create(t)})},cloneWithOver(e,t){return u({...e,over:t})}}),tr=u({is(e){return e.kind===`FunctionNode`},create(e,t){return u({kind:`FunctionNode`,func:e,arguments:t})}});var nr=class e{#e;constructor(e){this.#e=u(e)}get expressionType(){}as(e){return new rr(this,e)}distinct(){return new e({...this.#e,aggregateFunctionNode:X.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...t){return new e({...this.#e,aggregateFunctionNode:I.cloneWithOrderByItems(this.#e.aggregateFunctionNode,w(t))})}clearOrderBy(){return new e({...this.#e,aggregateFunctionNode:I.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...t){return new e({...this.#e,aggregateFunctionNode:X.cloneWithOrderBy(this.#e.aggregateFunctionNode,w(t),!0)})}filterWhere(...t){return new e({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,A(t))})}filterWhereRef(t,n,r){return new e({...this.#e,aggregateFunctionNode:X.cloneWithFilter(this.#e.aggregateFunctionNode,j(t,n,r))})}over(t){let n=In();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}},rr=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return m.create(this.#e.toOperationNode(),p.create(this.#t))}};function ir(){let e=(e,t)=>new J(tr.create(e,Re(t??[]))),n=(e,t)=>new nr({aggregateFunctionNode:X.create(e,t?Re(t):void 0)});return Object.assign(e,{agg:n,avg(e){return n(`avg`,[e])},coalesce(...t){return e(`coalesce`,t)},count(e){return n(`count`,[e])},countAll(e){return new nr({aggregateFunctionNode:X.create(`count`,z(e))})},max(e){return n(`max`,[e])},min(e){return n(`min`,[e])},sum(e){return n(`sum`,[e])},any(t){return e(`any`,[t])},jsonAgg(e){return new nr({aggregateFunctionNode:X.create(`json_agg`,[t(e)?Q(e):e.toOperationNode()])})},toJson(e){return new J(tr.create(`to_json`,[t(e)?Q(e):e.toOperationNode()]))}})}const ar=u({is(e){return e.kind===`UnaryOperationNode`},create(e,t){return u({kind:`UnaryOperationNode`,operator:e,operand:t})}});function or(e,t){if(xe(e))return ar.create(b.create(e),T(t));throw Error(`invalid unary operator ${JSON.stringify(e)}`)}const Z=u({is(e){return e.kind===`CaseNode`},create(e){return u({kind:`CaseNode`,value:e})},cloneWithWhen(e,t){return u({...e,when:u(e.when?[...e.when,t]:[t])})},cloneWithThen(e,t){return u({...e,when:e.when?u([...e.when.slice(0,-1),P.cloneWithResult(e.when[e.when.length-1],t)]):void 0})},cloneWith(e,t){return u({...e,...t})}});var sr=class{#e;constructor(e){this.#e=u(e)}when(...e){return new cr({...this.#e,node:Z.cloneWithWhen(this.#e.node,P.create(A(e)))})}whenRef(e,t,n){return new cr({...this.#e,node:Z.cloneWithWhen(this.#e.node,P.create(j(e,t,n)))})}},cr=class{#e;constructor(e){this.#e=u(e)}then(e){return new lr({...this.#e,node:Z.cloneWithThen(this.#e.node,Ye(e)?Xe(e):O(e))})}thenRef(e){return new lr({...this.#e,node:Z.cloneWithThen(this.#e.node,T(e))})}},lr=class{#e;constructor(e){this.#e=u(e)}when(...e){return new cr({...this.#e,node:Z.cloneWithWhen(this.#e.node,P.create(A(e)))})}whenRef(e,t,n){return new cr({...this.#e,node:Z.cloneWithWhen(this.#e.node,P.create(j(e,t,n)))})}else(e){return new ur({...this.#e,node:Z.cloneWith(this.#e.node,{else:Ye(e)?Xe(e):O(e)})})}elseRef(e){return new ur({...this.#e,node:Z.cloneWith(this.#e.node,{else:T(e)})})}end(){return new J(Z.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new J(Z.cloneWith(this.#e.node,{isStatement:!0}))}},ur=class{#e;constructor(e){this.#e=u(e)}end(){return new J(Z.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new J(Z.cloneWith(this.#e.node,{isStatement:!0}))}};const dr=u({is(e){return e.kind===`JSONPathLegNode`},create(e,t){return u({kind:`JSONPathLegNode`,type:e,value:t})}}),fr=/^#-\d+$/;var pr=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`&&!fr.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 Pe.is(this.#e)?new mr(Pe.cloneWithTraversal(this.#e,Ie.is(this.#e.traversal)?Ie.cloneWithLeg(this.#e.traversal,dr.create(e,t)):Fe.cloneWithValue(this.#e.traversal,D.createImmediate(t)))):new mr(Ie.cloneWithLeg(this.#e,dr.create(e,t)))}},mr=class e extends pr{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new hr(this,e)}$castTo(){return new e(this.#e)}$notNull(){return new e(this.#e)}toOperationNode(){return this.#e}},hr=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}get expression(){return this.#e}get alias(){return this.#t}toOperationNode(){return m.create(this.#e.toOperationNode(),g(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};const gr=u({is(e){return e.kind===`TupleNode`},create(e){return u({kind:`TupleNode`,values:u(e)})}}),_r=u({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}),vr=u([/^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+\)$/]),yr=u({is(e){return e.kind===`DataTypeNode`},create(e){return u({kind:`DataTypeNode`,dataType:e})}});function br(e){return _r[e]||vr.some(t=>t.test(e))}function xr(e){if(g(e))return e.toOperationNode();if(br(e))return yr.create(e);throw Error(`invalid column data type ${JSON.stringify(e)}`)}const Sr=u({is(e){return e.kind===`CastNode`},create(e,t){return u({kind:`CastNode`,expression:e,dataType:t})}});function Cr(t=Dn){function n(e,t,n){return new J(Qe(e,t,n))}function r(e,t){return new J(or(e,t))}let i=Object.assign(n,{fn:void 0,eb:void 0,selectFrom(e){return $n({queryId:U(),executor:t,queryNode:L.createFrom(jr(e))})},case(t){return new sr({node:Z.create(e(t)?void 0:T(t))})},ref(t,n){return e(n)?new J(E(t)):new pr(ze(t,n))},jsonPath(){return new pr(Ie.create())},table(e){return new J(Q(e))},val(e){return new J(O(e))},refTuple(...e){return new J(gr.create(e.map(T)))},tuple(...e){return new J(gr.create(e.map(O)))},lit(e){return new J(Xe(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(le.create(T(e),b.create(`between`),v.create(O(t),O(n))))},betweenSymmetric(e,t,n){return new J(le.create(T(e),b.create(`between symmetric`),v.create(O(t),O(n))))},and(e){return f(e)?new J(et(e,`and`)):new J($e(e,`and`))},or(e){return f(e)?new J(et(e,`or`)):new J($e(e,`or`))},parens(...e){let t=A(e);return k.is(t)?new J(t):new J(k.create(t))},cast(e,t){return new J(Sr.create(T(e),xr(t)))}});return i.fn=ir(),i.eb=i,i}function wr(e){return Cr()}function Tr(e){if(g(e))return e.toOperationNode();if(c(e))return e(wr()).toOperationNode();throw Error(`invalid expression: ${JSON.stringify(e)}`)}function Er(e){if(g(e))return e.toOperationNode();if(c(e))return e(wr()).toOperationNode();throw Error(`invalid aliased expression: ${JSON.stringify(e)}`)}function Dr(e){return ae(e)||oe(e)||c(e)}var Or=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new kr(this.#e,e)}},kr=class{#e;#t;get table(){return this.#e}get alias(){return this.#t}constructor(e,t){this.#e=e,this.#t=t}toOperationNode(){return m.create(Q(this.#e),p.create(this.#t))}};function Ar(e){return l(e)&&g(e)&&t(e.table)&&t(e.alias)}function jr(e){return f(e)?e.map(e=>Mr(e)):[Mr(e)]}function Mr(e){return t(e)?Nr(e):Ar(e)?e.toOperationNode():Er(e)}function Nr(e){let t=` as `;if(e.includes(t)){let[n,r]=e.split(t).map(Pr);return m.create(Q(n),p.create(r))}return Q(e)}function Q(e){if(e.includes(`.`)){let[t,n]=e.split(`.`).map(Pr);return h.createWithSchema(t,n)}return h.create(e)}function Pr(e){return e.trim()}const Fr=u({is(e){return e.kind===`CreateViewNode`},create(e){return u({kind:`CreateViewNode`,name:ie.create(e)})},cloneWith(e,t){return u({...e,...t})}});var Ir=class e{#e;constructor(e){this.#e=u(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new Lr(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?u([t]):u([...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?Dn: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 Ir(e)}var Lr=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 m.create(this.#e.toOperationNode(),g(this.#t)?this.#t.toOperationNode():p.create(this.#t))}};const Rr=Object.assign((e,...t)=>$({queryId:U(),rawNode:C.create(e,t?.map(zr)??[])}),{ref(e){return $({queryId:U(),rawNode:C.createWithChild(E(e))})},val(e){return $({queryId:U(),rawNode:C.createWithChild(O(e))})},table(e){return $({queryId:U(),rawNode:C.createWithChild(Q(e))})},id(...e){let t=Array(e.length+1).fill(`.`);return t[0]=``,t[t.length-1]=``,$({queryId:U(),rawNode:C.create(t,e.map(p.create))})},lit(e){return $({queryId:U(),rawNode:C.createWithChild(D.createImmediate(e))})},raw(e){return $({queryId:U(),rawNode:C.createWithSql(e)})},join(e,t=Rr`, `){let n=Array(Math.max(2*e.length-1,0)),r=t.toOperationNode();for(let t=0;t<e.length;++t)n[2*t]=zr(e[t]),t!==e.length-1&&(n[2*t+1]=r);return $({queryId:U(),rawNode:C.createWithChildren(n)})}});function zr(e){return g(e)?e.toOperationNode():O(e)}var Br=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 Vr=/'/g,Hr=/['"]/g;var Ur=class extends Br{#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&&!k.is(this.parentNode)&&!M.is(this.parentNode)&&!re.is(this.parentNode)&&!Fr.is(this.parentNode)&&!Wn.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&&!k.is(this.parentNode)&&!C.is(this.parentNode)&&!P.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&&!k.is(this.parentNode)&&!C.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(Kr[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&&!k.is(this.parentNode)&&!C.is(this.parentNode)&&!P.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(Wr[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 b.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||!re.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(Vr,`''`)}sanitizeJSONPathMemberValue(e){return e.replace(Hr,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?Gr[e.modifier]-Gr[t.modifier]:1))}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}};const Wr=u({ForKeyShare:`for key share`,ForNoKeyUpdate:`for no key update`,ForUpdate:`for update`,ForShare:`for share`,NoWait:`nowait`,SkipLocked:`skip locked`,Distinct:`distinct`}),Gr=u({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Kr=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`}),qr=`kysely_migration`,Jr=`kysely_migration_lock`;function Yr(e){let t=e.filter(e=>e.pk>0),n=t.length===1?t[0]:void 0;return n?.type.toLowerCase()===`integer`?n.name:void 0}async function Xr(e,t,n){let r=Yr(n);if(!r)return;let{rows:i}=await Rr`
|
|
2
|
+
PRAGMA index_list(${Rr.id(t)})
|
|
3
|
+
`.execute(e.withoutPlugins());return i.some(e=>e.origin===`pk`)?void 0:r}function Zr(e,t,n){return{name:e.name,isView:e.type===`view`,columns:t.map(e=>({name:e.name,dataType:e.type,isNullable:e.notnull===0,isAutoIncrementing:e.name===n,hasDefaultValue:e.dflt_value!=null}))}}async function Qr(e,t){let{rows:n}=await Rr`
|
|
4
|
+
PRAGMA table_info(${Rr.id(t)})
|
|
5
|
+
`.execute(e.withoutPlugins());if(n.length===0)return;let r=await Xr(e,t,n);return Zr({name:t},n,r)}async function $r(e,t){if(t.length===0)return[];try{return await e.introspection.getTables()}catch{return(await Promise.all(t.map(t=>Qr(e,t)))).filter(e=>e!==void 0)}}function ei(e){let t=e;async function n(){return[]}async function r(n={withInternalKyselyTables:!1}){let r=t.selectFrom(`sqlite_schema`).where(`type`,`=`,`table`).where(`name`,`not like`,`sqlite_%`).select(`name`);n.withInternalKyselyTables||(r=r.where(`name`,`!=`,qr).where(`name`,`!=`,Jr));let i=await r.execute();return Promise.all(i.map(async({name:t})=>{let n=await e.selectFrom(Rr`pragma_table_info(${t})`.as(`table_info`)).select([`cid`,`name`,`type`,`notnull`,`dflt_value`,`pk`]).execute(),r=await Xr(e,t,n);return Zr({name:t},n,r)}))}return{getSchemas:n,getTables:r,getMetadata:async e=>({tables:await r(e)})}}export{i as $,D as A,x as B,hn as C,L as D,on as E,ke as F,ne as G,h as H,C as I,o as J,p as K,we as L,Ve as M,He as N,I as O,E as P,c as Q,Ce as R,yn as S,U as T,ie as U,g as V,re as W,s as X,r as Y,a as Z,Nn as _,Yr as a,Cn as b,Rr as c,Or as d,n as et,Tr as f,ir as g,Z as h,$r as i,ee as it,qe as j,A as k,Fr as l,sr as m,qr as n,t as nt,Zr as o,xr as p,u as q,ei as r,e as rt,Ur as s,Jr as t,l as tt,Q as u,En as v,ln as w,bn as x,q as y,Se as z};
|