@dbml/parse 7.1.0-alpha.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,25 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},n=/^[A-Za-z]:\//;function r(e=``){return e&&e.replace(/\\/g,`/`).replace(n,e=>e.toUpperCase())}var i=/^[/\\]{2}/,a=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,o=/^[A-Za-z]:$/,s=/^\/([A-Za-z]:)?$/,c=/.(\.[^./]+|\.)$/,l=function(e){if(e.length===0)return`.`;e=r(e);let t=e.match(i),n=m(e),a=e[e.length-1]===`/`;return e=p(e,!n),e.length===0?n?`/`:a?`./`:`.`:(a&&(e+=`/`),o.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!m(e)?`/${e}`:e)},u=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 l(t)};function d(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var f=function(...e){e=e.map(e=>r(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:d();!i||i.length===0||(t=`${i}/${t}`,n=m(i))}return t=p(t,!n),n&&!m(t)?`/${t}`:t.length>0?t:`.`};function p(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 m=function(e){return a.test(e)},ee=function(e){if(e===`..`)return``;let t=c.exec(r(e));return t&&t[1]||``},te=function(e,t){let n=f(e).replace(s,`$1`).split(`/`),r=f(t).replace(s,`$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(`/`)},ne=function(e){let t=r(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&o.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(m(e)?`/`:`.`)},re=function(e,t){let n=r(e).split(`/`),i=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){i=t;break}}return t&&i.endsWith(t)?i.slice(0,-t.length):i},ie=/^[a-zA-Z]:\//,ae=class e{constructor(e){let t=l(e);if(!m(t))throw Error(`FilePath requires an absolute path, got: "${e}"`);this.path=t}intern(){return`filepath@${this.path}`}static from(t){return new e(t)}static resolve(t,n){return new e(f(t,n))}static fromUri(t){if(t.startsWith(`file://`)){let n=decodeURIComponent(new URL(t).pathname);return/^\/[a-zA-Z]:[\\/]/.test(n)&&(n=n.slice(1)),new e(l(n))}return new e(l(t))}get absolute(){return this.path}get dirname(){return ne(this.path)}get basename(){return re(this.path)}get extname(){return ee(this.path)}resolve(t){return new e(f(this.dirname,t))}join(...t){return new e(u(this.path,...t))}relativeTo(e){return te(e,this.path)}toString(){return this.path}equals(e){return this.path===e.path}toUri(){let e=ie.test(this.path)?`file:///`:`file://`;return new URL(e+this.path).href}static isRelative(e){return!m(l(e))}};const oe=[`null`,`true`,`false`],se=[`-`,`+`],ce=`public`,le=ae.from(`/main.dbml`),ue=ae.from(`/`);let h=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.Check=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e}({}),g=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}({});var de=typeof global==`object`&&global&&global.Object===Object&&global,fe=de,pe=typeof self==`object`&&self&&self.Object===Object&&self,me=fe||pe||Function(`return this`)(),he=me,ge=he.Symbol,_e=ge,ve=Object.prototype,ye=ve.hasOwnProperty,be=ve.toString,xe=_e?_e.toStringTag:void 0;function Se(e){var t=ye.call(e,xe),n=e[xe];try{e[xe]=void 0;var r=!0}catch{}var i=be.call(e);return r&&(t?e[xe]=n:delete e[xe]),i}var Ce=Se,we=Object.prototype.toString;function Te(e){return we.call(e)}var Ee=Te,De=`[object Null]`,Oe=`[object Undefined]`,ke=_e?_e.toStringTag:void 0;function Ae(e){return e==null?e===void 0?Oe:De:ke&&ke in Object(e)?Ce(e):Ee(e)}var je=Ae;function Me(e){return typeof e==`object`&&!!e}var Ne=Me,Pe=`[object Symbol]`;function Fe(e){return typeof e==`symbol`||Ne(e)&&je(e)==Pe}var Ie=Fe;function Le(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 Re=Le,ze=Array.isArray,Be=ze,Ve=1/0,He=_e?_e.prototype:void 0,Ue=He?He.toString:void 0;function We(e){if(typeof e==`string`)return e;if(Be(e))return Re(e,We)+``;if(Ie(e))return Ue?Ue.call(e):``;var t=e+``;return t==`0`&&1/e==-Ve?`-0`:t}var Ge=We,Ke=/\s/;function qe(e){for(var t=e.length;t--&&Ke.test(e.charAt(t)););return t}var Je=qe,Ye=/^\s+/;function Xe(e){return e&&e.slice(0,Je(e)+1).replace(Ye,``)}var Ze=Xe;function Qe(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var $e=Qe,et=NaN,tt=/^[-+]0x[0-9a-f]+$/i,nt=/^0b[01]+$/i,rt=/^0o[0-7]+$/i,it=parseInt;function at(e){if(typeof e==`number`)return e;if(Ie(e))return et;if($e(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=$e(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Ze(e);var n=nt.test(e);return n||rt.test(e)?it(e.slice(2),n?2:8):tt.test(e)?et:+e}var ot=at,st=1/0,ct=17976931348623157e292;function lt(e){return e?(e=ot(e),e===st||e===-st?(e<0?-1:1)*ct:e===e?e:0):e===0?e:0}var ut=lt;function dt(e){var t=ut(e),n=t%1;return t===t?n?t-n:t:0}var ft=dt;function pt(e){return e}var mt=pt,ht=`[object AsyncFunction]`,gt=`[object Function]`,_t=`[object GeneratorFunction]`,vt=`[object Proxy]`;function yt(e){if(!$e(e))return!1;var t=je(e);return t==gt||t==_t||t==ht||t==vt}var bt=yt,xt=he[`__core-js_shared__`],St=xt,Ct=function(){var e=/[^.]+$/.exec(St&&St.keys&&St.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function wt(e){return!!Ct&&Ct in e}var Tt=wt,Et=Function.prototype.toString;function Dt(e){if(e!=null){try{return Et.call(e)}catch{}try{return e+``}catch{}}return``}var Ot=Dt,kt=/[\\^$.*+?()[\]{}|]/g,At=/^\[object .+?Constructor\]$/,jt=Function.prototype,Mt=Object.prototype,Nt=jt.toString,Pt=Mt.hasOwnProperty,Ft=RegExp(`^`+Nt.call(Pt).replace(kt,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function It(e){return!$e(e)||Tt(e)?!1:(bt(e)?Ft:At).test(Ot(e))}var Lt=It;function Rt(e,t){return e?.[t]}var zt=Rt;function Bt(e,t){var n=zt(e,t);return Lt(n)?n:void 0}var Vt=Bt,Ht=Vt(he,`WeakMap`),Ut=Ht;function Wt(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 Gt=Wt;function Kt(){}var qt=Kt,Jt=800,Yt=16,Xt=Date.now;function Zt(e){var t=0,n=0;return function(){var r=Xt(),i=Yt-(r-n);if(n=r,i>0){if(++t>=Jt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var Qt=Zt;function $t(e){return function(){return e}}var en=$t,tn=function(){try{var e=Vt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),nn=tn,rn=nn?function(e,t){return nn(e,`toString`,{configurable:!0,enumerable:!1,value:en(t),writable:!0})}:mt,an=rn,on=Qt(an),sn=on;function cn(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 ln=cn;function un(e){return e!==e}var dn=un;function fn(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var pn=fn;function mn(e,t,n){return t===t?pn(e,t,n):ln(e,dn,n)}var hn=mn;function gn(e,t){return!!(e!=null&&e.length)&&hn(e,t,0)>-1}var _n=gn,vn=9007199254740991,yn=/^(?:0|[1-9]\d*)$/;function bn(e,t){var n=typeof e;return t??=vn,!!t&&(n==`number`||n!=`symbol`&&yn.test(e))&&e>-1&&e%1==0&&e<t}var xn=bn;function Sn(e,t,n){t==`__proto__`&&nn?nn(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var Cn=Sn;function wn(e,t){return e===t||e!==e&&t!==t}var Tn=wn,En=Math.max;function Dn(e,t,n){return t=En(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=En(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),Gt(e,this,s)}}var On=Dn;function kn(e,t){return sn(On(e,t,mt),e+``)}var An=kn,jn=9007199254740991;function Mn(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=jn}var Nn=Mn;function Pn(e){return e!=null&&Nn(e.length)&&!bt(e)}var Fn=Pn,In=Object.prototype;function Ln(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||In)}var Rn=Ln;function zn(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var Bn=zn,Vn=`[object Arguments]`;function Hn(e){return Ne(e)&&je(e)==Vn}var Un=Hn,Wn=Object.prototype,Gn=Wn.hasOwnProperty,Kn=Wn.propertyIsEnumerable,qn=Un(function(){return arguments}())?Un:function(e){return Ne(e)&&Gn.call(e,`callee`)&&!Kn.call(e,`callee`)},Jn=qn;function Yn(){return!1}var Xn=Yn,Zn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Qn=Zn&&typeof module==`object`&&module&&!module.nodeType&&module,$n=Qn&&Qn.exports===Zn?he.Buffer:void 0,er=($n?$n.isBuffer:void 0)||Xn,tr=er,nr=`[object Arguments]`,rr=`[object Array]`,ir=`[object Boolean]`,ar=`[object Date]`,or=`[object Error]`,sr=`[object Function]`,cr=`[object Map]`,lr=`[object Number]`,ur=`[object Object]`,dr=`[object RegExp]`,fr=`[object Set]`,pr=`[object String]`,mr=`[object WeakMap]`,hr=`[object ArrayBuffer]`,gr=`[object DataView]`,_r=`[object Float32Array]`,vr=`[object Float64Array]`,yr=`[object Int8Array]`,br=`[object Int16Array]`,xr=`[object Int32Array]`,Sr=`[object Uint8Array]`,Cr=`[object Uint8ClampedArray]`,wr=`[object Uint16Array]`,Tr=`[object Uint32Array]`,_={};_[_r]=_[vr]=_[yr]=_[br]=_[xr]=_[Sr]=_[Cr]=_[wr]=_[Tr]=!0,_[nr]=_[rr]=_[hr]=_[ir]=_[gr]=_[ar]=_[or]=_[sr]=_[cr]=_[lr]=_[ur]=_[dr]=_[fr]=_[pr]=_[mr]=!1;function Er(e){return Ne(e)&&Nn(e.length)&&!!_[je(e)]}var Dr=Er;function Or(e){return function(t){return e(t)}}var kr=Or,Ar=typeof exports==`object`&&exports&&!exports.nodeType&&exports,jr=Ar&&typeof module==`object`&&module&&!module.nodeType&&module,Mr=jr&&jr.exports===Ar&&fe.process,Nr=function(){try{return jr&&jr.require&&jr.require(`util`).types||Mr&&Mr.binding&&Mr.binding(`util`)}catch{}}(),Pr=Nr,Fr=Pr&&Pr.isTypedArray,Ir=Fr?kr(Fr):Dr,Lr=Ir,Rr=Object.prototype.hasOwnProperty;function zr(e,t){var n=Be(e),r=!n&&Jn(e),i=!n&&!r&&tr(e),a=!n&&!r&&!i&&Lr(e),o=n||r||i||a,s=o?Bn(e.length,String):[],c=s.length;for(var l in e)(t||Rr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||xn(l,c)))&&s.push(l);return s}var Br=zr;function Vr(e,t){return function(n){return e(t(n))}}var Hr=Vr,Ur=Hr(Object.keys,Object),Wr=Ur,Gr=Object.prototype.hasOwnProperty;function Kr(e){if(!Rn(e))return Wr(e);var t=[];for(var n in Object(e))Gr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var qr=Kr;function Jr(e){return Fn(e)?Br(e):qr(e)}var Yr=Jr;function Xr(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Zr=Xr,Qr=Object.prototype.hasOwnProperty;function $r(e){if(!$e(e))return Zr(e);var t=Rn(e),n=[];for(var r in e)r==`constructor`&&(t||!Qr.call(e,r))||n.push(r);return n}var ei=$r;function ti(e){return Fn(e)?Br(e,!0):ei(e)}var ni=ti,ri=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ii=/^\w*$/;function ai(e,t){if(Be(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||Ie(e)?!0:ii.test(e)||!ri.test(e)||t!=null&&e in Object(t)}var oi=ai,si=Vt(Object,`create`),ci=si;function li(){this.__data__=ci?ci(null):{},this.size=0}var ui=li;function di(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var fi=di,pi=`__lodash_hash_undefined__`,mi=Object.prototype.hasOwnProperty;function hi(e){var t=this.__data__;if(ci){var n=t[e];return n===pi?void 0:n}return mi.call(t,e)?t[e]:void 0}var gi=hi,_i=Object.prototype.hasOwnProperty;function vi(e){var t=this.__data__;return ci?t[e]!==void 0:_i.call(t,e)}var yi=vi,bi=`__lodash_hash_undefined__`;function xi(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=ci&&t===void 0?bi:t,this}var Si=xi;function Ci(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])}}Ci.prototype.clear=ui,Ci.prototype.delete=fi,Ci.prototype.get=gi,Ci.prototype.has=yi,Ci.prototype.set=Si;var wi=Ci;function Ti(){this.__data__=[],this.size=0}var Ei=Ti;function Di(e,t){for(var n=e.length;n--;)if(Tn(e[n][0],t))return n;return-1}var Oi=Di,ki=Array.prototype.splice;function Ai(e){var t=this.__data__,n=Oi(t,e);return n<0?!1:(n==t.length-1?t.pop():ki.call(t,n,1),--this.size,!0)}var ji=Ai;function Mi(e){var t=this.__data__,n=Oi(t,e);return n<0?void 0:t[n][1]}var Ni=Mi;function Pi(e){return Oi(this.__data__,e)>-1}var Fi=Pi;function Ii(e,t){var n=this.__data__,r=Oi(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Li=Ii;function Ri(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])}}Ri.prototype.clear=Ei,Ri.prototype.delete=ji,Ri.prototype.get=Ni,Ri.prototype.has=Fi,Ri.prototype.set=Li;var zi=Ri,Bi=Vt(he,`Map`),Vi=Bi;function Hi(){this.size=0,this.__data__={hash:new wi,map:new(Vi||zi),string:new wi}}var Ui=Hi;function Wi(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Gi=Wi;function Ki(e,t){var n=e.__data__;return Gi(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var qi=Ki;function Ji(e){var t=qi(this,e).delete(e);return this.size-=t?1:0,t}var Yi=Ji;function Xi(e){return qi(this,e).get(e)}var Zi=Xi;function Qi(e){return qi(this,e).has(e)}var $i=Qi;function ea(e,t){var n=qi(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var ta=ea;function na(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])}}na.prototype.clear=Ui,na.prototype.delete=Yi,na.prototype.get=Zi,na.prototype.has=$i,na.prototype.set=ta;var ra=na,ia=`Expected a function`;function aa(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ia);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(aa.Cache||ra),n}aa.Cache=ra;var oa=aa,sa=500;function ca(e){var t=oa(e,function(e){return n.size===sa&&n.clear(),e}),n=t.cache;return t}var la=ca,ua=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,da=/\\(\\)?/g,fa=la(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(ua,function(e,n,r,i){t.push(r?i.replace(da,`$1`):n||e)}),t}),pa=fa;function ma(e){return e==null?``:Ge(e)}var ha=ma;function ga(e,t){return Be(e)?e:oi(e,t)?[e]:pa(ha(e))}var _a=ga,va=1/0;function ya(e){if(typeof e==`string`||Ie(e))return e;var t=e+``;return t==`0`&&1/e==-va?`-0`:t}var ba=ya;function xa(e,t){t=_a(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[ba(t[n++])];return n&&n==r?e:void 0}var Sa=xa;function Ca(e,t,n){var r=e==null?void 0:Sa(e,t);return r===void 0?n:r}var wa=Ca;function Ta(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Ea=Ta,Da=_e?_e.isConcatSpreadable:void 0;function Oa(e){return Be(e)||Jn(e)||!!(Da&&e&&e[Da])}var ka=Oa;function Aa(e,t,n,r,i){var a=-1,o=e.length;for(n||=ka,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?Aa(s,t-1,n,r,i):Ea(i,s):r||(i[i.length]=s)}return i}var ja=Aa;function Ma(e){return e!=null&&e.length?ja(e,1):[]}var Na=Ma;function Pa(){this.__data__=new zi,this.size=0}var Fa=Pa;function Ia(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var La=Ia;function Ra(e){return this.__data__.get(e)}var za=Ra;function Ba(e){return this.__data__.has(e)}var Va=Ba,Ha=200;function Ua(e,t){var n=this.__data__;if(n instanceof zi){var r=n.__data__;if(!Vi||r.length<Ha-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new ra(r)}return n.set(e,t),this.size=n.size,this}var Wa=Ua;function Ga(e){this.size=(this.__data__=new zi(e)).size}Ga.prototype.clear=Fa,Ga.prototype.delete=La,Ga.prototype.get=za,Ga.prototype.has=Va,Ga.prototype.set=Wa;var Ka=Ga;function qa(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 Ja=qa;function Ya(){return[]}var Xa=Ya,Za=Object.prototype.propertyIsEnumerable,Qa=Object.getOwnPropertySymbols,$a=Qa?function(e){return e==null?[]:(e=Object(e),Ja(Qa(e),function(t){return Za.call(e,t)}))}:Xa,eo=$a;function to(e,t,n){var r=t(e);return Be(e)?r:Ea(r,n(e))}var no=to;function ro(e){return no(e,Yr,eo)}var io=ro,ao=Vt(he,`DataView`),oo=ao,so=Vt(he,`Promise`),co=so,lo=Vt(he,`Set`),uo=lo,fo=`[object Map]`,po=`[object Object]`,mo=`[object Promise]`,ho=`[object Set]`,go=`[object WeakMap]`,_o=`[object DataView]`,vo=Ot(oo),yo=Ot(Vi),bo=Ot(co),xo=Ot(uo),So=Ot(Ut),Co=je;(oo&&Co(new oo(new ArrayBuffer(1)))!=_o||Vi&&Co(new Vi)!=fo||co&&Co(co.resolve())!=mo||uo&&Co(new uo)!=ho||Ut&&Co(new Ut)!=go)&&(Co=function(e){var t=je(e),n=t==po?e.constructor:void 0,r=n?Ot(n):``;if(r)switch(r){case vo:return _o;case yo:return fo;case bo:return mo;case xo:return ho;case So:return go}return t});var wo=Co,To=he.Uint8Array,Eo=To;function Do(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 Oo=Do,ko=`__lodash_hash_undefined__`;function Ao(e){return this.__data__.set(e,ko),this}var jo=Ao;function Mo(e){return this.__data__.has(e)}var No=Mo;function Po(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new ra;++t<n;)this.add(e[t])}Po.prototype.add=Po.prototype.push=jo,Po.prototype.has=No;var Fo=Po;function Io(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 Lo=Io;function Ro(e,t){return e.has(t)}var zo=Ro,Bo=1,Vo=2;function Ho(e,t,n,r,i,a){var o=n&Bo,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&Vo?new Fo:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],ee=t[d];if(r)var te=o?r(ee,m,d,t,e,a):r(m,ee,d,e,t,a);if(te!==void 0){if(te)continue;f=!1;break}if(p){if(!Lo(t,function(e,t){if(!zo(p,t)&&(m===e||i(m,e,n,r,a)))return p.push(t)})){f=!1;break}}else if(!(m===ee||i(m,ee,n,r,a))){f=!1;break}}return a.delete(e),a.delete(t),f}var Uo=Ho;function Wo(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Go=Wo;function Ko(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var qo=Ko,Jo=1,Yo=2,Xo=`[object Boolean]`,Zo=`[object Date]`,Qo=`[object Error]`,$o=`[object Map]`,es=`[object Number]`,ts=`[object RegExp]`,ns=`[object Set]`,rs=`[object String]`,is=`[object Symbol]`,as=`[object ArrayBuffer]`,os=`[object DataView]`,ss=_e?_e.prototype:void 0,cs=ss?ss.valueOf:void 0;function ls(e,t,n,r,i,a,o){switch(n){case os:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case as:return!(e.byteLength!=t.byteLength||!a(new Eo(e),new Eo(t)));case Xo:case Zo:case es:return Tn(+e,+t);case Qo:return e.name==t.name&&e.message==t.message;case ts:case rs:return e==t+``;case $o:var s=Go;case ns:var c=r&Jo;if(s||=qo,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Yo,o.set(e,t);var u=Uo(s(e),s(t),r,i,a,o);return o.delete(e),u;case is:if(cs)return cs.call(e)==cs.call(t)}return!1}var us=ls,ds=1,fs=Object.prototype.hasOwnProperty;function ps(e,t,n,r,i,a){var o=n&ds,s=io(e),c=s.length;if(c!=io(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:fs.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 ee=e[u],te=t[u];if(r)var ne=o?r(te,ee,u,t,e,a):r(ee,te,u,e,t,a);if(!(ne===void 0?ee===te||i(ee,te,n,r,a):ne)){p=!1;break}m||=u==`constructor`}if(p&&!m){var re=e.constructor,ie=t.constructor;re!=ie&&`constructor`in e&&`constructor`in t&&!(typeof re==`function`&&re instanceof re&&typeof ie==`function`&&ie instanceof ie)&&(p=!1)}return a.delete(e),a.delete(t),p}var ms=ps,hs=1,gs=`[object Arguments]`,_s=`[object Array]`,vs=`[object Object]`,ys=Object.prototype.hasOwnProperty;function bs(e,t,n,r,i,a){var o=Be(e),s=Be(t),c=o?_s:wo(e),l=s?_s:wo(t);c=c==gs?vs:c,l=l==gs?vs:l;var u=c==vs,d=l==vs,f=c==l;if(f&&tr(e)){if(!tr(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Ka,o||Lr(e)?Uo(e,t,n,r,i,a):us(e,t,c,n,r,i,a);if(!(n&hs)){var p=u&&ys.call(e,`__wrapped__`),m=d&&ys.call(t,`__wrapped__`);if(p||m){var ee=p?e.value():e,te=m?t.value():t;return a||=new Ka,i(ee,te,n,r,a)}}return f?(a||=new Ka,ms(e,t,n,r,i,a)):!1}var xs=bs;function Ss(e,t,n,r,i){return e===t?!0:e==null||t==null||!Ne(e)&&!Ne(t)?e!==e&&t!==t:xs(e,t,n,r,Ss,i)}var Cs=Ss,ws=1,Ts=2;function Es(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 Ka;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Cs(u,l,ws|Ts,r,d):f))return!1}}return!0}var Ds=Es;function Os(e){return e===e&&!$e(e)}var ks=Os;function As(e){for(var t=Yr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,ks(i)]}return t}var js=As;function Ms(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var Ns=Ms;function Ps(e){var t=js(e);return t.length==1&&t[0][2]?Ns(t[0][0],t[0][1]):function(n){return n===e||Ds(n,e,t)}}var Fs=Ps;function Is(e,t){return e!=null&&t in Object(e)}var Ls=Is;function Rs(e,t,n){t=_a(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=ba(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&&Nn(i)&&xn(o,i)&&(Be(e)||Jn(e)))}var zs=Rs;function Bs(e,t){return e!=null&&zs(e,t,Ls)}var Vs=Bs,Hs=1,Us=2;function Ws(e,t){return oi(e)&&ks(t)?Ns(ba(e),t):function(n){var r=wa(n,e);return r===void 0&&r===t?Vs(n,e):Cs(t,r,Hs|Us)}}var Gs=Ws;function Ks(e){return function(t){return t?.[e]}}var qs=Ks;function Js(e){return function(t){return Sa(t,e)}}var Ys=Js;function Xs(e){return oi(e)?qs(ba(e)):Ys(e)}var Zs=Xs;function Qs(e){return typeof e==`function`?e:e==null?mt:typeof e==`object`?Be(e)?Gs(e[0],e[1]):Fs(e):Zs(e)}var $s=Qs;function ec(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 tc=ec;function nc(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 rc=nc,ic=rc(),ac=ic;function oc(e,t){return e&&ac(e,t,Yr)}var sc=oc;function cc(e,t){return function(n,r){if(n==null)return n;if(!Fn(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 lc=cc,uc=lc(sc),dc=uc;function fc(e,t,n,r){return dc(e,function(e,i,a){t(r,e,n(e),a)}),r}var pc=fc;function mc(e,t){return function(n,r){var i=Be(n)?tc:pc,a=t?t():{};return i(n,e,$s(r,2),a)}}var hc=mc;function gc(e){return Ne(e)&&Fn(e)}var _c=gc;function vc(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 yc=vc,bc=200;function xc(e,t,n,r){var i=-1,a=_n,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=Re(t,kr(n))),r?(a=yc,o=!1):t.length>=bc&&(a=zo,o=!1,t=new Fo(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 Sc=xc,Cc=An(function(e,t){return _c(e)?Sc(e,ja(t,1,_c,!0)):[]}),wc=Cc;function Tc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var v=Tc;function Ec(e){return typeof e==`function`?e:mt}var Dc=Ec;function Oc(e,t){var n=[];return dc(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var kc=Oc;function Ac(e,t){return(Be(e)?Ja:kc)(e,$s(t,3))}var jc=Ac,Mc=Math.max,Nc=Math.min;function Pc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=ft(n),i=n<0?Mc(r+i,0):Nc(i,r-1)),ln(e,$s(t,3),i,!0)}var Fc=Pc;function Ic(e){return e&&e.length?e[0]:void 0}var Lc=Ic;function Rc(e,t){var n=-1,r=Fn(e)?Array(e.length):[];return dc(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var zc=Rc;function Bc(e,t){return(Be(e)?Re:zc)(e,$s(t,3))}var Vc=Bc;function Hc(e,t){return ja(Vc(e,t),1)}var Uc=Hc;function Wc(e,t){return e==null?e:ac(e,Dc(t),ni)}var Gc=Wc,Kc=Object.prototype.hasOwnProperty,qc=hc(function(e,t,n){Kc.call(e,n)?e[n].push(t):Cn(e,n,[t])}),Jc=qc,Yc=`[object Map]`,Xc=`[object Set]`,Zc=Object.prototype.hasOwnProperty;function Qc(e){if(e==null)return!0;if(Fn(e)&&(Be(e)||typeof e==`string`||typeof e.splice==`function`||tr(e)||Lr(e)||Jn(e)))return!e.length;var t=wo(e);if(t==Yc||t==Xc)return!e.size;if(Rn(e))return!qr(e).length;for(var n in e)if(Zc.call(e,n))return!1;return!0}var $c=Qc,el=hc(function(e,t,n){Cn(e,n,t)}),tl=el,nl=hc(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),y=nl,rl=uo&&1/qo(new uo([,-0]))[1]==1/0?function(e){return new uo(e)}:qt,il=rl,al=200;function ol(e,t,n){var r=-1,i=_n,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=yc;else if(a>=al){var l=t?null:il(e);if(l)return qo(l);o=!1,i=zo,c=new Fo}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 sl=ol;function cl(e,t){return e&&e.length?sl(e,$s(t,2)):[]}var ll=cl,ul=Math.max;function dl(e){if(!(e&&e.length))return[];var t=0;return e=Ja(e,function(e){if(_c(e))return t=ul(e.length,t),!0}),Bn(t,function(t){return Re(e,qs(t))})}var fl=dl,pl=An(fl),ml=pl;let b=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 hl(e){switch(e.kind){case b.NEWLINE:case b.SPACE:case b.TAB:case b.SINGLE_LINE_COMMENT:case b.MULTILINE_COMMENT:return!0;default:return!1}}function gl(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 _l(e){return e!==void 0&&e.kind===b.OP}var vl=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 yl(e){return e.trailingTrivia.find(({kind:e})=>e===b.NEWLINE)!==void 0}function bl(e,t){return t.leadingTrivia.find(({kind:e})=>e===b.NEWLINE)!==void 0||yl(e)}function xl(e){return e.trailingTrivia.find(({kind:e})=>[b.SPACE,b.TAB].includes(e))!==void 0}function Sl(e){return e.trailingTrivia.length===0?e.end:Sl(v(e.trailingTrivia))}function Cl(e){return e.leadingTrivia.length===0?e.start:Cl(e.leadingTrivia[0])}function wl(e){return[b.SINGLE_LINE_COMMENT,b.MULTILINE_COMMENT].includes(e.kind)}var Tl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},x=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 vl?Cl(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 vl?Sl(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}`}parentOfKind(e){let t=this.parentNode;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){let t=this.start<e.start,n=t||this.start===e.start,r=this.end>e.end,i=r||this.end===e.end;return t&&i||n&&r}containsEq(e){return this.start<=e.start&&this.end>=e.end}};let S=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifer-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.WILDCARD=`<wildcard>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e}({});var C=class extends x{constructor({body:e=[],eof:t,source:n},r,i){super(r,S.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}},w=class e extends x{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,S.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof T||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)}},El=class extends x{constructor({identifiers:e=[]},t,n){super(t,S.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},Dl=class extends x{constructor({name:e,colon:t,value:n},r,i){super(r,S.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},Ol=class extends x{constructor({op:e,expression:t},n,r){super(n,S.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},kl=class extends x{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,S.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},Al=class extends x{constructor({op:e,expression:t},n,r){super(n,S.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},jl=class extends x{constructor({value:e},t,n){super(t,S.FUNCTION_EXPRESSION,n,[e]),this.value=e}},T=class extends x{constructor({callee:e,args:t=[]},n,r){super(n,S.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},E=class extends x{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,S.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},D=class extends x{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,S.LIST_EXPRESSION,a,[e,...Vl(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Ml=class extends x{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,S.TUPLE_EXPRESSION,a,[e,...Vl(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Nl=class extends x{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,S.COMMA_EXPRESSION,r,[...Vl(e,t)]),this.elementList=e,this.commaList=t}},Pl=class extends Ml{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=S.GROUP_EXPRESSION}},O=class extends x{constructor({callee:e,argumentList:t},n,r){super(n,S.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},Fl=class extends x{constructor({literal:e},t,n){super(t,S.LITERAL,n,[e]),this.literal=e}},Il=class extends x{constructor({token:e},t,n){super(t,S.WILDCARD,n,[e]),this.token=e}},Ll=class extends x{constructor({variable:e},t,n){super(t,S.VARIABLE,n,[e]),this.variable=e}},Rl=class extends x{constructor({expression:e},t,n){super(t,S.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},zl=class extends x{constructor({prevToken:e},t,n){let r=vl.create(b.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,S.EMPTY,n,[r])}},Bl=class extends x{constructor({expression:e,indexer:t},n,r){super(n,S.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function Vl(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?Na(ml(e,t)):Na(ml(t,e))).filter(e=>e!==null)}function Hl(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 Ul(e,t,n){let r=t,i=e;if(i instanceof O&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Ql(i)||r.length===0)return;let a=[...r],o=Xl(i),s=a.pop();if(!(s instanceof E))return;let c=v(a)instanceof D?a.pop():void 0;if(a.length===3){let e=Xl(a[1]);return!e||!Wl(e)?void 0:n.create(w,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(w,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(w,{type:o,attributeList:c,body:s})}function Wl(e){return e?.kind===b.IDENTIFIER&&e.value.toLowerCase()===`as`}function k(e){e&&(e instanceof vl?Gl(e):Kl(e))}function Gl(e){e.kind!==b.EOF&&(e.isInvalid=!0)}function Kl(e){if(e instanceof w)k(e.type),k(e.name),k(e.as),k(e.alias),k(e.bodyColon),k(e.attributeList),k(e.body);else if(e instanceof El)e.identifiers.forEach(k);else if(e instanceof Dl)k(e.name),k(e.colon),k(e.value);else if(e instanceof Ol)k(e.op),k(e.expression);else if(e instanceof kl)k(e.leftExpression),k(e.op),k(e.rightExpression);else if(e instanceof Al)k(e.op),k(e.expression);else if(e instanceof E)k(e.blockOpenBrace),e.body.forEach(k),k(e.blockCloseBrace);else if(e instanceof D)k(e.listOpenBracket),e.commaList.forEach(k),e.elementList.forEach(k),k(e.listCloseBracket);else if(e instanceof Ml)k(e.tupleOpenParen),e.commaList.forEach(k),e.elementList.forEach(k),k(e.tupleCloseParen);else if(e instanceof Nl)e.commaList.forEach(k),e.elementList.forEach(k);else if(e instanceof O)k(e.callee),k(e.argumentList);else if(e instanceof T)k(e.callee),e.args.forEach(k);else if(e instanceof Rl)k(e.expression);else if(e instanceof jl)k(e.value);else if(e instanceof Ll)k(e.variable);else if(e instanceof Fl)k(e.literal);else if(e instanceof Pl)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof Bl)k(e.array),k(e.indexer);else if(e instanceof C)e.body.forEach(k),k(e.eof);else if(!(e instanceof zl))if(e instanceof Il)k(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function ql(e){return!!e?.isInvalid}function Jl(...e){return e.filter(e=>e!==void 0)}function Yl(e){if(e instanceof C)return Jl(...e.body,e.eof);if(e instanceof w)return Jl(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof Dl)return Jl(e.name,e.colon,e.value);if(e instanceof El)return e.identifiers;if(e instanceof Fl)return e.literal?[e.literal]:[];if(e instanceof Ll)return Jl(e.variable);if(e instanceof Ol)return Jl(e.op,e.expression);if(e instanceof kl)return Jl(e.leftExpression,e.op,e.rightExpression);if(e instanceof Al)return Jl(e.expression,e.op);if(e instanceof jl)return Jl(e.value);if(e instanceof T)return Jl(e.callee,...e.args);if(e instanceof E)return Jl(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof D)return Jl(e.listOpenBracket,...Hl(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Ml)return Jl(e.tupleOpenParen,...Hl(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Nl)return Jl(...Hl(e.elementList,e.commaList));if(e instanceof O)return Jl(e.callee,e.argumentList);if(e instanceof Rl)return Jl(e.expression);if(e instanceof Bl)return Jl(e.array,e.indexer);if(e instanceof Il)return Jl(e.token);throw e instanceof Pl?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Xl(e){if(j(e))return e.expression.variable}function A(e){return e instanceof Rl&&(e.expression instanceof Ll&&e.expression.variable instanceof vl&&e.expression.variable.kind===b.QUOTED_STRING||e.expression instanceof Fl&&e.expression.literal?.kind===b.STRING_LITERAL)}function j(e){return e instanceof Rl&&e.expression instanceof Ll&&e.expression.variable instanceof vl}function Zl(e){return e?e instanceof Il:!1}function Ql(e){return e instanceof Rl&&e.expression instanceof Ll&&e.expression.variable?.kind===b.IDENTIFIER}function $l(e){return e instanceof kl&&e.leftExpression instanceof x&&e.rightExpression instanceof x&&e.op?.value===`.`}function eu(e){return j(e)?!0:$l(e)&&j(e.rightExpression)&&eu(e.leftExpression)}function tu(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function nu(e){let t=L(e?.name);return t===void 0?void 0:t.join(`.`)}let 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_DIAGRAMVIEW_CONTEXT=3082]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3083]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3084]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3085]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,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}({});var 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 ru(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},ru=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}},P=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 this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chainFiltered(t,n){if(this.value===t)return new e(void 0,this.errors,this.warnings);let r=n(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 this.value===t?new e(void 0,this.errors,this.warnings):new e(n(this.value),this.errors,this.warnings)}map(t){return new e(t(this.value),this.errors,this.warnings)}};let F=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.DiagramViewField=`DiagramView field`,e}({});function iu(e){return`${F.Schema}:${e}`}function au(e){return`${F.Table}:${e}`}function ou(e){return`${F.Column}:${e}`}function su(e){return`${F.Enum}:${e}`}function cu(e){return`${F.EnumField}:${e}`}function lu(e){return`${F.TableGroup}:${e}`}function uu(e){return`${F.TableGroupField}:${e}`}function du(e){return`${F.StickyNote}:${e}`}function fu(e){return`${F.TablePartial}:${e}`}function pu(e){return`${F.PartialInjection}:${e}`}function mu(e){return`${F.DiagramView}:${e}`}function hu(e){return`${F.DiagramViewField}:${e}`}function gu(e,t){switch(t){case F.Column:return ou(e);case F.Enum:return su(e);case F.EnumField:return cu(e);case F.Schema:return iu(e);case F.Table:return au(e);case F.TableGroup:return lu(e);case F.TableGroupField:return uu(e);case F.StickyNote:return du(e);case F.TablePartial:return fu(e);case F.PartialInjection:return pu(e);case F.DiagramView:return mu(e);case F.DiagramViewField:return hu(e);default:throw Error(`Unreachable`)}}function _u(e){let[t,n]=e.split(`:`);return Object.values(F).includes(t)?{name:n,kind:t}:void 0}var vu=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},yu=class{constructor({kind:e,declaration:t,symbolTable:n,filepath:r},i){this.references=[],this.id=i,this.kind=e,this.declaration=t,this.symbolTable=n,this.filepath=r??t?.filepath??le}isKind(e){return this.kind===e}},bu=class extends yu{constructor({symbolTable:e,name:t},n){super({kind:F.Schema,symbolTable:e},n),this.name=t}},xu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.Enum,symbolTable:e,declaration:t},n)}},Su=class extends yu{constructor({declaration:e},t){super({kind:F.EnumField,declaration:e},t)}},Cu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.Table,symbolTable:e,declaration:t},n)}},wu=class extends yu{constructor({declaration:e},t){super({kind:F.Column,declaration:e},t)}},Tu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.TableGroup,symbolTable:e,declaration:t},n)}},Eu=class extends yu{constructor({declaration:e},t){super({kind:F.TableGroupField,declaration:e},t)}},Du=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.TablePartial,symbolTable:e,declaration:t},n)}},Ou=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.PartialInjection,symbolTable:e,declaration:t},n)}},ku=class extends yu{constructor({declaration:e,tablePartialSymbol:t},n){super({kind:F.Column,declaration:e},n),this.tablePartialSymbol=t}},Au=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.DiagramView,symbolTable:e,declaration:t},n)}},ju=class extends yu{constructor({declaration:e},t){super({kind:F.DiagramViewField,declaration:e},t)}},Mu=class extends yu{constructor({declaration:e},t){super({kind:F.StickyNote,declaration:e},t)}},Nu=class{constructor(){this.table=new Map}has(e){return this.table.has(e)}set(e,t){this.table.set(e,t)}get(e,t){return this.table.get(e)||t!==void 0&&this.set(e,t)||t}entries(){return this.table.entries()}forEach(e){return this.table.forEach(e)}};function Pu(e){return[iu,au,su,lu,ou,cu,uu,fu,pu,mu,hu].map(t=>t(e))}var Fu=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}};function Iu(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Lu(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Ru(e){let[t]=e;return Lu(t)||Iu(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function zu(e){return Iu(e)||Lu(e)}function Bu(e,t){let n=t.toLowerCase();return Object.values(e).find(e=>e.toLowerCase()===n)}var Vu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=new N(M.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof C)return[e];let t=this.declarationNode.parent;return t instanceof w&&t.isKind(h.Table,h.TablePartial)?[]:[e]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Checks name`,e)]: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 T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=y(e.body,e=>e instanceof T);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 v(n)instanceof D&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof jl))&&t.push(new N(M.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];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=>{A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Hu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w&&this.declarationNode.parent.isKind(h.Project)?[]:[new N(M.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Custom element name`,e)]: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 E)return[new N(M.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return A(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}},Uu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement()],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?id(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)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Au,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t!==void 0){let n=t,r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=mu(r);if(i.has(a))return[new N(M.DUPLICATE_DIAGRAMVIEW_NAME,`DiagramView '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=I(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 T)return{errors:[new N(M.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=y(e.body,e=>e instanceof T),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>{if(Zl(e.callee))return e.args.length>0?e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[];let t=[];return t.push(new N(M.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)),t})}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(i.parent=this.declarationNode,!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 E))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof T&&Zl(e.callee)),a=r.body.some(e=>e instanceof T&&!Zl(e.callee));return i&&a&&n.push(new ru(M.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.registerSubBlockFields(e)),{errors:t,warnings:n}}registerSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof E))return t;let n=e.body.body.filter(e=>e instanceof T);for(let e of n){if(e.callee&&j(e.callee)){if(Zl(e.callee))continue;let n=z(e.callee),r=hu(n),i=this.symbolFactory.create(ju,{declaration:e});e.symbol=i;let a=this.declarationNode.symbol.symbolTable;if(a.has(r)){let i=a.get(r);t.push(new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,e),new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,i.declaration))}else a.set(r,i)}e.args.length>0&&t.push(...e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)))}return t}},Wu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:nd(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)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(xu,{declaration:this.declarationNode,symbolTable:new Nu});let{name:t}=this.declarationNode,n=L(t);if(n!==void 0){let r=n,i=r.pop(),a=od(r,this.publicSymbolTable,this.symbolFactory),o=su(i);a.has(o)&&e.push(new N(M.DUPLICATE_NAME,`Enum '${i}' already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return 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 T)return this.validateFields([e]);let[t,n]=y(e.body,e=>e instanceof T);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new N(M.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!j(e.callee)&&t.push(new N(M.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return v(n)instanceof D?(t.push(...this.validateFieldSettings(v(n))),n.pop()):n[0]instanceof D&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new N(M.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e))),t.push(...this.registerField(e)),t})}validateFieldSettings(e){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`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=>{A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=cu(t),r=this.symbolFactory.create(Su,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},Gu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=new N(M.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof C)return[e];let t=this.declarationNode.parent;return t instanceof w&&t.isKind(h.Table,h.TablePartial)?[]:[e]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as an Indexes name`,e)]: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 T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=y(e.body,e=>e instanceof T);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 v(n)instanceof D&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof O;)e.argumentList&&gd(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;gd(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=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];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=>{A(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=>{j(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Ku=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=this.declarationNode.parent;return!(e instanceof C)&&!(e instanceof w&&e.isKind(h.Table,h.TableGroup,h.TablePartial,h.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){if(!(this.declarationNode.parent instanceof C))return e?[new N(M.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new N(M.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];if(e instanceof Il)return[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,e)];let t=L(e);if(t===void 0)return[new N(M.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.join(`.`),r=du(n);return this.publicSymbolTable.has(r)?[new N(M.DUPLICATE_NAME,`Duplicate Note '${n}' in schema '${ce}'`,e)]:(this.declarationNode.symbol=this.symbolFactory.create(Mu,{declaration:this.declarationNode}),this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}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 Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof T)return this.validateFields([e]);let[t,n]=y(e.body,e=>e instanceof T);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))),A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},qu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Project name`,e)]:id(e)?[]:[new N(M.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=y(e.body,e=>e instanceof T);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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Ju=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=this.declarationNode.parent;return e instanceof C||e instanceof w&&e.isKind(h.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 Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof C?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof O))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)];let t=[];return(!e.callee||!nd(e.callee))&&t.push(new N(M.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!fd(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&&!fd(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 T)return this.validateDataRow(e);let[t,n]=y(e.body,e=>e instanceof T);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 Nl)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 zl||ud(e)||A(e)||e instanceof jl)return!0;if(j(e)){let t=e.expression.variable.value.toLowerCase();return oe.includes(t)}if($l(e)){let t=L(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Yu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof C?[]:[new N(M.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:id(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 T)return this.validateFields([e]);let[t,n]=y(e.body,e=>e instanceof T);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&&!yd(e.callee)&&t.push(new N(M.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&yd(e.callee)){let n=hd(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=hd(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&&!bd(e.callee)&&t.push(new N(M.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(v(n)instanceof D){let e=this.validateFieldSettings(v(n));t.push(...e),n.pop()}else n[0]instanceof D&&(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){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`delete`:case`update`:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Xu(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))});break;case`color`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}};function Xu(e){if(!(j(e)&&e.expression.variable.kind!==b.QUOTED_STRING)&&!(e instanceof El))return!1;let t;if(t=e instanceof El?tu(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}var Zu=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:e instanceof Bl?[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)]:nd(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?rd(e)?[]:[new N(M.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=I(e),n=t.getErrors();return Gc(t.getValue(),(e,t)=>{switch(t){case g.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case g.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{A(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}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Cu,{declaration:this.declarationNode,symbolTable:new Nu});let{name:t,alias:n}=this.declarationNode,r=L(t);if(r!==void 0){let n=[...r],i=n.pop(),a=od(n,this.publicSymbolTable,this.symbolFactory),o=au(i);a.has(o)&&e.push(new N(M.DUPLICATE_NAME,`Table '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&id(n)&&!Qu(n.expression.variable.value,r??[])){let r=z(n),i=au(r);this.publicSymbolTable.has(i)&&e.push(new N(M.DUPLICATE_NAME,`Table '${r}' already exists in schema '${ce}'`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=y(e.body,e=>e instanceof T);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)),j(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]&&!pd(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.push(...this.registerField(e)),t},n=e=>{let t=[];if(!e.callee)return[];if(!ad(e.callee))t.push(new N(M.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=R(e.callee.expression)??``,n=this.symbolFactory.create(Ou,{symbolTable:new Nu,declaration:e});e.symbol=n;let r=pu(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,n.declaration)]}i.set(r,n)}return 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 Ol&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=ou(t),r=this.symbolFactory.create(wu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every(Ql)||!e.slice(-1).every(e=>Ql(e)||e instanceof D))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;v(e)instanceof D&&(t=e.pop());let n=I(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=(z(e)??``).toLowerCase();if(t!==`pk`&&t!==`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[g.PK]||[],o=i[g.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))),Gc(i,(e,t)=>{switch(t){case g.Note:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{A(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case g.Ref:e.forEach(e=>{dd(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case g.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 g.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 Dl&&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 g.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[g.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 g.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 g.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 Dl&&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 g.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 Dl&&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 g.Default:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ld(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 g.Check:e.forEach(e=>{e.value instanceof jl||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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(h.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Qu(e,t){return t.length===1&&e===t[0]}var $u=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:id(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)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Tu,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t!==void 0){let n=[...t],r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=lu(r);if(i.has(a))return[new N(M.DUPLICATE_NAME,`TableGroup '${r}' already exists in schema '${n.join(`.`)||`public`}'`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=I(e),n=t.getErrors();return Gc(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!A(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(...e.map(e=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=y(e.body,e=>e instanceof T);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&L(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)),this.registerField(e),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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(h.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=uu(t),r=this.symbolFactory.create(Eu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new N(M.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},ed=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:id(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=I(e),n=t.getErrors();return Gc(t.getValue(),(e,t)=>{switch(t){case g.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=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case g.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=>{A(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}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Du,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t===void 0)return[];let n=[...t],r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=fu(r);return i.has(a)?[new N(M.DUPLICATE_NAME,`TablePartial '${r}' already exists in schema '${n.join(`.`)||`public`}'`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=y(e.body,e=>e instanceof T);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)),j(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]&&!pd(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),...this.registerField(e)),t})}registerField(e){if(!e.callee||!j(e.callee))return[];let t=z(e.callee),n=ou(t),r=this.symbolFactory.create(wu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=v(e);if(!e.slice(0,-1).every(Ql)||!(Ql(t)||t instanceof D))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;v(e)instanceof D&&(n=e.pop());let r=I(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=(z(e)??``).toLowerCase();if(t!==g.PK&&t!==g.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[g.PK]||[],s=a[g.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))),Gc(a,(e,t)=>{switch(t){case g.Note:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{A(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case g.Ref:e.forEach(e=>{dd(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case g.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 g.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 Dl&&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 g.NotNull:{e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[g.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 g.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 g.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 Dl&&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 g.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 Dl&&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 g.Default:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ld(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 g.Check:e.forEach(e=>{e.value instanceof jl||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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(h.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function td(e){switch(Bu(h,e.type.value)){case h.Enum:return Wu;case h.Table:return Zu;case h.TableGroup:return $u;case h.Project:return qu;case h.Ref:return Yu;case h.Note:return Ku;case h.Indexes:return Gu;case h.TablePartial:return ed;case h.Check:return Vu;case h.Records:return Ju;case h.DiagramView:return Uu;default:return Hu}}function nd(e){let t=L(e);return t!==void 0&&t.length>0}function rd(e){return id(e)}function id(e){return e instanceof Rl&&e.expression instanceof Ll}function ad(e){return e instanceof Ol&&e.op?.value===`~`&&j(e.expression)}function od(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=iu(t);if(r.has(i)){if(e=r.get(i)?.symbolTable,!e)throw Error(`Expect a symbol table in a schema symbol`)}else{e=new Nu;let a=n.create(bu,{symbolTable:e,name:t});r.set(i,a)}r=e}return r}function sd(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function cd(e){if(!(e instanceof Rl)||!(e.expression instanceof Fl)||e.expression.literal?.kind!==b.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(!Ru(t[e]))return!1;return!0}function ld(e){if(A(e)||ud(e)||Ql(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof Ol&&se.includes(e.op?.value)&&ud(e.expression)||e instanceof jl)return!0;if(!e||!eu(e))return!1;let t=md(e);return t.length===2||t.length===3}function ud(e){return e instanceof Ol?se.includes(e.op.value)?ud(e.expression):!1:e instanceof Rl&&e.expression instanceof Fl&&e.expression.literal?.kind===b.NUMERIC_LITERAL}function dd(e){if(!(e instanceof Ol)||!sd(e.op?.value))return!1;let t=L(e.expression);return t!==void 0&&t.length>0}function fd(e){return e instanceof Ml&&e.elementList.every(j)}function pd(e){if(!(e instanceof O||$l(e)||e instanceof Rl||e instanceof Bl))return!1;for(;e instanceof O||e instanceof Bl;)if(e instanceof O){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>ud(e)||A(e)||Ql(e)))return!1;e=e.callee}else if(e instanceof Bl){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&ud(e.name)))return!1;e=e.array}let t=L(e);return t!==void 0&&t.length>0}function I(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Rl){n.push(new N(M.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=tu(e.name)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new P(t,n)):new P({})}function md(e){if(!e)return;if(!$l(e))return[e];let t=md(e.leftExpression);if(t)return t.push(e.rightExpression),t}function L(e){if(e===void 0)return;let t=md(e);if(!t)return;let n=[];for(let e of t){let t=R(e);if(typeof t!=`string`)return;n.push(t)}return n}function hd(e){if(e===void 0)return;let t=md(e);if(!t||t.length===0)return;let n=[];if(!j(v(t))){let e=t.pop();if(fd(e))n=e.elementList;else return}let r=t;if(r.every(j))return{variables:r,tupleElements:n}}function R(e){if(j(e))return e.expression.variable.value}function gd(e){if(xd(e))return e instanceof jl?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof Ml&&e.elementList.every(xd))return{functional:e.elementList.filter(e=>e instanceof jl),nonFunctional:e.elementList.filter(j)}}function z(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function B(e){if(A(e))return e.expression instanceof Ll?e.expression.variable.value:e.expression.literal.value}function _d(e){return e instanceof Rl&&e.expression instanceof Fl&&e.expression.literal?.kind===b.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function vd(e){if(e)return j(e)?e.referee:e instanceof kl&&e.op?.value===`.`?vd(e.rightExpression):e.referee}function yd(e){return!(e instanceof kl)||!sd(e.op?.value)?!1:hd(e.leftExpression)!==void 0&&hd(e.rightExpression)!==void 0}function bd(e){let t=hd(e.leftExpression),n=hd(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function xd(e){return e instanceof Rl&&e.expression instanceof Ll||e instanceof jl}function Sd(e){if(!(e instanceof O)||!e.callee)return;let t=md(e.callee);if(!t||t.length===0||!t.every(j))return;let n=[];return fd(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}var Cd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},wd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Td=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=y(e.body,e=>e instanceof T);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value.toLowerCase();if(!(e.body instanceof E))return[];let n=[];switch(t){case`tables`:n.push(...this.bindTableReferences(e.body));break;case`notes`:n.push(...this.bindNoteReferences(e.body));break;case`tablegroups`:n.push(...this.bindTableGroupReferences(e.body));break;case`schemas`:n.push(...this.bindSchemaReferences(e.body));break;default:break}return n})}bindTableReferences(e){let[t]=y(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.Table}])}))}bindNoteReferences(e){let[t]=y(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>{let t=e.variables.pop();return t?Ld(this.ast,[{node:t,kind:F.StickyNote}]):[]}))}bindTableGroupReferences(e){let[t]=y(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.TableGroup}])}))}bindSchemaReferences(e){let[t]=y(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>Ld(this.ast,e.variables.map(e=>({node:e,kind:F.Schema})))))}},Ed=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Dd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof w)||!this.declarationNode.parent.isKind(h.Table)||!(this.declarationNode.body instanceof E)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=y(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=(()=>{let e=L(this.declarationNode.parent.name);return e===void 0?`<unnamed>`:e.join(`.`)})(),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(Id).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=z(e);if(r===void 0)return[];let i=ou(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new N(M.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Od=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},kd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Ad=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof E&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof C?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=Sd(e);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table}]);if(i.length>0)return i;let a=n.referee;if(!a?.symbolTable)return[];let o=nu(n.referee?.declaration)??`<invalid name>`,s=[];for(let e of t.args){let t=z(e)??`<unnamed>`,n=ou(t),r=a.symbolTable.get(n);if(!r){s.push(new N(M.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}e.referee=r,r.references.push(e);let i=this.boundColumns.get(r);i&&(s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,i)),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(r,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof w)||!t.isKind(h.Table))return[];let n=t.symbol?.symbolTable;if(!n||!fd(e))return[];let r=nu(t)??`<invalid name>`,i=[];for(let t of e.elementList){let e=z(t)??`<unnamed>`,a=ou(e),o=n.get(a);if(!o){i.push(new N(M.BINDING_ERROR,`Column '${e}' does not exist in Table '${r}'`,t));continue}t.referee=o,o.references.push(t)}return i}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof T),n=e.body.filter(e=>e instanceof w);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Nl?e.callee.elementList:[e.callee]).flatMap(Id).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];let r=e.variables;return Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum},{node:t,kind:F.EnumField}])}):[]}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},jd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof C)&&!this.declarationNode.parent?.isKind(h.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=y(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];Array.isArray(t)||(t=[t]);let r=e.variables;return t.flatMap(e=>Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:e,kind:F.Column}]))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Md=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof E?e.body:[e]:[]).filter(e=>e instanceof T&&ad(e.callee)).reverse().flatMap(e=>{let t=hd(e.callee.expression);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.TablePartial}]);return i.length?i:(n.referee?.symbolTable?.forEach(t=>{let r=R(t.declaration.callee);if(r===void 0)return;let i=this.symbolFactory.create(ku,{declaration:e,tablePartialSymbol:n.referee}),a=ou(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=y(e.body,e=>e instanceof T);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(v(n)instanceof D){let e=I(v(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=>!ad(e.callee)))}tryToBindColumnType(e){let t=hd(e);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}tryToBindEnumFieldRef(e){if(A(e))return[];if(j(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&oe.includes(t))return[]}let t=hd(e);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return Ld(this.ast,[...i.map(e=>({node:e,kind:F.Schema})),{node:r,kind:F.Enum},{node:n,kind:F.EnumField}])}bindInlineRef(e){return Id(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):Ld(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Nd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=y(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Pd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=y(e.body,e=>e instanceof T);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(v(n)instanceof D){let e=I(v(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=hd(e);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}bindInlineRef(e){return Id(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):Ld(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}};function Fd(e){switch(Bu(h,e.type.value)){case h.Enum:return Ed;case h.Table:return Md;case h.TableGroup:return Nd;case h.Project:return kd;case h.Ref:return jd;case h.Note:return Od;case h.Indexes:return Dd;case h.TablePartial:return Pd;case h.Check:return Cd;case h.Records:return Ad;case h.DiagramView:return Td;default:return wd}}function Id(e){if(!e)return[];if(j(e))return[{variables:[e],tupleElements:[]}];if(e instanceof kl){let t=hd(e);return t?[t]:[...Id(e.leftExpression),...Id(e.rightExpression)]}if(e instanceof Ol||e instanceof Al)return Id(e.expression);if(e instanceof Ml){let t=hd(e);return t?[t]:e.elementList.flatMap(Id)}return[]}function Ld(e,t){if(!e.symbol?.symbolTable)throw Error(`lookupAndBindInScope should only be called with initial scope having a symbol table`);let n=e.symbol.symbolTable,r=e.symbol.kind,i=e instanceof w?nu(e)??`<invalid name>`:ce;if(e instanceof C&&t.length){let{node:e,kind:n}=t[0];(z(e)??`<unnamed>`)===`public`&&n===F.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=z(t)??`<unnamed>`,s=gu(o,a),c=n.get(s);if(!c)return[new N(M.BINDING_ERROR,`${a} '${o}' does not exist in ${i===void 0?`global scope`:`${r} '${i}'`}`,t)];if(t.referee=c,c.references.push(t),i=o,r=a,!c.symbolTable)return[];n=c.symbolTable}return[]}var Rd=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>e.isKind(h.Table)).flatMap(e=>new Md(e,this.ast,this.symbolFactory).resolvePartialInjections())}resolve(){let e=[];e.push(...this.resolvePartialInjections());for(let t of this.ast.body)if(t.type){let n=new(Fd(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new P(this.ast,e)}},zd=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(bu,{symbolTable:new Nu,name:ce}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[],t=[];this.ast.body.forEach(n=>{if(n.parent=this.ast,n.type===void 0)return;let r=new(td(n))(n,this.publicSchemaSymbol.symbolTable,this.symbolFactory).validate();e.push(...r.errors),t.push(...r.warnings)});let n=this.ast.body.filter(e=>e.isKind(h.Project));return n.length>1&&n.forEach(t=>e.push(new N(M.PROJECT_REDEFINED,`Only one project can exist`,t))),new P(this.ast,e,t)}},Bd=class{constructor(e,t){this.ast=e,this.symbolFactory=new Fu(t)}analyze(){return new zd(this.ast,this.symbolFactory).validate().chain(e=>new Rd(e,this.symbolFactory).resolve())}validate(){return new zd(this.ast,this.symbolFactory).validate().chain(e=>new P(e,[]))}};function Vd(e){return e instanceof Ol?`${e.op?.value}${Vd(e.expression)}`:e.expression.literal.value}function Hd(e){return e instanceof Ol?e.op?.value===`-`?-Hd(e.expression):Hd(e.expression):Number.parseFloat(e.expression.literal.value)}function Ud(e,t){let{variables:n,tupleElements:r}=hd(e),i=r.map(e=>z(e)),a=n.map(e=>z(e));return r.length?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:i}:{tableName:a.pop(),schemaName:a.pop()||null,fieldNames:i}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[a[0]]}:{fieldNames:[a.pop()],tableName:a.pop(),schemaName:a.pop()||null}}function Wd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function V(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 Gd(e){let t=md(e)?.pop();return t instanceof Ml?t.elementList.map(e=>e.referee):[t.referee]}function Kd(e){let t=L(e);return{name:t.pop(),schemaName:t}}function qd(e){return e.expression.literal.value}function Jd(e,t){if(Array.isArray(e)){let n=e.map(({id:e})=>e).sort().join(`,`),r=t.map(({id:e})=>e).sort().join(`,`);return n<r?`${n}-${r}`:`${r}-${n}`}let n=e.id.toString(),r=t.id.toString();return n<r?`${n}-${r}`:`${r}-${n}`}function Yd(e,t){return Array.isArray(e)?ml(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function Xd(e){let t=e.split(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],enumerable:!0});return n&&e(r,Symbol.toStringTag,{value:`Module`}),r},n=/^[A-Za-z]:\//;function r(e=``){return e&&e.replace(/\\/g,`/`).replace(n,e=>e.toUpperCase())}var i=/^[/\\]{2}/,a=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,o=/^[A-Za-z]:$/,s=/^\/([A-Za-z]:)?$/,c=/.(\.[^./]+|\.)$/,l=function(e){if(e.length===0)return`.`;e=r(e);let t=e.match(i),n=m(e),a=e[e.length-1]===`/`;return e=p(e,!n),e.length===0?n?`/`:a?`./`:`.`:(a&&(e+=`/`),o.test(e)&&(e+=`/`),t?n?`//${e}`:`//./${e}`:n&&!m(e)?`/${e}`:e)},u=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 l(t)};function d(){return typeof process<`u`&&typeof process.cwd==`function`?process.cwd().replace(/\\/g,`/`):`/`}var f=function(...e){e=e.map(e=>r(e));let t=``,n=!1;for(let r=e.length-1;r>=-1&&!n;r--){let i=r>=0?e[r]:d();!i||i.length===0||(t=`${i}/${t}`,n=m(i))}return t=p(t,!n),n&&!m(t)?`/${t}`:t.length>0?t:`.`};function p(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 m=function(e){return a.test(e)},h=function(e){if(e===`..`)return``;let t=c.exec(r(e));return t&&t[1]||``},ee=function(e,t){let n=f(e).replace(s,`$1`).split(`/`),r=f(t).replace(s,`$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(`/`)},te=function(e){let t=r(e).replace(/\/$/,``).split(`/`).slice(0,-1);return t.length===1&&o.test(t[0])&&(t[0]+=`/`),t.join(`/`)||(m(e)?`/`:`.`)},ne=function(e,t){let n=r(e).split(`/`),i=``;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){i=t;break}}return t&&i.endsWith(t)?i.slice(0,-t.length):i},re=/^[a-zA-Z]:\//,ie=class e{constructor(e){let t=l(e);if(!m(t))throw Error(`FilePath requires an absolute path, got: "${e}"`);this.path=t}intern(){return`filepath@${this.path}`}static from(t){return new e(t)}static resolve(t,n){return new e(f(t,n))}static fromUri(t){if(t.startsWith(`file://`)){let n=decodeURIComponent(new URL(t).pathname);return/^\/[a-zA-Z]:[\\/]/.test(n)&&(n=n.slice(1)),new e(l(n))}return new e(l(t))}get absolute(){return this.path}get dirname(){return te(this.path)}get basename(){return ne(this.path)}get extname(){return h(this.path)}resolve(t){return new e(f(this.dirname,t))}join(...t){return new e(u(this.path,...t))}relativeTo(e){return ee(e,this.path)}toString(){return this.path}equals(e){return this.path===e.path}toUri(){let e=re.test(this.path)?`file:///`:`file://`;return new URL(e+this.path).href}static isRelative(e){return!m(l(e))}};const ae=[`null`,`true`,`false`],oe=[`-`,`+`],se=`public`,ce=ie.from(`/main.dbml`),le=ie.from(`/`);let g=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.Check=`checks`,e.Records=`records`,e.DiagramView=`diagramview`,e}({}),_=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}({});var ue=typeof global==`object`&&global&&global.Object===Object&&global,de=ue,fe=typeof self==`object`&&self&&self.Object===Object&&self,pe=de||fe||Function(`return this`)(),me=pe,he=me.Symbol,ge=he,_e=Object.prototype,ve=_e.hasOwnProperty,ye=_e.toString,be=ge?ge.toStringTag:void 0;function xe(e){var t=ve.call(e,be),n=e[be];try{e[be]=void 0;var r=!0}catch{}var i=ye.call(e);return r&&(t?e[be]=n:delete e[be]),i}var Se=xe,Ce=Object.prototype.toString;function we(e){return Ce.call(e)}var Te=we,Ee=`[object Null]`,De=`[object Undefined]`,Oe=ge?ge.toStringTag:void 0;function ke(e){return e==null?e===void 0?De:Ee:Oe&&Oe in Object(e)?Se(e):Te(e)}var Ae=ke;function je(e){return typeof e==`object`&&!!e}var Me=je,Ne=`[object Symbol]`;function Pe(e){return typeof e==`symbol`||Me(e)&&Ae(e)==Ne}var Fe=Pe;function Ie(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 Le=Ie,Re=Array.isArray,ze=Re,Be=1/0,Ve=ge?ge.prototype:void 0,He=Ve?Ve.toString:void 0;function Ue(e){if(typeof e==`string`)return e;if(ze(e))return Le(e,Ue)+``;if(Fe(e))return He?He.call(e):``;var t=e+``;return t==`0`&&1/e==-Be?`-0`:t}var We=Ue,Ge=/\s/;function Ke(e){for(var t=e.length;t--&&Ge.test(e.charAt(t)););return t}var qe=Ke,Je=/^\s+/;function Ye(e){return e&&e.slice(0,qe(e)+1).replace(Je,``)}var Xe=Ye;function Ze(e){var t=typeof e;return e!=null&&(t==`object`||t==`function`)}var Qe=Ze,$e=NaN,et=/^[-+]0x[0-9a-f]+$/i,tt=/^0b[01]+$/i,nt=/^0o[0-7]+$/i,rt=parseInt;function it(e){if(typeof e==`number`)return e;if(Fe(e))return $e;if(Qe(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=Qe(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=Xe(e);var n=tt.test(e);return n||nt.test(e)?rt(e.slice(2),n?2:8):et.test(e)?$e:+e}var at=it,ot=1/0,st=17976931348623157e292;function ct(e){return e?(e=at(e),e===ot||e===-ot?(e<0?-1:1)*st:e===e?e:0):e===0?e:0}var lt=ct;function ut(e){var t=lt(e),n=t%1;return t===t?n?t-n:t:0}var dt=ut;function ft(e){return e}var pt=ft,mt=`[object AsyncFunction]`,ht=`[object Function]`,gt=`[object GeneratorFunction]`,_t=`[object Proxy]`;function vt(e){if(!Qe(e))return!1;var t=Ae(e);return t==ht||t==gt||t==mt||t==_t}var yt=vt,bt=me[`__core-js_shared__`],xt=bt,St=function(){var e=/[^.]+$/.exec(xt&&xt.keys&&xt.keys.IE_PROTO||``);return e?`Symbol(src)_1.`+e:``}();function Ct(e){return!!St&&St in e}var wt=Ct,Tt=Function.prototype.toString;function Et(e){if(e!=null){try{return Tt.call(e)}catch{}try{return e+``}catch{}}return``}var Dt=Et,Ot=/[\\^$.*+?()[\]{}|]/g,kt=/^\[object .+?Constructor\]$/,At=Function.prototype,jt=Object.prototype,Mt=At.toString,Nt=jt.hasOwnProperty,Pt=RegExp(`^`+Mt.call(Nt).replace(Ot,`\\$&`).replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,`$1.*?`)+`$`);function Ft(e){return!Qe(e)||wt(e)?!1:(yt(e)?Pt:kt).test(Dt(e))}var It=Ft;function Lt(e,t){return e?.[t]}var Rt=Lt;function zt(e,t){var n=Rt(e,t);return It(n)?n:void 0}var Bt=zt,Vt=Bt(me,`WeakMap`),Ht=Vt;function Ut(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 Wt=Ut;function Gt(){}var Kt=Gt,qt=800,Jt=16,Yt=Date.now;function Xt(e){var t=0,n=0;return function(){var r=Yt(),i=Jt-(r-n);if(n=r,i>0){if(++t>=qt)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}var Zt=Xt;function Qt(e){return function(){return e}}var $t=Qt,en=function(){try{var e=Bt(Object,`defineProperty`);return e({},``,{}),e}catch{}}(),tn=en,nn=tn?function(e,t){return tn(e,`toString`,{configurable:!0,enumerable:!1,value:$t(t),writable:!0})}:pt,rn=nn,an=Zt(rn),on=an;function sn(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 cn=sn;function ln(e){return e!==e}var un=ln;function dn(e,t,n){for(var r=n-1,i=e.length;++r<i;)if(e[r]===t)return r;return-1}var fn=dn;function pn(e,t,n){return t===t?fn(e,t,n):cn(e,un,n)}var mn=pn;function hn(e,t){return!!(e!=null&&e.length)&&mn(e,t,0)>-1}var gn=hn,_n=9007199254740991,vn=/^(?:0|[1-9]\d*)$/;function yn(e,t){var n=typeof e;return t??=_n,!!t&&(n==`number`||n!=`symbol`&&vn.test(e))&&e>-1&&e%1==0&&e<t}var bn=yn;function xn(e,t,n){t==`__proto__`&&tn?tn(e,t,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[t]=n}var Sn=xn;function Cn(e,t){return e===t||e!==e&&t!==t}var wn=Cn,Tn=Math.max;function En(e,t,n){return t=Tn(t===void 0?e.length-1:t,0),function(){for(var r=arguments,i=-1,a=Tn(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),Wt(e,this,s)}}var Dn=En;function On(e,t){return on(Dn(e,t,pt),e+``)}var kn=On,An=9007199254740991;function jn(e){return typeof e==`number`&&e>-1&&e%1==0&&e<=An}var Mn=jn;function Nn(e){return e!=null&&Mn(e.length)&&!yt(e)}var Pn=Nn,Fn=Object.prototype;function In(e){var t=e&&e.constructor;return e===(typeof t==`function`&&t.prototype||Fn)}var Ln=In;function Rn(e,t){for(var n=-1,r=Array(e);++n<e;)r[n]=t(n);return r}var zn=Rn,Bn=`[object Arguments]`;function Vn(e){return Me(e)&&Ae(e)==Bn}var Hn=Vn,Un=Object.prototype,Wn=Un.hasOwnProperty,Gn=Un.propertyIsEnumerable,Kn=Hn(function(){return arguments}())?Hn:function(e){return Me(e)&&Wn.call(e,`callee`)&&!Gn.call(e,`callee`)},qn=Kn;function Jn(){return!1}var Yn=Jn,Xn=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Zn=Xn&&typeof module==`object`&&module&&!module.nodeType&&module,Qn=Zn&&Zn.exports===Xn?me.Buffer:void 0,$n=(Qn?Qn.isBuffer:void 0)||Yn,er=$n,tr=`[object Arguments]`,nr=`[object Array]`,rr=`[object Boolean]`,ir=`[object Date]`,ar=`[object Error]`,or=`[object Function]`,sr=`[object Map]`,cr=`[object Number]`,lr=`[object Object]`,ur=`[object RegExp]`,dr=`[object Set]`,fr=`[object String]`,pr=`[object WeakMap]`,mr=`[object ArrayBuffer]`,hr=`[object DataView]`,gr=`[object Float32Array]`,_r=`[object Float64Array]`,vr=`[object Int8Array]`,yr=`[object Int16Array]`,br=`[object Int32Array]`,xr=`[object Uint8Array]`,Sr=`[object Uint8ClampedArray]`,Cr=`[object Uint16Array]`,wr=`[object Uint32Array]`,v={};v[gr]=v[_r]=v[vr]=v[yr]=v[br]=v[xr]=v[Sr]=v[Cr]=v[wr]=!0,v[tr]=v[nr]=v[mr]=v[rr]=v[hr]=v[ir]=v[ar]=v[or]=v[sr]=v[cr]=v[lr]=v[ur]=v[dr]=v[fr]=v[pr]=!1;function Tr(e){return Me(e)&&Mn(e.length)&&!!v[Ae(e)]}var Er=Tr;function Dr(e){return function(t){return e(t)}}var Or=Dr,kr=typeof exports==`object`&&exports&&!exports.nodeType&&exports,Ar=kr&&typeof module==`object`&&module&&!module.nodeType&&module,jr=Ar&&Ar.exports===kr&&de.process,Mr=function(){try{return Ar&&Ar.require&&Ar.require(`util`).types||jr&&jr.binding&&jr.binding(`util`)}catch{}}(),Nr=Mr,Pr=Nr&&Nr.isTypedArray,Fr=Pr?Or(Pr):Er,Ir=Fr,Lr=Object.prototype.hasOwnProperty;function Rr(e,t){var n=ze(e),r=!n&&qn(e),i=!n&&!r&&er(e),a=!n&&!r&&!i&&Ir(e),o=n||r||i||a,s=o?zn(e.length,String):[],c=s.length;for(var l in e)(t||Lr.call(e,l))&&!(o&&(l==`length`||i&&(l==`offset`||l==`parent`)||a&&(l==`buffer`||l==`byteLength`||l==`byteOffset`)||bn(l,c)))&&s.push(l);return s}var zr=Rr;function Br(e,t){return function(n){return e(t(n))}}var Vr=Br,Hr=Vr(Object.keys,Object),Ur=Hr,Wr=Object.prototype.hasOwnProperty;function Gr(e){if(!Ln(e))return Ur(e);var t=[];for(var n in Object(e))Wr.call(e,n)&&n!=`constructor`&&t.push(n);return t}var Kr=Gr;function qr(e){return Pn(e)?zr(e):Kr(e)}var Jr=qr;function Yr(e){var t=[];if(e!=null)for(var n in Object(e))t.push(n);return t}var Xr=Yr,Zr=Object.prototype.hasOwnProperty;function Qr(e){if(!Qe(e))return Xr(e);var t=Ln(e),n=[];for(var r in e)r==`constructor`&&(t||!Zr.call(e,r))||n.push(r);return n}var $r=Qr;function ei(e){return Pn(e)?zr(e,!0):$r(e)}var ti=ei,ni=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,ri=/^\w*$/;function ii(e,t){if(ze(e))return!1;var n=typeof e;return n==`number`||n==`symbol`||n==`boolean`||e==null||Fe(e)?!0:ri.test(e)||!ni.test(e)||t!=null&&e in Object(t)}var ai=ii,oi=Bt(Object,`create`),si=oi;function ci(){this.__data__=si?si(null):{},this.size=0}var li=ci;function ui(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var di=ui,fi=`__lodash_hash_undefined__`,pi=Object.prototype.hasOwnProperty;function mi(e){var t=this.__data__;if(si){var n=t[e];return n===fi?void 0:n}return pi.call(t,e)?t[e]:void 0}var hi=mi,gi=Object.prototype.hasOwnProperty;function _i(e){var t=this.__data__;return si?t[e]!==void 0:gi.call(t,e)}var vi=_i,yi=`__lodash_hash_undefined__`;function bi(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=si&&t===void 0?yi:t,this}var xi=bi;function Si(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])}}Si.prototype.clear=li,Si.prototype.delete=di,Si.prototype.get=hi,Si.prototype.has=vi,Si.prototype.set=xi;var Ci=Si;function wi(){this.__data__=[],this.size=0}var Ti=wi;function Ei(e,t){for(var n=e.length;n--;)if(wn(e[n][0],t))return n;return-1}var Di=Ei,Oi=Array.prototype.splice;function ki(e){var t=this.__data__,n=Di(t,e);return n<0?!1:(n==t.length-1?t.pop():Oi.call(t,n,1),--this.size,!0)}var Ai=ki;function ji(e){var t=this.__data__,n=Di(t,e);return n<0?void 0:t[n][1]}var Mi=ji;function Ni(e){return Di(this.__data__,e)>-1}var Pi=Ni;function Fi(e,t){var n=this.__data__,r=Di(n,e);return r<0?(++this.size,n.push([e,t])):n[r][1]=t,this}var Ii=Fi;function Li(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])}}Li.prototype.clear=Ti,Li.prototype.delete=Ai,Li.prototype.get=Mi,Li.prototype.has=Pi,Li.prototype.set=Ii;var Ri=Li,zi=Bt(me,`Map`),Bi=zi;function Vi(){this.size=0,this.__data__={hash:new Ci,map:new(Bi||Ri),string:new Ci}}var Hi=Vi;function Ui(e){var t=typeof e;return t==`string`||t==`number`||t==`symbol`||t==`boolean`?e!==`__proto__`:e===null}var Wi=Ui;function Gi(e,t){var n=e.__data__;return Wi(t)?n[typeof t==`string`?`string`:`hash`]:n.map}var Ki=Gi;function qi(e){var t=Ki(this,e).delete(e);return this.size-=t?1:0,t}var Ji=qi;function Yi(e){return Ki(this,e).get(e)}var Xi=Yi;function Zi(e){return Ki(this,e).has(e)}var Qi=Zi;function $i(e,t){var n=Ki(this,e),r=n.size;return n.set(e,t),this.size+=n.size==r?0:1,this}var ea=$i;function ta(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])}}ta.prototype.clear=Hi,ta.prototype.delete=Ji,ta.prototype.get=Xi,ta.prototype.has=Qi,ta.prototype.set=ea;var na=ta,ra=`Expected a function`;function ia(e,t){if(typeof e!=`function`||t!=null&&typeof t!=`function`)throw TypeError(ra);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(ia.Cache||na),n}ia.Cache=na;var aa=ia,oa=500;function sa(e){var t=aa(e,function(e){return n.size===oa&&n.clear(),e}),n=t.cache;return t}var ca=sa,la=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ua=/\\(\\)?/g,da=ca(function(e){var t=[];return e.charCodeAt(0)===46&&t.push(``),e.replace(la,function(e,n,r,i){t.push(r?i.replace(ua,`$1`):n||e)}),t}),fa=da;function pa(e){return e==null?``:We(e)}var ma=pa;function ha(e,t){return ze(e)?e:ai(e,t)?[e]:fa(ma(e))}var ga=ha,_a=1/0;function va(e){if(typeof e==`string`||Fe(e))return e;var t=e+``;return t==`0`&&1/e==-_a?`-0`:t}var ya=va;function ba(e,t){t=ga(t,e);for(var n=0,r=t.length;e!=null&&n<r;)e=e[ya(t[n++])];return n&&n==r?e:void 0}var xa=ba;function Sa(e,t,n){var r=e==null?void 0:xa(e,t);return r===void 0?n:r}var Ca=Sa;function wa(e,t){for(var n=-1,r=t.length,i=e.length;++n<r;)e[i+n]=t[n];return e}var Ta=wa,Ea=ge?ge.isConcatSpreadable:void 0;function Da(e){return ze(e)||qn(e)||!!(Ea&&e&&e[Ea])}var Oa=Da;function ka(e,t,n,r,i){var a=-1,o=e.length;for(n||=Oa,i||=[];++a<o;){var s=e[a];t>0&&n(s)?t>1?ka(s,t-1,n,r,i):Ta(i,s):r||(i[i.length]=s)}return i}var Aa=ka;function ja(e){return e!=null&&e.length?Aa(e,1):[]}var Ma=ja;function Na(){this.__data__=new Ri,this.size=0}var Pa=Na;function Fa(e){var t=this.__data__,n=t.delete(e);return this.size=t.size,n}var Ia=Fa;function La(e){return this.__data__.get(e)}var Ra=La;function za(e){return this.__data__.has(e)}var Ba=za,Va=200;function Ha(e,t){var n=this.__data__;if(n instanceof Ri){var r=n.__data__;if(!Bi||r.length<Va-1)return r.push([e,t]),this.size=++n.size,this;n=this.__data__=new na(r)}return n.set(e,t),this.size=n.size,this}var Ua=Ha;function Wa(e){this.size=(this.__data__=new Ri(e)).size}Wa.prototype.clear=Pa,Wa.prototype.delete=Ia,Wa.prototype.get=Ra,Wa.prototype.has=Ba,Wa.prototype.set=Ua;var Ga=Wa;function Ka(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 qa=Ka;function Ja(){return[]}var Ya=Ja,Xa=Object.prototype.propertyIsEnumerable,Za=Object.getOwnPropertySymbols,Qa=Za?function(e){return e==null?[]:(e=Object(e),qa(Za(e),function(t){return Xa.call(e,t)}))}:Ya,$a=Qa;function eo(e,t,n){var r=t(e);return ze(e)?r:Ta(r,n(e))}var to=eo;function no(e){return to(e,Jr,$a)}var ro=no,io=Bt(me,`DataView`),ao=io,oo=Bt(me,`Promise`),so=oo,co=Bt(me,`Set`),lo=co,uo=`[object Map]`,fo=`[object Object]`,po=`[object Promise]`,mo=`[object Set]`,ho=`[object WeakMap]`,go=`[object DataView]`,_o=Dt(ao),vo=Dt(Bi),yo=Dt(so),bo=Dt(lo),xo=Dt(Ht),So=Ae;(ao&&So(new ao(new ArrayBuffer(1)))!=go||Bi&&So(new Bi)!=uo||so&&So(so.resolve())!=po||lo&&So(new lo)!=mo||Ht&&So(new Ht)!=ho)&&(So=function(e){var t=Ae(e),n=t==fo?e.constructor:void 0,r=n?Dt(n):``;if(r)switch(r){case _o:return go;case vo:return uo;case yo:return po;case bo:return mo;case xo:return ho}return t});var Co=So,wo=me.Uint8Array,To=wo;function Eo(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 Do=Eo,Oo=`__lodash_hash_undefined__`;function ko(e){return this.__data__.set(e,Oo),this}var Ao=ko;function jo(e){return this.__data__.has(e)}var Mo=jo;function No(e){var t=-1,n=e==null?0:e.length;for(this.__data__=new na;++t<n;)this.add(e[t])}No.prototype.add=No.prototype.push=Ao,No.prototype.has=Mo;var Po=No;function Fo(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 Io=Fo;function Lo(e,t){return e.has(t)}var Ro=Lo,zo=1,Bo=2;function Vo(e,t,n,r,i,a){var o=n&zo,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&Bo?new Po:void 0;for(a.set(e,t),a.set(t,e);++d<s;){var m=e[d],h=t[d];if(r)var ee=o?r(h,m,d,t,e,a):r(m,h,d,e,t,a);if(ee!==void 0){if(ee)continue;f=!1;break}if(p){if(!Io(t,function(e,t){if(!Ro(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 Ho=Vo;function Uo(e){var t=-1,n=Array(e.size);return e.forEach(function(e,r){n[++t]=[r,e]}),n}var Wo=Uo;function Go(e){var t=-1,n=Array(e.size);return e.forEach(function(e){n[++t]=e}),n}var Ko=Go,qo=1,Jo=2,Yo=`[object Boolean]`,Xo=`[object Date]`,Zo=`[object Error]`,Qo=`[object Map]`,$o=`[object Number]`,es=`[object RegExp]`,ts=`[object Set]`,ns=`[object String]`,rs=`[object Symbol]`,is=`[object ArrayBuffer]`,as=`[object DataView]`,os=ge?ge.prototype:void 0,ss=os?os.valueOf:void 0;function cs(e,t,n,r,i,a,o){switch(n){case as:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case is:return!(e.byteLength!=t.byteLength||!a(new To(e),new To(t)));case Yo:case Xo:case $o:return wn(+e,+t);case Zo:return e.name==t.name&&e.message==t.message;case es:case ns:return e==t+``;case Qo:var s=Wo;case ts:var c=r&qo;if(s||=Ko,e.size!=t.size&&!c)return!1;var l=o.get(e);if(l)return l==t;r|=Jo,o.set(e,t);var u=Ho(s(e),s(t),r,i,a,o);return o.delete(e),u;case rs:if(ss)return ss.call(e)==ss.call(t)}return!1}var ls=cs,us=1,ds=Object.prototype.hasOwnProperty;function fs(e,t,n,r,i,a){var o=n&us,s=ro(e),c=s.length;if(c!=ro(t).length&&!o)return!1;for(var l=c;l--;){var u=s[l];if(!(o?u in t:ds.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],ee=t[u];if(r)var te=o?r(ee,h,u,t,e,a):r(h,ee,u,e,t,a);if(!(te===void 0?h===ee||i(h,ee,n,r,a):te)){p=!1;break}m||=u==`constructor`}if(p&&!m){var ne=e.constructor,re=t.constructor;ne!=re&&`constructor`in e&&`constructor`in t&&!(typeof ne==`function`&&ne instanceof ne&&typeof re==`function`&&re instanceof re)&&(p=!1)}return a.delete(e),a.delete(t),p}var ps=fs,ms=1,hs=`[object Arguments]`,gs=`[object Array]`,_s=`[object Object]`,vs=Object.prototype.hasOwnProperty;function ys(e,t,n,r,i,a){var o=ze(e),s=ze(t),c=o?gs:Co(e),l=s?gs:Co(t);c=c==hs?_s:c,l=l==hs?_s:l;var u=c==_s,d=l==_s,f=c==l;if(f&&er(e)){if(!er(t))return!1;o=!0,u=!1}if(f&&!u)return a||=new Ga,o||Ir(e)?Ho(e,t,n,r,i,a):ls(e,t,c,n,r,i,a);if(!(n&ms)){var p=u&&vs.call(e,`__wrapped__`),m=d&&vs.call(t,`__wrapped__`);if(p||m){var h=p?e.value():e,ee=m?t.value():t;return a||=new Ga,i(h,ee,n,r,a)}}return f?(a||=new Ga,ps(e,t,n,r,i,a)):!1}var bs=ys;function xs(e,t,n,r,i){return e===t?!0:e==null||t==null||!Me(e)&&!Me(t)?e!==e&&t!==t:bs(e,t,n,r,xs,i)}var Ss=xs,Cs=1,ws=2;function Ts(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 Ga;if(r)var f=r(l,u,c,e,t,d);if(!(f===void 0?Ss(u,l,Cs|ws,r,d):f))return!1}}return!0}var Es=Ts;function Ds(e){return e===e&&!Qe(e)}var Os=Ds;function ks(e){for(var t=Jr(e),n=t.length;n--;){var r=t[n],i=e[r];t[n]=[r,i,Os(i)]}return t}var As=ks;function js(e,t){return function(n){return n==null?!1:n[e]===t&&(t!==void 0||e in Object(n))}}var Ms=js;function Ns(e){var t=As(e);return t.length==1&&t[0][2]?Ms(t[0][0],t[0][1]):function(n){return n===e||Es(n,e,t)}}var Ps=Ns;function Fs(e,t){return e!=null&&t in Object(e)}var Is=Fs;function Ls(e,t,n){t=ga(t,e);for(var r=-1,i=t.length,a=!1;++r<i;){var o=ya(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&&Mn(i)&&bn(o,i)&&(ze(e)||qn(e)))}var Rs=Ls;function zs(e,t){return e!=null&&Rs(e,t,Is)}var Bs=zs,Vs=1,Hs=2;function Us(e,t){return ai(e)&&Os(t)?Ms(ya(e),t):function(n){var r=Ca(n,e);return r===void 0&&r===t?Bs(n,e):Ss(t,r,Vs|Hs)}}var Ws=Us;function Gs(e){return function(t){return t?.[e]}}var Ks=Gs;function qs(e){return function(t){return xa(t,e)}}var Js=qs;function Ys(e){return ai(e)?Ks(ya(e)):Js(e)}var Xs=Ys;function Zs(e){return typeof e==`function`?e:e==null?pt:typeof e==`object`?ze(e)?Ws(e[0],e[1]):Ps(e):Xs(e)}var Qs=Zs;function $s(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 ec=$s;function tc(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 nc=tc,rc=nc(),ic=rc;function ac(e,t){return e&&ic(e,t,Jr)}var oc=ac;function sc(e,t){return function(n,r){if(n==null)return n;if(!Pn(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 cc=sc,lc=cc(oc),uc=lc;function dc(e,t,n,r){return uc(e,function(e,i,a){t(r,e,n(e),a)}),r}var fc=dc;function pc(e,t){return function(n,r){var i=ze(n)?ec:fc,a=t?t():{};return i(n,e,Qs(r,2),a)}}var mc=pc;function hc(e){return Me(e)&&Pn(e)}var gc=hc;function _c(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 vc=_c,yc=200;function bc(e,t,n,r){var i=-1,a=gn,o=!0,s=e.length,c=[],l=t.length;if(!s)return c;n&&(t=Le(t,Or(n))),r?(a=vc,o=!1):t.length>=yc&&(a=Ro,o=!1,t=new Po(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 xc=bc,Sc=kn(function(e,t){return gc(e)?xc(e,Aa(t,1,gc,!0)):[]}),Cc=Sc;function wc(e){var t=e==null?0:e.length;return t?e[t-1]:void 0}var y=wc;function Tc(e){return typeof e==`function`?e:pt}var Ec=Tc;function Dc(e,t){var n=[];return uc(e,function(e,r,i){t(e,r,i)&&n.push(e)}),n}var Oc=Dc;function kc(e,t){return(ze(e)?qa:Oc)(e,Qs(t,3))}var Ac=kc,jc=Math.max,Mc=Math.min;function Nc(e,t,n){var r=e==null?0:e.length;if(!r)return-1;var i=r-1;return n!==void 0&&(i=dt(n),i=n<0?jc(r+i,0):Mc(i,r-1)),cn(e,Qs(t,3),i,!0)}var Pc=Nc;function Fc(e){return e&&e.length?e[0]:void 0}var Ic=Fc;function Lc(e,t){var n=-1,r=Pn(e)?Array(e.length):[];return uc(e,function(e,i,a){r[++n]=t(e,i,a)}),r}var Rc=Lc;function zc(e,t){return(ze(e)?Le:Rc)(e,Qs(t,3))}var Bc=zc;function Vc(e,t){return Aa(Bc(e,t),1)}var Hc=Vc;function Uc(e,t){return e==null?e:ic(e,Ec(t),ti)}var Wc=Uc,Gc=Object.prototype.hasOwnProperty,Kc=mc(function(e,t,n){Gc.call(e,n)?e[n].push(t):Sn(e,n,[t])}),qc=Kc,Jc=`[object Map]`,Yc=`[object Set]`,Xc=Object.prototype.hasOwnProperty;function Zc(e){if(e==null)return!0;if(Pn(e)&&(ze(e)||typeof e==`string`||typeof e.splice==`function`||er(e)||Ir(e)||qn(e)))return!e.length;var t=Co(e);if(t==Jc||t==Yc)return!e.size;if(Ln(e))return!Kr(e).length;for(var n in e)if(Xc.call(e,n))return!1;return!0}var Qc=Zc,$c=mc(function(e,t,n){Sn(e,n,t)}),el=$c,tl=mc(function(e,t,n){e[n?0:1].push(t)},function(){return[[],[]]}),b=tl,nl=lo&&1/Ko(new lo([,-0]))[1]==1/0?function(e){return new lo(e)}:Kt,rl=nl,il=200;function al(e,t,n){var r=-1,i=gn,a=e.length,o=!0,s=[],c=s;if(n)o=!1,i=vc;else if(a>=il){var l=t?null:rl(e);if(l)return Ko(l);o=!1,i=Ro,c=new Po}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 ol=al;function sl(e,t){return e&&e.length?ol(e,Qs(t,2)):[]}var cl=sl,ll=Math.max;function ul(e){if(!(e&&e.length))return[];var t=0;return e=qa(e,function(e){if(gc(e))return t=ll(e.length,t),!0}),zn(t,function(t){return Le(e,Ks(t))})}var dl=ul,fl=kn(dl),pl=fl;let x=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 ml(e){switch(e.kind){case x.NEWLINE:case x.SPACE:case x.TAB:case x.SINGLE_LINE_COMMENT:case x.MULTILINE_COMMENT:return!0;default:return!1}}function hl(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 gl(e){return e!==void 0&&e.kind===x.OP}var _l=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 vl(e){return e.trailingTrivia.find(({kind:e})=>e===x.NEWLINE)!==void 0}function yl(e,t){return t.leadingTrivia.find(({kind:e})=>e===x.NEWLINE)!==void 0||vl(e)}function bl(e){return e.trailingTrivia.find(({kind:e})=>[x.SPACE,x.TAB].includes(e))!==void 0}function xl(e){return e.trailingTrivia.length===0?e.end:xl(y(e.trailingTrivia))}function Sl(e){return e.leadingTrivia.length===0?e.start:Sl(e.leadingTrivia[0])}function Cl(e){return[x.SINGLE_LINE_COMMENT,x.MULTILINE_COMMENT].includes(e.kind)}var wl=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},S=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 _l?Sl(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 _l?xl(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}`}parentOfKind(e){let t=this.parentNode;for(;t;){if(t instanceof e)return t;t=t.parentNode}}strictlyContains(e){let t=this.start<e.start,n=t||this.start===e.start,r=this.end>e.end,i=r||this.end===e.end;return t&&i||n&&r}containsEq(e){return this.start<=e.start&&this.end>=e.end}};let C=function(e){return e.PROGRAM=`<program>`,e.ELEMENT_DECLARATION=`<element-declaration>`,e.ATTRIBUTE=`<attribute>`,e.IDENTIFIER_STREAM=`<identifer-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.WILDCARD=`<wildcard>`,e.EMPTY=`<dummy>`,e.ARRAY=`<array>`,e}({});var Tl=class extends S{constructor({body:e=[],eof:t,source:n},r,i){super(r,C.PROGRAM,i,[...e,t]),this.source=n,this.body=e,this.eof=t}},w=class e extends S{constructor({type:t,name:n,as:r,alias:i,attributeList:a,bodyColon:o,body:s},c,l){if(super(c,C.ELEMENT_DECLARATION,l,[t,n,r,i,a,o,s]),s&&o&&!(s instanceof T||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)}},El=class extends S{constructor({identifiers:e=[]},t,n){super(t,C.IDENTIFIER_STREAM,n,e||[]),this.identifiers=e}},Dl=class extends S{constructor({name:e,colon:t,value:n},r,i){super(r,C.ATTRIBUTE,i,[e,t,n]),this.name=e,this.value=n,this.colon=t}},Ol=class extends S{constructor({op:e,expression:t},n,r){super(n,C.PREFIX_EXPRESSION,r,[e,t]),this.op=e,this.expression=t}},kl=class extends S{constructor({op:e,leftExpression:t,rightExpression:n},r,i){super(r,C.INFIX_EXPRESSION,i,[t,e,n]),this.op=e,this.leftExpression=t,this.rightExpression=n}},Al=class extends S{constructor({op:e,expression:t},n,r){super(n,C.POSTFIX_EXPRESSION,r,[t,e]),this.op=e,this.expression=t}},jl=class extends S{constructor({value:e},t,n){super(t,C.FUNCTION_EXPRESSION,n,[e]),this.value=e}},T=class extends S{constructor({callee:e,args:t=[]},n,r){super(n,C.FUNCTION_APPLICATION,r,[e,...t]),this.callee=e,this.args=t}},E=class extends S{constructor({blockOpenBrace:e,body:t=[],blockCloseBrace:n},r,i){super(r,C.BLOCK_EXPRESSION,i,[e,...t,n]),this.blockOpenBrace=e,this.body=t,this.blockCloseBrace=n}},D=class extends S{constructor({listOpenBracket:e,elementList:t=[],commaList:n=[],listCloseBracket:r},i,a){super(i,C.LIST_EXPRESSION,a,[e,...Vl(t,n),r]),this.listOpenBracket=e,this.elementList=t,this.commaList=n,this.listCloseBracket=r}},Ml=class extends S{constructor({tupleOpenParen:e,elementList:t=[],commaList:n=[],tupleCloseParen:r},i,a){super(i,C.TUPLE_EXPRESSION,a,[e,...Vl(t,n),r]),this.tupleOpenParen=e,this.elementList=t,this.commaList=n,this.tupleCloseParen=r}},Nl=class extends S{constructor({elementList:e=[],commaList:t=[]},n,r){super(n,C.COMMA_EXPRESSION,r,[...Vl(e,t)]),this.elementList=e,this.commaList=t}},Pl=class extends Ml{constructor({groupOpenParen:e,expression:t,groupCloseParen:n},r,i){super({tupleOpenParen:e,elementList:t&&[t],commaList:[],tupleCloseParen:n},r,i),this.kind=C.GROUP_EXPRESSION}},O=class extends S{constructor({callee:e,argumentList:t},n,r){super(n,C.CALL_EXPRESSION,r,[e,t]),this.callee=e,this.argumentList=t}},Fl=class extends S{constructor({literal:e},t,n){super(t,C.LITERAL,n,[e]),this.literal=e}},Il=class extends S{constructor({token:e},t,n){super(t,C.WILDCARD,n,[e]),this.token=e}},Ll=class extends S{constructor({variable:e},t,n){super(t,C.VARIABLE,n,[e]),this.variable=e}},Rl=class extends S{constructor({expression:e},t,n){super(t,C.PRIMARY_EXPRESSION,n,[e]),this.expression=e}},zl=class extends S{constructor({prevToken:e},t,n){let r=_l.create(x.SPACE,n,e.endPos,e.endPos,` `,!1);super(t,C.EMPTY,n,[r])}},Bl=class extends S{constructor({expression:e,indexer:t},n,r){super(n,C.ARRAY,r,[e,t]),this.array=e,this.indexer=t}};function Vl(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?Ma(pl(e,t)):Ma(pl(t,e))).filter(e=>e!==null)}function Hl(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 Ul(e,t,n){let r=t,i=e;if(i instanceof O&&i.argumentList&&(r=[i.argumentList,...r],i=i.callee),!i||!Ql(i)||r.length===0)return;let a=[...r],o=Xl(i),s=a.pop();if(!(s instanceof E))return;let c=y(a)instanceof D?a.pop():void 0;if(a.length===3){let e=Xl(a[1]);return!e||!Wl(e)?void 0:n.create(w,{type:o,name:a[0],as:e,alias:a[2],attributeList:c,body:s})}if(a.length===1)return n.create(w,{type:o,name:a[0],attributeList:c,body:s});if(a.length===0)return n.create(w,{type:o,attributeList:c,body:s})}function Wl(e){return e?.kind===x.IDENTIFIER&&e.value.toLowerCase()===`as`}function k(e){e&&(e instanceof _l?Gl(e):Kl(e))}function Gl(e){e.kind!==x.EOF&&(e.isInvalid=!0)}function Kl(e){if(e instanceof w)k(e.type),k(e.name),k(e.as),k(e.alias),k(e.bodyColon),k(e.attributeList),k(e.body);else if(e instanceof El)e.identifiers.forEach(k);else if(e instanceof Dl)k(e.name),k(e.colon),k(e.value);else if(e instanceof Ol)k(e.op),k(e.expression);else if(e instanceof kl)k(e.leftExpression),k(e.op),k(e.rightExpression);else if(e instanceof Al)k(e.op),k(e.expression);else if(e instanceof E)k(e.blockOpenBrace),e.body.forEach(k),k(e.blockCloseBrace);else if(e instanceof D)k(e.listOpenBracket),e.commaList.forEach(k),e.elementList.forEach(k),k(e.listCloseBracket);else if(e instanceof Ml)k(e.tupleOpenParen),e.commaList.forEach(k),e.elementList.forEach(k),k(e.tupleCloseParen);else if(e instanceof Nl)e.commaList.forEach(k),e.elementList.forEach(k);else if(e instanceof O)k(e.callee),k(e.argumentList);else if(e instanceof T)k(e.callee),e.args.forEach(k);else if(e instanceof Rl)k(e.expression);else if(e instanceof jl)k(e.value);else if(e instanceof Ll)k(e.variable);else if(e instanceof Fl)k(e.literal);else if(e instanceof Pl)throw Error(`This case is handled by the TupleExpressionNode case`);else if(e instanceof Bl)k(e.array),k(e.indexer);else if(e instanceof Tl)e.body.forEach(k),k(e.eof);else if(!(e instanceof zl))if(e instanceof Il)k(e.token);else throw Error(`Unreachable case in markInvalidNode`)}function ql(e){return!!e?.isInvalid}function Jl(...e){return e.filter(e=>e!==void 0)}function Yl(e){if(e instanceof Tl)return Jl(...e.body,e.eof);if(e instanceof w)return Jl(e.type,e.name,e.as,e.alias,e.attributeList,e.bodyColon,e.body);if(e instanceof Dl)return Jl(e.name,e.colon,e.value);if(e instanceof El)return e.identifiers;if(e instanceof Fl)return e.literal?[e.literal]:[];if(e instanceof Ll)return Jl(e.variable);if(e instanceof Ol)return Jl(e.op,e.expression);if(e instanceof kl)return Jl(e.leftExpression,e.op,e.rightExpression);if(e instanceof Al)return Jl(e.expression,e.op);if(e instanceof jl)return Jl(e.value);if(e instanceof T)return Jl(e.callee,...e.args);if(e instanceof E)return Jl(e.blockOpenBrace,...e.body,e.blockCloseBrace);if(e instanceof D)return Jl(e.listOpenBracket,...Hl(e.elementList,e.commaList),e.listCloseBracket);if(e instanceof Ml)return Jl(e.tupleOpenParen,...Hl(e.elementList,e.commaList),e.tupleCloseParen);if(e instanceof Nl)return Jl(...Hl(e.elementList,e.commaList));if(e instanceof O)return Jl(e.callee,e.argumentList);if(e instanceof Rl)return Jl(e.expression);if(e instanceof Bl)return Jl(e.array,e.indexer);if(e instanceof Il)return Jl(e.token);throw e instanceof Pl?Error(`This case is already handled by TupleExpressionNode`):Error(`Unreachable - no other possible cases`)}function Xl(e){if(j(e))return e.expression.variable}function A(e){return e instanceof Rl&&(e.expression instanceof Ll&&e.expression.variable instanceof _l&&e.expression.variable.kind===x.QUOTED_STRING||e.expression instanceof Fl&&e.expression.literal?.kind===x.STRING_LITERAL)}function j(e){return e instanceof Rl&&e.expression instanceof Ll&&e.expression.variable instanceof _l}function Zl(e){return e?e instanceof Il:!1}function Ql(e){return e instanceof Rl&&e.expression instanceof Ll&&e.expression.variable?.kind===x.IDENTIFIER}function $l(e){return e instanceof kl&&e.leftExpression instanceof S&&e.rightExpression instanceof S&&e.op?.value===`.`}function eu(e){return j(e)?!0:$l(e)&&j(e.rightExpression)&&eu(e.leftExpression)}function tu(e){if(e===void 0)return;let t=e.identifiers.map(e=>e.value).join(` `);if(t!==``)return t}function nu(e){let t=L(e?.name);return t===void 0?void 0:t.join(`.`)}let 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_DIAGRAMVIEW_CONTEXT=3082]=`INVALID_DIAGRAMVIEW_CONTEXT`,e[e.DUPLICATE_DIAGRAMVIEW_NAME=3083]=`DUPLICATE_DIAGRAMVIEW_NAME`,e[e.INVALID_DIAGRAMVIEW_FIELD=3084]=`INVALID_DIAGRAMVIEW_FIELD`,e[e.DUPLICATE_DIAGRAMVIEW_FIELD=3085]=`DUPLICATE_DIAGRAMVIEW_FIELD`,e[e.BINDING_ERROR=4e3]=`BINDING_ERROR`,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}({});var 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 ru(this.code,this.message,this.nodeOrToken)}get filepath(){return this.nodeOrToken.filepath}},ru=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}},P=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 this.value===e?void 0:this.value}getValue(){return this.value}getErrors(){return this.errors}getWarnings(){return this.warnings||[]}chainFiltered(t,n){if(this.value===t)return new e(void 0,this.errors,this.warnings);let r=n(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 this.value===t?new e(void 0,this.errors,this.warnings):new e(n(this.value),this.errors,this.warnings)}map(t){return new e(t(this.value),this.errors,this.warnings)}};let F=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.DiagramViewField=`DiagramView field`,e}({});function iu(e){return`${F.Schema}:${e}`}function au(e){return`${F.Table}:${e}`}function ou(e){return`${F.Column}:${e}`}function su(e){return`${F.Enum}:${e}`}function cu(e){return`${F.EnumField}:${e}`}function lu(e){return`${F.TableGroup}:${e}`}function uu(e){return`${F.TableGroupField}:${e}`}function du(e){return`${F.StickyNote}:${e}`}function fu(e){return`${F.TablePartial}:${e}`}function pu(e){return`${F.PartialInjection}:${e}`}function mu(e){return`${F.DiagramView}:${e}`}function hu(e){return`${F.DiagramViewField}:${e}`}function gu(e,t){switch(t){case F.Column:return ou(e);case F.Enum:return su(e);case F.EnumField:return cu(e);case F.Schema:return iu(e);case F.Table:return au(e);case F.TableGroup:return lu(e);case F.TableGroupField:return uu(e);case F.StickyNote:return du(e);case F.TablePartial:return fu(e);case F.PartialInjection:return pu(e);case F.DiagramView:return mu(e);case F.DiagramViewField:return hu(e);default:throw Error(`Unreachable`)}}function _u(e){let[t,n]=e.split(`:`);return Object.values(F).includes(t)?{name:n,kind:t}:void 0}var vu=class{constructor(){this.id=0}reset(){this.id=0}nextId(){return this.id++}},yu=class{constructor({kind:e,declaration:t,symbolTable:n,filepath:r},i){this.references=[],this.id=i,this.kind=e,this.declaration=t,this.symbolTable=n,this.filepath=r??t?.filepath??ce}isKind(e){return this.kind===e}},bu=class extends yu{constructor({symbolTable:e,name:t},n){super({kind:F.Schema,symbolTable:e},n),this.name=t}},xu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.Enum,symbolTable:e,declaration:t},n)}},Su=class extends yu{constructor({declaration:e},t){super({kind:F.EnumField,declaration:e},t)}},Cu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.Table,symbolTable:e,declaration:t},n)}},wu=class extends yu{constructor({declaration:e},t){super({kind:F.Column,declaration:e},t)}},Tu=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.TableGroup,symbolTable:e,declaration:t},n)}},Eu=class extends yu{constructor({declaration:e},t){super({kind:F.TableGroupField,declaration:e},t)}},Du=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.TablePartial,symbolTable:e,declaration:t},n)}},Ou=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.PartialInjection,symbolTable:e,declaration:t},n)}},ku=class extends yu{constructor({declaration:e,tablePartialSymbol:t},n){super({kind:F.Column,declaration:e},n),this.tablePartialSymbol=t}},Au=class extends yu{constructor({symbolTable:e,declaration:t},n){super({kind:F.DiagramView,symbolTable:e,declaration:t},n)}},ju=class extends yu{constructor({declaration:e},t){super({kind:F.DiagramViewField,declaration:e},t)}},Mu=class extends yu{constructor({declaration:e},t){super({kind:F.StickyNote,declaration:e},t)}},Nu=class{constructor(){this.table=new Map}has(e){return this.table.has(e)}set(e,t){this.table.set(e,t)}get(e,t){return this.table.get(e)||t!==void 0&&this.set(e,t)||t}entries(){return this.table.entries()}forEach(e){return this.table.forEach(e)}};function Pu(e){return[iu,au,su,lu,ou,cu,uu,fu,pu,mu,hu].map(t=>t(e))}var Fu=class{constructor(e){this.generator=e}create(e,t){return new e(t,this.generator.nextId())}};function Iu(e){return!!e.match(/(\p{L}|_|\p{M})/gu)}function Lu(e){if(!e)return!1;let t=e[0];return t>=`0`&&t<=`9`}function Ru(e){let[t]=e;return Lu(t)||Iu(t)&&t.toLowerCase()>=`a`&&t.toLowerCase()<=`f`}function zu(e){return Iu(e)||Lu(e)}function Bu(e,t){let n=t.toLowerCase();return Object.values(e).find(e=>e.toLowerCase()===n)}var Vu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=new N(M.INVALID_CHECKS_CONTEXT,`A Checks can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof Tl)return[e];let t=this.declarationNode.parent;return t instanceof w&&t.isKind(g.Table,g.TablePartial)?[]:[e]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Checks name`,e)]: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 T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Checks must have a complex body`,e)];let[t,n]=b(e.body,e=>e instanceof T);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 y(n)instanceof D&&t.push(...this.validateFieldSetting(n.pop())),(n.length>1||!(n[0]instanceof jl))&&t.push(new N(M.INVALID_CHECKS_FIELD,`A check field must be a function expression`,e)),t})}validateFieldSetting(e){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];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=>{A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Hu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w&&this.declarationNode.parent.isKind(g.Project)?[]:[new N(M.INVALID_CUSTOM_CONTEXT,`A Custom element can only appear in a Project`,this.declarationNode)]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Custom element name`,e)]: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 E)return[new N(M.UNEXPECTED_COMPLEX_BODY,`A Custom element can only have an inline field`,e)];let t=[];return A(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}},Uu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){let e=[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement()],t=this.validateBody(this.declarationNode.body);return e.push(...t.errors),{errors:e,warnings:t.warnings}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_DIAGRAMVIEW_CONTEXT,`DiagramView must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?id(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)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Au,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t!==void 0){let n=t,r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=mu(r);if(i.has(a))return[new N(M.DUPLICATE_DIAGRAMVIEW_NAME,`DiagramView '${r}' already exists`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=I(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 T)return{errors:[new N(M.UNEXPECTED_SIMPLE_BODY,`A DiagramView's body must be a block`,e)],warnings:[]};let[t,n]=b(e.body,e=>e instanceof T),r=this.validateSubElements(n);return{errors:[...this.validateFields(t),...r.errors],warnings:r.warnings}}validateFields(e){return e.flatMap(e=>{if(Zl(e.callee))return e.args.length>0?e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)):[];let t=[];return t.push(new N(M.INVALID_DIAGRAMVIEW_FIELD,`Fields are not allowed at DiagramView level. Use Tables, Notes, TableGroups, or Schemas blocks instead.`,e)),t})}validateSubElements(e){let t=[],n=[],r=[`tables`,`notes`,`tablegroups`,`schemas`];for(let i of e){if(i.parent=this.declarationNode,!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 E))return{errors:t,warnings:n};let r=e.body,i=r.body.some(e=>e instanceof T&&Zl(e.callee)),a=r.body.some(e=>e instanceof T&&!Zl(e.callee));return i&&a&&n.push(new ru(M.INVALID_DIAGRAMVIEW_FIELD,`Wildcard (*) combined with specific items in ${e.type?.value} block. Specific items will be ignored.`,e)),t.push(...this.registerSubBlockFields(e)),{errors:t,warnings:n}}registerSubBlockFields(e){let t=[];if(!e.body||!(e.body instanceof E))return t;let n=e.body.body.filter(e=>e instanceof T);for(let e of n){if(e.callee&&j(e.callee)){if(Zl(e.callee))continue;let n=z(e.callee),r=hu(n),i=this.symbolFactory.create(ju,{declaration:e});e.symbol=i;let a=this.declarationNode.symbol.symbolTable;if(a.has(r)){let i=a.get(r);t.push(new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,e),new N(M.DUPLICATE_DIAGRAMVIEW_FIELD,`${n} already exists in DiagramView`,i.declaration))}else a.set(r,i)}e.args.length>0&&t.push(...e.args.map(e=>new N(M.INVALID_DIAGRAMVIEW_FIELD,`DiagramView field should only have a single name`,e)))}return t}},Wu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_PROJECT_CONTEXT,`An Enum can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as an Enum name`,e)]:nd(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)]:[]}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(xu,{declaration:this.declarationNode,symbolTable:new Nu});let{name:t}=this.declarationNode,n=L(t);if(n!==void 0){let r=n,i=r.pop(),a=od(r,this.publicSymbolTable,this.symbolFactory),o=su(i);a.has(o)&&e.push(new N(M.DUPLICATE_NAME,`Enum '${i}' already exists in schema '${r.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}return 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 T)return this.validateFields([e]);let[t,n]=b(e.body,e=>e instanceof T);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.length===0?[new N(M.EMPTY_ENUM,`An Enum must have at least one element`,this.declarationNode)]:e.flatMap(e=>{let t=[];e.callee&&!j(e.callee)&&t.push(new N(M.INVALID_ENUM_ELEMENT_NAME,`An enum field must be an identifier or a quoted identifier`,e.callee));let n=[...e.args];return y(n)instanceof D?(t.push(...this.validateFieldSettings(y(n))),n.pop()):n[0]instanceof D&&(t.push(...this.validateFieldSettings(n[0])),n.shift()),n.length>0&&t.push(...n.map(e=>new N(M.INVALID_ENUM_ELEMENT,`An Enum must have only a field and optionally a setting list`,e))),t.push(...this.registerField(e)),t})}validateFieldSettings(e){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`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=>{A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=cu(t),r=this.symbolFactory.create(Su,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate enum field ${t}`,r.declaration)]}i.set(n,r)}return[]}},Gu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=new N(M.INVALID_INDEXES_CONTEXT,`An Indexes can only appear inside a Table or a TablePartial`,this.declarationNode);if(this.declarationNode.parent instanceof Tl)return[e];let t=this.declarationNode.parent;return t instanceof w&&t.isKind(g.Table,g.TablePartial)?[]:[e]}validateName(e){return e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as an Indexes name`,e)]: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 T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`An Indexes must have a complex body`,e)];let[t,n]=b(e.body,e=>e instanceof T);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 y(n)instanceof D&&t.push(...this.validateFieldSetting(n.pop())),n.forEach(e=>{for(;e instanceof O;)e.argumentList&&gd(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;gd(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=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];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=>{A(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=>{j(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Ku=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=this.declarationNode.parent;return!(e instanceof Tl)&&!(e instanceof w&&e.isKind(g.Table,g.TableGroup,g.TablePartial,g.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){if(!(this.declarationNode.parent instanceof Tl))return e?[new N(M.UNEXPECTED_NAME,`A Note shouldn't have a name`,e)]:[];if(!e)return[new N(M.INVALID_NAME,`Sticky note must have a name`,this.declarationNode)];if(e instanceof Il)return[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Note name`,e)];let t=L(e);if(t===void 0)return[new N(M.INVALID_NAME,`Invalid name for sticky note `,this.declarationNode)];let n=t.join(`.`),r=du(n);return this.publicSymbolTable.has(r)?[new N(M.DUPLICATE_NAME,`Duplicate Note '${n}' in schema '${se}'`,e)]:(this.declarationNode.symbol=this.symbolFactory.create(Mu,{declaration:this.declarationNode}),this.publicSymbolTable.set(r,this.declarationNode.symbol),[])}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 Note shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof T)return this.validateFields([e]);let[t,n]=b(e.body,e=>e instanceof T);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))),A(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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},qu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_PROJECT_CONTEXT,`A Project can only appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Project name`,e)]:id(e)?[]:[new N(M.INVALID_NAME,`A Project's name is optional or must be an identifier or a quoted identifer`,e)]:[]}validateAlias(e){return e?[new N(M.UNEXPECTED_ALIAS,`A Project shouldn't have an alias`,e)]:[]}validateSettingList(e){return e?[new N(M.UNEXPECTED_SETTINGS,`A Project shouldn't have a setting list`,e)]:[]}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Project's body must be a block`,e)];let[t,n]=b(e.body,e=>e instanceof T);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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Ju=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){let e=this.declarationNode.parent;return e instanceof Tl||e instanceof w&&e.isKind(g.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 Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Records name`,e)]:this.declarationNode.parent instanceof Tl?this.validateTopLevelName(e):this.validateInsideTableName(e)}validateTopLevelName(e){if(!(e instanceof O))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)];let t=[];return(!e.callee||!nd(e.callee))&&t.push(new N(M.INVALID_RECORDS_NAME,`Records table reference must be a valid table name`,e.callee||e)),(!e.argumentList||!fd(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&&!fd(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 T)return this.validateDataRow(e);let[t,n]=b(e.body,e=>e instanceof T);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 Nl)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 zl||ud(e)||A(e)||e instanceof jl)return!0;if(j(e)){let t=e.expression.variable.value.toLowerCase();return ae.includes(t)}if($l(e)){let t=L(e);return t!==void 0&&t.length>0}return!1}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}},Yu=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof Tl?[]:[new N(M.INVALID_REF_CONTEXT,`A Ref must appear top-level`,this.declarationNode)]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Ref name`,e)]:id(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 T)return this.validateFields([e]);let[t,n]=b(e.body,e=>e instanceof T);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&&!yd(e.callee)&&t.push(new N(M.INVALID_REF_FIELD,`A Ref field must be a binary relationship`,e.callee)),e.callee&&yd(e.callee)){let n=hd(e.callee.leftExpression)??{variables:[],tupleElements:[]},r=n.variables.length+Math.min(n.tupleElements.length,1),i=hd(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&&!bd(e.callee)&&t.push(new N(M.UNEQUAL_FIELDS_BINARY_REF,`Unequal fields in ref endpoints`,e.callee));let n=[...e.args];if(y(n)instanceof D){let e=this.validateFieldSettings(y(n));t.push(...e),n.pop()}else n[0]instanceof D&&(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){let t=I(e),n=t.getErrors(),r=t.getValue();for(let e in r){let t=r[e];switch(e){case`delete`:case`update`:t.length>1&&t.forEach(t=>n.push(new N(M.DUPLICATE_REF_SETTING,`'${e}' can only appear once`,t))),t.forEach(t=>{Xu(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))});break;case`color`:t.length>1&&n.push(...t.map(e=>new N(M.DUPLICATE_REF_SETTING,`'color' can only appear once`,e))),t.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_REF_SETTING_VALUE,`'color' must be a color literal`,e))});break;default:t.forEach(t=>n.push(new N(M.UNKNOWN_REF_SETTING,`Unknown ref setting '${e}'`,t)))}}return n}validateSubElements(e){return e.flatMap(e=>(e.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[]))}};function Xu(e){if(!(j(e)&&e.expression.variable.kind!==x.QUOTED_STRING)&&!(e instanceof El))return!1;let t;if(t=e instanceof El?tu(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}var Zu=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLE_CONTEXT,`Table must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a Table name`,e)]:e instanceof Bl?[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)]:nd(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?rd(e)?[]:[new N(M.INVALID_ALIAS,`Table aliases can only contains alphanumeric and underscore unless surrounded by double quotes`,e)]:[]}validateSettingList(e){let t=I(e),n=t.getErrors();return Wc(t.getValue(),(e,t)=>{switch(t){case _.HeaderColor:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'headercolor' can only appear once`,e))),e.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'headercolor' must be a color literal`,e.value||e.name))});break;case _.Note:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.forEach(e=>{A(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}registerElement(){let e=[];this.declarationNode.symbol=this.symbolFactory.create(Cu,{declaration:this.declarationNode,symbolTable:new Nu});let{name:t,alias:n}=this.declarationNode,r=L(t);if(r!==void 0){let n=[...r],i=n.pop(),a=od(n,this.publicSymbolTable,this.symbolFactory),o=au(i);a.has(o)&&e.push(new N(M.DUPLICATE_NAME,`Table '${i}' already exists in schema '${n.join(`.`)||`public`}'`,t)),a.set(o,this.declarationNode.symbol)}if(n&&id(n)&&!Qu(n.expression.variable.value,r??[])){let r=z(n),i=au(r);this.publicSymbolTable.has(i)&&e.push(new N(M.DUPLICATE_NAME,`Table '${r}' already exists in schema '${se}'`,t)),this.publicSymbolTable.set(i,this.declarationNode.symbol)}return e}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A Table's body must be a block`,e)];let[t,n]=b(e.body,e=>e instanceof T);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)),j(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]&&!pd(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.push(...this.registerField(e)),t},n=e=>{let t=[];if(!e.callee)return[];if(!ad(e.callee))t.push(new N(M.INVALID_TABLE_PARTIAL_INJECTION,`A partial injection should be of the form ~<table-partial>`,e.callee));else{let t=R(e.callee.expression)??``,n=this.symbolFactory.create(Ou,{symbolTable:new Nu,declaration:e});e.symbol=n;let r=pu(t),i=this.declarationNode.symbol.symbolTable;if(i.has(r)){let n=i.get(r);return[new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,e),new N(M.DUPLICATE_TABLE_PARTIAL_INJECTION_NAME,`Duplicate table partial injection '${t}'`,n.declaration)]}i.set(r,n)}return 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 Ol&&e.callee.op?.value===`~`?n(e):t(e))}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=ou(t),r=this.symbolFactory.create(wu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}i.set(n,r)}return[]}validateFieldSetting(e){if(!e.slice(0,-1).every(Ql)||!e.slice(-1).every(e=>Ql(e)||e instanceof D))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;y(e)instanceof D&&(t=e.pop());let n=I(t),r=n.getErrors(),i=n.getValue();e.forEach(e=>{let t=(z(e)??``).toLowerCase();if(t!==`pk`&&t!==`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[_.PK]||[],o=i[_.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))),Wc(i,(e,t)=>{switch(t){case _.Note:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`note can only appear once`,e))),e.forEach(e=>{A(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'note' must be a quoted string`,e.value||e.name))});break;case _.Ref:e.forEach(e=>{dd(e.value)||r.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'ref' must be a valid unary relationship`,e.value||e.name))});break;case _.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 _.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 Dl&&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 _.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[_.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 _.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 _.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 Dl&&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 _.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 Dl&&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 _.Default:e.length>1&&r.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'default' can only appear once`,e))),e.forEach(e=>{ld(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 _.Check:e.forEach(e=>{e.value instanceof jl||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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(g.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function Qu(e,t){return t.length===1&&e===t[0]}var $u=class{constructor(e,t,n){this.declarationNode=e,this.publicSymbolTable=t,this.symbolFactory=n}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLEGROUP_CONTEXT,`TableGroup must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TableGroup name`,e)]:id(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)]:[]}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Tu,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t!==void 0){let n=[...t],r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=lu(r);if(i.has(a))return[new N(M.DUPLICATE_NAME,`TableGroup '${r}' already exists in schema '${n.join(`.`)||`public`}'`,e)];i.set(a,this.declarationNode.symbol)}return[]}validateSettingList(e){let t=I(e),n=t.getErrors();return Wc(t.getValue(),(e,t)=>{switch(t){case`color`:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'color' can only appear once`,e))),e.forEach(e=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_SETTING_VALUE,`'color' must be a color literal`,e.value||e.name))});break;case`note`:e.length>1&&n.push(...e.map(e=>new N(M.DUPLICATE_TABLE_SETTING,`'note' can only appear once`,e))),e.filter(e=>!A(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(...e.map(e=>new N(M.UNKNOWN_TABLE_SETTING,`Unknown '${t}' setting`,e)));break}}),n}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TableGroup's body must be a block`,e)];let[t,n]=b(e.body,e=>e instanceof T);return[...this.validateFields(t),...this.validateSubElements(n)]}validateFields(e){return e.flatMap(e=>{let t=[];return e.callee&&L(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)),this.registerField(e),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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(g.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}registerField(e){if(e.callee&&j(e.callee)){let t=z(e.callee),n=uu(t),r=this.symbolFactory.create(Eu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,e),new N(M.DUPLICATE_TABLEGROUP_FIELD_NAME,`${t} already exists in the group`,r.declaration)]}i.set(n,r)}return[]}},ed=class{constructor(e,t,n){this.declarationNode=e,this.symbolFactory=n,this.publicSymbolTable=t}validate(){return{errors:[...this.validateContext(),...this.validateName(this.declarationNode.name),...this.validateAlias(this.declarationNode.alias),...this.validateSettingList(this.declarationNode.attributeList),...this.registerElement(),...this.validateBody(this.declarationNode.body)],warnings:[]}}validateContext(){return this.declarationNode.parent instanceof w?[new N(M.INVALID_TABLE_PARTIAL_CONTEXT,`TablePartial must appear top-level`,this.declarationNode)]:[]}validateName(e){return e?e instanceof Il?[new N(M.INVALID_NAME,`Wildcard (*) is not allowed as a TablePartial name`,e)]:id(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=I(e),n=t.getErrors();return Wc(t.getValue(),(e,t)=>{switch(t){case _.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=>{cd(e.value)||n.push(new N(M.INVALID_TABLE_PARTIAL_SETTING_VALUE,`'${t}' must be a color literal`,e.value||e.name))});break;case _.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=>{A(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}registerElement(){let{name:e}=this.declarationNode;this.declarationNode.symbol=this.symbolFactory.create(Du,{declaration:this.declarationNode,symbolTable:new Nu});let t=L(e);if(t===void 0)return[];let n=[...t],r=n.pop(),i=od(n,this.publicSymbolTable,this.symbolFactory),a=fu(r);return i.has(a)?[new N(M.DUPLICATE_NAME,`TablePartial '${r}' already exists in schema '${n.join(`.`)||`public`}'`,e)]:(i.set(a,this.declarationNode.symbol),[])}validateBody(e){if(!e)return[];if(e instanceof T)return[new N(M.UNEXPECTED_SIMPLE_BODY,`A TablePartial's body must be a block`,e)];let[t,n]=b(e.body,e=>e instanceof T);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)),j(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]&&!pd(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),...this.registerField(e)),t})}registerField(e){if(!e.callee||!j(e.callee))return[];let t=z(e.callee),n=ou(t),r=this.symbolFactory.create(wu,{declaration:e});e.symbol=r;let i=this.declarationNode.symbol.symbolTable;if(i.has(n)){let r=i.get(n);return[new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,e),new N(M.DUPLICATE_COLUMN_NAME,`Duplicate column ${t}`,r.declaration)]}return i.set(n,r),[]}validateFieldSetting(e){let t=y(e);if(!e.slice(0,-1).every(Ql)||!(Ql(t)||t instanceof D))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;y(e)instanceof D&&(n=e.pop());let r=I(n),i=r.getErrors(),a=r.getValue();e.forEach(e=>{let t=(z(e)??``).toLowerCase();if(t!==_.PK&&t!==_.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[_.PK]||[],s=a[_.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))),Wc(a,(e,t)=>{switch(t){case _.Note:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{A(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a quoted string`,e.value||e.name))});break;case _.Ref:e.forEach(e=>{dd(e.value)||i.push(new N(M.INVALID_COLUMN_SETTING_VALUE,`'${t}' must be a valid unary relationship`,e.value||e.name))});break;case _.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 _.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 Dl&&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 _.NotNull:{e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e)));let n=a[_.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 _.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 _.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 Dl&&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 _.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 Dl&&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 _.Default:e.length>1&&i.push(...e.map(e=>new N(M.DUPLICATE_COLUMN_SETTING,`'${t}' can only appear once`,e))),e.forEach(e=>{ld(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 _.Check:e.forEach(e=>{e.value instanceof jl||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.parent=this.declarationNode,e.type?new(td(e))(e,this.publicSymbolTable,this.symbolFactory).validate().errors:[])),n=e.filter(e=>e.isKind(g.Note));return n.length>1&&t.push(...n.map(e=>new N(M.NOTE_REDEFINED,`Duplicate notes are defined`,e))),t}};function td(e){switch(Bu(g,e.type.value)){case g.Enum:return Wu;case g.Table:return Zu;case g.TableGroup:return $u;case g.Project:return qu;case g.Ref:return Yu;case g.Note:return Ku;case g.Indexes:return Gu;case g.TablePartial:return ed;case g.Check:return Vu;case g.Records:return Ju;case g.DiagramView:return Uu;default:return Hu}}function nd(e){let t=L(e);return t!==void 0&&t.length>0}function rd(e){return id(e)}function id(e){return e instanceof Rl&&e.expression instanceof Ll}function ad(e){return e instanceof Ol&&e.op?.value===`~`&&j(e.expression)}function od(e,t,n){e[0]===`public`&&(e=e.slice(1));let r=t;for(let t of e){let e,i=iu(t);if(r.has(i)){if(e=r.get(i)?.symbolTable,!e)throw Error(`Expect a symbol table in a schema symbol`)}else{e=new Nu;let a=n.create(bu,{symbolTable:e,name:t});r.set(i,a)}r=e}return r}function sd(e){return e===`-`||e===`<>`||e===`>`||e===`<`}function cd(e){if(!(e instanceof Rl)||!(e.expression instanceof Fl)||e.expression.literal?.kind!==x.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(!Ru(t[e]))return!1;return!0}function ld(e){if(A(e)||ud(e)||Ql(e)&&[`true`,`false`,`null`].includes(e.expression.variable.value.toLowerCase())||e instanceof Ol&&oe.includes(e.op?.value)&&ud(e.expression)||e instanceof jl)return!0;if(!e||!eu(e))return!1;let t=md(e);return t.length===2||t.length===3}function ud(e){return e instanceof Ol?oe.includes(e.op.value)?ud(e.expression):!1:e instanceof Rl&&e.expression instanceof Fl&&e.expression.literal?.kind===x.NUMERIC_LITERAL}function dd(e){if(!(e instanceof Ol)||!sd(e.op?.value))return!1;let t=L(e.expression);return t!==void 0&&t.length>0}function fd(e){return e instanceof Ml&&e.elementList.every(j)}function pd(e){if(!(e instanceof O||$l(e)||e instanceof Rl||e instanceof Bl))return!1;for(;e instanceof O||e instanceof Bl;)if(e instanceof O){if(e.callee===void 0||e.argumentList===void 0||!e.argumentList.elementList.every(e=>ud(e)||A(e)||Ql(e)))return!1;e=e.callee}else if(e instanceof Bl){if(e.array===void 0||e.indexer===void 0||!e.indexer.elementList.every(e=>!e.colon&&!e.value&&ud(e.name)))return!1;e=e.array}let t=L(e);return t!==void 0&&t.length>0}function I(e){let t={},n=[];return e?(e.elementList.forEach(e=>{if(!e.name)return;if(e.name instanceof Rl){n.push(new N(M.INVALID_SETTINGS,`A setting name must be a stream of identifiers`,e.name));return}let r=tu(e.name)?.toLowerCase();r&&(t[r]===void 0?t[r]=[e]:t[r].push(e))}),new P(t,n)):new P({})}function md(e){if(!e)return;if(!$l(e))return[e];let t=md(e.leftExpression);if(t)return t.push(e.rightExpression),t}function L(e){if(e===void 0)return;let t=md(e);if(!t)return;let n=[];for(let e of t){let t=R(e);if(typeof t!=`string`)return;n.push(t)}return n}function hd(e){if(e===void 0)return;let t=md(e);if(!t||t.length===0)return;let n=[];if(!j(y(t))){let e=t.pop();if(fd(e))n=e.elementList;else return}let r=t;if(r.every(j))return{variables:r,tupleElements:n}}function R(e){if(j(e))return e.expression.variable.value}function gd(e){if(xd(e))return e instanceof jl?{functional:[e],nonFunctional:[]}:{functional:[],nonFunctional:[e]};if(e instanceof Ml&&e.elementList.every(xd))return{functional:e.elementList.filter(e=>e instanceof jl),nonFunctional:e.elementList.filter(j)}}function z(e){let t=e?.expression.variable?.value;return t===void 0?void 0:t}function B(e){if(A(e))return e.expression instanceof Ll?e.expression.variable.value:e.expression.literal.value}function _d(e){return e instanceof Rl&&e.expression instanceof Fl&&e.expression.literal?.kind===x.NUMERIC_LITERAL?Number(e.expression.literal.value):null}function vd(e){if(e)return j(e)?e.referee:e instanceof kl&&e.op?.value===`.`?vd(e.rightExpression):e.referee}function yd(e){return!(e instanceof kl)||!sd(e.op?.value)?!1:hd(e.leftExpression)!==void 0&&hd(e.rightExpression)!==void 0}function bd(e){let t=hd(e.leftExpression),n=hd(e.rightExpression);if(t===void 0||n===void 0)return!1;let{tupleElements:r}=t,{tupleElements:i}=n;return r?.length===i?.length}function xd(e){return e instanceof Rl&&e.expression instanceof Ll||e instanceof jl}function Sd(e){if(!(e instanceof O)||!e.callee)return;let t=md(e.callee);if(!t||t.length===0||!t.every(j))return;let n=[];return fd(e.argumentList)&&(n=[...e.argumentList.elementList]),{variables:t,args:n}}var Cd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return[]}},wd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Td=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){let[,t]=b(e.body,e=>e instanceof T);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>{if(!e.type)return[];let t=e.type.value.toLowerCase();if(!(e.body instanceof E))return[];let n=[];switch(t){case`tables`:n.push(...this.bindTableReferences(e.body));break;case`notes`:n.push(...this.bindNoteReferences(e.body));break;case`tablegroups`:n.push(...this.bindTableGroupReferences(e.body));break;case`schemas`:n.push(...this.bindSchemaReferences(e.body));break;default:break}return n})}bindTableReferences(e){let[t]=b(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.Table}])}))}bindNoteReferences(e){let[t]=b(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>{let t=e.variables.pop();return t?Ld(this.ast,[{node:t,kind:F.StickyNote}]):[]}))}bindTableGroupReferences(e){let[t]=b(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.TableGroup}])}))}bindSchemaReferences(e){let[t]=b(e.body,e=>e instanceof T);return t.flatMap(e=>!e.callee||Zl(e.callee)?[]:Id(e.callee).flatMap(e=>Ld(this.ast,e.variables.map(e=>({node:e,kind:F.Schema})))))}},Ed=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Dd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof w)||!this.declarationNode.parent.isKind(g.Table)||!(this.declarationNode.body instanceof E)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=b(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>{if(!e.callee)return[];let t=(()=>{let e=L(this.declarationNode.parent.name);return e===void 0?`<unnamed>`:e.join(`.`)})(),n=this.declarationNode.parent.symbol.symbolTable;return[e.callee,...e.args].flatMap(Id).flatMap(e=>e.variables.length+e.tupleElements.length>1?[]:e.variables.length?e.variables[0]:e.tupleElements).flatMap(e=>{let r=z(e);if(r===void 0)return[];let i=ou(r),a=n.get(i);return a?(e.referee=a,a.references.push(e),[]):new N(M.BINDING_ERROR,`No column named '${r}' inside Table '${t}'`,e)})})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Od=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.bindBody(this.declarationNode.body)}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},kd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e||e instanceof T)return[];let t=e.body.filter(e=>e instanceof w);return this.bindSubElements(t)}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Ad=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n,this.boundColumns=new Map}bind(){let e=[];return this.declarationNode.name&&e.push(...this.bindRecordsName(this.declarationNode.name)),this.declarationNode.body instanceof E&&e.push(...this.bindBody(this.declarationNode.body)),e}bindRecordsName(e){return this.declarationNode.parent instanceof Tl?this.bindTopLevelName(e):this.bindInsideTableName(e)}bindTopLevelName(e){let t=Sd(e);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table}]);if(i.length>0)return i;let a=n.referee;if(!a?.symbolTable)return[];let o=nu(n.referee?.declaration)??`<invalid name>`,s=[];for(let e of t.args){let t=z(e)??`<unnamed>`,n=ou(t),r=a.symbolTable.get(n);if(!r){s.push(new N(M.BINDING_ERROR,`Column '${t}' does not exist in Table '${o}'`,e));continue}e.referee=r,r.references.push(e);let i=this.boundColumns.get(r);i&&(s.push(new N(M.DUPLICATE_COLUMN_REFERENCES_IN_RECORDS,`Column '${t}' is referenced more than once in a Records for Table '${o}'`,i)),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(r,e)}return s}bindInsideTableName(e){let t=this.declarationNode.parent;if(!(t instanceof w)||!t.isKind(g.Table))return[];let n=t.symbol?.symbolTable;if(!n||!fd(e))return[];let r=nu(t)??`<invalid name>`,i=[];for(let t of e.elementList){let e=z(t)??`<unnamed>`,a=ou(e),o=n.get(a);if(!o){i.push(new N(M.BINDING_ERROR,`Column '${e}' does not exist in Table '${r}'`,t));continue}t.referee=o,o.references.push(t)}return i}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindDataRow(e);let t=e.body.filter(e=>e instanceof T),n=e.body.filter(e=>e instanceof w);return[...this.bindDataRows(t),...this.bindSubElements(n)]}bindDataRows(e){return e.flatMap(e=>this.bindDataRow(e))}bindDataRow(e){return e.callee?(e.callee instanceof Nl?e.callee.elementList:[e.callee]).flatMap(Id).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];let r=e.variables;return Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum},{node:t,kind:F.EnumField}])}):[]}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},jd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return!(this.declarationNode.parent instanceof Tl)&&!this.declarationNode.parent?.isKind(g.Project)?[]:this.bindBody(this.declarationNode.body)}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=b(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.tupleElements.length?e.tupleElements:e.variables.pop(),n=e.variables.pop();if(!t||!n)return[];Array.isArray(t)||(t=[t]);let r=e.variables;return t.flatMap(e=>Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:e,kind:F.Column}]))}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Md=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}resolvePartialInjections(){let{body:e}=this.declarationNode;return(e?e instanceof E?e.body:[e]:[]).filter(e=>e instanceof T&&ad(e.callee)).reverse().flatMap(e=>{let t=hd(e.callee.expression);if(!t)return[];let n=t.variables.pop(),r=t.variables;if(!n)return[];let i=Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.TablePartial}]);return i.length?i:(n.referee?.symbolTable?.forEach(t=>{let r=R(t.declaration.callee);if(r===void 0)return;let i=this.symbolFactory.create(ku,{declaration:e,tablePartialSymbol:n.referee}),a=ou(r),o=this.declarationNode.symbol?.symbolTable;o?.has(a)||o?.set(a,i)}),[])})}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=b(e.body,e=>e instanceof T);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(y(n)instanceof D){let e=I(y(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=>!ad(e.callee)))}tryToBindColumnType(e){let t=hd(e);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}tryToBindEnumFieldRef(e){if(A(e))return[];if(j(e)){let t=e.expression.variable?.value?.toLowerCase();if(t&&ae.includes(t))return[]}let t=hd(e);if(!t)return[];let n=t.variables.pop(),r=t.variables.pop();if(!n||!r)return[];let i=t.variables;return Ld(this.ast,[...i.map(e=>({node:e,kind:F.Schema})),{node:r,kind:F.Enum},{node:n,kind:F.EnumField}])}bindInlineRef(e){return Id(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):Ld(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Nd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=b(e.body,e=>e instanceof T);return[...this.bindFields(t),...this.bindSubElements(n)]}bindFields(e){return e.flatMap(e=>e.callee?[e.callee,...e.args].flatMap(Id).flatMap(e=>{let t=e.variables.pop();if(!t)return[];let n=e.variables;return Ld(this.ast,[...n.map(e=>({node:e,kind:F.Schema})),{node:t,kind:F.Table}])}):[])}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}},Pd=class{constructor(e,t,n){this.declarationNode=e,this.ast=t,this.symbolFactory=n}bind(){return this.declarationNode.body instanceof E?this.bindBody(this.declarationNode.body):[]}bindBody(e){if(!e)return[];if(e instanceof T)return this.bindFields([e]);let[t,n]=b(e.body,e=>e instanceof T);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(y(n)instanceof D){let e=I(y(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=hd(e);if(!t)return;let n=t.variables.pop(),r=t.variables;n&&Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Enum}])}bindInlineRef(e){return Id(e).flatMap(e=>{let t=e.variables.pop(),n=e.variables.pop();if(!t)return[];let r=e.variables;return n?Ld(this.ast,[...r.map(e=>({node:e,kind:F.Schema})),{node:n,kind:F.Table},{node:t,kind:F.Column}]):Ld(this.declarationNode,[{node:t,kind:F.Column}])})}bindSubElements(e){return e.flatMap(e=>e.type?new(Fd(e))(e,this.ast,this.symbolFactory).bind():[])}};function Fd(e){switch(Bu(g,e.type.value)){case g.Enum:return Ed;case g.Table:return Md;case g.TableGroup:return Nd;case g.Project:return kd;case g.Ref:return jd;case g.Note:return Od;case g.Indexes:return Dd;case g.TablePartial:return Pd;case g.Check:return Cd;case g.Records:return Ad;case g.DiagramView:return Td;default:return wd}}function Id(e){if(!e)return[];if(j(e))return[{variables:[e],tupleElements:[]}];if(e instanceof kl){let t=hd(e);return t?[t]:[...Id(e.leftExpression),...Id(e.rightExpression)]}if(e instanceof Ol||e instanceof Al)return Id(e.expression);if(e instanceof Ml){let t=hd(e);return t?[t]:e.elementList.flatMap(Id)}return[]}function Ld(e,t){if(!e.symbol?.symbolTable)throw Error(`lookupAndBindInScope should only be called with initial scope having a symbol table`);let n=e.symbol.symbolTable,r=e.symbol.kind,i=e instanceof w?nu(e)??`<invalid name>`:se;if(e instanceof Tl&&t.length){let{node:e,kind:n}=t[0];(z(e)??`<unnamed>`)===`public`&&n===F.Schema&&t.shift()}for(let e of t){let{node:t,kind:a}=e,o=z(t)??`<unnamed>`,s=gu(o,a),c=n.get(s);if(!c)return[new N(M.BINDING_ERROR,`${a} '${o}' does not exist in ${i===void 0?`global scope`:`${r} '${i}'`}`,t)];if(t.referee=c,c.references.push(t),i=o,r=a,!c.symbolTable)return[];n=c.symbolTable}return[]}var Rd=class{constructor(e,t){this.ast=e,this.symbolFactory=t}resolvePartialInjections(){return this.ast.body.filter(e=>e.isKind(g.Table)).flatMap(e=>new Md(e,this.ast,this.symbolFactory).resolvePartialInjections())}resolve(){let e=[];e.push(...this.resolvePartialInjections());for(let t of this.ast.body)if(t.type){let n=new(Fd(t))(t,this.ast,this.symbolFactory);e.push(...n.bind())}return new P(this.ast,e)}},zd=class{constructor(e,t){this.ast=e,this.symbolFactory=t,this.publicSchemaSymbol=this.symbolFactory.create(bu,{symbolTable:new Nu,name:se}),this.ast.symbol=this.publicSchemaSymbol,this.ast.symbol.declaration=this.ast}validate(){let e=[],t=[];this.ast.body.forEach(n=>{if(n.parent=this.ast,n.type===void 0)return;let r=new(td(n))(n,this.publicSchemaSymbol.symbolTable,this.symbolFactory).validate();e.push(...r.errors),t.push(...r.warnings)});let n=this.ast.body.filter(e=>e.isKind(g.Project));return n.length>1&&n.forEach(t=>e.push(new N(M.PROJECT_REDEFINED,`Only one project can exist`,t))),new P(this.ast,e,t)}},Bd=class{constructor(e,t){this.ast=e,this.symbolFactory=new Fu(t)}analyze(){return new zd(this.ast,this.symbolFactory).validate().chain(e=>new Rd(e,this.symbolFactory).resolve())}validate(){return new zd(this.ast,this.symbolFactory).validate().chain(e=>new P(e,[]))}};function Vd(e){return e instanceof Ol?`${e.op?.value}${Vd(e.expression)}`:e.expression.literal.value}function Hd(e){return e instanceof Ol?e.op?.value===`-`?-Hd(e.expression):Hd(e.expression):Number.parseFloat(e.expression.literal.value)}function Ud(e,t){let{variables:n,tupleElements:r}=hd(e),i=r.map(e=>z(e)),a=n.map(e=>z(e));return r.length?n.length===0?{schemaName:t.schemaName,tableName:t.name,fieldNames:i}:{tableName:a.pop(),schemaName:a.pop()||null,fieldNames:i}:n.length===1?{schemaName:t.schemaName,tableName:t.name,fieldNames:[a[0]]}:{fieldNames:[a.pop()],tableName:a.pop(),schemaName:a.pop()||null}}function Wd(e){switch(e){case`<`:return[`1`,`*`];case`<>`:return[`*`,`*`];case`>`:return[`*`,`1`];case`-`:return[`1`,`1`];default:throw Error(`Invalid relation op`)}}function V(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 Gd(e){let t=md(e)?.pop();return t instanceof Ml?t.elementList.map(e=>e.referee):[t.referee]}function Kd(e){let t=L(e);return{name:t.pop(),schemaName:t}}function qd(e){return e.expression.literal.value}function Jd(e,t){if(Array.isArray(e)){let n=e.map(({id:e})=>e).sort().join(`,`),r=t.map(({id:e})=>e).sort().join(`,`);return n<r?`${n}-${r}`:`${r}-${n}`}let n=e.id.toString(),r=t.id.toString();return n<r?`${n}-${r}`:`${r}-${n}`}function Yd(e,t){return Array.isArray(e)?pl(e.map(({id:e})=>e).sort(),t.map(({id:e})=>e).sort()).every(([e,t])=>e===t):e.id===t.id}function Xd(e){let t=e.split(`
2
2
  `),n=t.slice(t.findIndex(e=>e.trimStart()!==``)),r=n.filter(e=>e.trimStart()),i=Math.min(...r.map(e=>e.length-e.trimStart().length));return n.map(e=>e.slice(i)).join(`
3
- `)}function Zd(e){if(e){if(A(e))return{value:B(e),type:`string`};if(ud(e))return{type:`number`,value:Hd(e)};if(Ql(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof jl&&e.value)return{value:e.value.value,type:`expression`};if(eu(e))return{value:R(v(md(e))),type:`string`};throw Error(`Unreachable`)}}function Qd(e,t){let n=``,r=null,i,a;if(e instanceof O){let t=e.argumentList.elementList;if(r=t.map(e=>ud(e)?Vd(e):A(e)?B(e):R(e)).join(`,`),n=`(${r})`,t.length===2&&ud(t[0])&&ud(t[1])){let e=Hd(t[0]),n=Hd(t[1]);!isNaN(e)&&!isNaN(n)&&(i={precision:Math.trunc(e),scale:Math.trunc(n)})}else if(t.length===1&&ud(t[0])){let e=Hd(t[0]);isNaN(e)||(a={length:Math.trunc(e)})}e=e.callee}for(;e instanceof O||e instanceof Bl;)e instanceof O?(n=`(${e.argumentList.elementList.map(e=>ud(e)?Vd(e):A(e)?B(e):R(e)).join(`,`)})${n}`,e=e.callee):e instanceof Bl&&(n=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${n}`,e=e.array);let{name:o,schemaName:s}=Kd(e),c=s.length===0?null:s[0],l=!![...t.enums.values()].find(e=>e.name===o&&e.schemaName===c);return s.length>1?new P({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l},[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):new P({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l})}function $d(e,t){let n=[...t.tables.entries()].find(([,t])=>t===e)?.[0];if(!n)throw Error(`mergeTableAndPartials should be called after all tables are interpreted`);if(!(n.body instanceof E))throw Error(`Table element should have a block body`);let r=[...e.indexes],i=[...e.checks],a=e.headerColor,o=e.note,s=[...t.tablePartials.values()];for(let t of[...e.partials].reverse()){let{name:e}=t,n=s.find(t=>t.name===e);n&&(r.push(...n.indexes),i.push(...n.checks),n.headerColor!==void 0&&(a=n.headerColor),n.note!==void 0&&(o=n.note))}let c=new Map(e.fields.map(e=>[e.name,e])),l=new Set(c.keys()),u=new Map(s.map(e=>[e.name,e])),d=[];for(let e of n.body.body)if(e instanceof T)if(ad(e.callee)){let t=R(e.callee.expression),n=u.get(t);if(!n)continue;for(let e of n.fields)l.has(e.name)||d.push(e)}else{let t=R(e.callee),n=c.get(t);if(!n)continue;d.push(n)}let f=ll([...d].reverse(),`name`).reverse();return{...e,fields:f,indexes:r,checks:i,headerColor:a,note:o}}function ef(e,t){let n=[],r=[...t.tablePartials.values()],i=new Set(e.fields.map(e=>e.name));for(let t of[...e.partials].reverse()){let{name:a}=t,o=r.find(e=>e.name===a);if(o){for(let t of o.fields)if(!i.has(t.name))for(let r of t.inline_refs){let i=Wd(r.relation);n.push({name:null,schemaName:null,token:r.token,endpoints:[{schemaName:r.schemaName,tableName:r.tableName,fieldNames:r.fieldNames,token:r.token,relation:i[1]},{schemaName:e.schemaName,tableName:e.name,fieldNames:[t.name],token:t.token,relation:i[0]}]})}}}return n}var tf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];return this.diagramView.token=V(this.declarationNode),this.env.diagramViews.set(this.declarationNode,this.diagramView),this.env.diagramViewWildcards.set(this.diagramView,new Set),this.env.diagramViewExplicitlySet.set(this.diagramView,new Set),this.declarationNode.name&&e.push(...this.interpretName(this.declarationNode.name)),this.declarationNode.body instanceof E&&e.push(...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=L(e)??[];return t.length>0&&(this.diagramView.name=t[t.length-1],t.length>1&&(this.diagramView.schemaName=t.slice(0,-1).join(`.`))),[]}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof T&&Zl(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.env.diagramViewWildcards.set(this.diagramView,new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`])),this.env.diagramViewExplicitlySet.set(this.diagramView,new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`])),[]}let[t]=y(e.body,e=>e instanceof w),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof E&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;(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=[]));let i=this.env.diagramViewExplicitlySet.get(this.diagramView);return n.has(`tables`)&&i.add(`tables`),n.has(`tablegroups`)&&i.add(`tableGroups`),n.has(`schemas`)&&i.add(`schemas`),n.has(`notes`)&&i.add(`stickyNotes`),[]}interpretSubBlock(e,t){if(!t)return;if(e.body.some(e=>e instanceof T&&Zl(e.callee))){let e=this.env.diagramViewWildcards.get(this.diagramView);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 T))continue;let e=vd(t.callee);if(e?.declaration instanceof w){let t=L(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],r=t.length>1?t.slice(0,-1).join(`.`):ce;n.push({name:e,schemaName:r});continue}}let r=L(t.callee)??[];if(r.length===0)continue;let i=r[r.length-1],a=r.length>1?r[0]:ce;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}}},nf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=V(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t,schemaName:n}=Kd(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.enum.name=t,this.enum.schemaName=n.length?n[0]:null,[])}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=V(t),n.name=R(t.callee);let r=I(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Xd(B(r.value)),token:V(r)},this.enum.values.push(n),[]})}},rf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof w?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=V(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let t=[],n=L(this.declarationNode.name)??[];return this.ref.name=n.pop()||null,n.length>1&&t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof T?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=Gd(n),a=Gd(r);if(Yd(i,a))return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Jd(i,a);if(this.env.refIds[o])return[new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=I(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof El?tu(n):R(n);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof El?tu(r):R(r),this.ref.color=t.color?.length?qd(t.color?.at(0)?.value):void 0}let s=Wd(t);return this.ref.endpoints=[{...Ud(n,this.container),relation:s[0],token:V(n)},{...Ud(r,this.container),relation:s[1],token:V(r)}],this.env.refIds[o]=this.declarationNode,[]}},af=class{constructor(e,t){this.declarationNode=e,this.env=t,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=V(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);let e=[...this.interpretName(this.declarationNode.name),...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})),e}interpretName(e){let{name:t,schemaName:n}=Kd(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=z(e)??null;return t&&(this.env.aliases.push({name:t,kind:`table`,value:{elementName:this.table.name,tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=I(e).getValue();this.table.headerColor=t[g.HeaderColor]?.length?qd(t[g.HeaderColor]?.at(0)?.value):void 0;let[n]=t[g.Note]||[];return this.table.note=n&&{value:Xd(B(n?.value)),token:V(n)},[]}interpretBody(e){let[t,n]=y(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case h.Note:return this.table.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)},[];case h.Indexes:return this.interpretIndexes(e);case h.Check:return this.interpretChecks(e);case h.Records:return this.env.recordsElements.push(e),[];default:return[]}})}interpretInjection(e,t){let n={order:t,token:V(e)};return n.name=R(e.expression)??``,this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>(_u(e)??null)?.kind===F.Column).length?[]:[new N(M.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>ad(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=z(e.callee);let r=Qd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=V(e),n.inline_refs=[];let i=e.args.slice(1);if(v(i)instanceof D){let r=I(i.pop()).getValue();n.pk=!!r[g.PK]?.length||!!r[g.PrimaryKey]?.length,n.increment=!!r[g.Increment]?.length,n.unique=!!r[g.Unique]?.length,n.not_null=r[g.NotNull]?.length?!0:r[g.Null]?.length?!1:void 0,n.dbdefault=Zd(r[g.Default]?.at(0)?.value);let a=r[g.Note]?.at(0);n.note=a&&{value:Xd(B(a.value)),token:V(a)},n.inline_refs=(r[g.Ref]||[]).flatMap(n=>{let[r]=Gd(n.value.expression);if(Yd(r,e.symbol))return t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=L(n.value.expression),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:V(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:V(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:V(n)}}else{t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:V(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[g.Check]||[]).map(e=>({token:V(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Bu(g,R(e))===g.PK),n.unique||=i.some(e=>Bu(g,R(e))===g.Unique),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.table.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=V(n);let r=[n.callee,...n.args];if(v(r)instanceof D){let e=I(r.pop()).getValue();t.pk=!!e[g.PK]?.length,t.unique=!!e[g.Unique]?.length,t.name=B(e[g.Name]?.at(0)?.value);let n=e[g.Note]?.at(0);t.note=n&&{value:B(n.value),token:V(n)},t.type=R(e[g.Type]?.at(0)?.value)}return r.flatMap(e=>{if(!(e instanceof O))return e;let t=[];for(;e instanceof O;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=gd(e);t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:V(e)})),...r.map(e=>({value:z(e),type:`column`,token:V(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=V(n),n.args[0]instanceof D&&(t.name=B(I(n.args[0]).getValue()[g.Name]?.at(0)?.value)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Jd(e.symbol,t);if(this.env.refIds[i])return[new N(M.CIRCULAR_REF,`References with same endpoints exist`,r),new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=Wd(n.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:n.token,endpoints:[{...n,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[R(e.callee)],token:V(e),relation:a[0]}]}),[]}},of=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=V(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=[],{name:n,schemaName:r}=Kd(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]=y(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=L(e.callee);n.length>2&&t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,e));let r=md(e.callee).pop().referee.id;if(this.env.tableOwnerGroup[r]){let i=this.env.tableOwnerGroup[r],{schemaName:a,name:o}=this.env.tableGroups.get(i),s=a?`${a}.${o}`:o;t.push(new N(M.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n.join(`.`)}" already appears in group "${s}"`,e))}else this.env.tableOwnerGroup[r]=this.declarationNode;return{name:n.pop(),schemaName:n.join(`.`)||null}}),t}interpretSettingList(e){let t=I(e).getValue();this.tableGroup.color=t.color?.length?qd(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Xd(B(n?.value)),token:V(n)},[]}},sf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=V(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);let e=[...this.interpretName(this.declarationNode.name),...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})),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})),e}interpretName(e){let{name:t}=Kd(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=I(e).getValue(),n=Lc(t[g.HeaderColor]);this.tablePartial.headerColor=n?qd(n.value):void 0;let[r]=t[g.Note]||[];return this.tablePartial.note=r&&{value:Xd(B(r?.value)),token:V(r)},[]}interpretBody(e){let[t,n]=y(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case h.Note:return this.tablePartial.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)},[];case h.Indexes:return this.interpretIndexes(e);case h.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=z(e.callee);let r=Qd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=V(e),n.inline_refs=[];let i=e.args.slice(1);if(v(i)instanceof D){let r=I(i.pop()).getValue();n.pk=!!r[g.PK]?.length||!!r[g.PrimaryKey]?.length,n.increment=!!r[g.Increment]?.length,n.unique=!!r[g.Unique]?.length,n.not_null=r[g.NotNull]?.length?!0:r[g.Null]?.length?!1:void 0,n.dbdefault=Zd(r[g.Default]?.at(0)?.value);let a=r[g.Note]?.at(0);n.note=a&&{value:Xd(B(a.value)),token:V(a)},n.inline_refs=(r[g.Ref]||[]).flatMap(n=>{let[r]=Gd(n.value.expression);if(Yd(r,e.symbol))return t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=L(n.value.expression),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:V(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:V(n)}}else{t.push(new N(M.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:V(n)}}return o}),n.checks=(r[g.Check]||[]).map(e=>({token:V(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Bu(g,R(e))===g.PK),n.unique||=i.some(e=>Bu(g,R(e))===g.Unique),this.tablePartial.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.tablePartial.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=V(n);let r=[n.callee,...n.args];if(v(r)instanceof D){let e=I(r.pop()).getValue();t.pk=!!e[g.PK]?.length,t.unique=!!e[g.Unique]?.length,t.name=B(e[g.Name]?.at(0)?.value);let n=e[g.Note]?.at(0);t.note=n&&{value:B(n.value),token:V(n)},t.type=R(e[g.Type]?.at(0)?.value)}return r.flatMap(e=>{if(!(e instanceof O))return e;let t=[],n=e;for(;n instanceof O;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=gd(e);t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:V(e)})),...r.map(e=>({value:z(e),type:`column`,token:V(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=V(n),n.args[0]instanceof D&&(t.name=B(I(n.args[0]).getValue()[g.Name]?.at(0)?.value)),t.expression=n.callee.value.value,t})),[]}},cf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=V(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Kd(e);return this.project.name=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case`table`:{let e=new af(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new rf(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new of(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new nf(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:Xd(B(t.body instanceof E?t.body.body[0].callee:t.body.callee)),token:V(t)},[];case`tablepartial`:{let e=new sf(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=B(t.body.callee),[]}})}},lf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=V(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t}=Kd(e);return this.note.name=t,[]}interpretSettingList(e){let t=I(e).getValue();return this.note.headerColor=t.headercolor?.length?qd(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=y(e.body,e=>e instanceof T);return t.length!==1||n.length>0?[new N(M.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=wa(e,`callee.expression.literal.value`,``);return this.note.content=Xd(t),[]}},uf={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`])},df={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`])},ff={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},pf={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`])},mf={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`])},hf={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`])},gf={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function _f(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function vf(e,t){let n=_f(e);return t?uf[t].has(n):Object.values(uf).some(e=>e.has(n))}function yf(e,t){let n=_f(e);return t?df[t].has(n):Object.values(df).some(e=>e.has(n))}function bf(e,t){return vf(e,t)||yf(e,t)}function xf(e,t){let n=_f(e);return t?ff[t].has(n):Object.values(ff).some(e=>e.has(n))}function Sf(e,t){let n=_f(e);return t?pf[t].has(n):Object.values(pf).some(e=>e.has(n))}function Cf(e,t){let n=_f(e);return t?mf[t].has(n):Object.values(mf).some(e=>e.has(n))}function wf(e,t){let n=_f(e);return t?hf[t].has(n):Object.values(hf).some(e=>e.has(n))}function Tf(e,t){let n=_f(e);return t?gf[t].has(n):Object.values(gf).some(e=>e.has(n))}function Ef(e){let t=e.declaration;return t instanceof T&&t.args[0]||null}function Df(e){let t=Ef(e);if(!(t instanceof O)||!t.argumentList||t.argumentList.elementList.length!==2)return{};let n=_d(t.argumentList.elementList[0]),r=_d(t.argumentList.elementList[1]);return n===null||r===null?{}:{precision:Math.trunc(n),scale:Math.trunc(r)}}function Of(e){let t=Ef(e);if(!(t instanceof O)||!t.argumentList||t.argumentList.elementList.length!==1)return{};let n=_d(t.argumentList.elementList[0]);return n===null?{}:{length:Math.trunc(n)}}function kf(e,t){if(t)return`string`;if(vf(e))return`integer`;if(yf(e))return`real`;if(xf(e))return`bool`;if(Sf(e))return`string`;let n=_f(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:wf(e)?`datetime`:e}var Af=class extends Error{},jf=class extends Af{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Mf=class extends Af{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Nf=class extends Af{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Pf=class extends Af{},Ff=class extends Af{constructor(e){super(`Invalid unit ${e}`)}},If=class extends Af{},Lf=class extends Af{constructor(){super(`Zone is an abstract class`)}},H=`numeric`,Rf=`short`,zf=`long`,Bf={year:H,month:H,day:H},Vf={year:H,month:Rf,day:H},Hf={year:H,month:Rf,day:H,weekday:Rf},Uf={year:H,month:zf,day:H},Wf={year:H,month:zf,day:H,weekday:zf},Gf={hour:H,minute:H},Kf={hour:H,minute:H,second:H},qf={hour:H,minute:H,second:H,timeZoneName:Rf},Jf={hour:H,minute:H,second:H,timeZoneName:zf},Yf={hour:H,minute:H,hourCycle:`h23`},Xf={hour:H,minute:H,second:H,hourCycle:`h23`},Zf={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:Rf},Qf={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:zf},$f={year:H,month:H,day:H,hour:H,minute:H},ep={year:H,month:H,day:H,hour:H,minute:H,second:H},tp={year:H,month:Rf,day:H,hour:H,minute:H},np={year:H,month:Rf,day:H,hour:H,minute:H,second:H},rp={year:H,month:Rf,day:H,weekday:Rf,hour:H,minute:H},ip={year:H,month:zf,day:H,hour:H,minute:H,timeZoneName:Rf},ap={year:H,month:zf,day:H,hour:H,minute:H,second:H,timeZoneName:Rf},op={year:H,month:zf,day:H,weekday:zf,hour:H,minute:H,timeZoneName:zf},sp={year:H,month:zf,day:H,weekday:zf,hour:H,minute:H,second:H,timeZoneName:zf},cp=class{get type(){throw new Lf}get name(){throw new Lf}get ianaName(){return this.name}get isUniversal(){throw new Lf}offsetName(e,t){throw new Lf}formatOffset(e,t){throw new Lf}offset(e){throw new Lf}equals(e){throw new Lf}get isValid(){throw new Lf}},lp=null,up=class e extends cp{static get instance(){return lp===null&&(lp=new e),lp}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},dp=new Map;function fp(e){let t=dp.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`}),dp.set(e,t)),t}var pp={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function mp(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 hp(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=pp[t];t===`era`?r[a]=i:G(a)||(r[a]=parseInt(i,10))}return r}var gp=new Map,_p=class e extends cp{static create(t){let n=gp.get(t);return n===void 0&&gp.set(t,n=new e(t)),n}static resetCache(){gp.clear(),dp.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 Jm(e,t,n,this.name)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=fp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?hp(n,t):mp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Wm({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}},vp={};function yp(e,t={}){let n=JSON.stringify([e,t]),r=vp[n];return r||(r=new Intl.ListFormat(e,t),vp[n]=r),r}var bp=new Map;function xp(e,t={}){let n=JSON.stringify([e,t]),r=bp.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),bp.set(n,r)),r}var Sp=new Map;function Cp(e,t={}){let n=JSON.stringify([e,t]),r=Sp.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Sp.set(n,r)),r}var wp=new Map;function Tp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=wp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),wp.set(i,a)),a}var Ep=null;function Dp(){return Ep||(Ep=new Intl.DateTimeFormat().resolvedOptions().locale,Ep)}var Op=new Map;function kp(e){let t=Op.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Op.set(e,t)),t}var Ap=new Map;function jp(e){let t=Ap.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Vp,...t}),Ap.set(e,t)}return t}function Mp(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=xp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=xp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Np(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Pp(e){let t=[];for(let n=1;n<=12;n++){let r=J.utc(2009,n,1);t.push(e(r))}return t}function Fp(e){let t=[];for(let n=1;n<=7;n++){let r=J.utc(2016,11,13+n);t.push(e(r))}return t}function Ip(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Lp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||kp(e.locale).numberingSystem===`latn`}var Rp=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=Cp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return K(this.floor?Math.floor(e):Bm(e,3),this.padTo)}},zp=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&&_p.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=xp(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()}},Bp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Om()&&(this.rtf=Tp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):_h(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Vp={firstDay:1,minimalDays:4,weekend:[6,7]},U=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||W.defaultLocale;return new e(o||(a?`en-US`:Dp()),n||W.defaultNumberingSystem,r||W.defaultOutputCalendar,Pm(i)||W.defaultWeekSettings,o)}static resetCache(){Ep=null,bp.clear(),Sp.clear(),wp.clear(),Op.clear(),Ap.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]=Mp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Np(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??=Lp(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,Pm(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 Ip(this,e,rh,()=>{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]=Pp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Ip(this,e,sh,()=>{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]=Fp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Ip(this,void 0,()=>ch,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[J.utc(2016,11,13,9),J.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Ip(this,e,fh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[J.utc(-40,1,1),J.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 Rp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new zp(e,this.intl,t)}relFormatter(e={}){return new Bp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return yp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||kp(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:km()?jp(this.locale):Vp}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})`}},Hp=null,Up=class e extends cp{static get utcInstance(){return Hp===null&&(Hp=new e(0)),Hp}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(Ym(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Qm(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Qm(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Qm(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}},Wp=class extends cp{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 Gp(e,t){if(G(e)||e===null)return t;if(e instanceof cp)return e;if(Em(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?up.instance:n===`utc`||n===`gmt`?Up.utcInstance:Up.parseSpecifier(n)||_p.create(e)}else if(wm(e))return Up.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Wp(e)}var Kp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},qp={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]},Jp=Kp.hanidec.replace(/[\[|\]]/g,``).split(``);function Yp(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(Kp.hanidec)!==-1)t+=Jp.indexOf(e[n]);else for(let e in qp){let[n,i]=qp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Xp=new Map;function Zp(){Xp.clear()}function Qp({numberingSystem:e},t=``){let n=e||`latn`,r=Xp.get(n);r===void 0&&(r=new Map,Xp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Kp[n]}${t}`),r.set(t,i)),i}var $p=()=>Date.now(),em=`system`,tm=null,nm=null,rm=null,im=60,am,om=null,W=class{static get now(){return $p}static set now(e){$p=e}static set defaultZone(e){em=e}static get defaultZone(){return Gp(em,up.instance)}static get defaultLocale(){return tm}static set defaultLocale(e){tm=e}static get defaultNumberingSystem(){return nm}static set defaultNumberingSystem(e){nm=e}static get defaultOutputCalendar(){return rm}static set defaultOutputCalendar(e){rm=e}static get defaultWeekSettings(){return om}static set defaultWeekSettings(e){om=Pm(e)}static get twoDigitCutoffYear(){return im}static set twoDigitCutoffYear(e){im=e%100}static get throwOnInvalid(){return am}static set throwOnInvalid(e){am=e}static resetCaches(){U.resetCache(),_p.resetCache(),J.resetCache(),Zp()}},sm=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},cm=[0,31,59,90,120,151,181,212,243,273,304,334],lm=[0,31,60,91,121,152,182,213,244,274,305,335];function um(e,t){return new sm(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function dm(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 fm(e,t,n){return n+(Vm(e)?lm:cm)[t-1]}function pm(e,t){let n=Vm(e)?lm:cm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function mm(e,t){return(e-t+7)%7+1}function hm(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=fm(r,i,a),s=mm(dm(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Km(l,t,n)):c>Km(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...$m(e)}}function gm(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=mm(dm(r,1,t),n),s=Hm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Hm(l)):c>s?(l=r+1,c-=Hm(r)):l=r;let{month:u,day:d}=pm(l,c);return{year:l,month:u,day:d,...$m(e)}}function _m(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:fm(t,n,r),...$m(e)}}function vm(e){let{year:t,ordinal:n}=e,{month:r,day:i}=pm(t,n);return{year:t,month:r,day:i,...$m(e)}}function ym(e,t){if(!G(e.localWeekday)||!G(e.localWeekNumber)||!G(e.localWeekYear)){if(!G(e.weekday)||!G(e.weekNumber)||!G(e.weekYear))throw new Pf(`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 bm(e,t=4,n=1){let r=Tm(e.weekYear),i=Fm(e.weekNumber,1,Km(e.weekYear,t,n)),a=Fm(e.weekday,1,7);return r?i?a?!1:um(`weekday`,e.weekday):um(`week`,e.weekNumber):um(`weekYear`,e.weekYear)}function xm(e){let t=Tm(e.year),n=Fm(e.ordinal,1,Hm(e.year));return t?n?!1:um(`ordinal`,e.ordinal):um(`year`,e.year)}function Sm(e){let t=Tm(e.year),n=Fm(e.month,1,12),r=Fm(e.day,1,Um(e.year,e.month));return t?n?r?!1:um(`day`,e.day):um(`month`,e.month):um(`year`,e.year)}function Cm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Fm(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Fm(n,0,59),s=Fm(r,0,59),c=Fm(i,0,999);return a?o?s?c?!1:um(`millisecond`,i):um(`second`,r):um(`minute`,n):um(`hour`,t)}function G(e){return e===void 0}function wm(e){return typeof e==`number`}function Tm(e){return typeof e==`number`&&e%1==0}function Em(e){return typeof e==`string`}function Dm(e){return Object.prototype.toString.call(e)===`[object Date]`}function Om(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function km(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Am(e){return Array.isArray(e)?e:[e]}function jm(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 Mm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Nm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Pm(e){if(e==null)return null;if(typeof e!=`object`)throw new If(`Week settings must be an object`);if(!Fm(e.firstDay,1,7)||!Fm(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Fm(e,1,7)))throw new If(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Fm(e,t,n){return Tm(e)&&e>=t&&e<=n}function Im(e,t){return e-t*Math.floor(e/t)}function K(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Lm(e){if(!(G(e)||e===null||e===``))return parseInt(e,10)}function Rm(e){if(!(G(e)||e===null||e===``))return parseFloat(e)}function zm(e){if(!(G(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Bm(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 Vm(e){return e%4==0&&(e%100!=0||e%400==0)}function Hm(e){return Vm(e)?366:365}function Um(e,t){let n=Im(t-1,12)+1,r=e+(t-n)/12;return n===2?Vm(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Wm(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 Gm(e,t,n){return-mm(dm(e,1,t),n)+t-1}function Km(e,t=4,n=1){let r=Gm(e,t,n),i=Gm(e+1,t,n);return(Hm(e)-r+i)/7}function qm(e){return e>99?e:e>W.twoDigitCutoffYear?1900+e:2e3+e}function Jm(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 Ym(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 Xm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new If(`Invalid unit value ${e}`);return t}function Zm(e,t){let n={};for(let r in e)if(Nm(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Xm(i)}return n}function Qm(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}${K(n,2)}:${K(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${K(n,2)}${K(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function $m(e){return Mm(e,[`hour`,`minute`,`second`,`millisecond`])}var eh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],th=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],nh=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function rh(e){switch(e){case`narrow`:return[...nh];case`short`:return[...th];case`long`:return[...eh];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 ih=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],ah=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oh=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function sh(e){switch(e){case`narrow`:return[...oh];case`short`:return[...ah];case`long`:return[...ih];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ch=[`AM`,`PM`],lh=[`Before Christ`,`Anno Domini`],uh=[`BC`,`AD`],dh=[`B`,`A`];function fh(e){switch(e){case`narrow`:return[...dh];case`short`:return[...uh];case`long`:return[...lh];default:return null}}function ph(e){return ch[e.hour<12?0:1]}function mh(e,t){return sh(t)[e.weekday-1]}function hh(e,t){return rh(t)[e.month-1]}function gh(e,t){return fh(t)[e.year<0?0:1]}function _h(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 vh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var yh={D:Bf,DD:Vf,DDD:Uf,DDDD:Wf,t:Gf,tt:Kf,ttt:qf,tttt:Jf,T:Yf,TT:Xf,TTT:Zf,TTTT:Qf,f:$f,ff:tp,fff:ip,ffff:op,F:ep,FF:np,FFF:ap,FFFF:sp},bh=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 yh[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 K(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?ph(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?hh(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?mh(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?gh(t,e):a({era:e},`era`);return vh(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 vh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},xh=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Sh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Ch(...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 wh(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 Th(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Lm(t[n+i]);return[r,null,n+i]}}var Eh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Dh=`(?:${Eh.source}?(?:\\[(${xh.source})\\])?)?`,Oh=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,kh=RegExp(`${Oh.source}${Dh}`),Ah=RegExp(`(?:[Tt]${kh.source})?`),jh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Mh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Nh=/(\d{4})-?(\d{3})/,Ph=Th(`weekYear`,`weekNumber`,`weekDay`),Fh=Th(`year`,`ordinal`),Ih=/(\d{4})-(\d\d)-(\d\d)/,Lh=RegExp(`${Oh.source} ?(?:${Eh.source}|(${xh.source}))?`),Rh=RegExp(`(?: ${Lh.source})?`);function zh(e,t,n){let r=e[t];return G(r)?n:Lm(r)}function Bh(e,t){return[{year:zh(e,t),month:zh(e,t+1,1),day:zh(e,t+2,1)},null,t+3]}function Vh(e,t){return[{hours:zh(e,t,0),minutes:zh(e,t+1,0),seconds:zh(e,t+2,0),milliseconds:zm(e[t+3])},null,t+4]}function Hh(e,t){let n=!e[t]&&!e[t+1],r=Ym(e[t+1],e[t+2]);return[{},n?null:Up.instance(r),t+3]}function Uh(e,t){return[{},e[t]?_p.create(e[t]):null,t+1]}var Wh=RegExp(`^T?${Oh.source}$`),Gh=/^-?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 Kh(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(Rm(n)),months:f(Rm(r)),weeks:f(Rm(i)),days:f(Rm(a)),hours:f(Rm(o)),minutes:f(Rm(s)),seconds:f(Rm(c),c===`-0`),milliseconds:f(zm(l),d)}]}var qh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Jh(e,t,n,r,i,a,o){let s={year:t.length===2?qm(Lm(t)):Lm(t),month:th.indexOf(n)+1,day:Lm(r),hour:Lm(i),minute:Lm(a)};return o&&(s.second=Lm(o)),e&&(s.weekday=e.length>3?ih.indexOf(e)+1:ah.indexOf(e)+1),s}var Yh=/^(?:(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 Xh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Jh(t,i,r,n,a,o,s),p;return p=c?qh[c]:l?0:Ym(u,d),[f,new Up(p)]}function Zh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Qh=/^(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$/,$h=/^(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$/,eg=/^(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 tg(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,i,r,n,a,o,s),Up.utcInstance]}function ng(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,s,n,r,i,a,o),Up.utcInstance]}var rg=Sh(jh,Ah),ig=Sh(Mh,Ah),ag=Sh(Nh,Ah),og=Sh(kh),sg=Ch(Bh,Vh,Hh,Uh),cg=Ch(Ph,Vh,Hh,Uh),lg=Ch(Fh,Vh,Hh,Uh),ug=Ch(Vh,Hh,Uh);function dg(e){return wh(e,[rg,sg],[ig,cg],[ag,lg],[og,ug])}function fg(e){return wh(Zh(e),[Yh,Xh])}function pg(e){return wh(e,[Qh,tg],[$h,tg],[eg,ng])}function mg(e){return wh(e,[Gh,Kh])}var hg=Ch(Vh);function gg(e){return wh(e,[Wh,hg])}var _g=Sh(Ih,Rh),vg=Sh(Lh),yg=Ch(Vh,Hh,Uh);function bg(e){return wh(e,[_g,sg],[vg,yg])}var xg=`Invalid Duration`,Sg={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}},Cg={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},...Sg},wg=146097/400,Tg=146097/4800,Eg={years:{quarters:4,months:12,weeks:wg/7,days:wg,hours:wg*24,minutes:wg*24*60,seconds:wg*24*60*60,milliseconds:wg*24*60*60*1e3},quarters:{months:3,weeks:wg/28,days:wg/4,hours:wg*24/4,minutes:wg*24*60/4,seconds:wg*24*60*60/4,milliseconds:wg*24*60*60*1e3/4},months:{weeks:Tg/7,days:Tg,hours:Tg*24,minutes:Tg*24*60,seconds:Tg*24*60*60,milliseconds:Tg*24*60*60*1e3},...Sg},Dg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Og=Dg.slice(0).reverse();function kg(e,t,n=!1){return new Ng({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 Ag(e,t){let n=t.milliseconds??0;for(let r of Og.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function jg(e,t){let n=Ag(e,t)<0?-1:1;Dg.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),Dg.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 Mg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Ng=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Eg:Cg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||U.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 If(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Zm(t,e.normalizeUnit),loc:U.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(wm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new If(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=mg(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]=gg(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 If(`need to specify a reason the Duration is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new Nf(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 Ff(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?bh.create(this.loc,n).formatDurationFromString(this,e):xg}toHuman(e={}){if(!this.isValid)return xg;let t=e.showZeros!==!1,n=Dg.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+=Bm(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},J.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?Ag(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 Dg)(Nm(n.values,e)||Nm(this.values,e))&&(r[e]=n.get(e)+this.get(e));return kg(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]=Xm(e(this.values[n],n));return kg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Zm(t,e.normalizeUnit)};return kg(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 kg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return jg(this.matrix,e),kg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Mg(this.normalize().shiftToAll().toObject());return kg(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 Dg)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;wm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else wm(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 jg(this.matrix,n),kg(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 kg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Mg(this.values);return kg(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 Dg)if(!t(this.values[n],e.values[n]))return!1;return!0}},Pg=`Invalid Interval`;function Fg(e,t){return!e||!e.isValid?Ig.invalid(`missing or invalid start`):!t||!t.isValid?Ig.invalid(`missing or invalid end`):t<e?Ig.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 Ig=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 If(`need to specify a reason the Interval is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new Mf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=R_(t),i=R_(n);return Fg(r,i)??new e({start:r,end:i})}static after(t,n){let r=Ng.fromDurationLike(n),i=R_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Ng.fromDurationLike(n),i=R_(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=J.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=J.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Ng.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Ng.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(R_).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=Ng.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()})`:Pg}[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=Bf,t={}){return this.isValid?bh.create(this.s.loc.clone(t),e).formatInterval(this):Pg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Pg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Pg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Pg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Pg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Ng.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Lg=class{static hasDST(e=W.defaultZone){let t=J.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return _p.isValidZone(e)}static normalizeZone(e){return Gp(e,W.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return U.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return U.create(t,null,`gregory`).eras(e)}static features(){return{relative:Om(),localeWeek:km()}}};function Rg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Ng.fromMillis(r).as(`days`))}function zg(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=Rg(e,t);return(n-n%7)/7}],[`days`,Rg]],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 Bg(e,t,n,r){let[i,a,o,s]=zg(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=Ng.fromObject(a,r);return l.length>0?Ng.fromMillis(c,r).shiftTo(...l).plus(u):u}var Vg=`missing Intl.DateTimeFormat.formatToParts support`;function q(e,t=e=>e){return{regex:e,deser:([e])=>t(Yp(e))}}var Hg=`[ \xA0]`,Ug=new RegExp(Hg,`g`);function Wg(e){return e.replace(/\./g,`\\.?`).replace(Ug,Hg)}function Gg(e){return e.replace(/\./g,``).replace(Ug,` `).toLowerCase()}function Kg(e,t){return e===null?null:{regex:RegExp(e.map(Wg).join(`|`)),deser:([n])=>e.findIndex(e=>Gg(n)===Gg(e))+t}}function qg(e,t){return{regex:e,deser:([,e,t])=>Ym(e,t),groups:t}}function Jg(e){return{regex:e,deser:([e])=>e}}function Yg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Xg(e,t){let n=Qp(t),r=Qp(t,`{2}`),i=Qp(t,`{3}`),a=Qp(t,`{4}`),o=Qp(t,`{6}`),s=Qp(t,`{1,2}`),c=Qp(t,`{1,3}`),l=Qp(t,`{1,6}`),u=Qp(t,`{1,9}`),d=Qp(t,`{2,4}`),f=Qp(t,`{4,6}`),p=e=>({regex:RegExp(Yg(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Kg(t.eras(`short`),0);case`GG`:return Kg(t.eras(`long`),0);case`y`:return q(l);case`yy`:return q(d,qm);case`yyyy`:return q(a);case`yyyyy`:return q(f);case`yyyyyy`:return q(o);case`M`:return q(s);case`MM`:return q(r);case`MMM`:return Kg(t.months(`short`,!0),1);case`MMMM`:return Kg(t.months(`long`,!0),1);case`L`:return q(s);case`LL`:return q(r);case`LLL`:return Kg(t.months(`short`,!1),1);case`LLLL`:return Kg(t.months(`long`,!1),1);case`d`:return q(s);case`dd`:return q(r);case`o`:return q(c);case`ooo`:return q(i);case`HH`:return q(r);case`H`:return q(s);case`hh`:return q(r);case`h`:return q(s);case`mm`:return q(r);case`m`:return q(s);case`q`:return q(s);case`qq`:return q(r);case`s`:return q(s);case`ss`:return q(r);case`S`:return q(c);case`SSS`:return q(i);case`u`:return Jg(u);case`uu`:return Jg(s);case`uuu`:return q(n);case`a`:return Kg(t.meridiems(),0);case`kkkk`:return q(a);case`kk`:return q(d,qm);case`W`:return q(s);case`WW`:return q(r);case`E`:case`c`:return q(n);case`EEE`:return Kg(t.weekdays(`short`,!1),1);case`EEEE`:return Kg(t.weekdays(`long`,!1),1);case`ccc`:return Kg(t.weekdays(`short`,!0),1);case`cccc`:return Kg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return qg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return qg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Jg(/[a-z_+-/]{1,256}?/i);case` `:return Jg(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Vg};return m.token=e,m}var Zg={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 Qg(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=Zg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function $g(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function e_(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Nm(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 t_(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=_p.create(e.z)),G(e.Z)||(n||=new Up(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=zm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var n_=null;function r_(){return n_||=J.fromMillis(1555555555555),n_}function i_(e,t){if(e.literal)return e;let n=l_(bh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function a_(e,t){return Array.prototype.concat(...e.map(e=>i_(e,t)))}var o_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=a_(bh.parseFormat(t),e),this.units=this.tokens.map(t=>Xg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=$g(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=e_(e,this.regex,this.handlers),[r,i,a]=n?t_(n):[null,null,void 0];if(Nm(n,`a`)&&Nm(n,`H`))throw new Pf(`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 s_(e,t,n){return new o_(e,n).explainFromTokens(t)}function c_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=s_(e,t,n);return[r,i,a,o]}function l_(e,t){if(!e)return null;let n=bh.create(t,e).dtFormatter(r_()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Qg(t,e,i))}var u_=`Invalid DateTime`,d_=864e13;function f_(e){return new sm(`unsupported zone`,`the zone "${e.name}" is not supported`)}function p_(e){return e.weekData===null&&(e.weekData=hm(e.c)),e.weekData}function m_(e){return e.localWeekData===null&&(e.localWeekData=hm(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function h_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new J({...n,...t,old:n})}function g_(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 __(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 v_(e,t,n){return g_(Wm(e),t,n)}function y_(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,Um(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Ng.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]=g_(Wm(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function b_(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=J.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return J.invalid(new sm(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function x_(e,t,n=!0){return e.isValid?bh.create(U.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function S_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=K(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=K(e.c.month),n===`month`)return i;i+=`-`}else if(i+=K(e.c.month),n===`month`)return i;return i+=K(e.c.day),i}function C_(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+=K(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=K(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=K(e.c.second))}else{if(c+=K(e.c.minute),o===`minute`)break;s&&(c+=K(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=K(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=K(Math.trunc(-e.o/60)),c+=`:`,c+=K(Math.trunc(-e.o%60))):(c+=`+`,c+=K(Math.trunc(e.o/60)),c+=`:`,c+=K(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var w_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},T_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},E_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},D_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],O_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],k_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function A_(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 Ff(e);return t}function j_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return A_(e)}}function M_(e){if(I_===void 0&&(I_=W.now()),e.type!==`iana`)return e.offset(I_);let t=e.name,n=L_.get(t);return n===void 0&&(n=e.offset(I_),L_.set(t,n)),n}function N_(e,t){let n=Gp(t.zone,W.defaultZone);if(!n.isValid)return J.invalid(f_(n));let r=U.fromObject(t),i,a;if(G(e.year))i=W.now();else{for(let t of D_)G(e[t])&&(e[t]=w_[t]);let t=Sm(e)||Cm(e);if(t)return J.invalid(t);let r=M_(n);[i,a]=v_(e,r,n)}return new J({ts:i,zone:n,loc:r,o:a})}function P_(e,t,n){let r=G(n.round)?!0:n.round,i=G(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Bm(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 F_(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 I_,L_=new Map,J=class e{constructor(e){let t=e.zone||W.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new sm(`invalid input`):null)||(t.isValid?null:f_(t));this.ts=G(e.ts)?W.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=wm(e.o)&&!e.old?e.o:t.offset(this.ts);r=__(this.ts,a),n=Number.isNaN(r.year)?new sm(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||U.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]=F_(arguments),[n,r,i,a,o,s,c]=t;return N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Up.utcInstance,N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Dm(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Gp(n.zone,W.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:U.fromObject(n)}):e.invalid(f_(i))}static fromMillis(t,n={}){if(wm(t))return t<-d_||t>d_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Gp(n.zone,W.defaultZone),loc:U.fromObject(n)});throw new If(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(wm(t))return new e({ts:t*1e3,zone:Gp(n.zone,W.defaultZone),loc:U.fromObject(n)});throw new If(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Gp(n.zone,W.defaultZone);if(!r.isValid)return e.invalid(f_(r));let i=U.fromObject(n),a=Zm(t,j_),{minDaysInFirstWeek:o,startOfWeek:s}=ym(a,i),c=W.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 Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Pf(`Can't mix ordinal dates with month/day`);let ee=m||a.weekday&&!p,te,ne,re=__(c,l);ee?(te=O_,ne=T_,re=hm(re,o,s)):u?(te=k_,ne=E_,re=_m(re)):(te=D_,ne=w_);let ie=!1;for(let e of te){let t=a[e];G(t)?ie?a[e]=ne[e]:a[e]=re[e]:ie=!0}let ae=(ee?bm(a,o,s):u?xm(a):Sm(a))||Cm(a);if(ae)return e.invalid(ae);let[oe,se]=v_(ee?gm(a,o,s):u?vm(a):a,l,r),ce=new e({ts:oe,zone:r,o:se,loc:i});return a.weekday&&p&&t.weekday!==ce.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${ce.toISO()}`):ce.isValid?ce:e.invalid(ce.invalid)}static fromISO(e,t={}){let[n,r]=dg(e);return b_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=fg(e);return b_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=pg(e);return b_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=c_(U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):b_(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]=bg(e);return b_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new If(`need to specify a reason the DateTime is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new jf(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=l_(e,U.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return a_(bh.parseFormat(e),U.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){I_=void 0,L_.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?p_(this).weekYear:NaN}get weekNumber(){return this.isValid?p_(this).weekNumber:NaN}get weekday(){return this.isValid?p_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?m_(this).weekday:NaN}get localWeekNumber(){return this.isValid?m_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?m_(this).weekYear:NaN}get ordinal(){return this.isValid?_m(this.c).ordinal:NaN}get monthShort(){return this.isValid?Lg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Lg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Lg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Lg.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=Wm(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=__(s,a),u=__(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[h_(this,{ts:s}),h_(this,{ts:c})]:[this]}get isInLeapYear(){return Vm(this.year)}get daysInMonth(){return Um(this.year,this.month)}get daysInYear(){return this.isValid?Hm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Km(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Km(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=bh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Up.instance(e),t)}toLocal(){return this.setZone(W.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Gp(t,W.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]=v_(r,n,t)}return h_(this,{ts:e,zone:t})}else return e.invalid(f_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return h_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Zm(e,j_),{minDaysInFirstWeek:n,startOfWeek:r}=ym(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 Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Pf(`Can't mix ordinal dates with month/day`);let u;i?u=gm({...hm(this.c,n,r),...t},n,r):G(t.ordinal)?(u={...this.toObject(),...t},G(t.day)&&(u.day=Math.min(Um(u.year,u.month),u.day))):u=vm({..._m(this.c),...t});let[d,f]=v_(u,this.o,this.zone);return h_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e);return h_(this,y_(this,t))}minus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e).negate();return h_(this,y_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Ng.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?bh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):u_}toLocaleString(e=Bf,t={}){return this.isValid?bh.create(this.loc.clone(t),e).formatDateTime(this):u_}toLocaleParts(e={}){return this.isValid?bh.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_(a);let o=e===`extended`,s=S_(this,o,a);return D_.indexOf(a)>=3&&(s+=`T`),s+=C_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?S_(this,e===`extended`,A_(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=A_(o),(r&&D_.indexOf(o)>=3?`T`:``)+C_(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?S_(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():u_}[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 Ng.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Am(t).map(Ng.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Bg(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?Ig.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),P_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?P_(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 If(`min requires all arguments be DateTimes`);return jm(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new If(`max requires all arguments be DateTimes`);return jm(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return s_(U.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 o_(U.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new If(`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):b_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Bf}static get DATE_MED(){return Vf}static get DATE_MED_WITH_WEEKDAY(){return Hf}static get DATE_FULL(){return Uf}static get DATE_HUGE(){return Wf}static get TIME_SIMPLE(){return Gf}static get TIME_WITH_SECONDS(){return Kf}static get TIME_WITH_SHORT_OFFSET(){return qf}static get TIME_WITH_LONG_OFFSET(){return Jf}static get TIME_24_SIMPLE(){return Yf}static get TIME_24_WITH_SECONDS(){return Xf}static get TIME_24_WITH_SHORT_OFFSET(){return Zf}static get TIME_24_WITH_LONG_OFFSET(){return Qf}static get DATETIME_SHORT(){return $f}static get DATETIME_SHORT_WITH_SECONDS(){return ep}static get DATETIME_MED(){return tp}static get DATETIME_MED_WITH_SECONDS(){return np}static get DATETIME_MED_WITH_WEEKDAY(){return rp}static get DATETIME_FULL(){return ip}static get DATETIME_FULL_WITH_SECONDS(){return ap}static get DATETIME_HUGE(){return op}static get DATETIME_HUGE_WITH_SECONDS(){return sp}};function R_(e){if(J.isDateTime(e))return e;if(e&&e.valueOf&&wm(e.valueOf()))return J.fromJSDate(e);if(e&&typeof e==`object`)return J.fromObject(e);throw new If(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function z_(e){return Ql(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof zl}function B_(e){return B(e)===``}function V_(e){return e instanceof jl}function H_(e){let t=_d(e);if(t!==null)return t;if(ud(e)&&e instanceof Ol&&e.expression){let t=e.op?.value,n=_d(e.expression);if(n!==null)return t===`-`?-n:n}return null}function U_(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=H_(e);if(t!==null)return t;let n=B(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function W_(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=H_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=B(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const G_=[`true`,`yes`,`y`,`t`,`1`],K_=[`false`,`no`,`n`,`f`,`0`];function q_(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 G_.includes(t)?!0:K_.includes(t)?!1:null}if(Ql(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=_d(e);if(t===0)return!1;if(t===1)return!0;let n=B(e)?.toLowerCase();if(n){if(G_.includes(n))return!0;if(K_.includes(n))return!1}return null}function J_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=L(e);return t?v(t):B(e)??null}function Y_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=B(e)??null??U_(e)??q_(e);return t===null?null:t.toString()}var X_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Z_=[`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`],Q_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function $_(e){if(e==null)return null;let t=typeof e==`string`?e:B(e)??null;if(t===null)return null;for(let e of Q_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of X_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Z_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=J.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 ev(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 tv(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 nv(e){return e.increment||Tf(e.type.type_name)}function rv(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function iv(e,t,n){return n.length===1?rv(e,t,n[0]):`(${n.map(n=>rv(e,t,n)).join(`, `)})`}function av(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function ov(e,t,n){let r=t.map(t=>e.columnNodes[t]).filter(Boolean);return r.length>0?r.map(e=>new N(M.INVALID_RECORDS_FIELD,n,e)):[new N(M.INVALID_RECORDS_FIELD,n,e.node)]}var sv=e=>e>1?`Composite PK`:`PK`;function cv(e){return Uc(Array.from(e.records),([t,{rows:n}])=>{if($c(n))return[];e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,$d(t,e));let r=e.cachedMergedTables.get(t),i=fv(r),a=pv(n),o=tl(r.fields,`name`);return Uc(i,e=>lv(e,n,a,o,r))})}function lv(e,t,n,r,i){let a=mv(e,n,r,i,t);if(!$c(a))return a;let o=Oo(e.map(e=>r[e])),s=o.every(e=>e&&nv(e)),[c,l]=y(t,t=>tv(t.values,e,o)),u=s?[]:uv(c,e,i),d=dv(l,e,o,i);return[...u,...d]}function uv(e,t,n){if($c(e))return[];let r=`NULL in ${sv(t.length)}: ${iv(n.schemaName,n.name,t)} cannot be NULL`;return Uc(e,e=>ov(e,t,r))}function dv(e,t,n,r){return Uc(jc(Jc(e,e=>ev(e.values,t,n)),e=>e.length>1),e=>{let n=sv(t.length),i=iv(r.schemaName,r.name,t);return Uc(e.slice(1),e=>ov(e,t,`Duplicate ${n}: ${i} = ${av(e.values,t)}`))})}function fv(e){return[...e.fields.filter(e=>e.pk).map(e=>[e.name]),...e.indexes.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value))]}function pv(e){return new Set(e.flatMap(e=>Object.keys(e.values)))}function mv(e,t,n,r,i){let a=wc(e,Array.from(t));if($c(a))return[];let o=a.filter(e=>{let t=n[e];return t&&!t.increment&&!Tf(t.type.type_name)&&!t.dbdefault});if($c(o))return[];let s=`${sv(o.length)}: Column ${iv(r.schemaName,r.name,o)} is missing from record and has no default value`;return i.map(e=>new N(M.INVALID_RECORDS_FIELD,s,e.node))}var hv=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function gv(e){return Uc(Array.from(e.records),([t,{rows:n}])=>{e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,$d(t,e));let r=e.cachedMergedTables.get(t);if($c(n))return[];let i=_v(r),a=tl(r.fields,`name`);return Uc(i,e=>vv(n,e,Oo(e.map(e=>a[e])),r))})}function _v(e){return[...e.fields.filter(e=>e.unique).map(e=>[e.name]),...e.indexes.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value))]}function vv(e,t,n,r){return Uc(jc(Jc(e.filter(e=>!tv(e.values,t,n)),e=>ev(e.values,t,n)),e=>e.length>1),e=>{let n=hv(t.length),i=iv(r.schemaName,r.name,t);return Uc(e.slice(1),e=>ov(e,t,`Duplicate ${n}: ${i} = ${av(e.values,t)}`))})}function yv(e){let t=[...e.ref.values(),...Uc(Array.from(e.tables.values()),t=>ef(t,e))],n=bv(e);return Uc(t,e=>Cv(e,n))}function bv(e){let t=new Map;for(let n of e.tables.values()){let r=xv(n.schemaName,n.name),i=e.records.get(n)?.rows||[];e.cachedMergedTables.has(n)||e.cachedMergedTables.set(n,$d(n,e));let a=e.cachedMergedTables.get(n);t.set(r,{mergedTable:a,rows:i})}return t}function xv(e,t){return e?`${e}.${t}`:`${ce}.${t}`}function Sv(e,t,n,r){if($c(e.rows))return[];let i=new Set(t.rows.map(e=>ev(e.values,r.fieldNames)));return Uc(e.rows.filter(e=>!tv(e.values,n.fieldNames)).filter(e=>{let t=ev(e.values,n.fieldNames);return!i.has(t)}),i=>{let a=iv(e.mergedTable.schemaName,e.mergedTable.name,n.fieldNames),o=iv(t.mergedTable.schemaName,t.mergedTable.name,r.fieldNames),s=`FK violation: ${a} = ${av(i.values,n.fieldNames)} does not exist in ${o}`;return ov(i,n.fieldNames,s)})}function Cv(e,t){if(!e.endpoints)return[];let[n,r]=e.endpoints,i=t.get(xv(n.schemaName,n.tableName)),a=t.get(xv(r.schemaName,r.tableName));return!i||!a?[]:wv(i,a,n,r)}function wv(e,t,n,r){let i=n.relation,a=r.relation;return i===`1`&&a===`1`||i===`*`&&a===`*`?[...Sv(e,t,n,r),...Sv(t,e,r,n)]:i===`*`&&a===`1`?Sv(e,t,n,r):i===`1`&&a===`*`?Sv(t,e,r,n):[]}var Tv=class{constructor(e){this.env=e,this.tableToRecordMap=new Map}interpret(e){let t=[],n=[];for(let r of e){let{table:e,mergedColumns:i}=Ev(r,this.env),a=this.tableToRecordMap.get(e);if(a){t.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,a)),t.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,r));continue}this.tableToRecordMap.set(e,r),this.env.records.has(e)||this.env.records.set(e,{element:r,rows:[]});let o=this.env.records.get(e);for(let e of r.body.body){let r=e,a=Dv(r,i,this.env);t.push(...a.getErrors()),n.push(...a.getWarnings());let s=a.getValue();s.row&&o.rows.push({values:s.row,node:r,columnNodes:s.columnNodes})}}let r=this.validateConstraints();return n.push(...r),new P(void 0,t,n)}validateConstraints(){let e=[];return e.push(...cv(this.env).map(e=>e.toWarning())),e.push(...gv(this.env).map(e=>e.toWarning())),e.push(...yv(this.env).map(e=>e.toWarning())),e}};function Ev(e,t){let n=e.name,r=e.parent;if(r instanceof w){let e=t.tables.get(r),i=$d(e,t);return n?{table:e,mergedTable:i,mergedColumns:n.elementList.map(e=>i.fields.find(t=>t.name===R(e)))}:{table:e,mergedTable:i,mergedColumns:i.fields}}let i=Sd(n),a=v(i.variables).referee.declaration,o=t.tables.get(a),s=$d(o,t);return{table:o,mergedTable:s,mergedColumns:i.args.map(e=>s.fields.find(t=>t.name===R(e)))}}function Dv(e,t,n){let r=[],i=[],a={},o={},s=e.callee instanceof Nl?e.callee.elementList:[e.callee];if(s.length!==t.length)return r.push(new N(M.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new P({row:null,columnNodes:{}},r,i);for(let e=0;e<t.length;e++){let c=s[e],l=t[e];o[l.name]=c;let u=kv(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();d!==null&&(a[l.name]=d)}return new P({row:a,columnNodes:o},r,i)}function Ov(e,t){return e instanceof jl?e.value?.value||``:!isNaN(e.start)&&!isNaN(e.end)?t.slice(e.start,e.end):``}function kv(e,t,n){let r=t.type.type_name.split(`(`)[0],{increment:i,not_null:a,dbdefault:o}=t,s=t.type.isEnum||!1,c=kf(r,s),l=Y_(e),u=l===null?Ov(e,n.source):l,d=l===null?`expression`:c;if(e instanceof jl)return new P({value:e.value?.value||``,type:`expression`},[],[]);if(z_(e)||B_(e)&&!Sf(r)){let n=o&&o.value.toString().toLowerCase()!==`null`,s=Tf(r);return a&&!n&&!i&&!s?new P({value:null,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${t.name}' without default and increment`,e)]):new P({value:null,type:c},[],[])}if(s){let r=([...n.enums.values()].find(e=>e.schemaName===t.type.schemaName&&e.name===t.type.type_name)?.values||[]).map(e=>e.name),i=B(e);return i===void 0&&(i=(L(e)??[]).pop()),r.includes(i)?new P({value:i,type:c},[],[]):new P({value:i,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid enum value for column '${t.name}'`,e)])}if(bf(r)){let n=U_(e);if(n===null)return new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${t.name}'`,e)]);if(vf(r)&&!Number.isInteger(n))return new P({value:Math.floor(n),type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid integer value ${n} for column '${t.name}': expected integer, got decimal`,e)]);if(yf(r)&&t.type.numericParams){let{precision:r,scale:i}=t.type.numericParams,a=n.toString().split(`.`),o=a[0].replace(/^-/,``),s=a[1]||``,l=o.length+s.length,u=s.length;if(l>r)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds precision: expected at most ${r} total digits, got ${l}`,e)]);if(u>i)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds scale: expected at most ${i} decimal digits, got ${u}`,e)])}return new P({value:n,type:c},[],[])}if(xf(r)){let n=q_(e);return n===null?new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${t.name}'`,e)]):new P({value:n,type:c},[],[])}if(wf(r)){let n=$_(e);return n===null?new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${t.name}', 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 P({value:n,type:c},[],[])}if(Sf(r)){let n=Y_(e);if(n===null)return new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid string value for column '${t.name}'`,e)]);if(t.type.lengthParam){let{length:r}=t.type.lengthParam,i=new TextEncoder().encode(n).length;if(i>r)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`String value for column '${t.name}' exceeds maximum length: expected at most ${r} bytes (UTF-8), got ${i} bytes`,e)])}return new P({value:n,type:`string`},[],[])}return new P({value:u,type:d},[],[])}function Av(e){return{...e,fields:e.fields.map(e=>({...e,type:{...e.type,isEnum:void 0,lengthParam:void 0,numericParams:void 0}}))}}function jv(e){for(let t of e.diagramViews.values()){let n=t.visibleEntities,r=e.diagramViewWildcards.get(t),i=e.diagramViewExplicitlySet.get(t);!r||!i||r.has(`tableGroups`)&&n.tableGroups&&n.tableGroups.length===0&&(i.has(`tables`)||i.has(`schemas`)||(n.tableGroups=Array.from(e.tableGroups.values()).map(e=>({name:e.name}))))}}function Mv(e,t){let n=[];for(let[t,{element:r,rows:i}]of e.records){if(!i.length)continue;let e=Object.keys(i[0].columnNodes);n.push({schemaName:t.schemaName||void 0,tableName:t.name,columns:e,token:V(r),values:i.map(t=>e.map(e=>{let n=t.values[e];return n?{value:n.value,type:n.type}:{value:null,type:`expression`}}))})}return{schemas:[],tables:Array.from(e.tables.values()).map(Av),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values()).map(Av),records:n,diagramViews:Array.from(e.diagramViews.values()),token:V(t)}}var Nv=class{constructor(e){this.ast=e,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableOwnerGroup:{},tableGroups:new Map,aliases:[],project:new Map,tablePartials:new Map,records:new Map,recordsElements:[],cachedMergedTables:new Map,source:e.source,diagramViews:new Map,diagramViewWildcards:new Map,diagramViewExplicitlySet:new Map}}interpret(){let e=this.ast.body.flatMap(e=>{switch(Bu(h,e.type?.value??``)){case h.Table:return new af(e,this.env).interpret();case h.Note:return new lf(e,this.env).interpret();case h.Ref:return new rf(e,this.env).interpret();case h.TableGroup:return new of(e,this.env).interpret();case h.TablePartial:return new sf(e,this.env).interpret();case h.Enum:return new nf(e,this.env).interpret();case h.Project:return new cf(e,this.env).interpret();case h.DiagramView:return new tf(e,this.env).interpret();case h.Records:return this.env.recordsElements.push(e),[];default:return[]}}),t=[];if(this.env.recordsElements.length){let n=new Tv(this.env).interpret(this.env.recordsElements);e.push(...n.getErrors()),t.push(...n.getWarnings())}return jv(this.env),new P(Mv(this.env,this.ast),e,t)}},Pv=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===`
4
- `?(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 vl.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(vl.create(b.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new P(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(b.SPACE);break;case`\r`:break;case`
5
- `:this.addToken(b.NEWLINE);break;case` `:this.addToken(b.TAB);break;case`,`:this.addToken(b.COMMA);break;case`(`:this.addToken(b.LPAREN);break;case`)`:this.addToken(b.RPAREN);break;case`[`:this.addToken(b.LBRACKET);break;case`]`:this.addToken(b.RBRACKET);break;case`{`:this.addToken(b.LBRACE);break;case`}`:this.addToken(b.RBRACE);break;case`;`:this.addToken(b.SEMICOLON);break;case`:`:this.addToken(b.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(b.WILDCARD);break;default:if(gl(e)){this.operator(e);break}if(Iu(e)){this.identifier();break}if(Lu(e)){this.numericLiteralOrIdentifier();break}this.addToken(b.OP,!0),this.errors.push(new N(M.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(b.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)hl(i)?(t.push(i),i.kind===b.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&&ql(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];ql(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(`
3
+ `)}function Zd(e){if(e){if(A(e))return{value:B(e),type:`string`};if(ud(e))return{type:`number`,value:Hd(e)};if(Ql(e))return{value:e.expression.variable.value.toLowerCase(),type:`boolean`};if(e instanceof jl&&e.value)return{value:e.value.value,type:`expression`};if(eu(e))return{value:R(y(md(e))),type:`string`};throw Error(`Unreachable`)}}function Qd(e,t){let n=``,r=null,i,a;if(e instanceof O){let t=e.argumentList.elementList;if(r=t.map(e=>ud(e)?Vd(e):A(e)?B(e):R(e)).join(`,`),n=`(${r})`,t.length===2&&ud(t[0])&&ud(t[1])){let e=Hd(t[0]),n=Hd(t[1]);!isNaN(e)&&!isNaN(n)&&(i={precision:Math.trunc(e),scale:Math.trunc(n)})}else if(t.length===1&&ud(t[0])){let e=Hd(t[0]);isNaN(e)||(a={length:Math.trunc(e)})}e=e.callee}for(;e instanceof O||e instanceof Bl;)e instanceof O?(n=`(${e.argumentList.elementList.map(e=>ud(e)?Vd(e):A(e)?B(e):R(e)).join(`,`)})${n}`,e=e.callee):e instanceof Bl&&(n=`${`[${e.indexer.elementList.map(e=>e.name.expression.literal.value).join(`,`)}]`}${n}`,e=e.array);let{name:o,schemaName:s}=Kd(e),c=s.length===0?null:s[0],l=!![...t.enums.values()].find(e=>e.name===o&&e.schemaName===c);return s.length>1?new P({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l},[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):new P({schemaName:s.length===0?null:s[0],type_name:`${o}${n}`,args:r,numericParams:i,lengthParam:a,isEnum:l})}function $d(e,t){let n=[...t.tables.entries()].find(([,t])=>t===e)?.[0];if(!n)throw Error(`mergeTableAndPartials should be called after all tables are interpreted`);if(!(n.body instanceof E))throw Error(`Table element should have a block body`);let r=[...e.indexes],i=[...e.checks],a=e.headerColor,o=e.note,s=[...t.tablePartials.values()];for(let t of[...e.partials].reverse()){let{name:e}=t,n=s.find(t=>t.name===e);n&&(r.push(...n.indexes),i.push(...n.checks),n.headerColor!==void 0&&(a=n.headerColor),n.note!==void 0&&(o=n.note))}let c=new Map(e.fields.map(e=>[e.name,e])),l=new Set(c.keys()),u=new Map(s.map(e=>[e.name,e])),d=[];for(let e of n.body.body)if(e instanceof T)if(ad(e.callee)){let t=R(e.callee.expression),n=u.get(t);if(!n)continue;for(let e of n.fields)l.has(e.name)||d.push(e)}else{let t=R(e.callee),n=c.get(t);if(!n)continue;d.push(n)}let f=cl([...d].reverse(),`name`).reverse();return{...e,fields:f,indexes:r,checks:i,headerColor:a,note:o}}function ef(e,t){let n=[],r=[...t.tablePartials.values()],i=new Set(e.fields.map(e=>e.name));for(let t of[...e.partials].reverse()){let{name:a}=t,o=r.find(e=>e.name===a);if(o){for(let t of o.fields)if(!i.has(t.name))for(let r of t.inline_refs){let i=Wd(r.relation);n.push({name:null,schemaName:null,token:r.token,endpoints:[{schemaName:r.schemaName,tableName:r.tableName,fieldNames:r.fieldNames,token:r.token,relation:i[1]},{schemaName:e.schemaName,tableName:e.name,fieldNames:[t.name],token:t.token,relation:i[0]}]})}}}return n}var tf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.diagramView={visibleEntities:{tables:null,stickyNotes:null,tableGroups:null,schemas:null}}}interpret(){let e=[];return this.diagramView.token=V(this.declarationNode),this.env.diagramViews.set(this.declarationNode,this.diagramView),this.env.diagramViewWildcards.set(this.diagramView,new Set),this.env.diagramViewExplicitlySet.set(this.diagramView,new Set),this.declarationNode.name&&e.push(...this.interpretName(this.declarationNode.name)),this.declarationNode.body instanceof E&&e.push(...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=L(e)??[];return t.length>0&&(this.diagramView.name=t[t.length-1],t.length>1&&(this.diagramView.schemaName=t.slice(0,-1).join(`.`))),[]}interpretBody(e){if(e.body.length===1){let t=e.body[0];if(t instanceof T&&Zl(t.callee))return this.diagramView.visibleEntities={tables:[],stickyNotes:[],tableGroups:[],schemas:[]},this.env.diagramViewWildcards.set(this.diagramView,new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`])),this.env.diagramViewExplicitlySet.set(this.diagramView,new Set([`tables`,`stickyNotes`,`tableGroups`,`schemas`])),[]}let[t]=b(e.body,e=>e instanceof w),n=new Set;for(let e of t){let t=e.type?.value.toLowerCase();t&&n.add(t),e.body instanceof E&&this.interpretSubBlock(e.body,t)}let r=this.diagramView.visibleEntities;(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=[]));let i=this.env.diagramViewExplicitlySet.get(this.diagramView);return n.has(`tables`)&&i.add(`tables`),n.has(`tablegroups`)&&i.add(`tableGroups`),n.has(`schemas`)&&i.add(`schemas`),n.has(`notes`)&&i.add(`stickyNotes`),[]}interpretSubBlock(e,t){if(!t)return;if(e.body.some(e=>e instanceof T&&Zl(e.callee))){let e=this.env.diagramViewWildcards.get(this.diagramView);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 T))continue;let e=vd(t.callee);if(e?.declaration instanceof w){let t=L(e.declaration.name)??[];if(t.length>0){let e=t[t.length-1],r=t.length>1?t.slice(0,-1).join(`.`):se;n.push({name:e,schemaName:r});continue}}let r=L(t.callee)??[];if(r.length===0)continue;let i=r[r.length-1],a=r.length>1?r[0]:se;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}}},nf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.enum={values:[]}}interpret(){return this.enum.token=V(this.declarationNode),this.env.enums.set(this.declarationNode,this.enum),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t,schemaName:n}=Kd(e);return n.length>1?(this.enum.name=t,this.enum.schemaName=n.join(`.`),[new N(M.UNSUPPORTED,`Nested schema is not supported`,e)]):(this.enum.name=t,this.enum.schemaName=n.length?n[0]:null,[])}interpretBody(e){return e.body.flatMap(e=>{let t=e,n={};n.token=V(t),n.name=R(t.callee);let r=I(t.args[0]).getValue().note?.at(0);return n.note=r&&{value:Xd(B(r.value)),token:V(r)},this.enum.values.push(n),[]})}},rf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.container=this.declarationNode.parent instanceof w?this.env.tables.get(this.declarationNode.parent):void 0,this.ref={}}interpret(){return this.ref.token=V(this.declarationNode),this.env.ref.set(this.declarationNode,this.ref),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let t=[],n=L(this.declarationNode.name)??[];return this.ref.name=n.pop()||null,n.length>1&&t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,this.declarationNode.name)),this.ref.schemaName=n.join(`.`)||null,t}interpretBody(e){return e instanceof T?this.interpretField(e):this.interpretField(e.body[0])}interpretField(e){let t=e.callee.op.value,{leftExpression:n,rightExpression:r}=e.callee,i=Gd(n),a=Gd(r);if(Yd(i,a))return[new N(M.SAME_ENDPOINT,`Two endpoints are the same`,e)];let o=Jd(i,a);if(this.env.refIds[o])return[new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.declarationNode),new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[o])];if(e.args[0]){let t=I(e.args[0]).getValue(),n=t.delete?.at(0)?.value;this.ref.onDelete=n instanceof El?tu(n):R(n);let r=t.update?.at(0)?.value;this.ref.onUpdate=r instanceof El?tu(r):R(r),this.ref.color=t.color?.length?qd(t.color?.at(0)?.value):void 0}let s=Wd(t);return this.ref.endpoints=[{...Ud(n,this.container),relation:s[0],token:V(n)},{...Ud(r,this.container),relation:s[1],token:V(r)}],this.env.refIds[o]=this.declarationNode,[]}},af=class{constructor(e,t){this.declarationNode=e,this.env=t,this.table={name:void 0,schemaName:void 0,alias:null,fields:[],token:void 0,indexes:[],partials:[],checks:[]},this.pkColumns=[]}interpret(){this.table.token=V(this.declarationNode),this.env.tables.set(this.declarationNode,this.table);let e=[...this.interpretName(this.declarationNode.name),...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})),e}interpretName(e){let{name:t,schemaName:n}=Kd(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=z(e)??null;return t&&(this.env.aliases.push({name:t,kind:`table`,value:{elementName:this.table.name,tableName:this.table.name,schemaName:this.table.schemaName}}),this.table.alias=t),[]}interpretSettingList(e){let t=I(e).getValue();this.table.headerColor=t[_.HeaderColor]?.length?qd(t[_.HeaderColor]?.at(0)?.value):void 0;let[n]=t[_.Note]||[];return this.table.note=n&&{value:Xd(B(n?.value)),token:V(n)},[]}interpretBody(e){let[t,n]=b(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case g.Note:return this.table.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)},[];case g.Indexes:return this.interpretIndexes(e);case g.Check:return this.interpretChecks(e);case g.Records:return this.env.recordsElements.push(e),[];default:return[]}})}interpretInjection(e,t){let n={order:t,token:V(e)};return n.name=R(e.expression)??``,this.table.partials.push(n),[]}interpretFields(e){let t=(this.declarationNode.symbol?.symbolTable?[...this.declarationNode.symbol.symbolTable.entries()]:[]).filter(([e])=>(_u(e)??null)?.kind===F.Column).length?[]:[new N(M.EMPTY_TABLE,`A Table must have at least one column`,this.declarationNode)],n=e.flatMap((e,t)=>ad(e.callee)?this.interpretInjection(e.callee,t):this.interpretColumn(e));return[...t,...n]}interpretColumn(e){let t=[],n={};n.name=z(e.callee);let r=Qd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=V(e),n.inline_refs=[];let i=e.args.slice(1);if(y(i)instanceof D){let r=I(i.pop()).getValue();n.pk=!!r[_.PK]?.length||!!r[_.PrimaryKey]?.length,n.increment=!!r[_.Increment]?.length,n.unique=!!r[_.Unique]?.length,n.not_null=r[_.NotNull]?.length?!0:r[_.Null]?.length?!1:void 0,n.dbdefault=Zd(r[_.Default]?.at(0)?.value);let a=r[_.Note]?.at(0);n.note=a&&{value:Xd(B(a.value)),token:V(a)},n.inline_refs=(r[_.Ref]||[]).flatMap(n=>{let[r]=Gd(n.value.expression);if(Yd(r,e.symbol))return t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=L(n.value.expression),o;if(a.length===1){let[e]=a;o={schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[e],relation:i.value,token:V(n)}}else if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:V(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:V(n)}}else{t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:V(n)}}let s=this.registerInlineRefToEnv(e,r,o,n);return t.push(...s),s.length===0?o:[]}),n.checks=(r[_.Check]||[]).map(e=>({token:V(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Bu(_,R(e))===_.PK),n.unique||=i.some(e=>Bu(_,R(e))===_.Unique),this.table.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.table.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=V(n);let r=[n.callee,...n.args];if(y(r)instanceof D){let e=I(r.pop()).getValue();t.pk=!!e[_.PK]?.length,t.unique=!!e[_.Unique]?.length,t.name=B(e[_.Name]?.at(0)?.value);let n=e[_.Note]?.at(0);t.note=n&&{value:B(n.value),token:V(n)},t.type=R(e[_.Type]?.at(0)?.value)}return r.flatMap(e=>{if(!(e instanceof O))return e;let t=[];for(;e instanceof O;)t.push(e.argumentList),e=e.callee;return t.push(e),t}).forEach(e=>{let{functional:n,nonFunctional:r}=gd(e);t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:V(e)})),...r.map(e=>({value:z(e),type:`column`,token:V(e)})))}),t})),[]}interpretChecks(e){return this.table.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=V(n),n.args[0]instanceof D&&(t.name=B(I(n.args[0]).getValue()[_.Name]?.at(0)?.value)),t.expression=n.callee.value.value,t})),[]}registerInlineRefToEnv(e,t,n,r){let i=Jd(e.symbol,t);if(this.env.refIds[i])return[new N(M.CIRCULAR_REF,`References with same endpoints exist`,r),new N(M.CIRCULAR_REF,`References with same endpoints exist`,this.env.refIds[i])];let a=Wd(n.relation);return this.env.refIds[i]=r,this.env.ref.set(r,{name:null,schemaName:null,token:n.token,endpoints:[{...n,relation:a[1]},{schemaName:this.table.schemaName,tableName:this.table.name,fieldNames:[R(e.callee)],token:V(e),relation:a[0]}]}),[]}},of=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tableGroup={tables:[]}}interpret(){let e=[];return this.tableGroup.token=V(this.declarationNode),this.env.tableGroups.set(this.declarationNode,this.tableGroup),e.push(...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)),e}interpretName(e){let t=[],{name:n,schemaName:r}=Kd(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]=b(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case`note`:this.tableGroup.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)};break;default:break}return[]})}interpretFields(e){let t=[];return this.tableGroup.tables=e.map(e=>{let n=L(e.callee);n.length>2&&t.push(new N(M.UNSUPPORTED,`Nested schema is not supported`,e));let r=md(e.callee).pop().referee.id;if(this.env.tableOwnerGroup[r]){let i=this.env.tableOwnerGroup[r],{schemaName:a,name:o}=this.env.tableGroups.get(i),s=a?`${a}.${o}`:o;t.push(new N(M.TABLE_REAPPEAR_IN_TABLEGROUP,`Table "${n.join(`.`)}" already appears in group "${s}"`,e))}else this.env.tableOwnerGroup[r]=this.declarationNode;return{name:n.pop(),schemaName:n.join(`.`)||null}}),t}interpretSettingList(e){let t=I(e).getValue();this.tableGroup.color=t.color?.length?qd(t.color?.at(0)?.value):void 0;let[n]=t.note||[];return this.tableGroup.note=n&&{value:Xd(B(n?.value)),token:V(n)},[]}},sf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.tablePartial={name:void 0,fields:[],token:void 0,indexes:[],checks:[]},this.pkColumns=[]}interpret(){this.tablePartial.token=V(this.declarationNode),this.env.tablePartials.set(this.declarationNode,this.tablePartial);let e=[...this.interpretName(this.declarationNode.name),...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})),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})),e}interpretName(e){let{name:t}=Kd(e);return this.tablePartial.name=t,[]}interpretSettingList(e){let t=I(e).getValue(),n=Ic(t[_.HeaderColor]);this.tablePartial.headerColor=n?qd(n.value):void 0;let[r]=t[_.Note]||[];return this.tablePartial.note=r&&{value:Xd(B(r?.value)),token:V(r)},[]}interpretBody(e){let[t,n]=b(e.body,e=>e instanceof T);return[...this.interpretFields(t),...this.interpretSubElements(n)]}interpretSubElements(e){return e.flatMap(e=>{switch(e.type?.value.toLowerCase()){case g.Note:return this.tablePartial.note={value:Xd(B(e.body instanceof E?e.body.body[0].callee:e.body.callee)),token:V(e)},[];case g.Indexes:return this.interpretIndexes(e);case g.Check:return this.interpretChecks(e);default:return[]}})}interpretFields(e){return e.flatMap(e=>this.interpretColumn(e))}interpretColumn(e){let t=[],n={};n.name=z(e.callee);let r=Qd(e.args[0],this.env);n.type=r.getValue(),t.push(...r.getErrors()),n.token=V(e),n.inline_refs=[];let i=e.args.slice(1);if(y(i)instanceof D){let r=I(i.pop()).getValue();n.pk=!!r[_.PK]?.length||!!r[_.PrimaryKey]?.length,n.increment=!!r[_.Increment]?.length,n.unique=!!r[_.Unique]?.length,n.not_null=r[_.NotNull]?.length?!0:r[_.Null]?.length?!1:void 0,n.dbdefault=Zd(r[_.Default]?.at(0)?.value);let a=r[_.Note]?.at(0);n.note=a&&{value:Xd(B(a.value)),token:V(a)},n.inline_refs=(r[_.Ref]||[]).flatMap(n=>{let[r]=Gd(n.value.expression);if(Yd(r,e.symbol))return t.push(new N(M.SAME_ENDPOINT,`Two endpoints are the same`,n)),[];let i=n.value.op,a=L(n.value.expression),o;if(a.length===2){let[e,t]=a;o={schemaName:null,tableName:e,fieldNames:[t],relation:i.value,token:V(n)}}else if(a.length===3){let[e,t,r]=a;o={schemaName:e,tableName:t,fieldNames:[r],relation:i.value,token:V(n)}}else{t.push(new N(M.UNSUPPORTED,`Unsupported`,n));let e=a.pop(),r=a.pop();o={schemaName:a.join(`.`),tableName:r,fieldNames:[e],relation:i.value,token:V(n)}}return o}),n.checks=(r[_.Check]||[]).map(e=>({token:V(e),expression:e.value.value.value}))}return n.pk||=i.some(e=>Bu(_,R(e))===_.PK),n.unique||=i.some(e=>Bu(_,R(e))===_.Unique),this.tablePartial.fields.push(n),n.pk&&this.pkColumns.push(n),t}interpretIndexes(e){return this.tablePartial.indexes.push(...e.body.body.map(e=>{let t={columns:[]},n=e;t.token=V(n);let r=[n.callee,...n.args];if(y(r)instanceof D){let e=I(r.pop()).getValue();t.pk=!!e[_.PK]?.length,t.unique=!!e[_.Unique]?.length,t.name=B(e[_.Name]?.at(0)?.value);let n=e[_.Note]?.at(0);t.note=n&&{value:B(n.value),token:V(n)},t.type=R(e[_.Type]?.at(0)?.value)}return r.flatMap(e=>{if(!(e instanceof O))return e;let t=[],n=e;for(;n instanceof O;)t.push(n.argumentList),n=n.callee;return t.push(n),t}).forEach(e=>{let{functional:n,nonFunctional:r}=gd(e);t.columns.push(...n.map(e=>({value:e.value.value,type:`expression`,token:V(e)})),...r.map(e=>({value:z(e),type:`column`,token:V(e)})))}),t})),[]}interpretChecks(e){return this.tablePartial.checks.push(...e.body.body.map(e=>{let t={},n=e;return t.token=V(n),n.args[0]instanceof D&&(t.name=B(I(n.args[0]).getValue()[_.Name]?.at(0)?.value)),t.expression=n.callee.value.value,t})),[]}},cf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.project={enums:[],refs:[],tableGroups:[],tables:[],tablePartials:[]}}interpret(){return this.env.project.set(this.declarationNode,this.project),this.project.token=V(this.declarationNode),[...this.interpretName(this.declarationNode.name),...this.interpretBody(this.declarationNode.body)]}interpretName(e){if(!e)return this.project.name=null,[];let{name:t}=Kd(e);return this.project.name=t,[]}interpretBody(e){return e.body.flatMap(e=>{let t=e;switch(t.type?.value.toLowerCase()){case`table`:{let e=new af(t,this.env).interpret();return this.project.tables.push(this.env.tables.get(t)),e}case`ref`:{let e=new rf(t,this.env).interpret();return this.project.refs.push(this.env.ref.get(t)),e}case`tablegroup`:{let e=new of(t,this.env).interpret();return this.project.tableGroups.push(this.env.tableGroups.get(t)),e}case`enum`:{let e=new nf(t,this.env).interpret();return this.project.enums.push(this.env.enums.get(t)),e}case`note`:return this.project.note={value:Xd(B(t.body instanceof E?t.body.body[0].callee:t.body.callee)),token:V(t)},[];case`tablepartial`:{let e=new sf(t,this.env).interpret();return this.project.tablePartials.push(this.env.tablePartials.get(t)),e}default:return this.project[t.type.value.toLowerCase()]=B(t.body.callee),[]}})}},lf=class{constructor(e,t){this.declarationNode=e,this.env=t,this.note={name:void 0,content:void 0,token:void 0}}interpret(){return this.note.token=V(this.declarationNode),this.env.notes.set(this.declarationNode,this.note),[...this.interpretName(this.declarationNode.name),...this.interpretSettingList(this.declarationNode.attributeList),...this.interpretBody(this.declarationNode.body)]}interpretName(e){let{name:t}=Kd(e);return this.note.name=t,[]}interpretSettingList(e){let t=I(e).getValue();return this.note.headerColor=t.headercolor?.length?qd(t.headercolor?.at(0)?.value):void 0,[]}interpretBody(e){let[t,n]=b(e.body,e=>e instanceof T);return t.length!==1||n.length>0?[new N(M.INVALID_NOTE,`Invalid note syntax`,e)]:[...this.interpretNote(t[0])]}interpretNote(e){let t=Ca(e,`callee.expression.literal.value`,``);return this.note.content=Xd(t),[]}},uf={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`])},df={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`])},ff={mysql:new Set([`bool`,`boolean`,`bit`]),postgres:new Set([`bool`,`boolean`]),mssql:new Set([`bit`]),oracle:new Set([]),snowflake:new Set([`boolean`])},pf={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`])},mf={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`])},hf={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`])},gf={mysql:new Set([]),postgres:new Set([`serial`,`smallserial`,`bigserial`]),mssql:new Set([]),oracle:new Set([]),snowflake:new Set([])};function _f(e){return e.toLowerCase().trim().replace(/\s+/g,` `)}function vf(e,t){let n=_f(e);return t?uf[t].has(n):Object.values(uf).some(e=>e.has(n))}function yf(e,t){let n=_f(e);return t?df[t].has(n):Object.values(df).some(e=>e.has(n))}function bf(e,t){return vf(e,t)||yf(e,t)}function xf(e,t){let n=_f(e);return t?ff[t].has(n):Object.values(ff).some(e=>e.has(n))}function Sf(e,t){let n=_f(e);return t?pf[t].has(n):Object.values(pf).some(e=>e.has(n))}function Cf(e,t){let n=_f(e);return t?mf[t].has(n):Object.values(mf).some(e=>e.has(n))}function wf(e,t){let n=_f(e);return t?hf[t].has(n):Object.values(hf).some(e=>e.has(n))}function Tf(e,t){let n=_f(e);return t?gf[t].has(n):Object.values(gf).some(e=>e.has(n))}function Ef(e){let t=e.declaration;return t instanceof T&&t.args[0]||null}function Df(e){let t=Ef(e);if(!(t instanceof O)||!t.argumentList||t.argumentList.elementList.length!==2)return{};let n=_d(t.argumentList.elementList[0]),r=_d(t.argumentList.elementList[1]);return n===null||r===null?{}:{precision:Math.trunc(n),scale:Math.trunc(r)}}function Of(e){let t=Ef(e);if(!(t instanceof O)||!t.argumentList||t.argumentList.elementList.length!==1)return{};let n=_d(t.argumentList.elementList[0]);return n===null?{}:{length:Math.trunc(n)}}function kf(e,t){if(t)return`string`;if(vf(e))return`integer`;if(yf(e))return`real`;if(xf(e))return`bool`;if(Sf(e))return`string`;let n=_f(e);return n===`date`?`date`:n===`time`||n===`timetz`||n===`time with time zone`||n===`time without time zone`?`time`:wf(e)?`datetime`:e}var Af=class extends Error{},jf=class extends Af{constructor(e){super(`Invalid DateTime: ${e.toMessage()}`)}},Mf=class extends Af{constructor(e){super(`Invalid Interval: ${e.toMessage()}`)}},Nf=class extends Af{constructor(e){super(`Invalid Duration: ${e.toMessage()}`)}},Pf=class extends Af{},Ff=class extends Af{constructor(e){super(`Invalid unit ${e}`)}},If=class extends Af{},Lf=class extends Af{constructor(){super(`Zone is an abstract class`)}},H=`numeric`,Rf=`short`,zf=`long`,Bf={year:H,month:H,day:H},Vf={year:H,month:Rf,day:H},Hf={year:H,month:Rf,day:H,weekday:Rf},Uf={year:H,month:zf,day:H},Wf={year:H,month:zf,day:H,weekday:zf},Gf={hour:H,minute:H},Kf={hour:H,minute:H,second:H},qf={hour:H,minute:H,second:H,timeZoneName:Rf},Jf={hour:H,minute:H,second:H,timeZoneName:zf},Yf={hour:H,minute:H,hourCycle:`h23`},Xf={hour:H,minute:H,second:H,hourCycle:`h23`},Zf={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:Rf},Qf={hour:H,minute:H,second:H,hourCycle:`h23`,timeZoneName:zf},$f={year:H,month:H,day:H,hour:H,minute:H},ep={year:H,month:H,day:H,hour:H,minute:H,second:H},tp={year:H,month:Rf,day:H,hour:H,minute:H},np={year:H,month:Rf,day:H,hour:H,minute:H,second:H},rp={year:H,month:Rf,day:H,weekday:Rf,hour:H,minute:H},ip={year:H,month:zf,day:H,hour:H,minute:H,timeZoneName:Rf},ap={year:H,month:zf,day:H,hour:H,minute:H,second:H,timeZoneName:Rf},op={year:H,month:zf,day:H,weekday:zf,hour:H,minute:H,timeZoneName:zf},sp={year:H,month:zf,day:H,weekday:zf,hour:H,minute:H,second:H,timeZoneName:zf},cp=class{get type(){throw new Lf}get name(){throw new Lf}get ianaName(){return this.name}get isUniversal(){throw new Lf}offsetName(e,t){throw new Lf}formatOffset(e,t){throw new Lf}offset(e){throw new Lf}equals(e){throw new Lf}get isValid(){throw new Lf}},lp=null,up=class e extends cp{static get instance(){return lp===null&&(lp=new e),lp}get type(){return`system`}get name(){return new Intl.DateTimeFormat().resolvedOptions().timeZone}get isUniversal(){return!1}offsetName(e,{format:t,locale:n}){return Jm(e,t,n)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){return-new Date(e).getTimezoneOffset()}equals(e){return e.type===`system`}get isValid(){return!0}},dp=new Map;function fp(e){let t=dp.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`}),dp.set(e,t)),t}var pp={year:0,month:1,day:2,era:3,hour:4,minute:5,second:6};function mp(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 hp(e,t){let n=e.formatToParts(t),r=[];for(let e=0;e<n.length;e++){let{type:t,value:i}=n[e],a=pp[t];t===`era`?r[a]=i:G(a)||(r[a]=parseInt(i,10))}return r}var gp=new Map,_p=class e extends cp{static create(t){let n=gp.get(t);return n===void 0&&gp.set(t,n=new e(t)),n}static resetCache(){gp.clear(),dp.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 Jm(e,t,n,this.name)}formatOffset(e,t){return Qm(this.offset(e),t)}offset(e){if(!this.valid)return NaN;let t=new Date(e);if(isNaN(t))return NaN;let n=fp(this.name),[r,i,a,o,s,c,l]=n.formatToParts?hp(n,t):mp(n,t);o===`BC`&&(r=-Math.abs(r)+1);let u=Wm({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}},vp={};function yp(e,t={}){let n=JSON.stringify([e,t]),r=vp[n];return r||(r=new Intl.ListFormat(e,t),vp[n]=r),r}var bp=new Map;function xp(e,t={}){let n=JSON.stringify([e,t]),r=bp.get(n);return r===void 0&&(r=new Intl.DateTimeFormat(e,t),bp.set(n,r)),r}var Sp=new Map;function Cp(e,t={}){let n=JSON.stringify([e,t]),r=Sp.get(n);return r===void 0&&(r=new Intl.NumberFormat(e,t),Sp.set(n,r)),r}var wp=new Map;function Tp(e,t={}){let{base:n,...r}=t,i=JSON.stringify([e,r]),a=wp.get(i);return a===void 0&&(a=new Intl.RelativeTimeFormat(e,t),wp.set(i,a)),a}var Ep=null;function Dp(){return Ep||(Ep=new Intl.DateTimeFormat().resolvedOptions().locale,Ep)}var Op=new Map;function kp(e){let t=Op.get(e);return t===void 0&&(t=new Intl.DateTimeFormat(e).resolvedOptions(),Op.set(e,t)),t}var Ap=new Map;function jp(e){let t=Ap.get(e);if(!t){let n=new Intl.Locale(e);t=`getWeekInfo`in n?n.getWeekInfo():n.weekInfo,`minimalDays`in t||(t={...Vp,...t}),Ap.set(e,t)}return t}function Mp(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=xp(e).resolvedOptions(),r=e}catch{let i=e.substring(0,n);t=xp(i).resolvedOptions(),r=i}let{numberingSystem:i,calendar:a}=t;return[r,i,a]}}function Np(e,t,n){return n||t?(e.includes(`-u-`)||(e+=`-u`),n&&(e+=`-ca-${n}`),t&&(e+=`-nu-${t}`),e):e}function Pp(e){let t=[];for(let n=1;n<=12;n++){let r=J.utc(2009,n,1);t.push(e(r))}return t}function Fp(e){let t=[];for(let n=1;n<=7;n++){let r=J.utc(2016,11,13+n);t.push(e(r))}return t}function Ip(e,t,n,r){let i=e.listingMode();return i===`error`?null:i===`en`?n(t):r(t)}function Lp(e){return e.numberingSystem&&e.numberingSystem!==`latn`?!1:e.numberingSystem===`latn`||!e.locale||e.locale.startsWith(`en`)||kp(e.locale).numberingSystem===`latn`}var Rp=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=Cp(e,t)}}format(e){if(this.inf){let t=this.floor?Math.floor(e):e;return this.inf.format(t)}else return K(this.floor?Math.floor(e):Bm(e,3),this.padTo)}},zp=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&&_p.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=xp(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()}},Bp=class{constructor(e,t,n){this.opts={style:`long`,...n},!t&&Om()&&(this.rtf=Tp(e,n))}format(e,t){return this.rtf?this.rtf.format(e,t):_h(t,e,this.opts.numeric,this.opts.style!==`long`)}formatToParts(e,t){return this.rtf?this.rtf.formatToParts(e,t):[]}},Vp={firstDay:1,minimalDays:4,weekend:[6,7]},U=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||W.defaultLocale;return new e(o||(a?`en-US`:Dp()),n||W.defaultNumberingSystem,r||W.defaultOutputCalendar,Pm(i)||W.defaultWeekSettings,o)}static resetCache(){Ep=null,bp.clear(),Sp.clear(),wp.clear(),Op.clear(),Ap.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]=Mp(e);this.locale=a,this.numberingSystem=t||o||null,this.outputCalendar=n||s||null,this.weekSettings=r,this.intl=Np(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??=Lp(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,Pm(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 Ip(this,e,rh,()=>{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]=Pp(t)}return this.monthsCache[i][e]})}weekdays(e,t=!1){return Ip(this,e,sh,()=>{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]=Fp(e=>this.extract(e,n,`weekday`))),this.weekdaysCache[r][e]})}meridiems(){return Ip(this,void 0,()=>ch,()=>{if(!this.meridiemCache){let e={hour:`numeric`,hourCycle:`h12`};this.meridiemCache=[J.utc(2016,11,13,9),J.utc(2016,11,13,19)].map(t=>this.extract(t,e,`dayperiod`))}return this.meridiemCache})}eras(e){return Ip(this,e,fh,()=>{let t={era:e};return this.eraCache[e]||(this.eraCache[e]=[J.utc(-40,1,1),J.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 Rp(this.intl,e.forceSimple||this.fastNumbers,e)}dtFormatter(e,t={}){return new zp(e,this.intl,t)}relFormatter(e={}){return new Bp(this.intl,this.isEnglish(),e)}listFormatter(e={}){return yp(this.intl,e)}isEnglish(){return this.locale===`en`||this.locale.toLowerCase()===`en-us`||kp(this.intl).locale.startsWith(`en-us`)}getWeekSettings(){return this.weekSettings?this.weekSettings:km()?jp(this.locale):Vp}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})`}},Hp=null,Up=class e extends cp{static get utcInstance(){return Hp===null&&(Hp=new e(0)),Hp}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(Ym(n[1],n[2]))}return null}constructor(e){super(),this.fixed=e}get type(){return`fixed`}get name(){return this.fixed===0?`UTC`:`UTC${Qm(this.fixed,`narrow`)}`}get ianaName(){return this.fixed===0?`Etc/UTC`:`Etc/GMT${Qm(-this.fixed,`narrow`)}`}offsetName(){return this.name}formatOffset(e,t){return Qm(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}},Wp=class extends cp{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 Gp(e,t){if(G(e)||e===null)return t;if(e instanceof cp)return e;if(Em(e)){let n=e.toLowerCase();return n===`default`?t:n===`local`||n===`system`?up.instance:n===`utc`||n===`gmt`?Up.utcInstance:Up.parseSpecifier(n)||_p.create(e)}else if(wm(e))return Up.instance(e);else if(typeof e==`object`&&`offset`in e&&typeof e.offset==`function`)return e;else return new Wp(e)}var Kp={arab:`[٠-٩]`,arabext:`[۰-۹]`,bali:`[᭐-᭙]`,beng:`[০-৯]`,deva:`[०-९]`,fullwide:`[0-9]`,gujr:`[૦-૯]`,hanidec:`[〇|一|二|三|四|五|六|七|八|九]`,khmr:`[០-៩]`,knda:`[೦-೯]`,laoo:`[໐-໙]`,limb:`[᥆-᥏]`,mlym:`[൦-൯]`,mong:`[᠐-᠙]`,mymr:`[၀-၉]`,orya:`[୦-୯]`,tamldec:`[௦-௯]`,telu:`[౦-౯]`,thai:`[๐-๙]`,tibt:`[༠-༩]`,latn:`\\d`},qp={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]},Jp=Kp.hanidec.replace(/[\[|\]]/g,``).split(``);function Yp(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(Kp.hanidec)!==-1)t+=Jp.indexOf(e[n]);else for(let e in qp){let[n,i]=qp[e];r>=n&&r<=i&&(t+=r-n)}}return parseInt(t,10)}else return t}var Xp=new Map;function Zp(){Xp.clear()}function Qp({numberingSystem:e},t=``){let n=e||`latn`,r=Xp.get(n);r===void 0&&(r=new Map,Xp.set(n,r));let i=r.get(t);return i===void 0&&(i=RegExp(`${Kp[n]}${t}`),r.set(t,i)),i}var $p=()=>Date.now(),em=`system`,tm=null,nm=null,rm=null,im=60,am,om=null,W=class{static get now(){return $p}static set now(e){$p=e}static set defaultZone(e){em=e}static get defaultZone(){return Gp(em,up.instance)}static get defaultLocale(){return tm}static set defaultLocale(e){tm=e}static get defaultNumberingSystem(){return nm}static set defaultNumberingSystem(e){nm=e}static get defaultOutputCalendar(){return rm}static set defaultOutputCalendar(e){rm=e}static get defaultWeekSettings(){return om}static set defaultWeekSettings(e){om=Pm(e)}static get twoDigitCutoffYear(){return im}static set twoDigitCutoffYear(e){im=e%100}static get throwOnInvalid(){return am}static set throwOnInvalid(e){am=e}static resetCaches(){U.resetCache(),_p.resetCache(),J.resetCache(),Zp()}},sm=class{constructor(e,t){this.reason=e,this.explanation=t}toMessage(){return this.explanation?`${this.reason}: ${this.explanation}`:this.reason}},cm=[0,31,59,90,120,151,181,212,243,273,304,334],lm=[0,31,60,91,121,152,182,213,244,274,305,335];function um(e,t){return new sm(`unit out of range`,`you specified ${t} (of type ${typeof t}) as a ${e}, which is invalid`)}function dm(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 fm(e,t,n){return n+(Vm(e)?lm:cm)[t-1]}function pm(e,t){let n=Vm(e)?lm:cm,r=n.findIndex(e=>e<t),i=t-n[r];return{month:r+1,day:i}}function mm(e,t){return(e-t+7)%7+1}function hm(e,t=4,n=1){let{year:r,month:i,day:a}=e,o=fm(r,i,a),s=mm(dm(r,i,a),n),c=Math.floor((o-s+14-t)/7),l;return c<1?(l=r-1,c=Km(l,t,n)):c>Km(r,t,n)?(l=r+1,c=1):l=r,{weekYear:l,weekNumber:c,weekday:s,...$m(e)}}function gm(e,t=4,n=1){let{weekYear:r,weekNumber:i,weekday:a}=e,o=mm(dm(r,1,t),n),s=Hm(r),c=i*7+a-o-7+t,l;c<1?(l=r-1,c+=Hm(l)):c>s?(l=r+1,c-=Hm(r)):l=r;let{month:u,day:d}=pm(l,c);return{year:l,month:u,day:d,...$m(e)}}function _m(e){let{year:t,month:n,day:r}=e;return{year:t,ordinal:fm(t,n,r),...$m(e)}}function vm(e){let{year:t,ordinal:n}=e,{month:r,day:i}=pm(t,n);return{year:t,month:r,day:i,...$m(e)}}function ym(e,t){if(!G(e.localWeekday)||!G(e.localWeekNumber)||!G(e.localWeekYear)){if(!G(e.weekday)||!G(e.weekNumber)||!G(e.weekYear))throw new Pf(`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 bm(e,t=4,n=1){let r=Tm(e.weekYear),i=Fm(e.weekNumber,1,Km(e.weekYear,t,n)),a=Fm(e.weekday,1,7);return r?i?a?!1:um(`weekday`,e.weekday):um(`week`,e.weekNumber):um(`weekYear`,e.weekYear)}function xm(e){let t=Tm(e.year),n=Fm(e.ordinal,1,Hm(e.year));return t?n?!1:um(`ordinal`,e.ordinal):um(`year`,e.year)}function Sm(e){let t=Tm(e.year),n=Fm(e.month,1,12),r=Fm(e.day,1,Um(e.year,e.month));return t?n?r?!1:um(`day`,e.day):um(`month`,e.month):um(`year`,e.year)}function Cm(e){let{hour:t,minute:n,second:r,millisecond:i}=e,a=Fm(t,0,23)||t===24&&n===0&&r===0&&i===0,o=Fm(n,0,59),s=Fm(r,0,59),c=Fm(i,0,999);return a?o?s?c?!1:um(`millisecond`,i):um(`second`,r):um(`minute`,n):um(`hour`,t)}function G(e){return e===void 0}function wm(e){return typeof e==`number`}function Tm(e){return typeof e==`number`&&e%1==0}function Em(e){return typeof e==`string`}function Dm(e){return Object.prototype.toString.call(e)===`[object Date]`}function Om(){try{return typeof Intl<`u`&&!!Intl.RelativeTimeFormat}catch{return!1}}function km(){try{return typeof Intl<`u`&&!!Intl.Locale&&(`weekInfo`in Intl.Locale.prototype||`getWeekInfo`in Intl.Locale.prototype)}catch{return!1}}function Am(e){return Array.isArray(e)?e:[e]}function jm(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 Mm(e,t){return t.reduce((t,n)=>(t[n]=e[n],t),{})}function Nm(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Pm(e){if(e==null)return null;if(typeof e!=`object`)throw new If(`Week settings must be an object`);if(!Fm(e.firstDay,1,7)||!Fm(e.minimalDays,1,7)||!Array.isArray(e.weekend)||e.weekend.some(e=>!Fm(e,1,7)))throw new If(`Invalid week settings`);return{firstDay:e.firstDay,minimalDays:e.minimalDays,weekend:Array.from(e.weekend)}}function Fm(e,t,n){return Tm(e)&&e>=t&&e<=n}function Im(e,t){return e-t*Math.floor(e/t)}function K(e,t=2){let n=e<0,r;return r=n?`-`+(``+-e).padStart(t,`0`):(``+e).padStart(t,`0`),r}function Lm(e){if(!(G(e)||e===null||e===``))return parseInt(e,10)}function Rm(e){if(!(G(e)||e===null||e===``))return parseFloat(e)}function zm(e){if(!(G(e)||e===null||e===``)){let t=parseFloat(`0.`+e)*1e3;return Math.floor(t)}}function Bm(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 Vm(e){return e%4==0&&(e%100!=0||e%400==0)}function Hm(e){return Vm(e)?366:365}function Um(e,t){let n=Im(t-1,12)+1,r=e+(t-n)/12;return n===2?Vm(r)?29:28:[31,null,31,30,31,30,31,31,30,31,30,31][n-1]}function Wm(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 Gm(e,t,n){return-mm(dm(e,1,t),n)+t-1}function Km(e,t=4,n=1){let r=Gm(e,t,n),i=Gm(e+1,t,n);return(Hm(e)-r+i)/7}function qm(e){return e>99?e:e>W.twoDigitCutoffYear?1900+e:2e3+e}function Jm(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 Ym(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 Xm(e){let t=Number(e);if(typeof e==`boolean`||e===``||!Number.isFinite(t))throw new If(`Invalid unit value ${e}`);return t}function Zm(e,t){let n={};for(let r in e)if(Nm(e,r)){let i=e[r];if(i==null)continue;n[t(r)]=Xm(i)}return n}function Qm(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}${K(n,2)}:${K(r,2)}`;case`narrow`:return`${i}${n}${r>0?`:${r}`:``}`;case`techie`:return`${i}${K(n,2)}${K(r,2)}`;default:throw RangeError(`Value format ${t} is out of range for property format`)}}function $m(e){return Mm(e,[`hour`,`minute`,`second`,`millisecond`])}var eh=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],th=[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`],nh=[`J`,`F`,`M`,`A`,`M`,`J`,`J`,`A`,`S`,`O`,`N`,`D`];function rh(e){switch(e){case`narrow`:return[...nh];case`short`:return[...th];case`long`:return[...eh];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 ih=[`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`,`Sunday`],ah=[`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`,`Sun`],oh=[`M`,`T`,`W`,`T`,`F`,`S`,`S`];function sh(e){switch(e){case`narrow`:return[...oh];case`short`:return[...ah];case`long`:return[...ih];case`numeric`:return[`1`,`2`,`3`,`4`,`5`,`6`,`7`];default:return null}}var ch=[`AM`,`PM`],lh=[`Before Christ`,`Anno Domini`],uh=[`BC`,`AD`],dh=[`B`,`A`];function fh(e){switch(e){case`narrow`:return[...dh];case`short`:return[...uh];case`long`:return[...lh];default:return null}}function ph(e){return ch[e.hour<12?0:1]}function mh(e,t){return sh(t)[e.weekday-1]}function hh(e,t){return rh(t)[e.month-1]}function gh(e,t){return fh(t)[e.year<0?0:1]}function _h(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 vh(e,t){let n=``;for(let r of e)r.literal?n+=r.val:n+=t(r.val);return n}var yh={D:Bf,DD:Vf,DDD:Uf,DDDD:Wf,t:Gf,tt:Kf,ttt:qf,tttt:Jf,T:Yf,TT:Xf,TTT:Zf,TTTT:Qf,f:$f,ff:tp,fff:ip,ffff:op,F:ep,FF:np,FFF:ap,FFFF:sp},bh=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 yh[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 K(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?ph(t):a({hour:`numeric`,hourCycle:`h12`},`dayperiod`),c=(e,n)=>r?hh(t,e):a(n?{month:e}:{month:e,day:`numeric`},`month`),l=(e,n)=>r?mh(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?gh(t,e):a({era:e},`era`);return vh(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 vh(o,a(c,{isNegativeDuration:c<0,largestUnit:Object.keys(c.values)[0]}))}},xh=/[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/;function Sh(...e){let t=e.reduce((e,t)=>e+t.source,``);return RegExp(`^${t}$`)}function Ch(...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 wh(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 Th(...e){return(t,n)=>{let r={},i;for(i=0;i<e.length;i++)r[e[i]]=Lm(t[n+i]);return[r,null,n+i]}}var Eh=/(?:([Zz])|([+-]\d\d)(?::?(\d\d))?)/,Dh=`(?:${Eh.source}?(?:\\[(${xh.source})\\])?)?`,Oh=/(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/,kh=RegExp(`${Oh.source}${Dh}`),Ah=RegExp(`(?:[Tt]${kh.source})?`),jh=/([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/,Mh=/(\d{4})-?W(\d\d)(?:-?(\d))?/,Nh=/(\d{4})-?(\d{3})/,Ph=Th(`weekYear`,`weekNumber`,`weekDay`),Fh=Th(`year`,`ordinal`),Ih=/(\d{4})-(\d\d)-(\d\d)/,Lh=RegExp(`${Oh.source} ?(?:${Eh.source}|(${xh.source}))?`),Rh=RegExp(`(?: ${Lh.source})?`);function zh(e,t,n){let r=e[t];return G(r)?n:Lm(r)}function Bh(e,t){return[{year:zh(e,t),month:zh(e,t+1,1),day:zh(e,t+2,1)},null,t+3]}function Vh(e,t){return[{hours:zh(e,t,0),minutes:zh(e,t+1,0),seconds:zh(e,t+2,0),milliseconds:zm(e[t+3])},null,t+4]}function Hh(e,t){let n=!e[t]&&!e[t+1],r=Ym(e[t+1],e[t+2]);return[{},n?null:Up.instance(r),t+3]}function Uh(e,t){return[{},e[t]?_p.create(e[t]):null,t+1]}var Wh=RegExp(`^T?${Oh.source}$`),Gh=/^-?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 Kh(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(Rm(n)),months:f(Rm(r)),weeks:f(Rm(i)),days:f(Rm(a)),hours:f(Rm(o)),minutes:f(Rm(s)),seconds:f(Rm(c),c===`-0`),milliseconds:f(zm(l),d)}]}var qh={GMT:0,EDT:-240,EST:-300,CDT:-300,CST:-360,MDT:-360,MST:-420,PDT:-420,PST:-480};function Jh(e,t,n,r,i,a,o){let s={year:t.length===2?qm(Lm(t)):Lm(t),month:th.indexOf(n)+1,day:Lm(r),hour:Lm(i),minute:Lm(a)};return o&&(s.second=Lm(o)),e&&(s.weekday=e.length>3?ih.indexOf(e)+1:ah.indexOf(e)+1),s}var Yh=/^(?:(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 Xh(e){let[,t,n,r,i,a,o,s,c,l,u,d]=e,f=Jh(t,i,r,n,a,o,s),p;return p=c?qh[c]:l?0:Ym(u,d),[f,new Up(p)]}function Zh(e){return e.replace(/\([^()]*\)|[\n\t]/g,` `).replace(/(\s\s+)/g,` `).trim()}var Qh=/^(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$/,$h=/^(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$/,eg=/^(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 tg(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,i,r,n,a,o,s),Up.utcInstance]}function ng(e){let[,t,n,r,i,a,o,s]=e;return[Jh(t,s,n,r,i,a,o),Up.utcInstance]}var rg=Sh(jh,Ah),ig=Sh(Mh,Ah),ag=Sh(Nh,Ah),og=Sh(kh),sg=Ch(Bh,Vh,Hh,Uh),cg=Ch(Ph,Vh,Hh,Uh),lg=Ch(Fh,Vh,Hh,Uh),ug=Ch(Vh,Hh,Uh);function dg(e){return wh(e,[rg,sg],[ig,cg],[ag,lg],[og,ug])}function fg(e){return wh(Zh(e),[Yh,Xh])}function pg(e){return wh(e,[Qh,tg],[$h,tg],[eg,ng])}function mg(e){return wh(e,[Gh,Kh])}var hg=Ch(Vh);function gg(e){return wh(e,[Wh,hg])}var _g=Sh(Ih,Rh),vg=Sh(Lh),yg=Ch(Vh,Hh,Uh);function bg(e){return wh(e,[_g,sg],[vg,yg])}var xg=`Invalid Duration`,Sg={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}},Cg={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},...Sg},wg=146097/400,Tg=146097/4800,Eg={years:{quarters:4,months:12,weeks:wg/7,days:wg,hours:wg*24,minutes:wg*24*60,seconds:wg*24*60*60,milliseconds:wg*24*60*60*1e3},quarters:{months:3,weeks:wg/28,days:wg/4,hours:wg*24/4,minutes:wg*24*60/4,seconds:wg*24*60*60/4,milliseconds:wg*24*60*60*1e3/4},months:{weeks:Tg/7,days:Tg,hours:Tg*24,minutes:Tg*24*60,seconds:Tg*24*60*60,milliseconds:Tg*24*60*60*1e3},...Sg},Dg=[`years`,`quarters`,`months`,`weeks`,`days`,`hours`,`minutes`,`seconds`,`milliseconds`],Og=Dg.slice(0).reverse();function kg(e,t,n=!1){return new Ng({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 Ag(e,t){let n=t.milliseconds??0;for(let r of Og.slice(1))t[r]&&(n+=t[r]*e[r].milliseconds);return n}function jg(e,t){let n=Ag(e,t)<0?-1:1;Dg.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),Dg.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 Mg(e){let t={};for(let[n,r]of Object.entries(e))r!==0&&(t[n]=r);return t}var Ng=class e{constructor(e){let t=e.conversionAccuracy===`longterm`||!1,n=t?Eg:Cg;e.matrix&&(n=e.matrix),this.values=e.values,this.loc=e.loc||U.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 If(`Duration.fromObject: argument expected to be an object, got ${t===null?`null`:typeof t}`);return new e({values:Zm(t,e.normalizeUnit),loc:U.fromObject(n),conversionAccuracy:n.conversionAccuracy,matrix:n.matrix})}static fromDurationLike(t){if(wm(t))return e.fromMillis(t);if(e.isDuration(t))return t;if(typeof t==`object`)return e.fromObject(t);throw new If(`Unknown duration argument ${t} of type ${typeof t}`)}static fromISO(t,n){let[r]=mg(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]=gg(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 If(`need to specify a reason the Duration is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new Nf(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 Ff(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?bh.create(this.loc,n).formatDurationFromString(this,e):xg}toHuman(e={}){if(!this.isValid)return xg;let t=e.showZeros!==!1,n=Dg.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+=Bm(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},J.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?Ag(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 Dg)(Nm(n.values,e)||Nm(this.values,e))&&(r[e]=n.get(e)+this.get(e));return kg(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]=Xm(e(this.values[n],n));return kg(this,{values:t},!0)}get(t){return this[e.normalizeUnit(t)]}set(t){if(!this.isValid)return this;let n={...this.values,...Zm(t,e.normalizeUnit)};return kg(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 kg(this,i)}as(e){return this.isValid?this.shiftTo(e).get(e):NaN}normalize(){if(!this.isValid)return this;let e=this.toObject();return jg(this.matrix,e),kg(this,{values:e},!0)}rescale(){if(!this.isValid)return this;let e=Mg(this.normalize().shiftToAll().toObject());return kg(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 Dg)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;wm(i[e])&&(t+=i[e]);let o=Math.trunc(t);n[e]=o,r[e]=(t*1e3-o*1e3)/1e3}else wm(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 jg(this.matrix,n),kg(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 kg(this,{values:e},!0)}removeZeros(){if(!this.isValid)return this;let e=Mg(this.values);return kg(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 Dg)if(!t(this.values[n],e.values[n]))return!1;return!0}},Pg=`Invalid Interval`;function Fg(e,t){return!e||!e.isValid?Ig.invalid(`missing or invalid start`):!t||!t.isValid?Ig.invalid(`missing or invalid end`):t<e?Ig.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 Ig=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 If(`need to specify a reason the Interval is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new Mf(r);return new e({invalid:r})}static fromDateTimes(t,n){let r=R_(t),i=R_(n);return Fg(r,i)??new e({start:r,end:i})}static after(t,n){let r=Ng.fromDurationLike(n),i=R_(t);return e.fromDateTimes(i,i.plus(r))}static before(t,n){let r=Ng.fromDurationLike(n),i=R_(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=J.fromISO(r,n),a=t.isValid}catch{a=!1}let o,s;try{o=J.fromISO(i,n),s=o.isValid}catch{s=!1}if(a&&s)return e.fromDateTimes(t,o);if(a){let r=Ng.fromISO(i,n);if(r.isValid)return e.after(t,r)}else if(s){let t=Ng.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(R_).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=Ng.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()})`:Pg}[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=Bf,t={}){return this.isValid?bh.create(this.s.loc.clone(t),e).formatInterval(this):Pg}toISO(e){return this.isValid?`${this.s.toISO(e)}/${this.e.toISO(e)}`:Pg}toISODate(){return this.isValid?`${this.s.toISODate()}/${this.e.toISODate()}`:Pg}toISOTime(e){return this.isValid?`${this.s.toISOTime(e)}/${this.e.toISOTime(e)}`:Pg}toFormat(e,{separator:t=` – `}={}){return this.isValid?`${this.s.toFormat(e)}${t}${this.e.toFormat(e)}`:Pg}toDuration(e,t){return this.isValid?this.e.diff(this.s,e,t):Ng.invalid(this.invalidReason)}mapEndpoints(t){return e.fromDateTimes(t(this.s),t(this.e))}},Lg=class{static hasDST(e=W.defaultZone){let t=J.now().setZone(e).set({month:12});return!e.isUniversal&&t.offset!==t.set({month:6}).offset}static isValidIANAZone(e){return _p.isValidZone(e)}static normalizeZone(e){return Gp(e,W.defaultZone)}static getStartOfWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getStartOfWeek()}static getMinimumDaysInFirstWeek({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getMinDaysInFirstWeek()}static getWeekendWeekdays({locale:e=null,locObj:t=null}={}){return(t||U.create(e)).getWeekendDays().slice()}static months(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e)}static monthsFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null,outputCalendar:i=`gregory`}={}){return(r||U.create(t,n,i)).months(e,!0)}static weekdays(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e)}static weekdaysFormat(e=`long`,{locale:t=null,numberingSystem:n=null,locObj:r=null}={}){return(r||U.create(t,n,null)).weekdays(e,!0)}static meridiems({locale:e=null}={}){return U.create(e).meridiems()}static eras(e=`short`,{locale:t=null}={}){return U.create(t,null,`gregory`).eras(e)}static features(){return{relative:Om(),localeWeek:km()}}};function Rg(e,t){let n=e=>e.toUTC(0,{keepLocalTime:!0}).startOf(`day`).valueOf(),r=n(t)-n(e);return Math.floor(Ng.fromMillis(r).as(`days`))}function zg(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=Rg(e,t);return(n-n%7)/7}],[`days`,Rg]],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 Bg(e,t,n,r){let[i,a,o,s]=zg(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=Ng.fromObject(a,r);return l.length>0?Ng.fromMillis(c,r).shiftTo(...l).plus(u):u}var Vg=`missing Intl.DateTimeFormat.formatToParts support`;function q(e,t=e=>e){return{regex:e,deser:([e])=>t(Yp(e))}}var Hg=`[ \xA0]`,Ug=new RegExp(Hg,`g`);function Wg(e){return e.replace(/\./g,`\\.?`).replace(Ug,Hg)}function Gg(e){return e.replace(/\./g,``).replace(Ug,` `).toLowerCase()}function Kg(e,t){return e===null?null:{regex:RegExp(e.map(Wg).join(`|`)),deser:([n])=>e.findIndex(e=>Gg(n)===Gg(e))+t}}function qg(e,t){return{regex:e,deser:([,e,t])=>Ym(e,t),groups:t}}function Jg(e){return{regex:e,deser:([e])=>e}}function Yg(e){return e.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,`\\$&`)}function Xg(e,t){let n=Qp(t),r=Qp(t,`{2}`),i=Qp(t,`{3}`),a=Qp(t,`{4}`),o=Qp(t,`{6}`),s=Qp(t,`{1,2}`),c=Qp(t,`{1,3}`),l=Qp(t,`{1,6}`),u=Qp(t,`{1,9}`),d=Qp(t,`{2,4}`),f=Qp(t,`{4,6}`),p=e=>({regex:RegExp(Yg(e.val)),deser:([e])=>e,literal:!0}),m=(m=>{if(e.literal)return p(m);switch(m.val){case`G`:return Kg(t.eras(`short`),0);case`GG`:return Kg(t.eras(`long`),0);case`y`:return q(l);case`yy`:return q(d,qm);case`yyyy`:return q(a);case`yyyyy`:return q(f);case`yyyyyy`:return q(o);case`M`:return q(s);case`MM`:return q(r);case`MMM`:return Kg(t.months(`short`,!0),1);case`MMMM`:return Kg(t.months(`long`,!0),1);case`L`:return q(s);case`LL`:return q(r);case`LLL`:return Kg(t.months(`short`,!1),1);case`LLLL`:return Kg(t.months(`long`,!1),1);case`d`:return q(s);case`dd`:return q(r);case`o`:return q(c);case`ooo`:return q(i);case`HH`:return q(r);case`H`:return q(s);case`hh`:return q(r);case`h`:return q(s);case`mm`:return q(r);case`m`:return q(s);case`q`:return q(s);case`qq`:return q(r);case`s`:return q(s);case`ss`:return q(r);case`S`:return q(c);case`SSS`:return q(i);case`u`:return Jg(u);case`uu`:return Jg(s);case`uuu`:return q(n);case`a`:return Kg(t.meridiems(),0);case`kkkk`:return q(a);case`kk`:return q(d,qm);case`W`:return q(s);case`WW`:return q(r);case`E`:case`c`:return q(n);case`EEE`:return Kg(t.weekdays(`short`,!1),1);case`EEEE`:return Kg(t.weekdays(`long`,!1),1);case`ccc`:return Kg(t.weekdays(`short`,!0),1);case`cccc`:return Kg(t.weekdays(`long`,!0),1);case`Z`:case`ZZ`:return qg(RegExp(`([+-]${s.source})(?::(${r.source}))?`),2);case`ZZZ`:return qg(RegExp(`([+-]${s.source})(${r.source})?`),2);case`z`:return Jg(/[a-z_+-/]{1,256}?/i);case` `:return Jg(/[^\S\n\r]/);default:return p(m)}})(e)||{invalidReason:Vg};return m.token=e,m}var Zg={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 Qg(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=Zg[o];if(typeof s==`object`&&(s=s[a]),s)return{literal:!1,val:s}}function $g(e){return[`^${e.map(e=>e.regex).reduce((e,t)=>`${e}(${t.source})`,``)}$`,e]}function e_(e,t,n){let r=e.match(t);if(r){let e={},t=1;for(let i in n)if(Nm(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 t_(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=_p.create(e.z)),G(e.Z)||(n||=new Up(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=zm(e.u)),[Object.keys(e).reduce((n,r)=>{let i=t(r);return i&&(n[i]=e[r]),n},{}),n,r]}var n_=null;function r_(){return n_||=J.fromMillis(1555555555555),n_}function i_(e,t){if(e.literal)return e;let n=l_(bh.macroTokenToFormatOpts(e.val),t);return n==null||n.includes(void 0)?e:n}function a_(e,t){return Array.prototype.concat(...e.map(e=>i_(e,t)))}var o_=class{constructor(e,t){if(this.locale=e,this.format=t,this.tokens=a_(bh.parseFormat(t),e),this.units=this.tokens.map(t=>Xg(t,e)),this.disqualifyingUnit=this.units.find(e=>e.invalidReason),!this.disqualifyingUnit){let[e,t]=$g(this.units);this.regex=RegExp(e,`i`),this.handlers=t}}explainFromTokens(e){if(this.isValid){let[t,n]=e_(e,this.regex,this.handlers),[r,i,a]=n?t_(n):[null,null,void 0];if(Nm(n,`a`)&&Nm(n,`H`))throw new Pf(`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 s_(e,t,n){return new o_(e,n).explainFromTokens(t)}function c_(e,t,n){let{result:r,zone:i,specificOffset:a,invalidReason:o}=s_(e,t,n);return[r,i,a,o]}function l_(e,t){if(!e)return null;let n=bh.create(t,e).dtFormatter(r_()),r=n.formatToParts(),i=n.resolvedOptions();return r.map(t=>Qg(t,e,i))}var u_=`Invalid DateTime`,d_=864e13;function f_(e){return new sm(`unsupported zone`,`the zone "${e.name}" is not supported`)}function p_(e){return e.weekData===null&&(e.weekData=hm(e.c)),e.weekData}function m_(e){return e.localWeekData===null&&(e.localWeekData=hm(e.c,e.loc.getMinDaysInFirstWeek(),e.loc.getStartOfWeek())),e.localWeekData}function h_(e,t){let n={ts:e.ts,zone:e.zone,c:e.c,o:e.o,loc:e.loc,invalid:e.invalid};return new J({...n,...t,old:n})}function g_(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 __(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 v_(e,t,n){return g_(Wm(e),t,n)}function y_(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,Um(r,i))+Math.trunc(t.days)+Math.trunc(t.weeks)*7},o=Ng.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]=g_(Wm(a),n,e.zone);return o!==0&&(s+=o,c=e.zone.offset(s)),{ts:s,o:c}}function b_(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=J.fromObject(e,{...n,zone:r,specificOffset:a});return o?i:i.setZone(s)}else return J.invalid(new sm(`unparsable`,`the input "${i}" can't be parsed as ${r}`))}function x_(e,t,n=!0){return e.isValid?bh.create(U.create(`en-US`),{allowZ:n,forceSimple:!0}).formatDateTimeFromString(e,t):null}function S_(e,t,n){let r=e.c.year>9999||e.c.year<0,i=``;if(r&&e.c.year>=0&&(i+=`+`),i+=K(e.c.year,r?6:4),n===`year`)return i;if(t){if(i+=`-`,i+=K(e.c.month),n===`month`)return i;i+=`-`}else if(i+=K(e.c.month),n===`month`)return i;return i+=K(e.c.day),i}function C_(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+=K(e.c.hour),o===`hour`)break;if(t){if(c+=`:`,c+=K(e.c.minute),o===`minute`)break;s&&(c+=`:`,c+=K(e.c.second))}else{if(c+=K(e.c.minute),o===`minute`)break;s&&(c+=K(e.c.second))}if(o===`second`)break;s&&(!r||e.c.millisecond!==0)&&(c+=`.`,c+=K(e.c.millisecond,3))}return i&&(e.isOffsetFixed&&e.offset===0&&!a?c+=`Z`:e.o<0?(c+=`-`,c+=K(Math.trunc(-e.o/60)),c+=`:`,c+=K(Math.trunc(-e.o%60))):(c+=`+`,c+=K(Math.trunc(e.o/60)),c+=`:`,c+=K(Math.trunc(e.o%60)))),a&&(c+=`[`+e.zone.ianaName+`]`),c}var w_={month:1,day:1,hour:0,minute:0,second:0,millisecond:0},T_={weekNumber:1,weekday:1,hour:0,minute:0,second:0,millisecond:0},E_={ordinal:1,hour:0,minute:0,second:0,millisecond:0},D_=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],O_=[`weekYear`,`weekNumber`,`weekday`,`hour`,`minute`,`second`,`millisecond`],k_=[`year`,`ordinal`,`hour`,`minute`,`second`,`millisecond`];function A_(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 Ff(e);return t}function j_(e){switch(e.toLowerCase()){case`localweekday`:case`localweekdays`:return`localWeekday`;case`localweeknumber`:case`localweeknumbers`:return`localWeekNumber`;case`localweekyear`:case`localweekyears`:return`localWeekYear`;default:return A_(e)}}function M_(e){if(I_===void 0&&(I_=W.now()),e.type!==`iana`)return e.offset(I_);let t=e.name,n=L_.get(t);return n===void 0&&(n=e.offset(I_),L_.set(t,n)),n}function N_(e,t){let n=Gp(t.zone,W.defaultZone);if(!n.isValid)return J.invalid(f_(n));let r=U.fromObject(t),i,a;if(G(e.year))i=W.now();else{for(let t of D_)G(e[t])&&(e[t]=w_[t]);let t=Sm(e)||Cm(e);if(t)return J.invalid(t);let r=M_(n);[i,a]=v_(e,r,n)}return new J({ts:i,zone:n,loc:r,o:a})}function P_(e,t,n){let r=G(n.round)?!0:n.round,i=G(n.rounding)?`trunc`:n.rounding,a=(e,a)=>(e=Bm(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 F_(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 I_,L_=new Map,J=class e{constructor(e){let t=e.zone||W.defaultZone,n=e.invalid||(Number.isNaN(e.ts)?new sm(`invalid input`):null)||(t.isValid?null:f_(t));this.ts=G(e.ts)?W.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=wm(e.o)&&!e.old?e.o:t.offset(this.ts);r=__(this.ts,a),n=Number.isNaN(r.year)?new sm(`invalid input`):null,r=n?null:r,i=n?null:a}this._zone=t,this.loc=e.loc||U.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]=F_(arguments),[n,r,i,a,o,s,c]=t;return N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static utc(){let[e,t]=F_(arguments),[n,r,i,a,o,s,c]=t;return e.zone=Up.utcInstance,N_({year:n,month:r,day:i,hour:a,minute:o,second:s,millisecond:c},e)}static fromJSDate(t,n={}){let r=Dm(t)?t.valueOf():NaN;if(Number.isNaN(r))return e.invalid(`invalid input`);let i=Gp(n.zone,W.defaultZone);return i.isValid?new e({ts:r,zone:i,loc:U.fromObject(n)}):e.invalid(f_(i))}static fromMillis(t,n={}){if(wm(t))return t<-d_||t>d_?e.invalid(`Timestamp out of range`):new e({ts:t,zone:Gp(n.zone,W.defaultZone),loc:U.fromObject(n)});throw new If(`fromMillis requires a numerical input, but received a ${typeof t} with value ${t}`)}static fromSeconds(t,n={}){if(wm(t))return new e({ts:t*1e3,zone:Gp(n.zone,W.defaultZone),loc:U.fromObject(n)});throw new If(`fromSeconds requires a numerical input`)}static fromObject(t,n={}){t||={};let r=Gp(n.zone,W.defaultZone);if(!r.isValid)return e.invalid(f_(r));let i=U.fromObject(n),a=Zm(t,j_),{minDaysInFirstWeek:o,startOfWeek:s}=ym(a,i),c=W.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 Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(f&&u)throw new Pf(`Can't mix ordinal dates with month/day`);let h=m||a.weekday&&!p,ee,te,ne=__(c,l);h?(ee=O_,te=T_,ne=hm(ne,o,s)):u?(ee=k_,te=E_,ne=_m(ne)):(ee=D_,te=w_);let re=!1;for(let e of ee){let t=a[e];G(t)?re?a[e]=te[e]:a[e]=ne[e]:re=!0}let ie=(h?bm(a,o,s):u?xm(a):Sm(a))||Cm(a);if(ie)return e.invalid(ie);let[ae,oe]=v_(h?gm(a,o,s):u?vm(a):a,l,r),se=new e({ts:ae,zone:r,o:oe,loc:i});return a.weekday&&p&&t.weekday!==se.weekday?e.invalid(`mismatched weekday`,`you can't specify both a weekday of ${a.weekday} and a date of ${se.toISO()}`):se.isValid?se:e.invalid(se.invalid)}static fromISO(e,t={}){let[n,r]=dg(e);return b_(n,r,t,`ISO 8601`,e)}static fromRFC2822(e,t={}){let[n,r]=fg(e);return b_(n,r,t,`RFC 2822`,e)}static fromHTTP(e,t={}){let[n,r]=pg(e);return b_(n,r,t,`HTTP`,t)}static fromFormat(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormat requires an input string and a format`);let{locale:i=null,numberingSystem:a=null}=r,[o,s,c,l]=c_(U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0}),t,n);return l?e.invalid(l):b_(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]=bg(e);return b_(n,r,t,`SQL`,e)}static invalid(t,n=null){if(!t)throw new If(`need to specify a reason the DateTime is invalid`);let r=t instanceof sm?t:new sm(t,n);if(W.throwOnInvalid)throw new jf(r);return new e({invalid:r})}static isDateTime(e){return e&&e.isLuxonDateTime||!1}static parseFormatForOpts(e,t={}){let n=l_(e,U.fromObject(t));return n?n.map(e=>e?e.val:null).join(``):null}static expandFormat(e,t={}){return a_(bh.parseFormat(e),U.fromObject(t)).map(e=>e.val).join(``)}static resetCache(){I_=void 0,L_.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?p_(this).weekYear:NaN}get weekNumber(){return this.isValid?p_(this).weekNumber:NaN}get weekday(){return this.isValid?p_(this).weekday:NaN}get isWeekend(){return this.isValid&&this.loc.getWeekendDays().includes(this.weekday)}get localWeekday(){return this.isValid?m_(this).weekday:NaN}get localWeekNumber(){return this.isValid?m_(this).weekNumber:NaN}get localWeekYear(){return this.isValid?m_(this).weekYear:NaN}get ordinal(){return this.isValid?_m(this.c).ordinal:NaN}get monthShort(){return this.isValid?Lg.months(`short`,{locObj:this.loc})[this.month-1]:null}get monthLong(){return this.isValid?Lg.months(`long`,{locObj:this.loc})[this.month-1]:null}get weekdayShort(){return this.isValid?Lg.weekdays(`short`,{locObj:this.loc})[this.weekday-1]:null}get weekdayLong(){return this.isValid?Lg.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=Wm(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=__(s,a),u=__(c,o);return l.hour===u.hour&&l.minute===u.minute&&l.second===u.second&&l.millisecond===u.millisecond?[h_(this,{ts:s}),h_(this,{ts:c})]:[this]}get isInLeapYear(){return Vm(this.year)}get daysInMonth(){return Um(this.year,this.month)}get daysInYear(){return this.isValid?Hm(this.year):NaN}get weeksInWeekYear(){return this.isValid?Km(this.weekYear):NaN}get weeksInLocalWeekYear(){return this.isValid?Km(this.localWeekYear,this.loc.getMinDaysInFirstWeek(),this.loc.getStartOfWeek()):NaN}resolvedLocaleOptions(e={}){let{locale:t,numberingSystem:n,calendar:r}=bh.create(this.loc.clone(e),e).resolvedOptions(this);return{locale:t,numberingSystem:n,outputCalendar:r}}toUTC(e=0,t={}){return this.setZone(Up.instance(e),t)}toLocal(){return this.setZone(W.defaultZone)}setZone(t,{keepLocalTime:n=!1,keepCalendarTime:r=!1}={}){if(t=Gp(t,W.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]=v_(r,n,t)}return h_(this,{ts:e,zone:t})}else return e.invalid(f_(t))}reconfigure({locale:e,numberingSystem:t,outputCalendar:n}={}){let r=this.loc.clone({locale:e,numberingSystem:t,outputCalendar:n});return h_(this,{loc:r})}setLocale(e){return this.reconfigure({locale:e})}set(e){if(!this.isValid)return this;let t=Zm(e,j_),{minDaysInFirstWeek:n,startOfWeek:r}=ym(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 Pf(`Can't mix weekYear/weekNumber units with year/month/day or ordinals`);if(s&&a)throw new Pf(`Can't mix ordinal dates with month/day`);let u;i?u=gm({...hm(this.c,n,r),...t},n,r):G(t.ordinal)?(u={...this.toObject(),...t},G(t.day)&&(u.day=Math.min(Um(u.year,u.month),u.day))):u=vm({..._m(this.c),...t});let[d,f]=v_(u,this.o,this.zone);return h_(this,{ts:d,o:f})}plus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e);return h_(this,y_(this,t))}minus(e){if(!this.isValid)return this;let t=Ng.fromDurationLike(e).negate();return h_(this,y_(this,t))}startOf(e,{useLocaleWeeks:t=!1}={}){if(!this.isValid)return this;let n={},r=Ng.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?bh.create(this.loc.redefaultToEN(t)).formatDateTimeFromString(this,e):u_}toLocaleString(e=Bf,t={}){return this.isValid?bh.create(this.loc.clone(t),e).formatDateTime(this):u_}toLocaleParts(e={}){return this.isValid?bh.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_(a);let o=e===`extended`,s=S_(this,o,a);return D_.indexOf(a)>=3&&(s+=`T`),s+=C_(this,o,t,n,r,i,a),s}toISODate({format:e=`extended`,precision:t=`day`}={}){return this.isValid?S_(this,e===`extended`,A_(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=A_(o),(r&&D_.indexOf(o)>=3?`T`:``)+C_(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?S_(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():u_}[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 Ng.invalid(`created by diffing an invalid DateTime`);let r={locale:this.locale,numberingSystem:this.numberingSystem,...n},i=Am(t).map(Ng.normalizeUnit),a=e.valueOf()>this.valueOf(),o=Bg(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?Ig.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),P_(n,this.plus(r),{...t,numeric:`always`,units:i,unit:a})}toRelativeCalendar(t={}){return this.isValid?P_(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 If(`min requires all arguments be DateTimes`);return jm(t,e=>e.valueOf(),Math.min)}static max(...t){if(!t.every(e.isDateTime))throw new If(`max requires all arguments be DateTimes`);return jm(t,e=>e.valueOf(),Math.max)}static fromFormatExplain(e,t,n={}){let{locale:r=null,numberingSystem:i=null}=n;return s_(U.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 o_(U.fromOpts({locale:n,numberingSystem:r,defaultToEN:!0}),e)}static fromFormatParser(t,n,r={}){if(G(t)||G(n))throw new If(`fromFormatParser requires an input string and a format parser`);let{locale:i=null,numberingSystem:a=null}=r,o=U.fromOpts({locale:i,numberingSystem:a,defaultToEN:!0});if(!o.equals(n.locale))throw new If(`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):b_(s,c,r,`format ${n.format}`,t,l)}static get DATE_SHORT(){return Bf}static get DATE_MED(){return Vf}static get DATE_MED_WITH_WEEKDAY(){return Hf}static get DATE_FULL(){return Uf}static get DATE_HUGE(){return Wf}static get TIME_SIMPLE(){return Gf}static get TIME_WITH_SECONDS(){return Kf}static get TIME_WITH_SHORT_OFFSET(){return qf}static get TIME_WITH_LONG_OFFSET(){return Jf}static get TIME_24_SIMPLE(){return Yf}static get TIME_24_WITH_SECONDS(){return Xf}static get TIME_24_WITH_SHORT_OFFSET(){return Zf}static get TIME_24_WITH_LONG_OFFSET(){return Qf}static get DATETIME_SHORT(){return $f}static get DATETIME_SHORT_WITH_SECONDS(){return ep}static get DATETIME_MED(){return tp}static get DATETIME_MED_WITH_SECONDS(){return np}static get DATETIME_MED_WITH_WEEKDAY(){return rp}static get DATETIME_FULL(){return ip}static get DATETIME_FULL_WITH_SECONDS(){return ap}static get DATETIME_HUGE(){return op}static get DATETIME_HUGE_WITH_SECONDS(){return sp}};function R_(e){if(J.isDateTime(e))return e;if(e&&e.valueOf&&wm(e.valueOf()))return J.fromJSDate(e);if(e&&typeof e==`object`)return J.fromObject(e);throw new If(`Unknown datetime argument: ${e}, of type ${typeof e}`)}function z_(e){return Ql(e)?e.expression.variable?.value?.toLowerCase()===`null`:e instanceof zl}function B_(e){return B(e)===``}function V_(e){return e instanceof jl}function H_(e){let t=_d(e);if(t!==null)return t;if(ud(e)&&e instanceof Ol&&e.expression){let t=e.op?.value,n=_d(e.expression);if(n!==null)return t===`-`?-n:n}return null}function U_(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=H_(e);if(t!==null)return t;let n=B(e);if(n!==void 0){let e=Number(n);if(!isNaN(e))return e}return null}function W_(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=H_(e);if(t!==null)return Number.isInteger(t)?t:null;let n=B(e);if(n!==void 0){let e=Number(n);if(!isNaN(e)&&Number.isInteger(e))return e}return null}const G_=[`true`,`yes`,`y`,`t`,`1`],K_=[`false`,`no`,`n`,`f`,`0`];function q_(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 G_.includes(t)?!0:K_.includes(t)?!1:null}if(Ql(e)){let t=e.expression.variable?.value?.toLowerCase();if(t===`true`)return!0;if(t===`false`)return!1}let t=_d(e);if(t===0)return!1;if(t===1)return!0;let n=B(e)?.toLowerCase();if(n){if(G_.includes(n))return!0;if(K_.includes(n))return!1}return null}function J_(e){if(e==null)return null;if(typeof e==`string`)return e;let t=L(e);return t?y(t):B(e)??null}function Y_(e){if(e==null)return null;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return e.toString();let t=B(e)??null??U_(e)??q_(e);return t===null?null:t.toString()}var X_=[`yyyy-MM-dd`,`M/d/yyyy`,`d MMM yyyy`,`MMM d, yyyy`],Z_=[`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`],Q_=[`HH:mm:ss`,`HH:mm:ssZZ`,`HH:mm:ss.SSS`,`HH:mm:ss.SSSZZ`];function $_(e){if(e==null)return null;let t=typeof e==`string`?e:B(e)??null;if(t===null)return null;for(let e of Q_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISOTime({suppressMilliseconds:!0,includeOffset:r(n)})}for(let e of X_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISODate()}for(let e of Z_){let n=J.fromFormat(t,e,{setZone:!0});if(n.isValid)return n.toISO({suppressMilliseconds:!0,includeOffset:r(n)})}let n=J.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 ev(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 tv(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 nv(e){return e.increment||Tf(e.type.type_name)}function rv(e,t,n){return e?`${e}.${t}.${n}`:`${t}.${n}`}function iv(e,t,n){return n.length===1?rv(e,t,n[0]):`(${n.map(n=>rv(e,t,n)).join(`, `)})`}function av(e,t){return t.length===1?JSON.stringify(e[t[0]]?.value):`(${t.map(t=>JSON.stringify(e[t]?.value)).join(`, `)})`}function ov(e,t,n){let r=t.map(t=>e.columnNodes[t]).filter(Boolean);return r.length>0?r.map(e=>new N(M.INVALID_RECORDS_FIELD,n,e)):[new N(M.INVALID_RECORDS_FIELD,n,e.node)]}var sv=e=>e>1?`Composite PK`:`PK`;function cv(e){return Hc(Array.from(e.records),([t,{rows:n}])=>{if(Qc(n))return[];e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,$d(t,e));let r=e.cachedMergedTables.get(t),i=fv(r),a=pv(n),o=el(r.fields,`name`);return Hc(i,e=>lv(e,n,a,o,r))})}function lv(e,t,n,r,i){let a=mv(e,n,r,i,t);if(!Qc(a))return a;let o=Do(e.map(e=>r[e])),s=o.every(e=>e&&nv(e)),[c,l]=b(t,t=>tv(t.values,e,o)),u=s?[]:uv(c,e,i),d=dv(l,e,o,i);return[...u,...d]}function uv(e,t,n){if(Qc(e))return[];let r=`NULL in ${sv(t.length)}: ${iv(n.schemaName,n.name,t)} cannot be NULL`;return Hc(e,e=>ov(e,t,r))}function dv(e,t,n,r){return Hc(Ac(qc(e,e=>ev(e.values,t,n)),e=>e.length>1),e=>{let n=sv(t.length),i=iv(r.schemaName,r.name,t);return Hc(e.slice(1),e=>ov(e,t,`Duplicate ${n}: ${i} = ${av(e.values,t)}`))})}function fv(e){return[...e.fields.filter(e=>e.pk).map(e=>[e.name]),...e.indexes.filter(e=>e.pk).map(e=>e.columns.map(e=>e.value))]}function pv(e){return new Set(e.flatMap(e=>Object.keys(e.values)))}function mv(e,t,n,r,i){let a=Cc(e,Array.from(t));if(Qc(a))return[];let o=a.filter(e=>{let t=n[e];return t&&!t.increment&&!Tf(t.type.type_name)&&!t.dbdefault});if(Qc(o))return[];let s=`${sv(o.length)}: Column ${iv(r.schemaName,r.name,o)} is missing from record and has no default value`;return i.map(e=>new N(M.INVALID_RECORDS_FIELD,s,e.node))}var hv=e=>e>1?`Composite UNIQUE`:`UNIQUE`;function gv(e){return Hc(Array.from(e.records),([t,{rows:n}])=>{e.cachedMergedTables.has(t)||e.cachedMergedTables.set(t,$d(t,e));let r=e.cachedMergedTables.get(t);if(Qc(n))return[];let i=_v(r),a=el(r.fields,`name`);return Hc(i,e=>vv(n,e,Do(e.map(e=>a[e])),r))})}function _v(e){return[...e.fields.filter(e=>e.unique).map(e=>[e.name]),...e.indexes.filter(e=>e.unique).map(e=>e.columns.map(e=>e.value))]}function vv(e,t,n,r){return Hc(Ac(qc(e.filter(e=>!tv(e.values,t,n)),e=>ev(e.values,t,n)),e=>e.length>1),e=>{let n=hv(t.length),i=iv(r.schemaName,r.name,t);return Hc(e.slice(1),e=>ov(e,t,`Duplicate ${n}: ${i} = ${av(e.values,t)}`))})}function yv(e){let t=[...e.ref.values(),...Hc(Array.from(e.tables.values()),t=>ef(t,e))],n=bv(e);return Hc(t,e=>Cv(e,n))}function bv(e){let t=new Map;for(let n of e.tables.values()){let r=xv(n.schemaName,n.name),i=e.records.get(n)?.rows||[];e.cachedMergedTables.has(n)||e.cachedMergedTables.set(n,$d(n,e));let a=e.cachedMergedTables.get(n);t.set(r,{mergedTable:a,rows:i})}return t}function xv(e,t){return e?`${e}.${t}`:`${se}.${t}`}function Sv(e,t,n,r){if(Qc(e.rows))return[];let i=new Set(t.rows.map(e=>ev(e.values,r.fieldNames)));return Hc(e.rows.filter(e=>!tv(e.values,n.fieldNames)).filter(e=>{let t=ev(e.values,n.fieldNames);return!i.has(t)}),i=>{let a=iv(e.mergedTable.schemaName,e.mergedTable.name,n.fieldNames),o=iv(t.mergedTable.schemaName,t.mergedTable.name,r.fieldNames),s=`FK violation: ${a} = ${av(i.values,n.fieldNames)} does not exist in ${o}`;return ov(i,n.fieldNames,s)})}function Cv(e,t){if(!e.endpoints)return[];let[n,r]=e.endpoints,i=t.get(xv(n.schemaName,n.tableName)),a=t.get(xv(r.schemaName,r.tableName));return!i||!a?[]:wv(i,a,n,r)}function wv(e,t,n,r){let i=n.relation,a=r.relation;return i===`1`&&a===`1`||i===`*`&&a===`*`?[...Sv(e,t,n,r),...Sv(t,e,r,n)]:i===`*`&&a===`1`?Sv(e,t,n,r):i===`1`&&a===`*`?Sv(t,e,r,n):[]}var Tv=class{constructor(e){this.env=e,this.tableToRecordMap=new Map}interpret(e){let t=[],n=[];for(let r of e){let{table:e,mergedColumns:i}=Ev(r,this.env),a=this.tableToRecordMap.get(e);if(a){t.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,a)),t.push(new N(M.DUPLICATE_RECORDS_FOR_TABLE,`Duplicate Records blocks for the same Table '${e.name}' - A Table can only have one Records block`,r));continue}this.tableToRecordMap.set(e,r),this.env.records.has(e)||this.env.records.set(e,{element:r,rows:[]});let o=this.env.records.get(e);for(let e of r.body.body){let r=e,a=Dv(r,i,this.env);t.push(...a.getErrors()),n.push(...a.getWarnings());let s=a.getValue();s.row&&o.rows.push({values:s.row,node:r,columnNodes:s.columnNodes})}}let r=this.validateConstraints();return n.push(...r),new P(void 0,t,n)}validateConstraints(){let e=[];return e.push(...cv(this.env).map(e=>e.toWarning())),e.push(...gv(this.env).map(e=>e.toWarning())),e.push(...yv(this.env).map(e=>e.toWarning())),e}};function Ev(e,t){let n=e.name,r=e.parent;if(r instanceof w){let e=t.tables.get(r),i=$d(e,t);return n?{table:e,mergedTable:i,mergedColumns:n.elementList.map(e=>i.fields.find(t=>t.name===R(e)))}:{table:e,mergedTable:i,mergedColumns:i.fields}}let i=Sd(n),a=y(i.variables).referee.declaration,o=t.tables.get(a),s=$d(o,t);return{table:o,mergedTable:s,mergedColumns:i.args.map(e=>s.fields.find(t=>t.name===R(e)))}}function Dv(e,t,n){let r=[],i=[],a={},o={},s=e.callee instanceof Nl?e.callee.elementList:[e.callee];if(s.length!==t.length)return r.push(new N(M.INVALID_RECORDS_FIELD,`Expected ${t.length} values but got ${s.length}`,e)),new P({row:null,columnNodes:{}},r,i);for(let e=0;e<t.length;e++){let c=s[e],l=t[e];o[l.name]=c;let u=kv(c,l,n);r.push(...u.getErrors()),i.push(...u.getWarnings());let d=u.getValue();d!==null&&(a[l.name]=d)}return new P({row:a,columnNodes:o},r,i)}function Ov(e,t){return e instanceof jl?e.value?.value||``:!isNaN(e.start)&&!isNaN(e.end)?t.slice(e.start,e.end):``}function kv(e,t,n){let r=t.type.type_name.split(`(`)[0],{increment:i,not_null:a,dbdefault:o}=t,s=t.type.isEnum||!1,c=kf(r,s),l=Y_(e),u=l===null?Ov(e,n.source):l,d=l===null?`expression`:c;if(e instanceof jl)return new P({value:e.value?.value||``,type:`expression`},[],[]);if(z_(e)||B_(e)&&!Sf(r)){let n=o&&o.value.toString().toLowerCase()!==`null`,s=Tf(r);return a&&!n&&!i&&!s?new P({value:null,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`NULL not allowed for non-nullable column '${t.name}' without default and increment`,e)]):new P({value:null,type:c},[],[])}if(s){let r=([...n.enums.values()].find(e=>e.schemaName===t.type.schemaName&&e.name===t.type.type_name)?.values||[]).map(e=>e.name),i=B(e);return i===void 0&&(i=(L(e)??[]).pop()),r.includes(i)?new P({value:i,type:c},[],[]):new P({value:i,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid enum value for column '${t.name}'`,e)])}if(bf(r)){let n=U_(e);if(n===null)return new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid numeric value for column '${t.name}'`,e)]);if(vf(r)&&!Number.isInteger(n))return new P({value:Math.floor(n),type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid integer value ${n} for column '${t.name}': expected integer, got decimal`,e)]);if(yf(r)&&t.type.numericParams){let{precision:r,scale:i}=t.type.numericParams,a=n.toString().split(`.`),o=a[0].replace(/^-/,``),s=a[1]||``,l=o.length+s.length,u=s.length;if(l>r)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds precision: expected at most ${r} total digits, got ${l}`,e)]);if(u>i)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`Numeric value ${n} for column '${t.name}' exceeds scale: expected at most ${i} decimal digits, got ${u}`,e)])}return new P({value:n,type:c},[],[])}if(xf(r)){let n=q_(e);return n===null?new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid boolean value for column '${t.name}'`,e)]):new P({value:n,type:c},[],[])}if(wf(r)){let n=$_(e);return n===null?new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid datetime value for column '${t.name}', 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 P({value:n,type:c},[],[])}if(Sf(r)){let n=Y_(e);if(n===null)return new P({value:u,type:d},[],[new ru(M.INVALID_RECORDS_FIELD,`Invalid string value for column '${t.name}'`,e)]);if(t.type.lengthParam){let{length:r}=t.type.lengthParam,i=new TextEncoder().encode(n).length;if(i>r)return new P({value:n,type:c},[],[new ru(M.INVALID_RECORDS_FIELD,`String value for column '${t.name}' exceeds maximum length: expected at most ${r} bytes (UTF-8), got ${i} bytes`,e)])}return new P({value:n,type:`string`},[],[])}return new P({value:u,type:d},[],[])}function Av(e){return{...e,fields:e.fields.map(e=>({...e,type:{...e.type,isEnum:void 0,lengthParam:void 0,numericParams:void 0}}))}}function jv(e){for(let t of e.diagramViews.values()){let n=t.visibleEntities,r=e.diagramViewWildcards.get(t);if(r){if(r.has(`tables`)||r.has(`schemas`)){n.tables=[],n.tableGroups=[],n.schemas=[];continue}r.has(`tableGroups`)&&n.tableGroups&&n.tableGroups.length===0&&(n.tableGroups=Array.from(e.tableGroups.values()).map(e=>({name:e.name})))}}}function Mv(e,t){let n=[];for(let[t,{element:r,rows:i}]of e.records){if(!i.length)continue;let e=Object.keys(i[0].columnNodes);n.push({schemaName:t.schemaName||void 0,tableName:t.name,columns:e,token:V(r),values:i.map(t=>e.map(e=>{let n=t.values[e];return n?{value:n.value,type:n.type}:{value:null,type:`expression`}}))})}return{schemas:[],tables:Array.from(e.tables.values()).map(Av),notes:Array.from(e.notes.values()),refs:Array.from(e.ref.values()),enums:Array.from(e.enums.values()),tableGroups:Array.from(e.tableGroups.values()),aliases:e.aliases,project:Array.from(e.project.values())[0]||{},tablePartials:Array.from(e.tablePartials.values()).map(Av),records:n,diagramViews:Array.from(e.diagramViews.values()),token:V(t)}}var Nv=class{constructor(e){this.ast=e,this.env={schema:[],tables:new Map,notes:new Map,refIds:{},ref:new Map,enums:new Map,tableOwnerGroup:{},tableGroups:new Map,aliases:[],project:new Map,tablePartials:new Map,records:new Map,recordsElements:[],cachedMergedTables:new Map,source:e.source,diagramViews:new Map,diagramViewWildcards:new Map,diagramViewExplicitlySet:new Map}}interpret(){let e=this.ast.body.flatMap(e=>{switch(Bu(g,e.type?.value??``)){case g.Table:return new af(e,this.env).interpret();case g.Note:return new lf(e,this.env).interpret();case g.Ref:return new rf(e,this.env).interpret();case g.TableGroup:return new of(e,this.env).interpret();case g.TablePartial:return new sf(e,this.env).interpret();case g.Enum:return new nf(e,this.env).interpret();case g.Project:return new cf(e,this.env).interpret();case g.DiagramView:return new tf(e,this.env).interpret();case g.Records:return this.env.recordsElements.push(e),[];default:return[]}}),t=[];if(this.env.recordsElements.length){let n=new Tv(this.env).interpret(this.env.recordsElements);e.push(...n.getErrors()),t.push(...n.getWarnings())}return jv(this.env),new P(Mv(this.env,this.ast),e,t)}},Pv=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===`
4
+ `?(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 _l.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(_l.create(x.EOF,this.filepath,this.start,this.current,``,!1)),this.gatherTrivia(),this.gatherInvalid(),new P(this.tokens,this.errors)}scanTokens(){for(;!this.isAtEnd();){let e=this.advance();switch(e){case` `:this.addToken(x.SPACE);break;case`\r`:break;case`
5
+ `:this.addToken(x.NEWLINE);break;case` `:this.addToken(x.TAB);break;case`,`:this.addToken(x.COMMA);break;case`(`:this.addToken(x.LPAREN);break;case`)`:this.addToken(x.RPAREN);break;case`[`:this.addToken(x.LBRACKET);break;case`]`:this.addToken(x.RBRACKET);break;case`{`:this.addToken(x.LBRACE);break;case`}`:this.addToken(x.RBRACE);break;case`;`:this.addToken(x.SEMICOLON);break;case`:`:this.addToken(x.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(x.WILDCARD);break;default:if(hl(e)){this.operator(e);break}if(Iu(e)){this.identifier();break}if(Lu(e)){this.numericLiteralOrIdentifier();break}this.addToken(x.OP,!0),this.errors.push(new N(M.UNKNOWN_SYMBOL,`Unexpected token '${e}'`,this.createToken(x.OP,!0)));break}this.start={...this.current}}}gatherTrivia(){let e=!0,t=[],n,r=[];for(let i of this.tokens)ml(i)?(t.push(i),i.kind===x.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&&ql(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];ql(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(`
6
6
  `))&&!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(`
7
- `)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new N(M.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(vl.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(b.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(b.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(b.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(b.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(b.SINGLE_LINE_COMMENT,`
8
- `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(b.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&zu(this.peek());)this.advance();this.addToken(b.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(b.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(b.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=t?1:0,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Lu(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Lu(this.peek());)this.advance();if(this.isAtEnd()||!zu(this.peek()))return this.addToken(b.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(b.NUMERIC_LITERAL);if(!t&&!zu(this.peek()))return this.addToken(b.NUMERIC_LITERAL);if(!t&&!Lu(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||zu(this.peek()));)this.advance();let e=this.createToken(b.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new N(M.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&zu(this.peek());)this.advance();let e=this.createToken(b.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&zu(this.peek());)this.advance();this.addToken(b.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
7
+ `)&&!n){let t=this.createToken(e,!0);this.tokens.push(t),this.errors.push(new N(M.UNEXPECTED_NEWLINE,`Invalid newline encountered while parsing`,t));return}a&&this.match(t),this.tokens.push(_l.create(e,this.filepath,this.start,this.current,o,!1))}singleLineStringLiteral(){this.consumeUntil(x.STRING_LITERAL,`'`,{allowNewline:!1,allowEof:!1,raw:!1})}multilineStringLiteral(){this.consumeUntil(x.STRING_LITERAL,`'''`,{allowNewline:!0,allowEof:!1,raw:!1})}functionExpression(){this.consumeUntil(x.FUNCTION_EXPRESSION,"`",{allowNewline:!0,allowEof:!1,raw:!0})}quotedVariable(){this.consumeUntil(x.QUOTED_STRING,`"`,{allowNewline:!1,allowEof:!1,raw:!1})}singleLineComment(){this.consumeUntil(x.SINGLE_LINE_COMMENT,`
8
+ `,{allowNewline:!0,allowEof:!0,raw:!0,consumeStopSequence:!1})}multilineComment(){this.consumeUntil(x.MULTILINE_COMMENT,`*/`,{allowNewline:!0,allowEof:!1,raw:!0})}identifier(){for(;!this.isAtEnd()&&zu(this.peek());)this.advance();this.addToken(x.IDENTIFIER)}operator(e){switch(e){case`<`:[`>`,`=`].includes(this.peek())&&this.advance();break;case`>`:this.peek()===`=`&&this.advance();break;case`=`:this.peek()===`=`&&this.advance();break;case`!`:this.peek()===`=`&&this.advance();break;default:break}this.addToken(x.OP)}numericLiteralOrIdentifier(){let e=0;if(this.isAtEnd())return this.addToken(x.NUMERIC_LITERAL);for(;!this.isAtEnd();){let t=this.check(`.`);if(e+=t?1:0,e>1)break;if(this.check(`e`)||this.check(`E`)){let e=this.peek(1),t=e===`+`||e===`-`,n=t?this.peek(2):e;if(n&&Lu(n)){for(this.advance(),t&&this.advance();!this.isAtEnd()&&Lu(this.peek());)this.advance();if(this.isAtEnd()||!zu(this.peek()))return this.addToken(x.NUMERIC_LITERAL);break}break}if(!t&&this.current.offset===this.text.length-1)return this.advance(),this.addToken(x.NUMERIC_LITERAL);if(!t&&!zu(this.peek()))return this.addToken(x.NUMERIC_LITERAL);if(!t&&!Lu(this.peek()))break;this.advance()}if(e>0){for(;!this.isAtEnd()&&(this.check(`.`)||zu(this.peek()));)this.advance();let e=this.createToken(x.NUMERIC_LITERAL,!0);this.tokens.push(e),this.errors.push(new N(M.UNKNOWN_TOKEN,`Invalid number`,e))}else{for(;!this.isAtEnd()&&zu(this.peek());)this.advance();let e=this.createToken(x.IDENTIFIER,!1);this.tokens.push(e)}}colorLiteral(){for(;!this.isAtEnd()&&zu(this.peek());)this.advance();this.addToken(x.COLOR_LITERAL)}escapedString(){let e={column:this.current.column-1,offset:this.current.offset-1,line:this.current.line};if(this.isAtEnd())return`\\`;switch(this.advance()){case`\r`:return this.check(`
9
9
  `)&&this.advance(),``;case`
10
10
  `:return``;case`t`:return` `;case`n`:return`
11
- `;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!zu(this.peek()))return this.errors.push(new N(M.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,vl.create(b.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}};let Fv=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var Iv=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===Fv.ListExpression&&(this.numberOfNestedLBrackets+=1),e===Fv.GroupExpression&&(this.numberOfNestedLParens+=1),e===Fv.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===Fv.ListExpression&&--this.numberOfNestedLBrackets,e===Fv.GroupExpression&&--this.numberOfNestedLParens,e===Fv.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return v(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case b.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[Fv.GroupExpression,Fv.ListExpression].includes(e));break;case b.RPAREN:if(this.isWithinGroupExpressionContext())return Fv.GroupExpression;break;case b.RBRACE:if(this.isWithinBlockExpressionContext())return Fv.BlockExpression;break;case b.RBRACKET:if(this.isWithinListExpressionContext())return Fv.ListExpression;break;default:break}}},Lv=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},Y=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Rv=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Iv,this.synchronizeProgram=()=>{let e=this.peek();e.kind===b.EOF?this.logError(e,M.UNEXPECTED_EOF,`Unexpected EOF`):k(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Wl(e)||this.check(b.COLON,b.LBRACE,b.LBRACKET))break;k(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(b.COLON,b.LBRACE,b.LBRACKET))break;k(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Fv.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(E,e);try{this.consume(`Expect an opening brace '{'`,b.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(b.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof Y))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,b.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(b.RBRACE))for(k(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(b.RBRACE)||bl(this.previous(),e))break;k(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Fv.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Pl,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(Ml,e);try{this.consume(`Expect an opening parenthesis '('`,b.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(b.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(b.RPAREN);)try{this.consume(`Expect a comma ','`,b.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof Y))throw t;if(t.partialNode instanceof x&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new Y(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,b.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(b.RPAREN,b.COMMA))break;k(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Fv.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(D,e);try{this.consume(`Expect an opening bracket '['`,b.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(b.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(b.RBRACKET);)try{this.consume(`Expect a comma ','`,b.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(n.partialNode instanceof x&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,b.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(b.COMMA,b.RBRACKET))break;k(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(b.COMMA,b.RBRACKET,b.COLON))break;k(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(b.COMMA,b.RBRACKET))break;k(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Lv(n,r)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===b.EOF}advance(){return this.isAtEnd()?v(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?v(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),M.UNEXPECTED_TOKEN,e),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(k(this.peek()),this.logError(this.advance(),M.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)k(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),n=this.nodeFactory.create(C,{body:e,eof:t,source:this.source});return this.gatherInvalid(),new P({ast:n,tokens:this.tokens},this.errors)}program(){let e=[];for(;!this.isAtEnd();)try{let t=this.elementDeclaration();e.push(t)}catch(t){if(!(t instanceof Y))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,b.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof Y?new Y(e.token,t(),e.handlerContext):e}if(!this.check(b.COLON,b.LBRACE,b.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Wl(this.peek()))if(e.as=this.advance(),this.check(b.COLON,b.LBRACE,b.LBRACKET))this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(b.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof Y?(e.attributeList=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,b.LBRACE,b.COLON))return t();try{if(this.match(b.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof w?(k(t),this.logError(t,M.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,b.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof Y?(e.type=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,b.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof Y?(e.bodyColon=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof w?this.errors.push(new N(M.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}expression(){let e={args:[]},t=()=>Ul(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(T,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof Y?(e.callee=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){xl(this.previous())||this.logError(n,M.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof Y?(n=r.partialNode,e.args.push(n),new Y(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||yl(this.previous()))return!0;let e=this.peek().kind;return[b.RBRACE,b.RBRACKET,b.RPAREN,b.COMMA,b.COLON].includes(e)}commaExpression(){let e=this.check(b.COMMA)?this.nodeFactory.create(zl,{prevToken:this.previous()}):this.normalExpression();if(!this.check(b.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));break}if(this.check(b.COMMA)){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof Y?(e.partialNode&&t.elementList.push(e.partialNode),new Y(e.token,this.nodeFactory.create(Nl,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(b.COMMA));return this.nodeFactory.create(Nl,t)}shouldStopCommaExpression(){if(this.isAtEnd()||yl(this.previous()))return!0;let e=this.peek().kind;return[b.RBRACE,b.LBRACE,b.RBRACKET,b.LBRACKET,b.RPAREN,b.LPAREN,b.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===b.LPAREN){let{left:r}=Wv(n);if(r<e||bl(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(O,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(O,{callee:t,argumentList:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(n.kind===b.LBRACKET){if(xl(this.previous()))break;try{t=this.nodeFactory.create(Bl,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(Bl,{expression:t,indexer:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(_l(n)){let r=n,i=Wv(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Al,{expression:t,op:r})}else{let n=Bv(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(_l(this.peek())){let t={};t.op=this.peek();let n=Hv(t.op);if(n.right===null)throw this.logError(t.op,M.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new Y(t.op,this.nodeFactory.create(zl,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof Y?(t.expression=e.partialNode,new Y(e.token,this.nodeFactory.create(Ol,t),e.handlerContext)):e}e=this.nodeFactory.create(Ol,t)}else if(e=this.extractOperand(),e instanceof zl)throw new Y(this.peek(),this.nodeFactory.create(zl,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(b.WILDCARD)?(this.advance(),this.nodeFactory.create(Il,{token:this.previous()})):this.check(b.NUMERIC_LITERAL,b.STRING_LITERAL,b.COLOR_LITERAL,b.QUOTED_STRING,b.IDENTIFIER)?this.primaryExpression():this.check(b.FUNCTION_EXPRESSION)?this.functionExpression():this.check(b.LBRACKET)?this.listExpression():this.check(b.LBRACE)?this.blockExpression():this.check(b.LPAREN)?this.tupleExpression():(this.peek().kind===b.EOF?this.logError(this.peek(),M.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),M.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(zl,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,b.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(jl,e),t.handlerContext):t}return this.nodeFactory.create(jl,e)}canBeField(){return this.peek().kind===b.IDENTIFIER&&this.peek(1).kind===b.COLON}primaryExpression(){if(this.match(b.COLOR_LITERAL,b.STRING_LITERAL,b.NUMERIC_LITERAL))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Fl,{literal:this.previous()})});if(this.match(b.QUOTED_STRING,b.IDENTIFIER))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Ll,{variable:this.previous()})});throw this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect a variable or literal`),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(b.COLON,b.RBRACKET,b.COMMA)){let t=this.peek();this.logError(t,M.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(El,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof Y))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new Y(t.token,this.nodeFactory.create(Dl,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(b.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(Dl,e)}attributeValue(){let e;try{e=this.peek().kind===b.IDENTIFIER&&this.peek(1).kind===b.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof Y)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==b.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(b.COLON,b.COMMA,b.RBRACKET);)try{this.consume(`Expect an identifier`,b.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(El,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(El,{identifiers:e})}logError(e,t,n){this.errors.push(new N(t,n,e))}},zv={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Bv(e){return zv[e.value]||{left:null,right:null}}var Vv={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function Hv(e){return Vv[e.value]||{left:null,right:null}}var Uv={"(":{left:14,right:null}};function Wv(e){return Uv[e.value]||{left:null,right:null}}function Gv(e,t){return e.getOffsetAt(t)}var Kv=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(!e?.referee)continue;let t;if(e.referee?.declaration&&[S.PRIMARY_EXPRESSION,S.VARIABLE].includes(e?.kind)&&({declaration:t}=e.referee),t){let{startPos:e,endPos:r}=t;return[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:r.column+1,endLineNumber:r.line+1},uri:n}]}}return[]}};let X=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}({}),Z=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),qv=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});var Jv=class{constructor(e){this.compiler=e}provideDiagnostics(){let e=[],t=this.compiler.parse._(),n=t.getErrors();for(let t of n)e.push(this.createDiagnostic(t,`error`));let r=t.getWarnings();for(let t of r)e.push(this.createDiagnostic(t,`warning`));return e}provideErrors(){return this.compiler.parse._().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(){return this.compiler.parse._().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(){return this.provideDiagnostics().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}}getSeverityValue(e){return e===`error`?qv.Error:qv.Warning}},Yv=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[S.ELEMENT_DECLARATION,S.FUNCTION_APPLICATION,S.PRIMARY_EXPRESSION].includes(e?.kind)){let{symbol:t}=e;if(t?.references.length)return t.references.map(({startPos:e,endPos:t})=>({range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}))}}return[]}};function Xv(e,t){return e>=t.start&&e<t.end}function Zv(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function Qv(e){return Zv(e)?e:`"${ey(e)}"`}function $v(e){let t=``,n=0,r={n:`
11
+ `;case`\\`:return`\\`;case`r`:return`\r`;case`'`:return`'`;case`"`:return`"`;case"`":return"`";case`0`:return`\0`;case`b`:return`\b`;case`v`:return`\v`;case`f`:return`\f`;case` `:return`\\ `;case`u`:{let t=``;for(let n=0;n<=3;n+=1){if(this.isAtEnd()||!zu(this.peek()))return this.errors.push(new N(M.INVALID_ESCAPE_SEQUENCE,`Invalid unicode escape sequence '\\u${t}', only unicode escape sequences of the form '\\uHHHH' where H is a hexadecimal number are allowed`,_l.create(x.STRING_LITERAL,this.filepath,e,this.current,`\\u${t}`,!0))),`\\u${t}`;t+=this.advance()}return String.fromCharCode(parseInt(t,16))}default:return this.text[this.current.offset-1]}}};let Fv=function(e){return e[e.ListExpression=0]=`ListExpression`,e[e.GroupExpression=1]=`GroupExpression`,e[e.BlockExpression=2]=`BlockExpression`,e}({});var Iv=class{constructor(){this.stack=[],this.numberOfNestedLParens=0,this.numberOfNestedLBrackets=0,this.numberOfNestedLBraces=0}push(e){this.stack.push(e),e===Fv.ListExpression&&(this.numberOfNestedLBrackets+=1),e===Fv.GroupExpression&&(this.numberOfNestedLParens+=1),e===Fv.BlockExpression&&(this.numberOfNestedLBraces+=1)}pop(){let e=this.stack.pop();return e===Fv.ListExpression&&--this.numberOfNestedLBrackets,e===Fv.GroupExpression&&--this.numberOfNestedLParens,e===Fv.BlockExpression&&--this.numberOfNestedLBraces,e}top(){return y(this.stack)}isWithinGroupExpressionContext(){return this.numberOfNestedLParens>0}isWithinListExpressionContext(){return this.numberOfNestedLBrackets>0}isWithinBlockExpressionContext(){return this.numberOfNestedLBraces>0}withContextDo(e,t){return()=>{this.push(e);try{return t()}finally{this.pop()}}}findHandlerContext(e,t){if(!(this.numberOfNestedLBraces<=0&&this.numberOfNestedLBrackets<=0&&this.numberOfNestedLParens<=0))for(let n=t;n<e.length-1;n+=1)switch(e[n].kind){case x.COMMA:if(this.isWithinGroupExpressionContext()||this.isWithinListExpressionContext())return[...this.stack].reverse().find(e=>[Fv.GroupExpression,Fv.ListExpression].includes(e));break;case x.RPAREN:if(this.isWithinGroupExpressionContext())return Fv.GroupExpression;break;case x.RBRACE:if(this.isWithinBlockExpressionContext())return Fv.BlockExpression;break;case x.RBRACKET:if(this.isWithinListExpressionContext())return Fv.ListExpression;break;default:break}}},Lv=class{constructor(e,t){this.generator=e,this.filepath=t}create(e,t){return new e(t,this.generator.nextId(),this.filepath)}},Y=class{constructor(e,t,n){this.token=e,this.partialNode=t,this.handlerContext=n}},Rv=class{constructor(e,t,n,r){this.current=0,this.errors=[],this.contextStack=new Iv,this.synchronizeProgram=()=>{let e=this.peek();e.kind===x.EOF?this.logError(e,M.UNEXPECTED_EOF,`Unexpected EOF`):k(this.advance())},this.synchronizeElementDeclarationName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(Wl(e)||this.check(x.COLON,x.LBRACE,x.LBRACKET))break;k(e),this.advance()}},this.synchronizeElementDeclarationAlias=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COLON,x.LBRACE,x.LBRACKET))break;k(e),this.advance()}},this.blockExpression=this.contextStack.withContextDo(Fv.BlockExpression,()=>{let e={body:[]},t=()=>this.nodeFactory.create(E,e);try{this.consume(`Expect an opening brace '{'`,x.LBRACE),e.blockOpenBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}for(;!this.isAtEnd()&&!this.check(x.RBRACE);)try{e.body.push(this.canBeField()?this.fieldDeclaration():this.expression())}catch(n){if(!(n instanceof Y))throw n;if(e.body.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeBlock()}try{this.consume(`Expect a closing brace '}'`,x.RBRACE),e.blockCloseBrace=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeBlock()}return t()}),this.synchronizeBlock=()=>{if(!this.check(x.RBRACE))for(k(this.advance());!this.isAtEnd();){let e=this.peek();if(this.check(x.RBRACE)||yl(this.previous(),e))break;k(e),this.advance()}},this.tupleExpression=this.contextStack.withContextDo(Fv.GroupExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(Pl,{groupOpenParen:e.tupleOpenParen,groupCloseParen:e.tupleCloseParen,expression:e.elementList[0]}),n=()=>this.nodeFactory.create(Ml,e);try{this.consume(`Expect an opening parenthesis '('`,x.LPAREN),e.tupleOpenParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,n(),e.handlerContext);this.synchronizeTuple()}if(!this.isAtEnd()&&!this.check(x.RPAREN))try{e.elementList.push(this.normalExpression())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeTuple()}for(;!this.isAtEnd()&&!this.check(x.RPAREN);)try{this.consume(`Expect a comma ','`,x.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.normalExpression())}catch(t){if(!(t instanceof Y))throw t;if(t.partialNode instanceof S&&e.elementList.push(t.partialNode),!this.canHandle(t))throw new Y(t.token,n(),t.handlerContext);this.synchronizeTuple()}try{this.consume(`Expect a closing parenthesis ')'`,x.RPAREN),e.tupleCloseParen=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,n(),e.handlerContext);this.synchronizeTuple()}return e.elementList.length===1?t():n()}),this.synchronizeTuple=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.RPAREN,x.COMMA))break;k(e),this.advance()}},this.listExpression=this.contextStack.withContextDo(Fv.ListExpression,()=>{let e={elementList:[],commaList:[]},t=()=>this.nodeFactory.create(D,e);try{this.consume(`Expect an opening bracket '['`,x.LBRACKET),e.listOpenBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}if(!this.isAtEnd()&&!this.check(x.RBRACKET))try{e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}for(;!this.isAtEnd()&&!this.check(x.RBRACKET);)try{this.consume(`Expect a comma ','`,x.COMMA),e.commaList.push(this.previous()),e.elementList.push(this.attribute())}catch(n){if(!(n instanceof Y))throw n;if(n.partialNode instanceof S&&e.elementList.push(n.partialNode),!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeList()}try{this.consume(`Expect a closing bracket ']'`,x.RBRACKET),e.listCloseBracket=this.previous()}catch(e){if(!(e instanceof Y))throw e;if(!this.canHandle(e))throw new Y(e.token,t(),e.handlerContext);this.synchronizeList()}return t()}),this.synchronizeList=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET))break;k(e),this.advance()}},this.synchronizeAttributeName=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET,x.COLON))break;k(e),this.advance()}},this.synchronizeAttributeValue=()=>{for(;!this.isAtEnd();){let e=this.peek();if(this.check(x.COMMA,x.RBRACKET))break;k(e),this.advance()}},this.source=e,this.tokens=t,this.nodeFactory=new Lv(n,r)}isAtEnd(){return this.current>=this.tokens.length||this.tokens[this.current].kind===x.EOF}advance(){return this.isAtEnd()?y(this.tokens):this.tokens[this.current++]}peek(e=0){return e+this.current>=this.tokens.length?y(this.tokens):this.tokens[this.current+e]}match(...e){let t=this.check(...e);return t&&this.advance(),t}check(...e){let t=this.peek();return e.includes(t.kind)}previous(){return this.tokens[this.current-1]}canHandle(e){return e.handlerContext===void 0||e.handlerContext===this.contextStack.top()}consume(e,...t){if(!this.match(...t))throw this.logError(this.peek(),M.UNEXPECTED_TOKEN,e),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}discardUntil(e,...t){if(this.isAtEnd()||!this.check(...t)){for(k(this.peek()),this.logError(this.advance(),M.UNEXPECTED_TOKEN,e);!this.isAtEnd()&&!this.check(...t);)k(this.advance());return!this.isAtEnd()}return!0}gatherInvalid(){let e=[],t=[],n,r=0;for(;r<this.tokens.length&&this.tokens[r].isInvalid;r+=1)t.push(this.tokens[r]);for(n=this.tokens[r],n.leadingInvalid=[...t,...n.leadingInvalid],e.push(n),r+=1;r<this.tokens.length;r+=1){let t=this.tokens[r];t.isInvalid?n.trailingInvalid.push(t):(n=t,e.push(n))}this.tokens=e}parse(){let e=this.program(),t=this.advance(),n=this.nodeFactory.create(Tl,{body:e,eof:t,source:this.source});return this.gatherInvalid(),new P({ast:n,tokens:this.tokens},this.errors)}program(){let e=[];for(;!this.isAtEnd();)try{let t=this.elementDeclaration();e.push(t)}catch(t){if(!(t instanceof Y))throw t;e.push(t.partialNode),this.synchronizeProgram()}return e}elementDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.type=this.previous()}catch(e){throw e instanceof Y?new Y(e.token,t(),e.handlerContext):e}if(!this.check(x.COLON,x.LBRACE,x.LBRACKET))try{e.name=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.name=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationName()}if(Wl(this.peek()))if(e.as=this.advance(),this.check(x.COLON,x.LBRACE,x.LBRACKET))this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect an alias`);else try{e.alias=this.normalExpression()}catch(n){if(!(n instanceof Y))throw n;if(e.alias=n.partialNode,!this.canHandle(n))throw new Y(n.token,t(),n.handlerContext);this.synchronizeElementDeclarationAlias()}try{e.attributeList=this.check(x.LBRACKET)?this.listExpression():void 0}catch(n){throw n instanceof Y?(e.attributeList=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(!this.discardUntil(`Expect an opening brace '{' or a colon ':'`,x.LBRACE,x.COLON))return t();try{if(this.match(x.COLON)){e.bodyColon=this.previous();let t=this.expression();t instanceof w?(k(t),this.logError(t,M.UNEXPECTED_ELEMENT_DECLARATION,`An element's simple body must not be an element declaration`)):e.body=t}else e.body=this.blockExpression()}catch(n){throw n instanceof Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}fieldDeclaration(){let e={},t=()=>this.nodeFactory.create(w,e);try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.type=this.previous()}catch(n){throw n instanceof Y?(e.type=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{this.consume(`Expect a colon ':'`,x.COLON),e.bodyColon=this.previous()}catch(n){throw n instanceof Y?(e.bodyColon=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}try{let t=this.expression();t instanceof w?this.errors.push(new N(M.INVALID_ELEMENT_IN_SIMPLE_BODY,`Simple body cannot be an element declaration`,t)):e.body=t}catch(n){throw n instanceof Y?(e.body=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}return this.nodeFactory.create(w,e)}expression(){let e={args:[]},t=()=>Ul(e.callee,e.args,this.nodeFactory)??this.nodeFactory.create(T,e);try{e.callee=this.commaExpression()}catch(n){throw n instanceof Y?(e.callee=n.partialNode,new Y(n.token,t(),n.handlerContext)):n}if(this.shouldStopFunctionApplication())return t();let n=e.callee;for(;!this.shouldStopFunctionApplication();){bl(this.previous())||this.logError(n,M.MISSING_SPACES,`Expect a following space`);try{n=this.commaExpression(),e.args.push(n)}catch(r){throw r instanceof Y?(n=r.partialNode,e.args.push(n),new Y(r.token,t(),r.handlerContext)):r}}return t()}shouldStopFunctionApplication(){if(this.isAtEnd()||vl(this.previous()))return!0;let e=this.peek().kind;return[x.RBRACE,x.RBRACKET,x.RPAREN,x.COMMA,x.COLON].includes(e)}commaExpression(){let e=this.check(x.COMMA)?this.nodeFactory.create(zl,{prevToken:this.previous()}):this.normalExpression();if(!this.check(x.COMMA))return e;let t={elementList:[e],commaList:[]};do{if(t.commaList.push(this.advance()),this.shouldStopCommaExpression()){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));break}if(this.check(x.COMMA)){t.elementList.push(this.nodeFactory.create(zl,{prevToken:this.previous()}));continue}try{let e=this.normalExpression();t.elementList.push(e)}catch(e){throw e instanceof Y?(e.partialNode&&t.elementList.push(e.partialNode),new Y(e.token,this.nodeFactory.create(Nl,t),e.handlerContext)):e}}while(!this.shouldStopCommaExpression()&&this.check(x.COMMA));return this.nodeFactory.create(Nl,t)}shouldStopCommaExpression(){if(this.isAtEnd()||vl(this.previous()))return!0;let e=this.peek().kind;return[x.RBRACE,x.LBRACE,x.RBRACKET,x.LBRACKET,x.RPAREN,x.LPAREN,x.COLON].includes(e)}normalExpression(){return this.expression_bp(0)}expression_bp(e){let t=this.leftExpression_bp();for(;!this.isAtEnd();){let n=this.peek();if(n.kind===x.LPAREN){let{left:r}=Wv(n);if(r<e||yl(this.previous(),n)&&!this.contextStack.isWithinGroupExpressionContext()&&!this.contextStack.isWithinListExpressionContext())break;try{t=this.nodeFactory.create(O,{callee:t,argumentList:this.tupleExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(O,{callee:t,argumentList:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(n.kind===x.LBRACKET){if(bl(this.previous()))break;try{t=this.nodeFactory.create(Bl,{expression:t,indexer:this.listExpression()})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(Bl,{expression:t,indexer:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}else if(gl(n)){let r=n,i=Wv(r);if(i.left!==null){if(i.left<=e)break;this.advance(),t=this.nodeFactory.create(Al,{expression:t,op:r})}else{let n=Bv(r);if(n.left===null||n.left<=e)break;this.advance();try{t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:r.value===`.`?this.extractOperand():this.expression_bp(n.right)})}catch(e){throw e instanceof Y?(t=this.nodeFactory.create(kl,{leftExpression:t,op:r,rightExpression:e.partialNode}),new Y(e.token,t,e.handlerContext)):e}}}else break}return t}leftExpression_bp(){let e;if(gl(this.peek())){let t={};t.op=this.peek();let n=Hv(t.op);if(n.right===null)throw this.logError(t.op,M.UNKNOWN_PREFIX_OP,`Unexpected '${t.op.value}' in an expression`),new Y(t.op,this.nodeFactory.create(zl,{prevToken:t.op}),this.contextStack.findHandlerContext(this.tokens,this.current));this.advance();try{t.expression=this.expression_bp(n.right)}catch(e){throw e instanceof Y?(t.expression=e.partialNode,new Y(e.token,this.nodeFactory.create(Ol,t),e.handlerContext)):e}e=this.nodeFactory.create(Ol,t)}else if(e=this.extractOperand(),e instanceof zl)throw new Y(this.peek(),this.nodeFactory.create(zl,{prevToken:this.peek()}),this.contextStack.findHandlerContext(this.tokens,this.current));return e}extractOperand(){return this.check(x.WILDCARD)?(this.advance(),this.nodeFactory.create(Il,{token:this.previous()})):this.check(x.NUMERIC_LITERAL,x.STRING_LITERAL,x.COLOR_LITERAL,x.QUOTED_STRING,x.IDENTIFIER)?this.primaryExpression():this.check(x.FUNCTION_EXPRESSION)?this.functionExpression():this.check(x.LBRACKET)?this.listExpression():this.check(x.LBRACE)?this.blockExpression():this.check(x.LPAREN)?this.tupleExpression():(this.peek().kind===x.EOF?this.logError(this.peek(),M.UNEXPECTED_EOF,`Unexpected EOF`):this.logError(this.peek(),M.INVALID_OPERAND,`Invalid start of operand "${this.peek().value}"`),this.nodeFactory.create(zl,{prevToken:this.previous()}))}functionExpression(){let e={};try{this.consume(`Expect a function expression`,x.FUNCTION_EXPRESSION),e.value=this.previous()}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(jl,e),t.handlerContext):t}return this.nodeFactory.create(jl,e)}canBeField(){return this.peek().kind===x.IDENTIFIER&&this.peek(1).kind===x.COLON}primaryExpression(){if(this.match(x.COLOR_LITERAL,x.STRING_LITERAL,x.NUMERIC_LITERAL))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Fl,{literal:this.previous()})});if(this.match(x.QUOTED_STRING,x.IDENTIFIER))return this.nodeFactory.create(Rl,{expression:this.nodeFactory.create(Ll,{variable:this.previous()})});throw this.logError(this.peek(),M.UNEXPECTED_TOKEN,`Expect a variable or literal`),new Y(this.peek(),void 0,this.contextStack.findHandlerContext(this.tokens,this.current))}attribute(){let e={};if(this.check(x.COLON,x.RBRACKET,x.COMMA)){let t=this.peek();this.logError(t,M.EMPTY_ATTRIBUTE_NAME,`Expect a non-empty attribute name`),e.name=this.nodeFactory.create(El,{identifiers:[]})}else try{e.name=this.attributeName()}catch(t){if(!(t instanceof Y))throw t;if(e.name=t.partialNode,!this.canHandle(t))throw new Y(t.token,this.nodeFactory.create(Dl,e),t.handlerContext);this.synchronizeAttributeName()}return this.match(x.COLON)&&(e.colon=this.previous(),e.value=this.attributeValue()),this.nodeFactory.create(Dl,e)}attributeValue(){let e;try{e=this.peek().kind===x.IDENTIFIER&&this.peek(1).kind===x.IDENTIFIER?this.attributeName():this.normalExpression()}catch(t){if(!(t instanceof Y)||!this.canHandle(t))throw t;e=t.partialNode,this.synchronizeAttributeValue()}return e}attributeName(){let e=[];if(this.peek().kind!==x.IDENTIFIER)return this.primaryExpression();for(;!this.isAtEnd()&&!this.check(x.COLON,x.COMMA,x.RBRACKET);)try{this.consume(`Expect an identifier`,x.IDENTIFIER),e.push(this.previous())}catch(t){throw t instanceof Y?new Y(t.token,this.nodeFactory.create(El,{identifiers:e}),t.handlerContext):t}return this.nodeFactory.create(El,{identifiers:e})}logError(e,t,n){this.errors.push(new N(t,n,e))}},zv={"+":{left:9,right:10},"-":{left:9,right:10},"/":{left:11,right:12},"%":{left:11,right:12},"<":{left:7,right:8},"<=":{left:7,right:8},">":{left:7,right:8},">=":{left:7,right:8},"<>":{left:7,right:8},"=":{left:2,right:3},"==":{left:4,right:5},"!=":{left:4,right:5},".":{left:16,right:17}};function Bv(e){return zv[e.value]||{left:null,right:null}}var Vv={"+":{left:null,right:15},"-":{left:null,right:15},"<":{left:null,right:15},">":{left:null,right:15},"<>":{left:null,right:15},"!":{left:null,right:15},"~":{left:null,right:15}};function Hv(e){return Vv[e.value]||{left:null,right:null}}var Uv={"(":{left:14,right:null}};function Wv(e){return Uv[e.value]||{left:null,right:null}}function Gv(e,t){return e.getOffsetAt(t)}var Kv=class{constructor(e){this.compiler=e}provideDefinition(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(!e?.referee)continue;let t;if(e.referee?.declaration&&[C.PRIMARY_EXPRESSION,C.VARIABLE].includes(e?.kind)&&({declaration:t}=e.referee),t){let{startPos:e,endPos:r}=t;return[{range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:r.column+1,endLineNumber:r.line+1},uri:n}]}}return[]}};let X=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}({}),Z=function(e){return e[e.None=0]=`None`,e[e.KeepWhitespace=1]=`KeepWhitespace`,e[e.InsertAsSnippet=4]=`InsertAsSnippet`,e}({}),qv=function(e){return e[e.Hint=1]=`Hint`,e[e.Info=2]=`Info`,e[e.Warning=4]=`Warning`,e[e.Error=8]=`Error`,e}({});var Jv=class{constructor(e){this.compiler=e}provideDiagnostics(){let e=[],t=this.compiler.parse._(),n=t.getErrors();for(let t of n)e.push(this.createDiagnostic(t,`error`));let r=t.getWarnings();for(let t of r)e.push(this.createDiagnostic(t,`warning`));return e}provideErrors(){return this.compiler.parse._().getErrors().map(e=>this.createDiagnostic(e,`error`))}provideWarnings(){return this.compiler.parse._().getWarnings().map(e=>this.createDiagnostic(e,`warning`))}provideMarkers(){return this.provideDiagnostics().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}}getSeverityValue(e){return e===`error`?qv.Error:qv.Warning}},Yv=class{constructor(e){this.compiler=e}provideReferences(e,t){let{uri:n}=e,r=Gv(e,t),i=[...this.compiler.container.stack(r)];for(;i.length!==0;){let e=i.pop();if(e&&[C.ELEMENT_DECLARATION,C.FUNCTION_APPLICATION,C.PRIMARY_EXPRESSION].includes(e?.kind)){let{symbol:t}=e;if(t?.references.length)return t.references.map(({startPos:e,endPos:t})=>({range:{startColumn:e.column+1,startLineNumber:e.line+1,endColumn:t.column+1,endLineNumber:t.line+1},uri:n}))}}return[]}};function Xv(e,t){return e>=t.start&&e<t.end}function Zv(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function Qv(e){return Zv(e)?e:`"${ey(e)}"`}function $v(e){let t=``,n=0,r={n:`
12
12
  `,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 ey(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`
13
- `: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 ty(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`'${ey(e)}'`;let{value:t,type:n}=e;if(t==null||xf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(xf(n)){let e=q_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(bf(n)){let e=U_(t);return e===null?`\`${t}\``:String(e)}if(wf(n)){let e=$_(t);return e===null?`\`${t}\``:`'${ey(e)}'`}let r=Y_(t);return r===null?`\`${t}\``:`'${ey(r)}'`}function ny(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?$v(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function ry(e){switch(e){case F.Schema:return X.Module;case F.Table:case F.TablePartial:return X.Class;case F.Column:case F.TableGroupField:return X.Field;case F.Enum:return X.Enum;case F.EnumField:return X.EnumMember;case F.TableGroup:return X.Struct;default:return X.Text}}function iy(e,t){if(!e||xl(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===b.NEWLINE&&n.end<=t)return!1}return!0}function Q(){return{suggestions:[]}}function ay(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function oy(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Qv(e.insertText??``),quoted:!0}))}}function sy(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:Z.KeepWhitespace,kind:X.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function cy(e,t){return e<t.start||e>t.end?!1:t.body?e<t.body.start||e>t.body.end:!0}function ly(e){return e.commaList.length+e.elementList.length===0}function uy(e){let t=[];for(let[n,r]of e.symbolTable.entries()){let e=_u(n);if(e===void 0||e.kind!==F.Column||!(r instanceof wu||r instanceof ku))continue;let i=dy(r,e.name);i&&t.push(i)}return t}function dy(e,t){let n=ou(t),r=e instanceof ku?e.tablePartialSymbol.symbolTable.get(n)?.declaration:e.declaration;if(!(r instanceof T))return null;let i=R(r.callee)??null,a=R(r.args[0])??null;return i===null||a===null?null:{name:i,type:a}}function fy(e,t,n,r){let i=e.container.element(r);return!(i instanceof w)||!i.isKind(h.Records)||!(i.body instanceof E)||!i.body||!Xv(r,i.body)||t.getLineContent(n.lineNumber).trim()!==``?null:i.parent instanceof C?py(e,i):my(e,i)}function py(e,t){if(!(t.name instanceof O))return Q();let n=t.name.argumentList?.elementList||[],r=n.map(e=>vd(e));if(!r||r.length===0)return Q();let i=n.map((e,t)=>{let n=r[t];if(!n||!(n instanceof wu||n instanceof ku))return null;let i=R(e);return i?dy(n,i):null}).filter(e=>e!==null);return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function my(e,t){let n=t.parent;if(!(n instanceof w))return Q();let r=n.symbol;if(!(r instanceof Cu))return Q();let i;if(t.name instanceof Ml){let e=t.name.elementList,n=e.map(e=>vd(e)).filter(e=>e!==void 0);i=e.map((e,t)=>{let r=n[t];if(!r||!(r instanceof wu||r instanceof ku))return null;let i=R(e);return i===void 0?null:dy(r,i)}).filter(e=>e!==null)}else{let e=uy(r);if(!e)return Q();i=e}return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}var hy=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Gv(e,t),r=fy(this.compiler,e,t,n);if(r!==null)return r;let i=this.compiler.token.flatStream(),{token:a,index:o}=this.compiler.container.token(n),s=o===void 0?i[0]:i[o+1];if([...a?.trailingTrivia||[],...a?.leadingTrivia||[],...s?.leadingTrivia||[]].find(e=>wl(e)&&Xv(n,e)))return Q();if(o===void 0)return Dy();if([b.STRING_LITERAL,b.QUOTED_STRING].includes(a.kind)&&Xv(n,a))return Q();let c=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||c instanceof w&&c.type&&c.type.start<=n&&c.type.end>=n)return Dy();let l=[...this.compiler.container.stack(n)].reverse();for(let e of l)if(e instanceof Ol)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`~`:return gy(this.compiler,n);default:}else if(e instanceof kl)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`.`:return Ty(this.compiler,n,e);default:}else if(e instanceof Dl)return Sy(this.compiler,n,e);else if(e instanceof D)return Sy(this.compiler,n,e);else if(e instanceof Ml)return by(this.compiler,n,e);else if(e instanceof Nl)return xy(this.compiler,n);else if(e instanceof O)return Ny(this.compiler,n,e);else if(e instanceof T)return Ey(this.compiler,n,e);else if(e instanceof w){if(cy(n,e))return My(this.compiler,n,e);if(e.bodyColon&&n>=e.bodyColon.end||e.body&&Xv(n,e.body))return Ey(this.compiler,n,void 0)}return Q()}};function gy(e,t){return yy(e,t,e.parse.ast(),[F.TablePartial])}function _y(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=yy(e,t,e.container.element(t),[F.Table,F.Schema,F.Column]);return iy(n.op,t)?ay(r):r}return Q()}function vy(e,t,n){return oy({suggestions:e.symbol.members(t).filter(({kind:e})=>n.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:ry(t),sortText:ry(t).toString().padStart(2,`0`),range:void 0}))})}function yy(e,t,n,r){if(n===void 0)return Q();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...vy(e,t,r).suggestions)}i=i instanceof w?i.parent:void 0}return oy(a)}function by(e,t,n){let r=e.container.scopeKind(t),i=e.container.element(t),a=[...e.container.stack(t)];for(let r of a)if(r instanceof O&&r.argumentList===n)return Ny(e,t,r);if(i instanceof w&&i.isKind(h.Records)&&!(i.name instanceof O)&&cy(t,i)){let t=i.parent?.symbol||i.name?.referee;if(t){let r=vy(e,t,[F.Column]);return ly(n)?sy(r):r}}switch(r){case $.INDEXES:return zy(e,t);case $.REF:for(;a.length>0;){let n=a.pop();if(n instanceof kl&&n.op?.value===`.`)return Ty(e,t,n)}return jy(e,t);default:break}return Q()}function xy(e,t){return e.container.scopeKind(t)===$.RECORDS?yy(e,t,e.container.element(t),[F.Schema,F.Enum,F.EnumField]):Q()}function Sy(e,t,n){let{token:r}=e.container.token(t);if([b.COMMA,b.LBRACKET].includes(r?.kind)){let n=Cy(e,t);return r?.kind===b.COMMA&&iy(r,t)?ay(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return Cy(e,t);if(n.name instanceof El){let i=wy(e,t,tu(n.name)??``);return r?.kind===b.COLON&&iy(r,t)?ay(i):i}return Q()}function Cy(e,t){let n=e.container.element(t);if(n instanceof C)return Q();let r=e.container.scopeKind(t);if(n.body&&!Xv(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[g.HeaderColor,g.Note];break;case $.TABLEGROUP:e=[g.Color,g.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Z.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[g.PK,g.PrimaryKey,g.Null,g.NotNull,g.Increment,g.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[g.Ref,g.Default,g.Note,g.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[g.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[g.Unique,g.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[g.Note,g.Name,g.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[g.Update,g.Delete,g.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[g.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function wy(e,t,n){switch(n?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`default`:return yy(e,t,e.container.element(t),[F.Schema,F.Enum]);default:break}return Q()}function Ty(e,t,n){let r=md(n)??[];if(r.pop(),r.some(e=>!j(e)))return Q();let i=r.map(e=>R(e));return oy({suggestions:e.symbol.ofName(i,e.container.element(t)).flatMap(({symbol:t})=>e.symbol.members(t)).map(({kind:e,name:t})=>({label:t,insertText:t,kind:ry(e),range:void 0}))})}function Ey(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return ky(e,t,n);case $.PROJECT:return Ay(e,t,n);case $.INDEXES:return Ly(e,t);case $.ENUM:return Oy(e,t,n);case $.REF:{let n=jy(e,t);return e.container.token(t).token?.kind===b.COLON&&iy(e.container.token(t).token,t)?ay(n):n}case $.TABLEGROUP:return Py(e);case $.DIAGRAMVIEW:return Fy();case $.CUSTOM:{let n=e.container.element(t);return n instanceof w&&n.parent instanceof w&&n.parent.isKind(h.DiagramView)?Iy(e,t):Q()}default:return Q()}}function Dy(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function Oy(e,t,n){return n?.callee&&By(t,n)===1?yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column]):Q()}function ky(e,t,n){let r=[`Note`,`indexes`,`checks`,`Records`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=By(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?Ry(e,t):Q()}function Ay(e,t,n){return!n?.callee||By(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Q()}function jy(e,t){return yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column])}function My(e,t,n){return n.isKind(h.Records)?yy(e,t,n.parent,[F.Schema,F.Table]):Q()}function Ny(e,t,n){let r=e.container.element(t),i=n.callee&&Xv(t,n.callee),a=n.argumentList&&Xv(t,n.argumentList);if(r instanceof w&&r.isKind(h.Records)&&cy(t,r)){if(i)return yy(e,t,r.parent,[F.Schema,F.Table]);if(!a)return Q();let o=n.callee;if(!o)return Q();let s=md(o)??[o],c=s[s.length-1]?.referee;if(!c)return Q();let l=vy(e,c,[F.Column]),{argumentList:u}=n;return!u||!ly(u)?l:sy(l)}let o=[...e.container.stack(t)];for(let r of o){if(!a||!(r instanceof T)||r.callee!==n||Bu(h,R(n.callee)??``)!==h.Records)continue;let i=e.container.element(t).symbol;if(!i)return Q();let o=vy(e,i,[F.Column]),{argumentList:s}=n;return!s||!ly(s)?o:sy(o)}return Q()}function Py(e){return{suggestions:[...oy({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==F.Table&&n!==F.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:ry(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function Fy(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0})),{label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}]}}function Iy(e,t){let n=e.container.element(t);if(!(n instanceof w))return Q();let r=n.type?.value.toLowerCase(),i={label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0};switch(r){case`tables`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.Table,F.Schema]).suggestions]};case`tablegroups`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.TableGroup]).suggestions]};case`schemas`:return{suggestions:[i,{label:ce,insertText:ce,insertTextRules:Z.KeepWhitespace,kind:X.Module,range:void 0},...yy(e,t,e.parse.ast(),[F.Schema]).suggestions]};case`notes`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.StickyNote]).suggestions]};default:return Q()}}function Ly(e,t){return zy(e,t)}function Ry(e,t){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:Z.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...yy(e,t,e.container.element(t),[F.Enum,F.Schema]).suggestions]}}function zy(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Cu))return Q();let{symbolTable:r}=n.symbol;return oy({suggestions:[...r.entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:ry(F.Column),range:void 0}})})}function By(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 Vy={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`],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`]]}},Hy=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>hy,DBMLDefinitionProvider:()=>Kv,DBMLDiagnosticsProvider:()=>Jv,DBMLReferencesProvider:()=>Yv,MarkerSeverity:()=>qv,dbmlMonarchTokensProvider:()=>Vy},1);function Uy(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:Fc(t,e=>!e.isInvalid,n);if(i===-1)return[this.parse.ast()];let a=t[i].start,o=this.parse.ast(),s=[o];for(;;){let e=Yl(o).find(e=>Xv(a,e));if(e===void 0||e instanceof vl)break;s.push(e),o=e}if(r?.kind===b.COLON)return s;for(;s.length>0;){let t=!1,n=v(s);if(n instanceof T){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
14
- `&&(s.pop(),t=!0)}else n instanceof Ol||n instanceof kl?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof D?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof Ml?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof Nl?n.end<=e&&(s.pop(),t=!0):n instanceof E?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof El||n.end<e&&(s.pop(),t=!0);if(t){let t=v(s);t instanceof w&&t.end<=e&&s.pop()}if(!t)break}return s}function Wy(e){let t=this.token.flatStream().findIndex(t=>t.start>=e);return t===void 0||t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function Gy(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof w)return t[e];return this.parse.ast()}function Ky(e){return this.container.element(e)?.symbol?.symbolTable}let $=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 qy(e){let t=this.container.element(e);if(t instanceof C)return $.TOPLEVEL;switch(t.type?.value.toLowerCase()){case`table`:return $.TABLE;case`enum`:return $.ENUM;case`ref`:return $.REF;case`tablegroup`:return $.TABLEGROUP;case`indexes`:return $.INDEXES;case`note`:return $.NOTE;case`project`:return $.PROJECT;case`tablepartial`:return $.TABLEPARTIAL;case`checks`:return $.CHECKS;case`records`:return $.RECORDS;case`diagramview`:return $.DIAGRAMVIEW;default:return $.CUSTOM}}function Jy(){return this.parse._().getValue().ast}function Yy(){return this.parse._().getErrors()}function Xy(){return this.parse._().getWarnings()}function Zy(){return this.parse._().getValue().tokens}function Qy(){return this.parse._().getValue().rawDb}function $y(){return this.parse._().getValue().ast.symbol.symbolTable}function eb(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({..._u(e),symbol:t})):[]}function tb(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof w?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>Pu(t).flatMap(t=>{let n=e.get(t),r=_u(t);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function nb(e,t){return`${e.join(`.`)}@${t.id}`}function rb(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function ib(){return this.parse.tokens().filter(ql)}function ab(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function ob(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=ny(e);if(t.length===0)return{schema:ce,table:``};if(t.length===1)return{schema:ce,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function sb(e,t,n){let r=au(n);if(t===`public`){let t=e.get(r);return t instanceof Cu?t:null}let i=iu(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Cu?o:null}function cb(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function lb(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function ub(e,t){if(!e.declaration)return!1;let n=e.declaration;if(!n.name)return!1;let r=n.name;return t.substring(r.start,r.end).includes(`"`)}function db(e,t,n){let r=!lb(t),i=!lb(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function fb(e,t,n,r,i){let a=au(i),o;if(r===`public`)o=e.get(a);else{let t=iu(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function pb(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return cb(n.substring(i,a))===t?{start:i,end:e.end}:null}function mb(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=pb(o,t,r)??{start:o.start,end:o.end},s=`${e.start}-${e.end}`;if(a.has(s))continue;a.add(s);let c=n.schema===`public`?n.formattedTable:`${n.formattedSchema}.${n.formattedTable}`;i.push({start:e.start,end:e.end,newText:c})}return i}function hb(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=ob(e),a=ob(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=sb(r,o,s);if(!u||fb(r,o,s,c,l))return n;let d=db(c,l,ub(u,n)),f=[];if(u.declaration){let e=u.declaration;e.name&&f.push(e.name)}for(let e of u.references)n.substring(e.start,e.end).replace(/"/g,``)===s&&f.push(e);return ab(n,mb(f,o,d,n))}function gb(e){let t=[],n=new Pv(e,le).lex();if(n.getErrors().length>0)return t;let r=new Rv(e,n.getValue(),new Tl,le).parse();if(r.getErrors().length>0)return t;let i=r.getValue().ast;for(let e of i.body)if(e.isKind(h.DiagramView)){let n=e.name?L(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function _b(e,t){let n=[`DiagramView ${Qv(e)} {`];if(t?.tables!==void 0&&t.tables!==null)if(t.tables.length===0)n.push(` Tables { * }`);else{let e=t.tables.map(e=>e.schemaName===`public`?e.name:`${e.schemaName}.${e.name}`);n.push(` Tables {`),e.forEach(e=>n.push(` ${e}`)),n.push(` }`)}return t?.stickyNotes!==void 0&&(t.stickyNotes===null||(t.stickyNotes.length===0?n.push(` Notes { * }`):(n.push(` Notes {`),t.stickyNotes.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),t?.tableGroups!==void 0&&(t.tableGroups===null||(t.tableGroups.length===0?n.push(` TableGroups { * }`):(n.push(` TableGroups {`),t.tableGroups.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),t?.schemas!==void 0&&(t.schemas===null||(t.schemas.length===0?n.push(` Schemas { * }`):(n.push(` Schemas {`),t.schemas.forEach(e=>n.push(` ${e.name}`)),n.push(` }`)))),n.push(`}`),n.join(`
15
- `)}function vb(e,t,n){let r=n??gb(e),i=[];for(let n of t){let t=yb(e,n,r);i.push(...t)}return i.sort((e,t)=>t.start-e.start),{newDbml:ab(e,i,!0),edits:i}}function yb(e,t,n){switch(t.operation){case`create`:return bb(e,t,n);case`update`:return xb(e,t,n);case`delete`:return Sb(e,t,n);default:return[]}}function bb(e,t,n){if(n.find(e=>e.name===t.name))return xb(e,t,n);let r=`
13
+ `: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 ty(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`'${ey(e)}'`;let{value:t,type:n}=e;if(t==null||xf(n)&&typeof t==`string`&&t.toLowerCase()===`null`)return`null`;if(n===`expression`)return typeof t==`string`&&t.toLowerCase().trim()===`null`?`null`:`\`${t}\``;if(xf(n)){let e=q_(t);return e===null?`\`${t}\``:e?`true`:`false`}if(bf(n)){let e=U_(t);return e===null?`\`${t}\``:String(e)}if(wf(n)){let e=$_(t);return e===null?`\`${t}\``:`'${ey(e)}'`}let r=Y_(t);return r===null?`\`${t}\``:`'${ey(r)}'`}function ny(e){return(e.match(/"(?:[^"\\]|\\.)*"|[^."]+/g)||[]).map(e=>e.startsWith(`"`)&&e.endsWith(`"`)?$v(e.slice(1,-1)):e.trim()).filter(e=>e.length>0)}function ry(e){switch(e){case F.Schema:return X.Module;case F.Table:case F.TablePartial:return X.Class;case F.Column:case F.TableGroupField:return X.Field;case F.Enum:return X.Enum;case F.EnumField:return X.EnumMember;case F.TableGroup:return X.Struct;default:return X.Text}}function iy(e,t){if(!e||bl(e))return!1;for(let n of e.trailingTrivia){if(n.start>t)break;if(n.kind===x.NEWLINE&&n.end<=t)return!1}return!0}function Q(){return{suggestions:[]}}function ay(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:` ${e.insertText}`}))}}function oy(e){return{...e,suggestions:e.suggestions.map(e=>({...e,insertText:e.quoted?e.insertText:Qv(e.insertText??``),quoted:!0}))}}function sy(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:Z.KeepWhitespace,kind:X.Snippet,sortText:`00`,range:void 0},...e.suggestions]}:e}function cy(e,t){return e<t.start||e>t.end?!1:t.body?e<t.body.start||e>t.body.end:!0}function ly(e){return e.commaList.length+e.elementList.length===0}function uy(e){let t=[];for(let[n,r]of e.symbolTable.entries()){let e=_u(n);if(e===void 0||e.kind!==F.Column||!(r instanceof wu||r instanceof ku))continue;let i=dy(r,e.name);i&&t.push(i)}return t}function dy(e,t){let n=ou(t),r=e instanceof ku?e.tablePartialSymbol.symbolTable.get(n)?.declaration:e.declaration;if(!(r instanceof T))return null;let i=R(r.callee)??null,a=R(r.args[0])??null;return i===null||a===null?null:{name:i,type:a}}function fy(e,t,n,r){let i=e.container.element(r);return!(i instanceof w)||!i.isKind(g.Records)||!(i.body instanceof E)||!i.body||!Xv(r,i.body)||t.getLineContent(n.lineNumber).trim()!==``?null:i.parent instanceof Tl?py(e,i):my(e,i)}function py(e,t){if(!(t.name instanceof O))return Q();let n=t.name.argumentList?.elementList||[],r=n.map(e=>vd(e));if(!r||r.length===0)return Q();let i=n.map((e,t)=>{let n=r[t];if(!n||!(n instanceof wu||n instanceof ku))return null;let i=R(e);return i?dy(n,i):null}).filter(e=>e!==null);return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}function my(e,t){let n=t.parent;if(!(n instanceof w))return Q();let r=n.symbol;if(!(r instanceof Cu))return Q();let i;if(t.name instanceof Ml){let e=t.name.elementList,n=e.map(e=>vd(e)).filter(e=>e!==void 0);i=e.map((e,t)=>{let r=n[t];if(!r||!(r instanceof wu||r instanceof ku))return null;let i=R(e);return i===void 0?null:dy(r,i)}).filter(e=>e!==null)}else{let e=uy(r);if(!e)return Q();i=e}return i.length===0?Q():{suggestions:[{label:`Record row snippet`,insertText:i.map((e,t)=>`\${${t+1}:${e.name} (${e.type})}`).join(`, `),insertTextRules:Z.InsertAsSnippet,kind:X.Snippet,range:void 0}]}}var hy=class{constructor(e,t=[]){this.compiler=e,this.triggerCharacters=t}provideCompletionItems(e,t){let n=Gv(e,t),r=fy(this.compiler,e,t,n);if(r!==null)return r;let i=this.compiler.token.flatStream(),{token:a,index:o}=this.compiler.container.token(n),s=o===void 0?i[0]:i[o+1];if([...a?.trailingTrivia||[],...a?.leadingTrivia||[],...s?.leadingTrivia||[]].find(e=>Cl(e)&&Xv(n,e)))return Q();if(o===void 0)return Dy();if([x.STRING_LITERAL,x.QUOTED_STRING].includes(a.kind)&&Xv(n,a))return Q();let c=this.compiler.container.element(n);if(this.compiler.container.scopeKind(n)===$.TOPLEVEL||c instanceof w&&c.type&&c.type.start<=n&&c.type.end>=n)return Dy();let l=[...this.compiler.container.stack(n)].reverse();for(let e of l)if(e instanceof Ol)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`~`:return gy(this.compiler,n);default:}else if(e instanceof kl)switch(e.op?.value){case`>`:case`<`:case`<>`:case`-`:return _y(this.compiler,n,e);case`.`:return Ty(this.compiler,n,e);default:}else if(e instanceof Dl)return Sy(this.compiler,n,e);else if(e instanceof D)return Sy(this.compiler,n,e);else if(e instanceof Ml)return by(this.compiler,n,e);else if(e instanceof Nl)return xy(this.compiler,n);else if(e instanceof O)return Ny(this.compiler,n,e);else if(e instanceof T)return Ey(this.compiler,n,e);else if(e instanceof w){if(cy(n,e))return My(this.compiler,n,e);if(e.bodyColon&&n>=e.bodyColon.end||e.body&&Xv(n,e.body))return Ey(this.compiler,n,void 0)}return Q()}};function gy(e,t){return yy(e,t,e.parse.ast(),[F.TablePartial])}function _y(e,t,n){let r=e.container.scopeKind(t);if([$.REF,$.TABLE,$.TABLEPARTIAL].includes(r)){let r=yy(e,t,e.container.element(t),[F.Table,F.Schema,F.Column]);return iy(n.op,t)?ay(r):r}return Q()}function vy(e,t,n){return oy({suggestions:e.symbol.members(t).filter(({kind:e})=>n.includes(e)).map(({name:e,kind:t})=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:ry(t),sortText:ry(t).toString().padStart(2,`0`),range:void 0}))})}function yy(e,t,n,r){if(n===void 0)return Q();let i=n,a={suggestions:[]};for(;i;){if(i?.symbol?.symbolTable){let{symbol:t}=i;a.suggestions.push(...vy(e,t,r).suggestions)}i=i instanceof w?i.parent:void 0}return oy(a)}function by(e,t,n){let r=e.container.scopeKind(t),i=e.container.element(t),a=[...e.container.stack(t)];for(let r of a)if(r instanceof O&&r.argumentList===n)return Ny(e,t,r);if(i instanceof w&&i.isKind(g.Records)&&!(i.name instanceof O)&&cy(t,i)){let t=i.parent?.symbol||i.name?.referee;if(t){let r=vy(e,t,[F.Column]);return ly(n)?sy(r):r}}switch(r){case $.INDEXES:return zy(e,t);case $.REF:for(;a.length>0;){let n=a.pop();if(n instanceof kl&&n.op?.value===`.`)return Ty(e,t,n)}return jy(e,t);default:break}return Q()}function xy(e,t){return e.container.scopeKind(t)===$.RECORDS?yy(e,t,e.container.element(t),[F.Schema,F.Enum,F.EnumField]):Q()}function Sy(e,t,n){let{token:r}=e.container.token(t);if([x.COMMA,x.LBRACKET].includes(r?.kind)){let n=Cy(e,t);return r?.kind===x.COMMA&&iy(r,t)?ay(n):n}if(n.name&&n.name.start<=t&&n.name.end>=t)return Cy(e,t);if(n.name instanceof El){let i=wy(e,t,tu(n.name)??``);return r?.kind===x.COLON&&iy(r,t)?ay(i):i}return Q()}function Cy(e,t){let n=e.container.element(t);if(n instanceof Tl)return Q();let r=e.container.scopeKind(t);if(n.body&&!Xv(t,n.body)){let e;switch(r){case $.TABLE:case $.TABLEPARTIAL:e=[_.HeaderColor,_.Note];break;case $.TABLEGROUP:e=[_.Color,_.Note];break;default:e=[]}return{suggestions:e.map(e=>({label:e,insertText:`${e}: `,kind:X.Field,insertTextRules:Z.KeepWhitespace,range:void 0}))}}switch(r){case $.TABLE:case $.TABLEPARTIAL:return{suggestions:[...[_.PK,_.PrimaryKey,_.Null,_.NotNull,_.Increment,_.Unique].map(e=>({label:e,insertText:e,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0})),...[_.Ref,_.Default,_.Note,_.Check].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.ENUM:return{suggestions:[...[_.Note].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.INDEXES:return{suggestions:[...[_.Unique,_.PK].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Property,range:void 0})),...[_.Note,_.Name,_.Type].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))]};case $.REF:return{suggestions:[_.Update,_.Delete,_.Color].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};case $.CHECKS:return{suggestions:[_.Name].map(e=>({label:e,insertText:`${e}: `,kind:X.Property,insertTextRules:Z.KeepWhitespace,range:void 0}))};default:break}return Q()}function wy(e,t,n){switch(n?.toLowerCase()){case`update`:case`delete`:return{suggestions:[`cascade`,`set default`,`set null`,`restrict`].map(e=>({label:e,insertText:e,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`type`:return{suggestions:[`btree`,`hash`].map(e=>({label:e,insertText:`${e}`,kind:X.Value,insertTextRules:Z.KeepWhitespace,range:void 0}))};case`default`:return yy(e,t,e.container.element(t),[F.Schema,F.Enum]);default:break}return Q()}function Ty(e,t,n){let r=md(n)??[];if(r.pop(),r.some(e=>!j(e)))return Q();let i=r.map(e=>R(e));return oy({suggestions:e.symbol.ofName(i,e.container.element(t)).flatMap(({symbol:t})=>e.symbol.members(t)).map(({kind:e,name:t})=>({label:t,insertText:t,kind:ry(e),range:void 0}))})}function Ey(e,t,n){switch(e.container.scopeKind(t)){case $.TABLE:case $.TABLEPARTIAL:return ky(e,t,n);case $.PROJECT:return Ay(e,t,n);case $.INDEXES:return Ly(e,t);case $.ENUM:return Oy(e,t,n);case $.REF:{let n=jy(e,t);return e.container.token(t).token?.kind===x.COLON&&iy(e.container.token(t).token,t)?ay(n):n}case $.TABLEGROUP:return Py(e);case $.DIAGRAMVIEW:return Fy();case $.CUSTOM:{let n=e.container.element(t);return n instanceof w&&n.parent instanceof w&&n.parent.isKind(g.DiagramView)?Iy(e,t):Q()}default:return Q()}}function Dy(){return{suggestions:[`Table`,`TableGroup`,`Enum`,`Project`,`Ref`,`TablePartial`,`Records`,`DiagramView`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}}function Oy(e,t,n){return n?.callee&&By(t,n)===1?yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column]):Q()}function ky(e,t,n){let r=[`Note`,`indexes`,`checks`,`Records`];if(!n?.callee)return{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))};let i=By(t,n);return i===0?{suggestions:r.map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:i===1?Ry(e,t):Q()}function Ay(e,t,n){return!n?.callee||By(t,n)===0?{suggestions:[`Table`,`TableGroup`,`Enum`,`Note`,`Ref`,`TablePartial`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))}:Q()}function jy(e,t){return yy(e,t,e.container.element(t),[F.Schema,F.Table,F.Column])}function My(e,t,n){return n.isKind(g.Records)?yy(e,t,n.parent,[F.Schema,F.Table]):Q()}function Ny(e,t,n){let r=e.container.element(t),i=n.callee&&Xv(t,n.callee),a=n.argumentList&&Xv(t,n.argumentList);if(r instanceof w&&r.isKind(g.Records)&&cy(t,r)){if(i)return yy(e,t,r.parent,[F.Schema,F.Table]);if(!a)return Q();let o=n.callee;if(!o)return Q();let s=md(o)??[o],c=s[s.length-1]?.referee;if(!c)return Q();let l=vy(e,c,[F.Column]),{argumentList:u}=n;return!u||!ly(u)?l:sy(l)}let o=[...e.container.stack(t)];for(let r of o){if(!a||!(r instanceof T)||r.callee!==n||Bu(g,R(n.callee)??``)!==g.Records)continue;let i=e.container.element(t).symbol;if(!i)return Q();let o=vy(e,i,[F.Column]),{argumentList:s}=n;return!s||!ly(s)?o:sy(o)}return Q()}function Py(e){return{suggestions:[...oy({suggestions:[...e.parse.publicSymbolTable().entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{kind:n,name:r}=t;return n!==F.Table&&n!==F.Schema?[]:{label:r,insertText:r,insertTextRules:Z.KeepWhitespace,kind:ry(n),range:void 0}})}).suggestions,...[`Note`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}))]}}function Fy(){return{suggestions:[...[`Tables`,`TableGroups`,`Notes`,`Schemas`].map(e=>({label:e,insertText:e,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0})),{label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0}]}}function Iy(e,t){let n=e.container.element(t);if(!(n instanceof w))return Q();let r=n.type?.value.toLowerCase(),i={label:`*`,insertText:`*`,insertTextRules:Z.KeepWhitespace,kind:X.Keyword,range:void 0};switch(r){case`tables`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.Table,F.Schema]).suggestions]};case`tablegroups`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.TableGroup]).suggestions]};case`schemas`:return{suggestions:[i,{label:se,insertText:se,insertTextRules:Z.KeepWhitespace,kind:X.Module,range:void 0},...yy(e,t,e.parse.ast(),[F.Schema]).suggestions]};case`notes`:return{suggestions:[i,...yy(e,t,e.parse.ast(),[F.StickyNote]).suggestions]};default:return Q()}}function Ly(e,t){return zy(e,t)}function Ry(e,t){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:Z.KeepWhitespace,kind:X.TypeParameter,sortText:X.TypeParameter.toString().padStart(2,`0`),range:void 0})),...yy(e,t,e.container.element(t),[F.Enum,F.Schema]).suggestions]}}function zy(e,t){let n=e.container.element(t)?.parent;if(!(n?.symbol instanceof Cu))return Q();let{symbolTable:r}=n.symbol;return oy({suggestions:[...r.entries()].flatMap(([e])=>{let t=_u(e);if(t===void 0)return[];let{name:n}=t;return{label:n,insertText:n,insertTextRules:Z.KeepWhitespace,kind:ry(F.Column),range:void 0}})})}function By(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 Vy={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`],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`]]}},Hy=t({CompletionItemInsertTextRule:()=>Z,CompletionItemKind:()=>X,DBMLCompletionItemProvider:()=>hy,DBMLDefinitionProvider:()=>Kv,DBMLDiagnosticsProvider:()=>Jv,DBMLReferencesProvider:()=>Yv,MarkerSeverity:()=>qv,dbmlMonarchTokensProvider:()=>Vy},1);function Uy(e){let t=this.token.flatStream(),{index:n,token:r}=this.container.token(e),i=n===void 0?-1:Pc(t,e=>!e.isInvalid,n);if(i===-1)return[this.parse.ast()];let a=t[i].start,o=this.parse.ast(),s=[o];for(;;){let e=Yl(o).find(e=>Xv(a,e));if(e===void 0||e instanceof _l)break;s.push(e),o=e}if(r?.kind===x.COLON)return s;for(;s.length>0;){let t=!1,n=y(s);if(n instanceof T){let r=this.parse.source();for(let i=n.end;i<e;i+=1)r[i]===`
14
+ `&&(s.pop(),t=!0)}else n instanceof Ol||n instanceof kl?this.container.token(e).token!==n.op&&(s.pop(),t=!0):n instanceof D?n.listCloseBracket&&n.end<=e&&(s.pop(),t=!0):n instanceof Ml?n.tupleCloseParen&&n.end<=e&&(s.pop(),t=!0):n instanceof Nl?n.end<=e&&(s.pop(),t=!0):n instanceof E?n.blockCloseBrace&&n.end<=e&&(s.pop(),t=!0):n instanceof El||n.end<e&&(s.pop(),t=!0);if(t){let t=y(s);t instanceof w&&t.end<=e&&s.pop()}if(!t)break}return s}function Wy(e){let t=this.token.flatStream().findIndex(t=>t.start>=e);return t===void 0||t<=0?{token:void 0,index:void 0}:{token:this.token.flatStream()[t-1],index:t-1}}function Gy(e){let t=this.container.stack(e);for(let e=t.length-1;e>=0;--e)if(t[e]instanceof w)return t[e];return this.parse.ast()}function Ky(e){return this.container.element(e)?.symbol?.symbolTable}let $=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 qy(e){let t=this.container.element(e);if(t instanceof Tl)return $.TOPLEVEL;switch(t.type?.value.toLowerCase()){case`table`:return $.TABLE;case`enum`:return $.ENUM;case`ref`:return $.REF;case`tablegroup`:return $.TABLEGROUP;case`indexes`:return $.INDEXES;case`note`:return $.NOTE;case`project`:return $.PROJECT;case`tablepartial`:return $.TABLEPARTIAL;case`checks`:return $.CHECKS;case`records`:return $.RECORDS;case`diagramview`:return $.DIAGRAMVIEW;default:return $.CUSTOM}}function Jy(){return this.parse._().getValue().ast}function Yy(){return this.parse._().getErrors()}function Xy(){return this.parse._().getWarnings()}function Zy(){return this.parse._().getValue().tokens}function Qy(){return this.parse._().getValue().rawDb}function $y(){return this.parse._().getValue().ast.symbol.symbolTable}function eb(e){return e.symbolTable?[...e.symbolTable.entries()].map(([e,t])=>({..._u(e),symbol:t})):[]}function tb(e,t){if(e.length===0)return[];let n=[];for(let r=t;r;r=r instanceof w?r.parent:void 0){if(!r.symbol?.symbolTable)continue;let{symbolTable:t}=r.symbol,i=[t],a=[];for(let t of e)a=i.flatMap(e=>Pu(t).flatMap(t=>{let n=e.get(t),r=_u(t);return!n||!r?[]:{...r,symbol:n}})),i=a.flatMap(e=>e.symbol.symbolTable?e.symbol.symbolTable:[]);n.push(...a)}return n}function nb(e,t){return`${e.join(`.`)}@${t.id}`}function rb(){return this.parse.tokens().flatMap(e=>[...e.leadingInvalid,e,...e.trailingInvalid])}function ib(){return this.parse.tokens().filter(ql)}function ab(e,t,n=!1){let r=n?t:[...t].sort((e,t)=>t.start-e.start),i=e;for(let{start:e,end:t,newText:n}of r)i=i.substring(0,e)+n+i.substring(t);return i}function ob(e){if(typeof e!=`string`)return{schema:e.schema??`public`,table:e.table};let t=ny(e);if(t.length===0)return{schema:se,table:``};if(t.length===1)return{schema:se,table:t[0]};if(t.length===2)return{schema:t[0],table:t[1]};let n=t[t.length-1];return{schema:t.slice(0,-1).join(`.`),table:n}}function sb(e,t,n){let r=au(n);if(t===`public`){let t=e.get(r);return t instanceof Cu?t:null}let i=iu(t),a=e.get(i);if(!a||!a.symbolTable)return null;let o=a.symbolTable.get(r);return o instanceof Cu?o:null}function cb(e){return e.startsWith(`"`)&&e.endsWith(`"`)&&e.length>=2?e.slice(1,-1):e}function lb(e){return e?e.split(``).every(e=>Iu(e)||Lu(e))&&!Lu(e[0]):!1}function ub(e,t){if(!e.declaration)return!1;let n=e.declaration;if(!n.name)return!1;let r=n.name;return t.substring(r.start,r.end).includes(`"`)}function db(e,t,n){let r=!lb(t),i=!lb(e),a=n||r,o=n||i;return{schema:e,table:t,formattedSchema:o?`"${e}"`:e,formattedTable:a?`"${t}"`:t,shouldQuoteSchema:o,shouldQuoteTable:a}}function fb(e,t,n,r,i){let a=au(i),o;if(r===`public`)o=e.get(a);else{let t=iu(r),n=e.get(t);if(!n||!n.symbolTable)return!1;o=n.symbolTable.get(a)}return!(!o||t===r&&n===i)}function pb(e,t,n){let r=e.start-1;for(;r>=0&&/\s/.test(n[r]);)r--;if(r<0||n[r]!==`.`)return null;for(r--;r>=0&&/\s/.test(n[r]);)r--;if(r<0)return null;let i,a;if(n[r]===`"`){for(a=r+1,r--;r>=0&&n[r]!==`"`;)r--;if(r<0)return null;i=r}else{for(a=r+1;r>=0&&/[a-zA-Z0-9_]/.test(n[r]);)r--;i=r+1}return cb(n.substring(i,a))===t?{start:i,end:e.end}:null}function mb(e,t,n,r){let i=[],a=new Set;for(let o of e){let e=pb(o,t,r)??{start:o.start,end:o.end},s=`${e.start}-${e.end}`;if(a.has(s))continue;a.add(s);let c=n.schema===`public`?n.formattedTable:`${n.formattedSchema}.${n.formattedTable}`;i.push({start:e.start,end:e.end,newText:c})}return i}function hb(e,t){let n=this.parse.source(),r=this.parse.publicSymbolTable(),i=ob(e),a=ob(t),o=i.schema,s=i.table,c=a.schema,l=a.table,u=sb(r,o,s);if(!u||fb(r,o,s,c,l))return n;let d=db(c,l,ub(u,n)),f=[];if(u.declaration){let e=u.declaration;e.name&&f.push(e.name)}for(let e of u.references)n.substring(e.start,e.end).replace(/"/g,``)===s&&f.push(e);return ab(n,mb(f,o,d,n))}function gb(e){let t=[],n=new Pv(e,ce).lex();if(n.getErrors().length>0)return t;let r=new Rv(e,n.getValue(),new wl,ce).parse();if(r.getErrors().length>0)return t;let i=r.getValue().ast;for(let e of i.body)if(e.isKind(g.DiagramView)){let n=e.name?L(e.name)??[]:[],r=n.length>0?n[n.length-1]:``;t.push({name:r,startIndex:e.start,endIndex:e.end})}return t}function _b(e,t){let n=t.map(e=>e.schemaName===`public`?e.name:`${e.schemaName}.${e.name}`);e.push(` Tables {`),n.forEach(t=>e.push(` ${t}`)),e.push(` }`)}function vb(e,t){e.push(` TableGroups {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function yb(e,t){e.push(` Schemas {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function bb(e,t){e.push(` Notes {`),t.forEach(t=>e.push(` ${t.name}`)),e.push(` }`)}function xb(e,t){let n=`DiagramView ${Qv(e)} {`;if(!t)return`${n}\n}`;let{tables:r,tableGroups:i,schemas:a,stickyNotes:o}=t,s=r===null,c=i===null,l=a===null;if(s&&c&&l&&o===null)return`${n}\n}`;if(s||c||l){let e=!s&&r.length>0,t=!c&&i.length>0,u=!l&&a.length>0;if(!(e||t||u)){if(o&&o.length>0){let e=[n];return bb(e,o),e.push(`}`),e.join(`
15
+ `)}return`${n}\n Notes { * }\n}`}let d=[n];return e&&_b(d,r),t&&vb(d,i),u&&yb(d,a),o&&o.length>0&&bb(d,o),d.push(`}`),d.join(`
16
+ `)}let u=r,d=i,f=a,p=u.length===0&&d.length===0&&f.length===0,m=o!=null&&o.length>0;if(p){if(m){let e=[n,` Tables { * }`];return bb(e,o),e.push(`}`),e.join(`
17
+ `)}return`${n}\n *\n}`}let h=[n];return u.length>0&&_b(h,u),d.length>0&&vb(h,d),f.length>0&&yb(h,f),m&&bb(h,o),h.push(`}`),h.join(`
18
+ `)}function Sb(e,t,n){let r=n??gb(e),i=[];for(let n of t){let t=Cb(e,n,r);i.push(...t)}return i.sort((e,t)=>t.start-e.start),{newDbml:ab(e,i,!0),edits:i}}function Cb(e,t,n){switch(t.operation){case`create`:return wb(e,t,n);case`update`:return Tb(e,t,n);case`delete`:return Eb(e,t,n);default:return[]}}function wb(e,t,n){if(n.find(e=>e.name===t.name))return Tb(e,t,n);let r=`
16
19
 
17
- `+_b(t.name,t.visibleEntities)+`
18
- `;return[{start:e.length,end:e.length,newText:r}]}function xb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=_b(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function Sb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
20
+ `+xb(t.name,t.visibleEntities)+`
21
+ `;return[{start:e.length,end:e.length,newText:r}]}function Tb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=[];if(t.newName||t.visibleEntities){let e=xb(t.newName||t.name,t.visibleEntities);i.push({start:r.startIndex,end:r.endIndex,newText:e})}return i}function Eb(e,t,n){let r=n.find(e=>e.name===t.name);if(!r)return[];let i=r.startIndex,a=r.endIndex;for(;i>0&&e[i-1]===`
19
22
  `;){i--,i>0&&e[i-1]===`\r`&&i--;let t=e.lastIndexOf(`
20
23
  `,i-1)+1;if(e.substring(t,i).trim()!==``){i=r.startIndex,i>0&&e[i-1]===`
21
24
  `&&(i--,i>0&&e[i-1]===`\r`&&i--);break}}return a<e.length&&e[a]===`\r`&&a++,a<e.length&&e[a]===`
22
- `&&a++,[{start:i,end:a,newText:``}]}var Cb=class{constructor(){this.source=``,this.cache=new Map,this.nodeIdGenerator=new Tl,this.symbolIdGenerator=new vu,this.token={invalidStream:this.query(ib),flatStream:this.query(rb)},this.parse={source:()=>this.source,_:this.query(this.interpret),ast:this.query(Jy),errors:this.query(Yy),warnings:this.query(Xy),tokens:this.query(Zy),rawDb:this.query(Qy),publicSymbolTable:this.query($y)},this.container={stack:this.query(Uy),token:this.query(Wy),element:this.query(Gy),scope:this.query(Ky),scopeKind:this.query(qy)},this.symbol={ofName:this.query(tb,nb),members:this.query(eb)}}setSource(e){this.source=e,this.cache.clear(),this.nodeIdGenerator.reset(),this.symbolIdGenerator.reset()}query(e,t){let n=Symbol();return((...r)=>{if(r.length===0){if(this.cache.has(n))return this.cache.get(n);let t=e.apply(this,r);return this.cache.set(n,t),t}let i=t?t(...r):r[0],a=this.cache.get(n);if(a instanceof Map&&a.has(i))return a.get(i);let o=e.apply(this,r);return a instanceof Map||(a=new Map,this.cache.set(n,a)),a.set(i,o),o})}interpret(){let e=le,t=new Pv(this.source,e).lex().chain(t=>new Rv(this.source,t,this.nodeIdGenerator,e).parse()).chain(({ast:e,tokens:t})=>new Bd(e,this.symbolIdGenerator).analyze().map(()=>({ast:e,tokens:t})));return t.getErrors().length>0?t:t.chain(({ast:e,tokens:t})=>new Nv(e).interpret().map(n=>({ast:e,tokens:t,rawDb:n})))}renameTable(e,t){return hb.call(this,e,t)}syncDiagramView(e,t){return vb(this.parse.source(),e,t)}findDiagramViewBlocks(){return gb(this.parse.source())}applyTextEdits(e){return ab(this.parse.source(),e)}initMonacoServices(){return{definitionProvider:new Kv(this),referenceProvider:new Yv(this),autocompletionProvider:new hy(this),diagnosticsProvider:new Jv(this)}}};exports.CompileError=N,exports.CompileErrorCode=M,exports.Compiler=Cb,exports.ElementDeclarationNode=w,exports.ElementKind=h,exports.FALSY_VALUES=K_,exports.ProgramNode=C,exports.ScopeKind=$,exports.SyntaxNode=x,exports.SyntaxNodeKind=S,exports.SyntaxToken=vl,exports.SyntaxTokenKind=b,exports.TRUTHY_VALUES=G_,exports.addDoubleQuoteIfNeeded=Qv,exports.dbmlMonarchTokensProvider=Vy,exports.escapeString=ey,exports.extractNumericLiteral=_d,exports.extractSignedNumber=H_,exports.formatRecordValue=ty,exports.getLengthTypeParam=Of,exports.getNumericTypeParams=Df,exports.getRecordValueType=kf,exports.isBinaryType=Cf,exports.isBooleanType=xf,exports.isDateTimeType=wf,exports.isEmptyStringLiteral=B_,exports.isFloatType=yf,exports.isFunctionExpression=V_,exports.isIntegerType=vf,exports.isNullish=z_,exports.isNumericType=bf,exports.isSerialType=Tf,exports.isStringType=Sf,exports.isValidIdentifier=Zv,exports.normalizeTypeName=_f,Object.defineProperty(exports,`services`,{enumerable:!0,get:function(){return Hy}}),exports.splitQualifiedIdentifier=ny,exports.tryExtractBoolean=q_,exports.tryExtractDateTime=$_,exports.tryExtractEnum=J_,exports.tryExtractInteger=W_,exports.tryExtractNumeric=U_,exports.tryExtractString=Y_,exports.unescapeString=$v,exports.validateForeignKeys=yv,exports.validatePrimaryKey=cv,exports.validateUnique=gv;
25
+ `&&a++,[{start:i,end:a,newText:``}]}var Db=class{constructor(){this.source=``,this.cache=new Map,this.nodeIdGenerator=new wl,this.symbolIdGenerator=new vu,this.token={invalidStream:this.query(ib),flatStream:this.query(rb)},this.parse={source:()=>this.source,_:this.query(this.interpret),ast:this.query(Jy),errors:this.query(Yy),warnings:this.query(Xy),tokens:this.query(Zy),rawDb:this.query(Qy),publicSymbolTable:this.query($y)},this.container={stack:this.query(Uy),token:this.query(Wy),element:this.query(Gy),scope:this.query(Ky),scopeKind:this.query(qy)},this.symbol={ofName:this.query(tb,nb),members:this.query(eb)}}setSource(e){this.source=e,this.cache.clear(),this.nodeIdGenerator.reset(),this.symbolIdGenerator.reset()}query(e,t){let n=Symbol();return((...r)=>{if(r.length===0){if(this.cache.has(n))return this.cache.get(n);let t=e.apply(this,r);return this.cache.set(n,t),t}let i=t?t(...r):r[0],a=this.cache.get(n);if(a instanceof Map&&a.has(i))return a.get(i);let o=e.apply(this,r);return a instanceof Map||(a=new Map,this.cache.set(n,a)),a.set(i,o),o})}interpret(){let e=ce,t=new Pv(this.source,e).lex().chain(t=>new Rv(this.source,t,this.nodeIdGenerator,e).parse()).chain(({ast:e,tokens:t})=>new Bd(e,this.symbolIdGenerator).analyze().map(()=>({ast:e,tokens:t})));return t.getErrors().length>0?t:t.chain(({ast:e,tokens:t})=>new Nv(e).interpret().map(n=>({ast:e,tokens:t,rawDb:n})))}renameTable(e,t){return hb.call(this,e,t)}syncDiagramView(e,t){return Sb(this.parse.source(),e,t)}findDiagramViewBlocks(){return gb(this.parse.source())}applyTextEdits(e){return ab(this.parse.source(),e)}initMonacoServices(){return{definitionProvider:new Kv(this),referenceProvider:new Yv(this),autocompletionProvider:new hy(this),diagnosticsProvider:new Jv(this)}}};exports.CompileError=N,exports.CompileErrorCode=M,exports.Compiler=Db,exports.ElementDeclarationNode=w,exports.ElementKind=g,exports.FALSY_VALUES=K_,exports.ProgramNode=Tl,exports.ScopeKind=$,exports.SyntaxNode=S,exports.SyntaxNodeKind=C,exports.SyntaxToken=_l,exports.SyntaxTokenKind=x,exports.TRUTHY_VALUES=G_,exports.addDoubleQuoteIfNeeded=Qv,exports.dbmlMonarchTokensProvider=Vy,exports.escapeString=ey,exports.extractNumericLiteral=_d,exports.extractSignedNumber=H_,exports.formatRecordValue=ty,exports.getLengthTypeParam=Of,exports.getNumericTypeParams=Df,exports.getRecordValueType=kf,exports.isBinaryType=Cf,exports.isBooleanType=xf,exports.isDateTimeType=wf,exports.isEmptyStringLiteral=B_,exports.isFloatType=yf,exports.isFunctionExpression=V_,exports.isIntegerType=vf,exports.isNullish=z_,exports.isNumericType=bf,exports.isSerialType=Tf,exports.isStringType=Sf,exports.isValidIdentifier=Zv,exports.normalizeTypeName=_f,Object.defineProperty(exports,`services`,{enumerable:!0,get:function(){return Hy}}),exports.splitQualifiedIdentifier=ny,exports.tryExtractBoolean=q_,exports.tryExtractDateTime=$_,exports.tryExtractEnum=J_,exports.tryExtractInteger=W_,exports.tryExtractNumeric=U_,exports.tryExtractString=Y_,exports.unescapeString=$v,exports.validateForeignKeys=yv,exports.validatePrimaryKey=cv,exports.validateUnique=gv;