@noormdev/cli 1.0.0-alpha.12 → 1.0.0-alpha.14
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/noorm.js +41 -0
- package/package.json +4 -8
- package/scripts/postinstall.js +105 -56
- package/dist/chunk-5DTOZH7A.js +0 -9
- package/dist/chunk-CFWFYGBB.js +0 -7
- package/dist/chunk-CTFIMWJ7.js +0 -8
- package/dist/chunk-ERDQ5FIO.js +0 -2
- package/dist/chunk-GGT3S2QA.js +0 -5
- package/dist/chunk-GQBL2JPZ.js +0 -2
- package/dist/chunk-KVY4JR2A.js +0 -2
- package/dist/chunk-PJYMXUBP.js +0 -2
- package/dist/chunk-QI5B3GSQ.js +0 -2
- package/dist/chunk-QNPOKMVM.js +0 -208
- package/dist/chunk-UR6MHSHU.js +0 -2
- package/dist/connection-AQAVQLXV.js +0 -2
- package/dist/devtools-YYBWFXMQ.js +0 -8
- package/dist/engine-RYCOAOP4.js +0 -2
- package/dist/esm-74GQLDJV.js +0 -3
- package/dist/index.js +0 -3126
- package/dist/mssql-Y7W7F4UH.js +0 -2
- package/dist/mysql-EEPNIS5Q.js +0 -2
- package/dist/mysql2-GYI2HTEE.js +0 -3008
- package/dist/open-NGBTRDPN.js +0 -3
- package/dist/postgres-7E352BHM.js +0 -2
- package/dist/sqlite-KSGG7IKM.js +0 -2
- package/dist/storage-YJUXROPC.js +0 -2
- package/dist/tarn-LSH7NLRE.js +0 -2
- package/dist/tedious-7M6OXIVA.js +0 -192
package/dist/chunk-CTFIMWJ7.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
var se=(t,e,r=!1)=>{Object.entries(e).map(([i,n])=>{Object.defineProperty(t,i,{value:n,writable:!1,enumerable:!1,configurable:r})})};var ke=(t,e)=>e.split(".").reduce((i,n)=>{if(i==null)return null;if(i instanceof Map)return i.get(n);if(i instanceof Set){let s=i.has(n),o=Array.from(i);return s?o[o.indexOf(n)]:o[n]}return i[n]},t),tt=(t,e,r)=>{u(typeof t=="object"&&t!==null,"obj must be a non-null object"),u(typeof e=="string"&&e.length>0,"path must be a non-empty string");let i=e.split("."),n=i[i.length-1],s=t;for(let o=0;o<i.length-1;o++){let c=i[o];if(s==null)throw new Error(`Cannot set property '${c}' on ${s} at path: ${i.slice(0,o).join(".")}`);if(typeof s!="object")throw new Error(`Cannot set property '${c}' on primitive value at path: ${i.slice(0,o).join(".")}`);c in s||(s[c]={}),s=s[c]}if(s==null)throw new Error(`Cannot set property '${n}' on ${s}`);if(typeof s!="object")throw new Error(`Cannot set property '${n}' on primitive value`);s[n]=r},_e=(t,e)=>{u(typeof t=="object"&&t!==null,"obj must be a non-null object"),u(Array.isArray(e),"entries must be an array");for(let r=0;r<e.length;r++){let i=e[r];u(Array.isArray(i)&&i.length===2,`entry ${r} must be a [path, value] tuple`);let[n,s]=i;u(typeof n=="string"&&n.length>0,`entry ${r} must have a non-empty string path (received: ${typeof n})`),tt(t,n,s)}};var Se=class extends Error{};var ie=(t,e)=>t==null||(e instanceof Function?!!e(t):!!e),u=(t,e,r)=>{if((t instanceof Function?!!t():!!t)===!1)throw new(r||Se)(e||"assertion failed")};var A=(t,...e)=>{t!==void 0&&u(...e)};var B=t=>t==null||typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint",$=t=>t==null,H=(t,e)=>$(t)===!1&&$(e)===!1&&t.constructor===e.constructor;var b=t=>t instanceof Function,Te=t=>t instanceof Object,rt=new Set([Date,RegExp,Function,Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError,DOMException,Array,Set,Map,WeakMap,WeakSet,Promise,Proxy,Symbol,BigInt,WeakRef,FinalizationRegistry,DataView,ArrayBuffer,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array,FormData,URLSearchParams]),C=t=>!B(t)&&Te(t)&&!rt.has(t.constructor);var nt=new Set(["true","yes",!0]),st=new Set(["false","no",!1]),qe=t=>nt.has(t),Ue=t=>st.has(t);var O=async t=>{u(b(t),"fn must be a function");try{return[await t(),null]}catch(e){return[null,e]}},S=t=>{u(b(t),"fn must be a function");try{return[t(),null]}catch(e){return[null,e]}};var k=new Map,R=new Map;var it=new Set(["__proto__","constructor","prototype"]),P=t=>typeof t=="string"&&it.has(t),oe=t=>Object.keys(t).filter(e=>!P(e));var ot=()=>{k.set(Array,(e,r)=>e.map(i=>v(i,r))),k.set(Object,(e,r)=>{let i={},n=Object.keys(e);for(let s of n)P(s)||(i[s]=v(e[s],r));return i}),k.set(Map,(e,r)=>{let i=new Map;for(let n of e.entries()){let[s,o]=n;i.set(s,v(o,r))}return i}),k.set(Set,(e,r)=>{let i=new Set;for(let n of e)i.add(v(n,r));return i}),[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array].forEach(e=>{k.set(e,r=>new e(r))}),k.set(ArrayBuffer,e=>e.slice(0)),k.set(DataView,e=>{let r=e.buffer.slice(0);return new DataView(r,e.byteOffset,e.byteLength)}),k.set(Error,(e,r)=>{let i=typeof structuredClone=="function"?structuredClone(e):new e.constructor(e.message);e.name&&(i.name=e.name),e.stack&&(i.stack=e.stack);let n=Object.keys(e);for(let s of n)s!=="name"&&s!=="message"&&s!=="stack"&&!P(s)&&(i[s]=v(e[s],r));return i}),k.set(Date,e=>new Date(e.getTime())),k.set(RegExp,e=>new RegExp(e.source,e.flags))},Ke=!1,at=new Set([ArrayBuffer,DataView,Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array,Error,Date,RegExp]),v=(t,e=new WeakMap)=>{if(Ke||(ot(),Ke=!0),B(t))return t;if(e.has(t))return e.get(t);if(t instanceof Error)return k.get(Error)(t,e);let r=Object.getPrototypeOf(t)?.constructor||t.constructor,i=k.get(r);if(!i)return t;if(at.has(r))return i(t,e);let n;if(Array.isArray(t)){n=[],e.set(t,n);let o=i(t,e);return n.push(...o),n}if(t instanceof Map){n=new Map,e.set(t,n);let o=i(t,e);for(let[c,a]of o)n.set(c,a);return n}if(t instanceof Set){n=new Set,e.set(t,n);let o=i(t,e);for(let c of o)n.add(c);return n}n={},e.set(t,n);let s=i(t,e);return Object.assign(n,s),n};var ct=(t,e)=>{for(let r of e)t.push(r);return t},ut=(t,e)=>{for(let r of e)t.has(r)||t.add(r);return t},lt=(t,e)=>{t.length=0;for(let r of e)t.push(r);return t},ft=(t,e)=>{t.clear();for(let r of e)t.add(r);return t},pt=()=>{R.set(Array,(r,i,n)=>n?.mergeArrays?ct(r,i):lt(r,i)),R.set(Set,(r,i,n)=>n?.mergeSets?ut(r,i):ft(r,i)),R.set(Object,(r,i,n)=>{let s=r,o=i,c=Object.keys(o);for(let a of c)if(!P(a)){if(s[a]===void 0||$(s[a])||$(o[a])){s[a]=o[a];continue}if(H(s[a],o[a])){s[a]=J(s[a],o[a],n);continue}s[a]=o[a]}return s}),R.set(Map,(r,i,n)=>{let s=r,o=i;for(let[c,a]of o.entries()){if(!s.has(c)){s.set(c,a);continue}let l=s.get(c);if($(l)||$(a)){s.set(c,a);continue}if(H(a,l)){s.set(c,J(l,a,n));continue}s.set(c,a)}return s}),R.set(Error,(r,i,n)=>{let s=r,o=i,c=oe(o);for(let a of c){if(s[a]===void 0){s[a]=o[a];continue}if(H(s[a],o[a])){s[a]=J(s[a],o[a],n);continue}s[a]=o[a]}return s}),[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,BigInt64Array,BigUint64Array].forEach(r=>{R.set(r,(i,n)=>new r(n))}),R.set(ArrayBuffer,(r,i)=>i.slice(0)),R.set(DataView,(r,i)=>{let n=i,s=n.buffer.slice(0);return new DataView(s,n.byteOffset,n.byteLength)}),[Error,TypeError,ReferenceError,SyntaxError,RangeError,EvalError,URIError].forEach(r=>{R.set(r,(i,n)=>{let s=n,o=new s.constructor(s.message);s.name&&(o.name=s.name),s.stack&&(o.stack=s.stack);let c=Object.keys(s);for(let a of c)a!=="name"&&a!=="message"&&a!=="stack"&&!P(a)&&(o[a]=s[a]);return o})})},Be=!1,Re={mergeArrays:!0,mergeSets:!0},J=(t,e,r={})=>{if(Be||(pt(),Be=!0),r={...Re,...r},B(e)||e instanceof Date)return e;if(H(e,t)){let i=Object.getPrototypeOf(t)?.constructor||t.constructor,n=R.get(i);return n?n(t,e,r):t}return e};var ht=(t,e)=>t.priority===e.priority?t.order-e.order:t.priority-e.priority,mt=(t,e)=>t.priority===e.priority?e.order-t.order:t.priority-e.priority,V=class t{heap=[];insertionCounter=0;compare;options;constructor(e={}){if(this.compare=e.lifo?mt:ht,e.compare&&(this.compare=e.compare),e.maxHeap){let r=this.compare;this.compare=(i,n)=>-r(i,n)}this.options=e}push(e,r=0){let i={value:e,priority:r,order:this.insertionCounter++};this.heap.push(i),this.bubbleUp(this.heap.length-1)}pop(){if(this.heap.length===0)return null;let e=this.heap[0],r=this.heap.pop();return this.heap.length>0&&(this.heap[0]=r,this.bubbleDown(0)),e.value}popMany(e=1){let r=[];if(e===0)return r;e>this.heap.length&&(e=this.heap.length);for(let i=e;i>0;i--)r.push(this.pop());return r}peek(){return this.isEmpty()?null:this.heap[0].value}peekMany(e=1){return this.heap.slice(0,e).map(r=>r.value)}find(e){return this.heap.find(r=>e(r.value))?.value??null}heapify(e){this.heap=e.slice(0),this.insertionCounter=e.length;for(let r=Math.floor(this.heap.length/2);r>=0;r--)this.bubbleDown(r)}clone(){let e=new t(this.options);return e.heapify(this.heap),e}toSortedArray(){let e=this.clone(),r=[];for(;e.heap.length>0;)r.push(e.pop());return r}*[Symbol.iterator](){let e=this.clone();for(;e.heap.length>0;)yield e.pop()}size(){return this.heap.length}isEmpty(){return this.heap.length===0}clear(){this.heap=[],this.insertionCounter=0}bubbleUp(e){let r=e;for(;r>0;){let i=r-1>>1;if(this.compare(this.heap[r],this.heap[i])<0)this.swap(r,i),r=i;else break}}bubbleDown(e){let r=this.heap.length,i=e;for(;;){let n=(i<<1)+1,s=n+1,o=i;if(n<r&&this.compare(this.heap[n],this.heap[o])<0&&(o=n),s<r&&this.compare(this.heap[s],this.heap[o])<0&&(o=s),o===i)break;this.swap(i,o),i=o}}swap(e,r){[this.heap[e],this.heap[r]]=[this.heap[r],this.heap[e]]}};var Z=class{promise;resolve;reject;constructor(){this.promise=new Promise((e,r)=>{this.resolve=e,this.reject=r})}};typeof Promise.withResolvers!="function"&&(Promise.withResolvers=()=>new Z);var Me=class extends Promise{clear},M=(t,e=!0)=>{let r,i=new Me(n=>{r=setTimeout(()=>{r=null,n(e)},t)});return i.clear=()=>{r&&(clearTimeout(r),r=null)},i};if(typeof setImmediate!="function"){let t=0,e=new Map,r=new MessageChannel;r.port1.onmessage=async i=>{let n=i.data,s=e.get(n);if(!s)return;let[,o]=await O(s);o&&console.error("Error in setImmediate",o)},globalThis.setImmediate=(i,...n)=>{let s=t++;return e.set(s,()=>i(...n)),r.port2.postMessage(s),s},globalThis.clearImmediate=i=>{e.delete(i)}}var gt={retry:new WeakMap,circuitBreaker:new WeakMap,rateLimit:new WeakMap,throttle:new WeakMap,debounce:new WeakMap,memoize:new WeakMap,withTimeout:new WeakMap,inflight:new WeakMap};var ae=(t,e)=>{if(gt[e].has(t))throw new Error(`Function is already wrapped with ${e}`)};var Ie=class extends Error{constructor(e){super(e),this.name="RetryError"}};var bt=t=>{u(C(t),"opts must be an object"),A(t.retries,typeof t.retries=="number"&&t.retries>0,"retries must be a positive number"),A(t.delay,typeof t.delay=="number"&&t.delay>=0,"delay must be a positive number"),A(t.backoff,typeof t.backoff=="number"&&t.backoff>0,"backoff must be a positive number"),A(t.shouldRetry,b(t.shouldRetry),"shouldRetry must be a function"),A(t.signal,t.signal instanceof AbortSignal,"signal must be an AbortSignal")},Tr=async(t,e)=>{u(b(t),"fn must be a function"),ae(t,"retry"),bt(e);let{delay:r=0,retries:i=3,backoff:n=1,jitterFactor:s=0,shouldRetry:o=()=>!0,signal:c}=e,a=0;for(;a<i;){c?.throwIfAborted();let[l,d]=await O(t);if(c?.throwIfAborted(),d===null)return l;if(d&&o(d)){await M(r*n*(1+s*Math.random())),a++,c?.throwIfAborted();continue}throw d}throw new Ie("Max retries reached")};var j=()=>{},Oe=()=>"_"+Math.random().toString(36).slice(2,9);var Ce=new WeakMap,Q=t=>(Ce.has(t)||Ce.set(t,Oe()),Ce.get(t)),ce=t=>{let e=new WeakSet,r=n=>{if(n===null)return"null";if(n===void 0)return"undefined";if(typeof n=="string")return`${n}`;if(typeof n=="number")return Object.is(n,-0)?"-0":String(n);if(typeof n=="boolean")return String(n);if(typeof n=="bigint")return`bi:${n}`;if(typeof n=="symbol")return`sym:${Q(n)}`;if(typeof n=="function")return`fn:${Q(n)}`;if(n instanceof Date)return`d:${n.getTime()}`;if(n instanceof RegExp)return`r:${n.toString()}`;if(n instanceof Error)return`e:${Q(n)}`;if(n instanceof WeakMap)return`wm:${Q(n)}`;if(n instanceof WeakSet)return`ws:${Q(n)}`;if(typeof n=="object"){if(e.has(n))return`circ:${Q(n)}`;if(e.add(n),n instanceof Map){let l=`map:${Array.from(n.entries()).map(([d,y])=>`${r(d)}:${r(y)}`).sort().join(",")}`;return e.delete(n),l}if(n instanceof Set){let l=`set:${Array.from(n).map(r).sort().join(",")}`;return e.delete(n),l}if(Array.isArray(n)){let a=`[${n.map(r).join(",")}]`;return e.delete(n),a}let c=`{${Object.keys(n).sort().map(a=>`"${a}":${r(n[a])}`).join(",")}}`;return e.delete(n),c}return`u:${String(n)}`};return t.map(r).join("|")||"0"};var ue=t=>{if(t instanceof WeakRef){let e=t.deref();return[e,e===void 0]}return[t,!1]},le=(t,e,r,i,n)=>({value:i&&Te(t)&&t!==null?new WeakRef(t):t,createdAt:e,expiresAt:r,accessCount:1,lastAccessed:e,accessSequence:n}),G=t=>Date.now()>=t.expiresAt;var Pe=(t,e)=>{let r=Date.now();t.lastAccessed=r,t.accessCount=(t.accessCount??0)+1,t.accessSequence=e};var fe=t=>{let e=null,r=1/0,i=1/0;for(let[n,s]of t.entries()){let o=s.lastAccessed??0,c=s.accessSequence??0;(o<r||o===r&&c<i)&&(r=o,i=c,e=n)}return e&&t.delete(e),e};var Ve=new WeakSet,pe=(t,e={})=>{u(b(t),"fn must be a function"),u(!Ve.has(t),"Function is already wrapped by memoize");let{ttl:r=6e4,maxSize:i=1e3,generateKey:n,onError:s,cleanupInterval:o=6e4,useWeakRef:c=!1,shouldCache:a}=e,{staleIn:l,staleTimeout:d,adapter:y}=e;u(r>0,"ttl must be greater than 0"),u(i>0,"maxSize must be greater than 0"),u(ie(o,w=>typeof w=="number"&&w>=0),"cleanupInterval must be >= 0"),A(n,b(n),"generateKey must be a function"),A(s,b(s),"onError must be a function"),u(y===void 0,"memoizeSync does not support custom cache adapters (use memoize for async adapters like Redis)"),u(d===void 0,"memoizeSync does not support staleTimeout (sync functions execute instantly)"),u(l===void 0,"memoizeSync does not support staleIn (sync functions execute instantly, use ttl instead)");let p=new Map,h=0,g=0,x=0,f=0,m,E=()=>(h>=Number.MAX_SAFE_INTEGER-1&&(h=0),++h),U=()=>g++,F=()=>x++,be=()=>{let w=Date.now();for(let[T,N]of p.entries())w>=N.expiresAt&&p.delete(T)};o>0&&(m=setInterval(()=>be(),o),typeof m.unref=="function"&&m.unref());let we=function(...w){if(a){let[Ee,Ae]=S(()=>a(...w));if(!Ae&&!Ee)return t(...w)}let[T,N]=S(()=>n?n(...w):ce(w));if(N)return s?.(N,w),F(),t(...w);let K=p.get(T);if(K&&!G(K)){Pe(K,E());let[Ee,Ae]=ue(K.value);if(Ae){p.delete(T),F();let[Le,ve]=S(()=>t(...w));if(ve)throw s?.(ve,w),ve;let We=Date.now(),et=le(Le,We,We+r,c,E());return p.size>=i&&(fe(p),f++),p.set(T,et),Le}return U(),Ee}F();let[Ne,xe]=S(()=>t(...w));if(xe)throw s?.(xe,w),xe;let ze=Date.now(),Ze=le(Ne,ze,ze+r,c,E());return p.size>=i&&(fe(p),f++),p.set(T,Ze),Ne};return we.cache={clear:()=>{p.clear(),g=0,x=0,f=0,h=0,m!==void 0&&(clearInterval(m),m=void 0)},delete:w=>p.delete(w),has:w=>{let T=p.get(w);return T?G(T)?(p.delete(w),!1):!0:!1},get size(){return p.size},stats:()=>({hits:g,misses:x,evictions:f,hitRate:g+x>0?g/(g+x):0,size:p.size}),keys:()=>p.keys(),entries:()=>{let w=[];for(let[T,N]of p.entries())if(!G(N)){let[K]=ue(N.value);w.push([T,K])}return w}},Ve.add(we),we};var he=class{capacity;refillIntervalMs;#t;#n;#e;constructor(e,r){this.capacity=e,this.refillIntervalMs=r,this.#e={totalRequests:0,rejectedRequests:0,totalWaitTime:0,waitCount:0,createdAt:Date.now()},this.#t=e,this.#n=Date.now()}#r(){let e=Date.now(),r=e-this.#n,i=1/this.refillIntervalMs;if(r<0||r>this.refillIntervalMs*this.capacity*2){this.#n=e,this.#t=this.capacity;return}if(r>0){let n=r*i;this.#t=Math.min(this.capacity,this.#t+n),this.#n=e}}reset(){this.#t=this.capacity,this.#n=Date.now()}get tokens(){return Math.floor(this.#t)}consume(e=1){return this.#r(),this.#e.totalRequests++,this.#t>=e?(this.#t-=e,!0):(this.#e.rejectedRequests++,!1)}getWaitTimeMs(e=1){this.#r();let r=e-this.#t;if(r<=0)return 0;let i=1/this.refillIntervalMs;return Math.ceil(r/i)+1}getNextAvailable(e=1){return new Date(Date.now()+this.getWaitTimeMs(e))}get snapshot(){this.#r();let r=Date.now()-this.#e.createdAt;return{currentTokens:this.tokens,capacity:this.capacity,refillIntervalMs:this.refillIntervalMs,totalRequests:this.#e.totalRequests,rejectedRequests:this.#e.rejectedRequests,successfulRequests:this.#e.totalRequests-this.#e.rejectedRequests,rejectionRate:this.#e.totalRequests>0?this.#e.rejectedRequests/this.#e.totalRequests:0,totalWaitTime:this.#e.totalWaitTime,waitCount:this.#e.waitCount,averageWaitTime:this.#e.waitCount>0?this.#e.totalWaitTime/this.#e.waitCount:0,uptime:r,createdAt:this.#e.createdAt}}async waitForToken(e=1,r={}){let{onRateLimit:i,abortController:n,jitterFactor:s=0}=r;if(this.#r(),this.#t>=e)return;let o=Date.now();for(this.#e.waitCount++;this.#t<e;){if(n?.signal?.aborted)return;await i?.(new me("Rate limit exceeded",this.capacity),this.getNextAvailable(e)),await M(this.getWaitTimeMs(e)+Math.random()*s),this.#r()}let c=Date.now();this.#e.totalWaitTime+=c-o}async waitAndConsume(e=1,r={}){let{onRateLimit:i,abortController:n,jitterFactor:s=0}=r;if(this.#r(),this.#e.totalRequests++,this.#t>=e)return this.#t-=e,!0;let o=Date.now();for(this.#e.waitCount++;this.#t<e;){if(n?.signal?.aborted)return this.#e.rejectedRequests++,!1;await i?.(new me("Rate limit exceeded",this.capacity),this.getNextAvailable(e)),await M(this.getWaitTimeMs(e)+Math.random()*s),this.#r()}this.#t-=e;let c=Date.now();return this.#e.totalWaitTime+=c-o,!0}},me=class extends Error{maxCalls;constructor(e,r){super(e),this.name="RateLimitError",this.maxCalls=r}};var ee=class extends Error{constructor(e){super(e)}},Ye=t=>t?.constructor?.name===ee.name;var z={sec:1e3,min:6e4,min15:9e5,min30:18e5,hour:36e5,hour2:72e5,hour4:144e5,hour8:288e5,hour12:432e5,day:864e5,week:6048e5,secs(t){return t*this.sec},mins(t){return t*this.min},hours(t){return t*this.hour},days(t){return t*this.day},weeks(t){return t*this.week},months(t){return Math.round(t*30.4*this.day)},years(t){return t*365*this.day}},xt=t=>z.secs(t),Et=t=>z.mins(t),At=t=>z.hours(t),vt=t=>z.days(t),kt=t=>z.weeks(t),St=t=>z.months(t),Tt=t=>z.years(t),Qe=t=>{let e=t.match(/^(\d+(?:\.\d+)?)\s*(s|sec|secs?|seconds?|m|min|mins?|minutes?|h|hr|hrs?|hour|hours?|d|day|days?|w|wk|wks?|week|weeks?|mo|mon|mons?|month|months?|y|yr|yrs?|year|years?)$/i);if(!e)throw new Error(`Invalid time duration: ${t}`);let[,r,i]=e,n=parseFloat(r),s=i.toLowerCase();if(s.startsWith("s"))return xt(n);if(s.startsWith("m")&&!s.startsWith("mo"))return Et(n);if(s.startsWith("h"))return At(n);if(s.startsWith("d"))return vt(n);if(s.startsWith("w"))return kt(n);if(s.startsWith("mo"))return St(n);if(s.startsWith("y"))return Tt(n);throw new Error(`Unknown unit: ${i}`)};var de={kb:1024,mb:1048576,gb:1073741824,tb:1099511627776,kbs(t){return t*this.kb},mbs(t){return t*this.mb},gbs(t){return t*this.gb},tbs(t){return t*this.tb}},Rt=t=>de.kbs(t),Mt=t=>de.mbs(t),It=t=>de.gbs(t),Ct=t=>de.tbs(t),Ge=t=>{let e=t.match(/^(\d+(?:\.\d+)?)\s*(kb|kbs?|kilobytes?|mb|mbs?|megabytes?|gb|gbs?|gigabytes?|tb|tbs?|terabytes?)$/i);if(!e)throw new Error(`Invalid byte size: ${t}`);let[,r,i]=e,n=parseFloat(r),s=i.toLowerCase();if(s.startsWith("k"))return Rt(n);if(s.startsWith("m"))return Mt(n);if(s.startsWith("g"))return It(n);if(s.startsWith("t"))return Ct(n);throw new Error(`Unknown unit: ${i}`)};var Ot=/^\d+$/,Xe=(t,e={})=>{let{parseUnits:r=!1,skipConversion:i}=e;for(let n in t){let s=n,o=t[s];if(i?.(n,o))continue;if(typeof o=="object"&&o!==null){Xe(o,e);continue}if(r&&typeof o=="string"){let[d,y]=S(()=>Qe(o));if(!y&&typeof d=="number"){t[s]=d;continue}let[p,h]=S(()=>Ge(o));if(!h&&typeof p=="number"){t[s]=p;continue}}let a=qe(t[s]),l=Ue(t[s]);if(a||l){t[s]=a;continue}if(typeof o=="string"&&Ot.test(o)){t[s]=Number(o);continue}}},ps=(t,e={})=>{u(typeof t=="object"&&t!==null,"flatConfig must be a non-null object"),u(typeof e=="object"&&e!==null,"opts must be a non-null object"),u(e.filter===void 0||typeof e.filter=="function","filter must be a function"),u(e.forceAllCapToLower===void 0||typeof e.forceAllCapToLower=="boolean","forceAllCapToLower must be a boolean"),u(e.separator===void 0||typeof e.separator=="string","separator must be a string"),u(e.stripPrefix===void 0||typeof e.stripPrefix=="string"||typeof e.stripPrefix=="number","stripPrefix must be a string or number"),u(e.parseUnits===void 0||typeof e.parseUnits=="boolean","parseUnits must be a boolean"),u(e.skipConversion===void 0||typeof e.skipConversion=="function","skipConversion must be a function"),u(e.memoizeOpts===void 0||typeof e.memoizeOpts=="object"||e.memoizeOpts===!1,"memoizeOpts must be an object or false");let{filter:r,forceAllCapToLower:i=!0,separator:n="_",stripPrefix:s,parseUnits:o=!1,skipConversion:c,memoizeOpts:a=!1}=e,l=h=>/^[A-Z0-9_]+$/.test(h),d=h=>{let g=h;return s!==void 0&&(typeof s=="number"?g=h.slice(s):g=h.startsWith(s)?h.slice(s.length):h),g.split(n).map(f=>l(f)&&i?f.toLowerCase():f).join(".")};function y(){let h=v(t),g={},x=Object.entries(h).filter(([m,E])=>r?.(m,E)??!0).map(([m])=>m).sort(),[,f]=S(()=>{_e(g,x.map(m=>[d(m),h[m]])),Xe(g,{parseUnits:o,skipConversion:c})});if(f instanceof Error&&f.message.includes("on primitive value")){let m=F=>F.split("_").join(n),E=(F,be)=>`${m(F)}=${be}`,U=["Failed to load flatmap variables.","You're likely trying to set a nested property on a non-object value.",`For example, if you have ${E("APP_DB_NAME","foo")}, and then you try to set`,`${E("APP_DB_NAME_TEST","bar")}, you'll get this error because ${m("APP_DB_NAME")} is a string.`,"The correct way is to designate each namespace (separated by underscores) as ",`an object. For example, ${E("APP_DB_NAME","foo")} becomes { db: { name: "foo" } }, and,`,`${E("APP_DB_NAME_TEST","bar")} becomes { db: { name: { test: "bar" } } }, but both cannot coexist.`,`
|
|
3
|
-
|
|
4
|
-
You can either \`unset ${m("APP_PROBLEMATIC")}\` or scope all vars to \`${m("APP_NAMESPACE_NAME")}\` to`,"make it a nested object.",`
|
|
5
|
-
|
|
6
|
-
`];console.error(U.join(" "))}if(f)throw f;return g}function p(h,g){let x=y(),f=ke(x,h);return f??g}return a?{allConfigs:pe(y,a),getConfig:pe(p,a)}:{allConfigs:y,getConfig:p}};var je=class extends Error{listener;data;func;event;stack},Pt=new RegExp(`(${["node_modules","node:internal","$spy","makeEventTracer","sendToSpy","Function.spy","Observable.Engine"].join("|")})`),L=class extends Error{event;listener;data;constructor(e,r){super(e),this.event=r?.event,this.listener=r?.listener,this.data=r?.data}};var De=(t,e,r)=>{let n=new Error().stack.split(`
|
|
7
|
-
`);n.shift();let s=n.filter(l=>!Pt.test(l)),o=`EventStack (${t} ${e.toString()}):`;s.unshift(o);let c=s.join(`
|
|
8
|
-
`),a=new je(o);return a.name=o,a.func=e,a.event=t,a.stack=c,a.listener=null,a.data=null,typeof r=="function"?a.listener=r:a.data=r,a},Je=t=>{let e=t?.replace(/^\//,"").split("/"),r=e.pop(),i=e.join("/");return RegExp(i,r)},$e=(t,e)=>{let r=[];for(let i of t)for(let n of e.get(i)||new Set)r.push({event:i,func:n});return r},I=(function(t){return t.on="on",t.off="off",t.emit="emit",t.clear="clear",t})({}),D=class extends Event{type;data;constructor(e,r){super(e),this.data=r,this.type=e}},te=(t,e)=>{if(e.event===void 0||typeof e.event!="string"&&!(e.event instanceof RegExp))throw new L(`observer.${t}: Event must be a string or RegExp`,e)},Fe=(t,e)=>{if(e.listener!==void 0&&typeof e.listener!="function")throw new L(`observer.${t}: Listener must be a function`,e)};var W=class extends Z{cleanup},re=class{#t;#n;#e;#r=!1;#i=null;#a=null;#c=()=>{if(this.#r===!0)throw new L(`Event generator for ${this.#n.toString()} has been destroyed`,{event:this.#n,listener:this.#i,data:null})};cleanup;next;constructor(e,r,i){this.#t=e,this.#n=r,this.#e=new W,this.#e.promise.cleanup=this.cleanup,this.#e.promise.resolve=this.#e.resolve,this.#i=c=>{this.#a=c,this.#e.resolve(c),this.#e=new W,this.#e.promise.cleanup=this.cleanup,this.#e.promise.resolve=this.#e.resolve};let n=e.on(r,this.#i),s;this.next=()=>(this.#c(),this.#e.promise),this.cleanup=()=>{this.#r||(n(),this.#r=!0,this.#o.forEach(c=>{c.resolve?.(this.#a)}),this.#o.clear(),this.#a=null,s?.abort())};let o=i?.signal;if(o){if(o.aborted){this.#r=!0;return}s=new AbortController,o.addEventListener("abort",this.cleanup,{signal:s.signal})}}#o=new Set;async*[Symbol.asyncIterator](){for(;!this.#r;){let e=this.next();this.#o.add(e),yield await e,this.#o.delete(e)}return Promise.resolve(void 0)}get lastValue(){return this.#a}get done(){return this.#r}emit(e){this.#c(),this.#t.emit(this.#n,e)}};var ye=class{status="stopped";#t={running:["paused","draining","stopped"],draining:["stopped","paused"],paused:["running","draining","stopped"],stopped:["running","draining"]};transition(e){u(this.#t[this.status].includes(e),`Invalid transition from ${this.status} to ${e}`),this.status=e}is(...e){return e.includes(this.status)}get state(){return this.status}};var ge=class{observer;queueName;#t;#n;#e;#r;#i;#a;constructor(e,r){this.observer=e,this.queueName=r,this.#t=0,this.#n=0,this.#e=0,this.#r=0,this.#i=0,this.#a=0,this.observer.on(`queue:${this.queueName}:processing`,()=>{this.#t++}),this.observer.on(`queue:${this.queueName}:success`,i=>{this.#n++,this.#r++,this.#t--,this.#c(i.data.elapsed)}),this.observer.on(`queue:${this.queueName}:error`,()=>{this.#n++,this.#i++,this.#t--}),this.observer.on(`queue:${this.queueName}:rejected`,()=>this.#a++)}#c(e){this.#e=(this.#e*(this.#r-1)+e)/this.#r}get stats(){return{processed:this.#n,processing:this.#t,avgProcessingTime:this.#e,success:this.#r,error:this.#i,rejected:this.#a}}};var _=class{data;constructor(e){this.data=e}},ne=(function(t){return t.full="Queue is full",t.notRunning="Queue is not running",t})({});var X=class{opts;#t;#n;#e;#r;#i;#a;#c;#o;#l;#u;#f;#h;#p;constructor(e){this.opts=e,this.#n=new Map,this.#e=j,this.#r=new ye,this.#c=!0,this.#o=!1,this.#l=!1,this.#u=!1,this.#f=0,this.#h=0,this.#p=new Set;let{observer:r=new q,event:i,process:n,name:s,type:o="fifo",concurrency:c=1,pollIntervalMs:a=100,jitterFactor:l=0,rateLimitIntervalMs:d=1e3,processIntervalMs:y=0,taskTimeoutMs:p=0,autoStart:h=!0,debug:g=!1}=this.opts,{maxQueueSize:x=999999999,rateLimitCapacity:f=999999999}=this.opts;u(C(this.opts),"Options is required to be an object"),u(b(r?.on),"ObserverEngine is required"),u(typeof i=="string"&&i.length>0||i instanceof RegExp,"Event is required to be a string or RegExp"),u(b(n),"Process is required to be a function"),u(s&&typeof s=="string"&&s.length>0,"Name is required"),u(c>0,"Concurrency must be greater than 0"),u(a>0,"pollIntervalMs must be a number greater than 0"),u(l>=0&&l<=1,"Jitter must be a number greater than or equal to 0 and less than or equal to 1"),u(x>0,"MaxQueueSize must be a number greater than 0"),u(d>0,"rateLimitIntervalMs must be a number greater than 0"),u(f>0,"rateLimitCapacity must be a number greater than 0"),u(y>=0,"processIntervalMs must be a number greater than or equal to 0"),u(p>=0,"taskTimeoutMs must be a number greater than or equal to 0"),u(o==="fifo"||o==="lifo",'Type must be either "fifo" or "lifo"'),u(typeof h=="boolean","AutoStart must be a boolean"),x===1/0&&(x=999999999),f===1/0&&(f=999999999),Object.assign(this.opts,{observer:r,type:o,concurrency:c,maxQueueSize:x,pollIntervalMs:a,jitterFactor:l,processIntervalMs:y,taskTimeoutMs:p}),this.#u=g,this.#i=new ge(r,s),this.#a=new he(f,d),this.#t=new V({lifo:o==="lifo"}),h&&this.start()}#m(){if(this.#l)return;this.#l=!0;let e=this.opts.observer.on(this.opts.event,r=>{if((r?.data??r)instanceof _)return;let n=r,s={data:n,_taskId:Oe(),priority:this.#n.get(n)??0};if(this.#n.delete(n),this.#t.size()>=this.opts.maxQueueSize){this.#s("rejected",{...s,reason:ne.full});return}this.#s("added",s),this.#c=!1,this.#t.push(s,s.priority)});this.#e=()=>{e(),this.#l=!1}}#s(e,r){if(this.#u){let i=[`[${this.name}] ${e}`,r?._taskId??"",r?.data??""];this.#u==="verbose"&&(i[1]=r),console.log(...i)}this.opts.observer.emit(`queue:${this.name}:${e}`,new _(r))}#y(){let e=++this.#f;for(let r=0;r<this.opts.concurrency;r++)this.#w(e,r)}async#w(e,r){let{pollIntervalMs:i,jitterFactor:n}=this.opts;for(this.#h++;this.#r.is("running")&&this.#f===e;){if(!this.pending){!this.#c&&!this.pending&&this.#p.size===0&&(this.#c=!0,this.#s("idle")),this.#o=!0,await M(i*(1+Math.random()*n)),this.#o=!1;continue}let s=this.#t.pop();s&&(this.#p.add(`${e}-${r}`),await this.#g(s),this.opts.processIntervalMs>0&&await M(this.opts.processIntervalMs),this.#p.delete(`${e}-${r}`))}this.#h--}async#g(e){if(!this.#r.is("running","draining")){this.#t.push(e);return}let r=!1;this.#r.is("draining")||await this.#a.waitAndConsume(1,{onRateLimit:()=>{this.#s("rate-limited",e),r=!0}});let i=Date.now();this.#s("processing",{...e,startedAt:i,rateLimited:r});let[,n]=await O(async()=>{if(this.opts.taskTimeoutMs===0)return this.opts.process(e.data);let o=await Promise.race([this.opts.process(e.data),M(this.opts.taskTimeoutMs,new ee("Task timed out"))]);if(Ye(o))throw this.#s("timeout",{...e,error:o}),o;return o}),s=Date.now()-i;n?this.#s("error",{...e,error:n,rateLimited:r}):this.#s("success",{...e,startedAt:i,elapsed:s,rateLimited:r}),this.#t.size()===0&&this.#r.is("running")&&this.#s("empty")}start(){if(!this.#r.is("running"))return this.#m(),this.#r.transition("running"),this.#s("start"),this.#y(),this.#s("started"),Promise.resolve()}stop(){this.#r.is("stopped")||(this.#e(),this.#r.transition("stopped"),this.#s("stopped"))}pause(){if(!this.#r.is("paused"))return this.#r.transition("paused"),this.#s("paused"),Promise.resolve()}resume(){if(!this.#r.is("running"))return this.#m(),this.#r.transition("running"),this.#y(),this.#s("resumed"),Promise.resolve()}async#b(e=1/0,r,i){let n=e===1/0?this.#t.size():e,s=this.#t.popMany(n);if(n<s.length&&(n=s.length),r?.(n),n!==0)for(let o of s)await this.#g(o);return i?.(n),n}shutdown(e=!1){if(this.#r.is("draining","stopped"))return Promise.resolve(0);if(e){let r=this.purge();return this.stop(),this.#s("shutdown",{force:e,pending:r}),Promise.resolve(r)}return this.#b(1/0,r=>{this.pause(),this.#r.transition("draining"),this.#e(),this.#s("drain",{pending:r})},r=>{this.#s("drained",e?{pending:r}:{drained:r}),this.stop(),this.#s("shutdown",e?{force:e,pending:r}:{force:e})})}async flush(e=1/0){return this.#b(e,r=>this.#s("flush",{pending:r}),r=>this.#s("flushed",{flushed:r}))}purge(){let e=this.#t.size();return this.#t.clear(),this.#s("purged",{count:e}),e}add(e,r){return this.#r.is("running","paused")?this.#t.size()>=this.opts.maxQueueSize?(this.#s("rejected",{data:e,reason:ne.full}),!1):(r&&this.#n.set(e,r),this.opts.observer.emit(this.opts.event,e),!0):(this.#s("rejected",{data:e,reason:ne.notRunning}),!1)}debug(e=!1){this.#u=e}#d(){return this.opts.observer}on(e,r){return this.#d().on(`queue:${this.name}:${e}`,r)}once(e,r){return this.#d().once(`queue:${this.name}:${e}`,r)}off(e,r){return this.#d().off(`queue:${this.name}:${e}`,r)}get name(){return this.opts.name}get isWaiting(){return this.#o}get isIdle(){return this.#c&&this.#r.is("running")}get isRunning(){return this.#r.is("running")}get isPaused(){return this.#r.is("paused")}get isStopped(){return this.#r.is("stopped")}get isDraining(){return this.#r.is("draining")}get state(){return this.#r.state}get pending(){return this.#t.size()}get stats(){return v(this.#i.stats)}get snapshot(){return{name:this.name,state:this.state,pending:this.pending,stats:this.stats,rateLimiter:this.#a.snapshot,activeRunners:this.#h,runningNodes:this.#p,isIdle:this.isIdle,isWaiting:this.isWaiting,isRunning:this.isRunning,isPaused:this.isPaused,isStopped:this.isStopped,isDraining:this.isDraining,isEmpty:this.pending===0}}};var q=class{#t=new Map;#n=new Map;#e=new EventTarget;#r;#i;#a;#c=new AbortController;#o;constructor(e){e&&(u(!e.name||typeof e.name=="string","Observable options.name must be a string",TypeError),u(!e.spy||typeof e.spy=="function","Observable options.spy must be a function",TypeError),u(!e.emitValidator||typeof e.emitValidator=="function","Observable options.emitValidator must be a function",TypeError),this.#i=e.spy),this.#o=this.#c.signal;let r=e?.signal,i=()=>this.clear();this.#o.addEventListener("abort",i,{once:!0}),r&&r.addEventListener("abort",i,{once:!0}),se(this,{on:this.on,once:this.once,emit:this.emit,off:this.off,observe:this.observe,debug:this.debug,$has:this.$has,$facts:this.$facts,$internals:this.$internals,name:e?.name||Math.random().toString(36).substring(7)}),this.#r=e?.emitValidator}name;$facts(){let e=[...this.#t.keys()],r=[...this.#n.keys()],i=Object.fromEntries([e.map(n=>[n,this.#t.get(n)?.size]),r.map(n=>[n,this.#n.get(n)?.size])].flat());return{listeners:e,rgxListeners:r,listenerCounts:i,hasSpy:!!this.#i}}$internals(){return{listenerMap:v(this.#t),rgxListenerMap:v(this.#n),internalListener:v(this.#e),name:this.name,spy:this.#i}}$has(e){return e instanceof RegExp?this.#n.has(e.toString()):this.#t.has(e)||this.#n.has(e)}#l(...e){this.#i&&this.#i.apply(this,e)}debug(e=!0){let r=this.#i,i=n=>{let{event:s,fn:o,data:c,listener:a}=n;console.info(De(s,o,c||a)),r&&r(n)};if(e){this.#i=i,this.#a=r;return}this.#i=this.#a}spy(e,r=!1){u(b(e),"spy must be a function",TypeError),u(r||this.#i===void 0,"you already have a spy function set",TypeError),this.#i=e}observe(e,r){let i=this,n=r?.signal;if(n?.aborted)return se(e,{on:j,once:j,off:j,emit:j,clear:j,cleanup:j}),e;let s=new Map,o=(f,m)=>{let E=s.get(f)||new Set;return E.add(m),s.set(f,E),m},c=()=>{for(let f of s.entries()){let[m,E]=f;[...E].forEach(U=>i.off(m,U)),s.set(m,new Set)}},a=f=>{let[m,E]=f.data;s.get(m)?.delete(E)};this.#e.addEventListener(I.off,a),this.#e.addEventListener(I.clear,c);let l=(f,m)=>i.on(f,o(f,m)),d=(f,m)=>i.once(f,o(f,m)),y=(f,m)=>{i.off(f,m)},p=(f,m)=>i.emit(f,m),h=()=>c(),g,x=()=>{c(),i.#e.removeEventListener(I.off,a),i.#e.removeEventListener(I.clear,c),g?.abort()};return n&&(g=new AbortController,AbortSignal.any([this.#o,n]).addEventListener("abort",x,{signal:g.signal})),se(e,{on:l,once:d,off:y,emit:p,clear:h,cleanup:x}),e}#u(e){let r=e.constructor===RegExp,i=e.toString();return{isRgx:r,eventName:i,rgx:e}}#f(e){return[...this.#t.keys()].filter(r=>e.test(r))}#h(e){return[...this.#n.keys()].filter(r=>Je(r).test(e)).flat()}#p(e){let r=this.#f(e);return $e(r,this.#t)}#m(e){let r=this.#h(e);return $e(r,this.#n)}on(e,r,i){let n=typeof r=="function",s=n?r:void 0,o=n?i:r;if(o?.once||(te("on",{event:e,listener:s}),Fe("on",{event:e,listener:s})),s===void 0)return new re(this,e,o);let c=o?.signal;if(c?.aborted)return()=>{};let{eventName:a,isRgx:l}=this.#u(e),d=l?this.#n:this.#t;this.#l({event:e,fn:o?.once?"once":"on",data:null,listener:s,context:this});let y=d.get(a)||new Set([s]);y&&!y.has(s)&&y.add(s),d.has(a)||d.set(a,y),this.#e.dispatchEvent(new D(I.on,[e,s]));let p=!1,h=()=>{p||(p=!0,this.#l({event:e,fn:"cleanup",data:null,listener:s,context:this}),y.delete(s),y.size===0&&d.delete(a),this.#e.dispatchEvent(new D(I.off,[e,s])))};if(c){let g=()=>{h(),this.#o.removeEventListener("abort",g)};c.addEventListener("abort",g,{once:!0}),this.#o.addEventListener("abort",g,{once:!0});let x=h;return()=>{x(),c.removeEventListener("abort",g),this.#o.removeEventListener("abort",g)}}return h}once(e,r,i){let n=typeof r=="function",s=n?r:void 0,o=n?i:r;if(te("once",{event:e,listener:s}),Fe("once",{event:e,listener:s}),!s){let l=new W,d=o?.signal;if(d?.aborted)return l.reject(d.reason??new DOMException("Aborted","AbortError")),l.promise.cleanup=()=>{},l.promise;let y,p=this.once(e,h=>{l.resolve(h),y?.abort()},o);return d&&(y=new AbortController,d.addEventListener("abort",()=>{p(),l.reject(d.reason??new DOMException("Aborted","AbortError"))},{signal:y.signal})),l.promise.cleanup=()=>{p(),y?.abort()},l.promise}let c=this,a=function(...l){let{eventName:d,isRgx:y}=c.#u(e),p=y?c.#n:c.#t,h=p.get(d);h&&(h.delete(a),h.size===0&&p.delete(d)),s.apply(c,l)};return this.on(e,a,{once:!0,...o})}off(e,r){te("off",{event:e,listener:r}),this.#l({event:e,fn:"off",data:null,listener:r,context:this});let{eventName:i,isRgx:n,rgx:s}=this.#u(e);(n?this.#f(s):[i]).forEach(c=>{let a=c;if(this.#e.dispatchEvent(new D(I.off,[a,r])),r){let l=this.#t.get(a);l&&(l.delete(r),l.size===0&&this.#t.delete(a));return}this.#t.delete(a)})}emit(e,r){te("emit",{event:e,data:r}),this.#r&&this.#r(e,r,this),this.#l({event:e,fn:"emit",data:r,listener:null,context:this});let{eventName:i,isRgx:n,rgx:s}=this.#u(e);if(!n){let c=this.#t.get(i),a=this.#m(i);c&&c.forEach(l=>l.apply(this,[r,{event:e,listener:l}])),a&&a.forEach(({func:l})=>l.apply(this,[{data:r,event:e,listener:l}])),this.#e.dispatchEvent(new D(I.emit,[i,r]));return}let o=this.#p(s);o&&o.forEach(({event:c,func:a})=>a.apply(this,[r,{event:c,listener:a}])),this.#f(s).forEach(c=>{this.#e.dispatchEvent(new D(I.emit,[c,r]))})}clear(){this.#t.clear(),this.#n.clear(),this.#e.dispatchEvent(new D(I.clear,["clear",null]))}queue(e,r,i){return new X({...i,event:e,process:r,observer:this})}};var ni=new q({name:"noorm",spy:process.env.NOORM_DEBUG?t=>console.error(`[noorm:${t.fn}] ${String(t.event)}`):void 0});export{v as a,J as b,O as c,S as d,M as e,Tr as f,It as g,ps as h,ni as i};
|
package/dist/chunk-ERDQ5FIO.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{A as te,B as ct,C as ut,D as Ve,E as lt,H as u,I as mt,J as z,L as ft,M as Nt,N as wt,O as yt,P as vt,Q as xt,R as gt,S as T,T as pe,U as Ct,V as f,a as et,b as ze,c as tt,d as Be,e as it,f as rt,g as st,i as Q,j as O,k as i,l as m,m as p,n as w,o as nt,p as ot,q as d,r as at,s as ht,t as C,u as ae,v as pt,w as dt,x as R,y as he,z as P}from"./chunk-QI5B3GSQ.js";var o=i({is(t){return t.kind==="AlterTableNode"},create(t){return i({kind:"AlterTableNode",table:t})},cloneWithTableProps(t,e){return i({...t,...e})},cloneWithColumnAlteration(t,e){return i({...t,columnAlterations:t.columnAlterations?[...t.columnAlterations,e]:[e]})}});var y=i({is(t){return t.kind==="CreateIndexNode"},create(t){return i({kind:"CreateIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var de=i({is(t){return t.kind==="CreateSchemaNode"},create(t,e){return i({kind:"CreateSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var bt=["preserve rows","delete rows","drop"],l=i({is(t){return t.kind==="CreateTableNode"},create(t){return i({kind:"CreateTableNode",table:t,columns:i([])})},cloneWithColumn(t,e){return i({...t,columns:i([...t.columns,e])})},cloneWithConstraint(t,e){return i({...t,constraints:t.constraints?i([...t.constraints,e]):i([e])})},cloneWithFrontModifier(t,e){return i({...t,frontModifiers:t.frontModifiers?i([...t.frontModifiers,e]):i([e])})},cloneWithEndModifier(t,e){return i({...t,endModifiers:t.endModifiers?i([...t.endModifiers,e]):i([e])})},cloneWith(t,e){return i({...t,...e})}});var E=i({is(t){return t.kind==="DropIndexNode"},create(t,e){return i({kind:"DropIndexNode",name:w.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var ie=i({is(t){return t.kind==="DropSchemaNode"},create(t,e){return i({kind:"DropSchemaNode",schema:p.create(t),...e})},cloneWith(t,e){return i({...t,...e})}});var re=i({is(t){return t.kind==="DropTableNode"},create(t,e){return i({kind:"DropTableNode",table:t,...e})},cloneWith(t,e){return i({...t,...e})}});var Fe=i({is(t){return t.kind==="AddColumnNode"},create(t){return i({kind:"AddColumnNode",column:t})}});var a=i({is(t){return t.kind==="ColumnDefinitionNode"},create(t,e){return i({kind:"ColumnDefinitionNode",column:d.create(t),dataType:e})},cloneWithFrontModifier(t,e){return i({...t,frontModifiers:t.frontModifiers?i([...t.frontModifiers,e]):[e]})},cloneWithEndModifier(t,e){return i({...t,endModifiers:t.endModifiers?i([...t.endModifiers,e]):[e]})},cloneWith(t,e){return i({...t,...e})}});var Ue=i({is(t){return t.kind==="DropColumnNode"},create(t){return i({kind:"DropColumnNode",column:d.create(t)})}});var $e=i({is(t){return t.kind==="RenameColumnNode"},create(t,e){return i({kind:"RenameColumnNode",column:d.create(t),renameTo:d.create(e)})}});var B=i({is(t){return t.kind==="CheckConstraintNode"},create(t,e){return i({kind:"CheckConstraintNode",expression:t,name:e?p.create(e):void 0})}});var It=["no action","restrict","cascade","set null","set default"],V=i({is(t){return t.kind==="ReferencesNode"},create(t,e){return i({kind:"ReferencesNode",table:t,columns:i([...e])})},cloneWithOnDelete(t,e){return i({...t,onDelete:e})},cloneWithOnUpdate(t,e){return i({...t,onUpdate:e})}});function ce(t){return nt(t)?t.toOperationNode():P.createImmediate(t)}var se=i({is(t){return t.kind==="GeneratedNode"},create(t){return i({kind:"GeneratedNode",...t})},createWithExpression(t){return i({kind:"GeneratedNode",always:!0,expression:t})},cloneWith(t,e){return i({...t,...e})}});var Ot=i({is(t){return t.kind==="DefaultValueNode"},create(t){return i({kind:"DefaultValueNode",defaultValue:t})}});function F(t){if(It.includes(t))return t;throw new Error(`invalid OnModifyForeignAction ${t}`)}var D=class t{#e;constructor(e){this.#e=e}autoIncrement(){return new t(a.cloneWith(this.#e,{autoIncrement:!0}))}identity(){return new t(a.cloneWith(this.#e,{identity:!0}))}primaryKey(){return new t(a.cloneWith(this.#e,{primaryKey:!0}))}references(e){let r=pt(e);if(!r.table||at.is(r.column))throw new Error(`invalid call references('${e}'). The reference must have format table.column or schema.table.column`);return new t(a.cloneWith(this.#e,{references:V.create(r.table,[r.column])}))}onDelete(e){if(!this.#e.references)throw new Error("on delete constraint can only be added for foreign keys");return new t(a.cloneWith(this.#e,{references:V.cloneWithOnDelete(this.#e.references,F(e))}))}onUpdate(e){if(!this.#e.references)throw new Error("on update constraint can only be added for foreign keys");return new t(a.cloneWith(this.#e,{references:V.cloneWithOnUpdate(this.#e.references,F(e))}))}unique(){return new t(a.cloneWith(this.#e,{unique:!0}))}notNull(){return new t(a.cloneWith(this.#e,{notNull:!0}))}unsigned(){return new t(a.cloneWith(this.#e,{unsigned:!0}))}defaultTo(e){return new t(a.cloneWith(this.#e,{defaultTo:Ot.create(ce(e))}))}check(e){return new t(a.cloneWith(this.#e,{check:B.create(e.toOperationNode())}))}generatedAlwaysAs(e){return new t(a.cloneWith(this.#e,{generated:se.createWithExpression(e.toOperationNode())}))}generatedAlwaysAsIdentity(){return new t(a.cloneWith(this.#e,{generated:se.create({identity:!0,always:!0})}))}generatedByDefaultAsIdentity(){return new t(a.cloneWith(this.#e,{generated:se.create({identity:!0,byDefault:!0})}))}stored(){if(!this.#e.generated)throw new Error("stored() can only be called after generatedAlwaysAs");return new t(a.cloneWith(this.#e,{generated:se.cloneWith(this.#e.generated,{stored:!0})}))}modifyFront(e){return new t(a.cloneWithFrontModifier(this.#e,e.toOperationNode()))}nullsNotDistinct(){return new t(a.cloneWith(this.#e,{nullsNotDistinct:!0}))}ifNotExists(){return new t(a.cloneWith(this.#e,{ifNotExists:!0}))}modifyEnd(e){return new t(a.cloneWithEndModifier(this.#e,e.toOperationNode()))}$call(e){return e(this)}toOperationNode(){return this.#e}};var Ke=i({is(t){return t.kind==="ModifyColumnNode"},create(t){return i({kind:"ModifyColumnNode",column:t})}});var v=i({is(t){return t.kind==="ForeignKeyConstraintNode"},create(t,e,r,s){return i({kind:"ForeignKeyConstraintNode",columns:t,references:V.create(e,r),name:s?p.create(s):void 0})},cloneWith(t,e){return i({...t,...e})}});var U=class t{#e;constructor(e){this.#e=e}onDelete(e){return new t(v.cloneWith(this.#e,{onDelete:F(e)}))}onUpdate(e){return new t(v.cloneWith(this.#e,{onUpdate:F(e)}))}deferrable(){return new t(v.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(v.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(v.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(v.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var $=i({is(t){return t.kind==="AddConstraintNode"},create(t){return i({kind:"AddConstraintNode",constraint:t})}});var b=i({is(t){return t.kind==="UniqueConstraintNode"},create(t,e,r){return i({kind:"UniqueConstraintNode",columns:i(t.map(d.create)),name:e?p.create(e):void 0,nullsNotDistinct:r})},cloneWith(t,e){return i({...t,...e})}});var K=i({is(t){return t.kind==="DropConstraintNode"},create(t){return i({kind:"DropConstraintNode",constraintName:p.create(t)})},cloneWith(t,e){return i({...t,...e})}});var J=i({is(t){return t.kind==="AlterColumnNode"},create(t,e,r){return i({kind:"AlterColumnNode",column:d.create(t),[e]:r})}});var ne=class{#e;constructor(e){this.#e=e}setDataType(e){return new A(J.create(this.#e,"dataType",T(e)))}setDefault(e){return new A(J.create(this.#e,"setDefault",ce(e)))}dropDefault(){return new A(J.create(this.#e,"dropDefault",!0))}setNotNull(){return new A(J.create(this.#e,"setNotNull",!0))}dropNotNull(){return new A(J.create(this.#e,"dropNotNull",!0))}$call(e){return e(this)}},A=class{#e;constructor(e){this.#e=e}toOperationNode(){return this.#e}};var W=class{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var ue=class t{#e;constructor(e){this.#e=i(e)}onDelete(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onDelete(e)})}onUpdate(e){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.onUpdate(e)})}deferrable(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.deferrable()})}notDeferrable(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.notDeferrable()})}initiallyDeferred(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyDeferred()})}initiallyImmediate(){return new t({...this.#e,constraintBuilder:this.#e.constraintBuilder.initiallyImmediate()})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(o.cloneWithTableProps(this.#e.node,{addConstraint:$.create(this.#e.constraintBuilder.toOperationNode())}),this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var oe=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{dropConstraint:K.cloneWith(this.#e.node.dropConstraint,{ifExists:!0})})})}cascade(){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{dropConstraint:K.cloneWith(this.#e.node.dropConstraint,{modifier:"cascade"})})})}restrict(){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{dropConstraint:K.cloneWith(this.#e.node.dropConstraint,{modifier:"restrict"})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var S=i({is(t){return t.kind==="PrimaryKeyConstraintNode"},create(t,e){return i({kind:"PrimaryKeyConstraintNode",columns:i(t.map(d.create)),name:e?p.create(e):void 0})},cloneWith(t,e){return i({...t,...e})}});var k=i({is(t){return t.kind==="AddIndexNode"},create(t){return i({kind:"AddIndexNode",name:p.create(t)})},cloneWith(t,e){return i({...t,...e})},cloneWithColumns(t,e){return i({...t,columns:[...t.columns||[],...e]})}});var le=class t{#e;constructor(e){this.#e=i(e)}unique(){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.cloneWith(this.#e.node.addIndex,{unique:!0})})})}column(e){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.cloneWithColumns(this.#e.node.addIndex,[R(e)])})})}columns(e){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.cloneWithColumns(this.#e.node.addIndex,e.map(R))})})}expression(e){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.cloneWithColumns(this.#e.node.addIndex,[e.toOperationNode()])})})}using(e){return new t({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.cloneWith(this.#e.node.addIndex,{using:C.createWithSql(e)})})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var G=class t{#e;constructor(e){this.#e=e}nullsNotDistinct(){return new t(b.cloneWith(this.#e,{nullsNotDistinct:!0}))}deferrable(){return new t(b.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(b.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(b.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(b.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var j=class t{#e;constructor(e){this.#e=e}deferrable(){return new t(S.cloneWith(this.#e,{deferrable:!0}))}notDeferrable(){return new t(S.cloneWith(this.#e,{deferrable:!1}))}initiallyDeferred(){return new t(S.cloneWith(this.#e,{initiallyDeferred:!0}))}initiallyImmediate(){return new t(S.cloneWith(this.#e,{initiallyDeferred:!1}))}$call(e){return e(this)}toOperationNode(){return this.#e}};var H=class{#e;constructor(e){this.#e=e}$call(e){return e(this)}toOperationNode(){return this.#e}};var Tt=i({is(t){return t.kind==="RenameConstraintNode"},create(t,e){return i({kind:"RenameConstraintNode",oldName:p.create(t),newName:p.create(e)})}});var me=class{#e;constructor(e){this.#e=i(e)}renameTo(e){return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{renameTo:f(e)})})}setSchema(e){return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{setSchema:p.create(e)})})}alterColumn(e,r){let s=r(new ne(e));return new L({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,s.toOperationNode())})}dropColumn(e){return new L({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Ue.create(e))})}renameColumn(e,r){return new L({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,$e.create(e,r))})}addColumn(e,r,s=m){let n=s(new D(a.create(e,T(r))));return new L({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Fe.create(n.toOperationNode()))})}modifyColumn(e,r,s=m){let n=s(new D(a.create(e,T(r))));return new L({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Ke.create(n.toOperationNode()))})}addUniqueConstraint(e,r,s=m){let n=s(new G(b.create(r,e)));return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addConstraint:$.create(n.toOperationNode())})})}addCheckConstraint(e,r,s=m){let n=s(new H(B.create(r.toOperationNode(),e)));return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addConstraint:$.create(n.toOperationNode())})})}addForeignKeyConstraint(e,r,s,n,h=m){let c=h(new U(v.create(r.map(d.create),f(s),n.map(d.create),e)));return new ue({...this.#e,constraintBuilder:c})}addPrimaryKeyConstraint(e,r,s=m){let n=s(new j(S.create(r,e)));return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addConstraint:$.create(n.toOperationNode())})})}dropConstraint(e){return new oe({...this.#e,node:o.cloneWithTableProps(this.#e.node,{dropConstraint:K.create(e)})})}renameConstraint(e,r){return new oe({...this.#e,node:o.cloneWithTableProps(this.#e.node,{renameConstraint:Tt.create(e,r)})})}addIndex(e){return new le({...this.#e,node:o.cloneWithTableProps(this.#e.node,{addIndex:k.create(e)})})}dropIndex(e){return new W({...this.#e,node:o.cloneWithTableProps(this.#e.node,{dropIndex:E.create(e)})})}$call(e){return e(this)}},L=class t{#e;constructor(e){this.#e=i(e)}alterColumn(e,r){let s=r(new ne(e));return new t({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,s.toOperationNode())})}dropColumn(e){return new t({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Ue.create(e))})}renameColumn(e,r){return new t({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,$e.create(e,r))})}addColumn(e,r,s=m){let n=s(new D(a.create(e,T(r))));return new t({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Fe.create(n.toOperationNode()))})}modifyColumn(e,r,s=m){let n=s(new D(a.create(e,T(r))));return new t({...this.#e,node:o.cloneWithColumnAlteration(this.#e.node,Ke.create(n.toOperationNode()))})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Y=class extends mt{transformPrimitiveValueList(e){return he.create(e.values.map(P.createImmediate))}transformValue(e){return P.createImmediate(e.value)}};var fe=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:y.cloneWith(this.#e.node,{ifNotExists:!0})})}unique(){return new t({...this.#e,node:y.cloneWith(this.#e.node,{unique:!0})})}nullsNotDistinct(){return new t({...this.#e,node:y.cloneWith(this.#e.node,{nullsNotDistinct:!0})})}on(e){return new t({...this.#e,node:y.cloneWith(this.#e.node,{table:f(e)})})}column(e){return new t({...this.#e,node:y.cloneWithColumns(this.#e.node,[R(e)])})}columns(e){return new t({...this.#e,node:y.cloneWithColumns(this.#e.node,e.map(R))})}expression(e){return new t({...this.#e,node:y.cloneWithColumns(this.#e.node,[e.toOperationNode()])})}using(e){return new t({...this.#e,node:y.cloneWith(this.#e.node,{using:C.createWithSql(e)})})}where(...e){let r=new Y;return new t({...this.#e,node:lt.cloneWithWhere(this.#e.node,r.transformNode(ct(e),this.#e.queryId))})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Ne=class t{#e;constructor(e){this.#e=i(e)}ifNotExists(){return new t({...this.#e,node:de.cloneWith(this.#e.node,{ifNotExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};function Dt(t){if(bt.includes(t))return t;throw new Error(`invalid OnCommitAction ${t}`)}var we=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:l.cloneWith(this.#e.node,{temporary:!0})})}onCommit(e){return new t({...this.#e,node:l.cloneWith(this.#e.node,{onCommit:Dt(e)})})}ifNotExists(){return new t({...this.#e,node:l.cloneWith(this.#e.node,{ifNotExists:!0})})}addColumn(e,r,s=m){let n=s(new D(a.create(e,T(r))));return new t({...this.#e,node:l.cloneWithColumn(this.#e.node,n.toOperationNode())})}addPrimaryKeyConstraint(e,r,s=m){let n=s(new j(S.create(r,e)));return new t({...this.#e,node:l.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addUniqueConstraint(e,r,s=m){let n=s(new G(b.create(r,e)));return new t({...this.#e,node:l.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addCheckConstraint(e,r,s=m){let n=s(new H(B.create(r.toOperationNode(),e)));return new t({...this.#e,node:l.cloneWithConstraint(this.#e.node,n.toOperationNode())})}addForeignKeyConstraint(e,r,s,n,h=m){let c=h(new U(v.create(r.map(d.create),f(s),n.map(d.create),e)));return new t({...this.#e,node:l.cloneWithConstraint(this.#e.node,c.toOperationNode())})}modifyFront(e){return new t({...this.#e,node:l.cloneWithFrontModifier(this.#e.node,e.toOperationNode())})}modifyEnd(e){return new t({...this.#e,node:l.cloneWithEndModifier(this.#e.node,e.toOperationNode())})}as(e){return new t({...this.#e,node:l.cloneWith(this.#e.node,{selectQuery:pe(e)})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var ye=class t{#e;constructor(e){this.#e=i(e)}on(e){return new t({...this.#e,node:E.cloneWith(this.#e.node,{table:f(e)})})}ifExists(){return new t({...this.#e,node:E.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:E.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var ve=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:ie.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:ie.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var xe=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:re.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var x=i({is(t){return t.kind==="CreateViewNode"},create(t){return i({kind:"CreateViewNode",name:w.create(t)})},cloneWith(t,e){return i({...t,...e})}});var ge=class{#e=new Y;transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}transformResult(e){return Promise.resolve(e.result)}};var Ce=class t{#e;constructor(e){this.#e=i(e)}temporary(){return new t({...this.#e,node:x.cloneWith(this.#e.node,{temporary:!0})})}materialized(){return new t({...this.#e,node:x.cloneWith(this.#e.node,{materialized:!0})})}ifNotExists(){return new t({...this.#e,node:x.cloneWith(this.#e.node,{ifNotExists:!0})})}orReplace(){return new t({...this.#e,node:x.cloneWith(this.#e.node,{orReplace:!0})})}columns(e){return new t({...this.#e,node:x.cloneWith(this.#e.node,{columns:e.map(dt)})})}as(e){let r=e.withPlugin(new ge).toOperationNode();return new t({...this.#e,node:x.cloneWith(this.#e.node,{as:r})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var X=i({is(t){return t.kind==="DropViewNode"},create(t){return i({kind:"DropViewNode",name:w.create(t)})},cloneWith(t,e){return i({...t,...e})}});var be=class t{#e;constructor(e){this.#e=i(e)}materialized(){return new t({...this.#e,node:X.cloneWith(this.#e.node,{materialized:!0})})}ifExists(){return new t({...this.#e,node:X.cloneWith(this.#e.node,{ifExists:!0})})}cascade(){return new t({...this.#e,node:X.cloneWith(this.#e.node,{cascade:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Ie=i({is(t){return t.kind==="CreateTypeNode"},create(t){return i({kind:"CreateTypeNode",name:t})},cloneWithEnum(t,e){return i({...t,enum:he.create(e.map(P.createImmediate))})}});var Oe=class t{#e;constructor(e){this.#e=i(e)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}asEnum(e){return new t({...this.#e,node:Ie.cloneWithEnum(this.#e.node,e)})}$call(e){return e(this)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Te=i({is(t){return t.kind==="DropTypeNode"},create(t){return i({kind:"DropTypeNode",name:t})},cloneWith(t,e){return i({...t,...e})}});var De=class t{#e;constructor(e){this.#e=i(e)}ifExists(){return new t({...this.#e,node:Te.cloneWith(this.#e.node,{ifExists:!0})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};function Je(t){if(t.includes(".")){let r=t.split(".").map(Pt);if(r.length===2)return w.createWithSchema(r[0],r[1]);throw new Error(`invalid schemable identifier ${t}`)}else return w.create(t)}function Pt(t){return t.trim()}var Z=i({is(t){return t.kind==="RefreshMaterializedViewNode"},create(t){return i({kind:"RefreshMaterializedViewNode",name:w.create(t)})},cloneWith(t,e){return i({...t,...e})}});var We=class t{#e;constructor(e){this.#e=i(e)}concurrently(){return new t({...this.#e,node:Z.cloneWith(this.#e.node,{concurrently:!0,withNoData:!1})})}withData(){return new t({...this.#e,node:Z.cloneWith(this.#e.node,{withNoData:!1})})}withNoData(){return new t({...this.#e,node:Z.cloneWith(this.#e.node,{withNoData:!0,concurrently:!1})})}$call(e){return e(this)}toOperationNode(){return this.#e.executor.transformQuery(this.#e.node,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){await this.#e.executor.executeQuery(this.compile())}};var Se=class t{#e;constructor(e){this.#e=e}createTable(e){return new we({queryId:u(),executor:this.#e,node:l.create(f(e))})}dropTable(e){return new xe({queryId:u(),executor:this.#e,node:re.create(f(e))})}createIndex(e){return new fe({queryId:u(),executor:this.#e,node:y.create(e)})}dropIndex(e){return new ye({queryId:u(),executor:this.#e,node:E.create(e)})}createSchema(e){return new Ne({queryId:u(),executor:this.#e,node:de.create(e)})}dropSchema(e){return new ve({queryId:u(),executor:this.#e,node:ie.create(e)})}alterTable(e){return new me({queryId:u(),executor:this.#e,node:o.create(f(e))})}createView(e){return new Ce({queryId:u(),executor:this.#e,node:x.create(e)})}refreshMaterializedView(e){return new We({queryId:u(),executor:this.#e,node:Z.create(e)})}dropView(e){return new be({queryId:u(),executor:this.#e,node:X.create(e)})}createType(e){return new Oe({queryId:u(),executor:this.#e,node:Ie.create(Je(e))})}dropType(e){return new De({queryId:u(),executor:this.#e,node:Te.create(Je(e))})}withPlugin(e){return new t(this.#e.withPlugin(e))}withoutPlugins(){return new t(this.#e.withoutPlugins())}withSchema(e){return new t(this.#e.withPluginAtFront(new z(e)))}};var Ee=class{ref(e){return new ht(e)}table(e){return new Ct(e)}};var ke=class{#e;constructor(e){this.#e=e}async provideConnection(e){let r=await this.#e.acquireConnection();try{return await e(r)}finally{await this.#e.releaseConnection(r)}}};var Pe=class t extends Nt{#e;#t;#i;constructor(e,r,s,n=[]){super(n),this.#e=e,this.#t=r,this.#i=s}get adapter(){return this.#t}compileQuery(e,r){return this.#e.compileQuery(e,r)}provideConnection(e){return this.#i.provideConnection(e)}withPlugins(e){return new t(this.#e,this.#t,this.#i,[...this.plugins,...e])}withPlugin(e){return new t(this.#e,this.#t,this.#i,[...this.plugins,e])}withPluginAtFront(e){return new t(this.#e,this.#t,this.#i,[e,...this.plugins])}withConnectionProvider(e){return new t(this.#e,this.#t,e,[...this.plugins])}withoutPlugins(){return new t(this.#e,this.#t,this.#i,[])}};function Ae(){return typeof performance<"u"&&Q(performance.now)?performance.now():Date.now()}var Le=class{#e;#t;#i;#s;#r;#n=new WeakSet;constructor(e,r){this.#s=!1,this.#e=e,this.#t=r}async init(){if(this.#r)throw new Error("driver has already been destroyed");this.#i||(this.#i=this.#e.init().then(()=>{this.#s=!0}).catch(e=>(this.#i=void 0,Promise.reject(e)))),await this.#i}async acquireConnection(){if(this.#r)throw new Error("driver has already been destroyed");this.#s||await this.init();let e=await this.#e.acquireConnection();return this.#n.has(e)||(this.#p()&&this.#d(e),this.#n.add(e)),e}async releaseConnection(e){await this.#e.releaseConnection(e)}beginTransaction(e,r){return this.#e.beginTransaction(e,r)}commitTransaction(e){return this.#e.commitTransaction(e)}rollbackTransaction(e){return this.#e.rollbackTransaction(e)}savepoint(e,r,s){if(this.#e.savepoint)return this.#e.savepoint(e,r,s);throw new Error("The `savepoint` method is not supported by this driver")}rollbackToSavepoint(e,r,s){if(this.#e.rollbackToSavepoint)return this.#e.rollbackToSavepoint(e,r,s);throw new Error("The `rollbackToSavepoint` method is not supported by this driver")}releaseSavepoint(e,r,s){if(this.#e.releaseSavepoint)return this.#e.releaseSavepoint(e,r,s);throw new Error("The `releaseSavepoint` method is not supported by this driver")}async destroy(){this.#i&&(await this.#i,this.#r||(this.#r=this.#e.destroy().catch(e=>(this.#r=void 0,Promise.reject(e)))),await this.#r)}#p(){return this.#t.isLevelEnabled("query")||this.#t.isLevelEnabled("error")}#d(e){let r=e.executeQuery,s=e.streamQuery,n=this;e.executeQuery=async h=>{let c,I=Ae();try{return await r.call(e,h)}catch(g){throw c=g,await n.#o(g,h,I),g}finally{c||await n.#a(h,I)}},e.streamQuery=async function*(h,c){let I,g=Ae();try{for await(let N of s.call(e,h,c))yield N}catch(N){throw I=N,await n.#o(N,h,g),N}finally{I||await n.#a(h,g,!0)}}}async#o(e,r,s){await this.#t.error(()=>({level:"error",error:e,query:r,queryDurationMillis:this.#h(s)}))}async#a(e,r,s=!1){await this.#t.query(()=>({level:"query",isStream:s,query:e,queryDurationMillis:this.#h(r)}))}#h(e){return Ae()-e}};var At=()=>{},_=class{#e;#t;constructor(e){this.#e=e}async provideConnection(e){for(;this.#t;)await this.#t.catch(At);return this.#t=this.#i(e).finally(()=>{this.#t=void 0}),this.#t}async#i(e){return await e(this.#e)}};var Lt=["read only","read write"],Mt=["read uncommitted","read committed","repeatable read","serializable","snapshot"];function Ge(t){if(t.accessMode&&!Lt.includes(t.accessMode))throw new Error(`invalid transaction access mode ${t.accessMode}`);if(t.isolationLevel&&!Mt.includes(t.isolationLevel))throw new Error(`invalid transaction isolation level ${t.isolationLevel}`)}var qt=["query","error"],Ro=i(qt),Me=class{#e;#t;constructor(e){Q(e)?(this.#t=e,this.#e=i({query:!0,error:!0})):(this.#t=Qt,this.#e=i({query:e.includes("query"),error:e.includes("error")}))}isLevelEnabled(e){return this.#e[e]}async query(e){this.#e.query&&await this.#t(e())}async error(e){this.#e.error&&await this.#t(e())}};function Qt(t){if(t.level==="query"){let e=`kysely:query:${t.isStream?"stream:":""}`;console.log(`${e} ${t.query.sql}`),console.log(`${e} duration: ${t.queryDurationMillis.toFixed(1)}ms`)}else t.level==="error"&&(t.error instanceof Error?console.error(`kysely:error: ${t.error.stack??t.error.message}`):console.error(`kysely:error: ${JSON.stringify({error:t.error,query:t.query.sql,queryDurationMillis:t.queryDurationMillis})}`))}function Wt(t){return O(t)&&Q(t.compile)}Symbol.asyncDispose??=Symbol("Symbol.asyncDispose");var qe=class t extends wt{#e;constructor(e){let r,s;if(Rt(e))r={executor:e.executor},s={...e};else{let n=e.dialect,h=n.createDriver(),c=n.createQueryCompiler(),I=n.createAdapter(),g=new Me(e.log??[]),N=new Le(h,g),ee=new ke(N),_e=new Pe(c,I,ee,e.plugins??[]);r={executor:_e},s={config:e,executor:_e,dialect:n,driver:N}}super(r),this.#e=i(s)}get schema(){return new Se(this.#e.executor)}get dynamic(){return new Ee}get introspection(){return this.#e.dialect.createIntrospector(this.withoutPlugins())}case(e){return new gt({node:xt.create(et(e)?void 0:pe(e))})}get fn(){return vt()}transaction(){return new He({...this.#e})}startTransaction(){return new Ye({...this.#e})}connection(){return new je({...this.#e})}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new z(e))})}withTables(){return new t({...this.#e})}async destroy(){await this.#e.driver.destroy()}get isTransaction(){return!1}getExecutor(){return this.#e.executor}executeQuery(e,r){r!==void 0&&ae("Passing `queryId` in `db.executeQuery` is deprecated and will result in a compile-time error in the future.");let s=Wt(e)?e.compile():e;return this.getExecutor().executeQuery(s)}async[Symbol.asyncDispose](){await this.destroy()}},Qe=class t extends qe{#e;constructor(e){super(e),this.#e=e}get isTransaction(){return!0}transaction(){throw new Error("calling the transaction method for a Transaction is not supported")}connection(){throw new Error("calling the connection method for a Transaction is not supported")}async destroy(){throw new Error("calling the destroy method for a Transaction is not supported")}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new z(e))})}withTables(){return new t({...this.#e})}};function Rt(t){return O(t)&&O(t.config)&&O(t.driver)&&O(t.executor)&&O(t.dialect)}var je=class{#e;constructor(e){this.#e=i(e)}async execute(e){return this.#e.executor.provideConnection(async r=>{let s=this.#e.executor.withConnectionProvider(new _(r)),n=new qe({...this.#e,executor:s});return await e(n)})}},He=class t{#e;constructor(e){this.#e=i(e)}setAccessMode(e){return new t({...this.#e,accessMode:e})}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(e){let{isolationLevel:r,accessMode:s,...n}=this.#e,h={isolationLevel:r,accessMode:s};return Ge(h),this.#e.executor.provideConnection(async c=>{let I=this.#e.executor.withConnectionProvider(new _(c)),g=new Qe({...n,executor:I}),N=!1;try{await this.#e.driver.beginTransaction(c,h),N=!0;let ee=await e(g);return await this.#e.driver.commitTransaction(c),ee}catch(ee){throw N&&await this.#e.driver.rollbackTransaction(c),ee}})}},Ye=class t{#e;constructor(e){this.#e=i(e)}setAccessMode(e){return new t({...this.#e,accessMode:e})}setIsolationLevel(e){return new t({...this.#e,isolationLevel:e})}async execute(){let{isolationLevel:e,accessMode:r,...s}=this.#e,n={isolationLevel:e,accessMode:r};Ge(n);let h=await ft(this.#e.executor);return await this.#e.driver.beginTransaction(h.connection,n),new Xe({...s,connection:h,executor:this.#e.executor.withConnectionProvider(new _(h.connection))})}},Xe=class t extends Qe{#e;#t;#i;constructor(e){let r={isCommitted:!1,isRolledBack:!1};e={...e,executor:new Ze(e.executor,r)};let{connection:s,...n}=e;super(n),this.#e=i(e),this.#i=r;let h=u();this.#t=c=>e.executor.compileQuery(c,h)}get isCommitted(){return this.#i.isCommitted}get isRolledBack(){return this.#i.isRolledBack}commit(){return q(this.#i),new M(async()=>{await this.#e.driver.commitTransaction(this.#e.connection.connection),this.#i.isCommitted=!0,this.#e.connection.release()})}rollback(){return q(this.#i),new M(async()=>{await this.#e.driver.rollbackTransaction(this.#e.connection.connection),this.#i.isRolledBack=!0,this.#e.connection.release()})}savepoint(e){return q(this.#i),new M(async()=>(await this.#e.driver.savepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}rollbackToSavepoint(e){return q(this.#i),new M(async()=>(await this.#e.driver.rollbackToSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}releaseSavepoint(e){return q(this.#i),new M(async()=>(await this.#e.driver.releaseSavepoint?.(this.#e.connection.connection,e,this.#t),new t({...this.#e})))}withPlugin(e){return new t({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new t({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new t({...this.#e,executor:this.#e.executor.withPluginAtFront(new z(e))})}withTables(){return new t({...this.#e})}},M=class{#e;constructor(e){this.#e=e}async execute(){return await this.#e()}};function q(t){if(t.isCommitted)throw new Error("Transaction is already committed");if(t.isRolledBack)throw new Error("Transaction is already rolled back")}var Ze=class t{#e;#t;constructor(e,r){e instanceof t?this.#e=e.#e:this.#e=e,this.#t=r}get adapter(){return this.#e.adapter}get plugins(){return this.#e.plugins}transformQuery(e,r){return this.#e.transformQuery(e,r)}compileQuery(e,r){return this.#e.compileQuery(e,r)}provideConnection(e){return this.#e.provideConnection(e)}executeQuery(e){return q(this.#t),this.#e.executeQuery(e)}stream(e,r){return q(this.#t),this.#e.stream(e,r)}withConnectionProvider(e){return new t(this.#e.withConnectionProvider(e),this.#t)}withPlugin(e){return new t(this.#e.withPlugin(e),this.#t)}withPlugins(e){return new t(this.#e.withPlugins(e),this.#t)}withPluginAtFront(e){return new t(this.#e.withPluginAtFront(e),this.#t)}withoutPlugins(){return new t(this.#e.withoutPlugins(),this.#t)}};var Re=class{nodeStack=[];get parentNode(){return this.nodeStack[this.nodeStack.length-2]}#e=i({AliasNode:this.visitAlias.bind(this),ColumnNode:this.visitColumn.bind(this),IdentifierNode:this.visitIdentifier.bind(this),SchemableIdentifierNode:this.visitSchemableIdentifier.bind(this),RawNode:this.visitRaw.bind(this),ReferenceNode:this.visitReference.bind(this),SelectQueryNode:this.visitSelectQuery.bind(this),SelectionNode:this.visitSelection.bind(this),TableNode:this.visitTable.bind(this),FromNode:this.visitFrom.bind(this),SelectAllNode:this.visitSelectAll.bind(this),AndNode:this.visitAnd.bind(this),OrNode:this.visitOr.bind(this),ValueNode:this.visitValue.bind(this),ValueListNode:this.visitValueList.bind(this),PrimitiveValueListNode:this.visitPrimitiveValueList.bind(this),ParensNode:this.visitParens.bind(this),JoinNode:this.visitJoin.bind(this),OperatorNode:this.visitOperator.bind(this),WhereNode:this.visitWhere.bind(this),InsertQueryNode:this.visitInsertQuery.bind(this),DeleteQueryNode:this.visitDeleteQuery.bind(this),ReturningNode:this.visitReturning.bind(this),CreateTableNode:this.visitCreateTable.bind(this),AddColumnNode:this.visitAddColumn.bind(this),ColumnDefinitionNode:this.visitColumnDefinition.bind(this),DropTableNode:this.visitDropTable.bind(this),DataTypeNode:this.visitDataType.bind(this),OrderByNode:this.visitOrderBy.bind(this),OrderByItemNode:this.visitOrderByItem.bind(this),GroupByNode:this.visitGroupBy.bind(this),GroupByItemNode:this.visitGroupByItem.bind(this),UpdateQueryNode:this.visitUpdateQuery.bind(this),ColumnUpdateNode:this.visitColumnUpdate.bind(this),LimitNode:this.visitLimit.bind(this),OffsetNode:this.visitOffset.bind(this),OnConflictNode:this.visitOnConflict.bind(this),OnDuplicateKeyNode:this.visitOnDuplicateKey.bind(this),CreateIndexNode:this.visitCreateIndex.bind(this),DropIndexNode:this.visitDropIndex.bind(this),ListNode:this.visitList.bind(this),PrimaryKeyConstraintNode:this.visitPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.visitUniqueConstraint.bind(this),ReferencesNode:this.visitReferences.bind(this),CheckConstraintNode:this.visitCheckConstraint.bind(this),WithNode:this.visitWith.bind(this),CommonTableExpressionNode:this.visitCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.visitCommonTableExpressionName.bind(this),HavingNode:this.visitHaving.bind(this),CreateSchemaNode:this.visitCreateSchema.bind(this),DropSchemaNode:this.visitDropSchema.bind(this),AlterTableNode:this.visitAlterTable.bind(this),DropColumnNode:this.visitDropColumn.bind(this),RenameColumnNode:this.visitRenameColumn.bind(this),AlterColumnNode:this.visitAlterColumn.bind(this),ModifyColumnNode:this.visitModifyColumn.bind(this),AddConstraintNode:this.visitAddConstraint.bind(this),DropConstraintNode:this.visitDropConstraint.bind(this),RenameConstraintNode:this.visitRenameConstraint.bind(this),ForeignKeyConstraintNode:this.visitForeignKeyConstraint.bind(this),CreateViewNode:this.visitCreateView.bind(this),RefreshMaterializedViewNode:this.visitRefreshMaterializedView.bind(this),DropViewNode:this.visitDropView.bind(this),GeneratedNode:this.visitGenerated.bind(this),DefaultValueNode:this.visitDefaultValue.bind(this),OnNode:this.visitOn.bind(this),ValuesNode:this.visitValues.bind(this),SelectModifierNode:this.visitSelectModifier.bind(this),CreateTypeNode:this.visitCreateType.bind(this),DropTypeNode:this.visitDropType.bind(this),ExplainNode:this.visitExplain.bind(this),DefaultInsertValueNode:this.visitDefaultInsertValue.bind(this),AggregateFunctionNode:this.visitAggregateFunction.bind(this),OverNode:this.visitOver.bind(this),PartitionByNode:this.visitPartitionBy.bind(this),PartitionByItemNode:this.visitPartitionByItem.bind(this),SetOperationNode:this.visitSetOperation.bind(this),BinaryOperationNode:this.visitBinaryOperation.bind(this),UnaryOperationNode:this.visitUnaryOperation.bind(this),UsingNode:this.visitUsing.bind(this),FunctionNode:this.visitFunction.bind(this),CaseNode:this.visitCase.bind(this),WhenNode:this.visitWhen.bind(this),JSONReferenceNode:this.visitJSONReference.bind(this),JSONPathNode:this.visitJSONPath.bind(this),JSONPathLegNode:this.visitJSONPathLeg.bind(this),JSONOperatorChainNode:this.visitJSONOperatorChain.bind(this),TupleNode:this.visitTuple.bind(this),MergeQueryNode:this.visitMergeQuery.bind(this),MatchedNode:this.visitMatched.bind(this),AddIndexNode:this.visitAddIndex.bind(this),CastNode:this.visitCast.bind(this),FetchNode:this.visitFetch.bind(this),TopNode:this.visitTop.bind(this),OutputNode:this.visitOutput.bind(this),OrActionNode:this.visitOrAction.bind(this),CollateNode:this.visitCollate.bind(this)});visitNode=e=>{this.nodeStack.push(e),this.#e[e.kind](e),this.nodeStack.pop()}};var zt=/'/g,St=class extends Re{#e="";#t=[];get numParameters(){return this.#t.length}compileQuery(e,r){return this.#e="",this.#t=[],this.nodeStack.splice(0,this.nodeStack.length),this.visitNode(e),i({query:e,queryId:r,sql:this.getSql(),parameters:[...this.#t]})}getSql(){return this.#e}visitSelectQuery(e){let r=this.parentNode!==void 0&&!te.is(this.parentNode)&&!ut.is(this.parentNode)&&!l.is(this.parentNode)&&!x.is(this.parentNode)&&!yt.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&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])," ")),r&&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,r=", "){let s=e.length-1;for(let n=0;n<=s;n++)this.visitNode(e[n]),n<s&&this.append(r)}visitWhere(e){this.append("where "),this.visitNode(e.where)}visitHaving(e){this.append("having "),this.visitNode(e.having)}visitInsertQuery(e){let r=this.parentNode!==void 0&&!te.is(this.parentNode)&&!C.is(this.parentNode)&&!Ve.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append(e.replace?"replace":"insert"),e.ignore&&(ae("`InsertQueryNode.ignore` is deprecated. Use `InsertQueryNode.orAction` instead."),this.append(" ignore")),e.orAction&&(this.append(" "),this.visitNode(e.orAction)),e.top&&(this.append(" "),this.visitNode(e.top)),e.into&&(this.append(" into "),this.visitNode(e.into)),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.output&&(this.append(" "),this.visitNode(e.output)),e.values&&(this.append(" "),this.visitNode(e.values)),e.defaultValues&&(this.append(" "),this.append("default values")),e.onConflict&&(this.append(" "),this.visitNode(e.onConflict)),e.onDuplicateKey&&(this.append(" "),this.visitNode(e.onDuplicateKey)),e.returning&&(this.append(" "),this.visitNode(e.returning)),r&&this.append(")"),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitValues(e){this.append("values "),this.compileList(e.values)}visitDeleteQuery(e){let r=this.parentNode!==void 0&&!te.is(this.parentNode)&&!C.is(this.parentNode);this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&this.append("("),e.with&&(this.visitNode(e.with),this.append(" ")),this.append("delete "),e.top&&(this.visitNode(e.top),this.append(" ")),this.visitNode(e.from),e.output&&(this.append(" "),this.visitNode(e.output)),e.using&&(this.append(" "),this.visitNode(e.using)),e.joins&&(this.append(" "),this.compileList(e.joins," ")),e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),r&&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(!ze(e.name))throw new 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:r}=e;for(let s=0;s<r.length;++s)this.appendValue(r[s]),s!==r.length-1&&this.append(", ");this.append(")")}visitParens(e){this.append("("),this.visitNode(e.node),this.append(")")}visitJoin(e){this.append(Vt[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:r,parameters:s}=e;for(let n=0;n<r.length;++n)this.append(r[n]),s.length>n&&this.visitNode(s[n])}visitOperator(e){this.append(e.operator)}visitTable(e){this.visitNode(e.table)}visitSchemableIdentifier(e){e.schema&&(this.visitNode(e.schema),this.append(".")),this.visitNode(e.identifier)}visitCreateTable(e){this.append("create "),e.frontModifiers&&e.frontModifiers.length>0&&(this.compileList(e.frontModifiers," "),this.append(" ")),e.temporary&&this.append("temporary "),this.append("table "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.table),e.selectQuery?(this.append(" as "),this.visitNode(e.selectQuery)):(this.append(" ("),this.compileList([...e.columns,...e.constraints??[]]),this.append(")"),e.onCommit&&(this.append(" on commit "),this.append(e.onCommit)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," ")))}visitColumnDefinition(e){e.ifNotExists&&this.append("if not exists "),this.visitNode(e.column),this.append(" "),this.visitNode(e.dataType),e.unsigned&&this.append(" unsigned"),e.frontModifiers&&e.frontModifiers.length>0&&(this.append(" "),this.compileList(e.frontModifiers," ")),e.generated&&(this.append(" "),this.visitNode(e.generated)),e.identity&&this.append(" identity"),e.defaultTo&&(this.append(" "),this.visitNode(e.defaultTo)),e.notNull&&this.append(" not null"),e.unique&&this.append(" unique"),e.nullsNotDistinct&&this.append(" nulls not distinct"),e.primaryKey&&this.append(" primary key"),e.autoIncrement&&(this.append(" "),this.append(this.getAutoIncrement())),e.references&&(this.append(" "),this.visitNode(e.references)),e.check&&(this.append(" "),this.visitNode(e.check)),e.endModifiers&&e.endModifiers.length>0&&(this.append(" "),this.compileList(e.endModifiers," "))}getAutoIncrement(){return"auto_increment"}visitReferences(e){this.append("references "),this.visitNode(e.table),this.append(" ("),this.compileList(e.columns),this.append(")"),e.onDelete&&(this.append(" on delete "),this.append(e.onDelete)),e.onUpdate&&(this.append(" on update "),this.append(e.onUpdate))}visitDropTable(e){this.append("drop table "),e.ifExists&&this.append("if exists "),this.visitNode(e.table),e.cascade&&this.append(" cascade")}visitDataType(e){this.append(e.dataType)}visitOrderBy(e){this.append("order by "),this.compileList(e.items)}visitOrderByItem(e){this.visitNode(e.orderBy),e.collation&&(this.append(" "),this.visitNode(e.collation)),e.direction&&(this.append(" "),this.visitNode(e.direction)),e.nulls&&(this.append(" nulls "),this.append(e.nulls))}visitGroupBy(e){this.append("group by "),this.compileList(e.items)}visitGroupByItem(e){this.visitNode(e.groupBy)}visitUpdateQuery(e){let r=this.parentNode!==void 0&&!te.is(this.parentNode)&&!C.is(this.parentNode)&&!Ve.is(this.parentNode);if(this.parentNode===void 0&&e.explain&&(this.visitNode(e.explain),this.append(" ")),r&&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 new Error("Joins in an update query are only supported as a part of a PostgreSQL 'update set from join' query. If you want to create a MySQL 'update join set' query, see https://kysely.dev/docs/examples/update/my-sql-joins");this.append(" "),this.compileList(e.joins," ")}e.where&&(this.append(" "),this.visitNode(e.where)),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),e.limit&&(this.append(" "),this.visitNode(e.limit)),e.returning&&(this.append(" "),this.visitNode(e.returning)),r&&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 "),Be(e.materialized)&&(e.materialized||this.append("not "),this.append("materialized ")),this.visitNode(e.expression)}visitCommonTableExpressionName(e){this.visitNode(e.table),e.columns&&(this.append("("),this.compileList(e.columns),this.append(")"))}visitAlterTable(e){this.append("alter table "),this.visitNode(e.table),this.append(" "),e.renameTo&&(this.append("rename to "),this.visitNode(e.renameTo)),e.setSchema&&(this.append("set schema "),this.visitNode(e.setSchema)),e.addConstraint&&this.visitNode(e.addConstraint),e.dropConstraint&&this.visitNode(e.dropConstraint),e.renameConstraint&&this.visitNode(e.renameConstraint),e.columnAlterations&&this.compileColumnAlterations(e.columnAlterations),e.addIndex&&this.visitNode(e.addIndex),e.dropIndex&&this.visitNode(e.dropIndex)}visitAddColumn(e){this.append("add column "),this.visitNode(e.column)}visitRenameColumn(e){this.append("rename column "),this.visitNode(e.column),this.append(" to "),this.visitNode(e.renameTo)}visitDropColumn(e){this.append("drop column "),this.visitNode(e.column)}visitAlterColumn(e){this.append("alter column "),this.visitNode(e.column),this.append(" "),e.dataType&&(this.announcesNewColumnDataType()&&this.append("type "),this.visitNode(e.dataType),e.dataTypeExpression&&(this.append("using "),this.visitNode(e.dataTypeExpression))),e.setDefault&&(this.append("set default "),this.visitNode(e.setDefault)),e.dropDefault&&this.append("drop default"),e.setNotNull&&this.append("set not null"),e.dropNotNull&&this.append("drop not null")}visitModifyColumn(e){this.append("modify column "),this.visitNode(e.column)}visitAddConstraint(e){this.append("add "),this.visitNode(e.constraint)}visitDropConstraint(e){this.append("drop constraint "),e.ifExists&&this.append("if exists "),this.visitNode(e.constraintName),e.modifier==="cascade"?this.append(" cascade"):e.modifier==="restrict"&&this.append(" restrict")}visitRenameConstraint(e){this.append("rename constraint "),this.visitNode(e.oldName),this.append(" to "),this.visitNode(e.newName)}visitSetOperation(e){this.append(e.operator),this.append(" "),e.all&&this.append("all "),this.visitNode(e.expression)}visitCreateView(e){this.append("create "),e.orReplace&&this.append("or replace "),e.materialized&&this.append("materialized "),e.temporary&&this.append("temporary "),this.append("view "),e.ifNotExists&&this.append("if not exists "),this.visitNode(e.name),this.append(" "),e.columns&&(this.append("("),this.compileList(e.columns),this.append(") ")),e.as&&(this.append("as "),this.visitNode(e.as))}visitRefreshMaterializedView(e){this.append("refresh materialized view "),e.concurrently&&this.append("concurrently "),this.visitNode(e.name),e.withNoData?this.append(" with no data"):this.append(" with data")}visitDropView(e){this.append("drop "),e.materialized&&this.append("materialized "),this.append("view "),e.ifExists&&this.append("if exists "),this.visitNode(e.name),e.cascade&&this.append(" cascade")}visitGenerated(e){this.append("generated "),e.always&&this.append("always "),e.byDefault&&this.append("by default "),this.append("as "),e.identity&&this.append("identity"),e.expression&&(this.append("("),this.visitNode(e.expression),this.append(")")),e.stored&&this.append(" stored")}visitDefaultValue(e){this.append("default "),this.visitNode(e.defaultValue)}visitSelectModifier(e){e.rawModifier?this.visitNode(e.rawModifier):this.append(Bt[e.modifier]),e.of&&(this.append(" of "),this.compileList(e.of,", "))}visitCreateType(e){this.append("create type "),this.visitNode(e.name),e.enum&&(this.append(" as enum "),this.visitNode(e.enum))}visitDropType(e){this.append("drop type "),e.ifExists&&this.append("if exists "),this.visitNode(e.name)}visitExplain(e){this.append("explain"),(e.options||e.format)&&(this.append(" "),this.append(this.getLeftExplainOptionsWrapper()),e.options&&(this.visitNode(e.options),e.format&&this.append(this.getExplainOptionsDelimiter())),e.format&&(this.append("format"),this.append(this.getExplainOptionAssignment()),this.append(e.format)),this.append(this.getRightExplainOptionsWrapper()))}visitDefaultInsertValue(e){this.append("default")}visitAggregateFunction(e){this.append(e.func),this.append("("),e.distinct&&this.append("distinct "),this.compileList(e.aggregated),e.orderBy&&(this.append(" "),this.visitNode(e.orderBy)),this.append(")"),e.withinGroup&&(this.append(" within group ("),this.visitNode(e.withinGroup),this.append(")")),e.filter&&(this.append(" filter("),this.visitNode(e.filter),this.append(")")),e.over&&(this.append(" "),this.visitNode(e.over))}visitOver(e){this.append("over("),e.partitionBy&&(this.visitNode(e.partitionBy),e.orderBy&&this.append(" ")),e.orderBy&&this.visitNode(e.orderBy),this.append(")")}visitPartitionBy(e){this.append("partition by "),this.compileList(e.items)}visitPartitionByItem(e){this.visitNode(e.partitionBy)}visitBinaryOperation(e){this.visitNode(e.leftOperand),this.append(" "),this.visitNode(e.operator),this.append(" "),this.visitNode(e.rightOperand)}visitUnaryOperation(e){this.visitNode(e.operator),this.isMinusOperator(e.operator)||this.append(" "),this.visitNode(e.operand)}isMinusOperator(e){return ot.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 r of e.pathLegs)this.visitNode(r);this.append("'")}visitJSONPathLeg(e){let r=e.type==="ArrayLocation";this.append(r?"[":"."),this.append(String(e.value)),r&&this.append("]")}visitJSONOperatorChain(e){for(let r=0,s=e.values.length;r<s;r++)r===s-1?this.visitNode(e.operator):this.append("->"),this.visitNode(e.values[r])}visitMergeQuery(e){e.with&&(this.visitNode(e.with),this.append(" ")),this.append("merge "),e.top&&(this.visitNode(e.top),this.append(" ")),this.append("into "),this.visitNode(e.into),e.using&&(this.append(" "),this.visitNode(e.using)),e.whens&&(this.append(" "),this.compileList(e.whens," ")),e.returning&&(this.append(" "),this.visitNode(e.returning)),e.output&&(this.append(" "),this.visitNode(e.output)),e.endModifiers?.length&&(this.append(" "),this.compileList(e.endModifiers," "))}visitMatched(e){e.not&&this.append("not "),this.append("matched"),e.bySource&&this.append(" by source")}visitAddIndex(e){this.append("add "),e.unique&&this.append("unique "),this.append("index "),this.visitNode(e.name),e.columns&&(this.append(" ("),this.compileList(e.columns),this.append(")")),e.using&&(this.append(" using "),this.visitNode(e.using))}visitCast(e){this.append("cast("),this.visitNode(e.expression),this.append(" as "),this.visitNode(e.dataType),this.append(")")}visitFetch(e){this.append("fetch next "),this.visitNode(e.rowCount),this.append(` rows ${e.modifier}`)}visitOutput(e){this.append("output "),this.compileList(e.selections)}visitTop(e){this.append(`top(${e.expression})`),e.modifiers&&this.append(` ${e.modifiers}`)}visitOrAction(e){this.append(e.action)}visitCollate(e){this.append("collate "),this.visitNode(e.collation)}append(e){this.#e+=e}appendValue(e){this.addParameter(e),this.append(this.getCurrentParameterPlaceholder())}getLeftIdentifierWrapper(){return'"'}getRightIdentifierWrapper(){return'"'}getCurrentParameterPlaceholder(){return"$"+this.numParameters}getLeftExplainOptionsWrapper(){return"("}getExplainOptionAssignment(){return" "}getExplainOptionsDelimiter(){return", "}getRightExplainOptionsWrapper(){return")"}sanitizeIdentifier(e){let r=this.getLeftIdentifierWrapper(),s=this.getRightIdentifierWrapper(),n="";for(let h of e)n+=h,h===r?n+=r:h===s&&(n+=s);return n}sanitizeStringLiteral(e){return e.replace(zt,"''")}addParameter(e){this.#t.push(e)}appendImmediateValue(e){if(ze(e))this.appendStringLiteral(e);else if(tt(e)||Be(e)||st(e))this.append(e.toString());else if(it(e))this.append("null");else if(rt(e))this.appendImmediateValue(e.toISOString());else throw new Error(`invalid immediate value ${e}`)}appendStringLiteral(e){this.append("'"),this.append(this.sanitizeStringLiteral(e)),this.append("'")}sortSelectModifiers(e){return e.sort((r,s)=>r.modifier&&s.modifier?Et[r.modifier]-Et[s.modifier]:1),i(e)}compileColumnAlterations(e){this.compileList(e)}announcesNewColumnDataType(){return!0}},Bt=i({ForKeyShare:"for key share",ForNoKeyUpdate:"for no key update",ForUpdate:"for update",ForShare:"for share",NoWait:"nowait",SkipLocked:"skip locked",Distinct:"distinct"}),Et=i({ForKeyShare:1,ForNoKeyUpdate:1,ForUpdate:1,ForShare:1,NoWait:2,SkipLocked:2,Distinct:0}),Vt=i({InnerJoin:"inner join",LeftJoin:"left join",RightJoin:"right join",FullJoin:"full join",CrossJoin:"cross join",LateralInnerJoin:"inner join lateral",LateralLeftJoin:"left join lateral",LateralCrossJoin:"cross join lateral",OuterApply:"outer apply",CrossApply:"cross apply",Using:"using"});var Oa=i({raw(t,e=[]){return i({sql:t,query:C.createWithSql(t),parameters:i(e),queryId:u()})}});var kt=class{get supportsCreateIfNotExists(){return!0}get supportsTransactionalDdl(){return!1}get supportsReturning(){return!1}get supportsOutput(){return!1}};var Ea="kysely_migration",ka="kysely_migration_lock";var Pa=i({__noMigrations__:!0});export{qe as a,St as b,Oa as c,kt as d,Ea as e,ka as f};
|
package/dist/chunk-GGT3S2QA.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{b as c,j as i}from"./chunk-QI5B3GSQ.js";function o(t,n){if(e(t)&&n.stack){let s=n.stack.split(`
|
|
3
|
-
`).slice(1).join(`
|
|
4
|
-
`);return t.stack+=`
|
|
5
|
-
${s}`,t}return t}function e(t){return i(t)&&c(t.stack)}export{o as a};
|
package/dist/chunk-GQBL2JPZ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
import{a as i}from"./chunk-PJYMXUBP.js";import{c as u,d,i as m}from"./chunk-CTFIMWJ7.js";import{randomBytes as g,createCipheriv as x,createDecipheriv as v,createPrivateKey as V,createPublicKey as b,diffieHellman as E,generateKeyPairSync as T,hkdfSync as N}from"crypto";function _(){return g(32)}function k(e,r){let t=V({key:Buffer.from(e,"hex"),format:"der",type:"pkcs8"}),n=b({key:Buffer.from(r,"hex"),format:"der",type:"spki"});return E({privateKey:t,publicKey:n})}function S(e,r){return Buffer.from(N("sha256",e,Buffer.alloc(0),r,32))}function w(e,r){let{publicKey:t,privateKey:n}=T("x25519",{publicKeyEncoding:{type:"spki",format:"der"},privateKeyEncoding:{type:"pkcs8",format:"der"}}),a=n.toString("hex"),s=t.toString("hex"),c=k(a,r),o=S(c,"noorm-vault-key"),l=g(16),f=x("aes-256-gcm",o,l),y=Buffer.concat([f.update(e),f.final()]),p=f.getAuthTag();return{ephemeralPubKey:s,iv:l.toString("hex"),authTag:p.toString("hex"),ciphertext:y.toString("hex")}}function K(e,r){let[t,n]=d(()=>{let a=k(r,e.ephemeralPubKey),s=S(a,"noorm-vault-key"),c=v("aes-256-gcm",s,Buffer.from(e.iv,"hex"));return c.setAuthTag(Buffer.from(e.authTag,"hex")),Buffer.concat([c.update(Buffer.from(e.ciphertext,"hex")),c.final()])});return n?null:t}function B(e,r){let t=g(16),n=x("aes-256-gcm",r,t),a=Buffer.concat([n.update(e,"utf8"),n.final()]),s=n.getAuthTag();return{iv:t.toString("hex"),authTag:s.toString("hex"),ciphertext:a.toString("hex")}}function h(e,r){let[t,n]=d(()=>{let a=v("aes-256-gcm",r,Buffer.from(e.iv,"hex"));return a.setAuthTag(Buffer.from(e.authTag,"hex")),Buffer.concat([a.update(Buffer.from(e.ciphertext,"hex")),a.final()]).toString("utf8")});return n?null:t}async function z(e,r,t){let[n,a]=await u(async()=>e.selectFrom(i.identities).select("encrypted_vault_key").where("encrypted_vault_key","is not",null).limit(1).executeTakeFirst());if(a)return[null,a];if(n?.encrypted_vault_key)return[null,new Error("Vault already initialized")];let s=_(),c=w(s,t),o=JSON.stringify(c),[,l]=await u(async()=>e.updateTable(i.identities).set({encrypted_vault_key:o}).where("identity_hash","=",r).execute());return l?[null,l]:(m.emit("vault:initialized",{identityHash:r}),[s,null])}async function j(e,r,t){let[n,a]=await u(async()=>e.selectFrom(i.identities).select("encrypted_vault_key").where("identity_hash","=",r).executeTakeFirst());if(a||!n?.encrypted_vault_key)return null;let s=n.encrypted_vault_key,[c,o]=d(()=>JSON.parse(s));return o?null:K(c,t)}async function I(e,r,t,n,a){let s=B(n,r),c=JSON.stringify(s),o=new Date().toISOString(),[l,f]=await u(async()=>e.selectFrom(i.vault).select("id").where("secret_key","=",t).executeTakeFirst());if(f)return[void 0,f];if(l){let[,y]=await u(async()=>e.updateTable(i.vault).set({encrypted_value:c,set_by:a,updated_at:o}).where("secret_key","=",t).execute());if(y)return[void 0,y];m.emit("vault:secret:updated",{key:t,setBy:a})}else{let[,y]=await u(async()=>e.insertInto(i.vault).values({secret_key:t,encrypted_value:c,set_by:a}).execute());if(y)return[void 0,y];m.emit("vault:secret:created",{key:t,setBy:a})}return[void 0,null]}async function C(e,r,t){let[n,a]=await u(async()=>e.selectFrom(i.vault).select("encrypted_value").where("secret_key","=",t).executeTakeFirst());if(a||!n)return null;let[s,c]=d(()=>JSON.parse(n.encrypted_value));return c?null:h(s,r)}async function H(e,r){let[t,n]=await u(async()=>e.selectFrom(i.vault).selectAll().execute());if(n||!t)return{};let a={};for(let s of t){let[c,o]=d(()=>JSON.parse(s.encrypted_value));if(o)continue;let l=h(c,r);l&&(a[s.secret_key]={key:s.secret_key,value:l,setBy:s.set_by,createdAt:new Date(s.created_at),updatedAt:new Date(s.updated_at)})}return a}async function U(e){let[r,t]=await u(async()=>e.selectFrom(i.vault).select("secret_key").orderBy("secret_key","asc").execute());return t||!r?[]:r.map(n=>n.secret_key)}async function W(e,r){let[t,n]=await u(async()=>e.deleteFrom(i.vault).where("secret_key","=",r).execute());if(n||!t)return[!1,n??new Error("Delete failed")];let a=t[0],s=!!a&&Number(a.numDeletedRows)>0;return s&&m.emit("vault:secret:deleted",{key:r}),[s,null]}async function L(e,r){let[t,n]=await u(async()=>e.selectFrom(i.vault).select("id").where("secret_key","=",r).executeTakeFirst());return n?!1:!!t}async function M(e,r){let[t]=await u(async()=>e.selectFrom(i.vault).select(e.fn.count("id").as("count")).executeTakeFirst()),n=t?Number(t.count):0,[a]=await u(async()=>e.selectFrom(i.identities).select(["identity_hash","encrypted_vault_key"]).execute()),s=a??[],c=s.filter(p=>p.encrypted_vault_key!==null).length,o=s.filter(p=>p.encrypted_vault_key===null).length,l=c>0,y=s.find(p=>p.identity_hash===r)?.encrypted_vault_key!==null;return{isInitialized:l,hasAccess:y,secretCount:n,usersWithAccess:c,usersWithoutAccess:o}}export{w as a,z as b,j as c,I as d,C as e,H as f,U as g,W as h,L as i,M as j};
|
package/dist/chunk-KVY4JR2A.js
DELETED
package/dist/chunk-PJYMXUBP.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
var e=Object.freeze({version:"__noorm_version__",change:"__noorm_change__",executions:"__noorm_executions__",lock:"__noorm_lock__",identities:"__noorm_identities__",vault:"__noorm_vault__"});export{e as a};
|
package/dist/chunk-QI5B3GSQ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'; const require = createRequire(import.meta.url);
|
|
2
|
-
function M(r){return typeof r>"u"||r===void 0}function p(r){return typeof r=="string"}function pe(r){return typeof r=="number"}function ze(r){return typeof r=="boolean"}function Ie(r){return r===null}function ko(r){return r instanceof Date}function Ue(r){return typeof r=="bigint"}function Co(r){return typeof Buffer<"u"&&Buffer.isBuffer(r)}function x(r){return typeof r=="function"}function X(r){return typeof r=="object"&&r!==null}function o(r){return Object.freeze(r)}function Re(r){return C(r)?r:[r]}function C(r){return Array.isArray(r)}function Eo(r){return r}var nt=new Set;function le(r){nt.has(r)||(nt.add(r),console.log(r))}var it=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"];function st(r){let e="";for(let t=0;t<r;++t)e+=Xt();return e}function Xt(){return it[~~(Math.random()*it.length)]}function w(){return new Wr}var Wr=class{#e;get queryId(){return this.#e===void 0&&(this.#e=st(8)),this.#e}};var g=o({is(r){return r.kind==="AliasNode"},create(r,e){return o({kind:"AliasNode",node:r,alias:e})}});var u=o({is(r){return r.kind==="IdentifierNode"},create(r){return o({kind:"IdentifierNode",name:r})}});var T=o({is(r){return r.kind==="AndNode"},create(r,e){return o({kind:"AndNode",left:r,right:e})}});var P=o({is(r){return r.kind==="OrNode"},create(r,e){return o({kind:"OrNode",left:r,right:e})}});var Ve=o({is(r){return r.kind==="OnNode"},create(r){return o({kind:"OnNode",on:r})},cloneWithOperation(r,e,t){return o({...r,on:e==="And"?T.create(r.on,t):P.create(r.on,t)})}});var Q=o({is(r){return r.kind==="JoinNode"},create(r,e){return o({kind:"JoinNode",joinType:r,table:e,on:void 0})},createWithOn(r,e,t){return o({kind:"JoinNode",joinType:r,table:e,on:Ve.create(t)})},cloneWithOn(r,e){return o({...r,on:r.on?Ve.cloneWithOperation(r.on,"And",e):Ve.create(e)})}});var Je=o({is(r){return r.kind==="ListNode"},create(r){return o({kind:"ListNode",items:o(r)})}});var $e=class{nodeStack=[];#e=o({AliasNode:this.transformAlias.bind(this),ColumnNode:this.transformColumn.bind(this),IdentifierNode:this.transformIdentifier.bind(this),SchemableIdentifierNode:this.transformSchemableIdentifier.bind(this),RawNode:this.transformRaw.bind(this),ReferenceNode:this.transformReference.bind(this),SelectQueryNode:this.transformSelectQuery.bind(this),SelectionNode:this.transformSelection.bind(this),TableNode:this.transformTable.bind(this),FromNode:this.transformFrom.bind(this),SelectAllNode:this.transformSelectAll.bind(this),AndNode:this.transformAnd.bind(this),OrNode:this.transformOr.bind(this),ValueNode:this.transformValue.bind(this),ValueListNode:this.transformValueList.bind(this),PrimitiveValueListNode:this.transformPrimitiveValueList.bind(this),ParensNode:this.transformParens.bind(this),JoinNode:this.transformJoin.bind(this),OperatorNode:this.transformOperator.bind(this),WhereNode:this.transformWhere.bind(this),InsertQueryNode:this.transformInsertQuery.bind(this),DeleteQueryNode:this.transformDeleteQuery.bind(this),ReturningNode:this.transformReturning.bind(this),CreateTableNode:this.transformCreateTable.bind(this),AddColumnNode:this.transformAddColumn.bind(this),ColumnDefinitionNode:this.transformColumnDefinition.bind(this),DropTableNode:this.transformDropTable.bind(this),DataTypeNode:this.transformDataType.bind(this),OrderByNode:this.transformOrderBy.bind(this),OrderByItemNode:this.transformOrderByItem.bind(this),GroupByNode:this.transformGroupBy.bind(this),GroupByItemNode:this.transformGroupByItem.bind(this),UpdateQueryNode:this.transformUpdateQuery.bind(this),ColumnUpdateNode:this.transformColumnUpdate.bind(this),LimitNode:this.transformLimit.bind(this),OffsetNode:this.transformOffset.bind(this),OnConflictNode:this.transformOnConflict.bind(this),OnDuplicateKeyNode:this.transformOnDuplicateKey.bind(this),CreateIndexNode:this.transformCreateIndex.bind(this),DropIndexNode:this.transformDropIndex.bind(this),ListNode:this.transformList.bind(this),PrimaryKeyConstraintNode:this.transformPrimaryKeyConstraint.bind(this),UniqueConstraintNode:this.transformUniqueConstraint.bind(this),ReferencesNode:this.transformReferences.bind(this),CheckConstraintNode:this.transformCheckConstraint.bind(this),WithNode:this.transformWith.bind(this),CommonTableExpressionNode:this.transformCommonTableExpression.bind(this),CommonTableExpressionNameNode:this.transformCommonTableExpressionName.bind(this),HavingNode:this.transformHaving.bind(this),CreateSchemaNode:this.transformCreateSchema.bind(this),DropSchemaNode:this.transformDropSchema.bind(this),AlterTableNode:this.transformAlterTable.bind(this),DropColumnNode:this.transformDropColumn.bind(this),RenameColumnNode:this.transformRenameColumn.bind(this),AlterColumnNode:this.transformAlterColumn.bind(this),ModifyColumnNode:this.transformModifyColumn.bind(this),AddConstraintNode:this.transformAddConstraint.bind(this),DropConstraintNode:this.transformDropConstraint.bind(this),RenameConstraintNode:this.transformRenameConstraint.bind(this),ForeignKeyConstraintNode:this.transformForeignKeyConstraint.bind(this),CreateViewNode:this.transformCreateView.bind(this),RefreshMaterializedViewNode:this.transformRefreshMaterializedView.bind(this),DropViewNode:this.transformDropView.bind(this),GeneratedNode:this.transformGenerated.bind(this),DefaultValueNode:this.transformDefaultValue.bind(this),OnNode:this.transformOn.bind(this),ValuesNode:this.transformValues.bind(this),SelectModifierNode:this.transformSelectModifier.bind(this),CreateTypeNode:this.transformCreateType.bind(this),DropTypeNode:this.transformDropType.bind(this),ExplainNode:this.transformExplain.bind(this),DefaultInsertValueNode:this.transformDefaultInsertValue.bind(this),AggregateFunctionNode:this.transformAggregateFunction.bind(this),OverNode:this.transformOver.bind(this),PartitionByNode:this.transformPartitionBy.bind(this),PartitionByItemNode:this.transformPartitionByItem.bind(this),SetOperationNode:this.transformSetOperation.bind(this),BinaryOperationNode:this.transformBinaryOperation.bind(this),UnaryOperationNode:this.transformUnaryOperation.bind(this),UsingNode:this.transformUsing.bind(this),FunctionNode:this.transformFunction.bind(this),CaseNode:this.transformCase.bind(this),WhenNode:this.transformWhen.bind(this),JSONReferenceNode:this.transformJSONReference.bind(this),JSONPathNode:this.transformJSONPath.bind(this),JSONPathLegNode:this.transformJSONPathLeg.bind(this),JSONOperatorChainNode:this.transformJSONOperatorChain.bind(this),TupleNode:this.transformTuple.bind(this),MergeQueryNode:this.transformMergeQuery.bind(this),MatchedNode:this.transformMatched.bind(this),AddIndexNode:this.transformAddIndex.bind(this),CastNode:this.transformCast.bind(this),FetchNode:this.transformFetch.bind(this),TopNode:this.transformTop.bind(this),OutputNode:this.transformOutput.bind(this),OrActionNode:this.transformOrAction.bind(this),CollateNode:this.transformCollate.bind(this)});transformNode(e,t){if(!e)return e;this.nodeStack.push(e);let n=this.transformNodeImpl(e,t);return this.nodeStack.pop(),o(n)}transformNodeImpl(e,t){return this.#e[e.kind](e,t)}transformNodeList(e,t){return e&&o(e.map(n=>this.transformNode(n,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:o([...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),ignore:e.ignore,orAction:this.transformNode(e.orAction,t),replace:e.replace,explain:this.transformNode(e.explain,t),defaultValues:e.defaultValues,top:this.transformNode(e.top,t),output:this.transformNode(e.output,t)}}transformValues(e,t){return{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),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}}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)}}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),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)}}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}};var Ae=o({is(r){return r.kind==="SchemableIdentifierNode"},create(r){return o({kind:"SchemableIdentifierNode",identifier:u.create(r)})},createWithSchema(r,e){return o({kind:"SchemableIdentifierNode",schema:u.create(r),identifier:u.create(e)})}});var B=o({is(r){return r.kind==="TableNode"},create(r){return o({kind:"TableNode",table:Ae.create(r)})},createWithSchema(r,e){return o({kind:"TableNode",table:Ae.createWithSchema(r,e)})}});var Te=o({is(r){return r.kind==="UsingNode"},create(r){return o({kind:"UsingNode",tables:o(r)})},cloneWithTables(r,e){return o({...r,tables:o([...r.tables,...e])})}});var Zt=o({AlterTableNode:!0,CreateIndexNode:!0,CreateSchemaNode:!0,CreateTableNode:!0,CreateTypeNode:!0,CreateViewNode:!0,RefreshMaterializedViewNode:!0,DeleteQueryNode:!0,DropIndexNode:!0,DropSchemaNode:!0,DropTableNode:!0,DropTypeNode:!0,DropViewNode:!0,InsertQueryNode:!0,RawNode:!0,SelectQueryNode:!0,UpdateQueryNode:!0,MergeQueryNode:!0}),_t={json_agg:!0,to_json:!0},Ge=class extends $e{#e;#r=new Set;#t=new Set;constructor(e){super(),this.#e=e}transformNodeImpl(e,t){if(!this.#s(e))return super.transformNodeImpl(e,t);let n=this.#u(e);for(let A of n)this.#t.add(A);let i=this.#a(e);for(let A of i)this.#r.add(A);let m=super.transformNodeImpl(e,t);for(let A of i)this.#r.delete(A);for(let A of n)this.#t.delete(A);return m}transformSchemableIdentifier(e,t){let n=super.transformSchemableIdentifier(e,t);return n.schema||!this.#r.has(e.identifier.name)?n:{...n,schema:u.create(this.#e)}}transformReferences(e,t){let n=super.transformReferences(e,t);return n.table.table.schema?n:{...n,table:B.createWithSchema(this.#e,n.table.table.identifier.name)}}transformAggregateFunction(e,t){return{...super.transformAggregateFunction({...e,aggregated:[]},t),aggregated:this.#n(e,t,"aggregated")}}transformFunction(e,t){return{...super.transformFunction({...e,arguments:[]},t),arguments:this.#n(e,t,"arguments")}}transformSelectModifier(e,t){return{...super.transformSelectModifier({...e,of:void 0},t),of:e.of?.map(n=>B.is(n)&&!n.table.schema?{...n,table:this.transformIdentifier(n.table.identifier,t)}:this.transformNode(n,t))}}#n(e,t,n){return _t[e.func]?e[n].map(i=>!B.is(i)||i.table.schema?this.transformNode(i,t):{...i,table:this.transformIdentifier(i.table.identifier,t)}):this.transformNodeList(e[n],t)}#s(e){return e.kind in Zt}#a(e){let t=new Set;if("name"in e&&e.name&&Ae.is(e.name)&&this.#i(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&&(Q.is(e.using)?this.#o(e.using.table,t):this.#o(e.using,t)),t}#u(e){let t=new Set;return"with"in e&&e.with&&this.#d(e.with,t),t}#o(e,t){if(B.is(e))return this.#i(e.table,t);if(g.is(e)&&B.is(e.node))return this.#i(e.node.table,t);if(Je.is(e)){for(let n of e.items)this.#o(n,t);return}if(Te.is(e)){for(let n of e.tables)this.#o(n,t);return}}#i(e,t){let n=e.identifier.name;!this.#r.has(n)&&!this.#t.has(n)&&t.add(n)}#d(e,t){for(let n of e.expressions){let i=n.name.table.table.identifier.name;this.#t.has(i)||t.add(i)}}};var Ne=class{#e;constructor(e){this.#e=new Ge(e)}transformQuery(e){return this.#e.transformNode(e.node,e.queryId)}async transformResult(e){return e.result}};var Be=class{#e;#r;#t;constructor(){this.#e=new Promise((e,t)=>{this.#t=t,this.#r=e})}get promise(){return this.#e}resolve=e=>{this.#r&&this.#r(e)};reject=e=>{this.#t&&this.#t(e)}};async function at(r){let e=new Be,t=new Be;return r.provideConnection(async n=>(e.resolve(n),await t.promise)).catch(n=>e.reject(n)),o({connection:await e.promise,release:t.resolve})}var G=o({is(r){return r.kind==="SelectModifierNode"},create(r,e){return o({kind:"SelectModifierNode",modifier:r,of:e})},createWithExpression(r){return o({kind:"SelectModifierNode",rawModifier:r})}});var oe=o({is(r){return r.kind==="BinaryOperationNode"},create(r,e,t){return o({kind:"BinaryOperationNode",leftOperand:r,operator:e,rightOperand:t})}});function f(r){return X(r)&&x(r.toOperationNode)}var eo=["=","==","!=","<>",">",">=","<","<=","in","not in","is","is not","like","not like","match","ilike","not ilike","@>","<@","^@","&&","?","?&","?|","!<","!>","<=>","!~","~","~*","!~*","@@","@@@","!!","<->","regexp","is distinct from","is not distinct from"],ro=["+","-","*","/","%","^","&","|","#","<<",">>"],ut=["->","->>"],to=[...eo,...ro,"&&","||"],oo=["exists","not exists"],no=["not","-",...oo],dt=[...to,...ut,...no,"between","between symmetric"],v=o({is(r){return r.kind==="OperatorNode"},create(r){return o({kind:"OperatorNode",operator:r})}});function Sr(r){return p(r)&&ut.includes(r)}var E=o({is(r){return r.kind==="ColumnNode"},create(r){return o({kind:"ColumnNode",column:u.create(r)})}});var je=o({is(r){return r.kind==="SelectAllNode"},create(){return o({kind:"SelectAllNode"})}});var ye=o({is(r){return r.kind==="ReferenceNode"},create(r,e){return o({kind:"ReferenceNode",table:e,column:r})},createSelectAll(r){return o({kind:"ReferenceNode",table:r,column:je.create()})}});function Ke(r){return X(r)&&"expressionType"in r&&f(r)}function mt(r){return X(r)&&"expression"in r&&p(r.alias)&&f(r)}var me=o({is(r){return r.kind==="FromNode"},create(r){return o({kind:"FromNode",froms:o(r)})},cloneWithFroms(r,e){return o({...r,froms:o([...r.froms,...e])})}});var br=o({is(r){return r.kind==="GroupByNode"},create(r){return o({kind:"GroupByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var kr=o({is(r){return r.kind==="HavingNode"},create(r){return o({kind:"HavingNode",having:r})},cloneWithOperation(r,e,t){return o({...r,having:e==="And"?T.create(r.having,t):P.create(r.having,t)})}});var l=o({is(r){return r.kind==="InsertQueryNode"},create(r,e,t){return o({kind:"InsertQueryNode",into:r,...e&&{with:e},replace:t})},createWithoutInto(){return o({kind:"InsertQueryNode"})},cloneWith(r,e){return o({...r,...e})}});var j=o({is(r){return r.kind==="UpdateQueryNode"},create(r,e){return o({kind:"UpdateQueryNode",table:r.length===1?r[0]:Je.create(r),...e&&{with:e}})},createWithoutTable(){return o({kind:"UpdateQueryNode"})},cloneWithFromItems(r,e){return o({...r,from:r.from?me.cloneWithFroms(r.from,e):me.create(e)})},cloneWithUpdates(r,e){return o({...r,updates:r.updates?o([...r.updates,...e]):e})},cloneWithLimit(r,e){return o({...r,limit:e})}});var ne=o({is(r){return r.kind==="DeleteQueryNode"},create(r,e){return o({kind:"DeleteQueryNode",from:me.create(r),...e&&{with:e}})},cloneWithOrderByItems:(r,e)=>s.cloneWithOrderByItems(r,e),cloneWithoutOrderBy:r=>s.cloneWithoutOrderBy(r),cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithUsing(r,e){return o({...r,using:r.using!==void 0?Te.cloneWithTables(r.using,e):Te.create(e)})}});var b=o({is(r){return r.kind==="WhereNode"},create(r){return o({kind:"WhereNode",where:r})},cloneWithOperation(r,e,t){return o({...r,where:e==="And"?T.create(r.where,t):P.create(r.where,t)})}});var Cr=o({is(r){return r.kind==="ReturningNode"},create(r){return o({kind:"ReturningNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var ct=o({is(r){return r.kind==="ExplainNode"},create(r,e){return o({kind:"ExplainNode",format:r,options:e})}});var Z=o({is(r){return r.kind==="WhenNode"},create(r){return o({kind:"WhenNode",condition:r})},cloneWithResult(r,e){return o({...r,result:e})}});var q=o({is(r){return r.kind==="MergeQueryNode"},create(r,e){return o({kind:"MergeQueryNode",into:r,...e&&{with:e}})},cloneWithUsing(r,e){return o({...r,using:e})},cloneWithWhen(r,e){return o({...r,whens:r.whens?o([...r.whens,e]):o([e])})},cloneWithThen(r,e){return o({...r,whens:r.whens?o([...r.whens.slice(0,-1),Z.cloneWithResult(r.whens[r.whens.length-1],e)]):void 0})}});var Er=o({is(r){return r.kind==="OutputNode"},create(r){return o({kind:"OutputNode",selections:o(r)})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})}});var _=o({is(r){return r.kind==="OrderByNode"},create(r){return o({kind:"OrderByNode",items:o([...r])})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var s=o({is(r){return d.is(r)||l.is(r)||j.is(r)||ne.is(r)||q.is(r)},cloneWithEndModifier(r,e){return o({...r,endModifiers:r.endModifiers?o([...r.endModifiers,e]):o([e])})},cloneWithWhere(r,e){return o({...r,where:r.where?b.cloneWithOperation(r.where,"And",e):b.create(e)})},cloneWithJoin(r,e){return o({...r,joins:r.joins?o([...r.joins,e]):o([e])})},cloneWithReturning(r,e){return o({...r,returning:r.returning?Cr.cloneWithSelections(r.returning,e):Cr.create(e)})},cloneWithoutReturning(r){return o({...r,returning:void 0})},cloneWithoutWhere(r){return o({...r,where:void 0})},cloneWithExplain(r,e,t){return o({...r,explain:ct.create(e,t?.toOperationNode())})},cloneWithTop(r,e){return o({...r,top:e})},cloneWithOutput(r,e){return o({...r,output:r.output?Er.cloneWithSelections(r.output,e):Er.create(e)})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?_.cloneWithItems(r.orderBy,e):_.create(e)})},cloneWithoutOrderBy(r){return o({...r,orderBy:void 0})}});var d=o({is(r){return r.kind==="SelectQueryNode"},create(r){return o({kind:"SelectQueryNode",...r&&{with:r}})},createFrom(r,e){return o({kind:"SelectQueryNode",from:me.create(r),...e&&{with:e}})},cloneWithSelections(r,e){return o({...r,selections:r.selections?o([...r.selections,...e]):o(e)})},cloneWithDistinctOn(r,e){return o({...r,distinctOn:r.distinctOn?o([...r.distinctOn,...e]):o(e)})},cloneWithFrontModifier(r,e){return o({...r,frontModifiers:r.frontModifiers?o([...r.frontModifiers,e]):o([e])})},cloneWithOrderByItems:(r,e)=>s.cloneWithOrderByItems(r,e),cloneWithGroupByItems(r,e){return o({...r,groupBy:r.groupBy?br.cloneWithItems(r.groupBy,e):br.create(e)})},cloneWithLimit(r,e){return o({...r,limit:e})},cloneWithOffset(r,e){return o({...r,offset:e})},cloneWithFetch(r,e){return o({...r,fetch:e})},cloneWithHaving(r,e){return o({...r,having:r.having?kr.cloneWithOperation(r.having,"And",e):kr.create(e)})},cloneWithSetOperations(r,e){return o({...r,setOperations:r.setOperations?o([...r.setOperations,...e]):o([...e])})},cloneWithoutSelections(r){return o({...r,selections:[]})},cloneWithoutLimit(r){return o({...r,limit:void 0})},cloneWithoutOffset(r){return o({...r,offset:void 0})},cloneWithoutOrderBy:r=>s.cloneWithoutOrderBy(r),cloneWithoutGroupBy(r){return o({...r,groupBy:void 0})}});var ht=class{#e;get table(){return this.#e}constructor(e){this.#e=e}as(e){return new Rr(this.#e,e)}},Rr=class{#e;#r;get table(){return this.#e}get alias(){return this.#r}constructor(e,t){this.#e=e,this.#r=t}toOperationNode(){return g.create(N(this.#e),u.create(this.#r))}};function ft(r){return X(r)&&f(r)&&p(r.table)&&p(r.alias)}function z(r){return C(r)?r.map(e=>ce(e)):[ce(r)]}function ce(r){return p(r)?Ar(r):ft(r)?r.toOperationNode():He(r)}function Ar(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map(pt);return g.create(N(t),u.create(n))}else return N(r)}function N(r){if(r.includes(".")){let[t,n]=r.split(".").map(pt);return B.createWithSchema(t,n)}else return B.create(r)}function pt(r){return r.trim()}var ie=o({is(r){return r.kind==="ParensNode"},create(r){return o({kind:"ParensNode",node:r})}});var a=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}or(...e){return new Tr(P.create(this.#e,h(e)))}and(...e){return new Br(T.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},qe=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}},Tr=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}or(...e){return new r(P.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return ie.create(this.#e)}},Br=class r{#e;constructor(e){this.#e=e}get expressionType(){}as(e){return new qe(this,e)}and(...e){return new r(T.create(this.#e,h(e)))}$castTo(){return new r(this.#e)}toOperationNode(){return ie.create(this.#e)}};var K=o({is(r){return r.kind==="AggregateFunctionNode"},create(r,e=[]){return o({kind:"AggregateFunctionNode",func:r,aggregated:e})},cloneWithDistinct(r){return o({...r,distinct:!0})},cloneWithOrderBy(r,e,t=!1){let n=t?"withinGroup":"orderBy";return o({...r,[n]:r[n]?_.cloneWithItems(r[n],e):_.create(e)})},cloneWithFilter(r,e){return o({...r,filter:r.filter?b.cloneWithOperation(r.filter,"And",e):b.create(e)})},cloneWithOrFilter(r,e){return o({...r,filter:r.filter?b.cloneWithOperation(r.filter,"Or",e):b.create(e)})},cloneWithOver(r,e){return o({...r,over:e})}});var qr=o({is(r){return r.kind==="FunctionNode"},create(r,e){return o({kind:"FunctionNode",func:r,arguments:e})}});var we=o({is(r){return r.kind==="SelectionNode"},create(r){return o({kind:"SelectionNode",selection:r})},createSelectAll(){return o({kind:"SelectionNode",selection:je.create()})},createSelectAllFromTable(r){return o({kind:"SelectionNode",selection:ye.createSelectAll(r)})}});var lt=class{#e;get dynamicReference(){return this.#e}get refType(){}constructor(e){this.#e=e}toOperationNode(){return Lr(this.#e)}};function Ye(r){return X(r)&&f(r)&&p(r.dynamicReference)}function O(r){return x(r)?O(r(I())):C(r)?r.map(e=>Nt(e)):[Nt(r)]}function Nt(r){return p(r)?we.create(wt(r)):Ye(r)?we.create(r.toOperationNode()):we.create(He(r))}function W(r){return r?Array.isArray(r)?r.map(yt):[yt(r)]:[we.createSelectAll()]}function yt(r){if(p(r))return we.createSelectAllFromTable(N(r));throw new Error(`invalid value selectAll expression: ${JSON.stringify(r)}`)}var Fr=o({is(r){return r.kind==="PartitionByNode"},create(r){return o({kind:"PartitionByNode",items:o(r)})},cloneWithItems(r,e){return o({...r,items:o([...r.items,...e])})}});var Le=o({is(r){return r.kind==="OverNode"},create(){return o({kind:"OverNode"})},cloneWithOrderByItems(r,e){return o({...r,orderBy:r.orderBy?_.cloneWithItems(r.orderBy,e):_.create(e)})},cloneWithPartitionByItems(r,e){return o({...r,partitionBy:r.partitionBy?Fr.cloneWithItems(r.partitionBy,e):Fr.create(e)})}});var y=o({is(r){return r.kind==="RawNode"},create(r,e){return o({kind:"RawNode",sqlFragments:o(r),parameters:o(e)})},createWithSql(r){return y.create([r],[])},createWithChild(r){return y.create(["",""],[r])},createWithChildren(r){return y.create(new Array(r.length+1).fill(""),r)}});var Xe=class r{#e;constructor(e){this.#e=o(e)}on(...e){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,h(e))})}onRef(e,t,n){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,S(e,t,n))})}onTrue(){return new r({...this.#e,joinNode:Q.cloneWithOn(this.#e.joinNode,y.createWithSql("true"))})}$call(e){return e(this)}toOperationNode(){return this.#e.joinNode}};var U=o({is(r){return r.kind==="OrderByItemNode"},create(r,e){return o({kind:"OrderByItemNode",orderBy:r,direction:e})},cloneWith(r,e){return o({...r,...e})}});var Ot=o({is(r){return r.kind==="CollateNode"},create(r){return o({kind:"CollateNode",collation:u.create(r)})}});var Ze=class r{#e;constructor(e){this.#e=o(e)}desc(){return new r({node:U.cloneWith(this.#e.node,{direction:y.createWithSql("desc")})})}asc(){return new r({node:U.cloneWith(this.#e.node,{direction:y.createWithSql("asc")})})}nullsLast(){return new r({node:U.cloneWith(this.#e.node,{nulls:"last"})})}nullsFirst(){return new r({node:U.cloneWith(this.#e.node,{nulls:"first"})})}collate(e){return new r({node:U.cloneWith(this.#e.node,{collation:Ot.create(e)})})}toOperationNode(){return this.#e.node}};function Mr(r){return r==="asc"||r==="desc"}function L(r){if(r.length===2)return[Dr(r[0],r[1])];if(r.length===1){let[e]=r;return Array.isArray(e)?(le("orderBy(array) is deprecated, use multiple orderBy calls instead."),e.map(t=>Dr(t))):[Dr(e)]}throw new Error(`Invalid number of arguments at order by! expected 1-2, received ${r.length}`)}function Dr(r,e){let t=io(r);if(U.is(t)){if(e)throw new Error("Cannot specify direction twice!");return t}return xt(t,e)}function io(r){if(ee(r))return H(r);if(Ye(r))return r.toOperationNode();let[e,t]=r.split(" ");return t?(le("`orderBy('column asc')` is deprecated. Use `orderBy('column', 'asc')` instead."),xt(V(e),t)):V(r)}function xt(r,e){if(typeof e=="string"){if(!Mr(e))throw new Error(`Invalid order by direction: ${e}`);return U.create(r,y.createWithSql(e))}if(Ke(e))return le("`orderBy(..., expr)` is deprecated. Use `orderBy(..., 'asc')` or `orderBy(..., (ob) => ...)` instead."),U.create(r,e.toOperationNode());let t=U.create(r);return e?e(new Ze({node:t})).toOperationNode():t}var gt=o({is(r){return r.kind==="PartitionByItemNode"},create(r){return o({kind:"PartitionByItemNode",partitionBy:r})}});function Wt(r){return re(r).map(gt.create)}var _e=class r{#e;constructor(e){this.#e=o(e)}orderBy(...e){return new r({overNode:Le.cloneWithOrderByItems(this.#e.overNode,L(e))})}clearOrderBy(){return new r({overNode:s.cloneWithoutOrderBy(this.#e.overNode)})}partitionBy(e){return new r({overNode:Le.cloneWithPartitionByItems(this.#e.overNode,Wt(e))})}$call(e){return e(this)}toOperationNode(){return this.#e.overNode}};var so=o([]),er=class{#e;constructor(e=so){this.#e=e}get plugins(){return this.#e}transformQuery(e,t){for(let n of this.#e){let i=n.transformQuery({node:e,queryId:t});if(i.kind===e.kind)e=i;else throw new 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 ${i.kind}`].join(" "))}return e}async executeQuery(e){return await this.provideConnection(async t=>{let n=await t.executeQuery(e);return"numUpdatedOrDeletedRows"in n&&le("kysely:warning: outdated driver/plugin detected! `QueryResult.numUpdatedOrDeletedRows` has been replaced with `QueryResult.numAffectedRows`."),await this.#r(n,e.queryId)})}async*stream(e,t){let{connection:n,release:i}=await at(this);try{for await(let m of n.streamQuery(e,t))yield await this.#r(m,e.queryId)}finally{i()}}async#r(e,t){for(let n of this.#e)e=await n.transformResult({result:e,queryId:t});return e}};var Pr=class r extends er{get adapter(){throw new Error("this query cannot be compiled to SQL")}compileQuery(){throw new Error("this query cannot be compiled to SQL")}provideConnection(){throw new Error("this query cannot be executed")}withConnectionProvider(){throw new Error("this query cannot have a connection provider")}withPlugin(e){return new r([...this.plugins,e])}withPlugins(e){return new r([...this.plugins,...e])}withPluginAtFront(e){return new r([e,...this.plugins])}withoutPlugins(){return new r([])}},se=new Pr;function St(){return new rr({executor:se})}function bt(r,e){return new Xe({joinNode:Q.create(r,ce(e))})}function kt(){return new _e({overNode:Le.create()})}var Oe=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}as(e){return new Qr(this,e)}distinct(){return new r({...this.#e,aggregateFunctionNode:K.cloneWithDistinct(this.#e.aggregateFunctionNode)})}orderBy(...e){return new r({...this.#e,aggregateFunctionNode:s.cloneWithOrderByItems(this.#e.aggregateFunctionNode,L(e))})}clearOrderBy(){return new r({...this.#e,aggregateFunctionNode:s.cloneWithoutOrderBy(this.#e.aggregateFunctionNode)})}withinGroupOrderBy(...e){return new r({...this.#e,aggregateFunctionNode:K.cloneWithOrderBy(this.#e.aggregateFunctionNode,L(e),!0)})}filterWhere(...e){return new r({...this.#e,aggregateFunctionNode:K.cloneWithFilter(this.#e.aggregateFunctionNode,h(e))})}filterWhereRef(e,t,n){return new r({...this.#e,aggregateFunctionNode:K.cloneWithFilter(this.#e.aggregateFunctionNode,S(e,t,n))})}over(e){let t=kt();return new r({...this.#e,aggregateFunctionNode:K.cloneWithOver(this.#e.aggregateFunctionNode,(e?e(t):t).toOperationNode())})}$call(e){return e(this)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e.aggregateFunctionNode}},Qr=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),u.create(this.#r))}};function Ct(){let r=(t,n)=>new a(qr.create(t,re(n??[]))),e=(t,n)=>new Oe({aggregateFunctionNode:K.create(t,n?re(n):void 0)});return Object.assign(r,{agg:e,avg(t){return e("avg",[t])},coalesce(...t){return r("coalesce",t)},count(t){return e("count",[t])},countAll(t){return new Oe({aggregateFunctionNode:K.create("count",W(t))})},max(t){return e("max",[t])},min(t){return e("min",[t])},sum(t){return e("sum",[t])},any(t){return r("any",[t])},jsonAgg(t){return new Oe({aggregateFunctionNode:K.create("json_agg",[p(t)?N(t):t.toOperationNode()])})},toJson(t){return new a(qr.create("to_json",[p(t)?N(t):t.toOperationNode()]))}})}var Et=o({is(r){return r.kind==="UnaryOperationNode"},create(r,e){return o({kind:"UnaryOperationNode",operator:r,operand:e})}});function Rt(r,e){return Et.create(v.create(r),k(e))}var tr=o({is(r){return r.kind==="PrimitiveValueListNode"},create(r){return o({kind:"PrimitiveValueListNode",values:o([...r])})}});var or=o({is(r){return r.kind==="ValueListNode"},create(r){return o({kind:"ValueListNode",values:o(r)})}});var F=o({is(r){return r.kind==="ValueNode"},create(r){return o({kind:"ValueNode",value:r})},createImmediate(r){return o({kind:"ValueNode",value:r,immediate:!0})}});function At(r){return C(r)?ao(r):c(r)}function c(r){return ee(r)?H(r):F.create(r)}function nr(r){return pe(r)||ze(r)||Ie(r)}function Fe(r){if(!nr(r))throw new Error(`unsafe immediate value ${JSON.stringify(r)}`);return F.createImmediate(r)}function ao(r){return r.some(ee)?or.create(r.map(e=>c(e))):tr.create(r)}var J=o({is(r){return r.kind==="CaseNode"},create(r){return o({kind:"CaseNode",value:r})},cloneWithWhen(r,e){return o({...r,when:o(r.when?[...r.when,e]:[e])})},cloneWithThen(r,e){return o({...r,when:r.when?o([...r.when.slice(0,-1),Z.cloneWithResult(r.when[r.when.length-1],e)]):void 0})},cloneWith(r,e){return o({...r,...e})}});var ir=class{#e;constructor(e){this.#e=o(e)}when(...e){return new sr({...this.#e,node:J.cloneWithWhen(this.#e.node,Z.create(h(e)))})}},sr=class{#e;constructor(e){this.#e=o(e)}then(e){return new vr({...this.#e,node:J.cloneWithThen(this.#e.node,nr(e)?Fe(e):c(e))})}},vr=class{#e;constructor(e){this.#e=o(e)}when(...e){return new sr({...this.#e,node:J.cloneWithWhen(this.#e.node,Z.create(h(e)))})}else(e){return new zr({...this.#e,node:J.cloneWith(this.#e.node,{else:nr(e)?Fe(e):c(e)})})}end(){return new a(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(J.cloneWith(this.#e.node,{isStatement:!0}))}},zr=class{#e;constructor(e){this.#e=o(e)}end(){return new a(J.cloneWith(this.#e.node,{isStatement:!1}))}endCase(){return new a(J.cloneWith(this.#e.node,{isStatement:!0}))}};var ar=o({is(r){return r.kind==="JSONOperatorChainNode"},create(r){return o({kind:"JSONOperatorChainNode",operator:r,values:o([])})},cloneWithValue(r,e){return o({...r,values:o([...r.values,e])})}});var Ir=o({is(r){return r.kind==="JSONPathLegNode"},create(r,e){return o({kind:"JSONPathLegNode",type:r,value:e})}});var ae=o({is(r){return r.kind==="JSONPathNode"},create(r){return o({kind:"JSONPathNode",inOperator:r,pathLegs:o([])})},cloneWithLeg(r,e){return o({...r,pathLegs:o([...r.pathLegs,e])})}});var xe=o({is(r){return r.kind==="JSONReferenceNode"},create(r,e){return o({kind:"JSONReferenceNode",reference:r,traversal:e})},cloneWithTraversal(r,e){return o({...r,traversal:e})}});var ge=class{#e;constructor(e){this.#e=e}at(e){return this.#r("ArrayLocation",e)}key(e){return this.#r("Member",e)}#r(e,t){return xe.is(this.#e)?new ur(xe.cloneWithTraversal(this.#e,ae.is(this.#e.traversal)?ae.cloneWithLeg(this.#e.traversal,Ir.create(e,t)):ar.cloneWithValue(this.#e.traversal,F.createImmediate(t)))):new ur(ae.cloneWithLeg(this.#e,Ir.create(e,t)))}},ur=class r extends ge{#e;constructor(e){super(e),this.#e=e}get expressionType(){}as(e){return new Ur(this,e)}$castTo(){return new r(this.#e)}$notNull(){return new r(this.#e)}toOperationNode(){return this.#e}},Ur=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}};var Vr=o({is(r){return r.kind==="TupleNode"},create(r){return o({kind:"TupleNode",values:o(r)})}});var uo=["varchar","char","text","integer","int2","int4","int8","smallint","bigint","boolean","real","double precision","float4","float8","decimal","numeric","binary","bytea","date","datetime","time","timetz","timestamp","timestamptz","serial","bigserial","uuid","json","jsonb","blob","varbinary","int4range","int4multirange","int8range","int8multirange","numrange","nummultirange","tsrange","tsmultirange","tstzrange","tstzmultirange","daterange","datemultirange"],mo=[/^varchar\(\d+\)$/,/^char\(\d+\)$/,/^decimal\(\d+, \d+\)$/,/^numeric\(\d+, \d+\)$/,/^binary\(\d+\)$/,/^datetime\(\d+\)$/,/^time\(\d+\)$/,/^timetz\(\d+\)$/,/^timestamp\(\d+\)$/,/^timestamptz\(\d+\)$/,/^varbinary\(\d+\)$/],Tt=o({is(r){return r.kind==="DataTypeNode"},create(r){return o({kind:"DataTypeNode",dataType:r})}});function Bt(r){return!!(uo.includes(r)||mo.some(e=>e.test(r)))}function qt(r){if(f(r))return r.toOperationNode();if(Bt(r))return Tt.create(r);throw new Error(`invalid column data type ${JSON.stringify(r)}`)}var Lt=o({is(r){return r.kind==="CastNode"},create(r,e){return o({kind:"CastNode",expression:r,dataType:e})}});function mr(r=se){function e(i,m,A){return new a(dr(i,m,A))}function t(i,m){return new a(Rt(i,m))}let n=Object.assign(e,{fn:void 0,eb:void 0,selectFrom(i){return De({queryId:w(),executor:r,queryNode:d.createFrom(z(i))})},case(i){return new ir({node:J.create(M(i)?void 0:k(i))})},ref(i,m){return M(m)?new a(V(i)):new ge(Ft(i,m))},jsonPath(){return new ge(ae.create())},table(i){return new a(N(i))},val(i){return new a(c(i))},refTuple(...i){return new a(Vr.create(i.map(k)))},tuple(...i){return new a(Vr.create(i.map(c)))},lit(i){return new a(Fe(i))},unary:t,not(i){return t("not",i)},exists(i){return t("exists",i)},neg(i){return t("-",i)},between(i,m,A){return new a(oe.create(k(i),v.create("between"),T.create(c(m),c(A))))},betweenSymmetric(i,m,A){return new a(oe.create(k(i),v.create("between symmetric"),T.create(c(m),c(A))))},and(i){return C(i)?new a(We(i,"and")):new a(Jr(i,"and"))},or(i){return C(i)?new a(We(i,"or")):new a(Jr(i,"or"))},parens(...i){let m=h(i);return ie.is(m)?new a(m):new a(ie.create(m))},cast(i,m){return new a(Lt.create(k(i),qt(m)))},withSchema(i){return mr(r.withPluginAtFront(new Ne(i)))}});return n.fn=Ct(),n.eb=n,n}function I(r){return mr()}function H(r){if(f(r))return r.toOperationNode();if(x(r))return r(I()).toOperationNode();throw new Error(`invalid expression: ${JSON.stringify(r)}`)}function He(r){if(f(r))return r.toOperationNode();if(x(r))return r(I()).toOperationNode();throw new Error(`invalid aliased expression: ${JSON.stringify(r)}`)}function ee(r){return Ke(r)||mt(r)||x(r)}function Lr(r){return p(r)?V(r):r.toOperationNode()}function re(r){return C(r)?r.map(e=>k(e)):[k(r)]}function k(r){return ee(r)?H(r):Lr(r)}function Ft(r,e){let t=V(r);if(Sr(e))return xe.create(t,ar.create(v.create(e)));let n=e.slice(0,-1);if(Sr(n))return xe.create(t,ae.create(v.create(n)));throw new Error(`Invalid JSON operator: ${e}`)}function V(r){if(!r.includes("."))return ye.create(E.create(r));let t=r.split(".").map($r);if(t.length===3)return ho(t);if(t.length===2)return fo(t);throw new Error(`invalid column reference ${r}`)}function wt(r){let e=" as ";if(r.includes(e)){let[t,n]=r.split(e).map($r);return g.create(V(t),u.create(n))}else return V(r)}function co(r){return E.create(r)}function Ud(r){if(r.includes(" ")){let[t,n]=r.split(" ").map($r);if(!Mr(n))throw new Error(`invalid order direction "${n}" next to "${t}"`);return L([t,n])[0]}else return co(r)}function ho(r){let[e,t,n]=r;return ye.create(E.create(n),B.createWithSchema(e,t))}function fo(r){let[e,t]=r;return ye.create(E.create(t),B.create(e))}function $r(r){return r.trim()}function h(r){if(r.length===3)return dr(r[0],r[1],r[2]);if(r.length===1)return c(r[0]);throw new Error(`invalid arguments: ${JSON.stringify(r)}`)}function dr(r,e,t){return po(e)&&Mt(t)?oe.create(k(r),Gr(e),F.createImmediate(t)):oe.create(k(r),Gr(e),At(t))}function S(r,e,t){return oe.create(k(r),Gr(e),k(t))}function Jr(r,e){return We(Object.entries(r).filter(([,t])=>!M(t)).map(([t,n])=>dr(t,Mt(n)?"is":"=",n)),e)}function We(r,e,t=!0){let n=e==="and"?T.create:P.create;if(r.length===0)return oe.create(F.createImmediate(1),v.create("="),F.createImmediate(e==="and"?1:0));let i=Dt(r[0]);for(let m=1;m<r.length;++m)i=n(i,Dt(r[m]));return r.length>1&&t?ie.create(i):i}function po(r){return r==="is"||r==="is not"}function Mt(r){return Ie(r)||ze(r)}function Gr(r){if(p(r)&&dt.includes(r))return v.create(r);if(f(r))return r.toOperationNode();throw new Error(`invalid operator ${JSON.stringify(r)}`)}function Dt(r){return f(r)?r.toOperationNode():r}function ue(r,e){if(e.length===3)return No(r,e[0],e[1],e[2]);if(e.length===2)return lo(r,e[0],e[1]);if(e.length===1)return yo(r,e[0]);throw new Error("not implemented")}function lo(r,e,t){return t(bt(r,e)).toOperationNode()}function No(r,e,t,n){return Q.createWithOn(r,ce(e),S(t,"=",n))}function yo(r,e){return Q.create(r,ce(e))}var Se=o({is(r){return r.kind==="LimitNode"},create(r){return o({kind:"LimitNode",limit:r})}});var Pt=o({is(r){return r.kind==="OffsetNode"},create(r){return o({kind:"OffsetNode",offset:r})}});var Qt=o({is(r){return r.kind==="GroupByItemNode"},create(r){return o({kind:"GroupByItemNode",groupBy:r})}});function vt(r){return r=x(r)?r(I()):r,re(r).map(Qt.create)}var D=class extends Error{node;constructor(e){super("no result"),this.node=e}};function Y(r){return Object.prototype.hasOwnProperty.call(r,"prototype")}var zt=o({is(r){return r.kind==="SetOperationNode"},create(r,e,t){return o({kind:"SetOperationNode",operator:r,expression:e,all:t})}});function he(r,e,t){return x(e)&&(e=e(mr())),C(e)||(e=[e]),e.map(n=>zt.create(r,H(n),t))}var It=o({is(r){return r.kind==="FetchNode"},create(r,e){return{kind:"FetchNode",rowCount:F.create(r),modifier:e}}});function Ut(r,e){if(!pe(r)&&!Ue(r))throw new Error(`Invalid fetch row count: ${r}`);if(!wo(e))throw new Error(`Invalid fetch modifier: ${e}`);return It.create(r,e)}function wo(r){return r==="only"||r==="with ties"}var Vt=o({is(r){return r.kind==="TopNode"},create(r,e){return o({kind:"TopNode",expression:r,modifiers:e})}});function $(r,e){if(!pe(r)&&!Ue(r))throw new Error(`Invalid top expression: ${r}`);if(!M(e)&&!Oo(e))throw new Error(`Invalid top modifiers: ${e}`);return Vt.create(r,e)}function Oo(r){return r==="percent"||r==="with ties"||r==="percent with ties"}var jr=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}get isSelectQueryBuilder(){return!0}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}having(...e){return new r({...this.#e,queryNode:d.cloneWithHaving(this.#e.queryNode,h(e))})}havingRef(e,t,n){return new r({...this.#e,queryNode:d.cloneWithHaving(this.#e.queryNode,S(e,t,n))})}select(e){return new r({...this.#e,queryNode:d.cloneWithSelections(this.#e.queryNode,O(e))})}distinctOn(e){return new r({...this.#e,queryNode:d.cloneWithDistinctOn(this.#e.queryNode,re(e))})}modifyFront(e){return new r({...this.#e,queryNode:d.cloneWithFrontModifier(this.#e.queryNode,G.createWithExpression(e.toOperationNode()))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.createWithExpression(e.toOperationNode()))})}distinct(){return new r({...this.#e,queryNode:d.cloneWithFrontModifier(this.#e.queryNode,G.create("Distinct"))})}forUpdate(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForUpdate",e?Re(e).map(N):void 0))})}forShare(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForShare",e?Re(e).map(N):void 0))})}forKeyShare(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForKeyShare",e?Re(e).map(N):void 0))})}forNoKeyUpdate(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("ForNoKeyUpdate",e?Re(e).map(N):void 0))})}skipLocked(){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("SkipLocked"))})}noWait(){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,G.create("NoWait"))})}selectAll(e){return new r({...this.#e,queryNode:d.cloneWithSelections(this.#e.queryNode,W(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}crossJoin(...e){return this.#r("CrossJoin",e)}innerJoinLateral(...e){return this.#r("LateralInnerJoin",e)}leftJoinLateral(...e){return this.#r("LateralLeftJoin",e)}crossJoinLateral(...e){return this.#r("LateralCrossJoin",e)}crossApply(...e){return this.#r("CrossApply",e)}outerApply(...e){return this.#r("OuterApply",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}groupBy(e){return new r({...this.#e,queryNode:d.cloneWithGroupByItems(this.#e.queryNode,vt(e))})}limit(e){return new r({...this.#e,queryNode:d.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}offset(e){return new r({...this.#e,queryNode:d.cloneWithOffset(this.#e.queryNode,Pt.create(c(e)))})}fetch(e,t="only"){return new r({...this.#e,queryNode:d.cloneWithFetch(this.#e.queryNode,Ut(e,t))})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}union(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("union",e,!1))})}unionAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("union",e,!0))})}intersect(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("intersect",e,!1))})}intersectAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("intersect",e,!0))})}except(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("except",e,!1))})}exceptAll(e){return new r({...this.#e,queryNode:d.cloneWithSetOperations(this.#e.queryNode,he("except",e,!0))})}as(e){return new Kr(this,e)}clearSelect(){return new r({...this.#e,queryNode:d.cloneWithoutSelections(this.#e.queryNode)})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:d.cloneWithoutLimit(this.#e.queryNode)})}clearOffset(){return new r({...this.#e,queryNode:d.cloneWithoutOffset(this.#e.queryNode)})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}clearGroupBy(){return new r({...this.#e,queryNode:d.cloneWithoutGroupBy(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}$asTuple(){return new a(this.toOperationNode())}$asScalar(){return new a(this.toOperationNode())}withPlugin(e){return new r({...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(){let e=this.compile();return(await this.#e.executor.executeQuery(e)).rows}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};function De(r){return new jr(r)}var Kr=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}get isAliasedSelectQueryBuilder(){return!0}toOperationNode(){return g.create(this.#e.toOperationNode(),u.create(this.#r))}};var Jt=o({is(r){return r.kind==="ValuesNode"},create(r){return o({kind:"ValuesNode",values:o(r)})}});var $t=o({is(r){return r.kind==="DefaultInsertValueNode"},create(){return o({kind:"DefaultInsertValueNode"})}});function cr(r){let e=x(r)?r(I()):r,t=C(e)?e:o([e]);return xo(t)}function xo(r){let e=go(r);return[o([...e.keys()].map(E.create)),Jt.create(r.map(t=>Wo(t,e)))]}function go(r){let e=new Map;for(let t of r){let n=Object.keys(t);for(let i of n)!e.has(i)&&t[i]!==void 0&&e.set(i,e.size)}return e}function Wo(r,e){let t=Object.keys(r),n=Array.from({length:e.size}),i=!1,m=t.length;for(let ve of t){let Ee=e.get(ve);if(M(Ee)){m--;continue}let gr=r[ve];(M(gr)||ee(gr))&&(i=!0),n[Ee]=gr}if(m<e.size||i){let ve=$t.create();return or.create(n.map(Ee=>M(Ee)?ve:c(Ee)))}return tr.create(n)}var Hr=o({is(r){return r.kind==="ColumnUpdateNode"},create(r,e){return o({kind:"ColumnUpdateNode",column:r,value:e})}});function Gt(...r){return r.length===2?[Hr.create(k(r[0]),c(r[1]))]:Me(r[0])}function Me(r){let e=x(r)?r(I()):r;return Object.entries(e).filter(([t,n])=>n!==void 0).map(([t,n])=>Hr.create(E.create(t),c(n)))}var jt=o({is(r){return r.kind==="OnDuplicateKeyNode"},create(r){return o({kind:"OnDuplicateKeyNode",updates:r})}});var hr=class{insertId;numInsertedOrUpdatedRows;constructor(e,t){this.insertId=e,this.numInsertedOrUpdatedRows=t}};var R=o({is(r){return r.kind==="OnConflictNode"},create(){return o({kind:"OnConflictNode"})},cloneWith(r,e){return o({...r,...e})},cloneWithIndexWhere(r,e){return o({...r,indexWhere:r.indexWhere?b.cloneWithOperation(r.indexWhere,"And",e):b.create(e)})},cloneWithIndexOrWhere(r,e){return o({...r,indexWhere:r.indexWhere?b.cloneWithOperation(r.indexWhere,"Or",e):b.create(e)})},cloneWithUpdateWhere(r,e){return o({...r,updateWhere:r.updateWhere?b.cloneWithOperation(r.updateWhere,"And",e):b.create(e)})},cloneWithUpdateOrWhere(r,e){return o({...r,updateWhere:r.updateWhere?b.cloneWithOperation(r.updateWhere,"Or",e):b.create(e)})},cloneWithoutIndexWhere(r){return o({...r,indexWhere:void 0})},cloneWithoutUpdateWhere(r){return o({...r,updateWhere:void 0})}});var fr=class r{#e;constructor(e){this.#e=o(e)}column(e){let t=E.create(e);return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,t]):o([t])})})}columns(e){let t=e.map(E.create);return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{columns:this.#e.onConflictNode.columns?o([...this.#e.onConflictNode.columns,...t]):o(t)})})}constraint(e){return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{constraint:u.create(e)})})}expression(e){return new r({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{indexExpression:e.toOperationNode()})})}where(...e){return new r({...this.#e,onConflictNode:R.cloneWithIndexWhere(this.#e.onConflictNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:R.cloneWithIndexWhere(this.#e.onConflictNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:R.cloneWithoutIndexWhere(this.#e.onConflictNode)})}doNothing(){return new Yr({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{doNothing:!0})})}doUpdateSet(e){return new Xr({...this.#e,onConflictNode:R.cloneWith(this.#e.onConflictNode,{updates:Me(e)})})}$call(e){return e(this)}},Yr=class{#e;constructor(e){this.#e=o(e)}toOperationNode(){return this.#e.onConflictNode}},Xr=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,onConflictNode:R.cloneWithUpdateWhere(this.#e.onConflictNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,onConflictNode:R.cloneWithUpdateWhere(this.#e.onConflictNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,onConflictNode:R.cloneWithoutUpdateWhere(this.#e.onConflictNode)})}$call(e){return e(this)}toOperationNode(){return this.#e.onConflictNode}};var fe=o({is(r){return r.kind==="OrActionNode"},create(r){return o({kind:"OrActionNode",action:r})}});var Pe=class r{#e;constructor(e){this.#e=o(e)}values(e){let[t,n]=cr(e);return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{columns:t,values:n})})}columns(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{columns:o(e.map(E.create))})})}expression(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{values:H(e)})})}defaultValues(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{defaultValues:!0})})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}ignore(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("ignore")})})}orIgnore(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("ignore")})})}orAbort(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("abort")})})}orFail(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("fail")})})}orReplace(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("replace")})})}orRollback(){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{orAction:fe.create("rollback")})})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}onConflict(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{onConflict:e(new fr({onConflictNode:R.create()})).toOperationNode()})})}onDuplicateKeyUpdate(e){return new r({...this.#e,queryNode:l.cloneWith(this.#e.queryNode,{onDuplicateKey:jt.create(Me(e))})})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W())})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new hr(t.insertId,t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var pr=class{numDeletedRows;constructor(e){this.numDeletedRows=e}};var lr=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}using(e){return new r({...this.#e,queryNode:ne.cloneWithUsing(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}clearLimit(){return new r({...this.#e,queryNode:ne.cloneWithoutLimit(this.#e.queryNode)})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:ne.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new pr(t.numAffectedRows??BigInt(0))]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var Nr=class{numUpdatedRows;numChangedRows;constructor(e,t){this.numUpdatedRows=e,this.numChangedRows=t}};var be=class r{#e;constructor(e){this.#e=o(e)}where(...e){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,h(e))})}whereRef(e,t,n){return new r({...this.#e,queryNode:s.cloneWithWhere(this.#e.queryNode,S(e,t,n))})}clearWhere(){return new r({...this.#e,queryNode:s.cloneWithoutWhere(this.#e.queryNode)})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}from(e){return new r({...this.#e,queryNode:j.cloneWithFromItems(this.#e.queryNode,z(e))})}innerJoin(...e){return this.#r("InnerJoin",e)}leftJoin(...e){return this.#r("LeftJoin",e)}rightJoin(...e){return this.#r("RightJoin",e)}fullJoin(...e){return this.#r("FullJoin",e)}#r(e,t){return new r({...this.#e,queryNode:s.cloneWithJoin(this.#e.queryNode,ue(e,t))})}orderBy(...e){return new r({...this.#e,queryNode:s.cloneWithOrderByItems(this.#e.queryNode,L(e))})}clearOrderBy(){return new r({...this.#e,queryNode:s.cloneWithoutOrderBy(this.#e.queryNode)})}limit(e){return new r({...this.#e,queryNode:j.cloneWithLimit(this.#e.queryNode,Se.create(c(e)))})}set(...e){return new r({...this.#e,queryNode:j.cloneWithUpdates(this.#e.queryNode,Gt(...e))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}clearReturning(){return new r({...this.#e,queryNode:s.cloneWithoutReturning(this.#e.queryNode)})}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}$castTo(){return new r(this.#e)}$narrowType(){return new r(this.#e)}$assertType(){return new r(this.#e)}withPlugin(e){return new r({...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(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new Nr(t.numAffectedRows??BigInt(0),t.numChangedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}async*stream(e=100){let t=this.compile(),n=this.#e.executor.stream(t,e);for await(let i of n)yield*i.rows}async explain(e,t){return await new r({...this.#e,queryNode:s.cloneWithExplain(this.#e.queryNode,e,t)}).execute()}};var Zr=o({is(r){return r.kind==="CommonTableExpressionNameNode"},create(r,e){return o({kind:"CommonTableExpressionNameNode",table:B.create(r),columns:e?o(e.map(E.create)):void 0})}});var ke=o({is(r){return r.kind==="CommonTableExpressionNode"},create(r,e){return o({kind:"CommonTableExpressionNode",name:r,expression:e})},cloneWith(r,e){return o({...r,...e})}});var yr=class r{#e;constructor(e){this.#e=o(e)}materialized(){return new r({...this.#e,node:ke.cloneWith(this.#e.node,{materialized:!0})})}notMaterialized(){return new r({...this.#e,node:ke.cloneWith(this.#e.node,{materialized:!1})})}toOperationNode(){return this.#e.node}};function _r(r,e){let t=e(St()).toOperationNode();return x(r)?r(So(t)).toOperationNode():ke.create(Kt(r),t)}function So(r){return e=>new yr({node:ke.create(Kt(e),r)})}function Kt(r){if(r.includes("(")){let e=r.split(/[\(\)]/),t=e[0],n=e[1].split(",").map(i=>i.trim());return Zr.create(t,n)}else return Zr.create(r)}var Qe=o({is(r){return r.kind==="WithNode"},create(r,e){return o({kind:"WithNode",expressions:o([r]),...e})},cloneWithExpression(r,e){return o({...r,expressions:o([...r.expressions,e])})}});var Ht=o({is(r){return r.kind==="MatchedNode"},create(r,e=!1){return o({kind:"MatchedNode",not:r,bySource:e})}});function et(r,e,t){return Z.create(We([Ht.create(!r.isMatched,r.bySource),...e&&e.length>0?[e.length===3&&t?S(e[0],e[1],e[2]):h(e)]:[]],"and",!1))}function Ce(r){return p(r)?y.create([r],[]):f(r)?r.toOperationNode():r}var wr=class{numChangedRows;constructor(e){this.numChangedRows=e}};var Or=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}using(...e){return new de({...this.#e,queryNode:q.cloneWithUsing(this.#e.queryNode,ue("Using",e))})}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}},de=class r{#e;constructor(e){this.#e=o(e)}modifyEnd(e){return new r({...this.#e,queryNode:s.cloneWithEndModifier(this.#e.queryNode,e.toOperationNode())})}top(e,t){return new r({...this.#e,queryNode:s.cloneWithTop(this.#e.queryNode,$(e,t))})}whenMatched(){return this.#r([])}whenMatchedAnd(...e){return this.#r(e)}whenMatchedAndRef(e,t,n){return this.#r([e,t,n],!0)}#r(e,t){return new xr({...this.#e,queryNode:q.cloneWithWhen(this.#e.queryNode,et({isMatched:!0},e,t))})}whenNotMatched(){return this.#t([])}whenNotMatchedAnd(...e){return this.#t(e)}whenNotMatchedAndRef(e,t,n){return this.#t([e,t,n],!0)}whenNotMatchedBySource(){return this.#t([],!1,!0)}whenNotMatchedBySourceAnd(...e){return this.#t(e,!1,!0)}whenNotMatchedBySourceAndRef(e,t,n){return this.#t([e,t,n],!0,!0)}returning(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,O(e))})}returningAll(e){return new r({...this.#e,queryNode:s.cloneWithReturning(this.#e.queryNode,W(e))})}output(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,O(e))})}outputAll(e){return new r({...this.#e,queryNode:s.cloneWithOutput(this.#e.queryNode,W(e))})}#t(e,t=!1,n=!1){let i={...this.#e,queryNode:q.cloneWithWhen(this.#e.queryNode,et({isMatched:!1,bySource:n},e,t))},m=n?xr:rt;return new m(i)}$call(e){return e(this)}$if(e,t){return e?t(this):new r({...this.#e})}toOperationNode(){return this.#e.executor.transformQuery(this.#e.queryNode,this.#e.queryId)}compile(){return this.#e.executor.compileQuery(this.toOperationNode(),this.#e.queryId)}async execute(){let e=this.compile(),t=await this.#e.executor.executeQuery(e),{adapter:n}=this.#e.executor,i=e.query;return i.returning&&n.supportsReturning||i.output&&n.supportsOutput?t.rows:[new wr(t.numAffectedRows)]}async executeTakeFirst(){let[e]=await this.execute();return e}async executeTakeFirstOrThrow(e=D){let t=await this.executeTakeFirst();if(t===void 0)throw Y(e)?new e(this.toOperationNode()):e(this.toOperationNode());return t}},xr=class{#e;constructor(e){this.#e=o(e)}thenDelete(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("delete"))})}thenDoNothing(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("do nothing"))})}thenUpdate(e){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce(e(new be({queryId:this.#e.queryId,executor:se,queryNode:j.createWithoutTable()}))))})}thenUpdateSet(...e){return this.thenUpdate(t=>t.set(...e))}},rt=class{#e;constructor(e){this.#e=o(e)}thenDoNothing(){return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce("do nothing"))})}thenInsertValues(e){let[t,n]=cr(e);return new de({...this.#e,queryNode:q.cloneWithThen(this.#e.queryNode,Ce(l.cloneWith(l.createWithoutInto(),{columns:t,values:n})))})}};var rr=class r{#e;constructor(e){this.#e=o(e)}selectFrom(e){return De({queryId:w(),executor:this.#e.executor,queryNode:d.createFrom(z(e),this.#e.withNode)})}selectNoFrom(e){return De({queryId:w(),executor:this.#e.executor,queryNode:d.cloneWithSelections(d.create(this.#e.withNode),O(e))})}insertInto(e){return new Pe({queryId:w(),executor:this.#e.executor,queryNode:l.create(N(e),this.#e.withNode)})}replaceInto(e){return new Pe({queryId:w(),executor:this.#e.executor,queryNode:l.create(N(e),this.#e.withNode,!0)})}deleteFrom(e){return new lr({queryId:w(),executor:this.#e.executor,queryNode:ne.create(z(e),this.#e.withNode)})}updateTable(e){return new be({queryId:w(),executor:this.#e.executor,queryNode:j.create(z(e),this.#e.withNode)})}mergeInto(e){return new Or({queryId:w(),executor:this.#e.executor,queryNode:q.create(Ar(e),this.#e.withNode)})}with(e,t){let n=_r(e,t);return new r({...this.#e,withNode:this.#e.withNode?Qe.cloneWithExpression(this.#e.withNode,n):Qe.create(n)})}withRecursive(e,t){let n=_r(e,t);return new r({...this.#e,withNode:this.#e.withNode?Qe.cloneWithExpression(this.#e.withNode,n):Qe.create(n,{recursive:!0})})}withPlugin(e){return new r({...this.#e,executor:this.#e.executor.withPlugin(e)})}withoutPlugins(){return new r({...this.#e,executor:this.#e.executor.withoutPlugins()})}withSchema(e){return new r({...this.#e,executor:this.#e.executor.withPluginAtFront(new Ne(e))})}};var tt=class r{#e;constructor(e){this.#e=o(e)}get expressionType(){}get isRawBuilder(){return!0}as(e){return new ot(this,e)}$castTo(){return new r({...this.#e})}$notNull(){return new r(this.#e)}withPlugin(e){return new r({...this.#e,plugins:this.#e.plugins!==void 0?o([...this.#e.plugins,e]):o([e])})}toOperationNode(){return this.#t(this.#r())}compile(e){return this.#n(this.#r(e))}async execute(e){let t=this.#r(e);return t.executeQuery(this.#n(t))}#r(e){let t=e!==void 0?e.getExecutor():se;return this.#e.plugins!==void 0?t.withPlugins(this.#e.plugins):t}#t(e){return e.transformQuery(this.#e.rawNode,this.#e.queryId)}#n(e){return e.compileQuery(this.#t(e),this.#e.queryId)}};function te(r){return new tt(r)}var ot=class{#e;#r;constructor(e,t){this.#e=e,this.#r=t}get expression(){return this.#e}get alias(){return this.#r}get rawBuilder(){return this.#e}toOperationNode(){return g.create(this.#e.toOperationNode(),f(this.#r)?this.#r.toOperationNode():u.create(this.#r))}};var bo=Object.assign((r,...e)=>te({queryId:w(),rawNode:y.create(r,e?.map(Yt)??[])}),{ref(r){return te({queryId:w(),rawNode:y.createWithChild(V(r))})},val(r){return te({queryId:w(),rawNode:y.createWithChild(c(r))})},value(r){return this.val(r)},table(r){return te({queryId:w(),rawNode:y.createWithChild(N(r))})},id(...r){let e=new Array(r.length+1).fill(".");return e[0]="",e[e.length-1]="",te({queryId:w(),rawNode:y.create(e,r.map(u.create))})},lit(r){return te({queryId:w(),rawNode:y.createWithChild(F.createImmediate(r))})},literal(r){return this.lit(r)},raw(r){return te({queryId:w(),rawNode:y.createWithSql(r)})},join(r,e=bo`, `){let t=new Array(Math.max(2*r.length-1,0)),n=e.toOperationNode();for(let i=0;i<r.length;++i)t[2*i]=Yt(r[i]),i!==r.length-1&&(t[2*i+1]=n);return te({queryId:w(),rawNode:y.createWithChildren(t)})}});function Yt(r){return f(r)?r.toOperationNode():c(r)}export{M as a,p as b,pe as c,ze as d,Ie as e,ko as f,Ue as g,Co as h,x as i,X as j,o as k,Eo as l,u as m,Ae as n,f as o,v as p,E as q,je as r,lt as s,y as t,le as u,V as v,co as w,Ud as x,or as y,F as z,ie as A,h as B,l as C,Z as D,s as E,d as F,st as G,w as H,$e as I,Ne as J,Be as K,at as L,er as M,rr as N,zt as O,Ct as P,J as Q,ir as R,qt as S,H as T,ht as U,N as V,bo as W};
|