@dbml/core 8.0.0-alpha.7 → 8.0.0-alpha.9

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/lib/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(e&&(t=e(e=0)),t),s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n&&t(r,Symbol.toStringTag,{value:`Module`}),r},l=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},u=(n,r,a)=>(a=n==null?{}:e(i(n)),l(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n)),d=e=>a.call(e,`module.exports`)?e[`module.exports`]:l(t({},`__esModule`,{value:!0}),e),f,p,m=o((()=>{f=typeof global==`object`&&global&&global.Object===Object&&global,p=f})),h,g,_,ee=o((()=>{m(),h=typeof self==`object`&&self&&self.Object===Object&&self,g=p||h||Function(`return this`)(),_=g})),te,ne,v=o((()=>{ee(),te=_.Symbol,ne=te}));function re(e){var t=ae.call(e,se),n=e[se];try{e[se]=void 0;var r=!0}catch{}var i=oe.call(e);return r&&(t?e[se]=n:delete e[se]),i}var ie,ae,oe,se,ce,le=o((()=>{v(),ie=Object.prototype,ae=ie.hasOwnProperty,oe=ie.toString,se=ne?ne.toStringTag:void 0,ce=re}));function ue(e){return de.call(e)}var de,fe,pe=o((()=>{de=Object.prototype.toString,fe=ue}));function me(e){return e==null?e===void 0?ge:he:_e&&_e in Object(e)?ce(e):fe(e)}var he,ge,_e,ve,ye=o((()=>{v(),le(),pe(),he=`[object Null]`,ge=`[object Undefined]`,_e=ne?ne.toStringTag:void 0,ve=me}));function be(e){return typeof e==`object`&&!!e}var xe,Se=o((()=>{xe=be}));function Ce(e){return typeof e==`symbol`||xe(e)&&ve(e)==we}var we,Te,Ee=o((()=>{ye(),Se(),we=`[object Symbol]`,Te=Ce}));function De(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var Oe,ke=o((()=>{Oe=De})),Ae,je,Me=o((()=>{Ae=Array.isArray,je=Ae}));function Ne(e){if(typeof e==`string`)return e;if(je(e))return Oe(e,Ne)+``;if(Te(e))return Ie?Ie.call(e):``;var t=e+``;return t==`0`&&1/e==-Pe?`-0`:t}var Pe,Fe,Ie,Le,Re=o((()=>{v(),ke(),Me(),Ee(),Pe=1/0,Fe=ne?ne.prototype:void 0,Ie=Fe?Fe.toString:void 0,Le=Ne}));function ze(e){for(var t=e.length;t--&&Be.test(e.charAt(t)););return t}var Be,Ve,He=o((()=>{Be=/\s/,Ve=ze}));function Ue(e){return e&&e.slice(0,Ve(e)+1).replace(We,``)}var We,Ge,Ke=o((()=>{He(),We=/^\s+/,Ge=Ue}));function qe(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var Je,Ye=o((()=>{Je=qe}));function Xe(e){if(typeof e==`number`)return e;if(Te(e))return Ze;if(Je(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Je(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Ge(e);var n=$e.test(e);return n||et.test(e)?tt(e.slice(2),n?2:8):Qe.test(e)?Ze:+e}var Ze,Qe,$e,et,tt,nt,rt=o((()=>{Ke(),Ye(),Ee(),Ze=NaN,Qe=/^[-+]0x[0-9a-f]+$/i,$e=/^0b[01]+$/i,et=/^0o[0-7]+$/i,tt=parseInt,nt=Xe}));function it(e){return e?(e=nt(e),e===at||e===-at?(e<0?-1:1)*ot:e===e?e:0):e===0?e:0}var at,ot,st,ct=o((()=>{rt(),at=1/0,ot=17976931348623157e292,st=it}));function lt(e){var t=st(e),n=t%1;return t===t?n?t-n:t:0}var ut,dt=o((()=>{ct(),ut=lt}));function ft(e){return e}var pt,mt=o((()=>{pt=ft}));function ht(e){if(!Je(e))return!1;var t=ve(e);return t==_t||t==vt||t==gt||t==yt}var gt,_t,vt,yt,bt,xt=o((()=>{ye(),Ye(),gt=`[object AsyncFunction]`,_t=`[object Function]`,vt=`[object GeneratorFunction]`,yt=`[object Proxy]`,bt=ht})),St,y,Ct=o((()=>{ee(),St=_[`__core-js_shared__`],y=St}));function wt(e){return!!Tt&&Tt in e}var Tt,Et,Dt=o((()=>{Ct(),Tt=function(){var e=/[^.]+$/.exec(y&&y.keys&&y.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}(),Et=wt}));function Ot(e){if(e!=null){try{return kt.call(e)}catch{}try{return e+``}catch{}}return``}var kt,At,jt=o((()=>{kt=Function.prototype.toString,At=Ot}));function Mt(e){return!Je(e)||Et(e)?!1:(bt(e)?zt:Pt).test(At(e))}var Nt,Pt,Ft,It,Lt,Rt,zt,Bt,Vt=o((()=>{xt(),Dt(),Ye(),jt(),Nt=/[\\^$.*+?()[\]{}|]/g,Pt=/^\[object .+?Constructor\]$/,Ft=Function.prototype,It=Object.prototype,Lt=Ft.toString,Rt=It.hasOwnProperty,zt=RegExp(`^`+Lt.call(Rt).replace(Nt,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`),Bt=Mt}));function Ht(e,t){return e?.[t]}var Ut,Wt=o((()=>{Ut=Ht}));function Gt(e,t){var n=Ut(e,t);return Bt(n)?n:void 0}var Kt,qt=o((()=>{Vt(),Wt(),Kt=Gt})),Jt,Yt,Xt=o((()=>{qt(),ee(),Jt=Kt(_,`WeakMap`),Yt=Jt}));function Zt(e,t){var n=-1,r=e.length;for(t||=Array(r);++n<r;)t[n]=e[n];return t}var Qt,$t=o((()=>{Qt=Zt})),en,tn,nn=o((()=>{qt(),en=function(){try{var e=Kt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),tn=en}));function rn(e,t){for(var n=-1,r=e==null?0:e.length;++n<r&&t(e[n],n,e)!==!1;);return e}var an,on=o((()=>{an=rn}));function sn(e,t){var n=typeof e;return t??=cn,!!t&&(n==`number`||n!=`symbol`&&ln.test(e))&&e>-1&&e%1==0&&e<t}var cn,ln,un,dn=o((()=>{cn=9007199254740991,ln=/^(?:0|[1-9]\d*)$/,un=sn}));function fn(e,t,n){t==`__proto__`&&tn?tn(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var pn,mn=o((()=>{nn(),pn=fn}));function hn(e,t){return e===t||e!==e&&t!==t}var gn,_n=o((()=>{gn=hn}));function vn(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=yn}var yn,bn,xn=o((()=>{yn=9007199254740991,bn=vn}));function Sn(e){return e!=null&&bn(e.length)&&!bt(e)}var Cn,wn=o((()=>{xt(),xn(),Cn=Sn}));function Tn(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||En)}var En,Dn,On=o((()=>{En=Object.prototype,Dn=Tn}));function kn(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var An,jn=o((()=>{An=kn}));function Mn(e){return xe(e)&&ve(e)==Nn}var Nn,Pn,Fn=o((()=>{ye(),Se(),Nn=`[object Arguments]`,Pn=Mn})),In,Ln,Rn,zn,Bn,Vn=o((()=>{Fn(),Se(),In=Object.prototype,Ln=In.hasOwnProperty,Rn=In.propertyIsEnumerable,zn=Pn(function(){return arguments}())?Pn:function(e){return xe(e)&&Ln.call(e,`callee`)&&!Rn.call(e,`callee`)},Bn=zn}));function Hn(){return!1}var Un,Wn=o((()=>{Un=Hn})),Gn,Kn,qn,Jn,Yn,Xn=o((()=>{ee(),Wn(),Gn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Kn=Gn&&typeof module==`object`&&module&&!module.nodeType&&module,qn=Kn&&Kn.exports===Gn?_.Buffer:void 0,Jn=(qn?qn.isBuffer:void 0)||Un,Yn=Jn}));function Zn(e){return xe(e)&&bn(e.length)&&!!Sr[ve(e)]}var Qn,$n,er,tr,nr,rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr=o((()=>{ye(),xn(),Se(),Qn=`[object Arguments]`,$n=`[object Array]`,er=`[object Boolean]`,tr=`[object Date]`,nr=`[object Error]`,rr=`[object Function]`,ir=`[object Map]`,ar=`[object Number]`,or=`[object Object]`,sr=`[object RegExp]`,cr=`[object Set]`,lr=`[object String]`,ur=`[object WeakMap]`,dr=`[object ArrayBuffer]`,fr=`[object DataView]`,pr=`[object Float32Array]`,mr=`[object Float64Array]`,hr=`[object Int8Array]`,gr=`[object Int16Array]`,_r=`[object Int32Array]`,vr=`[object Uint8Array]`,yr=`[object Uint8ClampedArray]`,br=`[object Uint16Array]`,xr=`[object Uint32Array]`,Sr={},Sr[pr]=Sr[mr]=Sr[hr]=Sr[gr]=Sr[_r]=Sr[vr]=Sr[yr]=Sr[br]=Sr[xr]=!0,Sr[Qn]=Sr[$n]=Sr[dr]=Sr[er]=Sr[fr]=Sr[tr]=Sr[nr]=Sr[rr]=Sr[ir]=Sr[ar]=Sr[or]=Sr[sr]=Sr[cr]=Sr[lr]=Sr[ur]=!1,Cr=Zn}));function Tr(e){return function(t){return e(t)}}var Er,Dr=o((()=>{Er=Tr})),Or,kr,Ar,jr,Mr,Nr=o((()=>{m(),Or=typeof exports==`object`&&exports&&!exports.nodeType&&exports,kr=Or&&typeof module==`object`&&module&&!module.nodeType&&module,Ar=kr&&kr.exports===Or&&p.process,jr=function(){try{return kr&&kr.require&&kr.require(`util`).types||Ar&&Ar.binding&&Ar.binding(`util`)}catch{}}(),Mr=jr})),Pr,Fr,Ir,Lr=o((()=>{wr(),Dr(),Nr(),Pr=Mr&&Mr.isTypedArray,Fr=Pr?Er(Pr):Cr,Ir=Fr}));function Rr(e,t){var n=je(e),r=!n&&Bn(e),i=!n&&!r&&Yn(e),a=!n&&!r&&!i&&Ir(e),o=n||r||i||a,s=o?An(e.length,String):[],c=s.length;for(var l in e)(t||zr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||un(l,c)))&&s.push(l);return s}var zr,Br,Vr=o((()=>{jn(),Vn(),Me(),Xn(),dn(),Lr(),zr=Object.prototype.hasOwnProperty,Br=Rr}));function Hr(e,t){return function(n){return e(t(n))}}var Ur,Wr=o((()=>{Ur=Hr})),Gr,Kr,qr=o((()=>{Wr(),Gr=Ur(Object.keys,Object),Kr=Gr}));function Jr(e){if(!Dn(e))return Kr(e);var t=[];for(var n in Object(e))Yr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Yr,Xr,Zr=o((()=>{On(),qr(),Yr=Object.prototype.hasOwnProperty,Xr=Jr}));function Qr(e){return Cn(e)?Br(e):Xr(e)}var $r,ei=o((()=>{Vr(),Zr(),wn(),$r=Qr}));function ti(e,t){if(je(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||Te(e)?!0:ri.test(e)||!ni.test(e)||t!=null&&e in Object(t)}var ni,ri,b,ii=o((()=>{Me(),Ee(),ni=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ri=/^\w*$/,b=ti})),ai,oi,si=o((()=>{qt(),ai=Kt(Object,`create`),oi=ai}));function ci(){this.__data__=oi?oi(null):{},this.size=0}var li,ui=o((()=>{si(),li=ci}));function di(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var fi,pi=o((()=>{fi=di}));function mi(e){var t=this.__data__;if(oi){var n=t[e];return n===hi?void 0:n}return gi.call(t,e)?t[e]:void 0}var hi,gi,_i,vi=o((()=>{si(),hi=`__lodash_hash_undefined__`,gi=Object.prototype.hasOwnProperty,_i=mi}));function yi(e){var t=this.__data__;return oi?t[e]!==void 0:bi.call(t,e)}var bi,x,xi=o((()=>{si(),bi=Object.prototype.hasOwnProperty,x=yi}));function Si(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=oi&&t===void 0?Ci:t,this}var Ci,wi,S=o((()=>{si(),Ci=`__lodash_hash_undefined__`,wi=Si}));function Ti(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}var Ei,Di=o((()=>{ui(),pi(),vi(),xi(),S(),Ti.prototype.clear=li,Ti.prototype.delete=fi,Ti.prototype.get=_i,Ti.prototype.has=x,Ti.prototype.set=wi,Ei=Ti}));function Oi(){this.__data__=[],this.size=0}var ki,Ai=o((()=>{ki=Oi}));function ji(e,t){for(var n=e.length;n--;)if(gn(e[n][0],t))return n;return-1}var Mi,Ni=o((()=>{_n(),Mi=ji}));function Pi(e){var t=this.__data__,n=Mi(t,e);return n<0?!1:(n==t.length-1?t.pop():Fi.call(t,n,1),--this.size,!0)}var Fi,Ii,Li=o((()=>{Ni(),Fi=Array.prototype.splice,Ii=Pi}));function Ri(e){var t=this.__data__,n=Mi(t,e);return n<0?void 0:t[n][1]}var zi,Bi=o((()=>{Ni(),zi=Ri}));function Vi(e){return Mi(this.__data__,e)>-1}var Hi,Ui=o((()=>{Ni(),Hi=Vi}));function Wi(e,t){var n=this.__data__,r=Mi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Gi,Ki=o((()=>{Ni(),Gi=Wi}));function qi(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}var Ji,Yi=o((()=>{Ai(),Li(),Bi(),Ui(),Ki(),qi.prototype.clear=ki,qi.prototype.delete=Ii,qi.prototype.get=zi,qi.prototype.has=Hi,qi.prototype.set=Gi,Ji=qi})),Xi,Zi,Qi=o((()=>{qt(),ee(),Xi=Kt(_,`Map`),Zi=Xi}));function $i(){this.size=0,this.__data__={hash:new Ei,map:new(Zi||Ji),string:new Ei}}var ea,ta=o((()=>{Di(),Yi(),Qi(),ea=$i}));function na(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var ra,ia=o((()=>{ra=na}));function aa(e,t){var n=e.__data__;return ra(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var oa,sa=o((()=>{ia(),oa=aa}));function ca(e){var t=oa(this,e).delete(e);return this.size-=t?1:0,t}var la,ua=o((()=>{sa(),la=ca}));function da(e){return oa(this,e).get(e)}var fa,pa=o((()=>{sa(),fa=da}));function ma(e){return oa(this,e).has(e)}var ha,ga=o((()=>{sa(),ha=ma}));function _a(e,t){var n=oa(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var va,ya=o((()=>{sa(),va=_a}));function ba(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}var xa,Sa=o((()=>{ta(),ua(),pa(),ga(),ya(),ba.prototype.clear=ea,ba.prototype.delete=la,ba.prototype.get=fa,ba.prototype.has=ha,ba.prototype.set=va,xa=ba}));function Ca(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(wa);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(Ca.Cache||xa),n}var wa,Ta,Ea=o((()=>{Sa(),wa=`Expected a function`,Ca.Cache=xa,Ta=Ca}));function Da(e){var t=Ta(e,function(e){return n.size===Oa&&n.clear(),e}),n=t.cache;return t}var Oa,ka,Aa=o((()=>{Ea(),Oa=500,ka=Da})),ja,Ma,Na,Pa,C=o((()=>{Aa(),ja=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Ma=/\\(\\)?/g,Na=ka(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(ja,function(e,n,r,i){t.push(r?i.replace(Ma,`$1`):n||e)}),t}),Pa=Na}));function Fa(e){return e==null?``:Le(e)}var Ia,La=o((()=>{Re(),Ia=Fa}));function Ra(e,t){return je(e)?e:b(e,t)?[e]:Pa(Ia(e))}var w,za=o((()=>{Me(),ii(),C(),La(),w=Ra}));function Ba(e){if(typeof e==`string`||Te(e))return e;var t=e+``;return t==`0`&&1/e==-Va?`-0`:t}var Va,Ha,Ua=o((()=>{Ee(),Va=1/0,Ha=Ba}));function Wa(e,t){t=w(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[Ha(t[n++])];return n&&n==r?e:void 0}var Ga,Ka=o((()=>{za(),Ua(),Ga=Wa}));function qa(e,t,n){var r=e==null?void 0:Ga(e,t);return r===void 0?n:r}var T,Ja=o((()=>{Ka(),T=qa}));function Ya(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Xa,Za=o((()=>{Xa=Ya}));function Qa(e){return je(e)||Bn(e)||!!($a&&e&&e[$a])}var $a,eo,to=o((()=>{v(),Vn(),Me(),$a=ne?ne.isConcatSpreadable:void 0,eo=Qa}));function no(e,t,n,r,i){var a=-1,o=e.length;for(n||=eo,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?no(s,t-1,n,r,i):Xa(i,s):r||(i[i.length]=s)}return i}var ro,io=o((()=>{Za(),to(),ro=no}));function ao(e){return e!=null&&e.length?ro(e,1):[]}var oo,so=o((()=>{io(),oo=ao}));function co(e,t,n){var r=-1,i=e.length;t<0&&(t=-t>i?0:i+t),n=n>i?i:n,n<0&&(n+=i),i=t>n?0:n-t>>>0,t>>>=0;for(var a=Array(i);++r<i;)a[r]=e[r+t];return a}var lo,uo=o((()=>{lo=co}));function fo(e,t,n){var r=e.length;return n=n===void 0?r:n,!t&&n>=r?e:lo(e,t,n)}var po,mo=o((()=>{uo(),po=fo}));function ho(e){return go.test(e)}var go,_o,vo=o((()=>{go=RegExp(`[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]`),_o=ho}));function yo(e){return e.split(``)}var bo,xo=o((()=>{bo=yo}));function So(e){return e.match(zo)||[]}var Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo=o((()=>{Co=`\\ud800-\\udfff`,wo=`\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff`,To=`\\ufe0e\\ufe0f`,Eo=`[`+Co+`]`,Do=`[`+wo+`]`,Oo=`\\ud83c[\\udffb-\\udfff]`,ko=`(?:`+Do+`|`+Oo+`)`,Ao=`[^`+Co+`]`,jo=`(?:\\ud83c[\\udde6-\\uddff]){2}`,Mo=`[\\ud800-\\udbff][\\udc00-\\udfff]`,No=`\\u200d`,Po=ko+`?`,Fo=`[`+To+`]?`,Io=`(?:`+No+`(?:`+[Ao,jo,Mo].join(`|`)+`)`+Fo+Po+`)*`,Lo=Fo+Po+Io,Ro=`(?:`+[Ao+Do+`?`,Do,jo,Mo,Eo].join(`|`)+`)`,zo=RegExp(Oo+`(?=`+Oo+`)|`+Ro+Lo,`g`),Bo=So}));function Ho(e){return _o(e)?Bo(e):bo(e)}var Uo,Wo=o((()=>{xo(),vo(),Vo(),Uo=Ho}));function Go(e){return function(t){t=Ia(t);var n=_o(t)?Uo(t):void 0,r=n?n[0]:t.charAt(0),i=n?po(n,1).join(``):t.slice(1);return r[e]()+i}}var Ko,qo=o((()=>{mo(),vo(),Wo(),La(),Ko=Go})),Jo,Yo,Xo=o((()=>{qo(),Jo=Ko(`toUpperCase`),Yo=Jo}));function Zo(e){return Yo(Ia(e).toLowerCase())}var Qo,$o=o((()=>{La(),Xo(),Qo=Zo}));function es(e,t,n,r){var i=-1,a=e==null?0:e.length;for(r&&a&&(n=e[++i]);++i<a;)n=t(n,e[i],i,e);return n}var ts,ns=o((()=>{ts=es}));function rs(){this.__data__=new Ji,this.size=0}var is,as=o((()=>{Yi(),is=rs}));function os(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var ss,cs=o((()=>{ss=os}));function ls(e){return this.__data__.get(e)}var us,ds=o((()=>{us=ls}));function fs(e){return this.__data__.has(e)}var ps,ms=o((()=>{ps=fs}));function hs(e,t){var n=this.__data__;if(n instanceof Ji){var r=n.__data__;if(!Zi||r.length<gs-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new xa(r)}return n.set(e,t),this.size=n.size,this}var gs,_s,vs=o((()=>{Yi(),Qi(),Sa(),gs=200,_s=hs}));function ys(e){this.size=(this.__data__=new Ji(e)).size}var bs,xs=o((()=>{Yi(),as(),cs(),ds(),ms(),vs(),ys.prototype.clear=is,ys.prototype.delete=ss,ys.prototype.get=us,ys.prototype.has=ps,ys.prototype.set=_s,bs=ys}));function Ss(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var Cs,ws=o((()=>{Cs=Ss}));function Ts(){return[]}var Es,Ds=o((()=>{Es=Ts})),Os,ks,As,js,Ms=o((()=>{ws(),Ds(),Os=Object.prototype.propertyIsEnumerable,ks=Object.getOwnPropertySymbols,As=ks?function(e){return e==null?[]:(e=Object(e),Cs(ks(e),function(t){return Os.call(e,t)}))}:Es,js=As}));function Ns(e,t,n){var r=t(e);return je(e)?r:Xa(r,n(e))}var Ps,Fs=o((()=>{Za(),Me(),Ps=Ns}));function Is(e){return Ps(e,$r,js)}var Ls,Rs=o((()=>{Fs(),Ms(),ei(),Ls=Is})),zs,Bs,Vs=o((()=>{qt(),ee(),zs=Kt(_,`DataView`),Bs=zs})),Hs,Us,Ws=o((()=>{qt(),ee(),Hs=Kt(_,`Promise`),Us=Hs})),Gs,Ks,qs=o((()=>{qt(),ee(),Gs=Kt(_,`Set`),Ks=Gs})),Js,Ys,Xs,Zs,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc=o((()=>{Vs(),Qi(),Ws(),qs(),Xt(),ye(),jt(),Js=`[object Map]`,Ys=`[object Object]`,Xs=`[object Promise]`,Zs=`[object Set]`,Qs=`[object WeakMap]`,$s=`[object DataView]`,ec=At(Bs),tc=At(Zi),nc=At(Us),rc=At(Ks),ic=At(Yt),ac=ve,(Bs&&ac(new Bs(new ArrayBuffer(1)))!=$s||Zi&&ac(new Zi)!=Js||Us&&ac(Us.resolve())!=Xs||Ks&&ac(new Ks)!=Zs||Yt&&ac(new Yt)!=Qs)&&(ac=function(e){var t=ve(e),n=t==Ys?e.constructor:void 0,r=n?At(n):``;if(r)switch(r){case ec:return $s;case tc:return Js;case nc:return Xs;case rc:return Zs;case ic:return Qs}return t}),oc=ac})),cc,lc,uc=o((()=>{ee(),cc=_.Uint8Array,lc=cc}));function dc(){var e=arguments.length;if(!e)return[];for(var t=Array(e-1),n=arguments[0],r=e;r--;)t[r-1]=arguments[r];return Xa(je(n)?Qt(n):[n],ro(t,1))}var fc,pc=o((()=>{Za(),io(),$t(),Me(),fc=dc}));function mc(e){return this.__data__.set(e,hc),this}var hc,gc,_c=o((()=>{hc=`__lodash_hash_undefined__`,gc=mc}));function vc(e){return this.__data__.has(e)}var yc,eee=o((()=>{yc=vc}));function bc(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new xa;++t<n;)this.add(e[t])}var xc,Sc=o((()=>{Sa(),_c(),eee(),bc.prototype.add=bc.prototype.push=gc,bc.prototype.has=yc,xc=bc}));function Cc(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}var wc,Tc=o((()=>{wc=Cc}));function Ec(e,t){return e.has(t)}var Dc,Oc=o((()=>{Dc=Ec}));function kc(e,t,n,r,i,a){var o=n&Ac,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&jc?new xc:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var g=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(g!==void 0){if(g)continue;f=!1;break}if(p){if(!wc(t,function(e,t){if(!Dc(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var Ac,jc,Mc,Nc=o((()=>{Sc(),Tc(),Oc(),Ac=1,jc=2,Mc=kc}));function Pc(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Fc,tee=o((()=>{Fc=Pc}));function Ic(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Lc,Rc=o((()=>{Lc=Ic}));function zc(e,t,n,r,i,a,o){switch(n){case Qc:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case Zc:return!(e.byteLength!=t.byteLength||!a(new lc(e),new lc(t)));case Hc:case Uc:case Kc:return gn(+e,+t);case Wc:return e.name==t.name&&e.message==t.message;case qc:case Yc:return e==t+``;case Gc:var s=Fc;case Jc:var c=r&Bc;if(s||=Lc,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Vc,o.set(e,t);var u=Mc(s(e),s(t),r,i,a,o);return o.delete(e),u;case Xc:if(el)return el.call(e)==el.call(t)}return!1}var Bc,Vc,Hc,Uc,Wc,Gc,Kc,qc,Jc,Yc,Xc,Zc,Qc,$c,el,tl,nee=o((()=>{v(),uc(),_n(),Nc(),tee(),Rc(),Bc=1,Vc=2,Hc=`[object Boolean]`,Uc=`[object Date]`,Wc=`[object Error]`,Gc=`[object Map]`,Kc=`[object Number]`,qc=`[object RegExp]`,Jc=`[object Set]`,Yc=`[object String]`,Xc=`[object Symbol]`,Zc=`[object ArrayBuffer]`,Qc=`[object DataView]`,$c=ne?ne.prototype:void 0,el=$c?$c.valueOf:void 0,tl=zc}));function ree(e,t,n,r,i,a){var o=n&nl,s=Ls(e),c=s.length;if(c!=Ls(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:rl.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],g=t[u];if(r)var _=o?r(g,h,u,t,e,a):r(h,g,u,e,t,a);if(!(_===void 0?h===g||i(h,g,n,r,a):_)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ee=e.constructor,te=t.constructor;ee!=te&&`constructor`in e&&`constructor`in t&&!(typeof ee==`function`&&ee instanceof ee&&typeof te==`function`&&te instanceof te)&&(p=!1)}return a.delete(e),a.delete(t),p}var nl,rl,il,al=o((()=>{Rs(),nl=1,rl=Object.prototype.hasOwnProperty,il=ree}));function ol(e,t,n,r,i,a){var o=je(e),s=je(t),c=o?ll:oc(e),l=s?ll:oc(t);c=c==cl?ul:c,l=l==cl?ul:l;var u=c==ul,d=l==ul,f=c==l;if(f&&Yn(e)){if(!Yn(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new bs,o||Ir(e)?Mc(e,t,n,r,i,a):tl(e,t,c,n,r,i,a);if(!(n&sl)){var p=u&&dl.call(e,`__wrapped__`),m=d&&dl.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,g=m?t.value():t;return a||=new bs,i(h,g,n,r,a)}}return f?(a||=new bs,il(e,t,n,r,i,a)):!1}var sl,cl,ll,ul,dl,fl,pl=o((()=>{xs(),Nc(),nee(),al(),sc(),Me(),Xn(),Lr(),sl=1,cl=`[object Arguments]`,ll=`[object Array]`,ul=`[object Object]`,dl=Object.prototype.hasOwnProperty,fl=ol}));function ml(e,t,n,r,i){return e===t?!0:e==null||t==null||!xe(e)&&!xe(t)?e!==e&&t!==t:fl(e,t,n,r,ml,i)}var hl,gl=o((()=>{pl(),Se(),hl=ml}));function _l(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new bs;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?hl(u,l,vl|yl,r,d):f))return!1}}return!0}var vl,yl,bl,xl=o((()=>{xs(),gl(),vl=1,yl=2,bl=_l}));function iee(e){return e===e&&!Je(e)}var Sl,E=o((()=>{Ye(),Sl=iee}));function Cl(e){for(var t=$r(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Sl(i)]}return t}var wl,Tl=o((()=>{E(),ei(),wl=Cl}));function El(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var D,Dl=o((()=>{D=El}));function Ol(e){var t=wl(e);return t.length==1&&t[0][2]?D(t[0][0],t[0][1]):function(n){return n===e||bl(n,e,t)}}var kl,Al=o((()=>{xl(),Tl(),Dl(),kl=Ol}));function jl(e,t){return e!=null&&t in Object(e)}var Ml,Nl=o((()=>{Ml=jl}));function Pl(e,t,n){t=w(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=Ha(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&bn(i)&&un(o,i)&&(je(e)||Bn(e)))}var Fl,Il=o((()=>{za(),Vn(),Me(),dn(),xn(),Ua(),Fl=Pl}));function O(e,t){return e!=null&&Fl(e,t,Ml)}var Ll,Rl=o((()=>{Nl(),Il(),Ll=O}));function zl(e,t){return b(e)&&Sl(t)?D(Ha(e),t):function(n){var r=T(n,e);return r===void 0&&r===t?Ll(n,e):hl(t,r,Bl|Vl)}}var Bl,Vl,Hl,Ul=o((()=>{gl(),Ja(),Rl(),ii(),E(),Dl(),Ua(),Bl=1,Vl=2,Hl=zl}));function aee(e){return function(t){return t?.[e]}}var Wl,oee=o((()=>{Wl=aee}));function Gl(e){return function(t){return Ga(t,e)}}var Kl,ql=o((()=>{Ka(),Kl=Gl}));function Jl(e){return b(e)?Wl(Ha(e)):Kl(e)}var Yl,Xl=o((()=>{oee(),ql(),ii(),Ua(),Yl=Jl}));function Zl(e){return typeof e==`function`?e:e==null?pt:typeof e==`object`?je(e)?Hl(e[0],e[1]):kl(e):Yl(e)}var Ql,$l=o((()=>{Al(),Ul(),mt(),Me(),Xl(),Ql=Zl}));function eu(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}var tu,nu=o((()=>{tu=eu}));function ru(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var iu,au=o((()=>{iu=ru})),ou,su,cu=o((()=>{au(),ou=iu(),su=ou}));function lu(e,t){return e&&su(e,t,$r)}var uu,du=o((()=>{cu(),ei(),uu=lu}));function fu(e,t){return function(n,r){if(n==null)return n;if(!Cn(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var pu,mu=o((()=>{wn(),pu=fu})),hu,gu,_u=o((()=>{du(),mu(),hu=pu(uu),gu=hu}));function vu(e,t,n,r){return gu(e,function(e,i,a){t(r,e,n(e),a)}),r}var yu,bu=o((()=>{_u(),yu=vu}));function xu(e,t){return function(n,r){var i=je(n)?tu:yu,a=t?t():{};return i(n,e,Ql(r,2),a)}}var Su,Cu=o((()=>{nu(),bu(),$l(),Me(),Su=xu}));function wu(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var Tu,Eu=o((()=>{Tu=wu}));function Du(e){return typeof e==`function`?e:pt}var Ou,ku=o((()=>{mt(),Ou=Du}));function Au(e,t){return(je(e)?an:gu)(e,Ou(t))}var ju,Mu=o((()=>{on(),_u(),ku(),Me(),ju=Au}));function Nu(e){return e&&e.length?e[0]:void 0}var Pu,Fu=o((()=>{Pu=Nu})),Iu=o((()=>{Fu()}));function Lu(e){return e!=null&&e.length?ro(e,Ru):[]}var Ru,zu,Bu=o((()=>{io(),Ru=1/0,zu=Lu}));function Vu(e,t){return e!=null&&e.length?(t=t===void 0?1:ut(t),ro(e,t)):[]}var Hu,Uu=o((()=>{io(),dt(),Hu=Vu})),Wu,Gu,Ku,see=o((()=>{mn(),Cu(),Wu=Object.prototype.hasOwnProperty,Gu=Su(function(e,t,n){Wu.call(e,n)?e[n].push(t):pn(e,n,[t])}),Ku=Gu}));function qu(e){if(e==null)return!0;if(Cn(e)&&(je(e)||typeof e==`string`||typeof e.splice==`function`||Yn(e)||Ir(e)||Bn(e)))return!e.length;var t=oc(e);if(t==Ju||t==Yu)return!e.size;if(Dn(e))return!Xr(e).length;for(var n in e)if(Xu.call(e,n))return!1;return!0}var Ju,Yu,Xu,Zu,Qu=o((()=>{Zr(),sc(),Vn(),Me(),wn(),Xn(),On(),Lr(),Ju=`[object Map]`,Yu=`[object Set]`,Xu=Object.prototype.hasOwnProperty,Zu=qu}));function $u(e){return e==null}var ed,td=o((()=>{ed=$u}));function nd(e,t){var n=e.length;if(n)return t+=t<0?n:0,un(t,n)?e[t]:void 0}var rd,id=o((()=>{dn(),rd=nd}));function ad(e,t){return e&&e.length?rd(e,ut(t)):void 0}var od,sd=o((()=>{id(),dt(),od=ad}));function cd(e,t,n,r,i){return i(e,function(e,i,a){n=r?(r=!1,e):t(n,e,i,a)}),n}var ld,ud=o((()=>{ld=cd}));function dd(e,t,n){var r=je(e)?ts:ld,i=arguments.length<3;return r(e,Ql(t,4),n,i,gu)}var fd,pd=o((()=>{ns(),_u(),$l(),ud(),Me(),fd=dd})),md=o((()=>{$o(),pc(),Iu(),so(),Bu(),Uu(),Mu(),Ja(),see(),Qu(),td(),Eu(),sd(),pd()}));md();var hd=Symbol(`PASS_THROUGH`),gd=Symbol(`UNHANDLED`),k=class e{static create(t,n,r){return new e(t,n,r)}constructor(e,t,n){this.value=e,this.errors=t===void 0?[]:t,n?.length&&(this.warnings=n)}filter(t){return this.value===t?new e(void 0,this.errors,this.warnings):this}hasValue(e){return this.value===e}getFiltered(...e){return e.includes(this.value)?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chainFiltered(t,...n){if(n.includes(this.value))return new e(void 0,this.errors,this.warnings);let r=t(this.value),i=[...this.errors,...r.errors],a=[...this.getWarnings(),...r.getWarnings()];return new e(r.value,i,a)}chain(t){let n=t(this.value),r=[...this.errors,...n.errors],i=[...this.getWarnings(),...n.getWarnings()];return new e(n.value,r,i)}mapFiltered(t,...n){return n.includes(this.value)?new e(void 0,this.errors,this.warnings):new e(t(this.value),this.errors,this.warnings)}map(t){return new e(t(this.value),this.errors,this.warnings)}},_d=function(e){return e.Table=`table`,e.Enum=`enum`,e.Ref=`ref`,e.Note=`note`,e.Project=`project`,e.Indexes=`indexes`,e.TableGroup=`tablegroup`,e.TablePartial=`tablepartial`,e.Checks=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e.DiagramViewTables=`tables`,e.DiagramViewNotes=`notes`,e.DiagramViewTableGroups=`tablegroups`,e.DiagramViewSchemas=`schemas`,e}({}),vd=function(e){return e.Color=`color`,e.HeaderColor=`headercolor`,e.Note=`note`,e.PK=`pk`,e.PrimaryKey=`primary key`,e.Unique=`unique`,e.Ref=`ref`,e.NotNull=`not null`,e.Null=`null`,e.Increment=`increment`,e.Default=`default`,e.Name=`name`,e.Type=`type`,e.Check=`check`,e.Update=`update`,e.Delete=`delete`,e}({}),yd=typeof global==`object`&&global&&global.Object===Object&&global,bd=typeof self==`object`&&self&&self.Object===Object&&self,xd=yd||bd||Function(`return this`)(),Sd=xd.Symbol,Cd=Object.prototype,wd=Cd.hasOwnProperty,Td=Cd.toString,Ed=Sd?Sd.toStringTag:void 0;function Dd(e){var t=wd.call(e,Ed),n=e[Ed];try{e[Ed]=void 0;var r=!0}catch{}var i=Td.call(e);return r&&(t?e[Ed]=n:delete e[Ed]),i}var Od=Dd,kd=Object.prototype.toString;function cee(e){return kd.call(e)}var Ad=cee,lee=`[object Null]`,jd=`[object Undefined]`,Md=Sd?Sd.toStringTag:void 0;function Nd(e){return e==null?e===void 0?jd:lee:Md&&Md in Object(e)?Od(e):Ad(e)}var Pd=Nd;function Fd(e){return typeof e==`object`&&!!e}var Id=Fd,Ld=`[object Symbol]`;function Rd(e){return typeof e==`symbol`||Id(e)&&Pd(e)==Ld}var zd=Rd;function Bd(e,t){for(var n=-1,r=e==null?0:e.length,i=Array(r);++n<r;)i[n]=t(e[n],n,e);return i}var Vd=Bd,Hd=Array.isArray,Ud=1/0,Wd=Sd?Sd.prototype:void 0,Gd=Wd?Wd.toString:void 0;function Kd(e){if(typeof e==`string`)return e;if(Hd(e))return Vd(e,Kd)+``;if(zd(e))return Gd?Gd.call(e):``;var t=e+``;return t==`0`&&1/e==-Ud?`-0`:t}var qd=Kd,Jd=/\s/;function Yd(e){for(var t=e.length;t--&&Jd.test(e.charAt(t)););return t}var Xd=Yd,Zd=/^\s+/;function Qd(e){return e&&e.slice(0,Xd(e)+1).replace(Zd,``)}var $d=Qd;function ef(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var tf=ef,nf=NaN,rf=/^[-+]0x[0-9a-f]+$/i,af=/^0b[01]+$/i,of=/^0o[0-7]+$/i,sf=parseInt;function A(e){if(typeof e==`number`)return e;if(zd(e))return nf;if(tf(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=tf(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=$d(e);var n=af.test(e);return n||of.test(e)?sf(e.slice(2),n?2:8):rf.test(e)?nf:+e}var j=A,cf=1/0,lf=17976931348623157e292;function uf(e){return e?(e=j(e),e===cf||e===-cf?(e<0?-1:1)*lf:e===e?e:0):e===0?e:0}var df=uf;function ff(e){var t=df(e),n=t%1;return t===t?n?t-n:t:0}var pf=ff;function mf(e){return e}var hf=mf,gf=`[object AsyncFunction]`,_f=`[object Function]`,vf=`[object GeneratorFunction]`,yf=`[object Proxy]`;function bf(e){if(!tf(e))return!1;var t=Pd(e);return t==_f||t==vf||t==gf||t==yf}var xf=bf,Sf=xd[`__core-js_shared__`],Cf=function(){var e=/[^.]+$/.exec(Sf&&Sf.keys&&Sf.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function uee(e){return!!Cf&&Cf in e}var wf=uee,Tf=Function.prototype.toString;function Ef(e){if(e!=null){try{return Tf.call(e)}catch{}try{return e+``}catch{}}return``}var Df=Ef,Of=/[\\^$.*+?()[\]{}|]/g,kf=/^\[object .+?Constructor\]$/,Af=Function.prototype,jf=Object.prototype,Mf=Af.toString,Nf=jf.hasOwnProperty,Pf=RegExp(`^`+Mf.call(Nf).replace(Of,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ff(e){return!tf(e)||wf(e)?!1:(xf(e)?Pf:kf).test(Df(e))}var If=Ff;function Lf(e,t){return e?.[t]}var Rf=Lf;function zf(e,t){var n=Rf(e,t);return If(n)?n:void 0}var Bf=zf,Vf=Bf(xd,`WeakMap`);function Hf(e,t,n){switch(n.length){case 0:return e.call(t);case 1:return e.call(t,n[0]);case 2:return e.call(t,n[0],n[1]);case 3:return e.call(t,n[0],n[1],n[2])}return e.apply(t,n)}var Uf=Hf;function Wf(){}var Gf=Wf,Kf=800,qf=16,Jf=Date.now;function Yf(e){var t=0,n=0;return function(){var r=Jf(),i=qf-(r-n);if(n=r,i>0){if(++t>=Kf)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var Xf=Yf;function Zf(e){return function(){return e}}var Qf=Zf,$f=function(){try{var e=Bf(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),ep=Xf($f?function(e,t){return $f(e,`toString`,{configurable:!0,enumerable:!1,value:Qf(t),writable:!0})}:hf);function tp(e,t,n,r){for(var i=e.length,a=n+(r?1:-1);r?a--:++a<i;)if(t(e[a],a,e))return a;return-1}var np=tp;function rp(e){return e!==e}var ip=rp;function ap(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var op=ap;function sp(e,t,n){return t===t?op(e,t,n):np(e,ip,n)}var cp=sp;function lp(e,t){return!!(e!=null&&e.length)&&cp(e,t,0)>-1}var up=lp,dp=9007199254740991,fp=/^(?:0|[1-9]\d*)$/;function pp(e,t){var n=typeof e;return t??=dp,!!t&&(n==`number`||n!=`symbol`&&fp.test(e))&&e>-1&&e%1==0&&e<t}var mp=pp;function dee(e,t,n){t==`__proto__`&&$f?$f(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var hp=dee;function fee(e,t){return e===t||e!==e&&t!==t}var gp=fee,_p=Math.max;function pee(e,t,n){return t=_p(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=_p(r.length-t,0),o=Array(a);++i<a;)o[i]=r[t+i];i=-1;for(var s=Array(t+1);++i<t;)s[i]=r[i];return s[t]=n(o),Uf(e,this,s)}}var mee=pee;function hee(e,t){return ep(mee(e,t,hf),e+``)}var vp=hee,gee=9007199254740991;function _ee(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=gee}var yp=_ee;function vee(e){return e!=null&&yp(e.length)&&!xf(e)}var bp=vee,yee=Object.prototype;function bee(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||yee)}var xp=bee;function xee(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var See=xee,Cee=`[object Arguments]`;function wee(e){return Id(e)&&Pd(e)==Cee}var Tee=wee,Eee=Object.prototype,Dee=Eee.hasOwnProperty,Oee=Eee.propertyIsEnumerable,Sp=Tee(function(){return arguments}())?Tee:function(e){return Id(e)&&Dee.call(e,`callee`)&&!Oee.call(e,`callee`)};function kee(){return!1}var Aee=kee,jee=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Mee=jee&&typeof module==`object`&&module&&!module.nodeType&&module,Nee=Mee&&Mee.exports===jee?xd.Buffer:void 0,Cp=(Nee?Nee.isBuffer:void 0)||Aee,Pee=`[object Arguments]`,Fee=`[object Array]`,Iee=`[object Boolean]`,Lee=`[object Date]`,Ree=`[object Error]`,zee=`[object Function]`,Bee=`[object Map]`,Vee=`[object Number]`,Hee=`[object Object]`,Uee=`[object RegExp]`,Wee=`[object Set]`,Gee=`[object String]`,Kee=`[object WeakMap]`,qee=`[object ArrayBuffer]`,Jee=`[object DataView]`,Yee=`[object Float32Array]`,Xee=`[object Float64Array]`,Zee=`[object Int8Array]`,Qee=`[object Int16Array]`,$ee=`[object Int32Array]`,ete=`[object Uint8Array]`,tte=`[object Uint8ClampedArray]`,nte=`[object Uint16Array]`,rte=`[object Uint32Array]`,wp={};wp[Yee]=wp[Xee]=wp[Zee]=wp[Qee]=wp[$ee]=wp[ete]=wp[tte]=wp[nte]=wp[rte]=!0,wp[Pee]=wp[Fee]=wp[qee]=wp[Iee]=wp[Jee]=wp[Lee]=wp[Ree]=wp[zee]=wp[Bee]=wp[Vee]=wp[Hee]=wp[Uee]=wp[Wee]=wp[Gee]=wp[Kee]=!1;function ite(e){return Id(e)&&yp(e.length)&&!!wp[Pd(e)]}var ate=ite;function ote(e){return function(t){return e(t)}}var ste=ote,cte=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Tp=cte&&typeof module==`object`&&module&&!module.nodeType&&module,Ep=Tp&&Tp.exports===cte&&yd.process,lte=function(){try{return Tp&&Tp.require&&Tp.require(`util`).types||Ep&&Ep.binding&&Ep.binding(`util`)}catch{}}(),ute=lte&&lte.isTypedArray,Dp=ute?ste(ute):ate,dte=Object.prototype.hasOwnProperty;function fte(e,t){var n=Hd(e),r=!n&&Sp(e),i=!n&&!r&&Cp(e),a=!n&&!r&&!i&&Dp(e),o=n||r||i||a,s=o?See(e.length,String):[],c=s.length;for(var l in e)(t||dte.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||mp(l,c)))&&s.push(l);return s}var pte=fte;function mte(e,t){return function(n){return e(t(n))}}var hte=mte(Object.keys,Object),gte=Object.prototype.hasOwnProperty;function _te(e){if(!xp(e))return hte(e);var t=[];for(var n in Object(e))gte.call(e,n)&&n!=`constructor`&&t.push(n);return t}var vte=_te;function yte(e){return bp(e)?pte(e):vte(e)}var Op=yte;function bte(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var xte=bte,Ste=Object.prototype.hasOwnProperty;function Cte(e){if(!tf(e))return xte(e);var t=xp(e),n=[];for(var r in e)r==`constructor`&&(t||!Ste.call(e,r))||n.push(r);return n}var wte=Cte;function Tte(e){return bp(e)?pte(e,!0):wte(e)}var Ete=Tte,Dte=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Ote=/^\w*$/;function kte(e,t){if(Hd(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||zd(e)?!0:Ote.test(e)||!Dte.test(e)||t!=null&&e in Object(t)}var kp=kte,Ap=Bf(Object,`create`);function Ate(){this.__data__=Ap?Ap(null):{},this.size=0}var jte=Ate;function Mte(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var Nte=Mte,Pte=`__lodash_hash_undefined__`,Fte=Object.prototype.hasOwnProperty;function Ite(e){var t=this.__data__;if(Ap){var n=t[e];return n===Pte?void 0:n}return Fte.call(t,e)?t[e]:void 0}var Lte=Ite,Rte=Object.prototype.hasOwnProperty;function zte(e){var t=this.__data__;return Ap?t[e]!==void 0:Rte.call(t,e)}var Bte=zte,Vte=`__lodash_hash_undefined__`;function Hte(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Ap&&t===void 0?Vte:t,this}var Ute=Hte;function jp(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}jp.prototype.clear=jte,jp.prototype.delete=Nte,jp.prototype.get=Lte,jp.prototype.has=Bte,jp.prototype.set=Ute;var Wte=jp;function Gte(){this.__data__=[],this.size=0}var Kte=Gte;function qte(e,t){for(var n=e.length;n--;)if(gp(e[n][0],t))return n;return-1}var Mp=qte,Jte=Array.prototype.splice;function Yte(e){var t=this.__data__,n=Mp(t,e);return n<0?!1:(n==t.length-1?t.pop():Jte.call(t,n,1),--this.size,!0)}var Xte=Yte;function Zte(e){var t=this.__data__,n=Mp(t,e);return n<0?void 0:t[n][1]}var Qte=Zte;function $te(e){return Mp(this.__data__,e)>-1}var ene=$te;function tne(e,t){var n=this.__data__,r=Mp(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var nne=tne;function Np(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Np.prototype.clear=Kte,Np.prototype.delete=Xte,Np.prototype.get=Qte,Np.prototype.has=ene,Np.prototype.set=nne;var Pp=Np,Fp=Bf(xd,`Map`);function rne(){this.size=0,this.__data__={hash:new Wte,map:new(Fp||Pp),string:new Wte}}var ine=rne;function ane(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var one=ane;function sne(e,t){var n=e.__data__;return one(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Ip=sne;function cne(e){var t=Ip(this,e).delete(e);return this.size-=t?1:0,t}var lne=cne;function une(e){return Ip(this,e).get(e)}var dne=une;function fne(e){return Ip(this,e).has(e)}var pne=fne;function mne(e,t){var n=Ip(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var hne=mne;function Lp(e){var t=-1,n=e==null?0:e.length;for(this.clear();++t<n;){var r=e[t];this.set(r[0],r[1])}}Lp.prototype.clear=ine,Lp.prototype.delete=lne,Lp.prototype.get=dne,Lp.prototype.has=pne,Lp.prototype.set=hne;var Rp=Lp,gne=`Expected a function`;function _ne(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(gne);var n=function(){var r=arguments,i=t?t.apply(this,r):r[0],a=n.cache;if(a.has(i))return a.get(i);var o=e.apply(this,r);return n.cache=a.set(i,o)||a,o};return n.cache=new(_ne.Cache||Rp),n}_ne.Cache=Rp;var vne=_ne,yne=500;function bne(e){var t=vne(e,function(e){return n.size===yne&&n.clear(),e}),n=t.cache;return t}var xne=bne,Sne=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Cne=/\\(\\)?/g,wne=xne(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(Sne,function(e,n,r,i){t.push(r?i.replace(Cne,`$1`):n||e)}),t});function Tne(e){return e==null?``:qd(e)}var Ene=Tne;function Dne(e,t){return Hd(e)?e:kp(e,t)?[e]:wne(Ene(e))}var One=Dne,kne=1/0;function Ane(e){if(typeof e==`string`||zd(e))return e;var t=e+``;return t==`0`&&1/e==-kne?`-0`:t}var zp=Ane;function jne(e,t){t=One(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[zp(t[n++])];return n&&n==r?e:void 0}var Mne=jne;function Nne(e,t,n){var r=e==null?void 0:Mne(e,t);return r===void 0?n:r}var Pne=Nne;function Fne(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Ine=Fne,Lne=Sd?Sd.isConcatSpreadable:void 0;function Rne(e){return Hd(e)||Sp(e)||!!(Lne&&e&&e[Lne])}var zne=Rne;function Bne(e,t,n,r,i){var a=-1,o=e.length;for(n||=zne,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?Bne(s,t-1,n,r,i):Ine(i,s):r||(i[i.length]=s)}return i}var Vne=Bne;function Hne(e){return e!=null&&e.length?Vne(e,1):[]}var Une=Hne;function Wne(){this.__data__=new Pp,this.size=0}var Gne=Wne;function Kne(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var qne=Kne;function Jne(e){return this.__data__.get(e)}var Yne=Jne;function Xne(e){return this.__data__.has(e)}var Zne=Xne,Qne=200;function $ne(e,t){var n=this.__data__;if(n instanceof Pp){var r=n.__data__;if(!Fp||r.length<Qne-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new Rp(r)}return n.set(e,t),this.size=n.size,this}var ere=$ne;function Bp(e){this.size=(this.__data__=new Pp(e)).size}Bp.prototype.clear=Gne,Bp.prototype.delete=qne,Bp.prototype.get=Yne,Bp.prototype.has=Zne,Bp.prototype.set=ere;var Vp=Bp;function tre(e,t){for(var n=-1,r=e==null?0:e.length,i=0,a=[];++n<r;){var o=e[n];t(o,n,e)&&(a[i++]=o)}return a}var nre=tre;function rre(){return[]}var ire=rre,are=Object.prototype.propertyIsEnumerable,ore=Object.getOwnPropertySymbols,sre=ore?function(e){return e==null?[]:(e=Object(e),nre(ore(e),function(t){return are.call(e,t)}))}:ire;function cre(e,t,n){var r=t(e);return Hd(e)?r:Ine(r,n(e))}var lre=cre;function ure(e){return lre(e,Op,sre)}var dre=ure,fre=Bf(xd,`DataView`),pre=Bf(xd,`Promise`),Hp=Bf(xd,`Set`),mre=`[object Map]`,hre=`[object Object]`,gre=`[object Promise]`,_re=`[object Set]`,vre=`[object WeakMap]`,yre=`[object DataView]`,bre=Df(fre),xre=Df(Fp),Sre=Df(pre),Cre=Df(Hp),wre=Df(Vf),Up=Pd;(fre&&Up(new fre(new ArrayBuffer(1)))!=yre||Fp&&Up(new Fp)!=mre||pre&&Up(pre.resolve())!=gre||Hp&&Up(new Hp)!=_re||Vf&&Up(new Vf)!=vre)&&(Up=function(e){var t=Pd(e),n=t==hre?e.constructor:void 0,r=n?Df(n):``;if(r)switch(r){case bre:return yre;case xre:return mre;case Sre:return gre;case Cre:return _re;case wre:return vre}return t});var Tre=Up,Ere=xd.Uint8Array;function Dre(e){for(var t=-1,n=e==null?0:e.length,r=0,i=[];++t<n;){var a=e[t];a&&(i[r++]=a)}return i}var Ore=Dre,kre=`__lodash_hash_undefined__`;function Are(e){return this.__data__.set(e,kre),this}var jre=Are;function Mre(e){return this.__data__.has(e)}var Nre=Mre;function Wp(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new Rp;++t<n;)this.add(e[t])}Wp.prototype.add=Wp.prototype.push=jre,Wp.prototype.has=Nre;var Pre=Wp;function Fre(e,t){for(var n=-1,r=e==null?0:e.length;++n<r;)if(t(e[n],n,e))return!0;return!1}var Ire=Fre;function Lre(e,t){return e.has(t)}var Rre=Lre,zre=1,Bre=2;function Vre(e,t,n,r,i,a){var o=n&zre,s=e.length,c=t.length;if(s!=c&&!(o&&c>s))return!1;var l=a.get(e),u=a.get(t);if(l&&u)return l==t&&u==e;var d=-1,f=!0,p=n&Bre?new Pre:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var g=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(g!==void 0){if(g)continue;f=!1;break}if(p){if(!Ire(t,function(e,t){if(!Rre(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===h||i(m,h,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var Hre=Vre;function Ure(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Wre=Ure;function Gre(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Kre=Gre,qre=1,Jre=2,Yre=`[object Boolean]`,Xre=`[object Date]`,Zre=`[object Error]`,Qre=`[object Map]`,$re=`[object Number]`,eie=`[object RegExp]`,tie=`[object Set]`,nie=`[object String]`,rie=`[object Symbol]`,iie=`[object ArrayBuffer]`,aie=`[object DataView]`,oie=Sd?Sd.prototype:void 0,sie=oie?oie.valueOf:void 0;function cie(e,t,n,r,i,a,o){switch(n){case aie:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case iie:return!(e.byteLength!=t.byteLength||!a(new Ere(e),new Ere(t)));case Yre:case Xre:case $re:return gp(+e,+t);case Zre:return e.name==t.name&&e.message==t.message;case eie:case nie:return e==t+``;case Qre:var s=Wre;case tie:var c=r&qre;if(s||=Kre,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Jre,o.set(e,t);var u=Hre(s(e),s(t),r,i,a,o);return o.delete(e),u;case rie:if(sie)return sie.call(e)==sie.call(t)}return!1}var lie=cie,uie=1,die=Object.prototype.hasOwnProperty;function fie(e,t,n,r,i,a){var o=n&uie,s=dre(e),c=s.length;if(c!=dre(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:die.call(t,u)))return!1}var d=a.get(e),f=a.get(t);if(d&&f)return d==t&&f==e;var p=!0;a.set(e,t),a.set(t,e);for(var m=o;++l<c;){u=s[l];var h=e[u],g=t[u];if(r)var _=o?r(g,h,u,t,e,a):r(h,g,u,e,t,a);if(!(_===void 0?h===g||i(h,g,n,r,a):_)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ee=e.constructor,te=t.constructor;ee!=te&&`constructor`in e&&`constructor`in t&&!(typeof ee==`function`&&ee instanceof ee&&typeof te==`function`&&te instanceof te)&&(p=!1)}return a.delete(e),a.delete(t),p}var pie=fie,mie=1,hie=`[object Arguments]`,gie=`[object Array]`,Gp=`[object Object]`,_ie=Object.prototype.hasOwnProperty;function vie(e,t,n,r,i,a){var o=Hd(e),s=Hd(t),c=o?gie:Tre(e),l=s?gie:Tre(t);c=c==hie?Gp:c,l=l==hie?Gp:l;var u=c==Gp,d=l==Gp,f=c==l;if(f&&Cp(e)){if(!Cp(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Vp,o||Dp(e)?Hre(e,t,n,r,i,a):lie(e,t,c,n,r,i,a);if(!(n&mie)){var p=u&&_ie.call(e,`__wrapped__`),m=d&&_ie.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,g=m?t.value():t;return a||=new Vp,i(h,g,n,r,a)}}return f?(a||=new Vp,pie(e,t,n,r,i,a)):!1}var yie=vie;function bie(e,t,n,r,i){return e===t?!0:e==null||t==null||!Id(e)&&!Id(t)?e!==e&&t!==t:yie(e,t,n,r,bie,i)}var xie=bie,Sie=1,Cie=2;function wie(e,t,n,r){var i=n.length,a=i,o=!r;if(e==null)return!a;for(e=Object(e);i--;){var s=n[i];if(o&&s[2]?s[1]!==e[s[0]]:!(s[0]in e))return!1}for(;++i<a;){s=n[i];var c=s[0],l=e[c],u=s[1];if(o&&s[2]){if(l===void 0&&!(c in e))return!1}else{var d=new Vp;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?xie(u,l,Sie|Cie,r,d):f))return!1}}return!0}var Tie=wie;function Eie(e){return e===e&&!tf(e)}var Die=Eie;function Oie(e){for(var t=Op(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Die(i)]}return t}var kie=Oie;function Aie(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var jie=Aie;function Mie(e){var t=kie(e);return t.length==1&&t[0][2]?jie(t[0][0],t[0][1]):function(n){return n===e||Tie(n,e,t)}}var Nie=Mie;function Pie(e,t){return e!=null&&t in Object(e)}var Fie=Pie;function Iie(e,t,n){t=One(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=zp(t[r]);if(!(a=e!=null&&n(e,o)))break;e=e[o]}return a||++r!=i?a:(i=e==null?0:e.length,!!i&&yp(i)&&mp(o,i)&&(Hd(e)||Sp(e)))}var Lie=Iie;function Rie(e,t){return e!=null&&Lie(e,t,Fie)}var zie=Rie,Bie=1,Vie=2;function Hie(e,t){return kp(e)&&Die(t)?jie(zp(e),t):function(n){var r=Pne(n,e);return r===void 0&&r===t?zie(n,e):xie(t,r,Bie|Vie)}}var Uie=Hie;function Wie(e){return function(t){return t?.[e]}}var Gie=Wie;function Kie(e){return function(t){return Mne(t,e)}}var qie=Kie;function Jie(e){return kp(e)?Gie(zp(e)):qie(e)}var Yie=Jie;function Xie(e){return typeof e==`function`?e:e==null?hf:typeof e==`object`?Hd(e)?Uie(e[0],e[1]):Nie(e):Yie(e)}var Kp=Xie;function Zie(e,t,n,r){for(var i=-1,a=e==null?0:e.length;++i<a;){var o=e[i];t(r,o,n(o),e)}return r}var Qie=Zie;function $ie(e){return function(t,n,r){for(var i=-1,a=Object(t),o=r(t),s=o.length;s--;){var c=o[e?s:++i];if(n(a[c],c,a)===!1)break}return t}}var eae=$ie();function tae(e,t){return e&&eae(e,t,Op)}var nae=tae;function rae(e,t){return function(n,r){if(n==null)return n;if(!bp(n))return e(n,r);for(var i=n.length,a=t?i:-1,o=Object(n);(t?a--:++a<i)&&r(o[a],a,o)!==!1;);return n}}var iae=rae(nae);function aae(e,t,n,r){return iae(e,function(e,i,a){t(r,e,n(e),a)}),r}var oae=aae;function sae(e,t){return function(n,r){var i=Hd(n)?Qie:oae,a=t?t():{};return i(n,e,Kp(r,2),a)}}var cae=sae;function lae(e){return Id(e)&&bp(e)}var uae=lae;function dae(e,t,n){for(var r=-1,i=e==null?0:e.length;++r<i;)if(n(t,e[r]))return!0;return!1}var fae=dae,pae=200;function mae(e,t,n,r){var i=-1,a=up,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=Vd(t,ste(n))),r?(a=fae,o=!1):t.length>=pae&&(a=Rre,o=!1,t=new Pre(t));outer:for(;++i<s;){var u=e[i],d=n==null?u:n(u);if(u=r||u!==0?u:0,o&&d===d){for(var f=l;f--;)if(t[f]===d)continue outer;c.push(u)}else a(t,d,r)||c.push(u)}return c}var hae=mae,gae=vp(function(e,t){return uae(e)?hae(e,Vne(t,1,uae,!0)):[]});function _ae(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var qp=_ae;function vae(e){return typeof e==`function`?e:hf}var yae=vae;function bae(e,t){var n=[];return iae(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var xae=bae;function Sae(e,t){return(Hd(e)?nre:xae)(e,Kp(t,3))}var Cae=Sae,wae=Math.max,Tae=Math.min;function Eae(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=pf(n),i=n<0?wae(r+i,0):Tae(i,r-1)),np(e,Kp(t,3),i,!0)}var Dae=Eae;function Oae(e){return e&&e.length?e[0]:void 0}var kae=Oae;function Aae(e,t){var n=-1,r=bp(e)?Array(e.length):[];return iae(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var jae=Aae;function Mae(e,t){return(Hd(e)?Vd:jae)(e,Kp(t,3))}var Nae=Mae;function Pae(e,t){return Vne(Nae(e,t),1)}var Jp=Pae;function Fae(e,t){return e==null?e:eae(e,yae(t),Ete)}var Yp=Fae,Iae=Object.prototype.hasOwnProperty,Lae=cae(function(e,t,n){Iae.call(e,n)?e[n].push(t):hp(e,n,[t])}),Rae=`[object Map]`,zae=`[object Set]`,Bae=Object.prototype.hasOwnProperty;function Vae(e){if(e==null)return!0;if(bp(e)&&(Hd(e)||typeof e==`string`||typeof e.splice==`function`||Cp(e)||Dp(e)||Sp(e)))return!e.length;var t=Tre(e);if(t==Rae||t==zae)return!e.size;if(xp(e))return!vte(e).length;for(var n in e)if(Bae.call(e,n))return!1;return!0}var Xp=Vae,Hae=cae(function(e,t,n){hp(e,n,t)}),Zp=cae(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),Uae=Hp&&1/Kre(new Hp([,-0]))[1]==1/0?function(e){return new Hp(e)}:Gf,Wae=200;function Gae(e,t,n){var r=-1,i=up,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=fae;else if(a>=Wae){var l=t?null:Uae(e);if(l)return Kre(l);o=!1,i=Rre,c=new Pre}else c=t?[]:s;outer:for(;++r<a;){var u=e[r],d=t?t(u):u;if(u=n||u!==0?u:0,o&&d===d){for(var f=c.length;f--;)if(c[f]===d)continue outer;t&&c.push(d),s.push(u)}else i(c,d,n)||(c!==s&&c.push(d),s.push(u))}return s}var Kae=Gae;function qae(e,t){return e&&e.length?Kae(e,Kp(t,2)):[]}var Qp=qae,Jae=Math.max;function Yae(e){if(!(e&&e.length))return[];var t=0;return e=nre(e,function(e){if(uae(e))return t=Jae(e.length,t),!0}),See(t,function(t){return Vd(e,Gie(t))})}var $p=vp(Yae),em=function(e){return e.SPACE=`<space>`,e.TAB=`<tab>`,e.NEWLINE=`<newline>`,e.COMMA=`<comma>`,e.LPAREN=`<lparen>`,e.RPAREN=`<rparen>`,e.LBRACE=`<lbrace>`,e.RBRACE=`<rbrace>`,e.LBRACKET=`<lbracket>`,e.RBRACKET=`<rbracket>`,e.LANGLE=`<langle>`,e.RANGLE=`<rangle>`,e.OP=`<op>`,e.EOF=`<eof>`,e.NUMERIC_LITERAL=`<number>`,e.STRING_LITERAL=`<string>`,e.COLOR_LITERAL=`<color>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.QUOTED_STRING=`<variable>`,e.IDENTIFIER=`<identifier>`,e.SEMICOLON=`<semicolon>`,e.COLON=`<colon>`,e.SINGLE_LINE_COMMENT=`<single-line-comment>`,e.MULTILINE_COMMENT=`<multiline-comment>`,e.WILDCARD=`<wildcard>`,e}({});function Xae(e){switch(e.kind){case em.NEWLINE:case em.SPACE:case em.TAB:case em.SINGLE_LINE_COMMENT:case em.MULTILINE_COMMENT:return!0;default:return!1}}function Zae(e){if(!e)return!1;switch(e){case`+`:case`-`:case`/`:case`%`:case`<`:case`>`:case`=`:case`!`:case`.`:case`&`:case`|`:case`~`:return!0;default:return!1}}function Qae(e){return e!==void 0&&e.kind===em.OP}var tm=class e{constructor(e,t,n,r,i,a){this.kind=e,this.filepath=t,this.startPos=n,this.endPos=r,this.value=i,this.leadingTrivia=[],this.trailingTrivia=[],this.leadingInvalid=[],this.trailingInvalid=[],this.isInvalid=a,this.start=n.offset,this.end=r.offset}static create(t,n,r,i,a,o){return new e(t,n,r,i,a,o)}};function nm(e){return e.trailingTrivia.find(({kind:e})=>e===em.NEWLINE)!==void 0}function $ae(e,t){return t.leadingTrivia.find(({kind:e})=>e===em.NEWLINE)!==void 0||nm(e)}function rm(e){return e.trailingTrivia.find(({kind:e})=>[em.SPACE,em.TAB].includes(e))!==void 0}function eoe(e){return e.trailingTrivia.length===0?e.end:eoe(qp(e.trailingTrivia))}function toe(e){return e.leadingTrivia.length===0?e.start:toe(e.leadingTrivia[0])}function noe(e){return[em.SINGLE_LINE_COMMENT,em.MULTILINE_COMMENT].includes(e.kind)}function im(e){return e?.kind===em.IDENTIFIER&&e.value.toLowerCase()===`as`}function roe(e){return e?.kind===em.IDENTIFIER&&e.value.toLowerCase()===`use`}function ioe(e){return e?.kind===em.IDENTIFIER&&e.value.toLowerCase()===`from`}function aoe(e){return e?.kind===em.IDENTIFIER&&e.value.toLowerCase()===`reuse`}function am(e){return!!e?.isInvalid}var ooe=class{constructor(e){this.generator=e}create(e,t,n){return new e(t,this.generator.nextId(),n)}},soe=/^[A-Za-z]:\//;function om(e=``){return e&&e.replace(/\\/g,`/`).replace(soe,e=>e.toUpperCase())}var coe=/^[/\\]{2}/,loe=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,uoe=/^[A-Za-z]:$/,doe=/^\/([A-Za-z]:)?$/,foe=/.(\.[^./]+|\.)$/,sm=function(e){if(e.length===0)return`.`;e=om(e);let t=e.match(coe),n=lm(e),r=e[e.length-1]===`/`;return e=hoe(e,!n),e.length===0?n?`/`:r?`./`:`.`:(r&&(e+=`/`),uoe.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!lm(e)?`/${e}`:e)},poe=function(...e){let t=``;for(let n of e)if(n)if(t.length>0){let e=t[t.length-1]===`/`,r=n[0]===`/`;e&&r?t+=n.slice(1):t+=e||r?n:`/${n}`}else t+=n;return sm(t)};function moe(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var cm=function(...e){e=e.map(e=>om(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:moe();!i||i.length===0||(t=`${i}/${t}`,n=lm(i))}return t=hoe(t,!n),n&&!lm(t)?`/${t}`:t.length>0?t:`.`};function hoe(e,t){let n=``,r=0,i=-1,a=0,o=null;for(let s=0;s<=e.length;++s){if(s<e.length)o=e[s];else if(o===`/`)break;else o=`/`;if(o===`/`){if(!(i===s-1||a===1))if(a===2){if(n.length<2||r!==2||n[n.length-1]!==`.`||n[n.length-2]!==`.`){if(n.length>2){let e=n.lastIndexOf(`/`);e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}else if(n.length>0){n=``,r=0,i=s,a=0;continue}}t&&(n+=n.length>0?`/..`:`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1;i=s,a=0}else o===`.`&&a!==-1?++a:a=-1}return n}var lm=function(e){return loe.test(e)},goe=function(e){if(e===`..`)return``;let t=foe.exec(om(e));return t&&t[1]||``},_oe=function(e,t){let n=cm(e).replace(doe,`$1`).split(`/`),r=cm(t).replace(doe,`$1`).split(`/`);if(r[0][1]===`:`&&n[0][1]===`:`&&n[0]!==r[0])return r.join(`/`);let i=[...n];for(let e of i){if(r[0]!==e)break;n.shift(),r.shift()}return[...n.map(()=>`..`),...r].join(`/`)},voe=function(e){let t=om(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&uoe.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(lm(e)?`/`:`.`)},yoe=function(e,t){let n=om(e).split(`/`),r=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){r=t;break}}return t&&r.endsWith(t)?r.slice(0,-t.length):r},boe=/^[a-zA-Z]:\//,um=class e{constructor(e,t={}){let n=sm(e);if(!lm(n))throw Error(`FilePath requires an absolute path, got: "${e}"`);this.path=n,this.protocol=t.protocol}intern(){return this.protocol,`filepath@${this.path}`}static from(t){return new e(t)}static resolve(t,n){return new e(cm(t,n))}static fromUri(t){try{let n=new URL(t);return new e(sm(n.host?`/${n.host}${n.pathname}`:n.pathname),{protocol:n.protocol})}catch{return new e(sm(t))}}get absolute(){return this.path}get dirname(){return voe(this.path)}get basename(){return yoe(this.path)}get extname(){return goe(this.path)}resolve(t){return new e(cm(this.dirname,t))}join(...t){return new e(poe(this.path,...t))}relativeTo(e){let t=_oe(e,this.path);return t.startsWith(`.`)?t:`./${t}`}toString(){return this.path}equals(e){return this.path===e.path}isParentOf(e){if(this.path===e.path)return!1;let t=this.path.endsWith(`/`)?this.path:`${this.path}/`;return e.path.startsWith(t)}toUri(e={}){let t=e.protocol??this.protocol;if(t===void 0)return this.path;let n=boe.test(this.path)?`${t}:///`:`${t}://`;return new URL(n+this.path).href}static isRelative(e){return!lm(sm(e))}};function dm(e,t){if(!um.isRelative(t))return;let n=um.resolve(e.dirname,t);return n.absolute.endsWith(`.dbml`)?n:um.from(n.absolute+`.dbml`)}var fm=[`null`,`true`,`false`],xoe=[`-`,`+`],pm=`public`,mm=um.from(`/main.dbml`),M=function(e){return e[e.UNKNOWN_SYMBOL=1e3]=`UNKNOWN_SYMBOL`,e[e.UNEXPECTED_SYMBOL=1001]=`UNEXPECTED_SYMBOL`,e[e.UNEXPECTED_EOF=1002]=`UNEXPECTED_EOF`,e[e.UNEXPECTED_NEWLINE=1003]=`UNEXPECTED_NEWLINE`,e[e.UNKNOWN_TOKEN=1004]=`UNKNOWN_TOKEN`,e[e.UNEXPECTED_TOKEN=1005]=`UNEXPECTED_TOKEN`,e[e.UNEXPECTED_ELEMENT_DECLARATION=1006]=`UNEXPECTED_ELEMENT_DECLARATION`,e[e.MISSING_SPACES=1007]=`MISSING_SPACES`,e[e.UNKNOWN_PREFIX_OP=1008]=`UNKNOWN_PREFIX_OP`,e[e.INVALID_OPERAND=1009]=`INVALID_OPERAND`,e[e.EMPTY_ATTRIBUTE_NAME=1010]=`EMPTY_ATTRIBUTE_NAME`,e[e.INVALID_ESCAPE_SEQUENCE=1011]=`INVALID_ESCAPE_SEQUENCE`,e[e.INVALID_NAME=3e3]=`INVALID_NAME`,e[e.UNEXPECTED_NAME=3001]=`UNEXPECTED_NAME`,e[e.NAME_NOT_FOUND=3002]=`NAME_NOT_FOUND`,e[e.DUPLICATE_NAME=3003]=`DUPLICATE_NAME`,e[e.INVALID_ALIAS=3004]=`INVALID_ALIAS`,e[e.UNEXPECTED_ALIAS=3005]=`UNEXPECTED_ALIAS`,e[e.UNEXPECTED_SETTINGS=3006]=`UNEXPECTED_SETTINGS`,e[e.INVALID_SETTINGS=3007]=`INVALID_SETTINGS`,e[e.UNEXPECTED_SIMPLE_BODY=3008]=`UNEXPECTED_SIMPLE_BODY`,e[e.UNEXPECTED_COMPLEX_BODY=3009]=`UNEXPECTED_COMPLEX_BODY`,e[e.INVALID_TABLE_CONTEXT=3010]=`INVALID_TABLE_CONTEXT`,e[e.UNKNOWN_TABLE_SETTING=3011]=`UNKNOWN_TABLE_SETTING`,e[e.DUPLICATE_TABLE_SETTING=3012]=`DUPLICATE_TABLE_SETTING`,e[e.INVALID_TABLEGROUP_CONTEXT=3013]=`INVALID_TABLEGROUP_CONTEXT`,e[e.INVALID_TABLEGROUP_ELEMENT_NAME=3014]=`INVALID_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_ELEMENT_NAME=3015]=`DUPLICATE_TABLEGROUP_ELEMENT_NAME`,e[e.DUPLICATE_TABLEGROUP_FIELD_NAME=3016]=`DUPLICATE_TABLEGROUP_FIELD_NAME`,e[e.INVALID_TABLEGROUP_FIELD=3017]=`INVALID_TABLEGROUP_FIELD`,e[e.EMPTY_TABLE=3018]=`EMPTY_TABLE`,e[e.INVALID_COLUMN=3019]=`INVALID_COLUMN`,e[e.INVALID_COLUMN_NAME=3020]=`INVALID_COLUMN_NAME`,e[e.UNKNOWN_COLUMN_SETTING=3021]=`UNKNOWN_COLUMN_SETTING`,e[e.INVALID_COLUMN_TYPE=3022]=`INVALID_COLUMN_TYPE`,e[e.DUPLICATE_COLUMN_NAME=3023]=`DUPLICATE_COLUMN_NAME`,e[e.DUPLICATE_COLUMN_SETTING=3024]=`DUPLICATE_COLUMN_SETTING`,e[e.INVALID_COLUMN_SETTING_VALUE=3025]=`INVALID_COLUMN_SETTING_VALUE`,e[e.INVALID_ENUM_CONTEXT=3026]=`INVALID_ENUM_CONTEXT`,e[e.INVALID_ENUM_ELEMENT_NAME=3027]=`INVALID_ENUM_ELEMENT_NAME`,e[e.INVALID_ENUM_ELEMENT=3028]=`INVALID_ENUM_ELEMENT`,e[e.DUPLICATE_ENUM_ELEMENT_NAME=3029]=`DUPLICATE_ENUM_ELEMENT_NAME`,e[e.UNKNOWN_ENUM_ELEMENT_SETTING=3030]=`UNKNOWN_ENUM_ELEMENT_SETTING`,e[e.DUPLICATE_ENUM_ELEMENT_SETTING=3031]=`DUPLICATE_ENUM_ELEMENT_SETTING`,e[e.INVALID_ENUM_ELEMENT_SETTING=3032]=`INVALID_ENUM_ELEMENT_SETTING`,e[e.EMPTY_ENUM=3033]=`EMPTY_ENUM`,e[e.INVALID_REF_CONTEXT=3034]=`INVALID_REF_CONTEXT`,e[e.UNKNOWN_REF_SETTING=3035]=`UNKNOWN_REF_SETTING`,e[e.DUPLICATE_REF_SETTING=3036]=`DUPLICATE_REF_SETTING`,e[e.INVALID_REF_SETTING_VALUE=3037]=`INVALID_REF_SETTING_VALUE`,e[e.INVALID_REF_RELATIONSHIP=3038]=`INVALID_REF_RELATIONSHIP`,e[e.INVALID_REF_FIELD=3039]=`INVALID_REF_FIELD`,e[e.EMPTY_REF=3040]=`EMPTY_REF`,e[e.REF_REDEFINED=3041]=`REF_REDEFINED`,e[e.INVALID_NOTE_CONTEXT=3042]=`INVALID_NOTE_CONTEXT`,e[e.INVALID_NOTE=3043]=`INVALID_NOTE`,e[e.NOTE_REDEFINED=3044]=`NOTE_REDEFINED`,e[e.NOTE_CONTENT_REDEFINED=3045]=`NOTE_CONTENT_REDEFINED`,e[e.EMPTY_NOTE=3046]=`EMPTY_NOTE`,e[e.INVALID_INDEXES_CONTEXT=3047]=`INVALID_INDEXES_CONTEXT`,e[e.INVALID_INDEXES_FIELD=3048]=`INVALID_INDEXES_FIELD`,e[e.INVALID_INDEX=3049]=`INVALID_INDEX`,e[e.UNKNOWN_INDEX_SETTING=3050]=`UNKNOWN_INDEX_SETTING`,e[e.DUPLICATE_INDEX_SETTING=3051]=`DUPLICATE_INDEX_SETTING`,e[e.UNEXPECTED_INDEX_SETTING_VALUE=3052]=`UNEXPECTED_INDEX_SETTING_VALUE`,e[e.INVALID_INDEX_SETTING_VALUE=3053]=`INVALID_INDEX_SETTING_VALUE`,e[e.INVALID_PROJECT_CONTEXT=3054]=`INVALID_PROJECT_CONTEXT`,e[e.PROJECT_REDEFINED=3055]=`PROJECT_REDEFINED`,e[e.INVALID_PROJECT_FIELD=3056]=`INVALID_PROJECT_FIELD`,e[e.INVALID_CUSTOM_CONTEXT=3057]=`INVALID_CUSTOM_CONTEXT`,e[e.INVALID_CUSTOM_ELEMENT_VALUE=3058]=`INVALID_CUSTOM_ELEMENT_VALUE`,e[e.INVALID_ELEMENT_IN_SIMPLE_BODY=3059]=`INVALID_ELEMENT_IN_SIMPLE_BODY`,e[e.INVALID_TABLE_PARTIAL_CONTEXT=3060]=`INVALID_TABLE_PARTIAL_CONTEXT`,e[e.INVALID_TABLE_PARTIAL_ELEMENT_NAME=3061]=`INVALID_TABLE_PARTIAL_ELEMENT_NAME`,e[e.INVALID_TABLE_PARTIAL_SETTING_VALUE=3062]=`INVALID_TABLE_PARTIAL_SETTING_VALUE`,e[e.DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME=3063]=`DUPLICATE_TABLE_PARTIAL_ELEMENT_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_SETTING=3064]=`DUPLICATE_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_PARTIAL_INJECTION=3065]=`INVALID_TABLE_PARTIAL_INJECTION`,e[e.INVALID_TABLE_PARTIAL_INJECTION_OP=3066]=`INVALID_TABLE_PARTIAL_INJECTION_OP`,e[e.INVALID_TABLE_PARTIAL_INJECTION_NAME=3067]=`INVALID_TABLE_PARTIAL_INJECTION_NAME`,e[e.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME=3068]=`DUPLICATE_TABLE_PARTIAL_INJECTION_NAME`,e[e.UNKNOWN_TABLE_PARTIAL_SETTING=3069]=`UNKNOWN_TABLE_PARTIAL_SETTING`,e[e.INVALID_TABLE_SETTING_VALUE=3070]=`INVALID_TABLE_SETTING_VALUE`,e[e.INVALID_CHECKS_CONTEXT=3071]=`INVALID_CHECKS_CONTEXT`,e[e.INVALID_CHECKS_FIELD=3072]=`INVALID_CHECKS_FIELD`,e[e.INVALID_CHECK=3073]=`INVALID_CHECK`,e[e.UNKNOWN_CHECK_SETTING=3074]=`UNKNOWN_CHECK_SETTING`,e[e.DUPLICATE_CHECK_SETTING=3075]=`DUPLICATE_CHECK_SETTING`,e[e.INVALID_CHECK_SETTING_VALUE=3076]=`INVALID_CHECK_SETTING_VALUE`,e[e.INVALID_RECORDS_CONTEXT=3077]=`INVALID_RECORDS_CONTEXT`,e[e.INVALID_RECORDS_NAME=3078]=`INVALID_RECORDS_NAME`,e[e.INVALID_RECORDS_FIELD=3079]=`INVALID_RECORDS_FIELD`,e[e.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS=3080]=`DUPLICATE_COLUMN_REFERENCES_IN_RECORDS`,e[e.DUPLICATE_RECORDS_FOR_TABLE=3081]=`DUPLICATE_RECORDS_FOR_TABLE`,e[e.INVALID_USE_CONTEXT=3082]=`INVALID_USE_CONTEXT`,e[e.INVALID_USE_SPECIFIER_KIND=3083]=`INVALID_USE_SPECIFIER_KIND`,e[e.INVALID_USE_SPECIFIER_NAME=3084]=`INVALID_USE_SPECIFIER_NAME`,e[e.INVALID_DIAGRAMVIEW_CONTEXT=3085]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3086]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3087]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3088]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,e[e.NONEXISTENT_MODULE=4001]=`NONEXISTENT_MODULE`,e[e.UNSUPPORTED=5e3]=`UNSUPPORTED`,e[e.CIRCULAR_REF=5001]=`CIRCULAR_REF`,e[e.SAME_ENDPOINT=5002]=`SAME_ENDPOINT`,e[e.UNEQUAL_FIELDS_BINARY_REF=5003]=`UNEQUAL_FIELDS_BINARY_REF`,e[e.CONFLICTING_SETTING=5004]=`CONFLICTING_SETTING`,e[e.TABLE_REAPPEAR_IN_TABLEGROUP=5005]=`TABLE_REAPPEAR_IN_TABLEGROUP`,e}({}),N=class e extends Error{constructor(t,n,r){super(n),this.code=t,this.diagnostic=n,this.nodeOrToken=r,this.start=r.start,this.end=r.end,this.name=this.constructor.name,Object.setPrototypeOf(this,e.prototype)}toWarning(){return new hm(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},hm=class extends Error{constructor(e,t,n){super(t),this.code=e,this.diagnostic=t,this.nodeOrToken=n,this.start=n.start,this.end=n.end,this.name=this.constructor.name,Object.setPrototypeOf(this,N.prototype)}get filepath(){return this.nodeOrToken.filepath}};function gm(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function _m(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Soe(e){let[t]=e;return _m(t)||gm(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function vm(e){return gm(e)||_m(e)}function ym(e){let t=Jm(e);return t!==void 0&&t.length>0}function bm(e){return xm(e)}function xm(e){return e instanceof Uh&&e.expression instanceof Hh}function Sm(e){return e instanceof kh&&e.op?.value===`~`&&jm(e.expression)}function Cm(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function wm(e){if(!(e instanceof Uh)||!(e.expression instanceof Bh)||e.expression.literal?.kind!==em.COLOR_LITERAL)return!1;let t=e.expression.literal.value;if(t.length!==4&&t.length!==7||t[0]!==`#`)return!1;for(let e=1;e<t.length;e+=1)if(!Soe(t[e]))return!1;return!0}function Tm(e){if(Am(e)||Em(e)||Nm(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof kh&&xoe.includes(e.op?.value)&&Em(e.expression)||e instanceof Mh)return!0;if(!e||!Fm(e))return!1;let t=qm(e);return t.length===2||t.length===3}function Em(e){return e instanceof kh?xoe.includes(e.op.value)?Em(e.expression):!1:e instanceof Uh&&e.expression instanceof Bh&&e.expression.literal?.kind===em.NUMERIC_LITERAL}function Dm(e){if(!(e instanceof kh)||!Cm(e.op?.value))return!1;let t=Jm(e.expression);return t!==void 0&&t.length>0}function Om(e){return e instanceof Ih&&e.elementList.every(jm)}function Coe(e){if(!(e instanceof zh||Pm(e)||e instanceof Uh||e instanceof Gh))return!1;for(;e instanceof zh||e instanceof Gh;)if(e instanceof zh){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>Em(e)||Am(e)||Nm(e)))return!1;e=e.callee}else if(e instanceof Gh){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&Em(e.name)))return!1;e=e.array}let t=Jm(e);return t!==void 0&&t.length>0}function km(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Uh){n.push(new N(M.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=Wm(e.name)?.toLowerCase();if(!r)return;let i=t[r];i?i.push(e):t[r]=[e]}),new k(t,n)):new k(t)}function Am(e){return e instanceof Uh&&(e.expression instanceof Hh&&e.expression.variable instanceof tm&&e.expression.variable.kind===em.QUOTED_STRING||e.expression instanceof Bh&&e.expression.literal?.kind===em.STRING_LITERAL)}function jm(e){return e instanceof Uh&&e.expression instanceof Hh&&e.expression.variable instanceof tm}function Mm(e){return e?e instanceof Vh:!1}function Nm(e){return e instanceof Uh&&e.expression instanceof Hh&&e.expression.variable?.kind===em.IDENTIFIER}function Pm(e){return e instanceof Ah&&e.leftExpression instanceof bh&&e.rightExpression instanceof bh&&e.op?.value===`.`}function Fm(e){return jm(e)?!0:Pm(e)&&jm(e.rightExpression)&&Fm(e.leftExpression)}function Im(e,t){return e instanceof Eh&&e.isKind(t)}function woe(e){return e instanceof Ch}function Lm(e,t){return e instanceof wh&&(t===void 0||e.isKind(t))}function Rm(e){return e instanceof Sh}function zm(e,...t){return e instanceof Nh&&e.parent instanceof Eh&&e.parent.isKind(...t)}function Bm(e,t){let n=e.parent;return n instanceof Eh&&n.isKind(t)&&!!n.body&&n.body.strictlyContains(e)}function Vm(e,t){let n=e.parentOfKind(Nh);if(!n||t<0)return!1;if(t===0)return n.callee?n.callee.containsEq(e):!1;let r=n.args[t-1];return r?r.containsEq(e):!1}function Hm(e){return!!e.parentOfKind(Fh)}function Toe(e,t){let n=e.parentOfKind(Oh);return!n||(n.name instanceof Uh?eh(n.name):Wm(n.name))?.toLowerCase()!==t?!1:!!n.value?.containsEq(e)}function Um(e){return!(e instanceof Ah)||!Cm(e.op?.value)?!1:Ym(e.leftExpression)!==void 0&&Ym(e.rightExpression)!==void 0}function Eoe(e){let t=Ym(e.leftExpression),n=Ym(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function Doe(e){return e instanceof Uh&&e.expression instanceof Hh||e instanceof Mh}function Ooe(e){let t=e.parentNode;return!Pm(t)||t.rightExpression!==e?!1:!(Pm(t.parentNode)&&t.parentNode.leftExpression===t)}function koe(e){if(jm(e))return e.expression.variable}function Wm(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function Aoe(e){if(!(e instanceof Eh))return;let t=Jm(e?.name);return t===void 0?void 0:t.join(`.`)}function Gm(e){return e.elementList.length===0}function Km(e){return e?.body?e.body instanceof Ph?e.body.body:[e.body]:[]}function qm(e){if(!e)return;if(!Pm(e))return[e];let t=qm(e.leftExpression);if(t)return t.push(e.rightExpression),t}function Jm(e){if(e===void 0)return;let t=qm(e);if(!t)return;let n=[];for(let e of t){let t=eh(e);if(typeof t!=`string`)return;n.push(t)}return n}function Ym(e){if(e===void 0)return;let t=qm(e);if(!t||t.length===0)return;let n=[];if(!jm(qp(t))){let e=t.pop();if(Om(e))n=e.elementList;else return}let r=t;if(r.every(jm))return{variables:r,tupleElements:n}}function Xm(e){if(Doe(e))return e instanceof Mh?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof Ih&&e.elementList.every(Doe))return{functional:e.elementList.filter(e=>e instanceof Mh),nonFunctional:e.elementList.filter(jm)}}function Zm(e){if(Am(e))return e.expression instanceof Hh?e?.expression?.variable?.value:e.expression.literal.value}function Qm(e){return e instanceof Uh&&e.expression instanceof Bh&&e.expression.literal?.kind===em.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function $m(e){if(!(e instanceof zh)||!e.callee)return;let t=qm(e.callee);if(!t||t.length===0||!t.every(jm))return;let n=[];return Om(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}function eh(e){if(jm(e))return e.expression.variable.value}function th(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function nh(e){return e instanceof kh?`${e.op?.value}${nh(e.expression)}`:e.expression.literal.value}function rh(e){return e instanceof kh?e.op?.value===`-`?-rh(e.expression):rh(e.expression):Number.parseFloat(e.expression.literal.value)}function ih(e){return{start:{offset:e.startPos.offset,line:e.startPos.line+1,column:e.startPos.column+1},end:{offset:e.endPos.offset,line:e.endPos.line+1,column:e.endPos.column+1},filepath:e.filepath}}function ah(e){let t=e.split(`
2
2
  `),n=t.slice(t.findIndex(e=>e.trimStart()!==``)),r=n.filter(e=>e.trimStart());if(r.length===0)return n.join(`
3
3
  `);let i=Math.min(...r.map(e=>e.length-e.trimStart().length));return n.map(e=>e.slice(i)).join(`
4
- `)}function oh(e){let t=Jm(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function sh(e){if(e instanceof Uh&&e.expression instanceof Bh&&e.expression.literal?.kind===em.COLOR_LITERAL)return e.expression.literal.value}function joe(e){if(e){if(Am(e)){let t=Zm(e);if(t!==void 0)return{value:t,type:`string`}}if(Em(e))return{type:`number`,value:rh(e)};if(Nm(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof Mh&&e.value)return{value:e.value.value,type:`expression`};if(Fm(e)){let t=qm(e)?.at(-1),n=t?eh(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function ch(e,t){let n=``,r=null;if(t instanceof zh){if(r=(t.argumentList?.elementList??[]).map(e=>Em(e)?nh(e):Am(e)?Zm(e):eh(e)).join(`,`),n=`(${r})`,!t.callee)return new k({schemaName:null,type_name:``,args:r});t=t.callee}for(;t instanceof zh||t instanceof Gh;)if(t instanceof zh){if(n=`(${(t.argumentList?.elementList??[]).map(e=>Em(e)?nh(e):Am(e)?Zm(e):eh(e)).join(`,`)})${n}`,!t.callee)break;t=t.callee}else if(t instanceof Gh){if(n=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${n}`,!t.array)break;t=t.array}let{name:i,schemaName:a}=oh(t);return a.length>1?new k({schemaName:a[0]??null,type_name:`${i}${n}`,args:r},[new N(M.UNSUPPORTED,`Nested schema is not supported`,t)]):new k({schemaName:a.length===0?null:a[0],type_name:`${i}${n}`,args:r})}var P=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Program=`Program`,e}({}),lh={Table:P.Table,Enum:P.Enum,TableGroup:P.TableGroup,TablePartial:P.TablePartial,Note:P.StickyNote,Schema:P.Schema},Moe=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},uh=class{constructor({kind:e,declaration:t,name:n},r,i){this.id=r,this.kind=e,this.declaration=t,this.filepath=i,this.name=n}get originalFilepath(){return this.originalSymbol.filepath}intern(){return`symbol@${this.filepath.intern()}:${this.id}`}isKind(...e){return e.includes(this.kind)}canonicalName(e,t){return e.canonicalName(t,this).getValue()}interpretedName(e,t){if(!t)return{schema:null,name:this.name??``};let n=this.canonicalName(e,t);return n?{schema:n.schema===`public`?null:n.schema,name:n.name}:{schema:null,name:this.name??``}}settings(e){if(this.declaration)return e.nodeSettings(this.declaration).getFiltered(gd)}get token(){if(this.declaration)return ih(this.declaration)}references(e){return e.symbolReferences(this)}metadata(e){return e.symbolMetadata(this)}members(e){let t=e.symbolMembers(this);return t.hasValue(gd)?[]:t.getValue()}},dh=class e extends uh{constructor({name:e,parent:t},n,r){super({kind:P.Schema},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===pm}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},fh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Enum,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Noe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.EnumField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},ph=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Table,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof yh))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(P.Column))}partialInjections(e){return this.members(e).filter(e=>e.isKind(P.PartialInjection))}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}headercolor(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);return t?.[vd.HeaderColor]?.length?sh(t[vd.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===qh.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===qh.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===qh.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===qh.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(t=>{if(!(t.declaration instanceof Nh)||!Sm(t.declaration.callee))return[];let n=t.declaration.callee.expression;if(!n)return[];let r=e.nodeReferee(n).getFiltered(gd);return r?[r]:[]})}mergedIndexes(e){let t=this.indexes(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===qh.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===qh.TableChecks));return[...t,...n]}mergedHeadercolor(e){let t=this.headercolor(e);for(let n of this.resolvedPartials(e)){if(!n.declaration)continue;let r=e.nodeSettings(n.declaration).getFiltered(gd);r?.[vd.HeaderColor]?.length&&(t=sh(r[vd.HeaderColor].at(0)?.value))}return t}mergedNote(e){let t=t=>{if(!t.declaration)return;let n=e.nodeSettings(t.declaration).getFiltered(gd);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=ah(Zm(i));if(a)return{value:a,token:ih(r)}},n=t(this);for(let r of this.resolvedPartials(e)){let e=t(r);e&&(n=e)}return n}},mh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Column,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}pk(e){if(!this.declaration)return!1;let t=e.nodeSettings(this.declaration).getFiltered(gd);return!!(t?.[vd.PK]?.length||t?.[vd.PrimaryKey]?.length)}unique(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Unique]?.length:!1}nullable(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(t?.[vd.NotNull]?.length)return!1;if(t?.[vd.Null]?.length)return!0}increment(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Increment]?.length:!1}default(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Default]?.at(0)?.value;if(t)return joe(t)}type(e){if(!(this.declaration instanceof Nh))return;let t=ch(e,this.declaration.args[0]).getValue();if(!t)return;let n=t.args?t.args.split(`,`).map(e=>{let t=Number(e);return Number.isNaN(t)?e:t}):void 0,r=[],i=/\[([^\]]*)\]/g,a,o=t.type_name;for(;(a=i.exec(o))!==null;){let e=a[1];if(e===``)r.push(void 0);else{let t=Number(e);r.push(Number.isNaN(t)?e:t)}}let s=o.replace(/\[[^\]]*\]/g,``),c=e.nodeReferee(this.declaration.args[0]).getFiltered(gd);return{name:s,enumSymbol:c instanceof fh?c:void 0,args:n?.length?n:void 0,schema:t.schemaName??void 0,array:r.length?r:void 0}}checks(e){return this.metadata(e).filter(e=>e.kind===qh.TableChecks)}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},Poe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(P.TableGroupField))}color(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);return t?.color?.length?sh(t.color.at(0)?.value):void 0}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},Foe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TableGroupField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ioe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.StickyNote,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},hh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TablePartial,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Loe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.PartialInjection,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Roe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramView,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},zoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTopLevelWildcard,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Boe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTable,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Voe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Hoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewNote,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Uoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewSchema,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},gh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Program,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof dh&&r.inNestedSchema(e,t))return!0;return!1}},_h=class extends uh{constructor({kind:e,declaration:t,aliasedSymbol:n,name:r},i,a){super({kind:e,declaration:t,name:r},i,a),this.aliasedSymbol=n}get canBeImported(){return this.aliasedSymbol.canBeImported}get originalSymbol(){return this.aliasedSymbol.originalSymbol}},vh=class extends uh{constructor({kind:e,declaration:t,useSpecifierDeclaration:n,usedSymbol:r,name:i},a,o){super({kind:e,declaration:t,name:i},a,o),this.useSpecifierDeclaration=n,this.usedSymbol=r}get canBeImported(){let e=this.useSpecifierDeclaration?.parentOfKind(Ch);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},yh=class extends mh{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},Woe=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},bh=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof tm?toe(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof tm?eoe(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof Eh||e instanceof Sh)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},xh=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),Sh=class extends bh{constructor({body:e=[],eof:t,source:n},r,i){super(r,xh.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===xh.ELEMENT_DECLARATION)}get uses(){return this.body.filter(e=>e.kind===xh.USE_DECLARATION)}},Ch=class extends bh{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,xh.USE_DECLARATION,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return aoe(this.useKeyword)}},wh=class extends bh{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,xh.USE_SPECIFIER,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return Object.values(P).find(t=>t.toLowerCase()===e)}},Th=class extends bh{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,xh.USE_SPECIFIER_LIST,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},Eh=class e extends bh{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,xh.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof Nh||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(_d).find(e=>this.isKind(e))}},Dh=class extends bh{constructor({identifiers:e=[]},t,n){super(t,xh.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},Oh=class extends bh{constructor({name:e,colon:t,value:n},r,i){super(r,xh.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},kh=class extends bh{constructor({op:e,expression:t},n,r){super(n,xh.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},Ah=class extends bh{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,xh.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},jh=class extends bh{constructor({op:e,expression:t},n,r){super(n,xh.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},Mh=class extends bh{constructor({value:e},t,n){super(t,xh.FUNCTION_EXPRESSION,n,[e]),this.value=e}},Nh=class extends bh{constructor({callee:e,args:t=[]},n,r){super(n,xh.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},Ph=class extends bh{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,xh.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},Fh=class extends bh{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,xh.LIST_EXPRESSION,a,[e,...Kh(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Ih=class extends bh{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,xh.TUPLE_EXPRESSION,a,[e,...Kh(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Lh=class extends bh{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,xh.COMMA_EXPRESSION,r,[...Kh(e,t)]),this.elementList=e,this.commaList=t}},Rh=class extends Ih{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=xh.GROUP_EXPRESSION}},zh=class extends bh{constructor({callee:e,argumentList:t},n,r){super(n,xh.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},Bh=class extends bh{constructor({literal:e},t,n){super(t,xh.LITERAL,n,[e]),this.literal=e}},Vh=class extends bh{constructor({token:e},t,n){super(t,xh.WILDCARD,n,[e]),this.token=e}},Hh=class extends bh{constructor({variable:e},t,n){super(t,xh.VARIABLE,n,[e]),this.variable=e}},Uh=class extends bh{constructor({expression:e},t,n){super(t,xh.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},Wh=class extends bh{constructor({prevToken:e},t,n){let r=tm.create(em.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,xh.EMPTY,n,[r])}},Gh=class extends bh{constructor({expression:e,indexer:t},n,r){super(n,xh.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function Kh(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?Une($p(e,t)):Une($p(t,e))).filter(e=>e!==null)}var qh=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e}({}),Jh=class e{static#e=this.id=0;constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}},Yh=class extends Jh{constructor(e){super(e),this.kind=qh.Ref}container(e){let t=this.declaration.parentOfKind(Eh);if(t?.isKind(_d.Table))return e.nodeSymbol(t).getFiltered(gd)}leftColumns(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return[];let n=t.callee;return n instanceof Ah?Qh(e,n.leftExpression):[]}if(this.declaration instanceof Oh){let t=this.declaration.parentOfKind(Nh);if(!t)return[];let n=e.nodeSymbol(t).getFiltered(gd);return n?[n]:[]}return[]}rightColumns(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return[];let n=t.callee;return n instanceof Ah?Qh(e,n.rightExpression):[]}if(this.declaration instanceof Oh){let t=this.declaration.value;return t instanceof kh?Qh(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return;let n=t.callee;return n instanceof Ah?$h(e,n.leftExpression):void 0}if(this.declaration instanceof Oh)return this.container(e)}rightTable(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return;let n=t.callee;return n instanceof Ah?$h(e,n.rightExpression):void 0}if(this.declaration instanceof Oh){let t=this.declaration.value;return t instanceof kh?$h(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(!(e instanceof Nh))return;let t=e.callee;return t instanceof Ah?t.op?.value:void 0}if(this.declaration instanceof Oh){let e=this.declaration.value;return e instanceof kh?e.op?.value:void 0}}leftToken(){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(e instanceof Nh){let t=e.callee;if(t instanceof Ah&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof Oh){let e=this.declaration.parentOfKind(Nh);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(e instanceof Nh){let t=e.callee;if(t instanceof Ah&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof Oh,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);if(!t||!n)return[];let r=this.declaration.filepath;return e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(i=>e.reachableFiles(i.filepath).some(e=>e.equals(r))&&i.inNestedSchema(e,t)&&i.inNestedSchema(e,n))}},Xh=class extends Jh{constructor(e){super(e),this.kind=qh.PartialRef}container(e){let t=this.declaration.parentOfKind(Eh);if(t?.isKind(_d.TablePartial))return e.nodeSymbol(t).getFiltered(gd)}leftColumns(e){if(!(this.declaration instanceof Oh))return[];let t=this.declaration.parentOfKind(Nh);if(!t)return[];let n=e.nodeSymbol(t).getFiltered(gd);return n?[n]:[]}rightColumns(e){if(!(this.declaration instanceof Oh))return[];let t=this.declaration.value;return t instanceof kh?Qh(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof Oh)return this.container(e)}rightTable(e){if(!(this.declaration instanceof Oh))return;let t=this.declaration.value;if(t instanceof kh)return $h(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof Oh))return;let t=this.declaration.value;if(t instanceof kh)return t.op?.value}leftToken(){if(this.declaration instanceof Oh){let e=this.declaration.parentOfKind(Nh);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof Oh,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(r=>r.inNestedSchema(e,t)&&r.inNestedSchema(e,n))}},Goe=class extends Jh{constructor(e){super(e),this.kind=qh.TableChecks,this.ownerTable=e.parentNode?.parentOfKind(Eh)}owners(e){if(!this.ownerTable)return[];let t=e.nodeSymbol(this.ownerTable).getFiltered(gd);return t?[t.originalSymbol]:[]}},Koe=class extends Jh{constructor(e){super(e),this.kind=qh.Indexes,this.ownerTable=e.parentNode?.parentOfKind(Eh)}owners(e){if(!this.ownerTable)return[];let t=e.nodeSymbol(this.ownerTable).getFiltered(gd);return t?[t.originalSymbol]:[]}},Zh=class extends Jh{constructor(e){super(e),this.kind=qh.Records}table(e){let t=this.declaration,n=t.parent;if(n instanceof Eh&&n.isKind(_d.Table))return e.nodeSymbol(n).getFiltered(gd);let r=t.name;if(!(r instanceof zh))return;let i=$m(r);if(!i)return;let a=i.variables.at(-1);if(a)return e.nodeReferee(a).getFiltered(gd)?.originalSymbol}owners(e){let t=this.table(e);return t?e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(n=>n.inNestedSchema(e,t)):[]}},qoe=class extends Jh{constructor(e){super(e),this.kind=qh.Project}owners(e){let t=this.declaration.filepath,n=e.parseFile(t).getValue().ast,r=e.nodeSymbol(n).getFiltered(gd);return r?[r]:[]}};function Qh(e,t){if(!t)return[];let n=Ym(t);return n?(n.tupleElements.length>0?n.tupleElements:n.variables.at(-1)?[n.variables.at(-1)]:[]).flatMap(t=>{let n=e.nodeReferee(t).getFiltered(gd);return n?[n]:[]}):[]}function $h(e,t){if(!t)return;let n=Ym(t);if(!n)return;let r=n.tupleElements.length>0?n.variables.at(-1):n.variables.at(-2);if(r)return e.nodeReferee(r).getFiltered(gd)}var Joe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Yoe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof Ph?new k(e.body.flatMap(e=>{if(!(e instanceof Nh))return[];let t=ih(e),n=e.callee instanceof Mh?e.callee.value?.value??``:``,r,i=e.args.find(e=>e instanceof Fh);return i&&(r=Zm(km(i).getValue()[vd.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new k([])}},Xoe={nodeMetadata(e,t){if(Im(t,_d.Checks)){let e=t.parent;return!e||!Im(e,_d.Table)&&!Im(e,_d.TablePartial)?k.create(hd):k.create(new Goe(t))}return k.create(hd)},bindNode(e,t){return Im(t,_d.Checks)?k.create(void 0,new Joe(e,t).bind()):k.create(hd)},interpretMetadata(e,t){return t.kind===qh.TableChecks?t.declaration instanceof Eh?new Yoe(e,t.declaration).interpret():k.create(void 0):k.create(hd)}};function Zoe(e,t,n){let r=t,i=e;if(i instanceof zh&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Nm(i)||r.length===0)return;let a=[...r],o=koe(i),s=a.pop();if(!(s instanceof Ph))return;let c=qp(a)instanceof Fh?a.pop():void 0;if(a.length===3){let e=koe(a[1]);return!e||!im(e)?void 0:n.create(Eh,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(Eh,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(Eh,{type:o,attributeList:c,body:s})}function eg(e){e&&(e instanceof tm?Qoe(e):$oe(e))}function Qoe(e){e.kind!==em.EOF&&(e.isInvalid=!0)}function $oe(e){if(e instanceof Eh)eg(e.type),eg(e.name),eg(e.as),eg(e.alias),eg(e.bodyColon),eg(e.attributeList),eg(e.body);else if(e instanceof Dh)e.identifiers.forEach(eg);else if(e instanceof Oh)eg(e.name),eg(e.colon),eg(e.value);else if(e instanceof kh)eg(e.op),eg(e.expression);else if(e instanceof Ah)eg(e.leftExpression),eg(e.op),eg(e.rightExpression);else if(e instanceof jh)eg(e.op),eg(e.expression);else if(e instanceof Ph)eg(e.blockOpenBrace),e.body.forEach(eg),eg(e.blockCloseBrace);else if(e instanceof Fh)eg(e.listOpenBracket),e.commaList.forEach(eg),e.elementList.forEach(eg),eg(e.listCloseBracket);else if(e instanceof Ih)eg(e.tupleOpenParen),e.commaList.forEach(eg),e.elementList.forEach(eg),eg(e.tupleCloseParen);else if(e instanceof Lh)e.commaList.forEach(eg),e.elementList.forEach(eg);else if(e instanceof zh)eg(e.callee),eg(e.argumentList);else if(e instanceof Nh)eg(e.callee),e.args.forEach(eg);else if(e instanceof Uh)eg(e.expression);else if(e instanceof Mh)eg(e.value);else if(e instanceof Hh)eg(e.variable);else if(e instanceof Bh)eg(e.literal);else if(e instanceof Rh)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof Gh)eg(e.array),eg(e.indexer);else if(e instanceof Sh)e.body.forEach(eg),eg(e.eof);else if(!(e instanceof Wh))if(e instanceof Ch)eg(e.useKeyword),eg(e.specifiers),eg(e.fromKeyword),eg(e.importPath);else if(e instanceof Th)eg(e.openBrace),e.specifiers.forEach(eg),eg(e.closeBrace);else if(e instanceof wh)eg(e.importKind),eg(e.name);else if(e instanceof Vh)eg(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function tg(...e){return e.filter(e=>e!==void 0)}function ng(e){if(e instanceof Sh)return tg(...e.body,e.eof);if(e instanceof Eh)return tg(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof Oh)return tg(e.name,e.colon,e.value);if(e instanceof Dh)return e.identifiers;if(e instanceof Bh)return e.literal?[e.literal]:[];if(e instanceof Hh)return tg(e.variable);if(e instanceof kh)return tg(e.op,e.expression);if(e instanceof Ah)return tg(e.leftExpression,e.op,e.rightExpression);if(e instanceof jh)return tg(e.expression,e.op);if(e instanceof Mh)return tg(e.value);if(e instanceof Nh)return tg(e.callee,...e.args);if(e instanceof Ph)return tg(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof Fh)return tg(e.listOpenBracket,...rg(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Ih)return tg(e.tupleOpenParen,...rg(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Lh)return tg(...rg(e.elementList,e.commaList));if(e instanceof zh)return tg(e.callee,e.argumentList);if(e instanceof Uh)return tg(e.expression);if(e instanceof Gh)return tg(e.array,e.indexer);if(e instanceof Wh)return[];if(e instanceof Ch)return tg(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof Th)return tg(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof wh)return tg(e.importKind,e.name);if(e instanceof Vh)return tg(e.token);throw e instanceof Rh?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function rg(e,t){let n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)n.push(e[i],t[i]);return n.push(...e.slice(r),...t.slice(r)),n}function ese(e,t){let n=[...e.parseProject().values()].some(e=>e.getErrors().length>0),r=e.validateNode(t).getErrors().length>0,i=e.bindNode(t).getErrors().length>0;return!n&&!r&&!i}function ig(e){if(!e)return[];if(jm(e))return[{variables:[e],tupleElements:[]}];if(e instanceof Ah){let t=Ym(e);return t?[t]:[...ig(e.leftExpression),...ig(e.rightExpression)]}if(e instanceof kh||e instanceof jh)return ig(e.expression);if(e instanceof Ih){let t=Ym(e);return t?[t]:e.elementList.flatMap(ig)}return[]}function ag(e,t){let n=t.parentNode;if(!n||!Pm(n)||n.rightExpression!==t)return;let r=n.leftExpression;for(;Pm(r);)r=r.rightExpression;return e.nodeReferee(r).getFiltered(gd)??void 0}function tse(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var nse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=Zp(e.body,e=>e instanceof Nh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof Ph)?[]:e.isKind(_d.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(_d.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(_d.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(_d.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:[e.callee,...e.args].flatMap(ig).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindNoteReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},rse=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:n}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=n,this.declarationNode.body instanceof Ph&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new k(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof Nh&&Mm(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=Zp(e.body,e=>e instanceof Eh),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof Ph&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;return(n.has(`tables`)&&r.tables!==null||n.has(`tablegroups`)&&r.tableGroups!==null||n.has(`schemas`)&&r.schemas!==null)&&(n.has(`tables`)||(r.tables=[]),n.has(`tablegroups`)||(r.tableGroups=[]),n.has(`schemas`)||(r.schemas=[])),n.has(`tables`)&&this.diagramViewExplicitlySet.add(`tables`),n.has(`tablegroups`)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(`schemas`)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(`notes`)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,t){if(!t)return;if(e.body.some(e=>e instanceof Nh&&Mm(e.callee))){let e=this.diagramViewWildcards;switch(t){case`tables`:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case`notes`:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case`schemas`:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let n=[];for(let t of e.body){if(!(t instanceof Nh))continue;let e=t.callee&&this.compiler.nodeReferee(t.callee).getFiltered(gd);if(e?.declaration instanceof Eh){let t=Jm(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],r=t.length>1?t.slice(0,-1).join(`.`):pm;n.push({name:e,schemaName:r});continue}}let r=Jm(t.callee)??[];if(r.length===0)continue;let i=r[r.length-1],a=r.length>1?r[0]:pm;n.push({name:i,schemaName:a})}switch(t){case`tables`:this.diagramView.visibleEntities.tables=n.length>0?n:null;break;case`notes`:this.diagramView.visibleEntities.stickyNotes=n.length>0?n.map(e=>({name:e.name})):null;break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=n.length>0?n.map(e=>({name:e.name})):null;break;case`schemas`:this.diagramView.visibleEntities.schemas=n.length>0?n.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,t=this.compiler.nodeSymbol(e).getFiltered(gd);if(!t)return[];let n=this.compiler.symbolMembers(t).getFiltered(gd);return n?Qp(n.filter(e=>e.isKind(P.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function ise(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var ase=function(e){return e.Table=`table`,e}({}),og={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},ose={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.DiagramView)?new k(e.symbolFactory.create(Roe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramView)&&t instanceof Vh?new k(e.symbolFactory.create(zoe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewNotes)?new k(e.symbolFactory.create(Hoe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewTables)?new k(e.symbolFactory.create(Boe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewTableGroups)?new k(e.symbolFactory.create(Voe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewSchemas)?new k(e.symbolFactory.create(Uoe,{declaration:t,name:n},t.filepath)):k.create(hd)},nodeReferee(e,t){if(t.parent&&Hm(t))return k.create(hd);let n=sse(t);if(!n)return k.create(hd);let r=e.parseFile(t.filepath).getValue().ast,i=e.nodeSymbol(r).getFiltered(gd);return i?n.isKind(_d.DiagramViewTables)?cse(e,i,t):n.isKind(_d.DiagramViewNotes)?lse(e,i,t,P.StickyNote):n.isKind(_d.DiagramViewTableGroups)?lse(e,i,t,P.TableGroup):n.isKind(_d.DiagramViewSchemas)?use(e,i,t):k.create(hd):k.create(void 0)},symbolMembers(e,t){if(!t.isKind(P.DiagramView))return k.create(hd);if(!t.declaration)return k.create([]);let n=t.declaration;if(!Im(n,_d.DiagramView))return k.create([]);let r=[],i=[];for(let t of Km(n))if(t instanceof Nh){let n=e.nodeSymbol(t).getFiltered(gd);n&&i.push(n)}else t instanceof Eh&&i.push(...Km(t).flatMap(t=>e.nodeSymbol(t).getFiltered(gd)??[]));let a=new Map;for(let t of i){if(!t.isKind(P.DiagramViewSchema,P.DiagramViewTableGroup,P.DiagramViewTable,P.DiagramViewNote)||!t.declaration)continue;let n=(e.nodeFullname(t.declaration).getFiltered(gd)||[]).map(gv).join(`.`),i=`${t.kind}:${n}`;if(n!==void 0){let e=t.declaration,o=a.get(i);o?(r.push(og.getFieldDuplicateError(n,t.kind,o)),r.push(og.getFieldDuplicateError(n,t.kind,e))):a.set(i,e)}}return k.create(i,r)},bindNode(e,t){if(!Im(t,_d.DiagramView))return k.create(hd);let n=new nse(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof Roe?t.declaration instanceof Eh?new rse(e,t.declaration,t,n).interpret():k.create(void 0):k.create(hd)}};function sse(e){let t=e.parentOfKind(Nh);if(!t)return;let n=t.parentNode;if(!(n instanceof Ph))return;let r=n.parentNode;if(!(r instanceof Eh)||!r.isKind(_d.DiagramViewTables,_d.DiagramViewNotes,_d.DiagramViewTableGroups,_d.DiagramViewSchemas))return;let i=r.parentNode;if(!(i instanceof Ph))return;let a=i.parentNode;if(!(!(a instanceof Eh)||!a.isKind(_d.DiagramView)))return r}function cse(e,t,n){let r=th(n);if(r===void 0)return k.create(void 0);if(Pm(n.parentNode)){let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=Ooe(n),a=e.lookupMembers(i,t?P.Table:P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find ${t?`table`:`schema`} '${r}'`,n)])}return new k(void 0)}let a=e.lookupMembers(t,P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find schema '${r}'`,n)])}let i=e.symbolMembers(t).getFiltered(gd)||[];for(let e of i){let t=e.name;if(e.isKind(P.Table)&&r===t)return k.create(e)}let a=e.lookupMembers(t,P.Table,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find table '${r}'`,n)])}function lse(e,t,n,r){let i=th(n);if(i===void 0)return k.create(void 0);let a=e.lookupMembers(t,r,i);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find ${r===P.StickyNote?`note`:`tablegroup`} '${i}'`,n)])}function use(e,t,n){let r=th(n);if(r===void 0)return k.create(void 0);let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Could not find schema '${r}'`,n)])}var dse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof Nh)return[];let t=e.body.filter(e=>e instanceof Eh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},fse=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=ih(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return k.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=ih(t),n.name=eh(t.callee);let r=km(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:ah(Zm(r.value)),token:ih(r)},this.enum.values.push(n),[]})}},sg={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},pse={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.Enum)?new k(e.symbolFactory.create(fh,{declaration:t,name:n},t.filepath)):zm(t,_d.Enum)?new k(e.symbolFactory.create(Noe,{declaration:t,name:n},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Enum))return k.create(hd);let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=o.get(t);r?(a.push(sg.getFieldDuplicateError(t,r)),a.push(sg.getFieldDuplicateError(t,n))):o.set(t,n)}}return new k(i,a)},bindNode(e,t){if(!Im(t,_d.Enum))return k.create(hd);let n=new dse(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof fh?new fse(e,t,n).interpret():k.create(hd)}},mse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof Eh)||!this.declarationNode.parent.isKind(_d.Table)||!(this.declarationNode.body instanceof Ph)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=Jm(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(ig).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let n=th(e);if(n===void 0)return[];let r=this.compiler.nodeReferee(e);return!r.getValue()||r.hasValue(gd)?new N(M.BINDING_ERROR,`No column named '${n}' inside Table '${t}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},hse=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof Ph?new k(e.body.flatMap(e=>{if(!(e instanceof Nh)||!e.callee)return[];let t=[],n=ih(e),r=[e.callee,...e.args],i,a,o,s,c;qp(r)instanceof Fh&&r.pop();let l=this.compiler.nodeSettings(e).getFiltered(gd);if(l){i=!!l[vd.PK]?.length||void 0,a=!!l[vd.Unique]?.length||void 0,o=Zm(l[vd.Name]?.at(0)?.value);let e=l[vd.Note]?.at(0);if(e){let t=Zm(e.value);t!==void 0&&(s={value:t,token:ih(e)})}c=eh(l[vd.Type]?.at(0)?.value)}let u=r.flatMap(e=>{if(!(e instanceof zh))return e;let t=[],n=e;for(;n instanceof zh&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of u){let n=Xm(e);if(n){for(let e of n.functional)t.push({value:e.value?.value??``,type:`expression`,token:ih(e)});for(let e of n.nonFunctional)t.push({value:th(e)??``,type:`column`,token:ih(e)})}}return[{columns:t,pk:i,unique:a,name:o,note:s,type:c,token:n}]})):new k([])}},gse={nodeMetadata(e,t){if(!Im(t,_d.Indexes))return k.create(hd);let n=t.parent;return!n||!Im(n,_d.Table)&&!Im(n,_d.TablePartial)?k.create(hd):k.create(new Koe(t))},nodeReferee(e,t){if(!jm(t)||Hm(t))return k.create(hd);let n=t;for(;n&&!Im(n,_d.Indexes);)n=n.parent;if(!n)return k.create(hd);let r=n.parent;if(!r||!Im(r,_d.Table)&&!Im(r,_d.TablePartial))return k.create(hd);let i=e.nodeSymbol(r).getFiltered(gd);if(!i)return new k(void 0);let a=jm(t)?t.expression.variable?.value??``:``,o=e.lookupMembers(i,P.Column,a);if(o)return k.create(o);let s=Im(r,_d.TablePartial)?`TablePartial`:`Table`;return new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${a}' does not exist in ${s} 'public.${i.name}'`,t)])},bindNode(e,t){return Im(t,_d.Indexes)?k.create(void 0,new mse(e,t).bind()):k.create(hd)},interpretMetadata(e,t){return t.kind===qh.Indexes?t.declaration instanceof Eh?new hse(e,t.declaration).interpret():k.create(void 0):k.create(hd)}};function cg(e,t){let n=qm(t);if(!n||n.length===0)return;let r=n[n.length-1];if(r instanceof Ih){let t=[];for(let n of r.elementList){let r=e.nodeReferee(n).getFiltered(gd);if(!r)return;t.push(r.originalSymbol)}return t}let i=n[n.length-1];if(!i||i instanceof Ih)return;let a=e.nodeReferee(i).getFiltered(gd);if(a)return[a.originalSymbol]}function _se(e,t,n,r){let i=e.map(e=>e.intern()).sort().join(`,`),a=t.map(e=>e.intern()).sort().join(`,`);if(i===a)return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new N(M.CIRCULAR_REF,`References with same endpoints exist`,n),new N(M.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var vse=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],t=this.compiler.reachableFiles(this.ast.filepath);for(let n of t){let{ast:t}=this.compiler.parseFile(n).getFiltered(gd)||{ast:void 0};if(!t)continue;let r=t.body.filter(e=>e instanceof Eh&&e.isKind(_d.Project));r.length>1&&r.forEach(t=>e.push(new N(M.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let n of t.body)if(n instanceof Eh&&n.type){let t=n;e.push(...this.compiler.bindNode(t).getErrors())}else e.push(...this.compiler.bindNode(n).getErrors())}let n=this.compiler.nodeSymbol(this.ast).getFiltered(gd);return n&&e.push(...yse(this.compiler,n)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new k(void 0,e)}checkDuplicateRefs(){let e=[],t=new Map,n=this.compiler.reachableFiles(this.ast.filepath);for(let r of n){let n=this.compiler.parseFile(r).getFiltered(gd);if(!n)continue;let{ast:i}=n;for(let n of i.body){if(!(n instanceof Eh)||!n.type)continue;let r=n;Im(r,_d.Ref)&&e.push(...this.checkStandaloneRefs(r,t)),Im(r,_d.Table)&&e.push(...this.checkInlineRefs(r,t)),Im(r,_d.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(r))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of Km(e)){if(!(r instanceof Nh)||!r.callee||!Um(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=cg(this.compiler,i.leftExpression),o=cg(this.compiler,i.rightExpression);!a||!o||n.push(..._se(a,o,e,t))}return n}checkInlineRefs(e,t){let n=[];for(let r of Km(e)){if(!(r instanceof Nh)||!r.callee)continue;let e=this.compiler.nodeSymbol(r).getFiltered(gd);if(!e)continue;let i=this.compiler.nodeSettings(r).getFiltered(gd);if(!i)continue;let a=i[vd.Ref];if(!(!a||a.length===0))for(let r of a){let i=r.value;if(!(i instanceof kh)||!i.op||!Cm(i.op.value)||!i.expression)continue;let a=cg(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];n.push(..._se(o,a,r,t))}}return n}checkTablePartialSelfRefs(e){let t=[];for(let n of Km(e)){if(!(n instanceof Nh)||!n.callee)continue;let e=eh(n.callee);if(!e)continue;let r=this.compiler.nodeSettings(n).getFiltered(gd);if(!r)continue;let i=r[vd.Ref];if(!(!i||i.length===0))for(let n of i){let r=n.value;r instanceof kh&&(!r.op||!Cm(r.op.value)||r.expression&&jm(r.expression)&&r.expression.expression.variable?.value===e&&t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)))}}return t}checkTableGroups(){let e=[],t=new Map,n=this.compiler.reachableFiles(this.ast.filepath);for(let r of n){let n=this.compiler.parseFile(r).getFiltered(gd);if(!n)continue;let{ast:i}=n;for(let n of i.body){if(!(n instanceof Eh)||!n.type)continue;let r=n;if(!Im(r,_d.TableGroup))continue;let i=r.name?Jm(r.name):void 0,a=i?i.join(`.`):`<unknown>`,o=Km(r);for(let n of o){if(!(n instanceof Nh)||!n.callee)continue;let r=qm(n.callee);if(!r||r.length===0)continue;let i=r[r.length-1],o=this.compiler.nodeReferee(i).getFiltered(gd)?.originalSymbol;if(!o)continue;let s=t.get(o.id);if(s){let t=Jm(n.callee),r=t?t.join(`.`):`<unknown>`;e.push(new N(M.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r}" already appears in group "${s.groupName}"`,n))}else t.set(o.id,{groupName:a,node:n})}}}return e}};function yse(e,t,n=new Set){if(n.has(t.id))return[];n.add(t.id);let r=e.symbolMembers(t),i=[...r.getErrors()],a=r.getFiltered(gd);if(!a)return i;for(let t of a)t instanceof dh&&i.push(...yse(e,t,n));return i}function bse(e,t,n){t.isKind(P.Table)?e.externals.tables.push(n):t.isKind(P.Enum)?e.externals.enums.push(n):t.isKind(P.TableGroup)?e.externals.tableGroups.push(n):t.isKind(P.TablePartial)?e.externals.tablePartials.push(n):t.isKind(P.StickyNote)&&e.externals.notes.push(n)}var xse={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},Sse={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},Cse={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},wse={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},Tse={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},Ese={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},Dse={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function lg(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function ug(e,t){let n=lg(e);return t?xse[t].has(n):Object.values(xse).some(e=>e.has(n))}function dg(e,t){let n=lg(e);return t?Sse[t].has(n):Object.values(Sse).some(e=>e.has(n))}function fg(e,t){return ug(e,t)||dg(e,t)}function pg(e,t){let n=lg(e);return t?Cse[t].has(n):Object.values(Cse).some(e=>e.has(n))}function mg(e,t){let n=lg(e);return t?wse[t].has(n):Object.values(wse).some(e=>e.has(n))}function hg(e,t){let n=lg(e);return t?Tse[t].has(n):Object.values(Tse).some(e=>e.has(n))}function gg(e,t){let n=lg(e);return t?Ese[t].has(n):Object.values(Ese).some(e=>e.has(n))}function _g(e,t){let n=lg(e);return t?Dse[t].has(n):Object.values(Dse).some(e=>e.has(n))}function Ose(e,t){if(t)return`string`;if(ug(e))return`integer`;if(dg(e))return`real`;if(pg(e))return`bool`;if(mg(e))return`string`;let n=lg(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:gg(e)?`datetime`:e}var vg=class extends Error{},kse=class extends vg{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Ase=class extends vg{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},jse=class extends vg{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},yg=class extends vg{},Mse=class extends vg{constructor(e){super(`Invalid unit ${e}`)}},bg=class extends vg{},xg=class extends vg{constructor(){super(`Zone is an abstract class`)}},Sg=`numeric`,Cg=`short`,wg=`long`,Tg={year:Sg,month:Sg,day:Sg},Nse={year:Sg,month:Cg,day:Sg},Pse={year:Sg,month:Cg,day:Sg,weekday:Cg},Fse={year:Sg,month:wg,day:Sg},Ise={year:Sg,month:wg,day:Sg,weekday:wg},Lse={hour:Sg,minute:Sg},Rse={hour:Sg,minute:Sg,second:Sg},zse={hour:Sg,minute:Sg,second:Sg,timeZoneName:Cg},Bse={hour:Sg,minute:Sg,second:Sg,timeZoneName:wg},Vse={hour:Sg,minute:Sg,hourCycle:`h23`},Hse={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`},Use={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`,timeZoneName:Cg},Wse={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`,timeZoneName:wg},Gse={year:Sg,month:Sg,day:Sg,hour:Sg,minute:Sg},Kse={year:Sg,month:Sg,day:Sg,hour:Sg,minute:Sg,second:Sg},qse={year:Sg,month:Cg,day:Sg,hour:Sg,minute:Sg},Jse={year:Sg,month:Cg,day:Sg,hour:Sg,minute:Sg,second:Sg},Yse={year:Sg,month:Cg,day:Sg,weekday:Cg,hour:Sg,minute:Sg},Xse={year:Sg,month:wg,day:Sg,hour:Sg,minute:Sg,timeZoneName:Cg},Zse={year:Sg,month:wg,day:Sg,hour:Sg,minute:Sg,second:Sg,timeZoneName:Cg},Qse={year:Sg,month:wg,day:Sg,weekday:wg,hour:Sg,minute:Sg,timeZoneName:wg},$se={year:Sg,month:wg,day:Sg,weekday:wg,hour:Sg,minute:Sg,second:Sg,timeZoneName:wg},Eg=class{get type(){throw new xg}get name(){throw new xg}get ianaName(){return this.name}get isUniversal(){throw new xg}offsetName(e,t){throw new xg}formatOffset(e,t){throw new xg}offset(e){throw new xg}equals(e){throw new xg}get isValid(){throw new xg}},Dg=null,ece=class e extends Eg{static get instance(){return Dg===null&&(Dg=new e),Dg}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ele(e,t,n)}formatOffset(e,t){return v_(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Og=new Map;function tce(e){let t=Og.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,era:`short`}),Og.set(e,t)),t}var nce={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function rce(e,t){let n=e.format(t).replace(/\u200E/g,``),[,r,i,a,o,s,c,l]=/(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(n);return[a,r,i,o,s,c,l]}function ice(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=nce[t];t===`era`?r[a]=i:$g(a)||(r[a]=parseInt(i,10))}return r}var kg=new Map,Ag=class e extends Eg{static create(t){let n=kg.get(t);return n===void 0&&kg.set(t,n=new e(t)),n}static resetCache(){kg.clear(),Og.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ele(e,t,n,this.name)}formatOffset(e,t){return v_(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=tce(this.name),[r,i,a,o,s,c,l]=n.formatToParts?ice(n,t):rce(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=p_({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},ace={};function oce(e,t={}){let n=JSON.stringify([e,t]),r=ace[n];return r||(r=new Intl.ListFormat(e,t),ace[n]=r),r}var jg=new Map;function Mg(e,t={}){let n=JSON.stringify([e,t]),r=jg.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),jg.set(n,r)),r}var Ng=new Map;function sce(e,t={}){let n=JSON.stringify([e,t]),r=Ng.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Ng.set(n,r)),r}var Pg=new Map;function cce(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Pg.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Pg.set(i,a)),a}var Fg=null;function lce(){return Fg||(Fg=new Intl.DateTimeFormat().resolvedOptions().locale,Fg)}var Ig=new Map;function uce(e){let t=Ig.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Ig.set(e,t)),t}var Lg=new Map;function dce(e){let t=Lg.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...bce,...t}),Lg.set(e,t)}return t}function fce(e){let t=e.indexOf(`-x-`);t!==-1&&(e=e.substring(0,t));let n=e.indexOf(`-u-`);if(n===-1)return[e];{let t,r;try{t=Mg(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Mg(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function pce(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function mce(e){let t=[];for(let n=1;n<=12;n++){let r=nv.utc(2009,n,1);t.push(e(r))}return t}function hce(e){let t=[];for(let n=1;n<=7;n++){let r=nv.utc(2016,11,13+n);t.push(e(r))}return t}function Rg(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function gce(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||uce(e.locale).numberingSystem===`latn`}var _ce=class{constructor(e,t,n){this.padTo=n.padTo||0,this.floor=n.floor||!1;let{padTo:r,floor:i,...a}=n;if(!t||Object.keys(a).length>0){let t={useGrouping:!1,...n};n.padTo>0&&(t.minimumIntegerDigits=n.padTo),this.inf=sce(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return a_(this.floor?Math.floor(e):l_(e,3),this.padTo)}},vce=class{constructor(e,t,n){this.opts=n,this.originalZone=void 0;let r;if(this.opts.timeZone)this.dt=e;else if(e.zone.type===`fixed`){let t=-1*(e.offset/60),n=t>=0?`Etc/GMT+${t}`:`Etc/GMT${t}`;e.offset!==0&&Ag.create(n).valid?(r=n,this.dt=e):(r=`UTC`,this.dt=e.offset===0?e:e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone)}else e.zone.type===`system`?this.dt=e:e.zone.type===`iana`?(this.dt=e,r=e.zone.name):(r=`UTC`,this.dt=e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone);let i={...this.opts};i.timeZone=i.timeZone||r,this.dtf=Mg(t,i)}format(){return this.originalZone?this.formatToParts().map(({value:e})=>e).join(``):this.dtf.format(this.dt.toJSDate())}formatToParts(){let e=this.dtf.formatToParts(this.dt.toJSDate());return this.originalZone?e.map(e=>{if(e.type===`timeZoneName`){let t=this.originalZone.offsetName(this.dt.ts,{locale:this.dt.locale,format:this.opts.timeZoneName});return{...e,value:t}}else return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},yce=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&qce()&&(this.rtf=cce(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):yle(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},bce={firstDay:1,minimalDays:4,weekend:[6,7]},zg=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||Kg.defaultLocale;return new e(o||(a?`en-US`:lce()),n||Kg.defaultNumberingSystem,r||Kg.defaultOutputCalendar,r_(i)||Kg.defaultWeekSettings,o)}static resetCache(){Fg=null,jg.clear(),Ng.clear(),Pg.clear(),Ig.clear(),Lg.clear()}static fromObject({locale:t,numberingSystem:n,outputCalendar:r,weekSettings:i}={}){return e.create(t,n,r,i)}constructor(e,t,n,r,i){let[a,o,s]=fce(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=pce(this.locale,this.numberingSystem,this.outputCalendar),this.weekdaysCache={format:{},standalone:{}},this.monthsCache={format:{},standalone:{}},this.meridiemCache=null,this.eraCache={},this.specifiedLocale=i,this.fastNumbersCached=null}get fastNumbers(){return this.fastNumbersCached??=gce(this),this.fastNumbersCached}listingMode(){let e=this.isEnglish(),t=(this.numberingSystem===null||this.numberingSystem===`latn`)&&(this.outputCalendar===null||this.outputCalendar===`gregory`);return e&&t?`en`:`intl`}clone(t){return!t||Object.getOwnPropertyNames(t).length===0?this:e.create(t.locale||this.specifiedLocale,t.numberingSystem||this.numberingSystem,t.outputCalendar||this.outputCalendar,r_(t.weekSettings)||this.weekSettings,t.defaultToEN||!1)}redefaultToEN(e={}){return this.clone({...e,defaultToEN:!0})}redefaultToSystem(e={}){return this.clone({...e,defaultToEN:!1})}months(e,t=!1){return Rg(this,e,ale,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=mce(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Rg(this,e,lle,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=hce(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Rg(this,void 0,()=>ule,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[nv.utc(2016,11,13,9),nv.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Rg(this,e,mle,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[nv.utc(-40,1,1),nv.utc(2017,1,1)].map(e=>this.extract(e,t,`era`))),this.eraCache[e]})}extract(e,t,n){let r=this.dtFormatter(e,t).formatToParts().find(e=>e.type.toLowerCase()===n);return r?r.value:null}numberFormatter(e={}){return new _ce(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new vce(e,this.intl,t)}relFormatter(e={}){return new yce(this.intl,this.isEnglish(),e)}listFormatter(e={}){return oce(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||uce(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Jce()?dce(this.locale):bce}getStartOfWeek(){return this.getWeekSettings().firstDay}getMinDaysInFirstWeek(){return this.getWeekSettings().minimalDays}getWeekendDays(){return this.getWeekSettings().weekend}equals(e){return this.locale===e.locale&&this.numberingSystem===e.numberingSystem&&this.outputCalendar===e.outputCalendar}toString(){return`Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`}},Bg=null,Vg=class e extends Eg{static get utcInstance(){return Bg===null&&(Bg=new e(0)),Bg}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(g_(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${v_(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${v_(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return v_(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},xce=class extends Eg{constructor(e){super(),this.zoneName=e}get type(){return`invalid`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(){return null}formatOffset(){return``}offset(){return NaN}equals(){return!1}get isValid(){return!1}};function Hg(e,t){if($g(e)||e===null)return t;if(e instanceof Eg)return e;if(Gce(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?ece.instance:n===`utc`||n===`gmt`?Vg.utcInstance:Vg.parseSpecifier(n)||Ag.create(e)}else if(e_(e))return Vg.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new xce(e)}var Ug={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Sce={arab:[1632,1641],arabext:[1776,1785],bali:[6992,7001],beng:[2534,2543],deva:[2406,2415],fullwide:[65296,65303],gujr:[2790,2799],khmr:[6112,6121],knda:[3302,3311],laoo:[3792,3801],limb:[6470,6479],mlym:[3430,3439],mong:[6160,6169],mymr:[4160,4169],orya:[2918,2927],tamldec:[3046,3055],telu:[3174,3183],thai:[3664,3673],tibt:[3872,3881]},Cce=Ug.hanidec.replace(/[\[|\]]/g,``).split(``);function wce(e){let t=parseInt(e,10);if(isNaN(t)){t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(e[n].search(Ug.hanidec)!==-1)t+=Cce.indexOf(e[n]);else for(let e in Sce){let[n,i]=Sce[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Wg=new Map;function Tce(){Wg.clear()}function Gg({numberingSystem:e},t=``){let n=e||`latn`,r=Wg.get(n);r===void 0&&(r=new Map,Wg.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Ug[n]}${t}`),r.set(t,i)),i}var Ece=()=>Date.now(),Dce=`system`,Oce=null,kce=null,Ace=null,jce=60,Mce,Nce=null,Kg=class{static get now(){return Ece}static set now(e){Ece=e}static set defaultZone(e){Dce=e}static get defaultZone(){return Hg(Dce,ece.instance)}static get defaultLocale(){return Oce}static set defaultLocale(e){Oce=e}static get defaultNumberingSystem(){return kce}static set defaultNumberingSystem(e){kce=e}static get defaultOutputCalendar(){return Ace}static set defaultOutputCalendar(e){Ace=e}static get defaultWeekSettings(){return Nce}static set defaultWeekSettings(e){Nce=r_(e)}static get twoDigitCutoffYear(){return jce}static set twoDigitCutoffYear(e){jce=e%100}static get throwOnInvalid(){return Mce}static set throwOnInvalid(e){Mce=e}static resetCaches(){zg.resetCache(),Ag.resetCache(),nv.resetCache(),Tce()}},qg=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Pce=[0,31,59,90,120,151,181,212,243,273,304,334],Fce=[0,31,60,91,121,152,182,213,244,274,305,335];function Jg(e,t){return new qg(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Yg(e,t,n){let r=new Date(Date.UTC(e,t-1,n));e<100&&e>=0&&r.setUTCFullYear(r.getUTCFullYear()-1900);let i=r.getUTCDay();return i===0?7:i}function Ice(e,t,n){return n+(u_(e)?Fce:Pce)[t-1]}function Lce(e,t){let n=u_(e)?Fce:Pce,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Xg(e,t){return(e-t+7)%7+1}function Zg(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Ice(r,i,a),s=Xg(Yg(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=m_(l,t,n)):c>m_(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...y_(e)}}function Rce(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Xg(Yg(r,1,t),n),s=d_(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=d_(l)):c>s?(l=r+1,c-=d_(r)):l=r;let{month:u,day:d}=Lce(l,c);return{year:l,month:u,day:d,...y_(e)}}function Qg(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Ice(t,n,r),...y_(e)}}function zce(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Lce(t,n);return{year:t,month:r,day:i,...y_(e)}}function Bce(e,t){if(!$g(e.localWeekday)||!$g(e.localWeekNumber)||!$g(e.localWeekYear)){if(!$g(e.weekday)||!$g(e.weekNumber)||!$g(e.weekYear))throw new yg(`Cannot mix locale-based week fields with ISO-based week fields`);return $g(e.localWeekday)||(e.weekday=e.localWeekday),$g(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),$g(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}else return{minDaysInFirstWeek:4,startOfWeek:1}}function Vce(e,t=4,n=1){let r=t_(e.weekYear),i=i_(e.weekNumber,1,m_(e.weekYear,t,n)),a=i_(e.weekday,1,7);return r?i?a?!1:Jg(`weekday`,e.weekday):Jg(`week`,e.weekNumber):Jg(`weekYear`,e.weekYear)}function Hce(e){let t=t_(e.year),n=i_(e.ordinal,1,d_(e.year));return t?n?!1:Jg(`ordinal`,e.ordinal):Jg(`year`,e.year)}function Uce(e){let t=t_(e.year),n=i_(e.month,1,12),r=i_(e.day,1,f_(e.year,e.month));return t?n?r?!1:Jg(`day`,e.day):Jg(`month`,e.month):Jg(`year`,e.year)}function Wce(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=i_(t,0,23)||t===24&&n===0&&r===0&&i===0,o=i_(n,0,59),s=i_(r,0,59),c=i_(i,0,999);return a?o?s?c?!1:Jg(`millisecond`,i):Jg(`second`,r):Jg(`minute`,n):Jg(`hour`,t)}function $g(e){return e===void 0}function e_(e){return typeof e==`number`}function t_(e){return typeof e==`number`&&e%1==0}function Gce(e){return typeof e==`string`}function Kce(e){return Object.prototype.toString.call(e)===`[object Date]`}function qce(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Jce(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Yce(e){return Array.isArray(e)?e:[e]}function Xce(e,t,n){if(e.length!==0)return e.reduce((e,r)=>{let i=[t(r),r];return e&&n(e[0],i[0])===e[0]?e:i},null)[1]}function Zce(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function n_(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function r_(e){if(e==null)return null;if(typeof e!=`object`)throw new bg(`Week settings must be an object`);if(!i_(e.firstDay,1,7)||!i_(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!i_(e,1,7)))throw new bg(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function i_(e,t,n){return t_(e)&&e>=t&&e<=n}function Qce(e,t){return e-t*Math.floor(e/t)}function a_(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function o_(e){if(!($g(e)||e===null||e===``))return parseInt(e,10)}function s_(e){if(!($g(e)||e===null||e===``))return parseFloat(e)}function c_(e){if(!($g(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function l_(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function u_(e){return e%4==0&&(e%100!=0||e%400==0)}function d_(e){return u_(e)?366:365}function f_(e,t){let n=Qce(t-1,12)+1,r=e+(t-n)/12;return n===2?u_(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function p_(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function $ce(e,t,n){return-Xg(Yg(e,1,t),n)+t-1}function m_(e,t=4,n=1){let r=$ce(e,t,n),i=$ce(e+1,t,n);return(d_(e)-r+i)/7}function h_(e){return e>99?e:e>Kg.twoDigitCutoffYear?1900+e:2e3+e}function ele(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function g_(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function tle(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new bg(`Invalid unit value ${e}`);return t}function __(e,t){let n={};for(let r in e)if(n_(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=tle(i)}return n}function v_(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${a_(n,2)}:${a_(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${a_(n,2)}${a_(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function y_(e){return Zce(e,[`hour`,`minute`,`second`,`millisecond`])}var nle=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],rle=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ile=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function ale(e){switch(e){case`narrow`:return[...ile];case`short`:return[...rle];case`long`:return[...nle];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var ole=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],sle=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],cle=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function lle(e){switch(e){case`narrow`:return[...cle];case`short`:return[...sle];case`long`:return[...ole];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ule=[`AM`,`PM`],dle=[`Before Christ`,`Anno Domini`],fle=[`BC`,`AD`],ple=[`B`,`A`];function mle(e){switch(e){case`narrow`:return[...ple];case`short`:return[...fle];case`long`:return[...dle];default:return null}}function hle(e){return ule[e.hour<12?0:1]}function gle(e,t){return lle(t)[e.weekday-1]}function _le(e,t){return ale(t)[e.month-1]}function vle(e,t){return mle(t)[e.year<0?0:1]}function yle(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function ble(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var xle={D:Tg,DD:Nse,DDD:Fse,DDDD:Ise,t:Lse,tt:Rse,ttt:zse,tttt:Bse,T:Vse,TT:Hse,TTT:Use,TTTT:Wse,f:Gse,ff:qse,fff:Xse,ffff:Qse,F:Kse,FF:Jse,FFF:Zse,FFFF:$se},b_=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return xle[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return a_(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?hle(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?_le(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?gle(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?vle(t,e):a({era:e},`era`);return ble(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return ble(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Sle=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function x_(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function S_(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function C_(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Cle(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=o_(t[n+i]);return[r,null,n+i]}}var wle=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Tle=`(?:${wle.source}?(?:\\[(${Sle.source})\\])?)?`,w_=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Ele=RegExp(`${w_.source}${Tle}`),T_=RegExp(`(?:[Tt]${Ele.source})?`),Dle=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Ole=/(\d{4})-?W(\d\d)(?:-?(\d))?/,kle=/(\d{4})-?(\d{3})/,Ale=Cle(`weekYear`,`weekNumber`,`weekDay`),jle=Cle(`year`,`ordinal`),Mle=/(\d{4})-(\d\d)-(\d\d)/,Nle=RegExp(`${w_.source} ?(?:${wle.source}|(${Sle.source}))?`),Ple=RegExp(`(?: ${Nle.source})?`);function E_(e,t,n){let r=e[t];return $g(r)?n:o_(r)}function Fle(e,t){return[{year:E_(e,t),month:E_(e,t+1,1),day:E_(e,t+2,1)},null,t+3]}function D_(e,t){return[{hours:E_(e,t,0),minutes:E_(e,t+1,0),seconds:E_(e,t+2,0),milliseconds:c_(e[t+3])},null,t+4]}function O_(e,t){let n=!e[t]&&!e[t+1],r=g_(e[t+1],e[t+2]);return[{},n?null:Vg.instance(r),t+3]}function k_(e,t){return[{},e[t]?Ag.create(e[t]):null,t+1]}var Ile=RegExp(`^T?${w_.source}$`),Lle=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function Rle(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(s_(n)),months:f(s_(r)),weeks:f(s_(i)),days:f(s_(a)),hours:f(s_(o)),minutes:f(s_(s)),seconds:f(s_(c),c===`-0`),milliseconds:f(c_(l),d)}]}var zle={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function A_(e,t,n,r,i,a,o){let s={year:t.length===2?h_(o_(t)):o_(t),month:rle.indexOf(n)+1,day:o_(r),hour:o_(i),minute:o_(a)};return o&&(s.second=o_(o)),e&&(s.weekday=e.length>3?ole.indexOf(e)+1:sle.indexOf(e)+1),s}var Ble=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function Vle(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=A_(t,i,r,n,a,o,s),p;return p=c?zle[c]:l?0:g_(u,d),[f,new Vg(p)]}function Hle(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Ule=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,Wle=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,Gle=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function Kle(e){let[,t,n,r,i,a,o,s]=e;return[A_(t,i,r,n,a,o,s),Vg.utcInstance]}function qle(e){let[,t,n,r,i,a,o,s]=e;return[A_(t,s,n,r,i,a,o),Vg.utcInstance]}var Jle=x_(Dle,T_),Yle=x_(Ole,T_),Xle=x_(kle,T_),Zle=x_(Ele),Qle=S_(Fle,D_,O_,k_),$le=S_(Ale,D_,O_,k_),eue=S_(jle,D_,O_,k_),tue=S_(D_,O_,k_);function nue(e){return C_(e,[Jle,Qle],[Yle,$le],[Xle,eue],[Zle,tue])}function rue(e){return C_(Hle(e),[Ble,Vle])}function iue(e){return C_(e,[Ule,Kle],[Wle,Kle],[Gle,qle])}function aue(e){return C_(e,[Lle,Rle])}var oue=S_(D_);function sue(e){return C_(e,[Ile,oue])}var cue=x_(Mle,Ple),lue=x_(Nle),uue=S_(D_,O_,k_);function due(e){return C_(e,[cue,Qle],[lue,uue])}var fue=`Invalid Duration`,pue={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},mue={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...pue},j_=146097/400,M_=146097/4800,hue={years:{quarters:4,months:12,weeks:j_/7,days:j_,hours:j_*24,minutes:j_*24*60,seconds:j_*24*60*60,milliseconds:j_*24*60*60*1e3},quarters:{months:3,weeks:j_/28,days:j_/4,hours:j_*24/4,minutes:j_*24*60/4,seconds:j_*24*60*60/4,milliseconds:j_*24*60*60*1e3/4},months:{weeks:M_/7,days:M_,hours:M_*24,minutes:M_*24*60,seconds:M_*24*60*60,milliseconds:M_*24*60*60*1e3},...pue},N_=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],gue=N_.slice(0).reverse();function P_(e,t,n=!1){return new F_({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function _ue(e,t){let n=t.milliseconds??0;for(let r of gue.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function vue(e,t){let n=_ue(e,t)<0?-1:1;N_.reduceRight((r,i)=>{if($g(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),N_.reduce((n,r)=>{if($g(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function yue(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var F_=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?hue:mue;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||zg.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new bg(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:__(t,e.normalizeUnit),loc:zg.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(e_(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new bg(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=aue(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=sue(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the Duration is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new jse(r);return new e({invalid:r})}static normalizeUnit(e){let t={year:`years`,years:`years`,quarter:`quarters`,quarters:`quarters`,month:`months`,months:`months`,week:`weeks`,weeks:`weeks`,day:`days`,days:`days`,hour:`hours`,hours:`hours`,minute:`minutes`,minutes:`minutes`,second:`seconds`,seconds:`seconds`,millisecond:`milliseconds`,milliseconds:`milliseconds`}[e&&e.toLowerCase()];if(!t)throw new Mse(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?b_.create(this.loc,n).formatDurationFromString(this,e):fue}toHuman(e={}){if(!this.isValid)return fue;let t=e.showZeros!==!1,n=N_.map(n=>{let r=this.values[n];return $g(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=l_(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},nv.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?_ue(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of N_)(n_(n.values,e)||n_(this.values,e))&&(r[e]=n.get(e)+this.get(e));return P_(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=tle(e(this.values[n],n));return P_(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...__(t,e.normalizeUnit)};return P_(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return P_(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return vue(this.matrix,e),P_(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=yue(this.normalize().shiftToAll().toObject());return P_(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of N_)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;e_(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else e_(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return vue(this.matrix,n),P_(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return P_(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=yue(this.values);return P_(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of N_)if(!t(this.values[n],e.values[n]))return!1;return!0}},I_=`Invalid Interval`;function bue(e,t){return!e||!e.isValid?L_.invalid(`missing or invalid start`):!t||!t.isValid?L_.invalid(`missing or invalid end`):t<e?L_.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var L_=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the Interval is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new Ase(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=rv(t),i=rv(n);return bue(r,i)??new e({start:r,end:i})}static after(t,n){let r=F_.fromDurationLike(n),i=rv(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=F_.fromDurationLike(n),i=rv(t);return e.fromDateTimes(i.minus(r),i)}static fromISO(t,n){let[r,i]=(t||``).split(`/`,2);if(r&&i){let t,a;try{t=nv.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=nv.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=F_.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=F_.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(rv).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=F_.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:I_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Tg,t={}){return this.isValid?b_.create(this.s.loc.clone(t),e).formatInterval(this):I_}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:I_}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:I_}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:I_}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:I_}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):F_.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},R_=class{static hasDST(e=Kg.defaultZone){let t=nv.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ag.isValidZone(e)}static normalizeZone(e){return Hg(e,Kg.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zg.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zg.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zg.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zg.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return zg.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return zg.create(t,null,`gregory`).eras(e)}static features(){return{relative:qce(),localeWeek:Jce()}}};function xue(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(F_.fromMillis(r).as(`days`))}function Sue(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=xue(e,t);return(n-n%7)/7}],[`days`,xue]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Cue(e,t,n,r){let[i,a,o,s]=Sue(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=F_.fromObject(a,r);return l.length>0?F_.fromMillis(c,r).shiftTo(...l).plus(u):u}var wue=`missing Intl.DateTimeFormat.formatToParts support`;function z_(e,t=e=>e){return{regex:e,deser:([e])=>t(wce(e))}}var Tue=`[ \xA0]`,Eue=new RegExp(Tue,`g`);function Due(e){return e.replace(/\./g,`\\.?`).replace(Eue,Tue)}function Oue(e){return e.replace(/\./g,``).replace(Eue,` `).toLowerCase()}function B_(e,t){return e===null?null:{regex:RegExp(e.map(Due).join(`|`)),deser:([n])=>e.findIndex(e=>Oue(n)===Oue(e))+t}}function kue(e,t){return{regex:e,deser:([,e,t])=>g_(e,t),groups:t}}function V_(e){return{regex:e,deser:([e])=>e}}function Aue(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function jue(e,t){let n=Gg(t),r=Gg(t,`{2}`),i=Gg(t,`{3}`),a=Gg(t,`{4}`),o=Gg(t,`{6}`),s=Gg(t,`{1,2}`),c=Gg(t,`{1,3}`),l=Gg(t,`{1,6}`),u=Gg(t,`{1,9}`),d=Gg(t,`{2,4}`),f=Gg(t,`{4,6}`),p=e=>({regex:RegExp(Aue(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return B_(t.eras(`short`),0);case`GG`:return B_(t.eras(`long`),0);case`y`:return z_(l);case`yy`:return z_(d,h_);case`yyyy`:return z_(a);case`yyyyy`:return z_(f);case`yyyyyy`:return z_(o);case`M`:return z_(s);case`MM`:return z_(r);case`MMM`:return B_(t.months(`short`,!0),1);case`MMMM`:return B_(t.months(`long`,!0),1);case`L`:return z_(s);case`LL`:return z_(r);case`LLL`:return B_(t.months(`short`,!1),1);case`LLLL`:return B_(t.months(`long`,!1),1);case`d`:return z_(s);case`dd`:return z_(r);case`o`:return z_(c);case`ooo`:return z_(i);case`HH`:return z_(r);case`H`:return z_(s);case`hh`:return z_(r);case`h`:return z_(s);case`mm`:return z_(r);case`m`:return z_(s);case`q`:return z_(s);case`qq`:return z_(r);case`s`:return z_(s);case`ss`:return z_(r);case`S`:return z_(c);case`SSS`:return z_(i);case`u`:return V_(u);case`uu`:return V_(s);case`uuu`:return z_(n);case`a`:return B_(t.meridiems(),0);case`kkkk`:return z_(a);case`kk`:return z_(d,h_);case`W`:return z_(s);case`WW`:return z_(r);case`E`:case`c`:return z_(n);case`EEE`:return B_(t.weekdays(`short`,!1),1);case`EEEE`:return B_(t.weekdays(`long`,!1),1);case`ccc`:return B_(t.weekdays(`short`,!0),1);case`cccc`:return B_(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return kue(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return kue(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return V_(/[a-z_+-/]{1,256}?/i);case` `:return V_(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:wue};return m.token=e,m}var Mue={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function Nue(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=Mue[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function Pue(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function Fue(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(n_(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function Iue(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return $g(e.z)||(n=Ag.create(e.z)),$g(e.Z)||(n||=new Vg(e.Z),r=e.Z),$g(e.q)||(e.M=(e.q-1)*3+1),$g(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),$g(e.u)||(e.S=c_(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var Lue=null;function Rue(){return Lue||=nv.fromMillis(1555555555555),Lue}function zue(e,t){if(e.literal)return e;let n=Wue(b_.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Bue(e,t){return Array.prototype.concat(...e.map(e=>zue(e,t)))}var Vue=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Bue(b_.parseFormat(t),e),this.units=this.tokens.map(t=>jue(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=Pue(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=Fue(e,this.regex,this.handlers),[r,i,a]=n?Iue(n):[null,null,void 0];if(n_(n,`a`)&&n_(n,`H`))throw new yg(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function Hue(e,t,n){return new Vue(e,n).explainFromTokens(t)}function Uue(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Hue(e,t,n);return[r,i,a,o]}function Wue(e,t){if(!e)return null;let n=b_.create(t,e).dtFormatter(Rue()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Nue(t,e,i))}var H_=`Invalid DateTime`,Gue=864e13;function U_(e){return new qg(`unsupported zone`,`the zone "${e.name}" is not supported`)}function W_(e){return e.weekData===null&&(e.weekData=Zg(e.c)),e.weekData}function G_(e){return e.localWeekData===null&&(e.localWeekData=Zg(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function K_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new nv({...n,...t,old:n})}function Kue(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function q_(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function J_(e,t,n){return Kue(p_(e),t,n)}function que(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,f_(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=F_.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=Kue(p_(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Y_(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=nv.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return nv.invalid(new qg(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function X_(e,t,n=!0){return e.isValid?b_.create(zg.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Z_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=a_(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=a_(e.c.month),n===`month`)return i;i+=`-`}else if(i+=a_(e.c.month),n===`month`)return i;return i+=a_(e.c.day),i}function Jue(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=a_(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=a_(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=a_(e.c.second))}else{if(c+=a_(e.c.minute),o===`minute`)break;s&&(c+=a_(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=a_(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=a_(Math.trunc(-e.o/60)),c+=`:`,c+=a_(Math.trunc(-e.o%60))):(c+=`+`,c+=a_(Math.trunc(e.o/60)),c+=`:`,c+=a_(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Yue={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Xue={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Zue={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Q_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Que=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],$ue=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function $_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Mse(e);return t}function ede(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return $_(e)}}function tde(e){if(ev===void 0&&(ev=Kg.now()),e.type!==`iana`)return e.offset(ev);let t=e.name,n=tv.get(t);return n===void 0&&(n=e.offset(ev),tv.set(t,n)),n}function nde(e,t){let n=Hg(t.zone,Kg.defaultZone);if(!n.isValid)return nv.invalid(U_(n));let r=zg.fromObject(t),i,a;if($g(e.year))i=Kg.now();else{for(let t of Q_)$g(e[t])&&(e[t]=Yue[t]);let t=Uce(e)||Wce(e);if(t)return nv.invalid(t);let r=tde(n);[i,a]=J_(e,r,n)}return new nv({ts:i,zone:n,loc:r,o:a})}function rde(e,t,n){let r=$g(n.round)?!0:n.round,i=$g(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=l_(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function ide(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var ev,tv=new Map,nv=class e{constructor(e){let t=e.zone||Kg.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new qg(`invalid input`):null)||(t.isValid?null:U_(t));this.ts=$g(e.ts)?Kg.now():e.ts;let r=null,i=null;if(!n)if(e.old&&e.old.ts===this.ts&&e.old.zone.equals(t))[r,i]=[e.old.c,e.old.o];else{let a=e_(e.o)&&!e.old?e.o:t.offset(this.ts);r=q_(this.ts,a),n=Number.isNaN(r.year)?new qg(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||zg.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=ide(arguments),[n,r,i,a,o,s,c]=t;return nde({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=ide(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Vg.utcInstance,nde({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Kce(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Hg(n.zone,Kg.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:zg.fromObject(n)}):e.invalid(U_(i))}static fromMillis(t,n={}){if(e_(t))return t<-Gue||t>Gue?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Hg(n.zone,Kg.defaultZone),loc:zg.fromObject(n)});throw new bg(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(e_(t))return new e({ts:t*1e3,zone:Hg(n.zone,Kg.defaultZone),loc:zg.fromObject(n)});throw new bg(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Hg(n.zone,Kg.defaultZone);if(!r.isValid)return e.invalid(U_(r));let i=zg.fromObject(n),a=__(t,ede),{minDaysInFirstWeek:o,startOfWeek:s}=Bce(a,i),c=Kg.now(),l=$g(n.specificOffset)?r.offset(c):n.specificOffset,u=!$g(a.ordinal),d=!$g(a.year),f=!$g(a.month)||!$g(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new yg(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new yg(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,g,_,ee=q_(c,l);h?(g=Que,_=Xue,ee=Zg(ee,o,s)):u?(g=$ue,_=Zue,ee=Qg(ee)):(g=Q_,_=Yue);let te=!1;for(let e of g){let t=a[e];$g(t)?te?a[e]=_[e]:a[e]=ee[e]:te=!0}let ne=(h?Vce(a,o,s):u?Hce(a):Uce(a))||Wce(a);if(ne)return e.invalid(ne);let[v,re]=J_(h?Rce(a,o,s):u?zce(a):a,l,r),ie=new e({ts:v,zone:r,o:re,loc:i});return a.weekday&&p&&t.weekday!==ie.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ie.toISO()}`):ie.isValid?ie:e.invalid(ie.invalid)}static fromISO(e,t={}){let[n,r]=nue(e);return Y_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=rue(e);return Y_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=iue(e);return Y_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if($g(t)||$g(n))throw new bg(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Uue(zg.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Y_(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=due(e);return Y_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the DateTime is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new kse(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Wue(e,zg.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Bue(b_.parseFormat(e),zg.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){ev=void 0,tv.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?W_(this).weekYear:NaN}get weekNumber(){return this.isValid?W_(this).weekNumber:NaN}get weekday(){return this.isValid?W_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?G_(this).weekday:NaN}get localWeekNumber(){return this.isValid?G_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?G_(this).weekYear:NaN}get ordinal(){return this.isValid?Qg(this.c).ordinal:NaN}get monthShort(){return this.isValid?R_.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?R_.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?R_.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?R_.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=p_(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=q_(s,a),u=q_(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[K_(this,{ts:s}),K_(this,{ts:c})]:[this]}get isInLeapYear(){return u_(this.year)}get daysInMonth(){return f_(this.year,this.month)}get daysInYear(){return this.isValid?d_(this.year):NaN}get weeksInWeekYear(){return this.isValid?m_(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?m_(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=b_.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Vg.instance(e),t)}toLocal(){return this.setZone(Kg.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Hg(t,Kg.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=J_(r,n,t)}return K_(this,{ts:e,zone:t})}else return e.invalid(U_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return K_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=__(e,ede),{minDaysInFirstWeek:n,startOfWeek:r}=Bce(t,this.loc),i=!$g(t.weekYear)||!$g(t.weekNumber)||!$g(t.weekday),a=!$g(t.ordinal),o=!$g(t.year),s=!$g(t.month)||!$g(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new yg(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new yg(`Can't mix ordinal dates with month/day`);let u;i?u=Rce({...Zg(this.c,n,r),...t},n,r):$g(t.ordinal)?(u={...this.toObject(),...t},$g(t.day)&&(u.day=Math.min(f_(u.year,u.month),u.day))):u=zce({...Qg(this.c),...t});let[d,f]=J_(u,this.o,this.zone);return K_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=F_.fromDurationLike(e);return K_(this,que(this,t))}minus(e){if(!this.isValid)return this;let t=F_.fromDurationLike(e).negate();return K_(this,que(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=F_.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?b_.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):H_}toLocaleString(e=Tg,t={}){return this.isValid?b_.create(this.loc.clone(t),e).formatDateTime(this):H_}toLocaleParts(e={}){return this.isValid?b_.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=$_(a);let o=e===`extended`,s=Z_(this,o,a);return Q_.indexOf(a)>=3&&(s+=`T`),s+=Jue(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Z_(this,e===`extended`,$_(t)):null}toISOWeekDate(){return X_(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=$_(o),(r&&Q_.indexOf(o)>=3?`T`:``)+Jue(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return X_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return X_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Z_(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),X_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():H_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return F_.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Yce(t).map(F_.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Cue(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?L_.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),rde(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?rde(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new bg(`min requires all arguments be DateTimes`);return Xce(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new bg(`max requires all arguments be DateTimes`);return Xce(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Hue(zg.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new Vue(zg.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if($g(t)||$g(n))throw new bg(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=zg.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new bg(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):Y_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Tg}static get DATE_MED(){return Nse}static get DATE_MED_WITH_WEEKDAY(){return Pse}static get DATE_FULL(){return Fse}static get DATE_HUGE(){return Ise}static get TIME_SIMPLE(){return Lse}static get TIME_WITH_SECONDS(){return Rse}static get TIME_WITH_SHORT_OFFSET(){return zse}static get TIME_WITH_LONG_OFFSET(){return Bse}static get TIME_24_SIMPLE(){return Vse}static get TIME_24_WITH_SECONDS(){return Hse}static get TIME_24_WITH_SHORT_OFFSET(){return Use}static get TIME_24_WITH_LONG_OFFSET(){return Wse}static get DATETIME_SHORT(){return Gse}static get DATETIME_SHORT_WITH_SECONDS(){return Kse}static get DATETIME_MED(){return qse}static get DATETIME_MED_WITH_SECONDS(){return Jse}static get DATETIME_MED_WITH_WEEKDAY(){return Yse}static get DATETIME_FULL(){return Xse}static get DATETIME_FULL_WITH_SECONDS(){return Zse}static get DATETIME_HUGE(){return Qse}static get DATETIME_HUGE_WITH_SECONDS(){return $se}};function rv(e){if(nv.isDateTime(e))return e;if(e&&e.valueOf&&e_(e.valueOf()))return nv.fromJSDate(e);if(e&&typeof e==`object`)return nv.fromObject(e);throw new bg(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function ade(e){return Nm(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Wh}function ode(e){return Zm(e)===``}function iv(e){let t=Qm(e);if(t!==null)return t;if(Em(e)&&e instanceof kh&&e.expression){let t=e.op?.value,n=Qm(e.expression);if(n!==null)return t===`-`?-n:n}return null}function av(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=iv(e);if(t!==null)return t;let n=Zm(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function sde(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=iv(e);if(t!==null)return Number.isInteger(t)?t:null;let n=Zm(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var cde=[`true`,`yes`,`y`,`t`,`1`],lde=[`false`,`no`,`n`,`f`,`0`];function ov(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1?!0:null;if(typeof e==`string`){let t=e.toLowerCase();return cde.includes(t)?!0:lde.includes(t)?!1:null}if(Nm(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=Qm(e);if(t===0)return!1;if(t===1)return!0;let n=Zm(e)?.toLowerCase();if(n){if(cde.includes(n))return!0;if(lde.includes(n))return!1}return null}function ude(e){if(e==null)return null;if(typeof e==`string`)return e;let t=Jm(e);return t?qp(t):Zm(e)??null}function sv(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=Zm(e)??null??av(e)??ov(e);return t===null?null:t.toString()}var dde=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],fde=[`yyyy-MM-dd HH:mm:ss`,`yyyy-MM-dd HH:mm:ss.SSS`,`yyyy-MM-dd HH:mm:ss.SSSZZ`,`yyyy-MM-dd HH:mm:ssZZ`],pde=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function cv(e){if(e==null)return null;let t=typeof e==`string`?e:Zm(e)??null;if(t===null)return null;for(let e of pde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of dde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of fde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=nv.fromISO(t,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)});return null;function r(e){return e.zone.type!==`system`}}function mde(e,t){let n=e.type(t),r=e.default(t);return{name:e.name??``,pk:e.pk(t),unique:e.unique(t),increment:e.increment(t),notNull:e.nullable(t)===!1,dbdefault:r,typeName:n?.name??``}}function lv(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function uv(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function hde(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function gde(e){return e.increment||_g(e.typeName)}function _de(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function dv(e,t,n){return n.length===1?_de(e,t,n[0]):`(${n.map(n=>_de(e,t,n)).join(`, `)})`}function vde(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function fv(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new hm(M.INVALID_RECORDS_FIELD,n,i)}var yde=e=>e>1?`Composite PK`:`PK`;function bde(e,t,n,r){if(Xp(r.values))return[];let i=t.mergedColumns(e).map(t=>mde(t,e)),a=Hae(i,`name`),o=lv(r),s=Tde(t,i,e),c=new Set(r.columns);return Jp(s,i=>xde(e,t,n,i,o,c,a,r))}function xde(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=wde(n,r,a,o,c,l,s);if(!Xp(u))return u;let d=Ore(r.map(e=>o[e])),f=d.every(e=>e&&gde(e)),[p,m]=Zp(i,e=>hde(e,r,d)),h=f?[]:Sde(e,p,r,c,l),g=Cde(e,m,r,d,c,l);return[...h,...g]}function Sde(e,t,n,r,i){if(Xp(t))return[];let a=`NULL in ${yde(n.length)}: ${dv(r,i,n)} cannot be NULL`;return Jp(t,t=>n.map(n=>fv(e,t[n],a)))}function Cde(e,t,n,r,i,a){return Jp(Cae(Lae(t,e=>uv(e,n,r)),e=>e.length>1),t=>{let r=yde(n.length),o=dv(i,a,n);return Jp(t,t=>{let i=`Duplicate ${r}: ${o} = ${vde(t,n)}`;return n.map(n=>fv(e,t[n],i))})})}function wde(e,t,n,r,i,a,o){let s=gae(t,Array.from(n));if(Xp(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!gde(t)&&!t.dbdefault)});if(Xp(c))return[];let l=`${yde(c.length)}: Column ${dv(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new hm(M.INVALID_RECORDS_FIELD,l,e))}function Tde(e,t,n){return[...t.filter(e=>e.pk).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value)):[]})]}var Ede=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function Dde(e,t,n){if(Xp(n.values))return[];let r=t.mergedColumns(e).map(t=>mde(t,e)),i=Hae(r,`name`),a=lv(n),o=t.schema(e),s=t.name??``;return Jp(Ode(t,r,e),t=>kde(e,a,t,Ore(t.map(e=>i[e])),o,s))}function Ode(e,t,n){return[...t.filter(e=>e.unique).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value)):[]})]}function kde(e,t,n,r,i,a){return Jp(Cae(Lae(t.filter(e=>!hde(e,n,r)),e=>uv(e,n,r)),e=>e.length>1),t=>{let r=Ede(n.length),o=dv(i,a,n);return Jp(t,t=>{let i=`Duplicate ${r}: ${o} = ${vde(t,n)}`;return n.map(n=>fv(e,t[n],i))})})}function Ade(e,t,n,r){return Jp(t,t=>Mde(e,t,n,r))}function pv(e,t,n,r,i,a){if(!t.record||Xp(t.record.values))return[];let o=lv(t.record),s=n.record?lv(n.record):[],c=new Set(s.map(e=>uv(e,i.fieldNames))),l=o.filter(e=>!hde(e,r.fieldNames)).filter(e=>{let t=uv(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return Jp(l,t=>{let n=dv(u.schema,u.name,r.fieldNames),a=dv(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${vde(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>fv(e,t[n],o))})}function jde(e,t,n,r){let i=t.schemaName===`public`?null:t.schemaName;for(let a of e.values()){let{name:e,schema:o}=a.tableSymbol.interpretedName(n,r);if(e===t.tableName&&o===i)return a}}function Mde(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=jde(n,i,e,r),s=jde(n,a,e,r);return!o||!s?[]:Nde(e,o,s,i,a,r)}function Nde(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...pv(e,t,n,r,i,a),...pv(e,n,t,i,r,a)]:o===`*`&&s===`1`?pv(e,t,n,r,i,a):o===`1`&&s===`*`?pv(e,n,t,i,r,a):[]}var Pde=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:ih(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.warnings.push(...this.validateRecords()),new k(this.db,this.errors,this.warnings)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let t=this.compiler.nodeSymbol(e).getFiltered(gd);if(!t||t instanceof vh)continue;let n=this.compiler.interpretSymbol(t,this.filepath);if(n.hasValue(gd))continue;this.errors.push(...n.getErrors()),this.warnings.push(...n.getWarnings());let r=n.getValue();r&&this.pushElement(t,r)}let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let t of e){if(!(t instanceof dh))continue;let e=this.compiler.symbolMembers(t).getFiltered(gd)??[];for(let t of e)t instanceof vh&&this.interpretUseSymbol(t)}}interpretUseSymbol(e){let t=e.originalSymbol,n=this.compiler.interpretSymbol(t,this.filepath);if(!n.hasValue(gd)){this.errors.push(...n.getErrors()),this.warnings.push(...n.getWarnings());let t=n.getValue();t&&this.pushElement(e,t)}let r=t instanceof ph?t.interpretedName(this.compiler,t.filepath):{name:t.name??``,schema:null},i=t instanceof ph?t.interpretedName(this.compiler,this.filepath):{name:e.name??t.name??``,schema:null},a={name:r.name,schemaName:r.schema,filepath:t.filepath,visibleNames:[{schemaName:i.schema,name:i.name}]};bse(this.db,e,a)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],t=new Set,n=new Map;for(let t of e){if(!(t instanceof Zh))continue;let e=t.table(this.compiler);if(!e)continue;let r=e.originalSymbol.intern(),i=n.get(r);i?i.count++:n.set(r,{count:1,tableName:e.name??``})}for(let r of e){let e=this.compiler.interpretMetadata(r,this.filepath);if(e.hasValue(gd))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings());let i=e.getValue();if(i!==void 0)switch(r.kind){case qh.Ref:{let e=i,[n,a]=e.endpoints??[];if(n&&a){let e=[n.schemaName,n.tableName,n.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`),i=[a.schemaName,a.tableName,a.fieldNames.join(`,`),n.schemaName,n.tableName,n.fieldNames.join(`,`)].join(`|`);if(t.has(e)||t.has(i)){this.errors.push(new N(M.SAME_ENDPOINT,`Ref with same endpoints already exists`,r.declaration));break}t.add(e)}this.db.refs.push(e);break}case qh.Records:if(r instanceof Zh){let e=r.table(this.compiler)?.originalSymbol.intern()??``,t=e?n.get(e):void 0;if(t&&t.count>1){this.errors.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,r.declaration));break}}this.db.records.push(i);break;case qh.Project:this.db.project=i;break;default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let t of e){if(!(t instanceof _h)||!t.isKind(P.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:ase.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],t=new Map,n=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let e of n){if(!(e instanceof dh))continue;let n=this.compiler.symbolMembers(e).getFiltered(gd)??[];for(let e of n){if(!e.isKind(P.Table))continue;let n=e.originalSymbol;if(!(n instanceof ph))continue;let r=n.intern();t.has(r)||t.set(r,{tableSymbol:n,record:void 0,recordBlock:n.declaration})}}let r=this.compiler.symbolMetadata(this.programSymbol);for(let n of r){if(!(n instanceof Zh))continue;let r=n.table(this.compiler);if(!(r instanceof ph))continue;let i=this.compiler.interpretMetadata(n,this.filepath);if(i.hasValue(gd))continue;let a=i.getValue();if(!a)continue;e.push(...bde(this.compiler,r,n.declaration,a)),e.push(...Dde(this.compiler,r,a));let o=r.originalSymbol.intern(),s=t.get(o);s?s.record=a:t.set(o,{tableSymbol:r,record:a,recordBlock:n.declaration})}let i=this.collectPartialRefs(t);return e.push(...Ade(this.compiler,[...this.db.refs,...i],t,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Xh),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof yh&&t.declaration===e.declaration)))continue;let l=tse(s);if(!l)continue;let u=a instanceof hh&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:ih(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:ih(i.rightToken())};n.push({token:ih(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case P.Table:this.db.tables.push(t);break;case P.Enum:this.db.enums.push(t);break;case P.TableGroup:this.db.tableGroups.push(t);break;case P.TablePartial:this.db.tablePartials.push(t);break;case P.StickyNote:this.db.notes.push(t);break;case P.DiagramView:this.db.diagramViews.push(t);break;default:break}}},Fde={nodeSymbol(e,t){return Rm(t)?k.create(e.symbolFactory.create(gh,{declaration:t,name:t.filepath.absolute},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Program))return k.create(hd);if(!(t.declaration instanceof Sh))return k.create([]);let n=new Map;for(let r of e.reachableFiles(t.filepath)){let{schemaMembers:t}=e.usableMembers(r).getValue();for(let e of t)n.has(e.name)||n.set(e.name,e)}let r=n.get(pm);if(!r)return k.create([...n.values()]);let i=e.symbolMembers(r).getFiltered(gd)?.filter(e=>!e.isKind(P.Schema));return i?k.create([...n.values(),...i]):k.create([...n.values()])},bindNode(e,t){return Rm(t)?new vse(t,e).resolve():k.create(hd)},interpretSymbol(e,t,n){return t instanceof gh?t.declaration instanceof Sh?ese(e,t.declaration)?new Pde(e,t,n).interpret():k.create(void 0,[...e.validateNode(t.declaration).getErrors(),...e.bindNode(t.declaration).getErrors()]):k.create(void 0):k.create(hd)}},Ide=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof Nh)return[];let t=e.body.filter(e=>e instanceof Eh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Lde=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=ih(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new k(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=oh(e);return this.project.name=t,[]}interpretSubElement(e){let t=this.compiler.nodeSymbol(e).getFiltered(gd);if(t){let e=this.compiler.interpretSymbol(t,this.filepath);if(!e.hasValue(gd))return e}return k.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case _d.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case _d.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case _d.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case _d.Note:{let e=t.body instanceof Ph?t.body.body[0]?.callee:t.body?.callee,n=e?Zm(e):void 0;return n&&(this.project.note={value:ah(n),token:ih(t)}),[]}case _d.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=Zm(t.body.callee),[]}})}},Rde={nodeMetadata(e,t){return Im(t,_d.Project)?k.create(new qoe(t)):k.create(hd)},bindNode(e,t){return Im(t,_d.Project)?k.create(void 0,new Ide(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return!(t instanceof qoe)||!(t.declaration instanceof Eh)?k.create(hd):new Lde(e,t.declaration,n).interpret()}},zde=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof Ph&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof Sh?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=$m(e);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=this.compiler.nodeReferee(n).getErrors();if(i.length>0)return i;let a=this.compiler.nodeReferee(n).getFiltered(gd);if(!a)return[];let o=Aoe(a.declaration)??`<invalid name>`,s=r.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of t.args){let t=th(e)??`<unnamed>`,n=this.compiler.nodeReferee(e).getFiltered(gd);if(!n){s.push(new N(M.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}let r=this.boundColumns.get(n);r&&(s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,r)),s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,e))),this.boundColumns.set(n,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof Eh)||!t.isKind(_d.Table)||!this.compiler.nodeSymbol(t).getFiltered(gd)||!Om(e))return[];let n=Aoe(t)??`<invalid name>`,r=[];for(let t of e.elementList){let e=th(t)??`<unnamed>`;if(!this.compiler.nodeReferee(t).getFiltered(gd)){r.push(new N(M.BINDING_ERROR,`Column '${e}' does not exist in Table '${n}'`,t));continue}}return r}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof Nh),n=e.body.filter(e=>e instanceof Eh);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Lh?e.callee.elementList:[e.callee]).flatMap(ig).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Bde=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],n=Vde(this.element,this.compiler,this.filepath);if(!n||n.columns.length===0)return new k(void 0,e);let r=[];for(let i of this.element.body.body){let a=Hde(i,n.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getWarnings());let o=a.getValue();o.row&&r.push(o.row)}let i=ih(this.element);return new k({schemaName:n.schemaName,tableName:n.tableName,columns:n.columns.map(e=>e.name??``),values:r,token:i},e,t)}};function Vde(e,t,n){let r=e.name,i=e.parent;if(i instanceof Eh&&i.isKind(_d.Table)){let e=t.nodeSymbol(i).getFiltered(gd);if(!(e instanceof ph))return;let a=e.mergedColumns(t),o=e.interpretedName(t,n),s=o.schema,c=o.name;return r?{schemaName:s,tableName:c,columns:r.elementList.flatMap(e=>a.find(t=>t.name===eh(e))||[])}:{schemaName:s,tableName:c,columns:a}}let a=$m(r);if(!a)return;let o=a.variables.map(e=>e.expression.variable?.value??``),s=o.at(-1)??``,c=o.length>1?o.slice(0,-1).join(`.`):void 0,l=t.parseFile(e.filepath).getValue().ast,u=t.nodeSymbol(l).getFiltered(gd);if(!u)return;let d;if(c){let e=t.lookupMembers(u,P.Schema,c);e&&(d=t.lookupMembers(e,P.Table,s))}if(d||=t.lookupMembers(u,P.Table,s),!d)return;let f=d.originalSymbol;if(!(f instanceof ph))return;let p=f.mergedColumns(t),m=a.args.map(e=>p.find(t=>t.name===eh(e))).filter(Boolean),h=f.interpretedName(t,n);return{schemaName:h.schema,tableName:h.name,columns:m}}function Hde(e,t,n){let r=[],i=[],a={},o=e.callee instanceof Lh?e.callee.elementList:[e.callee];if(o.length!==t.length)return r.push(new N(M.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${o.length}`,e)),new k({row:null,columnNodes:{}},r,i);let s=[];for(let e=0;e<t.length;e++){let c=o[e],l=t[e];a[l.name??``]=c;let u=Wde(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();s.push(d??{value:null,type:`expression`,token:ih(c)})}return new k({row:s,columnNodes:a},r,i)}function Ude(e){return e instanceof Mh&&e.value?.value||``}function Wde(e,t,n){let r=ih(e),i=t.type(n),a=(i?.name??``).split(`(`)[0],o=!!i?.enumSymbol,s=t.increment(n),c=t.nullable(n)===!1,l=t.default(n),u=t.name??``,d=Ose(a,o),f=sv(e),p=f===null?Ude(e):f,m=f===null?`expression`:d;if(e instanceof Mh)return new k({value:e.value?.value||``,type:`expression`,token:r},[],[]);if(ade(e)||ode(e)&&!mg(a)){let t=l&&l.value.toString().toLowerCase()!==`null`,n=_g(a);return c&&!t&&!s&&!n?new k({value:null,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${u}' without default and increment`,e)]):new k({value:null,type:d,token:r},[],[])}if(o){let i=t.type(n)?.enumSymbol,a=i?i.members(n).filter(e=>e.isKind(P.EnumField)).map(e=>e.name).filter(Boolean):[],o=Zm(e);return o===void 0&&(o=jm(e)?e.expression.variable.value:void 0),a.includes(o)?new k({value:o,type:d,token:r},[],[]):new k({value:o,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid enum value for column '${u}'`,e)])}if(ug(a)||dg(a)||_g(a)){let t=iv(e);if(t===null)return new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${u}'`,e)]);if(ug(a)&&!Number.isInteger(t))return new k({value:Math.floor(t),type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${u}': expected integer, got decimal`,e)]);let n=dg(a)&&i?.args?.length?{precision:Number(i.args[0]),scale:i.args.length>=2?Number(i.args[1]):0}:void 0;if(dg(a)&&n){let{precision:i,scale:a}=n,o=t.toString().split(`.`),s=o[0].replace(/^-/,``),c=o[1]||``,l=s.length+c.length,f=c.length;if(l>i)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${u}' exceeds precision: expected at most ${i} total digits, got ${l}`,e)]);if(f>a)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${u}' exceeds scale: expected at most ${a} decimal digits, got ${f}`,e)])}return new k({value:t,type:d,token:r},[],[])}if(pg(a)){let t=ov(e);return t===null?new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${u}'`,e)]):new k({value:t,type:d,token:r},[],[])}if(gg(a)){let t=cv(e);return t===null?new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${u}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new k({value:t,type:d,token:r},[],[])}if(mg(a)){let t=sv(e);if(t===null)return new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid string value for column '${u}'`,e)]);let n=i?.args?.length?Number(i.args[0]):void 0;if(n&&!Number.isNaN(n)){let i=n,a=new TextEncoder().encode(t).length;if(a>i)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`String value for column '${u}' exceeds maximum length: expected at most ${i} bytes (UTF-8), got ${a} bytes`,e)])}return new k({value:t,type:`string`,token:r},[],[])}return new k({value:p,type:m,token:r},[],[])}var Gde={nodeMetadata(e,t){if(!Im(t,_d.Records))return k.create(hd);let n=t.parent;if(n&&Im(n,_d.Table))return k.create(new Zh(t));let r=t.name;return r instanceof zh&&r.callee?k.create(new Zh(t)):k.create(hd)},nodeReferee(e,t){if(!jm(t))return k.create(hd);let n=t.parentOfKind(Eh);if(!n?.isKind(_d.Records))return k.create(hd);let r=e.parseFile(t.filepath).getValue().ast,i=e.nodeSymbol(r).getFiltered(gd);if(!i)return k.create(void 0);let a=t.parentOfKind(Ih);if(a?.parentNode===n)return Kde(e,n,t);let o=t.parentOfKind(zh);return o?.parentNode===n&&a?.parentNode===o?qde(e,o,t):o?.parentNode===n&&o.callee?.containsEq(t)?Jde(e,i,t):Xde(e,i,t)},bindNode(e,t){return Im(t,_d.Records)?k.create(void 0,new zde(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return t instanceof Zh?t.declaration instanceof Eh?new Bde(e,t,n).interpret():k.create(void 0):k.create(hd)}};function Kde(e,t,n){let r=t.parent;if(r instanceof Eh&&r.isKind(_d.Table)){let t=e.nodeSymbol(r).getFiltered(gd);if(t)return Yde(e,t,n)}return new k(void 0)}function qde(e,t,n){if(t.callee){let r;if(jm(t.callee))r=e.nodeReferee(t.callee).getFiltered(gd);else{let n=qm(t.callee);if(n&&n.length>0){let t=n[n.length-1];r=e.nodeReferee(t).getFiltered(gd)}}if(r)return Yde(e,r,n)}return new k(void 0)}function Jde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let i=e.lookupMembers(t,[P.Table,P.Schema],r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table '${r}' does not exist in Schema 'public'`,n)])}let i=ag(e,n);if(!i){let i=e.lookupMembers(t,[P.Table,P.Schema],r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table or schema '${r}' does not exist`,n)])}return new k(void 0)}function Yde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``,i=e.lookupMembers(t,P.Column,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${r}' does not exist in Table 'public.${t.name}'`,n)])}function Xde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return new k(void 0);let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}if(i.isKind(P.Enum)){let t=e.lookupMembers(i,P.EnumField,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Enum field '${r}' does not exist in Enum 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Enum,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Enum '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}var Zde=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof Sh)&&!this.declarationNode.parent?.isKind(_d.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(ig).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qde=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=ih(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return k.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof Eh))return[];let e=[],t=Jm(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if($p(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=tse(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=ih(this.metadata.leftToken()),l=ih(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof Eh?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof Eh))return[];let u=Km(this.declarationNode)[0];if(u.args[0]){let e=km(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof Dh?Wm(t):eh(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof Dh?Wm(n):eh(n),this.ref.color=e.color?.length?sh(e.color?.at(0)?.value):void 0}return[]}};function $de(e){let t=e.parent;for(;t;){if(t instanceof Eh&&t.isKind(_d.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var efe={nodeReferee(e,t){if(!jm(t)&&!Pm(t)||!$de(t)||t.parentOfKind(Oh))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):nfe(e,r,t)},nodeMetadata(e,t){if(Im(t,_d.Ref)){let e=Km(t)[0];if(!(e instanceof Nh)||!e.callee)return k.create(hd);let n=e.callee;return!(n instanceof Ah)||!n.op?k.create(hd):k.create(new Yh(t))}if(t instanceof Oh){if(!(t.name instanceof Dh)||Wm(t.name)?.toLowerCase()!==vd.Ref)return k.create(hd);let e=t.parent;return e instanceof Eh&&e.isKind(_d.TablePartial)?k.create(new Xh(t)):k.create(new Yh(t))}return k.create(hd)},bindNode(e,t){return Im(t,_d.Ref)?k.create(void 0,new Zde(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return t instanceof Yh?new Qde(e,t,n).interpret():k.create(hd)}};function tfe(e,t){let n=e.symbolMembers(t).getFiltered(gd);if(n)return n.find(e=>e instanceof dh&&e.isPublicSchema())}function nfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let t=n.parentNode;if(t&&Pm(t.parentNode)&&t.parentNode.rightExpression===t){let i=t.parentNode.leftExpression,a=Pm(i)?i.rightExpression??i:i,o=e.nodeReferee(a).getFiltered(gd);if(o?.isKind(P.Table)){let t=e.lookupMembers(o,P.Column,r);if(t)return k.create(t);let i=o.declaration?e.nodeFullname(o.declaration).getFiltered(gd)?.join(`.`)??o.name:o.name;return new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table '${i}'`,n)])}}return k.create(void 0)}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Table)){let t=e.lookupMembers(i,P.Column,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table '${i.declaration?e.nodeFullname(i.declaration).getFiltered(gd)?.join(`.`)??i.name:i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Schema '${r}' does not exist`,n)])}let i=tfe(e,t);if(i){let t=e.lookupMembers(i,P.Table,r);if(t)return k.create(t)}let o=e.lookupMembers(t,P.Table,r);return o?k.create(o):new k(void 0,[new N(M.BINDING_ERROR,`Table '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}var mv={visibleName(e,t){let n=t instanceof bh?t:t.useSpecifierDeclaration instanceof wh?t.useSpecifierDeclaration:t.declaration;if(n instanceof wh&&t instanceof uh&&n.getSymbolKind()!==t.kind&&(n=t.declaration),n)return e.nodeAlias(n).mapFiltered(e=>[e],gd,void 0).getFiltered(gd)||e.nodeFullname(n).getFiltered(gd)}},rfe={nodeSymbol(e,t){if(!Lm(t)||!t.name)return k.create(hd);let n=t.getSymbolKind();if(n===void 0||n===P.Schema)return k.create(hd);let r=e.nodeReferee(t.name).getFiltered(gd);return r&&!r.canBeImported?k.create(hd):k.create(e.symbolFactory.create(vh,{useSpecifierDeclaration:t,declaration:r?.declaration,usedSymbol:r,kind:n,name:mv.visibleName(e,t)?.at(-1)},t.filepath),r===void 0?[new N(M.BINDING_ERROR,`Failed to resolve the import of ${n} '${(Jm(t.name)||[]).map(gv).join(`.`)}'`,t)]:[])},symbolMembers(e,t){if(!(t instanceof vh))return k.create(hd);let n=e.symbolMembers(t.originalSymbol).getFiltered(gd);return k.create(n??[])},nodeReferee(e,t){if(!jm(t)&&!Fm(t))return k.create(hd);let n=t.parentOfKind(wh);if(!n)return k.create(hd);let r=n.name===t||Pm(n.name)&&n.name.rightExpression===t?n.getSymbolKind():P.Schema;if(r===void 0)return k.create(void 0);let i=Jm(t.parentOfKind(Ah)),a=eh(t)??i?.at(-1);if(a===void 0)return k.create(void 0);let o=t.parentOfKind(Ch);if(o?.importPath?.value===void 0)return k.create(void 0);let s=dm(t.filepath,o.importPath.value);if(!s)return k.create(void 0);if(!e.layout.exists(s))return k.create(void 0,[new N(M.NONEXISTENT_MODULE,`${r} '${i?.join(`.`)??a}' does not exist in file ${s.toString()}. Does the file exist?`,t)]);let c=t.parentOfKind(Ah)?.leftExpression;if(c&&c!==t){let n=e.nodeReferee(c).getFiltered(gd);if(!n)return k.create(void 0);let i=e.lookupMembers(n,r,a);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Could not find ${r} '${a}'`,t)])}let l=ife(e,s,a,r);return l?k.create(l):k.create(void 0,[new N(M.BINDING_ERROR,`${r} '${a}' does not exist in file ${s.toString()}`,t)])},bindNode(e,t){if(woe(t)){let n=[];if(t.importPath?.value){let r=dm(t.filepath,t.importPath.value);r&&!e.layout.exists(r)&&n.push(new N(M.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${t.importPath.value}'`,t.importPath))}if(t.specifiers){let r=e.bindNode(t.specifiers);n.push(...r.getErrors())}return new k(void 0,n)}return t instanceof Th?new k(void 0,t.specifiers.flatMap(t=>e.bindNode(t).getErrors())):Lm(t)?t.name?new k(void 0,e.nodeReferee(t.name).getErrors()):new k(void 0):k.create(hd)},interpretSymbol(e,t,n){if(!(t instanceof vh))return k.create(hd);if(!t.usedSymbol)return k.create(void 0);let r=e.interpretSymbol(t.usedSymbol,n);if(r.hasValue(gd))return k.create(void 0);let i=r.getValue();if(!i||Array.isArray(i))return r;let a=t.name;return a&&`name`in i?k.create({...i,name:a}):k.create(i)}};function ife(e,t,n,r,i=new Set){if(!t||i.has(t.intern()))return;i.add(t.intern());let a=e.usableMembers(t).getFiltered(gd);if(!a)return;let o=a.nonSchemaMembers.find(e=>e.name===n);if(o?.isKind(r))return o;let s=a.schemaMembers.find(e=>e.name===n);if(s?.isKind(P.Schema))return s;for(let o of a.reuses.selective)if(Jm(o.alias??o.name)?.at(-1)===n){let a=o.parentOfKind(Ch);if(a?.importPath?.value){let s=ife(e,dm(t,a.importPath.value),Jm(o.name)?.at(-1)??n,r,i);if(s)return s}}for(let{importPath:t}of a.reuses.wildcard){let a=ife(e,t,n,r,i);if(a)return a}}function afe(e){if(e instanceof um){let{ast:t}=this.parseFile(e).getValue(),n=this.nodeSymbol(t).getFiltered(gd);return this.usableMembers(n)}let t=e.filepath,n=sfe(this,t),{nonSchemaMembers:r,schemaMembers:i}=e instanceof gh?cfe(this,e,n):lfe(this,e,n);return new k({nonSchemaMembers:r,schemaMembers:i,reuses:{selective:n.selectiveReuses,wildcard:n.wildcardReuses},uses:{selective:n.selectiveUses,wildcard:n.wildcardUses}},n.parseResult.getErrors(),n.parseResult.getWarnings())}function ofe(e,t,n){let r=t.qualifiedName,i;if(i=n instanceof wh?mv.visibleName(e,n):e.nodeFullname(n).getFiltered(gd),!i)return{kind:`none`};let a=i.length<=1?[pm]:i.slice(0,-1);return a.length<r.length||!r.every((e,t)=>e===a[t])?{kind:`none`}:a.length===r.length?{kind:`direct`}:{kind:`child`,schemaName:a[r.length]}}function sfe(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof Ch)||!e.specifiers||!e.importPath)continue;let n=dm(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof Vh?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof Vh?o.push({importPath:n,node:e.specifiers}):s.push(...e.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function cfe(e,t,n){let{ast:r,selectiveUses:i,selectiveReuses:a}=n,o=t.filepath,s=new Map([[pm,e.symbolFactory.create(dh,{name:pm},o)]]);for(let t of r.declarations){let n=e.nodeFullname(t).getFiltered(gd)||[],r=n.length<=1?pm:n[0];s.has(r)||s.set(r,e.symbolFactory.create(dh,{name:r},o))}ufe(e,[...i,...a],s,o);for(let t of e.reachableFiles(o))for(let n of ffe(e,t))s.has(n)||s.set(n,e.symbolFactory.create(dh,{name:n},o));let c=[...s.values()],l=[],u=c.find(e=>e.isPublicSchema());if(u){let t=e.usableMembers(u).getFiltered(gd);t&&l.push(...t.nonSchemaMembers)}return{nonSchemaMembers:l,schemaMembers:c}}function lfe(e,t,n){let{ast:r,selectiveUses:i,selectiveReuses:a}=n,o=[],s=new Map;for(let n of r.body){if(!(n instanceof Eh))continue;let r=ofe(e,t,n),i=e.nodeAlias(n).getFiltered(gd),a=e.nodeSymbol(n).getFiltered(gd);if(i!==void 0&&t.isPublicSchema()&&a&&o.push(e.symbolFactory.create(_h,{kind:a.kind,declaration:n,aliasedSymbol:a,name:i},t.filepath)),r.kind!==`none`)if(r.kind===`direct`){let t=e.nodeSymbol(n).getFiltered(gd);if(!t)continue;o.push(t)}else s.has(r.schemaName)||s.set(r.schemaName,e.symbolFactory.create(dh,{name:r.schemaName,parent:t},t.filepath))}dfe(e,[...i,...a],t,s);let c=t.qualifiedName;for(let n of e.reachableFiles(t.filepath))for(let r of pfe(e,n,c))s.has(r)||s.set(r,e.symbolFactory.create(dh,{name:r,parent:t},t.filepath));return{nonSchemaMembers:o,schemaMembers:[...s.values()]}}function ufe(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==P.Schema)continue;let t=mv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(dh,{name:t},r))}}function dfe(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==P.Schema)continue;let t=mv.visibleName(e,a);if(!t||t.length<=i.length||!i.every((e,n)=>e===t[n]))continue;let o=t[i.length];o&&!r.has(o)&&r.set(o,e.symbolFactory.create(dh,{name:o,parent:n},n.filepath))}}function ffe(e,t){let{ast:n}=e.parseFile(t).getValue(),r=[];for(let t of n.declarations){let n=e.nodeFullname(t).getFiltered(gd)||[],i=n.length<=1?pm:n[0];r.push(i)}let i=sfe(e,t);for(let t of[...i.selectiveUses,...i.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=mv.visibleName(e,t)?.at(0);n!==void 0&&r.push(n)}return r}function pfe(e,t,n){let{ast:r}=e.parseFile(t).getValue(),i=[];for(let t of r.declarations){let r=e.nodeFullname(t).getFiltered(gd)||[],a=r.length<=1?[pm]:r.slice(0,-1);a.length>n.length&&n.every((e,t)=>e===a[t])&&i.push(a[n.length])}let a=sfe(e,t);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let r=mv.visibleName(e,t);!r||r.length<=n.length||n.every((e,t)=>e===r[t])&&i.push(r[n.length])}return i}var mfe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(qp(n)instanceof Fh){let e=km(qp(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Sm(e.callee)))}tryToBindColumnType(e){let t=Ym(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(Am(e))return[];if(jm(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&fm.includes(t))return[]}let t=Ym(e);if(!t){if(Pm(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return ig(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},hfe=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??ih(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),k.create(this.table,t)}interpretName(e){let{name:t,schemaName:n}=oh(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.table.name=t,this.table.schemaName=n.length?n[0]:null,[])}interpretAlias(e){if(!e)return[];let t=th(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=km(e).getValue();this.table.headerColor=t[vd.HeaderColor]?.length?sh(t[vd.HeaderColor]?.at(0)?.value):void 0;let[n]=t[vd.Note]||[];return this.table.note=n&&{value:ah(Zm(n?.value)),token:ih(n)},[]}interpretBody(e){let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case _d.Note:return this.table.note={value:ah(Zm(e.body instanceof Ph?e.body.body[0].callee:e.body.callee)),token:ih(e)},[];case _d.Indexes:return this.interpretIndexes(e);case _d.Checks:return this.interpretChecks(e);case _d.Records:return[];default:return[]}})}interpretInjection(e,t){let n=[],r={order:t,token:ih(e)};r.name=eh(e.expression)||``;let i=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(gd):void 0,a=this.compiler.parseFile(this.filepath).getValue().ast,o=this.compiler.nodeSymbol(a).getFiltered(gd);if(i&&!o.inNestedSchema(this.compiler,i)){let t=this.compiler.nodeSymbol(this.declarationNode).getFiltered(gd),r=t?(this.compiler.symbolUses(t).getFiltered(gd)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;n.push(new N(M.UNSUPPORTED,`Import TablePartial from '${i.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,r?.useSpecifierDeclaration??e))}return this.table.partials.push(r),n}interpretFields(e){let t=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(gd),n=(t?this.compiler.symbolMembers(t).getFiltered(gd)??[]:[]).filter(e=>e.isKind(P.Column)).length?[]:[new N(M.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],r=e.flatMap((e,t)=>Sm(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...n,...r]}interpretColumn(e){let t=[],n={},r=this.compiler.nodeSymbol(e).getFiltered(gd);n.name=th(e.callee),n.token=ih(e);let i=ch(this.compiler,e.args[0]);n.type=i.getValue(),t.push(...i.getErrors()),n.pk=r?.pk(this.compiler)||!1,n.unique=r?.unique(this.compiler)||!1,n.increment=r?.increment(this.compiler)||void 0;let a=r?.nullable(this.compiler);n.not_null=a===void 0?void 0:!a,n.dbdefault=r?.default(this.compiler),n.note=r?.note(this.compiler);let o=this.compiler.nodeSettings(e).getFiltered(gd)??{},s=this.compiler.parseFile(this.filepath).getValue().ast,c=this.compiler.nodeSymbol(s).getFiltered(gd);return n.inline_refs=(o[vd.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(gd);if(!n)return[];let r=n.owners(this.compiler);if(c&&r.length>0&&!r.some(e=>e===c))return[];let i=this.compiler.interpretMetadata(n,this.filepath);if(i.hasValue(gd))return[];t.push(...i.getErrors());let a=i.getValue();if(!a?.endpoints?.[0])return[];let o=a.endpoints[0],s=n.op(this.compiler);return s?{schemaName:o.schemaName,tableName:o.tableName,fieldNames:o.fieldNames,relation:s,token:o.token}:[]}),n.checks=(o[vd.Check]||[]).map(e=>({token:ih(e),expression:e.value.value.value})),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.table.indexes.push(...r):r&&this.table.indexes.push(r),n.getErrors()}interpretChecks(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.table.checks.push(...r):r&&this.table.checks.push(r),n.getErrors()}},hv={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},gfe={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.Table)?new k(e.symbolFactory.create(ph,{declaration:t,name:n},t.filepath)):zm(t,_d.Table)?Sm(t.callee)?new k(e.symbolFactory.create(Loe,{declaration:t,name:n},t.filepath)):new k(e.symbolFactory.create(mh,{declaration:t,name:n},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Table))return k.create(hd);let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.Column,P.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof Eh&&e.declaration.name?e.declaration.name:e.declaration,r=o.get(t);r?e.isKind(P.Column)?(a.push(hv.getColumnDuplicateError(e.name,r)),a.push(hv.getColumnDuplicateError(e.name,n))):(a.push(hv.getPartialInjectionDuplicateError(e.name,r)),a.push(hv.getPartialInjectionDuplicateError(e.name,n))):o.set(t,n)}}let s=[];for(let t=0;t<i.length;t++){let r=i[t];if(!(r.declaration instanceof Nh)||!Sm(r.declaration.callee))continue;let o=r.declaration.callee.expression,c=eh(o);if(o===void 0||c===void 0)continue;let l=e.nodeReferee(o).getFiltered(gd);if(!l){a.push(new N(M.BINDING_ERROR,`TablePartial '${c}' does not exist in Schema 'public'`,o||n));continue}let u=e.symbolMembers(l).getFiltered(gd);if(u){let i=u.flatMap(t=>{if(!t.declaration)return[];let i=t.name;return i===void 0?t:e.symbolFactory.create(yh,{kind:P.Column,injectionDeclaration:r.declaration,declaration:t.declaration,name:i},n.filepath)});s.push({index:t,partialMembers:i})}}for(let e=s.length-1;e>=0;e--){let{index:t,partialMembers:n}=s[e];i.splice(t,0,...n)}let c=new Set(i.filter(e=>e.isKind(P.Column)&&!(e instanceof yh)).map(e=>e.name));return new k(Qp([...i.filter(e=>!(e instanceof yh&&c.has(e.name)))].reverse(),e=>e.isKind(P.Column)?e.name:e).reverse(),a)},nodeReferee(e,t){if(!Bm(t,_d.Table))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):jm(t)&&t.parentNode instanceof kh&&t.parentNode.op?.value===`~`?_fe(e,r,t):Vm(t,1)?vfe(e,r,t):Toe(t,vd.Ref)?yfe(e,r,t):Vm(t,0)?k.create(hd):bfe(e,r,t)},bindNode(e,t){if(!Im(t,_d.Table))return k.create(hd);let n=new mfe(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof ph?t.declaration instanceof Eh?new hfe(e,t.declaration,t,n).interpret():k.create(void 0):k.create(hd)}};function _fe(e,t,n){let r=eh(n)??``,i=e.symbolMembers(t).getFiltered(gd);if(i){let t=i.find(e=>e instanceof dh&&e.isPublicSchema());if(t){let n=e.lookupMembers(t,P.TablePartial,r);if(n)return k.create(n)}}let a=e.lookupMembers(t,P.TablePartial,r);return a?k.create(a):new k(void 0,[new N(M.NAME_NOT_FOUND,`TablePartial '${r}' does not exist in Schema 'public'`,n)])}function vfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=Ooe(n),a=e.lookupMembers(i,t?P.Enum:P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.NAME_NOT_FOUND,t?`Enum '${r}' does not exist in Schema 'public'`:`Schema '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}if(n.parentNode.leftExpression===n){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function yfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let i=n.parent,a=i instanceof Eh&&i.isKind(_d.Table)?e.nodeSymbol(i).getFiltered(gd):void 0;if(a){let t=e.lookupMembers(a,P.Column,r);if(t)return k.create(t)}let o=e.lookupMembers(t,P.Column,r);return o?k.create(o):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table 'public.${a?.name??``}'`,n)])}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Table)){let t=e.lookupMembers(i,P.Column,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Table,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Table '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function bfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return fm.includes(r.toLowerCase())?new k(void 0):k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}if(i.isKind(P.Enum)){let t=e.lookupMembers(i,P.EnumField,r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum field '${r}' does not exist in Enum 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Enum,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function xfe(e){return e?e.split(``).every(e=>gm(e)||_m(e))&&!_m(e[0]):!1}function gv(e){return xfe(e)?e:`"${_v(e)}"`}function Sfe(e){let t=``,n=0,r={n:`
4
+ `)}function oh(e){let t=Jm(e);return!t||t.length===0?{schemaName:[],name:``}:{name:t[t.length-1],schemaName:t.slice(0,-1)}}function sh(e){if(e instanceof Uh&&e.expression instanceof Bh&&e.expression.literal?.kind===em.COLOR_LITERAL)return e.expression.literal.value}function joe(e){if(e){if(Am(e)){let t=Zm(e);if(t!==void 0)return{value:t,type:`string`}}if(Em(e))return{type:`number`,value:rh(e)};if(Nm(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof Mh&&e.value)return{value:e.value.value,type:`expression`};if(Fm(e)){let t=qm(e)?.at(-1),n=t?eh(t):void 0;if(n!==void 0)return{value:n,type:`string`}}}}function ch(e,t){let n=``,r=null;if(t instanceof zh){if(r=(t.argumentList?.elementList??[]).map(e=>Em(e)?nh(e):Am(e)?Zm(e):eh(e)).join(`,`),n=`(${r})`,!t.callee)return new k({schemaName:null,type_name:``,args:r});t=t.callee}for(;t instanceof zh||t instanceof Gh;)if(t instanceof zh){if(n=`(${(t.argumentList?.elementList??[]).map(e=>Em(e)?nh(e):Am(e)?Zm(e):eh(e)).join(`,`)})${n}`,!t.callee)break;t=t.callee}else if(t instanceof Gh){if(n=`${`[${(t.indexer?.elementList??[]).map(e=>e?.name?.expression?.literal?.value??``).join(`,`)}]`}${n}`,!t.array)break;t=t.array}let{name:i,schemaName:a}=oh(t);return a.length>1?new k({schemaName:a[0]??null,type_name:`${i}${n}`,args:r},[new N(M.UNSUPPORTED,`Nested schema is not supported`,t)]):new k({schemaName:a.length===0?null:a[0],type_name:`${i}${n}`,args:r})}var P=function(e){return e.Schema=`Schema`,e.Table=`Table`,e.Column=`Column`,e.TableGroup=`TableGroup`,e.TableGroupField=`TableGroup field`,e.Enum=`Enum`,e.EnumField=`Enum field`,e.StickyNote=`Note`,e.TablePartial=`TablePartial`,e.PartialInjection=`PartialInjection`,e.DiagramView=`DiagramView`,e.DiagramViewTopLevelWildcard=`DiagramView top-level wildcard`,e.DiagramViewTable=`DiagramView table`,e.DiagramViewTableGroup=`DiagramView tablegroup`,e.DiagramViewNote=`DiagramView note`,e.DiagramViewSchema=`DiagramView schema`,e.Program=`Program`,e}({}),lh={Table:P.Table,Enum:P.Enum,TableGroup:P.TableGroup,TablePartial:P.TablePartial,Note:P.StickyNote,Schema:P.Schema},Moe=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},uh=class{constructor({kind:e,declaration:t,name:n},r,i){this.id=r,this.kind=e,this.declaration=t,this.filepath=i,this.name=n}get originalFilepath(){return this.originalSymbol.filepath}intern(){return`symbol@${this.filepath.intern()}:${this.id}`}isKind(...e){return e.includes(this.kind)}canonicalName(e,t){return e.canonicalName(t,this).getValue()}interpretedName(e,t){if(!t)return{schema:null,name:this.name??``};let n=this.canonicalName(e,t);return n?{schema:n.schema===`public`?null:n.schema,name:n.name}:{schema:null,name:this.name??``}}settings(e){if(this.declaration)return e.nodeSettings(this.declaration).getFiltered(gd)}get token(){if(this.declaration)return ih(this.declaration)}references(e){return e.symbolReferences(this)}metadata(e){return e.symbolMetadata(this)}members(e){let t=e.symbolMembers(this);return t.hasValue(gd)?[]:t.getValue()}},dh=class e extends uh{constructor({name:e,parent:t},n,r){super({kind:P.Schema},n,r),this.name=e??``,this.parent=t}get canBeImported(){return!0}get originalSymbol(){return this}get qualifiedName(){return this.parent?[...this.parent.qualifiedName,this.name]:[this.name]}isPublicSchema(){return this.qualifiedName.join(`.`)===pm}inNestedSchema(t,n){let r=this.members(t);if(r.some(e=>e.originalSymbol===n.originalSymbol))return!0;for(let i of r)if(i instanceof e&&i.inNestedSchema(t,n))return!0;return!1}},fh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Enum,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Noe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.EnumField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},ph=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Table,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}schema(e){let t=this.canonicalName(e,this.filepath);return t?t.schema===`public`?null:t.schema:null}columns(e){return this.mergedColumns(e).filter(e=>!(e instanceof yh))}mergedColumns(e){return this.members(e).filter(e=>e.isKind(P.Column))}partialInjections(e){return this.members(e).filter(e=>e.isKind(P.PartialInjection))}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}headercolor(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);return t?.[vd.HeaderColor]?.length?sh(t[vd.HeaderColor].at(0)?.value):void 0}refs(e){return this.metadata(e).filter(e=>e.kind===qh.Ref)}checks(e){return this.metadata(e).filter(e=>e.kind===qh.TableChecks)}indexes(e){return this.metadata(e).filter(e=>e.kind===qh.Indexes)}records(e){return this.metadata(e).filter(e=>e.kind===qh.Records)}resolvedPartials(e){return this.partialInjections(e).flatMap(t=>{if(!(t.declaration instanceof Nh)||!Sm(t.declaration.callee))return[];let n=t.declaration.callee.expression;if(!n)return[];let r=e.nodeReferee(n).getFiltered(gd);return r?[r]:[]})}mergedIndexes(e){let t=this.indexes(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===qh.Indexes));return[...t,...n]}mergedChecks(e){let t=this.checks(e),n=this.resolvedPartials(e).flatMap(t=>t.metadata(e).filter(e=>e.kind===qh.TableChecks));return[...t,...n]}mergedHeadercolor(e){let t=this.headercolor(e);for(let n of this.resolvedPartials(e)){if(!n.declaration)continue;let r=e.nodeSettings(n.declaration).getFiltered(gd);r?.[vd.HeaderColor]?.length&&(t=sh(r[vd.HeaderColor].at(0)?.value))}return t}mergedNote(e){let t=t=>{if(!t.declaration)return;let n=e.nodeSettings(t.declaration).getFiltered(gd);if(!n?.note?.length)return;let r=n.note[0],i=r?.value;if(!i)return;let a=ah(Zm(i));if(a)return{value:a,token:ih(r)}},n=t(this);for(let r of this.resolvedPartials(e)){let e=t(r);e&&(n=e)}return n}},mh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Column,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}pk(e){if(!this.declaration)return!1;let t=e.nodeSettings(this.declaration).getFiltered(gd);return!!(t?.[vd.PK]?.length||t?.[vd.PrimaryKey]?.length)}unique(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Unique]?.length:!1}nullable(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(t?.[vd.NotNull]?.length)return!1;if(t?.[vd.Null]?.length)return!0}increment(e){return this.declaration?!!e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Increment]?.length:!1}default(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd)?.[vd.Default]?.at(0)?.value;if(t)return joe(t)}type(e){if(!(this.declaration instanceof Nh))return;let t=ch(e,this.declaration.args[0]).getValue();if(!t)return;let n=t.args?t.args.split(`,`).map(e=>{let t=Number(e);return Number.isNaN(t)?e:t}):void 0,r=[],i=/\[([^\]]*)\]/g,a,o=t.type_name;for(;(a=i.exec(o))!==null;){let e=a[1];if(e===``)r.push(void 0);else{let t=Number(e);r.push(Number.isNaN(t)?e:t)}}let s=o.replace(/\[[^\]]*\]/g,``),c=e.nodeReferee(this.declaration.args[0]).getFiltered(gd);return{name:s,enumSymbol:c instanceof fh?c:void 0,args:n?.length?n:void 0,schema:t.schemaName??void 0,array:r.length?r:void 0}}checks(e){return this.metadata(e).filter(e=>e.kind===qh.TableChecks)}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},Poe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}fields(e){return this.members(e).filter(e=>e.isKind(P.TableGroupField))}color(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);return t?.color?.length?sh(t.color.at(0)?.value):void 0}note(e){if(!this.declaration)return;let t=e.nodeSettings(this.declaration).getFiltered(gd);if(!t?.note?.length)return;let n=t.note[0],r=n?.value;if(!r)return;let i=ah(Zm(r));if(i)return{value:i,token:ih(n)}}},Foe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TableGroupField,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Ioe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.StickyNote,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},hh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.TablePartial,declaration:e,name:t},n,r)}get canBeImported(){return!0}get originalSymbol(){return this}},Loe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.PartialInjection,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Roe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramView,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},zoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTopLevelWildcard,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Boe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTable,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Voe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewTableGroup,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Hoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewNote,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},Uoe=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.DiagramViewSchema,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}},gh=class extends uh{constructor({declaration:e,name:t},n,r){super({kind:P.Program,declaration:e,name:t},n,r)}get canBeImported(){return!1}get originalSymbol(){return this}inNestedSchema(e,t){let n=this.members(e);if(n.some(e=>e.originalSymbol===t.originalSymbol))return!0;for(let r of n)if(r instanceof dh&&r.inNestedSchema(e,t))return!0;return!1}},_h=class extends uh{constructor({kind:e,declaration:t,aliasedSymbol:n,name:r},i,a){super({kind:e,declaration:t,name:r},i,a),this.aliasedSymbol=n}get canBeImported(){return this.aliasedSymbol.canBeImported}get originalSymbol(){return this.aliasedSymbol.originalSymbol}},vh=class extends uh{constructor({kind:e,declaration:t,useSpecifierDeclaration:n,usedSymbol:r,name:i},a,o){super({kind:e,declaration:t,name:i},a,o),this.useSpecifierDeclaration=n,this.usedSymbol=r}get canBeImported(){let e=this.useSpecifierDeclaration?.parentOfKind(Ch);return!e||e.isReuse}get originalSymbol(){return this.usedSymbol?this.usedSymbol.originalSymbol:this}},yh=class extends mh{constructor({declaration:e,name:t,injectionDeclaration:n},r,i){super({declaration:e,name:t},r,i),this.injectionDeclaration=n,this.name=t}},Woe=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},bh=class{constructor(e,t,n,r){this.id=e,this.kind=t,this.filepath=n;let i=r.find(e=>e!==void 0&&!Number.isNaN(e.start));i?(this.startPos=i.startPos,this.fullStart=i instanceof tm?toe(i):i.fullStart):(this.startPos={offset:NaN,column:NaN,line:NaN},this.fullStart=NaN);let a=[...r].reverse().find(e=>e!==void 0&&!Number.isNaN(e.end));a?(this.endPos=a.endPos,this.fullEnd=a instanceof tm?eoe(a):a.fullEnd):(this.endPos={offset:NaN,column:NaN,line:NaN},this.fullEnd=NaN),this.start=this.startPos.offset,this.end=this.endPos.offset}intern(){return`node@${this.filepath.intern()}:${this.id}`}get parent(){let e=this.parentNode;for(;e;){if(e instanceof Eh||e instanceof Sh)return e;e=e.parentNode}}parentOfKind(e){let t=this;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){if(typeof e==`number`)return this.start<e&&this.end>e;let{start:t,end:n}=e,r=this.start<t,i=r||this.start===t,a=this.end>n,o=a||this.end===n;return r&&o||i&&a}containsEq(e){if(typeof e==`number`)return this.start<=e&&this.end>=e;let{start:t,end:n}=e;return this.start<=t&&this.end>=n}},xh=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.USE_DECLARATION=`<use-declaration>`,e.USE_SPECIFIER=`<use-specifier>`,e.USE_SPECIFIER_LIST=`<use-specifier-list>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifier-stream>`,e.LITERAL=`<literal>`,e.VARIABLE=`<variable>`,e.PREFIX_EXPRESSION=`<prefix-expression>`,e.INFIX_EXPRESSION=`<infix-expression>`,e.POSTFIX_EXPRESSION=`<postfix-expression>`,e.FUNCTION_EXPRESSION=`<function-expression>`,e.FUNCTION_APPLICATION=`<function-application>`,e.BLOCK_EXPRESSION=`<block-expression>`,e.LIST_EXPRESSION=`<list-expression>`,e.TUPLE_EXPRESSION=`<tuple-expression>`,e.CALL_EXPRESSION=`<call-expression>`,e.PRIMARY_EXPRESSION=`<primary-expression>`,e.GROUP_EXPRESSION=`<group-expression>`,e.COMMA_EXPRESSION=`<comma-expression>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e.WILDCARD=`<wildcard>`,e}({}),Sh=class extends bh{constructor({body:e=[],eof:t,source:n},r,i){super(r,xh.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}get declarations(){return this.body.filter(e=>e.kind===xh.ELEMENT_DECLARATION)}get uses(){return this.body.filter(e=>e.kind===xh.USE_DECLARATION)}},Ch=class extends bh{constructor({useKeyword:e,specifiers:t,fromKeyword:n,importPath:r},i,a){super(i,xh.USE_DECLARATION,a,[e,t,n,r]),this.useKeyword=e,this.specifiers=t,this.fromKeyword=n,this.importPath=r}get isReuse(){return aoe(this.useKeyword)}},wh=class extends bh{constructor({importKind:e,name:t,asKeyword:n,alias:r},i,a){super(i,xh.USE_SPECIFIER,a,[e,t,n,r]),this.importKind=e,this.name=t,this.asKeyword=n,this.alias=r}isKind(...e){return this.importKind?.value!==void 0&&e.map(e=>e.toLowerCase()).includes(this.importKind.value.toLowerCase())}getSymbolKind(){let e=this.importKind?.value?.toLowerCase();if(e!==void 0)return Object.values(P).find(t=>t.toLowerCase()===e)}},Th=class extends bh{constructor({openBrace:e,specifiers:t=[],closeBrace:n},r,i){super(r,xh.USE_SPECIFIER_LIST,i,[e,...t,n]),this.openBrace=e,this.specifiers=t,this.closeBrace=n}},Eh=class e extends bh{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,xh.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof Nh||s instanceof e))throw Error(`If an element has a simple body, it must be a function application node`);this.type=t,this.name=n,this.as=r,this.alias=i,this.attributeList=a,this.bodyColon=o,this.body=s}isKind(...e){return e.some(e=>this.type?.value.toLowerCase()===e)}getElementKind(){return Object.values(_d).find(e=>this.isKind(e))}},Dh=class extends bh{constructor({identifiers:e=[]},t,n){super(t,xh.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},Oh=class extends bh{constructor({name:e,colon:t,value:n},r,i){super(r,xh.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},kh=class extends bh{constructor({op:e,expression:t},n,r){super(n,xh.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},Ah=class extends bh{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,xh.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},jh=class extends bh{constructor({op:e,expression:t},n,r){super(n,xh.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},Mh=class extends bh{constructor({value:e},t,n){super(t,xh.FUNCTION_EXPRESSION,n,[e]),this.value=e}},Nh=class extends bh{constructor({callee:e,args:t=[]},n,r){super(n,xh.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},Ph=class extends bh{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,xh.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},Fh=class extends bh{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,xh.LIST_EXPRESSION,a,[e,...Kh(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Ih=class extends bh{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,xh.TUPLE_EXPRESSION,a,[e,...Kh(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Lh=class extends bh{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,xh.COMMA_EXPRESSION,r,[...Kh(e,t)]),this.elementList=e,this.commaList=t}},Rh=class extends Ih{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=xh.GROUP_EXPRESSION}},zh=class extends bh{constructor({callee:e,argumentList:t},n,r){super(n,xh.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},Bh=class extends bh{constructor({literal:e},t,n){super(t,xh.LITERAL,n,[e]),this.literal=e}},Vh=class extends bh{constructor({token:e},t,n){super(t,xh.WILDCARD,n,[e]),this.token=e}},Hh=class extends bh{constructor({variable:e},t,n){super(t,xh.VARIABLE,n,[e]),this.variable=e}},Uh=class extends bh{constructor({expression:e},t,n){super(t,xh.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},Wh=class extends bh{constructor({prevToken:e},t,n){let r=tm.create(em.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,xh.EMPTY,n,[r])}},Gh=class extends bh{constructor({expression:e,indexer:t},n,r){super(n,xh.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function Kh(e,t){if(!e||e.length===0)return t||[];if(!t||t.length===0)return e||[];let[n]=e,[r]=t;return(n.start<r.start?Une($p(e,t)):Une($p(t,e))).filter(e=>e!==null)}var qh=function(e){return e.Ref=`ref`,e.PartialRef=`partial ref`,e.TableChecks=`table checks`,e.Indexes=`indexes`,e.Records=`records`,e.Project=`project`,e}({}),Jh=class e{static#e=this.id=0;constructor(t){this.declaration=t,this.id=++e.id}intern(){return`metadata@${this.declaration.filepath.intern()}:${this.id}`}},Yh=class extends Jh{constructor(e){super(e),this.kind=qh.Ref}container(e){let t=this.declaration.parentOfKind(Eh);if(t?.isKind(_d.Table))return e.nodeSymbol(t).getFiltered(gd)}leftColumns(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return[];let n=t.callee;return n instanceof Ah?Qh(e,n.leftExpression):[]}if(this.declaration instanceof Oh){let t=this.declaration.parentOfKind(Nh);if(!t)return[];let n=e.nodeSymbol(t).getFiltered(gd);return n?[n]:[]}return[]}rightColumns(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return[];let n=t.callee;return n instanceof Ah?Qh(e,n.rightExpression):[]}if(this.declaration instanceof Oh){let t=this.declaration.value;return t instanceof kh?Qh(e,t.expression):[]}return[]}leftTable(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return;let n=t.callee;return n instanceof Ah?$h(e,n.leftExpression):void 0}if(this.declaration instanceof Oh)return this.container(e)}rightTable(e){if(this.declaration instanceof Eh){let t=Km(this.declaration)[0];if(!(t instanceof Nh))return;let n=t.callee;return n instanceof Ah?$h(e,n.rightExpression):void 0}if(this.declaration instanceof Oh){let t=this.declaration.value;return t instanceof kh?$h(e,t.expression)??this.container(e):void 0}}op(e){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(!(e instanceof Nh))return;let t=e.callee;return t instanceof Ah?t.op?.value:void 0}if(this.declaration instanceof Oh){let e=this.declaration.value;return e instanceof kh?e.op?.value:void 0}}leftToken(){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(e instanceof Nh){let t=e.callee;if(t instanceof Ah&&t.leftExpression)return t.leftExpression}}if(this.declaration instanceof Oh){let e=this.declaration.parentOfKind(Nh);if(e)return e}return this.declaration}rightToken(){if(this.declaration instanceof Eh){let e=Km(this.declaration)[0];if(e instanceof Nh){let t=e.callee;if(t instanceof Ah&&t.rightExpression)return t.rightExpression}}return this.declaration instanceof Oh,this.declaration}owners(e){let t=this.leftTable(e),n=this.rightTable(e);if(!t||!n)return[];let r=this.declaration.filepath;return e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(i=>e.reachableFiles(i.filepath).some(e=>e.equals(r))&&i.inNestedSchema(e,t)&&i.inNestedSchema(e,n))}},Xh=class extends Jh{constructor(e){super(e),this.kind=qh.PartialRef}container(e){let t=this.declaration.parentOfKind(Eh);if(t?.isKind(_d.TablePartial))return e.nodeSymbol(t).getFiltered(gd)}leftColumns(e){if(!(this.declaration instanceof Oh))return[];let t=this.declaration.parentOfKind(Nh);if(!t)return[];let n=e.nodeSymbol(t).getFiltered(gd);return n?[n]:[]}rightColumns(e){if(!(this.declaration instanceof Oh))return[];let t=this.declaration.value;return t instanceof kh?Qh(e,t.expression):[]}leftTablePartial(e){if(this.declaration instanceof Oh)return this.container(e)}rightTable(e){if(!(this.declaration instanceof Oh))return;let t=this.declaration.value;if(t instanceof kh)return $h(e,t.expression)??this.container(e)}op(e){if(!(this.declaration instanceof Oh))return;let t=this.declaration.value;if(t instanceof kh)return t.op?.value}leftToken(){if(this.declaration instanceof Oh){let e=this.declaration.parentOfKind(Nh);if(e)return e}return this.declaration}rightToken(){return this.declaration instanceof Oh,this.declaration}owners(e){let t=this.leftTablePartial(e),n=this.rightTable(e);return!t||!n?[]:e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(r=>r.inNestedSchema(e,t)&&r.inNestedSchema(e,n))}},Goe=class extends Jh{constructor(e){super(e),this.kind=qh.TableChecks,this.ownerTable=e.parentNode?.parentOfKind(Eh)}owners(e){if(!this.ownerTable)return[];let t=e.nodeSymbol(this.ownerTable).getFiltered(gd);return t?[t.originalSymbol]:[]}},Koe=class extends Jh{constructor(e){super(e),this.kind=qh.Indexes,this.ownerTable=e.parentNode?.parentOfKind(Eh)}owners(e){if(!this.ownerTable)return[];let t=e.nodeSymbol(this.ownerTable).getFiltered(gd);return t?[t.originalSymbol]:[]}},Zh=class extends Jh{constructor(e){super(e),this.kind=qh.Records}table(e){let t=this.declaration,n=t.parent;if(n instanceof Eh&&n.isKind(_d.Table))return e.nodeSymbol(n).getFiltered(gd);let r=t.name;if(!(r instanceof zh))return;let i=$m(r);if(!i)return;let a=i.variables.at(-1);if(a)return e.nodeReferee(a).getFiltered(gd)?.originalSymbol}owners(e){let t=this.table(e);return t?e.reachableFiles().flatMap(t=>e.nodeSymbol(e.parseFile(t).getValue().ast).getFiltered(gd)||[]).filter(n=>n.inNestedSchema(e,t)):[]}},qoe=class extends Jh{constructor(e){super(e),this.kind=qh.Project}owners(e){let t=this.declaration.filepath,n=e.parseFile(t).getValue().ast,r=e.nodeSymbol(n).getFiltered(gd);return r?[r]:[]}};function Qh(e,t){if(!t)return[];let n=Ym(t);return n?(n.tupleElements.length>0?n.tupleElements:n.variables.at(-1)?[n.variables.at(-1)]:[]).flatMap(t=>{let n=e.nodeReferee(t).getFiltered(gd);return n?[n]:[]}):[]}function $h(e,t){if(!t)return;let n=Ym(t);if(!n)return;let r=n.tupleElements.length>0?n.variables.at(-1):n.variables.at(-2);if(r)return e.nodeReferee(r).getFiltered(gd)}var Joe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return[]}},Yoe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}interpret(){let e=this.declarationNode.body;return e instanceof Ph?new k(e.body.flatMap(e=>{if(!(e instanceof Nh))return[];let t=ih(e),n=e.callee instanceof Mh?e.callee.value?.value??``:``,r,i=e.args.find(e=>e instanceof Fh);return i&&(r=Zm(km(i).getValue()[vd.Name]?.at(0)?.value)),{expression:n,name:r,token:t}})):new k([])}},Xoe={nodeMetadata(e,t){if(Im(t,_d.Checks)){let e=t.parent;return!e||!Im(e,_d.Table)&&!Im(e,_d.TablePartial)?k.create(hd):k.create(new Goe(t))}return k.create(hd)},bindNode(e,t){return Im(t,_d.Checks)?k.create(void 0,new Joe(e,t).bind()):k.create(hd)},interpretMetadata(e,t){return t.kind===qh.TableChecks?t.declaration instanceof Eh?new Yoe(e,t.declaration).interpret():k.create(void 0):k.create(hd)}};function Zoe(e,t,n){let r=t,i=e;if(i instanceof zh&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Nm(i)||r.length===0)return;let a=[...r],o=koe(i),s=a.pop();if(!(s instanceof Ph))return;let c=qp(a)instanceof Fh?a.pop():void 0;if(a.length===3){let e=koe(a[1]);return!e||!im(e)?void 0:n.create(Eh,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(Eh,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(Eh,{type:o,attributeList:c,body:s})}function eg(e){e&&(e instanceof tm?Qoe(e):$oe(e))}function Qoe(e){e.kind!==em.EOF&&(e.isInvalid=!0)}function $oe(e){if(e instanceof Eh)eg(e.type),eg(e.name),eg(e.as),eg(e.alias),eg(e.bodyColon),eg(e.attributeList),eg(e.body);else if(e instanceof Dh)e.identifiers.forEach(eg);else if(e instanceof Oh)eg(e.name),eg(e.colon),eg(e.value);else if(e instanceof kh)eg(e.op),eg(e.expression);else if(e instanceof Ah)eg(e.leftExpression),eg(e.op),eg(e.rightExpression);else if(e instanceof jh)eg(e.op),eg(e.expression);else if(e instanceof Ph)eg(e.blockOpenBrace),e.body.forEach(eg),eg(e.blockCloseBrace);else if(e instanceof Fh)eg(e.listOpenBracket),e.commaList.forEach(eg),e.elementList.forEach(eg),eg(e.listCloseBracket);else if(e instanceof Ih)eg(e.tupleOpenParen),e.commaList.forEach(eg),e.elementList.forEach(eg),eg(e.tupleCloseParen);else if(e instanceof Lh)e.commaList.forEach(eg),e.elementList.forEach(eg);else if(e instanceof zh)eg(e.callee),eg(e.argumentList);else if(e instanceof Nh)eg(e.callee),e.args.forEach(eg);else if(e instanceof Uh)eg(e.expression);else if(e instanceof Mh)eg(e.value);else if(e instanceof Hh)eg(e.variable);else if(e instanceof Bh)eg(e.literal);else if(e instanceof Rh)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof Gh)eg(e.array),eg(e.indexer);else if(e instanceof Sh)e.body.forEach(eg),eg(e.eof);else if(!(e instanceof Wh))if(e instanceof Ch)eg(e.useKeyword),eg(e.specifiers),eg(e.fromKeyword),eg(e.importPath);else if(e instanceof Th)eg(e.openBrace),e.specifiers.forEach(eg),eg(e.closeBrace);else if(e instanceof wh)eg(e.importKind),eg(e.name);else if(e instanceof Vh)eg(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function tg(...e){return e.filter(e=>e!==void 0)}function ng(e){if(e instanceof Sh)return tg(...e.body,e.eof);if(e instanceof Eh)return tg(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof Oh)return tg(e.name,e.colon,e.value);if(e instanceof Dh)return e.identifiers;if(e instanceof Bh)return e.literal?[e.literal]:[];if(e instanceof Hh)return tg(e.variable);if(e instanceof kh)return tg(e.op,e.expression);if(e instanceof Ah)return tg(e.leftExpression,e.op,e.rightExpression);if(e instanceof jh)return tg(e.expression,e.op);if(e instanceof Mh)return tg(e.value);if(e instanceof Nh)return tg(e.callee,...e.args);if(e instanceof Ph)return tg(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof Fh)return tg(e.listOpenBracket,...rg(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Ih)return tg(e.tupleOpenParen,...rg(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Lh)return tg(...rg(e.elementList,e.commaList));if(e instanceof zh)return tg(e.callee,e.argumentList);if(e instanceof Uh)return tg(e.expression);if(e instanceof Gh)return tg(e.array,e.indexer);if(e instanceof Wh)return[];if(e instanceof Ch)return tg(e.useKeyword,e.specifiers,e.fromKeyword,e.importPath);if(e instanceof Th)return tg(e.openBrace,...e.specifiers,e.closeBrace);if(e instanceof wh)return tg(e.importKind,e.name);if(e instanceof Vh)return tg(e.token);throw e instanceof Rh?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function rg(e,t){let n=[],r=Math.min(e.length,t.length);for(let i=0;i<r;i+=1)n.push(e[i],t[i]);return n.push(...e.slice(r),...t.slice(r)),n}function ese(e,t){let n=[...e.parseProject().values()].some(e=>e.getErrors().length>0),r=e.validateNode(t).getErrors().length>0,i=e.bindNode(t).getErrors().length>0;return!n&&!r&&!i}function ig(e){if(!e)return[];if(jm(e))return[{variables:[e],tupleElements:[]}];if(e instanceof Ah){let t=Ym(e);return t?[t]:[...ig(e.leftExpression),...ig(e.rightExpression)]}if(e instanceof kh||e instanceof jh)return ig(e.expression);if(e instanceof Ih){let t=Ym(e);return t?[t]:e.elementList.flatMap(ig)}return[]}function ag(e,t){let n=t.parentNode;if(!n||!Pm(n)||n.rightExpression!==t)return;let r=n.leftExpression;for(;Pm(r);)r=r.rightExpression;return e.nodeReferee(r).getFiltered(gd)??void 0}function tse(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:return}}var nse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=Zp(e.body,e=>e instanceof Nh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>!e.type||!(e.body instanceof Ph)?[]:e.isKind(_d.DiagramViewTables)?this.bindTableReferences(e.body):e.isKind(_d.DiagramViewNotes)?this.bindNoteReferences(e.body):e.isKind(_d.DiagramViewTableGroups)?this.bindTableGroupReferences(e.body):e.isKind(_d.DiagramViewSchemas)?this.bindSchemaReferences(e.body):[])}bindTableReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:[e.callee,...e.args].flatMap(ig).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindNoteReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindTableGroupReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>{let t=e.variables.pop();return t?this.compiler.nodeReferee(t).getErrors():[]}))}bindSchemaReferences(e){let[t]=Zp(e.body,e=>e instanceof Nh);return t.flatMap(e=>!e.callee||Mm(e.callee)?[]:ig(e.callee).flatMap(e=>e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors())))}},rse=class{constructor(e,t,n,r){this.diagramViewWildcards=new Set,this.diagramViewExplicitlySet=new Set,this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r??t.filepath,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];this.diagramView.token=this.symbol.token;let{name:t,schema:n}=this.symbol.interpretedName(this.compiler,this.filepath);return this.diagramView.name=t,this.diagramView.schemaName=n,this.declarationNode.body instanceof Ph&&e.push(...this.interpretBody(this.declarationNode.body)),this.expandDiagramViewWildcards(),new k(this.diagramView,e)}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof Nh&&Mm(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.diagramViewWildcards=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),this.diagramViewExplicitlySet=new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`]),[]}let[t]=Zp(e.body,e=>e instanceof Eh),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof Ph&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;return(n.has(`tables`)&&r.tables!==null||n.has(`tablegroups`)&&r.tableGroups!==null||n.has(`schemas`)&&r.schemas!==null)&&(n.has(`tables`)||(r.tables=[]),n.has(`tablegroups`)||(r.tableGroups=[]),n.has(`schemas`)||(r.schemas=[])),n.has(`tables`)&&this.diagramViewExplicitlySet.add(`tables`),n.has(`tablegroups`)&&this.diagramViewExplicitlySet.add(`tableGroups`),n.has(`schemas`)&&this.diagramViewExplicitlySet.add(`schemas`),n.has(`notes`)&&this.diagramViewExplicitlySet.add(`stickyNotes`),[]}interpretSubBlock(e,t){if(!t)return;if(e.body.some(e=>e instanceof Nh&&Mm(e.callee))){let e=this.diagramViewWildcards;switch(t){case`tables`:this.diagramView.visibleEntities.tables=[],e.add(`tables`);break;case`notes`:this.diagramView.visibleEntities.stickyNotes=[],e.add(`stickyNotes`);break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=[],e.add(`tableGroups`);break;case`schemas`:this.diagramView.visibleEntities.schemas=[],e.add(`schemas`);break}return}if(e.body.length===0)return;let n=[];for(let t of e.body){if(!(t instanceof Nh))continue;let e=t.callee&&this.compiler.nodeReferee(t.callee).getFiltered(gd);if(e?.declaration instanceof Eh){let t=Jm(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],r=t.length>1?t.slice(0,-1).join(`.`):pm;n.push({name:e,schemaName:r});continue}}let r=Jm(t.callee)??[];if(r.length===0)continue;let i=r[r.length-1],a=r.length>1?r[0]:pm;n.push({name:i,schemaName:a})}switch(t){case`tables`:this.diagramView.visibleEntities.tables=n.length>0?n:null;break;case`notes`:this.diagramView.visibleEntities.stickyNotes=n.length>0?n.map(e=>({name:e.name})):null;break;case`tablegroups`:this.diagramView.visibleEntities.tableGroups=n.length>0?n.map(e=>({name:e.name})):null;break;case`schemas`:this.diagramView.visibleEntities.schemas=n.length>0?n.map(e=>({name:e.name})):null;break}}expandDiagramViewWildcards(){let e=this.diagramView.visibleEntities,t=this.diagramViewWildcards;if(!(!t||!e)){if(t.has(`tables`)||t.has(`schemas`)){e.tables=[],e.tableGroups=[],e.schemas=[];return}t.has(`tableGroups`)&&e.tableGroups&&e.tableGroups.length===0&&(e.tableGroups=this.getAllTableGroupNames())}}getAllTableGroupNames(){let e=this.compiler.parseFile(this.declarationNode.filepath).getValue().ast,t=this.compiler.nodeSymbol(e).getFiltered(gd);if(!t)return[];let n=this.compiler.symbolMembers(t).getFiltered(gd);return n?Qp(n.filter(e=>e.isKind(P.TableGroup)),e=>e.originalSymbol.intern()).flatMap(e=>e.name===void 0?[]:{name:e.name}):[]}};function ise(e){return e==null?e:Array.isArray(e)?e.map(String).join(`\0`):typeof e==`object`&&`intern`in e?e.intern():e}var ase=function(e){return e.Table=`table`,e}({}),og={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`DiagramView '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t,n){return new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`Duplicate ${t} ${e}`,n)}},ose={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.DiagramView)?new k(e.symbolFactory.create(Roe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramView)&&t instanceof Vh?new k(e.symbolFactory.create(zoe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewNotes)?new k(e.symbolFactory.create(Hoe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewTables)?new k(e.symbolFactory.create(Boe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewTableGroups)?new k(e.symbolFactory.create(Voe,{declaration:t,name:n},t.filepath)):zm(t,_d.DiagramViewSchemas)?new k(e.symbolFactory.create(Uoe,{declaration:t,name:n},t.filepath)):k.create(hd)},nodeReferee(e,t){if(t.parent&&Hm(t))return k.create(hd);let n=sse(t);if(!n)return k.create(hd);let r=e.parseFile(t.filepath).getValue().ast,i=e.nodeSymbol(r).getFiltered(gd);return i?n.isKind(_d.DiagramViewTables)?cse(e,i,t):n.isKind(_d.DiagramViewNotes)?lse(e,i,t,P.StickyNote):n.isKind(_d.DiagramViewTableGroups)?lse(e,i,t,P.TableGroup):n.isKind(_d.DiagramViewSchemas)?use(e,i,t):k.create(hd):k.create(void 0)},symbolMembers(e,t){if(!t.isKind(P.DiagramView))return k.create(hd);if(!t.declaration)return k.create([]);let n=t.declaration;if(!Im(n,_d.DiagramView))return k.create([]);let r=[],i=[];for(let t of Km(n))if(t instanceof Nh){let n=e.nodeSymbol(t).getFiltered(gd);n&&i.push(n)}else t instanceof Eh&&i.push(...Km(t).flatMap(t=>e.nodeSymbol(t).getFiltered(gd)??[]));let a=new Map;for(let t of i){if(!t.isKind(P.DiagramViewSchema,P.DiagramViewTableGroup,P.DiagramViewTable,P.DiagramViewNote)||!t.declaration)continue;let n=(e.nodeFullname(t.declaration).getFiltered(gd)||[]).map(gv).join(`.`),i=`${t.kind}:${n}`;if(n!==void 0){let e=t.declaration,o=a.get(i);o?(r.push(og.getFieldDuplicateError(n,t.kind,o)),r.push(og.getFieldDuplicateError(n,t.kind,e))):a.set(i,e)}}return k.create(i,r)},bindNode(e,t){if(!Im(t,_d.DiagramView))return k.create(hd);let n=new nse(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof Roe?t.declaration instanceof Eh?new rse(e,t.declaration,t,n).interpret():k.create(void 0):k.create(hd)}};function sse(e){let t=e.parentOfKind(Nh);if(!t)return;let n=t.parentNode;if(!(n instanceof Ph))return;let r=n.parentNode;if(!(r instanceof Eh)||!r.isKind(_d.DiagramViewTables,_d.DiagramViewNotes,_d.DiagramViewTableGroups,_d.DiagramViewSchemas))return;let i=r.parentNode;if(!(i instanceof Ph))return;let a=i.parentNode;if(!(!(a instanceof Eh)||!a.isKind(_d.DiagramView)))return r}function cse(e,t,n){let r=th(n);if(r===void 0)return k.create(void 0);if(Pm(n.parentNode)){let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=Ooe(n),a=e.lookupMembers(i,t?P.Table:P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find ${t?`table`:`schema`} '${r}'`,n)])}return new k(void 0)}let a=e.lookupMembers(t,P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find schema '${r}'`,n)])}let i=e.symbolMembers(t).getFiltered(gd)||[];for(let e of i){let t=e.name;if(e.isKind(P.Table)&&r===t)return k.create(e)}let a=e.lookupMembers(t,P.Table,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find table '${r}'`,n)])}function lse(e,t,n,r){let i=th(n);if(i===void 0)return k.create(void 0);let a=e.lookupMembers(t,r,i);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Could not find ${r===P.StickyNote?`note`:`tablegroup`} '${i}'`,n)])}function use(e,t,n){let r=th(n);if(r===void 0)return k.create(void 0);let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Could not find schema '${r}'`,n)])}var dse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof Nh)return[];let t=e.body.filter(e=>e instanceof Eh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},fse=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.enum={values:[]}}interpret(){this.enum.token=ih(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody(this.declarationNode.body)];return k.create(this.enum,e)}interpretName(){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);return this.enum.name=e,this.enum.schemaName=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=ih(t),n.name=eh(t.callee);let r=km(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:ah(Zm(r.value)),token:ih(r)},this.enum.values.push(n),[]})}},sg={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`Enum '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field '${e}'`,t)}},pse={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.Enum)?new k(e.symbolFactory.create(fh,{declaration:t,name:n},t.filepath)):zm(t,_d.Enum)?new k(e.symbolFactory.create(Noe,{declaration:t,name:n},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Enum))return k.create(hd);let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.EnumField)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration,r=o.get(t);r?(a.push(sg.getFieldDuplicateError(t,r)),a.push(sg.getFieldDuplicateError(t,n))):o.set(t,n)}}return new k(i,a)},bindNode(e,t){if(!Im(t,_d.Enum))return k.create(hd);let n=new dse(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof fh?new fse(e,t,n).interpret():k.create(hd)}},mse=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof Eh)||!this.declarationNode.parent.isKind(_d.Table)||!(this.declarationNode.body instanceof Ph)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=Jm(this.declarationNode.parent.name)?.join(`.`)??`<unnamed>`;return[e.callee,...e.args].flatMap(ig).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let n=th(e);if(n===void 0)return[];let r=this.compiler.nodeReferee(e);return!r.getValue()||r.hasValue(gd)?new N(M.BINDING_ERROR,`No column named '${n}' inside Table '${t}'`,e):[]})})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},hse=class{constructor(e,t){this.compiler=e,this.node=t}interpret(){let e=this.node.body;return e instanceof Ph?new k(e.body.flatMap(e=>{if(!(e instanceof Nh)||!e.callee)return[];let t=[],n=ih(e),r=[e.callee,...e.args],i,a,o,s,c;qp(r)instanceof Fh&&r.pop();let l=this.compiler.nodeSettings(e).getFiltered(gd);if(l){i=!!l[vd.PK]?.length||void 0,a=!!l[vd.Unique]?.length||void 0,o=Zm(l[vd.Name]?.at(0)?.value);let e=l[vd.Note]?.at(0);if(e){let t=Zm(e.value);t!==void 0&&(s={value:t,token:ih(e)})}c=eh(l[vd.Type]?.at(0)?.value)}let u=r.flatMap(e=>{if(!(e instanceof zh))return e;let t=[],n=e;for(;n instanceof zh&&(n.argumentList&&t.push(n.argumentList),n.callee);)n=n.callee;return t.push(n),t});for(let e of u){let n=Xm(e);if(n){for(let e of n.functional)t.push({value:e.value?.value??``,type:`expression`,token:ih(e)});for(let e of n.nonFunctional)t.push({value:th(e)??``,type:`column`,token:ih(e)})}}return[{columns:t,pk:i,unique:a,name:o,note:s,type:c,token:n}]})):new k([])}},gse={nodeMetadata(e,t){if(!Im(t,_d.Indexes))return k.create(hd);let n=t.parent;return!n||!Im(n,_d.Table)&&!Im(n,_d.TablePartial)?k.create(hd):k.create(new Koe(t))},nodeReferee(e,t){if(!jm(t)||Hm(t))return k.create(hd);let n=t;for(;n&&!Im(n,_d.Indexes);)n=n.parent;if(!n)return k.create(hd);let r=n.parent;if(!r||!Im(r,_d.Table)&&!Im(r,_d.TablePartial))return k.create(hd);let i=e.nodeSymbol(r).getFiltered(gd);if(!i)return new k(void 0);let a=jm(t)?t.expression.variable?.value??``:``,o=e.lookupMembers(i,P.Column,a);if(o)return k.create(o);let s=Im(r,_d.TablePartial)?`TablePartial`:`Table`;return new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${a}' does not exist in ${s} 'public.${i.name}'`,t)])},bindNode(e,t){return Im(t,_d.Indexes)?k.create(void 0,new mse(e,t).bind()):k.create(hd)},interpretMetadata(e,t){return t.kind===qh.Indexes?t.declaration instanceof Eh?new hse(e,t.declaration).interpret():k.create(void 0):k.create(hd)}};function cg(e,t){let n=qm(t);if(!n||n.length===0)return;let r=n[n.length-1];if(r instanceof Ih){let t=[];for(let n of r.elementList){let r=e.nodeReferee(n).getFiltered(gd);if(!r)return;t.push(r.originalSymbol)}return t}let i=n[n.length-1];if(!i||i instanceof Ih)return;let a=e.nodeReferee(i).getFiltered(gd);if(a)return[a.originalSymbol]}function _se(e,t,n,r){let i=e.map(e=>e.intern()).sort().join(`,`),a=t.map(e=>e.intern()).sort().join(`,`);if(i===a)return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)];let o=i<a?`${i}-${a}`:`${a}-${i}`,s=r.get(o);return s?[new N(M.CIRCULAR_REF,`References with same endpoints exist`,n),new N(M.CIRCULAR_REF,`References with same endpoints exist`,s)]:(r.set(o,n),[])}var vse=class{constructor(e,t){this.compiler=t,this.ast=e}resolve(){let e=[],t=this.compiler.reachableFiles(this.ast.filepath);for(let n of t){let{ast:t}=this.compiler.parseFile(n).getFiltered(gd)||{ast:void 0};if(!t)continue;let r=t.body.filter(e=>e instanceof Eh&&e.isKind(_d.Project));r.length>1&&r.forEach(t=>e.push(new N(M.PROJECT_REDEFINED,`Only one project can exist`,t)));for(let n of t.body)if(n instanceof Eh&&n.type){let t=n;e.push(...this.compiler.bindNode(t).getErrors())}else e.push(...this.compiler.bindNode(n).getErrors())}let n=this.compiler.nodeSymbol(this.ast).getFiltered(gd);return n&&e.push(...yse(this.compiler,n)),e.push(...this.checkDuplicateRefs()),e.push(...this.checkTableGroups()),new k(void 0,e)}checkDuplicateRefs(){let e=[],t=new Map,n=this.compiler.reachableFiles(this.ast.filepath);for(let r of n){let n=this.compiler.parseFile(r).getFiltered(gd);if(!n)continue;let{ast:i}=n;for(let n of i.body){if(!(n instanceof Eh)||!n.type)continue;let r=n;Im(r,_d.Ref)&&e.push(...this.checkStandaloneRefs(r,t)),Im(r,_d.Table)&&e.push(...this.checkInlineRefs(r,t)),Im(r,_d.TablePartial)&&e.push(...this.checkTablePartialSelfRefs(r))}}return e}checkStandaloneRefs(e,t){let n=[];for(let r of Km(e)){if(!(r instanceof Nh)||!r.callee||!Um(r.callee))continue;let i=r.callee;if(!i.leftExpression||!i.rightExpression)continue;let a=cg(this.compiler,i.leftExpression),o=cg(this.compiler,i.rightExpression);!a||!o||n.push(..._se(a,o,e,t))}return n}checkInlineRefs(e,t){let n=[];for(let r of Km(e)){if(!(r instanceof Nh)||!r.callee)continue;let e=this.compiler.nodeSymbol(r).getFiltered(gd);if(!e)continue;let i=this.compiler.nodeSettings(r).getFiltered(gd);if(!i)continue;let a=i[vd.Ref];if(!(!a||a.length===0))for(let r of a){let i=r.value;if(!(i instanceof kh)||!i.op||!Cm(i.op.value)||!i.expression)continue;let a=cg(this.compiler,i.expression);if(!a)continue;let o=[e.originalSymbol];n.push(..._se(o,a,r,t))}}return n}checkTablePartialSelfRefs(e){let t=[];for(let n of Km(e)){if(!(n instanceof Nh)||!n.callee)continue;let e=eh(n.callee);if(!e)continue;let r=this.compiler.nodeSettings(n).getFiltered(gd);if(!r)continue;let i=r[vd.Ref];if(!(!i||i.length===0))for(let n of i){let r=n.value;r instanceof kh&&(!r.op||!Cm(r.op.value)||r.expression&&jm(r.expression)&&r.expression.expression.variable?.value===e&&t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)))}}return t}checkTableGroups(){let e=[],t=new Map,n=this.compiler.reachableFiles(this.ast.filepath);for(let r of n){let n=this.compiler.parseFile(r).getFiltered(gd);if(!n)continue;let{ast:i}=n;for(let n of i.body){if(!(n instanceof Eh)||!n.type)continue;let r=n;if(!Im(r,_d.TableGroup))continue;let i=r.name?Jm(r.name):void 0,a=i?i.join(`.`):`<unknown>`,o=Km(r);for(let n of o){if(!(n instanceof Nh)||!n.callee)continue;let r=qm(n.callee);if(!r||r.length===0)continue;let i=r[r.length-1],o=this.compiler.nodeReferee(i).getFiltered(gd)?.originalSymbol;if(!o)continue;let s=t.get(o.id);if(s){let t=Jm(n.callee),r=t?t.join(`.`):`<unknown>`;e.push(new N(M.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${r}" already appears in group "${s.groupName}"`,n))}else t.set(o.id,{groupName:a,node:n})}}}return e}};function yse(e,t,n=new Set){if(n.has(t.id))return[];n.add(t.id);let r=e.symbolMembers(t),i=[...r.getErrors()],a=r.getFiltered(gd);if(!a)return i;for(let t of a)t instanceof dh&&i.push(...yse(e,t,n));return i}function bse(e,t,n){t.isKind(P.Table)?e.externals.tables.push(n):t.isKind(P.Enum)?e.externals.enums.push(n):t.isKind(P.TableGroup)?e.externals.tableGroups.push(n):t.isKind(P.TablePartial)?e.externals.tablePartials.push(n):t.isKind(P.StickyNote)&&e.externals.notes.push(n)}var xse={mysql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`,`mediumint`]),postgres:new Set([`int`,`integer`,`smallint`,`bigint`,`serial`,`bigserial`,`smallserial`]),mssql:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`]),oracle:new Set([`int`,`integer`,`smallint`]),snowflake:new Set([`int`,`integer`,`smallint`,`bigint`,`tinyint`])},Sse={mysql:new Set([`decimal`,`numeric`,`float`,`double`,`real`]),postgres:new Set([`decimal`,`numeric`,`real`,`float`,`double precision`]),mssql:new Set([`decimal`,`numeric`,`real`,`float`]),oracle:new Set([`number`,`decimal`,`numeric`,`float`,`real`]),snowflake:new Set([`number`,`decimal`,`numeric`,`float`,`double`,`real`])},Cse={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},wse={mysql:new Set([`varchar`,`char`,`text`,`tinytext`,`mediumtext`,`longtext`,`string`]),postgres:new Set([`varchar`,`char`,`character`,`character varying`,`text`,`string`]),mssql:new Set([`varchar`,`char`,`nvarchar`,`nchar`,`text`,`ntext`,`string`]),oracle:new Set([`varchar`,`varchar2`,`char`,`nvarchar2`,`nchar`,`string`]),snowflake:new Set([`varchar`,`char`,`text`,`string`])},Tse={mysql:new Set([`binary`,`varbinary`,`blob`,`tinyblob`,`mediumblob`,`longblob`]),postgres:new Set([`bytea`]),mssql:new Set([`binary`,`varbinary`]),oracle:new Set([`blob`,`raw`]),snowflake:new Set([`binary`,`varbinary`])},Ese={mysql:new Set([`date`,`datetime`,`timestamp`,`time`]),postgres:new Set([`date`,`timestamp`,`timestamptz`,`timestamp with time zone`,`timestamp without time zone`,`time`,`timetz`,`time with time zone`,`time without time zone`]),mssql:new Set([`date`,`datetime`,`datetime2`,`smalldatetime`,`time`]),oracle:new Set([`date`,`timestamp`,`timestamp with time zone`,`timestamp with local time zone`]),snowflake:new Set([`date`,`datetime`,`timestamp`,`time`])},Dse={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function lg(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function ug(e,t){let n=lg(e);return t?xse[t].has(n):Object.values(xse).some(e=>e.has(n))}function dg(e,t){let n=lg(e);return t?Sse[t].has(n):Object.values(Sse).some(e=>e.has(n))}function fg(e,t){return ug(e,t)||dg(e,t)}function pg(e,t){let n=lg(e);return t?Cse[t].has(n):Object.values(Cse).some(e=>e.has(n))}function mg(e,t){let n=lg(e);return t?wse[t].has(n):Object.values(wse).some(e=>e.has(n))}function hg(e,t){let n=lg(e);return t?Tse[t].has(n):Object.values(Tse).some(e=>e.has(n))}function gg(e,t){let n=lg(e);return t?Ese[t].has(n):Object.values(Ese).some(e=>e.has(n))}function _g(e,t){let n=lg(e);return t?Dse[t].has(n):Object.values(Dse).some(e=>e.has(n))}function Ose(e,t){if(t)return`string`;if(ug(e))return`integer`;if(dg(e))return`real`;if(pg(e))return`bool`;if(mg(e))return`string`;let n=lg(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:gg(e)?`datetime`:e}var vg=class extends Error{},kse=class extends vg{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Ase=class extends vg{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},jse=class extends vg{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},yg=class extends vg{},Mse=class extends vg{constructor(e){super(`Invalid unit ${e}`)}},bg=class extends vg{},xg=class extends vg{constructor(){super(`Zone is an abstract class`)}},Sg=`numeric`,Cg=`short`,wg=`long`,Tg={year:Sg,month:Sg,day:Sg},Nse={year:Sg,month:Cg,day:Sg},Pse={year:Sg,month:Cg,day:Sg,weekday:Cg},Fse={year:Sg,month:wg,day:Sg},Ise={year:Sg,month:wg,day:Sg,weekday:wg},Lse={hour:Sg,minute:Sg},Rse={hour:Sg,minute:Sg,second:Sg},zse={hour:Sg,minute:Sg,second:Sg,timeZoneName:Cg},Bse={hour:Sg,minute:Sg,second:Sg,timeZoneName:wg},Vse={hour:Sg,minute:Sg,hourCycle:`h23`},Hse={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`},Use={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`,timeZoneName:Cg},Wse={hour:Sg,minute:Sg,second:Sg,hourCycle:`h23`,timeZoneName:wg},Gse={year:Sg,month:Sg,day:Sg,hour:Sg,minute:Sg},Kse={year:Sg,month:Sg,day:Sg,hour:Sg,minute:Sg,second:Sg},qse={year:Sg,month:Cg,day:Sg,hour:Sg,minute:Sg},Jse={year:Sg,month:Cg,day:Sg,hour:Sg,minute:Sg,second:Sg},Yse={year:Sg,month:Cg,day:Sg,weekday:Cg,hour:Sg,minute:Sg},Xse={year:Sg,month:wg,day:Sg,hour:Sg,minute:Sg,timeZoneName:Cg},Zse={year:Sg,month:wg,day:Sg,hour:Sg,minute:Sg,second:Sg,timeZoneName:Cg},Qse={year:Sg,month:wg,day:Sg,weekday:wg,hour:Sg,minute:Sg,timeZoneName:wg},$se={year:Sg,month:wg,day:Sg,weekday:wg,hour:Sg,minute:Sg,second:Sg,timeZoneName:wg},Eg=class{get type(){throw new xg}get name(){throw new xg}get ianaName(){return this.name}get isUniversal(){throw new xg}offsetName(e,t){throw new xg}formatOffset(e,t){throw new xg}offset(e){throw new xg}equals(e){throw new xg}get isValid(){throw new xg}},Dg=null,ece=class e extends Eg{static get instance(){return Dg===null&&(Dg=new e),Dg}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ele(e,t,n)}formatOffset(e,t){return v_(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},Og=new Map;function tce(e){let t=Og.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(`en-US`,{hour12:!1,timeZone:e,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,era:`short`}),Og.set(e,t)),t}var nce={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function rce(e,t){let n=e.format(t).replace(/\u200E/g,``),[,r,i,a,o,s,c,l]=/(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(n);return[a,r,i,o,s,c,l]}function ice(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=nce[t];t===`era`?r[a]=i:$g(a)||(r[a]=parseInt(i,10))}return r}var kg=new Map,Ag=class e extends Eg{static create(t){let n=kg.get(t);return n===void 0&&kg.set(t,n=new e(t)),n}static resetCache(){kg.clear(),Og.clear()}static isValidSpecifier(e){return this.isValidZone(e)}static isValidZone(e){if(!e)return!1;try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).format(),!0}catch{return!1}}constructor(t){super(),this.zoneName=t,this.valid=e.isValidZone(t)}get type(){return`iana`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return ele(e,t,n,this.name)}formatOffset(e,t){return v_(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=tce(this.name),[r,i,a,o,s,c,l]=n.formatToParts?ice(n,t):rce(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=p_({year:r,month:i,day:a,hour:s===24?0:s,minute:c,second:l,millisecond:0}),d=+t,f=d%1e3;return d-=f>=0?f:1e3+f,(u-d)/(60*1e3)}equals(e){return e.type===`iana`&&e.name===this.name}get isValid(){return this.valid}},ace={};function oce(e,t={}){let n=JSON.stringify([e,t]),r=ace[n];return r||(r=new Intl.ListFormat(e,t),ace[n]=r),r}var jg=new Map;function Mg(e,t={}){let n=JSON.stringify([e,t]),r=jg.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),jg.set(n,r)),r}var Ng=new Map;function sce(e,t={}){let n=JSON.stringify([e,t]),r=Ng.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Ng.set(n,r)),r}var Pg=new Map;function cce(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=Pg.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),Pg.set(i,a)),a}var Fg=null;function lce(){return Fg||(Fg=new Intl.DateTimeFormat().resolvedOptions().locale,Fg)}var Ig=new Map;function uce(e){let t=Ig.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Ig.set(e,t)),t}var Lg=new Map;function dce(e){let t=Lg.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...bce,...t}),Lg.set(e,t)}return t}function fce(e){let t=e.indexOf(`-x-`);t!==-1&&(e=e.substring(0,t));let n=e.indexOf(`-u-`);if(n===-1)return[e];{let t,r;try{t=Mg(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=Mg(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function pce(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function mce(e){let t=[];for(let n=1;n<=12;n++){let r=nv.utc(2009,n,1);t.push(e(r))}return t}function hce(e){let t=[];for(let n=1;n<=7;n++){let r=nv.utc(2016,11,13+n);t.push(e(r))}return t}function Rg(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function gce(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||uce(e.locale).numberingSystem===`latn`}var _ce=class{constructor(e,t,n){this.padTo=n.padTo||0,this.floor=n.floor||!1;let{padTo:r,floor:i,...a}=n;if(!t||Object.keys(a).length>0){let t={useGrouping:!1,...n};n.padTo>0&&(t.minimumIntegerDigits=n.padTo),this.inf=sce(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return a_(this.floor?Math.floor(e):l_(e,3),this.padTo)}},vce=class{constructor(e,t,n){this.opts=n,this.originalZone=void 0;let r;if(this.opts.timeZone)this.dt=e;else if(e.zone.type===`fixed`){let t=-1*(e.offset/60),n=t>=0?`Etc/GMT+${t}`:`Etc/GMT${t}`;e.offset!==0&&Ag.create(n).valid?(r=n,this.dt=e):(r=`UTC`,this.dt=e.offset===0?e:e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone)}else e.zone.type===`system`?this.dt=e:e.zone.type===`iana`?(this.dt=e,r=e.zone.name):(r=`UTC`,this.dt=e.setZone(`UTC`).plus({minutes:e.offset}),this.originalZone=e.zone);let i={...this.opts};i.timeZone=i.timeZone||r,this.dtf=Mg(t,i)}format(){return this.originalZone?this.formatToParts().map(({value:e})=>e).join(``):this.dtf.format(this.dt.toJSDate())}formatToParts(){let e=this.dtf.formatToParts(this.dt.toJSDate());return this.originalZone?e.map(e=>{if(e.type===`timeZoneName`){let t=this.originalZone.offsetName(this.dt.ts,{locale:this.dt.locale,format:this.opts.timeZoneName});return{...e,value:t}}else return e}):e}resolvedOptions(){return this.dtf.resolvedOptions()}},yce=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&qce()&&(this.rtf=cce(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):yle(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},bce={firstDay:1,minimalDays:4,weekend:[6,7]},zg=class e{static fromOpts(t){return e.create(t.locale,t.numberingSystem,t.outputCalendar,t.weekSettings,t.defaultToEN)}static create(t,n,r,i,a=!1){let o=t||Kg.defaultLocale;return new e(o||(a?`en-US`:lce()),n||Kg.defaultNumberingSystem,r||Kg.defaultOutputCalendar,r_(i)||Kg.defaultWeekSettings,o)}static resetCache(){Fg=null,jg.clear(),Ng.clear(),Pg.clear(),Ig.clear(),Lg.clear()}static fromObject({locale:t,numberingSystem:n,outputCalendar:r,weekSettings:i}={}){return e.create(t,n,r,i)}constructor(e,t,n,r,i){let[a,o,s]=fce(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=pce(this.locale,this.numberingSystem,this.outputCalendar),this.weekdaysCache={format:{},standalone:{}},this.monthsCache={format:{},standalone:{}},this.meridiemCache=null,this.eraCache={},this.specifiedLocale=i,this.fastNumbersCached=null}get fastNumbers(){return this.fastNumbersCached??=gce(this),this.fastNumbersCached}listingMode(){let e=this.isEnglish(),t=(this.numberingSystem===null||this.numberingSystem===`latn`)&&(this.outputCalendar===null||this.outputCalendar===`gregory`);return e&&t?`en`:`intl`}clone(t){return!t||Object.getOwnPropertyNames(t).length===0?this:e.create(t.locale||this.specifiedLocale,t.numberingSystem||this.numberingSystem,t.outputCalendar||this.outputCalendar,r_(t.weekSettings)||this.weekSettings,t.defaultToEN||!1)}redefaultToEN(e={}){return this.clone({...e,defaultToEN:!0})}redefaultToSystem(e={}){return this.clone({...e,defaultToEN:!1})}months(e,t=!1){return Rg(this,e,ale,()=>{let n=this.intl===`ja`||this.intl.startsWith(`ja-`);t&=!n;let r=t?{month:e,day:`numeric`}:{month:e},i=t?`format`:`standalone`;if(!this.monthsCache[i][e]){let t=n?e=>this.dtFormatter(e,r).format():e=>this.extract(e,r,`month`);this.monthsCache[i][e]=mce(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Rg(this,e,lle,()=>{let n=t?{weekday:e,year:`numeric`,month:`long`,day:`numeric`}:{weekday:e},r=t?`format`:`standalone`;return this.weekdaysCache[r][e]||(this.weekdaysCache[r][e]=hce(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Rg(this,void 0,()=>ule,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[nv.utc(2016,11,13,9),nv.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Rg(this,e,mle,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[nv.utc(-40,1,1),nv.utc(2017,1,1)].map(e=>this.extract(e,t,`era`))),this.eraCache[e]})}extract(e,t,n){let r=this.dtFormatter(e,t).formatToParts().find(e=>e.type.toLowerCase()===n);return r?r.value:null}numberFormatter(e={}){return new _ce(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new vce(e,this.intl,t)}relFormatter(e={}){return new yce(this.intl,this.isEnglish(),e)}listFormatter(e={}){return oce(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||uce(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:Jce()?dce(this.locale):bce}getStartOfWeek(){return this.getWeekSettings().firstDay}getMinDaysInFirstWeek(){return this.getWeekSettings().minimalDays}getWeekendDays(){return this.getWeekSettings().weekend}equals(e){return this.locale===e.locale&&this.numberingSystem===e.numberingSystem&&this.outputCalendar===e.outputCalendar}toString(){return`Locale(${this.locale}, ${this.numberingSystem}, ${this.outputCalendar})`}},Bg=null,Vg=class e extends Eg{static get utcInstance(){return Bg===null&&(Bg=new e(0)),Bg}static instance(t){return t===0?e.utcInstance:new e(t)}static parseSpecifier(t){if(t){let n=t.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i);if(n)return new e(g_(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${v_(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${v_(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return v_(this.fixed,t)}get isUniversal(){return!0}offset(){return this.fixed}equals(e){return e.type===`fixed`&&e.fixed===this.fixed}get isValid(){return!0}},xce=class extends Eg{constructor(e){super(),this.zoneName=e}get type(){return`invalid`}get name(){return this.zoneName}get isUniversal(){return!1}offsetName(){return null}formatOffset(){return``}offset(){return NaN}equals(){return!1}get isValid(){return!1}};function Hg(e,t){if($g(e)||e===null)return t;if(e instanceof Eg)return e;if(Gce(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?ece.instance:n===`utc`||n===`gmt`?Vg.utcInstance:Vg.parseSpecifier(n)||Ag.create(e)}else if(e_(e))return Vg.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new xce(e)}var Ug={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},Sce={arab:[1632,1641],arabext:[1776,1785],bali:[6992,7001],beng:[2534,2543],deva:[2406,2415],fullwide:[65296,65303],gujr:[2790,2799],khmr:[6112,6121],knda:[3302,3311],laoo:[3792,3801],limb:[6470,6479],mlym:[3430,3439],mong:[6160,6169],mymr:[4160,4169],orya:[2918,2927],tamldec:[3046,3055],telu:[3174,3183],thai:[3664,3673],tibt:[3872,3881]},Cce=Ug.hanidec.replace(/[\[|\]]/g,``).split(``);function wce(e){let t=parseInt(e,10);if(isNaN(t)){t=``;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(e[n].search(Ug.hanidec)!==-1)t+=Cce.indexOf(e[n]);else for(let e in Sce){let[n,i]=Sce[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Wg=new Map;function Tce(){Wg.clear()}function Gg({numberingSystem:e},t=``){let n=e||`latn`,r=Wg.get(n);r===void 0&&(r=new Map,Wg.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Ug[n]}${t}`),r.set(t,i)),i}var Ece=()=>Date.now(),Dce=`system`,Oce=null,kce=null,Ace=null,jce=60,Mce,Nce=null,Kg=class{static get now(){return Ece}static set now(e){Ece=e}static set defaultZone(e){Dce=e}static get defaultZone(){return Hg(Dce,ece.instance)}static get defaultLocale(){return Oce}static set defaultLocale(e){Oce=e}static get defaultNumberingSystem(){return kce}static set defaultNumberingSystem(e){kce=e}static get defaultOutputCalendar(){return Ace}static set defaultOutputCalendar(e){Ace=e}static get defaultWeekSettings(){return Nce}static set defaultWeekSettings(e){Nce=r_(e)}static get twoDigitCutoffYear(){return jce}static set twoDigitCutoffYear(e){jce=e%100}static get throwOnInvalid(){return Mce}static set throwOnInvalid(e){Mce=e}static resetCaches(){zg.resetCache(),Ag.resetCache(),nv.resetCache(),Tce()}},qg=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},Pce=[0,31,59,90,120,151,181,212,243,273,304,334],Fce=[0,31,60,91,121,152,182,213,244,274,305,335];function Jg(e,t){return new qg(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function Yg(e,t,n){let r=new Date(Date.UTC(e,t-1,n));e<100&&e>=0&&r.setUTCFullYear(r.getUTCFullYear()-1900);let i=r.getUTCDay();return i===0?7:i}function Ice(e,t,n){return n+(u_(e)?Fce:Pce)[t-1]}function Lce(e,t){let n=u_(e)?Fce:Pce,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function Xg(e,t){return(e-t+7)%7+1}function Zg(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=Ice(r,i,a),s=Xg(Yg(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=m_(l,t,n)):c>m_(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...y_(e)}}function Rce(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=Xg(Yg(r,1,t),n),s=d_(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=d_(l)):c>s?(l=r+1,c-=d_(r)):l=r;let{month:u,day:d}=Lce(l,c);return{year:l,month:u,day:d,...y_(e)}}function Qg(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:Ice(t,n,r),...y_(e)}}function zce(e){let{year:t,ordinal:n}=e,{month:r,day:i}=Lce(t,n);return{year:t,month:r,day:i,...y_(e)}}function Bce(e,t){if(!$g(e.localWeekday)||!$g(e.localWeekNumber)||!$g(e.localWeekYear)){if(!$g(e.weekday)||!$g(e.weekNumber)||!$g(e.weekYear))throw new yg(`Cannot mix locale-based week fields with ISO-based week fields`);return $g(e.localWeekday)||(e.weekday=e.localWeekday),$g(e.localWeekNumber)||(e.weekNumber=e.localWeekNumber),$g(e.localWeekYear)||(e.weekYear=e.localWeekYear),delete e.localWeekday,delete e.localWeekNumber,delete e.localWeekYear,{minDaysInFirstWeek:t.getMinDaysInFirstWeek(),startOfWeek:t.getStartOfWeek()}}else return{minDaysInFirstWeek:4,startOfWeek:1}}function Vce(e,t=4,n=1){let r=t_(e.weekYear),i=i_(e.weekNumber,1,m_(e.weekYear,t,n)),a=i_(e.weekday,1,7);return r?i?a?!1:Jg(`weekday`,e.weekday):Jg(`week`,e.weekNumber):Jg(`weekYear`,e.weekYear)}function Hce(e){let t=t_(e.year),n=i_(e.ordinal,1,d_(e.year));return t?n?!1:Jg(`ordinal`,e.ordinal):Jg(`year`,e.year)}function Uce(e){let t=t_(e.year),n=i_(e.month,1,12),r=i_(e.day,1,f_(e.year,e.month));return t?n?r?!1:Jg(`day`,e.day):Jg(`month`,e.month):Jg(`year`,e.year)}function Wce(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=i_(t,0,23)||t===24&&n===0&&r===0&&i===0,o=i_(n,0,59),s=i_(r,0,59),c=i_(i,0,999);return a?o?s?c?!1:Jg(`millisecond`,i):Jg(`second`,r):Jg(`minute`,n):Jg(`hour`,t)}function $g(e){return e===void 0}function e_(e){return typeof e==`number`}function t_(e){return typeof e==`number`&&e%1==0}function Gce(e){return typeof e==`string`}function Kce(e){return Object.prototype.toString.call(e)===`[object Date]`}function qce(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function Jce(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Yce(e){return Array.isArray(e)?e:[e]}function Xce(e,t,n){if(e.length!==0)return e.reduce((e,r)=>{let i=[t(r),r];return e&&n(e[0],i[0])===e[0]?e:i},null)[1]}function Zce(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function n_(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function r_(e){if(e==null)return null;if(typeof e!=`object`)throw new bg(`Week settings must be an object`);if(!i_(e.firstDay,1,7)||!i_(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!i_(e,1,7)))throw new bg(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function i_(e,t,n){return t_(e)&&e>=t&&e<=n}function Qce(e,t){return e-t*Math.floor(e/t)}function a_(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function o_(e){if(!($g(e)||e===null||e===``))return parseInt(e,10)}function s_(e){if(!($g(e)||e===null||e===``))return parseFloat(e)}function c_(e){if(!($g(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function l_(e,t,n=`round`){let r=10**t;switch(n){case`expand`:return e>0?Math.ceil(e*r)/r:Math.floor(e*r)/r;case`trunc`:return Math.trunc(e*r)/r;case`round`:return Math.round(e*r)/r;case`floor`:return Math.floor(e*r)/r;case`ceil`:return Math.ceil(e*r)/r;default:throw RangeError(`Value rounding ${n} is out of range`)}}function u_(e){return e%4==0&&(e%100!=0||e%400==0)}function d_(e){return u_(e)?366:365}function f_(e,t){let n=Qce(t-1,12)+1,r=e+(t-n)/12;return n===2?u_(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function p_(e){let t=Date.UTC(e.year,e.month-1,e.day,e.hour,e.minute,e.second,e.millisecond);return e.year<100&&e.year>=0&&(t=new Date(t),t.setUTCFullYear(e.year,e.month-1,e.day)),+t}function $ce(e,t,n){return-Xg(Yg(e,1,t),n)+t-1}function m_(e,t=4,n=1){let r=$ce(e,t,n),i=$ce(e+1,t,n);return(d_(e)-r+i)/7}function h_(e){return e>99?e:e>Kg.twoDigitCutoffYear?1900+e:2e3+e}function ele(e,t,n,r=null){let i=new Date(e),a={hourCycle:`h23`,year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`};r&&(a.timeZone=r);let o={timeZoneName:t,...a},s=new Intl.DateTimeFormat(n,o).formatToParts(i).find(e=>e.type.toLowerCase()===`timezonename`);return s?s.value:null}function g_(e,t){let n=parseInt(e,10);Number.isNaN(n)&&(n=0);let r=parseInt(t,10)||0,i=n<0||Object.is(n,-0)?-r:r;return n*60+i}function tle(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new bg(`Invalid unit value ${e}`);return t}function __(e,t){let n={};for(let r in e)if(n_(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=tle(i)}return n}function v_(e,t){let n=Math.trunc(Math.abs(e/60)),r=Math.trunc(Math.abs(e%60)),i=e>=0?`+`:`-`;switch(t){case`short`:return`${i}${a_(n,2)}:${a_(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${a_(n,2)}${a_(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function y_(e){return Zce(e,[`hour`,`minute`,`second`,`millisecond`])}var nle=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],rle=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],ile=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function ale(e){switch(e){case`narrow`:return[...ile];case`short`:return[...rle];case`long`:return[...nle];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`10`,`11`,`12`];case`2-digit`:return[`01`,`02`,`03`,`04`,`05`,`06`,`07`,`08`,`09`,`10`,`11`,`12`];default:return null}}var ole=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],sle=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],cle=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function lle(e){switch(e){case`narrow`:return[...cle];case`short`:return[...sle];case`long`:return[...ole];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ule=[`AM`,`PM`],dle=[`Before Christ`,`Anno Domini`],fle=[`BC`,`AD`],ple=[`B`,`A`];function mle(e){switch(e){case`narrow`:return[...ple];case`short`:return[...fle];case`long`:return[...dle];default:return null}}function hle(e){return ule[e.hour<12?0:1]}function gle(e,t){return lle(t)[e.weekday-1]}function _le(e,t){return ale(t)[e.month-1]}function vle(e,t){return mle(t)[e.year<0?0:1]}function yle(e,t,n=`always`,r=!1){let i={years:[`year`,`yr.`],quarters:[`quarter`,`qtr.`],months:[`month`,`mo.`],weeks:[`week`,`wk.`],days:[`day`,`day`,`days`],hours:[`hour`,`hr.`],minutes:[`minute`,`min.`],seconds:[`second`,`sec.`]},a=[`hours`,`minutes`,`seconds`].indexOf(e)===-1;if(n===`auto`&&a){let n=e===`days`;switch(t){case 1:return n?`tomorrow`:`next ${i[e][0]}`;case-1:return n?`yesterday`:`last ${i[e][0]}`;case 0:return n?`today`:`this ${i[e][0]}`}}let o=Object.is(t,-0)||t<0,s=Math.abs(t),c=s===1,l=i[e],u=r?c?l[1]:l[2]||l[1]:c?i[e][0]:e;return o?`${s} ${u} ago`:`in ${s} ${u}`}function ble(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var xle={D:Tg,DD:Nse,DDD:Fse,DDDD:Ise,t:Lse,tt:Rse,ttt:zse,tttt:Bse,T:Vse,TT:Hse,TTT:Use,TTTT:Wse,f:Gse,ff:qse,fff:Xse,ffff:Qse,F:Kse,FF:Jse,FFF:Zse,FFFF:$se},b_=class e{static create(t,n={}){return new e(t,n)}static parseFormat(e){let t=null,n=``,r=!1,i=[];for(let a=0;a<e.length;a++){let o=e.charAt(a);o===`'`?((n.length>0||r)&&i.push({literal:r||/^\s+$/.test(n),val:n===``?`'`:n}),t=null,n=``,r=!r):r||o===t?n+=o:(n.length>0&&i.push({literal:/^\s+$/.test(n),val:n}),n=o,t=o)}return n.length>0&&i.push({literal:r||/^\s+$/.test(n),val:n}),i}static macroTokenToFormatOpts(e){return xle[e]}constructor(e,t){this.opts=t,this.loc=e,this.systemLoc=null}formatWithSystemDefault(e,t){return this.systemLoc===null&&(this.systemLoc=this.loc.redefaultToSystem()),this.systemLoc.dtFormatter(e,{...this.opts,...t}).format()}dtFormatter(e,t={}){return this.loc.dtFormatter(e,{...this.opts,...t})}formatDateTime(e,t){return this.dtFormatter(e,t).format()}formatDateTimeParts(e,t){return this.dtFormatter(e,t).formatToParts()}formatInterval(e,t){return this.dtFormatter(e.start,t).dtf.formatRange(e.start.toJSDate(),e.end.toJSDate())}resolvedOptions(e,t){return this.dtFormatter(e,t).resolvedOptions()}num(e,t=0,n=void 0){if(this.opts.forceSimple)return a_(e,t);let r={...this.opts};return t>0&&(r.padTo=t),n&&(r.signDisplay=n),this.loc.numberFormatter(r).format(e)}formatDateTimeFromString(t,n){let r=this.loc.listingMode()===`en`,i=this.loc.outputCalendar&&this.loc.outputCalendar!==`gregory`,a=(e,n)=>this.loc.extract(t,e,n),o=e=>t.isOffsetFixed&&t.offset===0&&e.allowZ?`Z`:t.isValid?t.zone.formatOffset(t.ts,e.format):``,s=()=>r?hle(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?_le(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?gle(t,e):a(n?{weekday:e}:{weekday:e,month:`long`,day:`numeric`},`weekday`),u=n=>{let r=e.macroTokenToFormatOpts(n);return r?this.formatWithSystemDefault(t,r):n},d=e=>r?vle(t,e):a({era:e},`era`);return ble(e.parseFormat(n),e=>{switch(e){case`S`:return this.num(t.millisecond);case`u`:case`SSS`:return this.num(t.millisecond,3);case`s`:return this.num(t.second);case`ss`:return this.num(t.second,2);case`uu`:return this.num(Math.floor(t.millisecond/10),2);case`uuu`:return this.num(Math.floor(t.millisecond/100));case`m`:return this.num(t.minute);case`mm`:return this.num(t.minute,2);case`h`:return this.num(t.hour%12==0?12:t.hour%12);case`hh`:return this.num(t.hour%12==0?12:t.hour%12,2);case`H`:return this.num(t.hour);case`HH`:return this.num(t.hour,2);case`Z`:return o({format:`narrow`,allowZ:this.opts.allowZ});case`ZZ`:return o({format:`short`,allowZ:this.opts.allowZ});case`ZZZ`:return o({format:`techie`,allowZ:this.opts.allowZ});case`ZZZZ`:return t.zone.offsetName(t.ts,{format:`short`,locale:this.loc.locale});case`ZZZZZ`:return t.zone.offsetName(t.ts,{format:`long`,locale:this.loc.locale});case`z`:return t.zoneName;case`a`:return s();case`d`:return i?a({day:`numeric`},`day`):this.num(t.day);case`dd`:return i?a({day:`2-digit`},`day`):this.num(t.day,2);case`c`:return this.num(t.weekday);case`ccc`:return l(`short`,!0);case`cccc`:return l(`long`,!0);case`ccccc`:return l(`narrow`,!0);case`E`:return this.num(t.weekday);case`EEE`:return l(`short`,!1);case`EEEE`:return l(`long`,!1);case`EEEEE`:return l(`narrow`,!1);case`L`:return i?a({month:`numeric`,day:`numeric`},`month`):this.num(t.month);case`LL`:return i?a({month:`2-digit`,day:`numeric`},`month`):this.num(t.month,2);case`LLL`:return c(`short`,!0);case`LLLL`:return c(`long`,!0);case`LLLLL`:return c(`narrow`,!0);case`M`:return i?a({month:`numeric`},`month`):this.num(t.month);case`MM`:return i?a({month:`2-digit`},`month`):this.num(t.month,2);case`MMM`:return c(`short`,!1);case`MMMM`:return c(`long`,!1);case`MMMMM`:return c(`narrow`,!1);case`y`:return i?a({year:`numeric`},`year`):this.num(t.year);case`yy`:return i?a({year:`2-digit`},`year`):this.num(t.year.toString().slice(-2),2);case`yyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,4);case`yyyyyy`:return i?a({year:`numeric`},`year`):this.num(t.year,6);case`G`:return d(`short`);case`GG`:return d(`long`);case`GGGGG`:return d(`narrow`);case`kk`:return this.num(t.weekYear.toString().slice(-2),2);case`kkkk`:return this.num(t.weekYear,4);case`W`:return this.num(t.weekNumber);case`WW`:return this.num(t.weekNumber,2);case`n`:return this.num(t.localWeekNumber);case`nn`:return this.num(t.localWeekNumber,2);case`ii`:return this.num(t.localWeekYear.toString().slice(-2),2);case`iiii`:return this.num(t.localWeekYear,4);case`o`:return this.num(t.ordinal);case`ooo`:return this.num(t.ordinal,3);case`q`:return this.num(t.quarter);case`qq`:return this.num(t.quarter,2);case`X`:return this.num(Math.floor(t.ts/1e3));case`x`:return this.num(t.ts);default:return u(e)}})}formatDurationFromString(t,n){let r=this.opts.signMode===`negativeLargestOnly`?-1:1,i=e=>{switch(e[0]){case`S`:return`milliseconds`;case`s`:return`seconds`;case`m`:return`minutes`;case`h`:return`hours`;case`d`:return`days`;case`w`:return`weeks`;case`M`:return`months`;case`y`:return`years`;default:return null}},a=(e,t)=>n=>{let a=i(n);if(a){let i=t.isNegativeDuration&&a!==t.largestUnit?r:1,o;return o=this.opts.signMode===`negativeLargestOnly`&&a!==t.largestUnit?`never`:this.opts.signMode===`all`?`always`:`auto`,this.num(e.get(a)*i,n.length,o)}else return n},o=e.parseFormat(n),s=o.reduce((e,{literal:t,val:n})=>t?e:e.concat(n),[]),c=t.shiftTo(...s.map(i).filter(e=>e));return ble(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},Sle=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function x_(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function S_(...e){return t=>e.reduce(([e,n,r],i)=>{let[a,o,s]=i(t,r);return[{...e,...a},o||n,s]},[{},null,1]).slice(0,2)}function C_(e,...t){if(e==null)return[null,null];for(let[n,r]of t){let t=n.exec(e);if(t)return r(t)}return[null,null]}function Cle(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=o_(t[n+i]);return[r,null,n+i]}}var wle=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Tle=`(?:${wle.source}?(?:\\[(${Sle.source})\\])?)?`,w_=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,Ele=RegExp(`${w_.source}${Tle}`),T_=RegExp(`(?:[Tt]${Ele.source})?`),Dle=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Ole=/(\d{4})-?W(\d\d)(?:-?(\d))?/,kle=/(\d{4})-?(\d{3})/,Ale=Cle(`weekYear`,`weekNumber`,`weekDay`),jle=Cle(`year`,`ordinal`),Mle=/(\d{4})-(\d\d)-(\d\d)/,Nle=RegExp(`${w_.source} ?(?:${wle.source}|(${Sle.source}))?`),Ple=RegExp(`(?: ${Nle.source})?`);function E_(e,t,n){let r=e[t];return $g(r)?n:o_(r)}function Fle(e,t){return[{year:E_(e,t),month:E_(e,t+1,1),day:E_(e,t+2,1)},null,t+3]}function D_(e,t){return[{hours:E_(e,t,0),minutes:E_(e,t+1,0),seconds:E_(e,t+2,0),milliseconds:c_(e[t+3])},null,t+4]}function O_(e,t){let n=!e[t]&&!e[t+1],r=g_(e[t+1],e[t+2]);return[{},n?null:Vg.instance(r),t+3]}function k_(e,t){return[{},e[t]?Ag.create(e[t]):null,t+1]}var Ile=RegExp(`^T?${w_.source}$`),Lle=/^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/;function Rle(e){let[t,n,r,i,a,o,s,c,l]=e,u=t[0]===`-`,d=c&&c[0]===`-`,f=(e,t=!1)=>e!==void 0&&(t||e&&u)?-e:e;return[{years:f(s_(n)),months:f(s_(r)),weeks:f(s_(i)),days:f(s_(a)),hours:f(s_(o)),minutes:f(s_(s)),seconds:f(s_(c),c===`-0`),milliseconds:f(c_(l),d)}]}var zle={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function A_(e,t,n,r,i,a,o){let s={year:t.length===2?h_(o_(t)):o_(t),month:rle.indexOf(n)+1,day:o_(r),hour:o_(i),minute:o_(a)};return o&&(s.second=o_(o)),e&&(s.weekday=e.length>3?ole.indexOf(e)+1:sle.indexOf(e)+1),s}var Ble=/^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/;function Vle(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=A_(t,i,r,n,a,o,s),p;return p=c?zle[c]:l?0:g_(u,d),[f,new Vg(p)]}function Hle(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Ule=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/,Wle=/^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/,Gle=/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/;function Kle(e){let[,t,n,r,i,a,o,s]=e;return[A_(t,i,r,n,a,o,s),Vg.utcInstance]}function qle(e){let[,t,n,r,i,a,o,s]=e;return[A_(t,s,n,r,i,a,o),Vg.utcInstance]}var Jle=x_(Dle,T_),Yle=x_(Ole,T_),Xle=x_(kle,T_),Zle=x_(Ele),Qle=S_(Fle,D_,O_,k_),$le=S_(Ale,D_,O_,k_),eue=S_(jle,D_,O_,k_),tue=S_(D_,O_,k_);function nue(e){return C_(e,[Jle,Qle],[Yle,$le],[Xle,eue],[Zle,tue])}function rue(e){return C_(Hle(e),[Ble,Vle])}function iue(e){return C_(e,[Ule,Kle],[Wle,Kle],[Gle,qle])}function aue(e){return C_(e,[Lle,Rle])}var oue=S_(D_);function sue(e){return C_(e,[Ile,oue])}var cue=x_(Mle,Ple),lue=x_(Nle),uue=S_(D_,O_,k_);function due(e){return C_(e,[cue,Qle],[lue,uue])}var fue=`Invalid Duration`,pue={weeks:{days:7,hours:168,minutes:10080,seconds:10080*60,milliseconds:10080*60*1e3},days:{hours:24,minutes:1440,seconds:1440*60,milliseconds:1440*60*1e3},hours:{minutes:60,seconds:3600,milliseconds:3600*1e3},minutes:{seconds:60,milliseconds:60*1e3},seconds:{milliseconds:1e3}},mue={years:{quarters:4,months:12,weeks:52,days:365,hours:365*24,minutes:365*24*60,seconds:365*24*60*60,milliseconds:365*24*60*60*1e3},quarters:{months:3,weeks:13,days:91,hours:2184,minutes:2184*60,seconds:2184*60*60,milliseconds:2184*60*60*1e3},months:{weeks:4,days:30,hours:720,minutes:720*60,seconds:720*60*60,milliseconds:720*60*60*1e3},...pue},j_=146097/400,M_=146097/4800,hue={years:{quarters:4,months:12,weeks:j_/7,days:j_,hours:j_*24,minutes:j_*24*60,seconds:j_*24*60*60,milliseconds:j_*24*60*60*1e3},quarters:{months:3,weeks:j_/28,days:j_/4,hours:j_*24/4,minutes:j_*24*60/4,seconds:j_*24*60*60/4,milliseconds:j_*24*60*60*1e3/4},months:{weeks:M_/7,days:M_,hours:M_*24,minutes:M_*24*60,seconds:M_*24*60*60,milliseconds:M_*24*60*60*1e3},...pue},N_=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],gue=N_.slice(0).reverse();function P_(e,t,n=!1){return new F_({values:n?t.values:{...e.values,...t.values||{}},loc:e.loc.clone(t.loc),conversionAccuracy:t.conversionAccuracy||e.conversionAccuracy,matrix:t.matrix||e.matrix})}function _ue(e,t){let n=t.milliseconds??0;for(let r of gue.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function vue(e,t){let n=_ue(e,t)<0?-1:1;N_.reduceRight((r,i)=>{if($g(t[i]))return r;if(r){let a=t[r]*n,o=e[i][r],s=Math.floor(a/o);t[i]+=s*n,t[r]-=s*o*n}return i},null),N_.reduce((n,r)=>{if($g(t[r]))return n;if(n){let i=t[n]%1;t[n]-=i,t[r]+=i*e[n][r]}return r},null)}function yue(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var F_=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?hue:mue;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||zg.create(),this.conversionAccuracy=t?`longterm`:`casual`,this.invalid=e.invalid||null,this.matrix=n,this.isLuxonDuration=!0}static fromMillis(t,n){return e.fromObject({milliseconds:t},n)}static fromObject(t,n={}){if(typeof t!=`object`||!t)throw new bg(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:__(t,e.normalizeUnit),loc:zg.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(e_(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new bg(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=aue(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static fromISOTime(t,n){let[r]=sue(t);return r?e.fromObject(r,n):e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the Duration is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new jse(r);return new e({invalid:r})}static normalizeUnit(e){let t={year:`years`,years:`years`,quarter:`quarters`,quarters:`quarters`,month:`months`,months:`months`,week:`weeks`,weeks:`weeks`,day:`days`,days:`days`,hour:`hours`,hours:`hours`,minute:`minutes`,minutes:`minutes`,second:`seconds`,seconds:`seconds`,millisecond:`milliseconds`,milliseconds:`milliseconds`}[e&&e.toLowerCase()];if(!t)throw new Mse(e);return t}static isDuration(e){return e&&e.isLuxonDuration||!1}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}toFormat(e,t={}){let n={...t,floor:t.round!==!1&&t.floor!==!1};return this.isValid?b_.create(this.loc,n).formatDurationFromString(this,e):fue}toHuman(e={}){if(!this.isValid)return fue;let t=e.showZeros!==!1,n=N_.map(n=>{let r=this.values[n];return $g(r)||r===0&&!t?null:this.loc.numberFormatter({style:`unit`,unitDisplay:`long`,...e,unit:n.slice(0,-1)}).format(r)}).filter(e=>e);return this.loc.listFormatter({type:`conjunction`,style:e.listStyle||`narrow`,...e}).format(n)}toObject(){return this.isValid?{...this.values}:{}}toISO(){if(!this.isValid)return null;let e=`P`;return this.years!==0&&(e+=this.years+`Y`),(this.months!==0||this.quarters!==0)&&(e+=this.months+this.quarters*3+`M`),this.weeks!==0&&(e+=this.weeks+`W`),this.days!==0&&(e+=this.days+`D`),(this.hours!==0||this.minutes!==0||this.seconds!==0||this.milliseconds!==0)&&(e+=`T`),this.hours!==0&&(e+=this.hours+`H`),this.minutes!==0&&(e+=this.minutes+`M`),(this.seconds!==0||this.milliseconds!==0)&&(e+=l_(this.seconds+this.milliseconds/1e3,3)+`S`),e===`P`&&(e+=`T0S`),e}toISOTime(e={}){if(!this.isValid)return null;let t=this.toMillis();return t<0||t>=864e5?null:(e={suppressMilliseconds:!1,suppressSeconds:!1,includePrefix:!1,format:`extended`,...e,includeOffset:!1},nv.fromMillis(t,{zone:`UTC`}).toISOTime(e))}toJSON(){return this.toISO()}toString(){return this.toISO()}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Duration { values: ${JSON.stringify(this.values)} }`:`Duration { Invalid, reason: ${this.invalidReason} }`}toMillis(){return this.isValid?_ue(this.matrix,this.values):NaN}valueOf(){return this.toMillis()}plus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t),r={};for(let e of N_)(n_(n.values,e)||n_(this.values,e))&&(r[e]=n.get(e)+this.get(e));return P_(this,{values:r},!0)}minus(t){if(!this.isValid)return this;let n=e.fromDurationLike(t);return this.plus(n.negate())}mapUnits(e){if(!this.isValid)return this;let t={};for(let n of Object.keys(this.values))t[n]=tle(e(this.values[n],n));return P_(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...__(t,e.normalizeUnit)};return P_(this,{values:n})}reconfigure({locale:e,numberingSystem:t,conversionAccuracy:n,matrix:r}={}){let i={loc:this.loc.clone({locale:e,numberingSystem:t}),matrix:r,conversionAccuracy:n};return P_(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return vue(this.matrix,e),P_(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=yue(this.normalize().shiftToAll().toObject());return P_(this,{values:e},!0)}shiftTo(...t){if(!this.isValid||t.length===0)return this;t=t.map(t=>e.normalizeUnit(t));let n={},r={},i=this.toObject(),a;for(let e of N_)if(t.indexOf(e)>=0){a=e;let t=0;for(let n in r)t+=this.matrix[n][e]*r[n],r[n]=0;e_(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else e_(i[e])&&(r[e]=i[e]);for(let e in r)r[e]!==0&&(n[a]+=e===a?r[e]:r[e]/this.matrix[a][e]);return vue(this.matrix,n),P_(this,{values:n},!0)}shiftToAll(){return this.isValid?this.shiftTo(`years`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`):this}negate(){if(!this.isValid)return this;let e={};for(let t of Object.keys(this.values))e[t]=this.values[t]===0?0:-this.values[t];return P_(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=yue(this.values);return P_(this,{values:e},!0)}get years(){return this.isValid?this.values.years||0:NaN}get quarters(){return this.isValid?this.values.quarters||0:NaN}get months(){return this.isValid?this.values.months||0:NaN}get weeks(){return this.isValid?this.values.weeks||0:NaN}get days(){return this.isValid?this.values.days||0:NaN}get hours(){return this.isValid?this.values.hours||0:NaN}get minutes(){return this.isValid?this.values.minutes||0:NaN}get seconds(){return this.isValid?this.values.seconds||0:NaN}get milliseconds(){return this.isValid?this.values.milliseconds||0:NaN}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}equals(e){if(!this.isValid||!e.isValid||!this.loc.equals(e.loc))return!1;function t(e,t){return e===void 0||e===0?t===void 0||t===0:e===t}for(let n of N_)if(!t(this.values[n],e.values[n]))return!1;return!0}},I_=`Invalid Interval`;function bue(e,t){return!e||!e.isValid?L_.invalid(`missing or invalid start`):!t||!t.isValid?L_.invalid(`missing or invalid end`):t<e?L_.invalid(`end before start`,`The end of an interval must be after its start, but you had start=${e.toISO()} and end=${t.toISO()}`):null}var L_=class e{constructor(e){this.s=e.start,this.e=e.end,this.invalid=e.invalid||null,this.isLuxonInterval=!0}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the Interval is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new Ase(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=rv(t),i=rv(n);return bue(r,i)??new e({start:r,end:i})}static after(t,n){let r=F_.fromDurationLike(n),i=rv(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=F_.fromDurationLike(n),i=rv(t);return e.fromDateTimes(i.minus(r),i)}static fromISO(t,n){let[r,i]=(t||``).split(`/`,2);if(r&&i){let t,a;try{t=nv.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=nv.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=F_.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=F_.fromISO(r,n);if(t.isValid)return e.before(o,t)}}return e.invalid(`unparsable`,`the input "${t}" can't be parsed as ISO 8601`)}static isInterval(e){return e&&e.isLuxonInterval||!1}get start(){return this.isValid?this.s:null}get end(){return this.isValid?this.e:null}get lastDateTime(){return this.isValid&&this.e?this.e.minus(1):null}get isValid(){return this.invalidReason===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}length(e=`milliseconds`){return this.isValid?this.toDuration(e).get(e):NaN}count(e=`milliseconds`,t){if(!this.isValid)return NaN;let n=this.start.startOf(e,t),r;return r=t?.useLocaleWeeks?this.end.reconfigure({locale:n.locale}):this.end,r=r.startOf(e,t),Math.floor(r.diff(n,e).get(e))+(r.valueOf()!==this.end.valueOf())}hasSame(e){return this.isValid?this.isEmpty()||this.e.minus(1).hasSame(this.s,e):!1}isEmpty(){return this.s.valueOf()===this.e.valueOf()}isAfter(e){return this.isValid?this.s>e:!1}isBefore(e){return this.isValid?this.e<=e:!1}contains(e){return this.isValid?this.s<=e&&this.e>e:!1}set({start:t,end:n}={}){return this.isValid?e.fromDateTimes(t||this.s,n||this.e):this}splitAt(...t){if(!this.isValid)return[];let n=t.map(rv).filter(e=>this.contains(e)).sort((e,t)=>e.toMillis()-t.toMillis()),r=[],{s:i}=this,a=0;for(;i<this.e;){let t=n[a]||this.e,o=+t>+this.e?this.e:t;r.push(e.fromDateTimes(i,o)),i=o,a+=1}return r}splitBy(t){let n=F_.fromDurationLike(t);if(!this.isValid||!n.isValid||n.as(`milliseconds`)===0)return[];let{s:r}=this,i=1,a,o=[];for(;r<this.e;){let t=this.start.plus(n.mapUnits(e=>e*i));a=+t>+this.e?this.e:t,o.push(e.fromDateTimes(r,a)),r=a,i+=1}return o}divideEqually(e){return this.isValid?this.splitBy(this.length()/e).slice(0,e):[]}overlaps(e){return this.e>e.s&&this.s<e.e}abutsStart(e){return this.isValid?+this.e==+e.s:!1}abutsEnd(e){return this.isValid?+e.e==+this.s:!1}engulfs(e){return this.isValid?this.s<=e.s&&this.e>=e.e:!1}equals(e){return!this.isValid||!e.isValid?!1:this.s.equals(e.s)&&this.e.equals(e.e)}intersection(t){if(!this.isValid)return this;let n=this.s>t.s?this.s:t.s,r=this.e<t.e?this.e:t.e;return n>=r?null:e.fromDateTimes(n,r)}union(t){if(!this.isValid)return this;let n=this.s<t.s?this.s:t.s,r=this.e>t.e?this.e:t.e;return e.fromDateTimes(n,r)}static merge(e){let[t,n]=e.sort((e,t)=>e.s-t.s).reduce(([e,t],n)=>t?t.overlaps(n)||t.abutsStart(n)?[e,t.union(n)]:[e.concat([t]),n]:[e,n],[[],null]);return n&&t.push(n),t}static xor(t){let n=null,r=0,i=[],a=t.map(e=>[{time:e.s,type:`s`},{time:e.e,type:`e`}]),o=Array.prototype.concat(...a).sort((e,t)=>e.time-t.time);for(let t of o)r+=t.type===`s`?1:-1,r===1?n=t.time:(n&&+n!=+t.time&&i.push(e.fromDateTimes(n,t.time)),n=null);return e.merge(i)}difference(...t){return e.xor([this].concat(t)).map(e=>this.intersection(e)).filter(e=>e&&!e.isEmpty())}toString(){return this.isValid?`[${this.s.toISO()} – ${this.e.toISO()})`:I_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`Interval { start: ${this.s.toISO()}, end: ${this.e.toISO()} }`:`Interval { Invalid, reason: ${this.invalidReason} }`}toLocaleString(e=Tg,t={}){return this.isValid?b_.create(this.s.loc.clone(t),e).formatInterval(this):I_}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:I_}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:I_}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:I_}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:I_}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):F_.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},R_=class{static hasDST(e=Kg.defaultZone){let t=nv.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return Ag.isValidZone(e)}static normalizeZone(e){return Hg(e,Kg.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||zg.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zg.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||zg.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zg.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||zg.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return zg.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return zg.create(t,null,`gregory`).eras(e)}static features(){return{relative:qce(),localeWeek:Jce()}}};function xue(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(F_.fromMillis(r).as(`days`))}function Sue(e,t,n){let r=[[`years`,(e,t)=>t.year-e.year],[`quarters`,(e,t)=>t.quarter-e.quarter+(t.year-e.year)*4],[`months`,(e,t)=>t.month-e.month+(t.year-e.year)*12],[`weeks`,(e,t)=>{let n=xue(e,t);return(n-n%7)/7}],[`days`,xue]],i={},a=e,o,s;for(let[c,l]of r)n.indexOf(c)>=0&&(o=c,i[c]=l(e,t),s=a.plus(i),s>t?(i[c]--,e=a.plus(i),e>t&&(s=e,i[c]--,e=a.plus(i))):e=s);return[e,i,s,o]}function Cue(e,t,n,r){let[i,a,o,s]=Sue(e,t,n),c=t-i,l=n.filter(e=>[`hours`,`minutes`,`seconds`,`milliseconds`].indexOf(e)>=0);l.length===0&&(o<t&&(o=i.plus({[s]:1})),o!==i&&(a[s]=(a[s]||0)+c/(o-i)));let u=F_.fromObject(a,r);return l.length>0?F_.fromMillis(c,r).shiftTo(...l).plus(u):u}var wue=`missing Intl.DateTimeFormat.formatToParts support`;function z_(e,t=e=>e){return{regex:e,deser:([e])=>t(wce(e))}}var Tue=`[ \xA0]`,Eue=new RegExp(Tue,`g`);function Due(e){return e.replace(/\./g,`\\.?`).replace(Eue,Tue)}function Oue(e){return e.replace(/\./g,``).replace(Eue,` `).toLowerCase()}function B_(e,t){return e===null?null:{regex:RegExp(e.map(Due).join(`|`)),deser:([n])=>e.findIndex(e=>Oue(n)===Oue(e))+t}}function kue(e,t){return{regex:e,deser:([,e,t])=>g_(e,t),groups:t}}function V_(e){return{regex:e,deser:([e])=>e}}function Aue(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function jue(e,t){let n=Gg(t),r=Gg(t,`{2}`),i=Gg(t,`{3}`),a=Gg(t,`{4}`),o=Gg(t,`{6}`),s=Gg(t,`{1,2}`),c=Gg(t,`{1,3}`),l=Gg(t,`{1,6}`),u=Gg(t,`{1,9}`),d=Gg(t,`{2,4}`),f=Gg(t,`{4,6}`),p=e=>({regex:RegExp(Aue(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return B_(t.eras(`short`),0);case`GG`:return B_(t.eras(`long`),0);case`y`:return z_(l);case`yy`:return z_(d,h_);case`yyyy`:return z_(a);case`yyyyy`:return z_(f);case`yyyyyy`:return z_(o);case`M`:return z_(s);case`MM`:return z_(r);case`MMM`:return B_(t.months(`short`,!0),1);case`MMMM`:return B_(t.months(`long`,!0),1);case`L`:return z_(s);case`LL`:return z_(r);case`LLL`:return B_(t.months(`short`,!1),1);case`LLLL`:return B_(t.months(`long`,!1),1);case`d`:return z_(s);case`dd`:return z_(r);case`o`:return z_(c);case`ooo`:return z_(i);case`HH`:return z_(r);case`H`:return z_(s);case`hh`:return z_(r);case`h`:return z_(s);case`mm`:return z_(r);case`m`:return z_(s);case`q`:return z_(s);case`qq`:return z_(r);case`s`:return z_(s);case`ss`:return z_(r);case`S`:return z_(c);case`SSS`:return z_(i);case`u`:return V_(u);case`uu`:return V_(s);case`uuu`:return z_(n);case`a`:return B_(t.meridiems(),0);case`kkkk`:return z_(a);case`kk`:return z_(d,h_);case`W`:return z_(s);case`WW`:return z_(r);case`E`:case`c`:return z_(n);case`EEE`:return B_(t.weekdays(`short`,!1),1);case`EEEE`:return B_(t.weekdays(`long`,!1),1);case`ccc`:return B_(t.weekdays(`short`,!0),1);case`cccc`:return B_(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return kue(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return kue(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return V_(/[a-z_+-/]{1,256}?/i);case` `:return V_(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:wue};return m.token=e,m}var Mue={year:{"2-digit":`yy`,numeric:`yyyyy`},month:{numeric:`M`,"2-digit":`MM`,short:`MMM`,long:`MMMM`},day:{numeric:`d`,"2-digit":`dd`},weekday:{short:`EEE`,long:`EEEE`},dayperiod:`a`,dayPeriod:`a`,hour12:{numeric:`h`,"2-digit":`hh`},hour24:{numeric:`H`,"2-digit":`HH`},minute:{numeric:`m`,"2-digit":`mm`},second:{numeric:`s`,"2-digit":`ss`},timeZoneName:{long:`ZZZZZ`,short:`ZZZ`}};function Nue(e,t,n){let{type:r,value:i}=e;if(r===`literal`){let e=/^\s+$/.test(i);return{literal:!e,val:e?` `:i}}let a=t[r],o=r;r===`hour`&&(o=t.hour12==null?t.hourCycle==null?n.hour12?`hour12`:`hour24`:t.hourCycle===`h11`||t.hourCycle===`h12`?`hour12`:`hour24`:t.hour12?`hour12`:`hour24`);let s=Mue[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function Pue(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function Fue(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(n_(n,i)){let a=n[i],o=a.groups?a.groups+1:1;!a.literal&&a.token&&(e[a.token.val[0]]=a.deser(r.slice(t,t+o))),t+=o}return[r,e]}else return[r,{}]}function Iue(e){let t=e=>{switch(e){case`S`:return`millisecond`;case`s`:return`second`;case`m`:return`minute`;case`h`:case`H`:return`hour`;case`d`:return`day`;case`o`:return`ordinal`;case`L`:case`M`:return`month`;case`y`:return`year`;case`E`:case`c`:return`weekday`;case`W`:return`weekNumber`;case`k`:return`weekYear`;case`q`:return`quarter`;default:return null}},n=null,r;return $g(e.z)||(n=Ag.create(e.z)),$g(e.Z)||(n||=new Vg(e.Z),r=e.Z),$g(e.q)||(e.M=(e.q-1)*3+1),$g(e.h)||(e.h<12&&e.a===1?e.h+=12:e.h===12&&e.a===0&&(e.h=0)),e.G===0&&e.y&&(e.y=-e.y),$g(e.u)||(e.S=c_(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var Lue=null;function Rue(){return Lue||=nv.fromMillis(1555555555555),Lue}function zue(e,t){if(e.literal)return e;let n=Wue(b_.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function Bue(e,t){return Array.prototype.concat(...e.map(e=>zue(e,t)))}var Vue=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=Bue(b_.parseFormat(t),e),this.units=this.tokens.map(t=>jue(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=Pue(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=Fue(e,this.regex,this.handlers),[r,i,a]=n?Iue(n):[null,null,void 0];if(n_(n,`a`)&&n_(n,`H`))throw new yg(`Can't include meridiem when specifying 24-hour format`);return{input:e,tokens:this.tokens,regex:this.regex,rawMatches:t,matches:n,result:r,zone:i,specificOffset:a}}else return{input:e,tokens:this.tokens,invalidReason:this.invalidReason}}get isValid(){return!this.disqualifyingUnit}get invalidReason(){return this.disqualifyingUnit?this.disqualifyingUnit.invalidReason:null}};function Hue(e,t,n){return new Vue(e,n).explainFromTokens(t)}function Uue(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=Hue(e,t,n);return[r,i,a,o]}function Wue(e,t){if(!e)return null;let n=b_.create(t,e).dtFormatter(Rue()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Nue(t,e,i))}var H_=`Invalid DateTime`,Gue=864e13;function U_(e){return new qg(`unsupported zone`,`the zone "${e.name}" is not supported`)}function W_(e){return e.weekData===null&&(e.weekData=Zg(e.c)),e.weekData}function G_(e){return e.localWeekData===null&&(e.localWeekData=Zg(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function K_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new nv({...n,...t,old:n})}function Kue(e,t,n){let r=e-t*60*1e3,i=n.offset(r);if(t===i)return[r,t];r-=(i-t)*60*1e3;let a=n.offset(r);return i===a?[r,i]:[e-Math.min(i,a)*60*1e3,Math.max(i,a)]}function q_(e,t){e+=t*60*1e3;let n=new Date(e);return{year:n.getUTCFullYear(),month:n.getUTCMonth()+1,day:n.getUTCDate(),hour:n.getUTCHours(),minute:n.getUTCMinutes(),second:n.getUTCSeconds(),millisecond:n.getUTCMilliseconds()}}function J_(e,t,n){return Kue(p_(e),t,n)}function que(e,t){let n=e.o,r=e.c.year+Math.trunc(t.years),i=e.c.month+Math.trunc(t.months)+Math.trunc(t.quarters)*3,a={...e.c,year:r,month:i,day:Math.min(e.c.day,f_(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=F_.fromObject({years:t.years-Math.trunc(t.years),quarters:t.quarters-Math.trunc(t.quarters),months:t.months-Math.trunc(t.months),weeks:t.weeks-Math.trunc(t.weeks),days:t.days-Math.trunc(t.days),hours:t.hours,minutes:t.minutes,seconds:t.seconds,milliseconds:t.milliseconds}).as(`milliseconds`),[s,c]=Kue(p_(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function Y_(e,t,n,r,i,a){let{setZone:o,zone:s}=n;if(e&&Object.keys(e).length!==0||t){let r=t||s,i=nv.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return nv.invalid(new qg(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function X_(e,t,n=!0){return e.isValid?b_.create(zg.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function Z_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=a_(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=a_(e.c.month),n===`month`)return i;i+=`-`}else if(i+=a_(e.c.month),n===`month`)return i;return i+=a_(e.c.day),i}function Jue(e,t,n,r,i,a,o){let s=!n||e.c.millisecond!==0||e.c.second!==0,c=``;switch(o){case`day`:case`month`:case`year`:break;default:if(c+=a_(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=a_(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=a_(e.c.second))}else{if(c+=a_(e.c.minute),o===`minute`)break;s&&(c+=a_(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=a_(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=a_(Math.trunc(-e.o/60)),c+=`:`,c+=a_(Math.trunc(-e.o%60))):(c+=`+`,c+=a_(Math.trunc(e.o/60)),c+=`:`,c+=a_(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var Yue={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},Xue={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},Zue={ordinal:1,hour:0,minute:0,second:0,millisecond:0},Q_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],Que=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],$ue=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function $_(e){let t={year:`year`,years:`year`,month:`month`,months:`month`,day:`day`,days:`day`,hour:`hour`,hours:`hour`,minute:`minute`,minutes:`minute`,quarter:`quarter`,quarters:`quarter`,second:`second`,seconds:`second`,millisecond:`millisecond`,milliseconds:`millisecond`,weekday:`weekday`,weekdays:`weekday`,weeknumber:`weekNumber`,weeksnumber:`weekNumber`,weeknumbers:`weekNumber`,weekyear:`weekYear`,weekyears:`weekYear`,ordinal:`ordinal`}[e.toLowerCase()];if(!t)throw new Mse(e);return t}function ede(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return $_(e)}}function tde(e){if(ev===void 0&&(ev=Kg.now()),e.type!==`iana`)return e.offset(ev);let t=e.name,n=tv.get(t);return n===void 0&&(n=e.offset(ev),tv.set(t,n)),n}function nde(e,t){let n=Hg(t.zone,Kg.defaultZone);if(!n.isValid)return nv.invalid(U_(n));let r=zg.fromObject(t),i,a;if($g(e.year))i=Kg.now();else{for(let t of Q_)$g(e[t])&&(e[t]=Yue[t]);let t=Uce(e)||Wce(e);if(t)return nv.invalid(t);let r=tde(n);[i,a]=J_(e,r,n)}return new nv({ts:i,zone:n,loc:r,o:a})}function rde(e,t,n){let r=$g(n.round)?!0:n.round,i=$g(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=l_(e,r||n.calendary?0:2,n.calendary?`round`:i),t.loc.clone(n).relFormatter(n).format(e,a)),o=r=>n.calendary?t.hasSame(e,r)?0:t.startOf(r).diff(e.startOf(r),r).get(r):t.diff(e,r).get(r);if(n.unit)return a(o(n.unit),n.unit);for(let e of n.units){let t=o(e);if(Math.abs(t)>=1)return a(t,e)}return a(e>t?-0:0,n.units[n.units.length-1])}function ide(e){let t={},n;return e.length>0&&typeof e[e.length-1]==`object`?(t=e[e.length-1],n=Array.from(e).slice(0,e.length-1)):n=Array.from(e),[t,n]}var ev,tv=new Map,nv=class e{constructor(e){let t=e.zone||Kg.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new qg(`invalid input`):null)||(t.isValid?null:U_(t));this.ts=$g(e.ts)?Kg.now():e.ts;let r=null,i=null;if(!n)if(e.old&&e.old.ts===this.ts&&e.old.zone.equals(t))[r,i]=[e.old.c,e.old.o];else{let a=e_(e.o)&&!e.old?e.o:t.offset(this.ts);r=q_(this.ts,a),n=Number.isNaN(r.year)?new qg(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||zg.create(),this.invalid=n,this.weekData=null,this.localWeekData=null,this.c=r,this.o=i,this.isLuxonDateTime=!0}static now(){return new e({})}static local(){let[e,t]=ide(arguments),[n,r,i,a,o,s,c]=t;return nde({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=ide(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Vg.utcInstance,nde({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Kce(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Hg(n.zone,Kg.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:zg.fromObject(n)}):e.invalid(U_(i))}static fromMillis(t,n={}){if(e_(t))return t<-Gue||t>Gue?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Hg(n.zone,Kg.defaultZone),loc:zg.fromObject(n)});throw new bg(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(e_(t))return new e({ts:t*1e3,zone:Hg(n.zone,Kg.defaultZone),loc:zg.fromObject(n)});throw new bg(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Hg(n.zone,Kg.defaultZone);if(!r.isValid)return e.invalid(U_(r));let i=zg.fromObject(n),a=__(t,ede),{minDaysInFirstWeek:o,startOfWeek:s}=Bce(a,i),c=Kg.now(),l=$g(n.specificOffset)?r.offset(c):n.specificOffset,u=!$g(a.ordinal),d=!$g(a.year),f=!$g(a.month)||!$g(a.day),p=d||f,m=a.weekYear||a.weekNumber;if((p||u)&&m)throw new yg(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new yg(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,g,_,ee=q_(c,l);h?(g=Que,_=Xue,ee=Zg(ee,o,s)):u?(g=$ue,_=Zue,ee=Qg(ee)):(g=Q_,_=Yue);let te=!1;for(let e of g){let t=a[e];$g(t)?te?a[e]=_[e]:a[e]=ee[e]:te=!0}let ne=(h?Vce(a,o,s):u?Hce(a):Uce(a))||Wce(a);if(ne)return e.invalid(ne);let[v,re]=J_(h?Rce(a,o,s):u?zce(a):a,l,r),ie=new e({ts:v,zone:r,o:re,loc:i});return a.weekday&&p&&t.weekday!==ie.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ie.toISO()}`):ie.isValid?ie:e.invalid(ie.invalid)}static fromISO(e,t={}){let[n,r]=nue(e);return Y_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=rue(e);return Y_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=iue(e);return Y_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if($g(t)||$g(n))throw new bg(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=Uue(zg.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):Y_(o,s,r,`format ${n}`,t,c)}static fromString(t,n,r={}){return e.fromFormat(t,n,r)}static fromSQL(e,t={}){let[n,r]=due(e);return Y_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new bg(`need to specify a reason the DateTime is invalid`);let r=t instanceof qg?t:new qg(t,n);if(Kg.throwOnInvalid)throw new kse(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=Wue(e,zg.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return Bue(b_.parseFormat(e),zg.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){ev=void 0,tv.clear()}get(e){return this[e]}get isValid(){return this.invalid===null}get invalidReason(){return this.invalid?this.invalid.reason:null}get invalidExplanation(){return this.invalid?this.invalid.explanation:null}get locale(){return this.isValid?this.loc.locale:null}get numberingSystem(){return this.isValid?this.loc.numberingSystem:null}get outputCalendar(){return this.isValid?this.loc.outputCalendar:null}get zone(){return this._zone}get zoneName(){return this.isValid?this.zone.name:null}get year(){return this.isValid?this.c.year:NaN}get quarter(){return this.isValid?Math.ceil(this.c.month/3):NaN}get month(){return this.isValid?this.c.month:NaN}get day(){return this.isValid?this.c.day:NaN}get hour(){return this.isValid?this.c.hour:NaN}get minute(){return this.isValid?this.c.minute:NaN}get second(){return this.isValid?this.c.second:NaN}get millisecond(){return this.isValid?this.c.millisecond:NaN}get weekYear(){return this.isValid?W_(this).weekYear:NaN}get weekNumber(){return this.isValid?W_(this).weekNumber:NaN}get weekday(){return this.isValid?W_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?G_(this).weekday:NaN}get localWeekNumber(){return this.isValid?G_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?G_(this).weekYear:NaN}get ordinal(){return this.isValid?Qg(this.c).ordinal:NaN}get monthShort(){return this.isValid?R_.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?R_.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?R_.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?R_.weekdays(`long`,{locObj:this.loc})[this.weekday-1]:null}get offset(){return this.isValid?+this.o:NaN}get offsetNameShort(){return this.isValid?this.zone.offsetName(this.ts,{format:`short`,locale:this.locale}):null}get offsetNameLong(){return this.isValid?this.zone.offsetName(this.ts,{format:`long`,locale:this.locale}):null}get isOffsetFixed(){return this.isValid?this.zone.isUniversal:null}get isInDST(){return this.isOffsetFixed?!1:this.offset>this.set({month:1,day:1}).offset||this.offset>this.set({month:5}).offset}getPossibleOffsets(){if(!this.isValid||this.isOffsetFixed)return[this];let e=864e5,t=6e4,n=p_(this.c),r=this.zone.offset(n-e),i=this.zone.offset(n+e),a=this.zone.offset(n-r*t),o=this.zone.offset(n-i*t);if(a===o)return[this];let s=n-a*t,c=n-o*t,l=q_(s,a),u=q_(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[K_(this,{ts:s}),K_(this,{ts:c})]:[this]}get isInLeapYear(){return u_(this.year)}get daysInMonth(){return f_(this.year,this.month)}get daysInYear(){return this.isValid?d_(this.year):NaN}get weeksInWeekYear(){return this.isValid?m_(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?m_(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=b_.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Vg.instance(e),t)}toLocal(){return this.setZone(Kg.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Hg(t,Kg.defaultZone),t.equals(this.zone))return this;if(t.isValid){let e=this.ts;if(n||r){let n=t.offset(this.ts),r=this.toObject();[e]=J_(r,n,t)}return K_(this,{ts:e,zone:t})}else return e.invalid(U_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return K_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=__(e,ede),{minDaysInFirstWeek:n,startOfWeek:r}=Bce(t,this.loc),i=!$g(t.weekYear)||!$g(t.weekNumber)||!$g(t.weekday),a=!$g(t.ordinal),o=!$g(t.year),s=!$g(t.month)||!$g(t.day),c=o||s,l=t.weekYear||t.weekNumber;if((c||a)&&l)throw new yg(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new yg(`Can't mix ordinal dates with month/day`);let u;i?u=Rce({...Zg(this.c,n,r),...t},n,r):$g(t.ordinal)?(u={...this.toObject(),...t},$g(t.day)&&(u.day=Math.min(f_(u.year,u.month),u.day))):u=zce({...Qg(this.c),...t});let[d,f]=J_(u,this.o,this.zone);return K_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=F_.fromDurationLike(e);return K_(this,que(this,t))}minus(e){if(!this.isValid)return this;let t=F_.fromDurationLike(e).negate();return K_(this,que(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=F_.normalizeUnit(e);switch(r){case`years`:n.month=1;case`quarters`:case`months`:n.day=1;case`weeks`:case`days`:n.hour=0;case`hours`:n.minute=0;case`minutes`:n.second=0;case`seconds`:n.millisecond=0;break}if(r===`weeks`)if(t){let e=this.loc.getStartOfWeek(),{weekday:t}=this;t<e&&(n.weekNumber=this.weekNumber-1),n.weekday=e}else n.weekday=1;return r===`quarters`&&(n.month=(Math.ceil(this.month/3)-1)*3+1),this.set(n)}endOf(e,t){return this.isValid?this.plus({[e]:1}).startOf(e,t).minus(1):this}toFormat(e,t={}){return this.isValid?b_.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):H_}toLocaleString(e=Tg,t={}){return this.isValid?b_.create(this.loc.clone(t),e).formatDateTime(this):H_}toLocaleParts(e={}){return this.isValid?b_.create(this.loc.clone(e),e).formatDateTimeParts(this):[]}toISO({format:e=`extended`,suppressSeconds:t=!1,suppressMilliseconds:n=!1,includeOffset:r=!0,extendedZone:i=!1,precision:a=`milliseconds`}={}){if(!this.isValid)return null;a=$_(a);let o=e===`extended`,s=Z_(this,o,a);return Q_.indexOf(a)>=3&&(s+=`T`),s+=Jue(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?Z_(this,e===`extended`,$_(t)):null}toISOWeekDate(){return X_(this,`kkkk-'W'WW-c`)}toISOTime({suppressMilliseconds:e=!1,suppressSeconds:t=!1,includeOffset:n=!0,includePrefix:r=!1,extendedZone:i=!1,format:a=`extended`,precision:o=`milliseconds`}={}){return this.isValid?(o=$_(o),(r&&Q_.indexOf(o)>=3?`T`:``)+Jue(this,a===`extended`,t,e,n,i,o)):null}toRFC2822(){return X_(this,`EEE, dd LLL yyyy HH:mm:ss ZZZ`,!1)}toHTTP(){return X_(this.toUTC(),`EEE, dd LLL yyyy HH:mm:ss 'GMT'`)}toSQLDate(){return this.isValid?Z_(this,!0):null}toSQLTime({includeOffset:e=!0,includeZone:t=!1,includeOffsetSpace:n=!0}={}){let r=`HH:mm:ss.SSS`;return(t||e)&&(n&&(r+=` `),t?r+=`z`:e&&(r+=`ZZ`)),X_(this,r,!0)}toSQL(e={}){return this.isValid?`${this.toSQLDate()} ${this.toSQLTime(e)}`:null}toString(){return this.isValid?this.toISO():H_}[Symbol.for(`nodejs.util.inspect.custom`)](){return this.isValid?`DateTime { ts: ${this.toISO()}, zone: ${this.zone.name}, locale: ${this.locale} }`:`DateTime { Invalid, reason: ${this.invalidReason} }`}valueOf(){return this.toMillis()}toMillis(){return this.isValid?this.ts:NaN}toSeconds(){return this.isValid?this.ts/1e3:NaN}toUnixInteger(){return this.isValid?Math.floor(this.ts/1e3):NaN}toJSON(){return this.toISO()}toBSON(){return this.toJSDate()}toObject(e={}){if(!this.isValid)return{};let t={...this.c};return e.includeConfig&&(t.outputCalendar=this.outputCalendar,t.numberingSystem=this.loc.numberingSystem,t.locale=this.loc.locale),t}toJSDate(){return new Date(this.isValid?this.ts:NaN)}diff(e,t=`milliseconds`,n={}){if(!this.isValid||!e.isValid)return F_.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Yce(t).map(F_.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Cue(a?this:e,a?e:this,i,r);return a?o.negate():o}diffNow(t=`milliseconds`,n={}){return this.diff(e.now(),t,n)}until(e){return this.isValid?L_.fromDateTimes(this,e):this}hasSame(e,t,n){if(!this.isValid)return!1;let r=e.valueOf(),i=this.setZone(e.zone,{keepLocalTime:!0});return i.startOf(t,n)<=r&&r<=i.endOf(t,n)}equals(e){return this.isValid&&e.isValid&&this.valueOf()===e.valueOf()&&this.zone.equals(e.zone)&&this.loc.equals(e.loc)}toRelative(t={}){if(!this.isValid)return null;let n=t.base||e.fromObject({},{zone:this.zone}),r=t.padding?this<n?-t.padding:t.padding:0,i=[`years`,`months`,`days`,`hours`,`minutes`,`seconds`],a=t.unit;return Array.isArray(t.unit)&&(i=t.unit,a=void 0),rde(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?rde(t.base||e.fromObject({},{zone:this.zone}),this,{...t,numeric:`auto`,units:[`years`,`months`,`days`],calendary:!0}):null}static min(...t){if(!t.every(e.isDateTime))throw new bg(`min requires all arguments be DateTimes`);return Xce(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new bg(`max requires all arguments be DateTimes`);return Xce(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return Hue(zg.fromOpts({locale:r,numberingSystem:i,defaultToEN:!0}),e,t)}static fromStringExplain(t,n,r={}){return e.fromFormatExplain(t,n,r)}static buildFormatParser(e,t={}){let{locale:n=null,numberingSystem:r=null}=t;return new Vue(zg.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if($g(t)||$g(n))throw new bg(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=zg.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new bg(`fromFormatParser called with a locale of ${o}, but the format parser was created for ${n.locale}`);let{result:s,zone:c,specificOffset:l,invalidReason:u}=n.explainFromTokens(t);return u?e.invalid(u):Y_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Tg}static get DATE_MED(){return Nse}static get DATE_MED_WITH_WEEKDAY(){return Pse}static get DATE_FULL(){return Fse}static get DATE_HUGE(){return Ise}static get TIME_SIMPLE(){return Lse}static get TIME_WITH_SECONDS(){return Rse}static get TIME_WITH_SHORT_OFFSET(){return zse}static get TIME_WITH_LONG_OFFSET(){return Bse}static get TIME_24_SIMPLE(){return Vse}static get TIME_24_WITH_SECONDS(){return Hse}static get TIME_24_WITH_SHORT_OFFSET(){return Use}static get TIME_24_WITH_LONG_OFFSET(){return Wse}static get DATETIME_SHORT(){return Gse}static get DATETIME_SHORT_WITH_SECONDS(){return Kse}static get DATETIME_MED(){return qse}static get DATETIME_MED_WITH_SECONDS(){return Jse}static get DATETIME_MED_WITH_WEEKDAY(){return Yse}static get DATETIME_FULL(){return Xse}static get DATETIME_FULL_WITH_SECONDS(){return Zse}static get DATETIME_HUGE(){return Qse}static get DATETIME_HUGE_WITH_SECONDS(){return $se}};function rv(e){if(nv.isDateTime(e))return e;if(e&&e.valueOf&&e_(e.valueOf()))return nv.fromJSDate(e);if(e&&typeof e==`object`)return nv.fromObject(e);throw new bg(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function ade(e){return Nm(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof Wh}function ode(e){return Zm(e)===``}function iv(e){let t=Qm(e);if(t!==null)return t;if(Em(e)&&e instanceof kh&&e.expression){let t=e.op?.value,n=Qm(e.expression);if(n!==null)return t===`-`?-n:n}return null}function av(e){if(e==null)return null;if(typeof e==`number`)return e;if(typeof e==`string`){let t=Number(e);return isNaN(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=iv(e);if(t!==null)return t;let n=Zm(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function sde(e){if(e==null)return null;if(typeof e==`number`)return Number.isInteger(e)?e:null;if(typeof e==`string`){let t=Number(e);return isNaN(t)||!Number.isInteger(t)?null:t}if(typeof e==`boolean`)return e?1:0;let t=iv(e);if(t!==null)return Number.isInteger(t)?t:null;let n=Zm(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}var cde=[`true`,`yes`,`y`,`t`,`1`],lde=[`false`,`no`,`n`,`f`,`0`];function ov(e){if(e==null)return null;if(typeof e==`boolean`)return e;if(typeof e==`number`)return e===0?!1:e===1?!0:null;if(typeof e==`string`){let t=e.toLowerCase();return cde.includes(t)?!0:lde.includes(t)?!1:null}if(Nm(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=Qm(e);if(t===0)return!1;if(t===1)return!0;let n=Zm(e)?.toLowerCase();if(n){if(cde.includes(n))return!0;if(lde.includes(n))return!1}return null}function ude(e){if(e==null)return null;if(typeof e==`string`)return e;let t=Jm(e);return t?qp(t):Zm(e)??null}function sv(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=Zm(e)??null??av(e)??ov(e);return t===null?null:t.toString()}var dde=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],fde=[`yyyy-MM-dd HH:mm:ss`,`yyyy-MM-dd HH:mm:ss.SSS`,`yyyy-MM-dd HH:mm:ss.SSSZZ`,`yyyy-MM-dd HH:mm:ssZZ`],pde=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function cv(e){if(e==null)return null;let t=typeof e==`string`?e:Zm(e)??null;if(t===null)return null;for(let e of pde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of dde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of fde){let n=nv.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=nv.fromISO(t,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)});return null;function r(e){return e.zone.type!==`system`}}function mde(e,t){let n=e.type(t),r=e.default(t);return{name:e.name??``,pk:e.pk(t),unique:e.unique(t),increment:e.increment(t),notNull:e.nullable(t)===!1,dbdefault:r,typeName:n?.name??``}}function lv(e){return e.values.map(t=>{let n={};return e.columns.forEach((e,r)=>{n[e]=t[r]}),n})}function uv(e,t,n){return t.map((t,r)=>{let i=e[t]?.value;if(i==null&&n&&n[r]){let e=n[r];if(e?.dbdefault)return JSON.stringify(e.dbdefault.value)}return JSON.stringify(i)}).join(`|`)}function hde(e,t,n){return t.some((t,r)=>{let i=e[t]?.value;return i==null&&n&&n[r]&&n[r]?.dbdefault?!1:i==null})}function gde(e){return e.increment||_g(e.typeName)}function _de(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function dv(e,t,n){return n.length===1?_de(e,t,n[0]):`(${n.map(n=>_de(e,t,n)).join(`, `)})`}function vde(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function fv(e,t,n){let{token:r}=t,i=e.nodeAtPosition(r.filepath,r.start.offset)??e.parse.ast(r.filepath);return new hm(M.INVALID_RECORDS_FIELD,n,i)}var yde=e=>e>1?`Composite PK`:`PK`;function bde(e,t,n,r){if(Xp(r.values))return[];let i=t.mergedColumns(e).map(t=>mde(t,e)),a=Hae(i,`name`),o=lv(r),s=Tde(t,i,e),c=new Set(r.columns);return Jp(s,i=>xde(e,t,n,i,o,c,a,r))}function xde(e,t,n,r,i,a,o,s){let c=t.schema(e),l=t.name??``,u=wde(n,r,a,o,c,l,s);if(!Xp(u))return u;let d=Ore(r.map(e=>o[e])),f=d.every(e=>e&&gde(e)),[p,m]=Zp(i,e=>hde(e,r,d)),h=f?[]:Sde(e,p,r,c,l),g=Cde(e,m,r,d,c,l);return[...h,...g]}function Sde(e,t,n,r,i){if(Xp(t))return[];let a=`NULL in ${yde(n.length)}: ${dv(r,i,n)} cannot be NULL`;return Jp(t,t=>n.map(n=>fv(e,t[n],a)))}function Cde(e,t,n,r,i,a){return Jp(Cae(Lae(t,e=>uv(e,n,r)),e=>e.length>1),t=>{let r=yde(n.length),o=dv(i,a,n);return Jp(t,t=>{let i=`Duplicate ${r}: ${o} = ${vde(t,n)}`;return n.map(n=>fv(e,t[n],i))})})}function wde(e,t,n,r,i,a,o){let s=gae(t,Array.from(n));if(Xp(s))return[];let c=s.filter(e=>{let t=r[e];return!!(t&&!gde(t)&&!t.dbdefault)});if(Xp(c))return[];let l=`${yde(c.length)}: Column ${dv(i,a,c)} is missing from record and has no default value`;return o.values.map(()=>new hm(M.INVALID_RECORDS_FIELD,l,e))}function Tde(e,t,n){return[...t.filter(e=>e.pk).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value)):[]})]}var Ede=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function Dde(e,t,n){if(Xp(n.values))return[];let r=t.mergedColumns(e).map(t=>mde(t,e)),i=Hae(r,`name`),a=lv(n),o=t.schema(e),s=t.name??``;return Jp(Ode(t,r,e),t=>kde(e,a,t,Ore(t.map(e=>i[e])),o,s))}function Ode(e,t,n){return[...t.filter(e=>e.unique).map(e=>[e.name]),...e.mergedIndexes(n).flatMap(e=>{let t=n.interpretMetadata(e,e.declaration.filepath).getValue();return Array.isArray(t)?t.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value)):[]})]}function kde(e,t,n,r,i,a){return Jp(Cae(Lae(t.filter(e=>!hde(e,n,r)),e=>uv(e,n,r)),e=>e.length>1),t=>{let r=Ede(n.length),o=dv(i,a,n);return Jp(t,t=>{let i=`Duplicate ${r}: ${o} = ${vde(t,n)}`;return n.map(n=>fv(e,t[n],i))})})}function Ade(e,t,n,r){return Jp(t,t=>Mde(e,t,n,r))}function pv(e,t,n,r,i,a){if(!t.record||Xp(t.record.values))return[];let o=lv(t.record),s=n.record?lv(n.record):[],c=new Set(s.map(e=>uv(e,i.fieldNames))),l=o.filter(e=>!hde(e,r.fieldNames)).filter(e=>{let t=uv(e,r.fieldNames);return!c.has(t)}),u=t.tableSymbol.interpretedName(e,a),d=n.tableSymbol.interpretedName(e,a);return Jp(l,t=>{let n=dv(u.schema,u.name,r.fieldNames),a=dv(d.schema,d.name,i.fieldNames),o=`FK violation: ${n} = ${vde(t,r.fieldNames)} does not exist in ${a}`;return r.fieldNames.map(n=>fv(e,t[n],o))})}function jde(e,t,n,r){let i=t.schemaName===`public`?null:t.schemaName;for(let a of e.values()){let{name:e,schema:o}=a.tableSymbol.interpretedName(n,r);if(e===t.tableName&&o===i)return a}}function Mde(e,t,n,r){if(!t.endpoints)return[];let[i,a]=t.endpoints,o=jde(n,i,e,r),s=jde(n,a,e,r);return!o||!s?[]:Nde(e,o,s,i,a,r)}function Nde(e,t,n,r,i,a){let o=r.relation,s=i.relation;return o===`1`&&s===`1`||o===`*`&&s===`*`?[...pv(e,t,n,r,i,a),...pv(e,n,t,i,r,a)]:o===`*`&&s===`1`?pv(e,t,n,r,i,a):o===`1`&&s===`*`?pv(e,n,t,i,r,a):[]}var Pde=class{constructor(e,t,n){this.errors=[],this.warnings=[],this.compiler=e,this.programSymbol=t,this.programNode=t.declaration,this.filepath=n,this.db={schemas:[],tables:[],notes:[],refs:[],enums:[],tableGroups:[],aliases:[],tablePartials:[],records:[],diagramViews:[],token:ih(this.programNode),externals:{tables:[],enums:[],tableGroups:[],tablePartials:[],notes:[]}}}interpret(){return this.interpretAllSymbols(),this.interpretAllMetadata(),this.interpretAllAliases(),this.warnings.push(...this.validateRecords()),new k(this.db,this.errors,this.warnings)}interpretAllSymbols(){for(let e of this.programSymbol.declaration.declarations){let t=this.compiler.nodeSymbol(e).getFiltered(gd);if(!t||t instanceof vh)continue;let n=this.compiler.interpretSymbol(t,this.filepath);if(n.hasValue(gd))continue;this.errors.push(...n.getErrors()),this.warnings.push(...n.getWarnings());let r=n.getValue();r&&this.pushElement(t,r)}let e=new Set,t=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let n of t){if(!(n instanceof dh))continue;let t=this.compiler.symbolMembers(n).getFiltered(gd)??[];for(let n of t){if(!(n instanceof vh))continue;let t=n.originalSymbol.intern();e.has(t)||(e.add(t),this.interpretUseSymbol(n))}}}interpretUseSymbol(e){let t=e.originalSymbol,n=this.compiler.interpretSymbol(t,this.filepath);if(!n.hasValue(gd)){this.errors.push(...n.getErrors()),this.warnings.push(...n.getWarnings());let t=n.getValue();t&&this.pushElement(e,t)}let r=t instanceof ph?t.interpretedName(this.compiler,t.filepath):{name:t.name??``,schema:null},i=t instanceof ph?t.interpretedName(this.compiler,this.filepath):{name:e.name??t.name??``,schema:null},a={name:r.name,schemaName:r.schema,filepath:t.filepath,visibleNames:[{schemaName:i.schema,name:i.name}]};bse(this.db,e,a)}interpretAllMetadata(){let e=this.compiler.symbolMetadata(this.programSymbol)??[],t=new Set,n=new Map;for(let t of e){if(!(t instanceof Zh))continue;let e=t.table(this.compiler);if(!e)continue;let r=e.originalSymbol.intern(),i=n.get(r);i?i.count++:n.set(r,{count:1,tableName:e.name??``})}for(let r of e){let e=this.compiler.interpretMetadata(r,this.filepath);if(e.hasValue(gd))continue;this.errors.push(...e.getErrors()),this.warnings.push(...e.getWarnings());let i=e.getValue();if(i!==void 0)switch(r.kind){case qh.Ref:{let e=i,[n,a]=e.endpoints??[];if(n&&a){let e=[n.schemaName,n.tableName,n.fieldNames.join(`,`),a.schemaName,a.tableName,a.fieldNames.join(`,`)].join(`|`),i=[a.schemaName,a.tableName,a.fieldNames.join(`,`),n.schemaName,n.tableName,n.fieldNames.join(`,`)].join(`|`);if(t.has(e)||t.has(i)){this.errors.push(new N(M.SAME_ENDPOINT,`Ref with same endpoints already exists`,r.declaration));break}t.add(e)}this.db.refs.push(e);break}case qh.Records:if(r instanceof Zh){let e=r.table(this.compiler)?.originalSymbol.intern()??``,t=e?n.get(e):void 0;if(t&&t.count>1){this.errors.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${t.tableName}' - A Table can only have one Records block`,r.declaration));break}}this.db.records.push(i);break;case qh.Project:this.db.project=i;break;default:break}}}interpretAllAliases(){let e=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let t of e){if(!(t instanceof _h)||!t.isKind(P.Table))continue;let{name:e,schema:n}=t.originalSymbol.interpretedName(this.compiler,this.filepath),r={name:t.name,kind:ase.Table,value:{tableName:e,schemaName:n}};this.db.aliases.push(r)}}validateRecords(){let e=[],t=new Map,n=this.compiler.symbolMembers(this.programSymbol).getFiltered(gd)??[];for(let e of n){if(!(e instanceof dh))continue;let n=this.compiler.symbolMembers(e).getFiltered(gd)??[];for(let e of n){if(!e.isKind(P.Table))continue;let n=e.originalSymbol;if(!(n instanceof ph))continue;let r=n.intern();t.has(r)||t.set(r,{tableSymbol:n,record:void 0,recordBlock:n.declaration})}}let r=this.compiler.symbolMetadata(this.programSymbol);for(let n of r){if(!(n instanceof Zh))continue;let r=n.table(this.compiler);if(!(r instanceof ph))continue;let i=this.compiler.interpretMetadata(n,this.filepath);if(i.hasValue(gd))continue;let a=i.getValue();if(!a)continue;e.push(...bde(this.compiler,r,n.declaration,a)),e.push(...Dde(this.compiler,r,a));let o=r.originalSymbol.intern(),s=t.get(o);s?s.record=a:t.set(o,{tableSymbol:r,record:a,recordBlock:n.declaration})}let i=this.collectPartialRefs(t);return e.push(...Ade(this.compiler,[...this.db.refs,...i],t,this.filepath)),e}collectPartialRefs(e){let t=this.compiler.symbolMetadata(this.programSymbol).filter(e=>e instanceof Xh),n=[];for(let{tableSymbol:r}of e.values())for(let e of r.resolvedPartials(this.compiler))for(let i of t){if(i.leftTablePartial(this.compiler)?.originalSymbol!==e.originalSymbol)continue;let t=i.leftColumns(this.compiler),a=i.rightTable(this.compiler),o=i.rightColumns(this.compiler),s=i.op(this.compiler);if(!a||!s||t.length===0||o.length===0)continue;let c=r.mergedColumns(this.compiler);if(!t.some(e=>c.some(t=>t instanceof yh&&t.declaration===e.declaration)))continue;let l=tse(s);if(!l)continue;let u=a instanceof hh&&a.originalSymbol===e.originalSymbol?r:a,d=r.interpretedName(this.compiler,this.filepath),f=u.interpretedName(this.compiler,this.filepath),p={schemaName:d.schema,tableName:d.name,fieldNames:t.map(e=>e.name??``),relation:l[0],token:ih(i.leftToken())},m={schemaName:f.schema,tableName:f.name,fieldNames:o.map(e=>e.name??``),relation:l[1],token:ih(i.rightToken())};n.push({token:ih(i.declaration),endpoints:[p,m]})}return n}pushElement(e,t){if(!Array.isArray(t))switch(e.kind){case P.Table:this.db.tables.push(t);break;case P.Enum:this.db.enums.push(t);break;case P.TableGroup:this.db.tableGroups.push(t);break;case P.TablePartial:this.db.tablePartials.push(t);break;case P.StickyNote:this.db.notes.push(t);break;case P.DiagramView:this.db.diagramViews.push(t);break;default:break}}},Fde={nodeSymbol(e,t){return Rm(t)?k.create(e.symbolFactory.create(gh,{declaration:t,name:t.filepath.absolute},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Program))return k.create(hd);if(!(t.declaration instanceof Sh))return k.create([]);let n=new Map;for(let r of e.reachableFiles(t.filepath)){let{schemaMembers:t}=e.usableMembers(r).getValue();for(let e of t)n.has(e.name)||n.set(e.name,e)}let r=n.get(pm);if(!r)return k.create([...n.values()]);let i=e.symbolMembers(r).getFiltered(gd)?.filter(e=>!e.isKind(P.Schema));return i?k.create([...n.values(),...i]):k.create([...n.values()])},bindNode(e,t){return Rm(t)?new vse(t,e).resolve():k.create(hd)},interpretSymbol(e,t,n){return t instanceof gh?t.declaration instanceof Sh?ese(e,t.declaration)?new Pde(e,t,n).interpret():k.create(void 0,[...e.validateNode(t.declaration).getErrors(),...e.bindNode(t.declaration).getErrors()]):k.create(void 0):k.create(hd)}},Ide=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof Nh)return[];let t=e.body.filter(e=>e instanceof Eh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Lde=class{constructor(e,t,n){this.declarationNode=t,this.compiler=e,this.filepath=n,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){this.project.token=ih(this.declarationNode);let e=[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)];return new k(this.project,e)}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=oh(e);return this.project.name=t,[]}interpretSubElement(e){let t=this.compiler.nodeSymbol(e).getFiltered(gd);if(t){let e=this.compiler.interpretSymbol(t,this.filepath);if(!e.hasValue(gd))return e}return k.create(void 0)}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case _d.Table:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tables?.push(e.getValue()),e.getErrors()}case _d.TableGroup:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tableGroups?.push(e.getValue()),e.getErrors()}case _d.Enum:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.enums?.push(e.getValue()),e.getErrors()}case _d.Note:{let e=t.body instanceof Ph?t.body.body[0]?.callee:t.body?.callee,n=e?Zm(e):void 0;return n&&(this.project.note={value:ah(n),token:ih(t)}),[]}case _d.TablePartial:{let e=this.interpretSubElement(t);return e.getValue()&&this.project.tablePartials?.push(e.getValue()),e.getErrors()}default:return this.project[t.type.value.toLowerCase()]=Zm(t.body.callee),[]}})}},Rde={nodeMetadata(e,t){return Im(t,_d.Project)?k.create(new qoe(t)):k.create(hd)},bindNode(e,t){return Im(t,_d.Project)?k.create(void 0,new Ide(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return!(t instanceof qoe)||!(t.declaration instanceof Eh)?k.create(hd):new Lde(e,t.declaration,n).interpret()}},zde=class{constructor(e,t){this.compiler=e,this.declarationNode=t,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof Ph&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof Sh?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=$m(e);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=this.compiler.nodeReferee(n).getErrors();if(i.length>0)return i;let a=this.compiler.nodeReferee(n).getFiltered(gd);if(!a)return[];let o=Aoe(a.declaration)??`<invalid name>`,s=r.flatMap(e=>this.compiler.nodeReferee(e).getErrors());for(let e of t.args){let t=th(e)??`<unnamed>`,n=this.compiler.nodeReferee(e).getFiltered(gd);if(!n){s.push(new N(M.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}let r=this.boundColumns.get(n);r&&(s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,r)),s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,e))),this.boundColumns.set(n,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof Eh)||!t.isKind(_d.Table)||!this.compiler.nodeSymbol(t).getFiltered(gd)||!Om(e))return[];let n=Aoe(t)??`<invalid name>`,r=[];for(let t of e.elementList){let e=th(t)??`<unnamed>`;if(!this.compiler.nodeReferee(t).getFiltered(gd)){r.push(new N(M.BINDING_ERROR,`Column '${e}' does not exist in Table '${n}'`,t));continue}}return r}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof Nh),n=e.body.filter(e=>e instanceof Eh);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Lh?e.callee.elementList:[e.callee]).flatMap(ig).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();return!t||!n?[]:[...e.variables.flatMap(e=>this.compiler.nodeReferee(e).getErrors()),...n?this.compiler.nodeReferee(n).getErrors():[],...this.compiler.nodeReferee(t).getErrors()]}):[]}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Bde=class{constructor(e,t,n){this.compiler=e,this.metadata=t,this.element=t.declaration,this.filepath=n}interpret(){let e=[],t=[],n=Vde(this.element,this.compiler,this.filepath);if(!n||n.columns.length===0)return new k(void 0,e);let r=[];for(let i of this.element.body.body){let a=Hde(i,n.columns,this.compiler);e.push(...a.getErrors()),t.push(...a.getWarnings());let o=a.getValue();o.row&&r.push(o.row)}let i=ih(this.element);return new k({schemaName:n.schemaName,tableName:n.tableName,columns:n.columns.map(e=>e.name??``),values:r,token:i},e,t)}};function Vde(e,t,n){let r=e.name,i=e.parent;if(i instanceof Eh&&i.isKind(_d.Table)){let e=t.nodeSymbol(i).getFiltered(gd);if(!(e instanceof ph))return;let a=e.mergedColumns(t),o=e.interpretedName(t,n),s=o.schema,c=o.name;return r?{schemaName:s,tableName:c,columns:r.elementList.flatMap(e=>a.find(t=>t.name===eh(e))||[])}:{schemaName:s,tableName:c,columns:a}}let a=$m(r);if(!a)return;let o=a.variables.map(e=>e.expression.variable?.value??``),s=o.at(-1)??``,c=o.length>1?o.slice(0,-1).join(`.`):void 0,l=t.parseFile(e.filepath).getValue().ast,u=t.nodeSymbol(l).getFiltered(gd);if(!u)return;let d;if(c){let e=t.lookupMembers(u,P.Schema,c);e&&(d=t.lookupMembers(e,P.Table,s))}if(d||=t.lookupMembers(u,P.Table,s),!d)return;let f=d.originalSymbol;if(!(f instanceof ph))return;let p=f.mergedColumns(t),m=a.args.map(e=>p.find(t=>t.name===eh(e))).filter(Boolean),h=f.interpretedName(t,n);return{schemaName:h.schema,tableName:h.name,columns:m}}function Hde(e,t,n){let r=[],i=[],a={},o=e.callee instanceof Lh?e.callee.elementList:[e.callee];if(o.length!==t.length)return r.push(new N(M.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${o.length}`,e)),new k({row:null,columnNodes:{}},r,i);let s=[];for(let e=0;e<t.length;e++){let c=o[e],l=t[e];a[l.name??``]=c;let u=Wde(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();s.push(d??{value:null,type:`expression`,token:ih(c)})}return new k({row:s,columnNodes:a},r,i)}function Ude(e){return e instanceof Mh&&e.value?.value||``}function Wde(e,t,n){let r=ih(e),i=t.type(n),a=(i?.name??``).split(`(`)[0],o=!!i?.enumSymbol,s=t.increment(n),c=t.nullable(n)===!1,l=t.default(n),u=t.name??``,d=Ose(a,o),f=sv(e),p=f===null?Ude(e):f,m=f===null?`expression`:d;if(e instanceof Mh)return new k({value:e.value?.value||``,type:`expression`,token:r},[],[]);if(ade(e)||ode(e)&&!mg(a)){let t=l&&l.value.toString().toLowerCase()!==`null`,n=_g(a);return c&&!t&&!s&&!n?new k({value:null,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${u}' without default and increment`,e)]):new k({value:null,type:d,token:r},[],[])}if(o){let i=t.type(n)?.enumSymbol,a=i?i.members(n).filter(e=>e.isKind(P.EnumField)).map(e=>e.name).filter(Boolean):[],o=Zm(e);return o===void 0&&(o=jm(e)?e.expression.variable.value:void 0),a.includes(o)?new k({value:o,type:d,token:r},[],[]):new k({value:o,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid enum value for column '${u}'`,e)])}if(ug(a)||dg(a)||_g(a)){let t=iv(e);if(t===null)return new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${u}'`,e)]);if(ug(a)&&!Number.isInteger(t))return new k({value:Math.floor(t),type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid integer value ${t} for column '${u}': expected integer, got decimal`,e)]);let n=dg(a)&&i?.args?.length?{precision:Number(i.args[0]),scale:i.args.length>=2?Number(i.args[1]):0}:void 0;if(dg(a)&&n){let{precision:i,scale:a}=n,o=t.toString().split(`.`),s=o[0].replace(/^-/,``),c=o[1]||``,l=s.length+c.length,f=c.length;if(l>i)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${u}' exceeds precision: expected at most ${i} total digits, got ${l}`,e)]);if(f>a)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Numeric value ${t} for column '${u}' exceeds scale: expected at most ${a} decimal digits, got ${f}`,e)])}return new k({value:t,type:d,token:r},[],[])}if(pg(a)){let t=ov(e);return t===null?new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${u}'`,e)]):new k({value:t,type:d,token:r},[],[])}if(gg(a)){let t=cv(e);return t===null?new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${u}', expected valid datetime format (e.g., 'YYYY-MM-DD', 'HH:MM:SS', 'YYYY-MM-DD HH:MM:SS', 'MM/DD/YYYY', 'D MMM YYYY', or 'MMM D, YYYY')`,e)]):new k({value:t,type:d,token:r},[],[])}if(mg(a)){let t=sv(e);if(t===null)return new k({value:p,type:m,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`Invalid string value for column '${u}'`,e)]);let n=i?.args?.length?Number(i.args[0]):void 0;if(n&&!Number.isNaN(n)){let i=n,a=new TextEncoder().encode(t).length;if(a>i)return new k({value:t,type:d,token:r},[],[new hm(M.INVALID_RECORDS_FIELD,`String value for column '${u}' exceeds maximum length: expected at most ${i} bytes (UTF-8), got ${a} bytes`,e)])}return new k({value:t,type:`string`,token:r},[],[])}return new k({value:p,type:m,token:r},[],[])}var Gde={nodeMetadata(e,t){if(!Im(t,_d.Records))return k.create(hd);let n=t.parent;if(n&&Im(n,_d.Table))return k.create(new Zh(t));let r=t.name;return r instanceof zh&&r.callee?k.create(new Zh(t)):k.create(hd)},nodeReferee(e,t){if(!jm(t))return k.create(hd);let n=t.parentOfKind(Eh);if(!n?.isKind(_d.Records))return k.create(hd);let r=e.parseFile(t.filepath).getValue().ast,i=e.nodeSymbol(r).getFiltered(gd);if(!i)return k.create(void 0);let a=t.parentOfKind(Ih);if(a?.parentNode===n)return Kde(e,n,t);let o=t.parentOfKind(zh);return o?.parentNode===n&&a?.parentNode===o?qde(e,o,t):o?.parentNode===n&&o.callee?.containsEq(t)?Jde(e,i,t):Xde(e,i,t)},bindNode(e,t){return Im(t,_d.Records)?k.create(void 0,new zde(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return t instanceof Zh?t.declaration instanceof Eh?new Bde(e,t,n).interpret():k.create(void 0):k.create(hd)}};function Kde(e,t,n){let r=t.parent;if(r instanceof Eh&&r.isKind(_d.Table)){let t=e.nodeSymbol(r).getFiltered(gd);if(t)return Yde(e,t,n)}return new k(void 0)}function qde(e,t,n){if(t.callee){let r;if(jm(t.callee))r=e.nodeReferee(t.callee).getFiltered(gd);else{let n=qm(t.callee);if(n&&n.length>0){let t=n[n.length-1];r=e.nodeReferee(t).getFiltered(gd)}}if(r)return Yde(e,r,n)}return new k(void 0)}function Jde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let i=e.lookupMembers(t,[P.Table,P.Schema],r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table '${r}' does not exist in Schema 'public'`,n)])}let i=ag(e,n);if(!i){let i=e.lookupMembers(t,[P.Table,P.Schema],r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table or schema '${r}' does not exist`,n)])}return new k(void 0)}function Yde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``,i=e.lookupMembers(t,P.Column,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${r}' does not exist in Table 'public.${t.name}'`,n)])}function Xde(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return new k(void 0);let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}if(i.isKind(P.Enum)){let t=e.lookupMembers(i,P.EnumField,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Enum field '${r}' does not exist in Enum 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Enum,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Enum '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}var Zde=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return!(this.declarationNode.parent instanceof Sh)&&!this.declarationNode.parent?.isKind(_d.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(ig).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();return!t||!n?[]:(Array.isArray(t)||(t=[t]),[...e.variables,n,...t].flatMap(e=>this.compiler.nodeReferee(e).getErrors()))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Qde=class{constructor(e,t,n){this.compiler=e,this.filepath=n,this.metadata=t,this.declarationNode=t.declaration,this.ref={}}interpret(){this.ref.token=ih(this.declarationNode);let e=[...this.interpretName(),...this.interpretBody()];return k.create(this.ref,e)}interpretName(){if(!(this.declarationNode instanceof Eh))return[];let e=[],t=Jm(this.declarationNode.name)??[];return this.ref.name=t.pop()||null,t.length>1&&e.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=t.join(`.`)||null,e}interpretBody(){let e=this.metadata.op(this.compiler),t=this.metadata.leftColumns(this.compiler),n=this.metadata.leftTable(this.compiler),r=this.metadata.rightColumns(this.compiler),i=this.metadata.rightTable(this.compiler);if($p(t,r).every(([e,t])=>e?.originalSymbol===t?.originalSymbol))return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,this.declarationNode)];let a=tse(e),o=n?.interpretedName(this.compiler,this.filepath),s=i?.interpretedName(this.compiler,this.filepath),c=ih(this.metadata.leftToken()),l=ih(this.metadata.rightToken());if(this.ref.endpoints=this.declarationNode instanceof Eh?[{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c},{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l}]:[{schemaName:s?.schema??null,tableName:s?.name??``,fieldNames:r.map(e=>e.name??``),relation:a[1],token:l},{schemaName:o?.schema??null,tableName:o?.name??``,fieldNames:t.map(e=>e.name??``),relation:a[0],token:c}],!(this.declarationNode instanceof Eh))return[];let u=Km(this.declarationNode)[0];if(u.args[0]){let e=km(u.args[0]).getValue(),t=e.delete?.at(0)?.value;this.ref.onDelete=t instanceof Dh?Wm(t):eh(t);let n=e.update?.at(0)?.value;this.ref.onUpdate=n instanceof Dh?Wm(n):eh(n),this.ref.color=e.color?.length?sh(e.color?.at(0)?.value):void 0}return[]}};function $de(e){let t=e.parent;for(;t;){if(t instanceof Eh&&t.isKind(_d.Ref))return t.body?.containsEq(e)??!1;t=t.parent}return!1}var efe={nodeReferee(e,t){if(!jm(t)&&!Pm(t)||!$de(t)||t.parentOfKind(Oh))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):nfe(e,r,t)},nodeMetadata(e,t){if(Im(t,_d.Ref)){let e=Km(t)[0];if(!(e instanceof Nh)||!e.callee)return k.create(hd);let n=e.callee;return!(n instanceof Ah)||!n.op?k.create(hd):k.create(new Yh(t))}if(t instanceof Oh){if(!(t.name instanceof Dh)||Wm(t.name)?.toLowerCase()!==vd.Ref)return k.create(hd);let e=t.parent;return e instanceof Eh&&e.isKind(_d.TablePartial)?k.create(new Xh(t)):k.create(new Yh(t))}return k.create(hd)},bindNode(e,t){return Im(t,_d.Ref)?k.create(void 0,new Zde(e,t).bind()):k.create(hd)},interpretMetadata(e,t,n){return t instanceof Yh?new Qde(e,t,n).interpret():k.create(hd)}};function tfe(e,t){let n=e.symbolMembers(t).getFiltered(gd);if(n)return n.find(e=>e instanceof dh&&e.isPublicSchema())}function nfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let t=n.parentNode;if(t&&Pm(t.parentNode)&&t.parentNode.rightExpression===t){let i=t.parentNode.leftExpression,a=Pm(i)?i.rightExpression??i:i,o=e.nodeReferee(a).getFiltered(gd);if(o?.isKind(P.Table)){let t=e.lookupMembers(o,P.Column,r);if(t)return k.create(t);let i=o.declaration?e.nodeFullname(o.declaration).getFiltered(gd)?.join(`.`)??o.name:o.name;return new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table '${i}'`,n)])}}return k.create(void 0)}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Table)){let t=e.lookupMembers(i,P.Column,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table '${i.declaration?e.nodeFullname(i.declaration).getFiltered(gd)?.join(`.`)??i.name:i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Schema '${r}' does not exist`,n)])}let i=tfe(e,t);if(i){let t=e.lookupMembers(i,P.Table,r);if(t)return k.create(t)}let o=e.lookupMembers(t,P.Table,r);return o?k.create(o):new k(void 0,[new N(M.BINDING_ERROR,`Table '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}var mv={visibleName(e,t){let n=t instanceof bh?t:t.useSpecifierDeclaration instanceof wh?t.useSpecifierDeclaration:t.declaration;if(n instanceof wh&&t instanceof uh&&n.getSymbolKind()!==t.kind&&(n=t.declaration),n)return e.nodeAlias(n).mapFiltered(e=>[e],gd,void 0).getFiltered(gd)||e.nodeFullname(n).getFiltered(gd)}},rfe={nodeSymbol(e,t){if(!Lm(t)||!t.name)return k.create(hd);let n=t.getSymbolKind();if(n===void 0||n===P.Schema)return k.create(hd);let r=e.nodeReferee(t.name).getFiltered(gd);return r&&!r.canBeImported?k.create(hd):k.create(e.symbolFactory.create(vh,{useSpecifierDeclaration:t,declaration:r?.declaration,usedSymbol:r,kind:n,name:mv.visibleName(e,t)?.at(-1)},t.filepath),r===void 0?[new N(M.BINDING_ERROR,`Failed to resolve the import of ${n} '${(Jm(t.name)||[]).map(gv).join(`.`)}'`,t)]:[])},symbolMembers(e,t){if(!(t instanceof vh))return k.create(hd);let n=e.symbolMembers(t.originalSymbol).getFiltered(gd);return k.create(n??[])},nodeReferee(e,t){if(!jm(t)&&!Fm(t))return k.create(hd);let n=t.parentOfKind(wh);if(!n)return k.create(hd);let r=n.name===t||Pm(n.name)&&n.name.rightExpression===t?n.getSymbolKind():P.Schema;if(r===void 0)return k.create(void 0);let i=Jm(t.parentOfKind(Ah)),a=eh(t)??i?.at(-1);if(a===void 0)return k.create(void 0);let o=t.parentOfKind(Ch);if(o?.importPath?.value===void 0)return k.create(void 0);let s=dm(t.filepath,o.importPath.value);if(!s)return k.create(void 0,[new N(M.BINDING_ERROR,`Import path must be relative, got '${o.importPath.value}'`,t)]);if(!e.layout.exists(s))return k.create(void 0,[new N(M.NONEXISTENT_MODULE,`${r} '${i?.join(`.`)??a}' does not exist in file ${s.toString()}. Does the file exist?`,t)]);let c=t.parentOfKind(Ah)?.leftExpression;if(c&&c!==t){let n=e.nodeReferee(c).getFiltered(gd);if(!n)return k.create(void 0);let i=e.lookupMembers(n,r,a);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Could not find ${r} '${a}'`,t)])}let l=ife(e,s,a,r);return l?k.create(l):k.create(void 0,[new N(M.BINDING_ERROR,`${r} '${a}' does not exist in file ${s.toString()}`,t)])},bindNode(e,t){if(woe(t)){let n=[];if(t.importPath?.value){let r=dm(t.filepath,t.importPath.value);r?e.layout.exists(r)||n.push(new N(M.NONEXISTENT_MODULE,`Failed to resolve the non-existent file '${t.importPath.value}'`,t.importPath)):n.push(new N(M.BINDING_ERROR,`Import path must be relative, got '${t.importPath.value}'`,t.importPath))}if(t.specifiers){let r=e.bindNode(t.specifiers);n.push(...r.getErrors())}return new k(void 0,n)}return t instanceof Th?new k(void 0,t.specifiers.flatMap(t=>e.bindNode(t).getErrors())):Lm(t)?t.name?new k(void 0,e.nodeReferee(t.name).getErrors()):new k(void 0):k.create(hd)},interpretSymbol(e,t,n){if(!(t instanceof vh))return k.create(hd);if(!t.usedSymbol)return k.create(void 0);let r=e.interpretSymbol(t.usedSymbol,n);if(r.hasValue(gd))return k.create(void 0);let i=r.getValue();if(!i||Array.isArray(i))return r;let a=t.name;return a&&`name`in i?k.create({...i,name:a}):k.create(i)}};function ife(e,t,n,r,i=new Set){if(!t||i.has(t.intern()))return;i.add(t.intern());let a=e.usableMembers(t).getFiltered(gd);if(!a)return;let o=a.nonSchemaMembers.find(e=>e.name===n);if(o?.isKind(r))return o;let s=a.schemaMembers.find(e=>e.name===n);if(s?.isKind(P.Schema))return s;for(let o of a.reuses.selective)if(Jm(o.alias??o.name)?.at(-1)===n){let a=o.parentOfKind(Ch);if(a?.importPath?.value){let s=ife(e,dm(t,a.importPath.value),Jm(o.name)?.at(-1)??n,r,i);if(s)return s}}for(let{importPath:t}of a.reuses.wildcard){let a=ife(e,t,n,r,i);if(a)return a}}function afe(e){if(e instanceof um){let{ast:t}=this.parseFile(e).getValue(),n=this.nodeSymbol(t).getFiltered(gd);return this.usableMembers(n)}let t=e.filepath,n=sfe(this,t),{nonSchemaMembers:r,schemaMembers:i}=e instanceof gh?cfe(this,e,n):lfe(this,e,n);return new k({nonSchemaMembers:r,schemaMembers:i,reuses:{selective:n.selectiveReuses,wildcard:n.wildcardReuses},uses:{selective:n.selectiveUses,wildcard:n.wildcardUses}},n.parseResult.getErrors(),n.parseResult.getWarnings())}function ofe(e,t,n){let r=t.qualifiedName,i;if(i=n instanceof wh?mv.visibleName(e,n):e.nodeFullname(n).getFiltered(gd),!i)return{kind:`none`};let a=i.length<=1?[pm]:i.slice(0,-1);return a.length<r.length||!r.every((e,t)=>e===a[t])?{kind:`none`}:a.length===r.length?{kind:`direct`}:{kind:`child`,schemaName:a[r.length]}}function sfe(e,t){let n=e.parseFile(t),{ast:r}=n.getValue(),i=[],a=[],o=[],s=[];for(let e of r.body){if(!(e instanceof Ch)||!e.specifiers||!e.importPath)continue;let n=dm(t,e.importPath.value);n&&(e.isReuse?e.specifiers instanceof Vh?i.push({importPath:n,node:e.specifiers}):a.push(...e.specifiers.specifiers):e.specifiers instanceof Vh?o.push({importPath:n,node:e.specifiers}):s.push(...e.specifiers.specifiers))}return{ast:r,parseResult:n,selectiveReuses:a,wildcardReuses:i,selectiveUses:s,wildcardUses:o}}function cfe(e,t,n){let{ast:r,selectiveUses:i,selectiveReuses:a}=n,o=t.filepath,s=new Map([[pm,e.symbolFactory.create(dh,{name:pm},o)]]);for(let t of r.declarations){let n=e.nodeFullname(t).getFiltered(gd)||[],r=n.length<=1?pm:n[0];s.has(r)||s.set(r,e.symbolFactory.create(dh,{name:r},o))}ufe(e,[...i,...a],s,o);for(let t of e.reachableFiles(o))for(let n of ffe(e,t))s.has(n)||s.set(n,e.symbolFactory.create(dh,{name:n},o));let c=[...s.values()],l=[],u=c.find(e=>e.isPublicSchema());if(u){let t=e.usableMembers(u).getFiltered(gd);t&&l.push(...t.nonSchemaMembers)}return{nonSchemaMembers:l,schemaMembers:c}}function lfe(e,t,n){let{ast:r,selectiveUses:i,selectiveReuses:a}=n,o=[],s=new Map;for(let n of r.body){if(!(n instanceof Eh))continue;let r=ofe(e,t,n),i=e.nodeAlias(n).getFiltered(gd),a=e.nodeSymbol(n).getFiltered(gd);if(i!==void 0&&t.isPublicSchema()&&a&&o.push(e.symbolFactory.create(_h,{kind:a.kind,declaration:n,aliasedSymbol:a,name:i},t.filepath)),r.kind!==`none`)if(r.kind===`direct`){let t=e.nodeSymbol(n).getFiltered(gd);if(!t)continue;o.push(t)}else s.has(r.schemaName)||s.set(r.schemaName,e.symbolFactory.create(dh,{name:r.schemaName,parent:t},t.filepath))}dfe(e,[...i,...a],t,s);let c=t.qualifiedName;for(let n of e.reachableFiles(t.filepath))for(let r of pfe(e,n,c))s.has(r)||s.set(r,e.symbolFactory.create(dh,{name:r,parent:t},t.filepath));return{nonSchemaMembers:o,schemaMembers:[...s.values()]}}function ufe(e,t,n,r){for(let i of t){if(i.getSymbolKind()!==P.Schema)continue;let t=mv.visibleName(e,i)?.at(0);t!==void 0&&!n.has(t)&&n.set(t,e.symbolFactory.create(dh,{name:t},r))}}function dfe(e,t,n,r){let i=n.qualifiedName;for(let a of t){if(a.getSymbolKind()!==P.Schema)continue;let t=mv.visibleName(e,a);if(!t||t.length<=i.length||!i.every((e,n)=>e===t[n]))continue;let o=t[i.length];o&&!r.has(o)&&r.set(o,e.symbolFactory.create(dh,{name:o,parent:n},n.filepath))}}function ffe(e,t){let{ast:n}=e.parseFile(t).getValue(),r=[];for(let t of n.declarations){let n=e.nodeFullname(t).getFiltered(gd)||[],i=n.length<=1?pm:n[0];r.push(i)}let i=sfe(e,t);for(let t of[...i.selectiveUses,...i.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let n=mv.visibleName(e,t)?.at(0);n!==void 0&&r.push(n)}return r}function pfe(e,t,n){let{ast:r}=e.parseFile(t).getValue(),i=[];for(let t of r.declarations){let r=e.nodeFullname(t).getFiltered(gd)||[],a=r.length<=1?[pm]:r.slice(0,-1);a.length>n.length&&n.every((e,t)=>e===a[t])&&i.push(a[n.length])}let a=sfe(e,t);for(let t of[...a.selectiveUses,...a.selectiveReuses]){if(t.getSymbolKind()!==P.Schema)continue;let r=mv.visibleName(e,t);!r||r.length<=n.length||n.every((e,t)=>e===r[t])&&i.push(r[n.length])}return i}var mfe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return(e=>e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(qp(n)instanceof Fh){let e=km(qp(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),t.push(...e.default?.flatMap(e=>e.value?this.tryToBindEnumFieldRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t}))(e.filter(e=>!Sm(e.callee)))}tryToBindColumnType(e){let t=Ym(e);if(!t)return;let n=t.variables.pop();n&&this.compiler.nodeReferee(n).getErrors()}tryToBindEnumFieldRef(e){if(Am(e))return[];if(jm(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&fm.includes(t))return[]}let t=Ym(e);if(!t){if(Pm(e)){let t=e,n=[];return t.leftExpression&&n.push(...this.compiler.nodeReferee(t.leftExpression).getErrors()),t.rightExpression&&n.push(...this.compiler.nodeReferee(t.rightExpression).getErrors()),n}return[]}let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=[],a=t.variables;for(let e of a)i.push(...this.compiler.nodeReferee(e).getErrors());return i.push(...this.compiler.nodeReferee(r).getErrors()),i.push(...this.compiler.nodeReferee(n).getErrors()),i}bindInlineRef(e){return ig(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;if(n){let e=[];for(let t of r)e.push(...this.compiler.nodeReferee(t).getErrors());return e.push(...this.compiler.nodeReferee(n).getErrors()),e.push(...this.compiler.nodeReferee(t).getErrors()),e}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},hfe=class{constructor(e,t,n,r){this.compiler=e,this.declarationNode=t,this.symbol=n,this.filepath=r,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=this.symbol?.token??ih(this.declarationNode);let e=[];if(this.symbol){let{name:e,schema:t}=this.symbol.interpretedName(this.compiler,this.filepath);this.table.name=e,this.table.schemaName=t}else e.push(...this.interpretName(this.declarationNode.name));let t=[...e,...this.interpretAlias(this.declarationNode.alias),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.table.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath},pk:!0}),this.pkColumns.forEach(e=>{e.pk=!1})),k.create(this.table,t)}interpretName(e){let{name:t,schemaName:n}=oh(e);return n.length>1?(this.table.name=t,this.table.schemaName=n.join(`.`),[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.table.name=t,this.table.schemaName=n.length?n[0]:null,[])}interpretAlias(e){if(!e)return[];let t=th(e);return t&&(this.table.alias=t),[]}interpretSettingList(e){let t=km(e).getValue();this.table.headerColor=t[vd.HeaderColor]?.length?sh(t[vd.HeaderColor]?.at(0)?.value):void 0;let[n]=t[vd.Note]||[];return this.table.note=n&&{value:ah(Zm(n?.value)),token:ih(n)},[]}interpretBody(e){let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case _d.Note:return this.table.note={value:ah(Zm(e.body instanceof Ph?e.body.body[0].callee:e.body.callee)),token:ih(e)},[];case _d.Indexes:return this.interpretIndexes(e);case _d.Checks:return this.interpretChecks(e);case _d.Records:return[];default:return[]}})}interpretInjection(e,t){let n=[],r={order:t,token:ih(e)};r.name=eh(e.expression)||``;let i=e.expression?this.compiler.nodeReferee(e.expression).getFiltered(gd):void 0,a=this.compiler.parseFile(this.filepath).getValue().ast,o=this.compiler.nodeSymbol(a).getFiltered(gd);if(i&&!o.inNestedSchema(this.compiler,i)){let t=this.compiler.nodeSymbol(this.declarationNode).getFiltered(gd),r=t?(this.compiler.symbolUses(t).getFiltered(gd)??[]).find(e=>e.filepath.equals(this.filepath)):void 0;n.push(new N(M.UNSUPPORTED,`Import TablePartial from '${i.filepath}' first. Currently, importing a table that uses a table partial requires that table partial to also be in scope.`,r?.useSpecifierDeclaration??e))}return this.table.partials.push(r),n}interpretFields(e){let t=this.symbol??this.compiler.nodeSymbol(this.declarationNode).getFiltered(gd),n=(t?this.compiler.symbolMembers(t).getFiltered(gd)??[]:[]).filter(e=>e.isKind(P.Column)).length?[]:[new N(M.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],r=e.flatMap((e,t)=>Sm(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...n,...r]}interpretColumn(e){let t=[],n={},r=this.compiler.nodeSymbol(e).getFiltered(gd);n.name=th(e.callee),n.token=ih(e);let i=ch(this.compiler,e.args[0]);n.type=i.getValue(),t.push(...i.getErrors()),n.pk=r?.pk(this.compiler)||!1,n.unique=r?.unique(this.compiler)||!1,n.increment=r?.increment(this.compiler)||void 0;let a=r?.nullable(this.compiler);n.not_null=a===void 0?void 0:!a,n.dbdefault=r?.default(this.compiler),n.note=r?.note(this.compiler);let o=this.compiler.nodeSettings(e).getFiltered(gd)??{},s=this.compiler.parseFile(this.filepath).getValue().ast,c=this.compiler.nodeSymbol(s).getFiltered(gd);return n.inline_refs=(o[vd.Ref]||[]).flatMap(e=>{let n=this.compiler.nodeMetadata(e).getFiltered(gd);if(!n)return[];let r=n.owners(this.compiler);if(c&&r.length>0&&!r.some(e=>e===c))return[];let i=this.compiler.interpretMetadata(n,this.filepath);if(i.hasValue(gd))return[];t.push(...i.getErrors());let a=i.getValue();if(!a?.endpoints?.[0])return[];let o=a.endpoints[0],s=n.op(this.compiler);return s?{schemaName:o.schemaName,tableName:o.tableName,fieldNames:o.fieldNames,relation:s,token:o.token}:[]}),n.checks=(o[vd.Check]||[]).map(e=>({token:ih(e),expression:e.value.value.value})),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.table.indexes.push(...r):r&&this.table.indexes.push(r),n.getErrors()}interpretChecks(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.table.checks.push(...r):r&&this.table.checks.push(r),n.getErrors()}},hv={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`Table '${e}' already exists in schema '${t}'`,n)},getColumnDuplicateError(e,t){return new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column '${e}'`,t)},getPartialInjectionDuplicateError(e,t){return new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${e}'`,t)}},gfe={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.Table)?new k(e.symbolFactory.create(ph,{declaration:t,name:n},t.filepath)):zm(t,_d.Table)?Sm(t.callee)?new k(e.symbolFactory.create(Loe,{declaration:t,name:n},t.filepath)):new k(e.symbolFactory.create(mh,{declaration:t,name:n},t.filepath)):k.create(hd)},symbolMembers(e,t){if(!t.isKind(P.Table))return k.create(hd);let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.Column,P.PartialInjection)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof Eh&&e.declaration.name?e.declaration.name:e.declaration,r=o.get(t);r?e.isKind(P.Column)?(a.push(hv.getColumnDuplicateError(e.name,r)),a.push(hv.getColumnDuplicateError(e.name,n))):(a.push(hv.getPartialInjectionDuplicateError(e.name,r)),a.push(hv.getPartialInjectionDuplicateError(e.name,n))):o.set(t,n)}}let s=[];for(let t=0;t<i.length;t++){let r=i[t];if(!(r.declaration instanceof Nh)||!Sm(r.declaration.callee))continue;let o=r.declaration.callee.expression,c=eh(o);if(o===void 0||c===void 0)continue;let l=e.nodeReferee(o).getFiltered(gd);if(!l){a.push(new N(M.BINDING_ERROR,`TablePartial '${c}' does not exist in Schema 'public'`,o||n));continue}let u=e.symbolMembers(l).getFiltered(gd);if(u){let i=u.flatMap(t=>{if(!t.declaration)return[];let i=t.name;return i===void 0?t:e.symbolFactory.create(yh,{kind:P.Column,injectionDeclaration:r.declaration,declaration:t.declaration,name:i},n.filepath)});s.push({index:t,partialMembers:i})}}for(let e=s.length-1;e>=0;e--){let{index:t,partialMembers:n}=s[e];i.splice(t,0,...n)}let c=new Set(i.filter(e=>e.isKind(P.Column)&&!(e instanceof yh)).map(e=>e.name));return new k(Qp([...i.filter(e=>!(e instanceof yh&&c.has(e.name)))].reverse(),e=>e.isKind(P.Column)?e.name:e).reverse(),a)},nodeReferee(e,t){if(!Bm(t,_d.Table))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):jm(t)&&t.parentNode instanceof kh&&t.parentNode.op?.value===`~`?_fe(e,r,t):Vm(t,1)?vfe(e,r,t):Toe(t,vd.Ref)?yfe(e,r,t):Vm(t,0)?k.create(hd):bfe(e,r,t)},bindNode(e,t){if(!Im(t,_d.Table))return k.create(hd);let n=new mfe(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof ph?t.declaration instanceof Eh?new hfe(e,t.declaration,t,n).interpret():k.create(void 0):k.create(hd)}};function _fe(e,t,n){let r=eh(n)??``,i=e.symbolMembers(t).getFiltered(gd);if(i){let t=i.find(e=>e instanceof dh&&e.isPublicSchema());if(t){let n=e.lookupMembers(t,P.TablePartial,r);if(n)return k.create(n)}}let a=e.lookupMembers(t,P.TablePartial,r);return a?k.create(a):new k(void 0,[new N(M.NAME_NOT_FOUND,`TablePartial '${r}' does not exist in Schema 'public'`,n)])}function vfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=Ooe(n),a=e.lookupMembers(i,t?P.Enum:P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.NAME_NOT_FOUND,t?`Enum '${r}' does not exist in Schema 'public'`:`Schema '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}if(n.parentNode.leftExpression===n){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function yfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let i=n.parent,a=i instanceof Eh&&i.isKind(_d.Table)?e.nodeSymbol(i).getFiltered(gd):void 0;if(a){let t=e.lookupMembers(a,P.Column,r);if(t)return k.create(t)}let o=e.lookupMembers(t,P.Column,r);return o?k.create(o):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table 'public.${a?.name??``}'`,n)])}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Table)){let t=e.lookupMembers(i,P.Column,r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Column '${r}' does not exist in Table 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Table,r);return i?k.create(i):new k(void 0,[new N(M.BINDING_ERROR,`Table '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function bfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return fm.includes(r.toLowerCase())?new k(void 0):k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}if(i.isKind(P.Enum)){let t=e.lookupMembers(i,P.EnumField,r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum field '${r}' does not exist in Enum 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Enum,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function xfe(e){return e?e.split(``).every(e=>gm(e)||_m(e))&&!_m(e[0]):!1}function gv(e){return xfe(e)?e:`"${_v(e)}"`}function Sfe(e){let t=``,n=0,r={n:`
5
5
  `,t:` `,r:`\r`,b:`\b`,f:`\f`,v:`\v`,0:`\0`,"\\":`\\`,'"':`"`,"'":`'`,"`":"`"};for(;n<e.length;)if(e[n]===`\\`&&n+1<e.length){let i=e[n+1];if(i===`u`&&n+5<e.length){let r=e.slice(n+2,n+6);if(/^[0-9a-fA-F]{4}$/.test(r)){t+=String.fromCharCode(parseInt(r,16)),n+=6;continue}}i in r?(t+=r[i],n+=2):(t+=i,n+=2)}else t+=e[n],n++;return t}function _v(e){let t=``;for(let n=0;n<e.length;n++){let r=e[n];switch(r){case`\\`:t+=`\\\\`;break;case`"`:t+=`\\"`;break;case`'`:t+=`\\'`;break;case`
6
6
  `:t+=`\\n`;break;case` `:t+=`\\t`;break;case`\r`:t+=`\\r`;break;case`\b`:t+=`\\b`;break;case`\f`:t+=`\\f`;break;case`\v`:t+=`\\v`;break;case`\0`:t+=`\\0`;break;default:t+=r}}return t}function Cfe(e){if(e==null)return`null`;if(typeof e==`boolean`)return e?`true`:`false`;if(typeof e==`number`)return String(e);if(typeof e==`string`)return`'${_v(e)}'`;let{value:t,type:n}=e;if(t==null||pg(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(pg(n)){let e=ov(t);return e===null?`\`${t}\``:e?`true`:`false`}if(fg(n)){let e=av(t);return e===null?`\`${t}\``:String(e)}if(gg(n)){let e=cv(t);return e===null?`\`${t}\``:`'${_v(e)}'`}let r=sv(t);return r===null?`\`${t}\``:`'${_v(r)}'`}function wfe(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?Sfe(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function Tfe(e,t){let n=new Set,r=[];for(let i of t)for(let t of e.reachableFiles(i))n.has(t.intern())||(n.add(t.intern()),r.push(t));return r}function Efe(e){let t=[],n=[],r=[];e.bindProject();for(let i of e.parseProject().values()){n.push(...i.getErrors()),r.push(...i.getWarnings());let a=e.nodeSymbol(i.getValue().ast).getFiltered(gd);if(!a)continue;let o=e.symbolMembers(a);n.push(...o.getErrors()),r.push(...o.getWarnings());for(let i of o.getFiltered(gd)??[])if(t.push(i),i instanceof dh&&i.isKind(P.Schema)){let a=e.symbolMembers(i);n.push(...a.getErrors()),r.push(...a.getWarnings()),t.push(...a.getFiltered(gd)??[])}}return new k(t,n,r)}var Dfe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(ig).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=this.compiler.nodeReferee(t),r=n.getFiltered(gd);return r instanceof vh?[...n.getErrors(),new N(M.BINDING_ERROR,`TableGroup cannot reference imported table '${r.name}'`,t)]:n.getErrors()}):[])}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Ofe=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=ih(this.declarationNode),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),k.create(this.tableGroup,e)}interpretName(e){let t=[],{name:n,schemaName:r}=oh(e);return r.length>=2&&(this.tableGroup.name=n,this.tableGroup.schemaName=r.join(`.`),t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name))),this.tableGroup.name=n,this.tableGroup.schemaName=r[0]||null,t}interpretBody(e){let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:ah(Zm(e.body instanceof Ph?e.body.body[0].callee:e.body.callee)),token:ih(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=e.callee?this.compiler.nodeReferee(e.callee).getFiltered(gd):void 0;if(n?.isKind(P.Table)){let{name:e,schema:t}=n.interpretedName(this.compiler,this.filepath);return{name:e,schemaName:t}}let r=Jm(e.callee);return r.length>2&&t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,e)),{name:r.pop(),schemaName:r.join(`.`)||null}}),t}interpretSettingList(e){let t=km(e).getValue();this.tableGroup.color=t.color?.length?sh(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:ah(Zm(n?.value)),token:ih(n)},[]}},kfe={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`TableGroup '${e}' already exists in schema '${t}'`,n)},getFieldDuplicateError(e,t){return new N(M.DUPLICATE_NAME,`Duplicate TableGroupField '${e}'`,t)}},Afe={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd),r=n?.at(-1);return Im(t,_d.TableGroup)?new k(e.symbolFactory.create(Poe,{declaration:t,name:r},t.filepath)):zm(t,_d.TableGroup)?new k(e.symbolFactory.create(Foe,{declaration:t,name:n?.map(gv).join(`.`)},t.filepath)):k.create(hd)},symbolMembers(e,t){if(t.isKind(P.TableGroup)){let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.TableGroupField)||!e.declaration)continue;let t=`${e.kind}:${e.name}`;if(e.name!==void 0){let n=e.declaration instanceof Eh&&e.declaration.name?e.declaration.name:e.declaration,r=o.get(t);r?(a.push(kfe.getFieldDuplicateError(e.name,r)),a.push(kfe.getFieldDuplicateError(e.name,n))):o.set(t,n)}}return new k(i,a)}return t.isKind(P.TableGroupField)?new k([]):k.create(hd)},nodeReferee(e,t){if(!jm(t)||!Bm(t,_d.TableGroup)||t.parent&&Hm(t))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):jfe(e,r,t)},bindNode(e,t){if(!Im(t,_d.TableGroup))return k.create(hd);let n=new Dfe(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){let r=t.declaration;return!Im(r,_d.TableGroup)||!(t instanceof Poe)?k.create(hd):ese(e,r)?new Ofe(e,t,n).interpret():k.create(void 0)}};function jfe(e,t,n){let r=th(n)??``;if(!Pm(n.parentNode)){let i=e.symbolMembers(t).getFiltered(gd);if(i){let t=i.find(e=>e instanceof dh&&e.isPublicSchema());if(t){let n=e.lookupMembers(t,P.Table,r);if(n)return k.create(n)}}let a=e.lookupMembers(t,P.Table,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Table '${r}' does not exist in Schema 'public'`,n)])}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.BINDING_ERROR,`Table or schema '${r}' does not exist`,n)])}return new k(void 0)}let a=e.lookupMembers(t,P.Schema,r);return a?k.create(a):new k(void 0,[new N(M.BINDING_ERROR,`Schema '${r}' does not exist`,n)])}var Mfe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.declarationNode.body instanceof Ph?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof Nh)return this.bindFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];if(qp(n)instanceof Fh){let e=km(qp(n)).getValue();t.push(...e.ref?.flatMap(e=>e.value?this.bindInlineRef(e.value):[])||[]),n.pop()}return n[1]&&this.tryToBindColumnType(n[1]),t})}tryToBindColumnType(e){let t=Ym(e);if(!t)return[];let n=t.variables.pop();return n?this.compiler.nodeReferee(n).getErrors():[]}bindInlineRef(e){return ig(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];if(n){let r=[],i=e.variables;for(let e of i)r.push(...this.compiler.nodeReferee(e).getErrors());let a=this.compiler.nodeReferee(n);return r.push(...a.getErrors()),a.getValue()&&r.push(...this.compiler.nodeReferee(t).getErrors()),r}return this.compiler.nodeReferee(t).getErrors()})}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},Nfe=class{constructor(e,t,n){this.compiler=e,this.declarationNode=t.declaration,this.symbol=t,this.filepath=n,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=this.symbol?.token??ih(this.declarationNode),this.symbol?this.tablePartial.name=this.symbol.interpretedName(this.compiler,this.filepath).name:this.interpretName(this.declarationNode.name);let e=[...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return this.pkColumns.length>=2&&(this.tablePartial.indexes.push({columns:this.pkColumns.map(({name:e,token:t})=>({value:e,type:`column`,token:t})),pk:!0,token:{start:{offset:-1,line:-1,column:-1},end:{offset:-1,line:-1,column:-1},filepath:this.declarationNode.filepath}}),this.pkColumns.forEach(e=>{e.pk=!1})),new k(this.tablePartial,e)}interpretName(e){let{name:t}=oh(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=km(e).getValue(),n=kae(t[vd.HeaderColor]);this.tablePartial.headerColor=n?sh(n.value):void 0;let[r]=t[vd.Note]||[];return this.tablePartial.note=r&&{value:Zm(r?.value)?ah(Zm(r?.value)):``,token:ih(r)},[]}interpretBody(e){let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case _d.Note:return this.tablePartial.note={value:ah(Zm(e.body instanceof Ph?e.body.body[0].callee:e.body.callee)),token:ih(e)},[];case _d.Indexes:return this.interpretIndexes(e);case _d.Checks:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={},r=this.compiler.nodeSymbol(e).getFiltered(gd);n.name=th(e.callee)??``,n.token=ih(e);let i=ch(this.compiler,e.args[0]);n.type=i.getValue(),t.push(...i.getErrors()),n.pk=r?.pk(this.compiler)||void 0,n.unique=r?.unique(this.compiler)||void 0,n.increment=r?.increment(this.compiler)||void 0;let a=r?.nullable(this.compiler);n.not_null=a===void 0?void 0:!a,n.dbdefault=r?.default(this.compiler),n.note=r?.note(this.compiler);let o=this.compiler.nodeSettings(e).getFiltered(gd)??{},s=this.compiler.parseFile(this.filepath).getValue().ast,c=this.compiler.nodeSymbol(s).getFiltered(gd);return n.inline_refs=(o[vd.Ref]||[]).flatMap(e=>{let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!(t instanceof Xh))return[];let n=t.owners(this.compiler);if(c&&n.length>0&&!n.some(e=>e===c))return[];let r=t.op(this.compiler);if(!r)return[];let i=t.rightTable(this.compiler),a=t.rightColumns(this.compiler);if(!i||a.length===0)return[];let o=i.interpretedName(this.compiler,this.filepath);return{schemaName:o.schema,tableName:o.name,fieldNames:a.map(e=>e.name??``),relation:r,token:ih(t.rightToken())}}),n.checks=(o[vd.Check]||[]).map(e=>({token:ih(e),expression:e.value.value.value})),this.tablePartial.fields?.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.tablePartial.indexes?.push(...r):r&&this.tablePartial.indexes?.push(r),n.getErrors()}interpretChecks(e){let t=this.compiler.nodeMetadata(e).getFiltered(gd);if(!t)return[];let n=this.compiler.interpretMetadata(t,this.filepath);if(n.hasValue(gd))return[];let r=n.getValue();return Array.isArray(r)?this.tablePartial.checks?.push(...r):r&&this.tablePartial.checks?.push(r),n.getErrors()}},Pfe={getDuplicateError(e,t,n){return new N(M.DUPLICATE_NAME,`TablePartial '${e}' already exists in schema '${t}'`,n)}},Ffe={nodeSymbol(e,t){let n=e.nodeFullname(t).getFiltered(gd)?.at(-1);return Im(t,_d.TablePartial)?new k(e.symbolFactory.create(hh,{declaration:t,name:n},t.filepath)):zm(t,_d.TablePartial)?new k(e.symbolFactory.create(mh,{declaration:t,name:n},t.filepath)):k.create(hd)},symbolMembers(e,t){if(t.isKind(P.TablePartial)){let n=t.declaration;if(!(n instanceof Eh))return new k([]);let r=Km(n),i=[],a=[];for(let t of r){let n=e.nodeSymbol(t),r=n.getFiltered(gd);r&&(i.push(r),a.push(...n.getErrors()))}let o=new Map;for(let e of i){if(!e.isKind(P.Column)||!e.declaration)continue;let t=e.name;if(t!==void 0){let n=e.declaration instanceof Eh&&e.declaration.name?e.declaration.name:e.declaration,r=o.get(t);r?(a.push(hv.getColumnDuplicateError(t,r)),a.push(hv.getColumnDuplicateError(t,n))):o.set(t,n)}}return new k(i,a)}return t.isKind(P.Column)&&Im(t.declaration?.parent,_d.TablePartial)?new k([]):k.create(hd)},nodeReferee(e,t){if(!jm(t)&&!Pm(t)||!Bm(t,_d.TablePartial))return k.create(hd);let n=e.parseFile(t.filepath).getValue().ast,r=e.nodeSymbol(n).getValue();return r===gd?k.create(void 0):Vm(t,1)?Ife(e,r,t):Toe(t,vd.Ref)?Lfe(e,r,t):Rfe(e,r,t)},bindNode(e,t){if(!Im(t,_d.TablePartial))return k.create(hd);let n=new Mfe(e,t).bind(),r=e.nodeSymbol(t).getFiltered(gd);return r&&n.push(...e.symbolMembers(r).getErrors()),k.create(void 0,n)},interpretSymbol(e,t,n){return t instanceof hh?t.declaration instanceof Eh?new Nfe(e,t,n).interpret():k.create(void 0):k.create(hd)}};function Ife(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}return new k(void 0)}if(n.parentNode.leftExpression===n){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function Lfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode)){let i=n.parent;if(i instanceof Eh&&i.isKind(_d.TablePartial)){let t=e.nodeSymbol(i).getFiltered(gd);if(t){let i=e.lookupMembers(t,P.Column,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${r}' does not exist in TablePartial '${t.name}'`,n)])}}let a=e.lookupMembers(t,P.Column,r);return a?k.create(a):new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${r}' does not exist`,n)])}let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Table,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table or schema '${r}' does not exist`,n)])}if(i.isKind(P.Table)){let t=e.lookupMembers(i,P.Column,r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Column '${r}' does not exist in Table 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Table,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Table '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}function Rfe(e,t,n){if(!jm(n))return new k(void 0);let r=th(n)??``;if(!Pm(n.parentNode))return fm.includes(r.toLowerCase())?new k(void 0):k.create(e.lookupMembers(t,P.Enum,r));let i=ag(e,n);if(i){if(i.isKind(P.Schema)){let t=e.lookupMembers(i,[P.Enum,P.Schema],r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum or schema '${r}' does not exist`,n)])}if(i.isKind(P.Enum)){let t=e.lookupMembers(i,P.EnumField,r);return t?k.create(t):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum field '${r}' does not exist in Enum 'public.${i.name}'`,n)])}return new k(void 0)}let a=n.parentNode;if(a.leftExpression===n){if(Pm(a.parentNode)&&a.parentNode.leftExpression===a){let i=e.lookupMembers(t,P.Schema,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Schema '${r}' does not exist in Schema 'public'`,n)])}let i=e.lookupMembers(t,P.Enum,r);return i?k.create(i):new k(void 0,[new N(M.NAME_NOT_FOUND,`Enum '${r}' does not exist in Schema 'public'`,n)])}return new k(void 0)}var zfe={symbolMembers(e,t){if(!t.isKind(P.Schema)||!(t instanceof dh))return k.create(hd);let n=t.qualifiedName,r=e.usableMembers(t).getFiltered(gd);if(!r)return k.create([]);let i=[...r.nonSchemaMembers],a=new Map(r.schemaMembers.map(e=>[e.name,e])),o=[];for(let n of r.reuses.selective){let r=Vfe(e,t,n,a);o.push(...r.getErrors());let s=r.getFiltered(gd);s&&i.push(s),i.push(...vv(e,t,n))}for(let{importPath:n,node:o}of r.reuses.wildcard)i.push(...Hfe(e,t,n,o,a));for(let n of r.uses.selective){let r=Vfe(e,t,n,a);o.push(...r.getErrors());let s=r.getFiltered(gd);s&&i.push(s),i.push(...vv(e,t,n))}for(let{importPath:n,node:o}of r.uses.wildcard)i.push(...Hfe(e,t,n,o,a));i.push(...a.values());let s=[...i];{let n=i.filter(e=>e.isKind(P.TableGroup));if(!t.isPublicSchema()){let r=e.usableMembers(t.filepath).getFiltered(gd)?.schemaMembers.find(e=>e.isPublicSchema());if(r){let t=e.symbolMembers(r).getFiltered(gd);t&&n.push(...t.filter(e=>e.isKind(P.TableGroup)))}}for(let r of n)s.push(...Wfe(e,t,r))}let c=new Set,l=s.filter(e=>{if(e instanceof vh&&e.isKind(P.Schema))return!1;let t=`${e.originalSymbol.intern()}:${e.name??``}`;return c.has(t)?!1:(c.add(t),!0)}),u=new Map;for(let e of l){let t=`${e.kind}:${e.name}`;if(u.get(t)){if(e.isKind(P.Schema))continue;let t=e instanceof vh?e.useSpecifierDeclaration??e.declaration:e.declaration instanceof Eh&&e.declaration.name?e.declaration.name:e.declaration;t&&e.name!==void 0&&o.push(Bfe(e.kind,e.name,n.join(`.`),t))}else u.set(t,e)}return new k(l,o)}};function Bfe(e,t,n,r){switch(e){case P.Table:return hv.getDuplicateError(t,n,r);case P.Enum:return sg.getDuplicateError(t,n,r);case P.TablePartial:return Pfe.getDuplicateError(t,n,r);case P.TableGroup:return kfe.getDuplicateError(t,n,r);case P.DiagramView:return og.getDuplicateError(t,n,r);default:return new N(M.DUPLICATE_NAME,`Duplicate ${e} '${t}' in schema '${n}'`,r)}}function Vfe(e,t,n,r){let i=ofe(e,t,n);if(i.kind===`none`)return k.create(void 0);if(i.kind===`direct`){let t=e.nodeSymbol(n);return t.hasValue(gd)?k.create(void 0):t}return r.has(i.schemaName)||r.set(i.schemaName,e.symbolFactory.create(dh,{name:i.schemaName,parent:t},t.filepath)),k.create(void 0)}function vv(e,t,n,r=new Set){if(n.getSymbolKind()!==P.Schema||!n.name)return[];let i=e.nodeReferee(n.name).getFiltered(gd);if(!i||!i.isKind(P.Schema)||(e.nodeAlias(n).getFiltered(gd)??e.nodeFullname(n).getFiltered(gd)?.at(0))!==t.name)return[];let a=i.intern();if(r.has(a))return[];r.add(a);let o=e.usableMembers(i).getFiltered(gd);if(!o)return[];let s=o.nonSchemaMembers.filter(e=>e.canBeImported).map(r=>e.symbolFactory.create(vh,{kind:r.kind,declaration:r.originalSymbol.declaration,usedSymbol:r.originalSymbol,useSpecifierDeclaration:n,name:r.name},t.filepath));for(let n of[...s])n.isKind(P.TableGroup)&&s.push(...Wfe(e,t,n));for(let n of o.reuses.selective)s.push(...vv(e,t,n,r));return s}function Hfe(e,t,n,r,i,a=new Set){if(a.has(n))return[];a.add(n);let o=Ufe(e,n,t.qualifiedName);if(!o)return[];let s=e.usableMembers(o).getFiltered(gd);if(!s)return[];let c=s.nonSchemaMembers.filter(e=>e.canBeImported).map(n=>e.symbolFactory.create(vh,{kind:n.kind,declaration:n.declaration,usedSymbol:n,useSpecifierDeclaration:r,name:n.name},t.filepath));for(let n of s.schemaMembers)i.has(n.name)||i.set(n.name,e.symbolFactory.create(dh,{name:n.name},t.filepath));let{reuses:{selective:l,wildcard:u}}=s;for(let n of l){let r=Vfe(e,t,n,i).getFiltered(gd);r&&c.push(r),c.push(...vv(e,t,n))}for(let{importPath:n}of u)c.push(...Hfe(e,t,n,r,i,a));return c}function Ufe(e,t,n){if(n.length===0)return;let r=e.usableMembers(t).getFiltered(gd);if(!r)return;let{schemaMembers:i}=r,a,o=[...n];for(;o.length>0;){let t=o.shift();if(a=i.find(e=>e.name===t),!a)return;let n=e.usableMembers(a).getValue();({schemaMembers:i}=n)}return a}function Wfe(e,t,n){if(!n.isKind(P.TableGroup)||!(n instanceof vh))return[];let r=n.originalSymbol,i=e.symbolMembers(r).getFiltered(gd);if(!i)return[];let a=t.qualifiedName,o=[];for(let t of i){if(!t.isKind(P.TableGroupField)||!t.declaration)continue;let r=t.declaration.callee;if(!r)continue;let i=Jm(r);if(!i||i.length===0)continue;let s=i.length<=1?[pm]:i.slice(0,-1);if(s.length!==a.length||!a.every((e,t)=>e===s[t]))continue;let c=t.declaration.filepath,l=Gfe(e,c,i);l&&o.push(e.symbolFactory.create(vh,{kind:P.Table,declaration:l.declaration,usedSymbol:l,useSpecifierDeclaration:void 0,name:l.name},n.filepath))}return o}function Gfe(e,t,n){if(n.length===1){let r=e.usableMembers(t).getFiltered(gd);return r?r.nonSchemaMembers.find(e=>e.isKind(P.Table)&&e.name===n[0]):void 0}let r=n[0],i=n[n.length-1],a=e.usableMembers(t).getFiltered(gd);if(!a)return;let o=a.schemaMembers.find(e=>e.name===r);if(!o)return;let s=e.usableMembers(o).getFiltered(gd);if(s)return s.nonSchemaMembers.find(e=>e.isKind(P.Table)&&e.name===i)}var Kfe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof Nh)return[];let t=e.body.filter(e=>e instanceof Eh);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?this.compiler.bindNode(e).getErrors():[])}},qfe=class{constructor(e,t,n){this.compiler=e,this.symbol=t,this.declarationNode=t.declaration,this.filepath=n,this.note={name:void 0,content:void 0,token:void 0}}interpret(){this.note.token=ih(this.declarationNode);let e=[...this.interpretName(),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)];return k.create(this.note,e)}interpretName(){let{name:e}=this.symbol.interpretedName(this.compiler,this.filepath);return this.note.name=e,[]}interpretSettingList(e){let t=km(e).getValue();return this.note.headerColor=t.headercolor?.length?sh(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=Zp(e.body,e=>e instanceof Nh);return t.length!==1||n.length>0?[new N(M.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=Pne(e,`callee.expression.literal.value`,``);return this.note.content=ah(t),[]}},Jfe=[gfe,pse,Gde,gse,Xoe,efe,Rde,Afe,Ffe,{nodeSymbol(e,t){return!Im(t,_d.Note)||!(t.parentNode instanceof Sh)?k.create(hd):new k(e.symbolFactory.create(Ioe,{declaration:t,name:e.nodeFullname(t).getFiltered(gd)?.at(-1)},t.filepath))},symbolMembers(e,t){return t.isKind(P.StickyNote)?new k([]):k.create(hd)},bindNode(e,t){return Im(t,_d.Note)?k.create(void 0,new Kfe(e,t).bind()):k.create(hd)},interpretSymbol(e,t,n){return t instanceof Ioe?t.declaration instanceof Eh?new qfe(e,t,n).interpret():k.create(void 0):k.create(hd)}},rfe,zfe,ose,Fde];function yv(e,...t){for(let n of Jfe){let r=n[e];if(r){let e=r(...t);if(e instanceof k&&!e.hasValue(hd))return e}}return k.create(hd)}function Yfe(e){let t=yv(`nodeSymbol`,this,e);return t.hasValue(hd)?k.create(gd):t}function Xfe(e){let t=yv(`symbolMembers`,this,e);return t.hasValue(hd)?k.create(gd):t}function Zfe(e){let t=yv(`nodeReferee`,this,e);return t.hasValue(hd)?k.create(gd):t}function Qfe(e){let t=yv(`bindNode`,this,e);return t.hasValue(hd)?k.create(gd):t}function $fe(e){let t=yv(`nodeMetadata`,this,e);return t.hasValue(hd)?k.create(gd):t}function epe(e,t){let n=yv(`interpretSymbol`,this,e,t);return n.hasValue(hd)?k.create(gd):n}function tpe(e,t){let n=yv(`interpretMetadata`,this,e,t);return n.hasValue(hd)?k.create(gd):n}var npe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new N(M.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof Sh?[e]:this.declarationNode.parent?.isKind(_d.Table,_d.TablePartial)?[]:[e]}validateName(e){return e?[new N(M.UNEXPECTED_NAME,`A Checks shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return qp(n)instanceof Fh&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof Mh))&&t.push(new N(M.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=km(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`name`:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_CHECK_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Am(t.value)||n.push(new N(M.INVALID_CHECK_SETTING_VALUE,`'${e}' must be a string`,t))});break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_CHECK_SETTING,`Unknown check setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},rpe={validateNode(e,t){if(!Im(t,_d.Checks))return k.create(hd);let n=new npe(e,t);return k.create(void 0,n.validate())},nodeFullname(e,t){return Im(t,_d.Checks)?t.name?new k(void 0,[new N(M.UNEXPECTED_NAME,`A Checks shouldn't have a name`,t.name)]):new k(void 0):k.create(hd)},nodeAlias(e,t){return Im(t,_d.Checks)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A Checks shouldn't have an alias`,t.alias)]):new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.Checks)?t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`A Checks shouldn't have a setting list`,t.attributeList)]):new k({}):k.create(hd)}},ipe=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh&&this.declarationNode.parent.isKind(_d.Project)?[]:[new N(M.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e?[new N(M.UNEXPECTED_NAME,`A Custom element shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_NAME,`A Custom element shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Custom element shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Ph)return[new N(M.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return Am(e.callee)||t.push(new N(M.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e)),e.args.length>0&&t.push(...e.args.map(e=>new N(M.INVALID_CUSTOM_ELEMENT_VALUE,`A Custom element value can only be a string`,e))),t}};function bv(e){return e instanceof Eh&&!!e.type?.value}var ape={validateNode(e,t){if(!bv(t))return k.create(hd);let n=new ipe(e,t);return k.create(void 0,n.validate())},nodeFullname(e,t){return bv(t)?t.name?new k(void 0,[new N(M.UNEXPECTED_NAME,`A custom field shouldn't have a name`,t.name)]):new k(void 0):k.create(hd)},nodeAlias(e,t){return bv(t)?t.alias?new k(void 0,[new N(M.UNEXPECTED_NAME,`A custom field shouldn't have an alias`,t.alias)]):new k(void 0):k.create(hd)},nodeSettings(e,t){return bv(t)?t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`A custom field shouldn't have a setting list`,t.attributeList)]):new k({}):k.create(hd)}},ope=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList)],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?xm(e)?[]:[new N(M.INVALID_NAME,`A DiagramView name must be a single identifier`,e)]:[new N(M.NAME_NOT_FOUND,`A DiagramView must have a name`,this.declarationNode)]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A DiagramView shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=km(e),n=t.getErrors(),r=t.getValue();for(let e of Object.keys(r))n.push(...r[e].map(t=>new N(M.UNEXPECTED_SETTINGS,`Unknown '${e}' setting for DiagramView`,t)));return n}validateBody(e){if(!e)return{errors:[],warnings:[]};if(e instanceof Nh)return{errors:[new N(M.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=Zp(e.body,e=>e instanceof Nh),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>Mm(e.callee)?e.args.length>0?e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[]:[new N(M.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)])}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(!i.type)continue;let e=i.type.value.toLowerCase();if(!r.includes(e)){t.push(new N(M.INVALID_DIAGRAMVIEW_FIELD,`Unknown block type "${i.type.value}" in DiagramView. Allowed: Tables, Notes, TableGroups, Schemas`,i));continue}let a=this.validateSubBlock(i);t.push(...a.errors),n.push(...a.warnings)}return{errors:t,warnings:n}}validateSubBlock(e){let t=[],n=[];if(!e.body||!(e.body instanceof Ph))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof Nh&&Mm(e.callee)),a=r.body.some(e=>e instanceof Nh&&!Mm(e.callee));return i&&a&&n.push(new hm(M.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.validateSubBlockFields(e)),{errors:t,warnings:n}}validateSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof Ph))return t;let n=e.body.body.filter(e=>e instanceof Nh);for(let e of n)Mm(e.callee)||(e.args.length>0||!Jm(e.callee))&&t.push(...e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)));return t}},spe={validateNode(e,t){if(!Im(t,_d.DiagramView))return k.create(hd);let{errors:n,warnings:r}=new ope(e,t).validate();return k.create(void 0,n,r)},nodeFullname(e,t){if(Im(t,_d.DiagramView)){if(!t.name)return new k(void 0,[new N(M.NAME_NOT_FOUND,`A DiagramView must have a name`,t)]);let e=Jm(t.name);return e?new k(e):new k(void 0)}else if(zm(t,_d.DiagramViewTables,_d.DiagramViewNotes,_d.DiagramViewSchemas,_d.DiagramViewTableGroups)){let e=Jm(t.callee);return e?(e.length===1&&zm(t,_d.DiagramViewTables)&&e.unshift(pm),new k(e)):new k(void 0)}return new k(hd)},nodeAlias(e,t){return Im(t,_d.DiagramView)?new k(void 0):k.create(hd)}},cpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:ym(e)?[]:[new N(M.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,e)]:[new N(M.NAME_NOT_FOUND,`An Enum must have a name`,this.declarationNode)]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return this.validateFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new N(M.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)];let t=[];for(let n of e){n.callee&&!jm(n.callee)&&t.push(new N(M.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,n.callee));let e=[...n.args];qp(e)instanceof Fh?(t.push(...this.validateFieldSettings(qp(e))),e.pop()):e[0]instanceof Fh&&(t.push(...this.validateFieldSettings(e[0])),e.shift()),e.length>0&&t.push(...e.map(e=>new N(M.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e)))}return t}validateFieldSettings(e){let t=km(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];if(t)switch(e){case vd.Note:t.length>1&&t.forEach(e=>n.push(new N(M.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Am(e.value)||n.push(new N(M.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))});break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},lpe={validateNode(e,t){return Im(t,_d.Enum)?k.create(void 0,new cpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(Im(t,_d.Enum)){if(!t.name)return new k(void 0,[new N(M.NAME_NOT_FOUND,`An Enum must have a name`,t)]);if(!ym(t.name))return new k(void 0,[new N(M.INVALID_NAME,`An Enum name must be of the form <enum> or <schema>.<enum>`,t.name)]);let e=Jm(t.name);return e?.length===1&&e.unshift(pm),new k(e)}if(zm(t,_d.Enum)){let e=eh(t.callee);return new k(e===void 0?void 0:[e])}return k.create(hd)},nodeAlias(e,t){return Im(t,_d.Enum)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`An Enum shouldn't have an alias`,t.alias)]):new k(void 0):zm(t,_d.Enum)?new k(void 0):k.create(hd)},nodeSettings(e,t){if(Im(t,_d.Enum))return t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`An Enum shouldn't have a setting list`,t.attributeList)]):new k({});if(zm(t,_d.Enum)){let e=[...t.args],n;if(qp(e)instanceof Fh?n=qp(e):e[0]instanceof Fh&&(n=e[0]),!n)return new k({});let r=km(n),i=r.getErrors(),a=r.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case vd.Note:t.length>1&&t.forEach(e=>i.push(new N(M.DUPLICATE_ENUM_ELEMENT_SETTING,`'note' can only appear once`,e))),t.forEach(e=>{Am(e.value)||i.push(new N(M.INVALID_ENUM_ELEMENT_SETTING,`'note' must be a string`,e))}),o[e]=t;break;default:t.forEach(t=>i.push(new N(M.UNKNOWN_ENUM_ELEMENT_SETTING,`Unknown enum field setting '${e}'`,t)))}return new k(o,i)}return k.create(hd)}},upe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=new N(M.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);return this.declarationNode.parent instanceof Sh?[e]:this.declarationNode.parent?.isKind(_d.Table,_d.TablePartial)?[]:[e]}validateName(e){return e?[new N(M.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[],n=[e.callee,...e.args];return qp(n)instanceof Fh&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof zh;)e.argumentList&&Xm(e.argumentList)===void 0&&t.push(new N(M.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e.argumentList)),e=e.callee;Xm(e)===void 0&&t.push(new N(M.INVALID_INDEXES_FIELD,`An index field must be an identifier, a quoted identifier, a functional expression or a tuple of such`,e))}),t})}validateFieldSetting(e){let t=km(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`note`:case`name`:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Am(t.value)||n.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))});break;case`unique`:case`pk`:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&n.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))});break;case`type`:t.length>1&&t.forEach(e=>n.push(new N(M.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{jm(e.value)||n.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))});break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return n}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},dpe={validateNode(e,t){return Im(t,_d.Indexes)?k.create(void 0,new upe(e,t).validate()):k.create(hd)},nodeFullname(e,t){return Im(t,_d.Indexes)?t.name?new k(void 0,[new N(M.UNEXPECTED_NAME,`An Indexes shouldn't have a name`,t.name)]):new k(void 0):zm(t,_d.Indexes)?new k(void 0):k.create(hd)},nodeAlias(e,t){return Im(t,_d.Indexes)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`An Indexes shouldn't have an alias`,t.alias)]):new k(void 0):zm(t,_d.Indexes)?new k(void 0):k.create(hd)},nodeSettings(e,t){if(Im(t,_d.Indexes))return t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`An Indexes shouldn't have a setting list`,t.attributeList)]):new k({});if(zm(t,_d.Indexes)){let e=[t.callee,...t.args],n;if(qp(e)instanceof Fh&&(n=qp(e)),!n)return new k({});let r=km(n),i=r.getErrors(),a=r.getValue(),o={};for(let[e,t]of Object.entries(a))switch(e){case vd.Note:case vd.Name:t.length>1&&t.forEach(t=>i.push(new N(M.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Am(t.value)||i.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'${e}' must be a string`,t))}),o[e]=t;break;case vd.Unique:case vd.PK:t.length>1&&t.forEach(t=>i.push(new N(M.DUPLICATE_INDEX_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{t.value!==void 0&&i.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'${e}' must not have a value`,t))}),o[e]=t;break;case vd.Type:t.length>1&&t.forEach(e=>i.push(new N(M.DUPLICATE_INDEX_SETTING,`'type' can only appear once`,e))),t.forEach(e=>{jm(e.value)||i.push(new N(M.INVALID_INDEX_SETTING_VALUE,`'type' must be "btree" or "hash"`,e))}),o[e]=t;break;default:t.forEach(t=>i.push(new N(M.UNKNOWN_INDEX_SETTING,`Unknown index setting '${e}'`,t)))}return new k(o,i)}return k.create(hd)}},fpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return!(e instanceof Sh)&&!(e instanceof Eh&&e.isKind(_d.Table,_d.TableGroup,_d.TablePartial,_d.Project))?[new N(M.INVALID_NOTE_CONTEXT,`A Note can only appear inside a Table, a TableGroup, a TablePartial or a Project. Sticky note can only appear at the global scope.`,this.declarationNode)]:[]}validateName(e){return this.compiler.nodeFullname(this.declarationNode).getErrors()}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return this.validateFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=[];return e.length===0?[new N(M.EMPTY_NOTE,`A Note must have a content`,this.declarationNode)]:(e.length>1&&e.slice(1).forEach(e=>t.push(new N(M.NOTE_CONTENT_REDEFINED,`A Note can only contain one string`,e))),Am(e[0].callee)||t.push(new N(M.INVALID_NOTE,`A Note content must be a quoted string`,e[0])),e[0].args.length>0&&t.push(...e[0].args.map(e=>new N(M.INVALID_NOTE,`A Note can only contain one quoted string`,e))),t)}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},ppe={validateNode(e,t){return Im(t,_d.Note)?k.create(void 0,new fpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(!Im(t,_d.Note))return k.create(hd);if(!(t.parent instanceof Sh))return t.name?new k(void 0,[new N(M.UNEXPECTED_NAME,`A Note shouldn't have a name`,t.name)]):new k(void 0);if(!t.name)return new k(void 0,[new N(M.INVALID_NAME,`Sticky note must have a name`,t)]);if(t.name instanceof Vh)return new k(void 0,[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,t.name)]);let n=Jm(t.name);return n===void 0?new k(void 0,[new N(M.INVALID_NAME,`Invalid name for sticky note `,t)]):new k(n)},nodeAlias(e,t){return Im(t,_d.Note)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A Note shouldn't have an alias`,t.alias)]):new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.Note)?t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`A Note shouldn't have a setting list`,t.attributeList)]):new k({}):k.create(hd)}},mpe=class{constructor(e,t){this.ast=t,this.compiler=e}validate(){let e=[],t=[];for(let n of this.ast.body){let r=this.compiler.validateNode(n);e.push(...r.getErrors()),t.push(...r.getWarnings())}return new k(this.ast,e,t)}},hpe={validateNode(e,t){return Rm(t)?k.create(void 0,new mpe(e,t).validate().getErrors()):k.create(hd)},nodeFullname(e,t){return Rm(t)?new k(void 0):k.create(hd)},nodeAlias(e,t){return Rm(t)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Rm(t)?new k({}):k.create(hd)}},gpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name).getErrors(),...this.validateAlias(this.declarationNode.alias).getErrors(),...this.validateSettingList(this.declarationNode.attributeList).getErrors(),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?xm(e)?new k(Jm(e)):new k(void 0,[new N(M.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]):new k(void 0)}validateAlias(e){return e?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]):new k(void 0)}validateSettingList(e){return e?new k({},[new N(M.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]):new k({})}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...t.map(e=>new N(M.INVALID_PROJECT_FIELD,`A Project can not have inline fields`,e)),...this.validateSubElements(n)]}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},_pe={validateNode(e,t){return Im(t,_d.Project)?k.create(void 0,new gpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){return Im(t,_d.Project)?t.name?xm(t.name)?new k(Jm(t.name)):new k(void 0,[new N(M.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,t.name)]):new k(void 0):zm(t,_d.Project)?new k(void 0):k.create(hd)},nodeAlias(e,t){return Im(t,_d.Project)&&t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,t.alias)]):zm(t,_d.Project)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.Project)?t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,t.attributeList)]):new k({}):zm(t,_d.Project)?new k({}):k.create(hd)}},vpe=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){let e=this.declarationNode.parent;return e instanceof Sh||e instanceof Eh&&e.isKind(_d.Table)?[]:[new N(M.INVALID_RECORDS_CONTEXT,`Records can only appear at top-level or inside a Table`,this.declarationNode)]}validateName(e){return e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof Sh?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof zh))return[new N(M.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,e||this.declarationNode.type||this.declarationNode)];let t=[];return(!e.callee||!ym(e.callee))&&t.push(new N(M.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!Om(e.argumentList))&&t.push(new N(M.INVALID_RECORDS_NAME,`Records column list must be simple column names`,e.argumentList||e)),t}validateInsideTableName(e){return e&&!Om(e)?[new N(M.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`Records cannot have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return this.validateDataRow(e);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateDataRows(t),...this.validateSubElements(n)]}validateDataRows(e){return e.flatMap(e=>this.validateDataRow(e))}validateDataRow(e){let t=[];if(!e.callee||e.args.length>0)return t.push(new N(M.INVALID_RECORDS_FIELD,`Invalid record row structure`,e)),t;if(e.callee instanceof Lh)for(let n of e.callee.elementList)this.isValidRecordValue(n)||t.push(new N(M.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,n));else this.isValidRecordValue(e.callee)||t.push(new N(M.INVALID_RECORDS_FIELD,`Records can only contain simple values (literals, null, true, false, or enum references). Complex expressions are not allowed.`,e.callee));return t}isValidRecordValue(e){if(e instanceof Wh||Em(e)||Am(e)||e instanceof Mh)return!0;if(jm(e)){let t=e.expression.variable.value.toLowerCase();return fm.includes(t)}if(Pm(e)){let t=Jm(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}},ype={validateNode(e,t){return Im(t,_d.Records)?k.create(void 0,new vpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(Im(t,_d.Records)){if(t.name instanceof Vh)return new k(void 0,[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,t.name)]);if(t.parent instanceof Sh){if(!(t.name instanceof zh))return new k(void 0,[new N(M.INVALID_RECORDS_NAME,`Records at top-level must have a name in the form of table(col1, col2, ...) or schema.table(col1, col2, ...)`,t.name||t.type||t)]);let e=[];(!t.name.callee||!ym(t.name.callee))&&e.push(new N(M.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,t.name.callee||t.name)),(!t.name.argumentList||!Om(t.name.argumentList))&&e.push(new N(M.INVALID_RECORDS_NAME,`Records column list must be simple column names`,t.name.argumentList||t.name));let n=Jm(t.name.callee);return n?.length===1&&n.unshift(pm),new k(n,e)}else{let n=t.parent&&e.nodeFullname(t.parent).getFiltered(gd);return t.name&&!Om(t.name)?new k(n,[new N(M.INVALID_RECORDS_NAME,`Records inside a Table can only have a column list like (col1, col2, ...)`,t.name)]):new k(n)}}return zm(t,_d.Records)?new k(void 0):k.create(hd)},nodeAlias(e,t){return Im(t,_d.Records)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`Records cannot have an alias`,t.alias)]):new k(void 0):zm(t,_d.Records)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.Records)?t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`Records cannot have a setting list`,t.attributeList)]):new k({}):zm(t,_d.Records)?new k({}):k.create(hd)}},bpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Sh?[]:[new N(M.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:xm(e)?[]:[new N(M.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof Nh)return this.validateFields([e]);let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){if(e.length===0)return[new N(M.EMPTY_REF,`A Ref must have at least one field`,this.declarationNode)];let t=[];return e.length>1&&t.push(...e.slice(1).map(e=>new N(M.REF_REDEFINED,`A Ref can only contain one binary relationship`,e))),e.forEach(e=>{if(e.callee&&!Um(e.callee)&&t.push(new N(M.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&Um(e.callee)){let n=Ym(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=Ym(e.callee.rightExpression)??{variables:[],tupleElements:[]},a=i.variables.length+Math.min(i.tupleElements.length,1);r<2&&t.push(new N(M.INVALID_REF_FIELD,`Invalid column reference`,e.callee.leftExpression||e.callee)),a<2&&t.push(new N(M.INVALID_REF_FIELD,`Invalid column reference`,e.callee.rightExpression||e.callee))}e.callee&&!Eoe(e.callee)&&t.push(new N(M.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(qp(n)instanceof Fh){let e=this.validateFieldSettings(qp(n));t.push(...e),n.pop()}else n[0]instanceof Fh&&(t.push(...this.validateFieldSettings(n[0])),n.shift());n.length>0&&t.push(...n.map(e=>new N(M.INVALID_REF_FIELD,`A Ref field should only have a single binary relationship`,e)))}),t}validateFieldSettings(e){return Spe(e).getErrors()}validateSubElements(e){return e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[])}};function xpe(e){if(!(jm(e)&&e.expression.variable.kind!==em.QUOTED_STRING)&&!(e instanceof Dh))return!1;let t;if(t=e instanceof Dh?Wm(e)||``:e.expression.variable.value,t)switch(t.toLowerCase()){case`cascade`:case`no action`:case`set null`:case`set default`:case`restrict`:return!0;default:return!1}return!1}function Spe(e){let t=km(e),n=t.getErrors(),r=t.getValue(),i={};for(let[e,t]of Object.entries(r))switch(e){case vd.Delete:case vd.Update:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{xpe(t.value)||n.push(new N(M.INVALID_REF_SETTING_VALUE,`'${e}' can only have values "cascade", "no action", "set null", "set default" or "restrict"`,t))}),i[e]=t;break;case vd.Color:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))}),i[e]=t;break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}return new k(i,n)}var Cpe={validateNode(e,t){return Im(t,_d.Ref)?k.create(void 0,new bpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){return Im(t,_d.Ref)?t.name?xm(t.name)?new k(Jm(t.name)):new k(void 0,[new N(M.INVALID_NAME,`A Ref's name is optional or must be an identifier or a quoted identifer`,t.name)]):new k(void 0):zm(t,_d.Ref)?new k(void 0):k.create(hd)},nodeAlias(e,t){return Im(t,_d.Ref)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A Ref shouldn't have an alias`,t.alias)]):new k(void 0):zm(t,_d.Ref)?new k(void 0):k.create(hd)},nodeSettings(e,t){if(Im(t,_d.Ref))return t.attributeList?new k({},[new N(M.UNEXPECTED_SETTINGS,`A Ref shouldn't have a setting list`,t.attributeList)]):new k({});if(zm(t,_d.Ref)){let e=[...t.args],n;return qp(e)instanceof Fh?n=qp(e):e[0]instanceof Fh&&(n=e[0]),n?Spe(n):new k({})}return k.create(hd)}},wpe=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Gh?[new N(M.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,e)]:e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:ym(e)?[]:[new N(M.INVALID_NAME,`A Table name must be of the form <table> or <schema>.<table>`,e)]:[new N(M.NAME_NOT_FOUND,`A Table must have a name`,this.declarationNode)]}validateAlias(e){return e?bm(e)?[]:[new N(M.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=km(e),n=t.getErrors();return Yp(t.getValue(),(e,t)=>{switch(t){case vd.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case vd.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{Am(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){let t=e=>{let t=[];if(!e.callee)return[];e.args.length===0&&t.push(new N(M.INVALID_COLUMN,`A column must have a type`,e.callee)),jm(e.callee)||t.push(new N(M.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Coe(e.args[0])&&t.push(new N(M.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t},n=e=>{let t=[];return e.callee?(Sm(e.callee)||t.push(new N(M.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee)),e.args.length&&t.push(...e.args.map(e=>new N(M.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection does not have any trailing attributes`,e))),t):[]};return e.flatMap(e=>e.callee instanceof kh&&e.callee.op?.value===`~`?n(e):t(e))}validateFieldSetting(e){if(!e.slice(0,-1).every(Nm)||!e.slice(-1).every(e=>Nm(e)||e instanceof Fh))return e.map(e=>new N(M.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let t;qp(e)instanceof Fh&&(t=e.pop());let n=km(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=(eh(e)??``).toLowerCase();if(t!==vd.PK&&t!==vd.Unique){r.push(new N(M.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}i[t]===void 0?i[t]=[e]:i[t].push(e)});let a=i[vd.PK]||[],o=i[vd.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Yp(i,(e,t)=>{switch(t){case vd.Note:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{Am(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case vd.Ref:e.forEach(e=>{Dm(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case vd.PrimaryKey:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case vd.PK:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case vd.NotNull:{e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[vd.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new N(M.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case vd.Null:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case vd.Unique:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case vd.Increment:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case vd.Default:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Tm(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case vd.Check:e.forEach(e=>{e.value instanceof Mh||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new N(M.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),r}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(_d.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Tpe(e){let t=km(e),n=t.getErrors(),r=t.getValue();return Yp(r,(e,t)=>{switch(t){case vd.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case vd.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{Am(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)))}}),new k(r,n)}function Epe(e){if(!e.slice(0,-1).every(Nm)||!e.slice(-1).every(e=>Nm(e)||e instanceof Fh))return new k({},e.map(e=>new N(M.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new k({});let t;qp(e)instanceof Fh&&(t=e.pop());let n=km(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=(eh(e)??``).toLowerCase();if(t!==vd.PK&&t!==vd.Unique){r.push(new N(M.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}i[t]===void 0?i[t]=[e]:i[t].push(e)});let a=i[vd.PK]||[],o=i[vd.PrimaryKey]||[];return a.length>=1&&o.length>=1&&r.push(...[...a,...o].map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Yp(i,(e,t)=>{switch(t){case vd.Note:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{Am(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case vd.Ref:e.forEach(e=>{Dm(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case vd.PrimaryKey:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`primary key can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'primary key' must not have a value`,e.value||e.name))});break;case vd.PK:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'pk' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'pk' must not have a value`,e.value||e.name))});break;case vd.NotNull:{e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'not null' can only appear once`,e)));let t=i[vd.Null]||[];e.length>=1&&t.length>=1&&r.push(...[...e,...t].map(e=>new N(M.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'not null' must not have a value`,e.value||e.name))});break}case vd.Null:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'null' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'null' must not have a value`,e.value||e.name))});break;case vd.Unique:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'unique' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'unique' must not have a value`,e.value||e.name))});break;case vd.Increment:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'increment' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'increment' must not have a value`,e.value||e.name))});break;case vd.Default:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{Tm(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'default' must be an enum value, a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case vd.Check:e.forEach(e=>{e.value instanceof Mh||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>r.push(new N(M.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new k(i,r)}var Dpe={validateNode(e,t){return Im(t,_d.Table)?k.create(void 0,new wpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(Im(t,_d.Table)){if(!t.name)return new k(void 0,[new N(M.NAME_NOT_FOUND,`A Table must have a name`,t)]);if(t.name instanceof Gh)return new k(void 0,[new N(M.INVALID_NAME,`Invalid array as Table name, maybe you forget to add a space between the name and the setting list?`,t.name)]);let e=Jm(t.name);return e?.length===1&&e.unshift(pm),new k(e)}if(zm(t,_d.Table)){if(Sm(t.callee)){let e=eh(t.callee.expression);return new k(e?[e]:void 0)}let e=eh(t.callee);return new k(e?[e]:void 0)}return k.create(hd)},nodeAlias(e,t){return Im(t,_d.Table)?t.alias?bm(t.alias)?new k(eh(t.alias)):new k(void 0,[new N(M.INVALID_ALIAS,`Table aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,t.alias)]):new k(void 0):zm(t,_d.Table)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.Table)?t.attributeList?Tpe(t.attributeList):new k({}):zm(t,_d.Table)?Epe(t.args.slice(1)):k.create(hd)}},Ope=class{constructor(e,t){this.declarationNode=t,this.compiler=e}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:xm(e)?[]:[new N(M.INVALID_NAME,`A TableGroup name must be a single identifier`,e)]:[new N(M.NAME_NOT_FOUND,`A TableGroup must have a name`,this.declarationNode)]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=km(e),n=t.getErrors(),r=t.getValue();for(let[e,t]of Object.entries(r))switch(e){case`color`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!Am(e.value)).forEach(e=>{n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))});break;default:n.push(...t.map(t=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return n}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&Jm(e.callee)===void 0&&t.push(new N(M.INVALID_TABLEGROUP_FIELD,`A TableGroup field must be of the form <table> or <schema>.<table>`,e.callee)),e.args.length>0&&t.push(...e.args.map(e=>new N(M.INVALID_TABLEGROUP_FIELD,`A TableGroup field should only have a single Table name`,e))),t})}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(_d.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function kpe(e){let t=km(e),n=t.getErrors(),r=t.getValue(),i={};for(let[e,t]of Object.entries(r))switch(e){case`color`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))}),i[e]=t;break;case`note`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),t.filter(e=>!Am(e.value)).forEach(e=>{n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'note' must be a string literal`,e.value||e.name))}),i[e]=t;break;default:n.push(...t.map(t=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${e}' setting`,t)));break}return new k(i,n)}var Ape={validateNode(e,t){return Im(t,_d.TableGroup)?k.create(void 0,new Ope(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(Im(t,_d.TableGroup))return t.name?xm(t.name)?new k(Jm(t.name)):new k(void 0,[new N(M.INVALID_NAME,`A TableGroup name must be a single identifier`,t.name)]):new k(void 0,[new N(M.NAME_NOT_FOUND,`A TableGroup must have a name`,t)]);if(zm(t,_d.TableGroup)){let e=Jm(t.callee);return e?.length===1&&e.unshift(pm),new k(e)}return k.create(hd)},nodeAlias(e,t){return Im(t,_d.TableGroup)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A TableGroup shouldn't have an alias`,t.alias)]):new k(void 0):zm(t,_d.TableGroup)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.TableGroup)?kpe(t.attributeList):zm(t,_d.TableGroup)?new k({}):k.create(hd)}},jpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)]}validateContext(){return this.declarationNode.parent instanceof Eh?[new N(M.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Vh?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:xm(e)?[]:[new N(M.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,e)]:[new N(M.NAME_NOT_FOUND,`A TablePartial must have a name`,this.declarationNode)]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,e)]:[]}validateSettingList(e){let t=km(e),n=t.getErrors();return Yp(t.getValue(),(e,t)=>{switch(t){case vd.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case vd.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Am(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new N(M.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),n}validateBody(e){if(!e)return[];if(e instanceof Nh)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=Zp(e.body,e=>e instanceof Nh);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=[];e.args.length===0&&t.push(new N(M.INVALID_COLUMN,`A column must have a type`,e.callee)),jm(e.callee)||t.push(new N(M.INVALID_COLUMN_NAME,`A column name must be an identifier or a quoted identifier`,e.callee)),e.args[0]&&!Coe(e.args[0])&&t.push(new N(M.INVALID_COLUMN_TYPE,`Invalid column type`,e.args[0]));let n=e.args.slice(1);return t.push(...this.validateFieldSetting(n)),t})}validateFieldSetting(e){let t=qp(e);if(!e.slice(0,-1).every(Nm)||!(Nm(t)||t instanceof Fh))return e.map(e=>new N(M.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e));if(e.length===0)return[];let n;qp(e)instanceof Fh&&(n=e.pop());let r=km(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=(eh(e)??``).toLowerCase();if(t!==vd.PK&&t!==vd.Unique){i.push(new N(M.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[vd.PK]||[],s=a[vd.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Yp(a,(e,t)=>{switch(t){case vd.Note:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Am(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case vd.Ref:e.forEach(e=>{Dm(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case vd.PrimaryKey:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.PK:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.NotNull:{e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[vd.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new N(M.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case vd.Null:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Unique:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Increment:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Default:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Tm(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case vd.Check:e.forEach(e=>{e.value instanceof Mh||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new N(M.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),i}validateSubElements(e){let t=e.flatMap(e=>e.type?this.compiler.validateNode(e).getErrors():[]),n=e.filter(e=>e.isKind(_d.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Mpe(e){let t=km(e),n=t.getErrors(),r=t.getValue();return Yp(r,(e,t)=>{switch(t){case vd.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{wm(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case vd.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_PARTIAL_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Am(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a string literal`,e.value||e.name))});break;default:n.push(...e.map(e=>new N(M.UNKNOWN_TABLE_PARTIAL_SETTING,`Unknown '${t}' setting`,e)))}}),new k(r,n)}function Npe(e){let t=qp(e);if(e.length>0&&(!e.slice(0,-1).every(Nm)||!(Nm(t)||t instanceof Fh)))return new k({},e.map(e=>new N(M.INVALID_COLUMN,`These fields must be some inline settings optionally ended with a setting list`,e)));if(e.length===0)return new k({});let n;qp(e)instanceof Fh&&(n=e.pop());let r=km(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=(eh(e)??``).toLowerCase();if(t!==vd.PK&&t!==vd.Unique){i.push(new N(M.INVALID_SETTINGS,"Inline column settings can only be `pk` or `unique`",e));return}a[t]===void 0?a[t]=[e]:a[t].push(e)});let o=a[vd.PK]||[],s=a[vd.PrimaryKey]||[];return o.length>=1&&s.length>=1&&i.push(...[...o,...s].map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`Either one of 'primary key' and 'pk' can appear`,e))),Yp(a,(e,t)=>{switch(t){case vd.Note:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Am(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case vd.Ref:e.forEach(e=>{Dm(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case vd.PrimaryKey:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.PK:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.NotNull:{e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[vd.Null]||[];e.length>=1&&n.length>=1&&i.push(...[...e,...n].map(e=>new N(M.CONFLICTING_SETTING,`'not null' and 'null' can not be set at the same time`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break}case vd.Null:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Unique:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Increment:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{e instanceof Oh&&e.value!==void 0&&i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must not have a value`,e.value||e.name))});break;case vd.Default:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{Tm(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a string literal, number literal, function expression, true, false or null`,e.value||e.name))});break;case vd.Check:e.forEach(e=>{e.value instanceof Mh||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'check' must be a function expression`,e.value||e.name))});break;default:e.forEach(e=>i.push(new N(M.UNKNOWN_COLUMN_SETTING,`Unknown column setting '${t}'`,e)))}}),new k(a,i)}var Ppe={validateNode(e,t){return Im(t,_d.TablePartial)?k.create(void 0,new jpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(Im(t,_d.TablePartial))return t.name?xm(t.name)?new k(Jm(t.name)):new k(void 0,[new N(M.INVALID_NAME,`A TablePartial name must be an identifier or a quoted identifer`,t.name)]):new k(void 0,[new N(M.NAME_NOT_FOUND,`A TablePartial must have a name`,t)]);if(zm(t,_d.TablePartial)){let e=eh(t.callee);return new k(e?[e]:void 0)}return k.create(hd)},nodeAlias(e,t){return Im(t,_d.TablePartial)?t.alias?new k(void 0,[new N(M.UNEXPECTED_ALIAS,`A TablePartial shouldn't have an alias`,t.alias)]):new k(eh(t.alias)):zm(t,_d.TablePartial)?new k(void 0):k.create(hd)},nodeSettings(e,t){return Im(t,_d.TablePartial)?Mpe(t.attributeList):zm(t,_d.TablePartial)?Npe(t.args.slice(1)):k.create(hd)}},Fpe=class{constructor(e,t){this.compiler=e,this.declarationNode=t}validate(){return[...this.validateContext(),...this.validateBody()]}validateContext(){return this.declarationNode.parent instanceof Sh?[]:[new N(M.INVALID_USE_CONTEXT,`'use' must appear at the top level`,this.declarationNode)]}validateBody(){let e=[];if(this.declarationNode.importPath&&!um.isRelative(this.declarationNode.importPath.value)&&e.push(new N(M.INVALID_USE_SPECIFIER_NAME,`Import path must be a relative path (starting with './' or '../')`,this.declarationNode.importPath)),this.declarationNode.specifiers instanceof Vh)return[];for(let t of this.declarationNode.specifiers?.specifiers||[])e.push(...this.validateSpecifier(t));return e}validateSpecifier(e){let t=[];return e.importKind===void 0?t.push(new N(M.INVALID_USE_SPECIFIER_KIND,`A use specifier must have a type (e.g. table, enum)`,e)):e.isKind(...Object.values(lh))||t.push(new N(M.INVALID_USE_SPECIFIER_KIND,`'${e.importKind.value}' is not a valid specifier type`,e.importKind)),[...t,...this.compiler.nodeFullname(e).getErrors(),...this.compiler.nodeAlias(e).getErrors()]}},Ipe=[Dpe,lpe,ype,dpe,rpe,Cpe,_pe,Ape,Ppe,ppe,spe,hpe,{validateNode(e,t){return t instanceof Ch?k.create(void 0,new Fpe(e,t).validate()):k.create(hd)},nodeFullname(e,t){if(!Lm(t))return k.create(hd);let n=Jm(t.name);return!n||n.length===0?k.create(void 0,[new N(M.INVALID_NAME,`Use specifiers must have a valid name (simple name or schema-qualified name)`,t)]):t.isKind(lh.TableGroup)&&n.length>1?k.create(n,[new N(M.INVALID_USE_SPECIFIER_NAME,`A TableGroup name must be a simple name`,t)]):t.isKind(lh.TablePartial)&&n.length>1?k.create(n,[new N(M.INVALID_USE_SPECIFIER_NAME,`A TablePartial name must be a simple name`,t)]):t.isKind(lh.Note)&&n.length>1?k.create(n,[new N(M.INVALID_USE_SPECIFIER_NAME,`A Sticky note name must be a simple name`,t)]):(n.length===1&&!t.isKind(lh.Schema)&&n.unshift(pm),new k(n))},nodeAlias(e,t){return Lm(t)?t.alias?bm(t.alias)?new k(eh(t.alias)):new k(void 0,[new N(M.INVALID_ALIAS,`Use aliases can only contain alphanumeric and underscore unless surrounded by double quotes`,t.alias)]):new k(void 0):k.create(hd)},nodeSettings(e,t){return t instanceof Ch?k.create({}):k.create(hd)}},ape];function xv(e,...t){for(let n of Ipe){let r=n[e];if(r){let e=r(...t);if(!e.hasValue(hd))return e}}return k.create(hd)}function Lpe(e){let t=xv(`validateNode`,this,e);return t.hasValue(hd)?k.create(gd):t}function Rpe(e){let t=xv(`nodeSettings`,this,e);return t.hasValue(hd)?k.create(gd):t}function zpe(e){let t=xv(`nodeFullname`,this,e);return t.hasValue(hd)?k.create(gd):t}function Bpe(e){let t=xv(`nodeAlias`,this,e);return t.hasValue(hd)?k.create(gd):t}var Vpe=typeof document<`u`&&document.location&&document.location.hash.indexOf(`pseudo=true`)>=0;function Hpe(e,t){let n;return n=t.length===0?e:e.replace(/\{(\d+)\}/g,(e,n)=>{let r=t[n[0]],i=e;return typeof r==`string`?i=r:(typeof r==`number`||typeof r==`boolean`||r==null)&&(i=String(r)),i}),Vpe&&(n=`[`+n.replace(/[aouei]/g,`$&$&`)+`]`),n}function Upe(e,t,...n){return Hpe(t,n)}var Wpe=!1,Gpe=!1,Kpe=!1,qpe=!1,Sv=void 0,Cv=typeof self==`object`?self:typeof global==`object`?global:{},wv=void 0;Cv.vscode!==void 0&&Cv.vscode.process!==void 0?wv=Cv.vscode.process:typeof process<`u`&&(wv=process);var Jpe=typeof wv?.versions?.electron==`string`&&wv?.type===`renderer`;if(typeof navigator==`object`&&!Jpe)Sv=navigator.userAgent,Wpe=Sv.indexOf(`Windows`)>=0,Gpe=Sv.indexOf(`Macintosh`)>=0,(Sv.indexOf(`Macintosh`)>=0||Sv.indexOf(`iPad`)>=0||Sv.indexOf(`iPhone`)>=0)&&navigator.maxTouchPoints&&navigator.maxTouchPoints,Kpe=Sv.indexOf(`Linux`)>=0,Sv?.indexOf(`Mobi`),qpe=!0,Upe({key:`ensureLoaderPluginIsLoaded`,comment:[`{Locked}`]},`_`),navigator.language;else if(typeof wv==`object`){Wpe=wv.platform===`win32`,Gpe=wv.platform===`darwin`,Kpe=wv.platform===`linux`,Kpe&&wv.env.SNAP&&wv.env.SNAP_REVISION,wv.env.CI||wv.env.BUILD_ARTIFACTSTAGINGDIRECTORY;let e=wv.env.VSCODE_NLS_CONFIG;if(e)try{let t=JSON.parse(e);t.availableLanguages[`*`],t.locale,t.osLocale,t._translationsConfigFile}catch{}}else console.error(`Unable to resolve platform.`);var Tv=Wpe,Ype=Gpe;qpe&&Cv.importScripts;var Ev=Sv,Xpe=typeof Cv.postMessage==`function`&&!Cv.importScripts;(()=>{if(Xpe){let e=[];Cv.addEventListener(`message`,t=>{if(t.data&&t.data.vscodeScheduleAsyncWork)for(let n=0,r=e.length;n<r;n++){let r=e[n];if(r.id===t.data.vscodeScheduleAsyncWork){e.splice(n,1),r.callback();return}}});let t=0;return n=>{let r=++t;e.push({id:r,callback:n}),Cv.postMessage({vscodeScheduleAsyncWork:r},`*`)}}return e=>setTimeout(e)})();var Zpe=!!(Ev&&Ev.indexOf(`Chrome`)>=0);Ev&&Ev.indexOf(`Firefox`),!Zpe&&Ev&&Ev.indexOf(`Safari`),Ev&&Ev.indexOf(`Edg/`),Ev&&Ev.indexOf(`Android`);var Dv;if(Cv.vscode!==void 0&&Cv.vscode.process!==void 0){let e=Cv.vscode.process;Dv={get platform(){return e.platform},get arch(){return e.arch},get env(){return e.env},cwd(){return e.cwd()}}}else Dv=typeof process<`u`?{get platform(){return process.platform},get arch(){return process.arch},get env(){return process.env},cwd(){return process.env.VSCODE_CWD||process.cwd()}}:{get platform(){return Tv?`win32`:Ype?`darwin`:`linux`},get arch(){},get env(){return{}},cwd(){return`/`}};var Ov=Dv.cwd,Qpe=Dv.env,$pe=Dv.platform,eme=65,tme=97,nme=90,rme=122,kv=46,Av=47,jv=92,Mv=58,ime=63,ame=class extends Error{constructor(e,t,n){let r;typeof t==`string`&&t.indexOf(`not `)===0?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;let i=`The "${e}" ${e.indexOf(`.`)===-1?`argument`:`property`} ${r} of type ${t}`;i+=`. Received type ${typeof n}`,super(i),this.code=`ERR_INVALID_ARG_TYPE`}};function ome(e,t){if(typeof e!=`object`||!e)throw new ame(t,`Object`,e)}function Nv(e,t){if(typeof e!=`string`)throw new ame(t,`string`,e)}var Pv=$pe===`win32`;function Fv(e){return e===Av||e===jv}function sme(e){return e===Av}function Iv(e){return e>=eme&&e<=nme||e>=tme&&e<=rme}function Lv(e,t,n,r){let i=``,a=0,o=-1,s=0,c=0;for(let l=0;l<=e.length;++l){if(l<e.length)c=e.charCodeAt(l);else if(r(c))break;else c=Av;if(r(c)){if(!(o===l-1||s===1))if(s===2){if(i.length<2||a!==2||i.charCodeAt(i.length-1)!==kv||i.charCodeAt(i.length-2)!==kv){if(i.length>2){let e=i.lastIndexOf(n);e===-1?(i=``,a=0):(i=i.slice(0,e),a=i.length-1-i.lastIndexOf(n)),o=l,s=0;continue}else if(i.length!==0){i=``,a=0,o=l,s=0;continue}}t&&(i+=i.length>0?`${n}..`:`..`,a=2)}else i.length>0?i+=`${n}${e.slice(o+1,l)}`:i=e.slice(o+1,l),a=l-o-1;o=l,s=0}else c===kv&&s!==-1?++s:s=-1}return i}function cme(e,t){ome(t,`pathObject`);let n=t.dir||t.root,r=t.base||`${t.name||``}${t.ext||``}`;return n?n===t.root?`${n}${r}`:`${n}${e}${r}`:r}var Rv={resolve(...e){let t=``,n=``,r=!1;for(let i=e.length-1;i>=-1;i--){let a;if(i>=0){if(a=e[i],Nv(a,`path`),a.length===0)continue}else t.length===0?a=Ov():(a=Qpe[`=${t}`]||Ov(),(a===void 0||a.slice(0,2).toLowerCase()!==t.toLowerCase()&&a.charCodeAt(2)===jv)&&(a=`${t}\\`));let o=a.length,s=0,c=``,l=!1,u=a.charCodeAt(0);if(o===1)Fv(u)&&(s=1,l=!0);else if(Fv(u))if(l=!0,Fv(a.charCodeAt(1))){let e=2,t=e;for(;e<o&&!Fv(a.charCodeAt(e));)e++;if(e<o&&e!==t){let n=a.slice(t,e);for(t=e;e<o&&Fv(a.charCodeAt(e));)e++;if(e<o&&e!==t){for(t=e;e<o&&!Fv(a.charCodeAt(e));)e++;(e===o||e!==t)&&(c=`\\\\${n}\\${a.slice(t,e)}`,s=e)}}}else s=1;else Iv(u)&&a.charCodeAt(1)===Mv&&(c=a.slice(0,2),s=2,o>2&&Fv(a.charCodeAt(2))&&(l=!0,s=3));if(c.length>0)if(t.length>0){if(c.toLowerCase()!==t.toLowerCase())continue}else t=c;if(r){if(t.length>0)break}else if(n=`${a.slice(s)}\\${n}`,r=l,l&&t.length>0)break}return n=Lv(n,!r,`\\`,Fv),r?`${t}\\${n}`:`${t}${n}`||`.`},normalize(e){Nv(e,`path`);let t=e.length;if(t===0)return`.`;let n=0,r,i=!1,a=e.charCodeAt(0);if(t===1)return sme(a)?`\\`:e;if(Fv(a))if(i=!0,Fv(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!Fv(e.charCodeAt(i));)i++;if(i<t&&i!==a){let o=e.slice(a,i);for(a=i;i<t&&Fv(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!Fv(e.charCodeAt(i));)i++;if(i===t)return`\\\\${o}\\${e.slice(a)}\\`;i!==a&&(r=`\\\\${o}\\${e.slice(a,i)}`,n=i)}}}else n=1;else Iv(a)&&e.charCodeAt(1)===Mv&&(r=e.slice(0,2),n=2,t>2&&Fv(e.charCodeAt(2))&&(i=!0,n=3));let o=n<t?Lv(e.slice(n),!i,`\\`,Fv):``;return o.length===0&&!i&&(o=`.`),o.length>0&&Fv(e.charCodeAt(t-1))&&(o+=`\\`),r===void 0?i?`\\${o}`:o:i?`${r}\\${o}`:`${r}${o}`},isAbsolute(e){Nv(e,`path`);let t=e.length;if(t===0)return!1;let n=e.charCodeAt(0);return Fv(n)||t>2&&Iv(n)&&e.charCodeAt(1)===Mv&&Fv(e.charCodeAt(2))},join(...e){if(e.length===0)return`.`;let t,n;for(let r=0;r<e.length;++r){let i=e[r];Nv(i,`path`),i.length>0&&(t===void 0?t=n=i:t+=`\\${i}`)}if(t===void 0)return`.`;let r=!0,i=0;if(typeof n==`string`&&Fv(n.charCodeAt(0))){++i;let e=n.length;e>1&&Fv(n.charCodeAt(1))&&(++i,e>2&&(Fv(n.charCodeAt(2))?++i:r=!1))}if(r){for(;i<t.length&&Fv(t.charCodeAt(i));)i++;i>=2&&(t=`\\${t.slice(i)}`)}return Rv.normalize(t)},relative(e,t){if(Nv(e,`from`),Nv(t,`to`),e===t)return``;let n=Rv.resolve(e),r=Rv.resolve(t);if(n===r||(e=n.toLowerCase(),t=r.toLowerCase(),e===t))return``;let i=0;for(;i<e.length&&e.charCodeAt(i)===jv;)i++;let a=e.length;for(;a-1>i&&e.charCodeAt(a-1)===jv;)a--;let o=a-i,s=0;for(;s<t.length&&t.charCodeAt(s)===jv;)s++;let c=t.length;for(;c-1>s&&t.charCodeAt(c-1)===jv;)c--;let l=c-s,u=o<l?o:l,d=-1,f=0;for(;f<u;f++){let n=e.charCodeAt(i+f);if(n!==t.charCodeAt(s+f))break;n===jv&&(d=f)}if(f!==u){if(d===-1)return r}else{if(l>u){if(t.charCodeAt(s+f)===jv)return r.slice(s+f+1);if(f===2)return r.slice(s+f)}o>u&&(e.charCodeAt(i+f)===jv?d=f:f===2&&(d=3)),d===-1&&(d=0)}let p=``;for(f=i+d+1;f<=a;++f)(f===a||e.charCodeAt(f)===jv)&&(p+=p.length===0?`..`:`\\..`);return s+=d,p.length>0?`${p}${r.slice(s,c)}`:(r.charCodeAt(s)===jv&&++s,r.slice(s,c))},toNamespacedPath(e){if(typeof e!=`string`||e.length===0)return e;let t=Rv.resolve(e);if(t.length<=2)return e;if(t.charCodeAt(0)===jv){if(t.charCodeAt(1)===jv){let e=t.charCodeAt(2);if(e!==ime&&e!==kv)return`\\\\?\\UNC\\${t.slice(2)}`}}else if(Iv(t.charCodeAt(0))&&t.charCodeAt(1)===Mv&&t.charCodeAt(2)===jv)return`\\\\?\\${t}`;return e},dirname(e){Nv(e,`path`);let t=e.length;if(t===0)return`.`;let n=-1,r=0,i=e.charCodeAt(0);if(t===1)return Fv(i)?e:`.`;if(Fv(i)){if(n=r=1,Fv(e.charCodeAt(1))){let i=2,a=i;for(;i<t&&!Fv(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&Fv(e.charCodeAt(i));)i++;if(i<t&&i!==a){for(a=i;i<t&&!Fv(e.charCodeAt(i));)i++;if(i===t)return e;i!==a&&(n=r=i+1)}}}}else Iv(i)&&e.charCodeAt(1)===Mv&&(n=t>2&&Fv(e.charCodeAt(2))?3:2,r=n);let a=-1,o=!0;for(let n=t-1;n>=r;--n)if(Fv(e.charCodeAt(n))){if(!o){a=n;break}}else o=!1;if(a===-1){if(n===-1)return`.`;a=n}return e.slice(0,a)},basename(e,t){t!==void 0&&Nv(t,`ext`),Nv(e,`path`);let n=0,r=-1,i=!0,a;if(e.length>=2&&Iv(e.charCodeAt(0))&&e.charCodeAt(1)===Mv&&(n=2),t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=n;--a){let c=e.charCodeAt(a);if(Fv(c)){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=n;--a)if(Fv(e.charCodeAt(a))){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Nv(e,`path`);let t=0,n=-1,r=0,i=-1,a=!0,o=0;e.length>=2&&e.charCodeAt(1)===Mv&&Iv(e.charCodeAt(0))&&(t=r=2);for(let s=e.length-1;s>=t;--s){let t=e.charCodeAt(s);if(Fv(t)){if(!a){r=s+1;break}continue}i===-1&&(a=!1,i=s+1),t===kv?n===-1?n=s:o!==1&&(o=1):n!==-1&&(o=-1)}return n===-1||i===-1||o===0||o===1&&n===i-1&&n===r+1?``:e.slice(n,i)},format:cme.bind(null,`\\`),parse(e){Nv(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.length,r=0,i=e.charCodeAt(0);if(n===1)return Fv(i)?(t.root=t.dir=e,t):(t.base=t.name=e,t);if(Fv(i)){if(r=1,Fv(e.charCodeAt(1))){let t=2,i=t;for(;t<n&&!Fv(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&Fv(e.charCodeAt(t));)t++;if(t<n&&t!==i){for(i=t;t<n&&!Fv(e.charCodeAt(t));)t++;t===n?r=t:t!==i&&(r=t+1)}}}}else if(Iv(i)&&e.charCodeAt(1)===Mv){if(n<=2)return t.root=t.dir=e,t;if(r=2,Fv(e.charCodeAt(2))){if(n===3)return t.root=t.dir=e,t;r=3}}r>0&&(t.root=e.slice(0,r));let a=-1,o=r,s=-1,c=!0,l=e.length-1,u=0;for(;l>=r;--l){if(i=e.charCodeAt(l),Fv(i)){if(!c){o=l+1;break}continue}s===-1&&(c=!1,s=l+1),i===kv?a===-1?a=l:u!==1&&(u=1):a!==-1&&(u=-1)}return s!==-1&&(a===-1||u===0||u===1&&a===s-1&&a===o+1?t.base=t.name=e.slice(o,s):(t.name=e.slice(o,a),t.base=e.slice(o,s),t.ext=e.slice(a,s))),o>0&&o!==r?t.dir=e.slice(0,o-1):t.dir=t.root,t},sep:`\\`,delimiter:`;`,win32:null,posix:null},lme=(()=>{if(Pv){let e=/\\/g;return()=>{let t=Ov().replace(e,`/`);return t.slice(t.indexOf(`/`))}}return()=>Ov()})(),zv={resolve(...e){let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:lme();Nv(i,`path`),i.length!==0&&(t=`${i}/${t}`,n=i.charCodeAt(0)===Av)}return t=Lv(t,!n,`/`,sme),n?`/${t}`:t.length>0?t:`.`},normalize(e){if(Nv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Av,n=e.charCodeAt(e.length-1)===Av;return e=Lv(e,!t,`/`,sme),e.length===0?t?`/`:n?`./`:`.`:(n&&(e+=`/`),t?`/${e}`:e)},isAbsolute(e){return Nv(e,`path`),e.length>0&&e.charCodeAt(0)===Av},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];Nv(r,`path`),r.length>0&&(t===void 0?t=r:t+=`/${r}`)}return t===void 0?`.`:zv.normalize(t)},relative(e,t){if(Nv(e,`from`),Nv(t,`to`),e===t||(e=zv.resolve(e),t=zv.resolve(t),e===t))return``;let n=e.length,r=n-1,i=t.length-1,a=r<i?r:i,o=-1,s=0;for(;s<a;s++){let n=e.charCodeAt(1+s);if(n!==t.charCodeAt(1+s))break;n===Av&&(o=s)}if(s===a)if(i>a){if(t.charCodeAt(1+s)===Av)return t.slice(1+s+1);if(s===0)return t.slice(1+s)}else r>a&&(e.charCodeAt(1+s)===Av?o=s:s===0&&(o=0));let c=``;for(s=1+o+1;s<=n;++s)(s===n||e.charCodeAt(s)===Av)&&(c+=c.length===0?`..`:`/..`);return`${c}${t.slice(1+o)}`},toNamespacedPath(e){return e},dirname(e){if(Nv(e,`path`),e.length===0)return`.`;let t=e.charCodeAt(0)===Av,n=-1,r=!0;for(let t=e.length-1;t>=1;--t)if(e.charCodeAt(t)===Av){if(!r){n=t;break}}else r=!1;return n===-1?t?`/`:`.`:t&&n===1?`//`:e.slice(0,n)},basename(e,t){t!==void 0&&Nv(t,`ext`),Nv(e,`path`);let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===Av){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===Av){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){Nv(e,`path`);let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===Av){if(!i){n=o+1;break}continue}r===-1&&(i=!1,r=o+1),s===kv?t===-1?t=o:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||r===-1||a===0||a===1&&t===r-1&&t===n+1?``:e.slice(t,r)},format:cme.bind(null,`/`),parse(e){Nv(e,`path`);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;let n=e.charCodeAt(0)===Av,r;n?(t.root=`/`,r=1):r=0;let i=-1,a=0,o=-1,s=!0,c=e.length-1,l=0;for(;c>=r;--c){let t=e.charCodeAt(c);if(t===Av){if(!s){a=c+1;break}continue}o===-1&&(s=!1,o=c+1),t===kv?i===-1?i=c:l!==1&&(l=1):i!==-1&&(l=-1)}if(o!==-1){let r=a===0&&n?1:a;i===-1||l===0||l===1&&i===o-1&&i===a+1?t.base=t.name=e.slice(r,o):(t.name=e.slice(r,i),t.base=e.slice(r,o),t.ext=e.slice(i,o))}return a>0?t.dir=e.slice(0,a-1):n&&(t.dir=`/`),t},sep:`/`,delimiter:`:`,win32:null,posix:null};zv.win32=Rv.win32=Rv,zv.posix=Rv.posix=zv,Pv?Rv.normalize:zv.normalize,Pv?Rv.resolve:zv.resolve,Pv?Rv.relative:zv.relative,Pv?Rv.dirname:zv.dirname,Pv?Rv.basename:zv.basename,Pv?Rv.extname:zv.extname,Pv?Rv.sep:zv.sep;var ume=/^\w[\w\d+.-]*$/,dme=/^\//,fme=/^\/\//;function pme(e,t){if(!e.scheme&&t)throw Error(`[UriError]: Scheme is missing: {scheme: "", authority: "${e.authority}", path: "${e.path}", query: "${e.query}", fragment: "${e.fragment}"}`);if(e.scheme&&!ume.test(e.scheme))throw Error(`[UriError]: Scheme contains illegal characters.`);if(e.path){if(e.authority){if(!dme.test(e.path))throw Error(`[UriError]: If a URI contains an authority component, then the path component must either be empty or begin with a slash ("/") character`)}else if(fme.test(e.path))throw Error(`[UriError]: If a URI does not contain an authority component, then the path cannot begin with two slash characters ("//")`)}}function mme(e,t){return!e&&!t?`file`:e}function hme(e,t){switch(e){case`https`:case`http`:case`file`:t?t[0]!==Vv&&(t=Vv+t):t=Vv;break}return t}var Bv=``,Vv=`/`,gme=/^(([^:/?#]+?):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/,_me=class e{static isUri(t){return t instanceof e?!0:t?typeof t.authority==`string`&&typeof t.fragment==`string`&&typeof t.path==`string`&&typeof t.query==`string`&&typeof t.scheme==`string`&&typeof t.fsPath==`string`&&typeof t.with==`function`&&typeof t.toString==`function`:!1}constructor(e,t,n,r,i,a=!1){typeof e==`object`?(this.scheme=e.scheme||Bv,this.authority=e.authority||Bv,this.path=e.path||Bv,this.query=e.query||Bv,this.fragment=e.fragment||Bv):(this.scheme=mme(e,a),this.authority=t||Bv,this.path=hme(this.scheme,n||Bv),this.query=r||Bv,this.fragment=i||Bv,pme(this,a))}get fsPath(){return Sme(this,!1)}with(e){if(!e)return this;let{scheme:t,authority:n,path:r,query:i,fragment:a}=e;return t===void 0?t=this.scheme:t===null&&(t=Bv),n===void 0?n=this.authority:n===null&&(n=Bv),r===void 0?r=this.path:r===null&&(r=Bv),i===void 0?i=this.query:i===null&&(i=Bv),a===void 0?a=this.fragment:a===null&&(a=Bv),t===this.scheme&&n===this.authority&&r===this.path&&i===this.query&&a===this.fragment?this:new Hv(t,n,r,i,a)}static parse(e,t=!1){let n=gme.exec(e);return n?new Hv(n[2]||Bv,Uv(n[4]||Bv),Uv(n[5]||Bv),Uv(n[7]||Bv),Uv(n[9]||Bv),t):new Hv(Bv,Bv,Bv,Bv,Bv)}static file(e){let t=Bv;if(Tv&&(e=e.replace(/\\/g,Vv)),e[0]===Vv&&e[1]===Vv){let n=e.indexOf(Vv,2);n===-1?(t=e.substring(2),e=Vv):(t=e.substring(2,n),e=e.substring(n)||Vv)}return new Hv(`file`,t,e,Bv,Bv)}static from(e,t){return new Hv(e.scheme,e.authority,e.path,e.query,e.fragment,t)}static joinPath(t,...n){if(!t.path)throw Error(`[UriError]: cannot call joinPath on URI without path`);let r;return r=Tv&&t.scheme===`file`?e.file(Rv.join(Sme(t,!0),...n)).path:zv.join(t.path,...n),t.with({path:r})}toString(e=!1){return Cme(this,e)}toJSON(){return this}static revive(t){if(t){if(t instanceof e)return t;{let e=new Hv(t);return e._formatted=t.external??null,e._fsPath=t._sep===vme?t.fsPath??null:null,e}}else return t}},vme=Tv?1:void 0,Hv=class extends _me{constructor(){super(...arguments),this._formatted=null,this._fsPath=null}get fsPath(){return this._fsPath||=Sme(this,!1),this._fsPath}toString(e=!1){return e?Cme(this,!0):(this._formatted||=Cme(this,!1),this._formatted)}toJSON(){let e={$mid:1};return this._fsPath&&(e.fsPath=this._fsPath,e._sep=vme),this._formatted&&(e.external=this._formatted),this.path&&(e.path=this.path),this.scheme&&(e.scheme=this.scheme),this.authority&&(e.authority=this.authority),this.query&&(e.query=this.query),this.fragment&&(e.fragment=this.fragment),e}},yme={58:`%3A`,47:`%2F`,63:`%3F`,35:`%23`,91:`%5B`,93:`%5D`,64:`%40`,33:`%21`,36:`%24`,38:`%26`,39:`%27`,40:`%28`,41:`%29`,42:`%2A`,43:`%2B`,44:`%2C`,59:`%3B`,61:`%3D`,32:`%20`};function bme(e,t,n){let r,i=-1;for(let a=0;a<e.length;a++){let o=e.charCodeAt(a);if(o>=97&&o<=122||o>=65&&o<=90||o>=48&&o<=57||o===45||o===46||o===95||o===126||t&&o===47||n&&o===91||n&&o===93||n&&o===58)i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r!==void 0&&(r+=e.charAt(a));else{r===void 0&&(r=e.substr(0,a));let t=yme[o];t===void 0?i===-1&&(i=a):(i!==-1&&(r+=encodeURIComponent(e.substring(i,a)),i=-1),r+=t)}}return i!==-1&&(r+=encodeURIComponent(e.substring(i))),r===void 0?e:r}function xme(e){let t;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);r===35||r===63?(t===void 0&&(t=e.substr(0,n)),t+=yme[r]):t!==void 0&&(t+=e[n])}return t===void 0?e:t}function Sme(e,t){let n;return n=e.authority&&e.path.length>1&&e.scheme===`file`?`//${e.authority}${e.path}`:e.path.charCodeAt(0)===47&&(e.path.charCodeAt(1)>=65&&e.path.charCodeAt(1)<=90||e.path.charCodeAt(1)>=97&&e.path.charCodeAt(1)<=122)&&e.path.charCodeAt(2)===58?t?e.path.substr(1):e.path[1].toLowerCase()+e.path.substr(2):e.path,Tv&&(n=n.replace(/\//g,`\\`)),n}function Cme(e,t){let n=t?xme:bme,r=``,{scheme:i,authority:a,path:o,query:s,fragment:c}=e;if(i&&(r+=i,r+=`:`),(a||i===`file`)&&(r+=Vv,r+=Vv),a){let e=a.indexOf(`@`);if(e!==-1){let t=a.substr(0,e);a=a.substr(e+1),e=t.lastIndexOf(`:`),e===-1?r+=n(t,!1,!1):(r+=n(t.substr(0,e),!1,!1),r+=`:`,r+=n(t.substr(e+1),!1,!0)),r+=`@`}a=a.toLowerCase(),e=a.lastIndexOf(`:`),e===-1?r+=n(a,!1,!0):(r+=n(a.substr(0,e),!1,!0),r+=a.substr(e))}if(o){if(o.length>=3&&o.charCodeAt(0)===47&&o.charCodeAt(2)===58){let e=o.charCodeAt(1);e>=65&&e<=90&&(o=`/${String.fromCharCode(e+32)}:${o.substr(3)}`)}else if(o.length>=2&&o.charCodeAt(1)===58){let e=o.charCodeAt(0);e>=65&&e<=90&&(o=`${String.fromCharCode(e+32)}:${o.substr(2)}`)}r+=n(o,!0,!1)}return s&&(r+=`?`,r+=n(s,!1,!1)),c&&(r+=`#`,r+=t?c:bme(c,!1,!1)),r}function wme(e){try{return decodeURIComponent(e)}catch{return e.length>3?e.substr(0,3)+wme(e.substr(3)):e}}var Tme=/(%[0-9A-Za-z][0-9A-Za-z])+/g;function Uv(e){return e.match(Tme)?e.replace(Tme,e=>wme(e)):e}var Wv=function(e){return e[e.Function=1]=`Function`,e[e.Constructor=2]=`Constructor`,e[e.Field=3]=`Field`,e[e.Variable=4]=`Variable`,e[e.Class=5]=`Class`,e[e.Struct=6]=`Struct`,e[e.Interface=7]=`Interface`,e[e.Module=8]=`Module`,e[e.Property=9]=`Property`,e[e.Event=10]=`Event`,e[e.Operator=11]=`Operator`,e[e.Unit=12]=`Unit`,e[e.Value=13]=`Value`,e[e.Constant=14]=`Constant`,e[e.Enum=15]=`Enum`,e[e.EnumMember=16]=`EnumMember`,e[e.Keyword=17]=`Keyword`,e[e.Text=18]=`Text`,e[e.Color=19]=`Color`,e[e.File=20]=`File`,e[e.Reference=21]=`Reference`,e[e.Customcolor=22]=`Customcolor`,e[e.Folder=23]=`Folder`,e[e.TypeParameter=24]=`TypeParameter`,e[e.User=25]=`User`,e[e.Issue=26]=`Issue`,e[e.Snippet=27]=`Snippet`,e}({}),Gv=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),Eme=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});function Dme(e,t){return e.getOffsetAt(t)}function Ome(e,t){let{startPos:n,endPos:r}=t;return{startLineNumber:n.line+1,startColumn:n.column+1,endLineNumber:r.line+1,endColumn:r.column+1}}var kme=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=um.fromUri(String(e.uri)),i=Dme(e,t),a=[...this.compiler.container.stack(r,i)];for(;a.length!==0;){let e=a.pop();if(!e)continue;let t=this.compiler.nodeReferee(e);if(t.hasValue(gd))continue;let r=t.getValue();if(!r)continue;let i;if(r.declaration&&[xh.PRIMARY_EXPRESSION,xh.VARIABLE].includes(e.kind)&&({declaration:i}=r),i){let{startPos:e,endPos:t}=i,r=n;return n&&i.filepath&&(r=_me.parse(i.filepath.toUri())),[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:r}]}}return[]}},Ame=class{constructor(e){this.compiler=e}provideDiagnostics(e){return[...this.provideErrors(e),...this.provideWarnings(e)]}provideErrors(e){return e?this.compiler.parse.errors(e).map(e=>this.createDiagnostic(e,`error`)):this.compiler.interpretProject().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(e){return e?this.compiler.parse.warnings(e).map(e=>this.createDiagnostic(e,`warning`)):this.compiler.interpretProject().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(e){return this.provideDiagnostics(e).filter(t=>t.filepath.equals(e)).map(e=>({severity:this.getSeverityValue(e.type),message:e.text,startLineNumber:e.startRow,startColumn:e.startColumn,endLineNumber:e.endRow,endColumn:e.endColumn,code:e.code?String(e.code):void 0}))}createDiagnostic(e,t){let n=e.nodeOrToken,r=n.startPos,i=n.endPos;return{type:t,text:e.diagnostic,startRow:r.line+1,startColumn:r.column+1,endRow:i.line+1,endColumn:i.column+1,code:e.code,filepath:e.filepath}}getSeverityValue(e){return e===`error`?Eme.Error:Eme.Warning}},jme=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=um.fromUri(String(n)),i=Dme(e,t);this.compiler.bindProject();let a=[...this.compiler.container.stack(r,i)];for(;a.length!==0;){let e=a.pop();if(e&&[xh.ELEMENT_DECLARATION,xh.FUNCTION_APPLICATION,xh.PRIMARY_EXPRESSION].includes(e?.kind)){let t=this.compiler.nodeSymbol(e).getFiltered(gd)??this.compiler.nodeReferee(e).getFiltered(gd),r=t?this.compiler.symbolReferences(t):void 0;if(r&&r.length>0)return r.map(e=>{let t=n;return n&&e.filepath&&(t=_me.parse(e.filepath.toUri())),{range:{startColumn:e.startPos.column+1,startLineNumber:e.startPos.line+1,endColumn:e.endPos.column+1,endLineNumber:e.endPos.line+1},uri:t}})}}return[]}};function Kv(e,t){return e>=t.start&&e<t.end}function Mme(e,t){let n=t.bodyColon?.start??t.body?.start;return n===void 0?e>=t.start&&e<=t.end:e>=t.start&&e<n}function Nme(e,t,n){let r=[],i=e.parseFile(t).getValue()?.ast;if(!i)return r;for(let e of i.uses){let t=e.importPath?.value??``;if(!t){let r=e.useKeyword?.start??e.fullStart,i=n.lastIndexOf(`
7
7
  `,r-1)+1,a=n.indexOf(`
@@ -13,7 +13,7 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.
13
13
  `:`
14
14
  `}function zme(e,t){return e.relativeTo(t.dirname).replace(/\.dbml$/,``)}function qv(e){switch(e){case P.Schema:return Wv.Module;case P.Table:case P.TablePartial:return Wv.Class;case P.Column:case P.TableGroupField:return Wv.Field;case P.Enum:return Wv.Enum;case P.EnumField:return Wv.EnumMember;case P.TableGroup:return Wv.Struct;default:return Wv.Text}}function Jv(e,t){if(!e||rm(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===em.NEWLINE&&n.end<=t)return!1}return!0}function Yv(){return{suggestions:[]}}function Xv(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function Zv(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:gv(e.insertText??``),quoted:!0}))}}function Bme(e,t=`, `){let n=e.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label).join(t);return n?{...e,suggestions:[{label:`* (all)`,insertText:n,insertTextRules:Gv.KeepWhitespace,kind:Wv.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function Vme(e,t,n){let r=[],i=new Set,a=e.layout.getSource(n)??``;for(let o of e.layout.getEntryPoints()){if(o.equals(n))continue;let s=e.usableMembers(o).getFiltered(gd);if(s)for(let c of[...s.nonSchemaMembers,...s.schemaMembers]){if(!t.includes(c.kind))continue;let s=c.name;!s||i.has(s)||(i.add(s),r.push(Hme(e,s,c.kind,o,n,a)))}}return r}function Hme(e,t,n,r,i,a){let o=Pme(e,t,n,r,i,a),s=[];if(o.topInsert&&s.push({range:{startLineNumber:1,startColumn:1,endLineNumber:1,endColumn:1},text:o.topInsert}),o.removeRange){let e=Ume(a,o.removeRange.startOffset),t=Ume(a,o.removeRange.endOffset);s.push({range:{startLineNumber:e.line,startColumn:e.column,endLineNumber:t.line,endColumn:t.column},text:``})}return{label:t,insertText:t,insertTextRules:Gv.KeepWhitespace,kind:qv(n),detail:`from ${r.basename}`,sortText:`zzz_${qv(n).toString().padStart(2,`0`)}_${t}`,range:void 0,additionalTextEdits:s}}function Ume(e,t){let n=1,r=1;for(let i=0;i<t&&i<e.length;i++)e[i]===`
15
15
  `?(n++,r=1):r++;return{line:n,column:r}}function Wme(e,t,n,r,i){let a=e.container.element(r,i);return!(a instanceof Eh)||!a.isKind(_d.Records)||!(a.body instanceof Ph)||!a.body||!Kv(i,a.body)||t.getLineContent(n.lineNumber).trim()!==``?null:a.parent instanceof Sh?Gme(e,a):Kme(e,a)}function Gme(e,t){if(!(t.name instanceof zh))return Yv();let n=t.name.argumentList?.elementList||[],r=n.map(t=>e.nodeReferee(t).getFiltered(gd));if(!r||r.length===0)return Yv();let i=n.flatMap((t,n)=>{let i=r[n];if(!(i instanceof mh||i instanceof yh))return[];let{name:a}=i.canonicalName(e,t.filepath),{name:o}=i.type(e);return{name:a,type:o}});return i.length===0?Yv():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Gv.InsertAsSnippet,kind:Wv.Snippet,range:void 0}]}}function Kme(e,t){let n=t.parent;if(!(n instanceof Eh))return Yv();let r=e.nodeSymbol(n).getFiltered(gd);if(!(r instanceof ph))return Yv();let i;if(t.name instanceof Ih){let n=t.name.elementList,r=n.map(t=>e.nodeReferee(t).getFiltered(gd)).filter(e=>e!==void 0);i=n.flatMap((t,n)=>{let i=r[n];if(!(i instanceof mh||i instanceof yh))return[];let{name:a}=i.canonicalName(e,t.filepath),{name:o}=i.type(e);return{name:a,type:o}})}else{let t=r.mergedColumns(e).flatMap(t=>{let{name:n}=t.canonicalName(e,t.filepath),{name:r}=t.type(e);return{name:n,type:r}});if(!t)return Yv();i=t}return i.length===0?Yv():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Gv.InsertAsSnippet,kind:Wv.Snippet,range:void 0}]}}function qme(e,t,n,r,i){let a=e.parse.ast(t);for(let o of a.body)if(o instanceof Ch&&n>=o.start&&n<=o.fullEnd)return Jme(e,t,n,o,i,r);return null}function Jme(e,t,n,r,i,a){if(r.importPath&&Kv(n,r.importPath))return $me(e,t,r.importPath,i,r);if(r.fromKeyword&&n>r.fromKeyword.end)return $me(e,t,void 0,i,r);if(r.specifiers instanceof Th){if(!r.specifiers.openBrace){let e=Qme();return Jv(r.useKeyword,n)?Xv(e):e}return Yme(e,t,n,r.specifiers,r.importPath,a)}if(r.specifiers instanceof Vh)return Yv();let o=Qme();return Jv(r.useKeyword,n)?Xv(o):o}function Yme(e,t,n,r,i,a){for(let o of r.specifiers){let r=!Number.isNaN(o.start)&&n>=o.start&&n<=o.end,s=a===o.importKind||a===o.asKeyword;if(r||s){if(o.importKind&&n>o.importKind.end){let n=o.getSymbolKind();if(n!==void 0&&n!==P.Schema)return Zme(e,t,i,n)}return Xme()}}return Xme()}function Xme(){return{suggestions:Object.keys(lh).map(e=>({label:e.toLowerCase(),insertText:`${e.toLowerCase()} `,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))}}function Zme(e,t,n,r){if(!n)return Yv();let i=dm(t,n.value);if(!i)return Yv();let a=e.usableMembers(i).getFiltered(gd);if(!a)return Yv();let o=[];for(let e of a.nonSchemaMembers){if(e.kind!==r)continue;let t=e.name;t&&o.push(t)}for(let t of a.schemaMembers){if(t.isPublicSchema())continue;let n=t.name;if(!n)continue;let i=e.symbolMembers(t).getFiltered(gd)??[];for(let e of i){if(e.kind!==r)continue;let t=e.name;t&&o.push(`${n}.${t}`)}}return{suggestions:o.map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:qv(r),range:void 0}))}}function Qme(){return{suggestions:[{label:`* from`,detail:`import all`,insertText:"* from '${1:path}'",insertTextRules:Gv.InsertAsSnippet,kind:Wv.Snippet,range:void 0},{label:`{ } from`,detail:`import named`,insertText:"{ ${1:table} ${2:name} } from '${3:path}'",insertTextRules:Gv.InsertAsSnippet,kind:Wv.Snippet,range:void 0}]}}function $me(e,t,n,r,i){let a=t.dirname,o=n?n.value:`./`,s=n===void 0,c;if(n){let e=Ome(r,n);c={startLineNumber:e.startLineNumber,startColumn:e.startColumn+1,endLineNumber:e.endLineNumber,endColumn:e.endColumn-1}}let l=new Map,u=new Map,d=Qp(e.layout.getEntryPoints().flatMap(t=>[...e.reachableFiles(t)]),e=>e.intern());for(let n of d){if(n.equals(t))continue;let r=n.relativeTo(a);if(r.endsWith(`.dbml`)&&(r=r.slice(0,-5)),r.startsWith(`.`)||(r=`./${r}`),o&&!r.startsWith(o))continue;let d=`${o}${r.slice(o.length).split(`/`)[0]}`,f=um.resolve(a,d),p=e.layout.isDirectory(f);if(the(e,n,ehe(i))&&u.set(d,!0),l.has(d))continue;let m=s?`'${d}'`:d;l.set(d,{label:d,insertText:m,insertTextRules:Gv.KeepWhitespace,kind:p?Wv.Folder:Wv.File,sortText:`${p?`2`:`3`}${d}`,range:c})}for(let[e,t]of l)u.get(e)&&(t.sortText=`${t.kind===Wv.File?`0`:`1`}${e}`,t.detail=`best match`);return{suggestions:[...l.values()]}}function ehe(e){let t=e.specifiers;return t instanceof Th?t.specifiers.flatMap(e=>{let t=eh(e.name),n=e.importKind?.value.toLowerCase();return!t||!n?[]:[{name:t,kind:n}]}):[]}function the(e,t,n){if(n.length===0)return!1;let r=e.usableMembers(t).getFiltered(gd);return r?n.every(({name:e,kind:t})=>r.nonSchemaMembers.some(n=>n.kind===t&&n.name===e)):!1}var nhe=class{constructor(e,t={}){this.compiler=e,this.triggerCharacters=t.triggerCharacters??[]}provideCompletionItems(e,t){let n=um.fromUri(String(e.uri)),r=Dme(e,t),i=Wme(this.compiler,e,t,n,r);if(i!==null)return i;let a=this.compiler.token.flatStream(n),{token:o,index:s}=this.compiler.container.token(n,r),c=s===void 0?a[0]:a[s+1];if([...o?.trailingTrivia||[],...o?.leadingTrivia||[],...c?.leadingTrivia||[]].find(e=>noe(e)&&Kv(r,e)))return Yv();if(s===void 0)return phe();let l=qme(this.compiler,n,r,o,e);if(l!==null)return l;if([em.STRING_LITERAL,em.QUOTED_STRING].includes(o.kind)&&Kv(r,o))return Yv();let u=this.compiler.container.element(n,r);if(this.compiler.container.scopeKind(n,r)===ty.TOPLEVEL||u instanceof Eh&&u.type&&u.type.start<=r&&u.type.end>=r)return phe();let d=[...this.compiler.container.stack(n,r)].reverse();for(let e of d)if(e instanceof kh)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return ihe(this.compiler,n,r,e);case`~`:return rhe(this.compiler,n,r);default:}else if(e instanceof Ah)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return ihe(this.compiler,n,r,e);case`.`:return dhe(this.compiler,n,r,e);default:}else if(e instanceof Oh)return she(this.compiler,n,r,e);else if(e instanceof Fh)return she(this.compiler,n,r,e);else if(e instanceof Ih)return ahe(this.compiler,n,r,e);else if(e instanceof Lh)return ohe(this.compiler,n,r);else if(e instanceof zh)return yhe(this.compiler,n,r,e);else if(e instanceof Nh)return fhe(this.compiler,n,r,e);else if(e instanceof Eh){if(Mme(r,e))return vhe(this.compiler,n,r,e);if(e.bodyColon&&r>=e.bodyColon.end||e.body&&Kv(r,e.body))return fhe(this.compiler,n,r,void 0)}return Yv()}};function rhe(e,t,n){return $v(e,t,n,e.parse.ast(t),[P.TablePartial])}function ihe(e,t,n,r){let i=e.container.scopeKind(t,n);if([ty.REF,ty.TABLE,ty.TABLEPARTIAL].includes(i)){let i=$v(e,t,n,e.container.element(t,n),[P.Table,P.Schema,P.Column]);return Jv(r.op,n)?Xv(i):i}return Yv()}function Qv(e,t,n){let r=e.symbolMembers(t).getFiltered(gd);return r?Zv({suggestions:r.filter(e=>n.includes(e.kind)).filter(e=>!(e instanceof dh&&e.isPublicSchema())).flatMap(e=>{let n=e.name;if(n===void 0)return[];let r=e.originalFilepath,i=r&&!r.equals(t.filepath)?`from ${r.basename}`:`this file`;return{label:n,insertText:n,insertTextRules:Gv.KeepWhitespace,kind:qv(e.kind),sortText:qv(e.kind).toString().padStart(2,`0`),detail:i,range:void 0}}).filter(e=>e.label!==``)}):Yv()}function $v(e,t,n,r,i){if(r===void 0)return Yv();let a=r,o={suggestions:[]},s;for(;a;){a instanceof Sh&&(s=a);let t=e.nodeSymbol(a).getFiltered(gd);if(t){let n=Qv(e,t,i).suggestions,r=e=>{switch(e){case Wv.Field:return 0;case Wv.Module:return 1;case Wv.Class:return 2;default:return 3}};n.sort((e,t)=>r(e.kind)-r(t.kind)),o.suggestions.push(...n)}a=a instanceof Eh?a.parent:void 0}if(s?.filepath){let t=s.filepath,n=new Set(o.suggestions.map(e=>typeof e.label==`string`?e.label:e.label.label));for(let r of Vme(e,i,t)){let e=typeof r.label==`string`?r.label:r.label.label;n.has(e)||(n.add(e),o.suggestions.push(r))}}return Zv(o)}function ahe(e,t,n,r){let i=e.container.scopeKind(t,n),a=e.container.element(t,n),o=[...e.container.stack(t,n)];for(let i of o)if(i instanceof zh&&i.argumentList===r)return yhe(e,t,n,i);if(a instanceof Eh&&a.isKind(_d.Records)&&!(a.name instanceof zh)&&Mme(n,a)){let t=a.parent?e.nodeSymbol(a.parent).getFiltered(gd):void 0,n=a.name?e.nodeReferee(a.name).getFiltered(gd):void 0,i=t||n;if(i){let t=Qv(e,i,[P.Column]);return Gm(r)?Bme(t):t}}switch(i){case ty.INDEXES:return Che(e,t,n);case ty.REF:for(;o.length>0;){let r=o.pop();if(r instanceof Ah&&r.op?.value===`.`)return dhe(e,t,n,r)}return _he(e,t,n);default:break}return Yv()}function ohe(e,t,n){return e.container.scopeKind(t,n)===ty.RECORDS?$v(e,t,n,e.container.element(t,n),[P.Schema,P.Enum,P.EnumField]):Yv()}function she(e,t,n,r){let{token:i}=e.container.token(t,n);if([em.COMMA,em.LBRACKET].includes(i?.kind)){let r=che(e,t,n);return i?.kind===em.COMMA&&Jv(i,n)?Xv(r):r}if(r.name&&r.name.start<=n&&r.name.end>=n)return che(e,t,n);if(r.name instanceof Dh){let a=lhe(e,t,n,Wm(r.name)??``);return i?.kind===em.COLON&&Jv(i,n)?Xv(a):a}return Yv()}function che(e,t,n){let r=e.container.element(t,n);if(r instanceof Sh)return Yv();let i=e.container.scopeKind(t,n);if(r.body&&!Kv(n,r.body)){let e;switch(i){case ty.TABLE:case ty.TABLEPARTIAL:e=[vd.HeaderColor,vd.Note];break;case ty.TABLEGROUP:e=[vd.Color,vd.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:Wv.Field,insertTextRules:Gv.KeepWhitespace,range:void 0}))}}switch(i){case ty.TABLE:case ty.TABLEPARTIAL:return{suggestions:[...[vd.PK,vd.PrimaryKey,vd.Null,vd.NotNull,vd.Increment,vd.Unique].map(e=>({label:e,insertText:e,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0})),...[vd.Ref,vd.Default,vd.Note,vd.Check].map(e=>({label:e,insertText:`${e}: `,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0}))]};case ty.ENUM:return{suggestions:[...[vd.Note].map(e=>({label:e,insertText:`${e}: `,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0}))]};case ty.INDEXES:return{suggestions:[...[vd.Unique,vd.PK].map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Property,range:void 0})),...[vd.Note,vd.Name,vd.Type].map(e=>({label:e,insertText:`${e}: `,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0}))]};case ty.REF:return{suggestions:[vd.Update,vd.Delete,vd.Color].map(e=>({label:e,insertText:`${e}: `,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0}))};case ty.CHECKS:return{suggestions:[vd.Name].map(e=>({label:e,insertText:`${e}: `,kind:Wv.Property,insertTextRules:Gv.KeepWhitespace,range:void 0}))};default:break}return Yv()}function lhe(e,t,n,r){switch(r?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:Wv.Value,insertTextRules:Gv.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:Wv.Value,insertTextRules:Gv.KeepWhitespace,range:void 0}))};case`default`:return $v(e,t,n,e.container.element(t,n),[P.Schema,P.Enum]);default:break}return Yv()}function uhe(e,t,n){if(!n)return[];let r=[],i=n;for(;i;){let t=e.nodeSymbol(i).getFiltered(gd);if(t){let n=e.symbolMembers(t).getFiltered(gd);r.push(...n||[])}i=i instanceof Eh?i.parent:void 0}for(let e of t){let t=r.filter(t=>t.name===e);if(t.length===0)return[];r=t}return r}function dhe(e,t,n,r){let i=qm(r)??[];return i.pop(),i.some(e=>!jm(e))?Yv():Zv({suggestions:uhe(e,i.map(e=>eh(e)),e.container.element(t,n)).flatMap(t=>e.symbolMembers(t).getFiltered(gd)||[]).flatMap(e=>{let t=e.name;return t===void 0?[]:{label:t,insertText:t,kind:qv(e.kind),range:void 0}})})}function fhe(e,t,n,r){switch(e.container.scopeKind(t,n)){case ty.TABLE:case ty.TABLEPARTIAL:return hhe(e,t,n,r);case ty.PROJECT:return ghe(e,t,n,r);case ty.INDEXES:return xhe(e,t,n);case ty.ENUM:return mhe(e,t,n,r);case ty.REF:{let r=_he(e,t,n);return e.container.token(t,n).token?.kind===em.COLON&&Jv(e.container.token(t,n).token,n)?Xv(r):r}case ty.TABLEGROUP:return bhe(e,t);case ty.DIAGRAMVIEW:return The();case ty.CUSTOM:{let r=e.container.element(t,n);if(r instanceof Eh){let i=r.parentNode,a=i instanceof Ph?i.parentNode:void 0;if(a instanceof Eh&&a.isKind(_d.DiagramView))return Ehe(e,t,n,r)}return Yv()}default:return Yv()}}function phe(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`].map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))}}function mhe(e,t,n,r){return r?.callee&&whe(n,r)===1?$v(e,t,n,e.container.element(t,n),[P.Schema,P.Table,P.Column]):Yv()}function hhe(e,t,n,r){let i=[`Note`,`indexes`,`checks`,`Records`];if(!r?.callee)return{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))};let a=whe(n,r);return a===0?{suggestions:i.map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))}:a===1?She(e,t,n):Yv()}function ghe(e,t,n,r){return!r?.callee||whe(n,r)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))}:Yv()}function _he(e,t,n){return $v(e,t,n,e.container.element(t,n),[P.Schema,P.Table,P.Column])}function vhe(e,t,n,r){return r.isKind(_d.Records)?$v(e,t,n,r.parent,[P.Schema,P.Table]):Yv()}function yhe(e,t,n,r){let i=e.container.element(t,n),a=r.callee&&Kv(n,r.callee),o=r.argumentList&&Kv(n,r.argumentList);if(i instanceof Eh&&i.isKind(_d.Records)&&Mme(n,i)){if(a)return $v(e,t,n,i.parent,[P.Schema,P.Table]);if(!o)return Yv();let s=r.callee;if(!s)return Yv();let c=qm(s)??[s],l=c[c.length-1],u=l?e.nodeReferee(l).getFiltered(gd):void 0;if(!u)return Yv();let d=Qv(e,u,[P.Column]),{argumentList:f}=r;return!f||!Gm(f)?d:Bme(d)}let s=[...e.container.stack(t,n)];for(let i of s){if(!o||!(i instanceof Nh)||i.callee!==r||(eh(r.callee)??``).toLowerCase()!==_d.Records)continue;let a=e.nodeSymbol(e.container.element(t,n)).getFiltered(gd);if(!a)return Yv();let s=Qv(e,a,[P.Column]),{argumentList:c}=r;return!c||!Gm(c)?s:Bme(s)}return Yv()}function bhe(e,t){return{suggestions:[...Zv({suggestions:(e.parse.publicSymbolTable(t)??[]).flatMap(e=>{if(e.kind!==P.Table&&e.kind!==P.Schema)return[];let t=e.name;return t===void 0||e instanceof dh&&e.isPublicSchema()?[]:{label:t,insertText:t,insertTextRules:Gv.KeepWhitespace,kind:qv(e.kind),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0}))]}}function xhe(e,t,n){return Che(e,t,n)}function She(e,t,n){return{suggestions:[...`integer.int.tinyint.smallint.mediumint.bigint.bit.bool.binary.varbinary.logical.char.nchar.varchar.varchar2.nvarchar.nvarchar2.binary_float.binary_double.float.double.decimal.dec.real.money.smallmoney.enum.tinyblob.tinytext.blob.text.mediumblob.mediumtext.longblob.longtext.ntext.set.inet6.uuid.image.date.time.datetime.datetime2.timestamp.year.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`).map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.TypeParameter,sortText:Wv.TypeParameter.toString().padStart(2,`0`),range:void 0})),...$v(e,t,n,e.container.element(t,n),[P.Enum,P.Schema]).suggestions]}}function Che(e,t,n){let r=e.container.element(t,n)?.parent,i=r?e.nodeSymbol(r).getFiltered(gd):void 0;if(!i||!i?.isKind(P.Table))return Yv();let a=e.symbolMembers(i).getFiltered(gd);return a?Zv({suggestions:a.flatMap(t=>{let n=t.declaration?e.nodeFullname(t.declaration):void 0,r=n&&!n.hasValue(gd)?n.getValue()?.at(-1):void 0;return r?{label:r,insertText:r,insertTextRules:Gv.KeepWhitespace,kind:qv(P.Column),range:void 0}:[]})}):Yv()}function whe(e,t){if(!t.callee)return-1;let n=[t.callee,...t.args],r=n.findIndex(t=>e<=t.end);return r===-1?n.length:r}var ey={label:`*`,insertText:`*`,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0};function The(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:Gv.KeepWhitespace,kind:Wv.Keyword,range:void 0})),ey]}}function Ehe(e,t,n,r){switch(r.type?.value.toLowerCase()){case`tables`:return{suggestions:[ey,...$v(e,t,n,e.parse.ast(t),[P.Table,P.Schema]).suggestions]};case`tablegroups`:return{suggestions:[ey,...$v(e,t,n,e.parse.ast(t),[P.TableGroup]).suggestions]};case`schemas`:return{suggestions:[ey,{label:pm,insertText:pm,insertTextRules:Gv.KeepWhitespace,kind:Wv.Module,range:void 0},...$v(e,t,n,e.parse.ast(t),[P.Schema]).suggestions]};case`notes`:return{suggestions:[ey,...$v(e,t,n,e.parse.ast(t),[P.StickyNote]).suggestions]};default:return Yv()}}var Dhe={tokenPostfix:`.dbml`,brackets:[{open:`[`,close:`]`,token:`delimiter.square`},{open:`(`,close:`)`,token:`delimiter.parenthesis`},{open:`{`,close:`}`,token:`delimiter.curly`}],decls:[`project`,`tablegroup`,`table`,`enum`,`ref`,`note`,`tablepartial`,`records`,`checks`,`diagramview`,`use`,`reuse`,`from`],dataTypes:`TINYINT.SMALLINT.MEDIUMINT.INT.INTEGER.BIGINT.FLOAT.DOUBLE.DECIMAL.DEC.BIT.BOOL.REAL.MONEY.BINARY_FLOAT.BINARY_DOUBLE.smallmoney.ENUM.CHAR.BINARY.VARCHAR.VARBINARY.TINYBLOB.TINYTEXT.BLOB.TEXT.MEDIUMBLOB.MEDIUMTEXT.LONGBLOB.LONGTEXT.SET.INET6.UUID.NVARCHAR.NCHAR.NTEXT.IMAGE.VARCHAR2.NVARCHAR2.DATE.TIME.DATETIME.DATETIME2.TIMESTAMP.YEAR.smalldatetime.datetimeoffset.XML.sql_variant.uniqueidentifier.CURSOR.BFILE.CLOB.NCLOB.RAW`.split(`.`),settings:[`indexes`,`ref`,`note`,`headercolor`,`pk`,`null`,`increment`,`unique`,`default`,`note`,`primary`,`key`,`name`,`as`,`color`,`check`,`tables`,`tablegroups`,`notes`,`schemas`],symbols:/[=><!~?:&|+\-/^%]+/,escapes:/\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,newline:/[\r\n]/,digits:/\d+(_+\d+)*/,idtf:/[\p{L}0-9_]+/u,ignoreCase:!0,unicode:!0,tokenizer:{root:[[/[{}[\]()]/,`@bracket`],[/[,.:]/,`delimiter`],{include:`@numbers`},{include:`common`}],common:[{include:`@whitespace`},[/[<>-]/,`operators`],[/\*/,`keyword.wildcard`],[/("[^"\\]*(?:\\.[^"\\]*)*")(\s+)(@idtf(?:\.@idtf*)*)/,[`string`,``,`keyword`]],[/"([^"\\]|\\.)*$/,``],[/'([^'\\]|\\.)*$/,``],[/"/,`string`,`@string_double`],[/'/,`string`,`@string_single`],[/`/,`string`,`@string_backtick`],[/(@idtf)(\s+)(@idtf(?:\.@idtf)*)/,{cases:{"$1@decls":[`keyword`,``,`identifier`],"$1==not":{cases:{"$3==null":[`keyword`,``,`keyword`],"@default":[`identifier`,``,`identifier`]}},"@default":[`identifier`,``,`keyword`]}}],[/@idtf/,{cases:{"@dataTypes":`keyword`,"@decls":`keyword`,"@settings":`keyword`,"@default":`identifier`}}]],numbers:[[/0[xX][0-9a-fA-F]*/,`number`],[/[$][+-]*\d*(\.\d*)?/,`number`],[/((\d+(\.\d*)?)|(\.\d+))([eE][-+]?\d+)?/,`number`],[/#([0-9A-F]{3}){1,2}/,`number.hex`]],string_double:[[/[^\\"]+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/"/,`string`,`@pop`]],string_single:[[/[^\\']+/,`string`],[/@escapes/,`string.escape`],[/\\./,`string.escape.invalid`],[/'/,`string`,`@pop`]],string_backtick:[[/[^\\`$]+/,`string`],[/@escapes/,`string.escape`],[/`/,`string`,`@pop`]],endTripleQuotesString:[[/\\'/,`string`],[/(.*[^\\])?(\\\\)*'''/,`string`,`@popall`],[/.*$/,`string`]],whitespace:[[/[ \t\r\n]+/,``],[/\/\*/,`comment`,`@comment`],[/\/\/.*$/,`comment`],[/'''(.*[^\\])?(\\\\)*'''/,`string`],[/'''.*$/,`string`,`@endTripleQuotesString`]],comment:[[/[^/*]+/,`comment`],[/\*\//,`comment`,`@pop`],[/[/*]/,`comment`]]}},Ohe=class e{constructor(e={}){this.files=e instanceof Map?new Map(e):new Map(Object.entries(e))}setSource(e,t){this.files.set(e.absolute,t)}getSource(e){return this.files.get(e.absolute)??void 0}deleteSource(e){this.files.delete(e.absolute)}clearSource(){this.files.clear()}exists(e){return this.isFile(e)||this.isDirectory(e)}isFile(e){return this.files.has(e.absolute)}isDirectory(e){let t=e.absolute.endsWith(`/`)?e.absolute:`${e.absolute}/`;for(let e of this.files.keys())if(e.startsWith(t))return!0;return!1}listDirectory(e){let t=e?.absolute??`/`,n=t.endsWith(`/`)?t:t+`/`,r=new Set;for(let e of this.files.keys()){if(!e.startsWith(n))continue;let t=e.slice(n.length),i=t.indexOf(`/`);r.add(n+(i===-1?t:t.slice(0,i)))}return[...r].sort().map(um.from)}getEntryPoints(){return[...this.files.keys()].map(um.from).sort((e,t)=>e.absolute.localeCompare(t.absolute))}clone(){return new e(this.files)}};function khe(e,t){let n=this.token.flatStream(e),{index:r,token:i}=this.container.token(e,t),a=r===void 0?-1:Dae(n,e=>!e.isInvalid,r);if(a===-1)return[this.parse.ast(e)];let o=n[a].start,s=this.parse.ast(e),c=[s];for(;;){let e=ng(s).find(e=>Kv(o,e));if(e===void 0||e instanceof tm)break;c.push(e),s=e}if(i?.kind===em.COLON)return c;for(;c.length>0;){let n=!1,r=qp(c);if(r instanceof Nh){let i=this.layout.getSource(e)||``;for(let e=r.end;e<t;e+=1)i[e]===`
16
- `&&(c.pop(),n=!0)}else r instanceof kh||r instanceof Ah?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof Fh?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof Ih?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof Lh?r.end<=t&&(c.pop(),n=!0):r instanceof Ph?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof Dh||r.end<t&&(c.pop(),n=!0);if(n){let e=qp(c);e instanceof Eh&&e.end<=t&&c.pop()}if(!n)break}return c}function Ahe(e,t){let n=this.token.flatStream(e).findIndex(e=>e.start>=t);return n===void 0||n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream(e)[n-1],index:n-1}}function jhe(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof Eh)return n[e];return this.parse.ast(e)}function Mhe(e,t){let n=this.container.element(e,t);if(!n)return;let r=this.nodeSymbol(n);if(r.hasValue(gd))return;let i=this.symbolMembers(r.getValue());if(!i.hasValue(gd))return i.getValue()}var ty=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function Nhe(e,t){let n=this.container.element(e,t);if(n instanceof Sh)return ty.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return ty.TABLE;case`enum`:return ty.ENUM;case`ref`:return ty.REF;case`tablegroup`:return ty.TABLEGROUP;case`indexes`:return ty.INDEXES;case`note`:return ty.NOTE;case`project`:return ty.PROJECT;case`tablepartial`:return ty.TABLEPARTIAL;case`checks`:return ty.CHECKS;case`records`:return ty.RECORDS;case`diagramview`:return ty.DIAGRAMVIEW;default:return ty.CUSTOM}}function Phe(e,t){let n=t.originalSymbol;if(n.filepath.intern()===e.intern())return k.create(Ihe(this,n));let r=[...this.symbolUses(n).getValue(),...this.symbolAliases(n).getValue()].filter(t=>t.filepath.equals(e));for(let e of r){let t=e.name;if(!t)continue;if(t!==n.name)return k.create({schema:``,name:t});let r=Fhe(this,e);if(r.length>0)return k.create({schema:r.join(`.`),name:t});let i=Ihe(this,n);return i?k.create({...i,name:t}):k.create({schema:pm,name:t})}return k.create(Ihe(this,n))}function Fhe(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof dh&&e.isKind(P.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function Ihe(e,t){if(!t.declaration)return t.name?{schema:pm,name:t.name}:void 0;let n=e.nodeFullname(t.declaration).getFiltered(gd);if(!n||n.length===0)return t.name?{schema:pm,name:t.name}:void 0;let r=n[n.length-1];return{schema:n.length>1?n.slice(0,-1).join(`.`):pm,name:r}}function Lhe(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof Ch)||!i.importPath)continue;let t=dm(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function Rhe(e){let t=new Set,n=[],r=e?[e]:this.layout.getEntryPoints(),i=0;for(;i<r.length;){let e=r[i++],a=e.intern();if(!t.has(a)){t.add(a),n.push(e);for(let t of this.fileDependencies(e))r.push(t)}}return n}function zhe(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function Bhe(e){return this.interpretFile(e).getErrors()}function Vhe(e){return this.interpretFile(e).getWarnings()}function Hhe(e){return this.parseFile(e).getValue().tokens}function Uhe(e){let t=this.parseFile(e).getValue().ast,n=this.nodeSymbol(t).getFiltered(gd);if(n)return this.interpretSymbol(n,e).getFiltered(gd)}function Whe(e){let t=this.parseFile(e).getValue().ast,n=this.nodeSymbol(t);if(n.hasValue(gd))return;let r=this.symbolMembers(n.getValue());if(r.hasValue(gd))return;let i=[];for(let e of r.getValue())i.push(e);return i}function Ghe(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Khe(e){return this.parseFile(e).getValue().tokens.filter(am)}function qhe(e,t){let n=this.parse.ast(e);for(;;){let e=ng(n).find(e=>Kv(t,e));if(e===void 0)return n;if(e instanceof tm)return e;n=e}}function Jhe(e){let t=this.validateFile(e),n=this.parseFile(e).getValue().ast,r=this.bindNode(n).map(()=>void 0);return new k(void 0,[...t.getErrors(),...r.getErrors()],[...t.getWarnings(),...r.getWarnings()])}function Yhe(){let e=Tfe(this,this.layout.getEntryPoints()),t=new Map;for(let n of e){let e=this.bindFile(n);t.set(n.absolute,e)}return t}function Xhe(e){let t=this.bindFile(e);if(t.getErrors().length>0)return t.map(()=>void 0);let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(gd);return r?this.interpretSymbol(r,e).map(e=>e===gd||!e?void 0:e):k.create(void 0)}function Zhe(){let e=[],t=[],n=new Set,r=[];for(let e of this.layout.getEntryPoints())for(let t of this.reachableFiles(e)){let e=t.intern();n.has(e)||(n.add(e),r.push(t))}let i=new Map;for(let n of r){let r=this.parseFile(n);e.push(...r.getErrors()),t.push(...r.getWarnings());let a=r.getValue().ast,o=this.nodeSymbol(a).getFiltered(gd),s=o?this.interpretSymbol(o,n):k.create(gd),c=s.getFiltered(gd);c&&i.set(n.absolute,c),e.push(...s.getErrors()),t.push(...s.getWarnings())}let a={};for(let[e,t]of i)a[e]=t;return new k({files:a},e,t)}function Qhe(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var $he=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
16
+ `&&(c.pop(),n=!0)}else r instanceof kh||r instanceof Ah?this.container.token(e,t).token!==r.op&&(c.pop(),n=!0):r instanceof Fh?r.listCloseBracket&&r.end<=t&&(c.pop(),n=!0):r instanceof Ih?r.tupleCloseParen&&r.end<=t&&(c.pop(),n=!0):r instanceof Lh?r.end<=t&&(c.pop(),n=!0):r instanceof Ph?r.blockCloseBrace&&r.end<=t&&(c.pop(),n=!0):r instanceof Dh||r.end<t&&(c.pop(),n=!0);if(n){let e=qp(c);e instanceof Eh&&e.end<=t&&c.pop()}if(!n)break}return c}function Ahe(e,t){let n=this.token.flatStream(e).findIndex(e=>e.start>=t);return n===void 0||n<=0?{token:void 0,index:void 0}:{token:this.token.flatStream(e)[n-1],index:n-1}}function jhe(e,t){let n=this.container.stack(e,t);for(let e=n.length-1;e>=0;--e)if(n[e]instanceof Eh)return n[e];return this.parse.ast(e)}function Mhe(e,t){let n=this.container.element(e,t);if(!n)return;let r=this.nodeSymbol(n);if(r.hasValue(gd))return;let i=this.symbolMembers(r.getValue());if(!i.hasValue(gd))return i.getValue()}var ty=function(e){return e[e.TABLE=0]=`TABLE`,e[e.ENUM=1]=`ENUM`,e[e.TABLEGROUP=2]=`TABLEGROUP`,e[e.INDEXES=3]=`INDEXES`,e[e.NOTE=4]=`NOTE`,e[e.REF=5]=`REF`,e[e.PROJECT=6]=`PROJECT`,e[e.CUSTOM=7]=`CUSTOM`,e[e.TOPLEVEL=8]=`TOPLEVEL`,e[e.TABLEPARTIAL=9]=`TABLEPARTIAL`,e[e.CHECKS=10]=`CHECKS`,e[e.RECORDS=11]=`RECORDS`,e[e.DIAGRAMVIEW=12]=`DIAGRAMVIEW`,e}({});function Nhe(e,t){let n=this.container.element(e,t);if(n instanceof Sh)return ty.TOPLEVEL;switch(n.type?.value.toLowerCase()){case`table`:return ty.TABLE;case`enum`:return ty.ENUM;case`ref`:return ty.REF;case`tablegroup`:return ty.TABLEGROUP;case`indexes`:return ty.INDEXES;case`note`:return ty.NOTE;case`project`:return ty.PROJECT;case`tablepartial`:return ty.TABLEPARTIAL;case`checks`:return ty.CHECKS;case`records`:return ty.RECORDS;case`diagramview`:return ty.DIAGRAMVIEW;default:return ty.CUSTOM}}function Phe(e,t){let n=t.originalSymbol;if(n.filepath.equals(e))return k.create(Ihe(this,n));let r=[...this.symbolUses(n).getValue(),...this.symbolAliases(n).getValue()].filter(t=>t.filepath.equals(e));for(let e of r){let t=e.name;if(!t)continue;if(t!==n.name)return k.create({schema:``,name:t});let r=Fhe(this,e);if(r.length>0)return k.create({schema:r.join(`.`),name:t});let i=Ihe(this,n);return i?k.create({...i,name:t}):k.create({schema:pm,name:t})}return k.create(Ihe(this,n))}function Fhe(e,t){let n=[],r=t;for(;r;){let t=e.symbolParent(r).find(e=>e instanceof dh&&e.isKind(P.Schema));if(!t||t.isPublicSchema())break;n.unshift(t.name??``),r=t}return n}function Ihe(e,t){if(!t.declaration)return t.name?{schema:pm,name:t.name}:void 0;let n=e.nodeFullname(t.declaration).getFiltered(gd);if(!n||n.length===0)return t.name?{schema:pm,name:t.name}:void 0;let r=n[n.length-1];return{schema:n.length>1?n.slice(0,-1).join(`.`):pm,name:r}}function Lhe(e){let{ast:t}=this.parseFile(e).getValue(),n=[],r=new Set;for(let i of t.body){if(!(i instanceof Ch)||!i.importPath)continue;let t=dm(e,i.importPath.value);!t||r.has(t.absolute)||(r.add(t.absolute),n.push(t))}return n}function Rhe(e){let t=new Set,n=[],r=e?[e]:this.layout.getEntryPoints(),i=0;for(;i<r.length;){let e=r[i++],a=e.intern();if(!t.has(a)){t.add(a),n.push(e);for(let t of this.fileDependencies(e))r.push(t)}}return n}function zhe(e){return this.bindFile(e),this.parseFile(e).getValue().ast}function Bhe(e){return this.interpretFile(e).getErrors()}function Vhe(e){return this.interpretFile(e).getWarnings()}function Hhe(e){return this.parseFile(e).getValue().tokens}function Uhe(e){let t=this.parseFile(e).getValue().ast,n=this.nodeSymbol(t).getFiltered(gd);if(n)return this.interpretSymbol(n,e).getFiltered(gd)}function Whe(e){let t=this.parseFile(e).getValue().ast,n=this.nodeSymbol(t);if(n.hasValue(gd))return;let r=this.symbolMembers(n.getValue());if(r.hasValue(gd))return;let i=[];for(let e of r.getValue())i.push(e);return i}function Ghe(e){return this.parseFile(e).getValue().tokens.flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function Khe(e){return this.parseFile(e).getValue().tokens.filter(am)}function qhe(e,t){let n=this.parse.ast(e);for(;;){let e=ng(n).find(e=>Kv(t,e));if(e===void 0)return n;if(e instanceof tm)return e;n=e}}function Jhe(e){let t=this.validateFile(e),n=this.parseFile(e).getValue().ast,r=this.bindNode(n).map(()=>void 0);return new k(void 0,[...t.getErrors(),...r.getErrors()],[...t.getWarnings(),...r.getWarnings()])}function Yhe(){let e=Tfe(this,this.layout.getEntryPoints()),t=new Map;for(let n of e){let e=this.bindFile(n);t.set(n.absolute,e)}return t}function Xhe(e){let t=this.bindFile(e);if(t.getErrors().length>0)return t.map(()=>void 0);let n=this.parseFile(e).getValue().ast,r=this.nodeSymbol(n).getFiltered(gd);return r?this.interpretSymbol(r,e).map(e=>e===gd||!e?void 0:e):k.create(void 0)}function Zhe(){let e=[],t=[],n=new Set,r=[];for(let e of this.layout.getEntryPoints())for(let t of this.reachableFiles(e)){let e=t.intern();n.has(e)||(n.add(e),r.push(t))}let i=new Map;for(let n of r){let r=this.parseFile(n);e.push(...r.getErrors()),t.push(...r.getWarnings());let a=r.getValue().ast,o=this.nodeSymbol(a).getFiltered(gd),s=o?this.interpretSymbol(o,n):k.create(gd),c=s.getFiltered(gd);c&&i.set(n.absolute,c),e.push(...s.getErrors()),t.push(...s.getWarnings())}let a={};for(let[e,t]of i)a[e]=t;return new k({files:a},e,t)}function Qhe(e){return this.parseFile(e).chain(({ast:e})=>this.validateNode(e).map(()=>void 0))}var $he=class{constructor(e,t){this.start={offset:0,line:0,column:0},this.current={offset:0,line:0,column:0},this.tokens=[],this.errors=[],this.text=e,this.filepath=t}isAtEnd(){return this.current.offset>=this.text.length}advance(){let e=this.peek();return this.current={...this.current},e===`
17
17
  `?(this.current.line+=1,this.current.column=0):this.current.column+=1,this.current.offset+=1,e}peek(e=0){if(!(this.current.offset+e>=this.text.length))return this.text[this.current.offset+e]}check(e){for(let t=0;t<e.length;t+=1)if(e[t]!==this.peek(t))return!1;return!0}match(e){return this.check(e)?(e.split(``).forEach(()=>this.advance()),!0):!1}addToken(e,t=!1){this.tokens.push(this.createToken(e,t))}createToken(e,t=!1){return tm.create(e,this.filepath,this.start,this.current,this.text.substring(this.start.offset,this.current.offset),t)}lex(){return this.scanTokens(),this.tokens.push(tm.create(em.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new k(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(em.SPACE);break;case`\r`:break;case`
18
18
  `:this.addToken(em.NEWLINE);break;case` `:this.addToken(em.TAB);break;case`,`:this.addToken(em.COMMA);break;case`(`:this.addToken(em.LPAREN);break;case`)`:this.addToken(em.RPAREN);break;case`[`:this.addToken(em.LBRACKET);break;case`]`:this.addToken(em.RBRACKET);break;case`{`:this.addToken(em.LBRACE);break;case`}`:this.addToken(em.RBRACE);break;case`;`:this.addToken(em.SEMICOLON);break;case`:`:this.addToken(em.COLON);break;case`'`:this.match(`''`)?this.multilineStringLiteral():this.singleLineStringLiteral();break;case`"`:this.quotedVariable();break;case"`":this.functionExpression();break;case`#`:this.colorLiteral();break;case`/`:this.match(`/`)?this.singleLineComment():this.match(`*`)?this.multilineComment():this.operator(e);break;case`*`:this.addToken(em.WILDCARD);break;default:if(Zae(e)){this.operator(e);break}if(gm(e)){this.identifier();break}if(_m(e)){this.numericLiteralOrIdentifier();break}this.addToken(em.OP,!0),this.errors.push(new N(M.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(em.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)Xae(i)?(t.push(i),i.kind===em.NEWLINE&&n&&(n.trailingTrivia=t,e=!0,n=void 0,t=[])):(e?i.leadingTrivia=t:n.trailingTrivia=t,r.push(i),t=[],n=i,e=!1);this.tokens=r}gatherInvalid(){let e,t=[],n=[];for(e=0;e<this.tokens.length&&am(this.tokens[e]);e+=1)n.push(this.tokens[e]);let r=this.tokens[e];for(r.leadingInvalid=[...n,...r.leadingInvalid];e<this.tokens.length;e+=1){let n=this.tokens[e];am(n)?r.trailingInvalid.push(n):(r=n,t.push(n))}this.tokens=t}consumeUntil(e,t,{allowNewline:n,allowEof:r,raw:i,consumeStopSequence:a=!0}){let o=``;for(;!this.isAtEnd()&&(n||!this.check(`
19
19
  `))&&!this.check(t);)this.peek()===`\\`&&!i?(this.advance(),o+=this.escapedString()):o+=this.advance();if(this.isAtEnd()&&!r){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new N(M.UNEXPECTED_EOF,`EOF reached while parsing`,t));return}if(this.check(`
@@ -155,4 +155,4 @@ function print() { __p += __j.call(arguments, '') }
155
155
  `,!1),gt=`
156
156
  `,_t=At(`
157
157
  `,!1),vt=Nt(`whitespace`),yt=/^[ \t\r\n\r]/,bt=jt([` `,` `,`\r`,`
158
- `,`\r`],!1,!1),xt=` `,St=At(` `,!1),y=0,Ct=0,wt=[{line:1,column:1}],Tt=0,Et=[],Dt=0,Ot;if(`startRule`in t){if(!(t.startRule in i))throw Error(`Can't start parsing from rule "`+t.startRule+`".`);a=i[t.startRule]}function kt(e,t){throw t=t===void 0?Ft(Ct,y):t,Lt(e,t)}function At(e,t){return{type:`literal`,text:e,ignoreCase:t}}function jt(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function Mt(){return{type:`end`}}function Nt(e){return{type:`other`,description:e}}function Pt(t){var n=wt[t],r;if(n)return n;for(r=t-1;!wt[r];)r--;for(n=wt[r],n={line:n.line,column:n.column};r<t;)e.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return wt[t]=n,n}function Ft(e,t){var n=Pt(e),r=Pt(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function It(e){y<Tt||(y>Tt&&(Tt=y,Et=[]),Et.push(e))}function Lt(e,t){return new r(e,null,null,t)}function Rt(e,t,n){return new r(r.buildMessage(e,t),e,t,n)}function zt(){for(var e=y,t=[],r=Bt();r!==n;)t.push(r),r=Bt();return t!==n&&(Ct=e,t=o()),e=t,e}function Bt(){for(var e=y,t=[],r=An();r!==n;)t.push(r),r=An();return t===n?(y=e,e=n):(r=Vt(),r===n?(y=e,e=n):(t=[t,r],e=t)),e===n&&(e=xn(),e===n&&(e=bn(),e===n&&(e=En()))),e}function Vt(){var e=y,t=Gt();return t!==n&&(Ct=e,t=s(t)),e=t,e===n&&(e=y,t=Ut(),t!==n&&(Ct=e,t=c(t)),e=t,e===n&&(e=Ht(),e===n&&(e=fn()))),e}function Ht(){for(var t=y,r=[],i=jn(),a,o,s,c,f,p,m;i!==n;)r.push(i),i=jn();if(r!==n)if(i=sn(),i!==n){for(a=[],o=jn();o!==n;)a.push(o),o=jn();if(a!==n)if(o=gn(),o===n&&(o=pn()),o!==n)if(e.charCodeAt(y)===44?(s=l,y++):(s=n,Dt===0&&It(u)),s!==n){for(c=[],f=jn();f!==n;)c.push(f),f=jn();if(c!==n)if(f=pn(),f!==n){for(p=[],m=en();m!==n;)p.push(m),m=en();p===n?(y=t,t=n):(Ct=t,r=d(o,f,p),t=r)}else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;return t}function Ut(){for(var t=y,r=[],i=jn(),a,o,s,c,d,p,m;i!==n;)r.push(i),i=jn();if(r!==n)if(i=cn(),i!==n){for(a=[],o=jn();o!==n;)a.push(o),o=jn();if(a!==n)if(o=pn(),o!==n)if(e.charCodeAt(y)===44?(s=l,y++):(s=n,Dt===0&&It(u)),s!==n){for(c=[],d=jn();d!==n;)c.push(d),d=jn();if(c!==n)if(d=pn(),d!==n){for(p=[],m=Wt();m!==n;)p.push(m),m=Wt();p===n?(y=t,t=n):(Ct=t,r=f(o,d,p),t=r)}else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;return t}function Wt(){var t=y,r,i,a,o,s,c;if(e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=ln(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=h(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;if(t===n){if(t=y,e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=un(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=g(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;if(t===n)if(t=y,e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=tn(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=gn(),c===n?(y=t,t=n):(Ct=t,r=_(a,c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n}return t}function Gt(){var e=y,t=nn(),r,i,a,o,s,c;if(t!==n){for(r=[],i=jn();i!==n;)r.push(i),i=jn();r===n?(y=e,e=n):(i=pn(),i===n?(y=e,e=n):(a=Sn(),a===n?(y=e,e=n):(o=Dn(),o===n?(y=e,e=n):(s=Kt(),s===n?(y=e,e=n):(c=bn(),c===n?(y=e,e=n):(Ct=e,t=ee(i,s),e=t))))))}else y=e,e=n;return e}function Kt(){for(var e=y,t=[],r=qt();r!==n;)t.push(r),r=qt();return t!==n&&(Ct=e,t=te(t)),e=t,e}function qt(){for(var e=y,t=[],r=An(),i,a;r!==n;)t.push(r),r=An();if(t!==n)if(r=Jt(),r!==n){for(i=[],a=Cn();a!==n;)i.push(a),a=Cn();i===n?(y=e,e=n):(a=Dn(),a===n?(y=e,e=n):(Ct=e,t=ne(r),e=t))}else y=e,e=n;else y=e,e=n;return e}function Jt(){var e=Yt(),t;return e===n&&(e=y,t=Xt(),t!==n&&(Ct=e,t=v(t)),e=t,e===n&&(e=y,t=Zt(),t!==n&&(Ct=e,t=re(t)),e=t,e===n&&(e=y,t=Qt(),t!==n&&(Ct=e,t=ie(t)),e=t))),e}function Yt(){var e=y,t=rn(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=Sn(),i===n?(y=e,e=n):(t=[t,r,i],e=t))}else y=e,e=n;return e}function Xt(){var e=y,t=an(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=$t(),i===n?(y=e,e=n):(Ct=e,t=ae(i),e=t))}else y=e,e=n;return e}function Zt(){var e=y,t=on(),r,i,a,o;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;if(r!==n)if(i=pn(),i!==n){for(a=[],o=en();o!==n;)a.push(o),o=en();a===n?(y=e,e=n):(Ct=e,t=oe(i,a),e=t)}else y=e,e=n;else y=e,e=n}else y=e,e=n;return e}function Qt(){var e=y,t=vn(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=pn(),i===n?(y=e,e=n):(Ct=e,t=se(t,i),e=t))}else y=e,e=n;return e}function $t(){var t=y,r,i;return e.charCodeAt(y)===58?(r=p,y++):(r=n,Dt===0&&It(m)),r===n?(y=t,t=n):(i=_n(),i===n?(y=t,t=n):(Ct=t,r=ce(i),t=r)),t===n&&(t=y,r=pn(),r!==n&&(Ct=t,r=ce(r)),t=r),t}function en(){var t=y,r,i,a,o,s,c;if(e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(e.substr(y,4).toLowerCase()===le?(a=e.substr(y,4),y+=4):(a=n,Dt===0&&It(ue)),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=de(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;return t}function tn(){var t;return e.substr(y,9).toLowerCase()===fe?(t=e.substr(y,9),y+=9):(t=n,Dt===0&&It(pe)),t===n&&(e.substr(y,9).toLowerCase()===me?(t=e.substr(y,9),y+=9):(t=n,Dt===0&&It(he))),t}function nn(){var t;return Dt++,e.substr(y,12).toLowerCase()===_e?(t=e.substr(y,12),y+=12):(t=n,Dt===0&&It(ve)),Dt--,t===n&&Dt===0&&It(ge),t}function rn(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,6)===be?(i=be,y+=6):(i=n,Dt===0&&It(xe)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(ye)),t}function an(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,11)===Ce?(i=Ce,y+=11):(i=n,Dt===0&&It(we)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(Se)),t}function on(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,17)===Ee?(i=Ee,y+=17):(i=n,Dt===0&&It(De)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(Te)),t}function sn(){var t;return Dt++,e.substr(y,20).toLowerCase()===ke?(t=e.substr(y,20),y+=20):(t=n,Dt===0&&It(Ae)),Dt--,t===n&&Dt===0&&It(Oe),t}function cn(){var t;return Dt++,e.substr(y,15).toLowerCase()===Me?(t=e.substr(y,15),y+=15):(t=n,Dt===0&&It(Ne)),Dt--,t===n&&Dt===0&&It(je),t}function ln(){var t;return Dt++,e.substr(y,6)===Fe?(t=Fe,y+=6):(t=n,Dt===0&&It(Ie)),Dt--,t===n&&Dt===0&&It(Pe),t}function un(){var t;return Dt++,e.substr(y,11)===Re?(t=Re,y+=11):(t=n,Dt===0&&It(ze)),Dt--,t===n&&Dt===0&&It(Le),t}function dn(){var t;return e.substr(y,3)===Be?(t=Be,y+=3):(t=n,Dt===0&&It(Ve)),t}function fn(){var e=y,t=_n(),r,i;return t===n?(y=e,e=n):(r=Sn(),r===n?(y=e,e=n):(i=Dn(),i===n&&(i=null),i===n?(y=e,e=n):(t=[t,r,i],e=t))),e}function pn(){var e=mn();return e===n&&(e=hn()),e}function mn(){var t=y,r=Tn(),i,a;if(r!==n){for(i=[],He.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ue));a!==n;)i.push(a),He.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ue));i===n?(y=t,t=n):(a=Tn(),a===n?(y=t,t=n):(Ct=t,r=We(i),t=r))}else y=t,t=n;return t}function hn(){var t=y,r=wn(),i,a;if(r!==n){for(i=[],Ge.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ke));a!==n;)i.push(a),Ge.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ke));i===n?(y=t,t=n):(a=wn(),a===n?(y=t,t=n):(Ct=t,r=We(i),t=r))}else y=t,t=n;return t}function gn(){var t=y,r,i,a;if(e.charCodeAt(y)===58?(r=p,y++):(r=n,Dt===0&&It(m)),r!==n){for(i=[],a=yn();a!==n;)i.push(a),a=yn();i===n?(y=t,t=n):(Ct=t,r=We(i),t=r)}else y=t,t=n;return t}function _n(){var e=y,t=[],r=yn();if(r!==n)for(;r!==n;)t.push(r),r=yn();else t=n;return t!==n&&(Ct=e,t=We(t)),e=t,e}function vn(){var t=y,r=yn(),i,a,o;if(r!==n)if(e.charCodeAt(y)===46?(i=qe,y++):(i=n,Dt===0&&It(Je)),i!==n){if(a=[],o=yn(),o!==n)for(;o!==n;)a.push(o),o=yn();else a=n;a===n?(y=t,t=n):(Ct=t,r=We(a),t=r)}else y=t,t=n;else y=t,t=n;return t}function yn(){var t;return Dt++,Xe.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(Ze)),Dt--,t===n&&Dt===0&&It(Ye),t}function bn(){for(var e=y,t=[],r=An(),i;r!==n;)t.push(r),r=An();return t===n?(y=e,e=n):(r=dn(),r===n?(y=e,e=n):(i=Dn(),i===n&&(i=null),i===n?(y=e,e=n):(t=[t,r,i],e=t))),e}function xn(){var t,r,i,a,o;for(Dt++,t=y,r=[],i=An();i!==n;)r.push(i),i=An();return r===n?(y=t,t=n):(e.charCodeAt(y)===35?(i=$e,y++):(i=n,Dt===0&&It(et)),i===n?(y=t,t=n):(a=Sn(),a===n?(y=t,t=n):(o=Dn(),o===n&&(o=null),o===n?(y=t,t=n):(r=[r,i,a,o],t=r)))),Dt--,t===n&&(r=n,Dt===0&&It(Qe)),t}function Sn(){var t,r;for(Dt++,t=[],nt.test(e.charAt(y))?(r=e.charAt(y),y++):(r=n,Dt===0&&It(rt));r!==n;)t.push(r),nt.test(e.charAt(y))?(r=e.charAt(y),y++):(r=n,Dt===0&&It(rt));return Dt--,t===n&&(r=n,Dt===0&&It(tt)),t}function Cn(){var t;return nt.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(rt)),t}function wn(){var t;return e.charCodeAt(y)===39?(t=it,y++):(t=n,Dt===0&&It(at)),t}function Tn(){var t;return e.charCodeAt(y)===34?(t=ot,y++):(t=n,Dt===0&&It(st)),t}function En(){var e=[],t=On();if(t===n&&(t=An()),t!==n)for(;t!==n;)e.push(t),t=On(),t===n&&(t=An());else e=n;return e}function Dn(){for(var e=y,t=[],r=jn();r!==n;)t.push(r),r=jn();return t===n?(y=e,e=n):(r=kn(),r===n?(y=e,e=n):(t=[t,r],e=t)),e}function On(){var t,r,i;return Dt++,t=y,e.substr(y,2)===lt?(r=lt,y+=2):(r=n,Dt===0&&It(ut)),r===n?(y=t,t=n):(dt.test(e.charAt(y))?(i=e.charAt(y),y++):(i=n,Dt===0&&It(ft)),i===n&&(i=null),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(ct)),t}function kn(){var t;return Dt++,e.substr(y,2)===mt?(t=mt,y+=2):(t=n,Dt===0&&It(ht)),t===n&&(e.charCodeAt(y)===10?(t=gt,y++):(t=n,Dt===0&&It(_t))),Dt--,t===n&&Dt===0&&It(pt),t}function An(){var t;return Dt++,yt.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(bt)),Dt--,t===n&&Dt===0&&It(vt),t}function jn(){var t;return e.charCodeAt(y)===32?(t=xt,y++):(t=n,Dt===0&&It(St)),t}var Mn=$7(),Nn=Q7();let Pn={tables:[],refs:[]};function Fn(e){Pn.tables.find(t=>t.name==e.name)?kt(`Duplicated table name`):(e.fields.find(e=>e.name===`id`)||e.fields.unshift({name:`id`,type:{type_name:`varchar`}}),Pn.tables.push(e))}function In(e,t,n){let r=Pn.tables.find(t=>t.name===e);r||kt("Table ${tableName} not found"),r.checks||=[];let i={expression:t};n&&(i.name=n),r.checks.push(i)}function Ln(e=[],t=[]){let n=t.find(e=>e.name===`primary_key`);return n?e.find(e=>e.name===n.value)?e.map(({name:e,type:t})=>({name:e,type:t,PK:n.value===field.name})):[{name:n.value,type:{type_name:`varchar`},PK:!0}].concat(e):e}function Rn(e,t){return e.tableName==t.tableName&&Nn.isEqual(Nn.sortBy(e.fieldNames),Nn.sortBy(t.fieldNames))}function zn(e,t){return Rn(e[0],t[0])&&Rn(e[1],t[1])}function Bn(e,t){return zn(e.endpoints,t.endpoints)||zn(e.endpoints,t.endpoints.slice().reverse())}function Vn(e){e&&(Pn.refs.find(t=>Bn(t,e))&&kt(`Duplicated references`),Pn.refs.push(e))}function Hn(e=[]){if(!(!e||e.length===0))for(let t=0;t<e.length;t+=1)Vn(e[t])}function Un(e){let{tables:t}=Pn,{endpoints:n}=e,r=t.find(e=>e.name===n[0].tableName);if(!r||!t.find(e=>e.name===n[1].tableName))return null;if(!n[0].fieldNames){let e=`${Mn.singular(n[1].tableName)}_id`;if(n[0].fieldNames=[e],!r.fields.find(t=>t.name===e))return null;n[0].fieldNames=[e]}return n[1].fieldNames||(n[1].fieldNames=[`id`]),e}function Wn(e,t,n){let r=[{tableName:e,relation:`1`},{tableName:t,relation:`1`}],i={};for(let e=0;e<n.length;e+=1){let t=n[e];t.columnName&&(r[0].fieldNames=[t.columnName]),t.primaryKey&&(r[1].fieldNames=[t.primaryKey]),t.onDelete&&(i={...i,onDelete:t.onDelete}),t.onUpdate&&(i={...i,onUpdate:t.onUpdate})}return{name:`fk_rails_${e}_${t}`,endpoints:r,...i}}function Gn(e,t){if(!t||t.length===0)return[];let n=[];for(let r=0;r<t.length;r+=1){let i=t[r],a=Mn.plural(i),{tables:o}=Pn,s=o.find(e=>e.name===a);if(!s)continue;let c=`${i}_id`,l=e.fields.find(e=>e.name===c),u=s.fields.find(e=>e.name===`id`);l||e.fields.push({name:c,type:{type_name:u?u.type.type_name:`varchar`}}),n.push({name:`fk_rails_${e.name}_${a}`,endpoints:[{tableName:e.name,fieldNames:[c],relation:`1`},{tableName:a,fieldNames:[`id`],relation:`1`}]})}return n}function Kn(e){let{tables:t,refs:n}=e,r=t.map(e=>{let{name:t}=e;return{name:t,field:`${Mn.singular(t)}_id`}});for(let e=0;e<t.length;e+=1){let i=t[e],{fields:a}=i;for(let e=0;e<a.length;e+=1){let t=a[e],o=r.find(e=>e.field===t.name);if(o){let e={name:`fk_rails_${i.name}_${o.name}`,endpoints:[{tableName:i.name,fieldNames:[t.name],relation:`1`},{tableName:o.name,fieldNames:[`id`],relation:`1`}]};n.find(t=>Bn(t,e))||n.push(e)}}}return e}if(Ot=a(),Ot!==n&&y===e.length)return Ot;throw Ot!==n&&y<e.length&&It(Mt()),Rt(Et,Tt<e.length?e.charAt(Tt):null,Tt<e.length?Ft(Tt,Tt+1):Ft(Tt,Tt))}t.exports={SyntaxError:r,parse:i}})),U7e=u(I3e()),W7e=u(z7e()),G7e=u(B7e()),K7e=u(V7e()),q7e=u(H7e()),J7e=class e{constructor(e){this.DBMLCompiler=e||new oy}static parseJSONToDatabase(e){return new Db(e)}static parseMySQLToJSONv2(e){return Z7(e,`mysql`)}static parseMySQLToJSON(e){return G7e.default.parse(e)}static parsePostgresToJSONv2(e){return Z7(e,`postgres`)}static parsePostgresToJSON(e){return K7e.default.parse(e)}static parseDBMLToJSONv2(e,t){let n=t||new oy;n.setSource(mm,e);let r=n.parse.errors(mm).map(e=>({message:e.diagnostic,location:{start:{line:e.nodeOrToken.startPos.line+1,column:e.nodeOrToken.startPos.column+1},end:{line:e.nodeOrToken.endPos.line+1,column:e.nodeOrToken.endPos.column+1}},code:e.code}));if(r.length>0)throw W7.create(r);return n.parse.rawDb(mm)}static parseDBMLToJSON(e){return U7e.default.parse(e)}static parseSchemaRbToJSON(e){return q7e.default.parse(e)}static parseMSSQLToJSON(e){return W7e.default.parseWithPegError(e)}static parseMSSQLToJSONv2(e){return Z7(e,`mssql`)}static parseSnowflakeToJSON(e){return Z7(e,`snowflake`)}static parseOracleToJSON(e){return Z7(e,`oracle`)}static parse(t,n){return new e().parse(t,n)}parse(t,n){try{let r={};switch(n){case`mysql`:r=e.parseMySQLToJSONv2(t);break;case`mysqlLegacy`:r=e.parseMySQLToJSON(t);break;case`postgres`:r=e.parsePostgresToJSONv2(t);break;case`snowflake`:r=e.parseSnowflakeToJSON(t);break;case`postgresLegacy`:r=e.parsePostgresToJSON(t);break;case`dbml`:r=e.parseDBMLToJSON(t);break;case`dbmlv2`:r=e.parseDBMLToJSONv2(t,this.DBMLCompiler);break;case`schemarb`:r=e.parseSchemaRbToJSON(t);break;case`mssqlLegacy`:r=e.parseMSSQLToJSON(t);break;case`mssql`:r=e.parseMSSQLToJSONv2(t);break;case`oracle`:r=e.parseOracleToJSON(t);break;case`json`:r=typeof t==`object`?t:JSON.parse(t);break;default:break}return e.parseJSONToDatabase(r)}catch(e){throw W7.create(e)}}},Y7e=J7e;function X7e(e,t,n={isNormalized:!0,includeRecords:!0}){let r=Z7e(n),i=new Y7e().parse(e,`dbmlv2`);return $9.export(i.normalize(),t,r)}function Z7e(e={}){if(typeof e==`boolean`)return{isNormalized:e,includeRecords:!0};let{isNormalized:t=!0,includeRecords:n=!0}=e;return{isNormalized:t,includeRecords:n}}var Q7e={export:X7e},$7e=class{static export(e,t,n={isNormalized:!0,includeRecords:!0}){let{isNormalized:r,includeRecords:i}=Z7e(n),a=e instanceof Db?e.normalize():e,o=``;switch(t){case`dbml`:o=rxe.export(a,{includeRecords:i});break;case`mysql`:o=axe.export(a);break;case`postgres`:o=uxe.export(a);break;case`json`:o=Uxe.export(e,{isNormalized:r});break;case`mssql`:o=Gxe.export(a);break;case`oracle`:o=qxe.export(a);break;default:break}return o}},$9=$7e,e9e=e=>new Db(e),t9e=e=>e.map(e=>{let{name:t,endpoints:n,onDelete:r,onUpdate:i}=e;return new m3e({name:t,endpoints:n.map(e=>new M7(e)),onDelete:r,onUpdate:i}).toJSON()}),n9e=e=>e.map(e=>{let{name:t,schemaName:n,values:r}=e;return new N7({name:t,schemaName:n,values:r})}),r9e=(e,t)=>e.map(e=>{let n=t[e.name]||{};return new A7({name:e.name,type:e.type,dbdefault:e.dbdefault,not_null:e.not_null,increment:e.increment,pk:n.pk||e.pk,unique:n.unique||e.unique,note:e.note,checks:n.checks})}),i9e=e=>e.map(e=>{let{name:t,unique:n,pk:r,type:i,columns:a}=e;return new k7({name:t,unique:n,pk:r,type:i,columns:a})}),a9e=(e,t,n,r,i)=>e.map(e=>{let{name:a,schemaName:o,note:s}=e,c=o?`${o}.${a}`:`${a}`,l=i[c]||{};return new j7({name:a,schemaName:o,fields:r9e(t[c],l),indexes:i9e(n[c]||[]),note:s,checks:r[c]})}),o9e=e=>{let{tables:t,fields:n,indexes:r,refs:i,enums:a,tableConstraints:o,checks:s}=e;try{let e=a9e(t,n,r,s,o),c=n9e(a);return e9e({schemas:[],tables:e,refs:t9e(i),enums:c,tableGroups:[],aliases:[],project:{}})}catch(e){throw Error(e)}};function s9e(e,t,n={includeRecords:!0}){let{includeRecords:r=!0}=n,i=new Y7e().parse(e,t);return $9.export(i.normalize(),`dbml`,{includeRecords:r})}function c9e(e){let t=o9e(e);return $9.export(t.normalize(),`dbml`)}var l9e={import:s9e,generateDbml:c9e};function u9e(e,t,n){let r=new oy;return r.setSource(mm,n),r.renameTable(mm,e,t).getSource(mm)??n}function d9e(e,t,n){let r=new oy;return r.setSource(mm,e),r.syncDiagramView(mm,t,n)}function f9e(e){let t=new oy;return t.setSource(mm,e),t.findDiagramViewBlocks(mm)}const p9e=`8.0.0-alpha.7`,m9e=`8.0.0-alpha.7`;exports.CompilerError=W7,exports.ModelExporter=$9,exports.Parser=Y7e,exports.VERSION=`8.0.0-alpha.7`,exports.addDoubleQuoteIfNeeded=gv,exports.dbmlMonarchTokensProvider=Dhe,exports.exporter=Q7e,exports.findDiagramViewBlocks=f9e,exports.formatRecordValue=Cfe,exports.importer=l9e,exports.isBinaryType=hg,exports.isBooleanType=pg,exports.isDateTimeType=gg,exports.isFloatType=dg,exports.isIntegerType=ug,exports.isNumericType=fg,exports.isSerialType=_g,exports.isStringType=mg,exports.renameTable=u9e,exports.syncDiagramView=d9e,exports.tryExtractBoolean=ov,exports.tryExtractDateTime=cv,exports.tryExtractEnum=ude,exports.tryExtractInteger=sde,exports.tryExtractNumeric=av,exports.tryExtractString=sv;
158
+ `,`\r`],!1,!1),xt=` `,St=At(` `,!1),y=0,Ct=0,wt=[{line:1,column:1}],Tt=0,Et=[],Dt=0,Ot;if(`startRule`in t){if(!(t.startRule in i))throw Error(`Can't start parsing from rule "`+t.startRule+`".`);a=i[t.startRule]}function kt(e,t){throw t=t===void 0?Ft(Ct,y):t,Lt(e,t)}function At(e,t){return{type:`literal`,text:e,ignoreCase:t}}function jt(e,t,n){return{type:`class`,parts:e,inverted:t,ignoreCase:n}}function Mt(){return{type:`end`}}function Nt(e){return{type:`other`,description:e}}function Pt(t){var n=wt[t],r;if(n)return n;for(r=t-1;!wt[r];)r--;for(n=wt[r],n={line:n.line,column:n.column};r<t;)e.charCodeAt(r)===10?(n.line++,n.column=1):n.column++,r++;return wt[t]=n,n}function Ft(e,t){var n=Pt(e),r=Pt(t);return{start:{offset:e,line:n.line,column:n.column},end:{offset:t,line:r.line,column:r.column}}}function It(e){y<Tt||(y>Tt&&(Tt=y,Et=[]),Et.push(e))}function Lt(e,t){return new r(e,null,null,t)}function Rt(e,t,n){return new r(r.buildMessage(e,t),e,t,n)}function zt(){for(var e=y,t=[],r=Bt();r!==n;)t.push(r),r=Bt();return t!==n&&(Ct=e,t=o()),e=t,e}function Bt(){for(var e=y,t=[],r=An();r!==n;)t.push(r),r=An();return t===n?(y=e,e=n):(r=Vt(),r===n?(y=e,e=n):(t=[t,r],e=t)),e===n&&(e=xn(),e===n&&(e=bn(),e===n&&(e=En()))),e}function Vt(){var e=y,t=Gt();return t!==n&&(Ct=e,t=s(t)),e=t,e===n&&(e=y,t=Ut(),t!==n&&(Ct=e,t=c(t)),e=t,e===n&&(e=Ht(),e===n&&(e=fn()))),e}function Ht(){for(var t=y,r=[],i=jn(),a,o,s,c,f,p,m;i!==n;)r.push(i),i=jn();if(r!==n)if(i=sn(),i!==n){for(a=[],o=jn();o!==n;)a.push(o),o=jn();if(a!==n)if(o=gn(),o===n&&(o=pn()),o!==n)if(e.charCodeAt(y)===44?(s=l,y++):(s=n,Dt===0&&It(u)),s!==n){for(c=[],f=jn();f!==n;)c.push(f),f=jn();if(c!==n)if(f=pn(),f!==n){for(p=[],m=en();m!==n;)p.push(m),m=en();p===n?(y=t,t=n):(Ct=t,r=d(o,f,p),t=r)}else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;return t}function Ut(){for(var t=y,r=[],i=jn(),a,o,s,c,d,p,m;i!==n;)r.push(i),i=jn();if(r!==n)if(i=cn(),i!==n){for(a=[],o=jn();o!==n;)a.push(o),o=jn();if(a!==n)if(o=pn(),o!==n)if(e.charCodeAt(y)===44?(s=l,y++):(s=n,Dt===0&&It(u)),s!==n){for(c=[],d=jn();d!==n;)c.push(d),d=jn();if(c!==n)if(d=pn(),d!==n){for(p=[],m=Wt();m!==n;)p.push(m),m=Wt();p===n?(y=t,t=n):(Ct=t,r=f(o,d,p),t=r)}else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;else y=t,t=n;return t}function Wt(){var t=y,r,i,a,o,s,c;if(e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=ln(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=h(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;if(t===n){if(t=y,e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=un(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=g(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;if(t===n)if(t=y,e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(a=tn(),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=gn(),c===n?(y=t,t=n):(Ct=t,r=_(a,c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n}return t}function Gt(){var e=y,t=nn(),r,i,a,o,s,c;if(t!==n){for(r=[],i=jn();i!==n;)r.push(i),i=jn();r===n?(y=e,e=n):(i=pn(),i===n?(y=e,e=n):(a=Sn(),a===n?(y=e,e=n):(o=Dn(),o===n?(y=e,e=n):(s=Kt(),s===n?(y=e,e=n):(c=bn(),c===n?(y=e,e=n):(Ct=e,t=ee(i,s),e=t))))))}else y=e,e=n;return e}function Kt(){for(var e=y,t=[],r=qt();r!==n;)t.push(r),r=qt();return t!==n&&(Ct=e,t=te(t)),e=t,e}function qt(){for(var e=y,t=[],r=An(),i,a;r!==n;)t.push(r),r=An();if(t!==n)if(r=Jt(),r!==n){for(i=[],a=Cn();a!==n;)i.push(a),a=Cn();i===n?(y=e,e=n):(a=Dn(),a===n?(y=e,e=n):(Ct=e,t=ne(r),e=t))}else y=e,e=n;else y=e,e=n;return e}function Jt(){var e=Yt(),t;return e===n&&(e=y,t=Xt(),t!==n&&(Ct=e,t=v(t)),e=t,e===n&&(e=y,t=Zt(),t!==n&&(Ct=e,t=re(t)),e=t,e===n&&(e=y,t=Qt(),t!==n&&(Ct=e,t=ie(t)),e=t))),e}function Yt(){var e=y,t=rn(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=Sn(),i===n?(y=e,e=n):(t=[t,r,i],e=t))}else y=e,e=n;return e}function Xt(){var e=y,t=an(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=$t(),i===n?(y=e,e=n):(Ct=e,t=ae(i),e=t))}else y=e,e=n;return e}function Zt(){var e=y,t=on(),r,i,a,o;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;if(r!==n)if(i=pn(),i!==n){for(a=[],o=en();o!==n;)a.push(o),o=en();a===n?(y=e,e=n):(Ct=e,t=oe(i,a),e=t)}else y=e,e=n;else y=e,e=n}else y=e,e=n;return e}function Qt(){var e=y,t=vn(),r,i;if(t!==n){if(r=[],i=jn(),i!==n)for(;i!==n;)r.push(i),i=jn();else r=n;r===n?(y=e,e=n):(i=pn(),i===n?(y=e,e=n):(Ct=e,t=se(t,i),e=t))}else y=e,e=n;return e}function $t(){var t=y,r,i;return e.charCodeAt(y)===58?(r=p,y++):(r=n,Dt===0&&It(m)),r===n?(y=t,t=n):(i=_n(),i===n?(y=t,t=n):(Ct=t,r=ce(i),t=r)),t===n&&(t=y,r=pn(),r!==n&&(Ct=t,r=ce(r)),t=r),t}function en(){var t=y,r,i,a,o,s,c;if(e.charCodeAt(y)===44?(r=l,y++):(r=n,Dt===0&&It(u)),r!==n){for(i=[],a=jn();a!==n;)i.push(a),a=jn();if(i!==n)if(e.substr(y,4).toLowerCase()===le?(a=e.substr(y,4),y+=4):(a=n,Dt===0&&It(ue)),a!==n)if(e.charCodeAt(y)===58?(o=p,y++):(o=n,Dt===0&&It(m)),o!==n){for(s=[],c=jn();c!==n;)s.push(c),c=jn();s===n?(y=t,t=n):(c=pn(),c===n?(y=t,t=n):(Ct=t,r=de(c),t=r))}else y=t,t=n;else y=t,t=n;else y=t,t=n}else y=t,t=n;return t}function tn(){var t;return e.substr(y,9).toLowerCase()===fe?(t=e.substr(y,9),y+=9):(t=n,Dt===0&&It(pe)),t===n&&(e.substr(y,9).toLowerCase()===me?(t=e.substr(y,9),y+=9):(t=n,Dt===0&&It(he))),t}function nn(){var t;return Dt++,e.substr(y,12).toLowerCase()===_e?(t=e.substr(y,12),y+=12):(t=n,Dt===0&&It(ve)),Dt--,t===n&&Dt===0&&It(ge),t}function rn(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,6)===be?(i=be,y+=6):(i=n,Dt===0&&It(xe)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(ye)),t}function an(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,11)===Ce?(i=Ce,y+=11):(i=n,Dt===0&&It(we)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(Se)),t}function on(){var t,r,i;return Dt++,t=y,r=yn(),r===n?(y=t,t=n):(e.substr(y,17)===Ee?(i=Ee,y+=17):(i=n,Dt===0&&It(De)),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(Te)),t}function sn(){var t;return Dt++,e.substr(y,20).toLowerCase()===ke?(t=e.substr(y,20),y+=20):(t=n,Dt===0&&It(Ae)),Dt--,t===n&&Dt===0&&It(Oe),t}function cn(){var t;return Dt++,e.substr(y,15).toLowerCase()===Me?(t=e.substr(y,15),y+=15):(t=n,Dt===0&&It(Ne)),Dt--,t===n&&Dt===0&&It(je),t}function ln(){var t;return Dt++,e.substr(y,6)===Fe?(t=Fe,y+=6):(t=n,Dt===0&&It(Ie)),Dt--,t===n&&Dt===0&&It(Pe),t}function un(){var t;return Dt++,e.substr(y,11)===Re?(t=Re,y+=11):(t=n,Dt===0&&It(ze)),Dt--,t===n&&Dt===0&&It(Le),t}function dn(){var t;return e.substr(y,3)===Be?(t=Be,y+=3):(t=n,Dt===0&&It(Ve)),t}function fn(){var e=y,t=_n(),r,i;return t===n?(y=e,e=n):(r=Sn(),r===n?(y=e,e=n):(i=Dn(),i===n&&(i=null),i===n?(y=e,e=n):(t=[t,r,i],e=t))),e}function pn(){var e=mn();return e===n&&(e=hn()),e}function mn(){var t=y,r=Tn(),i,a;if(r!==n){for(i=[],He.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ue));a!==n;)i.push(a),He.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ue));i===n?(y=t,t=n):(a=Tn(),a===n?(y=t,t=n):(Ct=t,r=We(i),t=r))}else y=t,t=n;return t}function hn(){var t=y,r=wn(),i,a;if(r!==n){for(i=[],Ge.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ke));a!==n;)i.push(a),Ge.test(e.charAt(y))?(a=e.charAt(y),y++):(a=n,Dt===0&&It(Ke));i===n?(y=t,t=n):(a=wn(),a===n?(y=t,t=n):(Ct=t,r=We(i),t=r))}else y=t,t=n;return t}function gn(){var t=y,r,i,a;if(e.charCodeAt(y)===58?(r=p,y++):(r=n,Dt===0&&It(m)),r!==n){for(i=[],a=yn();a!==n;)i.push(a),a=yn();i===n?(y=t,t=n):(Ct=t,r=We(i),t=r)}else y=t,t=n;return t}function _n(){var e=y,t=[],r=yn();if(r!==n)for(;r!==n;)t.push(r),r=yn();else t=n;return t!==n&&(Ct=e,t=We(t)),e=t,e}function vn(){var t=y,r=yn(),i,a,o;if(r!==n)if(e.charCodeAt(y)===46?(i=qe,y++):(i=n,Dt===0&&It(Je)),i!==n){if(a=[],o=yn(),o!==n)for(;o!==n;)a.push(o),o=yn();else a=n;a===n?(y=t,t=n):(Ct=t,r=We(a),t=r)}else y=t,t=n;else y=t,t=n;return t}function yn(){var t;return Dt++,Xe.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(Ze)),Dt--,t===n&&Dt===0&&It(Ye),t}function bn(){for(var e=y,t=[],r=An(),i;r!==n;)t.push(r),r=An();return t===n?(y=e,e=n):(r=dn(),r===n?(y=e,e=n):(i=Dn(),i===n&&(i=null),i===n?(y=e,e=n):(t=[t,r,i],e=t))),e}function xn(){var t,r,i,a,o;for(Dt++,t=y,r=[],i=An();i!==n;)r.push(i),i=An();return r===n?(y=t,t=n):(e.charCodeAt(y)===35?(i=$e,y++):(i=n,Dt===0&&It(et)),i===n?(y=t,t=n):(a=Sn(),a===n?(y=t,t=n):(o=Dn(),o===n&&(o=null),o===n?(y=t,t=n):(r=[r,i,a,o],t=r)))),Dt--,t===n&&(r=n,Dt===0&&It(Qe)),t}function Sn(){var t,r;for(Dt++,t=[],nt.test(e.charAt(y))?(r=e.charAt(y),y++):(r=n,Dt===0&&It(rt));r!==n;)t.push(r),nt.test(e.charAt(y))?(r=e.charAt(y),y++):(r=n,Dt===0&&It(rt));return Dt--,t===n&&(r=n,Dt===0&&It(tt)),t}function Cn(){var t;return nt.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(rt)),t}function wn(){var t;return e.charCodeAt(y)===39?(t=it,y++):(t=n,Dt===0&&It(at)),t}function Tn(){var t;return e.charCodeAt(y)===34?(t=ot,y++):(t=n,Dt===0&&It(st)),t}function En(){var e=[],t=On();if(t===n&&(t=An()),t!==n)for(;t!==n;)e.push(t),t=On(),t===n&&(t=An());else e=n;return e}function Dn(){for(var e=y,t=[],r=jn();r!==n;)t.push(r),r=jn();return t===n?(y=e,e=n):(r=kn(),r===n?(y=e,e=n):(t=[t,r],e=t)),e}function On(){var t,r,i;return Dt++,t=y,e.substr(y,2)===lt?(r=lt,y+=2):(r=n,Dt===0&&It(ut)),r===n?(y=t,t=n):(dt.test(e.charAt(y))?(i=e.charAt(y),y++):(i=n,Dt===0&&It(ft)),i===n&&(i=null),i===n?(y=t,t=n):(r=[r,i],t=r)),Dt--,t===n&&(r=n,Dt===0&&It(ct)),t}function kn(){var t;return Dt++,e.substr(y,2)===mt?(t=mt,y+=2):(t=n,Dt===0&&It(ht)),t===n&&(e.charCodeAt(y)===10?(t=gt,y++):(t=n,Dt===0&&It(_t))),Dt--,t===n&&Dt===0&&It(pt),t}function An(){var t;return Dt++,yt.test(e.charAt(y))?(t=e.charAt(y),y++):(t=n,Dt===0&&It(bt)),Dt--,t===n&&Dt===0&&It(vt),t}function jn(){var t;return e.charCodeAt(y)===32?(t=xt,y++):(t=n,Dt===0&&It(St)),t}var Mn=$7(),Nn=Q7();let Pn={tables:[],refs:[]};function Fn(e){Pn.tables.find(t=>t.name==e.name)?kt(`Duplicated table name`):(e.fields.find(e=>e.name===`id`)||e.fields.unshift({name:`id`,type:{type_name:`varchar`}}),Pn.tables.push(e))}function In(e,t,n){let r=Pn.tables.find(t=>t.name===e);r||kt("Table ${tableName} not found"),r.checks||=[];let i={expression:t};n&&(i.name=n),r.checks.push(i)}function Ln(e=[],t=[]){let n=t.find(e=>e.name===`primary_key`);return n?e.find(e=>e.name===n.value)?e.map(({name:e,type:t})=>({name:e,type:t,PK:n.value===field.name})):[{name:n.value,type:{type_name:`varchar`},PK:!0}].concat(e):e}function Rn(e,t){return e.tableName==t.tableName&&Nn.isEqual(Nn.sortBy(e.fieldNames),Nn.sortBy(t.fieldNames))}function zn(e,t){return Rn(e[0],t[0])&&Rn(e[1],t[1])}function Bn(e,t){return zn(e.endpoints,t.endpoints)||zn(e.endpoints,t.endpoints.slice().reverse())}function Vn(e){e&&(Pn.refs.find(t=>Bn(t,e))&&kt(`Duplicated references`),Pn.refs.push(e))}function Hn(e=[]){if(!(!e||e.length===0))for(let t=0;t<e.length;t+=1)Vn(e[t])}function Un(e){let{tables:t}=Pn,{endpoints:n}=e,r=t.find(e=>e.name===n[0].tableName);if(!r||!t.find(e=>e.name===n[1].tableName))return null;if(!n[0].fieldNames){let e=`${Mn.singular(n[1].tableName)}_id`;if(n[0].fieldNames=[e],!r.fields.find(t=>t.name===e))return null;n[0].fieldNames=[e]}return n[1].fieldNames||(n[1].fieldNames=[`id`]),e}function Wn(e,t,n){let r=[{tableName:e,relation:`1`},{tableName:t,relation:`1`}],i={};for(let e=0;e<n.length;e+=1){let t=n[e];t.columnName&&(r[0].fieldNames=[t.columnName]),t.primaryKey&&(r[1].fieldNames=[t.primaryKey]),t.onDelete&&(i={...i,onDelete:t.onDelete}),t.onUpdate&&(i={...i,onUpdate:t.onUpdate})}return{name:`fk_rails_${e}_${t}`,endpoints:r,...i}}function Gn(e,t){if(!t||t.length===0)return[];let n=[];for(let r=0;r<t.length;r+=1){let i=t[r],a=Mn.plural(i),{tables:o}=Pn,s=o.find(e=>e.name===a);if(!s)continue;let c=`${i}_id`,l=e.fields.find(e=>e.name===c),u=s.fields.find(e=>e.name===`id`);l||e.fields.push({name:c,type:{type_name:u?u.type.type_name:`varchar`}}),n.push({name:`fk_rails_${e.name}_${a}`,endpoints:[{tableName:e.name,fieldNames:[c],relation:`1`},{tableName:a,fieldNames:[`id`],relation:`1`}]})}return n}function Kn(e){let{tables:t,refs:n}=e,r=t.map(e=>{let{name:t}=e;return{name:t,field:`${Mn.singular(t)}_id`}});for(let e=0;e<t.length;e+=1){let i=t[e],{fields:a}=i;for(let e=0;e<a.length;e+=1){let t=a[e],o=r.find(e=>e.field===t.name);if(o){let e={name:`fk_rails_${i.name}_${o.name}`,endpoints:[{tableName:i.name,fieldNames:[t.name],relation:`1`},{tableName:o.name,fieldNames:[`id`],relation:`1`}]};n.find(t=>Bn(t,e))||n.push(e)}}}return e}if(Ot=a(),Ot!==n&&y===e.length)return Ot;throw Ot!==n&&y<e.length&&It(Mt()),Rt(Et,Tt<e.length?e.charAt(Tt):null,Tt<e.length?Ft(Tt,Tt+1):Ft(Tt,Tt))}t.exports={SyntaxError:r,parse:i}})),U7e=u(I3e()),W7e=u(z7e()),G7e=u(B7e()),K7e=u(V7e()),q7e=u(H7e()),J7e=class e{constructor(e){this.DBMLCompiler=e||new oy}static parseJSONToDatabase(e){return new Db(e)}static parseMySQLToJSONv2(e){return Z7(e,`mysql`)}static parseMySQLToJSON(e){return G7e.default.parse(e)}static parsePostgresToJSONv2(e){return Z7(e,`postgres`)}static parsePostgresToJSON(e){return K7e.default.parse(e)}static parseDBMLToJSONv2(e,t){let n=t||new oy;n.setSource(mm,e);let r=n.parse.errors(mm).map(e=>({message:e.diagnostic,location:{start:{line:e.nodeOrToken.startPos.line+1,column:e.nodeOrToken.startPos.column+1},end:{line:e.nodeOrToken.endPos.line+1,column:e.nodeOrToken.endPos.column+1}},code:e.code}));if(r.length>0)throw W7.create(r);return n.parse.rawDb(mm)}static parseDBMLToJSON(e){return U7e.default.parse(e)}static parseSchemaRbToJSON(e){return q7e.default.parse(e)}static parseMSSQLToJSON(e){return W7e.default.parseWithPegError(e)}static parseMSSQLToJSONv2(e){return Z7(e,`mssql`)}static parseSnowflakeToJSON(e){return Z7(e,`snowflake`)}static parseOracleToJSON(e){return Z7(e,`oracle`)}static parse(t,n){return new e().parse(t,n)}parse(t,n){try{let r={};switch(n){case`mysql`:r=e.parseMySQLToJSONv2(t);break;case`mysqlLegacy`:r=e.parseMySQLToJSON(t);break;case`postgres`:r=e.parsePostgresToJSONv2(t);break;case`snowflake`:r=e.parseSnowflakeToJSON(t);break;case`postgresLegacy`:r=e.parsePostgresToJSON(t);break;case`dbml`:r=e.parseDBMLToJSON(t);break;case`dbmlv2`:r=e.parseDBMLToJSONv2(t,this.DBMLCompiler);break;case`schemarb`:r=e.parseSchemaRbToJSON(t);break;case`mssqlLegacy`:r=e.parseMSSQLToJSON(t);break;case`mssql`:r=e.parseMSSQLToJSONv2(t);break;case`oracle`:r=e.parseOracleToJSON(t);break;case`json`:r=typeof t==`object`?t:JSON.parse(t);break;default:break}return e.parseJSONToDatabase(r)}catch(e){throw W7.create(e)}}},Y7e=J7e;function X7e(e,t,n={isNormalized:!0,includeRecords:!0}){let r=Z7e(n),i=new Y7e().parse(e,`dbmlv2`);return $9.export(i.normalize(),t,r)}function Z7e(e={}){if(typeof e==`boolean`)return{isNormalized:e,includeRecords:!0};let{isNormalized:t=!0,includeRecords:n=!0}=e;return{isNormalized:t,includeRecords:n}}var Q7e={export:X7e},$7e=class{static export(e,t,n={isNormalized:!0,includeRecords:!0}){let{isNormalized:r,includeRecords:i}=Z7e(n),a=e instanceof Db?e.normalize():e,o=``;switch(t){case`dbml`:o=rxe.export(a,{includeRecords:i});break;case`mysql`:o=axe.export(a);break;case`postgres`:o=uxe.export(a);break;case`json`:o=Uxe.export(e,{isNormalized:r});break;case`mssql`:o=Gxe.export(a);break;case`oracle`:o=qxe.export(a);break;default:break}return o}},$9=$7e,e9e=e=>new Db(e),t9e=e=>e.map(e=>{let{name:t,endpoints:n,onDelete:r,onUpdate:i}=e;return new m3e({name:t,endpoints:n.map(e=>new M7(e)),onDelete:r,onUpdate:i}).toJSON()}),n9e=e=>e.map(e=>{let{name:t,schemaName:n,values:r}=e;return new N7({name:t,schemaName:n,values:r})}),r9e=(e,t)=>e.map(e=>{let n=t[e.name]||{};return new A7({name:e.name,type:e.type,dbdefault:e.dbdefault,not_null:e.not_null,increment:e.increment,pk:n.pk||e.pk,unique:n.unique||e.unique,note:e.note,checks:n.checks})}),i9e=e=>e.map(e=>{let{name:t,unique:n,pk:r,type:i,columns:a}=e;return new k7({name:t,unique:n,pk:r,type:i,columns:a})}),a9e=(e,t,n,r,i)=>e.map(e=>{let{name:a,schemaName:o,note:s}=e,c=o?`${o}.${a}`:`${a}`,l=i[c]||{};return new j7({name:a,schemaName:o,fields:r9e(t[c],l),indexes:i9e(n[c]||[]),note:s,checks:r[c]})}),o9e=e=>{let{tables:t,fields:n,indexes:r,refs:i,enums:a,tableConstraints:o,checks:s}=e;try{let e=a9e(t,n,r,s,o),c=n9e(a);return e9e({schemas:[],tables:e,refs:t9e(i),enums:c,tableGroups:[],aliases:[],project:{}})}catch(e){throw Error(e)}};function s9e(e,t,n={includeRecords:!0}){let{includeRecords:r=!0}=n,i=new Y7e().parse(e,t);return $9.export(i.normalize(),`dbml`,{includeRecords:r})}function c9e(e){let t=o9e(e);return $9.export(t.normalize(),`dbml`)}var l9e={import:s9e,generateDbml:c9e};function u9e(e,t,n){let r=new oy;return r.setSource(mm,n),r.renameTable(mm,e,t).getSource(mm)??n}function d9e(e,t,n){let r=new oy;return r.setSource(mm,e),r.syncDiagramView(mm,t,n)}function f9e(e){let t=new oy;return t.setSource(mm,e),t.findDiagramViewBlocks(mm)}const p9e=`8.0.0-alpha.9`,m9e=`8.0.0-alpha.9`;exports.CompilerError=W7,exports.ModelExporter=$9,exports.Parser=Y7e,exports.VERSION=`8.0.0-alpha.9`,exports.addDoubleQuoteIfNeeded=gv,exports.dbmlMonarchTokensProvider=Dhe,exports.exporter=Q7e,exports.findDiagramViewBlocks=f9e,exports.formatRecordValue=Cfe,exports.importer=l9e,exports.isBinaryType=hg,exports.isBooleanType=pg,exports.isDateTimeType=gg,exports.isFloatType=dg,exports.isIntegerType=ug,exports.isNumericType=fg,exports.isSerialType=_g,exports.isStringType=mg,exports.renameTable=u9e,exports.syncDiagramView=d9e,exports.tryExtractBoolean=ov,exports.tryExtractDateTime=cv,exports.tryExtractEnum=ude,exports.tryExtractInteger=sde,exports.tryExtractNumeric=av,exports.tryExtractString=sv;